Corretta gestione del libro giornale

git-svn-id: svn://10.65.10.50/trunk@3521 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1996-09-05 13:26:56 +00:00
parent fb5f11a162
commit 8246fd8547
4 changed files with 74 additions and 67 deletions

View File

@ -235,7 +235,9 @@ bool TPrimanota_application::read_caus(const char* cod, int year)
const bool nota_credito = is_nota_credito(); const bool nota_credito = is_nota_credito();
const bool show_games = is_pagamento() || nota_credito; const bool show_games = is_pagamento() || nota_credito;
TMask& cgm = cgs().sheet_mask();
TSheet_field& cgsheet = (TSheet_field&)m->field(F_SHEETCG);
TMask& cgm = cgsheet.sheet_mask();
cgm.set_handler(100, show_games ? showpartite_handler : NULL); // bottoncino riga cgm.set_handler(100, show_games ? showpartite_handler : NULL); // bottoncino riga
cgm.enable(100, show_games); cgm.enable(100, show_games);
if (iva == nessuna_iva) if (iva == nessuna_iva)
@ -265,8 +267,8 @@ bool TPrimanota_application::read_caus(const char* cod, int year)
} }
if (ins && !ci_sono_importi()) if (ins && !ci_sono_importi())
{ {
cgs().reset(); cgsheet.reset();
for (int i = 1; i < causale().size(); i++) for (int i = 1; i < causale().size(); i++)
{ {
const TRectype* rcaus = (TRectype*)causale().objptr(i); const TRectype* rcaus = (TRectype*)causale().objptr(i);
@ -313,7 +315,7 @@ bool TPrimanota_application::read_caus(const char* cod, int year)
} }
const int pos = set_cgs_row(-1, zero, tc, desc, tipr); const int pos = set_cgs_row(-1, zero, tc, desc, tipr);
if (sezione > ' ') if (sezione > ' ')
cgs().disable_cell(pos, sezione == 'A' ? 0 : 1); cgsheet.disable_cell(pos, sezione == 'A' ? 0 : 1);
} }
else else
{ {
@ -405,7 +407,7 @@ void TPrimanota_application::on_firm_change()
void TPrimanota_application::on_config_change() void TPrimanota_application::on_config_change()
{ {
TConfig cnf(CONFIG_DITTA); TConfig cnf(CONFIG_DITTA, "cg");
_ges_val = cnf.get_bool("GesVal"); _ges_val = cnf.get_bool("GesVal");
_ges_sal = cnf.get_bool("GesSal"); _ges_sal = cnf.get_bool("GesSal");
_npart_is_prot = cnf.get_bool("RifPro"); _npart_is_prot = cnf.get_bool("RifPro");
@ -624,7 +626,7 @@ int TPrimanota_application::read(TMask& m)
occas_mask().reset(); occas_mask().reset();
const TString16 occode(_rel->lfile().get("OCFPI")); const TString16 occode(_rel->lfile().get("OCFPI"));
occas_mask().set(O_CODICE, occode); occas_mask().set(O_CODICE, occode, TRUE);
const char clifo = _rel->lfile().get_char("TIPO"); const char clifo = _rel->lfile().get_char("TIPO");
if (_iva == iva_acquisti && clifo == 'C') if (_iva == iva_acquisti && clifo == 'C')
@ -806,23 +808,22 @@ void TPrimanota_application::mask2rel(const TMask& m)
{ {
rec.put("TIPO", clifo()); rec.put("TIPO", clifo());
int err = ~NOERR;
if (m.field(F_OCCASEDIT).active()) // Se e' un occasionale if (m.field(F_OCCASEDIT).active()) // Se e' un occasionale
{ {
TRelation occas(LF_OCCAS);
const TMask& om = occas_mask(); const TMask& om = occas_mask();
TRelation occas(LF_OCCAS);
om.autosave(occas); // Salva i dati anagrafici om.autosave(occas); // Salva i dati anagrafici
err = occas.write(); int err = occas.write();
if (err == _isreinsert) if (err == _isreinsert)
err = occas.rewrite(); err = occas.rewrite();
if (err == NOERR) if (err == NOERR)
rec.put("OCFPI", occas_mask().get(O_CODICE)); rec.put("OCFPI", om.get(O_CODICE));
else else
error_box("Errore di scrittura sul file dei clienti/fornitori occasionali: %d", err); error_box("Errore di scrittura sul file dei clienti/fornitori occasionali: %d", err);
} }
if (err) else
rec.zero("OCFPI"); rec.zero("OCFPI");
} }

View File

@ -418,7 +418,8 @@ BEGIN
FLAGS "RU" FLAGS "RU"
GROUP 3 GROUP 3
PICTURE ".5" PICTURE ".5"
CHECKTYPE REQUIRED CHECKTYPE REQUIRED
WARNING "Inserire il cambio o eliminare il codice valuta"
END END
NUMBER F_TOTALE 15 NUMBER F_TOTALE 15

View File

@ -203,8 +203,10 @@ int TPrimanota_application::bill_used(const TBill& conto) const
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
TSheet_field& TPrimanota_application::cgs() const TSheet_field& TPrimanota_application::cgs() const
{ {
TSheet_field& s = (TSheet_field&)curr_mask().field(F_SHEETCG); const TMask* m = _msk[_iva == nessuna_iva ? 1 : 2];
CHECK(m, "Null cgs() mask");
TSheet_field& s = (TSheet_field&)m->field(F_SHEETCG);
return s; return s;
} }
@ -1194,7 +1196,7 @@ void TPrimanota_application::ivas_pack()
bool TPrimanota_application::iva_notify(TSheet_field& iva, int r, KEY k) bool TPrimanota_application::iva_notify(TSheet_field& iva, int r, KEY k)
{ {
static int oldpos,oldposiva; static int oldpos,oldposiva;
static real oldimp, oldiva; static TImporto oldimp, oldiva;
TPrimanota_application& a = app(); TPrimanota_application& a = app();
if (a._as400) if (a._as400)
@ -1205,14 +1207,14 @@ bool TPrimanota_application::iva_notify(TSheet_field& iva, int r, KEY k)
if (k == K_SPACE) if (k == K_SPACE)
{ {
oldimp = real(row.get(0)); // Imponibile oldimp = a.real2imp(real(row.get(0)), 'I'); // Imponibile
oldiva = real(row.get(3)); // Imposta oldiva = a.real2imp(real(row.get(3)), 'I'); // Imposta
if (oldiva.is_zero() && cau.corrispettivi()) // In caso di corrispettivi ... if (oldiva.is_zero() && cau.corrispettivi()) // In caso di corrispettivi ...
{ {
const TString zanicchi(row.get(1)); // Codice IVA const TString zanicchi(row.get(1)); // Codice IVA
const TCodiceIVA i(zanicchi); const TCodiceIVA i(zanicchi);
oldiva = i.scorpora(oldimp); // ... scorpora imposta dall'imponibile oldiva.valore() = i.scorpora(oldimp.valore()); // ... scorpora imposta dall'imponibile
} }
const char tipod = detraibile(row) ? 'D' : 'N'; const char tipod = detraibile(row) ? 'D' : 'N';
@ -1220,12 +1222,12 @@ bool TPrimanota_application::iva_notify(TSheet_field& iva, int r, KEY k)
if (oldposiva < 0 && !oldiva.is_zero()) if (oldposiva < 0 && !oldiva.is_zero())
{ {
const int ri = tipod == 'D' ? 3 : 4; // Calcola riga causale per l'IVA const int ri = tipod == 'D' ? 3 : 4; // Calcola riga causale per l'IVA
TBill c; cau.bill(ri, c); TBill c; cau.bill(ri, c);
if (c.ok()) if (c.ok())
{ {
const TString80 d(cau.desc_agg(ri)); const TString80 d(cau.desc_agg(ri));
oldposiva = a.set_cgs_row(-1, app().real2imp(ZERO, 'I'), c, d, tipod); oldposiva = a.set_cgs_row(-1, a.real2imp(ZERO, 'I'), c, d, tipod);
} }
else else
if (ri == 4) // Se non esiste il conto IVA indetraibile ... if (ri == 4) // Se non esiste il conto IVA indetraibile ...
@ -1260,14 +1262,14 @@ bool TPrimanota_application::iva_notify(TSheet_field& iva, int r, KEY k)
if (oldpos >= 0) // Se il conto esisteva anche prima ... if (oldpos >= 0) // Se il conto esisteva anche prima ...
{ // sottrai il vecchio imponibile { // sottrai il vecchio imponibile
TImporto i(a.get_cgs_imp(oldpos)); TImporto i(a.get_cgs_imp(oldpos));
i.valore() -= oldimp; i -= oldimp;
a.set_cgs_imp(oldpos, i); a.set_cgs_imp(oldpos, i);
if (i.is_zero()) delimp = oldpos; if (i.is_zero()) delimp = oldpos;
} }
if (oldposiva >= 0) // Se conto IVA esisteva anche prima ... if (oldposiva >= 0) // Se conto IVA esisteva anche prima ...
{ // sottrai la vecchia imposta { // sottrai la vecchia imposta
TImporto i(a.get_cgs_imp(oldposiva)); TImporto i(a.get_cgs_imp(oldposiva));
i.valore() -= oldiva; i -= oldiva;
a.set_cgs_imp(oldposiva, i); a.set_cgs_imp(oldposiva, i);
if (i.is_zero()) deliva = oldposiva; if (i.is_zero()) deliva = oldposiva;
} }
@ -1297,6 +1299,8 @@ bool TPrimanota_application::iva_notify(TSheet_field& iva, int r, KEY k)
imposta = 0.0; imposta = 0.0;
} }
const TImporto newimp = a.real2imp(imponibile, 'I');
// Aggiorna conto sulla riga contabile // Aggiorna conto sulla riga contabile
if (newpos < 0) if (newpos < 0)
{ {
@ -1306,24 +1310,22 @@ bool TPrimanota_application::iva_notify(TSheet_field& iva, int r, KEY k)
if (deliva > delimp) deliva--; if (deliva > delimp) deliva--;
} }
const TImporto val(a.real2imp(imponibile, 'I')); if (conto.ok() && !newimp.is_zero()) // Se c'e' imponibile ...
if (conto.ok() && !val.is_zero()) // Se c'e' imponibile ...
{ // crea una nuova riga contabile { // crea una nuova riga contabile
const TString d(cau.desc_agg(2)); const TString d(cau.desc_agg(2));
a.set_cgs_row(-1, val, conto, d, 'I'); a.set_cgs_row(-1, newimp, conto, d, 'I');
} }
} }
else else
{ {
TImporto val(a.real2imp(imponibile, 'I')); const bool empty = a.add_cgs_imp(newpos, newimp);
const bool empty = a.add_cgs_imp(newpos, val);
if (empty) // Se la riga si e' azzerata ... if (empty) // Se la riga si e' azzerata ...
{ // ... cancellala { // ... cancellala
a.reset_cgs_row(newpos); a.reset_cgs_row(newpos);
newpos = -1; newpos = -1;
} }
} }
oldimp = imponibile; oldimp = newimp;
oldpos = newpos; oldpos = newpos;
// Aggiorna conto IVA sulla riga contabile // Aggiorna conto IVA sulla riga contabile
@ -1334,19 +1336,18 @@ bool TPrimanota_application::iva_notify(TSheet_field& iva, int r, KEY k)
if (deliva >= 0 && newposiva != deliva) // E' cambiato il tipo d'imposta if (deliva >= 0 && newposiva != deliva) // E' cambiato il tipo d'imposta
a.reset_cgs_row(deliva); // Azzera il vecchio tipo se necessario a.reset_cgs_row(deliva); // Azzera il vecchio tipo se necessario
const TImporto newiva = a.real2imp(imposta, 'I');
if (newposiva < 0) if (newposiva < 0)
{ {
if (!imposta.is_zero()) // Se c'e' imposta ... if (!imposta.is_zero()) // Se c'e' imposta ...
{ // ... crea nuova riga per l'IVA { // ... crea nuova riga per l'IVA
const TImporto val(a.real2imp(imposta, 'I'));
const TString d(cau.desc_agg(ri)); const TString d(cau.desc_agg(ri));
newposiva = a.set_cgs_row(-1, val, contoiva, d, tipod); newposiva = a.set_cgs_row(-1, newiva, contoiva, d, tipod);
} }
} }
else else
{ {
const TImporto val(a.real2imp(imposta, 'I')); const bool empty = a.add_cgs_imp(newposiva, newiva);
const bool empty = a.add_cgs_imp(newposiva, val);
if (empty) // Se l'imposta si e' azzerata ... if (empty) // Se l'imposta si e' azzerata ...
{ {
a.reset_cgs_row(newposiva); // ... cancellala a.reset_cgs_row(newposiva); // ... cancellala
@ -1354,7 +1355,7 @@ bool TPrimanota_application::iva_notify(TSheet_field& iva, int r, KEY k)
} }
} }
oldiva = imposta; oldiva = newiva;
oldposiva = newposiva; oldposiva = newposiva;
TMask& m = a.curr_mask(); TMask& m = a.curr_mask();
@ -1663,20 +1664,22 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key)
return f.error_box("La data dell'operazione e' superiore quella di sistema"); return f.error_box("La data dell'operazione e' superiore quella di sistema");
TPrimanota_application& a = app(); TPrimanota_application& a = app();
TLibro_giornale& gio = a.giornale();
const int ae = a._esercizi.date2esc(dr); // Codice esercizio
const int ae = a._esercizi.date2esc(dr); // Anno esercizio
if (ae <= 0) if (ae <= 0)
return f.error_box("La data dell'operazione non appartiene a nessun esercizio"); return f.error_box("La data dell'operazione non appartiene a nessun esercizio");
if (m.query_mode() || gio.year() != ae) TLibro_giornale& gio = a.giornale();
ok = gio.read(ae); const int ar = dr.year(); // Anno per registri
if (m.query_mode() || gio.year() != ar)
{
ok = gio.read(ar);
if (!ok)
return f.error_box("Non esiste il libro giornale del %d", ar);
}
else else
ok = TRUE; ok = TRUE;
if (!ok)
return f.error_box("Non esiste il libro giornale dell'esercizio %d", ae);
if (key == K_ENTER || f.focusdirty()) if (key == K_ENTER || f.focusdirty())
{ {
const long numreg = m.get_long(F_NUMREG); const long numreg = m.get_long(F_NUMREG);
@ -1687,26 +1690,26 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key)
if (dr < gio.last_print()) if (dr < gio.last_print())
{ {
f.error_box("La data dell'operazione e' antecedente al %s,\n" f.error_box("La data dell'operazione e' antecedente al %s,\n"
"ultima stampa del libro giornale dell'esercizio %d", "ultima stampa del libro giornale del %d",
gio.last_print().string(), ae); gio.last_print().string(), ar);
if (error) return FALSE; if (error) return FALSE;
} }
if (key == K_TAB && dr < gio.last_reg()) if (key == K_TAB && dr < gio.last_reg())
f.warning_box("La data dell'operazione e' antecedente al %s,\n" f.warning_box("La data dell'operazione e' antecedente al %s,\n"
"ultima registrazione sul libro giornale dell'esercizio %d", "ultima registrazione sul libro giornale del %d",
gio.last_reg().string(), ae); gio.last_reg().string(), ar);
} }
if (m.query_mode()) if (m.query_mode())
a.read_caus(m.get(F_CODCAUS), dr.year()); a.read_caus(m.get(F_CODCAUS), ar);
TRegistro& reg = a.causale().reg(); TRegistro& reg = a.causale().reg();
const TString codreg(reg.name()); const TString codreg(reg.name());
if (codreg.not_empty()) if (codreg.not_empty())
{ {
if (reg.year() != dr.year()) if (reg.year() != ar)
{ {
const bool ok = reg.read(codreg, dr.year()); const bool ok = reg.read(codreg, ar);
if (!ok) return FALSE; if (!ok) return FALSE;
a.read_caus(NULL, 0); a.read_caus(NULL, 0);
if (a.iva() != nessuna_iva) if (a.iva() != nessuna_iva)
@ -1718,14 +1721,14 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key)
if (dr < reg.last_print()) if (dr < reg.last_print())
{ {
f.error_box("La data dell'operazione e' antecedente al %s,\n" f.error_box("La data dell'operazione e' antecedente al %s,\n"
"ultima stampa del registro '%s' dell'anno %d", "ultima stampa del registro '%s' del %d",
reg.last_print().string(), (const char*)codreg, dr.year()); reg.last_print().string(), (const char*)codreg, ar);
if (error) return FALSE; if (error) return FALSE;
} }
if (key == K_TAB && dr < reg.last_reg()) if (key == K_TAB && dr < reg.last_reg())
f.warning_box("La data dell'operazione e' antecedente al %s,\n" f.warning_box("La data dell'operazione e' antecedente al %s,\n"
"ultima registrazione sul registro '%s' dell'anno %d", "ultima registrazione sul registro '%s' del %d",
reg.last_reg().string(), (const char*)codreg, dr.year()); reg.last_reg().string(), (const char*)codreg, ar);
} }
if (reg.iva() != nessuna_iva && a._rel->controlla_liquidazione(dr, reg) == TRUE) if (reg.iva() != nessuna_iva && a._rel->controlla_liquidazione(dr, reg) == TRUE)
@ -1856,16 +1859,16 @@ bool TPrimanota_application::datadoc_handler(TMask_field& f, KEY key)
bool TPrimanota_application::occas_code_handler(TMask_field& f, KEY key) bool TPrimanota_application::occas_code_handler(TMask_field& f, KEY key)
{ {
if (key == K_TAB) TMask& m = f.mask();
if (key == K_TAB && (f.dirty() || !m.is_running()))
{ {
const char* code = f.get(); const TString& code = f.get();
if (*code) if (code.not_empty())
{ {
TRelation occas(LF_OCCAS); TRelation occas(LF_OCCAS);
occas.curr().put("CFPI", code); occas.curr().put("CFPI", code);
if (occas.read(_isequal) == NOERR) if (occas.read(_isequal) == NOERR)
{ {
TMask& m = f.mask();
m.autoload(occas); m.autoload(occas);
m.send_key(K_TAB, O_COMUNE); // Forza decodifica comuni m.send_key(K_TAB, O_COMUNE); // Forza decodifica comuni
m.send_key(K_TAB, O_COMUNENAS); m.send_key(K_TAB, O_COMUNENAS);
@ -2401,9 +2404,9 @@ bool TPrimanota_application::corrvaluta_handler(TMask_field& f, KEY key)
bool TPrimanota_application::activate_numrif(bool init_pag) bool TPrimanota_application::activate_numrif(bool init_pag)
{ {
CHECK(iva() != nessuna_iva, "Non esiste il numero riferimento in questa maschera!"); CHECK(_msk[2] != NULL, "Null saldaconto mask");
TMask& m = curr_mask(); TMask& m = *_msk[2];
bool shown = is_saldaconto(); // Il numero riferimento esiste bool shown = is_saldaconto(); // Il numero riferimento esiste
if (shown) if (shown)

View File

@ -227,11 +227,13 @@ bool TLibro_giornale::read(int y)
TString16 anno; anno.format("%04d", y); TString16 anno; anno.format("%04d", y);
TTable reg("REG"); TTable reg("REG");
reg.setkey(1); reg.setkey(1);
reg.put("CODTAB", anno); // Cerca il primo registro dell'anno y reg.put("CODTAB", anno); // Cerca il primo registro dell'anno
for (int err = reg.read(_isgteq); err == NOERR; err = reg.next()) for (int err = reg.read(_isgteq); err == NOERR; err = reg.next())
{ {
//if (reg.get("CODTAB").compare(anno, 4) != 0) break; if (reg.get("CODTAB").compare(anno, 4) != 0)
break; // Sono arrivato all'anno dopo
if (reg.get_int("I0") == libro_giornale) if (reg.get_int("I0") == libro_giornale)
{ {
found = TRUE; found = TRUE;
@ -337,7 +339,7 @@ bool TCausale::read(const char* cod, int year)
const TString codreg(caus.get(CAU_REG)); const TString codreg(caus.get(CAU_REG));
const bool ok = _reg.read(codreg, year); // Read register const bool ok = _reg.read(codreg, year); // Read register
if (!ok && codreg.not_empty()) if (!ok && codreg.not_empty())
return error_box("Non esiste il registro '%s' per l'anno %d", return error_box("Non esiste il registro '%s' del %d",
(const char*)codreg, year); (const char*)codreg, year);
calcIVA(); calcIVA();
} }