Gestione prima nota con TRecord_array

Corretta contropartita fantasma della prima riga


git-svn-id: svn://10.65.10.50/trunk@1281 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1995-04-20 14:29:00 +00:00
parent 580a95fa86
commit d0483278e1
19 changed files with 5789 additions and 5801 deletions

View File

@ -312,12 +312,10 @@ bool TPrimanota_application::read_caus(const char* cod, int year)
if (iva == nessuna_iva) if (iva == nessuna_iva)
{ {
char tipr = ' '; char tipr = ' ';
if (_is_saldaconto) if (_is_saldaconto)
{ {
// non si cagano gli importi totali if (nriga < 8) continue; // non si cagano gli importi totali
if (nriga < 8) continue;
switch(nriga) switch(nriga)
{ {
case 8: case 8:
@ -611,38 +609,28 @@ int TPrimanota_application::read(TMask& m)
_saldi.set_num_ulmov(m.get_long(F_NUMREG)); _saldi.set_num_ulmov(m.get_long(F_NUMREG));
_saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); _saldi.set_data_ulmov((TDate)m.get(F_DATAREG));
TToken_string riga(255);
for (int i = 0; i < _rel->cg_items(); i++) for (int i = 0; i < _rel->cg_items(); i++)
{ {
const TRectype& r = _rel->cg(i); const TRectype& r = _rel->cg(i);
riga.cut(0); // Vuota la riga TToken_string& riga = cgs().row(i); // Vuota la riga
const char sezione = toupper(r.get_char("SEZIONE")); TImporto import(r.get_char("SEZIONE"), r.get_real("IMPORTO"));
const real im(r.get_real("IMPORTO"));
TImporto import(sezione, im);
import.add_to(riga); // Dare/Avere 101-102 import.add_to(riga); // Dare/Avere 101-102
TBill conto; conto.get(r); TBill conto; conto.get(r);
riga.add(conto.string(0x3)); // Conto 103-107 riga.add(conto.string(0x3)); // Conto 103-107
_saldi.aggiorna(conto, im, sezione, FALSE);
_saldi.aggiorna(conto, import, FALSE);
riga.add(""); // Codice descrizione 108 riga.add(""); // Codice descrizione 108
riga.add(r.get("DESCR")); // Descrizione riga 109 riga.add(r.get("DESCR")); // Descrizione riga 109
conto.set(r.get_int("GRUPPOC"), r.get_int("CONTOC"), conto.get(r, TRUE);
r.get_long("SOTTOCONTC"), r.get_char("TIPOCC"));
riga.add(conto.string(0x3)); // Contropartita 110-114 riga.add(conto.string(0x3)); // Contropartita 110-114
riga.add(r.get("NUMGIO")); riga.add(r.get("NUMGIO"));
const char tipo = r.get_char("ROWTYPE"); const char tipo = r.get_char("ROWTYPE");
riga.add(tipo); // Tipo di riga 115 riga.add(tipo); // Tipo di riga 115
if (iva() == nessuna_iva && tipo > ' ')
error_box("Riga %d con tipo incompatibile con un movimento puramente contabile", i+1);
cgs().row(i) = riga;
disable_cgs_cells(i, tipo); disable_cgs_cells(i, tipo);
} }
@ -663,7 +651,7 @@ int TPrimanota_application::read(TMask& m)
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); TToken_string& riga = ivas().row(i);
real imponibile(r.get("IMPONIBILE")); real imponibile(r.get("IMPONIBILE"));
if (to_swap) imponibile = -imponibile; if (to_swap) imponibile = -imponibile;
@ -684,8 +672,6 @@ int TPrimanota_application::read(TMask& m)
TBill c; c.get(r); TBill c; c.get(r);
c.add_to(riga, 4, 0x7); // Conto 105-110 c.add_to(riga, 4, 0x7); // Conto 105-110
ivas().row(i) = riga;
} }
TString16 dt(m.get(F_DATAREG)); TString16 dt(m.get(F_DATAREG));
@ -709,10 +695,10 @@ void TPrimanota_application::mask2rel(const TMask& m)
_saldi.set_movprovv(m.get_bool(F_PROVVISORIO)); _saldi.set_movprovv(m.get_bool(F_PROVVISORIO));
_saldi.set_movap(causale().apertura()); _saldi.set_movap(causale().apertura());
_saldi.set_anno_es(annoes); _saldi.set_anno_es(annoes);
_saldi.set_num_ulmov(m.get_long(F_NUMREG)); _saldi.set_num_ulmov(numreg);
_saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); _saldi.set_data_ulmov((TDate)m.get(F_DATAREG));
_rel->destroy_rows(); // Destroy all records _rel->destroy_rows(numreg); // Destroy all records
cgs_pack(); // Destroy all null rows cgs_pack(); // Destroy all null rows
TArray& rows = cgs().rows_array(); TArray& rows = cgs().rows_array();
@ -726,7 +712,7 @@ void TPrimanota_application::mask2rel(const TMask& m)
TImporto n; n = row; TImporto n; n = row;
const TBill conto(row, 2, 0x3); const TBill conto(row, 2, 0x3);
_saldi.aggiorna(conto, n.valore(), n.sezione(), TRUE); _saldi.aggiorna(conto, n, TRUE);
TRectype &r = _rel->cg(i); TRectype &r = _rel->cg(i);
r.zero(); r.zero();
@ -875,6 +861,11 @@ int TPrimanota_application::write(const TMask& m)
genera_incasso(causimm); genera_incasso(causimm);
} }
} }
else
{
if (_is_saldaconto)
_partite.write();
}
} }
return err; return err;
} }
@ -889,8 +880,14 @@ int TPrimanota_application::rewrite(const TMask& m)
_saldi.registra(); _saldi.registra();
check_saldi(); check_saldi();
} }
if (_is_saldaconto && iva() != nessuna_iva)
if (_is_saldaconto)
{
if (iva() != nessuna_iva)
write_scadenze(m); write_scadenze(m);
else
_partite.rewrite();
}
return err; return err;
} }
@ -902,8 +899,12 @@ bool TPrimanota_application::remove()
{ {
_saldi.registra(); _saldi.registra();
check_saldi(); check_saldi();
if (_is_saldaconto && iva() == nessuna_iva)
{
// TBI _partite.remove();
}
} }
// TBI eliminazione partita
return ok; return ok;
} }
@ -1060,9 +1061,8 @@ void TPrimanota_application::genera_incasso(const char* causimm)
{ {
const TRectype& rec = inc.cg(r); const TRectype& rec = inc.cg(r);
TBill c; c.get(rec); TBill c; c.get(rec);
const real im(rec.get("IMPORTO")); const TImporto im(rec.get_char("SEZIONE"), rec.get_real("IMPORTO"));
const char sezione = rec.get_char("SEZIONE"); _saldi.aggiorna(c, im, TRUE);
_saldi.aggiorna(c, im, sezione, TRUE);
} }
_saldi.registra(); _saldi.registra();
check_saldi(); check_saldi();

View File

@ -112,7 +112,7 @@ STRING F_TIPODOC 2
BEGIN BEGIN
PROMPT 60 6 "Tipo documento " PROMPT 60 6 "Tipo documento "
FIELD TIPODOC FIELD TIPODOC
FLAGS "D" FLAGS "DG"
MESSAGE COPY,K_TIPODOC MESSAGE COPY,K_TIPODOC
END END
@ -341,7 +341,6 @@ END
STRING K_TIPODOC 2 STRING K_TIPODOC 2
BEGIN BEGIN
PROMPT 60 6 "Tipo documento " PROMPT 60 6 "Tipo documento "
FIELD TIPODOC
FLAGS "D" FLAGS "D"
END END

View File

@ -4,12 +4,18 @@ TOOLBAR "" 0 20 0 2
BUTTON DLG_OK 10 2 BUTTON DLG_OK 10 2
BEGIN BEGIN
PROMPT -12 -1 "" PROMPT -13 -1 ""
END
BUTTON DLG_DELREC 10 2
BEGIN
PROMPT -23 -1 "~Elimina"
MESSAGE EXIT,K_DEL
END END
BUTTON DLG_CANCEL 10 2 BUTTON DLG_CANCEL 10 2
BEGIN BEGIN
PROMPT -22 -1 "" PROMPT -33 -1 ""
END END
ENDPAGE ENDPAGE
@ -132,9 +138,11 @@ BEGIN
FIELD RITENUTE FIELD RITENUTE
END END
BOOLEAN S_SALDOACC LIST S_SALDOACC 1 12
BEGIN BEGIN
PROMPT 2 9 "Saldo " PROMPT 2 9 "Saldo "
ITEM "A|Acconto"
ITEM "S|Saldo"
FIELD SALACC FIELD SALACC
END END
@ -199,14 +207,14 @@ BEGIN
ITEM " |Conto" ITEM " |Conto"
ITEM "C|Cliente" ITEM "C|Cliente"
ITEM "F|Fornitore" ITEM "F|Fornitore"
FIELD TIPOCF FIELD TIPOC
FLAGS "H" FLAGS "H"
END END
NUMBER S_GRUPPO 3 NUMBER S_GRUPPO 3
BEGIN BEGIN
PROMPT 24 12 "Gruppo " PROMPT 24 12 "Gruppo "
FIELD GRUPPO FIELD GRUPPOC
CHECKTYPE REQUIRED CHECKTYPE REQUIRED
FLAGS "R" FLAGS "R"
END END
@ -214,7 +222,7 @@ END
NUMBER S_CONTO 3 NUMBER S_CONTO 3
BEGIN BEGIN
PROMPT 42 12 "Conto " PROMPT 42 12 "Conto "
FIELD CONTO FIELD CONTOC
CHECKTYPE REQUIRED CHECKTYPE REQUIRED
FLAGS "R" FLAGS "R"
END END
@ -222,7 +230,7 @@ END
NUMBER S_SOTTOCONTO 6 NUMBER S_SOTTOCONTO 6
BEGIN BEGIN
PROMPT 57 12 "Sottoconto " PROMPT 57 12 "Sottoconto "
FIELD SOTTOCONTO FIELD SOTTOCONTC
USE LF_PCON USE LF_PCON
INPUT GRUPPO S_GRUPPO INPUT GRUPPO S_GRUPPO
INPUT CONTO S_CONTO INPUT CONTO S_CONTO

View File

@ -1,7 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <applicat.h>
#include <tabutil.h> #include <tabutil.h>
#include <prefix.h>
#include <utility.h> #include <utility.h>
#include "cg2101.h" #include "cg2101.h"
@ -36,64 +36,46 @@ int date2esc(const TDate& d, int* prevesc)
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
TMovimentoPN::TMovimentoPN() TMovimentoPN::TMovimentoPN()
: TRelation(LF_MOV), _oldcg(0), _oldiva(0) : TRelation(LF_MOV), _cg(LF_RMOV, "NUMRIG"), _iva(LF_RMOVIVA, "NUMRIG")
{ {
add(LF_RMOV, "NUMREG=NUMREG"); add(LF_RMOV, "NUMREG=NUMREG");
add(LF_RMOVIVA, "NUMREG=NUMREG"); add(LF_RMOVIVA, "NUMREG=NUMREG");
} }
void TMovimentoPN::destroy_rows() void TMovimentoPN::destroy_rows(long num)
{ {
_cg.destroy(); _cg.destroy_rows();
_iva.destroy(); _cg.renum_key("NUMREG", num);
_iva.destroy_rows();
_iva.renum_key("NUMREG", num);
} }
TRectype& TMovimentoPN::cg(int i) TRectype& TMovimentoPN::cg(int i)
{ {
TRectype* r = (TRectype*)_cg.objptr(i); return _cg.row(i >= 0 ? i+1 : -1, TRUE);
if (r == NULL)
{
r = new TRectype(LF_RMOV);
_cg.add(r, i);
}
return *r;
} }
TRectype& TMovimentoPN::iva(int i) TRectype& TMovimentoPN::iva(int i)
{ {
TRectype* r = (TRectype*)_iva.objptr(i); return _iva.row(i >= 0 ? i+1 : -1, TRUE);
if (r == NULL)
{
r = new TRectype(LF_RMOVIVA);
_iva.add(r, i);
} }
return *r;
}
int TMovimentoPN::read_mov_rows() int TMovimentoPN::read_mov_rows()
{ {
const TLocalisamfile& rm = lfile(LF_RMOV); const long numreg = lfile().get_long(MOV_NUMREG);
const TLocalisamfile& ri = lfile(LF_RMOVIVA);
position_rels();
destroy_rows(); TRectype cgfilter(LF_RMOV);
for(bool ok = is_first_match(LF_RMOV); ok; ok = next_match(LF_RMOV)) cgfilter.zero();
{ cgfilter.put(RMV_NUMREG, numreg);
const int row = rm.get_int(RMV_NUMRIG) - 1; _cg.read(cgfilter);
cg(row) = rm.curr();
}
_oldcg = cg_items();
for(ok = is_first_match(LF_RMOVIVA); ok; ok = next_match(LF_RMOVIVA)) TRectype ivafilter(LF_RMOVIVA);
{ ivafilter.zero();
const int row = ri.get_int(RMI_NUMRIG) - 1; ivafilter.put(RMI_NUMREG, numreg);
iva(row) = ri.curr(); _iva.read(ivafilter);
}
_oldiva = iva_items();
return NOERR; return _cg.rows();
} }
@ -103,49 +85,18 @@ int TMovimentoPN::read(TIsamop op, TReclock lockop, TDate& atdate)
if (err == NOERR) if (err == NOERR)
{ {
_olddate = file().get("DATAREG"); _olddate = file().get("DATAREG");
err = read_mov_rows(); read_mov_rows();
} }
return err; return err;
} }
int TMovimentoPN::write_rec(bool re, const TRectype& rec, TLocalisamfile& f)
{
const bool scrivi = re ? (f.rewrite(rec) != NOERR) : TRUE;
if (scrivi)
f.write(rec);
#ifdef TRC
const long numreg = rec.get_long("NUMREG");
const int numrig = f.num() == LF_MOV ? 0 : rec.get_int("NUMRIG");
TRACE("write file=%d record=%ld nummov=%ld numrig=%d status=%d",
f.num(), f.recno(), numreg, numrig, f.status());
#endif
return f.status();
}
int TMovimentoPN::cancella(TLocalisamfile& f, int da, int a)
{
const long numreg = lfile().get_long(MOV_NUMREG);
for (int i = da; i <= a; i++)
{
f.put(MOV_NUMREG, numreg);
f.put(RMV_NUMRIG, i);
if (f.read(_isequal, _lock) == NOERR)
f.remove();
}
return f.status();
}
char TMovimentoPN::frequenza_versamenti(int year) const char TMovimentoPN::frequenza_versamenti(int year) const
{ {
static int last_year = 0; static int last_year = 0;
static long last_firm = 0; static long last_firm = 0;
static char last_freq = ' '; static char last_freq = ' ';
const long firm = main_app().get_firm(); const long firm = prefix().get_codditta();
if (firm != last_firm || year != last_year) if (firm != last_firm || year != last_year)
{ {
@ -161,8 +112,10 @@ char TMovimentoPN::frequenza_versamenti(int year) const
} }
else else
last_freq = lia.get_char("S7"); last_freq = lia.get_char("S7");
last_firm = firm;
CHECK(last_freq == 'M' || last_freq == 'T', "Frequenza versamenti IVA assurda"); CHECK(last_freq == 'M' || last_freq == 'T', "Frequenza versamenti IVA assurda");
last_firm = firm;
last_year = year;
} }
return last_freq; return last_freq;
@ -207,38 +160,27 @@ bool TMovimentoPN::controlla_liquidazione(const TDate& data, bool reset) const
int TMovimentoPN::registra(bool re, bool force) int TMovimentoPN::registra(bool re, bool force)
{ {
TLocalisamfile& m = lfile(); int err = re ? TRelation::rewrite(force) : TRelation::write(force);
if (err != NOERR)
const int err = write_rec(re, m.curr(), m); return err;
if (err != NOERR) return err;
TLocalisamfile& rm = lfile(LF_RMOV);
TLocalisamfile& ri = lfile(LF_RMOVIVA);
const TRectype& m = lfile().curr();
const long numreg = m.get_long("NUMREG"); const long numreg = m.get_long("NUMREG");
for (int i = 0 ; i < cg_items(); i++) if (!re)
{ _cg.renum_key("NUMREG", numreg);
if (!re) cg(i).put("NUMREG", numreg); err = _cg.write(re);
const int err = write_rec(re, cg(i), rm); if (err != NOERR)
if (!force && err != NOERR) return err; return err;
}
if (i < _oldcg)
cancella(rm, i+1, _oldcg);
_oldcg = cg_items();
const int annoiva = m.get_int("ANNOIVA"); const int annoiva = m.get_int("ANNOIVA");
const TString16 reg(m.get("REG")); const TString16 reg(m.get_str("REG"));
TRegistro registro(reg, annoiva); TRegistro registro(reg, annoiva);
const bool att_mista = reg.empty() ? FALSE : registro.attivita_mista(); const bool att_mista = reg.empty() ? FALSE : registro.attivita_mista();
for (i = 0 ; i < iva_items(); i++) for (int i = 0 ; i < iva_items(); i++)
{ {
TRectype& r = iva(i); TRectype& r = iva(i);
if (!re) r.put("NUMREG", numreg); // Force correct number
int tipoatt = 1; int tipoatt = 1;
if (att_mista) if (att_mista)
{ {
@ -250,14 +192,14 @@ int TMovimentoPN::registra(bool re, bool force)
} }
} }
r.put("TIPOATT", tipoatt); r.put("TIPOATT", tipoatt);
const int err = write_rec(re, r, ri);
if (!force && err != NOERR) return err;
} }
if (i < _oldiva) if (!re)
cancella(ri, i+1, _oldiva); _iva.renum_key("NUMREG", numreg);
_oldiva = iva_items(); err = _iva.write(re);
if (err != NOERR)
return err;
// Aggiorna data registrazione e protocollo IVA sul registro // Aggiorna data registrazione e protocollo IVA sul registro
const TDate datareg(m.get("DATAREG")); const TDate datareg(m.get("DATAREG"));
@ -265,7 +207,8 @@ int TMovimentoPN::registra(bool re, bool force)
{ {
const long protiva = m.get_long("PROTIVA"); const long protiva = m.get_long("PROTIVA");
const long uprotiva = m.get_long("UPROTIVA"); const long uprotiva = m.get_long("UPROTIVA");
registro.update(max(protiva, uprotiva), datareg); const long max = protiva > uprotiva ? protiva : uprotiva;
registro.update(max, datareg);
} }
// Aggiorna flags di ricalcolo liquidazione // Aggiorna flags di ricalcolo liquidazione
@ -301,12 +244,7 @@ int TMovimentoPN::registra(bool re, bool force)
int TMovimentoPN::write(bool force, TDate&) int TMovimentoPN::write(bool force, TDate&)
{ {
const TRectype& r = lfile().curr(); return registra(FALSE, force);
_oldcg = _oldiva = 0;
int err = registra(FALSE, force);
return err;
} }
@ -318,14 +256,14 @@ int TMovimentoPN::rewrite(bool force, TDate&)
int TMovimentoPN::remove(TDate&) int TMovimentoPN::remove(TDate&)
{ {
TLocalisamfile& m = lfile(); int err = TRelation::remove();
TLocalisamfile& rm = lfile(LF_RMOV);
TLocalisamfile& ri = lfile(LF_RMOVIVA);
cancella(rm, 1, _oldcg); if (err == NOERR)
cancella(ri, 1, _oldiva); err = _cg.remove();
m.remove();
_oldcg = _oldiva = 0; if (err == NOERR)
return m.status(); err = _iva.remove();
return err;
} }

View File

@ -13,15 +13,13 @@ class TMovimentoPN : public TRelation
// @END // @END
// @DPRIV // @DPRIV
TArray _cg, _iva; TRecord_array _cg, _iva;
int _oldcg, _oldiva;
TDate _olddate; TDate _olddate;
// @END // @END
protected: protected:
// @FPROT // @FPROT
int write_rec(bool re, const TRectype&r, TLocalisamfile& f);
int cancella(TLocalisamfile& f, int da, int a);
int registra(bool re, bool force); int registra(bool re, bool force);
int read_mov_rows(); int read_mov_rows();
// @END // @END
@ -40,9 +38,9 @@ public:
TRectype& cg(int i); TRectype& cg(int i);
TRectype& iva(int i); TRectype& iva(int i);
int cg_items() const { return _cg.items(); } int cg_items() const { return _cg.rows(); }
int iva_items() const { return _iva.items(); } int iva_items() const { return _iva.rows(); }
void destroy_rows(); void destroy_rows(long numreg);
int date2liq(const TDate& data) const; // Estrae dalla data il mese di liquidazione int date2liq(const TDate& data) const; // Estrae dalla data il mese di liquidazione
char frequenza_versamenti(int year) const; // Ritorna 'M'ensile o 'T'rimestrale char frequenza_versamenti(int year) const; // Ritorna 'M'ensile o 'T'rimestrale

View File

@ -1,7 +1,7 @@
#include <progind.h> #include <progind.h>
#include <tabutil.h> #include <tabutil.h>
#include <urldefid.h>
#include <utility.h> #include <utility.h>
#include <defmask.h>
#include "cg2100.h" #include "cg2100.h"
#include "cg2102.h" #include "cg2102.h"
@ -473,15 +473,15 @@ real TPrimanota_application::calcola_saldo() const
real sbilancio = abs(tdare)-abs(tavere); real sbilancio = abs(tdare)-abs(tavere);
switch (sbilancio.sign()) switch (sbilancio.sign())
{ {
case 1: case +1: // Il dare supera l'avere in valore assoluto
curr_mask().set(F_DARE, (tdare-tavere).string()); curr_mask().set(F_DARE, (tdare-tavere).string());
curr_mask().reset(F_AVERE); curr_mask().reset(F_AVERE);
break; break;
case -1: case -1: // L'avere supera il dare in valore assoluto
curr_mask().reset(F_DARE); curr_mask().reset(F_DARE);
curr_mask().set(F_AVERE, (tavere-tdare).string()); curr_mask().set(F_AVERE, (tavere-tdare).string());
break; break;
default: default: // Sbilancio nullo
curr_mask().reset(F_DARE); curr_mask().reset(F_DARE);
curr_mask().reset(F_AVERE); curr_mask().reset(F_AVERE);
break; break;
@ -495,12 +495,10 @@ real TPrimanota_application::calcola_saldo() const
// Certified 90% // Certified 90%
bool TPrimanota_application::cg_handler(TMask_field& f, KEY k) bool TPrimanota_application::cg_handler(TMask_field& f, KEY k)
{ {
if ((k == K_TAB && !f.mask().is_running()) || k == K_ENTER) if (k == K_ENTER)
{ {
const real saldo = app().calcola_saldo(); const real saldo = app().calcola_saldo();
if (k == K_ENTER)
{
if (saldo != ZERO) if (saldo != ZERO)
{ {
const char* ss = saldo.string("."); const char* ss = saldo.string(".");
@ -512,13 +510,13 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k)
const int max = cg.items(); const int max = cg.items();
for (int i = 0; i < max; i++) for (int i = 0; i < max; i++)
{ {
const TImporto im(app().get_cgs_imp(i)); TToken_string& r = cg.row(i);
if (!im.valore().is_zero()) if (!can_remove(r))
{ {
const TBill c(cg.row(i), 3, 0x0); const TBill c(r, 3, 0x0);
if (!c.ok()) if (!c.ok())
return f.error_box("Il conto della riga %d non e' completo", i+1); return f.error_box("Il conto della riga %d non e' completo", i+1);
const TBill co(cg.row(i), 10, 0x0); const TBill co(r, 10, 0x0);
if (!co.empty() && !co.ok()) if (!co.empty() && !co.ok())
return f.error_box("La contropartita della riga %d non e' completa", i+1); return f.error_box("La contropartita della riga %d non e' completa", i+1);
empty = FALSE; empty = FALSE;
@ -528,27 +526,27 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k)
if (empty) if (empty)
return error_box("Il movimento non ha nessuna riga contabile con un importo"); return error_box("Il movimento non ha nessuna riga contabile con un importo");
} }
}
return TRUE; return TRUE;
} }
void TPrimanota_application::generazione_righe_cg(int r) void TPrimanota_application::generazione_righe_cg(int r)
{ {
begin_wait();
TSheet_field& cg = cgs(); TSheet_field& cg = cgs();
TToken_string& row = cg.row(r); TToken_string& row = cg.row(r);
if (can_remove(row)) // Ignora righe senza importo
return;
TImporto importo; importo = row; TImporto importo; importo = row;
if (importo.is_zero())
return; // Ignora righe senza importo
const bool causale_ok = causale().codice()[0] > ' '; const bool causale_ok = causale().codice()[0] > ' ';
if (r == 0 && cg.row(1).empty_items()) if (r == 0 && cg.row(1).empty_items())
{ {
TBill contro(row, 9, 0x3); // Contropartita della prima riga TBill contro(row, 9, 0x3); // Contropartita della prima riga
if (!contro.ok() && causale_ok) if (causale_ok && !contro.ok())
{ {
causale().bill(2, contro); // Prendi contropartita dalla causale causale().bill(2, contro); // Prendi contropartita dalla causale
if (contro.ok()) if (contro.ok())
@ -572,8 +570,8 @@ void TPrimanota_application::generazione_righe_cg(int r)
int first_not_empty = 0; int first_not_empty = 0;
for (int i = 0; i < r; i++) for (int i = 0; i < r; i++)
{ {
TToken_string& r = cg.row(i); TToken_string& row = cg.row(i);
if (r.get(0)[0] > ' ' || r.get()[0] > ' ') if (!can_remove(row))
{ {
first_not_empty = i; first_not_empty = i;
break; break;
@ -639,18 +637,21 @@ void TPrimanota_application::generazione_righe_cg(int r)
} }
} }
} }
end_wait();
} }
bool TPrimanota_application::cg_notify(int r, KEY k) bool TPrimanota_application::cg_notify(int r, KEY k)
{ {
TSheet_field& cg = app().cgs();
const char tipo = cg.row(r).right(1)[0];
switch(k) switch(k)
{ {
case K_SPACE: case K_SPACE:
{
TSheet_field& cg = app().cgs();
const char tipo = row_type(cg.row(r));
cg.sheet_mask().enable(DLG_DELREC, tipo <= ' '); cg.sheet_mask().enable(DLG_DELREC, tipo <= ' ');
}
break; break;
case K_ENTER: case K_ENTER:
if (app().iva() == nessuna_iva) if (app().iva() == nessuna_iva)
@ -658,10 +659,8 @@ bool TPrimanota_application::cg_notify(int r, KEY k)
app().calcola_saldo(); app().calcola_saldo();
break; break;
case K_DEL: case K_DEL:
if (tipo > ' ') if (app().is_saldaconto() && app().iva() == nessuna_iva)
return error_box("La riga %d non puo' essere cancellata", r+1); app().notify_cgline_deletion(r+1);
// if (app().is_saldaconto() && app().iva() == nessuna_iva)
// app().notify_cgline_deletion(r+1);
break; break;
default: default:
break; break;
@ -697,7 +696,7 @@ bool TPrimanota_application::descr_handler(TMask_field& f, KEY k)
// Scrivendo qualcosa in dare (101) cancella l'importo in avere (102) e viceversa // Scrivendo qualcosa in dare (101) cancella l'importo in avere (102) e viceversa
bool TPrimanota_application::dareavere_handler(TMask_field& f, KEY k) bool TPrimanota_application::dareavere_handler(TMask_field& f, KEY k)
{ {
if (k == K_TAB && f.focusdirty() && !f.get().empty()) if (k == K_TAB && f.focusdirty() && f.get().not_empty())
{ {
const int id = 203-f.dlg(); // Calcola id del campo da resettare const int id = 203-f.dlg(); // Calcola id del campo da resettare
f.mask().reset(id); f.mask().reset(id);

View File

@ -215,9 +215,11 @@ protected:
int nuovo_pagamento(TPartita& partita, int rata, int rmov, TRectype& part); int nuovo_pagamento(TPartita& partita, int rata, int rmov, TRectype& part);
bool edit_pagamento(TPartita& partita, TRectype& part); bool edit_pagamento(TPartita& partita, TRectype& part);
static TPrimanota_application& app() { return (TPrimanota_application&)main_app(); } bool notify_cgline_deletion(TPartita& partita, long nreg, int numrig);
bool notify_cgline_deletion(int numrig);
public: public:
static TPrimanota_application& app() { return (TPrimanota_application&)main_app(); }
TPrimanota_application(); TPrimanota_application();
}; };

View File

@ -370,9 +370,9 @@ void TPrimanota_application::write_scadenze(const TMask& m)
int nriga = 1; int nriga = 1;
int numrig = 1; int numrig = 1;
partita.put("ANNO", anno); partita.put(PART_ANNO, anno);
partita.put("NUMPART", numpart); partita.put(PART_NUMPART, numpart);
partita.put("NRIGA", nriga); partita.put(PART_NRIGA, nriga);
bool fromscratch = FALSE, new_part = TRUE; bool fromscratch = FALSE, new_part = TRUE;
@ -381,7 +381,7 @@ void TPrimanota_application::write_scadenze(const TMask& m)
if (partita.read() == NOERR) if (partita.read() == NOERR)
{ {
// se si e' specificato un codice pagamento diverso si rifa' da capo // se si e' specificato un codice pagamento diverso si rifa' da capo
if (pag.code() != partita.get("CODPAG")) if (pag.code() != partita.get(PART_CODPAG))
fromscratch = TRUE; fromscratch = TRUE;
new_part = FALSE; new_part = FALSE;
} }
@ -390,13 +390,13 @@ void TPrimanota_application::write_scadenze(const TMask& m)
if (new_part) if (new_part)
{ {
partita.zero(); partita.zero();
partita.put("TIPOCF", tipocf); partita.put(PART_TIPOCF, tipocf);
partita.put("GRUPPO", gruppo); partita.put(PART_GRUPPO, gruppo);
partita.put("CONTO", conto); partita.put(PART_CONTO, conto);
partita.put("SOTTOCONTO", sottoconto); partita.put(PART_SOTTOCONTO, sottoconto);
partita.put("ANNO", anno); partita.put(PART_ANNO, anno);
partita.put("NUMPART", numpart); partita.put(PART_NUMPART, numpart);
partita.put("NRIGA", nriga); partita.put(PART_NRIGA, nriga);
} }
// put data on partita // put data on partita
@ -435,13 +435,13 @@ void TPrimanota_application::write_scadenze(const TMask& m)
{ {
new_scad = TRUE; new_scad = TRUE;
scadenza.zero(); scadenza.zero();
scadenza.put("TIPOCF", tipocf); scadenza.put(SCAD_TIPOCF, tipocf);
scadenza.put("GRUPPO", gruppo); scadenza.put(SCAD_GRUPPO, gruppo);
scadenza.put("CONTO", conto); scadenza.put(SCAD_CONTO, conto);
scadenza.put("SOTTOCONTO", sottoconto); scadenza.put(SCAD_SOTTOCONTO, sottoconto);
scadenza.put("ANNO", anno); scadenza.put(SCAD_ANNO, anno);
scadenza.put("NUMPART", numpart); scadenza.put(SCAD_NUMPART, numpart);
scadenza.put("NRATA", i+1); scadenza.put(SCAD_NRATA, i+1);
} }
// set everything // set everything
scadenza.put("CODPAG", pag.code()); scadenza.put("CODPAG", pag.code());
@ -459,9 +459,9 @@ void TPrimanota_application::write_scadenze(const TMask& m)
for (; !new_scad ; i++) for (; !new_scad ; i++)
{ {
scadenza.zero(); scadenza.zero();
scadenza.put("ANNO", anno); scadenza.put(SCAD_ANNO, anno);
scadenza.put("NUMPART", numpart); scadenza.put(SCAD_NUMPART, numpart);
scadenza.put("NRATA", i+1); scadenza.put(SCAD_NRATA, i+1);
if (scadenza.read() == NOERR) if (scadenza.read() == NOERR)
scadenza.remove(); scadenza.remove();
@ -474,22 +474,16 @@ void TPrimanota_application::write_scadenze(const TMask& m)
// Sheet partite // Sheet partite
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
HIDDEN int _riga;
HIDDEN TImporto _soldi, _max;
bool TPrimanota_application::edit_partite(int riga) bool TPrimanota_application::edit_partite(int riga)
{ {
begin_wait();
const long curreg = curr_mask().get_long(F_NUMREG); // Numero registrazione
TToken_string& cgr = cgs().row(riga); TToken_string& cgr = cgs().row(riga);
const TBill b(cgr, 2, 0x3); // Legge il conto della riga selezionata const TBill b(cgr, 2, 0x3); // Legge il conto della riga selezionata
_riga = riga; // Riga correntemente in gestione if (!b.ok()) return FALSE;
_soldi = cgr; // Importo della riga selezionata
TString80 caption("Partite aperte del conto "); begin_wait();
TString caption("Partite aperte del conto ");
caption << b.gruppo() << ' ' << b.conto() << ' ' << b.sottoconto(); caption << b.gruppo() << ' ' << b.conto() << ' ' << b.sottoconto();
TArray_sheet a(-1, -1, 0, 0, caption, "Anno|Numero@7|Descrizione@50|Importo@15R|Sezione", 0x8); TArray_sheet a(-1, -1, 0, 0, caption, "Anno|Numero@7|Descrizione@50|Importo@15R|Sezione", 0x8);
@ -498,7 +492,7 @@ bool TPrimanota_application::edit_partite(int riga)
partita.setkey(2); // Chiave per conto partita.setkey(2); // Chiave per conto
partita.zero(); partita.zero();
if (b.tipo() != ' ') // Ignora gruppo e conto dei clifo if (b.tipo() > ' ') // Ignora gruppo e conto dei clifo
{ {
partita.put(PART_TIPOCF, b.tipo()); partita.put(PART_TIPOCF, b.tipo());
partita.put(PART_SOTTOCONTO, b.sottoconto()); partita.put(PART_SOTTOCONTO, b.sottoconto());
@ -514,6 +508,8 @@ bool TPrimanota_application::edit_partite(int riga)
TImporto saldo; // Saldo ultima parita TImporto saldo; // Saldo ultima parita
TToken_string r(80); TToken_string r(80);
const long curreg = curr_mask().get_long(F_NUMREG); // Numero registrazione
for (int err = partita.read(_isgteq); err == NOERR && partita.curr() == recpar; err = partita.next()) for (int err = partita.read(_isgteq); err == NOERR && partita.curr() == recpar; err = partita.next())
{ {
num = partita.get(PART_NUMPART); num = partita.get(PART_NUMPART);
@ -524,13 +520,6 @@ bool TPrimanota_application::edit_partite(int riga)
{ {
const TImporto i(partita.get_char(PART_SEZ), partita.get_real(PART_IMPORTO)); const TImporto i(partita.get_char(PART_SEZ), partita.get_real(PART_IMPORTO));
saldo += i; // ... incrementa totale saldo += i; // ... incrementa totale
if (nreg == curreg)
{
const int numrig = partita.get_int(PART_NUMRIG);
if (numrig == (riga+1))
_soldi -= i;
}
} }
else else
{ {
@ -582,7 +571,7 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int rata, int rmo
const int nriga = partita.righe(); const int nriga = partita.righe();
CHECKD(nriga > 0, "Riga partita errata ", nriga); CHECKD(nriga > 0, "Riga partita errata ", nriga);
part = partita.riga(nriga); part = partita.riga(1);
// PART_ANNO viene preso dalla partita base // PART_ANNO viene preso dalla partita base
// PART_NUMPART viene preso dalla partita base // PART_NUMPART viene preso dalla partita base
@ -592,7 +581,7 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int rata, int rmo
part.put(PART_CODCAUS, causale().codice()); part.put(PART_CODCAUS, causale().codice());
part.put(PART_NREG, curr_mask().get(F_NUMREG)); // Numero operazione part.put(PART_NREG, curr_mask().get(F_NUMREG)); // Numero operazione
part.put(PART_NUMRIG, rmov+1); // Riga su cui ho cliccato part.put(PART_NUMRIG, rmov); // Riga su cui ho cliccato
// Copia dati movimento corrente // Copia dati movimento corrente
part.put(PART_DATAREG, curr_mask().get(F_DATAREG)); part.put(PART_DATAREG, curr_mask().get(F_DATAREG));
@ -643,19 +632,24 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int rata, int rmo
caus = 2; break; caus = 2; break;
} }
// PART_TIPOC viene preso dalla partita base
// PART_GRUPPO viene preso dalla partita base
// PART_CONTO viene preso dalla partita base
// PART_SOTTOCONTO viene preso dalla partita base
TBill bill; causale().bill(caus, bill); TBill bill; causale().bill(caus, bill);
if (bill.empty()) causale().bill(caus = 1, bill); if (bill.empty()) causale().bill(caus = 1, bill);
bill.put(part); bill.put(part, TRUE);
TBill b; b.get(partita.riga(1)); bill.get(partita.riga(1));
if (b.tipo() > ' ') // Se cliente o fornitore cerca sua banca if (bill.tipo() > ' ') // Se cliente o fornitore cerca sua banca
{ {
TRelation cliforel(LF_CLIFO); TRelation cliforel(LF_CLIFO);
cliforel.add(LF_CFVEN, "TIPOCF=TIPOCF|CODCF=CODCF"); cliforel.add(LF_CFVEN, "TIPOCF=TIPOCF|CODCF=CODCF");
TRectype& clifo = cliforel.lfile().curr(); TRectype& clifo = cliforel.lfile().curr();
clifo.put(CLI_TIPOCF, b.tipo()); clifo.put(CLI_TIPOCF, bill.tipo());
clifo.put(CLI_CODCF, b.codclifo()); clifo.put(CLI_CODCF, bill.codclifo());
const int err = cliforel.read(); const int err = cliforel.read();
CHECK(err == NOERR, "Chiss'e' fregato il clifo"); CHECK(err == NOERR, "Chiss'e' fregato il clifo");
@ -699,16 +693,10 @@ bool TPrimanota_application::edit_scadenze(int anno, const char* num)
{ {
TString caption; caption.format("Pagamenti della partita %s dell'anno %d", num, anno); TString caption; caption.format("Pagamenti della partita %s dell'anno %d", num, anno);
TArray_sheet a(-1, -1, 0, 0, caption, "Rata|Data@10|Importo@15|Descrizione@50|Riga", 0x8); TArray_sheet a(-1, -1, 0, 0, caption, "Rata|Data@10|Importo@15|Descrizione@50|Riga", 0x8);
TPartita& partita = _partite.partita(anno, num);
TPartita* game = _partite.partita(anno, num);
if (game == NULL)
{
game = new TPartita(anno, num);
_partite.add(game);
}
TPartita& partita = *game;
const long curreg = curr_mask().get_long(F_NUMREG); // Numero registrazione corrente const long curreg = curr_mask().get_long(F_NUMREG); // Numero registrazione corrente
const int currig = cgs().selected()+1; // Numero riga corrente
TToken_string r(80); // Work string TToken_string r(80); // Work string
@ -749,7 +737,7 @@ bool TPrimanota_application::edit_scadenze(int anno, const char* num)
r.add(paga.get(PART_DESCR)); r.add(paga.get(PART_DESCR));
r.add(paga.get(PART_NRIGA)); r.add(paga.get(PART_NRIGA));
nr = a.add(r); nr = a.add(r);
if (paga.get_long(PART_NREG) != curreg || paga.get_int(PART_NUMRIG) != _riga+1) if (paga.get_long(PART_NREG) != curreg || paga.get_int(PART_NUMRIG) != currig)
a.disable(nr); a.disable(nr);
} }
} }
@ -765,7 +753,7 @@ bool TPrimanota_application::edit_scadenze(int anno, const char* num)
TRectype part(LF_PARTITE); TRectype part(LF_PARTITE);
if (nrig == 0) // Se ho cliccato su una scadenza ... if (nrig == 0) // Se ho cliccato su una scadenza ...
nrig = nuovo_pagamento(partita, rata, _riga, part); nrig = nuovo_pagamento(partita, rata, currig, part);
else else
part = partita.riga(nrig); part = partita.riga(nrig);
@ -777,40 +765,28 @@ bool TPrimanota_application::edit_scadenze(int anno, const char* num)
} }
static bool importopag_handler(TMask_field& f, KEY k) static bool importopag_handler(TMask_field& f, KEY k)
{ {
if (k == K_F8)
{
TMask& m = f.mask();
f.set(m.get(S_IMPORTO));
k = K_TAB;
}
if (f.to_check(k)) if (f.to_check(k))
{ {
TMask& m = f.mask(); TMask& m = f.mask();
const real r(m.get(S_RESIDUO));
real i(f.get()); real i(f.get());
const real tot(m.get(S_IMPORTO));
if (i > r) if (i > tot)
{ {
warning_box("Non e' possibile inserire un importo superiore al residuo"); warning_box("Non e' possibile inserire un importo superiore a ", tot.string("."));
i = r; i = tot;
f.set(i.string()); f.set(i.string());
} }
if (i > _max.valore()) if (i == tot)
{ m.set(S_SALDOACC, "S");
const TFixed_string val(_max.valore().string("."));
warning_box("La riga contabile ha un residuo di %s", (const char*)val);
f.set(val);
}
if (i == r)
{
m.set(S_SALDOACC, "X");
m.disable(S_SALDOACC);
}
else
m.enable(S_SALDOACC);
}
else
if (k == K_F8)
{
const TString& val = f.mask().get(S_RESIDUO);
f.set(val);
} }
return TRUE; return TRUE;
} }
@ -847,49 +823,122 @@ bool TPrimanota_application::edit_pagamento(TPartita& p, TRectype& part)
m.set(S_IMPORTOVAL, scaden.get(SCAD_IMPORTOVAL)); // " in valuta m.set(S_IMPORTOVAL, scaden.get(SCAD_IMPORTOVAL)); // " in valuta
m.set(S_RATA, scaden.get(SCAD_NRATA)); m.set(S_RATA, scaden.get(SCAD_NRATA));
// Memorizza importi prima di eventuali variazioni const char sez = part.get_char(PART_SEZ); // Sezione importo e rituenute
const real importo(part.get(PART_IMPORTO)); const char controsez = sez == 'D' ? 'A' : 'D'; // Sezione opposta
const real ritenute(part.get(PART_RITENUTE));
_max.set(_soldi.sezione(), _soldi.valore() + importo); // Importo massimo del campo S_IMPORTOPAG // Memorizza importi prima di eventuali variazioni
const real old_importo(part.get(PART_IMPORTO));
const real old_ritenute(part.get(PART_RITENUTE));
const TBill old_conto(m.get_int(S_GRUPPO), m.get_int(S_CONTO), m.get_long(S_SOTTOCONTO));
const int old_riga = old_conto.ok() ? bill2pos(old_conto, 'I') : -1;
const KEY key = m.run(); const KEY key = m.run();
if (key == K_ENTER) if (key == K_ENTER || key == K_DEL)
{ {
if (key == K_DEL)
{
m.reset(S_IMPORTOPAG);
m.reset(S_RITENUTE);
}
m.autosave(&rel); m.autosave(&rel);
part = partita.curr(); part = partita.curr();
const char sez = _soldi.sezione() == 'D' ? 'A' : 'D'; if (old_riga >= 0)
sub_cgs_imp(old_riga, old_importo);
const real imp(m.get(S_IMPORTOPAG)); // Importo della contropartita
const TImporto impg(sez, imp-importo); const TImporto new_importo(controsez, part.get_real(PART_IMPORTO));
if (!new_importo.is_zero())
if (!impg.is_zero())
{ {
_soldi += impg; // Sottrai soldi spesi qui TBill conto; conto.get(part);
TBill conto(m.get_int(S_GRUPPO), m.get_int(S_CONTO), m.get_long(S_SOTTOCONTO));
const int riga = bill2pos(conto, 'I'); const int riga = bill2pos(conto, 'I');
if (riga < 0) if (riga < 0)
set_cgs_row(riga, impg, conto, m.get(S_DESCAGG), 'I'); set_cgs_row(riga, new_importo, conto, part.get(PART_DESCR), 'I');
else else
add_cgs_imp(riga, impg); add_cgs_imp(riga, new_importo);
} }
const real rit(m.get(S_RITENUTE)); const real rit(part.get(PART_RITENUTE));
const TImporto ritg(sez, rit-ritenute); const TImporto grow_ritenute(controsez, rit-old_ritenute); // Variazione ritenute fiscali
if (!ritg.is_zero()) if (!grow_ritenute.is_zero())
{ {
const riga = type2pos('F'); const riga = type2pos('F');
if (riga < 0) if (riga < 0)
{ {
TBill conto_rit; causale().bill(11, conto_rit); TBill conto_rit; causale().bill(11, conto_rit);
set_cgs_row(riga, ritg, conto_rit, "", 'F'); set_cgs_row(riga, grow_ritenute, conto_rit, "", 'F');
} }
else add_cgs_imp(riga, ritg); else add_cgs_imp(riga, grow_ritenute);
}
p.add_riga(part);
} }
return key == K_ENTER; if (key == K_ENTER)
p.add_riga(part);
else
p.remove_riga(part);
}
return key != K_ESC;
}
bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg, int numrig)
{
bool found = FALSE;
const int riga_ritenute = type2pos('F');
for (int r = partita.righe(); r > 0; r--)
{
TRectype pag(partita.riga(r));
const long reg = pag.get_long(PART_NREG);
if (reg == nreg) // Se la registrazione corrisponde
{
const int num = pag.get_int(PART_NUMRIG);
if (num == numrig) // Se la riga corrisponde
{
const real ritenute = pag.get_real(PART_RITENUTE);
if (!ritenute.is_zero())
{
if (riga_ritenute >= 0)
sub_cgs_imp(riga_ritenute, ritenute);
else
error_box("Non esiste la riga delle ritenute di un pagamento della riga %d", numrig);
}
const real importo = pag.get_real(PART_IMPORTO);
if (!importo.is_zero())
{
TBill contro; contro.get(pag);
const int riga_contro = bill2pos(contro, 'I');
if (riga_contro >= 0)
sub_cgs_imp(riga_contro, importo);
else
error_box("Non esiste la riga dell'importo di un pagamento della riga %d", numrig);
}
partita.remove_riga(pag);
found = TRUE;
}
else
if (num > numrig) // Se la riga e' successiva
{
pag.put(PART_NUMRIG, num-1);
partita.add_riga(pag);
}
}
}
return found;
}
bool TPrimanota_application::notify_cgline_deletion(int numrig)
{
bool found = FALSE;
const long nreg = curr_mask().get_long(F_NUMREG);
_partite.add_reg_num(nreg, 0);
for (TPartita* game = _partite.first(); game; game = _partite.next())
found |= notify_cgline_deletion(*game, nreg, numrig);
return found;
} }

View File

@ -22,7 +22,7 @@ END
STRING 109 50 STRING 109 50
BEGIN BEGIN
PROMPT 14 2 "" PROMPT 12 2 ""
USE %DPN KEY 2 USE %DPN KEY 2
INPUT S0 109 INPUT S0 109
DISPLAY "Descrizione@50" S0 DISPLAY "Descrizione@50" S0

View File

@ -1,16 +1,13 @@
// Ricezione dati da sistema // Ricezione dati da sistema
#include <mask.h>
#include <printapp.h>
#include <relation.h>
#include <tabutil.h>
#include <utility.h>
#include <config.h> #include <config.h>
#include <urldefid.h> #include <mask.h>
#include <mailbox.h>
#include <execp.h>
#include <prefix.h> #include <prefix.h>
#include <scanner.h> #include <printapp.h>
#include <tabutil.h>
#include <urldefid.h>
#include <utility.h>
#include <nditte.h> #include <nditte.h>
#include "cglib04.h" #include "cglib04.h"
@ -18,14 +15,13 @@
//#include "ba7.h" //#include "ba7.h"
#include "cg2400.h" #include "cg2400.h"
TString80 TEMP;
class TRic_sistema : public TApplication class TRic_sistema : public TApplication
{ {
TTable* _tab_tra; TTable* _tab_tra;
TTransfer_file* _tras_file; TTransfer_file* _tras_file;
TString80 TEMP;
int _numtotdisk,_progdisk,_numdisk,_numinv,_numinvp,_nultras; int _numtotdisk,_progdisk,_numdisk,_numinv,_numinvp,_nultras;
int _stato_ripartenza,_nultras_tab; int _stato_ripartenza,_nultras_tab;
bool _sequenza,_disketto; bool _sequenza,_disketto;
@ -53,7 +49,7 @@ public:
bool set_flag(); bool set_flag();
void aggiorna_tabella(); void aggiorna_tabella();
const char* converti (TString& data_AS400); const char* converti (const TString& data_AS400);
static bool baipassa(TMask& m,KEY k); static bool baipassa(TMask& m,KEY k);
@ -121,7 +117,7 @@ void TRic_sistema::componi_path(TMask& msk)
} }
} }
const char* TRic_sistema::converti (TString& data_AS400) const char* TRic_sistema::converti (const TString& data_AS400)
{ {
TEMP = data_AS400.mid(4,2); TEMP = data_AS400.mid(4,2);
TEMP << "-" << data_AS400.mid(2,2); TEMP << "-" << data_AS400.mid(2,2);

View File

@ -1,18 +1,14 @@
// //
// Ricezione dati: lista controllo movimenti // Ricezione dati: lista controllo movimenti
// //
#include <config.h>
#include <mask.h> #include <mask.h>
#include <prefix.h>
#include <printapp.h> #include <printapp.h>
#include <relation.h> #include <progind.h>
#include <tabutil.h> #include <tabutil.h>
#include <utility.h> #include <utility.h>
#include <config.h>
#include <urldefid.h>
#include <mailbox.h>
#include <execp.h>
#include <prefix.h>
#include <scanner.h>
#include <progind.h>
#include <nditte.h> #include <nditte.h>
#include <mov.h> #include <mov.h>
#include <rmov.h> #include <rmov.h>

View File

@ -5,12 +5,9 @@
#include <tabutil.h> #include <tabutil.h>
#include <utility.h> #include <utility.h>
#include <config.h> #include <config.h>
#include <urldefid.h>
#include <mailbox.h> #include <mailbox.h>
#include <execp.h>
#include <prefix.h> #include <prefix.h>
#include <scanner.h>
#include <lffiles.h>
#include <nditte.h> #include <nditte.h>
#include <mov.h> #include <mov.h>
#include <rmov.h> #include <rmov.h>

View File

@ -317,16 +317,16 @@ int TInv_cont::calcola_numero_dischi(TMask& msk)
switch (item) switch (item)
{ {
case 1 : case 1 :
_dim_disk = 1400000; _dim_disk = 1400000L;
break; break;
case 2 : case 2 :
_dim_disk = 1200000; _dim_disk = 1200000L;
break; break;
case 3 : case 3 :
_dim_disk = 720000; _dim_disk = 720000L;
break; break;
case 4 : case 4 :
_dim_disk = 360000; _dim_disk = 360000L;
break; break;
default : default :
break; break;
@ -338,7 +338,7 @@ int TInv_cont::calcola_numero_dischi(TMask& msk)
{ {
//double dischi = _dim_tot / _dim_disk; //double dischi = _dim_tot / _dim_disk;
//numdisc = (int)ceil(dischi); //numdisc = (int)ceil(dischi);
numdisc = _dim_tot / _dim_disk; numdisc = int(_dim_tot / _dim_disk);
if ( (_dim_tot % _dim_disk) != 0) if ( (_dim_tot % _dim_disk) != 0)
numdisc += 1; numdisc += 1;
} }

View File

@ -97,8 +97,8 @@ public:
class TTab_conti : public TAssoc_array class TTab_conti : public TAssoc_array
{ {
public: public:
void aggiorna_conto(const TBill& tc, int anno_es, const real& importo, void aggiorna_conto(const TBill& tc, int anno_es, const TImporto& importo,
char sezione, bool movap, bool provv, bool somma); bool movap, bool provv, bool somma);
TConto* add(const TBill& c, int anno); TConto* add(const TBill& c, int anno);
TConto* find(const TBill& c, int anno); TConto* find(const TBill& c, int anno);
@ -120,7 +120,7 @@ class TSaldo_agg : public TObject
public: public:
void clear_saldi(int year); void clear_saldi(int year);
void registra(); void registra();
void aggiorna (const TBill& tc, const real& importo, char sezione, bool somma=TRUE); void aggiorna (const TBill& tc, const TImporto& importo, bool somma=TRUE);
void aggiorna (int gruppo, int conto, long sottoconto, void aggiorna (int gruppo, int conto, long sottoconto,
const real& importo, char sezione, bool somma=TRUE); const real& importo, char sezione, bool somma=TRUE);

View File

@ -40,30 +40,36 @@ void TTab_conti::remove(const TBill& c, int anno)
} }
void TTab_conti::aggiorna_conto(const TBill& tcon, void TTab_conti::aggiorna_conto(const TBill& tcon,
int anno_es, const real& importo, char sezione, int anno_es, const TImporto& importo,
bool movap, bool provv, bool somma) bool movap, bool provv, bool somma)
{ {
TConto* tc = find(tcon, anno_es); TConto* tc = find(tcon, anno_es);
if (tc == NULL) if (tc == NULL)
tc = add(tcon, anno_es); tc = add(tcon, anno_es);
real i = somma ? importo : -importo; const real i(somma ? importo.valore() : -importo.valore());
if (movap) if (movap)
{ {
if (sezione == 'D') tc->saldo() += i; if (importo.sezione() == 'D')
else tc->saldo() -= i; tc->saldo() += i;
else
tc->saldo() -= i;
} }
else else
if (provv) if (provv)
{ {
if (sezione == 'D') tc->darepro() += i; if (importo.sezione() == 'D')
else tc->averepro() += i; tc->darepro() += i;
else
tc->averepro() += i;
} }
else else
{ {
if (sezione == 'D') tc->dare() += i; if (importo.sezione() == 'D')
else tc->avere() += i; tc->dare() += i;
else
tc->avere() += i;
} }
// rimuovo dalla tabella il conto se dare e avere vanno a zero // rimuovo dalla tabella il conto se dare e avere vanno a zero
@ -83,15 +89,15 @@ TSaldo_agg::TSaldo_agg()
reset(); // pulizia dell'array dei conti reset(); // pulizia dell'array dei conti
} }
void TSaldo_agg::aggiorna(const TBill& tc, const real& importo, char sezione, bool somma) void TSaldo_agg::aggiorna(const TBill& tc, const TImporto& imp, bool somma)
{ {
_tab_conti.aggiorna_conto(tc, _anno_es, importo, sezione, _movap, _provv, somma); _tab_conti.aggiorna_conto(tc, _anno_es, imp, _movap, _provv, somma);
} }
void TSaldo_agg::aggiorna(int gruppo, int conto, long sottoconto, const real& importo, char sezione, bool somma) void TSaldo_agg::aggiorna(int gruppo, int conto, long sottoconto, const real& importo, char sezione, bool somma)
{ {
_tab_conti.aggiorna_conto(TBill(gruppo, conto, sottoconto), _anno_es, importo, const TImporto imp(sezione, importo);
sezione, _movap, _provv, somma); _tab_conti.aggiorna_conto(TBill(gruppo, conto, sottoconto), _anno_es, imp, _movap, _provv, somma);
} }
void TSaldo_agg::reset() void TSaldo_agg::reset()

View File

@ -81,36 +81,44 @@ const TBill& TBill::add_to(TToken_string& ts, int from, int mode)
} }
const char* TBill::file2type(int num) const const char* TBill::field_name(int n, bool contro) const
{ {
const char* t = "TIPOC"; CHECKD(n >= 0 && n <= 3, "Invalid bill field", n);
switch (num) const char* f;
if (contro)
switch(n)
{ {
case LF_PARTITE: case 0: f = "GRUPPOC"; break;
case LF_SCADENZE: case 1: f = "CONTOC"; break;
t = "TIPOCF"; break; case 2: f = "SOTTOCONTC"; break;
default: default:f = "TIPOCC"; break;
break; }
else
switch(n)
{
case 0: f = "GRUPPO"; break;
case 1: f = "CONTO"; break;
case 2: f = "SOTTOCONTO"; break;
default:f = "TIPOC"; break;
}
return f;
} }
return t; void TBill::put(TRectype& r, bool c) const
{
r.put(field_name(0, c), gruppo());
r.put(field_name(1, c), conto());
r.put(field_name(2, c), sottoconto());
r.put(field_name(3, c), tipo());
} }
void TBill::put(TRectype& r) const bool TBill::get(const TRectype& r, bool c)
{ {
r.put(file2type(r.num()), tipo()); set(r.get_int(field_name(0, c)),
r.put("GRUPPO", gruppo()); r.get_int(field_name(1, c)),
r.put("CONTO", conto()); r.get_long(field_name(2, c)),
r.put("SOTTOCONTO", sottoconto()); r.get_char(field_name(3, c)));
}
bool TBill::get(const TRectype& r)
{
set(r.get_int("GRUPPO"),
r.get_int("CONTO"),
r.get_long("SOTTOCONTO"),
r.get_char(file2type(r.num())));
if (r.num() == LF_RMOVIVA) if (r.num() == LF_RMOVIVA)
tipo_cr(r.get_int("TIPOCR")); tipo_cr(r.get_int("TIPOCR"));
@ -285,83 +293,3 @@ const char* TBill::string(int mode)
} }
///////////////////////////////////////////////////////////
// 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 (_valore.is_zero())
_sezione = i._sezione;
if (_sezione == i._sezione)
_valore += i._valore;
else
_valore -= i._valore;
return *this;
}
const TImporto& TImporto::operator -= (const TImporto& i)
{
if (_valore.is_zero())
_sezione = i._sezione;
if (_sezione == i._sezione)
_valore -= i._valore;
else
_valore += i._valore;
return *this;
}
const TImporto& TImporto::swap_section()
{
_sezione = (_sezione == 'D') ? 'A' : 'D';
return *this;
}
const TImporto& TImporto::normalize()
{
if (_valore.sign() < 0)
{
_valore = -_valore;
swap_section();
}
return *this;
}

View File

@ -20,7 +20,7 @@ protected:
virtual const char* class_name() const { return "Conto"; } virtual const char* class_name() const { return "Conto"; }
const TBill& copy(const TBill& b); const TBill& copy(const TBill& b);
const char* file2type(int logicnum) const; const char* field_name(int n, bool contro) const;
public: public:
TBill(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = NULL, int r = -1) TBill(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = NULL, int r = -1)
@ -56,39 +56,13 @@ public:
bool sospeso() const { return _sospeso; } // _sospeso e' letto nella read() bool sospeso() const { return _sospeso; } // _sospeso e' letto nella read()
char sezione() const { return _sezione; } char sezione() const { return _sezione; }
void put(TRectype& r) const; void put(TRectype& r, bool contro = FALSE) const;
bool get(const TRectype& r); bool get(const TRectype& r, bool contro = FALSE);
const char* string(int mode = 0); const char* string(int mode = 0);
}; };
class TImporto : public TObject
{
char _sezione;
real _valore;
public:
char sezione() const { return _sezione; }
const real& valore() const { return _valore; }
bool is_zero() const { return _valore.is_zero(); }
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& normalize();
const TImporto& swap_section();
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) {}
};
enum TIndbil { ib_null, ib_attivita, ib_passivita, ib_costi, ib_ricavi, ib_conti_ordine }; enum TIndbil { ib_null, ib_attivita, ib_passivita, ib_costi, ib_ricavi, ib_conti_ordine };
class TConto : public TBill class TConto : public TBill

View File

@ -995,6 +995,8 @@ TPartita::TPartita(int anno, const char* num)
int TPartita::add_riga(const TRectype& r) int TPartita::add_riga(const TRectype& r)
{ {
CHECK(r.num() == LF_PARTITE, "Tipo record errato");
const char sez = r.get_char(PART_SEZ); const char sez = r.get_char(PART_SEZ);
const real val = r.get_real(PART_IMPORTO); const real val = r.get_real(PART_IMPORTO);
const TImporto imp(sez, val); const TImporto imp(sez, val);
@ -1025,6 +1027,13 @@ int TPartita::add_riga(const TRectype& r)
return _part.add_row(r); return _part.add_row(r);
} }
void TPartita::remove_riga(TRectype& z)
{
z.zero(PART_IMPORTO);
add_riga(z);
_part.destroy_row(z, TRUE);
}
int TPartita::add_rata(const TRectype& r) int TPartita::add_rata(const TRectype& r)
{ {
return _scad.add_row(r); return _scad.add_row(r);
@ -1094,6 +1103,26 @@ bool TPartita::rata_pagata(int r) const
return pagata; return pagata;
} }
real TPartita::importo_speso(long nreg, int numrig) const
{
real imp;
for (int r = righe(); r > 0; r--)
{
const TRectype& pag = riga(r);
const long reg = pag.get_long(PART_NREG);
if (reg == nreg)
{
const int num = pag.get_int(PART_NUMRIG);
if (num == numrig)
imp += pag.get_real(PART_IMPORTO);
}
}
return imp;
}
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// TPartite_array // TPartite_array
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
@ -1106,31 +1135,90 @@ const TString& TPartite_array::key(int anno, const char* num)
} }
// Certified 99% // Certified 99%
void TPartite_array::add(TPartita* p) TPartita* TPartite_array::find(int anno, const char* num, bool create)
{
const TString& k = key(p->anno(), p->numero());
TAssoc_array::add(k, p);
}
TPartita* TPartite_array::partita(int anno, const char* num)
{ {
const TString& k = key(anno, num); const TString& k = key(anno, num);
TPartita* p = (TPartita*)objptr(k); TPartita* p = (TPartita*)objptr(k);
if (p == NULL && create)
{
p = new TPartita(anno, num);
if (p->ok())
add(k, p);
else
{
delete p;
p = NULL;
}
}
return p; return p;
} }
TPartita* TPartite_array::find(const TRectype& r, bool create)
{
const int anno = r.get_int(PART_ANNO);
const char* num = r.get_str(PART_NUMPART);
return find(anno, num, create);
}
TPartita& TPartite_array::partita(int anno, const char* num)
{
TPartita* game = find(anno, num, TRUE);
CHECKS(game, "Partita errata ", num);
return *game;
}
TPartita& TPartite_array::partita(const TRectype& r)
{
TPartita* game = find(r, TRUE);
CHECK(game, "Partita errata");
return *game;
}
bool TPartite_array::write(bool re) bool TPartite_array::write(bool re)
{ {
int err = NOERR; int err = NOERR;
TPartita* game;
restart(); restart();
TPartita* p; while ((game = (TPartita*)get()) != NULL)
while ((p = (TPartita*)get()) != NULL)
{ {
err = p->write(re); err = game->write(re);
if (err != NOERR) // L'errore viene gia' segnalato dalla partita if (err != NOERR) // L'errore viene gia' segnalato dalla partita
break; break;
} }
return err == NOERR; return err == NOERR;
} }
// Aggiunge all'array tutte le partite che si riferiscono alla registrazione nreg
int TPartite_array::add_reg_num(long nreg, int numrig)
{
TRelation rel(LF_PARTITE);
TRectype& part = rel.lfile().curr();
// Costruzione filtro del cursore
part.zero();
part.put(PART_NREG, nreg);
if (numrig > 0)
part.put(PART_NUMRIG, numrig);
const TRectype filter(part);
TCursor cur(&rel, "", 3, &filter, &filter);
for (cur = 0; cur.ok(); ++cur)
partita(part); // Aggiungi partita se non esiste gia'
return (int)cur.items();
}
real TPartite_array::importo_speso(long nreg, int numrig)
{
real imp;
const int found = add_reg_num(nreg, numrig);
if (found)
for (TPartita* game = first(); game; game = next())
imp += game->importo_speso(nreg, numrig);
return imp;
}

View File

@ -163,6 +163,7 @@ public: // TObject
public: public:
int add_riga(const TRectype& r); int add_riga(const TRectype& r);
const TRectype& riga(int r) const { return _part.row(r); } const TRectype& riga(int r) const { return _part.row(r); }
void remove_riga(TRectype& z);
int righe() const { return _part.rows(); } int righe() const { return _part.rows(); }
bool rata_pagata(int r) const; bool rata_pagata(int r) const;
@ -181,28 +182,37 @@ public:
const TString& descrizione() const { return riga(1).get(PART_DESCR); } const TString& descrizione() const { return riga(1).get(PART_DESCR); }
const TImporto& totale() const { return _totale; } const TImporto& totale() const { return _totale; }
real importo_speso(long numreg, int numrig) const;
TPartita(int anno, const char* num); TPartita(int anno, const char* num);
}; };
class TPartite_array : private TAssoc_array class TPartite_array : private TAssoc_array
{ {
TString16 _key; TString16 _key; // Work string
protected: protected:
const TString& key(int anno, const char* num); const TString& key(int anno, const char* num); // Build key for TAssoc_array
TPartita* find(int anno, const char* numero, bool create);
TPartita* find(const TRectype& part, bool create);
public: // TAssoc_array public: // TAssoc_array
virtual void destroy() { TAssoc_array::destroy(); } virtual void destroy() { TAssoc_array::destroy(); }
public: public:
TPartita* partita(int anno, const char* numero); TPartita& partita(int anno, const char* numero);
TPartita& partita(const TRectype& r);
void add(TPartita* p);
bool write(bool re = FALSE); bool write(bool re = FALSE);
bool rewrite() { return write(TRUE); } bool rewrite() { return write(TRUE); }
int add_reg_num(long numreg, int numrig);
real importo_speso(long numreg, int numrig);
TPartita* first() { restart(); return next(); }
TPartita* next() { return (TPartita*)get(); }
TPartite_array() {} TPartite_array() {}
}; };