a7ca6ce82d
git-svn-id: svn://10.65.10.50/trunk@1729 c028cbd2-c16b-5b4b-a496-9718f37d4682
692 lines
23 KiB
C++
Executable File
692 lines
23 KiB
C++
Executable File
#include "cg2102.h" // Applicazione di prima nota
|
|
|
|
#include "cg2100.h" // Campi maschere prima nota
|
|
#include "cg2100p.h" // Campi maschere partite e pagamenti
|
|
|
|
#include <clifo.h> // Archivio clienti/fornitori
|
|
#include <partite.h> // Archivio partite
|
|
#include <scadenze.h> // Archivio scadenze
|
|
#include <pagsca.h> // Archivio pagamenti
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Maschera partite
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TGame_mask : public TMask
|
|
{
|
|
const TBill _conto; // Conto fisso
|
|
int _riga_partite;
|
|
|
|
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 show_all_handler(TMask_field& f, KEY k);
|
|
static bool scambio_handler(TMask_field& f, KEY k);
|
|
static bool edit_scadenza_handler(TMask_field& f, KEY k);
|
|
|
|
void add_importo(TToken_string& s, const TImporto& i) const;
|
|
void fill_partite(bool all) 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; }
|
|
|
|
TGame_mask(const TBill& bill);
|
|
virtual ~TGame_mask() {}
|
|
};
|
|
|
|
TGame_mask::TGame_mask(const TBill& bill)
|
|
: TMask("cg2100p"), _conto(bill)
|
|
{
|
|
const char tipocf[2] = { bill.tipo(), '\0' };
|
|
set(P_TIPOC, tipocf);
|
|
set(P_GRUPPO, bill.gruppo());
|
|
set(P_CONTO, bill.conto());
|
|
set(P_SOTTOCONTO, bill.sottoconto());
|
|
set(P_DESCR, ((TBill&)bill).descrizione());
|
|
|
|
set_handler(P_ANNO, annopart_handler);
|
|
set_handler(P_NUMERO, numpart_handler);
|
|
set_handler(P_SHOWALL, show_all_handler);
|
|
set_handler(P_SCAMBIO, scambio_handler);
|
|
|
|
partite().set_notify(partite_notify);
|
|
scadenze().sheet_mask().set_handler(100, edit_scadenza_handler);
|
|
}
|
|
|
|
bool TGame_mask::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(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 ...
|
|
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;
|
|
}
|
|
|
|
bool TGame_mask::show_all_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
{
|
|
const TGame_mask& gm = (const TGame_mask&)f.mask();
|
|
const bool all = f.get().not_empty();
|
|
gm.fill_partite(all);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TGame_mask::scambio_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
{
|
|
const TGame_mask& gm = (const TGame_mask&)f.mask();
|
|
const TSheet_field& sheet = gm.scadenze();
|
|
sheet.swap_columns(103, 110); // Scambia colonne
|
|
sheet.swap_columns(104, 111);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k)
|
|
{
|
|
if (k == K_TAB)
|
|
{
|
|
TGame_mask& gm = (TGame_mask&)partite.mask();
|
|
gm._riga_partite = r;
|
|
|
|
TSheet_field& scadenze = gm.scadenze();
|
|
scadenze.destroy();
|
|
|
|
const TBill& zio = gm.conto(); // Conto cliente/fornitore
|
|
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);
|
|
|
|
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
|
|
|
|
const int lastrow = game->last();
|
|
for (int ri = game->first(); ri <= lastrow; ri = game->succ(ri))
|
|
{
|
|
const TRiga_partite& riga = game->riga(ri);
|
|
for (int ra = 1; ra <= riga.rate(); ra++)
|
|
{
|
|
const TRiga_scadenze& scad = riga.rata(ra);
|
|
TToken_string& row = scadenze.row(-1);
|
|
row.add(ri);
|
|
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_real(SCAD_IMPORTOVAL).string(0, 2));
|
|
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 = ap.succ_row(pa))
|
|
{
|
|
const TRiga_partite& rigp = game->riga(pa);
|
|
const TRectype& pag = ap.row(pa);
|
|
|
|
TToken_string& row = scadenze.row(-1);
|
|
row.add(ri);
|
|
row.add(ra);
|
|
row.add(rigp.get(PART_DATADOC));
|
|
row.add(rigp.get(PART_NREG));
|
|
row.add(rigp.get(PART_DATAREG));
|
|
row.add(scad.get(SCAD_DATASCAD));
|
|
row.add(pag.get_real(SCAD_IMPORTO).string());
|
|
row.add(pag.get_real(SCAD_IMPORTOVAL).string(0, 2));
|
|
row.add(rigp.get(PART_DESCR));
|
|
row.add(rigp.get(PART_NUMDOC));
|
|
row.add("");
|
|
row.add(pa);
|
|
}
|
|
}
|
|
}
|
|
scadenze.force_update();
|
|
if (should_delete_game)
|
|
delete game;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
{
|
|
TMask& m = f.mask();
|
|
TGame_mask& gm = (TGame_mask&)(m.get_sheet()->mask());
|
|
|
|
const TBill& bill = gm.conto();
|
|
const int anno = gm.get_int(P_ANNO);
|
|
const TString16 numero = gm.get(P_NUMERO);
|
|
const int nriga = m.get_int(101);
|
|
const int nrata = m.get_int(102);
|
|
const int rmov = app().cgs().selected()+1;
|
|
|
|
CHECK(nriga && nrata, "La riga della scadenza sembra vuota, ma tutti sanno che e' una balla!");
|
|
|
|
int nrigp = m.get_int(112);
|
|
if (nrigp == 0)
|
|
{
|
|
TPartita& game = app().partite().partita(bill, anno, numero);
|
|
nrigp = app().nuovo_pagamento(game, nriga, nrata, rmov);
|
|
if (nrigp < 1)
|
|
return f.error_box("La rata %d e' gia' stata pagata", nrata);
|
|
}
|
|
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)
|
|
return f.error_box("Non si possono modificare pagamenti di movimenti diversi dal %ld",
|
|
cur_reg);
|
|
}
|
|
|
|
TPartita& game = app().partite().partita(bill, anno, numero);
|
|
const bool dirty = app().edit_pagamento(game, nriga, nrata, nrigp);
|
|
|
|
if (dirty)
|
|
partite_notify(gm.partite(), gm._riga_partite, K_TAB);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
void TGame_mask::add_importo(TToken_string& s, const TImporto& i) const
|
|
{
|
|
if (i.is_zero())
|
|
s.add("");
|
|
else
|
|
{
|
|
s.add(i.valore().string());
|
|
s << ' ' << i.sezione();
|
|
}
|
|
}
|
|
|
|
void TGame_mask::fill_partite(bool all) const
|
|
{
|
|
TString_array& a = partite().rows_array();
|
|
a.destroy();
|
|
|
|
app().begin_wait();
|
|
|
|
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().sottoconto());
|
|
}
|
|
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));
|
|
|
|
TPartita* game = NULL;
|
|
bool should_delete_game = FALSE;
|
|
if (app().partite().exist(conto(), anno, num))
|
|
game = &app().partite().partita(conto(), anno, num);
|
|
else
|
|
{
|
|
game = new TPartita(conto(), anno, num);
|
|
should_delete_game = TRUE;
|
|
}
|
|
|
|
TImporto saldo, doc, pag, imp;
|
|
game->calcola_saldo(saldo, doc, pag, imp);
|
|
|
|
if (all || !saldo.is_zero())
|
|
{
|
|
int riga_fatt = game->prima_fattura();
|
|
if (riga_fatt < 1) riga_fatt = game->first(); // E' un anticipo
|
|
|
|
const TRiga_partite& riga = game->riga(riga_fatt);
|
|
const TString16 data_doc = riga.get(PART_DATADOC);
|
|
const TString16 num_doc = riga.get(PART_NUMDOC);
|
|
const char*descr = riga.get(PART_DESCR);
|
|
|
|
TToken_string &r = partite().row(-1); // Stringa di lavoro per lo sheet
|
|
r.add(anno);
|
|
r.add(num);
|
|
r.add(data_doc);
|
|
r.add(num_doc);
|
|
add_importo(r, saldo);
|
|
add_importo(r, doc);
|
|
add_importo(r, pag);
|
|
add_importo(r, imp);
|
|
r.add(descr);
|
|
}
|
|
|
|
if (should_delete_game)
|
|
delete game;
|
|
|
|
partita.put(PART_NRIGA, 9999); // Forza lettura partita successiva nella prossima read
|
|
}
|
|
|
|
partite().force_update();
|
|
if (a.items() > 0)
|
|
partite_notify(partite(), 0, K_TAB);
|
|
else
|
|
{
|
|
scadenze().destroy();
|
|
scadenze().force_update();
|
|
}
|
|
app().end_wait();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Metodi di prima nota
|
|
///////////////////////////////////////////////////////////
|
|
|
|
bool TPrimanota_application::edit_partite(int riga)
|
|
{
|
|
TToken_string& cgr = cgs().row(riga);
|
|
const TBill b(cgr, 2, 0x3); // Legge il conto della riga selezionata
|
|
if (!b.ok()) return FALSE;
|
|
|
|
TGame_mask mask(b); // Inizializzazione maschera di selezione partite
|
|
mask.run();
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
int TPrimanota_application::nuovo_pagamento(TPartita& partita, int nriga, int rata, int rmov)
|
|
{
|
|
const TRiga_partite& riga_part = partita.riga(nriga);
|
|
CHECKD(rata >= 1 && rata <= riga_part.rate(), "Rata errata ", rata);
|
|
|
|
TRiga_scadenze& riga_scad = riga_part.rata(rata);
|
|
if (riga_scad.pagata())
|
|
return -1;
|
|
|
|
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
|
|
|
|
if (nrigp < 1) // Devo creare una nuova riga di partita
|
|
{
|
|
TRiga_partite& part = partita.nuova_riga(); // Creazione nuova riga vuota
|
|
nrigp = part.get_int(PART_NRIGA);
|
|
|
|
// Copia dati movimento corrente
|
|
part.put(PART_NREG, numreg); // Numero operazione
|
|
part.put(PART_NUMRIG, rmov); // 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));
|
|
part.put(PART_DESCR, curr_mask().get(F_DESCR));
|
|
part.put(PART_CAMBIO, curr_mask().get(S_CAMBIO));
|
|
part.put(PART_DATACAM, curr_mask().get(S_DATACAMBIO));
|
|
|
|
// Copia dati causale corrente
|
|
const int tipomov = causale().tipomov();
|
|
part.put(PART_TIPOMOV, tipomov);
|
|
part.put(PART_CODCAUS, causale().codice());
|
|
const TRegistro& reg = causale().reg();
|
|
part.put(PART_REG, reg.name());
|
|
part.put(PART_PROTIVA, reg.protocol());
|
|
|
|
// Complesso algoritmo per calcolare la sezione di una nuova riga partita
|
|
char sezione = ' '; // Sezione nulla
|
|
TBill bill; causale().bill(1, bill); // Legge primo conto causale
|
|
if (bill.tipo() == conto.tipo()) // Se il tipo coincide ...
|
|
sezione = causale().sezione(1); // ... usa la sezione della causale
|
|
|
|
if (sezione <= ' ') // Se non c'e' la sezione bell'e' ch'e' pronta
|
|
{
|
|
if (tipomov == 1 || tipomov == 5) // calcola in base al tipo movimento e
|
|
sezione = (conto.tipo() == 'C') ? 'D' : 'A'; // al tipo cliente/fornitore
|
|
else
|
|
sezione = (conto.tipo() == 'C') ? 'A' : 'D';
|
|
|
|
if (bill.tipo() != conto.tipo()) // Compensazioni
|
|
sezione = (sezione == 'D') ? 'A' : 'D'; // scambia segno
|
|
}
|
|
part.put(PART_SEZ, sezione); // Memorizza solo la sezione (importi nulli)
|
|
}
|
|
|
|
TRectype& pagamento = riga_scad.row(nrigp, TRUE); // Crea nuovo pagamento
|
|
|
|
int caus = 2; // Calcola riga causale per la contropartita in base al tipo pagamento
|
|
switch (riga_scad.get_int(SCAD_TIPOPAG))
|
|
{
|
|
case 2: // Tratta
|
|
case 7: // Tratta accettata
|
|
caus = 3; break;
|
|
case 3: // Ricevuta bancaria
|
|
caus = 4; break;
|
|
case 4: // Cessione
|
|
caus = 5; break;
|
|
case 5: // Paghero'
|
|
caus = 6; break;
|
|
case 6: // Fattura di credito
|
|
caus = 7; break;
|
|
case 1: // Rimessa
|
|
case 8: // Rapporti interbancari diretti
|
|
case 9: // Bonifico
|
|
default:
|
|
caus = 2; break;
|
|
}
|
|
|
|
TBill contro; causale().bill(caus, contro); // Legge conto contropartita
|
|
if (contro.empty()) // Se non specificato ...
|
|
causale().bill(caus = 1, contro); // ... prende il primo
|
|
contro.put(pagamento, TRUE); // Scrive conto contropartita
|
|
|
|
if (conto.tipo() > ' ') // Se cliente o fornitore cerca sua banca
|
|
{
|
|
TRelation cliforel(LF_CLIFO);
|
|
cliforel.add(LF_CFVEN, "TIPOCF=TIPOCF|CODCF=CODCF");
|
|
TRectype& clifo = cliforel.lfile().curr();
|
|
|
|
clifo.put(CLI_TIPOCF, conto.tipo());
|
|
clifo.put(CLI_CODCF, conto.codclifo());
|
|
const int err = cliforel.read();
|
|
CHECK(err == NOERR, "Chiss'e' fregato il clifo");
|
|
|
|
pagamento.put(PAGSCA_CODABI, clifo.get(CLI_CODABI));
|
|
pagamento.put(PAGSCA_CODCAB, clifo.get(CLI_CODCAB));
|
|
pagamento.put(PAGSCA_CODAG, cliforel.lfile(LF_CFVEN).get(CLI_CODAG));
|
|
}
|
|
pagamento.put(PAGSCA_CODABIPR, riga_scad.get(SCAD_CODABIPR));
|
|
pagamento.put(PAGSCA_CODCABPR, riga_scad.get(SCAD_CODCABPR));
|
|
|
|
return nrigp;
|
|
}
|
|
|
|
HIDDEN bool importo_handler(TMask_field& f, KEY k)
|
|
{
|
|
TMask& m = f.mask();
|
|
|
|
if (k == K_F8)
|
|
{
|
|
f.set(m.get(S_RESIDUO));
|
|
k = K_TAB;
|
|
}
|
|
|
|
if (f.to_check(k))
|
|
{
|
|
const real i(f.get());
|
|
const real tot(m.get(S_RESIDUO));
|
|
if (i >= tot)
|
|
m.set(S_SALDOACC, "S");
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pag)
|
|
{
|
|
const int nriga = new_pag.get_int(PAGSCA_NRIGA); // Riga fattura
|
|
const TRiga_partite& parbas = p.riga(nriga);
|
|
|
|
const int nrata = new_pag.get_int(PAGSCA_NRATA); // Numero rata
|
|
TRiga_scadenze& scaden = parbas.rata(nrata);
|
|
|
|
const int nrigp = new_pag.get_int(PAGSCA_NRIGP); // Riga pagamento
|
|
const TRectype& old_pag = scaden.row(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
|
|
|
|
// Aggiornamento contopartita
|
|
const TImporto old_importo(controsez, old_pag.get_real(PAGSCA_IMPORTO));
|
|
TBill old_conto; old_conto.get(old_pag, TRUE);
|
|
|
|
const TImporto new_importo(controsez, new_pag.get_real(PAGSCA_IMPORTO));
|
|
TBill new_conto; new_conto.get(new_pag, TRUE);
|
|
|
|
if (old_importo != new_importo || old_conto != new_conto)
|
|
{
|
|
const int old_riga = bill2pos(old_conto, 'I');
|
|
if (old_riga >= 0)
|
|
{
|
|
const bool empty = sub_cgs_imp(old_riga, old_importo);
|
|
if (empty && (new_importo.is_zero() || new_conto != old_conto))
|
|
reset_cgs_row(old_riga);
|
|
}
|
|
|
|
// Importo della contropartita
|
|
if (!new_importo.is_zero())
|
|
{
|
|
const int new_riga = bill2pos(new_conto, 'I');
|
|
if (new_riga < 0)
|
|
set_cgs_row(new_riga, new_importo, new_conto, "", 'I');
|
|
else
|
|
add_cgs_imp(new_riga, new_importo);
|
|
}
|
|
}
|
|
|
|
// Aggiornamento ritenute
|
|
const real old_ritenute(old_pag.get(PAGSCA_RITENUTE));
|
|
const real new_ritenute(new_pag.get(PAGSCA_RITENUTE));
|
|
if (old_ritenute != new_ritenute)
|
|
{
|
|
const TImporto grow_ritenute(controsez, new_ritenute-old_ritenute);
|
|
const riga = type2pos('F');
|
|
if (riga < 0)
|
|
{
|
|
TBill conto_rit; causale().bill(11, conto_rit);
|
|
set_cgs_row(riga, grow_ritenute, conto_rit, "", 'F');
|
|
}
|
|
else
|
|
{
|
|
const bool empty = add_cgs_imp(riga, grow_ritenute);
|
|
if (empty) reset_cgs_row(riga);
|
|
}
|
|
}
|
|
|
|
char old_ap, new_ap;
|
|
TImporto old_abbuono, new_abbuono, old_diffcam, new_diffcam;
|
|
const bool empty = p.modifica_pagamento(new_pag,
|
|
old_ap, old_abbuono, new_abbuono,
|
|
new_ap, new_abbuono, new_diffcam);
|
|
|
|
// Se c'e' differenza negli abbuoni
|
|
if (old_abbuono != new_abbuono || old_ap != new_ap)
|
|
{
|
|
const int riga_contabile = app().cgs().selected();
|
|
if (old_ap != ' ') // Se c'era un abbuono ...
|
|
{
|
|
const int riga_abb = type2pos(old_ap);
|
|
CHECK(riga_abb >= 0, "Chiss'e' fregato gli abbuoni?");
|
|
const bool empty = sub_cgs_imp(riga_abb, old_abbuono);
|
|
if (empty && new_ap != old_ap)
|
|
reset_cgs_row(riga_abb);
|
|
|
|
// Sottrae l'abbuono con la sezione invertita dalla riga contabile
|
|
add_cgs_imp(riga_contabile, old_abbuono);
|
|
}
|
|
if (new_ap != ' ') // Se ci sono abbuoni
|
|
{
|
|
const riga_abb = type2pos(new_ap);
|
|
if (riga_abb < 0)
|
|
{
|
|
TBill conto_abb; causale().bill(new_ap == 'A' ? 9 : 8, conto_abb);
|
|
app().set_cgs_row(riga_abb, new_abbuono, conto_abb, "", new_ap);
|
|
}
|
|
else
|
|
add_cgs_imp(riga_abb, new_abbuono);
|
|
sub_cgs_imp(riga_contabile, new_abbuono); // Aggiunge l'abbuono con la sezione invertita
|
|
}
|
|
}
|
|
|
|
// Se c'e' variazione nella differenza cambi
|
|
if (old_diffcam != new_diffcam)
|
|
{
|
|
const int riga_diffcam = type2pos('C');
|
|
TImporto grow_diffcam(new_diffcam); grow_diffcam -= old_diffcam;
|
|
|
|
if (riga_diffcam < 0)
|
|
{
|
|
TBill conto_diffcam; causale().bill(12, conto_diffcam);
|
|
set_cgs_row(riga_diffcam, grow_diffcam, conto_diffcam, "", 'C');
|
|
}
|
|
else
|
|
{
|
|
const bool empty = add_cgs_imp(riga_diffcam, grow_diffcam);
|
|
if (empty) reset_cgs_row(riga_diffcam);
|
|
}
|
|
}
|
|
|
|
return empty;
|
|
}
|
|
|
|
|
|
bool TPrimanota_application::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp)
|
|
{
|
|
TMask m("cg2100s");
|
|
m.set_handler(S_IMPORTO, importo_handler);
|
|
|
|
const TRiga_partite& parbas = p.riga(nriga);
|
|
const TRiga_scadenze& scaden = parbas.rata(nrata);
|
|
const TRectype& oldpag = scaden.row(nrigp);
|
|
TRiga_partite& somma = p.riga(nrigp);
|
|
|
|
const bool in_valuta = scaden.in_valuta();
|
|
m.show(S_IMPORTOVAL_SCAD, in_valuta);
|
|
m.show(S_IMPORTOVAL, in_valuta);
|
|
|
|
TRelation rel(LF_PAGSCA); // Working relation
|
|
rel.lfile().curr() = oldpag;
|
|
m.autoload(&rel); // Load current record on mask
|
|
|
|
m.set(S_DESCAGG, somma.get(PART_DESCR));
|
|
|
|
// Dati del documento (fattura) che ha generato la scadenza
|
|
m.set(S_NUMDOC, parbas.get(PART_NUMDOC)); // Numero documento
|
|
m.set(S_DATADOC, parbas.get(PART_DATADOC)); // Data documento
|
|
m.set(S_NUMPROT, parbas.get(PART_PROTIVA)); // Protocollo IVA
|
|
m.set(S_DESCR, parbas.get(PART_DESCR)); // Descrizione documento
|
|
|
|
// Dati della scadenza che ha generato la partita
|
|
TReal_field& residuo = (TReal_field&)m.field(S_RESIDUO);
|
|
residuo.set_decimals(in_valuta ? 2 : 0);
|
|
residuo.set(scaden.residuo().string()); // Residuo da pagare
|
|
m.set(S_DATASCAD, scaden.get(SCAD_DATASCAD)); // Data della scadenza
|
|
m.set(S_SEZIONE_SCAD, parbas.get(PART_SEZ)); // Sezione della rata
|
|
m.set(S_RATA, scaden.get(SCAD_NRATA));
|
|
m.set(S_IMPORTO_SCAD, scaden.get(SCAD_IMPORTO)); // Importo della rata
|
|
m.set(S_IMPORTOVAL_SCAD, scaden.get(SCAD_IMPORTOVAL)); // Importo in valuta
|
|
|
|
const KEY key = m.run();
|
|
if (key == K_ENTER || key == K_DEL)
|
|
{
|
|
if (key == K_DEL)
|
|
{
|
|
m.reset(S_IMPORTO);
|
|
m.reset(S_IMPORTOVAL);
|
|
m.reset(S_RITENUTE);
|
|
}
|
|
else
|
|
{
|
|
somma.put(PART_DESCR, m.get(S_DESCAGG)); // Aggiorna descrizione (comune ai pagamenti)
|
|
}
|
|
|
|
m.autosave(&rel);
|
|
TRectype& new_pag = rel.lfile().curr();
|
|
notify_edit_pagamento(p, new_pag);
|
|
}
|
|
|
|
return key != K_ESC;
|
|
}
|
|
|
|
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))
|
|
{
|
|
const TRiga_partite& part = partita.riga(p);
|
|
if (part.get_int(PART_TIPOMOV) == 1)
|
|
{
|
|
for (int r = part.rate(); r > 0; r--)
|
|
{
|
|
const TRiga_scadenze& scad = part.rata(r);
|
|
for (int s = scad.last(); s > 0; s = scad.pred(s))
|
|
{
|
|
const TRiga_partite& sum = partita.riga(s);
|
|
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);
|
|
notify_edit_pagamento(partita, pag);
|
|
found = TRUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return found;
|
|
}
|
|
|
|
bool TPrimanota_application::notify_cgline_deletion(int numrig)
|
|
{
|
|
bool found = FALSE;
|
|
const long nreg = curr_mask().get_long(F_NUMREG);
|
|
_partite.add_reg_num(nreg, 0);
|
|
|
|
for (TPartita* game = _partite.first(); game; game = _partite.next())
|
|
found |= notify_cgline_deletion(*game, nreg, numrig);
|
|
|
|
return found;
|
|
}
|