Patch level : 12.0 938
Files correlati : fp0.exe Commento : Corretta contabilizzazione per importi a 0: problema scadenzario
This commit is contained in:
parent
6ab12f151d
commit
e25a49daa7
@ -663,117 +663,125 @@ int TPassive_mask::prepara_contab() const
|
|||||||
|
|
||||||
clean_ini(F1_INIREGCONT);
|
clean_ini(F1_INIREGCONT);
|
||||||
|
|
||||||
FOR_EACH_SHEET_ROW(sf, n, row) {
|
FOR_EACH_SHEET_ROW(sf, n, row)
|
||||||
if (row->starts_with("X"))
|
{
|
||||||
{
|
if (row->starts_with("X"))
|
||||||
TString prokeys = row->get(sf.cid2index(S_PROKEY));
|
{
|
||||||
TToken_string keys(prokeys, ';');
|
TString prokeys = row->get(sf.cid2index(S_PROKEY));
|
||||||
const TString codcaus(get_codcaus(row->get(cid2index(S_TIPODOCSDI)), row->get(cid2index(S_FORNITORE))));
|
TToken_string keys(prokeys, ';');
|
||||||
|
const TString codcaus(get_codcaus(row->get(cid2index(S_TIPODOCSDI)), row->get(cid2index(S_FORNITORE))));
|
||||||
|
|
||||||
TString tipodoc(row->get(sf.cid2index(S_TIPODOCSDI)));
|
TString tipodoc(row->get(sf.cid2index(S_TIPODOCSDI)));
|
||||||
if(tipodoc == "TD01" && !check_causale(codcaus, "FA", true))
|
if (tipodoc == "TD01" && !check_causale(codcaus, "FA", true))
|
||||||
if(!yesno_box("Attenzione, per un documento di tipo TD01 e' stata selezionata \nuna causale diversa da Fattura d'Acquisto.\nProcedere lo stesso con l'esportazione?"))
|
if (!yesno_box("Attenzione, per un documento di tipo TD01 e' stata selezionata \nuna causale diversa da Fattura d'Acquisto.\nProcedere lo stesso con l'esportazione?"))
|
||||||
continue;
|
continue;
|
||||||
if(tipodoc == "TD04" && !check_causale(codcaus, "NC", true))
|
if (tipodoc == "TD04" && !check_causale(codcaus, "NC", true))
|
||||||
if(!yesno_box("Attenzione, per un documento di tipo TD04 e' stata selezionata \nuna causale diversa da Nota Credito di Acquisto.\nProcedere lo stesso con l'esportazione?"))
|
if (!yesno_box("Attenzione, per un documento di tipo TD04 e' stata selezionata \nuna causale diversa da Nota Credito di Acquisto.\nProcedere lo stesso con l'esportazione?"))
|
||||||
continue;
|
continue;
|
||||||
n_sel++;
|
n_sel++;
|
||||||
|
|
||||||
vector<iva>& riva = get_righe_iva(keys);
|
vector<iva>& riva = get_righe_iva(keys);
|
||||||
TString num; num.format("%04d", n);
|
TString num; num.format("%04d", n);
|
||||||
TFilename newf_ini;
|
TFilename newf_ini;
|
||||||
#ifndef DBG
|
#ifndef DBG
|
||||||
newf_ini.tempdir() << "\\" << F1_INIREGCONT << num << ".ini";
|
newf_ini.tempdir() << "\\" << F1_INIREGCONT << num << ".ini";
|
||||||
#else
|
#else
|
||||||
newf_ini << F1_INIREGCONT << num << ".ini";
|
newf_ini << F1_INIREGCONT << num << ".ini";
|
||||||
#endif
|
#endif
|
||||||
TConfig contab_ini(newf_ini, "Transaction");
|
TConfig contab_ini(newf_ini, "Transaction");
|
||||||
contab_ini.set("Action", "INSERT");
|
contab_ini.set("Action", "INSERT");
|
||||||
|
|
||||||
// Esporto dati di testata
|
// Esporto dati di testata
|
||||||
contab_ini.set_paragraph(LF_MOV); // [23]
|
contab_ini.set_paragraph(LF_MOV); // [23]
|
||||||
contab_ini.set("CODCAUS", codcaus);
|
contab_ini.set("CODCAUS", codcaus);
|
||||||
contab_ini.set("CODCF", row->get(sf.cid2index(S_FORNITORE)));
|
contab_ini.set("CODCF", row->get(sf.cid2index(S_FORNITORE)));
|
||||||
TDate datareg;
|
TDate datareg;
|
||||||
if (get_bool(F_USEDATARIC))
|
if (get_bool(F_USEDATARIC))
|
||||||
datareg = TDate(row->get(sf.cid2index(S_DATARIC)));
|
datareg = TDate(row->get(sf.cid2index(S_DATARIC)));
|
||||||
else
|
else
|
||||||
datareg = !get(F_DATAREGDIF).empty() ? TDate(get(F_DATAREGDIF)) : TDate(TODAY);
|
datareg = !get(F_DATAREGDIF).empty() ? TDate(get(F_DATAREGDIF)) : TDate(TODAY);
|
||||||
contab_ini.set("DATAREG", datareg);
|
contab_ini.set("DATAREG", datareg);
|
||||||
contab_ini.set("DATACOMP", datareg);
|
contab_ini.set("DATACOMP", datareg);
|
||||||
contab_ini.set("DATADOC", row->get(sf.cid2index(S_DATADOC)));
|
contab_ini.set("DATADOC", row->get(sf.cid2index(S_DATADOC)));
|
||||||
contab_ini.set("NUMDOCEXT", row->get(sf.cid2index(S_NDOC)));
|
contab_ini.set("NUMDOCEXT", row->get(sf.cid2index(S_NDOC)));
|
||||||
contab_ini.set("NUMDOC", TString(row->get(sf.cid2index(S_NDOC))).right(7));
|
contab_ini.set("NUMDOC", TString(row->get(sf.cid2index(S_NDOC))).right(7));
|
||||||
TString totdoc = row->get(sf.cid2index(S_TOTDOC));
|
TString totdoc = row->get(sf.cid2index(S_TOTDOC));
|
||||||
if(totdoc.empty())
|
if (totdoc.empty())
|
||||||
{
|
|
||||||
real imp = calcola_importo(riva);
|
|
||||||
totdoc.cut(0) << imp;
|
|
||||||
}
|
|
||||||
real rit = fppro_db().set_keys(keys).get_ritenute();
|
|
||||||
if (rit != ZERO)
|
|
||||||
{
|
|
||||||
contab_ini.set("TOTDOC", (abs(real(totdoc)) - rit).string());
|
|
||||||
contab_ini.set("RITFIS", rit.string());
|
|
||||||
}
|
|
||||||
else if (is_doc_split(riva)) // Documento con split
|
|
||||||
{
|
|
||||||
contab_ini.set("TOTDOC", get_tot_imp_riva(riva));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
contab_ini.set("TOTDOC", abs(real(totdoc)).string());
|
|
||||||
}
|
|
||||||
contab_ini.set("KEYFPPRO", prokeys);
|
|
||||||
|
|
||||||
// Esporto righe iva
|
|
||||||
int i = 1;
|
|
||||||
for (auto it = riva.begin(); it != riva.end(); ++it)
|
|
||||||
{
|
|
||||||
contab_ini.set_paragraph(LF_RMOVIVA, i); // [25]
|
|
||||||
contab_ini.set("IMPONIBILE", abs(it->imponibile).string());
|
|
||||||
contab_ini.set("IMPOSTA", abs(it->imposta).string());
|
|
||||||
contab_ini.set("PERCIVA", it->aliquota.string());
|
|
||||||
contab_ini.set("NATURA", it->natura);
|
|
||||||
contab_ini.set("NRIGA", i);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Se ci sono le scadenze esporto anche quelle
|
|
||||||
TString where_q;
|
|
||||||
where_q << "WHERE PO_KEYPRGINVIO = '" << keys.get(0) << "'";
|
|
||||||
where_q << " AND PO_KEYHEADERFATT = '" << keys.get() << "'";
|
|
||||||
where_q << " AND PO_KEYBODYFATT = '" << keys.get() << "'";
|
|
||||||
TString query; query << "SELECT PO_RIGA AS RIGA, PO_DATASCADENZA AS DATA, PO_IMPORTO AS IMPORTO \nFROM PAA2500F \n" << where_q;
|
|
||||||
|
|
||||||
fp_db().sq_set_exec(query,false);
|
|
||||||
for (bool ok = fp_db().sq_next(); ok; ok = fp_db().sq_next())
|
|
||||||
{
|
|
||||||
const int riga = real(fp_db().sq_get("RIGA")).integer();
|
|
||||||
contab_ini.set_paragraph(LF_SCADENZE, riga); // Setto il paragrafo con riga scad [29]
|
|
||||||
contab_ini.set("DATASCAD", fp_db().sq_get_date("DATA"));
|
|
||||||
contab_ini.set("IMPORTO", fp_db().sq_get("IMPORTO"));
|
|
||||||
contab_ini.set("NRATA", riga);
|
|
||||||
contab_ini.set("NRIGA", "1");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(check_causale(codcaus, "NC", true) && is_tipomov_nc(codcaus))
|
|
||||||
{
|
{
|
||||||
contab_ini.set_paragraph(LF_MOV); // Aggiungo i riferimenti al documento se nota credito: GESTISCO DA CG PER IMPOSTARE PARTITE/SCADENZIARIO
|
real imp = calcola_importo(riva);
|
||||||
where_q.cut(0) << "WHERE PD_KEYPRGINVIO = '" << keys.get(0) << "'";
|
totdoc.cut(0) << imp;
|
||||||
where_q << " AND PD_KEYHEADERFATT = '" << keys.get() << "'";
|
}
|
||||||
where_q << " AND PD_KEYBODYFATT = '" << keys.get() << "'";
|
real rit = fppro_db().set_keys(keys).get_ritenute();
|
||||||
query.cut(0) << "SELECT PD_RIFNUMLINEA AS NUMLINEA, PD_IDDOC AS DOC, PD_DATADOC AS DATADOC\nFROM PAA1400F\n" << where_q;
|
if (rit != ZERO)
|
||||||
|
{
|
||||||
|
contab_ini.set("TOTDOC", (abs(real(totdoc)) - rit).string());
|
||||||
|
contab_ini.set("RITFIS", rit.string());
|
||||||
|
}
|
||||||
|
else if (is_doc_split(riva)) // Documento con split
|
||||||
|
{
|
||||||
|
contab_ini.set("TOTDOC", get_tot_imp_riva(riva));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
contab_ini.set("TOTDOC", abs(real(totdoc)).string());
|
||||||
|
}
|
||||||
|
contab_ini.set("KEYFPPRO", prokeys);
|
||||||
|
|
||||||
|
// Esporto righe iva
|
||||||
|
int i = 1;
|
||||||
|
for (auto it = riva.begin(); it != riva.end(); ++it)
|
||||||
|
{
|
||||||
|
contab_ini.set_paragraph(LF_RMOVIVA, i); // [25]
|
||||||
|
contab_ini.set("IMPONIBILE", abs(it->imponibile).string());
|
||||||
|
contab_ini.set("IMPOSTA", abs(it->imposta).string());
|
||||||
|
contab_ini.set("PERCIVA", it->aliquota.string());
|
||||||
|
contab_ini.set("NATURA", it->natura);
|
||||||
|
contab_ini.set("NRIGA", i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
TString where_q, query;
|
||||||
|
/* Se ci sono le scadenze esporto anche quelle
|
||||||
|
*
|
||||||
|
* Solo se l'importo non e' nullo: modifica dopo esserci accorti che lo scadenzario in
|
||||||
|
* questo caso rompeva le scatole per scadenza nulla. In pratica se sporchi le rate non puoi
|
||||||
|
* salvarle se nulle.
|
||||||
|
*/
|
||||||
|
if (real(totdoc) != ZERO)
|
||||||
|
{
|
||||||
|
where_q << "WHERE PO_KEYPRGINVIO = '" << keys.get(0) << "'";
|
||||||
|
where_q << " AND PO_KEYHEADERFATT = '" << keys.get() << "'";
|
||||||
|
where_q << " AND PO_KEYBODYFATT = '" << keys.get() << "'";
|
||||||
|
query << "SELECT PO_RIGA AS RIGA, PO_DATASCADENZA AS DATA, PO_IMPORTO AS IMPORTO \nFROM PAA2500F \n" << where_q;
|
||||||
|
|
||||||
fp_db().sq_set_exec(query, false);
|
fp_db().sq_set_exec(query, false);
|
||||||
bool ok = fp_db().sq_next();
|
for (bool ok = fp_db().sq_next(); ok; ok = fp_db().sq_next())
|
||||||
for(int j = 0; ok; ok = fp_db().sq_next(), j++)
|
|
||||||
{
|
{
|
||||||
contab_ini.set(TString("NUMLINEA(") << j << ")", fp_db().sq_get("NUMLINEA"));
|
const int riga = real(fp_db().sq_get("RIGA")).integer();
|
||||||
contab_ini.set(TString("DOC(") << j << ")", fp_db().sq_get("DOC"));
|
contab_ini.set_paragraph(LF_SCADENZE, riga); // Setto il paragrafo con riga scad [29]
|
||||||
contab_ini.set(TString("DATADOC(") << j << ")", fp_db().sq_get("DATADOC"));
|
contab_ini.set("DATASCAD", fp_db().sq_get_date("DATA"));
|
||||||
|
contab_ini.set("IMPORTO", fp_db().sq_get("IMPORTO"));
|
||||||
|
contab_ini.set("NRATA", riga);
|
||||||
|
contab_ini.set("NRIGA", "1");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (check_causale(codcaus, "NC", true) && is_tipomov_nc(codcaus))
|
||||||
|
{
|
||||||
|
contab_ini.set_paragraph(LF_MOV); // Aggiungo i riferimenti al documento se nota credito: GESTISCO DA CG PER IMPOSTARE PARTITE/SCADENZIARIO
|
||||||
|
where_q.cut(0) << "WHERE PD_KEYPRGINVIO = '" << keys.get(0) << "'";
|
||||||
|
where_q << " AND PD_KEYHEADERFATT = '" << keys.get() << "'";
|
||||||
|
where_q << " AND PD_KEYBODYFATT = '" << keys.get() << "'";
|
||||||
|
query.cut(0) << "SELECT PD_RIFNUMLINEA AS NUMLINEA, PD_IDDOC AS DOC, PD_DATADOC AS DATADOC\nFROM PAA1400F\n" << where_q;
|
||||||
|
fp_db().sq_set_exec(query, false);
|
||||||
|
bool ok = fp_db().sq_next();
|
||||||
|
for (int j = 0; ok; ok = fp_db().sq_next(), j++)
|
||||||
|
{
|
||||||
|
contab_ini.set(TString("NUMLINEA(") << j << ")", fp_db().sq_get("NUMLINEA"));
|
||||||
|
contab_ini.set(TString("DOC(") << j << ")", fp_db().sq_get("DOC"));
|
||||||
|
contab_ini.set(TString("DATADOC(") << j << ")", fp_db().sq_get("DATADOC"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
row->add("", 0);
|
row->add("", 0);
|
||||||
break; // Chiudo subito tanto se ne può selezionare solo una alla volta
|
break; // Chiudo subito tanto se ne può selezionare solo una alla volta
|
||||||
|
Loading…
x
Reference in New Issue
Block a user