#include #include #include #include #include "movana.h" #include "pconana.h" #include "rmovana.h" #include "ca3.h" #include "calib01.h" //////////////////////////////////////////////////////// // APPLICAZIONE //////////////////////////////////////////////////////// class TRandom_ca : public TSkeleton_application { protected: void kill_bill(); public: virtual void main_loop(); }; void TRandom_ca::kill_bill() { const int lnum[3] = { LF_MOVANA, LF_RMOVANA, LF_SALDANA }; for (int i = 0; i < 3; i++) { TSystemisamfile f(lnum[i]); f.zap(); } } void TRandom_ca::main_loop() { 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_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); if (mask.run() == K_QUIT) return; kill_bill(); const TMultilevel_code_info& info = ca_multilevel_code_info(LF_PCONANA); TString filter; int len = 0; for (int l = info.levels()-1; l >= 0; l--) len += info.len(l); filter << "LEN(CODCONTO)==" << len; TRelation relconti(LF_PCONANA); TCursor curconti(&relconti, filter); const TRecnotype conti = curconti.items(); curconti.freeze(); TRelation relcommesse(LF_COMMESSE); TCursor curcommesse(&relcommesse); const TRecnotype commesse = curcommesse.items(); curcommesse.freeze(); TRelation relcaus(LF_CAUSALI); TCursor curcaus(&relcaus, "MOVIND=\"X\""); const TRecnotype causali = curcaus.items(); curcaus.freeze(); TEsercizi_contabili esc; const int quanti = (mask.get_int(101)+1)/2; TProgind pi(quanti, "Generazione in corso", 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"); if (causali > 0) { curcaus = rand() % causali; mov.put(MOVANA_CODCAUS, curcaus.curr().get("CODCAUS")); } const int rows = rand()%10+1; TImporto tot; int i; for (i = 0; i < rows; i++) { TRectype& rmov = mov.new_row(); rmov.put(RMOVANA_DATACOMP, mov.get(MOVANA_DATACOMP)); rmov.put(RMOVANA_ANNOES, mov.get(MOVANA_ANNOES)); TString80 descr; descr.format("Riga casuale %d", i+1); rmov.put(RMOVANA_DESCR, descr); if (conti > 0) { curconti = rand() % conti; rmov.put(RMOVANA_CODCONTO, curconti.curr().get(PCONANA_CODCONTO)); } if (commesse > 0) { curcommesse = rand() % commesse; rmov.put(RMOVANA_CODCMS, curcommesse.curr().get("CODCMS")); } 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()); TLocalisamfile fmov(LF_MOVANA); 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]; rmov.put(RMOVANA_ANNOES, mov.get(MOVANA_ANNOES)); rmov.put(RMOVANA_DATACOMP, mov.get(MOVANA_DATACOMP)); 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); } } int ca3900(int argc, char* argv[]) { TRandom_ca a; a.run(argc, argv, TR("Movimenti casuali ma perfetti")); return 0; }