#include #include #include #include #include #include #include #include #include #include #include #include #include #include "../cg/cglib01.h" #include "lv4.h" #include "lv4100.h" #include "lv4100a.h" #include #include #include #include #define DITTA_PK 0 #define TIPO 1 #define GRUPPO 2 #define CONTO 3 #define SOTTOCONTO 4 #define ANNO 5 #define VALUTA 6 #define CREAZIONE 7 #define PROGR_DARE 8 #define PROGR_AVERE 9 #define SALDO_APERTURA 10 #define SALDO_CHIUSURA 11 #define ULT_PAG_PART 12 #define DARE_PARTITARIO 13 #define AVERE_PARTITARIO 14 #define DATAAGG_PARTITARIO 15 /*const TVariant& TImporta_saldi_recset::get(unsigned int column) const { TString str = TCSV_recordset::get(column).as_string(); TVariant& var = get_tmp_var(); int len = str.len(); if (len == 0) return NULL_VARIANT; if (str[len -1] == '"') str.rtrim(1); if (str[0] == '"') str.ltrim(1); var.set(str); return var; } */ /////////////////////////////////////////////////////////// // TAutomask /////////////////////////////////////////////////////////// class TImporta_saldi_mask : public TAutomask { protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); public: TImporta_saldi_mask(); }; TImporta_saldi_mask::TImporta_saldi_mask() :TAutomask ("lv4100a") { } bool TImporta_saldi_mask::on_field_event(TOperable_field& f, TField_event e, long jolly) { switch (f.dlg()) { //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) { name = *row; *row = name.name(); } if (as.run() == K_ENTER) { f.set(as.row(as.selected())); } } break; default: break; } return true; } /////////////////////////////////////// // TSkeleton_application /////////////////////////////////////// class TImporta_saldi : public TSkeleton_application { virtual bool check_autorization() const {return false;} virtual const char * extra_modules() const {return "ba";} TImporta_saldi_mask* _msk; //protected: public: virtual bool create(); virtual bool destroy(); virtual void main_loop(); void transfer(const TFilename& file); TImporta_saldi() {}; }; void TImporta_saldi::transfer(const TFilename& file) { TFilename outdir(_msk->get(F_PATHOUT)); TImporta_cogeco_recset s(file); TProgind pi(s.items(),"Importazione saldi in corso ...",true,true); TConfig * conf = NULL; long ntran = 1L; int nrow = 1; int anno = 0; TString8 reg; TDate dataop = _msk->get_date(F_DATAMOV); TImporto totmov; TConfig cditta(CONFIG_DITTA, "cg"); const TString4 ctypes("GCF"); const TString8 causale = cditta.get("CoCaAp"); const int gruppoap = cditta.get_int("CsBiApG"); const int contoap = cditta.get_int("CsBiApC"); const long sottocontoap = cditta.get_long("CsBiApS"); int lastgruppo = 0; const int codes = _msk->get_int(F_ANNOES); const long ditta = _msk->get_long(F_CODITTA); const TEsercizi_contabili esc; TString8 paragraph; for (bool ok=s.move_first();ok;ok=s.move_next()) { if (!pi.addstatus(1)) break; const long dt = s.get(DITTA_PK).as_int(); if (ditta != dt) continue; const int es = s.get(ANNO).as_int(); if (codes != es) continue; if (ctypes.find(s.get(TIPO).as_string()[0]) < 0) continue; int gruppo = s.get(GRUPPO).as_int(); int conto = s.get(CONTO).as_int(); long sottoconto = s.get(SOTTOCONTO).as_int(); if (lastgruppo != gruppo && nrow >= 99) { if (conf != NULL) { paragraph.format("%d,%d",LF_RMOV,nrow++); conf->set_paragraph(paragraph); conf->set(RMV_SEZIONE, totmov.sezione()); conf->set(RMV_IMPORTO, totmov.valore().string()); conf->set(RMV_GRUPPO, gruppoap); conf->set(RMV_CONTO, contoap); conf->set(RMV_SOTTOCONTO, sottocontoap); delete conf; } conf = NULL; TFilename temp(outdir); temp << '/' << format("%05ld", ntran++); temp.ext("ini"); if (fexist(temp)) 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_paragraph("23"); //setto il paragrafo [23] del file ini (testata) conf->set(MOV_CODCAUS, causale); conf->set(MOV_DATAREG, dataop.stringa()); conf->set(MOV_DESCR, "Ripresa Saldi"); nrow = 1; lastgruppo = gruppo; } real val = s.get(SALDO_APERTURA).as_real(); TImporto impmov(val > ZERO ? 'D' : 'A', abs(val)); const TImporto pdare('D', s.get(PROGR_DARE).as_real()); const TImporto pavere('A', s.get(PROGR_AVERE).as_real()); impmov += pdare; impmov += pavere; if (impmov.valore() != ZERO) { paragraph.format("%d,%d",LF_RMOV,nrow++); conf->set_paragraph(paragraph); conf->set(RMV_SEZIONE, impmov.sezione()); conf->set(RMV_IMPORTO, impmov.valore().string()); conf->set(RMV_GRUPPO, gruppo); conf->set(RMV_CONTO, conto); conf->set(RMV_SOTTOCONTO, sottoconto); totmov -= impmov; } } if (conf != NULL) { paragraph.format("%d,%d",LF_RMOV,nrow++); conf->set_paragraph(paragraph); conf->set(RMV_SEZIONE, totmov.sezione()); conf->set(RMV_IMPORTO, totmov.valore().string()); conf->set(RMV_GRUPPO, gruppoap); conf->set(RMV_CONTO, contoap); conf->set(RMV_SOTTOCONTO, sottocontoap); delete conf; } 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_saldi::create() { _msk = new TImporta_saldi_mask(); return TSkeleton_application::create(); } bool TImporta_saldi::destroy() { delete _msk; return TApplication::destroy(); } void TImporta_saldi::main_loop() { KEY tasto; tasto = _msk->run(); if (tasto == K_ENTER) { //genero il nome del file da caricare TFilename name = _msk->get(F_PATH); name.add(_msk->get(F_NAME)); transfer(name); } } TImporta_saldi& app() { return (TImporta_saldi&) main_app(); } int lv4100 (int argc, char* argv[]) { TImporta_saldi main_app; main_app.run(argc, argv, TR("Importazione contabilità Galileo")); return true; }