Gestione del saldaconto in prima nota

git-svn-id: svn://10.65.10.50/trunk@1696 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1995-08-09 09:52:08 +00:00
parent f51bfda33c
commit 0516fcfdde
14 changed files with 1824 additions and 1543 deletions

View File

@ -47,7 +47,7 @@ protected:
virtual void on_config_change();
////////////
static bool indsp_notify(int r, KEY key);
static bool indsp_notify(TSheet_field& s, int r, KEY key);
static bool indsp_handler(TMask_field& f, KEY key) ;
virtual int write(const TMask& m);
virtual int rewrite(const TMask& m);
@ -553,10 +553,8 @@ bool TClifo_application::indsp_handler(TMask_field& f, KEY key)
return TRUE;
}
bool TClifo_application::indsp_notify(int r, KEY key)
bool TClifo_application::indsp_notify(TSheet_field& indsp, int r, KEY key)
{
TSheet_field& indsp=app().indsp_sheet();
switch (key)
{
case K_SPACE:
@ -564,7 +562,6 @@ bool TClifo_application::indsp_notify(int r, KEY key)
// Request to modify row #r
// Disable field CODIND update # of row
TMask& m = indsp.sheet_mask();
if (m.get_int(F_CODINDI)==0) // Is it a new row ?
m.set(F_CODINDI,(long)(r+1));
m.disable(F_CODINDI);

View File

@ -57,7 +57,7 @@ protected:
static bool sottoconto_hndl (TMask_field& f, KEY k);
static bool codcausim_hndl (TMask_field& f, KEY k);
static bool m770_hndl (TMask_field& f, KEY k);
static bool ss_notify (int r, KEY k);
static bool ss_notify (TSheet_field& s, int r, KEY k);
bool fill_sheet(TMask&);
@ -498,11 +498,11 @@ bool TCaus_app::cod_reg_hndl (TMask_field& f, KEY k)
// Handler della maschera dello spreadsheet
////////////////////////////////////////////////////////////////////////////
bool TCaus_app::ss_notify(int r, KEY k)
bool TCaus_app::ss_notify(TSheet_field& s, int r, KEY k)
{
if (k == K_ENTER)
{
TToken_string &riga = app().ss().row(r);
TToken_string &riga = s.row(r);
const int g = riga.get_int(3);
if (g == 0) // riga azzerata
app().clear(r); // pulisco la riga anche nell'array

View File

@ -155,9 +155,10 @@ bool TPrimanota_application::user_create()
_occas = new TLocalisamfile(LF_OCCAS);
_nditte = new TLocalisamfile(LF_NDITTE);
_scadenze = new TLocalisamfile(LF_SCADENZE);
_pagamenti = new TLocalisamfile(LF_PAGSCA);
_rel = new TMovimentoPN;
_rel->add(LF_PARTITE, "NREG=NUMREG", 2);
_rel->add(LF_PARTITE, "NREG=NUMREG", 2); // Collega la partita aperta dalla fattura
_causale = new TCausale();
_giornale = new TLibro_giornale();

View File

@ -413,7 +413,7 @@ BEGIN
FLAGS "H"
END
STRING F_VALUTA 3
STRING S_VALUTA 3
BEGIN
PROMPT 1 12 "Valuta "
HELP "Codice della valuta per operazione con l'estero"
@ -421,18 +421,18 @@ BEGIN
FLAGS "UZ"
GROUP 3
USE %VAL
INPUT CODTAB F_VALUTA
INPUT CODTAB S_VALUTA
DISPLAY "Codice" CODTAB
DISPLAY "Nome@50" S0
DISPLAY "Cambio@15" R10
DISPLAY "Ultimo aggiornamento" D0
OUTPUT F_VALUTA CODTAB
OUTPUT F_CAMBIO R10
OUTPUT S_VALUTA CODTAB
OUTPUT S_CAMBIO R10
CHECKTYPE NORMAL
WARNING "Codice valuta assente"
END
NUMBER F_CAMBIO 12 5
NUMBER S_CAMBIO 12 5
BEGIN
PROMPT 20 12 "Cambio "
HELP "Cambio della valuta per operazione con l'estero"
@ -442,13 +442,6 @@ BEGIN
PICTURE ".5"
END
BOOLEAN F_VISVAL
BEGIN
PROMPT 47 12 "Visualizza importi in valuta"
HELP "Indicare se visualizzare gli importi in valuta (non in Lit.)"
GROUP 3
END
NUMBER F_TOTALE 15
BEGIN
PROMPT 1 13 "Totale documento "

View File

@ -166,10 +166,7 @@ int TMovimentoPN::registra(bool re, bool force)
int err = re ? TRelation::rewrite(force) : TRelation::write(force);
if (err != NOERR)
{
CHECKD(!m.empty(), "Record empty after error ", err);
return err;
}
if (!re)
_cg.renum_key("NUMREG", numreg);

View File

@ -465,7 +465,7 @@ void TPrimanota_application::cgs_pack()
if (can_remove(r))
{
if (salda && row_type(r) == ' ')
cg_notify(i, K_DEL);
cg_notify(cgs(), i, K_DEL);
rows.destroy(i, salda);
}
}
@ -688,13 +688,12 @@ void TPrimanota_application::generazione_righe_cg(int r)
}
bool TPrimanota_application::cg_notify(int r, KEY k)
bool TPrimanota_application::cg_notify(TSheet_field& cg, int r, KEY k)
{
switch(k)
{
case K_SPACE:
{
TSheet_field& cg = app().cgs();
const char tipo = row_type(cg.row(r));
cg.sheet_mask().enable(DLG_DELREC, tipo <= ' ');
}
@ -930,12 +929,11 @@ void TPrimanota_application::ivas_pack()
}
// Certified 50%
bool TPrimanota_application::iva_notify(int r, KEY k)
bool TPrimanota_application::iva_notify(TSheet_field& iva, int r, KEY k)
{
static int oldpos,oldposiva;
static real oldimp, oldiva;
TSheet_field& iva = app().ivas();
TToken_string& row = iva.row(r);
const TCausale& cau = app().causale();
@ -1247,7 +1245,7 @@ bool TPrimanota_application::num_handler(TMask_field& f, KEY key)
"si desidera continuare ugualmente");
}
if (ok)
if (ok) // Riempie a mano i campi necessari nel caso non sia stato usata la ricerca F9
{
m.set(F_DATAREG, mov.get("DATAREG"), TRUE);
m.set(F_DATACOMP, mov.get("DATACOMP"), TRUE);
@ -1687,7 +1685,7 @@ bool TPrimanota_application::main_codiva_handler(TMask_field& f, KEY key)
TToken_string& row = app().ivas().row(0);
TMask& m = f.mask();
iva_notify(0, K_SPACE);
iva_notify(app().ivas(), 0, K_SPACE);
const TCodiceIVA iva(f.get());
const bool corr = app().causale().corrispettivi();
@ -1710,7 +1708,7 @@ bool TPrimanota_application::main_codiva_handler(TMask_field& f, KEY key)
}
app().ivas().force_update(0);
iva_notify(0, K_ENTER);
iva_notify(app().ivas(), 0, K_ENTER);
}
}
return TRUE;
@ -1915,9 +1913,9 @@ bool TPrimanota_application::solaiva_handler(TMask_field& f, KEY key)
{
oldrow = r;
r = "";
iva_notify(i, K_SPACE);
iva_notify(iva, i, K_SPACE);
r = oldrow;
iva_notify(i, K_ENTER);
iva_notify(iva, i, K_ENTER);
}
pi.setstatus(i+1);
}

View File

@ -36,6 +36,7 @@ class TPrimanota_application : public TRelation_application
TLocalisamfile* _occas;
TLocalisamfile* _nditte;
TLocalisamfile* _scadenze;
TLocalisamfile* _pagamenti;
TPagamento* _pag;
@ -104,11 +105,11 @@ class TPrimanota_application : public TRelation_application
static bool cg_conto_handler(TMask_field& f, KEY key);
static bool codpag_handler(TMask_field& f, KEY key);
static bool iva_notify(int r, KEY key);
static bool iva_notify(TSheet_field& s, int r, KEY key);
static bool iva_handler(TMask_field& f, KEY key);
static bool cg_notify(int r, KEY key);
static bool cg_notify(TSheet_field& s, int r, KEY key);
static bool cg_handler(TMask_field& f, KEY key);
static bool pag_notify(int r, KEY key);
static bool pag_notify(TSheet_field& s, int r, KEY key);
void reset_sheet_row(TSheet_field& s, int n);
@ -209,7 +210,7 @@ protected:
void write_scadenze(const TMask& m);
bool edit_partite(int riga);
bool edit_scadenze(int anno, const char* num);
bool edit_scadenze(const TBill& clifo, int anno, const char* num);
int nuovo_pagamento(TPartita& partita, int rata, int rmov, TRectype& part);
bool edit_pagamento(TPartita& partita, TRectype& part);

View File

@ -4,17 +4,18 @@
// --------------------------------------------------------------------------
#include <sheet.h>
#include "pagament.h"
#include "cg2102.h"
#include "cg2100.h"
#include "cg21sld.h"
#include "pagament.h"
#include "cg2100p.h"
#include <clifo.h>
#include <partite.h>
#include <scadenze.h>
bool TPrimanota_application::pag_notify(int r, KEY k)
bool TPrimanota_application::pag_notify(TSheet_field&, int r, KEY k)
{
TPagamento& pag = app().pagamento();
TSheet_field& ps = app().pags();
@ -340,7 +341,7 @@ void TPrimanota_application::write_scadenze(const TMask& m)
int gruppo = (tipocf == 'C' || tipocf == 'F') ? 0 : _rel->cg(0).get_char("GRUPPO");
int conto = (tipocf == 'C' || tipocf == 'F') ? 0 : _rel->cg(0).get_char("CONTO");
long sottoconto = _rel->cg(0).get_long("SOTTOCONTO");
int nriga = 1;
const int nriga = 1;
int numrig = 1;
partita.put(PART_ANNO, anno);
@ -400,9 +401,14 @@ void TPrimanota_application::write_scadenze(const TMask& m)
{
new_scad = FALSE;
scadenza.zero();
scadenza.put("ANNO", anno);
scadenza.put("NUMPART", numpart);
scadenza.put("NRATA", i+1);
scadenza.put(SCAD_TIPOCF, tipocf);
scadenza.put(SCAD_GRUPPO, gruppo);
scadenza.put(SCAD_CONTO, conto);
scadenza.put(SCAD_SOTTOCONTO, sottoconto);
scadenza.put(SCAD_ANNO, anno);
scadenza.put(SCAD_NUMPART, numpart);
scadenza.put(SCAD_NRIGA, nriga);
scadenza.put(SCAD_NRATA, i+1);
if (scadenza.read() != NOERR)
{
@ -414,6 +420,7 @@ void TPrimanota_application::write_scadenze(const TMask& m)
scadenza.put(SCAD_SOTTOCONTO, sottoconto);
scadenza.put(SCAD_ANNO, anno);
scadenza.put(SCAD_NUMPART, numpart);
scadenza.put(SCAD_NRIGA, nriga);
scadenza.put(SCAD_NRATA, i+1);
}
// set everything
@ -447,6 +454,131 @@ void TPrimanota_application::write_scadenze(const TMask& m)
// Sheet partite
///////////////////////////////////////////////////////////
HIDDEN void add_importo(TToken_string& s, const TImporto& i)
{
if (i.is_zero())
s.add("");
else
{
s.add(i.valore().string());
s << ' ' << i.sezione();
}
}
HIDDEN bool partite_notify(TSheet_field& partite, int r, KEY k)
{
if (k == K_TAB)
{
TMask& m = partite.mask();
TSheet_field& scadenze = (TSheet_field&)m.field(P_SCADENZE);
scadenze.destroy();
const TBill zio(m.get_int(P_GRUPPO), m.get_int(P_CONTO),
m.get_long(P_SOTTOCONTO), m.get(P_TIPOC)[0]);
TToken_string& row = partite.row(r);
const int anno = row.get_int(0);
const TString16 num = row.get();
m.set(P_ANNO, anno); // Aggiorna campi di ricerca
m.set(P_NUMERO, num);
TPartita game(zio, anno, num);
TRecord_array& p = game.rows_array();
const int lastr = p.last_row();
for (int r = p.first_row(); r <= lastr; r++) if (p.exist(r))
{
const TRiga_partite& riga = game.riga(r);
for (int ra = 1; ra <= riga.rate(); ra++)
{
const TRiga_scadenze& scad = riga.rata(ra);
TToken_string& row = scadenze.row(-1);
row.add(ra);
row.add(riga.get(PART_DATADOC));
row.add(riga.get(PART_NREG));
row.add(riga.get(PART_DATAREG));
row.add(scad.get(SCAD_DATASCAD));
row.add(scad.get(SCAD_IMPORTO));
row.add(scad.get(SCAD_IMPORTOVAL));
row.add(riga.get(PART_DESCR));
row.add(riga.get(PART_NUMDOC));
row.add(riga.get(PART_PROTIVA));
const TRecord_array& ap = scad.rows_array();
const int lastp = ap.last_row();
for (int pa = ap.first_row(); pa < lastp; pa++) if (ap.exist(pa))
{
const TRectype& pag = ap.row(pa);
TToken_string& row = scadenze.row(-1);
row.add("");
row.add(riga.get(PART_DATADOC));
row.add(riga.get(PART_DATAREG));
row.add(scad.get(SCAD_DATASCAD));
row.add(pag.get_real(SCAD_IMPORTO).string(0, 0));
row.add(pag.get_real(SCAD_IMPORTOVAL).string(0, 2));
row.add(riga.get(PART_DESCR));
row.add(riga.get(PART_NUMDOC));
row.add(riga.get(PART_PROTIVA));
}
}
}
scadenze.force_update();
}
return TRUE;
}
HIDDEN bool numpart_handler(TMask_field& f, KEY k)
{
if (k == K_TAB && f.dirty())
{
const TMask& m = f.mask();
const int anno = m.get_int(P_ANNO);
const TString16 num = f.get();
if (anno > 0 && num.not_empty())
{
TSheet_field& sheet = (TSheet_field&)m.field(P_PARTITE);
for (int i = 0; i < sheet.items(); i++)
{
TToken_string& row = sheet.row(i);
if (anno == row.get_int(0)) // Se corrisponde l'anno e ...
if (num == row.get()) // corrisponde il numero partita ...
{
sheet.select(i); // Seleziona la partita
partite_notify(sheet, i, K_TAB); // ed esplodi le sue righe
break;
}
}
if (i >= sheet.items())
f.warning_box("Partita inesistente");
}
}
return TRUE;
}
HIDDEN bool annopart_handler(TMask_field& f, KEY k)
{
if (k == K_TAB && f.dirty() && f.get().not_empty())
{
TMask_field& n = f.mask().field(P_NUMERO);
n.set_dirty();
numpart_handler(f, k);
}
return TRUE;
}
HIDDEN bool scambio_handler(TMask_field& f, KEY k)
{
const TMask& m = f.mask();
if (k == K_SPACE && m.is_running())
{
const TSheet_field& sheet = (TSheet_field&)m.field(P_SCADENZE);
sheet.swap_columns(103, 109);
sheet.swap_columns(104, 110);
}
return TRUE;
}
bool TPrimanota_application::edit_partite(int riga)
{
TToken_string& cgr = cgs().row(riga);
@ -456,14 +588,24 @@ bool TPrimanota_application::edit_partite(int riga)
begin_wait();
TString caption("Partite aperte del conto ");
caption << b.gruppo() << ' ' << b.conto() << ' ' << b.sottoconto();
TMask mask("cg2100p"); // Inizializzazione maschera di selezione partite
TArray_sheet a(-1, -1, 0, 0, caption, "Anno|Numero@7|Dare@15R|Avere@15R|Descrizione@50", 0x8);
const char tipocf[2] = { b.tipo(), '\0' };
mask.set(P_TIPOC, tipocf);
mask.set(P_GRUPPO, b.gruppo());
mask.set(P_CONTO, b.conto());
mask.set(P_SOTTOCONTO, b.sottoconto());
mask.set(P_DESCR, ((TBill&)b).descrizione());
mask.set_handler(P_ANNO, annopart_handler);
mask.set_handler(P_NUMERO, numpart_handler);
mask.set_handler(P_SCAMBIO, scambio_handler);
TSheet_field& sheet = (TSheet_field&)mask.field(P_PARTITE);
sheet.set_notify(partite_notify);
TString_array& a = sheet.rows_array();
TLocalisamfile partita(LF_PARTITE);
partita.setkey(2); // Chiave per conto
partita.zero();
if (b.tipo() > ' ') // Ignora gruppo e conto dei clifo
{
@ -472,76 +614,121 @@ bool TPrimanota_application::edit_partite(int riga)
}
else b.put(partita.curr()); // Scrive completamente i conti normali
const TRectype recpar(partita.curr());// Record campione
const TRectype filter(partita.curr());// Record campione
int ult, anno; // Anno ultima partita
TString16 last, num; // Ultimo numero partita e numero corrente
long nreg;
TString desc; // Descrizione prima partita del gruppo
TString16 numdoc;
TString16 datadoc;
TImporto saldo; // Saldo ultima parita
TImporto documenti; // Documenti ultima parita
TImporto pagamenti; // Pagamenti ultima parita
TImporto importi; // Altri importi ultima parita
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() == filter; err = partita.next())
{
num = partita.get(PART_NUMPART);
anno = partita.get_int(PART_ANNO);
nreg = partita.get_long(PART_NREG);
num = partita.get(PART_NUMPART);
const int tipomov = partita.get_int(PART_TIPOMOV);
if (num == last && anno == ult) // Se la partita e' la stessa ...
{
const TImporto i(partita.get_char(PART_SEZ), partita.get_real(PART_IMPORTO));
switch (tipomov)
{
case 1:
case 2:
documenti += i;
break;
case 3:
pagamenti += i;
break;
default:
importi += i;
break;
}
saldo += i; // ... incrementa totale
}
else
{
if (!saldo.is_zero() || nreg == curreg) // Se il saldo non e' nullo allora e' aperta
if (!saldo.is_zero()) // Se il saldo non e' nullo allora e' aperta
{
r.cut(0);
r.add(ult); r.add(last);
saldo.add_to(r, 2);
r.add(ult);
r.add(last);
r.add(datadoc);
r.add(numdoc);
add_importo(r, saldo);
add_importo(r, documenti);
add_importo(r, pagamenti);
add_importo(r, importi);
r.add(desc);
a.add(r); // Aggiunge partita alla lista
}
ult = anno;
last = num;
numdoc = partita.get(PART_NUMDOC);
datadoc = partita.get(PART_DATADOC);
desc = partita.get(PART_DESCR);
saldo.set(partita.get_char(PART_SEZ), partita.get_real(PART_IMPORTO));
switch (tipomov)
{
case 1:
case 2:
documenti = saldo;
pagamenti.set('D', ZERO);
importi.set('D', ZERO);
break;
case 3:
pagamenti = saldo;
documenti.set('D', ZERO);
importi.set('D', ZERO);
break;
default:
importi = saldo;
documenti.set('D', ZERO);
pagamenti.set('D', ZERO);
break;
}
}
}
if (!saldo.is_zero() || nreg == curreg) // Aggiunge ultima partita se aperta
if (!saldo.is_zero()) // Aggiunge ultima partita se aperta
{
r.cut(0);
r.add(ult); r.add(last);
saldo.add_to(r, 2);
r.add(ult);
r.add(last);
r.add(datadoc);
r.add(numdoc);
add_importo(r, saldo);
add_importo(r, documenti);
add_importo(r, pagamenti);
add_importo(r, importi);
r.add(desc);
a.add(r);
}
end_wait();
bool dirty = FALSE;
KEY k = a.items() > 0 ? K_ENTER : K_ESC; // Esce se non ci sono righe
while (k == K_ENTER)
if (a.items() > 0)
{
k = a.run();
if (k == K_ENTER)
{
const int anno = a.row().get_int(0);
const TString16 num = a.row().get(1);
dirty |= edit_scadenze(anno, num); // Edita pagamenti
}
sheet.force_update();
mask.run();
}
return dirty;
return TRUE;
}
int TPrimanota_application::nuovo_pagamento(TPartita& partita, int rata, int rmov, TRectype& part)
{
/*
CHECKD(rata >= 1 && rata <= partita.rate(), "Rata errata ", rata);
CHECKD(!partita.rata_pagata(rata), "Rata pagata ", rata);
@ -569,7 +756,7 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int rata, int rmo
part.zero(PART_REG);
part.zero(PART_PROTIVA);
part.put(PART_SEZ, (partita.totale().sezione() == 'D') ? 'A' : 'D');
// part.put(PART_SEZ, (partita.totale().sezione() == 'D') ? 'A' : 'D');
part.zero(PART_IMPORTO); // Azzera importi vari
part.zero(PART_IMPOSTA);
part.zero(PART_SPESE);
@ -662,105 +849,22 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int rata, int rmo
part.put(PART_CODCABPR, tmp);
return nriga+1;
*/
return 1;
}
// Edit scadenze relative all'anno/numero partita specificati
bool TPrimanota_application::edit_scadenze(int anno, const char* num)
bool TPrimanota_application::edit_scadenze(const TBill& clifo, int anno, const char* num)
{
TString caption; caption.format("Pagamenti della partita %s dell'anno %d", num, anno);
TArray_sheet a(-1, -1, 0, 0, caption, "Rata|Data@10|Dare@15R|Avere@15R|Descrizione@50|Riga", 0x8);
TPartita& partita = _partite.partita(anno, num);
TPartita& partita = _partite.partita(clifo, anno, num);
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
KEY k = K_ENTER;
bool dirty = TRUE, one_dirty = FALSE;
while (k == K_ENTER)
{
if (dirty)
{
const TString desc(partita.descrizione());
a.destroy();
long nr;
const char sez_par = partita.riga(1).get_char(PART_SEZ);
for (int s = 1; s <= partita.rate(); s++)
{
const TRectype& rata = partita.rata(s);
r.cut(0);
r.add(rata.get(SCAD_NRATA));
r.add(rata.get(SCAD_DATASCAD));
if (sez_par == 'A')
{
r.add(rata.get(SCAD_IMPORTO));
r.add("");
}
else
{
r.add("");
r.add(rata.get(SCAD_IMPORTO));
}
r.add(desc);
r.add("S");
nr = a.add(r);
if (partita.rata_pagata(s))
a.disable(nr);
for (int p = 1; p <= partita.righe(); p++)
{
const TRectype& paga = partita.riga(p);
if (paga.get_int(PART_NRATA) == s)
{
r.cut(0);
r.add(s);
r.add(paga.get(PART_DATAREG));
const char sez = paga.get_char(PART_SEZ);
if (sez == 'D')
{
r.add(paga.get(PART_IMPORTO));
r.add("");
}
else
{
r.add(paga.get(PART_IMPORTO));
r.add("");
}
r.add(paga.get(PART_DESCR));
r.add(paga.get(PART_NRIGA));
nr = a.add(r);
if (paga.get_long(PART_NREG) != curreg || paga.get_int(PART_NUMRIG) != currig)
a.disable(nr);
}
}
}
}
k = a.run();
if (k == K_ENTER)
{
const int rata = a.row().get_int(0);
int nrig = a.row().get_int(5); // Numero riga pagamento corrente
TRectype part(LF_PARTITE);
if (nrig == 0) // Se ho cliccato su una scadenza ...
nrig = nuovo_pagamento(partita, rata, currig, part);
else
part = partita.riga(nrig);
dirty = edit_pagamento(partita, part);
one_dirty |= dirty;
} // if k == K_ENTER
} // while k == K_ENTER
return one_dirty;
return FALSE;
}
@ -793,6 +897,7 @@ static bool importopag_handler(TMask_field& f, KEY k)
bool TPrimanota_application::edit_pagamento(TPartita& p, TRectype& part)
{
/*
TMask m("cg2100s");
m.set_handler(S_IMPORTOPAG, importopag_handler);
@ -880,6 +985,8 @@ bool TPrimanota_application::edit_pagamento(TPartita& p, TRectype& part)
}
return key != K_ESC;
*/
return FALSE;
}
bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg, int numrig)
@ -887,7 +994,7 @@ bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg
bool found = FALSE;
const int riga_ritenute = type2pos('F');
for (int r = partita.righe(); r > 0; r--)
for (int r = 1; r > 0; r--)
{
TRectype pag(partita.riga(r));
@ -917,19 +1024,19 @@ bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg
else
error_box("Non esiste la riga dell'importo di un pagamento della riga %d", numrig);
}
partita.remove_riga(pag);
// partita.remove_riga(pag);
found = TRUE;
}
else
{
const int n = pag.get_int(PART_NUMRIG);
pag.put(PART_NUMRIG, n-1);
partita.add_riga(pag);
// partita.add_riga(pag);
}
}
else // numrig == 0
{
partita.remove_riga(pag); // Cancellazione pura e semplice
// partita.remove_riga(pag); // Cancellazione pura e semplice
found = TRUE; // usata solo da ::remove
}
} // if reg == numreg

View File

@ -51,7 +51,7 @@ protected: // Relapp
protected:
void check_registers(int year);
void init_array(TMask& m, bool update);
static bool sheet_action(int r, KEY k);
static bool sheet_action(TSheet_field& s, int r, KEY k);
public:
@ -175,7 +175,7 @@ bool TParaliq_app::user_destroy()
return TRUE;
}
bool TParaliq_app::sheet_action(int r, KEY k)
bool TParaliq_app::sheet_action(TSheet_field& s, int r, KEY k)
{
// non si possono cancellare o aggiungere righe in PLA
return (k != K_DEL && k != K_INS);

View File

@ -214,13 +214,13 @@ void Visliq_app::set_mask_freq(TMask& m)
}
bool Visliq_app::sheet_action(int r, KEY k)
bool Visliq_app::sheet_action(TSheet_field& s, int r, KEY k)
{
// non si possono cancellare o aggiungere righe
return (k != K_DEL && k != K_INS);
}
bool Visliq_app::vers_action(int r, KEY k)
bool Visliq_app::vers_action(TSheet_field& s, int r, KEY k)
{
// non si possono cancellare o aggiungere righe
return (k != K_DEL && k != K_INS);

View File

@ -60,8 +60,8 @@ protected:
static const char* link_handler(TMask&, int, const char*, bool doubleclick);
static bool sheet_action(int r, KEY k);
static bool vers_action(int r, KEY k);
static bool sheet_action(TSheet_field& s, int r, KEY k);
static bool vers_action(TSheet_field& s, int r, KEY k);
public:

View File

@ -213,7 +213,7 @@ STRINGA
BEGIN
KEY "Partita IVA"
PROMPT 12 30 ""
PICTURE "# # # # # # # ~ ~ ~ #"
PICTURE "# # # # # # # ^ ^ ^ #"
FIELD 6->PAIV
END
@ -229,7 +229,7 @@ NUMERO
BEGIN
KEY "Anno di versamento"
PROMPT 40 35 ""
PICTURE "~ ~ @ @"
PICTURE "^ ^ @ @"
FIELD CODTAB[6,9]
END
@ -299,7 +299,7 @@ NUMERO
BEGIN
KEY "Importo in cifre"
PROMPT 20 52 ""
PICTURE "###.###.###~~~"
PICTURE "###.###.###^^^"
FIELD R0
END
@ -347,7 +347,7 @@ STRINGA
BEGIN
KEY "Codice Filiale"
PROMPT 70 62 ""
PICTURE "~ ~ @ @"
PICTURE "^ ^ @ @"
FIELD S8
END

View File

@ -1055,17 +1055,183 @@ _def_tpr(1), _def_ulc("")
}
///////////////////////////////////////////////////////////
// TTree_rectype
///////////////////////////////////////////////////////////
TTree_rectype::TTree_rectype(const TRectype& testa, const TRectype& riga, const char* num)
: TRectype(testa), _recarr(riga, num)
{
}
TTree_rectype::TTree_rectype(int testa, int riga, const char* num)
: TRectype(testa), _recarr(riga, num)
{
}
TTree_rectype::TTree_rectype(const TTree_rectype& t)
: TRectype(t), _recarr(t._recarr)
{
}
TObject* TTree_rectype::dup() const
{
TTree_rectype* r = new TTree_rectype(*this);
return r;
}
void TTree_rectype::copy_key_to_row(TRectype& row) const
{
const int numkey = 0; // Memento! Gli indici delle chiavi partono da zero!
RecDes* recd = rec_des(); // Descrizione del record della testata
row.zero();
for (int i = 0; i < recd->Ky[numkey].NkFields; i++)
{
const KeyDes& kd = recd->Ky[numkey];
const int nf = kd.FieldSeq[i] % MaxFields;
const RecFieldDes& rf = recd->Fd[nf];
const char* name = rf.Name;
const TString& val = get(name);
row.put(name, val);
}
}
int TTree_rectype::fill_array()
{
TRectype* row = (TRectype*)_recarr.key().dup();
copy_key_to_row(*row);
const int err = _recarr.read(row);
return err;
}
int TTree_rectype::read(TBaseisamfile& f, word op)
{
int err = TRectype::read(f, op);
if (err == NOERR)
fill_array();
else
_recarr.destroy_rows();
return err;
}
int TTree_rectype::next(TBaseisamfile& f)
{
int err = TRectype::next(f);
if (err == NOERR)
fill_array();
else
_recarr.destroy_rows();
return err;
}
int TTree_rectype::write(TBaseisamfile& f) const
{
int err = TRectype::write(f);
if (err == NOERR)
err = _recarr.write();
return err;
}
int TTree_rectype::rewrite(TBaseisamfile& f) const
{
int err = TRectype::rewrite(f);
if (err == NOERR)
err = _recarr.rewrite();
return err;
}
int TTree_rectype::remove(TBaseisamfile& f)
{
int err = TRectype::remove(f);
if (err == NOERR)
err = _recarr.remove();
return err;
}
///////////////////////////////////////////////////////////
// TRiga_scadenze
///////////////////////////////////////////////////////////
TRiga_scadenze::TRiga_scadenze()
: TTree_rectype(LF_SCADENZE, LF_PAGSCA, "NRIGP")
{
zero();
}
///////////////////////////////////////////////////////////
// TRiga_partite
///////////////////////////////////////////////////////////
TRiga_partite::TRiga_partite()
: TTree_rectype(LF_PARTITE, LF_SCADENZE, "NRATA")
{
zero();
}
TRiga_partite::TRiga_partite(const TRiga_partite& r)
: TTree_rectype(r)
{}
int TRiga_partite::read(TBaseisamfile& f, word op)
{
int err = TRectype::read(f, op);
if (err == NOERR && get_int(PART_TIPOMOV) == 1)
{
TRiga_scadenze* s = new TRiga_scadenze;
copy_key_to_row(*s);
err = _recarr.read(s); // Deve esistere almento una scadenza
#ifdef DBG
if (err != NOERR)
yesnofatal_box("Riga di partite senza nessuna scadenza");
#endif
}
else
_recarr.destroy_rows();
return err;
}
TObject* TRiga_partite::dup() const
{
return new TRiga_partite(*this);
}
int TRiga_partite::add_rata(const TRectype& r)
{
return 1;
}
int TRiga_partite::ultimo_pagamento(int r) const
{
const TRiga_scadenze& s = rata(r);
return s.rows_array().last_row();
}
// Controlla se la rata r e' stata completamente pagata
bool TRiga_partite::rata_pagata(int r) const
{
const TRiga_scadenze& scad = rata(r);
real importo(scad.get(SCAD_IMPORTO));
importo -= scad.get_real(SCAD_IMPORTOPAG);
const bool pagata = importo.is_zero();
return pagata;
}
///////////////////////////////////////////////////////////
// TPartita
///////////////////////////////////////////////////////////
TPartita::TPartita(int anno, const char* num)
: _scad(LF_SCADENZE, SCAD_NRATA), _part(LF_PARTITE, PART_NRIGA)
TPartita::TPartita(const TBill& clifo, int anno, const char* num)
: _part(LF_PARTITE, PART_NRIGA), _unassigned(LF_PAGSCA, "NRIGP")
{
read(anno, num);
read(clifo, anno, num);
}
int TPartita::add_riga(const TRectype& r)
int TPartita::add_riga(const TRiga_partite& r)
{
CHECK(r.num() == LF_PARTITE, "Tipo record errato");
@ -1076,7 +1242,7 @@ int TPartita::add_riga(const TRectype& r)
TImporto grow(imp);
const int n = r.get_int(PART_NRIGA);
CHECK(n > 0, "Numero riga nullo");
if (n <= righe())
if (n <= _part.last_row())
{
const TRectype& oldrow = riga(n);
const char osez = oldrow.get_char(PART_SEZ);
@ -1084,102 +1250,68 @@ int TPartita::add_riga(const TRectype& r)
const TImporto old(osez, oval);
grow -= old;
}
_totale += grow;
if (rate() > 0) // Se sono in aggiornamento (non nella read!)
{
const int nr = r.get_int(PART_NRATA);
TRectype scad = rata(nr);
real ip(scad.get(SCAD_IMPORTOPAG));
ip += grow.valore();
scad.put(SCAD_IMPORTOPAG, ip);
add_rata(scad);
}
return _part.add_row(r);
}
void TPartita::remove_riga(TRectype& z)
void TPartita::remove_riga(TRiga_partite& z)
{
z.zero(PART_IMPORTO);
add_riga(z);
_part.destroy_row(z, TRUE);
}
int TPartita::add_rata(const TRectype& r)
// Costruisce le righe della partita
bool TPartita::read(const TBill& clifo, int anno, const char* num)
{
return _scad.add_row(r);
}
// Costruisce le righe della partita a partire da 1
bool TPartita::read(int anno, const char* num)
{
TRectype partita(LF_PARTITE); partita.zero();
partita.put(PART_ANNO, anno); partita.put(PART_NUMPART, num);
TRiga_partite* partita = new TRiga_partite; // Record campione della partita
partita->put(PART_TIPOCF, clifo.tipo()); // Tipo clifo
if (clifo.tipo() <= ' ')
{
partita->put(PART_GRUPPO, clifo.gruppo()); // Scrivi gruppo e conto solamente
partita->put(PART_CONTO, clifo.conto()); // nei conti normali (no clifo)
}
partita->put(PART_SOTTOCONTO, clifo.sottoconto()); // Sottoconto o codice clifo
partita->put(PART_ANNO, anno); // Anno partita
partita->put(PART_NUMPART, num); // Numero partita
_part.read(partita);
TRectype scadenza(LF_SCADENZE); scadenza.zero();
scadenza.put(SCAD_ANNO, anno); scadenza.put(SCAD_NUMPART, num);
_scad.read(scadenza);
_totale.set('D', ZERO); // Azzera totale partita
for (int i = 1; i <= righe(); i++)
{
const TRectype& r = riga(i);
const char sez = r.get_char(PART_SEZ);
const real val = r.get_real(PART_IMPORTO);
const TImporto imp(sez, val);
_totale += imp;
}
TRectype unas(LF_PAGSCA); // Record campione pagamenti non assegnati
unas.zero();
unas.put(PART_TIPOCF, partita->get(PART_TIPOCF)); // Copia chiave partite
unas.put(PART_GRUPPO, partita->get(PART_GRUPPO));
unas.put(PART_CONTO, partita->get(PART_CONTO));
unas.put(PART_SOTTOCONTO, partita->get(PART_SOTTOCONTO));
unas.put(PART_ANNO, partita->get(PART_ANNO));
unas.put(PART_NUMPART, partita->get(PART_NUMPART));
unas.put(PART_NRIGA, 9999); // Numeri magici di non assegamento
unas.put(SCAD_NRATA, 9999);
_unassigned.read(unas);
return ok();
}
bool TPartita::reread()
{
TBill zio;
conto(zio);
const int year = anno();
const TString16 num = numero();
return read(year, num);
return read(zio, year, num);
}
bool TPartita::write(bool re)
{
const bool ok = _part.write(re) && _scad.write(re);
const bool ok = _part.write(re);
return ok;
}
int TPartita::ultimo_pagamento(int rata) const
{
int ultimo = 1;
for (int p = 1; p <= righe(); p++)
{
const TRectype& paga = riga(p);
if (paga.get_int(PART_NRATA) == rata)
{
const int u = paga.get_int(PART_NRIGA); // Non pretende che siano in ordine
if (u > ultimo) ultimo = u;
}
}
return ultimo;
}
// Controlla se la rata r e' stata completamente pagata
bool TPartita::rata_pagata(int r) const
{
const TRectype& scad = rata(r);
real importo(scad.get(SCAD_IMPORTO));
importo -= scad.get_real(SCAD_IMPORTOPAG);
const bool pagata = importo.is_zero();
return pagata;
}
TImporto TPartita::importo_speso(long nreg, int numrig) const
{
TImporto imp;
for (int r = righe(); r > 0; r--)
for (int r = _part.last_row(); r > 0; r--)
{
const TRectype& pag = riga(r);
@ -1188,7 +1320,10 @@ TImporto TPartita::importo_speso(long nreg, int numrig) const
{
const int num = pag.get_int(PART_NUMRIG);
if (num == numrig)
imp += TImporto(pag.get_char(PART_SEZ), pag.get_real(PART_IMPORTO));
{
imp = TImporto(pag.get_char(PART_SEZ), pag.get_real(PART_IMPORTO));
break;
}
}
}
@ -1198,7 +1333,7 @@ TImporto TPartita::importo_speso(long nreg, int numrig) const
void TPartita::update_reg_num(long nreg, const TRectype& mov)
{
for (int r = righe(); r > 0; r--)
for (int r = _part.last_row(); r > 0; r--)
{
TRectype& pag = _part.row(r, FALSE);
@ -1219,20 +1354,24 @@ void TPartita::update_reg_num(long nreg, const TRectype& mov)
///////////////////////////////////////////////////////////
// Certified 99%
const TString& TPartite_array::key(int anno, const char* num)
const TString& TPartite_array::key(const TBill& clifo, int anno, const char* num)
{
_key.format("%4d%s", anno, num);
if (clifo.tipo() > ' ')
_key.format("%c%3d%3d%6ld%4d%s", clifo.tipo(), 0, 0, clifo.sottoconto(), anno, num);
else
_key.format("%c%3d%3d%6ld%4d%s",
clifo.tipo(), clifo.gruppo(), clifo.conto(), clifo.sottoconto(), anno, num);
return _key;
}
// Certified 99%
TPartita* TPartite_array::find(int anno, const char* num, bool create)
TPartita* TPartite_array::find(const TBill& clifo, int anno, const char* num, bool create)
{
const TString& k = key(anno, num);
const TString& k = key(clifo, anno, num);
TPartita* p = (TPartita*)objptr(k);
if (p == NULL && create)
{
p = new TPartita(anno, num);
p = new TPartita(clifo, anno, num);
if (p->ok())
add(k, p);
else
@ -1246,14 +1385,15 @@ TPartita* TPartite_array::find(int anno, const char* num, bool create)
TPartita* TPartite_array::find(const TRectype& r, bool create)
{
TBill zio; zio.get(r);
const int anno = r.get_int(PART_ANNO);
const char* num = r.get_str(PART_NUMPART);
return find(anno, num, create);
return find(zio, anno, num, create);
}
TPartita& TPartite_array::partita(int anno, const char* num)
TPartita& TPartite_array::partita(const TBill& clifo, int anno, const char* num)
{
TPartita* game = find(anno, num, TRUE);
TPartita* game = find(clifo, anno, num, TRUE);
CHECKS(game, "Partita errata ", num);
return *game;
}
@ -1295,7 +1435,7 @@ int TPartite_array::add_reg_num(long nreg, int numrig)
const TRectype filter(part);
TCursor cur(&rel, "", 3, &filter, &filter);
TCursor cur(&rel, "", 2, &filter, &filter);
for (cur = 0; cur.ok(); ++cur)
partita(part); // Aggiungi partita se non esiste gia'

View File

@ -165,57 +165,103 @@ public:
#include <partite.h>
#endif
class TPartita : public TObject
class TTree_rectype : public TRectype
{
TRecord_array _scad, _part;
TImporto _totale;
protected:
TRecord_array _recarr;
public: // TObject
virtual bool ok() const { return rate() > 0; }
void copy_key_to_row(TRectype& row) const;
int fill_array();
protected: // TRectype
virtual TObject* dup() const;
virtual int read(TBaseisamfile& f, word op = _isequal);
virtual int next(TBaseisamfile& f);
virtual int write(TBaseisamfile& f) const;
virtual int rewrite(TBaseisamfile& f) const;
virtual int remove(TBaseisamfile& f);
public:
int add_riga(const TRectype& r);
const TRectype& riga(int r) const { return _part.row(r); }
void remove_riga(TRectype& z);
int righe() const { return _part.rows(); }
const TRecord_array& rows_array() const { return _recarr; }
TTree_rectype(const TRectype& testata, const TRectype& riga, const char* num);
TTree_rectype(int testata, int riga, const char* num);
TTree_rectype(const TTree_rectype& t);
virtual ~TTree_rectype() {}
};
class TRiga_scadenze : public TTree_rectype
{
public:
TRiga_scadenze();
virtual ~TRiga_scadenze() {}
};
class TRiga_partite : public TTree_rectype
{
public: // TTree_rectype
virtual TObject* dup() const;
virtual int read(TBaseisamfile& f, word op);
public:
int rate() const { return _recarr.rows(); }
TRiga_scadenze& rata(int r) const { return (TRiga_scadenze&)_recarr.row(r); }
bool rata_pagata(int r) const;
int add_rata(const TRectype& r);
const TRectype& rata(int r) const { return _scad.row(r); }
int rate() const { return _scad.rows(); }
int ultimo_pagamento(int rata) const;
TRiga_partite();
TRiga_partite(const TRiga_partite& r);
virtual ~TRiga_partite() {}
};
class TPartita : public TObject
{
TRecord_array _part;
TRecord_array _unassigned;
public: // TObject
virtual bool ok() const { return _part.rows() > 0; }
public:
int add_riga(const TRiga_partite& r);
const TRiga_partite& riga(int r) const { return (const TRiga_partite&)_part.row(r); }
TRecord_array& rows_array() { return _part; }
void remove_riga(TRiga_partite& z);
bool reread();
bool read(int anno, const char* num);
bool read(const TBill& clifo, int anno, const char* num);
bool write(bool re = FALSE);
bool rewrite() { return write(TRUE); }
int anno() const { return riga(1).get_int(PART_ANNO); }
const TString& numero() const { return riga(1).get(PART_NUMPART); }
const TString& descrizione() const { return riga(1).get(PART_DESCR); }
const TImporto& totale() const { return _totale; }
void conto(TBill& c) const { c.get(_part.key()); }
int anno() const { return _part.key().get_int(PART_ANNO); }
const TString& numero() const { return _part.key().get(PART_NUMPART); }
const TString& descrizione() const { return _part.key().get(PART_DESCR); }
TImporto importo_speso(long numreg, int numrig) const;
void update_reg_num(long nreg, const TRectype& mov);
TPartita(int anno, const char* num);
TPartita(const TBill& clifo, int anno, const char* num);
};
class TPartite_array : private TAssoc_array
{
TString16 _key; // Work string
TString80 _key; // Work string
protected:
const TString& key(int anno, const char* num); // Build key for TAssoc_array
TPartita* find(int anno, const char* numero, bool create);
const TString& key(const TBill& clifo, int anno, const char* num); // Build key for TAssoc_array
TPartita* find(const TBill& clifo, int anno, const char* numero, bool create);
TPartita* find(const TRectype& part, bool create);
public: // TAssoc_array
virtual void destroy() { TAssoc_array::destroy(); }
public:
TPartita& partita(int anno, const char* numero);
TPartita& partita(const TBill& clifo, int anno, const char* numero);
TPartita& partita(const TRectype& r);
bool write(bool re = FALSE);
@ -229,6 +275,7 @@ public:
TPartita* next() { return (TPartita*)get(); }
TPartite_array() {}
virtual ~TPartite_array() {}
};
#endif