Gestione note di credito

git-svn-id: svn://10.65.10.50/trunk@1818 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1995-09-13 16:01:30 +00:00
parent 662b7d8bba
commit 8d43a014c7
10 changed files with 280 additions and 175 deletions

View File

@ -235,24 +235,24 @@ bool TPrimanota_application::read_caus(const char* cod, int year)
m->efield(F_DATADOC).check_type(dob ? CHECK_REQUIRED : CHECK_NORMAL); // Data doc. obbligatoria
m->enable(F_PROVVISORIO, !_is_saldaconto); // Il saldaconto vieta i movimenti provvisori
const bool nota_credito = _is_saldaconto && causale().tipomov() == 2;
const bool show_games = is_pagamento() || nota_credito;
TMask& cgm = cgs().sheet_mask();
cgm.set_handler(100, show_games ? showpartite_handler : NULL); // bottoncino riga
cgm.enable(100, show_games);
if (iva == nessuna_iva)
{
TMask& cgm = cgs().sheet_mask();
cgm.set_handler(100, _is_saldaconto ? showpartite_handler : NULL); // bottoncino riga
cgm.enable(100, _is_saldaconto);
m->show(S_TIPORIGA, _is_saldaconto);
}
else
{
// m->enable_page(2, m->get(F_NUMRIF).empty());
m->efield(F_CODPAG).check_type(_is_saldaconto ? CHECK_REQUIRED : CHECK_NORMAL); // Cod. pag. obbligatorio
m->show(S_TIPORIGA, is_pagamento());
}
else
{
m->efield(F_CODPAG).check_type(_is_saldaconto ? CHECK_REQUIRED : CHECK_NORMAL);
m->efield(F_CODPAG).enable(!nota_credito);
m->enable_page(2, _is_saldaconto && !nota_credito);
m->show(F_ANNORIF, _is_saldaconto); // Mostra/nasconde anno e riferimento partita
m->show(F_NUMRIF, _is_saldaconto);
// m->enable(F_ANNORIF, ins); // Dis/abilita anno e riferimento partita
// m->enable(F_NUMRIF, ins);
m->field(F_NUMRIF).set_justify(iva == iva_acquisti ? _num_for : _num_cli);
const bool av = causale().reg().agenzia_viaggi();
@ -350,13 +350,6 @@ bool TPrimanota_application::changing_mask(int mode)
#if XVT_OS == XVT_OS_WIN
if (flag && !_sheet_shown)
{
/*
if (iva() != nessuna_iva)
{
curr_mask().show_page(2);
do_events();
}
*/
curr_mask().show_page(1);
do_events();
_sheet_shown = TRUE;
@ -652,8 +645,8 @@ int TPrimanota_application::read(TMask& m)
if (to_swap) imposta = -imposta;
if (imponibile.sign() * imposta.sign() < 0)
{
warning_box("Registrazione con imponibile e imposta con segni discordi:\n"
"assegnato il segno dell'imponibile");
error_box("Registrazione con imponibile e imposta con segni discordi:\n"
"assegnato il segno dell'imponibile");
imposta = -imposta;
}
riga.add(imposta.string()); // Imposta 104
@ -663,10 +656,10 @@ int TPrimanota_application::read(TMask& m)
}
calcola_imp(); // Calcola totale imponibile ed imposte
TString16 dt(m.get(F_DATAREG));
if (!m.get(F_NUMRIF).empty())
if (is_saldaconto() && causale().tipomov() != 2) // Ci sono scadenze
{
const TString16 dt(m.get(F_DATAREG));
set_numrif(m.get(F_NUMRIF));
set_pagamento(m.get(F_CODPAG), dt);
if (!read_scadenze(m))
@ -848,6 +841,8 @@ int TPrimanota_application::write(const TMask& m)
_saldi.registra();
check_saldi();
bool salvaconto = FALSE;
if (iva() != nessuna_iva)
{
causale().reg().reread(); // Aggiorna protocollo IVA
@ -865,17 +860,22 @@ int TPrimanota_application::write(const TMask& m)
genera_incasso(causimm); // Genera incasso immediato
}
}
if (causale().tipomov() == 2)
salvaconto = TRUE;
}
else
{
if (is_saldaconto())
{
const long old_nreg = numreg - (lasterr == _isreinsert ? 1 : 0);
partite().update_reg(_rel->lfile().curr(), old_nreg);
partite().rewrite();
}
salvaconto = is_pagamento();
}
if (salvaconto)
{
const long old_nreg = numreg - (lasterr == _isreinsert ? 1 : 0);
partite().update_reg(_rel->lfile().curr(), old_nreg);
partite().rewrite();
}
link_m770();
}
@ -894,15 +894,24 @@ int TPrimanota_application::rewrite(const TMask& m)
check_saldi();
if (_is_saldaconto)
{
{
bool salvaconto = FALSE;
if (iva() != nessuna_iva)
{
write_scadenze(m);
{
if (causale().tipomov() == 2)
salvaconto = TRUE;
else
write_scadenze(m);
}
else
{
_partite.update_reg(_rel->lfile().curr());
_partite.rewrite();
{
salvaconto = is_pagamento();
}
if (salvaconto)
{
partite().update_reg(_rel->lfile().curr());
partite().rewrite();
}
}
@ -1164,6 +1173,24 @@ long TPrimanota_application::calcola_m770(int tipo_coll, real& spese, real& comp
}
}
if (tipo_coll == 4)
{
TBill zio; causale().bill(2, zio);
TString_array& rcg = cgs().rows_array();
for (int i = 0; i < rcg.items(); i++)
{
TToken_string& r = rcg.row(i);
const TBill bill(r, 3, 0x0);
if (zio == bill)
{
TImporto imp; imp = r;
ritfis = imp.valore();
break;
}
}
}
return forn;
}
@ -1212,7 +1239,7 @@ bool TPrimanota_application::link_m770()
}
break;
case 2:
tipo_coll = 4;
calcola_m770(tipo_coll = 4, spese, compenso, imposte, ritenute);
break;
case 6:
calcola_m770(tipo_coll = 6, spese, compenso, imposte, ritenute);

View File

@ -25,7 +25,7 @@
#define S_NUMDOC 106
#define S_DESCR 107
#define S_RATA 108
#define S_DATASCAD 109
#define S_DATA_SCAD 109
#define S_IMPORTO_SCAD 110
#define S_IMPORTOVAL_SCAD 111
#define S_SEZIONE_SCAD 112
@ -35,8 +35,7 @@
#define S_IMPORTOVAL 115
#define S_SALDOACC 116
#define S_RESIDUORATA 117
#define S_DATAPAG 118
#define S_CODPAG 119
#define S_DATAPAG 119
#define S_TIPOPAG 120
#define S_TIPO 121
#define S_GRUPPO 122

View File

@ -71,7 +71,6 @@ BEGIN
OUTPUT P_DATACAMBIO D0
OUTPUT P_CAMBIO R10
GROUP 3
CHECKTYPE NORMAL
END
NUMBER P_CAMBIO 15 5
@ -93,6 +92,7 @@ END
STRING P_NUMERO 7
BEGIN
PROMPT 21 3 "Numero "
FLAGS "U"
END
NUMBER P_RESIDUO 15
@ -236,7 +236,7 @@ END
NUMBER 104 5
BEGIN
PROMPT 1 3 "Numero reg. "
PROMPT 1 3 "Numero reg. "
END
DATE 105
@ -246,7 +246,7 @@ END
NUMBER 110 5
BEGIN
PROMPT 1 4 "Numero doc. "
PROMPT 1 4 "Numero doc. "
END
NUMBER 111 5
@ -256,7 +256,7 @@ END
DATE 106
BEGIN
PROMPT 30 4 "Data scad. "
PROMPT 30 4 "Data scad. "
END
STRING 109 50

View File

@ -56,7 +56,7 @@ BEGIN
FIELD NRATA
END
DATE S_DATASCAD
DATE S_DATA_SCAD
BEGIN
PROMPT 57 1 "Scadenza "
FLAGS "D"
@ -152,6 +152,7 @@ BEGIN
PROMPT 38 8 "Ritenute professionali "
PICTURE "."
FIELD RITENUTE
GROUP 2
END
LIST S_SALDOACC 1 12
@ -160,6 +161,7 @@ BEGIN
ITEM "A|Acconto"
ITEM "S|Saldo"
FIELD ACCSAL
GROUP 2
END
LIST S_TIPOPAG 2 35
@ -178,6 +180,12 @@ BEGIN
FIELD TIPOPAG
END
DATE S_DATAPAG
BEGIN
PROMPT 2 11 "Data pag. "
FIELD DATAPAG
END
TEXT DLG_NULL
BEGIN
PROMPT 2 12 "@bContropartita"
@ -197,12 +205,14 @@ NUMBER S_GRUPPO 3
BEGIN
PROMPT 24 12 "Gruppo "
FIELD GRUPPOC
GROUP 2
END
NUMBER S_CONTO 3
BEGIN
PROMPT 42 12 "Conto "
FIELD CONTOC
GROUP 2
END
NUMBER S_SOTTOCONTO 6
@ -223,6 +233,7 @@ BEGIN
OUTPUT S_DESCRCONTO DESCR
CHECKTYPE NORMAL
VALIDATE REQIF_FUNC 1 S_IMPORTO
GROUP 2
END
STRING S_DESCRCONTO 50
@ -236,6 +247,7 @@ BEGIN
DISPLAY "Sottoconto" SOTTOCONTO
COPY OUTPUT S_SOTTOCONTO
CHECKTYPE REQUIRED
GROUP 2
END
STRING S_CODDESC 5

View File

@ -417,7 +417,7 @@ HIDDEN bool can_remove(TToken_string& s)
void TPrimanota_application::cgs_pack()
{
TString_array& rows = cgs().rows_array();
const bool pagamento = is_saldaconto() && iva() == nessuna_iva;
const bool pagamento = is_pagamento();
for (int i = rows.items()-1; i >= 0; i--)
{
@ -497,7 +497,9 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k)
}
const long numreg = f.mask().get_long(F_NUMREG);
const bool paga = app().is_saldaconto() && app().iva() == nessuna_iva ;
const bool paga = app().is_pagamento();
const bool nota = app().is_saldaconto() && app().causale().tipomov() == 2;
TImporto saldaconto;
TSheet_field& cg = app().cgs();
@ -517,13 +519,13 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k)
return f.error_box("La contropartita della riga %d non e' completa", i+1);
empty = FALSE;
if (paga)
if (paga || nota)
{
const char tipo = row_type(r);
if (tipo == 'K')
if (tipo == 'K' || tipo == 'T')
{
const int currig = i+1;
const TImporto speso = app().partite().importo_speso(numreg, currig, TRUE);
const TImporto speso = app().partite().importo_speso(numreg, currig);
if (importo != speso)
{
const char* ss = speso.valore().string(".");
@ -721,7 +723,7 @@ bool TPrimanota_application::cg_notify(TSheet_field& cg, int r, KEY k)
app().calcola_saldo();
break;
case K_INS:
if (app().iva() == nessuna_iva && app().is_saldaconto())
if (app().is_pagamento())
{
const char tipo = app().curr_mask().get(S_TIPORIGA)[0];
if (tipo == 'K' || tipo == 'G')
@ -778,7 +780,18 @@ bool TPrimanota_application::descr_handler(TMask_field& f, KEY k)
// Handler per le colonne 'Dare' e 'Avere' dello sheet contabile.
// Scrivendo qualcosa in dare (101) cancella l'importo in avere (102) e viceversa
bool TPrimanota_application::dareavere_handler(TMask_field& f, KEY k)
{
{
if (k == K_F8 && app().is_pagamento())
{
const long numreg = app().curr_mask().get_long(F_NUMREG);
const int numrig = app().cgs().selected()+1;
const TImporto speso = app().partite().importo_speso(numreg, numrig);
const char* ss = speso.valore().string();
TMask& m = f.mask();
m.set(101, speso.sezione() == 'D' ? ss : "");
m.set(102, speso.sezione() == 'A' ? ss : "");
}
if (k == K_TAB && f.focusdirty() && f.get().not_empty())
{
const int id = 203-f.dlg(); // Calcola id del campo da resettare

View File

@ -163,6 +163,7 @@ protected:
bool gestione_saldaconto() const { return _ges_sal; }
bool is_saldaconto() const { return _is_saldaconto; }
void set_saldaconto(bool b) { _is_saldaconto = b; }
bool is_pagamento() const { return is_saldaconto() && iva() == nessuna_iva; }
bool npart_is_prot() { return _npart_is_prot; }
void fill_sheet(TMask& m) const;
@ -182,7 +183,6 @@ protected:
TBill& ivas_bill(TBill& tc);
bool read_caus(const char* cod, int year);
TCausale& causale() { return *_causale; }
TLibro_giornale& giornale() { return *_giornale; }
bool test_swap(bool ritsoc);
@ -229,6 +229,7 @@ protected:
public:
static char row_type(const TToken_string& s);
TCausale& causale() { return *_causale; }
TPartite_array& partite() { return _partite; } // Partite editate
int nuovo_pagamento(TPartita& p, int nriga, int rata, int rmov);
bool edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp);

View File

@ -35,14 +35,14 @@ protected:
static void add_importo(TToken_string& s, const TImporto& i, int dec = 0);
TImporto get_importo(TToken_string& s, int pos) const;
void fill_partite() const;
void fill_partite(int anno = 0, const char* numero = "");
real aggiorna_residuo();
void update_partita(const TPartita& game, int prow) const;
void update_saldo_clifo() const;
int update_partita(const TPartita& game, int prow);
void update_saldo_clifo();
bool cerca_valuta(TValuta& val) const;
void aggiorna_valuta(const TValuta& val) const;
void aggiorna_valuta(const TValuta& val);
public:
TSheet_field& partite() const { return (TSheet_field&)field(P_PARTITE); }
@ -54,8 +54,8 @@ public:
};
TGame_mask::TGame_mask(const TBill& bill, long numreg, int riga)
: TMask("cg2100p"), _conto(bill), _numreg(numreg), _numrig(riga+1)
{
: TMask("cg2100p"), _conto(bill), _numreg(numreg), _numrig(riga)
{
const char tipocf[2] = { _conto.tipo(), '\0' };
set(P_TIPOC, tipocf);
set(P_GRUPPO, _conto.gruppo());
@ -85,8 +85,6 @@ TGame_mask::TGame_mask(const TBill& bill, long numreg, int riga)
partite().set_notify(partite_notify);
scadenze().sheet_mask().set_handler(100, edit_scadenza_handler);
aggiorna_residuo();
}
///////////////////////////////////////////////////////////
@ -137,7 +135,7 @@ bool TGame_mask::show_all_handler(TMask_field& f, KEY k)
{
if (k == K_SPACE)
{
const TGame_mask& gm = (const TGame_mask&)f.mask();
TGame_mask& gm = (TGame_mask&)f.mask();
gm.fill_partite();
}
return TRUE;
@ -160,7 +158,7 @@ bool TGame_mask::cambio_handler(TMask_field& f, KEY k)
if (k == K_TAB && f.focusdirty() &&
yesno_box("Aggiornare gli importi dei pagamenti?"))
{
const TGame_mask& gm = (const TGame_mask&)f.mask();
TGame_mask& gm = (TGame_mask&)f.mask();
TValuta val; val.get(gm, P_VALUTA, P_DATACAMBIO, P_CAMBIO);
gm.aggiorna_valuta(val);
}
@ -174,7 +172,7 @@ bool TGame_mask::cambio_handler(TMask_field& f, KEY k)
real TGame_mask::aggiorna_residuo()
{
TImporto residuo(app().get_cgs_imp(_numrig-1));
residuo -= app().partite().importo_speso(_numreg, _numrig, TRUE);
residuo -= app().partite().importo_speso(_numreg, _numrig);
set(P_RESIDUO, residuo.valore().string());
return residuo.valore();
}
@ -197,9 +195,10 @@ bool TGame_mask::cerca_valuta(TValuta& val) const
return found;
}
void TGame_mask::aggiorna_valuta(const TValuta& val) const
void TGame_mask::aggiorna_valuta(const TValuta& val)
{
bool found = FALSE;
int annorif = 0;
TString16 numrif;
TPartite_array& pa = app().partite();
for (TPartita* game = pa.first(); game; game = pa.next())
@ -215,8 +214,12 @@ void TGame_mask::aggiorna_valuta(const TValuta& val) const
TRiga_partite& sum = game->riga(p);
if (sum.get_long(PART_NREG) == _numreg &&
sum.get_int(PART_NUMRIG) == _numrig)
{
found = TRUE;
{
if (annorif == 0)
{
annorif = sum.get_int(PART_ANNO);
numrif = sum.get(PART_NUMPART);
}
TRectype pag(scad.row(p));
real imp(pag.get(PAGSCA_IMPORTOVAL));
val.val2lit(imp);
@ -228,8 +231,21 @@ void TGame_mask::aggiorna_valuta(const TValuta& val) const
}
}
if (found)
fill_partite();
if (annorif != 0)
{
const bool nota_credito = app().causale().tipomov() == 2;
if (nota_credito)
{
const TMask& cm = app().curr_mask();
const int anno = cm.get_int(F_ANNORIF);
if (anno != 0)
{
annorif = anno;
numrif = cm.get(F_NUMRIF);
}
}
}
fill_partite(annorif, numrif);
}
bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
@ -430,15 +446,12 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k)
int nrigp = m.get_int(112);
if (nrigp == 0)
{
const int rmov = app().cgs().selected()+1;
nrigp = app().nuovo_pagamento(game, nriga, nrata, rmov);
nrigp = app().nuovo_pagamento(game, nriga, nrata, gm._numrig);
}
else
{
const TMask& cm = app().curr_mask();
const long cur_reg = cm.get_long(F_NUMREG);
const long nreg = m.get_long(104);
if (cur_reg != nreg)
if (nreg != gm._numreg)
return f.error_box("Modificare il movimento %ld", nreg);
}
@ -448,7 +461,6 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k)
{
gm.update_partita(game, gm._riga_partite);
partite_notify(gm.partite(), gm._riga_partite, K_TAB);
gm.aggiorna_residuo();
}
}
return TRUE;
@ -461,11 +473,18 @@ bool TGame_mask::nuovo_handler(TMask_field& f, KEY k)
{
TMask new_game("Nuova partita", 1, 24, 5);
new_game.add_number(P_ANNO, 0, "Anno ", 1, 1, 4, "A");
new_game.add_string(P_NUMERO, 0, "Partita ", 1, 2, 7);
new_game.add_string(P_NUMERO, 0, "Partita ", 1, 2, 7, "U");
new_game.add_button(DLG_OK, 0, "" , -12, 3, 8, 2);
new_game.add_button(DLG_CANCEL, 0, "" , -22, 3, 8, 2);
new_game.first_focus(P_NUMERO);
if (app().causale().tipomov() == 2)
{
const TMask& cm = app().curr_mask();
new_game.set(P_ANNO, cm.get(F_ANNORIF));
new_game.set(P_NUMERO, cm.get(F_NUMRIF));
}
if (new_game.run() == K_ENTER)
{
TGame_mask& gm = (TGame_mask&)f.mask();
@ -482,9 +501,7 @@ bool TGame_mask::nuovo_handler(TMask_field& f, KEY k)
if (game.ok())
{
game.write();
gm.send_key(K_SPACE, P_SHOWALL); // Aggiorna sheet partite
gm.set(P_ANNO, anno);
gm.set(P_NUMERO, numero, TRUE); // Selezione nuova partita
gm.fill_partite(anno, numero); // Aggiorna sheet partite
}
else
app().partite().destroy(gm.conto(), anno, numero);
@ -518,37 +535,53 @@ TImporto TGame_mask::get_importo(TToken_string& s, int pos) const
}
void TGame_mask::update_partita(const TPartita& game, int prow) const
int TGame_mask::update_partita(const TPartita& game, int prow)
{
TImporto saldo, doc, pag, imp;
game.calcola_saldo(saldo, doc, pag, imp);
TSheet_field& games = partite();
int riga_fatt = game.prima_fattura();
if (riga_fatt <= 0) riga_fatt = game.first(); // E' un anticipo
const TRiga_partite& riga = game.riga(riga_fatt);
TToken_string &r = partite().row(prow); // Stringa di lavoro per lo sheet
r.cut(0);
r.add(riga.get(PART_ANNO));
r.add(riga.get(PART_NUMPART));
r.add(riga.get(PART_DATADOC));
r.add(riga.get(PART_NUMDOC));
add_importo(r, saldo);
add_importo(r, doc);
add_importo(r, pag);
add_importo(r, imp);
r.add(riga.get(PART_DESCR));
TToken_string &r = games.row(prow); // Stringa di lavoro per lo sheet
if (game.esiste(riga_fatt)) // Esiste veramente
{
const TRiga_partite& riga = game.riga(riga_fatt);
r.cut(0);
r.add(riga.get(PART_ANNO));
r.add(riga.get(PART_NUMPART));
r.add(riga.get(PART_DATADOC));
r.add(riga.get(PART_NUMDOC));
add_importo(r, saldo);
add_importo(r, doc);
add_importo(r, pag);
add_importo(r, imp);
r.add(riga.get(PART_DESCR));
}
else
{
r.add("", 4);
r.add("", 5);
r.add("", 6);
r.add("", 7);
}
if (prow >= 0)
{
TSheet_field& games = partite();
games.force_update(prow);
update_saldo_clifo();
games.force_update(games.items()-1);
}
aggiorna_residuo();
}
else
prow = partite().items()-1;
return prow;
}
void TGame_mask::update_saldo_clifo() const
void TGame_mask::update_saldo_clifo()
{
TString_array& s = partite().rows_array();
@ -584,10 +617,12 @@ void TGame_mask::update_saldo_clifo() const
r << "fornitore";
}
void TGame_mask::fill_partite() const
{
void TGame_mask::fill_partite(int annorif, const char* numrif)
{
const bool all = get(P_SHOWALL).not_empty();
int first_game = -1;
TString_array& a = partite().rows_array();
a.destroy();
@ -602,7 +637,6 @@ void TGame_mask::fill_partite() const
}
else conto().put(partita.curr()); // Scrive completamente i conti normali
const long nreg = app().curr_mask().get_long(F_NUMREG);
const TRectype filter(partita.curr()); // Record campione
for (int err = partita.read(_isgteq);
@ -622,8 +656,12 @@ void TGame_mask::fill_partite() const
should_delete_game = TRUE;
}
if (all || (!game->chiusa() || game->mov2rig(nreg, 0) > 0))
update_partita(*game, -1);
int added = -1;
if (all || (!game->chiusa() || game->mov2rig(_numreg, 0) > 0))
added = update_partita(*game, -1);
if (first_game < 0 && added >= 0 && anno == annorif && num == numrif)
first_game = added;
if (should_delete_game)
delete game;
@ -632,9 +670,13 @@ void TGame_mask::fill_partite() const
}
update_saldo_clifo();
partite().force_update();
aggiorna_residuo();
if (a.items() > 0)
partite_notify(partite(), 0, K_TAB);
{
if (first_game < 0) first_game = 0;
partite_notify(partite(), first_game, K_TAB);
}
else
{
scadenze().destroy();
@ -681,7 +723,7 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad)
set(S_NUMPROT, fatt.get(PART_PROTIVA)); // Protocollo IVA
set(S_DESCR, fatt.get(PART_DESCR)); // Descrizione documento
set(S_DATASCAD, scad.get(SCAD_DATASCAD)); // Data della scadenza
set(S_DATA_SCAD, scad.get(SCAD_DATASCAD)); // Data della scadenza
set(S_SEZIONE_SCAD, scad.riga().sezione()); // Sezione della rata
set(S_IMPORTO_SCAD, scad.get(SCAD_IMPORTO)); // Importo della rata
set(S_IMPORTOVAL_SCAD, scad.get(SCAD_IMPORTOVAL)); // Importo in valuta
@ -704,9 +746,14 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad)
const TPartita& p = scad.partita();
const int nrigp = oldpag.get_int(PAGSCA_NRIGP);
const TRiga_partite& sum = p.riga(nrigp);
_valuta.get(sum);
const long numreg = sum.get_long(PART_NREG);
const int numrig = sum.get_int(PART_NUMRIG);
TImporto residuo(app().get_cgs_imp(numrig-1));
residuo -= app().partite().importo_speso(numreg, numrig);
set(S_RESIDUOPAG, residuo.valore().string());
// Il flag di saldo/acconto e' attivo solo se non ci sono acconti
bool sa = oldpag.get_int(PAGSCA_NRIGA) != TPartita::UNASSIGNED;
if (sa)
@ -715,7 +762,15 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad)
const TDate datapag(sum.get(PART_DATADOC));
sa = datapag >= datasca;
}
else
{
hide(S_RESIDUORATA);
}
enable(S_SALDOACC, sa);
const bool nota_credito = app().causale().tipomov() == 2;
if (nota_credito)
send_key(K_CTRL + K_SHIFT + 'c', -2); // Disabilita contropartita e ritenute
}
void TPay_mask::get_pag(TRectype& newpag) const
@ -724,7 +779,7 @@ void TPay_mask::get_pag(TRectype& newpag) const
rel.curr() = newpag;
autosave(&rel); // Load current record from mask
newpag = rel.curr();
}
}
bool TPay_mask::importo_handler(TMask_field& f, KEY k)
{
@ -764,31 +819,31 @@ bool TPrimanota_application::showpartite_handler(TMask_field& f, KEY k)
bool ok = TRUE;
TMask& m = f.mask();
if (m.get(116) == "K")
const char tipo = m.get(116)[0];
if (tipo == 'K' || (tipo == 'T' && app().causale().tipomov() == 2))
{
TSheet_field& s = *m.get_sheet();
const int riga = s.selected();
if (k == K_SPACE)
{
const bool dirty = app().edit_partite(riga);
if (dirty)
{
if (m.field(103).enabled())
app().disable_cgs_cells(riga, 'K');
const bool ok = app().edit_partite(riga);
if (ok)
k = K_ENTER;
}
}
if (k == K_ENTER)
{
const long curreg = app().curr_mask().get_long(F_NUMREG);
const TImporto importo(app().get_cgs_imp(riga));
const TImporto speso(app().partite().importo_speso(curreg, riga+1, TRUE));
const TImporto speso(app().partite().importo_speso(curreg, riga+1));
if (importo != speso)
{
const char* ss = speso.valore().string(".");
return f.error_box("L'importo deve essere %s %c", ss, speso.sezione());
}
if (tipo == 'K' && !speso.is_zero())
app().disable_cgs_cells(riga, 'K');
}
}
return ok;
@ -798,8 +853,6 @@ bool TPrimanota_application::showpartite_handler(TMask_field& f, KEY k)
bool TPrimanota_application::edit_partite(int riga)
{
TToken_string& cgr = cgs().row(riga);
if (row_type(cgr) != 'K')
return FALSE; // Esci se non c'e' nessun importo
TImporto imp; imp = cgr;
if (imp.is_zero()) // Esci se 'importo e' nullo
@ -814,7 +867,7 @@ bool TPrimanota_application::edit_partite(int riga)
partite().update_reg(mov);
// Esecuzione maschera di selezione partite
TGame_mask mask(b, mov.get_long(MOV_NUMREG), riga);
TGame_mask mask(b, mov.get_long(MOV_NUMREG), riga+1);
mask.run();
cgs().force_update(); // Aggiornamento righe contabili
@ -822,12 +875,12 @@ bool TPrimanota_application::edit_partite(int riga)
}
int TPrimanota_application::nuovo_pagamento(TPartita& partita, int nriga, int rata, int rmov)
int TPrimanota_application::nuovo_pagamento(TPartita& partita, int nriga, int rata, int numrig)
{
TBill conto; partita.conto(conto); // Legge conto principale
const long numreg = curr_mask().get_long(F_NUMREG);
int nrigp = partita.mov2rig(numreg, rmov); // Cerca riga partita relativa alla riga rmov
int nrigp = partita.mov2rig(numreg, numrig); // Cerca riga partita relativa alla riga rmov
if (nrigp <= 0) // Devo creare una nuova riga di partita
{
@ -836,7 +889,7 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int nriga, int ra
// Copia dati movimento corrente
part.put(PART_NREG, numreg); // Numero operazione
part.put(PART_NUMRIG, rmov); // Riga su cui ho cliccato
part.put(PART_NUMRIG, numrig); // Riga su cui ho cliccato
part.put(PART_DATAREG, curr_mask().get(F_DATAREG));
part.put(PART_DATADOC, curr_mask().get(F_DATADOC));
part.put(PART_NUMDOC, curr_mask().get(F_NUMDOC));
@ -902,13 +955,15 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int nriga, int ra
case 9: // Bonifico
default:
caus = 2; break;
}
}
pagamento.put(PAGSCA_TIPOPAG, tp);
pagamento.put(PAGSCA_CODABIPR, scad.get(SCAD_CODABIPR));
pagamento.put(PAGSCA_CODCABPR, scad.get(SCAD_CODCABPR));
pagamento.put(PAGSCA_CODABI, scad.get(SCAD_CODABI));
pagamento.put(PAGSCA_CODCAB, scad.get(SCAD_CODCAB));
pagamento.put(PAGSCA_CODAG, scad.get(SCAD_CODAG));
pagamento.put(PAGSCA_DATAPAG, curr_mask().get(F_DATADOC));
}
TBill contro; causale().bill(caus, contro); // Legge conto contropartita
@ -937,19 +992,25 @@ int TPrimanota_application::nuovo_pagamento(TPartita& partita, int nriga, int ra
}
// deleting significato
// -1 non sto cancellando nulla
// 0 sto cancellando tutto
// 1 sto cancellando la prima riga contabile
// n sto cancellando la ennesima riga contabile
bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pag,
const TValuta& valuta, int deleting)
{
const int nriga = new_pag.get_int(PAGSCA_NRIGA); // Riga fattura
const int nrata = new_pag.get_int(PAGSCA_NRATA); // Numero rata
const int nrigp = new_pag.get_int(PAGSCA_NRIGP); // Riga pagamento
const TRectype& old_pag = p.pagamento(nriga, nrata, nrigp);
const TRiga_partite& somma = p.riga(nrigp);
const int riga_contabile = somma.get_int(PART_NUMRIG); // Riga movimento
if (deleting != 0)
{
const int nriga = new_pag.get_int(PAGSCA_NRIGA); // Riga fattura
const int nrata = new_pag.get_int(PAGSCA_NRATA); // Numero rata
const int nrigp = new_pag.get_int(PAGSCA_NRIGP); // Riga pagamento
const TRectype& old_pag = p.pagamento(nriga, nrata, nrigp);
const TRiga_partite& somma = p.riga(nrigp);
const char sez = somma.sezione(); // Sezione importo e ritenute
const char controsez = sez == 'A' ? 'D' : 'A'; // Sezione contropartita
const char sez = somma.sezione(); // Sezione importo e ritenute
const char controsez = sez == 'A' ? 'D' : 'A'; // Sezione contropartita
// Aggiornamento contopartita
const TImporto old_importo(controsez, old_pag.get_real(PAGSCA_IMPORTO));
@ -969,7 +1030,7 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa
}
// Importo della contropartita
if (!new_importo.is_zero())
if (!new_importo.is_zero() && new_conto.ok())
{
const int new_riga = bill2pos(new_conto, 'I');
if (new_riga < 0)
@ -1007,8 +1068,6 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa
if (deleting != 0)
{
const int riga_contabile = app().cgs().selected();
// Se c'e' differenza negli abbuoni
if (old_abbuono != new_abbuono || old_ap != new_ap)
{
@ -1111,21 +1170,22 @@ bool TPrimanota_application::edit_pagamento(TPartita& p, int nriga, int nrata, i
m.reset(S_RITENUTE); // Azzera ritenute
}
else
{
somma.put(PART_DESCR, m.get(S_DESCAGG)); // Aggiorna descrizione (comune ai pagamenti)
TRectype new_pag(oldpag);
m.get_pag(new_pag);
const TValuta val; // Non cambiare valuta!
notify_edit_pagamento(p, new_pag, val);
}
return key != K_ESC;
}
TRectype new_pag(oldpag);
m.get_pag(new_pag);
const TValuta val; // Non cambiare valuta!
notify_edit_pagamento(p, new_pag, val);
}
return key != K_ESC;
}
// Scorre tutte le righe della partita ed azzera i pagamenti relativi a alla riga contabile
// cancellata e decrementa i numeri riga superiori a numrig
bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg, int numrig)
{
{
bool found = FALSE;
for (int p = partita.last(); p > 0; p = partita.pred(p))
@ -1142,12 +1202,13 @@ bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg
if (sum.get_long(PART_NREG) == nreg &&
(numrig <= 0 || sum.get_int(PART_NUMRIG) == numrig))
{
TRectype pag(scad.row(s));
pag.zero(PAGSCA_IMPORTO);
pag.zero(PAGSCA_IMPORTOVAL);
pag.zero(PAGSCA_RITENUTE);
TRectype nul_pag(scad.row(s));
nul_pag.zero(PAGSCA_IMPORTO);
nul_pag.zero(PAGSCA_IMPORTOVAL);
nul_pag.zero(PAGSCA_RITENUTE);
nul_pag.put(PAGSCA_ACCSAL, 'A');
const TValuta val; // Non cambiare valuta
notify_edit_pagamento(partita, pag, val, numrig);
notify_edit_pagamento(partita, nul_pag, val, numrig);
found = TRUE;
}
}
@ -1167,11 +1228,8 @@ bool TPrimanota_application::notify_cgline_deletion(int numrig)
{
bool found = FALSE;
const long nreg = curr_mask().get_long(F_NUMREG);
partite().add_numreg(nreg); // Carica tutte le partite interessate
for (TPartita* game = _partite.first(); game; game = _partite.next())
found |= notify_cgline_deletion(*game, nreg, numrig);
return found;
}

View File

@ -47,7 +47,7 @@ END
NUMBER 102 15
BEGIN
PROMPT 42 5 "Avere "
PROMPT 43 5 "Avere "
HELP "Importo 'avere' del conto della riga"
FLAGS "RV"
PICTURE "."

View File

@ -149,7 +149,7 @@ void TValuta::set(TMask& m, short v, short d, short c) const
{
m.set(v, _cod);
m.set(d, _dat.string());
m.set(c, _cam.string(2));
m.set(c, _cam.string());
}
void TValuta::get(const TMask& m, short v, short d, short c)
@ -311,9 +311,9 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(int p, bool update)
{
TImporto diffcam;
if (in_valuta())
TRectype& pag = row(p);
if (pag.get_char(PAGSCA_ACCSAL) == 'S' && in_valuta())
{
TRectype& pag = row(p);
const char sez = partita().riga(p).sezione();
if (update)
@ -333,7 +333,7 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(int p, bool update)
else
{
if (update)
row(p).zero(PAGSCA_DIFFCAM);
pag.zero(PAGSCA_DIFFCAM);
}
return diffcam;
}
@ -403,9 +403,8 @@ bool TRiga_scadenze::modifica_pagamento(const TRectype& new_pag, const TValuta&
partita().chiusa(TRUE); // Aggiorna flag di chiusura
const bool empty = new_pag.get(PAGSCA_IMPORTO).empty() &&
new_pag.get(PAGSCA_ABBUONI).empty() &&
new_pag.get(PAGSCA_DIFFCAM).empty();
const bool empty = new_pag.get_char(PAGSCA_ACCSAL) != 'S' &&
new_pag.get_real(PAGSCA_IMPORTO).is_zero();
if (empty)
rows_array().destroy_row(nrigp);
@ -628,7 +627,7 @@ bool TPartita::esiste(int nriga, int nrata, int nrigp) const
}
// Ritorna l'importo in lire speso su di una riga contabile
TImporto TPartita::importo_speso(long nreg, int numrig, bool extra) const
TImporto TPartita::importo_speso(long nreg, int numrig) const
{
TImporto imp;
@ -638,17 +637,15 @@ TImporto TPartita::importo_speso(long nreg, int numrig, bool extra) const
if (nreg == part.get_long(PART_NREG) && numrig == part.get_int(PART_NUMRIG))
{
imp += TImporto(part.sezione(), part.get_real(PART_IMPORTO));
if (extra)
TImporto abbuoni(part.get_char(PART_SEZABB), part.get_real(PART_ABBUONI));
const TValuta valuta(part);
if (!valuta.in_lire())
{
TImporto abbuoni(part.get_char(PART_SEZABB), part.get_real(PART_ABBUONI));
if (part.in_valuta())
{
abbuoni.valore() *= part.get_real(PART_CAMBIO);
abbuoni.valore().round();
imp += TImporto(part.get_char(PART_SEZDIFCAM), part.get_real(PART_DIFFCAM));
}
imp += abbuoni;
valuta.val2lit(abbuoni);
imp += TImporto(part.get_char(PART_SEZDIFCAM), part.get_real(PART_DIFFCAM));
}
imp += abbuoni;
}
}
@ -706,7 +703,7 @@ int TPartita::prima_fattura(long nreg) const
const TRiga_partite& row = riga(r);
const int tipomov = row.get_int(PART_TIPOMOV);
if (tipomov == 1 || tipomov == 2)
if (nreg == -1 || nreg == row.get_long(PART_NREG))
if (nreg <= 0 || nreg == row.get_long(PART_NREG))
return r;
}
return -1;
@ -720,8 +717,8 @@ int TPartita::primo_pagamento(long nreg) const
{
const TRiga_partite& row = riga(r);
const int tipomov = row.get_int(PART_TIPOMOV);
if (tipomov == 3) // TBI controllare per insoluti (tipomov == 6)
if (nreg == -1 || nreg == row.get_long(PART_NREG))
if (tipomov != 1)
if (nreg <= 0 || nreg == row.get_long(PART_NREG))
return r;
}
return -1;
@ -959,12 +956,10 @@ int TPartite_array::add_numreg(long nreg)
TRelation rel(LF_PARTITE);
TRectype& part = rel.lfile().curr();
// Costruzione filtro del cursore
// Costruzione cursore filtrato
part.zero();
part.put(PART_NREG, nreg);
const TRectype filter(part);
TCursor cur(&rel, "", 2, &filter, &filter);
for (cur = 0; cur.ok(); ++cur)
@ -976,12 +971,12 @@ int TPartite_array::add_numreg(long nreg)
return items();
}
TImporto TPartite_array::importo_speso(long nreg, int numrig, bool extra)
TImporto TPartite_array::importo_speso(long nreg, int numrig)
{
TImporto imp;
add_numreg(nreg);
for (TPartita* game = first(); game; game = next())
imp += game->importo_speso(nreg, numrig, extra);
imp += game->importo_speso(nreg, numrig);
return imp;
}

View File

@ -214,7 +214,7 @@ public:
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, bool extra) const;
TImporto importo_speso(long numreg, int numrig) const;
void update_reg(long nreg, const TRectype& mov);
void calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImporto& imp) const;
@ -257,7 +257,7 @@ public:
bool rewrite() { return write(TRUE); }
int add_numreg(long numreg); // Carica tutte le partite relative alla registrazione numreg
TImporto importo_speso(long numreg, int numrig, bool extra);
TImporto importo_speso(long numreg, int numrig);
void update_reg(const TRectype& mov, long old_reg = 0);
TPartita* first() { restart(); return next(); }