Files correlati :ca3 & friends Ricompilazione Demo : [ ] Commento :completato ca3800 (bilancio di commessa); spostato il prg x generare movana casuali in ca3400;aggiunto ca3900 (stima ricavi di competenza) anche a menu, ma da completare git-svn-id: svn://10.65.10.50/trunk@14348 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			299 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			299 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						|
#include <mask.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <urldefid.h>
 | 
						|
 | 
						|
#include <causali.h>
 | 
						|
#include <pconti.h>
 | 
						|
 | 
						|
#include "cdc.h"
 | 
						|
#include "fasi.h"
 | 
						|
#include "movana.h"
 | 
						|
#include "pconana.h"
 | 
						|
#include "rmovana.h"
 | 
						|
 | 
						|
#include "ca3.h"
 | 
						|
#include "calib01.h"
 | 
						|
#include "../cg/cglib01.h"
 | 
						|
 | 
						|
class TCode_generator
 | 
						|
{
 | 
						|
  TRelation* _rel;
 | 
						|
  TCursor* _cur;
 | 
						|
 | 
						|
public:
 | 
						|
  TRecnotype items() const { return _cur->items(); }
 | 
						|
  const TString& code();
 | 
						|
  
 | 
						|
  TCode_generator(int logicnum);
 | 
						|
  ~TCode_generator();
 | 
						|
};
 | 
						|
 | 
						|
const TString& TCode_generator::code()
 | 
						|
{
 | 
						|
  const TRecnotype i = items();
 | 
						|
  if (i > 0)
 | 
						|
  {
 | 
						|
    *_cur = rand() % i;
 | 
						|
    const TRectype& curr = _rel->curr();
 | 
						|
    const int logicnum = curr.num();
 | 
						|
    switch (logicnum)
 | 
						|
    {
 | 
						|
    case LF_CAUSALI:
 | 
						|
      return curr.get(CAU_CODCAUS);
 | 
						|
    case LF_CDC: 
 | 
						|
      return curr.get(CDC_CODCOSTO);
 | 
						|
    case LF_COMMESSE: 
 | 
						|
      return curr.get("CODCMS");
 | 
						|
    case LF_FASI: 
 | 
						|
      return curr.get(FASI_CODFASE);
 | 
						|
    case LF_PCON: 
 | 
						|
      {
 | 
						|
        TString& tmp = get_tmp_string(12);
 | 
						|
        tmp.format("%03d%03d%06ld", 
 | 
						|
                   curr.get_int(PCN_GRUPPO), curr.get_int(PCN_CONTO), curr.get_long(PCN_SOTTOCONTO));
 | 
						|
        return tmp;
 | 
						|
      }
 | 
						|
    case LF_PCONANA: 
 | 
						|
      return curr.get(PCONANA_CODCONTO);
 | 
						|
    default:
 | 
						|
      break;
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return EMPTY_STRING;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
TCode_generator::TCode_generator(int logicnum)
 | 
						|
{
 | 
						|
  TWait_cursor hourglass;
 | 
						|
  TString filter;
 | 
						|
 | 
						|
  if (logicnum <= 0)
 | 
						|
  {
 | 
						|
   	TConfig& cfg = ca_config();
 | 
						|
    const bool use_pdcc =  cfg.get_bool("UsePdcc");
 | 
						|
    logicnum = use_pdcc ? LF_PCON : LF_PCONANA;
 | 
						|
  }
 | 
						|
 | 
						|
  switch (logicnum)
 | 
						|
  {
 | 
						|
  case LF_CAUSALI:
 | 
						|
    filter = "MOVIND=\"X\"";
 | 
						|
    break;
 | 
						|
  case LF_PCON:
 | 
						|
    filter = "SOTTOCONTO!=''";
 | 
						|
    break;
 | 
						|
  case LF_PCONANA:
 | 
						|
    {
 | 
						|
      const TMultilevel_code_info& info = ca_multilevel_code_info(LF_PCONANA);
 | 
						|
      const int min_len = info.total_len(-1);
 | 
						|
      filter << "STR(NUM(LEN(CODCONTO))>" << min_len << ')';
 | 
						|
    }
 | 
						|
    break;
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }
 | 
						|
 | 
						|
  _rel = new TRelation(logicnum);
 | 
						|
  _cur = new TCursor(_rel, filter);
 | 
						|
  const TRecnotype conti = _cur->items();
 | 
						|
  _cur->freeze();
 | 
						|
}
 | 
						|
 | 
						|
TCode_generator::~TCode_generator()
 | 
						|
{
 | 
						|
  delete _cur;
 | 
						|
  delete _rel;
 | 
						|
}
 | 
						|
 | 
						|
////////////////////////////////////////////////////////
 | 
						|
//	APPLICAZIONE
 | 
						|
////////////////////////////////////////////////////////
 | 
						|
class TRandom_ca : public TSkeleton_application
 | 
						|
{
 | 
						|
protected:
 | 
						|
  bool chiedi_quanti(int& mov, bool& ric);
 | 
						|
  void kill_bill();
 | 
						|
  void genera(int quanti);
 | 
						|
  void genera_riclass();
 | 
						|
 | 
						|
public:
 | 
						|
  void riclassify(const TString& conto);
 | 
						|
  virtual void main_loop();
 | 
						|
};
 | 
						|
 | 
						|
bool TRandom_ca::chiedi_quanti(int& mov, bool& ric)
 | 
						|
{
 | 
						|
  TMask mask("Movimenti casuali ma perfetti", 1, 60, 6);
 | 
						|
 | 
						|
  TReal_field& add_number (short id, int page, const char* prompt, int x, int y, int dim,  const char* flags = "", int ndec = 0);
 | 
						|
  mask.add_number(101, 0, "Numero di movimenti ", 1, 1, 4, "U");
 | 
						|
  mask.add_boolean(102, 0, "Genera riclassificazioni", 1, 2);
 | 
						|
  mask.add_static (DLG_NULL, 0, "@bAttenzione: verranno distrutti movimenti e saldi", 1, 3);
 | 
						|
  mask.add_button(DLG_OK, 0, "", -12, -1, 10, 2);
 | 
						|
  mask.add_button(DLG_QUIT, 0, "", -22, -1, 10, 2);
 | 
						|
  mask.set(101, 100);
 | 
						|
  const bool ok = mask.run() != K_QUIT;
 | 
						|
  if (ok)
 | 
						|
  {
 | 
						|
    mov = (mask.get_int(101)+1)/2;
 | 
						|
    ric = mask.get_bool(102);
 | 
						|
  }
 | 
						|
  
 | 
						|
  return ok;
 | 
						|
}
 | 
						|
 | 
						|
void TRandom_ca::kill_bill()
 | 
						|
{
 | 
						|
  const int lnum[] = { LF_MOVANA, LF_RMOVANA, LF_SALDANA, 0 };
 | 
						|
  for (int i = 0; lnum[i]; i++)
 | 
						|
  {
 | 
						|
    TSystemisamfile f(lnum[i]);
 | 
						|
    f.zap();
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TRandom_ca::riclassify(const TString& conto)
 | 
						|
{
 | 
						|
  const TMultilevel_code_info& info = ca_multilevel_code_info(LF_PCONANA);
 | 
						|
  const int min_len = info.total_len(-1);
 | 
						|
  if (conto.len() > min_len)
 | 
						|
  {
 | 
						|
    TRecord_array ric(conto, LF_PANAPDC);
 | 
						|
 | 
						|
    TCode_generator conti(LF_PCON);
 | 
						|
    const int righe = rand() % 4 + 1;
 | 
						|
    for (int i = 1; i <= righe; i++)
 | 
						|
    {
 | 
						|
      TRectype& row = ric.row(i, true);
 | 
						|
      const TString& c = conti.code();
 | 
						|
      row.put(PCN_GRUPPO,     c.mid(0, 3));
 | 
						|
      row.put(PCN_CONTO,      c.mid(3, 3));
 | 
						|
      row.put(PCN_SOTTOCONTO, c.mid(6, 6));
 | 
						|
    }
 | 
						|
    ric.write();
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
static bool riclass_callback(const TRelation& rel, void* jolly)
 | 
						|
{
 | 
						|
  TRandom_ca* myself = (TRandom_ca*)jolly;
 | 
						|
  const TString80 conto = rel.curr().get(PCONANA_CODCONTO);
 | 
						|
  myself->riclassify(conto);
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
void TRandom_ca::genera_riclass()
 | 
						|
{
 | 
						|
  {
 | 
						|
    TSystemisamfile f(LF_PANAPDC);
 | 
						|
    f.zap();
 | 
						|
  }
 | 
						|
 | 
						|
  TRelation rel(LF_PCONANA);
 | 
						|
  TCursor cur(&rel);
 | 
						|
  cur.scan(riclass_callback, this, "Generazione riclassificazioni");
 | 
						|
}
 | 
						|
 | 
						|
void TRandom_ca::genera(int quanti)
 | 
						|
{
 | 
						|
  TEsercizi_contabili esc;
 | 
						|
 | 
						|
  TCode_generator conti(0);
 | 
						|
  TCode_generator commesse(LF_COMMESSE);
 | 
						|
  TCode_generator fasi(LF_FASI);
 | 
						|
  TCode_generator costi(LF_CDC);
 | 
						|
  TCode_generator causali(LF_CAUSALI);
 | 
						|
 | 
						|
  TLocalisamfile fmov(LF_MOVANA);
 | 
						|
  TProgind pi(quanti, "Generazione movimenti", FALSE, TRUE);
 | 
						|
  for (int m = 0; m < quanti; m++)
 | 
						|
  {
 | 
						|
    pi.addstatus(1);
 | 
						|
    TAnal_mov mov;
 | 
						|
  
 | 
						|
    TDate data(TODAY); data -= rand()%365;
 | 
						|
    mov.put(MOVANA_DATAREG, data);
 | 
						|
    mov.put(MOVANA_DATACOMP, data-1L);
 | 
						|
    mov.put(MOVANA_DATADOC, data-2L);
 | 
						|
    mov.put(MOVANA_ANNOES, esc.date2esc(data));
 | 
						|
    mov.put(MOVANA_DESCR, "Movimento random preventivo");
 | 
						|
    mov.put(MOVANA_TIPOMOV, "P");
 | 
						|
    mov.put(MOVANA_CODCAUS, causali.code());
 | 
						|
 | 
						|
    const int rows = rand()%10+1;
 | 
						|
    TImporto tot;
 | 
						|
    int i;
 | 
						|
    for (i = 0; i < rows; i++)
 | 
						|
    {
 | 
						|
      TRectype& rmov = mov.new_row();
 | 
						|
      TString80 descr; descr.format("Riga casuale %d", i+1);
 | 
						|
      rmov.put(RMOVANA_DESCR, descr);
 | 
						|
      rmov.put(RMOVANA_CODCONTO, conti.code());
 | 
						|
      rmov.put(RMOVANA_CODCMS, commesse.code());
 | 
						|
      rmov.put(RMOVANA_CODFASE, fasi.code());
 | 
						|
      rmov.put(RMOVANA_CODCCOSTO, costi.code());
 | 
						|
 | 
						|
      const TImporto imp(i & 0x1 ? 'A' : 'D', real(10*(rand()%1000+1)));
 | 
						|
      rmov.put(RMOVANA_SEZIONE, imp.sezione());
 | 
						|
      rmov.put(RMOVANA_IMPORTO, imp.valore());
 | 
						|
      tot += imp;
 | 
						|
    }
 | 
						|
 | 
						|
    tot.normalize();
 | 
						|
    mov.put(MOVANA_SEZIONE, tot.sezione());
 | 
						|
    mov.put(MOVANA_TOTDOC, tot.valore());
 | 
						|
 | 
						|
    mov.write(fmov);
 | 
						|
 | 
						|
    // Consuntivo
 | 
						|
    mov.put(MOVANA_NUMREG, mov.get_long(MOVANA_NUMREG)+1);
 | 
						|
    data += rand()%30+30;
 | 
						|
    mov.put(MOVANA_DATAREG, data);
 | 
						|
    mov.put(MOVANA_DATACOMP, data-1L);
 | 
						|
    mov.put(MOVANA_DATADOC, data-2L);
 | 
						|
    mov.put(MOVANA_ANNOES, esc.date2esc(data));
 | 
						|
    mov.put(MOVANA_DESCR, "Movimento random consuntivo");
 | 
						|
    mov.put(MOVANA_TIPOMOV, "");
 | 
						|
 | 
						|
    tot.set('D', ZERO);
 | 
						|
    for (i = 1; i <= rows; i++)
 | 
						|
    {
 | 
						|
      TRectype& rmov = mov.body()[i];
 | 
						|
      real imp = rmov.get(RMOVANA_IMPORTO);
 | 
						|
      imp += real((rand()%100)-50);
 | 
						|
      rmov.put(RMOVANA_IMPORTO, imp);
 | 
						|
      tot += TImporto(rmov.get_char(RMOVANA_SEZIONE), imp);
 | 
						|
    }
 | 
						|
    tot.normalize();
 | 
						|
    mov.put(MOVANA_SEZIONE, tot.sezione());
 | 
						|
    mov.put(MOVANA_TOTDOC, tot.valore());
 | 
						|
    
 | 
						|
    mov.write(fmov);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TRandom_ca::main_loop()
 | 
						|
{
 | 
						|
  int quanti = 100;
 | 
						|
  bool ric = false;
 | 
						|
  if (chiedi_quanti(quanti, ric))
 | 
						|
  {
 | 
						|
    if (quanti > 0)
 | 
						|
    {
 | 
						|
      kill_bill();
 | 
						|
      genera(quanti);
 | 
						|
    }
 | 
						|
    if (ric) 
 | 
						|
      genera_riclass();
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
int ca3400(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TRandom_ca a;
 | 
						|
  a.run(argc, argv, TR("Movimenti casuali ma perfetti"));
 | 
						|
  return 0;
 | 
						|
}
 |