diff --git a/ps/ps0713.cpp b/ps/ps0713.cpp index 4e6502c4b..980901705 100755 --- a/ps/ps0713.cpp +++ b/ps/ps0713.cpp @@ -7,13 +7,13 @@ int main(int argc, char** argv) int n = argc > 1 ? atoi(argv[1]+1) : 0; switch(n) { - case 0: ps0713100(argc, argv); break; //Trasferimento dati contabili per ATS - case 1: ps0713200(argc, argv); break; //Trasferimento commesse - case 2: ps0713300(argc, argv); break; //Importazione fatture di acquisto per ATS - case 3: ps0713400(argc, argv); break; //Importazione fatture di vendita per ATS - case 4: ps0713500(argc, argv); break; //Importazione spese per ATS - default: - ps0713100(argc, argv); break; //Trasferimento dati contabili per ATS + case 0: ps0713100(argc, argv); break; //Esportazione righe IVA + case 1: ps0713200(argc, argv); break; //Importazione commesse +//case 2: ps0713300(argc, argv); break; //Importazione fatture di acquisto per ATS + case 3: ps0713400(argc, argv); break; //Importazione fatture di vendita per ATS +//case 4: ps0713500(argc, argv); break; //Importazione spese per ATS +//case 5: ps0713600(argc, argv); break; //Importazione fatture fornitori / fatture da ricevere + default: ps0713100(argc, argv); break; //Esportazione righe IVA } exit(0); return 0; diff --git a/ps/ps0713.h b/ps/ps0713.h index 678505f54..3eb43f2fd 100755 --- a/ps/ps0713.h +++ b/ps/ps0713.h @@ -3,3 +3,4 @@ int ps0713200(int argc, char* argv[]); int ps0713300(int argc, char* argv[]); int ps0713400(int argc, char* argv[]); int ps0713500(int argc, char* argv[]); +int ps0713600(int argc, char* argv[]); \ No newline at end of file diff --git a/ps/ps0713100.cpp b/ps/ps0713100.cpp index 08fe94661..69e04be1e 100755 --- a/ps/ps0713100.cpp +++ b/ps/ps0713100.cpp @@ -1,101 +1,76 @@ #include #include #include -#include -#include #include #include #include +#include "../ca/calib01.h" +#include "../ca/calib02.h" #include "../cg/cgsaldac.h" -#include "ps0713.h" #include "ps0713100a.h" -/////////////////////////////////////////////////////////// -// TEsporta_ps0713 maschera -/////////////////////////////////////////////////////////// + /////////////////////////////////// + //// TESPORTA_DATIVA_MSK //// + /////////////////////////////////// -class TEsporta_ps0713_mask : public TAutomask +//Classe TEsporta_dativa_msk +class TEsporta_dativa_msk : public TAutomask { public: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); - TEsporta_ps0713_mask(); - ~TEsporta_ps0713_mask(); + TEsporta_dativa_msk(); }; -bool TEsporta_ps0713_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) +//ON_FIELD_EVENT: metodo che gestisce i comportamenti dei vari campi della maschera +bool TEsporta_dativa_msk::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) - { - //giochetto per avere la lista dei files validi nella directory di trasferimento! - case F_ADATA: - if (e == fe_modify || e == fe_close) - { - TDate adata = o.get(); - TString str_adata; - str_adata << adata.date2ansi() << ".txt"; - set(F_NAME, str_adata); - } - break; - default: - break; + { + case F_ADATA: + if (e == fe_modify || e == fe_close) + { + //setto il campo F_NAME a un valore fisso, e cioè: "data_in_ANSI.txt" + TDate adata = o.get(); + TString16 str_adata; str_adata << adata.date2ansi() << ".txt"; + set(F_NAME, str_adata); + } + break; + default: break; } return true; } -TEsporta_ps0713_mask::TEsporta_ps0713_mask() : TAutomask("ps0713100a") -{ - //carica i parametri del file di configurazione - TConfig configfile("ps0713conf.ini", "MAIN"); - for (int i = 0; i < fields() ; i++) - { - TMask_field& f = fld(i); - const TFieldref* fr = f.field(); - if (fr != NULL) - f.set(configfile.get(fr->name())); - } -} +//metodo costruttore +TEsporta_dativa_msk::TEsporta_dativa_msk() : TAutomask("ps0713100a"){} -TEsporta_ps0713_mask::~TEsporta_ps0713_mask() -{ - //carica i parametri del file di configurazione - TConfig configfile("ps0713conf.ini", "MAIN"); - for (int i = 0; i < fields() ; i++) - { - TMask_field& f = fld(i); - const TFieldref* fr = f.field(); - if (fr != NULL) - configfile.set(fr->name(), f.get()); - } -} + /////////////////////////////////// + //// TESPORTA_DATIVA_REC //// + /////////////////////////////////// -///////////////////////////////////////////////////////////// -// TEsporta_ps0713 recordset (righe movimenti iva) -///////////////////////////////////////////////////////////// - -class TEsporta_ps0713_recordset : public TCSV_recordset +//Classe TEsporta_dativa_rec (righe movimenti iva) +class TEsporta_dativa_rec : public TCSV_recordset { public: - TEsporta_ps0713_recordset(); + TEsporta_dativa_rec(); }; - -TEsporta_ps0713_recordset::TEsporta_ps0713_recordset() -: TCSV_recordset("CSV(\"\t\")") +//metodo costruttore +TEsporta_dativa_rec::TEsporta_dativa_rec() + : TCSV_recordset("CSV(\"\t\")") { } + /////////////////////////////////// + //// TESPORTA_DATIVA_APP //// + /////////////////////////////////// -/////////////////////////////////////////////////////////// -// TEsporta_ps0713 applicazione -/////////////////////////////////////////////////////////// - -class TEsporta_ps0713_app : public TSkeleton_application +//Classe TEsporta_dativa_app +class TEsporta_dativa_app : public TSkeleton_application { - protected: virtual bool check_autorization() const {return false;} virtual const char * extra_modules() const {return "cg";} @@ -105,41 +80,180 @@ protected: public: void esporta_righe_iva(const TMask& msk) const; - void set_inviva(TISAM_recordset& rmoviva) const; - + void set_inviva(TISAM_recordset& rmoviva) const; }; -void TEsporta_ps0713_app::set_inviva(TISAM_recordset& rmoviva) const +//TEST_PARTITA: metodo che cerca l'ultima data pagamento delle partite relative ad un numreg (la maggiore) +//il metodo restiruisce true se esiste almeno una partita per il numreg indicato +bool TEsporta_dativa_app::test_partita(const long numreg, TDate& last_data_pag) const { - long last_numreg = 0L; - const long items = rmoviva.items(); - TProgind pi(items, TR("Impostazione flag Inviata parte IVA..."), true, true); - TLocalisamfile mov(LF_MOV); + TPartite_array torneo; + //aggiungo all'array tutte le partite con quel numreg + torneo.add_numreg(numreg); + TPartita* partita = torneo.first(); + //se esiste almeno una partita ed è chiusa + if (partita != NULL && partita->chiusa()) + { + //scorro tutte le partite + for (int r = partita->last(); r > 0; r = partita->pred(r)) + { + //instanzio una riga_partite + const TRiga_partite& row = partita->riga(r); + const tipo_movimento tipo = row.tipo(); + //controllo il tipo_movimento; se è del tipo tm_pagamento o tm_pagamento_insoluto + //recupero la data del pagamento, e se questa è maggiore di quella già trovata, aggiorno + //quest'ultima + if (tipo == tm_pagamento || tipo == tm_pagamento_insoluto) + { + const TDate datadoc = row.get_date(PART_DATAPAG); + if (datadoc > last_data_pag) + last_data_pag = datadoc; + } + } + return true; + } + return false; +} + +//ESPORTA_RIGHE_IVA: metodo che prepara il csv-recordset per essere esportato +void TEsporta_dativa_app::esporta_righe_iva(const TMask& m) const +{ + //instanzio il TFilename e controllo la sua esistenza + TFilename path = m.get(F_PATH); + path.add(m.get(F_NAME)); + if (path.exist()) + { + TString str; + str << "ATTENZIONE! " << "Il file " << m.get(F_NAME) << "è già esistente.\n" + << "Se si procede sara' azzerato il file esistente!\nContinuare?"; + if (!yesno_box(str)) + return; + } + + //preparo le date di interesse + const TDate adata(m.get_date(F_ADATA)); + const TDate dadata(1, 1, adata.year() - 1); + + //preparo query su righe iva joinati ai mov + TString query; + query << "USE RMOVIVA " + << "SELECT ((NUM(ANSI(23.DATAREG))>=NUM(ANSI(#DADATA)))" + << "&&(NUM(ANSI(23.DATAREG))<=NUM(ANSI(#ADATA))))&&(23.INVIVA!=\"X\")&&(23.TIPO=\"F\")"; + + if (m.get_int(F_JOB) == 1) + query << "&&(CODCMS!=\"\")\n"; + else + query << "&&(CODCMS=\"\")\n"; + + query << "JOIN MOV INTO NUMREG==NUMREG\n" + << "JOIN %IVA ALIAS 101 INTO CODTAB==CODIVA\n" + << "JOIN CLIFO TO MOV INTO TIPOCF==TIPO CODCF==CODCF"; + + //instanzio il recordset + TISAM_recordset rmoviva(query); + rmoviva.set_var("#DADATA", dadata); + rmoviva.set_var("#ADATA", adata); + + //instanzio il csv recordset + TEsporta_dativa_rec csv; + + TProgind pi(rmoviva.items(), TR("Estrazione dati..."), true, true); for (bool ok = rmoviva.move_first(); ok; ok = rmoviva.move_next()) { if (!pi.addstatus(1)) break; - const long curr_numreg = rmoviva.get(RMI_NUMREG).as_int(); - if (curr_numreg != last_numreg) + + TDate last_data_pag; + const long numreg = rmoviva.get(RMI_NUMREG).as_int(); + const real impiva = rmoviva.get(RMI_IMPONIBILE).as_real(); + bool partita_chiusa = test_partita(numreg, last_data_pag); + + if (partita_chiusa) + { + //creazione di un nuovo record da esportare + csv.new_rec(""); + //..e successivo riempimento + TString8 codcms; codcms.cut(0); + TString query_movana; + query_movana << "USE MOVANA KEY 3\n" + << "FROM NUMREGCG=NUMREG\n" + << "TO NUMREGCG=NUMREG"; + TISAM_recordset rec_movana(query_movana); + rec_movana.set_var("#NUMREGCG", numreg); + + TAnal_mov movana = rec_movana.move_first(); + + for(int i = 1; i <= movana.rows(); i++) + { + const TRectype& rmovana = movana.body()[i]; + const real impana = rmovana.get_real("IMPORTO"); + + if(impiva == impana) + codcms = rmovana.get("CODCMS"); + } + + csv.set(0, codcms); + csv.set(1, rmoviva.get("23.CODCF")); + csv.set(2, rmoviva.get("20.RAGSOC")); + csv.set(3, rmoviva.get(RMI_IMPONIBILE).as_real()); + csv.set(6, rmoviva.get("23.DATADOC")); + csv.set(7, rmoviva.get("23.NUMDOC")); + csv.set(8, last_data_pag); + } + } + csv.save_as(path, fmt_text); + +#ifdef DBG + xvt_sys_goto_url(path, "open"); +#endif + + TString msg; + msg << "Si conferma l'esportazione definitiva dei movimenti IVA fino al "; + msg << m.get(F_ADATA); + if (yesno_box(msg)) + set_inviva(rmoviva); //mette il flag di "INVIVA" alla testata movimento +} + +//SET_INVIA: metodo che mette il flag di "INVIVA" alla testata movimento +void TEsporta_dativa_app::set_inviva(TISAM_recordset& rmoviva) const +{ + long last_numreg = 0L; + + TProgind pi(rmoviva.items(), TR("Impostazione flag Inviata parte IVA..."), true, true); + TLocalisamfile mov(LF_MOV); + + //scorro il recordset che contiene le righe IVA joinate con i movimenti + for (bool ok = rmoviva.move_first(); ok; ok = rmoviva.move_next()) + { + if (!pi.addstatus(1)) + break; + + const long curr_numreg = rmoviva.get(RMI_NUMREG).as_int(); + //ad ogni cambio di numreg + if (curr_numreg != last_numreg) { TDate last_data_pag; bool partita_chiusa = test_partita(curr_numreg, last_data_pag); - + //controllo che la partita sia chiusa if (partita_chiusa) { - mov.put(MOV_NUMREG, curr_numreg); + //leggo dal file LF_MOV quello che ha il numero di registrazione selezioante + mov.put(MOV_NUMREG, curr_numreg); int err = mov.read(); + + //se riesco a leggerlo setto il flag di invio e aggriono il movimento if (err == NOERR) { mov.put(MOV_INVIVA, 'X'); err = mov.rewrite(); } + + //se non sono riuscito ne a leggerlo ne a scriverlo, lo segnalo if (err != NOERR) { - TString cazzone; - cazzone << TR("Impossibile aggiornare il movimento "); - cazzone << curr_numreg; - error_box(cazzone); + TString str; + str << "Impossibile aggiornare il movimento " << curr_numreg; + error_box(str); break; } } @@ -148,124 +262,16 @@ void TEsporta_ps0713_app::set_inviva(TISAM_recordset& rmoviva) const } } -bool TEsporta_ps0713_app::test_partita(const long numreg, TDate& last_data_pag) const +void TEsporta_dativa_app::main_loop() { - bool finito = false; - - TPartite_array torneo; - torneo.add_numreg(numreg); - TPartita* partita = torneo.first(); - if (partita != NULL && partita->chiusa()) - { - for (int r = partita->last(); r > 0; r = partita->pred(r)) - { - const TRiga_partite& row = partita->riga(r); - const tipo_movimento tipo = row.tipo(); - if (tipo == tm_pagamento || tipo == tm_pagamento_insoluto) - { - const TDate datadoc = row.get_date(PART_DATAPAG); - if (datadoc > last_data_pag) - last_data_pag = datadoc; - } - } - finito = true; - } - - return finito; -} - - -void TEsporta_ps0713_app::esporta_righe_iva(const TMask& m) const -{ - TFilename path = m.get(F_PATH); - path.add(m.get(F_NAME)); - if (path.exist()) - if (!yesno_box(TR("ATTENZIONE! File gia' presente! Se si procede sara' azzerato il file esistente!\nContinuare?"))) - return; - - // query su righe iva joinati ai mov - TString query; - query << "USE RMOVIVA "; - query << "SELECT ((NUM(ANSI(23.DATAREG))>=NUM(ANSI(#DADATA)))&&(NUM(ANSI(23.DATAREG))<=NUM(ANSI(#ADATA))))&&(23.INVIVA!=\"X\")&&(23.TIPO=\"F\")"; - - if (m.get_int(F_JOB) == 1) - query << "&&(CODCMS!=\"\")"; - else - query << "&&(CODCMS=\"\")"; - - query << "\nJOIN MOV INTO NUMREG==NUMREG"; - query << "\nJOIN %IVA ALIAS 101 INTO CODTAB==CODIVA"; - query << "\nJOIN CLIFO TO MOV INTO TIPOCF==TIPO CODCF==CODCF"; - - TISAM_recordset rmoviva(query); - const TDate& adata = m.get_date(F_ADATA); - const TDate dadata(1,1, adata.year() - 1); - rmoviva.set_var("#DADATA", dadata); - rmoviva.set_var("#ADATA", adata); - - TEsporta_ps0713_recordset csv; - - const long items = rmoviva.items(); - TProgind pi(items, TR("Estrazione dati..."), true, true); - TString ws; - for (bool ok = rmoviva.move_first(); ok; ok = rmoviva.move_next()) - { - if (!pi.addstatus(1)) - break; - - TDate last_data_pag; - bool partita_chiusa = test_partita(rmoviva.get(RMI_NUMREG).as_int(), last_data_pag); - - if (partita_chiusa) - { - //creazione di un nuovo record da esportare - csv.new_rec(""); - //..e successivo riempimento - csv.set(0, rmoviva.get(RMI_CODCMS)); - csv.set(1, rmoviva.get("23.CODCF")); - csv.set(2, rmoviva.get("20.RAGSOC")); - const real imponibile = rmoviva.get(RMI_IMPONIBILE).as_real(); -// const real imposta = rmoviva.get(RMI_IMPOSTA).as_real(); -// const real lordo = imponibile + imposta; -// csv.set(3, lordo); - csv.set(3, imponibile); - //csv.set(2, rmoviva.get("101@.R0")); //aliquota non ci vuole piu' -// csv.set(5, imposta); - csv.set(6, rmoviva.get("23.DATADOC")); - csv.set(7, rmoviva.get("23.NUMDOC")); - csv.set(8, last_data_pag); - - // csv.set(9, rmoviva.get(RMI_GRUPPO)); - // csv.set(10, rmoviva.get(RMI_CONTO)); - // csv.set(11, rmoviva.get(RMI_SOTTOCONTO)); - // csv.set(12, rmoviva.get(RMI_NUMREG)); - } - - } //for(move_first().. - - csv.save_as(path, fmt_text); - -#ifdef DBG - xvt_sys_goto_url(path, "open"); -#endif - - TString msg; - msg << TR("Si conferma l'esportazione definitiva dei movimenti IVA fino al "); - msg << m.get(F_ADATA); - if (yesno_box(msg)) - set_inviva(rmoviva); //mette il flag di "INVIVA" alla testata movimento -} - -void TEsporta_ps0713_app::main_loop() -{ - TEsporta_ps0713_mask m; + TEsporta_dativa_msk m; while (m.run() == K_ENTER) esporta_righe_iva(m); } int ps0713100(int argc, char* argv[]) { - TEsporta_ps0713_app app; + TEsporta_dativa_app app; app.run(argc, argv, TR("Trasferimento dati IVA")); return 0; } diff --git a/ps/ps0713100a.h b/ps/ps0713100a.h index 82ebfd504..65b2b56a0 100755 --- a/ps/ps0713100a.h +++ b/ps/ps0713100a.h @@ -1,5 +1,4 @@ //campi maschera ps0713100a - #define F_PATH 101 #define F_NAME 102 #define F_ADATA 103 diff --git a/ps/ps0713100a.uml b/ps/ps0713100a.uml index 07692564d..e6be09984 100755 --- a/ps/ps0713100a.uml +++ b/ps/ps0713100a.uml @@ -1,52 +1,60 @@ #include "ps0713100a.h" -TOOLBAR "" 0 -2 0 2 +TOOLBAR "topbar" 0 0 0 2 -BUTTON DLG_OK 10 2 -BEGIN - PROMPT -12 -11 "" -END - -BUTTON DLG_QUIT 10 2 -BEGIN - PROMPT -22 -11 "" -END +#include ENDPAGE -PAGE "Trasferimento dati IVA per ATS" -1 -1 64 10 +PAGE "Trasferimento dati IVA per ATS" -1 -1 80 10 -STRING F_PATH 255 40 +STRING DLG_PROFILE 50 BEGIN - PROMPT 2 2 "Cartella dove creare il file da esportare " - DSELECT - FLAGS "M" - CHECKTYPE REQUIRED - FIELD PATH - WARNING "Selezionare una cartella valida!" + PROMPT 9 -12 "Profilo " + PSELECT + FLAGS "H" END -STRING F_NAME 30 +GROUPBOX DLG_NULL 78 4 BEGIN - PROMPT 2 3 "Nome file generato da esportare " - FLAGS "B" + PROMPT 1 1 "@bParametri file da esportare" +END + +STRING F_PATH 255 50 +BEGIN + PROMPT 2 2 "Cartella " + DSELECT CHECKTYPE REQUIRED - FIELD NAME + FLAGS "M" + FIELD PATH +END + +STRING F_NAME 50 +BEGIN + PROMPT 2 3 "File " FLAGS "D" + CHECKTYPE NORMAL + FIELD NAME +END + +GROUPBOX DLG_NULL 78 6 +BEGIN + PROMPT 1 5 "@bParametri movimenti da esportare" END DATE F_ADATA BEGIN - PROMPT 2 5 "Esporta movimenti fino alla data " + PROMPT 2 6 "Esporta movimenti fino alla data " CHECKTYPE REQUIRED - FIELD ADATA + FIELD ADATA END -RADIOBUTTON F_JOB 20 +RADIOBUTTON F_JOB 60 BEGIN PROMPT 2 7 "Tipo record da esportare" - ITEM "1|CON id. lavoro" - ITEM "2|SENZA id. lavoro" + ITEM "1|CON id. lavoro" + ITEM "2|SENZA id. lavoro" + FLAGS "Z" END ENDPAGE diff --git a/ps/ps0713200.cpp b/ps/ps0713200.cpp index b8723dd40..a88c00b17 100755 --- a/ps/ps0713200.cpp +++ b/ps/ps0713200.cpp @@ -8,167 +8,115 @@ #include "tabutil.h" -#include "ps0713.h" #include "ps0713200a.h" + ///////////////////////////////// + //// TIMPORTA_COMM_MSK //// + ///////////////////////////////// - -/////////////////////////////////////////////////////////// -// TAutomask -/////////////////////////////////////////////////////////// - -class TImportaComm_mask : public TAutomask +//Classe TImporta_comm_msk +class TImporta_comm_msk : public TAutomask { protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); public: - TImportaComm_mask(); + TImporta_comm_msk(); }; - -TImportaComm_mask::TImportaComm_mask() :TAutomask ("ps0713200a") -{ -} -bool TImportaComm_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("*.csv"); //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; - } +//ON_FIELD_EVENT: metodo che gestisce i comportamenti dei vari campi della maschera +//(per adesso segnaposto) +bool TImporta_comm_msk::on_field_event(TOperable_field& f, TField_event e, long jolly) +{ return true; } -/////////////////////////////////////// -// TSkeleton_application -/////////////////////////////////////// -class TCommCSV : public TSkeleton_application +//metodo costruttore +TImporta_comm_msk::TImporta_comm_msk() : TAutomask("ps0713200a"){} + + ///////////////////////////////// + //// TIMPORTA_COMM_APP //// + ///////////////////////////////// + +//Classe TImporta_comm_app +class TImporta_comm_app : public TSkeleton_application { virtual bool check_autorization() const {return false;} virtual const char * extra_modules() const {return "cg";} - TImportaComm_mask* _msk; - TConfig* _configfile; + TImporta_comm_msk* _msk; public: virtual bool create(); virtual bool destroy(); virtual void main_loop(); - virtual void ini2mask(); - virtual void mask2ini(); + bool transfer(const TFilename& file); - TCommCSV() {}; + TImporta_comm_app() {}; }; -TCommCSV& app() { return (TCommCSV&) main_app(); } +TImporta_comm_app& app() { return (TImporta_comm_app&) main_app(); } -///////////////////////////////// -// inserimento commesse -///////////////////////////////// - -bool TCommCSV::transfer(const TFilename& file) +//TRASNFER: metodo che effettivamente svolge l'elaborazione di importazione +bool TImporta_comm_app::transfer(const TFilename& file) { - TLog_report log("Inserimento Commesse"); - - TToken_string rec(50,','); + TLog_report log("Importazione Commesse"); + //Instazio lo scanner con cui leggerò il file di testo + //che contiene codcms|gr|co|stco TScanner s(file); + TToken_string rec(50, ','); rec = s.line(); - - + + //Instanzio la tabella che devo riempire TTable comm("CMS"); - TProgind pi(fsize(file),"Inserimento Commesse in corso...",true,true); + TProgind pi(fsize(file), "Importazione Commesse in corso...", true, true); + //scorro tutto il file (per ogni riga devo riportare l'esito dell'importazione nel log) while (s.ok()) { if (!pi.addstatus(s.tellg())) - break; + break; - TString str = "La commessa "; - TString codtab = rec.get(0); - codtab.strip("\""); + TString codtab = rec.get(0); codtab.strip("\""); //salto le righe vuote del file if (codtab.empty()) continue; + //recupero i dati di interesse dal file + TString descr = "IDLAVORO "; descr << codtab; + //gruppo conto e sottoconto devono avere dei valori sensati + TString gr = rec.get(1); gr.strip("\""); (gr == "" || gr == "?") ? gr ="0" : gr = gr; + TString co = rec.get(2); co.strip("\""); (co == "" || co == "?") ? co ="0" : co = co; + TString sc = rec.get(3); sc.strip("\""); (sc == "" || sc == "?") ? sc ="0" : sc = gr; + comm.zero(); comm.put("CODTAB", codtab); //setto il campo CODTAB - - TString tmp = "IDLAVORO "; - tmp << codtab; - - comm.put("S0", tmp); //setto il campo descrizione (S0) - - TString gr = rec.get(1); - gr.strip("\""); - TString co = rec.get(2); - co.strip("\""); - TString sc = rec.get(3); - sc.strip("\""); - - //inserisco il gruppo, il conto e il sottoconto - //solo se esistono e/o hanno valori sensati - if (gr == "" || gr == "?") - gr = "0"; - - comm.put("I1", gr); - - if (co == "" || co == "?") - co = "0"; - - comm.put("I2", co); - - if (sc == "" || sc == "?") - sc = "0"; - - comm.put("I3", sc); + comm.put("S0", descr); //setto il campo descrizione (S0) + comm.put("I1", gr); //setto il campo gruppo (I1) + comm.put("I2", co); //setto il campo conto (I2) + comm.put("I3", sc); //setto il campo sottoconto (I3) + //salvo ciò che ho appena importato int err = comm.write(); - if (err == NOERR) + //preparo il log con tutti i risultati delle operazioni svolte + TString str = "La commessa "; + switch(err) { - str << codtab << " è stata inserita"; - log.log(0, str); - } - else - { - if (err == 224) - str << codtab << " NON è stata inserita perchè esiste già"; - else - str << codtab << " NON è stata inserita. Errore = " << err; - - log.log(2, str); + case NOERR: str << codtab << " è stata inserita"; log.log(0, str); break; + case 224: str << codtab << " NON è stata inserita perchè esiste già"; log.log(2, str); break; + default: str << codtab << " NON è stata inserita. Errore = " << err; log.log(2, str); break; } + //leggo la riga successiva rec = s.line(); - } + //stampo a video il log TReport_book buc; buc.add(log); buc.preview(); @@ -176,70 +124,38 @@ bool TCommCSV::transfer(const TFilename& file) return true; } -void TCommCSV::mask2ini() +bool TImporta_comm_app::create() { - //carica i parametri del file di configurazione - _configfile->set_paragraph("MAIN"); - for (int i = 0; i < _msk->fields() ; i++) - { - TMask_field& f = _msk->fld(i); - const TFieldref* fr = f.field(); - if (fr != NULL) - _configfile->set(fr->name(), f.get()); - } -} - -void TCommCSV::ini2mask() -{ - //carica i parametri del file di configurazione - _configfile->set_paragraph("MAIN"); - for (int i = 0; i < _msk->fields() ; i++) - { - TMask_field& f = _msk->fld(i); - const TFieldref* fr = f.field(); - if (fr != NULL) - f.set(_configfile->get(fr->name())); - } -} - -bool TCommCSV::create() -{ - _configfile = new TConfig("ps0713conf.ini"); - _msk = new TImportaComm_mask(); - - + _msk = new TImporta_comm_msk(); return TSkeleton_application::create(); } -bool TCommCSV::destroy() +bool TImporta_comm_app::destroy() { - delete _msk; - delete _configfile; + delete _msk; return TApplication::destroy(); } -void TCommCSV::main_loop() +void TImporta_comm_app::main_loop() { - KEY tasto; - ini2mask(); + KEY tasto; tasto = _msk->run(); if (tasto == K_ENTER) { - mask2ini(); - //genero il nome del file da caricare TFilename name = _msk->get(F_PATH); name.add(_msk->get(F_NAME)); + TString str; if (transfer(name)) - { - message_box(TR("Importazione documenti completata")); - } + message_box(TR("Importazione commesse completata")); + else + error_box(TR("L'importazione non è andata a buon fine")); } } int ps0713200 (int argc, char* argv[]) { - TCommCSV main_app; + TImporta_comm_app main_app; main_app.run(argc, argv, TR("Importazione Commesse")); return true; } \ No newline at end of file diff --git a/ps/ps0713200a.h b/ps/ps0713200a.h index c27a7df49..4c3a61009 100755 --- a/ps/ps0713200a.h +++ b/ps/ps0713200a.h @@ -1,6 +1,3 @@ //campi maschera ps0713200a - -#define F_CODITTA 101 -#define F_RAGSOC 102 -#define F_PATH 103 -#define F_NAME 104 +#define F_PATH 101 +#define F_NAME 102 diff --git a/ps/ps0713200a.uml b/ps/ps0713200a.uml index ff652487a..fe78748d7 100755 --- a/ps/ps0713200a.uml +++ b/ps/ps0713200a.uml @@ -1,59 +1,38 @@ #include "ps0713200a.h" -PAGE "Importazione dati commesse da file" -1 -1 78 12 +TOOLBAR "" 0 0 0 2 -GROUPBOX DLG_NULL 76 3 +#include + +ENDPAGE + +PAGE "Importazione dati commesse da file" 0 0 0 0 + +STRING DLG_PROFILE 50 BEGIN - PROMPT 2 1 "@bDitta corrente" + PROMPT 1 -1 "Profilo " + PSELECT + FLAGS "H" END -NUMBER F_CODITTA 5 +GROUPBOX DLG_NULL 78 4 BEGIN - PROMPT 3 2 "Codice " - FLAGS "FD" - USE LF_NDITTE - INPUT CODDITTA F_CODITTA - OUTPUT F_RAGSOC RAGSOC - CHECKTYPE REQUIRED + PROMPT 1 1 "@bSorgente" END -STRING F_RAGSOC 50 +STRING F_PATH 255 50 BEGIN - PROMPT 23 2 "" - FLAGS "D" -END - -GROUPBOX DLG_NULL 76 4 -BEGIN - PROMPT 2 4 "@bSorgente" -END - -STRING F_PATH 256 39 -BEGIN - PROMPT 3 5 "Cartella " + PROMPT 2 2 "Cartella " DSELECT CHECKTYPE REQUIRED FIELD ComInPath END -STRING F_NAME 18 +STRING F_NAME 255 50 BEGIN - PROMPT 3 6 "File " + PROMPT 2 3 "File " + FSELECT "*.*" FIELD ComInFile END -BUTTON DLG_ELABORA 10 2 -BEGIN - PROMPT -12 -1 "" - PICTURE BMP_ELABORA - MESSAGE EXIT,K_ENTER -END - -BUTTON DLG_QUIT 10 2 -BEGIN - PROMPT -22 -1 "" -END - -ENDPAGE - ENDMASK \ No newline at end of file diff --git a/ps/ps0713400.cpp b/ps/ps0713400.cpp index c237440c0..acc051280 100755 --- a/ps/ps0713400.cpp +++ b/ps/ps0713400.cpp @@ -1,23 +1,17 @@ +#include #include #include -#include #include -#include "ps0713.h" -#include "ps0713400a.h" - -#include "../cg/cglib01.h" -#include "../mg/anamag.h" #include "../ve/velib.h" -#include "clifo.h" -#include "doc.h" -#include "rdoc.h" +#include "ps0713400a.h" -/////////////////////////////////////////////////////////// -// TAutomask -/////////////////////////////////////////////////////////// + /////////////////////////////////// + //// TIMPORTA_FATVEN_MSK //// + /////////////////////////////////// +//Classe TImporta_fatven_msk class TImporta_fatven_msk : public TAutomask { protected: @@ -31,54 +25,30 @@ TImporta_fatven_msk::TImporta_fatven_msk() :TAutomask ("ps0713400a") { } +//ON_FIELD_EVENT: metodo che gestisce i comportamenti dei vari campi della maschera +//(per adesso segnaposto) bool TImporta_fatven_msk::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("*.csv"); //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; } - /////////////////////////////////////////////// - //// CLASSI DERIVATE PER IMPORTAZIONE DATI //// - /////////////////////////////////////////////// + /////////////////////////////////// + //// TIMPORTA_FATVEN_REC //// + /////////////////////////////////// -///////////////////////////////////////////////////////////// -// Recordset specifici per i dati da trasferire -///////////////////////////////////////////////////////////// - -class TImporta_fatven_recset : public TCSV_recordset +//Classe TImporta_fatven_rec +class TImporta_fatven_rec : public TCSV_recordset { protected: virtual TRecnotype new_rec(const char* buf = NULL); public: - TImporta_fatven_recset(const char * fileName); + TImporta_fatven_rec(const char * fileName); }; -TRecnotype TImporta_fatven_recset::new_rec(const char* buf) +//NEW_REC: metodo che crea una nuova riga del recordset, cambiando il separatore col carattere TAB +//e eliminando eventuali doppi apici agli estremi del campo +TRecnotype TImporta_fatven_rec::new_rec(const char* buf) { TToken_string str(256,'\t'); //nuovo record tab separator @@ -116,16 +86,18 @@ TRecnotype TImporta_fatven_recset::new_rec(const char* buf) return n; } - -TImporta_fatven_recset::TImporta_fatven_recset(const char * fileName) - : TCSV_recordset("CSV(,)") +//metodo contruttre +TImporta_fatven_rec::TImporta_fatven_rec(const char * fileName) + : TCSV_recordset("CSV(,)") { load_file(fileName); } -/////////////////////////////////////// -// TSkeleton_application -/////////////////////////////////////// + /////////////////////////////////// + //// TIMPORTA_FATVEN_APP //// + /////////////////////////////////// + +//Classe TImporta_fatven_app class TImporta_fatven_app : public TSkeleton_application { virtual bool check_autorization() const {return false;} @@ -135,8 +107,8 @@ class TImporta_fatven_app : public TSkeleton_application protected: - long togli_apici_numero(TImporta_fatven_recset& s, int i); - const TString& togli_apici(TImporta_fatven_recset& s, int i); + long togli_apici_numero(TImporta_fatven_rec& s, int i); + const TString& togli_apici(TImporta_fatven_rec& s, int i); bool find_clifo(long& codcf, TString& paiv, long& abi, long& cab, TString& codpag); public: @@ -148,14 +120,18 @@ public: TImporta_fatven_app() {} }; -long TImporta_fatven_app::togli_apici_numero(TImporta_fatven_recset & s, int i) +//TOGLI_APICI_NUMERO: metodo che restituisce un campo del recordset come numero +//preoccupandosi prima di eliminare eventuali doppi apici +long TImporta_fatven_app::togli_apici_numero(TImporta_fatven_rec& s, int i) { TString80 tmp = s.get(i).as_string(); tmp.strip("\""); return atol(tmp); } -const TString& TImporta_fatven_app::togli_apici(TImporta_fatven_recset & s, int i) +//TOGLI_APICI: metodo che restituisce un campo del recordset come stringa +//preoccupandosi prima di eliminare eventuali doppi apici +const TString& TImporta_fatven_app::togli_apici(TImporta_fatven_rec & s, int i) { TString& tmp = get_tmp_string(); tmp = s.get(i).as_string(); @@ -164,6 +140,8 @@ const TString& TImporta_fatven_app::togli_apici(TImporta_fatven_recset & s, int return tmp; } +//FIND_CLIFO: metodo che cerca un cliente dati codcf e paiv: se lo trova setta tutti i campi di interesse +//legati al cliente e restituisce true; in caso contrario restituisce false bool TImporta_fatven_app::find_clifo(long& codcf, TString& paiv, long& abi, long& cab, TString& codpag) { if (!paiv.blank()) @@ -183,12 +161,14 @@ bool TImporta_fatven_app::find_clifo(long& codcf, TString& paiv, long& abi, long return false; } +//TRANSFER: metodo che effettivamente fa l'elaborazione del file di input, generando i vari documenti +//pronti per essere contabilizzati bool TImporta_fatven_app::transfer(const TFilename& file) { - const TString4 codnum = "F01"; //?????????????????????????? - const TString4 tpdoc = "F01"; //?????????????????????????? + const TString4 codnum = "F01"; //Da analisi + const TString4 tpdoc = "F01"; //Da analisi - TImporta_fatven_recset s(file); + TImporta_fatven_rec s(file); TProgind pi(s.items(),"Importazione fatture in corso ...",true,true); @@ -207,7 +187,6 @@ bool TImporta_fatven_app::transfer(const TFilename& file) return true; } - for (bool ok = s.move_first(); ok; ok = s.move_next()) { if (!pi.addstatus(1)) @@ -279,7 +258,6 @@ bool TImporta_fatven_app::transfer(const TFilename& file) long cab; TString4 codpag; - if (!find_clifo(codcf, paiv, abi, cab, codpag)) { //campi cliente (da utilizzare se non esiste già) @@ -386,6 +364,7 @@ bool TImporta_fatven_app::transfer(const TFilename& file) return true; } +//CREATE: metodo che instanzia maschera e appicazione bool TImporta_fatven_app::create() { _msk = new TImporta_fatven_msk(); @@ -393,6 +372,7 @@ bool TImporta_fatven_app::create() return TSkeleton_application::create(); } +//DESTROY: metodo che rilascia maschera e applicazione bool TImporta_fatven_app::destroy() { delete _msk; diff --git a/ps/ps0713400a.h b/ps/ps0713400a.h index c7808f8a3..322be3822 100755 --- a/ps/ps0713400a.h +++ b/ps/ps0713400a.h @@ -1,6 +1,3 @@ //campi maschera ps0713400a - -#define F_CODITTA 101 -#define F_RAGSOC 102 -#define F_PATH 103 -#define F_NAME 104 +#define F_PATH 201 +#define F_NAME 202 diff --git a/ps/ps0713400a.uml b/ps/ps0713400a.uml index 0091897ca..b67616bde 100755 --- a/ps/ps0713400a.uml +++ b/ps/ps0713400a.uml @@ -1,68 +1,38 @@ #include "ps0713400a.h" -TOOLBAR "" 0 20 0 2 +TOOLBAR "topbar" 0 0 0 2 -BUTTON DLG_ELABORA 10 2 -BEGIN - PICTURE BMP_ELABORA - MESSAGE EXIT,K_ENTER - PROMPT -12 -1 "" -END +#include -BUTTON DLG_QUIT 10 2 -BEGIN - PROMPT -22 -1 "" -END +ENDPAGE + +PAGE "Inserimento fatture" -1 -1 80 10 STRING DLG_PROFILE 50 BEGIN - PROMPT 9 0 "Profilo " + PROMPT 9 -12 "Profilo " PSELECT FLAGS "H" END -ENDPAGE - -PAGE "Inserimento fatture" 0 0 0 -3 - -GROUPBOX DLG_NULL 90 3 +GROUPBOX DLG_NULL 78 4 BEGIN - PROMPT 2 1 "@bDitta corrente" + PROMPT 1 1 "@bSorgente" END -NUMBER F_CODITTA 5 +STRING F_PATH 255 50 BEGIN - PROMPT 3 2 "Codice " - FLAGS "FD" - USE LF_NDITTE - INPUT CODDITTA F_CODITTA - OUTPUT F_RAGSOC RAGSOC - CHECKTYPE REQUIRED -END - -STRING F_RAGSOC 50 -BEGIN - PROMPT 23 2 "" - FLAGS "D" -END - -GROUPBOX DLG_NULL 90 4 -BEGIN - PROMPT 2 4 "@bSorgente" -END - -STRING F_PATH 256 39 -BEGIN - PROMPT 3 5 "Cartella " + PROMPT 2 2 "Cartella " DSELECT CHECKTYPE REQUIRED FIELD ComInPath END -STRING F_NAME 18 +STRING F_NAME 255 50 BEGIN - PROMPT 3 6 "File " + PROMPT 2 3 "File " FIELD ComInFile + FSELECT "*.csv" CHECKTYPE REQUIRED END