Gestione del segno Dare Avere delle causali

git-svn-id: svn://10.65.10.50/trunk@157 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1994-09-05 10:57:12 +00:00
parent b22b9d1466
commit a51e2b75ba
9 changed files with 389 additions and 240 deletions

View File

@ -29,76 +29,75 @@ TMask* TPrimanota_application::load_mask(int n)
switch (n) switch (n)
{ {
case 0: case 0:
{
m->set_handler(F_NUMREG, num_handler); m->set_handler(F_NUMREG, num_handler);
m->set_handler(F_CODCAUS, caus_query_handler); m->set_handler(F_CODCAUS, caus_query_handler);
m->set_handler(F_DATAREG, datareg_handler); m->set_handler(F_DATAREG, datareg_handler);
m->set_handler(F_DATACOMP, datacomp_handler); m->set_handler(F_DATACOMP, datacomp_handler);
{
TConfig c(CONFIG_STUDIO, "cg"); TConfig c(CONFIG_STUDIO, "cg");
const bool dr = c.get_bool("PoCuDr"); // Scelta primo campo col focus const bool dr = c.get_bool("PoCuDr"); // Scelta primo campo col focus
m->first_focus(dr ? F_DATAREG : F_CODCAUS); m->first_focus(dr ? F_DATAREG : F_CODCAUS);
}
break;
case 1:
m->set_handler(F_VISVAL, visval_handler);
m->set_handler(F_DESCR, descr_handler);
break;
case 2:
m->set_handler(F_CODREG, reg_handler);
m->set_handler(F_CLIENTE, clifo_handler);
m->set_handler(F_FORNITORE, clifo_handler);
m->set_handler(F_TOTALE, totale_handler);
m->set_handler(F_RITFIS, ritfis_handler);
m->set_handler(F_RITSOC, ritsoc_handler);
m->set_handler(F_VISVAL, visval_handler);
m->set_handler(F_OCCASEDIT, occas_handler);
m->set_handler(F_SOLAIVA, solaiva_handler);
m->set_handler(F_SHEETIVA, iva_handler);
{
TSheet_field& is = (TSheet_field&)m->field(F_SHEETIVA);
is.set_notify(iva_notify);
TMask& ism = is.sheet_mask();
ism.set_handler(101, imponibile_handler);
ism.set_handler(102, codiva_handler);
ism.set_handler(104, imposta_handler);
ism.set_handler(108, conto_handler);
ism.set_handler(109, suspended_handler);
ism.set_handler(209, suspended_handler);
ism.set_handler(309, suspended_handler);
} }
break; break;
case 3: case 1:
m->set_handler(O_CODICE, occas_code_handler); m->set_handler(F_VISVAL, visval_handler);
break; m->set_handler(F_DESCR, descr_handler);
default: break;
CHECKD(0, "Che cavolo di maschera e' la ", n); case 2:
break; {
} m->set_handler(F_CODREG, reg_handler);
if (n == 1 || n == 2) m->set_handler(F_CLIENTE, clifo_handler);
{ m->set_handler(F_FORNITORE, clifo_handler);
m->set_handler(F_DATAREG, datareg_handler); m->set_handler(F_TOTALE, totale_handler);
m->set_handler(F_DATACOMP, datacomp_handler); m->set_handler(F_RITFIS, ritfis_handler);
m->set_handler(F_CODCAUS, caus_modify_handler); m->set_handler(F_RITSOC, ritsoc_handler);
m->set_handler(F_SHEETCG, cg_handler); m->set_handler(F_VISVAL, visval_handler);
{ m->set_handler(F_OCCASEDIT, occas_handler);
TSheet_field& cg = (TSheet_field&)m->field(F_SHEETCG); m->set_handler(F_SOLAIVA, solaiva_handler);
cg.set_notify(cg_notify); m->set_handler(F_SHEETIVA, iva_handler);
TMask& cgm = cg.sheet_mask();
cgm.set_handler(101, dareavere_handler); TSheet_field& is = (TSheet_field&)m->field(F_SHEETIVA);
cgm.set_handler(102, dareavere_handler); is.set_notify(iva_notify);
cgm.set_handler(105, suspended_handler); TMask& ism = is.sheet_mask();
cgm.set_handler(106, suspended_handler); ism.set_handler(101, imponibile_handler);
cgm.set_handler(206, suspended_handler); ism.set_handler(102, codiva_handler);
cgm.set_handler(306, suspended_handler); ism.set_handler(104, imposta_handler);
cgm.set_handler(112, suspended_handler); ism.set_handler(109, suspended_handler);
cgm.set_handler(113, suspended_handler); ism.set_handler(209, suspended_handler);
cgm.set_handler(213, suspended_handler); ism.set_handler(309, suspended_handler);
cgm.set_handler(313, suspended_handler); }
} break;
} case 3:
m->set_handler(O_CODICE, occas_code_handler);
return _msk[n] = m; break;
default:
CHECKD(0, "Che cavolo di maschera e' la ", n);
break;
}
if (n == 1 || n == 2)
{
m->set_handler(F_DATAREG, datareg_handler);
m->set_handler(F_DATACOMP, datacomp_handler);
m->set_handler(F_CODCAUS, caus_modify_handler);
m->set_handler(F_SHEETCG, cg_handler);
TSheet_field& cg = (TSheet_field&)m->field(F_SHEETCG);
cg.set_notify(cg_notify);
TMask& cgm = cg.sheet_mask();
cgm.set_handler(101, dareavere_handler);
cgm.set_handler(102, dareavere_handler);
cgm.set_handler(105, suspended_handler);
cgm.set_handler(106, suspended_handler);
cgm.set_handler(206, suspended_handler);
cgm.set_handler(306, suspended_handler);
cgm.set_handler(112, suspended_handler);
cgm.set_handler(113, suspended_handler);
cgm.set_handler(213, suspended_handler);
cgm.set_handler(313, suspended_handler);
}
return _msk[n] = m;
} }
@ -225,12 +224,6 @@ void TPrimanota_application::init_mask(TMask& m)
if (_iva != nessuna_iva) if (_iva != nessuna_iva)
{ {
/*
TString16 fil; fil = "I0="; fil << (_iva == iva_acquisti ? '2' : '1');
TEdit_field& f = (TEdit_field&)m.field(F_CODREG);
f.browse()->cursor()->filter(fil);
*/
char clig, forg; char clig, forg;
if (_iva == iva_acquisti) if (_iva == iva_acquisti)
{ {
@ -331,9 +324,11 @@ void TPrimanota_application::init_insert_mode(TMask& m)
desc = rcaus->get(RCA_DESC); desc = rcaus->get(RCA_DESC);
const TImporto zero('D', ZERO);
if (iva() == nessuna_iva) if (iva() == nessuna_iva)
{ {
set_cgs_row(-1,ZERO,tc,desc,' '); set_cgs_row(-1,zero,tc,desc,' ');
} }
else else
{ {
@ -349,7 +344,7 @@ void TPrimanota_application::init_insert_mode(TMask& m)
else else
{ {
const char tipo = nriga < 2 ? 'T' : ' '; const char tipo = nriga < 2 ? 'T' : ' ';
set_cgs_row(-1,ZERO,tc,desc,tipo); set_cgs_row(-1,zero,tc,desc,tipo);
if (nriga == 1 && tc.tipo() > ' ' && tc.sottoconto() > 0) if (nriga == 1 && tc.tipo() > ' ' && tc.sottoconto() > 0)
m.set(tc.tipo() == 'C' ? F_CLIENTE : F_FORNITORE, tc.sottoconto()); m.set(tc.tipo() == 'C' ? F_CLIENTE : F_FORNITORE, tc.sottoconto());
@ -374,8 +369,18 @@ bool TPrimanota_application::get_conto(int r, TConto& c) const
} }
int TPrimanota_application::read(TMask& m) bool TPrimanota_application::test_swap(bool ritsoc)
{ {
bool s = FALSE;
const char sez = ritsoc ? causale().sezione_ritsoc() : causale().sezione_clifo();
s = (iva() == iva_vendite) ^ sez == 'D';
return s;
}
int TPrimanota_application::read(TMask& m)
{
m.autoload(_rel); m.autoload(_rel);
if (_iva != nessuna_iva) if (_iva != nessuna_iva)
@ -408,22 +413,23 @@ int TPrimanota_application::read(TMask& m)
_saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); _saldi.set_data_ulmov((TDate)m.get(F_DATAREG));
TToken_string riga(180); TToken_string riga(180);
for (int i = 0; i < _rel->cg_items(); i++) for (int i = 0; i < _rel->cg_items(); i++)
{ {
TRectype& r = _rel->cg(i); TRectype& r = _rel->cg(i);
riga.cut(0); // Vuota la riga riga.cut(0); // Vuota la riga
const real im(r.get_real("IMPORTO"));
const char sezione = toupper(r.get_char("SEZIONE"));
const int rcontr = r.get_int("RCONTR") -1; const int rcontr = r.get_int("RCONTR") -1;
#ifdef DBG #ifdef DBG
if (rcontr < -1 || rcontr >= _rel->cg_items() || rcontr == i) if (rcontr < -1 || rcontr >= _rel->cg_items() || rcontr == i)
error_box("La riga %d non puo' avere per contropartita la %d", i+1, rcontr+1); error_box("La riga %d non puo' avere per contropartita la %d", i+1, rcontr+1);
#endif #endif
const bool dare = sezione == 'D';
riga.add(dare ? im.string() : " "); // Dare 101 const real im(r.get_real("IMPORTO"));
riga.add(dare ? " " : im.string()); // Avere 102 const char sezione = toupper(r.get_char("SEZIONE"));
TImporto import(sezione, im);
import.add_to(riga); // Dare/Avere 101-102
TConto conto; get_conto(i, conto); TConto conto; get_conto(i, conto);
riga.add(conto.string(0x3)); // Conto 103-107 riga.add(conto.string(0x3)); // Conto 103-107
@ -440,11 +446,11 @@ int TPrimanota_application::read(TMask& m)
} }
else riga.add(" | | | | "); else riga.add(" | | | | ");
const char* tipo = r.get("ROWTYPE"); // Tipo di riga 115 const char tipo = r.get_char("ROWTYPE");
riga.add(tipo); riga.add(tipo); // Tipo di riga 115
cgs.row(i) = riga; cgs.row(i) = riga;
disable_cgs_cells(i, *tipo); disable_cgs_cells(i, tipo);
} }
if (_iva == nessuna_iva) if (_iva == nessuna_iva)
@ -456,13 +462,18 @@ int TPrimanota_application::read(TMask& m)
TSheet_field& ivas = (TSheet_field&)m.field(F_SHEETIVA); TSheet_field& ivas = (TSheet_field&)m.field(F_SHEETIVA);
ivas.reset(); ivas.reset();
const bool to_swap = test_swap(FALSE);
for (i = 0; i < _rel->iva_items(); i++) for (i = 0; i < _rel->iva_items(); i++)
{ {
TRectype& r = _rel->iva(i); TRectype& r = _rel->iva(i);
riga.cut(0); riga.cut(0);
real imponibile(r.get("IMPONIBILE"));
if (to_swap) imponibile = -imponibile;
riga.add(imponibile.string()); // Imponibile 101
riga.add(r.get("IMPONIBILE")); // Imponibile 101
riga.add(r.get("CODIVA")); // IVA 102 riga.add(r.get("CODIVA")); // IVA 102
riga.add(r.get("TIPODET")); // Detrazione 103 riga.add(r.get("TIPODET")); // Detrazione 103
riga.add(r.get("IMPOSTA")); // Imposta 104 riga.add(r.get("IMPOSTA")); // Imposta 104
@ -515,40 +526,30 @@ void TPrimanota_application::mask2rel(const TMask& m)
TArray& rows = cgs().rows_array(); TArray& rows = cgs().rows_array();
int cur = 1; int cur = 1;
// Controlla se e' un movimento con righe contabili // Controlla se e' un movimento con righe contabili
if (iva() == nessuna_iva || !m.get_bool(F_SOLAIVA)) if (iva() == nessuna_iva || !m.get_bool(F_SOLAIVA))
{
for (int i = 0; i < rows.items(); i++) for (int i = 0; i < rows.items(); i++)
{ {
TToken_string& row = (TToken_string&)rows[i]; TToken_string& row = (TToken_string&)rows[i];
TImporto n; n = row;
const TConto conto(row, 2, 0x3);
if (conto.ok())
_saldi.aggiorna(conto, n.valore(), n.sezione(), TRUE);
TRectype &r = _rel->cg(cur-1); TRectype &r = _rel->cg(cur-1);
r.zero(); r.zero();
r.put("IMPORTO", n.valore()); // Importo
r.put("SEZIONE", n.sezione()); // Sezione
r.put("NUMREG", numreg); r.put("NUMREG", numreg);
r.put("ANNOES", annoes); r.put("ANNOES", annoes);
r.put("DATAREG", datareg); r.put("DATAREG", datareg);
r.put("NUMRIG", cur); r.put("NUMRIG", cur);
char sezione = 'D';
const char* n = row.get(0);
real val0(n); // Dare
n = row.get();
real val1(n); // Avere
if (val0.is_zero())
{
sezione = 'A';
val0 = val1;
}
r.put("IMPORTO", val0); // Importo
r.put("SEZIONE", sezione); // Sezione
const TConto conto(row, -1, 0x3);
if (conto.ok())
_saldi.aggiorna(conto, val0, sezione, TRUE);
r.put("TIPOC", conto.tipo()); // Conto r.put("TIPOC", conto.tipo()); // Conto
r.put("GRUPPO", conto.gruppo()); r.put("GRUPPO", conto.gruppo());
r.put("CONTO", conto.conto()); r.put("CONTO", conto.conto());
@ -561,7 +562,7 @@ void TPrimanota_application::mask2rel(const TMask& m)
const TConto contro(row, -1, 0x3); // Conto contropartita const TConto contro(row, -1, 0x3); // Conto contropartita
if (contro.ok()) if (contro.ok())
{ {
rcontr = bill2contr(contro, sezione)+1; rcontr = bill2contr(contro, n.sezione())+1;
if (rcontr < 1) if (rcontr < 1)
{ {
warning_box("La riga contabile %d non ha una contropartita", cur); warning_box("La riga contabile %d non ha una contropartita", cur);
@ -569,10 +570,13 @@ void TPrimanota_application::mask2rel(const TMask& m)
} }
} }
r.put("RCONTR", rcontr); // Contropartita r.put("RCONTR", rcontr); // Contropartita
r.put("ROWTYPE", row.get());
const char tipo = row.get_char();
r.put("ROWTYPE", tipo);
cur++; cur++;
} }
}
if (_iva == nessuna_iva) return; if (_iva == nessuna_iva) return;
if (causale().reg().corrispettivi()) if (causale().reg().corrispettivi())
@ -602,6 +606,7 @@ void TPrimanota_application::mask2rel(const TMask& m)
if (err) _rel->lfile()->zero("OCFPI"); if (err) _rel->lfile()->zero("OCFPI");
} }
const bool to_swap = test_swap(FALSE);
TArray& irows = ivas().rows_array(); TArray& irows = ivas().rows_array();
cur = 1; cur = 1;
for (int i = 0; i < irows.items(); i++) for (int i = 0; i < irows.items(); i++)
@ -615,7 +620,11 @@ void TPrimanota_application::mask2rel(const TMask& m)
r.put("ANNOES", annoes); r.put("ANNOES", annoes);
r.put("NUMREG", numreg); r.put("NUMREG", numreg);
r.put("NUMRIG", cur); r.put("NUMRIG", cur);
r.put("IMPONIBILE", row.get(0));
real imponibile(row.get(0));
if (to_swap) imponibile = -imponibile;
r.put("IMPONIBILE", imponibile);
r.put("CODIVA", row.get()); r.put("CODIVA", row.get());
r.put("TIPODET", row.get()); r.put("TIPODET", row.get());
r.put("IMPOSTA", row.get()); r.put("IMPOSTA", row.get());

View File

@ -188,14 +188,14 @@ END
NUMBER F_DARE 17 NUMBER F_DARE 17
BEGIN BEGIN
PROMPT 1 -1 "Saldo Dare " PROMPT 1 -1 "Sbilancio Dare "
FLAGS "DRV" FLAGS "DRV"
PICTURE "." PICTURE "."
END END
NUMBER F_AVERE 17 NUMBER F_AVERE 17
BEGIN BEGIN
PROMPT 40 -1 "Saldo Avere " PROMPT 41 -1 "Sbilancio Avere "
FLAGS "DRV" FLAGS "DRV"
PICTURE "." PICTURE "."
END END

View File

@ -1,9 +1,7 @@
#include "cg2100.h" #include "cg2100.h"
TOOLBAR "" 0 20 0 2 TOOLBAR "" 0 20 0 2
#include <toolbar.h> #include <toolbar.h>
ENDPAGE ENDPAGE
PAGE "OPERAZIONE DI PRIMA NOTA" -1 -1 77 20 PAGE "OPERAZIONE DI PRIMA NOTA" -1 -1 77 20
@ -556,7 +554,7 @@ END
NUMBER F_IMPOSTE 17 NUMBER F_IMPOSTE 17
BEGIN BEGIN
PROMPT 40 11 "Totale imposte " PROMPT 41 11 "Totale imposte "
FLAGS "DRV" FLAGS "DRV"
PICTURE "." PICTURE "."
END END
@ -583,14 +581,14 @@ END
NUMBER F_DARE 17 NUMBER F_DARE 17
BEGIN BEGIN
PROMPT 1 -1 "Saldo Dare " PROMPT 1 -1 "Sbilancio Dare "
FLAGS "DRV" FLAGS "DRV"
PICTURE "." PICTURE "."
END END
NUMBER F_AVERE 17 NUMBER F_AVERE 17
BEGIN BEGIN
PROMPT 40 -1 "Saldo Avere " PROMPT 41 -1 "Sbilancio Avere "
FLAGS "DRV" FLAGS "DRV"
PICTURE "." PICTURE "."
END END

View File

@ -208,53 +208,55 @@ TSheet_field& TPrimanota_application::cgs() const
} }
// 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% // Certified 99%
// Scrive l'importo imp nella opportuna sezione della riga n // Scrive l'importo imp nella opportuna sezione della riga n
void TPrimanota_application::set_cgs_imp(int n, const real& imp) void TPrimanota_application::set_cgs_imp(int n, const TImporto& imp)
{ {
TToken_string& row = cgs().row(n); imp.add_to(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); cgs().force_update(n);
} }
// Legge l'importo della riga n e lo ritorna col segno dovuto // Legge l'importo della riga n e lo ritorna col segno dovuto
// Certified 99% // Certified 99%
real TPrimanota_application::get_cgs_imp(int n) TImporto TPrimanota_application::get_cgs_imp(int n)
{
TImporto importo;
importo = cgs().row(n);
return importo;
}
// Certified 90%
void TPrimanota_application::add_cgs_imp(int n, const TImporto& imp)
{ {
TToken_string& row = cgs().row(n); TImporto tot(get_cgs_imp(n));
const real dare(row.get(0)); tot.set(imp.sezione(), tot.valore() + imp.valore());
if (dare > 0.0) return dare; set_cgs_imp(n, tot);
const real avere(row.get()); }
return -avere;
// Certified 90%
void TPrimanota_application::sub_cgs_imp(int n, const real& imp)
{
TImporto tot(get_cgs_imp(n));
tot.set(tot.sezione(), tot.valore() - imp);
set_cgs_imp(n, tot);
} }
// Certified 90% TImporto TPrimanota_application::real2imp(const real& r, char row_type)
void TPrimanota_application::add_cgs_imp(int n, const real& imp) {
{ bool dare;
const real tot = get_cgs_imp(n) + imp; if (row_type == 'S')
set_cgs_imp(n, tot); {
dare = causale().sezione_ritsoc() == 'D';
}
else
{
dare = causale().sezione_clifo() == 'D';
if (row_type != 'T' && row_type != 'F') dare = !dare;
}
TImporto importo(dare ? 'D' : 'A', r);
return importo;
} }
// Disabilita le celle della riga contabile n in base al suo tipo // Disabilita le celle della riga contabile n in base al suo tipo
@ -290,7 +292,7 @@ void TPrimanota_application::disable_cgs_cells(int n, char tipo)
} }
int TPrimanota_application::set_cgs_row(int n, const real& imp, int TPrimanota_application::set_cgs_row(int n, const TImporto& imp,
TConto& conto, const char* desc, TConto& conto, const char* desc,
char tipo) char tipo)
{ {
@ -298,7 +300,7 @@ int TPrimanota_application::set_cgs_row(int n, const real& imp,
if (n < 0) n = cg.first_empty(); if (n < 0) n = cg.first_empty();
TToken_string& row = cg.row(n); TToken_string& row = cg.row(n);
row = ""; row = "";
set_cgs_imp(n, imp); imp.add_to(row);
row.add(conto.string(0x3)); row.add(conto.string(0x3));
row.add(""); row.add("");
row.add(desc); row.add(desc);
@ -347,8 +349,8 @@ void TPrimanota_application::cgs_pack()
del = TRUE; del = TRUE;
else else
{ {
const real imp = get_cgs_imp(i); const TImporto& imp = get_cgs_imp(i);
if (imp == 0.0) if (imp.valore() == ZERO)
del = TRUE; del = TRUE;
} }
if (del) if (del)
@ -368,24 +370,20 @@ real TPrimanota_application::calcola_saldo() const
for (int i = 0; i < max; i++) for (int i = 0; i < max; i++)
{ {
TToken_string& r = (TToken_string&)rows[i]; TToken_string& r = (TToken_string&)rows[i];
const real dare(r.get(0)); tdare += real(r.get(0));
const real avere(r.get()); tavere += real(r.get());
tdare += dare;
tavere += avere;
} }
real saldo = tdare-tavere; real sbilancio = abs(tdare)-abs(tavere);
switch (saldo.sign()) switch (sbilancio.sign())
{ {
case 1: case 1:
mask().set(F_DARE, saldo.string()); mask().set(F_DARE, (tdare-tavere).string());
mask().reset(F_AVERE); mask().reset(F_AVERE);
break; break;
case -1: case -1:
mask().reset(F_DARE); mask().reset(F_DARE);
saldo = -saldo; mask().set(F_AVERE, (tavere-tdare).string());
mask().set(F_AVERE, saldo.string());
break; break;
default: default:
mask().reset(F_DARE); mask().reset(F_DARE);
@ -393,7 +391,7 @@ real TPrimanota_application::calcola_saldo() const
break; break;
} }
return saldo; return sbilancio;
} }
@ -411,7 +409,7 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k)
return f.error_box("Il movimento e' sbilanciato di %s lire.", ss); return f.error_box("Il movimento e' sbilanciato di %s lire.", ss);
} }
else else
if (app().get_cgs_imp(0) == ZERO) if (app().get_cgs_imp(0).valore() == ZERO)
return f.error_box("Il movimento non ha una prima riga contabile valida!"); return f.error_box("Il movimento non ha una prima riga contabile valida!");
} }
return TRUE; return TRUE;
@ -519,7 +517,12 @@ bool TPrimanota_application::codiva_handler(TMask_field& f, KEY key)
TMask_field& i = f.mask().field(101); TMask_field& i = f.mask().field(101);
i.set_dirty(); i.set_dirty();
return imponibile_handler(i, key); return imponibile_handler(i, key);
} } else
if (key == K_ENTER)
{
if (f.get().empty() && f.mask().get(101).not_empty())
return f.error_box("Codice IVA obbligatorio");
}
return TRUE; return TRUE;
} }
@ -578,73 +581,80 @@ real TPrimanota_application::calcola_imp() const
return imponibili+imposte; return imponibili+imposte;
} }
// Certified 50% // Certified 50%
bool TPrimanota_application::iva_notify(int r, KEY k) bool TPrimanota_application::iva_notify(int r, KEY k)
{ {
static int oldpos; static int oldpos,oldposiva;
static real oldimp; static real oldimp, oldiva;
static int oldposiva;
static real oldiva;
TSheet_field& iva = app().ivas(); TSheet_field& iva = app().ivas();
TToken_string& row = iva.row(r); TToken_string& row = iva.row(r);
if (k == K_SPACE) if (k == K_SPACE)
{ {
const TConto oldconto(row, 5, 0x1); oldimp = real(row.get(0)); // Imponibile 0
oldiva = real(row.get(3)); // Imposta 3
oldposiva = type2pos(detraibile(row.get_int()) ? 'D' : 'N'); // Tipodet 4
const TConto oldconto(row, 5, 0x1); // t/g/c/s 5 6 7 8
oldpos = bill2pos(oldconto, 'I'); oldpos = bill2pos(oldconto, 'I');
oldimp = imp2sez(real(row.get(0)));
oldposiva = type2pos(detraibile(row.get_int(4)) ? 'D' : 'N');
oldiva = imp2sez(real(row.get(3)));
} }
if (k == K_DEL) if (k == K_DEL)
{ {
row.add("0", 0); // Azzera imponibile row.add("0", 0); // Azzera imponibile
row.add("0", 3); // Azzera imposta row.add("0", 3); // Azzera imposta
k = K_ENTER; // Elegante o Sporco trucco k = K_ENTER; // Elegante o Sporco trucco (dipende dai gusti!)
} }
if (k == K_ENTER) if (k == K_ENTER)
{ {
if (oldpos >= 0) // Il conto esisteva anche prima if (oldpos >= 0) // Il conto esisteva anche prima
{ {
app().add_cgs_imp(oldpos, -oldimp); app().sub_cgs_imp(oldpos, oldimp);
oldimp = 0.0;
} }
if (oldposiva >= 0) // Il conto IVA esisteva anche prima if (oldposiva >= 0) // Il conto IVA esisteva anche prima
{ {
app().add_cgs_imp(oldposiva, -oldiva); app().sub_cgs_imp(oldposiva, oldiva);
oldiva = 0.0;
} }
// Aggiorna conto sulla riga contabile // Aggiorna conto sulla riga contabile
real imp = imp2sez(real(row.get(0))); // Imponibile real imp(row.get(0)); // Imponibile
TConto conto(row, 5, 0x3); TConto conto(row, 5, 0x3);
oldpos = bill2pos(conto, 'I'); const int newpos = bill2pos(conto, 'I');
if (oldpos < 0) if (newpos < 0)
app().set_cgs_row(-1, imp-oldimp, conto, "", 'I'); {
const TImporto val(app().real2imp(oldpos >= 0 ? imp-oldimp : imp, 'I'));
if (val.valore() != ZERO)
app().set_cgs_row(-1, val, conto, "", 'I');
}
else else
app().add_cgs_imp(oldpos, imp-oldimp); {
const TImporto val(app().real2imp(imp, 'I'));
app().add_cgs_imp(newpos, val);
}
oldimp = imp; oldimp = imp;
oldpos = newpos;
// Aggiorna conto IVA sulla riga contabile // Aggiorna conto IVA sulla riga contabile
imp = imp2sez(real(row.get(3))); // Imposta imp = real(row.get(3)); // Imposta
const bool detrarre = detraibile(row.get_int(4)); // Determina se IVA detraibile const bool detrarre = detraibile(row.get_int()); // Determina se IVA detraibile
app().causale().bill(detrarre ? 3 : 4, conto); app().causale().bill(detrarre ? 3 : 4, conto);
const char tipod = detrarre ? 'D' : 'N'; const char tipod = detrarre ? 'D' : 'N';
oldposiva = type2pos(tipod); const int newposiva = type2pos(tipod);
if (oldposiva < 0)
if (newposiva < 0)
{ {
const real val = imp-oldiva; const TImporto val(app().real2imp(oldposiva >= 0 ? imp-oldiva : imp, 'I'));
if (!val.is_zero()) if (val.valore() != ZERO)
app().set_cgs_row(-1, val, conto, "", tipod); app().set_cgs_row(-1, val, conto, "", tipod);
} }
else else
app().add_cgs_imp(oldposiva, imp-oldiva); {
const TImporto val(app().real2imp(imp, 'I'));
app().add_cgs_imp(newposiva, val);
}
oldiva = imp; oldiva = imp;
oldposiva = newposiva;
app().calcola_imp(); app().calcola_imp();
app().calcola_saldo(); app().calcola_saldo();
@ -662,9 +672,16 @@ bool TPrimanota_application::iva_handler(TMask_field& f, KEY k)
const real imp = app().calcola_imp(); const real imp = app().calcola_imp();
const TMask& m = f.mask(); const TMask& m = f.mask();
const bool swapt = app().test_swap(FALSE);
const bool swaps = app().test_swap(TRUE);
real tot(m.get(F_TOTALE)); real tot(m.get(F_TOTALE));
tot += real(m.get(F_RITFIS)); tot += real(m.get(F_RITFIS));
tot += real(m.get(F_RITSOC)); if (swapt ^ swaps)
tot -= real(m.get(F_RITSOC));
else
tot += real(m.get(F_RITSOC));
if (imp != tot) if (imp != tot)
{ {
@ -746,29 +763,32 @@ bool TPrimanota_application::caus_modify_handler(TMask_field& f, KEY key)
} }
// Handler of the F_DATAREG field on the modify mask // Handler of the F_DATAREG field
// Certified 70% // Certified 70%
bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key)
{ {
bool ok = TRUE; bool ok = TRUE;
if (f.to_check(key)) if ((key == K_TAB && f.focusdirty()) || key == K_ENTER)
{ {
const TDate dr(f.get()); // Data dell'operazione const TDate dr(f.get()); // Data dell'operazione
if (dr > TDate(TODAY)) if (dr > TDate(TODAY))
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");
TMask& m = f.mask(); TMask& m = f.mask();
const int ae = date2esc(dr); // Anno esercizio
if (m.query_mode()) const int ae = 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() || app().giornale().year() != ae)
ok = app().giornale().read(ae); ok = app().giornale().read(ae);
if (!ok) else
return f.error_box("Non esiste il libro giornale dell'esercizio %d", ae); ok = TRUE;
}
if (!ok)
return f.error_box("Non esiste il libro giornale dell'esercizio %d", ae);
if (dr < app().giornale().last_print()) if (dr < app().giornale().last_print())
return f.error_box("La data dell'operazione e' antecedente alla " return f.error_box("La data dell'operazione e' antecedente alla "
"data di stampa del libro giornale dell'esercizio %d", ae); "data di stampa del libro giornale dell'esercizio %d", ae);
@ -941,12 +961,14 @@ void TPrimanota_application::add_cgs_tot(TMask& m)
real tot(m.get(F_TOTALE)); real tot(m.get(F_TOTALE));
// Creazione/Aggiornamento riga totale // Creazione/Aggiornamento riga totale
int pos = type2pos('T'); const int pos = type2pos('T');
pos = set_cgs_row(pos, -imp2sez(tot), c, "Totale documento", 'T'); set_cgs_row(pos, real2imp(tot, 'T'), c, "Totale documento", 'T');
TToken_string& row = ivas().row(0);
const TCodiceIVA iva(m.get(F_CODIVA)); const TCodiceIVA iva(m.get(F_CODIVA));
if (iva.ok()) TToken_string& row = ivas().row(0);
const real imp(row.get(0));
if (imp == ZERO && iva.ok())
{ {
iva_notify(0, K_SPACE); iva_notify(0, K_SPACE);
const real imposta = scorpora(tot, iva.percentuale()); const real imposta = scorpora(tot, iva.percentuale());
@ -967,7 +989,6 @@ void TPrimanota_application::add_cgs_tot(TMask& m)
bill.set(m.get_int(F_GRUPPORIC), m.get_int(F_CONTORIC), m.get_long(F_SOTTOCONTORIC)); bill.set(m.get_int(F_GRUPPORIC), m.get_int(F_CONTORIC), m.get_long(F_SOTTOCONTORIC));
if (!bill.ok()) if (!bill.ok())
_causale.bill(2, bill); _causale.bill(2, bill);
row.add(bill.tipo(), 5); row.add(bill.tipo(), 5);
row.add(bill.gruppo(), 6); row.add(bill.gruppo(), 6);
row.add(bill.conto(), 7); row.add(bill.conto(), 7);
@ -976,7 +997,7 @@ void TPrimanota_application::add_cgs_tot(TMask& m)
app().ivas().force_update(0); app().ivas().force_update(0);
iva_notify(0, K_ENTER); iva_notify(0, K_ENTER);
} }
} }
@ -1027,10 +1048,10 @@ void TPrimanota_application::add_cgs_rit(bool fiscali)
TString80 desc("Ritenute "); TString80 desc("Ritenute ");
desc << (fiscali ? "fiscali" : "sociali"); desc << (fiscali ? "fiscali" : "sociali");
set_cgs_row(-1, -imp2sez(imp), conto, desc, tipo); set_cgs_row(-1, real2imp(imp, tipo), conto, desc, tipo);
} }
else else
set_cgs_imp(pos, -imp2sez(imp)); set_cgs_imp(pos, real2imp(imp, tipo));
} }
@ -1105,14 +1126,3 @@ bool TPrimanota_application::solaiva_handler(TMask_field& f, KEY key)
} }
// Fill missing bill
// Certified 50%
bool TPrimanota_application::conto_handler(TMask_field& f, KEY k)
{
if (k == K_ENTER && f.get().empty())
{
if (f.mask().get(101).empty()) return TRUE; // Se non c'e' importo ignora la riga
return f.error_box("Il conto e' obbligatorio sulla riga IVA");
}
return TRUE;
}

View File

@ -67,7 +67,6 @@ class TPrimanota_application : public TRelation_application
static bool codiva_handler(TMask_field& f, KEY key); static bool codiva_handler(TMask_field& f, KEY key);
static bool imposta_handler(TMask_field& f, KEY key); static bool imposta_handler(TMask_field& f, KEY key);
static bool dareavere_handler(TMask_field& f, KEY k); static bool dareavere_handler(TMask_field& f, KEY k);
static bool conto_handler(TMask_field& f, KEY key);
static bool iva_notify(int r, KEY key); static bool iva_notify(int r, KEY key);
static bool iva_handler(TMask_field& f, KEY key); static bool iva_handler(TMask_field& f, KEY key);
@ -106,7 +105,6 @@ protected:
TSheet_field& cgs() const; TSheet_field& cgs() const;
TSheet_field& ivas() const; TSheet_field& ivas() const;
static real imp2sez(const real& importo);
static int bill2pos(const TConto& conto, char tipo); static int bill2pos(const TConto& conto, char tipo);
static TipoIVA reg2IVA(const char* registro, int anno); static TipoIVA reg2IVA(const char* registro, int anno);
static TipoIVA cau2IVA(const char* causale, int anno); static TipoIVA cau2IVA(const char* causale, int anno);
@ -123,15 +121,20 @@ protected:
TCausale& causale() { return _causale; } TCausale& causale() { return _causale; }
TLibro_giornale& giornale() { return _giornale; } TLibro_giornale& giornale() { return _giornale; }
void set_cgs_imp(int n, const real& importo); bool test_swap(bool ritsoc);
real get_cgs_imp(int n); TImporto real2imp(const real& r, char tipo);
void add_cgs_imp(int n, const real& importo);
void set_cgs_imp(int n, const TImporto& importo);
TImporto get_cgs_imp(int n);
void add_cgs_imp(int n, const TImporto& importo);
void sub_cgs_imp(int n, const real& imp);
void cgs_pack(); void cgs_pack();
real calcola_saldo() const; real calcola_saldo() const;
real calcola_imp() const; real calcola_imp() const;
void set_ivas_row(int n, const char* codiva, TConto& tc, const char* desc); void set_ivas_row(int n, const char* codiva, TConto& tc, const char* desc);
int set_cgs_row(int n, const real& importo, TConto& conto, const char* desc, char tipo); int set_cgs_row(int n, const TImporto& importo, TConto& conto, const char* desc, char tipo);
void disable_cgs_cells(int n, char tipo); void disable_cgs_cells(int n, char tipo);
void add_cgs_tot(TMask& m); void add_cgs_tot(TMask& m);
void add_cgs_rit(bool fisc); void add_cgs_rit(bool fisc);

View File

@ -203,7 +203,8 @@ TLibro_giornale::TLibro_giornale(int y)
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
TCausale::TCausale(const char* cod, int year) TCausale::TCausale(const char* cod, int year)
: TArray(12), _rec(LF_CAUSALI), _iva(iva_errata) : TArray(12), _rec(LF_CAUSALI), _iva(iva_errata),
_sezione_clifo(' '), _sezione_ritsoc(' ')
{ {
if (*cod) read(cod, year); if (*cod) read(cod, year);
} }
@ -214,9 +215,11 @@ bool TCausale::read(const char* cod, int year)
{ {
destroy(); // Delete all rows destroy(); // Delete all rows
_iva = iva_errata;
_sezione_clifo = _sezione_ritsoc = ' ';
if (*cod > ' ') if (*cod > ' ')
{ {
_iva = iva_errata;
TLocalisamfile caus(LF_CAUSALI); TLocalisamfile caus(LF_CAUSALI);
caus.setkey(1); caus.setkey(1);
@ -299,13 +302,37 @@ bool TCausale::intra() const
bool TCausale::corrval() const bool TCausale::corrval() const
{ return _rec.ok() ? _rec.get_bool("VALINTRA") : FALSE; } { return _rec.ok() ? _rec.get_bool("VALINTRA") : FALSE; }
const char* TCausale::causale_inc_imm() const const char* TCausale::causale_inc_imm() const
{ return _rec.ok() ? _rec.get("CODCAUSIM") : ""; } { return _rec.ok() ? _rec.get("CODCAUSIM") : ""; }
const char* TCausale::tipo_doc() const const char* TCausale::tipo_doc() const
{ return _rec.ok() ? _rec.get("TIPODOC") : ""; } { return _rec.ok() ? _rec.get("TIPODOC") : ""; }
char TCausale::sezione(int riga) const
{
const TRectype& r = row(riga);
char sez = toupper(r.get_char("SEZIONE"));
if (sez <= ' ') // Guess section on tipocf
{
const char tipocf = toupper(row(1).get_char("TIPOCF"));
sez = (tipocf == 'C') ? 'D' : 'A';
}
return sez;
}
char TCausale::sezione_clifo()
{
if (_sezione_clifo == ' ')
_sezione_clifo = sezione(1);
return _sezione_clifo;
}
char TCausale::sezione_ritsoc()
{
if (_sezione_ritsoc == ' ')
_sezione_ritsoc = sezione(9);
return _sezione_ritsoc;
}
TipoIVA TCausale::iva() const TipoIVA TCausale::iva() const
{ {
@ -365,3 +392,68 @@ bool TCodiceIVA::read(const char* cod)
if (err != NOERR) zero(); if (err != NOERR) zero();
return err == NOERR; return err == NOERR;
} }
///////////////////////////////////////////////////////////
// Importo
///////////////////////////////////////////////////////////
const TImporto& TImporto::add_to(TToken_string& s) const
{
const bool dare = sezione() == 'D';
const char* v = valore().string();
s.add(dare ? v : "", 0);
s.add(dare ? "" : v, 1);
return *this;
}
// Cerified 99%
// Ambigous section for ZERO
const TImporto& TImporto::operator =(TToken_string& sv)
{
_valore = real(sv.get(0));
if (_valore == ZERO)
{
_valore = real(sv.get());
_sezione = 'A';
}
else
_sezione = 'D';
return *this;
}
const TImporto& TImporto::set(char s, const real& v)
{
CHECKD(s == 'D' || s == 'A', "Sezione errata per importo: codice ", (int)s);
_sezione = s; _valore = v;
return *this;
}
const TImporto& TImporto::operator += (const TImporto& i)
{
if (_sezione == i._sezione)
_valore += i._valore;
else
_valore -= i._valore;
return *this;
}
const TImporto& TImporto::operator -= (const TImporto& i)
{
if (_sezione == i._sezione)
_valore -= i._valore;
else
_valore += i._valore;
return *this;
}
const TImporto& TImporto::swap()
{
_sezione = (_sezione == 'D') ? 'A' : 'D';
_valore = -_valore;
return *this;
}

View File

@ -9,7 +9,8 @@
#include "conto.h" #include "conto.h"
#endif #endif
enum TipoIVA { enum TipoIVA
{
iva_errata = -1, iva_errata = -1,
nessuna_iva = 0, nessuna_iva = 0,
iva_vendite = 1, iva_vendite = 1,
@ -19,7 +20,6 @@ enum TipoIVA {
const char* iva2name(TipoIVA i); const char* iva2name(TipoIVA i);
class TRegistro : public TObject class TRegistro : public TObject
{ {
bool read_att(); bool read_att();
@ -65,10 +65,12 @@ public:
class TCausale : public TArray class TCausale : public TArray
{ {
TipoIVA _iva;
TRectype _rec; TRectype _rec;
TRegistro _reg; TRegistro _reg;
TipoIVA _iva;
char _sezione_clifo, _sezione_ritsoc;
protected: protected:
const TRectype& row(int num) const; const TRectype& row(int num) const;
@ -91,6 +93,10 @@ public:
virtual bool ok() const { return !_rec.empty(); } virtual bool ok() const { return !_rec.empty(); }
bool similar(const TCausale& c) const; bool similar(const TCausale& c) const;
char sezione(int riga) const;
char sezione_clifo();
char sezione_ritsoc();
bool read(const char* cod, int year); bool read(const char* cod, int year);
TCausale(const char* code = "", int year = 0); TCausale(const char* code = "", int year = 0);
@ -108,4 +114,27 @@ public:
const TString& tipo() const { return get("S1"); } const TString& tipo() const { return get("S1"); }
}; };
class TImporto : public TObject
{
char _sezione;
real _valore;
public:
char sezione() const { return _sezione; }
const real& valore() const { return _valore; }
const TImporto& operator=(const TImporto& i) { return set(i.sezione(), i.valore()); }
const TImporto& operator=(TToken_string& sv);
const TImporto& operator+=(const TImporto& i);
const TImporto& operator-=(const TImporto& i);
const TImporto& swap();
const TImporto& TImporto::normalize() { if (_valore < ZERO) swap(); return *this; }
const TImporto& set(char s, const real& v);
const TImporto& add_to(TToken_string& s) const;
TImporto(char s = 'D', const real& v = ZERO) { set(s, v); }
TImporto(const TImporto& i) : _sezione(i._sezione), _valore(i._valore) {}
};
#endif #endif

View File

@ -94,7 +94,7 @@ BEGIN
ADD RUN cg0 -0 ADD RUN cg0 -0
CHECKTYPE NORMAL CHECKTYPE NORMAL
VALIDATE REQIF_FUNC 2 101 102 VALIDATE REQIF_FUNC 2 101 102
WARNING "Sottoconto inesistente o mancante sulla riga contabile" WARNING "Sottoconto inesistente sulla riga contabile"
END END
NUMBER 206 6 NUMBER 206 6
@ -113,6 +113,7 @@ BEGIN
MESSAGE COPY,106 MESSAGE COPY,106
ADD RUN cg0 -1 ADD RUN cg0 -1
CHECKTYPE NORMAL CHECKTYPE NORMAL
VALIDATE REQIF_FUNC 2 101 102
WARNING "Cliente inesistente sulla riga contabile" WARNING "Cliente inesistente sulla riga contabile"
END END
@ -133,6 +134,7 @@ BEGIN
ADD RUN cg0 -1 ADD RUN cg0 -1
MESSAGE COPY,106 MESSAGE COPY,106
CHECKTYPE NORMAL CHECKTYPE NORMAL
VALIDATE REQIF_FUNC 2 101 102
WARNING "Fornitore inesistente sulla riga contabile" WARNING "Fornitore inesistente sulla riga contabile"
END END

View File

@ -65,6 +65,7 @@ BEGIN
OUTPUT 110 DESCR OUTPUT 110 DESCR
ADD RUN cg0 -0 ADD RUN cg0 -0
CHECKTYPE NORMAL CHECKTYPE NORMAL
VALIDATE REQIF_FUNC 1 101
WARNING "Sottoconto inesistente nella riga IVA" WARNING "Sottoconto inesistente nella riga IVA"
END END
@ -85,6 +86,8 @@ BEGIN
ADD RUN cg0 -1 ADD RUN cg0 -1
FLAGS "G" FLAGS "G"
MESSAGE COPY,109|RESET,105 MESSAGE COPY,109|RESET,105
VALIDATE REQIF_FUNC 1 101
WARNING "Cliente inesistente nella riga IVA"
END END
NUMBER 309 6 NUMBER 309 6
@ -103,6 +106,8 @@ BEGIN
ADD RUN cg0 -1 ADD RUN cg0 -1
FLAGS "G" FLAGS "G"
MESSAGE COPY,109|RESET,105 MESSAGE COPY,109|RESET,105
VALIDATE REQIF_FUNC 1 101
WARNING "Fornitore inesistente nella riga IVA"
END END
STRING 110 50 STRING 110 50
@ -177,6 +182,7 @@ BEGIN
OUTPUT 102 CODTAB OUTPUT 102 CODTAB
OUTPUT 211 S0 OUTPUT 211 S0
CHECKTYPE NORMAL CHECKTYPE NORMAL
VALIDATE REQIF_FUNC 1 101
END END
STRING 211 50 STRING 211 50