1342 lines
41 KiB
C++
Executable File
1342 lines
41 KiB
C++
Executable File
#include <defmask.h> // Serve per DLG_NEWREC
|
|
|
|
#include "cg2100p.h" // Campi maschere partite e pagamenti
|
|
|
|
#ifndef __EXTRA__
|
|
#include "cg2100.h" // Campi maschere prima nota
|
|
#include "cg2102.h" // Applicazione di prima nota
|
|
#endif
|
|
|
|
#include <clifo.h> // Archivio clienti/fornitori
|
|
#include <mov.h> // Archivio movimenti di prima nota
|
|
#include <pagsca.h> // Archivio pagamenti
|
|
#include <partite.h> // Archivio partite
|
|
#include <scadenze.h> // Archivio scadenze
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Maschera pagamenti
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TPay_mask : public TMask
|
|
{
|
|
real _da_pagare, _pagabile;
|
|
|
|
protected:
|
|
static bool importo_handler(TMask_field& f, KEY k);
|
|
static bool cambio_handler(TMask_field& f, KEY k);
|
|
|
|
public:
|
|
void set_pag(const TRectype& oldpag, const TRiga_scadenze& scad, const TImporto& importo);
|
|
void get_pag(TRectype& oldpag) const;
|
|
|
|
TPay_mask();
|
|
virtual ~TPay_mask() {}
|
|
};
|
|
|
|
TPay_mask::TPay_mask() : TMask("cg2100s")
|
|
{
|
|
}
|
|
|
|
void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad,
|
|
const TImporto& importo)
|
|
{
|
|
TRelation rel(LF_PAGSCA); // Working relation
|
|
rel.curr() = oldpag;
|
|
autoload(&rel); // Load current record on mask
|
|
|
|
const TPartita& p = scad.partita();
|
|
const int nrigp = oldpag.get_int(PAGSCA_NRIGP);
|
|
const TRiga_partite& sum = p.riga(nrigp);
|
|
const TRiga_partite& fatt = scad.riga();
|
|
|
|
TMask_field& group = field(S_RATA);
|
|
TString prompt(80);
|
|
prompt << "Partita:" << p.anno() << ' ' << p.numero()
|
|
<< " Riga:" << fatt.get_int(PART_NRIGA)
|
|
<< " Rata:" << scad.get_int(SCAD_NRATA)
|
|
<< " del " << scad.get_date(SCAD_DATASCAD).string();
|
|
group.set(prompt);
|
|
|
|
set(S_NUMDOC, fatt.get(PART_NUMDOC)); // Numero documento
|
|
set(S_DATADOC, fatt.get(PART_DATADOC)); // Data documento
|
|
set(S_NUMPROT, fatt.get(PART_PROTIVA)); // Protocollo IVA
|
|
|
|
set(S_DESCR, sum.get(PART_DESCR)); // Descrizione documento
|
|
set(S_DATAPAG, sum.get(PART_DATAPAG)); // Data pagamento
|
|
set(S_TIPOPAG, sum.get(PART_TIPOPAG)); // Tipo pagamento
|
|
|
|
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
|
|
|
|
const bool in_valuta = scad.in_valuta();
|
|
|
|
_da_pagare = scad.residuo(in_valuta).valore(); // Calcola residuo in valuta
|
|
|
|
TReal_field& res = (TReal_field&)field(S_RESIDUORATA);
|
|
res.set_decimals(in_valuta ? 2 : 0);
|
|
if (get(S_SALDOACC)[0] != 'S')
|
|
res.set(_da_pagare.string());
|
|
|
|
set_handler(in_valuta ? S_IMPORTOVAL : S_IMPORTO, importo_handler);
|
|
|
|
real oldimp = oldpag.get_real(in_valuta ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO);
|
|
if (!in_valuta)
|
|
oldimp += oldpag.get_real(PAGSCA_RITENUTE);
|
|
|
|
// Ricorda l'importo da pagare
|
|
_da_pagare += oldimp;
|
|
|
|
TValuta val; val.get(sum);
|
|
val.set(*this, S_VALUTA, S_DATACAMBIO, S_CAMBIO);
|
|
|
|
const long numreg = sum.get_long(PART_NREG);
|
|
const int numrig = sum.get_int(PART_NUMRIG);
|
|
|
|
TReal_field& resp = (TReal_field&)field(S_RESIDUOPAG);
|
|
resp.set_decimals(in_valuta ? 2 : 0);
|
|
TImporto r(importo);
|
|
r -= app().partite().importo_speso(numreg, numrig);
|
|
if (in_valuta)
|
|
_pagabile = val.lit2val(r.valore());
|
|
else
|
|
_pagabile = r.valore();
|
|
resp.set(_pagabile.string());
|
|
|
|
_pagabile += oldimp;
|
|
|
|
// Il flag di saldo/acconto e' attivo solo se non ci sono acconti, cioe':
|
|
// pagamento non assegnato o con data documento antecedente quella della fattura
|
|
bool sa = oldpag.get_int(PAGSCA_NRIGA) != TPartita::UNASSIGNED;
|
|
if (sa)
|
|
{
|
|
const tipo_movimento tm = sum.tipo();
|
|
sa = !(tm == tm_nota_credito || tm == tm_insoluto);
|
|
if (sa)
|
|
{
|
|
const TDate datasca(fatt.get(PART_DATADOC));
|
|
const TDate datapag(sum.get(PART_DATADOC));
|
|
sa = datapag >= datasca;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
hide(S_RESIDUORATA); // Se non assegnato nascondi residuo rata
|
|
}
|
|
// Mostra saldo solo se non e' ne' un acconto, ne' una nota di credito
|
|
enable(S_SALDOACC, sa);
|
|
|
|
show(-3, in_valuta); // Attiva campi relativi alla valuta
|
|
|
|
#ifdef __EXTRA__
|
|
set_handler(S_CAMBIO, cambio_handler);
|
|
hide(S_RESIDUOPAG);
|
|
const bool mostra_conto = FALSE;
|
|
show(-4, in_valuta); // Attiva campi relativi al cambio
|
|
#else
|
|
const bool mostra_conto = !sum.is_nota_credito();
|
|
#endif
|
|
show(-2, mostra_conto); // mostra/nasconde conto contropartita
|
|
|
|
const bool mostra_ritenute = !(sum.is_nota_credito() || in_valuta);
|
|
show(S_RITENUTE, mostra_ritenute); // mostra/nasconde ritenute
|
|
}
|
|
|
|
void TPay_mask::get_pag(TRectype& newpag) const
|
|
{
|
|
TRelation rel(LF_PAGSCA); // Working relation
|
|
rel.curr() = newpag;
|
|
autosave(&rel); // Load current record from mask
|
|
newpag = rel.curr();
|
|
}
|
|
|
|
bool TPay_mask::importo_handler(TMask_field& f, KEY k)
|
|
{
|
|
TPay_mask& m = (TPay_mask&)f.mask();
|
|
|
|
if (k == K_F8)
|
|
{
|
|
real imp;
|
|
if (m.field(S_RESIDUORATA).shown() && m.field(S_RESIDUOPAG).shown())
|
|
imp = fnc_min(m._da_pagare, m._pagabile);
|
|
else
|
|
imp = m.field(S_RESIDUORATA).shown() ? m._da_pagare : m._pagabile;
|
|
|
|
if (m.field(S_RITENUTE).active())
|
|
imp -= real(m.get(S_RITENUTE));
|
|
|
|
f.set(imp.string());
|
|
k = K_TAB;
|
|
}
|
|
|
|
if (k == K_TAB && f.focusdirty())
|
|
{
|
|
real i(f.get());
|
|
if (m.field(S_RITENUTE).active())
|
|
i += real(m.get(S_RITENUTE));
|
|
|
|
if (i >= m._da_pagare && m.field(S_SALDOACC).active())
|
|
m.set(S_SALDOACC, "S");
|
|
|
|
if (m.get(S_SALDOACC)[0] != 'S')
|
|
{
|
|
const real residuo(m._da_pagare - i);
|
|
m.set(S_RESIDUORATA, residuo);
|
|
}
|
|
else
|
|
m.reset(S_RESIDUORATA);
|
|
|
|
const real residuopag(m._pagabile - i);
|
|
m.set(S_RESIDUOPAG, residuopag);
|
|
|
|
if (f.dlg() == S_IMPORTOVAL)
|
|
{
|
|
TValuta val; val.get(m, S_VALUTA, S_DATACAMBIO, S_CAMBIO);
|
|
val.val2lit(i);
|
|
m.set(S_IMPORTO, i);
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool TPay_mask::cambio_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_TAB && f.focusdirty())
|
|
{
|
|
TMask_field& i = f.mask().field(S_IMPORTOVAL);
|
|
i.set_dirty();
|
|
i.on_hit();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Maschera partite
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TGame_mask : public TMask
|
|
{
|
|
const TBill _conto; // Conto fisso del cliente/fornitore
|
|
long _numreg; // Numero movimento contabile
|
|
int _numrig; // Riga contabile corrente (prima = 1!)
|
|
TImporto _importo; // Importo riga contabile
|
|
int _riga_partite; // Riga corrente delle partite
|
|
bool _changed;
|
|
|
|
tipo_movimento _tipomov; // Dati per la creazione di un nuovo movimento
|
|
char _sezione;
|
|
TDate _datadoc;
|
|
TString _codpag, _descr, _numdoc;
|
|
|
|
TDecoder _causali; // Decodificatore delle causali
|
|
|
|
protected:
|
|
static bool annopart_handler(TMask_field& f, KEY k);
|
|
static bool numpart_handler(TMask_field& f, KEY k);
|
|
static bool partite_notify(TSheet_field& partite, int r, KEY k);
|
|
static bool scadenze_notify(TSheet_field& partite, int r, KEY k);
|
|
static bool show_all_handler(TMask_field& f, KEY k);
|
|
static bool edit_scadenza_handler(TMask_field& f, KEY k);
|
|
static bool nuovo_handler(TMask_field& f, KEY k);
|
|
static bool cambio_handler(TMask_field& f, KEY k);
|
|
|
|
void add_importo(TToken_string& s, const TImporto& i, bool val = FALSE, int pos = -1);
|
|
void add_descrizione(TToken_string& s, const TRiga_partite& riga, int pos = -1);
|
|
TImporto get_importo(TToken_string& s, int pos) const;
|
|
|
|
void fill_partite(int anno = 0, const char* numero = "");
|
|
real aggiorna_residuo();
|
|
|
|
int update_partita(const TPartita& game, int prow);
|
|
void update_saldo_clifo();
|
|
int nuova_riga(TPartita& partita) const;
|
|
int nuovo_pagamento(TPartita& partita, int nriga, int rata) const;
|
|
bool edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) const;
|
|
|
|
bool same_number(const char* s1, const char* s2) const;
|
|
|
|
#ifdef __EXTRA__
|
|
bool edit_fattura(TPartita& p, int nriga);
|
|
bool prima_nota(const long nreg);
|
|
#endif
|
|
|
|
const TRiga_partite* cerca_prima_riga() const;
|
|
bool cerca_valuta(TValuta& val) const;
|
|
void aggiorna_valuta(const TValuta& val);
|
|
void aggiorna_sorelle(const TRiga_partite& part) const;
|
|
|
|
public:
|
|
TSheet_field& partite() const { return (TSheet_field&)field(P_PARTITE); }
|
|
TSheet_field& scadenze() const { return (TSheet_field&)field(P_SCADENZE); }
|
|
const TBill& conto() const { return _conto; }
|
|
|
|
bool changed() const { return _changed; }
|
|
|
|
TGame_mask(const TBill& bill, long numreg, int riga);
|
|
virtual ~TGame_mask() {}
|
|
};
|
|
|
|
TGame_mask::TGame_mask(const TBill& bill, long numreg, int riga)
|
|
: TMask("cg2100p"), _conto(bill), _numreg(numreg), _numrig(riga),
|
|
_changed(FALSE), _causali(LF_CAUSALI, "CODCAUS", "DESCR")
|
|
{
|
|
TString descr(80);
|
|
switch (_conto.tipo())
|
|
{
|
|
case 'C': descr = "Cliente"; break;
|
|
case 'F': descr = "Fornitore"; break;
|
|
default: descr = "Conto"; break;
|
|
}
|
|
descr << ' ' << _conto.sottoconto() << ' ' << ((TBill&)_conto).descrizione();
|
|
set(P_DESCR, descr);
|
|
|
|
TValuta val;
|
|
#ifndef __EXTRA__
|
|
TMask& cm = app().curr_mask();
|
|
val.get(cm, SK_VALUTA, SK_DATACAMBIO, SK_CAMBIO);
|
|
cerca_valuta(val);
|
|
val.set(*this, P_VALUTA, P_DATACAMBIO, P_CAMBIO);
|
|
#endif
|
|
enable(-3, val.in_valuta());
|
|
|
|
set_handler(P_ANNO, annopart_handler);
|
|
set_handler(P_NUMERO, numpart_handler);
|
|
set_handler(P_SHOWALL, show_all_handler);
|
|
set_handler(P_NUOVO, nuovo_handler);
|
|
set_handler(P_CAMBIO, cambio_handler);
|
|
|
|
partite().set_notify(partite_notify);
|
|
|
|
scadenze().set_notify(scadenze_notify);
|
|
scadenze().sheet_mask().set_handler(100, edit_scadenza_handler);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Handlers dei campi e della maschera principale
|
|
///////////////////////////////////////////////////////////
|
|
|
|
bool TGame_mask::annopart_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_TAB && f.focusdirty() && f.get().not_empty())
|
|
{
|
|
TMask_field& n = f.mask().field(P_NUMERO);
|
|
n.set_dirty();
|
|
numpart_handler(n, k);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TGame_mask::numpart_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_TAB && f.dirty())
|
|
{
|
|
const TGame_mask& m = (const TGame_mask&)f.mask();
|
|
|
|
const int anno = m.get_int(P_ANNO);
|
|
const TString16 num = f.get();
|
|
if (anno > 0 && num.not_empty())
|
|
{
|
|
TSheet_field& sheet = m.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 ...
|
|
{
|
|
TString16 n = row.get(); n.trim();
|
|
if (num == n) // 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;
|
|
}
|
|
|
|
bool TGame_mask::show_all_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
{
|
|
TGame_mask& gm = (TGame_mask&)f.mask();
|
|
gm.fill_partite();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TGame_mask::cambio_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_TAB && f.focusdirty() &&
|
|
yesno_box("Aggiornare gli importi dei pagamenti?"))
|
|
{
|
|
TGame_mask& gm = (TGame_mask&)f.mask();
|
|
TValuta val; val.get(gm, P_VALUTA, P_DATACAMBIO, P_CAMBIO);
|
|
gm.aggiorna_valuta(val);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Metodi dei campi e della maschera principale
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Aggiorna il campo con il residuo da spendere sui pagamenti
|
|
real TGame_mask::aggiorna_residuo()
|
|
{
|
|
#ifdef __EXTRA__
|
|
return ZERO;
|
|
#else
|
|
_importo = app().get_cgs_imp(_numrig-1); // Importo sulla riga contabile
|
|
TImporto residuo(_importo);
|
|
residuo -= app().partite().importo_speso(_numreg, _numrig); // Sottraggo importi spesi
|
|
set(P_RESIDUO, residuo.valore());
|
|
return residuo.valore();
|
|
#endif
|
|
}
|
|
|
|
// Scandisce tutte le partite per cercare la prima del movimento corrente
|
|
const TRiga_partite* TGame_mask::cerca_prima_riga() const
|
|
{
|
|
const TRiga_partite* riga = NULL;
|
|
TPartite_array& pa = app().partite();
|
|
for (const TPartita* game = pa.first(); game != NULL; game = pa.next())
|
|
{
|
|
const int r = game->mov2rig(_numreg, _numrig);
|
|
if (r > 0)
|
|
{
|
|
riga = &game->riga(r);
|
|
break;
|
|
}
|
|
}
|
|
return riga;
|
|
}
|
|
|
|
|
|
// Cerca la valuta della prima riga di partita relativa al movimento corrente
|
|
bool TGame_mask::cerca_valuta(TValuta& val) const
|
|
{
|
|
const TRiga_partite* row = cerca_prima_riga();
|
|
if (row != NULL)
|
|
val.get(*row);
|
|
return row != NULL;
|
|
}
|
|
|
|
void TGame_mask::aggiorna_valuta(const TValuta& val)
|
|
{
|
|
int annorif = 0;
|
|
TString16 numrif;
|
|
|
|
TPartite_array& pa = app().partite();
|
|
for (TPartita* game = pa.first(); game; game = pa.next())
|
|
{
|
|
for (int r = game->last(); r > 0; r = game->pred(r))
|
|
{
|
|
const TRiga_partite& riga = game->riga(r);
|
|
for (int s = riga.rate(); s > 0; s--)
|
|
{
|
|
const TRiga_scadenze& scad = riga.rata(s);
|
|
for (int p = scad.last(); p > 0; p = scad.pred(p))
|
|
{
|
|
TRiga_partite& sum = game->riga(p);
|
|
if (sum.get_long(PART_NREG) == _numreg &&
|
|
sum.get_int(PART_NUMRIG) == _numrig)
|
|
{
|
|
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);
|
|
pag.put(PAGSCA_IMPORTO, imp); // Converte in lire l'importo in valuta
|
|
#ifdef __EXTRA__
|
|
game->modifica_pagamento(pag, val, TRUE);
|
|
#else
|
|
app().notify_edit_pagamento(*game, pag, val);
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#ifndef __EXTRA__
|
|
if (annorif != 0)
|
|
{
|
|
const bool proponi = app().causale().tipomov() == 2;
|
|
if (proponi)
|
|
{
|
|
const TMask& cm = app().curr_mask();
|
|
const int anno = cm.get_int(F_ANNORIF);
|
|
if (anno != 0)
|
|
{
|
|
annorif = anno;
|
|
numrif = cm.get(F_NUMRIF);
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
fill_partite(annorif, numrif);
|
|
}
|
|
|
|
void TGame_mask::aggiorna_sorelle(const TRiga_partite& part) const
|
|
{
|
|
TPartite_array& pa = app().partite();
|
|
for (TPartita* game = pa.first(); game; game = pa.next())
|
|
{
|
|
for (int r = game->last(); r > 0; r = game->pred(r))
|
|
{
|
|
TRiga_partite& row = game->riga(r);
|
|
if (row.get_long(PART_NREG) == _numreg && row.get_int(PART_NUMRIG) == _numrig)
|
|
{
|
|
row.put(PART_DESCR, part.get(PART_DESCR));
|
|
row.put(PART_DATAPAG, part.get(PART_DATAPAG));
|
|
row.put(PART_TIPOPAG, part.get(PART_TIPOPAG));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
|
|
{
|
|
TGame_mask& gm = (TGame_mask&)partite.mask();
|
|
|
|
if (k == K_TAB)
|
|
{
|
|
gm._riga_partite = r;
|
|
|
|
TString_array& scadenze = gm.scadenze().rows_array();
|
|
scadenze.destroy();
|
|
|
|
TToken_string& row = partite.row(r);
|
|
const int anno = row.get_int(0); // Anno partita
|
|
const TString16 num = row.get(); // Numero partita
|
|
gm.set(P_ANNO, anno); // Aggiorna campi di ricerca
|
|
gm.set(P_NUMERO, num);
|
|
|
|
if (anno > 0)
|
|
{
|
|
const TBill& zio = gm.conto(); // Conto cliente/fornitore
|
|
|
|
TPartita* game = app().partite().exist(zio, anno, num); // Cerca la partita tra quelle editate
|
|
const bool should_delete_game = (game == NULL); // Ricorda di fare delete
|
|
if (should_delete_game) // Se non c'era ...
|
|
game = new TPartita(zio, anno, num); // ... creane una temporanea
|
|
|
|
TImporto tot_lit, tot_val;
|
|
TToken_string riga_fattura(80);
|
|
|
|
const int lastrow = game->last();
|
|
for (int ri = game->first(); ri <= lastrow; ri = game->succ(ri))
|
|
{
|
|
const TRiga_partite& riga = game->riga(ri);
|
|
if (!riga.is_fattura())
|
|
continue;
|
|
|
|
const bool in_valuta = riga.in_valuta();
|
|
riga_fattura.cut(0);
|
|
riga_fattura.add(ri);
|
|
riga_fattura.add("");
|
|
riga_fattura.add("");
|
|
riga_fattura.add(riga.get(PART_DATADOC));
|
|
gm.add_descrizione(riga_fattura, riga);
|
|
gm.add_importo(riga_fattura, riga.importo(FALSE, 0x1));
|
|
if (in_valuta)
|
|
gm.add_importo(riga_fattura, riga.importo(TRUE, 0x1), TRUE);
|
|
else
|
|
riga_fattura.add("");
|
|
riga_fattura.add(riga.get(PART_NREG));
|
|
riga_fattura.add(riga.get(PART_DATAREG));
|
|
riga_fattura.add(riga.get(PART_NUMDOC));
|
|
riga_fattura.add(riga.get(PART_PROTIVA));
|
|
scadenze.add(riga_fattura);
|
|
|
|
for (int ra = 1; ra <= riga.rate(); ra++)
|
|
{
|
|
const TRiga_scadenze& scad = riga.rata(ra);
|
|
|
|
TToken_string& row = scadenze.row(scadenze.add(riga_fattura));
|
|
row.add(ra, 1);
|
|
row.add(scad.get(SCAD_DATASCAD), 2);
|
|
gm.add_importo(row, scad.importo(FALSE), FALSE, 5);
|
|
if (in_valuta)
|
|
gm.add_importo(row, scad.importo(TRUE), TRUE, 6);
|
|
|
|
const int lastp = scad.last();
|
|
for (int pa = scad.first(); pa <= lastp; pa = scad.succ(pa))
|
|
{
|
|
const TRectype& pag = scad.row(pa);
|
|
const TRiga_partite& sum = game->riga(pa);
|
|
const char sez = sum.sezione();
|
|
|
|
TToken_string& row = scadenze.row(scadenze.add(""));
|
|
row.add(ri);
|
|
row.add(ra);
|
|
row.add(sum.get(PART_DATAPAG));
|
|
row.add(sum.get(PART_DATADOC));
|
|
gm.add_descrizione(row, sum);
|
|
TImporto imp(sez, pag.get_real(PAGSCA_IMPORTO));
|
|
if (in_valuta)
|
|
{
|
|
gm.add_importo(row, imp);
|
|
gm.add_importo(row, TImporto(sez, pag.get_real(PAGSCA_IMPORTOVAL)), TRUE);
|
|
}
|
|
else
|
|
{
|
|
imp.valore() += pag.get_real(PAGSCA_RITENUTE);
|
|
gm.add_importo(row, imp);
|
|
row.add("");
|
|
}
|
|
row.add(sum.get(PART_NREG));
|
|
row.add(sum.get(PART_DATAREG));
|
|
row.add(sum.get(PART_NUMDOC));
|
|
row.add("");
|
|
row.add(pa);
|
|
}
|
|
|
|
TImporto abb(scad.importo_pagato(TRUE, 0x2));
|
|
if (!abb.is_zero())
|
|
{
|
|
TToken_string& rabb = scadenze.row(scadenze.add(""));
|
|
rabb.add("Abbuoni rata ", 4); rabb << ra;
|
|
if (in_valuta)
|
|
{
|
|
gm.add_importo(rabb, scad.importo_pagato(FALSE, 0x2), FALSE);
|
|
gm.add_importo(rabb, abb, TRUE);
|
|
}
|
|
else
|
|
{
|
|
gm.add_importo(rabb, abb, FALSE);
|
|
rabb.add("");
|
|
}
|
|
}
|
|
|
|
if (in_valuta)
|
|
{
|
|
TImporto diff(scad.importo_pagato(FALSE, 0x4));
|
|
if (!diff.is_zero())
|
|
{
|
|
TToken_string& rdiff = scadenze.row(scadenze.add(""));
|
|
rdiff.add("Differ. cambio rata ", 4); rdiff << ra;
|
|
gm.add_importo(rdiff, diff);
|
|
}
|
|
}
|
|
|
|
TToken_string& rsal = scadenze.row(scadenze.add(""));
|
|
rsal.add("Saldo rata ", 4); rsal << ra;
|
|
if (!scad.chiusa())
|
|
{
|
|
TImporto sl = scad.residuo(FALSE);
|
|
gm.add_importo(rsal, sl);
|
|
tot_lit += sl;
|
|
|
|
if (in_valuta)
|
|
{
|
|
sl = scad.residuo(TRUE, 0xB);
|
|
gm.add_importo(rsal, sl, TRUE);
|
|
tot_val += sl;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
TRecord_array& unas = game->unassigned();
|
|
const int lastp = unas.last_row();
|
|
for (int pa = unas.first_row(); pa <= lastp; pa = unas.succ_row(pa))
|
|
{
|
|
const TRectype& pag = unas.row(pa);
|
|
const TRiga_partite& sum = game->riga(pa);
|
|
TImporto imp(sum.sezione(), ZERO);
|
|
|
|
TToken_string& row = scadenze.row(scadenze.add(""));
|
|
row.add(pag.get(PAGSCA_NRIGA));
|
|
row.add(pag.get(PAGSCA_NRATA));
|
|
row.add(sum.get(PART_DATAPAG));
|
|
row.add(sum.get(PART_DATADOC));
|
|
gm.add_descrizione(row, sum);
|
|
TImporto i(sum.sezione(), pag.get_real(PAGSCA_IMPORTO));
|
|
i.valore() += pag.get_real(PAGSCA_RITENUTE);
|
|
i.normalize();
|
|
gm.add_importo(row, i);
|
|
tot_lit += i;
|
|
|
|
const real& impval = pag.get_real(PAGSCA_IMPORTOVAL);
|
|
if (!impval.is_zero())
|
|
{
|
|
i.set(sum.sezione(), impval);
|
|
i.normalize();
|
|
gm.add_importo(row, i, TRUE);
|
|
tot_val += i;
|
|
}
|
|
else
|
|
row.add("");
|
|
row.add(sum.get(PART_NREG));
|
|
row.add(sum.get(PART_DATAREG));
|
|
row.add(sum.get(PART_NUMDOC));
|
|
row.add("");
|
|
row.add(pa);
|
|
}
|
|
|
|
if (lastrow > 0)
|
|
{
|
|
TToken_string& sp = scadenze.row(scadenze.add(""));
|
|
sp.add("Saldo ", 4); sp << anno << ' ' << num;
|
|
gm.add_importo(sp, tot_lit);
|
|
gm.add_importo(sp, tot_val, TRUE);
|
|
}
|
|
|
|
if (should_delete_game)
|
|
delete game;
|
|
}
|
|
|
|
gm.scadenze().force_update();
|
|
}
|
|
if (k == K_INS)
|
|
{
|
|
gm.send_key(K_CTRL + 'N', 0, &partite); // Simula la pressione del tasto nuovo
|
|
return FALSE; // Rifiuta l'aggiunta di una riga
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool TGame_mask::scadenze_notify(TSheet_field& scadenze, int r, KEY k)
|
|
{
|
|
if (k == K_INS)
|
|
{
|
|
TGame_mask& gm = (TGame_mask&)scadenze.mask();
|
|
gm.send_key(K_CTRL + 'N', 0, &scadenze); // Simula la pressione del tasto nuovo
|
|
return FALSE; // Rifiuta l'aggiunta di una riga
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
int TGame_mask::nuova_riga(TPartita& partita) const
|
|
{
|
|
TRiga_partite& part = partita.new_row(); // Creazione nuova riga vuota
|
|
const int nriga = part.get_int(PART_NRIGA);
|
|
|
|
// Copia dati movimento corrente
|
|
part.put(PART_NREG, _numreg); // Numero operazione
|
|
part.put(PART_NUMRIG, _numrig); // Riga su cui ho cliccato
|
|
|
|
// Forza il gruppo/conto cliente corretto
|
|
part.put(PART_GRUPPOCL, conto().gruppo());
|
|
part.put(PART_CONTOCL, conto().conto());
|
|
|
|
// Setta il cambio corrente
|
|
TValuta valuta; valuta.get(*this, P_VALUTA, P_DATACAMBIO, P_CAMBIO);
|
|
valuta.put(part);
|
|
|
|
#ifdef __EXTRA__
|
|
part.put(PART_TIPOMOV, (int)_tipomov);
|
|
part.put(PART_DESCR, _descr);
|
|
part.put(PART_NUMDOC, _numdoc);
|
|
part.put(PART_DATADOC, _datadoc);
|
|
part.put(PART_DATAPAG, _datadoc);
|
|
part.put(PART_DATAREG, TDate(TODAY));
|
|
part.put(PART_SEZ, _sezione);
|
|
part.put(PART_SEZABB, _sezione);
|
|
part.put(PART_SEZDIFCAM,_sezione);
|
|
if (_tipomov == tm_fattura)
|
|
{
|
|
part.put(PART_IMPORTO, _importo.valore());
|
|
if (valuta.in_valuta())
|
|
{
|
|
const real impval = valuta.lit2val(_importo.valore());
|
|
part.put(PART_IMPORTOVAL, impval);
|
|
}
|
|
}
|
|
#else
|
|
TMask& cm = app().curr_mask();
|
|
const TCausale& causale = app().causale();
|
|
const tipo_movimento tm = (tipo_movimento)causale.tipomov();
|
|
part.put(PART_TIPOMOV, (int)tm);
|
|
part.put(PART_NUMDOC, cm.get(F_NUMDOC));
|
|
part.put(PART_DATADOC, cm.get(F_DATADOC));
|
|
part.put(PART_DATAREG, cm.get(F_DATAREG));
|
|
part.put(PART_DESCR, cm.get(F_DESCR));
|
|
part.put(PART_DATAPAG, cm.get(F_DATAREG));
|
|
part.put(PART_TIPOPAG, 1);
|
|
|
|
const TRiga_partite* prima = (tm != tm_fattura) ? cerca_prima_riga() : NULL;
|
|
if (prima != NULL && prima != &part)
|
|
{
|
|
part.put(PART_DESCR, prima->get(PART_DESCR));
|
|
part.put(PART_DATAPAG, prima->get(PART_DATAPAG));
|
|
part.put(PART_TIPOPAG, prima->get(PART_TIPOPAG));
|
|
}
|
|
|
|
// Copia dati causale corrente
|
|
part.put(PART_CODCAUS, causale.codice());
|
|
if (causale.iva() != nessuna_iva)
|
|
{
|
|
part.put(PART_REG, cm.get(F_CODREG));
|
|
part.put(PART_PROTIVA, cm.get(F_PROTIVA));
|
|
}
|
|
|
|
const char tipoc = conto().tipo();
|
|
// Complesso algoritmo per calcolare la sezione di una nuova riga partita
|
|
char sezione = causale.sezione(1); // Usa la sezione della causale
|
|
if (sezione <= ' ') // Se non c'e' la sezione bell'e' ch'e' pronta
|
|
{
|
|
if (tm == tm_fattura || tm == tm_insoluto) // calcola in base al tipo movimento e
|
|
sezione = (tipoc == 'C') ? 'D' : 'A'; // al tipo cliente/fornitore
|
|
else
|
|
sezione = (tipoc == 'C') ? 'A' : 'D';
|
|
}
|
|
if (tipoc > ' ') // Se il tipo e' C o F
|
|
{
|
|
TBill bill; causale.bill(1, bill); // Legge primo conto causale
|
|
if (bill.tipo() != tipoc)
|
|
sezione = (sezione == 'D') ? 'A' : 'D'; // scambia segno
|
|
}
|
|
// Memorizza solo la sezione (importi nulli)
|
|
part.put(PART_SEZ, sezione);
|
|
part.put(PART_SEZABB, sezione);
|
|
part.put(PART_SEZDIFCAM, sezione);
|
|
#endif
|
|
|
|
return nriga;
|
|
}
|
|
|
|
int TGame_mask::nuovo_pagamento(TPartita& partita, int nriga, int rata) const
|
|
{
|
|
#ifdef __EXTRA__
|
|
const int nrigp = nuova_riga(partita);
|
|
if (nriga > 0)
|
|
{
|
|
const TRiga_partite& fattura = partita.riga(nriga);
|
|
const TValuta val(fattura);
|
|
TRiga_partite& somma = partita.riga(nrigp);
|
|
val.put(somma);
|
|
}
|
|
#else
|
|
int nrigp = partita.mov2rig(_numreg, _numrig); // Cerca riga partita relativa alla riga rmov
|
|
if (nrigp <= 0) // Devo creare una nuova riga di partita
|
|
nrigp = nuova_riga(partita);
|
|
#endif
|
|
TRectype& pagamento = partita.pagamento(nriga, rata, nrigp); // Crea nuovo pagamento
|
|
|
|
// Calcola riga causale per la contropartita in base al tipo pagamento
|
|
int caus = 2;
|
|
if (rata != TPartita::UNASSIGNED)
|
|
{
|
|
const TRiga_scadenze& scad = partita.rata(nriga, rata);
|
|
const int tp = scad.get_int(SCAD_TIPOPAG);
|
|
caus = partita.tipopag2causale(tp);
|
|
|
|
TRiga_partite& somma = partita.riga(nrigp);
|
|
somma.put(PART_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));
|
|
}
|
|
|
|
#ifndef __EXTRA__
|
|
const TCausale& causale = app().causale();
|
|
TBill contro; causale.bill(caus, contro); // Legge conto contropartita
|
|
if (caus != 2 && contro.empty()) // Se non specificato ...
|
|
causale.bill(caus = 2, contro); // ... prende il primo
|
|
contro.put(pagamento, TRUE); // Scrive conto contropartita
|
|
#endif
|
|
|
|
return nrigp;
|
|
}
|
|
|
|
bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
{
|
|
TMask& m = f.mask();
|
|
const int nriga = m.get_int(101);
|
|
|
|
if (nriga == 0)
|
|
return FALSE; // Ho cliccato su di un saldo (per sbaglio!)
|
|
|
|
TGame_mask& gm = (TGame_mask&)(m.get_sheet()->mask());
|
|
TMask_field& cambio = gm.field(P_CAMBIO);
|
|
if (cambio.active() && cambio.get().empty())
|
|
return f.error_box("E' necessario specificare un cambio");
|
|
|
|
const TBill& bill = gm.conto();
|
|
const int anno = gm.get_int(P_ANNO);
|
|
const TString16 numero = gm.get(P_NUMERO);
|
|
|
|
TPartita& game = app().partite().partita(bill, anno, numero);
|
|
|
|
long nreg = m.get_long(108); // Numero registrazione
|
|
const int nrata = m.get_int(102); // Rata selezionata (puo' essere 0)
|
|
int nrigp = m.get_int(112); // Pagamento selezionato (puo' essere 0)
|
|
|
|
if (nrata != 0 && nrigp == 0)
|
|
{
|
|
#ifdef __EXTRA__
|
|
gm._tipomov = (tipo_movimento) 3;
|
|
gm._descr = "";
|
|
gm._numdoc = "";
|
|
gm._datadoc = TDate(TODAY);
|
|
gm._sezione = game.riga(nriga).sezione() == 'D' ? 'A' : 'D';
|
|
#endif
|
|
nrigp = gm.nuovo_pagamento(game, nriga, nrata);
|
|
nreg = gm._numreg;
|
|
}
|
|
|
|
bool cambiato = FALSE;
|
|
|
|
if (nrigp > 0) // Si vuole editare un pagamento
|
|
{
|
|
if (nreg == gm._numreg)
|
|
{
|
|
cambiato = gm.edit_pagamento(game, nriga, nrata, nrigp);
|
|
if (cambiato)
|
|
{
|
|
if (!game.esiste(nriga, nrata, nrigp))
|
|
m.stop_run(K_ESC);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
#ifdef __EXTRA__
|
|
gm.prima_nota(nreg);
|
|
#else
|
|
return f.error_box("Modificare il movimento %ld", nreg);
|
|
#endif
|
|
}
|
|
}
|
|
else
|
|
{ // Si vogliono editare le rate
|
|
#ifdef __EXTRA__
|
|
if (nreg > 0)
|
|
gm.prima_nota(nreg);
|
|
else
|
|
cambiato = gm.edit_fattura(game, nriga);
|
|
#else
|
|
if (nreg != gm._numreg || nrata == 0)
|
|
{
|
|
if (nreg == 0)
|
|
f.error_box("Utilizzare la gestione extra-contabile");
|
|
else
|
|
f.error_box("Modificare il movimento %ld", nreg);
|
|
return FALSE;
|
|
}
|
|
#endif
|
|
}
|
|
if (cambiato)
|
|
{
|
|
gm.update_partita(game, gm._riga_partite);
|
|
partite_notify(gm.partite(), gm._riga_partite, K_TAB);
|
|
gm._changed = TRUE;
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool TGame_mask::nuovo_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
{
|
|
TGame_mask& gm = (TGame_mask&)f.mask();
|
|
int anno;
|
|
TString numero;
|
|
|
|
// Graffa tattica per distruggere la maschera new_game alla fine del blocco
|
|
{
|
|
TMask new_game("cg2100n");
|
|
new_game.first_focus(P_NUMERO);
|
|
|
|
#ifndef __EXTRA__
|
|
const TMask& cm = app().curr_mask();
|
|
new_game.disable(-1);
|
|
gm._tipomov = (tipo_movimento)app().causale().tipomov();
|
|
new_game.set(P_NUOVO, gm._tipomov);
|
|
new_game.set(P_SEZIONE, gm._importo.sezione());
|
|
new_game.set(P_RESIDUO, gm.get(P_RESIDUO));
|
|
new_game.set(P_DATADOC, cm.get(F_DATADOC));
|
|
new_game.set(P_NUMDOC, cm.get(F_NUMDOC));
|
|
new_game.set(P_DESCR, cm.get(F_DESCR));
|
|
if (gm._tipomov < 3)
|
|
new_game.set(P_CODPAG,cm.get(F_CODPAG));
|
|
if (gm._tipomov == 2)
|
|
{
|
|
new_game.set(P_ANNO, cm.get(F_ANNORIF));
|
|
new_game.set(P_NUMERO, cm.get(F_NUMRIF));
|
|
}
|
|
#endif
|
|
|
|
k = new_game.run();
|
|
anno = new_game.get_int(P_ANNO);
|
|
numero = new_game.get(P_NUMERO);
|
|
|
|
gm._tipomov = (tipo_movimento)new_game.get_int(P_NUOVO);
|
|
gm._codpag = new_game.get(P_CODPAG);
|
|
gm._sezione = new_game.get(P_SEZIONE)[0];
|
|
gm._importo.set(gm._sezione, real(new_game.get(P_RESIDUO)));
|
|
gm._numdoc = new_game.get(P_NUMDOC);
|
|
gm._datadoc = new_game.get(P_DATADOC);
|
|
gm._descr = new_game.get(P_DESCR);
|
|
}
|
|
|
|
if (k == K_ENTER)
|
|
{
|
|
TPartita& game = app().partite().partita(gm.conto(), anno, numero);
|
|
|
|
if (gm._tipomov > 1)
|
|
{
|
|
if (game.ok())
|
|
return error_box("La partita %d '%s' esiste gia'.", anno, (const char*)game.numero());
|
|
|
|
const int nriga = TPartita::UNASSIGNED;
|
|
const int nrata = TPartita::UNASSIGNED;
|
|
const int nrigp = gm.nuovo_pagamento(game, nriga, nrata);
|
|
gm.edit_pagamento(game, nriga, nrata, nrigp);
|
|
}
|
|
#ifdef __EXTRA__
|
|
else
|
|
{
|
|
gm.edit_fattura(game, 0);
|
|
}
|
|
#endif
|
|
if (game.ok())
|
|
{
|
|
gm.fill_partite(anno, numero); // Aggiorna sheet partite
|
|
gm._changed = TRUE;
|
|
}
|
|
else
|
|
app().partite().destroy(gm.conto(), anno, numero);
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Metodi della maschera delle partite
|
|
///////////////////////////////////////////////////////////
|
|
|
|
void TGame_mask::add_importo(TToken_string& s, const TImporto& i, bool valuta, int pos)
|
|
{
|
|
if (i.is_zero())
|
|
s.add("", pos);
|
|
else
|
|
{
|
|
TString80 v;
|
|
TImporto n(i); n.normalize();
|
|
v << n.valore().string(0, valuta ? 3 : 0) << ' ' << n.sezione();
|
|
s.add(v, pos);
|
|
}
|
|
}
|
|
|
|
void TGame_mask::add_descrizione(TToken_string& s, const TRiga_partite& riga, int pos)
|
|
{
|
|
const TString& desc = riga.get(PART_DESCR);
|
|
if (desc.empty())
|
|
{
|
|
const TString& caus = riga.get(PART_CODCAUS);
|
|
if (caus.not_empty())
|
|
s.add(_causali.decode(caus), pos);
|
|
else
|
|
s.add("", pos);
|
|
}
|
|
else
|
|
s.add(desc, pos);
|
|
}
|
|
|
|
|
|
TImporto TGame_mask::get_importo(TToken_string& s, int pos) const
|
|
{
|
|
const TFixed_string imp(s.get(pos));
|
|
const real i(imp);
|
|
const char sez = imp.right(1)[0];
|
|
return TImporto(sez, i);
|
|
}
|
|
|
|
|
|
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
|
|
|
|
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)
|
|
{
|
|
games.force_update(prow);
|
|
update_saldo_clifo();
|
|
games.force_update(games.items()-1);
|
|
aggiorna_residuo();
|
|
}
|
|
else
|
|
prow = partite().items()-1;
|
|
|
|
if (prow == 0)
|
|
{
|
|
const char all = game.allineamento_richiesto();
|
|
field(P_NUMERO).set_justify(all == 'R');
|
|
}
|
|
|
|
return prow;
|
|
}
|
|
|
|
void TGame_mask::update_saldo_clifo()
|
|
{
|
|
TString_array& s = partite().rows_array();
|
|
|
|
TImporto sal, doc, pag, imp;
|
|
for (int i = 0; i < s.items(); i++)
|
|
{
|
|
TToken_string& r = s.row(i);
|
|
if (r.get_int(0) > 0)
|
|
{
|
|
sal += get_importo(r, 4);
|
|
doc += get_importo(r, -1);
|
|
pag += get_importo(r, -1);
|
|
imp += get_importo(r, -1);
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
|
|
TToken_string& r = s.row(s.add("", i));
|
|
r.add("");
|
|
r.add("");
|
|
r.add(TDate(TODAY).string());
|
|
r.add("");
|
|
add_importo(r, sal);
|
|
add_importo(r, doc);
|
|
add_importo(r, pag);
|
|
add_importo(r, imp);
|
|
r.add("Saldo ");
|
|
|
|
if (conto().tipo() == 'C')
|
|
r << "cliente";
|
|
else
|
|
r << "fornitore";
|
|
r << ' ' << conto().sottoconto();
|
|
}
|
|
|
|
bool TGame_mask::same_number(const char* s1, const char* s2) const
|
|
{
|
|
TString16 t1(s1); t1.upper(); t1.trim();
|
|
TString16 t2(s2); t2.upper(); t2.trim(); t2.cut(t1.len());
|
|
return t1 == t2;
|
|
}
|
|
|
|
void TGame_mask::fill_partite(int annorif, const char* numrif)
|
|
{
|
|
const bool all = get(P_SHOWALL).not_empty();
|
|
|
|
TString_array& a = partite().rows_array();
|
|
a.destroy();
|
|
|
|
app().begin_wait();
|
|
|
|
for (TPartita* gioco = app().partite().first(); gioco != NULL; gioco = app().partite().next())
|
|
{
|
|
const TBill& zio = gioco->conto();
|
|
if (zio.tipo() <= ' ' || zio.sottoconto() == conto().sottoconto())
|
|
update_partita(*gioco, -1);
|
|
}
|
|
|
|
TLocalisamfile partita(LF_PARTITE);
|
|
partita.zero();
|
|
if (conto().tipo() > ' ') // Ignora gruppo e conto dei clifo
|
|
{
|
|
partita.put(PART_TIPOCF, conto().tipo());
|
|
partita.put(PART_SOTTOCONTO, conto().codclifo());
|
|
}
|
|
else
|
|
conto().put(partita.curr()); // Scrive completamente i conti normali
|
|
|
|
const TRectype filter(partita.curr()); // Record campione
|
|
|
|
for (int err = partita.read(_isgteq);
|
|
err == NOERR && partita.curr() == filter;
|
|
err = partita.read(_isgreat))
|
|
{
|
|
const int anno = partita.get_int(PART_ANNO);
|
|
const TString16 num(partita.get(PART_NUMPART));
|
|
|
|
if (!app().partite().exist(conto(), anno, num))
|
|
{
|
|
TPartita game(conto(), anno, num);
|
|
if (all || !game.chiusa())
|
|
update_partita(game, -1);
|
|
}
|
|
partita.put(PART_NRIGA, 9999); // Forza lettura partita successiva nella prossima read
|
|
}
|
|
|
|
a.sort();
|
|
for (int r = a.items()-1; r > 0; r--)
|
|
{
|
|
TToken_string& row = a.row(r);
|
|
if (annorif == row.get_int(0) && same_number(numrif, row.get(1)))
|
|
break;
|
|
}
|
|
|
|
update_saldo_clifo();
|
|
partite().force_update();
|
|
aggiorna_residuo();
|
|
|
|
if (a.items() > 1)
|
|
{
|
|
partite_notify(partite(), r, K_TAB);
|
|
}
|
|
else
|
|
{
|
|
scadenze().destroy();
|
|
}
|
|
app().end_wait();
|
|
}
|
|
|
|
|
|
bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) const
|
|
{
|
|
TRectype oldpag = p.pagamento(nriga, nrata, nrigp);
|
|
TRiga_partite& somma = p.riga(nrigp);
|
|
|
|
TPay_mask* pm = new TPay_mask;
|
|
TPay_mask& m = *pm;
|
|
|
|
if (nriga == TPartita::UNASSIGNED)
|
|
{
|
|
nriga = p.primo_pagamento();
|
|
TRiga_partite& riga = p.riga(nriga);
|
|
const TRiga_scadenze& scaden = riga.new_row(); // Crea una rata falsa
|
|
m.set_pag(oldpag, scaden, _importo);
|
|
riga.destroy_rows(); // Distrugge la rata falsa
|
|
}
|
|
else
|
|
{
|
|
const TRiga_scadenze& scaden = p.rata(nriga, nrata);
|
|
m.set_pag(oldpag, scaden, _importo);
|
|
}
|
|
m.set(S_DESCAGG, somma.get(PART_DESCR));
|
|
|
|
const bool nuovo = oldpag.get(PAGSCA_ACCSAL) != "S" &&
|
|
oldpag.get_real(PAGSCA_IMPORTO).is_zero() &&
|
|
oldpag.get_real(PAGSCA_RITENUTE).is_zero();
|
|
|
|
KEY key = m.run();
|
|
|
|
if (key == K_ESC && nuovo)
|
|
key = K_DEL;
|
|
|
|
if (key == K_ENTER || key == K_DEL)
|
|
{
|
|
TRectype newpag(oldpag);
|
|
|
|
if (key == K_DEL)
|
|
{
|
|
newpag.zero(PAGSCA_ACCSAL); // Non puo' essere un saldo
|
|
newpag.zero(PAGSCA_IMPORTO); // Azzera importo ...
|
|
newpag.zero(PAGSCA_IMPORTOVAL); // .. anche in valuta
|
|
newpag.zero(PAGSCA_RITENUTE); // Azzera ritenute
|
|
}
|
|
else
|
|
{
|
|
m.get_pag(newpag);
|
|
somma.put(PART_DESCR, m.get(S_DESCAGG)); // Aggiorna descrizione (comune alla riga)
|
|
somma.put(PART_DATAPAG, m.get(S_DATAPAG)); // Aggiorna data pagamento (comune alla riga)
|
|
somma.put(PART_TIPOPAG, m.get(S_TIPOPAG)); // Aggiorna tipo pagamento (comune alla riga)
|
|
#ifndef __EXTRA__
|
|
aggiorna_sorelle(somma);
|
|
#endif
|
|
}
|
|
|
|
TValuta val;
|
|
#ifdef __EXTRA__
|
|
val.get(m, S_VALUTA, S_DATACAMBIO, S_CAMBIO);
|
|
p.modifica_pagamento(newpag, val, TRUE);
|
|
#else
|
|
if (somma.is_nota_credito())
|
|
p.modifica_pagamento(newpag, val, TRUE);
|
|
else
|
|
app().notify_edit_pagamento(p, newpag, val);
|
|
#endif
|
|
}
|
|
|
|
delete pm;
|
|
|
|
return key != K_ESC;
|
|
}
|
|
|
|
#ifndef __EXTRA__
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Edit delle partite
|
|
///////////////////////////////////////////////////////////
|
|
|
|
bool TPrimanota_application::edit_partite(const TMask& m, int riga)
|
|
{
|
|
const TImporto imp = get_cgs_imp(riga);
|
|
if (imp.is_zero()) // Esci se importo e' nullo
|
|
return FALSE;
|
|
|
|
const char tipo = m.get(103)[0];
|
|
const int gruppo = m.get_int(104);
|
|
const int conto = m.get_int(105);
|
|
const long sottoconto = m.get_int(106);
|
|
const TBill b(gruppo, conto, sottoconto, tipo); // Legge il conto della riga selezionata
|
|
if (!b.ok())
|
|
return FALSE; // Esci se il conto della riga cliente non e' valido
|
|
|
|
TMovimentoPN* pn = (TMovimentoPN*)get_relation();
|
|
curr_mask().autosave(pn); // Aggiorna i dati della testata sulle partite
|
|
const TRectype& mov = pn->curr();
|
|
partite().update_reg(mov, pn->cg_rows());
|
|
|
|
// Esecuzione maschera di selezione partite
|
|
TGame_mask* mask = new TGame_mask(b, mov.get_long(MOV_NUMREG), riga+1);
|
|
mask->run();
|
|
const bool changed = mask->changed();
|
|
delete mask;
|
|
|
|
if (changed)
|
|
{
|
|
cgs().force_update(); // Aggiornamento righe contabili
|
|
calcola_saldo();
|
|
}
|
|
return changed;
|
|
}
|
|
|
|
#endif
|