diff --git a/crpa/crpa.ini b/crpa/crpa.ini index 133a172ac..00a7711ab 100755 --- a/crpa/crpa.ini +++ b/crpa/crpa.ini @@ -101,3 +101,10 @@ EUR=EU [Descrizioni] F01=Percentuale,QTAGG1|Giorni,QTAGG2 + +[Ditte] +1=S +2=S + +[Cespiti] +CodNum=CES \ No newline at end of file diff --git a/crpa/crpa0.cpp b/crpa/crpa0.cpp index d3fb77e77..4667d26f4 100755 --- a/crpa/crpa0.cpp +++ b/crpa/crpa0.cpp @@ -62,6 +62,7 @@ protected: bool get_fdaric_dadoc(const TDocumento& doc) const; long get_protiva(const TDocumento& doc) const; bool search_costo_ricavo(TBill& conto, const TRiga_documento& r); + bool search_conto_cespite(TBill& conto, const TRiga_documento& r); bool test_swap() const; bool test_swap_conto(const int gr, const int co, const char sezione) const; @@ -802,10 +803,45 @@ int TIni2Sql::build_nriga(const TString& paragrafo) return nriga; } +bool TIni2Sql::search_conto_cespite(TBill& conto, const TRiga_documento& r) +{ + int gr,co; + long so; + int codcat; + + TString16 idcesp = r.get(RDOC_CODART); + if (idcesp.empty()) + codcat = r.doc().get_int(DOC_NDOC); + else + { + const TRectype& cespi = cache().get(LF_CESPI, idcesp); + codcat = cespi.get_int("CODCAT"); + } + TEsercizi_contabili esercizi; + int esc = esercizi.date2esc(r.doc().get_date(DOC_DATADOC)); + TString16 str; + str.format("%04d", esc); + const TRectype& curr_ccb = cache().get("CCB", str); + TString80 codtab = curr_ccb.get("CODTAB"); + const char* codgruppo = codtab.sub(5,6); + const char* codspecie = codtab.sub(7,10); + TToken_string key; + key.add(codgruppo); + key.add(codspecie); + key.add(codcat); + const TRectype& collces = cache().get(LF_COLLCES, key); + gr = collces.get_int("GRUPPOQNO"); + co = collces.get_int("CONTOQNO"); + so = collces.get_int("SOTTOCQNO"); + conto.set(gr,co,so); + return (conto.ok()); +} // scrive il file che contiene il comando insert completo dei record da inserire void TIni2Sql::write_sqlinsert() -{ +{ + bool is_cespite = false; + TString80 numcesp = _configfile->get("CodNum", "Cespiti"); TString_array lp; if (_inputfile->list_paragraphs(lp) > 0) { @@ -837,6 +873,7 @@ void TIni2Sql::write_sqlinsert() if (_doc == NULL) { const TString16 codnum = _inputfile->get("CODNUM"); + is_cespite = (codnum == numcesp); const char provv = _inputfile->get("PROVV")[0]; const int anno = atoi(_inputfile->get("ANNO")); const long numdoc = atol(_inputfile->get("NDOC")); @@ -866,42 +903,10 @@ void TIni2Sql::write_sqlinsert() if (nriga <= _doc->rows()) { _rigadoc = new TRiga_documento((*_doc)[nriga]); - /* - TString8 gruppoa = ""; - TString8 gruppov = ""; - - TString80 codart; - if (tiporigatab == 'M') - codart = _inputfile->get(RDOC_CODARTMAG); - if (codart.blank()) - codart = _inputfile->get(RDOC_CODART); - - switch (tiporigatab) - { - case 'P': - { - const TRectype& prs = cache().get("PRS", codart); - gruppov = prs.get("I0"); - gruppoa = prs.get("I3"); - } - break; - case 'S': - { - const TRectype& spp = cache().get("SPP", codart); - gruppov = spp.get("I0"); - gruppoa = spp.get("I3"); - } - break; - default: - { - const TRectype& anamag = cache().get(LF_ANAMAG, codart); - gruppoa = anamag.get("GRUPPOA"); - gruppov = anamag.get("GRUPPOV"); - } - break; - } - */ - ok = search_costo_ricavo(_conto, (*_rigadoc)); + if (is_cespite) + ok = search_conto_cespite(_conto, (*_rigadoc)); + else + ok = search_costo_ricavo(_conto, (*_rigadoc)); if (ok) { TString8 gruppos; @@ -909,7 +914,6 @@ void TIni2Sql::write_sqlinsert() gruppos.format("%d", _conto.gruppo()); ok = (_configfile->get_bool(gruppos, "Gruppi")); } - //ok = (_configfile->get_bool(gruppoa, "Gruppi")) || (_configfile->get_bool(gruppov, "Gruppi")); } } }