b0ab13f0fc
git-svn-id: svn://10.65.10.50/trunk@4 c028cbd2-c16b-5b4b-a496-9718f37d4682
1089 lines
27 KiB
C++
Executable File
1089 lines
27 KiB
C++
Executable File
#include <progind.h>
|
|
#include <tabutil.h>
|
|
#include <utility.h>
|
|
#include <defmask.h>
|
|
|
|
#include "cg2100.h"
|
|
#include "cg2102.h"
|
|
|
|
|
|
// Certified 100%
|
|
inline TPrimanota_application& app()
|
|
{ return (TPrimanota_application&)*MainApp(); }
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Funzioni di decodifica/calcolo
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Determina il tipo IVA da causale+anno
|
|
// Certified 50%
|
|
TipoIVA TPrimanota_application::cau2IVA(const char* causale, int annoiva)
|
|
{
|
|
TipoIVA i = iva_errata;
|
|
|
|
if (*causale > ' ')
|
|
{
|
|
TCausale c;
|
|
if (c.read(causale, annoiva))
|
|
i = c.iva();
|
|
else
|
|
error_box("Causale errata: '%s'", causale);
|
|
} else i = nessuna_iva;
|
|
|
|
return i;
|
|
}
|
|
|
|
// Calcola l'anno di esercizio di una data
|
|
// Certified 99%
|
|
int TPrimanota_application::date2esc(const TDate& d, int* prevesc)
|
|
{
|
|
if (prevesc) *prevesc = 0;
|
|
TTable esc("ESC");
|
|
for (int err = esc.first(); err == NOERR; err = esc.next())
|
|
{
|
|
const TDate ia(esc.get("D0")); // Data inizio esercizio
|
|
const TDate fa(esc.get("D1")); // Data fine esercizio
|
|
const anno = esc.get_int("CODTAB");
|
|
if (d >= ia && d <= fa)
|
|
return anno;
|
|
if (prevesc) *prevesc = anno;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// Calcolo della percentuale di un dato codice IVA
|
|
// Certified 99%
|
|
const real& TPrimanota_application::cod2IVA(const char* codiva)
|
|
{
|
|
static TString16 _codiva;
|
|
static real _percent;
|
|
|
|
if (_codiva != codiva)
|
|
{
|
|
_codiva = codiva;
|
|
TCodiceIVA c(_codiva);
|
|
_percent = c.percentuale();
|
|
}
|
|
|
|
return _percent;
|
|
}
|
|
|
|
real TPrimanota_application::scorpora(real& imponibile, const real& percent)
|
|
{
|
|
real imposta = imponibile * percent / (percent + 100.0); imposta.ceil();
|
|
imponibile -= imposta;
|
|
return imposta;
|
|
}
|
|
|
|
|
|
// Determina se un codice sospeso o no
|
|
// Certified 50%
|
|
bool TPrimanota_application::suspended_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (f.to_check(k))
|
|
{
|
|
CHECKD(f.is_edit(), "Can't check suspension of a non edit-field ", f.dlg());
|
|
const TEdit_field& c = (const TEdit_field&)f;
|
|
const TBrowse* b = c.browse();
|
|
CHECKD(b, "Can't check suspension of a edit-field without a USE ", f.dlg());
|
|
const TLocalisamfile* i = b->cursor()->file();
|
|
|
|
const char* sf = i->tab() ? "B2" : "SOSPESO";
|
|
const bool suspended = i->get_bool(sf);
|
|
if (suspended)
|
|
{
|
|
sf = f.get();
|
|
return f.error_box("Il codice '%s' e' sospeso e non puo' essere utilizzato", sf);
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// Determina se un codice detrazione e' di tipo detraibile o no
|
|
// Certified 70%
|
|
bool TPrimanota_application::detraibile(int tipodet)
|
|
{
|
|
if (tipodet)
|
|
return FALSE;
|
|
if (app().iva() != iva_acquisti)
|
|
return TRUE;
|
|
|
|
const TSheet_field& iva = app().ivas();
|
|
|
|
TString16 chiave;
|
|
chiave = iva.mask().get(F_ANNOIVA);
|
|
chiave << iva.mask().get(F_CODREG);
|
|
TTable reg("REG");
|
|
reg.put("CODTAB", chiave);
|
|
reg.read();
|
|
#ifdef DBG
|
|
if(reg.status() != NOERR)
|
|
error_box("La minchia che trovo il registro '%s'", (const char*)chiave);
|
|
#endif
|
|
|
|
const char* att = reg.get("S8");
|
|
chiave.cut(4); chiave << att;
|
|
|
|
TTable pla("PLA");
|
|
pla.put("CODTAB", chiave);
|
|
const int err = pla.read();
|
|
real prorata;
|
|
if (err == NOERR)
|
|
prorata = pla.get_real("R8");
|
|
|
|
return prorata != 100.0;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Funzioni di ricerca
|
|
///////////////////////////////////////////////////////////
|
|
|
|
int TPrimanota_application::type2pos(char tipo)
|
|
{
|
|
TSheet_field& cg = app().cgs();
|
|
for (int i = 0; i < cg.items(); i++)
|
|
{
|
|
TToken_string& s = cg.row(i);
|
|
if (s[s.len()-1] == tipo)
|
|
return i;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
int TPrimanota_application::bill2pos(const TConto& conto, char tipo)
|
|
{
|
|
TSheet_field& cg = app().cgs();
|
|
for (int i = 0; i < cg.items(); i++)
|
|
{
|
|
TToken_string& s = cg.row(i);
|
|
if (s[s.len()-1] == tipo)
|
|
{
|
|
const TConto c(s, 3, 0x0);
|
|
if (c == conto)
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
int TPrimanota_application::bill2contr(const TConto& conto, char sezione) const
|
|
{
|
|
const TArray& rows = cgs().rows_array();
|
|
for (int i = 0; i < rows.items(); i++)
|
|
{
|
|
TToken_string& row = (TToken_string&)rows[i];
|
|
const char sez = row.get(0)[0] > ' ' ? 'D' : 'A';
|
|
if (sez == sezione) // Devo cercare sezione contraria
|
|
continue;
|
|
const TConto c(row, 3, 0x0);
|
|
if (conto == c)
|
|
return i;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::bill_used(const TConto& conto) const
|
|
{
|
|
const TArray& rows = ivas().rows_array();
|
|
for (int i = 0; i < rows.items(); i++)
|
|
{
|
|
TToken_string& row = (TToken_string&)rows[i];
|
|
const TConto c(row, 6, 0x0);
|
|
if (conto == c)
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Gestione sheet CG
|
|
///////////////////////////////////////////////////////////
|
|
|
|
TMask& TPrimanota_application::mask() const
|
|
{
|
|
TipoIVA i = app().iva();
|
|
return *_msk[i == nessuna_iva ? 1 : 2];
|
|
}
|
|
|
|
|
|
TSheet_field& TPrimanota_application::cgs() const
|
|
{
|
|
TSheet_field& s = (TSheet_field&)mask().field(F_SHEETCG);
|
|
return s;
|
|
}
|
|
|
|
|
|
// Certified 99%
|
|
// Dato un importo stabilisce se deve andare in DARE o AVERE
|
|
// ritornandolo poi col segno opportuno + o -
|
|
real TPrimanota_application::imp2sez(const real& imp)
|
|
{
|
|
const int dare = (imp >= 0.0) ^ (app().iva() == iva_vendite);
|
|
return abs(imp) * (dare ? +1.0 : -1.0);
|
|
}
|
|
|
|
|
|
// Certified 99%
|
|
// Scrive l'importo imp nella opportuna sezione della riga n
|
|
void TPrimanota_application::set_cgs_imp(int n, const real& imp)
|
|
{
|
|
TToken_string& row = cgs().row(n);
|
|
const char* val = imp.string();
|
|
if (*val == '-')
|
|
{
|
|
row.add(" ", 0);
|
|
row.add(val+1, 1);
|
|
}
|
|
else
|
|
{
|
|
row.add(val, 0);
|
|
row.add(" ", 1);
|
|
}
|
|
cgs().force_update(n);
|
|
}
|
|
|
|
|
|
// Legge l'importo della riga n e lo ritorna col segno dovuto
|
|
// Certified 99%
|
|
real TPrimanota_application::get_cgs_imp(int n)
|
|
{
|
|
TToken_string& row = cgs().row(n);
|
|
const real dare(row.get(0));
|
|
if (dare > 0.0) return dare;
|
|
const real avere(row.get());
|
|
return -avere;
|
|
}
|
|
|
|
|
|
// Certified 90%
|
|
void TPrimanota_application::add_cgs_imp(int n, const real& imp)
|
|
{
|
|
const real tot = get_cgs_imp(n) + imp;
|
|
set_cgs_imp(n, tot);
|
|
}
|
|
|
|
// Disabilita le celle della riga contabile n in base al suo tipo
|
|
void TPrimanota_application::disable_cgs_cells(int n, char tipo)
|
|
{
|
|
int last;
|
|
switch(tipo)
|
|
{
|
|
case 'F': // Ritenute Fiscali
|
|
case 'S': // Ritenute Sociali
|
|
case 'D': // IVA Detraibile
|
|
case 'N':last = 3; break; // IVA Non detraibile
|
|
case 'T': // Totale documento
|
|
case 'I':last = 6; break; // Imponibile
|
|
default :last = 0; break; // Solo contabile
|
|
}
|
|
|
|
TSheet_field& cg = cgs();
|
|
for (int i = 0; i < last; i++)
|
|
cg.disable_cell(n, i);
|
|
|
|
if (tipo == 'T')
|
|
{
|
|
cg.enable_cell(n, 3);
|
|
cg.enable_cell(n, 4);
|
|
}
|
|
}
|
|
|
|
|
|
int TPrimanota_application::set_cgs_row(int n, const real& imp,
|
|
TConto& conto, const char* desc,
|
|
char tipo)
|
|
{
|
|
TSheet_field& cg = cgs();
|
|
if (n < 0) n = cg.first_empty();
|
|
TToken_string& row = cg.row(n);
|
|
row = "";
|
|
set_cgs_imp(n, imp);
|
|
row.add(conto.string(0x3));
|
|
row.add("");
|
|
row.add(desc);
|
|
|
|
int pos = 0;
|
|
if (tipo == 'I' && (pos = type2pos('T')) >= 0)
|
|
{
|
|
TConto contro(cg.row(pos), 2, 0x3);
|
|
row.add(contro.string(0x3));
|
|
}
|
|
else
|
|
{
|
|
row.add(" | | | | "); // Contropartita
|
|
}
|
|
row << '|' << tipo;
|
|
disable_cgs_cells(n, tipo);
|
|
cg.force_update(n);
|
|
|
|
return n;
|
|
}
|
|
|
|
|
|
HIDDEN int compare_rows(const TObject** o1, const TObject** o2)
|
|
{
|
|
// Totale, Rit.Fisc., Rit.Soc., da riga IVA, riga contabile, IVA detr., IVA non detr.
|
|
static char* sort_order = "TFSI DN";
|
|
|
|
const TToken_string* r1 = (const TToken_string*)*o1;
|
|
const TToken_string* r2 = (const TToken_string*)*o2;
|
|
const char c1 = r1->right(1)[0];
|
|
const char c2 = r2->right(1)[0];
|
|
return int(strchr(sort_order, c1) - strchr(sort_order, c2));
|
|
}
|
|
|
|
|
|
void TPrimanota_application::cgs_pack()
|
|
{
|
|
TArray& rows = cgs().rows_array();
|
|
|
|
const int max = rows.items();
|
|
for (int i = 0; i < max; i++)
|
|
{
|
|
TToken_string& r = (TToken_string&)rows[i];
|
|
bool del = FALSE;
|
|
if (r.empty_items()) // Remove all empty strings
|
|
del = TRUE;
|
|
else
|
|
{
|
|
const real imp = get_cgs_imp(i);
|
|
if (imp == 0.0)
|
|
{
|
|
del = TRUE;
|
|
/*
|
|
const TConto c(r, 6, 0x0); // Remove if import=0 and Bill not used
|
|
del = !bill_used(c);
|
|
*/
|
|
}
|
|
|
|
}
|
|
if (del)
|
|
rows.destroy(i, FALSE);
|
|
}
|
|
|
|
rows.sort(compare_rows); // Pack and sort array
|
|
}
|
|
|
|
|
|
// Handler dello sheet di contabilita'
|
|
// Certified 90%
|
|
bool TPrimanota_application::cg_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_ENTER)
|
|
{
|
|
TSheet_field& cg = app().cgs();
|
|
bool empty = TRUE;
|
|
real saldo;
|
|
for (int i = 0; i < cg.items(); i++)
|
|
{
|
|
const real imp = app().get_cgs_imp(i);
|
|
if (empty) empty = imp == 0.0;
|
|
saldo += imp;
|
|
}
|
|
if (saldo != 0.0)
|
|
{
|
|
const char* ss = saldo.string(".");
|
|
return f.error_box("Il movimento e' sbilanciato di %s lire.", ss);
|
|
}
|
|
else
|
|
if (empty)
|
|
return f.error_box("Il movimento non contiene nessuna riga contabile!");
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::cg_notify(int r, KEY k)
|
|
{
|
|
TSheet_field& cg = app().cgs();
|
|
TToken_string& row = cg.row(r);
|
|
const char tipo = row.empty() ? ' ' : row.right(1)[0];
|
|
|
|
if (k == K_SPACE)
|
|
{
|
|
TMask& m = cg.sheet_mask();
|
|
m.enable(DLG_DELREC, tipo == ' ');
|
|
} else
|
|
if (k == K_DEL)
|
|
{
|
|
if (tipo != ' ')
|
|
return error_box("La riga %d non puo' essere cancellata", r+1);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TPrimanota_application::descr_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_ENTER && f.get().empty())
|
|
{
|
|
if (f.mask().get(F_CODCAUS).empty())
|
|
return error_box("Descrizione documento necessaria in mancanza della causale");
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// Handler per le colonne 'Dare' e 'Avere' dello sheet contabile.
|
|
// Scrivendo qualcosa in dare (101) cancella l'importo in avere (102) e viceversa
|
|
bool TPrimanota_application::dareavere_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_TAB && f.focusdirty() && !f.get().empty())
|
|
{
|
|
const int id = 203-f.dlg(); // Calcola id del campo da resettare
|
|
f.mask().reset(id);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Gestione sheet IVA
|
|
///////////////////////////////////////////////////////////
|
|
|
|
TSheet_field& TPrimanota_application::ivas() const
|
|
{
|
|
TSheet_field& s = (TSheet_field&)_msk[2]->field(F_SHEETIVA);
|
|
return s;
|
|
}
|
|
|
|
|
|
void TPrimanota_application::set_ivas_row(int nriga, const char* codiva, TConto& tc,
|
|
const char* desc)
|
|
{
|
|
TToken_string& riga = ivas().row(nriga);
|
|
riga = " "; // Importo
|
|
riga.add (codiva); // codiva
|
|
riga.add (" | | "); // Imposta - C/R - Det
|
|
riga.add(tc.string(0x3)); // Conto
|
|
riga.add(desc); // Descrizione
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::imponibile_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (key == K_TAB && f.dirty())
|
|
{
|
|
const TString& iva = f.mask().get(102);
|
|
if (iva.not_empty()) // Se c'e' il codice IVA
|
|
{
|
|
const real& percent = cod2IVA(iva);
|
|
const real imponibile(f.get());
|
|
real imposta = imponibile * percent / 100.0; imposta.ceil();
|
|
f.mask().set(103, imposta.string());
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::codiva_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (key == K_TAB && f.dirty())
|
|
{
|
|
TMask_field& i = f.mask().field(101);
|
|
i.set_dirty();
|
|
return imponibile_handler(i, key);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::imposta_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (key == K_ENTER)
|
|
{
|
|
const real imponibile(f.mask().get(101));
|
|
const real& percent = cod2IVA(f.mask().get(102));
|
|
real imposta = imponibile * percent / 100.0; imposta.ceil();
|
|
const real val(f.get());
|
|
if (val != imposta)
|
|
{
|
|
const TString16 wrong(val.string("."));
|
|
const TString16 right(imposta.string("."));
|
|
if (f.yesno_box("Imposta di '%s' errata: modificare in '%s'?",
|
|
(const char*)wrong, (const char*)right))
|
|
f.set(imposta.string());
|
|
}
|
|
} else
|
|
if (key == K_F8 && f.get().empty())
|
|
{
|
|
real imponibile(f.mask().get(101));
|
|
const real& percent = cod2IVA(f.mask().get(102));
|
|
const real imposta = scorpora(imponibile, percent);
|
|
f.set(imposta.string());
|
|
f.mask().set(101, imponibile.string());
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// Certified 50%
|
|
bool TPrimanota_application::iva_notify(int r, KEY k)
|
|
{
|
|
static int oldpos;
|
|
static real oldimp;
|
|
|
|
static int oldposiva;
|
|
static real oldiva;
|
|
|
|
TSheet_field& iva = app().ivas();
|
|
TToken_string& row = iva.row(r);
|
|
|
|
if (k == K_SPACE)
|
|
{
|
|
const TConto oldconto(row, 5, 0x1);
|
|
oldpos = bill2pos(oldconto, 'I');
|
|
oldimp = imp2sez(real(row.get(0)));
|
|
oldposiva = type2pos(detraibile(row.get_int(4)) ? 'D' : 'N');
|
|
oldiva = imp2sez(real(row.get(2)));
|
|
}
|
|
if (k == K_DEL)
|
|
{
|
|
row.add("0", 0); // Azzera imponibile
|
|
row.add("0", 2); // Azzera imposta
|
|
k = K_ENTER; // Elegante o Sporco trucco
|
|
}
|
|
if (k == K_ENTER)
|
|
{
|
|
if (oldpos >= 0) // Il conto esisteva anche prima
|
|
{
|
|
app().add_cgs_imp(oldpos, -oldimp);
|
|
oldimp = 0.0;
|
|
}
|
|
if (oldposiva >= 0) // Il conto IVA esisteva anche prima
|
|
{
|
|
app().add_cgs_imp(oldposiva, -oldiva);
|
|
oldiva = 0.0;
|
|
}
|
|
|
|
// Aggiorna conto sulla riga contabile
|
|
real imp = imp2sez(real(row.get(0))); // Imponibile
|
|
TConto conto(row, 5, 0x3);
|
|
oldpos = bill2pos(conto, 'I');
|
|
|
|
if (oldpos < 0)
|
|
app().set_cgs_row(-1, imp-oldimp, conto, "", 'I');
|
|
else
|
|
app().add_cgs_imp(oldpos, imp-oldimp);
|
|
oldimp = imp;
|
|
|
|
// Aggiorna conto IVA sulla riga contabile
|
|
|
|
imp = imp2sez(real(row.get(2))); // Imposta
|
|
const bool detrarre = detraibile(row.get_int(4)); // Determina se IVA detraibile
|
|
app().causale().bill(detrarre ? 3 : 4, conto);
|
|
const char tipod = detrarre ? 'D' : 'N';
|
|
oldposiva = type2pos(tipod);
|
|
if (oldposiva < 0)
|
|
{
|
|
const real val = imp-oldiva;
|
|
if (!val.is_zero())
|
|
app().set_cgs_row(-1, val, conto, "", tipod);
|
|
}
|
|
else
|
|
app().add_cgs_imp(oldposiva, imp-oldiva);
|
|
oldiva = imp;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// Handler dello sheet di contabilita'
|
|
// Certified 90%
|
|
bool TPrimanota_application::iva_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k != K_ENTER) return TRUE;
|
|
|
|
real imp;
|
|
for (int r = 0; r < app().ivas().items(); r++)
|
|
{
|
|
TToken_string& row = app().ivas().row(r);
|
|
imp += real(row.get(0)); // imponibile
|
|
row.get(); // IVA
|
|
imp += real(row.get()); // imposta
|
|
}
|
|
|
|
const TMask& m = f.mask();
|
|
real tot(m.get(F_TOTALE));
|
|
tot += real(m.get(F_RITFIS));
|
|
tot += real(m.get(F_RITSOC));
|
|
|
|
if (imp != tot)
|
|
{
|
|
TString16 t(tot.string("."));
|
|
TString16 i(imp.string("."));
|
|
return error_box("La somma del totale documento e delle ritenute (%s) e' diverso dalla "
|
|
"somma degli imponibili e delle imposte (%s)", t, i);
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Handlers dei campi della testata
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
// Handler of the F_NUMREG field on the query mask
|
|
// Certified 90%
|
|
bool TPrimanota_application::num_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (!f.mask().is_running()) return TRUE;
|
|
|
|
if (key == K_TAB && f.get().not_empty())
|
|
{
|
|
if (app().find(1))
|
|
dispatch_e_char(f.parent(), K_SHIFT_ENTER);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// Handler of the F_CODCAUS field on the query mask
|
|
// Certified 90%
|
|
bool TPrimanota_application::caus_query_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (!f.mask().is_running()) return TRUE;
|
|
|
|
if (key == K_TAB && f.focusdirty())
|
|
{
|
|
const int ann = f.mask().get_int(F_ANNOIVA);
|
|
const char* cau = f.get();
|
|
|
|
const TipoIVA i = cau2IVA(cau, ann);
|
|
if (i != iva_errata)
|
|
{
|
|
const bool ok = suspended_handler(f, key);
|
|
if (ok)
|
|
dispatch_e_char(f.parent(), K_INS);
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
// Handler of the F_CODCAUS field on the modify mask
|
|
// Certified 99%
|
|
bool TPrimanota_application::caus_modify_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (f.to_check(key))
|
|
{
|
|
bool ok = suspended_handler(f, key);
|
|
if (!ok) return FALSE;
|
|
|
|
const int ann = f.mask().get_int(F_ANNOIVA);
|
|
const char* cau = f.get();
|
|
TCausale c(cau, ann);
|
|
ok = app().causale().similar(c);
|
|
if (!ok)
|
|
{
|
|
f.error_box("Causale incongruente con quella precedentemente inserita");
|
|
return FALSE;
|
|
}
|
|
app().read_caus(cau, ann);
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// Handler of the F_DATAREG field on the modify mask
|
|
// Certified 70%
|
|
bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key)
|
|
{
|
|
bool ok = TRUE;
|
|
|
|
if (f.to_check(key))
|
|
{
|
|
const TDate dr(f.get()); // Data dell'operazione
|
|
if (dr > TDate(TODAY))
|
|
return f.error_box("La data dell'operazione e' superiore quella di sistema");
|
|
|
|
TMask& m = f.mask();
|
|
const int ae = date2esc(dr); // Anno esercizio
|
|
|
|
if (m.query_mode())
|
|
{
|
|
if (ae == 0) return f.error_box("La data dell'operazione non appartiene a nessun esercizio");
|
|
ok = app().giornale().read(ae);
|
|
if (!ok) return f.error_box("Non esiste il libro giornale dell'esercizio %d", ae);
|
|
}
|
|
if (dr < app().giornale().last_print())
|
|
return f.error_box("La data dell'operazione e' antecedente alla "
|
|
"data di stampa del libro giornale dell'esercizio %d", ae);
|
|
|
|
if (!m.query_mode() && app().iva() != nessuna_iva)
|
|
{
|
|
const int annoiva = m.get_int(F_ANNOIVA);
|
|
if (dr.year() != annoiva)
|
|
{
|
|
TRegistro& reg = app().causale().reg();
|
|
const TString16 codreg(reg.name());
|
|
ok = reg.read(codreg, dr.year());
|
|
if (ok && dr < reg.last_reg())
|
|
warning_box("La data dell'operazione e' antecedente al %s, ultima registrazione "
|
|
"sul registro '%s' del %d",
|
|
reg.last_reg().string(), (const char*)codreg, dr.year());
|
|
}
|
|
}
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
// Handler of the F_DATACOMP field on the modify mask
|
|
// Certified 70%
|
|
bool TPrimanota_application::datacomp_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (!f.to_check(key, TRUE))
|
|
return TRUE;
|
|
|
|
const TDate dc(f.get()); // Data di competenza
|
|
const int ae = date2esc(dc); // Esercizio corrispondente
|
|
TMask& m = f.mask();
|
|
|
|
if (ae)
|
|
{
|
|
if (f.dlg() == F_DATACOMP)
|
|
m.set(F_ANNOES, ae);
|
|
|
|
const TDate dr(m.get(F_DATAREG)); // Data operazione
|
|
int pr; // Esercizio precedente
|
|
const int ar = date2esc(dr, &pr); // Esercizio in corso
|
|
if (ae != ar && ae != pr)
|
|
{
|
|
TString80 e("La data deve appartenere all'esercizio ");
|
|
e << ar;
|
|
if (pr > 0) e << " o al " << pr;
|
|
return f.error_box(e);
|
|
}
|
|
}
|
|
else
|
|
return f.error_box("La data non appartiene a nessun esercizio");
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
// Handler of the F_DATA74TER field on the modify mask
|
|
// Certified 70%
|
|
bool TPrimanota_application::data74ter_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (!f.to_check(key)) return TRUE;
|
|
bool ok = datacomp_handler(f, key);
|
|
if (ok)
|
|
{
|
|
const TDate d74(f.get());
|
|
const TLibro_giornale& g = app().giornale();
|
|
if (d74 < g.last_print())
|
|
{
|
|
ok = f.error_box("La data per il 74/ter e' antecedente alla data di stampa "
|
|
"del libro giornale dell'esercizio %d", g.year());
|
|
}
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
// Handler of the F_CODREG field on the modify mask
|
|
// Certified 99%
|
|
bool TPrimanota_application::reg_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (f.to_check(key, TRUE))
|
|
{
|
|
// if (!suspended_handler(f, key)) return FALSE;
|
|
|
|
const int ai = f.mask().get_int(F_ANNOIVA);
|
|
const char* r = f.get();
|
|
TRegistro reg(r, ai);
|
|
|
|
const TipoIVA i = reg.iva();
|
|
if (i == iva_errata)
|
|
return f.error_box("Tipo registro errato");
|
|
|
|
if (reg.iva() != app().iva())
|
|
{
|
|
const TString16 i1(iva2name(reg.iva()));
|
|
const TString16 i2(iva2name(app().iva()));
|
|
return f.error_box("Tipo registro (%s) incongruente col tipo di registrazione (%s)",
|
|
(const char*)i1, (const char*)i2);
|
|
}
|
|
|
|
const bool av = reg.agenzia_viaggi();
|
|
f.mask().show(F_DATA74TER, av);
|
|
if (!av) f.mask().reset(F_DATA74TER);
|
|
|
|
if (key == K_TAB)
|
|
app().causale().reg() = reg;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool TPrimanota_application::occas_code_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (key == K_TAB)
|
|
{
|
|
const char* code = f.get();
|
|
if (*code)
|
|
{
|
|
TRelation occas(LF_OCCAS);
|
|
occas.lfile()->put("CFPI", code);
|
|
if (occas.read() == NOERR)
|
|
{
|
|
f.mask().autoload(&occas);
|
|
f.mask().send_key(K_TAB, O_COMUNE);
|
|
f.mask().send_key(K_TAB, O_COMUNENAS);
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TPrimanota_application::occas_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (key == K_SPACE && f.mask().is_running())
|
|
{
|
|
TMask& om = app().occas_mask();
|
|
om.run();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
// Crea o aggiorna la riga contabile col totale documento
|
|
// Certified 99%
|
|
void TPrimanota_application::add_cgs_tot(TMask& m)
|
|
{
|
|
// Lettura del conto dalla maschera
|
|
const char tipo = m.get(F_CLIFO)[0];
|
|
int gruppo = m.get_int(F_GRUPPOCLIFO);
|
|
int conto = m.get_int(F_CONTOCLIFO);
|
|
long codice = m.get_long(tipo == 'C' ? F_CLIENTE : F_FORNITORE);
|
|
|
|
// Se l'utente non ha ancora specificato un conto lo prendo dalla prima riga della causale
|
|
if (conto == 0)
|
|
{
|
|
TConto bill; _causale.bill(1, bill);
|
|
gruppo = bill.gruppo(); m.set(F_GRUPPOCLIFO, gruppo);
|
|
conto = bill.conto(); m.set(F_CONTOCLIFO, conto);
|
|
}
|
|
|
|
TConto c(gruppo, conto, codice, tipo);
|
|
real tot(m.get(F_TOTALE));
|
|
|
|
// Creazione/Aggiornamento riga totale
|
|
int pos = type2pos('T');
|
|
pos = set_cgs_row(pos, -imp2sez(tot), c, "Totale documento", 'T');
|
|
|
|
TToken_string& row = ivas().row(0);
|
|
const TCodiceIVA iva(m.get(F_CODIVA));
|
|
if (iva.ok())
|
|
{
|
|
iva_notify(0, K_SPACE);
|
|
const real imposta = scorpora(tot, iva.percentuale());
|
|
row.add(tot.string(), 0);
|
|
row.add(iva.codice(), 1);
|
|
row.add(imposta.string(), 2);
|
|
row.add(" | ");
|
|
|
|
TConto bill; // Conto della prima riga IVA
|
|
const TString& tipo = iva.tipo();
|
|
if (tipo.not_empty())
|
|
{
|
|
if (tipo == "ES") _causale.bill(5, bill); else
|
|
if (tipo == "NI") _causale.bill(6, bill); else
|
|
if (tipo == "NS") _causale.bill(7, bill);
|
|
}
|
|
if (!bill.ok())
|
|
bill.set(m.get_int(F_GRUPPORIC), m.get_int(F_CONTORIC), m.get_long(F_SOTTOCONTORIC));
|
|
if (!bill.ok())
|
|
_causale.bill(2, bill);
|
|
|
|
row.add(bill.string(0x3));
|
|
app().ivas().force_update(0);
|
|
iva_notify(0, K_ENTER);
|
|
}
|
|
}
|
|
|
|
|
|
// Handler of the F_CLIENTE & F_FORNITORE field on the modify mask
|
|
// Certified 99%
|
|
bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (!suspended_handler(f, key))
|
|
return FALSE;
|
|
|
|
if (key == K_TAB && f.focusdirty())
|
|
{
|
|
app().add_cgs_tot(f.mask());
|
|
TLocalisamfile clifo(LF_CLIFO);
|
|
const int alleg = clifo.get_int("ALLEG");
|
|
TEdit_field& upi = (TEdit_field&)f.mask().field(F_RIEPILOGO);
|
|
upi.check_type(alleg == 3 ? CHECK_REQUIRED : CHECK_NORMAL);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// Handler of the F_TOTALE
|
|
// Certified 99%
|
|
bool TPrimanota_application::totale_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (key == K_TAB && f.focusdirty())
|
|
{
|
|
app().add_cgs_tot(f.mask());
|
|
} else
|
|
if (key == K_ENTER && f.get().empty())
|
|
return f.yesno_box("Totale documento nullo: continuare ugualmente?");
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
void TPrimanota_application::add_cgs_rit(bool fiscali)
|
|
{
|
|
const real imp(_msk[2]->get(fiscali ? F_RITFIS : F_RITSOC));
|
|
|
|
const char tipo = fiscali ? 'F' : 'S';
|
|
int pos = type2pos(tipo);
|
|
if (pos < 0)
|
|
{
|
|
const int riga = fiscali ? 8 : 9;
|
|
TConto conto; _causale.bill(riga, conto);
|
|
|
|
TString80 desc("Ritenute ");
|
|
desc << (fiscali ? "fiscali" : "sociali");
|
|
|
|
set_cgs_row(-1, -imp2sez(imp), conto, desc, tipo);
|
|
}
|
|
else
|
|
set_cgs_imp(pos, -imp2sez(imp));
|
|
}
|
|
|
|
|
|
// Handler of the F_RITFIS
|
|
// Certified 99%
|
|
bool TPrimanota_application::ritfis_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (key == K_TAB && f.focusdirty())
|
|
app().add_cgs_rit(TRUE);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// Handler of F_RITSOC
|
|
// Certified 99%
|
|
bool TPrimanota_application::ritsoc_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (key == K_TAB && f.focusdirty())
|
|
app().add_cgs_rit(FALSE);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// Handler of F_VISVAL
|
|
// Certified 90%
|
|
bool TPrimanota_application::visval_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (key == K_SPACE)
|
|
{
|
|
TMask& m = f.mask();
|
|
const real e(f.get() == "X" ? m.get(F_CAMBIO) : "1");
|
|
m.set_exchange(e);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::solaiva_handler(TMask_field& f, KEY key)
|
|
{
|
|
if (key == K_SPACE)
|
|
{
|
|
TMask& m = f.mask();
|
|
const bool anchecg = !m.get_bool(F_SOLAIVA);
|
|
|
|
m.enable_page(2, anchecg);
|
|
app().cgs().enable(anchecg);
|
|
|
|
if (m.is_running() && anchecg)
|
|
{
|
|
TSheet_field& iva = app().ivas();
|
|
const int righe = iva.items();
|
|
TProgind pi(righe, "Generazione righe contabilita'", FALSE, TRUE, 16);
|
|
|
|
app().cgs().reset();
|
|
app().add_cgs_tot(m);
|
|
if (m.get(F_RITFIS).not_empty()) app().add_cgs_rit(TRUE);
|
|
if (m.get(F_RITSOC).not_empty()) app().add_cgs_rit(FALSE);
|
|
|
|
for (int i = 0; i < righe; i++)
|
|
{
|
|
if (!iva.row(i).empty_items())
|
|
{
|
|
iva_notify(i, K_SPACE);
|
|
iva_notify(i, K_ENTER);
|
|
}
|
|
pi.setstatus(i+1);
|
|
}
|
|
app().fill_sheet(m);
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// Fill missing bill
|
|
// Certified 50%
|
|
bool TPrimanota_application::conto_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_ENTER && f.get().empty())
|
|
{
|
|
TMask& m = f.mask();
|
|
if (m.get(101).empty()) return TRUE; // Se non c'e' importo ignora la riga
|
|
|
|
int riga = 0;
|
|
|
|
TString16 cod(m.get(102));
|
|
TTable iva("%IVA");
|
|
iva.put("CODTAB", cod);
|
|
if (iva.read() == NOERR)
|
|
{
|
|
TConto conto;
|
|
cod = iva.get("S1");
|
|
if (cod == "ES") riga = 5; else
|
|
if (cod == "NI") riga = 6; else
|
|
if (cod == "NS") riga = 7; else
|
|
{
|
|
TMask& m = app().mask();
|
|
const char tipocf = m.get(F_CLIFO)[0];
|
|
const long codcf = m.get_long(F_CLIENTE);
|
|
TLocalisamfile clifo(LF_CLIFO);
|
|
clifo.put("TIPOCF", tipocf);
|
|
clifo.put("CODCF", codcf);
|
|
clifo.read(); // Try Jolly bill
|
|
conto.set(clifo.get_int("GRUPPORIC"),
|
|
clifo.get_int("CONTORIC"),
|
|
clifo.get_long("SOTTOCRIC"));
|
|
riga = conto.ok() ? -1 : 2; // else use second row
|
|
}
|
|
if (riga > 0)
|
|
app().causale().bill(riga, conto);
|
|
|
|
if (conto.ok())
|
|
{
|
|
m.set(106, " ");
|
|
m.set(107, conto.gruppo());
|
|
m.set(108, conto.conto());
|
|
m.set(109, conto.sottoconto());
|
|
} else riga = 0;
|
|
}
|
|
|
|
if (riga == 0)
|
|
return f.error_box("Il conto e' obbligatorio sulla riga IVA");
|
|
}
|
|
return TRUE;
|
|
}
|