Files correlati : tf Commento : - Corretto errore di creazione record custom da prima nota gia' inviato - Aggiunta Natura nella tabella TRASFATT git-svn-id: svn://10.65.10.50/branches/R_10_00@24041 c028cbd2-c16b-5b4b-a496-9718f37d4682
734 lines
21 KiB
C++
734 lines
21 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_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));
|
||
row.add(get(F_TIPOCF), s.cid2index(A_TIPOCF));
|
||
} 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;
|
||
if(imposta != o.mask().get_real(A_IMPOSTA) && yesno_box("Aggiornare l'imposta?"))
|
||
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;
|
||
if(imposta != o.mask().get_real(A_IMPOSTA) && yesno_box("Aggiornare l'imposta?"))
|
||
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());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case A_TIPOCF:
|
||
case A_CODCF:
|
||
case A_OCFPI:
|
||
{
|
||
if(e != fe_modify) break;
|
||
// Leggo dal clifo
|
||
TString tipocf, codcf, ocfpi;
|
||
tipocf = o.mask().get(A_TIPOCF);
|
||
codcf = o.mask().get(A_CODCF);
|
||
ocfpi = o.mask().get(A_OCFPI);
|
||
TRectype app = getCli(tipocf, codcf, ocfpi);
|
||
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"));
|
||
|
||
// Abilito se il cliente <20> occasionale
|
||
o.mask().enable(A_OCFPI, app.get_bool("OCCAS"));
|
||
|
||
// 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");
|
||
}
|
||
}
|
||
break;
|
||
case A_TIPODOC:
|
||
// Controllo che il tipo di documento rientri in quelli del filtro
|
||
if(e == fe_modify && !get_bool(getTipoDoc(o.get())))
|
||
{
|
||
error_box("Attenzione! il tipo di documento scelto non fa parte dei filtri correnti!");
|
||
o.set("");
|
||
}
|
||
break;
|
||
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(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);
|
||
}
|
||
else
|
||
return error_box(TR("Riga non cancellabile"));
|
||
|
||
// Elimino la riga
|
||
TSheet_field& sheet = sfield(F_RIGHE);
|
||
// Vado a cercare la riga
|
||
FOR_EACH_SHEET_ROW(sheet, r, strarr)
|
||
{
|
||
long thisProg;
|
||
TString thisAlq;
|
||
strarr->get(_numero, thisProg);
|
||
strarr->get(_aliquota, thisAlq);
|
||
if(thisProg == progr && thisAlq == codalq) break;
|
||
}
|
||
sheet.destroy(r); // Aggiorna in automatico
|
||
|
||
// Se ha cancellato un movimento custom che deriva dalla prima nota propongo di andarlo a ripescare
|
||
if(progr < MOV_CUSTOM && yesno_box("Hai cancellato una riga custom di un movimento in prima nota, vuoi ricaricare la tabella?\n(Tutti i record verranno salvati per non perdere le modifiche!)"))
|
||
{
|
||
saveAll();
|
||
load_sheet();
|
||
return true;
|
||
}
|
||
}
|
||
break;
|
||
case DLG_EMAIL:
|
||
if(e == fe_button)
|
||
openJava();
|
||
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
|
||
{
|
||
TString invio = o.mask().get(A_INVIO);
|
||
if(invio != FLAG_FORZATO || invio != FLAG_ERRORE)
|
||
changeInvio(o.mask().get(A_TIPOCF), o.mask().get(A_CODCF), o.mask().get(A_NUMDOC), 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::openJava()
|
||
{
|
||
TFilename tmp;
|
||
tmp = SPESOMETROBASE "\\ModuliSirio.jar";
|
||
tmp.make_absolute_path();
|
||
|
||
DIRECTORY old_dir; xvt_fsys_get_dir(&old_dir);
|
||
DIRECTORY new_dir; xvt_fsys_convert_str_to_dir(tmp.path(), &new_dir);
|
||
xvt_fsys_set_dir(&new_dir);
|
||
|
||
const bool good = goto_url(tmp);
|
||
if (good)
|
||
{
|
||
xvt_sys_sleep(3000);
|
||
}
|
||
else
|
||
{
|
||
error_box(FR("Impossibile eseguire Java -jar %s"), (const char*)tmp);
|
||
}
|
||
xvt_fsys_set_dir(&old_dir);
|
||
}
|
||
|
||
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 = "";
|
||
TLocalisamfile mov(LF_MOV);
|
||
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;
|
||
}
|
||
// Salvo il valore di invio se <20> stato modificato
|
||
else if(strcmp(strarr->get(_invio), FLAG_INVIO) != 0)
|
||
{
|
||
TRectype rmov = cache().get(LF_MOV, strarr->get(_numero));
|
||
rmov.put("TFINVIO", strarr->get(_invio));
|
||
mov.rewrite(rmov);
|
||
}
|
||
}
|
||
message_box("Salvataggio effettuato!");
|
||
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;";
|
||
}
|
||
|
||
if(decodTipo(rec) == "ERR0")
|
||
{
|
||
ok = false;
|
||
msgerr.cut(0) << "Non riesco a determinare il tipo di documento corretto per l'agenzia delle entrate!";
|
||
printError(stampa, numMov, numDoc, msgerr);
|
||
coderr << "4;";
|
||
}
|
||
|
||
// Flaggo il record con i messaggi di errore
|
||
rec->add(coderr, _coderr); // Sempre potrebbero esserci errori non bloccanti
|
||
|
||
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() // IT'S THE FINAL CHECKDOOOOOOOWN! WE'RE CHECKING TOGEEEETHEEEEER!!!!
|
||
{
|
||
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);
|
||
}
|
||
}
|
||
// Forzo l'aggiornamento dello sheet
|
||
sfield(F_RIGHE).force_update();
|
||
}
|
||
|
||
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, rinvio;
|
||
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);
|
||
rinvio.cut(0); rinvio << strarr->get(_invio);
|
||
if(rinvio != FLAG_FORZATO && invio != FLAG_ERRORE && tipocf == rtipo && codcf == rcod && rnum == numdoc)
|
||
{
|
||
strarr->add(invio, _invio);
|
||
// Aggiorno la riga
|
||
sheet.force_update(r);
|
||
}
|
||
}
|
||
}
|
||
|
||
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);
|
||
|
||
// Importanti! Evito errori dopo premendo il bottone invia
|
||
if(!dal.ok())
|
||
{
|
||
dal = TDate(01, 01, 2017); // Data inizio validit<69> questo spesometro
|
||
set(F_DATAINI, dal);
|
||
}
|
||
if(!al.ok())
|
||
{
|
||
al = TDate(TODAY);
|
||
set(F_DATAFIN, al);
|
||
}
|
||
//TString key; key << "TIPOA=" << prefix().firm().get("TIPOA")<< ",CODANAGR=" << prefix().firm().get("CODANAGR");
|
||
TString key; key << prefix().firm().get("TIPOA") << "|" << prefix().firm().get("CODANAGR");
|
||
static const TString pivaDitta = cache().get(LF_ANAG, key, "PAIV");
|
||
static const TString cofiDitta = cache().get(LF_ANAG, key, "COFI");
|
||
|
||
TTrFa_cursors c;
|
||
|
||
TSheet_field& sheet = sfield(F_RIGHE);
|
||
|
||
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));
|
||
TString tipocf, codcf, ocfpi, nat;
|
||
for(bool ok = true; items > 0 && ok;)
|
||
{
|
||
tipocf.cut(0), codcf.cut(0), ocfpi.cut(0), nat.cut(0);
|
||
int err = c.next(recimposte, ok, tipocf, codcf, ocfpi);
|
||
|
||
// Carico i clienti
|
||
TRectype cli = getCli(tipocf, codcf, ocfpi);
|
||
|
||
FOR_EACH_ASSOC_OBJECT(recimposte, h, iva, rec)
|
||
{
|
||
TRectype movimento = *(TRectype*)rec;
|
||
// Controllo che sia un tipo documento da leggere
|
||
if(!get_bool(getTipoDoc(movimento.get("TIPODOC")))) continue;
|
||
// A volte mi pesca movimenti con invio sbagliato
|
||
if(!checkInvio(movimento.get("TFINVIO"))) continue;
|
||
|
||
// Creo una nuova riga nello sheet
|
||
TToken_string& row = sheet.row(-1);
|
||
|
||
/* 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);
|
||
|
||
if(isCust.full() && (err < foundcust || err > foundidcust))
|
||
bool tolla = true;
|
||
|
||
row.add(movimento.get("TFINVIO") == "I" ? "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
|
||
nat.cut(0) << movimento.get("NATURA");
|
||
row.add(nat.full() ? nat : 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 <20> stato flaggato l'autofattura, quindi in trasfat <20> 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
|
||
}
|
||
sheet.enable_cell(sheet.items()-1, _occas, movimento.get("OCCAS").full());
|
||
}
|
||
recimposte.destroy();
|
||
}
|
||
sheet.force_update();
|
||
sheet.show();
|
||
}
|
||
|
||
|
||
bool TTrFa_mask::checkInvio(const TString& invio)
|
||
{
|
||
bool ok;
|
||
switch(get_int(F_FATTSEL))
|
||
{
|
||
case 0:
|
||
ok = invio == "" || invio == FLAG_INVIO || invio == FLAG_FORZATO || invio == FLAG_ERRORE;
|
||
break;
|
||
case 1:
|
||
ok = invio == FLAG_INVIATO;
|
||
break;
|
||
case 2:
|
||
default:
|
||
ok = invio == FLAG_NINVIO;
|
||
break;
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
|
||
TTrFa_mask::TTrFa_mask(TString msk)
|
||
: TAutomask(msk), _filter_changed(true)
|
||
{
|
||
loadConfig();
|
||
}
|