diff --git a/src/li/lilib01.cpp b/src/li/lilib01.cpp index a3765b5fd..a35b65902 100644 --- a/src/li/lilib01.cpp +++ b/src/li/lilib01.cpp @@ -84,14 +84,12 @@ const real TLi_manager::elabPlaRes(TToken_string tipi, TToken_string stati, TDat for(int i = 0; i < din.items(); i++) { TAssoc_array tabIva = din[i].tabella_iva(true); - TString numerazione = din[i].numerazione(); - int numdoc = din[i].numero(); - int anno = din[i].anno(); - TRiepilogo_iva * totali = dynamic_cast(tabIva.get()); - - if(totali->cod_iva().codice() == codiva) + for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tabIva.get(); totali != NULL; totali = (TRiepilogo_iva *) tabIva.get()) { - resPlafond -= cache().get("%TIP", din[i].tipo().codice()).get_bool("B7") ? -totali->imp_orig() : totali->imp_orig(); + if(totali->cod_iva().codice() == codiva) + { + resPlafond -= cache().get("%TIP", din[i].tipo().codice()).get_bool("B7") ? -totali->imp_orig() : totali->imp_orig(); + } } // Nel caso il plafond trovato fosse una soluzione unica e ho già trovato dei documenti vuol dire che il plafond non è più valido @@ -120,14 +118,12 @@ const real TLi_manager::elabUtil(TToken_string tipi, TToken_string stati, TDate for(int i = 0; i < din.items(); i++) { TAssoc_array tabIva = din[i].tabella_iva(true); - TString numerazione = din[i].numerazione(); - int numdoc = din[i].numero(); - int anno = din[i].anno(); - TRiepilogo_iva * totali = dynamic_cast(tabIva.get()); - - if(totali->cod_iva().codice() == codiva) + for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tabIva.get(); totali != NULL; totali = (TRiepilogo_iva *) tabIva.get()) { - utilizzato += cache().get("%TIP", din[i].tipo().codice()).get_bool("B7") ? -totali->imp_orig() : totali->imp_orig(); + if(totali->cod_iva().codice() == codiva) + { + utilizzato += cache().get("%TIP", din[i].tipo().codice()).get_bool("B7") ? -totali->imp_orig() : totali->imp_orig(); + } } // Nel caso il plafond trovato fosse una soluzione unica e ho già trovato dei documenti vuol dire che il plafond non è più valido @@ -153,11 +149,13 @@ bool TLi_manager::testPlafond(TLista_documenti dout, TLog_report& lerr) for(int i = 0; i < dout.items(); i++) { TAssoc_array tabIva = dout[i].tabella_iva(true); - TRiepilogo_iva * totali = static_cast(tabIva.get()); - if(totali->cod_iva().codice() == codiva) + for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tabIva.get(); totali != NULL; totali = (TRiepilogo_iva *) tabIva.get()) { - resPlafond -= totali->imp_orig(); - totFatt += totali->imp_orig(); + if(totali->cod_iva().codice() == codiva) + { + resPlafond -= totali->imp_orig(); + totFatt += totali->imp_orig(); + } } } if(resPlafond < 0) diff --git a/src/li/lilib01.h b/src/li/lilib01.h index fa98175b8..c579f4173 100644 --- a/src/li/lilib01.h +++ b/src/li/lilib01.h @@ -45,6 +45,7 @@ public: // Functions void elabPlafond(); // Vado a estrapolare il plafond bool testPlafond(TLista_documenti dout, TLog_report& lerr); // Testo se con i documenti passati supero il plafond + bool checkIva(TString cod) { return cod == codiva; } // Controllo se il codice iva è uguale a quello impostato per il calcolo del plafond const real getPlaRes(); // Calcolo il rimanente del plafond const real getPlaRes(TToken_string tipi, TToken_string stati); // Calcolo il rimanente del plafond su tipi e stati documento passati const real elabPlaRes(TToken_string tipi, TToken_string stati, TDate ad = 0L); // Funzione che effettivamente effettua il calcolodalla data della dichiarazione alla data passata diff --git a/src/ve/clifor.cpp b/src/ve/clifor.cpp index 9d1c5961a..fe84ab0a4 100755 --- a/src/ve/clifor.cpp +++ b/src/ve/clifor.cpp @@ -1,308 +1,308 @@ -#include -#include - -#include "velib.h" - -#include "condv.h" -#include "../li/letint.h" -#include "../cg/cfban.h" - -TOccasionale::TOccasionale() : TRectype(LF_OCCAS) -{ } - -TOccasionale::TOccasionale(const TRectype& r) : TRectype(r) -{ } - -TOccasionale::TOccasionale(const TOccasionale& r) : TRectype(r) -{ } - -TRectype& TOccasionale::operator=(const TRectype& r) -{ - return TRectype::operator=(r); -} - -TOccasionale& TOccasionale::operator=(const TOccasionale& r) -{ - TRectype::operator=(r); - return *this; -} - -TOccasionale::~TOccasionale() -{ } - -int TCli_for::write_rewrite(TBaseisamfile& f, bool re) const -{ - int err = TMultiple_rectype::write_rewrite(f, re); - - if (err == NOERR) - { - TLocalisamfile v(LF_CFVEN); - const TRectype& v_rec = vendite(); - err = v.write(v_rec); - if (err == _isreinsert) - err = v.write(v_rec); - } - return err; -} - -TRectype& TCli_for::vendite() const -{ - const char t = tipo(); - const long c = codice(); - - if (_ven_rec.empty() || t != _ven_rec.get_char(CFV_TIPOCF) || c != _ven_rec.get_long(CFV_CODCF)) - { - TLocalisamfile v(LF_CFVEN); - v.put(CFV_TIPOCF,t); - v.put(CFV_CODCF, c); - if (v.read() == NOERR) - ((TCli_for*)this)->_ven_rec = v.curr(); - } - return (TRectype &) _ven_rec; -} - -bool TCli_for::read_lettera(const TDate& data, bool extended) -{ - if (use_lettere()) - { - if (data != _last_data || _extended != extended) - { - _letint.zero(); - TRelation r(LF_LETINT); - - TRectype to(r.curr()); - to.put(LETINT_CODCLI, codice()); - to.put(LETINT_ANNO, data.year()); - - TRectype from(to); - from.put(LETINT_ANNO, data.year() - 1); - - TCursor c(&r, "", 2, &from, &to); - const int items = c.items(); - if (items > 0) - { - TDate dal; - TDate al(31, 12, data.year()); - - for (long pos = items - 1; pos >= 0L; pos--) - { - c = pos; - - const int tipo = c.curr().get_int(LETINT_TIPOOP); - - if (tipo == 3) // Nel periodo - { - dal = c.curr().get_date(LETINT_DAL); - al = c.curr().get_date(LETINT_AL); - } - else - { - dal = c.curr().get_date(LETINT_VSDATA); - if (c.pos() < items - 1) - { - ++c; - const int tipo_next = c.curr().get_int(LETINT_TIPOOP); - if (tipo_next == 3) - al = c.curr().get_date(LETINT_DAL); - else - al = c.curr().get_date(LETINT_VSDATA); - --c; - } - } - if (dal <= data) - { - _letint = c.curr(); - break; - } - } - _lettera_found = !_letint.empty(); - if (_lettera_found && !extended) - _lettera_found = data <= al; - } - _last_data = data; - _extended = extended; - } - } - return _lettera_found; -} - -int TCli_for::read(const TRectype & rec, word op, word lockop) -{ - _ven_rec.zero(); - int err = TMultiple_rectype::read(rec, op, lockop); - _last_data = botime; - return err; -} - -int TCli_for::read(char tipo, long codice, word op, word lockop) -{ - int err = NOERR; - _ven_rec.zero(); - zero(); - if (tipo > ' ' && codice > 0L) - { - put(CLI_TIPOCF, tipo); - put(CLI_CODCF, codice); - err = TMultiple_rectype::read(op, lockop); - } - _last_data = botime; - return err; -} - -int TCli_for::remove(TBaseisamfile& f) const -{ - TLocalisamfile v(LF_CFVEN); - const int err = vendite().remove(v); - if (err != NOERR && err != _iskeynotfound) - return err; - return TMultiple_rectype::remove(f); -} - -void TCli_for::init() -{ -// _tipo = new TRecfield(*this, CLI_TIPOCF); -// _codice = new TRecfield(*this, CLI_CODCF); -// _ven_tipo = new TRecfield(_ven_rec, CFV_TIPOCF); -// _ven_codice = new TRecfield(_ven_rec, CFV_CODCF); - _use_lettere = main_app().has_module(LIAUT, CHK_DONGLE); - if (_use_lettere) - _use_lettere = ini_get_bool(CONFIG_DITTA, "ve", "USELETTERE"); -} - -const TString& TCli_for::find_listino_al(const TDate& datadoc) const -{ - const bool gest_list_catven = ini_get_bool(CONFIG_DITTA, "ve", "GESLISCV", false, 1); - const TRectype& v = vendite(); - TString4 listino = v.get(CFV_CODLIST); - - TToken_string key_condv; - key_condv = "L"; - if (gest_list_catven) - key_condv.add(v.get(CFV_CATVEN)); - - //se il cliente ha un listino specificato -> va usato (previo controllo validità) - while (listino.full()) - { - key_condv.add(listino, 4); - - const TRectype& rec_condv = cache().get(LF_CONDV, key_condv); - const TDate inizio_validita = rec_condv.get_date(CONDV_VALIN); - const TDate fine_validita = rec_condv.get_date(CONDV_VALFIN); - - // usa il listino indicato sul cliente solo se è valido per la data del documento - if (datadoc >= inizio_validita && (datadoc <= fine_validita || !fine_validita.ok())) - break; - - listino = rec_condv.get(CONDV_CODLISSUCC); - } - return get_tmp_string() = listino; -} - -void TCli_for::cli2doc(TDocumento& doc) -{ - const TRectype& v = vendite(); - - doc.put(DOC_CODVAL, get(CLI_CODVAL)); - doc.put(DOC_CODLIN, get(CLI_CODLIN)); - doc.put(DOC_CODPAG, get(CLI_CODPAG)); - - TToken_string key; - - key.add(get(CLI_TIPOCF)); - key.add(get(CLI_CODCF)); - key.add("V"); - key.add("1"); - - const TRectype& cfban = cache().get(LF_CFBAN, key); - - if (cfban.empty()) - { - doc.put(DOC_CODABIA, get(CLI_CODABI)); - doc.put(DOC_CODCABA, get(CLI_CODCAB)); - doc.put(DOC_IBAN, get(CLI_IBAN)); - } - else - { - doc.put(DOC_CODABIA, cfban.get(CFBAN_ABI)); - doc.put(DOC_CODCABA, cfban.get(CFBAN_CAB)); - doc.put(DOC_IBAN, cfban.get(CFBAN_IBAN)); - } - - // Trasforma chiave da Vostra a Nostra banca - key.add("N", 2); - const TRectype& cfbanpr = cache().get(LF_CFBAN, key); - - // Setta i campi che appartengono al file LF_CFVEN - if (cfbanpr.empty()) - { - doc.put(DOC_CODABIP, v.get(CFV_CODABIPR)); - doc.put(DOC_CODCABP, v.get(CFV_CODCABPR)); - } - else - { - doc.put(DOC_CODABIP, cfbanpr.get(CFBAN_ABI)); - doc.put(DOC_CODCABP, cfbanpr.get(CFBAN_CAB)); - doc.put(DOC_PROGBNP, cfbanpr.get(CFBAN_PROGPR)); - } - doc.put(DOC_RAGGR, v.get(CFV_RAGGDOC)); - doc.put(DOC_RAGGREFF, v.get(CFV_RAGGEFF)); - doc.put(DOC_CODINDSP, v.get(CFV_CODINDSP)); - doc.put(DOC_CODAG, v.get(CFV_CODAG)); - doc.put(DOC_CODAGVIS, v.get(CFV_CODAG1)); - doc.put(DOC_CODSPMEZZO, v.get(CFV_CODSPMEZZO)); - doc.put(DOC_CODPORTO, v.get(CFV_CODPORTO)); - doc.put(DOC_CODNOTESP1, v.get(CFV_CODNOTESP1)); - doc.put(DOC_CODNOTESP2, v.get(CFV_CODNOTESP2)); - doc.put(DOC_CODNOTE, v.get(CFV_CODNOTE)); - doc.put(DOC_CODVETT1, v.get(CFV_CODVETT1)); - doc.put(DOC_CODVETT2, v.get(CFV_CODVETT2)); - doc.put(DOC_CODVETT3, v.get(CFV_CODVETT3)); - doc.put(DOC_PERCSPINC, v.get(CFV_PERCSPINC)); - doc.put(DOC_ADDBOLLI, v.get(CFV_ADDBOLLI)); - doc.put(DOC_CATVEN, v.get(CFV_CATVEN)); - +#include +#include + +#include "velib.h" + +#include "condv.h" +#include "../li/letint.h" +#include "../cg/cfban.h" + +TOccasionale::TOccasionale() : TRectype(LF_OCCAS) +{ } + +TOccasionale::TOccasionale(const TRectype& r) : TRectype(r) +{ } + +TOccasionale::TOccasionale(const TOccasionale& r) : TRectype(r) +{ } + +TRectype& TOccasionale::operator=(const TRectype& r) +{ + return TRectype::operator=(r); +} + +TOccasionale& TOccasionale::operator=(const TOccasionale& r) +{ + TRectype::operator=(r); + return *this; +} + +TOccasionale::~TOccasionale() +{ } + +int TCli_for::write_rewrite(TBaseisamfile& f, bool re) const +{ + int err = TMultiple_rectype::write_rewrite(f, re); + + if (err == NOERR) + { + TLocalisamfile v(LF_CFVEN); + const TRectype& v_rec = vendite(); + err = v.write(v_rec); + if (err == _isreinsert) + err = v.write(v_rec); + } + return err; +} + +TRectype& TCli_for::vendite() const +{ + const char t = tipo(); + const long c = codice(); + + if (_ven_rec.empty() || t != _ven_rec.get_char(CFV_TIPOCF) || c != _ven_rec.get_long(CFV_CODCF)) + { + TLocalisamfile v(LF_CFVEN); + v.put(CFV_TIPOCF,t); + v.put(CFV_CODCF, c); + if (v.read() == NOERR) + ((TCli_for*)this)->_ven_rec = v.curr(); + } + return (TRectype &) _ven_rec; +} + +bool TCli_for::read_lettera(const TDate& data, bool extended) +{ + if (use_lettere()) + { + if (data != _last_data || _extended != extended) + { + _letint.zero(); + TRelation r(LF_LETINT); + + TRectype to(r.curr()); + to.put(LETINT_CODCLI, codice()); + to.put(LETINT_ANNO, data.year()); + + TRectype from(to); + from.put(LETINT_ANNO, data.year() - 1); + + TCursor c(&r, "", 2, &from, &to); + const int items = c.items(); + if (items > 0) + { + TDate dal; + TDate al(31, 12, data.year()); + + for (long pos = items - 1; pos >= 0L; pos--) + { + c = pos; + + const int tipo = c.curr().get_int(LETINT_TIPOOP); + + if (tipo == 3) // Nel periodo + { + dal = c.curr().get_date(LETINT_DAL); + al = c.curr().get_date(LETINT_AL); + } + else + { + dal = c.curr().get_date(LETINT_VSDATA); + if (c.pos() < items - 1) + { + ++c; + const int tipo_next = c.curr().get_int(LETINT_TIPOOP); + if (tipo_next == 3) + al = c.curr().get_date(LETINT_DAL); + else + al = c.curr().get_date(LETINT_VSDATA); + --c; + } + } + if (dal <= data) + { + _letint = c.curr(); + break; + } + } + _lettera_found = !_letint.empty(); + if (_lettera_found && !extended) + _lettera_found = data <= al; + } + _last_data = data; + _extended = extended; + } + } + return _lettera_found; +} + +int TCli_for::read(const TRectype & rec, word op, word lockop) +{ + _ven_rec.zero(); + int err = TMultiple_rectype::read(rec, op, lockop); + _last_data = botime; + return err; +} + +int TCli_for::read(char tipo, long codice, word op, word lockop) +{ + int err = NOERR; + _ven_rec.zero(); + zero(); + if (tipo > ' ' && codice > 0L) + { + put(CLI_TIPOCF, tipo); + put(CLI_CODCF, codice); + err = TMultiple_rectype::read(op, lockop); + } + _last_data = botime; + return err; +} + +int TCli_for::remove(TBaseisamfile& f) const +{ + TLocalisamfile v(LF_CFVEN); + const int err = vendite().remove(v); + if (err != NOERR && err != _iskeynotfound) + return err; + return TMultiple_rectype::remove(f); +} + +void TCli_for::init() +{ +// _tipo = new TRecfield(*this, CLI_TIPOCF); +// _codice = new TRecfield(*this, CLI_CODCF); +// _ven_tipo = new TRecfield(_ven_rec, CFV_TIPOCF); +// _ven_codice = new TRecfield(_ven_rec, CFV_CODCF); + _use_lettere = main_app().has_module(LIAUT, CHK_DONGLE); + if (_use_lettere) + _use_lettere = ini_get_bool(CONFIG_DITTA, "ve", "USELETTERE"); +} + +const TString& TCli_for::find_listino_al(const TDate& datadoc) const +{ + const bool gest_list_catven = ini_get_bool(CONFIG_DITTA, "ve", "GESLISCV", false, 1); + const TRectype& v = vendite(); + TString4 listino = v.get(CFV_CODLIST); + + TToken_string key_condv; + key_condv = "L"; + if (gest_list_catven) + key_condv.add(v.get(CFV_CATVEN)); + + //se il cliente ha un listino specificato -> va usato (previo controllo validità) + while (listino.full()) + { + key_condv.add(listino, 4); + + const TRectype& rec_condv = cache().get(LF_CONDV, key_condv); + const TDate inizio_validita = rec_condv.get_date(CONDV_VALIN); + const TDate fine_validita = rec_condv.get_date(CONDV_VALFIN); + + // usa il listino indicato sul cliente solo se è valido per la data del documento + if (datadoc >= inizio_validita && (datadoc <= fine_validita || !fine_validita.ok())) + break; + + listino = rec_condv.get(CONDV_CODLISSUCC); + } + return get_tmp_string() = listino; +} + +void TCli_for::cli2doc(TDocumento& doc) +{ + const TRectype& v = vendite(); + + doc.put(DOC_CODVAL, get(CLI_CODVAL)); + doc.put(DOC_CODLIN, get(CLI_CODLIN)); + doc.put(DOC_CODPAG, get(CLI_CODPAG)); + + TToken_string key; + + key.add(get(CLI_TIPOCF)); + key.add(get(CLI_CODCF)); + key.add("V"); + key.add("1"); + + const TRectype& cfban = cache().get(LF_CFBAN, key); + + if (cfban.empty()) + { + doc.put(DOC_CODABIA, get(CLI_CODABI)); + doc.put(DOC_CODCABA, get(CLI_CODCAB)); + doc.put(DOC_IBAN, get(CLI_IBAN)); + } + else + { + doc.put(DOC_CODABIA, cfban.get(CFBAN_ABI)); + doc.put(DOC_CODCABA, cfban.get(CFBAN_CAB)); + doc.put(DOC_IBAN, cfban.get(CFBAN_IBAN)); + } + + // Trasforma chiave da Vostra a Nostra banca + key.add("N", 2); + const TRectype& cfbanpr = cache().get(LF_CFBAN, key); + + // Setta i campi che appartengono al file LF_CFVEN + if (cfbanpr.empty()) + { + doc.put(DOC_CODABIP, v.get(CFV_CODABIPR)); + doc.put(DOC_CODCABP, v.get(CFV_CODCABPR)); + } + else + { + doc.put(DOC_CODABIP, cfbanpr.get(CFBAN_ABI)); + doc.put(DOC_CODCABP, cfbanpr.get(CFBAN_CAB)); + doc.put(DOC_PROGBNP, cfbanpr.get(CFBAN_PROGPR)); + } + doc.put(DOC_RAGGR, v.get(CFV_RAGGDOC)); + doc.put(DOC_RAGGREFF, v.get(CFV_RAGGEFF)); + doc.put(DOC_CODINDSP, v.get(CFV_CODINDSP)); + doc.put(DOC_CODAG, v.get(CFV_CODAG)); + doc.put(DOC_CODAGVIS, v.get(CFV_CODAG1)); + doc.put(DOC_CODSPMEZZO, v.get(CFV_CODSPMEZZO)); + doc.put(DOC_CODPORTO, v.get(CFV_CODPORTO)); + doc.put(DOC_CODNOTESP1, v.get(CFV_CODNOTESP1)); + doc.put(DOC_CODNOTESP2, v.get(CFV_CODNOTESP2)); + doc.put(DOC_CODNOTE, v.get(CFV_CODNOTE)); + doc.put(DOC_CODVETT1, v.get(CFV_CODVETT1)); + doc.put(DOC_CODVETT2, v.get(CFV_CODVETT2)); + doc.put(DOC_CODVETT3, v.get(CFV_CODVETT3)); + doc.put(DOC_PERCSPINC, v.get(CFV_PERCSPINC)); + doc.put(DOC_ADDBOLLI, v.get(CFV_ADDBOLLI)); + doc.put(DOC_CATVEN, v.get(CFV_CATVEN)); + const int alleg = get_int(CLI_ALLEG); - const bool split_payment = doc.get_date(DOC_DATADOC).year() >= 2015 && get_bool(CLI_SPLITPAY); - - doc.put(DOC_LIQDIFF, !split_payment && alleg == 7 && ini_get_bool(CONFIG_DITTA, "cg", "GesLiqDiff") ? "X" : ""); - - //listino: deve essere attiva la gestione listini nella ditta - const bool gest_listini = ini_get_bool(CONFIG_DITTA, "ve", "GES", false, 1); - if (gest_listini) - { - const TDate datadoc = doc.get_date(DOC_DATADOC); - const TString& listino = find_listino_al(datadoc); - doc.put(DOC_CODLIST, listino); - } - - doc.put(DOC_ZONA, v.get(CFV_CODZONA)); - doc.put(DOC_RAGGR, v.get(CFV_RAGGDOC)); - - //aggiungere gestione spese e bolli??? -} - - -TCli_for::TCli_for(char tipo, long codice) : TMultiple_rectype( LF_CLIFO ), _ven_rec(LF_CFVEN), - _letint(LF_LETINT), _use_lettere(false), _lettera_found(false), _extended(false) -{ - init(); - add_file(LF_INDSP, IND_CODIND); - if (tipo > ' ' && codice > 0L) - read(tipo, codice); -} - -TCli_for::TCli_for(const TRectype & rec) : TMultiple_rectype(rec), _ven_rec(LF_CFVEN), - _letint(LF_LETINT), _use_lettere(false), _lettera_found(false), _extended(false) -{ - init(); - add_file(LF_INDSP, IND_CODIND); - read(rec); -} - -TCli_for::TCli_for(const TCli_for & c) : TMultiple_rectype(c), _ven_rec(c._ven_rec), - _letint(LF_LETINT), _use_lettere(false), _lettera_found(false), _extended(false) -{ init(); } - -TCli_for::~TCli_for() -{ } - + const bool split_payment = doc.get_date(DOC_DATADOC).year() >= 2015 && get_bool(CLI_SPLITPAY); + + doc.put(DOC_LIQDIFF, !split_payment && alleg == 7 && ini_get_bool(CONFIG_DITTA, "cg", "GesLiqDiff") ? "X" : ""); + + //listino: deve essere attiva la gestione listini nella ditta + const bool gest_listini = ini_get_bool(CONFIG_DITTA, "ve", "GES", false, 1); + if (gest_listini) + { + const TDate datadoc = doc.get_date(DOC_DATADOC); + const TString& listino = find_listino_al(datadoc); + doc.put(DOC_CODLIST, listino); + } + + doc.put(DOC_ZONA, v.get(CFV_CODZONA)); + doc.put(DOC_RAGGR, v.get(CFV_RAGGDOC)); + + //aggiungere gestione spese e bolli??? +} + + +TCli_for::TCli_for(char tipo, long codice) : TMultiple_rectype( LF_CLIFO ), _ven_rec(LF_CFVEN), + _letint(LF_LETINT), _use_lettere(false), _lettera_found(false), _extended(false) +{ + init(); + add_file(LF_INDSP, IND_CODIND); + if (tipo > ' ' && codice > 0L) + read(tipo, codice); +} + +TCli_for::TCli_for(const TRectype & rec) : TMultiple_rectype(rec), _ven_rec(LF_CFVEN), + _letint(LF_LETINT), _use_lettere(false), _lettera_found(false), _extended(false) +{ + init(); + add_file(LF_INDSP, IND_CODIND); + read(rec); +} + +TCli_for::TCli_for(const TCli_for & c) : TMultiple_rectype(c), _ven_rec(c._ven_rec), + _letint(LF_LETINT), _use_lettere(false), _lettera_found(false), _extended(false) +{ init(); } + +TCli_for::~TCli_for() +{ } + diff --git a/src/ve/ve0100.cpp b/src/ve/ve0100.cpp index 182019702..e352ce2ff 100755 --- a/src/ve/ve0100.cpp +++ b/src/ve/ve0100.cpp @@ -1271,8 +1271,16 @@ int TMotore_application::checkPlafondAvaibility(TDocumento d) { TLi_manager plafond(d.tipocf(), d.codcf(), TDate(TODAY).year()); TAssoc_array tabIva = d.tabella_iva(true); - TRiepilogo_iva * totali = static_cast(tabIva.get()); - real diff = plafond.getPlaRes() - (cache().get("%TIP", d.tipo().codice()).get_bool("B7") ? -totali->imp_orig() : totali->imp_orig()); + + real diff(ZERO); + for (TRiepilogo_iva * totali = (TRiepilogo_iva *) tabIva.get(); totali != NULL; totali = (TRiepilogo_iva *) tabIva.get()) + { + if(plafond.checkIva(totali->cod_iva().codice())) // Se l'iva del documento è diversa non mi interessa + { + diff = plafond.getPlaRes() - (cache().get("%TIP", d.tipo().codice()).get_bool("B7") ? -totali->imp_orig() : totali->imp_orig()); + break; + } + } if(diff >= 0) return NOERR; else diff --git a/src/ve/velib05.cpp b/src/ve/velib05.cpp index 81af71eed..655a7a536 100755 --- a/src/ve/velib05.cpp +++ b/src/ve/velib05.cpp @@ -356,7 +356,7 @@ void TDocumentoEsteso::set_riga_tic() } bool TDocumentoEsteso::is_split_payment() const -{ +{/* const long numregcg = get_long(DOC_NUMREG); if (numregcg > 0) { @@ -364,7 +364,7 @@ bool TDocumentoEsteso::is_split_payment() const if (!mov.empty()) return ::is_split_payment(mov); } - + */ bool yes = get_int(DOC_ANNO) >= 2015 && clifor().get_bool(CLI_SPLITPAY) && (is_fattura() || is_nota_credito()) && !imposta().is_zero() && ritenute().is_zero(); if (yes) @@ -372,6 +372,17 @@ bool TDocumentoEsteso::is_split_payment() const const TRectype& causale = cache().get(LF_CAUSALI, tipo().causale()); const int rsi = causale.get_int(CAU_REGSPIVA); yes = rsi != 13 && rsi != 50 && rsi != 51; // No reverse charge + if(yes && physical_rows() > 0) + { + TAssoc_array& table = ((TDocumento*)this)->tabella_iva(); + + for (TRiepilogo_iva * ri = (TRiepilogo_iva *) table.get(); ri != NULL && yes; + ri = (TRiepilogo_iva *) table.get()) + { + TString ivaPA = cache().get("%IVA", ri->cod_iva().codice()).get("S12"); + yes = ivaPA != "N6" && ivaPA != "N5"; + } + } } return yes; }