diff --git a/cg/cg7200.cpp b/cg/cg7200.cpp index 86c4adacf..25eec2faa 100755 --- a/cg/cg7200.cpp +++ b/cg/cg7200.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -13,6 +14,9 @@ #include "cg7.h" #include "cg7200a.h" #include "cglib01.h" +#include "cg2101.h" +#include "cg2103.h" +#include "cgsaldac.h" #include #include @@ -39,19 +43,25 @@ TInvioP_file::TInvioP_file(const TString& file_name) { } +////////////////////////////////////////////////////// +// MASCHERA +////////////////////////////////////////////////////// + class TInvioP_mask : public TAutomask { protected: bool on_field_event(TOperable_field& o, TField_event e, long jolly); -public: + void config_loader(TSheet_field& sf, const char* paragrafo); + void config_setter(TSheet_field& sf, const char* paragrafo); - TInvioP_mask(); - +public: + TInvioP_mask(); virtual ~TInvioP_mask(){}; }; TInvioP_mask::TInvioP_mask() :TAutomask ("cg7200a") { + config_loader(sfield(F_PDCC), "Pdcc"); } bool TInvioP_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) @@ -66,12 +76,61 @@ bool TInvioP_mask::on_field_event(TOperable_field& o, TField_event e, long jolly disable(F_CODDITTA); } break; + case DLG_SAVEREC: + if (e == fe_button) + { + config_setter(sfield(F_PDCC), "Pdcc"); + } + break; default: break; } - return TRUE; + return true; } +void TInvioP_mask::config_loader(TSheet_field& sf, const char* paragrafo) +{ + //carica file configurazione conti; attenzione!!!il file di configurazione in questione e' il + //medesimo del programma per la stampa del pagato in contabilita' analitica, visto che i due + //programmi necessitano degli stessi conti + TFilename configname = "ca3600.ini"; + configname.custom_path(); + TConfig configfile(configname, paragrafo); + + TString_array conti; + + int n = configfile.list_variables(conti, false, paragrafo, true); + FOR_EACH_ARRAY_ROW(conti, i, row) + { + sf.row(-1) = configfile.get(*row); //carica la riga del .ini senza il contatore + sf.check_row(i); + } +} + +void TInvioP_mask::config_setter(TSheet_field& sf, const char* paragrafo) +{ + TFilename configname = "ca3600.ini"; + configname.custom_path(); + TConfig configfile(configname, paragrafo); + + configfile.remove_all(); //svuota il paragrafo sul .ini prima di ricompilarlo (se non si facesse + //non si riuscirebbero ad ammazzare le righe sul .ini + FOR_EACH_SHEET_ROW (sf, i, row) + { + TToken_string conto(""); + conto.add(row->get(0)); + conto.add(row->get(1)); + conto.add(row->get(2)); + conto.add(row->get(3)); + + configfile.set("conto", conto, NULL, true, i); + } +} + +////////////////////////////////////////////// +// APPLICAZIONE +////////////////////////////////////////////// + class TInvioP : public TSkeleton_application { TCursor* _cur; @@ -80,6 +139,7 @@ class TInvioP : public TSkeleton_application long _nregcosto, _nregpag; real _importo; TConfig* _configfile; + TAssoc_array _fiscali,_sociali; //array che contengono i conti protected: virtual bool create(void); @@ -92,6 +152,14 @@ protected: bool i_proforma_clifor(char tipocf = 'C'); bool i_proforma_conti(); + real totale_documento(const TRectype& mov) const; + void lettura_conti(TAssoc_array& assoc, const char tipoconto); + bool cerca_conto(const TBill& bill, const TAssoc_array& assoc, const char tipoconto) const; + bool cerca_fiscali(const TBill& bill) const; + bool cerca_sociali(const TBill& bill) const; + bool test_swap(TCausale& caus, bool ritsoc) const; + real calcola_pagamento(TRectype& curpag_rec); + public: const real get_importo() {return _importo;}; const char* get_nregcosto() {return format("%d", _nregcosto);}; @@ -399,29 +467,202 @@ bool TInvioP::i_proforma_righe(TCursor& cur, TInvioP_file* trasfilerighe) return true; } +// Calcola il totale del documento tenendo conto del segno della prima riga e di quella delle +// ritenute sociali sulla causale +real TInvioP::totale_documento(const TRectype& mov) const +{ + real tot = mov.get_real(MOV_TOTDOC); // Legge totale + const real ritfis = mov.get_real(MOV_RITFIS); + tot += ritfis; // Somma ritenute fiscali + + const real ritsoc = mov.get_real(MOV_RITSOC); + + if (!ritsoc.is_zero()) + { + TCausale caus(mov.get(MOV_CODCAUS)); + const bool swapt = test_swap(caus, false); // Totale invertito ? + const bool swaps = test_swap(caus, true); // Ritenute sociali invertite ? + if (swapt ^ swaps) // Somma ritenute sociali con segno + tot -= ritsoc; + else + tot += ritsoc; + } + + return tot; +} + +// Controlla sulla causale se il segno del totale documento (ritsoc=FALSE) +// o quello delle ritenute sociali (ritsoc=TRUE) e' invertito rispetto al normale +bool TInvioP::test_swap(TCausale& caus, bool ritsoc) const +{ + const char sez = ritsoc ? caus.sezione_ritsoc() : caus.sezione_clifo(); + const bool s = (caus.iva() == iva_vendite) ^ (sez == 'D'); + return s; +} + +bool TInvioP::cerca_conto(const TBill& bill, const TAssoc_array& assoc, const char tipoconto) const +{ + TToken_string key(15); + key.add(tipoconto); //il primo char della tokenstring e' il tipoconto (Fiscale o Sociale) + + key.add(bill.gruppo()); + if (assoc.is_key(key)) + return true; + + key.add(bill.conto()); + if (assoc.is_key(key)) + return true; + + key.add(bill.sottoconto()); + if (assoc.is_key(key)) + return true; + + return false; +} + +bool TInvioP::cerca_fiscali(const TBill& bill) const +{ + return cerca_conto(bill, _fiscali, 'F'); +} + +bool TInvioP::cerca_sociali(const TBill& bill) const +{ + return cerca_conto(bill, _sociali, 'S'); +} + +void TInvioP::lettura_conti(TAssoc_array& assoc, const char tipoconto) +{ + TConfig conti("ca3600.ini","Pdcc"); //paragrafo da scandire nell'ini + TAssoc_array& vars = conti.list_variables(); + + FOR_EACH_ASSOC_STRING(vars, h, k, val) //riempie l'assoc con i soli valori del paragrafo dell'ini + { + if (*val == tipoconto) //mette nell'assocarray solo i conti corrispondenti al tipoconto passato + assoc.add(val); + } +} + +real TInvioP::calcola_pagamento(TRectype& curpag_rec) +{ + real totpagato = curpag_rec.get_real(PAGSCA_IMPORTO) + curpag_rec.get_real(PAGSCA_RITENUTE); + + //deve costruirsi la riga di partita che riguarda il documento di origine + //per prima cosa crea tale riga a partire dal pagamento, che ha una chiave lunghissima... + TToken_string key_part; + key_part.add(curpag_rec.get(PAGSCA_TIPOC)); + key_part.add(curpag_rec.get(PAGSCA_GRUPPO)); + key_part.add(curpag_rec.get(PAGSCA_CONTO)); + key_part.add(curpag_rec.get(PAGSCA_SOTTOCONTO)); + key_part.add(curpag_rec.get(PAGSCA_ANNO)); + key_part.add(curpag_rec.get(PAGSCA_NUMPART)); + key_part.add(curpag_rec.get(PAGSCA_NRIGA)); + //..ecco il record delle partite.. + const TRectype& rec_partite = cache().get(LF_PARTITE, key_part); + //..da cui prende nreg + const long nreg = rec_partite.get_long(PART_NREG); + //se nreg esiste... + if (nreg != 0) + { + TMovimentoPN pn; + pn.curr().put(MOV_NUMREG, nreg); + if (pn.read() == NOERR) + { + const TRectype& movfat = pn.curr(); + + //dichiariamo una serie di simpatici real utilizzati in seguito + real totdoc,imponibile,imposta; + + //Le ritenute sociali invece vanno testate con la test_swap.. + const real ritsoc = curpag_rec.get_real(PAGSCA_RITSOC); + + if (!ritsoc.is_zero()) + { + const TRectype& mov = pn.curr(); + TCausale caus(mov.get(MOV_CODCAUS)); + const bool swapt = test_swap(caus, false); // Totale invertito ? + const bool swaps = test_swap(caus, true); // Ritenute sociali invertite ? + if (swapt ^ swaps) // Somma ritenute sociali con segno + totpagato -= ritsoc; + else + totpagato += ritsoc; + } + //Movimenti CON SALDACONTO + //se movimento IVA.. + if (pn.iva_items() > 0) + { + for (int i = 0; i < pn.iva_items(); i++) + { + const TRectype& rmoviva = pn.iva(i); + const TBill conto(rmoviva); + + if (conto.indicatore_bilancio() != 5) + { + const real importo = rmoviva.get_real(RMI_IMPONIBILE); + real iva = rmoviva.get_real(RMI_IMPOSTA); + + imponibile += importo; + imposta += iva; + } + } + totdoc = totale_documento(pn.curr()); //tot doc con ritenute fiscali + ritenute sociali (da stampare) + } //if pn.iva_items().. + else + { + for (int i = 0; i < pn.cg_items(); i++) + { + const TRectype& rmov = pn.cg(i); + const TBill conto(rmov); + + TImporto importo(rmov.get_char(RMV_SEZIONE), rmov.get_real(RMV_IMPORTO)); + importo.normalize('D'); + + if (conto.tipo() > ' ') + totdoc -= importo.valore(); + else + if (cerca_fiscali(conto) || cerca_sociali(conto)) + totdoc -= importo.valore(); //valore da stampare nella colonna Tot.fattura con ritenute + else + if (rmov.get_char(RMV_ROWTYPE) != 'T' && conto.indicatore_bilancio() != 5) + { + imponibile += importo.valore(); + totdoc += importo.valore(); + } + } + } //end di else pn.iva_items()... + + real percentuale = imponibile / totdoc; + totpagato *= percentuale; + } + } + return totpagato; +} + bool TInvioP::i_proforma_pagamenti() { TInvioP_file* trasfilepag = apri_file("pagament"); - TRectype da(LF_MOVANA); - TRectype a(LF_MOVANA); - da.put(MOVANA_DATACOMP, _dataini); + TRectype da(LF_MOV); + TRectype a(LF_MOV); + da.put(MOV_DATACOMP, _dataini); a.put(MOV_DATACOMP, _datafin); - TRelation rel(LF_MOVANA); - rel.add(LF_MOV, "NUMREG==NUMREGCG"); + TRelation rel(LF_MOV); rel.add(LF_CAUSALI, "CODCAUS==CODCAUS"); - TCursor cur(&rel, "NUMREGCG!=0", 2, &da, &a); + TCursor cur(&rel, "", 2, &da, &a); const long cur_items = cur.items(); if (cur_items != 0) - { + { + //se ha almeno un movimento carica lo sheet dei conti che gli servira' in seguito nel calcolo.. + //..delle ritenute + lettura_conti(_fiscali, 'F'); + lettura_conti(_sociali, 'S'); + cur.freeze(); TRectype& cur_rec = cur.curr(); for (cur = 0; cur.pos() < cur_items; ++(cur)) { - -// const char tipomov = cur_rec.get(MOVANA_TIPOMOV)[0]; -// if (tipomov == '3' || tipomov == '2' || tipomov == '6') -// { + const char tipomov = cur_rec.get(MOV_TIPOMOV)[0]; + if (tipomov == '3' || tipomov == '2' || tipomov == '6') + { TRelation relpart(LF_PARTITE); TRectype da(LF_PARTITE); da.put(PART_NREG, cur.curr().get(MOV_NUMREG)); @@ -460,7 +701,8 @@ bool TInvioP::i_proforma_pagamenti() real importo = ZERO; bool is_key = pagame.is_key(indice); real& somma = is_key ? (real&) pagame[indice] : importo; - somma += curpag_rec.get_real(PAGSCA_IMPORTO); + const real importo_pagato = calcola_pagamento(curpag_rec); //aggiunta nuova!!! + somma += importo_pagato; if (!is_key) pagame.add(indice, somma); } @@ -488,9 +730,7 @@ bool TInvioP::i_proforma_pagamenti() }//if curpag_items.. }//for curpart =.. }//if curpart_items.. - -// }//if tipomov.. - + }//if tipomov.. }//for cur =.. }//if cur_items.. diff --git a/cg/cg7200a.h b/cg/cg7200a.h index dbc9d777a..4f35bf6a5 100755 --- a/cg/cg7200a.h +++ b/cg/cg7200a.h @@ -1,15 +1,23 @@ // invio dati ad altra procedura (Proforma) -#define F_CODDITTA 101 -#define F_RAGSOC 102 -#define F_MOVIMENTI 103 -#define F_CLIENTI 104 -#define F_FORNITORI 105 -#define F_CONTI 106 -#define F_PAGAMENTI 107 -#define F_TIPOINVIO 108 -#define F_DESTINAZIONE 109 -#define F_DATAINI 110 -#define F_DATAFIN 111 -#define F_RIPRISTINA 112 -#define F_DATARIPRISTINO 113 +#define F_CODDITTA 301 +#define F_RAGSOC 302 +#define F_MOVIMENTI 303 +#define F_CLIENTI 304 +#define F_FORNITORI 305 +#define F_CONTI 306 +#define F_PAGAMENTI 307 +#define F_TIPOINVIO 308 +#define F_DESTINAZIONE 309 +#define F_DATAINI 310 +#define F_DATAFIN 311 +#define F_RIPRISTINA 312 +#define F_DATARIPRISTINO 313 + +#define F_PDCC 315 + +#define S_TIPO 101 +#define S_GRUPPO 102 +#define S_CONTO 103 +#define S_SOTTOCONTO 104 +#define S_DESCRIZIONE 105 diff --git a/cg/cg7200a.uml b/cg/cg7200a.uml index 5c47bec1a..b9473c42c 100755 --- a/cg/cg7200a.uml +++ b/cg/cg7200a.uml @@ -1,5 +1,19 @@ #include "cg7200a.h" +TOOLBAR "" 0 -2 0 2 + +BUTTON DLG_OK 10 2 +BEGIN + PROMPT -12 -11 "" +END + +BUTTON DLG_QUIT 10 2 +BEGIN + PROMPT -22 -11 "" +END + +ENDPAGE + PAGE "Invio dati contabilita'" -1 -1 78 20 GROUPBOX DLG_NULL 76 3 @@ -88,14 +102,121 @@ BEGIN FLAGS "HD" END -BUTTON DLG_OK 9 2 +ENDPAGE + +PAGE "Conti" -1 -1 78 20 + +TEXT -1 BEGIN - PROMPT -12 -1 "" + PROMPT 1 1 "@bPiano dei conti contabile" END -BUTTON DLG_QUIT 9 2 +SPREADSHEET F_PDCC 78 -4 BEGIN - PROMPT -22 -1 "" + PROMPT 1 2 "Pdcc" + ITEM "Tipo" + ITEM "Gruppo" + ITEM "Conto" + ITEM "Sottoconto" + ITEM "Descrizione@50" +END + +BUTTON DLG_SAVEREC 12 2 +BEGIN + PROMPT -11 19 "" + PICTURE BMP_SAVEREC + PICTURE BMP_SAVERECDN +END + +ENDPAGE + +ENDMASK + +//-------------------------------------------------------------------- +// Riga dello sheet dei conti +//-------------------------------------------------------------------- + +PAGE "Riga Piano dei conti contabile" -1 -1 78 8 + +LIST S_TIPO 1 18 +BEGIN + PROMPT 1 1 "Tipo " + ITEM "C|Costo" + ITEM "P|Pagamento" + ITEM "F|Ritenute fiscali" + ITEM "S|Ritenute sociali" +END + +NUMBER S_GRUPPO 3 +BEGIN + PROMPT 1 2 "Gruppo " + USE LF_PCON KEY 1 SELECT CONTO="" + INPUT GRUPPO S_GRUPPO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Descrizione@50" DESCR + OUTPUT S_GRUPPO GRUPPO + CHECKTYPE REQUIRED +END + +NUMBER S_CONTO 3 +BEGIN + PROMPT 1 3 "Conto " + USE LF_PCON KEY 1 SELECT ((CONTO!="")&&(SOTTOCONTO="")) + COPY INPUT S_GRUPPO + INPUT CONTO S_CONTO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Descrizione@50" DESCR + OUTPUT S_GRUPPO GRUPPO + OUTPUT S_CONTO CONTO + CHECKTYPE NORMAL + VALIDATE REQIF_FUNC 1 S_SOTTOCONTO +END + +NUMBER S_SOTTOCONTO 6 +BEGIN + PROMPT 1 4 "Sottoconto " + USE LF_PCON KEY 1 SELECT SOTTOCONTO!="" + COPY INPUT S_CONTO + INPUT SOTTOCONTO S_SOTTOCONTO + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto" SOTTOCONTO + DISPLAY "Descrizione@50" DESCR + OUTPUT S_SOTTOCONTO SOTTOCONTO + OUTPUT S_CONTO CONTO + OUTPUT S_GRUPPO GRUPPO + OUTPUT S_DESCRIZIONE DESCR + CHECKTYPE NORMAL +END + +STRING S_DESCRIZIONE 50 +BEGIN + PROMPT 1 5 "Descrizione " + KEY 2 + USE LF_PCON KEY 2 + INPUT DESCR S_DESCRIZIONE + DISPLAY "Descrizione@50" DESCR + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto" SOTTOCONTO + COPY OUTPUT S_SOTTOCONTO + CHECKTYPE REQUIRED +END + +BUTTON DLG_OK 10 2 +BEGIN + PROMPT -13 -1 "" +END + +BUTTON DLG_DELREC 10 2 +BEGIN + PROMPT -23 -1 "" +END + +BUTTON DLG_CANCEL 10 2 +BEGIN + PROMPT -33 -1 "" END ENDPAGE diff --git a/cg/proforma.ini b/cg/proforma.ini index 8c0d1ca50..7d6d7fd4d 100755 --- a/cg/proforma.ini +++ b/cg/proforma.ini @@ -157,22 +157,22 @@ LENGTH(2) = 1 FIELD(2) = 108->SEZIONE NAME(3) = CODICE MASTRO -TYPE(3) = STRINGA +TYPE(3) = NUMERO POSITION(3) = 12 LENGTH(3) = 5 FIELD(3) = 108->CODCONTO[1,3] NAME(4) = CODICE CONTO -TYPE(4) = STRINGA +TYPE(4) = NUMERO POSITION(4) = 17 LENGTH(4) = 5 FIELD(4) = 108->CODCONTO[4,6] NAME(5) = CODICE SOTTOCONTO -TYPE(5) = STRINGA +TYPE(5) = NUMERO POSITION(5) = 22 LENGTH(5) = 5 -FIELD(5) = 108->CODCONTO[7,12] +FIELD(5) = 108->CODCONTO[8,12] NAME(6) = FLAG CLIFOR TYPE(6) = STRINGA @@ -181,7 +181,7 @@ LENGTH(6) = 1 //MESSAGE(6) = _TIPOCF NAME(7) = CODICE CLIFOR -TYPE(7) = STRINGA +TYPE(7) = NUMERO POSITION(7) = 28 LENGTH(7) = 10 FIELD(7) = 108->CODCONTO[7,12] @@ -238,19 +238,19 @@ LENGTH(1) = 1 MESSAGE(1) = _FISSO,!S NAME(3) = CODICE MASTRO -TYPE(3) = STRINGA +TYPE(3) = NUMERO POSITION(3) = 12 LENGTH(3) = 5 FIELD(3) = 25->GRUPPO NAME(4) = CODICE CONTO -TYPE(4) = STRINGA +TYPE(4) = NUMERO POSITION(4) = 17 LENGTH(4) = 5 FIELD(4) = 25->CONTO NAME(5) = CODICE SOTTOCONTO -TYPE(5) = STRINGA +TYPE(5) = NUMERO POSITION(5) = 22 LENGTH(5) = 5 FIELD(5) = 25->SOTTOCONTO @@ -262,7 +262,7 @@ LENGTH(6) = 1 FIELD(6) = 25->TIPOC NAME(7) = CODICE CLIFOR -TYPE(7) = STRINGA +TYPE(7) = NUMERO POSITION(7) = 28 LENGTH(7) = 10 FIELD(7) = 25->SOTTOCONTO