666 lines
19 KiB
C++
666 lines
19 KiB
C++
|
/* Gestione maschera */
|
|||
|
|
|||
|
#include "tf0100b.h"
|
|||
|
|
|||
|
/////////////////////////////////////////////////////////////////////////////////////
|
|||
|
// TTrFa_mask
|
|||
|
/////////////////////////////////////////////////////////////////////////////////////
|
|||
|
|
|||
|
TTrFa_mask::~TTrFa_mask()
|
|||
|
{
|
|||
|
TSheet_field& sheet = sfield(F_RIGHE);
|
|||
|
if(!sheet.empty())
|
|||
|
sheet.destroy();
|
|||
|
}
|
|||
|
|
|||
|
void TTrFa_mask::next_page(int p)
|
|||
|
{
|
|||
|
TAutomask::next_page(p);
|
|||
|
if (_filter_changed)
|
|||
|
{
|
|||
|
TSheet_field & sf = sfield(F_RIGHE);
|
|||
|
if (curr_win() == sf.parent())
|
|||
|
{
|
|||
|
load_sheet();
|
|||
|
sf.force_update();
|
|||
|
_filter_changed = false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
bool TTrFa_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|||
|
{
|
|||
|
switch (o.dlg())
|
|||
|
{
|
|||
|
case F_DATAINI:
|
|||
|
if (e == fe_init)
|
|||
|
o.set(ini_get_string(CONFIG_DITTA, "tf", "LastSend", "01-01-2017"));
|
|||
|
break;
|
|||
|
case F_DATAFIN:
|
|||
|
if (e == fe_init)
|
|||
|
o.set(TDate(TODAY));
|
|||
|
break;
|
|||
|
case DLG_ALL:
|
|||
|
if (e == fe_button)
|
|||
|
{
|
|||
|
TSheet_field& docs = sfield(F_RIGHE);
|
|||
|
TString_array& sht = docs.rows_array();
|
|||
|
const int items = sht.items();
|
|||
|
|
|||
|
if (items > 0)
|
|||
|
{
|
|||
|
const TString4 select = *(sht.row(0).get(0)) == 'X' ? "" : "X";
|
|||
|
for (int i = 0; i < items; i++)
|
|||
|
sht.row(i).add(select, 0);
|
|||
|
docs.force_update();
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
case F_RIGHE:
|
|||
|
if (e == se_notify_add)
|
|||
|
{
|
|||
|
TSheet_field& s = (TSheet_field&)o;
|
|||
|
TToken_string& row = s.row(jolly);
|
|||
|
row.add(nuovo_progr(), s.cid2index(A_NUMERO));
|
|||
|
} else
|
|||
|
if (e == se_query_del)
|
|||
|
{
|
|||
|
TSheet_field& s = (TSheet_field&)o;
|
|||
|
TToken_string& row = s.row(jolly);
|
|||
|
const TRecnotype progr = row.get_long(0);
|
|||
|
return progr >= MOV_CUSTOM;
|
|||
|
} else
|
|||
|
if(e == se_enter)
|
|||
|
{
|
|||
|
//primaNota(o,e);
|
|||
|
}
|
|||
|
break;
|
|||
|
case A_DATAREG:
|
|||
|
{
|
|||
|
// Mi interessa solo fe_edit
|
|||
|
if(e != fe_modify) break;
|
|||
|
// Controllo che la data sia < della data documento e l'esercizio sia quello richiesto
|
|||
|
TDate datareg = o.get(), datadoc = o.mask().get(A_DATADOC);
|
|||
|
if(datareg >= get_date(F_DATAINI) && datareg <= get_date(F_DATAFIN))
|
|||
|
{
|
|||
|
// Controllo la data del documento
|
|||
|
if(datadoc.ok())
|
|||
|
{
|
|||
|
if(datadoc > datareg)
|
|||
|
{
|
|||
|
error_box("La data del documento <20> antecedente a quella di registrazione");
|
|||
|
o.set("");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
error_box("La data di registrazione non appartiene al periodo corrente");
|
|||
|
o.set("");
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
case A_DATADOC:
|
|||
|
{
|
|||
|
// Mi interessa solo fe_edit
|
|||
|
if(e != fe_modify) break;
|
|||
|
TDate datareg = o.mask().get(A_DATAREG), datadoc = o.get();
|
|||
|
// Controllo la data di registrazione
|
|||
|
if(datareg.ok())
|
|||
|
{
|
|||
|
if(datadoc > datareg)
|
|||
|
{
|
|||
|
error_box("La data del documento <20> antecedente a quella di registrazione");
|
|||
|
o.set("");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
case A_ALIQUOTA:
|
|||
|
if(e == fe_modify)
|
|||
|
{
|
|||
|
// Calcolo la natura
|
|||
|
o.mask().set(A_NATURA, natura(o.get()));
|
|||
|
// Se esiste un imponibile calcolo l'imposta
|
|||
|
real imponibile = o.mask().get(A_IMPONIBILE), imposta = ZERO;
|
|||
|
if(imponibile > 0)
|
|||
|
{
|
|||
|
imposta = imponibile * real(cache().get("%IVA", o.get(), "R0")) / 100;
|
|||
|
o.mask().set(A_IMPOSTA, imposta.round(2).string());
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
case A_IMPONIBILE:
|
|||
|
if(e == fe_modify)
|
|||
|
{
|
|||
|
// Se esiste l'iva calcolo l'imposta
|
|||
|
real imponibile = o.get(), imposta = ZERO;
|
|||
|
TString codiva = o.mask().get(A_ALIQUOTA);
|
|||
|
if(codiva != "")
|
|||
|
{
|
|||
|
imposta = imponibile * real(cache().get("%IVA", codiva, "R0")) / 100;
|
|||
|
o.mask().set(A_IMPOSTA, imposta.round(2).string());
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
case A_IMPOSTA:
|
|||
|
if(e == fe_modify)
|
|||
|
{
|
|||
|
// Controllo dell'esistenza sia di codiva che dell'imponibile e verifico che l'importo immesso sia corretto
|
|||
|
real imponibile = o.mask().get(A_IMPONIBILE), imposta = ZERO;
|
|||
|
TString codiva = o.mask().get(A_ALIQUOTA);
|
|||
|
if(codiva != "" && imponibile > ZERO)
|
|||
|
{
|
|||
|
imposta = imponibile * real(cache().get("%IVA", codiva, "R0")) / 100; imposta = imposta.round(2);
|
|||
|
// Controllo che l'aliquota calcolata sia == a quella che ho qua
|
|||
|
real impostaInserita = o.get();
|
|||
|
if(impostaInserita != imposta)
|
|||
|
{
|
|||
|
TString msg;
|
|||
|
msg << "Attenzione!! Il valore immesso " << impostaInserita.string() << "<EFBFBD> non <20> corretto!\n";
|
|||
|
msg << "Valore corretto: " << imposta.string() << "<EFBFBD>\nVuoi proseguire?";
|
|||
|
if(!yesno_box(msg))
|
|||
|
{
|
|||
|
o.set(imposta.string());
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
case A_TIPOCF:
|
|||
|
case A_CODCF:
|
|||
|
case A_OCFPI:
|
|||
|
{
|
|||
|
if(e != fe_modify) break;
|
|||
|
TString tipocf, codcf;
|
|||
|
// Controllo se <20> un cliente occasionale
|
|||
|
tipocf = "O";
|
|||
|
codcf = o.mask().get(A_OCFPI);
|
|||
|
if(codcf.empty())
|
|||
|
{
|
|||
|
tipocf = o.mask().get(A_TIPOCF);
|
|||
|
codcf = o.mask().get(A_CODCF);
|
|||
|
}
|
|||
|
TRectype app = getCli(tipocf, codcf);
|
|||
|
o.mask().set(A_RAGSOC, app.get("RAGSOC"));
|
|||
|
o.mask().set(A_RFSO, app.get("CODRFSO"));
|
|||
|
o.mask().set(A_RAGSOCRFSO, getRFSO(app.get("CODRFSO")));
|
|||
|
o.mask().set(A_PAIV, app.get("PAIV"));
|
|||
|
o.mask().set(A_COFI, app.get("COFI"));
|
|||
|
|
|||
|
// Controllo autofattura
|
|||
|
TString key; key << prefix().firm().get("TIPOA") << "|" << prefix().firm().get("CODANAGR");
|
|||
|
TString piva = cache().get(LF_ANAG, key, "PAIV");
|
|||
|
if(piva == app.get("PAIV"))
|
|||
|
{
|
|||
|
// Autofattura!
|
|||
|
o.mask().set(A_AUTOFATT, "X");
|
|||
|
}
|
|||
|
}
|
|||
|
case DLG_SAVEREC:
|
|||
|
if(e == fe_button)
|
|||
|
saveAll();
|
|||
|
break;
|
|||
|
case DLG_ARCHIVE:
|
|||
|
if(e == fe_button)
|
|||
|
checkAll();
|
|||
|
break;
|
|||
|
case DLG_EDIT:
|
|||
|
if(e == fe_button)
|
|||
|
{
|
|||
|
TSheet_field& sheet = sfield(F_RIGHE);
|
|||
|
if(sheet.items() > 0)
|
|||
|
{
|
|||
|
sheet.esporta();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
warning_box("Impossibile esportare una griglia vuota");
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
case DLG_RECALC:
|
|||
|
if(e == fe_button)
|
|||
|
next_page(1);
|
|||
|
break;
|
|||
|
case DLG_USER:
|
|||
|
if (e == fe_button || e == fe_init)
|
|||
|
{
|
|||
|
const long numreg = o.mask().get_long(A_NUMERO);
|
|||
|
const bool enab = (numreg > 0) && (numreg < MOV_CUSTOM);
|
|||
|
if (e == fe_button && enab)
|
|||
|
{
|
|||
|
o.disable(); // Tecnica anti doppio click!
|
|||
|
TRectype mov(LF_MOV);
|
|||
|
mov.put("NUMREG", numreg);
|
|||
|
mov.edit();
|
|||
|
o.enable();
|
|||
|
}
|
|||
|
else
|
|||
|
o.enable(enab);
|
|||
|
}
|
|||
|
break;
|
|||
|
case DLG_DELREC:
|
|||
|
if (e == fe_button && o.active())
|
|||
|
{
|
|||
|
const long progr = o.mask().get_long(A_NUMERO);
|
|||
|
TString codalq = o.mask().get(A_ALIQUOTA);
|
|||
|
TString key; key << progr << "|" << codalq;
|
|||
|
if (progr >= MOV_CUSTOM)
|
|||
|
{
|
|||
|
if(cache().get(LF_TRASFATT, key).full())
|
|||
|
{
|
|||
|
TLocalisamfile trasfat(LF_TRASFATT);
|
|||
|
trasfat.put("NUMREG", progr);
|
|||
|
trasfat.put("CODIVA", codalq);
|
|||
|
const int err = trasfat.remove();
|
|||
|
if (err != NOERR)
|
|||
|
return error_box(FR("Errore di cancellazione: %d"), err);
|
|||
|
}
|
|||
|
// In qualsiasi caso elimino sta riga
|
|||
|
TSheet_field& s = o.mask().sfield(F_RIGHE);
|
|||
|
TToken_string& row = s.row(jolly);
|
|||
|
row.destroy(jolly);
|
|||
|
}
|
|||
|
else
|
|||
|
return error_box(TR("Riga non cancellabile"));
|
|||
|
}
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
const short id = o.dlg();
|
|||
|
if (e == fe_modify && jolly == 1)
|
|||
|
{
|
|||
|
if (id >= START_SHEET && id < END_SHEET && id != A_FORZATA)
|
|||
|
{
|
|||
|
// Se ho modificato l'impostazione dell'invio non va segnata la modifica MA devo togliere o mettere il flag a tutti quelli con movimento uguale
|
|||
|
if(id != A_INVIO)
|
|||
|
o.mask().set(A_FORZATA, true);
|
|||
|
else
|
|||
|
{
|
|||
|
changeInvio(o.mask().get(A_TIPOCF), o.mask().get(A_CODCF), o.mask().get(A_NUMDOC), o.mask().get(A_INVIO));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
if (e == fe_modify && jolly == 0)
|
|||
|
{
|
|||
|
if (id >= START_MASK && id <= END_MASK)
|
|||
|
{
|
|||
|
setFilterChanged();
|
|||
|
}
|
|||
|
if(id >= START_BOOLEAN && id <= END_BOOLEAN)
|
|||
|
saveConfig();
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
void TTrFa_mask::loadConfig()
|
|||
|
{
|
|||
|
// Rilevo i tipi scelti
|
|||
|
TToken_string tipidoc(ini_get_string(CONFIG_DITTA, "tf", "TIPIDOC"));
|
|||
|
// Potrei fare un for su TToken_string ma non darebbe la possibilit<69> di flaggare tutto in caso di prima installazione
|
|||
|
for(int pos = 0; pos < tipidoc.items(); pos++)
|
|||
|
{
|
|||
|
int field = getTipoDoc(tipidoc.get(pos));
|
|||
|
if(field != -1)
|
|||
|
set(field, "X");
|
|||
|
}
|
|||
|
}
|
|||
|
void TTrFa_mask::saveConfig()
|
|||
|
{
|
|||
|
TToken_string tipidoc;
|
|||
|
for(int id = START_BOOLEAN; id <= END_BOOLEAN; id++)
|
|||
|
{
|
|||
|
if(get_bool(id))
|
|||
|
{
|
|||
|
tipidoc.add(getTipoDoc(id));
|
|||
|
}
|
|||
|
}
|
|||
|
ini_set_string(CONFIG_DITTA, "tf", "TIPIDOC", tipidoc);
|
|||
|
}
|
|||
|
|
|||
|
/* salvo tutti i record modificati */
|
|||
|
bool TTrFa_mask::saveAll()
|
|||
|
{
|
|||
|
TSheet_field& sheet = sfield(F_RIGHE);
|
|||
|
//TString_array& strarr = sheet.rows_array();
|
|||
|
TString mod = "";
|
|||
|
FOR_EACH_SHEET_ROW(sheet, r, strarr)
|
|||
|
{
|
|||
|
strarr->get(_forzata, mod);
|
|||
|
if(mod == "X")
|
|||
|
{
|
|||
|
bool ok, retry = false;
|
|||
|
do
|
|||
|
{
|
|||
|
ok = saveRec(*strarr);
|
|||
|
if(!ok)
|
|||
|
{
|
|||
|
TString msg = "Errore durante il salvataggio del movimento ";
|
|||
|
msg << "alla riga " << r << "\nRitentare?";
|
|||
|
retry = yesno_box(msg);
|
|||
|
}
|
|||
|
} while(retry && !ok);
|
|||
|
if(!ok)
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
bool TTrFa_mask::checkAll()
|
|||
|
{
|
|||
|
// Controllo di avere uno sheet pieno
|
|||
|
if(!checkNotEmpty()) return true;
|
|||
|
|
|||
|
if(yesno_box("Controllare tutti i C.F. P.IVA?"))
|
|||
|
{
|
|||
|
TExternal_app servizio("cg1 -2 L");
|
|||
|
servizio.run();
|
|||
|
}
|
|||
|
|
|||
|
// Sistemo i flag
|
|||
|
theFinalCheckDown();
|
|||
|
|
|||
|
static TPrinter stampa;
|
|||
|
stampa.reset();
|
|||
|
stampa.open();
|
|||
|
TPrintrow riga;
|
|||
|
riga.put(TR("------------------ Controllo Errori TF -------------------"), 30);
|
|||
|
stampa.setheaderline(1, riga);
|
|||
|
riga.reset();
|
|||
|
riga.put("N.Registrazione", 0);
|
|||
|
riga.put("N.Documento", 20);
|
|||
|
riga.put("Tipo errore", 40);
|
|||
|
stampa.setheaderline(3, riga);
|
|||
|
riga.reset();
|
|||
|
riga.put(TR("Tutti i record qui elencati sono stati segnati con il codice \"Errore\" e non verranno inviati"), 0);
|
|||
|
stampa.setheaderline(2, riga);
|
|||
|
riga.reset();
|
|||
|
stampa.setheaderline(4, riga);
|
|||
|
stampa.print(riga);
|
|||
|
TSheet_field& sheet = sfield(F_RIGHE);
|
|||
|
FOR_EACH_SHEET_ROW(sheet, r, strarr)
|
|||
|
{
|
|||
|
checkRec(&stampa, *strarr);
|
|||
|
}
|
|||
|
riga.reset();
|
|||
|
riga.put(TR("------------------ Fine controllo! ------------------"), 30);
|
|||
|
stampa.print(riga);
|
|||
|
stampa.close();
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
inline void printError(TPrinter* stampa, TString movimento, TString documento, TString msgerr)
|
|||
|
{
|
|||
|
TPrintrow riga;
|
|||
|
riga.put(movimento, 0);
|
|||
|
riga.put(documento, 20);
|
|||
|
riga.put(msgerr, 40);
|
|||
|
stampa->print(riga);
|
|||
|
}
|
|||
|
|
|||
|
bool TTrFa_mask::checkRec(TPrinter* stampa, TToken_string rec)
|
|||
|
{
|
|||
|
bool ok = true;
|
|||
|
TString numMov = rec.get(_numero), numDoc = rec.get(_numdoc);
|
|||
|
TString msgerr;
|
|||
|
TString coderr;
|
|||
|
// Controllo date ***********************************************************************************
|
|||
|
TDate reg = rec.get(_datareg), doc = rec.get(_datadoc);
|
|||
|
if(reg < doc)
|
|||
|
{
|
|||
|
ok = false;
|
|||
|
msgerr.cut(0) << "Data registrazione precedente alla data del documento";
|
|||
|
printError(stampa, numMov, numDoc, msgerr);
|
|||
|
coderr << "1;";
|
|||
|
}
|
|||
|
|
|||
|
// Controllo aliquota, imponibile e imposta *********************************************************
|
|||
|
TCodiceIVA codiva(rec.get(_aliquota));
|
|||
|
TString nat = rec.get(_natura), realNat(natura(rec.get(_aliquota)));
|
|||
|
nat.ltrim(); // Se vuoto arriva con uno spazio
|
|||
|
real imponibile = rec.get(_imponibile), imposta = rec.get(_importoIVA);
|
|||
|
if(nat != realNat)
|
|||
|
{
|
|||
|
msgerr.cut(0) << "Natura del movimento errata, valore dichiarato: " << nat << " valore corretto: " << realNat;
|
|||
|
printError(stampa, numMov, numDoc, msgerr);
|
|||
|
coderr << "2;";
|
|||
|
}
|
|||
|
|
|||
|
real realImp = imponibile * codiva.percentuale() / CENTO;
|
|||
|
realImp.round(2);
|
|||
|
if(imposta > realImp + TOLLARANZA || imposta < realImp - TOLLARANZA)
|
|||
|
{
|
|||
|
msgerr.cut(0) << "Imposta errata, valore dichiarato: " << imposta.string() << " valore \"potenzialmente\" corretto: " << realImp.string();
|
|||
|
printError(stampa, numMov, numDoc, msgerr);
|
|||
|
coderr << "3;";
|
|||
|
}
|
|||
|
|
|||
|
// Controllo Stato ***********************************************************************************
|
|||
|
/*
|
|||
|
TRectype clifo = getCli(rec.get(_tipocf), rec.get(_codcf));
|
|||
|
if(clifo.get("STATOCF") == "" &&
|
|||
|
*/
|
|||
|
// Flaggo il record con i messaggi di errore
|
|||
|
if(!ok)
|
|||
|
{
|
|||
|
rec.add("E", _invio);
|
|||
|
rec.add(coderr, _coderr);
|
|||
|
}
|
|||
|
|
|||
|
return ok;
|
|||
|
}
|
|||
|
|
|||
|
bool TTrFa_mask::checkNotEmpty()
|
|||
|
{
|
|||
|
TSheet_field& sheet = sfield(F_RIGHE);
|
|||
|
TString msg;
|
|||
|
|
|||
|
if(sheet.empty())
|
|||
|
msg = "La tabella dei movimenti <20> vuota, vuoi caricarla con i filtri selezionati?";
|
|||
|
else if(_filter_changed)
|
|||
|
msg = "I filtri sono stati cambiati, vuoi ricaricare la tabella con i nuovi filtri selezionati?";
|
|||
|
|
|||
|
if(msg.full() && yesno_box(msg))
|
|||
|
{
|
|||
|
_filter_changed = false;
|
|||
|
load_sheet();
|
|||
|
}
|
|||
|
return sheet.full();
|
|||
|
}
|
|||
|
|
|||
|
void TTrFa_mask::theFinalCheckDown()
|
|||
|
{
|
|||
|
TSheet_field& sheet = sfield(F_RIGHE);
|
|||
|
TAssoc_array cliDocs;
|
|||
|
FOR_EACH_SHEET_ROW(sheet, r, strarr)
|
|||
|
{
|
|||
|
// Chiave: TIPOCF + CODCF + NUMDOC + CODIVA
|
|||
|
TString key; key << strarr->get_char(_tipocf) << "|" << strarr->get_int(_codcf) << "|" << strarr->get(_numdoc) << "|" << strarr->get(_aliquota);
|
|||
|
TToken_string newNumero; newNumero.add(r, 0); newNumero.add(strarr->get_char(_invio), 1);
|
|||
|
if(cliDocs.is_key(key))
|
|||
|
{
|
|||
|
TToken_string oldnumero = *(TToken_string*)cliDocs.objptr(key);
|
|||
|
TString oldflag; oldnumero.get(1, oldflag);
|
|||
|
if(oldflag == FLAG_FORZATO)
|
|||
|
flagRow(r, FLAG_NINVIO);
|
|||
|
else
|
|||
|
{
|
|||
|
int oldr; oldnumero.get(0, oldr);
|
|||
|
flagRow(oldr, FLAG_NINVIO);
|
|||
|
}
|
|||
|
|
|||
|
cliDocs.add(key, newNumero);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
cliDocs.add(key, newNumero);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void TTrFa_mask::flagRow(int nrow, TString flag)
|
|||
|
{
|
|||
|
TSheet_field& sheet = sfield(F_RIGHE);
|
|||
|
TToken_string& row = sheet.row(nrow);
|
|||
|
row.add(flag, _invio);
|
|||
|
}
|
|||
|
|
|||
|
TRecnotype TTrFa_mask::nuovo_progr() const
|
|||
|
{
|
|||
|
static TRectype app(LF_TRASFATT);
|
|||
|
app.last(TLocalisamfile(LF_TRASFATT));
|
|||
|
// Lo inizializzo solo la prima volta poi incremento
|
|||
|
static TRecnotype numreg = app.get_long("NUMREG") > MOV_CUSTOM ? app.get_long("NUMREG") : MOV_CUSTOM;
|
|||
|
numreg++;
|
|||
|
return numreg;
|
|||
|
}
|
|||
|
|
|||
|
// Dato un cliente e il suo numero documento imposto il nuovo flag di invio su tutti i campi
|
|||
|
void TTrFa_mask::changeInvio(TString tipocf, TString codcf, TString numdoc, TString invio) const
|
|||
|
{
|
|||
|
TSheet_field& sheet = sfield(F_RIGHE);
|
|||
|
TString rtipo, rcod, rnum;
|
|||
|
FOR_EACH_SHEET_ROW(sheet, r, strarr)
|
|||
|
{
|
|||
|
// Ricevo i parametri della riga
|
|||
|
rtipo.cut(0); rtipo << strarr->get_char(_tipocf);
|
|||
|
rcod.cut(0); rcod << strarr->get_int(_codcf);
|
|||
|
rnum.cut(0); rnum << strarr->get(_numdoc);
|
|||
|
if(tipocf == rtipo && codcf == rcod && rnum == numdoc)
|
|||
|
{
|
|||
|
strarr->add(invio, _invio);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void TTrFa_mask::load_sheet()
|
|||
|
{
|
|||
|
const char tipo = get(F_TIPOCF)[0];
|
|||
|
const long codice = get_long(F_CODCF);
|
|||
|
TDate dal = get_date(F_DATAINI), al = get_date(F_DATAFIN);
|
|||
|
//TString key; key << "TIPOA=" << prefix().firm().get("TIPOA")<< ",CODANAGR=" << prefix().firm().get("CODANAGR");
|
|||
|
TString key; key << prefix().firm().get("TIPOA") << "|" << prefix().firm().get("CODANAGR");
|
|||
|
const TString pivaDitta = cache().get(LF_ANAG, key, "PAIV");
|
|||
|
const TString cofiDitta = cache().get(LF_ANAG, key, "COFI");
|
|||
|
|
|||
|
TTrFa_cursors c;
|
|||
|
|
|||
|
TSheet_field& sheet = sfield(F_RIGHE);
|
|||
|
TString_array& strarr = sheet.rows_array();
|
|||
|
|
|||
|
sheet.hide(); // Nascondo lo sheet per guadagnare un 20% di velocit<69> di caricamento, le ottimizzazioni da PRO!
|
|||
|
if(!sheet.empty())
|
|||
|
sheet.destroy();
|
|||
|
TAssoc_array recimposte;
|
|||
|
int items = c.updateFilters(tipo, codice, dal, al, get_int(F_FATTSEL));
|
|||
|
for(bool ok = true; items > 0 && ok;)
|
|||
|
{
|
|||
|
TString tipocf, codcf;
|
|||
|
int err = c.next(recimposte, ok, tipocf, codcf);
|
|||
|
// Carico i clienti
|
|||
|
TRectype cli = getCli(tipocf, codcf);
|
|||
|
|
|||
|
FOR_EACH_ASSOC_OBJECT(recimposte, h, iva, rec)
|
|||
|
{
|
|||
|
TToken_string* row = new TToken_string;
|
|||
|
TRectype movimento = *(TRectype*)rec;
|
|||
|
|
|||
|
// Controllo che sia un tipo documento da leggere
|
|||
|
if(!get_bool(getTipoDoc(movimento.get("TIPODOC")))) continue;
|
|||
|
|
|||
|
/* Siccome mi cambiano l'ordine ogni volta e non ho voglia di cambiare tutto ovunque
|
|||
|
* basta settare i valori negli enum e lo sheet
|
|||
|
*/
|
|||
|
TRectype isCust = getTrasFatt(movimento.get("NUMREG"), iva);
|
|||
|
|
|||
|
row->add(isCust.get_bool("TFINVIO") ? "X" : "", _spedita); // Spedita
|
|||
|
row->add("X"); // Da spedire, sempre!
|
|||
|
row->add(isCust.full() ? "X" : "", _forzata); // Modificato
|
|||
|
row->add(movimento.get_long("NUMREG"), _numero); // Numero registrazione
|
|||
|
row->add(movimento.get_date("DATAREG"), _datareg); // Data Registrazione
|
|||
|
row->add(movimento.get("TIPO"), _tipocf); // Tipo Cli/For
|
|||
|
row->add(movimento.get("CODCF"), _codcf); // Codice Cli/For
|
|||
|
row->add(movimento.get("OCCAS"), _occas); // Codice Occasionale
|
|||
|
row->add(cli.get("RAGSOC"), _ragsoc); // Ragione sociale
|
|||
|
row->add(cli.get("CODRFSO"), _rfso); // Codice RF/SO
|
|||
|
row->add(getRFSO(cli.get("CODRFSO")), _ragsocrfso); // Ragione Sociale RF/SO
|
|||
|
row->add(movimento.get("TIPODOC"), _codnum); // Tipo documento
|
|||
|
row->add(movimento.get("NUMDOC"), _numdoc); // Numero documento
|
|||
|
row->add(movimento.get_date("DATADOC"), _datadoc); // Data documento
|
|||
|
row->add(natura(iva), _natura); // NATURA!
|
|||
|
row->add(iva, _aliquota); // Codice aliquota!
|
|||
|
row->add(findDetraib(movimento.get("TIPODET")), _detraibile); // Detraibilit<69>
|
|||
|
row->add(movimento.get_real("IMPONIBILE"), _imponibile); // Imponibile
|
|||
|
row->add(movimento.get_real("IMPOSTA"), _importoIVA); // Imposta
|
|||
|
row->add(revCharge(movimento.get("NUMREG")), _reverse); // Rev.Charge
|
|||
|
|
|||
|
/*
|
|||
|
* Possono esistere movimenti custom dove il cliente ha una partita IVA propria
|
|||
|
* ma <EFBFBD> stato flaggato l'autofattura, quindi in trasfat <EFBFBD> presente il codice cliente con PIVA e CODFIS della ditta.
|
|||
|
* Controllo sia il movimento che il cliente
|
|||
|
*/
|
|||
|
if(movimento.get("AUTOFATT") == "X" || pivaDitta == cli.get("PAIV")) // Se <20> un autofattura
|
|||
|
{
|
|||
|
row->add("X", _autofatt); // AutoFatt
|
|||
|
row->add(pivaDitta, _paiv); // P.IVA
|
|||
|
row->add(cofiDitta, _codfis); // Codice Fiscale
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
row->add("", _autofatt); // AutoFatt
|
|||
|
row->add(cli.get("PAIV"), _paiv); // P.IVA
|
|||
|
row->add(cli.get("COFI"), _codfis); // Codice Fiscale
|
|||
|
}
|
|||
|
|
|||
|
strarr.add(row);
|
|||
|
}
|
|||
|
recimposte.destroy();
|
|||
|
}
|
|||
|
sheet.force_update();
|
|||
|
sheet.show();
|
|||
|
}
|
|||
|
|
|||
|
TString TTrFa_mask::findDetraib(TString tipodet) const
|
|||
|
{
|
|||
|
real perc = cache().get("%DET", tipodet, "R0");
|
|||
|
return perc.stringa(6,2);
|
|||
|
}
|
|||
|
|
|||
|
const char * TTrFa_mask::natura(const TString& codiva) const
|
|||
|
{
|
|||
|
const TRectype& ai = cache().get("%IVA", codiva);
|
|||
|
TString & natura = get_tmp_string(4);
|
|||
|
|
|||
|
natura = ai.get("S12");
|
|||
|
return natura;
|
|||
|
}
|
|||
|
|
|||
|
real TTrFa_mask::get_IVA(const TString& codiva) const
|
|||
|
{
|
|||
|
const TRectype& ai = cache().get("%IVA", codiva);
|
|||
|
return ai.get_real("R0");
|
|||
|
}
|
|||
|
|
|||
|
TString TTrFa_mask::revCharge(TString numreg) const
|
|||
|
{
|
|||
|
// Controllo se la causale ha il reverse charge, se il cliente non l'ha impostata giusta sono ARAZZI suoi
|
|||
|
TString key = numreg;
|
|||
|
TCausale caus(cache().get(LF_MOV, key, "CODCAUS"));
|
|||
|
return caus.reverse_charge() ? "X" : "";
|
|||
|
}
|
|||
|
|
|||
|
TString TTrFa_mask::getRFSO(TString codrfso) const
|
|||
|
{
|
|||
|
TString key; key << codrfso[0] << "|" << codrfso.mid(1);
|
|||
|
return cache().get(LF_ANAG, key, "RAGSOC");
|
|||
|
}
|
|||
|
|
|||
|
TTrFa_mask::TTrFa_mask(TString msk)
|
|||
|
: TAutomask(msk), _filter_changed(true)
|
|||
|
{
|
|||
|
loadConfig();
|
|||
|
}
|