Patch level : 12.00 1284
Files correlati : sc0.exe cg2.exe Commento : Programma di controllo e ripristino partite errate ricorretto.
This commit is contained in:
parent
66c11094d1
commit
a15a0581c2
@ -69,7 +69,10 @@ TPrimanota_application::TPrimanota_application()
|
||||
HIDDEN bool key_handler(TMask& m, KEY k)
|
||||
{
|
||||
if (k == K_SHIFT + K_F12)
|
||||
{
|
||||
app().aggiorna_saldaconto();
|
||||
app().calcola_saldo();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <pconti.h>
|
||||
#include <doc.h>
|
||||
#include <occas.h>
|
||||
#include <pagsca.h>
|
||||
#include "../fp/fplib.h"
|
||||
#include "../f1/f1lib.h"
|
||||
#include "../f9/f9lib.h"
|
||||
@ -526,12 +527,249 @@ TImporto TPrimanota_application::imposte_split_pay() const
|
||||
return imposte;
|
||||
}
|
||||
|
||||
void set_importo(TSheet_field & cgrows, int row, const TImporto & imp)
|
||||
{
|
||||
TImporto row_imp;
|
||||
real val = cgrows.get_real_row_cell(row, CG_DARE);
|
||||
|
||||
if (val != ZERO)
|
||||
row_imp.set('D', val);
|
||||
else
|
||||
{
|
||||
val = cgrows.get_real_row_cell(row, CG_AVERE);
|
||||
|
||||
if (val != ZERO)
|
||||
row_imp.set('A', val);
|
||||
}
|
||||
row_imp += imp;
|
||||
row_imp.normalize();
|
||||
if (row_imp.sezione() == 'D')
|
||||
{
|
||||
cgrows.set_row_cell(CG_DARE, row_imp.valore(), row);
|
||||
cgrows.set_row_cell(CG_AVERE, ZERO, row);
|
||||
}
|
||||
else
|
||||
{
|
||||
cgrows.set_row_cell(CG_DARE, ZERO, row);
|
||||
cgrows.set_row_cell(CG_AVERE, row_imp.valore(), row);
|
||||
}
|
||||
}
|
||||
|
||||
void TPrimanota_application::aggiorna_saldaconto()
|
||||
{
|
||||
const bool pag = is_pagamento() && !_as400;
|
||||
const long nreg = _rel->lfile().get_long(MOV_NUMREG);
|
||||
int fgruppo = -1;
|
||||
int fconto = -1;
|
||||
long fsottoc = -1;
|
||||
|
||||
if (pag)
|
||||
{
|
||||
TSheet_field& cgrows = cgs();
|
||||
TAssoc_array rows_index;
|
||||
|
||||
FOR_EACH_SHEET_ROW_BACK(cgrows, i, r)
|
||||
{
|
||||
const char tipo = row_type(*r);
|
||||
|
||||
if ((tipo == cgrowtype_imponibile) ||
|
||||
(tipo == cgrowtype_spese) ||
|
||||
(tipo == cgrowtype_abbattivo) ||
|
||||
(tipo == cgrowtype_diffcambio) ||
|
||||
(tipo == cgrowtype_abbpassivo) ||
|
||||
(tipo == cgrowtype_ritfis))
|
||||
{
|
||||
cgrows.set_row_cell(CG_DARE, ZERO, i);
|
||||
cgrows.set_row_cell(CG_AVERE, ZERO, i);
|
||||
|
||||
TToken_string key;
|
||||
TString srow;
|
||||
|
||||
srow << i;
|
||||
key << tipo;
|
||||
if (tipo == cgrowtype_imponibile)
|
||||
{
|
||||
key.add(cgrows.get_int_row_cell(i, CG_GRUPPO));
|
||||
key.add(cgrows.get_int_row_cell(i, CG_CONTO));
|
||||
key.add(cgrows.get_long_row_cell(i, CG_SOTTOCONTO));
|
||||
if (fgruppo < 0)
|
||||
{
|
||||
fgruppo = cgrows.get_int_row_cell(i, CG_GRUPPO);
|
||||
fconto = cgrows.get_int_row_cell(i, CG_CONTO);
|
||||
fsottoc = cgrows.get_long_row_cell(i, CG_SOTTOCONTO);
|
||||
}
|
||||
}
|
||||
rows_index.add(key, srow);
|
||||
if (tipo == cgrowtype_imponibile)
|
||||
{
|
||||
key.cut(0);
|
||||
key << tipo;
|
||||
key.add(0);
|
||||
key.add(0);
|
||||
key.add(0);
|
||||
rows_index.add(key, srow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TPartite_array & part = partite();
|
||||
int items = part.items();
|
||||
TString_array parts;
|
||||
|
||||
part.get_keys(parts);
|
||||
FOR_EACH_ARRAY_ROW(parts, row, key)
|
||||
{
|
||||
TPartita & partita = (TPartita &) part[*key];
|
||||
|
||||
for (int row = partita.prima_fattura(); row > 0 && row <= partita.last(); row = partita.succ(row))
|
||||
{
|
||||
const TRiga_partite & rpart = partita.riga(row);
|
||||
|
||||
if (rpart.is_fattura())
|
||||
{
|
||||
const int nrate = rpart.rate();
|
||||
for (int s = 1; s <= nrate; s++)
|
||||
{
|
||||
const TRiga_scadenze & scad = rpart.rata(s);
|
||||
int rp = scad.last();
|
||||
|
||||
for (; rp > 0; rp = scad.pred(rp))
|
||||
{
|
||||
|
||||
TRectype & pag = (TRectype &) scad.row(rp);
|
||||
int rpag = pag.get_int(PAGSCA_NRIGP);
|
||||
|
||||
if (partita.exist(rpag))
|
||||
{
|
||||
TRiga_partite & riga_pag = partita.riga(rpag);
|
||||
const long nreg_pag = riga_pag.get_long(PART_NREG);
|
||||
|
||||
if (nreg == nreg_pag)
|
||||
{
|
||||
char sez = pag.get(PAGSCA_TIPOC) == "C" ? 'D' : 'A';
|
||||
real val = pag.get_real(PAGSCA_IMPORTO);
|
||||
|
||||
if (val != ZERO)
|
||||
{
|
||||
TImporto imp(sez, val);
|
||||
TToken_string key;
|
||||
const int gruppo = pag.get_int(PAGSCA_GRUPPOC);
|
||||
|
||||
key << (char)cgrowtype_imponibile;
|
||||
key.add(gruppo);
|
||||
key.add(pag.get_int(PAGSCA_CONTOC));
|
||||
key.add(pag.get_long(PAGSCA_SOTTOCONTC));
|
||||
|
||||
if (rows_index.is_key(key))
|
||||
set_importo(cgrows, rows_index.get_int(key), imp);
|
||||
if (gruppo <= 0 && fgruppo > 0)
|
||||
{
|
||||
pag.put(PAGSCA_GRUPPOC, fgruppo);
|
||||
pag.put(PAGSCA_CONTOC, fconto);
|
||||
pag.put(PAGSCA_SOTTOCONTC, fsottoc);
|
||||
}
|
||||
}
|
||||
val = pag.get_real(PAGSCA_ABBUONI);
|
||||
|
||||
bool attivo = pag.get_real(PAGSCA_PASSATT) == "A";
|
||||
|
||||
if (val != ZERO)
|
||||
{
|
||||
TImporto imp(sez, val);
|
||||
TToken_string key;
|
||||
|
||||
key << (char)(attivo ? cgrowtype_abbattivo : cgrowtype_abbpassivo);
|
||||
|
||||
if (rows_index.is_key(key))
|
||||
set_importo(cgrows, rows_index.get_int(key), imp);
|
||||
}
|
||||
val = pag.get_real(PAGSCA_DIFFCAM);
|
||||
if (val != ZERO)
|
||||
{
|
||||
TImporto imp(sez, val);
|
||||
TToken_string key;
|
||||
|
||||
key << (char)cgrowtype_diffcambio;
|
||||
|
||||
if (rows_index.is_key(key))
|
||||
set_importo(cgrows, rows_index.get_int(key), imp);
|
||||
}
|
||||
val = pag.get_real(PAGSCA_RITENUTE);
|
||||
if (val != ZERO)
|
||||
{
|
||||
TImporto imp(sez, val);
|
||||
TToken_string key;
|
||||
|
||||
key << (char)cgrowtype_ritfis;
|
||||
|
||||
if (rows_index.is_key(key))
|
||||
set_importo(cgrows, rows_index.get_int(key), imp);
|
||||
}
|
||||
val = pag.get_real(PAGSCA_RITSOC);
|
||||
if (val != ZERO)
|
||||
{
|
||||
TImporto imp(sez, val);
|
||||
TToken_string key;
|
||||
|
||||
key << (char)cgrowtype_ritsoc;
|
||||
|
||||
if (rows_index.is_key(key))
|
||||
set_importo(cgrows, rows_index.get_int(key), imp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TRecord_array & unas = partita.unassigned();
|
||||
if (unas.rows() > 0)
|
||||
{
|
||||
for (int r = unas.last_row(); r > 0; r = unas.pred_row(r))
|
||||
{
|
||||
const TRectype & pag = unas.row(r);
|
||||
int rpag = pag.get_int(PAGSCA_NRIGP);
|
||||
|
||||
if (partita.exist(rpag))
|
||||
{
|
||||
TRiga_partite & riga_pag = partita.riga(rpag);
|
||||
const long nreg_pag = riga_pag.get_long(PART_NREG);
|
||||
|
||||
if (nreg == nreg_pag)
|
||||
{
|
||||
char sez = pag.get(PAGSCA_TIPOC) == "C" ? 'D' : 'A';
|
||||
real val = pag.get_real(PAGSCA_IMPORTO);
|
||||
|
||||
if (val != ZERO)
|
||||
{
|
||||
TImporto imp(sez, val);
|
||||
TToken_string key;
|
||||
|
||||
key << (char)cgrowtype_imponibile;
|
||||
key.add(pag.get_int(PAGSCA_GRUPPOC));
|
||||
key.add(pag.get_int(PAGSCA_CONTOC));
|
||||
key.add(pag.get_long(PAGSCA_SOTTOCONTC));
|
||||
|
||||
if (rows_index.is_key(key))
|
||||
set_importo(cgrows, rows_index.get_int(key), imp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cgrows.force_update();
|
||||
}
|
||||
}
|
||||
|
||||
real TPrimanota_application::calcola_saldo() const
|
||||
{
|
||||
const bool pag = is_pagamento() && !_as400;
|
||||
TImporto importo, bilancio, saldaconto;
|
||||
|
||||
TSheet_field& cgrows = cgs();
|
||||
|
||||
FOR_EACH_SHEET_ROW_BACK(cgrows, i, r)
|
||||
{
|
||||
importo = *r;
|
||||
|
@ -454,6 +454,7 @@ public:
|
||||
void type2colors(char tipor, COLOR& back, COLOR& fore);
|
||||
void set_type_colors(char tipor, COLOR back, COLOR fore);
|
||||
void reset_colors();
|
||||
void aggiorna_saldaconto();
|
||||
real calcola_saldo() const;
|
||||
|
||||
TCausale& causale() const { return * _causale; }
|
||||
|
@ -1487,6 +1487,21 @@ void TPartita::allinea(char all)
|
||||
}
|
||||
}
|
||||
|
||||
void TPartita::recover_rpag(const TRiga_partite & riga, TImporto & importo, int rigaf, int rataf)
|
||||
{
|
||||
TRectype & pag = riga.partita().pagamento(rigaf, rataf, riga.get_int(PART_NRIGA));
|
||||
|
||||
pag.put(PAGSCA_IMPORTO, importo.valore());
|
||||
if (riga.partita().in_valuta())
|
||||
{
|
||||
const TString & codval = riga.get(PART_CODVAL);
|
||||
const real cambio = riga.get_real(PART_CAMBIO);
|
||||
TCurrency importo_val(importo.valore());
|
||||
|
||||
importo_val.change_value(codval, cambio);
|
||||
pag.put(PAGSCA_IMPORTOVAL, importo_val.get_value());
|
||||
}
|
||||
}
|
||||
|
||||
void TPartita::recover_rpart(const TRectype & pag, int rigap, int unass_row)
|
||||
{
|
||||
@ -1686,7 +1701,7 @@ bool TPartita::read(const TBill& clifo, int year, const char* num)
|
||||
_part.read(partita);
|
||||
|
||||
TAssoc_array regs;
|
||||
int firstrow =first();
|
||||
int firstrow = first();
|
||||
|
||||
for (int r = last(); r >= firstrow; r = pred(r))
|
||||
{
|
||||
@ -1733,6 +1748,9 @@ bool TPartita::read(const TBill& clifo, int year, const char* num)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TBit_array fatture;
|
||||
|
||||
for (int p = last(); p > 0; p = pred(p))
|
||||
{
|
||||
TRiga_partite & rpart = riga(p);
|
||||
@ -1740,6 +1758,8 @@ bool TPartita::read(const TBill& clifo, int year, const char* num)
|
||||
if (rpart.tipo() == tm_fattura)
|
||||
{
|
||||
int nrate = rpart.rate();
|
||||
|
||||
fatture.set(p);
|
||||
for (int s = 1; s <= nrate; s++)
|
||||
{
|
||||
TRiga_scadenze & rscad = rpart.rata(s);
|
||||
@ -1768,7 +1788,84 @@ bool TPartita::read(const TBill& clifo, int year, const char* num)
|
||||
_unassigned.read(unas);
|
||||
if (_unassigned.rows() > 0 && _part.rows() <= 0) // non assegnati orfani!
|
||||
_unassigned.destroy_rows();
|
||||
for (int f = _unassigned.last_row(); f > 0; f = _unassigned.pred_row(f))
|
||||
{
|
||||
const TRectype & pag = _unassigned.row(f);
|
||||
const int rigap = pag.get_int(PAGSCA_NRIGP);
|
||||
|
||||
if (!esiste(rigap))
|
||||
{
|
||||
recover_rpart(pag, rigap, f);
|
||||
_patched = true;
|
||||
}
|
||||
}
|
||||
if (fatture.some_one())
|
||||
{
|
||||
int rigaf = TPartita::UNASSIGNED;
|
||||
int rataf = TPartita::UNASSIGNED;
|
||||
|
||||
if (fatture.ones() == 1)
|
||||
{
|
||||
rigaf = fatture.first_one();
|
||||
|
||||
TRiga_partite & fatt = riga(rigaf);
|
||||
|
||||
if (fatt.rate() == 1)
|
||||
rataf = 1;
|
||||
}
|
||||
|
||||
for (int p = last(); p > 0; p = pred(p))
|
||||
{
|
||||
TRiga_partite & rpart = riga(p);
|
||||
|
||||
if (rpart.tipo() != tm_fattura)
|
||||
{
|
||||
TImporto pagato;
|
||||
|
||||
for (int rf = fatture.first_one(); rf > 0 && rf <= fatture.last_one(); rf++)
|
||||
if (fatture[rf])
|
||||
{
|
||||
TRiga_partite & fatt = riga(rf);
|
||||
int nrate = fatt.rate();
|
||||
|
||||
for (int s = 1; s <= nrate; s++)
|
||||
{
|
||||
TRiga_scadenze & rscad = fatt.rata(s);
|
||||
|
||||
if (rscad.exist(p))
|
||||
{
|
||||
const TRectype & pag = rscad.row(p);
|
||||
|
||||
pagato += rpart.importo_pagsca(pag, false, 0x1);
|
||||
}
|
||||
}
|
||||
|
||||
TRecord_array& unas = unassigned();
|
||||
|
||||
if (unas.exist(p))
|
||||
{
|
||||
const TRectype & pag = unas.row(p);
|
||||
const real importo = pag.get(PAGSCA_IMPORTO);
|
||||
char sez = pag.get(PAGSCA_TIPOC) == "C" ? 'A' : 'D';
|
||||
TImporto i(sez, importo);
|
||||
|
||||
pagato += i;
|
||||
}
|
||||
}
|
||||
|
||||
TImporto importo = rpart.importo(false, 0x1);
|
||||
char sez = importo.sezione();
|
||||
|
||||
importo -= pagato;
|
||||
importo.normalize(sez);
|
||||
if (!importo.is_zero())
|
||||
{
|
||||
recover_rpag(rpart, importo, rigaf, rataf);
|
||||
_patched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TImporto saldo;
|
||||
TImporto doc;
|
||||
TImporto pag;
|
||||
@ -1786,17 +1883,7 @@ bool TPartita::read(const TBill& clifo, int year, const char* num)
|
||||
|
||||
if (saldo != oldsaldo || doc != olddoc || pag != oldpag || imp != oldimp)
|
||||
write_saldo(true);
|
||||
for (int f = _unassigned.last_row(); f > 0; f = _unassigned.pred_row(f))
|
||||
{
|
||||
const TRectype & pag = _unassigned.row(f);
|
||||
const int rigap = pag.get_int(PAGSCA_NRIGP);
|
||||
|
||||
if (!esiste(rigap))
|
||||
{
|
||||
recover_rpart(pag, rigap, f);
|
||||
_patched = true;
|
||||
}
|
||||
}
|
||||
if (_patched)
|
||||
rewrite();
|
||||
return ok();
|
||||
|
@ -260,6 +260,7 @@ public:
|
||||
TRectype& pagamento(int nriga, int nrata, int nrigp);
|
||||
bool rata_chiusa(int nriga, int nrata) const;
|
||||
bool esiste(int nriga, int nrata = 0, int nrigp = 0) const;
|
||||
bool exist(int nriga) const { return _part.exist(nriga); }
|
||||
bool esistono_abbuoni_diffcam(long nreg = 0) const;
|
||||
|
||||
const TString& codice_valuta() const;
|
||||
@ -271,6 +272,7 @@ public:
|
||||
void scollega_pagamenti(int riga, int rata = 1);
|
||||
|
||||
void allinea(char all = ' ');
|
||||
void recover_rpag(const TRiga_partite & riga, TImporto & importo, int rigaf, int rataf);
|
||||
void recover_rpart(const TRectype & pag, int rigap, int unass_row = 0);
|
||||
|
||||
int succ(int r) const { return _part.succ_row(r); }
|
||||
@ -337,7 +339,7 @@ public:
|
||||
virtual ~TPartita();
|
||||
};
|
||||
|
||||
class TPartite_array : private TAssoc_array
|
||||
class TPartite_array : public TAssoc_array
|
||||
{
|
||||
TString _key; // Work string
|
||||
long _numreg; // Last registration loaded
|
||||
|
Loading…
x
Reference in New Issue
Block a user