From 5dc73ee370a50cca23ae40d1d68a9dc41dddfa34 Mon Sep 17 00:00:00 2001 From: Alessandro Bonazzi Date: Sat, 17 Oct 2020 00:25:24 +0200 Subject: [PATCH] Patch level : 12.0 1002 Files correlati : vetbspp.msk ve0.exe ve1.exe ve5,exe ve6,exe vetabcom.txt vetbtib.msk Commento : 1) Spostati i campi per il calcolo ritenute sulle spese su di una riga. 2) Autoevasione degli ordini. 3) Tolte le spesse di incasso dalla formula IMPCAS. Interno 1) Verificare se soggetto a ritenuta e soggetto al calcolo ritenuta sono la stessa cosa. 2) Nella tabella dei tipi documento c'e un flag di autoevasione e il codice di una elaborazione di evasione ordini. 3) Da correggere presso i clienti che eventualmente la usino. 4) Verificare anche il raggruppamento righe in fatturazione bolle --- src/ve/velib04a.cpp | 49 +++---- src/ve/velib04b.cpp | 325 +++++++++++++++++++++++--------------------- src/ve/velib04d.cpp | 18 ++- 3 files changed, 198 insertions(+), 194 deletions(-) diff --git a/src/ve/velib04a.cpp b/src/ve/velib04a.cpp index f99d2ad01..60b6da616 100755 --- a/src/ve/velib04a.cpp +++ b/src/ve/velib04a.cpp @@ -6,18 +6,15 @@ void TFatturazione_bolle::init() { - // Attenzione: uso il TConfig perchè con varibili del tipo AGGFLD(FATPROV) la ini_get_string() NON funziona bene - TConfig ini(CONFIG_DITTA, "ve"); - - const char* cod = get("CODTAB"); + const TString& cod = get("CODTAB"); TString80 name; - name.format("AGGFLD(%s)", cod); - _lista_campi = ini.get(name); + name.format("AGGFLD(%s)", (const char *)cod); + _lista_campi = ini_get_string(CONFIG_DITTA, "ve", name); - name.format("ROWSORT(%s)", cod); - _rowsort = ini.get(name); - _impminfat = real(ini.get("IMPMINFAT")); + name.format("ROWSORT(%s)", (const char *)cod); + _rowsort = ini_get_string(CONFIG_DITTA, "ve", name); + _impminfat = ini_get_real(CONFIG_DITTA, "ve", "IMPMINFAT"); } TFatturazione_bolle::TFatturazione_bolle(const char* cod) @@ -147,10 +144,8 @@ void TFatturazione_bolle::elabora_riga(TRiga_documento& r, TDocumento& doc_out, { FOR_EACH_PHYSICAL_RDOC(doc_out, nr, rout) // ... cerca una riga compatibile { - if (rout->sola_descrizione()) // Ignora le righe descrittive - continue; - - if (rin.raggruppabile(*rout, campi_riga)) // Se esiste una riga compatibile ... + if (!rout->sola_descrizione() && // Ignora le righe descrittive + rin.raggruppabile(*rout, campi_riga)) // Se esiste una riga compatibile ... { add_rows(*rout, rin); r.set_final_rdoc_key(*rout); @@ -203,10 +198,12 @@ bool TFatturazione_bolle::raggruppa(TDocumento& doc_in, TDocumento& doc_out) if (usa_dcons) { - bool da_elaborare = FALSE; + bool da_elaborare = false; + FOR_EACH_PHYSICAL_RDOC(doc_in, r, rin) { TDate data_cons = rin->get_date(RDOC_DATACONS); + if (!data_cons.ok()) data_cons = dcons; da_elaborare = ddoc >= data_cons && !rin->get_bool(RDOC_RIGAEVASA); @@ -443,28 +440,26 @@ bool TFatturazione_bolle::elabora(TLista_documenti& doc_in, TLista_documenti& do if (!rdoc->is_descrizione() && rdoc->get(RDOC_CODIVA).blank()) { if (codesiva.full()) - { -/* if (rdoc->imponibile().is_zero()) - rdoc->zero(RDOC_CODIVA); - else */ rdoc->put(RDOC_CODIVA, codesiva); - } else { if (rdoc->is_articolo()) { const TArticolo_giacenza& art = rdoc->articolo(); const TString& codiva = art.get(ANAMAG_CODIVA); - if (codiva.full()) + + if (codiva.full()) rdoc->put(RDOC_CODIVA, codiva); - } else - if ((rdoc->is_spese() || rdoc->is_prestazione())) - { - const TSpesa_prest& s = rdoc->spesa(); - const TString& codiva = s.cod_iva(); - if (codiva.full()) - rdoc->put(RDOC_CODIVA, codiva); } + else + if ((rdoc->is_spese() || rdoc->is_prestazione())) + { + const TSpesa_prest& s = rdoc->spesa(); + const TString& codiva = s.cod_iva(); + + if (codiva.full()) + rdoc->put(RDOC_CODIVA, codiva); + } } } } diff --git a/src/ve/velib04b.cpp b/src/ve/velib04b.cpp index ed970faef..96a5139d6 100755 --- a/src/ve/velib04b.cpp +++ b/src/ve/velib04b.cpp @@ -2842,8 +2842,8 @@ error_type TContabilizzazione::write_scadenze(TDocumento& doc, bool recontabiliz if (anticipo.abs() < td.abs()) { const real imposte_effettive = is_split_payment(head) ? ZERO : totimposte.get_num(); - TGeneric_distrib d(anticipo.get_num(), ndec); + d.add(totimponibili.get_num()); d.add(imposte_effettive); d.add(totspese.get_num()); @@ -2861,6 +2861,7 @@ error_type TContabilizzazione::write_scadenze(TDocumento& doc, bool recontabiliz TCurrency_documento val3(pagtotspese); val3.change_to_firm_val(); TCurrency val1(totdoc); TCurrency_documento ant(anticipo.get_num(), doc); + ant.change_to_firm_val(); val1 -= ant + val2 + val3; if (test_swap()) @@ -3031,6 +3032,7 @@ error_type TContabilizzazione::write_scadenze(TDocumento& doc, bool recontabiliz real importo_rata_val = in_valuta ? pag.importo_rata(r-1, true) : importo_rata_lit; real delta_lit = importo_rata_lit - imprata; real delta_val = in_valuta ? importo_rata_val - imprataval : ZERO; + // Controlla se l'importo della nota di credito supera quello della fattura if (delta_lit > ZERO || delta_val > ZERO) { @@ -3589,10 +3591,12 @@ error_type TContabilizzazione::write_pagamento_anticipo(TDocumento& doc) const TString8 numpart = mov.get(MOV_NUMDOC); // Nessun controllo se prot.iva o numdoc xche' tanto proviene dal mov precedentemente scritto TPartita* partita = new TPartita(_co_cliente,anno,numpart); + partita->allinea(); // reperire il numero della riga partita (nrigp) appena aggiunta int nriga = (int) TPartita::UNASSIGNED; + // Cerca la riga di partita con riferimento alla fattura che si sta pagando for (int r = partita->last(); r > 0; r = partita->pred(r)) { @@ -3648,6 +3652,7 @@ error_type TContabilizzazione::write_pagamento_anticipo(TDocumento& doc) const TString4 val(doc.get(DOC_CODVAL)); const TDate datacam(doc.get_date(DOC_DATACAMBIO)); const bool valuta = val.not_empty(); + riga_part.put(PART_IMPORTO,imp.get_num()); riga_part.put(PART_IMPORTOVAL,impval.get_num()); riga_part.put(PART_IMPTOTDOC,imp.get_num()); @@ -3837,8 +3842,8 @@ error_type TContabilizzazione::write_anticipo(TDocumento& doc, const TMovimentoP error_type TContabilizzazione::write_intra(TDocumento& doc) { const TRectype& rm = _movimento->curr(); - const TDate data_reg = rm.get(MOV_DATAREG); + /* Ora so fare le rettifiche! 29-09-2015 // Controllo la liceita' della scrittura del movimento intra const TDate data_intra = rm.get(MOV_DATACOMPI); @@ -3899,175 +3904,181 @@ error_type TContabilizzazione::write_intra(TDocumento& doc) TGeneric_distrib d(spese, doc.decimals()); TGeneric_distrib dlit(speselit, TCurrency::get_firm_dec()); - FOR_EACH_PHYSICAL_RDOC(doc, i, prdoc0) if (prdoc0->is_articolo()) - { - const TRiga_documento& rr = doc[i]; - TCurrency_documento imp_val(rr.TVariable_rectype::exist("VALINTRA") ? rr.get_real("VALINTRA") : rr.importo(true, false), doc); - TCurrency_documento imp(imp_val); imp.change_to_firm_val(); + FOR_EACH_PHYSICAL_RDOC(doc, i, rr) + if (rr->is_articolo()) + { + + TCurrency_documento imp_val(rr->TVariable_rectype::exist("VALINTRA") ? rr->get_real("VALINTRA") : rr->importo(true, false), doc); + TCurrency_documento imp(imp_val); imp.change_to_firm_val(); - d.add(imp_val.get_num()); - dlit.add(imp.get_num()); - } + d.add(imp_val.get_num()); + dlit.add(imp.get_num()); + } - FOR_EACH_PHYSICAL_RDOC(doc, i, prdoc) if (prdoc->is_articolo()) - { - const TRiga_documento& rr = doc[i]; - const TRectype& rec_anamag = cchh.get(LF_ANAMAG, rr.get(RDOC_CODARTMAG)); - const TString16 nomenclatura = rec_anamag.get(ANAMAG_CLASSDOG); + FOR_EACH_PHYSICAL_RDOC(doc, i1, rr1) + if (rr1->is_articolo()) + { + const TRectype& rec_anamag = cchh.get(LF_ANAMAG, rr1->get(RDOC_CODARTMAG)); + const TString16 nomenclatura = rec_anamag.get(ANAMAG_CLASSDOG); + const TRectype& rec_noc = cchh.get("%NOC", nomenclatura); + const char noc_s4 = rec_noc.get_char("S4"); // Obbligatorietà unità di misura supplementare + bool ums_obbl = noc_s4 > ' '; - const TRectype& rec_noc = cchh.get("%NOC", nomenclatura); - const char noc_s4 = rec_noc.get_char("S4"); // Obbligatorietà unità di misura supplementare - bool ums_obbl = noc_s4 > ' '; - if (ums_obbl && noc_s4 != 'E') - ums_obbl = is_cessione ? noc_s4=='C' : noc_s4=='A'; + if (ums_obbl && noc_s4 != 'E') + ums_obbl = is_cessione ? noc_s4=='C' : noc_s4=='A'; - const TString4 ums = rec_noc.get("S5"); - const real massanun = rec_anamag.get_real(ANAMAG_MASSANUN); // Massa KG - const real unsuppun = rec_anamag.get_real(ANAMAG_UNSUPPUN); // Massa UMS - const TString16 paeseorig = is_cessione ? EMPTY_STRING : rec_anamag.get(ANAMAG_PAESE); // Campo solo per Acquisti - TString4 provincia; - if (is_cessione) - provincia = rec_anamag.get(ANAMAG_PROV); - else - { - const TString8 codmag = rr.get(RDOC_CODMAG); - TString4 com = cchh.get("MAG", codmag, "S5"); // Comune del magazzino - if (com.empty()) - { - const long codditta = prefix().get_codditta(); - TString8 codulc; codulc.format("%ld|1", codditta); - const TRectype& unloc = cchh.get(LF_UNLOC, codulc); - com = unloc.get(ULC_COMULC); - } - key.format(" |%s", (const char*)com); - provincia = cchh.get(LF_COMUNI, key, COM_PROVCOM); - } + const TString4 ums = rec_noc.get("S5"); + const real massanun = rec_anamag.get_real(ANAMAG_MASSANUN); // Massa KG + const real unsuppun = rec_anamag.get_real(ANAMAG_UNSUPPUN); // Massa UMS + const TString16 paeseorig = is_cessione ? EMPTY_STRING : rec_anamag.get(ANAMAG_PAESE); // Campo solo per Acquisti + TString4 provincia; - if (nomenclatura.blank() || (ums_obbl && unsuppun.is_zero() && ums.blank()) || massanun.is_zero() || provincia.blank()) - { - TString msg; - msg << "--- L'articolo " << rec_anamag.get(ANAMAG_CODART) << " non riporta tutti i dati necessari per il movimento intracomunitario."; - _viswin->add_line(msg); - msg = " Si consiglia di verificare i seguenti valori sull'anagrafica:"; - _viswin->add_line(msg); - msg = " "; - if (nomenclatura.blank()) msg << "nomenclatura combinata; "; - if (ums_obbl && unsuppun.is_zero()) msg << "unità di misura supplementare; "; - if (massanun.is_zero()) msg << "massa netta unitaria; "; - if (provincia.blank()) msg << (is_cessione ? "provincia d'origine; " : "provincia di destinazione; "); - msg.rtrim(2); msg << '.'; // Sostituisce l'ultimo punto e virgola con un punto - _viswin->add_line(msg); - } - - key.cut(0); - key.add(nomenclatura); - key.add(paeseorig); - key.add(provincia); - TRectype* rc = (TRectype*)righe.objptr(key); // Riga intra - if (rc == NULL) - { - rc = new TRectype(LF_RINTRA); - rc->put("NUMREG", numreg); - rc->put("NUMRIG", numrig++); - rc->put("NATURA", natura); - rc->put("CONSEGNA", consegna); - rc->put("TRASPORTO", trasporto); - - rc->put("NOMENCL", nomenclatura); - rc->put("UMS", ums); - rc->put("PAESE", paese); - rc->put("PAESEORIG", paeseorig); - rc->put("PROV", provincia); - righe.add(key, rc); - } - const real qta = rr.get_real(RDOC_QTA); - TCurrency_documento imp_val(rr.TVariable_rectype::exist("VALINTRA") ? rr.get_real("VALINTRA") : rr.importo(true, false), doc); - TCurrency_documento imp(imp_val); imp.change_to_firm_val(); - - imp_val += d.get(); - imp += dlit.get(); - imp_val.change_value(codvali, cambioi); - - real ammeuro = rc->get_real("AMMLIRE"); - real ammvaluta = rc->get_real("AMMVALUTA"); - real massakg = rc->get_real("MASSAKG"); - real massaums = rc->get_real("MASSAUMS"); - real valstat = rc->get_real("VALSTAT"); - - if (nota_credito) - { - ammeuro -= imp.get_num(); - ammvaluta -= is_val ? imp_val.get_num() : ZERO; - } - else - { - ammeuro += imp.get_num(); - ammvaluta += is_val ? imp_val.get_num() : ZERO; - } - - real peso = qta * massanun; // peso netto - if (peso.is_zero()) - peso = rr.get_real(RDOC_PNETTO); - massakg += peso; - - if (ums_obbl || ums.full() || !unsuppun.is_zero()) - { - real qta_ums; - // Campo Fisico o Formulato? TAuto_variable_rectype::exist("MASSAUMS") è sempre TRUE! - if (rr.TVariable_rectype::exist("MASSAUMS")) - qta_ums = rr.get_real("MASSAUMS"); + if (is_cessione) + provincia = rec_anamag.get(ANAMAG_PROV); else { - // Cerco di convertire l'unità di misura su rdoc nella unità di misura supplementare - const TString4 um = rr.get(RDOC_UMQTA); - if (ums.full() && um.full()) + const TString8 codmag = rr1->get(RDOC_CODMAG); + TString4 com = cchh.get("MAG", codmag, "S5"); // Comune del magazzino + + if (com.empty()) { - if (ums == um) // Se coincidono, ho già finito ... - qta_ums = qta; - else + const long codditta = prefix().get_codditta(); + TString8 codulc; codulc.format("%ld|1", codditta); + const TRectype& unloc = cchh.get(LF_UNLOC, codulc); + com = unloc.get(ULC_COMULC); + } + key.format(" |%s", (const char*)com); + provincia = cchh.get(LF_COMUNI, key, COM_PROVCOM); + } + + if (nomenclatura.blank() || (ums_obbl && unsuppun.is_zero() && ums.blank()) || massanun.is_zero() || provincia.blank()) + { + TString msg; + msg << "--- L'articolo " << rec_anamag.get(ANAMAG_CODART) << " non riporta tutti i dati necessari per il movimento intracomunitario."; + _viswin->add_line(msg); + msg = " Si consiglia di verificare i seguenti valori sull'anagrafica:"; + _viswin->add_line(msg); + msg = " "; + if (nomenclatura.blank()) msg << "nomenclatura combinata; "; + if (ums_obbl && unsuppun.is_zero()) msg << "unità di misura supplementare; "; + if (massanun.is_zero()) msg << "massa netta unitaria; "; + if (provincia.blank()) msg << (is_cessione ? "provincia d'origine; " : "provincia di destinazione; "); + msg.rtrim(2); msg << '.'; // Sostituisce l'ultimo punto e virgola con un punto + _viswin->add_line(msg); + } + + key.cut(0); + key.add(nomenclatura); + key.add(paeseorig); + key.add(provincia); + + TRectype* rc = (TRectype*)righe.objptr(key); // Riga intra + + if (rc == nullptr) + { + rc = new TRectype(LF_RINTRA); + rc->put("NUMREG", numreg); + rc->put("NUMRIG", numrig++); + rc->put("NATURA", natura); + rc->put("CONSEGNA", consegna); + rc->put("TRASPORTO", trasporto); + + rc->put("NOMENCL", nomenclatura); + rc->put("UMS", ums); + rc->put("PAESE", paese); + rc->put("PAESEORIG", paeseorig); + rc->put("PROV", provincia); + righe.add(key, rc); + } + const real qta = rr1->get_real(RDOC_QTA); + TCurrency_documento imp_val(rr1->TVariable_rectype::exist("VALINTRA") ? rr1->get_real("VALINTRA") : rr1->importo(true, false), doc); + TCurrency_documento imp(imp_val); imp.change_to_firm_val(); + + imp_val += d.get(); + imp += dlit.get(); + imp_val.change_value(codvali, cambioi); + + real ammeuro = rc->get_real("AMMLIRE"); + real ammvaluta = rc->get_real("AMMVALUTA"); + real massakg = rc->get_real("MASSAKG"); + real massaums = rc->get_real("MASSAUMS"); + real valstat = rc->get_real("VALSTAT"); + + if (nota_credito) + { + ammeuro -= imp.get_num(); + ammvaluta -= is_val ? imp_val.get_num() : ZERO; + } + else + { + ammeuro += imp.get_num(); + ammvaluta += is_val ? imp_val.get_num() : ZERO; + } + + real peso = qta * massanun; // peso netto + if (peso.is_zero()) + peso = rr1->get_real(RDOC_PNETTO); + massakg += peso; + + if (ums_obbl || ums.full() || !unsuppun.is_zero()) + { + real qta_ums; + // Campo Fisico o Formulato? TAuto_variable_rectype::exist("MASSAUMS") è sempre TRUE! + if (rr1->TVariable_rectype::exist("MASSAUMS")) + qta_ums = rr1->get_real("MASSAUMS"); + else + { + // Cerco di convertire l'unità di misura su rdoc nella unità di misura supplementare + const TString4 um = rr1->get(RDOC_UMQTA); + + if (ums.full() && um.full()) { - TArticolo& art = rr.articolo(); - qta_ums = art.convert_to_um(qta, ums, um); // ... altrimenti converto + if (ums == um) // Se coincidono, ho già finito ... + qta_ums = qta; + else + { + TArticolo& art = rr1->articolo(); + qta_ums = art.convert_to_um(qta, ums, um); // ... altrimenti converto + } } } + if (qta_ums.is_zero()) // Se non sono riuscito in altro modo ... + qta_ums = qta * unsuppun; // ... calcolo peso/qta in unità di misura supplementare + + massaums += qta_ums; } - if (qta_ums.is_zero()) // Se non sono riuscito in altro modo ... - qta_ums = qta * unsuppun; // ... calcolo peso/qta in unità di misura supplementare - - massaums += qta_ums; - } - real vs; // Valore statistico - // Campo Fisico o Formulato? TAuto_variable_rectype::exist("VALSTAT") è sempre TRUE! - if (rr.TVariable_rectype::exist("VALSTAT")) - { - TCurrency_documento vstat(rr.get_real("VALSTAT"), doc); - vstat.change_to_firm_val(); - vs = vstat.get_num(); + real vs; // Valore statistico + // Campo Fisico o Formulato? TAuto_variable_rectype::exist("VALSTAT") è sempre TRUE! + if (rr1->TVariable_rectype::exist("VALSTAT")) + { + TCurrency_documento vstat(rr1->get_real("VALSTAT"), doc); + vstat.change_to_firm_val(); + vs = vstat.get_num(); + } + else + { + vs = qta * rec_anamag.get_real(ANAMAG_VALSTATUN); + if (vs.is_zero()) + vs = imp.get_num(); + } + if (nota_credito) + valstat -= vs; + else + valstat += vs; + + rc->put("AMMLIRE", ammeuro); + rc->put("AMMVALUTA", ammvaluta); + rc->put("MASSAKG", massakg); + rc->put("MASSAUMS", massaums); + rc->put("VALSTAT", valstat); + + // Il totale delle righe in Euro! + if (nota_credito) + totale_righe -= imp.get_num(); + else + totale_righe += imp.get_num(); } - else - { - vs = qta * rec_anamag.get_real(ANAMAG_VALSTATUN); - if (vs.is_zero()) - vs = imp.get_num(); - } - if (nota_credito) - valstat -= vs; - else - valstat += vs; - - rc->put("AMMLIRE", ammeuro); - rc->put("AMMVALUTA", ammvaluta); - rc->put("MASSAKG", massakg); - rc->put("MASSAUMS", massaums); - rc->put("VALSTAT", valstat); - - // Il totale delle righe in Euro! - if (nota_credito) - totale_righe -= imp.get_num(); - else - totale_righe += imp.get_num(); - } if (_error == no_error) diff --git a/src/ve/velib04d.cpp b/src/ve/velib04d.cpp index bbd4fa5f8..1d048d631 100755 --- a/src/ve/velib04d.cpp +++ b/src/ve/velib04d.cpp @@ -862,20 +862,18 @@ bool TConsegna_ordini::elabora(TLista_documenti& doc_in, TLista_documenti& doc_o if (nettifica()) { - FOR_EACH_PHYSICAL_RDOC_BACK(indoc, i, rdoc) - { - TRiga_documento& inrec = *rdoc; - if (inrec.is_evasa()) + FOR_EACH_PHYSICAL_RDOC_BACK(indoc, i, inrec) + if (inrec->is_evasa()) indoc.destroy_row(i, true); else { - const real evaso = inrec.qtaevasa(); - const char* fq = inrec.field_qta(); - const char* fqe = inrec.field_qtaevasa(); - inrec.add(fq, -evaso); // nuovo modo di incrementare - inrec.zero(fqe); + const real evaso = inrec->qtaevasa(); + const char* fq = inrec->field_qta(); + const char* fqe = inrec->field_qtaevasa(); + + inrec->add(fq, -evaso); // nuovo modo di incrementare + inrec->zero(fqe); } - } } if (indoc.is_evaso()) indoc.stato(stato_finale_doc_iniziale()[0]);