diff --git a/ps/pi0001.cpp b/ps/pi0001.cpp index 94a47fb55..b43fe6703 100755 --- a/ps/pi0001.cpp +++ b/ps/pi0001.cpp @@ -7,14 +7,9 @@ int main(int argc, char** argv) int n = argc > 1 ? atoi(argv[1]+1) : 0; switch(n) { - case 1: - pi0001200(argc, argv); break; //importazione saldaconto - case 2: - pi0001300(argc, argv); break; //importazione cespiti - case 0: - default: - pi0001100(argc, argv); break; //importazione movimenti contabili + case 1: pi0001200(argc, argv); break; //importazione saldaconto + case 2: pi0001300(argc, argv); break; //importazione cespiti + default : pi0001100(argc, argv); break; //importazione movimenti contabili } - exit(0); return 0; } diff --git a/ps/pi0001100.cpp b/ps/pi0001100.cpp index 0e7b439a2..ab6131ba0 100755 --- a/ps/pi0001100.cpp +++ b/ps/pi0001100.cpp @@ -112,29 +112,25 @@ bool TImporta_mov_mask::on_field_event(TOperable_field& f, TField_event e, long { switch (f.dlg()) { - //giochetto per avere la lista dei files validi nella directory di trasferimento! - case F_NAME: - if (e == fe_button) + //giochetto per avere la lista dei files validi nella directory di trasferimento! + case F_NAME: + if (e == fe_button) + { + TArray_sheet as(-1, -1, 72, 20, TR("Selezione file"), "File@32"); + TFilename path = get(F_PATH); path.add("*.txt"); //files delle testate + list_files(path, as.rows_array()); + TFilename name; + FOR_EACH_ARRAY_ROW(as.rows_array(), i, row) { - TArray_sheet as(-1, -1, 72, 20, TR("Selezione file"), - "File@32"); - TFilename path = get(F_PATH); - path.add("*.txt"); //files delle testate - list_files(path, as.rows_array()); - TFilename name; - FOR_EACH_ARRAY_ROW(as.rows_array(), i, row) - { - name = *row; - *row = name.name(); - } - if (as.run() == K_ENTER) - { - f.set(as.row(as.selected())); - } + name = *row; + *row = name.name(); } - break; - default: - break; + if (as.run() == K_ENTER) + f.set(as.row(as.selected())); + } + break; + default: + break; } return true; } @@ -145,49 +141,55 @@ bool TImporta_mov_mask::on_field_event(TOperable_field& f, TField_event e, long /////////////////////////////////////// class TImporta_mov : public TSkeleton_application { - virtual bool check_autorization() const {return false;} - virtual const char * extra_modules() const {return "ba";} - - TImporta_mov_mask* _msk; - -//protected: - +protected: + virtual const char* extra_modules() const { return "cg"; } + void build_IVA(TConfig & conf, TArray & rows, TString_array & concg, TArray & impcg, int nrigai); public: - virtual bool create(); - virtual bool destroy(); virtual void main_loop(); - void build_IVA(TConfig & conf, TArray & rows, TString_array & concg, TArray & impcg, int nrigai); - void transfer(const TFilename& file); - - TImporta_mov() {}; + void transfer(const TMask& msk); }; -void TImporta_mov::build_IVA(TConfig & conf, TArray & rows, TString_array & concg, TArray & impcg, int nrigai) +void TImporta_mov::build_IVA(TConfig& conf, TArray& rows, TString_array& concg, TArray& impcg, int nrigai) { const int items = rows.items(); - TString paragraph; - TToken_string key; - - if (items > 0) + if (items > 0) { - int i = 0; - TString *gcs = (TString *)concg.first_item(); - real imptot = *((real *) impcg.first_item()); - TString4 gruppo = gcs->left(2); - TString4 conto = gcs->mid(2, 2); - TString8 sottoconto = gcs->right(6); + TString paragraph; + TToken_string key; + int icg = 0; + + TString4 gruppo, conto; + TString8 sottoconto; + + if (icg < concg.items()) + { + const TString& gcs = concg.row(icg); + gruppo = gcs.left(2); + conto = gcs.mid(2, 2); + sottoconto = gcs.right(6); + } + else + { + // Non so come inventare il conto + } + + real imptot; + if (icg < impcg.items()) + imptot = (const real&)impcg[icg]; + + int i = 0; while (i < items) { - TRectype & rec = (TRectype &)rows[i]; + TRectype& rec = (TRectype&)rows[i]; real imp = rec.get(RMI_IMPONIBILE); real iva = rec.get(RMI_IMPOSTA); if (imp <= imptot) i++; else { - TCodiceIVA codiva(rec.get(RMI_CODIVA)); + const TCodiceIVA codiva(rec.get(RMI_CODIVA)); imp -= imptot; rec.put(RMI_IMPONIBILE, imp); @@ -211,25 +213,32 @@ void TImporta_mov::build_IVA(TConfig & conf, TArray & rows, TString_array & conc conf.set(RMI_GRUPPO, gruppo); conf.set(RMI_CONTO, conto); conf.set(RMI_SOTTOCONTO, sottoconto); - if (imptot <= 0) + if (imptot <= ZERO) { - gcs = (TString *)concg.succ_item(); - if (gcs == NULL) - break; - imptot = *((real *) impcg.succ_item()); - gruppo = gcs->left(2); - conto = gcs->mid(2, 2); - sottoconto = gcs->right(6); + if (++icg >= concg.items()) + break; + const TString& gcs = concg.row(icg); + gruppo = gcs.left(2); + conto = gcs.mid(2, 2); + sottoconto = gcs.right(6); + + if (icg < impcg.items()) + imptot = (const real&)impcg[icg]; + else + imptot = ZERO; } - } + } } } -void TImporta_mov::transfer(const TFilename& file) +void TImporta_mov::transfer(const TMask& msk) { - TFilename outdir(_msk->get(F_PATHOUT)); - TImporta_galileo_recset s(file); - TProgind pi(s.items(),"Importazione movimenti in corso ...",true,true); + TFilename filename = msk.get(F_PATH); filename.add(msk.get(F_NAME)); + TFilename outdir(msk.get(F_PATHOUT)); + + TImporta_galileo_recset s(filename); + + TProgind pi(s.items(), TR("Importazione movimenti in corso...")); TConfig * conf = NULL; long nmov = - 1; int anno = 0; @@ -243,28 +252,25 @@ void TImporta_mov::transfer(const TFilename& file) TString4 conto; TString8 sottoconto; TString descr(50); - const int codes = _msk->get_int(F_ANNOES); - const long ditta = _msk->get_long(F_CODITTA); + const int codes = msk.get_int(F_ANNOES); + const long ditta = msk.get_long(F_CODITTA); const TEsercizi_contabili esc; TArray rows; TArray impcg; TString_array concg; TCausali_cache cache_causali; - for (bool ok=s.move_first();ok;ok=s.move_next()) { if (!pi.addstatus(1)) break; const long dt = s.get(CDDTCM).as_int(); - if (ditta != dt) continue; - const TDate datareg(s.get(DTRGCM).as_int()); - if (datareg.year() == 2009) - int i = 1; - const int es = esc.date2esc(datareg); + + const TDate datareg(s.get(DTRGCM).as_int()); + const int es = esc.date2esc(datareg); if (codes != es) continue; @@ -282,7 +288,6 @@ void TImporta_mov::transfer(const TFilename& file) dataop = d; nmov = n; - if (conf != NULL) delete conf; conf = NULL; @@ -290,22 +295,21 @@ void TImporta_mov::transfer(const TFilename& file) temp << '/' << format("%05ld", ntran++); temp.ext("ini"); - if (fexist(temp)) + if (temp.exist()) remove_file(temp); conf = new TConfig(temp); conf->set_paragraph("Transaction"); //setto il paragrafo [Transaction] del file ini conf->set("Action","INSERT"); - conf->set("Mode","AUTO"); + conf->set("Mode", "AUTO"); conf->set_paragraph("23"); //setto il paragrafo [23] del file ini (testata) - TString8 codcaus = s.get(CAUSCM).as_string(); - + TString4 codcaus = s.get(CAUSCM).as_string(); iva = s.get(TPMVCM).as_string() == "I"; if (atoi(codcaus) != 0) { codcaus << '0'; - const TCausale & c = cache_causali.causale(codcaus, codes); + const TCausale& c = cache_causali.causale(codcaus, codes); if (!iva && c.iva() != nessuna_iva) codcaus.cut(0); } @@ -369,11 +373,10 @@ void TImporta_mov::transfer(const TFilename& file) key.add(gruppo); key.add(conto); - const TString4 tipocf = cache().get(LF_PCON, key, PCN_TMCF); - + const char tipocf = cache().get(LF_PCON, key, PCN_TMCF)[0]; if (iva) { - if (tipocf.full()) + if (tipocf > ' ') { conf->set_paragraph("23"); //setto il paragrafo [23] del file ini (testata) conf->set(MOV_TIPO, tipocf); @@ -427,8 +430,8 @@ void TImporta_mov::transfer(const TFilename& file) if (ind > ZERO && ind < CENTO) { - real impind = importo * ind / 100; - real ivaind = imposta * ind / 100; + real impind = importo * ind / CENTO; + real ivaind = imposta * ind / CENTO; impind.round(2); ivaind.round(2); importo -= impind; @@ -494,44 +497,22 @@ void TImporta_mov::transfer(const TFilename& file) if (yesno_box(FR("Si desidera confermare l'importazione di %ld movimenti"), ntran -1)) { TString app; - app << "cg2 -0 -i" << outdir << "/*.ini"; TExternal_app primanota(app); primanota.run(true); } } - -bool TImporta_mov::create() -{ - _msk = new TImporta_mov_mask(); - - return TSkeleton_application::create(); -} - -bool TImporta_mov::destroy() -{ - delete _msk; - return TApplication::destroy(); -} - void TImporta_mov::main_loop() { - KEY tasto; - tasto = _msk->run(); - if (tasto == K_ENTER) + TImporta_mov_mask msk; + while (msk.run() == K_ENTER) { - //genero il nome del file da caricare - TFilename name = _msk->get(F_PATH); - name.add(_msk->get(F_NAME)); - transfer(name); - } + TWait_cursor hourglass; + transfer(msk); + } } - -TImporta_mov& app() { return (TImporta_mov&) main_app(); } - - int pi0001100 (int argc, char* argv[]) { TImporta_mov main_app; diff --git a/ps/pi0001100.h b/ps/pi0001100.h index 3c101324c..02a68507b 100755 --- a/ps/pi0001100.h +++ b/ps/pi0001100.h @@ -1,10 +1,7 @@ class TImporta_galileo_recset : public TCSV_recordset { - public: virtual const TVariant& get(unsigned int column) const; - TImporta_galileo_recset(const char* query = "") : TCSV_recordset(TString("CSV(\";)\n") << query) {} - virtual ~TImporta_galileo_recset() {} }; diff --git a/ps/pi0001100a.uml b/ps/pi0001100a.uml index 30de083cf..7c1e1332a 100755 --- a/ps/pi0001100a.uml +++ b/ps/pi0001100a.uml @@ -2,17 +2,7 @@ TOOLBAR "" 0 0 0 2 -BUTTON DLG_ELABORA 10 2 -BEGIN - PICTURE BMP_ELABORA - MESSAGE EXIT,K_ENTER - PROMPT -12 -1 "E~labora" -END - -BUTTON DLG_QUIT 10 2 -BEGIN - PROMPT -22 -1 "" -END +#include ENDPAGE @@ -60,6 +50,7 @@ BEGIN DSELECT CHECKTYPE REQUIRED FIELD ComInPath + FLAGS "M" END STRING F_NAME 18 @@ -94,6 +85,7 @@ BEGIN DSELECT CHECKTYPE REQUIRED FIELD ComOutPath + FLAGS "M" END ENDPAGE