Files correlati : ef0.exe Ricompilazione Demo : [ ] Commento : Bug 0001475: 0001837: Aggiungere selezione banca di appoggio su Disp. Incassi e pagamenti Nel programma di disposizioni incasso e pagamento non è possibile selezionare su quale banca bonificare il fornitore tra quelle presenti in anagrafica. Inoltre anche dal programma aggiornamento effetti se vado nella pagina dei parametri, non posso selezionare dalla tabella dalle banche del fornitore ma dall'anagrafica delle banche. git-svn-id: svn://10.65.10.50/branches/R_10_00@22152 c028cbd2-c16b-5b4b-a496-9718f37d4682
1205 lines
33 KiB
C++
Executable File
1205 lines
33 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <automask.h>
|
||
#include <defmask.h>
|
||
#include <execp.h>
|
||
#include <modaut.h>
|
||
#include <progind.h>
|
||
#include <relation.h>
|
||
#include <reputils.h>
|
||
#include <tabutil.h>
|
||
|
||
#include <clifo.h>
|
||
#include <cfven.h>
|
||
#include <partite.h>
|
||
#include <rmov.h>
|
||
#include "../cg/cgsaldac.h"
|
||
#include "../ef/ef0301.h"
|
||
|
||
#include "ef0.h"
|
||
#include "ef0A00a.h"
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Main Mask
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TPE_mask : public TAutomask
|
||
{
|
||
TRelation* _rel;
|
||
bool _spork;
|
||
bool _is_new;
|
||
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
bool on_sheet_event(TOperable_field& o, TField_event e, long jolly);
|
||
bool check_bank(TEffetto& effetto, TLog_report& log) const;
|
||
|
||
public:
|
||
bool calc_residual(const TRiga_scadenze& scad, real& impres, real& imppag, TDate & datapag, bool & valben,
|
||
char& accsal, int& rdist, int& reff,
|
||
bool& partially_unassigned, int& tipopag, bool is_old = false) const;
|
||
bool fill_row(const TRiga_scadenze& rs, TToken_string& row, bool& partially_unassigned, bool force, bool is_new);
|
||
bool fill_rate();
|
||
int insert_row(const TToken_string& row);
|
||
bool fill_distinta(bool clear_all = false);
|
||
void sort_sheet();
|
||
void update_total();
|
||
virtual bool on_key(KEY key);
|
||
|
||
TRectype& new_row_effetto(TDistinta& dist, char tipocf, long codcf, const TString & cup, const TString & cig,
|
||
const TDate & datapag, int& rigadist, int& rigaeff) const;
|
||
long get_free_num() const;
|
||
void save_rate();
|
||
void print();
|
||
|
||
TPE_mask();
|
||
virtual ~TPE_mask();
|
||
};
|
||
|
||
|
||
bool TPE_mask::on_key(KEY key)
|
||
{
|
||
if (key == K_F8)
|
||
{
|
||
TSheet_field & s = sfield(F_SHEET);
|
||
const int row = s.selected();
|
||
|
||
if (row >= 0)
|
||
{
|
||
s.update_row(row);
|
||
TToken_string & r = s.row(row);
|
||
const bool attivo = get(F_TIPOCF) == "C";
|
||
const TString data(attivo ? get(F_DATADIST) : r.get(s.cid2index(F_DATA)));
|
||
|
||
r.add(data, s.cid2index(F_DATAPAG));
|
||
s.update_mask(row);
|
||
s.force_update(row);
|
||
}
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
// Calcola il residuo di una rata tenendo conto anche degli eventuali
|
||
// effetti non ancora contabilizzati
|
||
bool TPE_mask::calc_residual(const TRiga_scadenze& scad,
|
||
real& impres, real& imppag, TDate & datapag, bool & valben,
|
||
char& accsal, int& rdist, int& reff,
|
||
bool& partially_unassigned, int& tipopag,
|
||
bool is_old) const
|
||
{
|
||
tipopag = scad.get_int(SCAD_TIPOPAG);
|
||
const bool valuta = scad.in_valuta();
|
||
const char tipocf = scad.get_char(SCAD_TIPOCF);
|
||
|
||
TImporto importo = scad.residuo(TRUE);
|
||
importo.normalize(tipocf == 'C' ? 'D' : 'A');
|
||
|
||
impres = importo.valore();
|
||
imppag = ZERO;
|
||
accsal = 'A';
|
||
rdist = reff = 0;
|
||
partially_unassigned = FALSE;
|
||
|
||
// Contolla se ci sono pagamenti non assegnati da gestire
|
||
const TRiga_partite& fattura = scad.riga();
|
||
TPartita& partita = fattura.partita();
|
||
const TRecord_array& unassigned = partita.unassigned();
|
||
if (unassigned.rows() > 0)
|
||
{
|
||
real tot_unassigned; // Totale pagamenti non assegnati
|
||
for (int u = unassigned.last_row(); u > 0; u = unassigned.pred_row(u))
|
||
{
|
||
const real imp = unassigned[u].get(valuta ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO);
|
||
tot_unassigned += imp;
|
||
}
|
||
|
||
// Scala non assegnati dalle rate precedenti ancora aperte
|
||
const int nrata = scad.get_int(SCAD_NRATA);
|
||
for (int r = 1; r < nrata; r++)
|
||
{
|
||
if (!fattura.rata(r).chiusa())
|
||
{
|
||
TImporto res = fattura.rata(r).residuo(TRUE);
|
||
tot_unassigned -= res.valore();
|
||
if (tot_unassigned <= ZERO)
|
||
break;
|
||
}
|
||
}
|
||
// Scala non assegnati dalla rata corrente
|
||
if (tot_unassigned > ZERO)
|
||
{
|
||
if (tot_unassigned >= impres)
|
||
impres = ZERO;
|
||
else
|
||
impres -= tot_unassigned;
|
||
partially_unassigned = TRUE;
|
||
}
|
||
}
|
||
|
||
// Se c'e' ancora un residuo calcola totale pagato con effetti
|
||
if (!impres.is_zero())
|
||
{
|
||
TRectype& filter = _rel->curr();
|
||
const char* field[] = { SCAD_ANNO, SCAD_NUMPART, SCAD_NRIGA, SCAD_NRATA, NULL };
|
||
for (int i = 0; field[i]; i++)
|
||
filter.put(field[i], scad.get(field[i]));
|
||
TCursor cur(_rel, "", 2, &filter, &filter); // Elenco effetti su questa rata
|
||
|
||
const long codcf = scad.get_long(SCAD_SOTTOCONTO);
|
||
TString80 expr;
|
||
expr << '(' << LF_EFFETTI << "->" << EFF_EFFCONT << "!=\"X\")&&";
|
||
expr << '(' << LF_EFFETTI << "->" << EFF_TIPOCF << "==\"" << tipocf << "\")&&";
|
||
expr << '(' << LF_EFFETTI << "->" << EFF_CODCF << "==\"" << codcf << "\")";
|
||
cur.setfilter(expr, TRUE);
|
||
const long items = cur.items();
|
||
if (items > 0L)
|
||
{
|
||
cur.freeze();
|
||
const TRectype& riga = cur.curr();
|
||
const TRectype& effe = cur.curr(LF_EFFETTI);
|
||
TString8 key = get(F_TIPODIST); key << get(F_DIST);
|
||
for (cur = 0L; cur.pos() < items; ++cur)
|
||
{
|
||
TString8 effkey = effe.get(EFF_TIPODIST); effkey << effe.get(EFF_NDIST);
|
||
if (effkey == key)
|
||
{
|
||
rdist = effe.get_int(EFF_NRIGADIST);
|
||
datapag = effe.get_date(EFF_DATASCAD);
|
||
valben = effe.get_bool(EFF_DSCVAL);
|
||
reff = riga.get_int(REFF_NRIGATR);
|
||
accsal = riga.get_char(REFF_ACCSAL);
|
||
imppag += riga.get_real(valuta ? REFF_IMPORTOVAL : REFF_IMPORTO);
|
||
tipopag = effe.get_int(EFF_TIPOPAG);
|
||
}
|
||
else
|
||
{
|
||
if (riga.get_char(REFF_ACCSAL) == 'S')
|
||
{
|
||
impres = ZERO;
|
||
if (is_old)
|
||
return true; // Devo farla vedere
|
||
break;
|
||
}
|
||
impres -= riga.get_real(valuta ? REFF_IMPORTOVAL : REFF_IMPORTO);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return !impres.is_zero();
|
||
}
|
||
|
||
void TPE_mask::update_total()
|
||
{
|
||
TSheet_field& s = sfield(F_SHEET);
|
||
const int postot = s.cid2index(F_IMPORTO);
|
||
real tot;
|
||
FOR_EACH_SHEET_ROW_BACK(s, r, row)
|
||
tot += real(row->get(postot));
|
||
set(F_TOTAL, tot);
|
||
enable(DLG_SAVEREC, !tot.is_zero());
|
||
}
|
||
|
||
bool TPE_mask::fill_row(const TRiga_scadenze& rs, TToken_string& row, bool& partially_unassigned, bool force, bool is_old)
|
||
{
|
||
const int tipopageff = get_int(F_TIPOPAGEFF);
|
||
int tipopag = 0;
|
||
real impres, imppag;
|
||
char accsal; int rigadist, rigaeff;
|
||
TDate datapag;
|
||
bool valben = false;
|
||
const bool attivo = get(F_TIPOCF) == "C";
|
||
|
||
row.cut(0);
|
||
bool ok = calc_residual(rs, impres, imppag, datapag, valben, accsal, rigadist, rigaeff, partially_unassigned, tipopag, is_old) || force;
|
||
if (ok)
|
||
ok = tipopageff == 0 || tipopag == tipopageff; // Eventuale filtro sul tipo pagamento
|
||
if (ok)
|
||
{
|
||
row.add(imppag.string());
|
||
row.add(accsal);
|
||
const TDate datadef = attivo ? rs.get_date(SCAD_DATASCAD) : get_date(F_DATADIST);
|
||
row.add(datapag == datadef ? "" : datapag);
|
||
row.add(valben ? "X" : "");
|
||
row.add(impres.string());
|
||
row.add(rs.get_long(SCAD_SOTTOCONTO));
|
||
TString8 cod; cod << rs.get_char(SCAD_TIPOCF) << '|' << rs.get_long(SCAD_SOTTOCONTO);
|
||
row.add(cache().get(LF_CLIFO, cod, CLI_RAGSOC));
|
||
row.add(rs.get(SCAD_ANNO));
|
||
row.add(rs.get(SCAD_NUMPART));
|
||
row.add(rs.get(SCAD_NRIGA));
|
||
row.add(rs.get(SCAD_NRATA));
|
||
row.add(rs.get(SCAD_DATASCAD));
|
||
row.add(rigadist);
|
||
row.add(rigaeff);
|
||
switch (tipopag)
|
||
{
|
||
case 1:row.add(TR("Rimessa Diretta")); break;
|
||
case 2:row.add(TR("Tratta")); break;
|
||
case 3:row.add(TR("Ricevuta Bancaria")); break;
|
||
case 4:row.add(TR("Cessione")); break;
|
||
case 5:row.add(TR("Pagher<EFBFBD>")); break;
|
||
case 6:row.add(TR("Lettera di credito")); break;
|
||
case 7:row.add(TR("Tratta accettata")); break;
|
||
case 8:row.add(TR("Rapporti interbancari diretti")); break;
|
||
case 9:row.add(TR("Bonifico")); break;
|
||
default: break;
|
||
}
|
||
|
||
TRiga_partite& rp = rs.riga();
|
||
TString cup;
|
||
TString cig;
|
||
|
||
const long numreg = rp.get_long(PART_NREG);
|
||
|
||
if (numreg > 0)
|
||
{
|
||
TToken_string key;
|
||
|
||
key.add(numreg);
|
||
key.add(1);
|
||
|
||
const TRectype & rmov = cache().get(LF_RMOV, key);
|
||
|
||
cup = rmov.get(RMV_CUP);
|
||
cig = rmov.get(RMV_CIG);
|
||
}
|
||
row.add(cup);
|
||
row.add("");
|
||
row.add(cig);
|
||
row.add("");
|
||
TToken_string key;
|
||
|
||
key.add(get(F_TIPOCF));
|
||
key.add(rs.get_long(SCAD_SOTTOCONTO));
|
||
key.add("V");
|
||
key.add(1);
|
||
const TRectype & ns_ban = cache().get(LF_CFBAN, key);
|
||
if (ns_ban.empty())
|
||
{
|
||
row.add("");
|
||
row.add("");
|
||
}
|
||
else
|
||
{
|
||
row.add(rs.get(SCAD_CODABI));
|
||
row.add(rs.get(SCAD_CODCAB));
|
||
}
|
||
row.add("");
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
HIDDEN long row_compare(TToken_string& r1, TToken_string& r2, const int sort_mode)
|
||
{
|
||
long cmp = 0;
|
||
if (sort_mode == 1)
|
||
{
|
||
const TDate d1 = r1.get(F_DATA-FIRST_FIELD);
|
||
const TDate d2 = r2.get(F_DATA-FIRST_FIELD);
|
||
cmp = d1 - d2;
|
||
if (cmp != 0)
|
||
return cmp; // else normal comparing
|
||
}
|
||
else if (sort_mode == 2)
|
||
{
|
||
const real i1 = r1.get(F_RESIDUO-FIRST_FIELD);
|
||
const real i2 = r2.get(F_RESIDUO-FIRST_FIELD);
|
||
const real diff = i1 - i2;
|
||
cmp = diff.sign();
|
||
if (cmp != 0)
|
||
return cmp; // else normal comparing
|
||
}
|
||
for (int i = 5; cmp == 0 && i <= 10; i++)
|
||
{
|
||
if (i == 6) continue;
|
||
if (i == 8)
|
||
{
|
||
TString16 p1; r1.get(i, p1);
|
||
TString16 p2; r2.get(i, p2);
|
||
cmp = p1.compare(p2);
|
||
}
|
||
else
|
||
{
|
||
long n1; r1.get(i, n1);
|
||
long n2; r2.get(i, n2);
|
||
cmp = n1 - n2;
|
||
}
|
||
}
|
||
|
||
return cmp;
|
||
}
|
||
|
||
int TPE_mask::insert_row(const TToken_string& row)
|
||
{
|
||
const int sort_mode = get_int(F_SORT);
|
||
TString_array& sheet = sfield(F_SHEET).rows_array();
|
||
int first = 0;
|
||
int last = sheet.items()-1;
|
||
|
||
long cmp = -1;
|
||
int cur = 0;
|
||
while (first <= last)
|
||
{
|
||
cur = (first+last) / 2;
|
||
TToken_string& curr = sheet.row(cur);
|
||
cmp = row_compare((TToken_string&)row, curr, sort_mode);
|
||
if (cmp == 0)
|
||
break;
|
||
if (cmp > 0)
|
||
first = cur+1;
|
||
else
|
||
last = cur-1;
|
||
}
|
||
if (cmp)
|
||
{
|
||
if (cmp > 0)
|
||
cur++;
|
||
sheet.insert(row, cur);
|
||
}
|
||
return cur;
|
||
}
|
||
|
||
void TPE_mask::sort_sheet()
|
||
{
|
||
TWait_cursor hourglass;
|
||
const int sort_mode = get_int(F_SORT);
|
||
|
||
TString_array& rows = sfield(F_SHEET).rows_array();
|
||
for (int i = 0; i < rows.items()-1; i++)
|
||
{
|
||
for (int j = i+1; j < rows.items(); j++)
|
||
{
|
||
TToken_string& r1 = rows.row(i);
|
||
TToken_string& r2 = rows.row(j);
|
||
if (row_compare(r1, r2, sort_mode) > 0)
|
||
rows.swap(i, j);
|
||
}
|
||
}
|
||
}
|
||
|
||
bool TPE_mask::fill_rate()
|
||
{
|
||
const long ndist = get_long(F_DIST);
|
||
const TDate dadata = get(F_DA_DATA);
|
||
const TDate adata = get(F_A_DATA);
|
||
const TString& codval = get(F_CODVAL);
|
||
TSheet_field& sheet = sfield(F_SHEET);
|
||
// sheet.destroy();
|
||
|
||
TRelation rel(LF_PARTITE);
|
||
TRectype filter(LF_PARTITE);
|
||
filter.put(PART_TIPOCF, get(F_TIPOCF));
|
||
filter.put(PART_GRUPPO, 0);
|
||
filter.put(PART_CONTO, 0);
|
||
filter.put(PART_SOTTOCONTO, get(F_CLIFO));
|
||
|
||
TString filtro;
|
||
filtro << "(CHIUSA!=\"X\")&&(CODVAL==\"" << codval << "\")";
|
||
TCursor partite(&rel, filtro, 1, &filter, &filter);
|
||
|
||
const long items = partite.items();
|
||
partite.freeze();
|
||
if (items > 0)
|
||
{
|
||
TRectype& partita = partite.curr();
|
||
|
||
TProgind pi(items, "Caricamento partite aperte", TRUE, TRUE);
|
||
|
||
long last_cf = 0;
|
||
int last_year = 0;
|
||
TString16 last_game;
|
||
|
||
TToken_string row;
|
||
|
||
for (partite = 0L; partite.pos() < items; ++partite)
|
||
{
|
||
pi.addstatus(1);
|
||
if (pi.iscancelled())
|
||
break;
|
||
if (sheet.items() > 900) // Anche troppe righe
|
||
break;
|
||
|
||
const long cur_cf = partita.get_long(PART_SOTTOCONTO);
|
||
const int cur_year = partita.get_int(PART_ANNO);
|
||
const TString& cur_game = partita.get(PART_NUMPART);
|
||
if (cur_cf == last_cf && cur_year == last_year && cur_game == last_game)
|
||
continue;
|
||
last_cf = cur_cf;
|
||
last_year = cur_year;
|
||
last_game = cur_game;
|
||
|
||
const TPartita game(partita);
|
||
const int last = game.last();
|
||
for (int riga = game.prima_fattura(); riga > 0 && riga <= last; riga = game.succ(riga))
|
||
{
|
||
const TRiga_partite& rp = game.riga(riga);
|
||
if (rp.is_fattura())
|
||
{
|
||
for (int rata = 1; rata <= rp.rate(); rata++)
|
||
{
|
||
const TRiga_scadenze& rs = rp.rata(rata);
|
||
if (!rs.chiusa())
|
||
{
|
||
const TDate data = rs.get(SCAD_DATASCAD);
|
||
if (data >= dadata && (!adata.ok() || data <= adata))
|
||
{
|
||
bool partially_unassigned;
|
||
if (fill_row(rs, row, partially_unassigned, false, false))
|
||
{
|
||
const int numrow = sheet.items();
|
||
sheet.row(numrow) = row;
|
||
sheet.check_row(numrow);
|
||
if (partially_unassigned)
|
||
sheet.disable_cell(numrow, 1); // Non permette di mettere a saldo
|
||
}
|
||
}
|
||
} // if rata aperta
|
||
} // for ogni rata
|
||
} // if e' una fattura
|
||
} // for ogni fattura
|
||
} // for ogni partita
|
||
} // if ci sono partite
|
||
return fill_distinta(false);
|
||
}
|
||
|
||
bool TPE_mask::fill_distinta(bool clear_all)
|
||
{
|
||
TWait_cursor hourglass;
|
||
TSheet_field& sheet = sfield(F_SHEET);
|
||
if (clear_all)
|
||
sheet.destroy();
|
||
const char tdist = get(F_TIPODIST)[0];
|
||
const long ndist = get_long(F_DIST);
|
||
TDistinta dist(tdist, ndist);
|
||
const bool dist_cont = dist.contabilizzata();
|
||
if (dist.items() > 0)
|
||
{
|
||
int rows = 0;
|
||
for (int e = 0; e < dist.items(); e++)
|
||
{
|
||
const TEffetto& eff = dist[e];
|
||
const TBill clifo(0, 0, eff.get_long(EFF_CODCF), eff.get_char(EFF_TIPOCF));
|
||
|
||
if (e==0)
|
||
set(F_TIPOPAG, eff.get_int(EFF_TIPOPAG));
|
||
for (int r = 1; r <= eff.rows_r(); r++)
|
||
{
|
||
const TRectype& reff = eff.row_r(r);
|
||
const int anno = reff.get_int(REFF_ANNO);
|
||
const TString16 part = reff.get(REFF_NUMPART);
|
||
const int nriga = reff.get_int(REFF_NRIGA);
|
||
const int nrata = reff.get_int(REFF_NRATA);
|
||
TPartita game(clifo, anno, part);
|
||
if (game.esiste(nriga, nrata))
|
||
{
|
||
TRiga_scadenze& rs = game.rata(nriga, nrata);
|
||
bool partially_unassigned;
|
||
TSheet_field& sheet = sfield(F_SHEET);
|
||
TToken_string& row = sheet.row(rows++);
|
||
if (fill_row(rs, row, partially_unassigned, dist_cont, clear_all))
|
||
{
|
||
|
||
row.add(eff.get(EFF_CUP), sheet.cid2index(F_CUP));
|
||
row.add(eff.get(EFF_CIG), sheet.cid2index(F_CIG));
|
||
row.add(eff.get(EFF_CODABI), sheet.cid2index(F_ABIAPP));
|
||
row.add(eff.get(EFF_CODCAB), sheet.cid2index(F_CABAPP));
|
||
row.add(eff.get(EFF_IBAN), sheet.cid2index(F_IBANAPP));
|
||
sheet.check_row(r - 1);
|
||
if (partially_unassigned)
|
||
sheet.disable_cell(r - 1, 1); // Non e' possibile mettere saldo
|
||
if (dist_cont)
|
||
sheet.disable_cell(r - 1, -1); // Non e' possibile modificare nulla
|
||
}
|
||
}
|
||
else
|
||
{
|
||
TString msg;
|
||
msg << "La riga " << (e+1) << " della distinta " << ndist
|
||
<< " si riferisce ad una rata o partita non valida:\n"
|
||
<< clifo.tipo() << ' ' << clifo.codclifo() << ' ' << anno << ' '
|
||
<< part << " Riga " << nriga << " Rata " << nrata << "\n"
|
||
<< "Si desidera eliminare l'effetto?";
|
||
if (yesno_box(msg))
|
||
{
|
||
TLocalisamfile righe(LF_REFFETTI);
|
||
righe.curr() = reff;
|
||
if (righe.remove() != NOERR)
|
||
error_box("Errore di cancellazione riga effetto: %d", righe.status());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if (get_bool(F_SORT))
|
||
sort_sheet();
|
||
|
||
sheet.force_update();
|
||
update_total();
|
||
_spork = FALSE;
|
||
|
||
const bool full = sheet.items() > 0;
|
||
if (full)
|
||
{
|
||
disable(-3);
|
||
disable(-4);
|
||
}
|
||
enable(-5, full && !dist_cont);
|
||
show(F_UNCONTABIL, dist_cont);
|
||
|
||
return full;
|
||
}
|
||
|
||
TRectype& TPE_mask::new_row_effetto(TDistinta& dist, char tipocf, long codcf, const TString & cup, const TString & cig,
|
||
const TDate & datapag, int& rigadist, int& rigaeff ) const
|
||
{
|
||
TString16 codice; codice << tipocf << '|' << codcf;
|
||
const bool ragg = !cache().get(LF_CFVEN, codice, CFV_RAGGEFF).blank();
|
||
|
||
TEffetto* neweff = NULL;
|
||
if (ragg)
|
||
{
|
||
for (int i = 0; i < dist.items(); i++)
|
||
{
|
||
TEffetto& eff = dist[i];
|
||
if (eff.get_char(EFF_TIPOCF) == tipocf && eff.get_long(EFF_CODCF) == codcf && datapag == eff.get_date(EFF_DATASCAD))
|
||
{
|
||
bool found = true;
|
||
|
||
if (main_app().has_module(CUAUT))
|
||
{
|
||
const TString & eff_cup = eff.get(EFF_CUP);
|
||
|
||
found = (cup == eff_cup) && (cig == eff.get(EFF_CIG));
|
||
}
|
||
if (found)
|
||
{
|
||
neweff = &eff;
|
||
rigadist = i+1;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (neweff == NULL)
|
||
{
|
||
neweff = new TEffetto;
|
||
dist.righe().add(neweff);
|
||
rigadist = dist.items();
|
||
neweff->put(EFF_TIPOCF, tipocf);
|
||
neweff->put(EFF_CODCF, codcf);
|
||
neweff->put(EFF_CODVAL, get(F_CODVAL));
|
||
neweff->put(EFF_CAMBIO, get(F_CAMBIO));
|
||
neweff->put(EFF_DATACAMBIO, get(F_DATACAMBIO));
|
||
neweff->put(EFF_CUP, cup);
|
||
neweff->put(EFF_CIG, cig);
|
||
}
|
||
rigaeff = neweff->rows_r()+1;
|
||
return neweff->row_r(rigaeff, TRUE);
|
||
}
|
||
|
||
bool TPE_mask::check_bank(TEffetto& effetto, TLog_report& log) const
|
||
{
|
||
const int tipopag = effetto.get_int(EFF_TIPOPAG);
|
||
const int tipocf = effetto.get_char(EFF_TIPOCF);
|
||
|
||
// Controllo solo ri.ba. clienti e bonifici fornitori
|
||
TString8 abi = effetto.get(EFF_CODABI);
|
||
TString8 cab = effetto.get(EFF_CODCAB);
|
||
TString80 iban = effetto.get(EFF_IBAN);
|
||
|
||
TToken_string key(8);
|
||
key = effetto.get(EFF_TIPOCF);
|
||
key.add(effetto.get(EFF_CODCF));
|
||
const TRectype& clifo = cache().get(LF_CLIFO, key);
|
||
|
||
if (real::is_null(abi) || real::is_null(cab))
|
||
{
|
||
abi = clifo.get(CLI_CODABI);
|
||
cab = clifo.get(CLI_CODCAB);
|
||
}
|
||
if (iban.blank())
|
||
iban = clifo.get(CLI_IBAN);
|
||
if (iban.starts_with("IT") && iban.len() > 15)
|
||
{
|
||
abi = iban.mid( 5, 5);
|
||
cab = iban.mid(10, 5);
|
||
}
|
||
|
||
effetto.put(EFF_CODABI, abi);
|
||
effetto.put(EFF_CODCAB, cab);
|
||
effetto.put(EFF_IBAN, iban);
|
||
|
||
if ((tipocf == 'C' || tipopag != 9) && (real::is_null(abi) || real::is_null(cab)))
|
||
{
|
||
TString msg;
|
||
msg.format(FR("Impossibile determinare ABI/CAB del %s sull'effetto %ld"),
|
||
(const char*)key, effetto.get_long(EFF_NPROGTR));
|
||
log.log(2, msg);
|
||
return false;
|
||
}
|
||
|
||
if ((tipocf == 'F' && tipopag == 9) && iban.blank())
|
||
{
|
||
TString msg;
|
||
msg.format(FR("Impossibile determinare IBAN del %s sull'effetto %ld"),
|
||
(const char*)key, effetto.get_long(EFF_NPROGTR));
|
||
log.log(2, msg);
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
void TPE_mask::save_rate()
|
||
{
|
||
TLog_report log(TR("Generazione effetti"));
|
||
|
||
const char tipodist = get(F_TIPODIST)[0];
|
||
long numdist = get_long(F_DIST);
|
||
if (_is_new)
|
||
{
|
||
TLocalisamfile f(LF_EFFETTI); f.setkey(4);
|
||
while (true)
|
||
{
|
||
f.put(EFF_TIPODIST, tipodist);
|
||
f.put(EFF_NDIST, numdist);
|
||
f.put(EFF_NRIGADIST, 1);
|
||
if (f.read() != NOERR)
|
||
break;
|
||
const long nd = get_free_num();
|
||
TString msg; msg.format(FR("La distinta %ld <20> gi<67> presente: verr<72> rinumerata in %ld"), numdist, nd);
|
||
log.log(1, msg);
|
||
numdist = nd;
|
||
}
|
||
_is_new = FALSE;
|
||
}
|
||
|
||
TDistinta distinta(tipodist, numdist, _lock);
|
||
|
||
const TString& codval = get(F_CODVAL);
|
||
const real cambio = get(F_CAMBIO);
|
||
const bool eurocambio = get_bool(F_EURO);
|
||
const int tipopag = get_int(F_TIPOPAG);
|
||
|
||
bool zeroes = false; // Esistono righe effetto da cancellare
|
||
const bool attivo = get(F_TIPOCF) == "C";
|
||
|
||
TSheet_field& sheet = sfield(F_SHEET);
|
||
FOR_EACH_SHEET_ROW(sheet, r, row)
|
||
{
|
||
real imp = row->get(sheet.cid2index(F_IMPORTO));
|
||
real impval;
|
||
if (codval.full() && !imp.is_zero())
|
||
{
|
||
impval = imp;
|
||
TCurrency c(impval, codval, cambio, eurocambio ? _exchange_contro : _exchange_base);
|
||
c.change_to_firm_val();
|
||
imp = c.get_num();
|
||
}
|
||
char accsal = row->get_char(sheet.cid2index(F_ACCSAL));
|
||
int rigadist = row->get_int(sheet.cid2index(F_RIGADIST));
|
||
int rigaeff = row->get_int(sheet.cid2index(F_RIGAEFF));
|
||
if (rigaeff > 0 || accsal == 'S' || imp > ZERO)
|
||
{
|
||
TToken_string key;
|
||
key.add(get(F_TIPOCF));
|
||
key.add("0|0");
|
||
key.add(row->get(sheet.cid2index(F_CODCF)));
|
||
key.add(row->get(sheet.cid2index(F_ANNO)));
|
||
key.add(row->get(sheet.cid2index(F_PARTITA)));
|
||
key.add(row->get(sheet.cid2index(F_RIGA)));
|
||
// Trova partita
|
||
const TRectype& part = cache().get(LF_PARTITE, key);
|
||
// Trova rata
|
||
key.add(row->get(sheet.cid2index(F_RATA)));
|
||
const TRectype& scad = cache().get(LF_SCADENZE, key);
|
||
// eff.put(EFF_DATASCAD, scad.get(SCAD_DATASCAD));
|
||
TDate datapag(row->get(sheet.cid2index(F_DATAPAG)));
|
||
|
||
if (!datapag.ok())
|
||
datapag = attivo ? scad.get(SCAD_DATASCAD) : get(F_DATADIST);
|
||
const TString cup = row->get(sheet.cid2index(F_CUP));
|
||
const TString cig = row->get(sheet.cid2index(F_CIG));
|
||
if (rigaeff <= 0)
|
||
{
|
||
const char tipocf = get(F_TIPOCF)[0];
|
||
const long codcf = row->get_long(sheet.cid2index(F_CODCF));
|
||
|
||
TRectype& reff = new_row_effetto(distinta, tipocf, codcf, cup, cig, datapag, rigadist, rigaeff);
|
||
reff.put(REFF_ANNO, row->get(sheet.cid2index(F_ANNO)));
|
||
reff.put(REFF_NUMPART, row->get(sheet.cid2index(F_PARTITA)));
|
||
reff.put(REFF_NRIGA, row->get(sheet.cid2index(F_RIGA)));
|
||
reff.put(REFF_NRATA, row->get(sheet.cid2index(F_RATA)));
|
||
|
||
reff.put(REFF_NFATT, part.get(PART_NUMDOC));
|
||
reff.put(REFF_DATAFATT, part.get(PART_DATADOC));
|
||
reff.put(REFF_IMPFATT, part.get(PART_IMPORTO));
|
||
|
||
TEffetto& eff = distinta[rigadist-1];
|
||
|
||
eff.put(EFF_DSCVAL, row->get(sheet.cid2index(F_VALBEN)));
|
||
eff.put(EFF_TIPOPAG, tipopag);
|
||
eff.put(EFF_CODABI, row->get(sheet.cid2index(F_ABIAPP)));
|
||
eff.put(EFF_CODCAB, row->get(sheet.cid2index(F_ABIAPP)));
|
||
eff.put(EFF_IBAN, row->get(sheet.cid2index(F_IBANAPP)));
|
||
}
|
||
|
||
TEffetto& eff = distinta[rigadist-1];
|
||
|
||
eff.put(EFF_DATASCAD, datapag);
|
||
eff.put(EFF_CUP, cup);
|
||
eff.put(EFF_CIG, cig);
|
||
check_bank(eff, log); // Cerca di sistemare ABI/CAB/IBAN
|
||
|
||
|
||
TRectype& reff = eff.row_r(rigaeff);
|
||
const real oldimp = reff.get(REFF_IMPORTO);
|
||
const real oldimpval = reff.get(REFF_IMPORTOVAL);
|
||
reff.put(REFF_IMPORTO, imp);
|
||
reff.put(REFF_IMPORTOVAL, impval);
|
||
reff.put(REFF_ACCSAL, accsal);
|
||
if (accsal != 'S' && imp.is_zero())
|
||
{
|
||
reff.put(REFF_ACCSAL, 'Z'); // Segna la riga come NULLA
|
||
zeroes = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
// Ricalcola totali righe ed elimina le righe NULLE
|
||
TLocalisamfile f(LF_EFFETTI); f.setkey(1);
|
||
for (int rd = distinta.items()-1; rd >= 0; rd--)
|
||
{
|
||
TEffetto& eff = distinta[rd];
|
||
real totimp, totimpval;
|
||
for (int i = eff.rows_r(); i > 0; i--)
|
||
{
|
||
const TRectype& reff = eff.row_r(i);
|
||
if (reff.get_char(REFF_ACCSAL) == 'Z')
|
||
{
|
||
eff.destroy_row_r(i, true);
|
||
}
|
||
else
|
||
{
|
||
totimp += reff.get_real(EFF_IMPORTO);
|
||
totimpval += reff.get_real(EFF_IMPORTOVAL);
|
||
}
|
||
}
|
||
if (eff.rows_r() == 0)
|
||
{
|
||
int err = eff.read(f, eff, _lock);
|
||
if (err == NOERR)
|
||
err = eff.remove(f);
|
||
if (err == NOERR)
|
||
distinta.righe().destroy(rd, true);
|
||
else
|
||
{
|
||
TString msg;
|
||
msg.format(FR("Errore %d durante la cancellazione della riga %d"), err, rd+1);
|
||
log.log(2, msg);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
eff.put(EFF_TIPOPAG, tipopag);
|
||
eff.put(EFF_IMPORTO, totimp);
|
||
eff.put(EFF_IMPORTOVAL, totimpval);
|
||
eff.put(EFF_CODVAL, codval);
|
||
eff.put(EFF_CAMBIO, cambio);
|
||
eff.put(EFF_CONTROEURO, eurocambio);
|
||
eff.put(EFF_DATACAMBIO, get(F_DATACAMBIO));
|
||
eff.put(EFF_SPESE, get(F_SPESE));
|
||
}
|
||
}
|
||
|
||
TToken_string dati_dist;
|
||
dati_dist.add(tipodist);
|
||
dati_dist.add(numdist);
|
||
dati_dist.add(get(F_DATADIST));
|
||
dati_dist.add(get(F_ABI));
|
||
dati_dist.add(get(F_CAB));
|
||
dati_dist.add(get(F_PROG));
|
||
distinta.write(false, &dati_dist);
|
||
|
||
if (log.recordset()->items() > 0)
|
||
log.preview();
|
||
}
|
||
|
||
void TPE_mask::print()
|
||
{
|
||
TString16 cmd;
|
||
cmd << "ef0 -4 " << get(F_TIPODIST) << ' ' << get(F_DIST);
|
||
TExternal_app app(cmd);
|
||
app.run();
|
||
}
|
||
|
||
bool TPE_mask::on_sheet_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
TMask& m = o.mask();
|
||
switch (o.dlg())
|
||
{
|
||
case F_IMPORTO:
|
||
if (e == fe_modify)
|
||
{
|
||
TMask_field& as = m.field(F_ACCSAL);
|
||
if (as.enabled())
|
||
{
|
||
const real imp = m.get(F_IMPORTO);
|
||
const real res = m.get(F_RESIDUO);
|
||
as.set(imp >= res ? "S" : "A");
|
||
}
|
||
}
|
||
break;
|
||
case F_PAGA:
|
||
if (e == fe_button)
|
||
{
|
||
TMask& m = o.mask();
|
||
if (m.get_real(F_IMPORTO).is_zero())
|
||
{
|
||
m.set(F_IMPORTO, m.get(F_RESIDUO));
|
||
TMask_field& as = m.field(F_ACCSAL);
|
||
if (as.enabled())
|
||
as.set("S");
|
||
}
|
||
else
|
||
{
|
||
m.reset(F_IMPORTO);
|
||
m.reset(F_ACCSAL);
|
||
}
|
||
_spork = true;
|
||
}
|
||
break;
|
||
case F_SHEET:
|
||
switch(e)
|
||
{
|
||
case se_query_add:
|
||
{
|
||
TOperable_field& ronaldo = (TOperable_field&)field(F_AGGIORNA);
|
||
if (ronaldo.active())
|
||
on_field_event(ronaldo, fe_button, 0);
|
||
}
|
||
return false;
|
||
case se_notify_modify:
|
||
_spork = true;
|
||
update_total();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
long TPE_mask::get_free_num() const
|
||
{
|
||
TLocalisamfile eff(LF_EFFETTI); eff.setkey(4);
|
||
TRectype& curr = eff.curr();
|
||
const TString& tipodist = get(F_TIPODIST);
|
||
curr.put(EFF_TIPODIST, tipodist);
|
||
curr.put(EFF_NDIST, 99999L);
|
||
const int err = eff.read(_isgreat);
|
||
long n = 1L;
|
||
if (err != _isemptyfile)
|
||
{
|
||
if (err == NOERR)
|
||
eff.prev();
|
||
if (curr.get(EFF_TIPODIST) == tipodist)
|
||
n += curr.get_long(EFF_NDIST);
|
||
}
|
||
return n;
|
||
}
|
||
|
||
bool TPE_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case DLG_NEWREC:
|
||
{
|
||
const long n = get_free_num();
|
||
set(F_DIST, n);
|
||
disable(F_DIST);
|
||
disable(DLG_NEWREC);
|
||
set_focus_field(F_ABI);
|
||
_is_new = TRUE;
|
||
_spork = FALSE;
|
||
}
|
||
break;
|
||
case F_DIST:
|
||
if (e == fe_modify)
|
||
{
|
||
TEdit_field& ef = (TEdit_field&)o;
|
||
bool ok = ef.check();
|
||
if (ok)
|
||
{
|
||
const TCursor& cur = *ef.browse()->cursor();
|
||
ok = cur.ok();
|
||
if (ok)
|
||
{
|
||
const TRectype& rec = cur.curr();
|
||
if (rec.get_bool(EFF_EFFCONT))
|
||
{
|
||
warning_box(FR("La distinta %s <20> gi<67> stata contabilizzata,\n"
|
||
"per cui non <20> possibile modificarla"), (const char*)ef.get());
|
||
show(F_UNCONTABIL);
|
||
}
|
||
ok = fill_distinta(true);
|
||
}
|
||
}
|
||
_is_new = !ok; // Memorizza se <20> una distinta nuova
|
||
enable(-3, _is_new); // Abilita tipo, cliente, valuta, ecc., solo se nuova
|
||
enable(F_TIPOPAG, _is_new);
|
||
disable(F_AGGIORNA);
|
||
}
|
||
break;
|
||
case F_CODVAL:
|
||
if (e == fe_modify && !o.empty())
|
||
{
|
||
TTable cam("CAM");
|
||
cam.put("CODTAB", o.get());
|
||
int err = cam.read(_isgteq);
|
||
if (err != NOERR || cam.get("CODTAB").compare(o.get(), 3) != 0)
|
||
{
|
||
const TRectype& val = cache().get("%VAL", o.get());
|
||
TString16 str = val.get("S4");
|
||
if (str.blank()) str = val.get("R10");
|
||
set(F_CAMBIO, str);
|
||
}
|
||
}
|
||
break;
|
||
case F_AGGIORNA:
|
||
if (e == fe_button)
|
||
{
|
||
TEdit_field& numdist = efield(F_DIST);
|
||
if (!numdist.empty())
|
||
{
|
||
bool go = TRUE;
|
||
if (!numdist.enabled() && sfield(F_SHEET).items() > 0)
|
||
{
|
||
go = check_fields();
|
||
if (go && _spork && yesno_box(TR("Si desidera registrare la distinta?")))
|
||
save_rate();
|
||
}
|
||
if (go)
|
||
go = fill_rate();
|
||
}
|
||
else
|
||
return error_box(TR("E' necessario specificare un numero di distinta"));
|
||
}
|
||
break;
|
||
case F_CONTABILI:
|
||
if (e == fe_button)
|
||
{
|
||
const char tipodist = get(F_TIPODIST)[0];
|
||
const long numdist = get_long(F_DIST);
|
||
TString16 cmd;
|
||
cmd << "ef0 -7 " << tipodist << ' ' << numdist;
|
||
TExternal_app app(cmd);
|
||
if (app.run() == 0)
|
||
{
|
||
long numreg = 0; // Numero di registrazione contabile
|
||
TLocalisamfile eff(LF_EFFETTI);
|
||
eff.setkey(4);
|
||
eff.put(EFF_TIPODIST, tipodist);
|
||
eff.put(EFF_NDIST,numdist);
|
||
eff.put(EFF_NRIGADIST, 1); // Cerco prima riga distinta
|
||
if (eff.read() == NOERR)
|
||
numreg = eff.get_long(EFF_NUMREG);
|
||
if (numreg > 0)
|
||
message_box("La distinta %ld e' stata contabilizzata col movimento %ld",
|
||
numdist, numreg);
|
||
else
|
||
warning_box("La distinta %ld non e' stata contabilizzata", numdist);
|
||
}
|
||
stop_run(K_ESC);
|
||
}
|
||
break;
|
||
case F_UNCONTABIL:
|
||
if (e == fe_button)
|
||
{
|
||
const char tipodist = get(F_TIPODIST)[0];
|
||
const long numdist = get_long(F_DIST);
|
||
if (tipodist > ' ' && numdist > 0)
|
||
{
|
||
TRelation rel(LF_EFFETTI);
|
||
TRectype& rec = rel.curr();
|
||
rec.put(EFF_TIPODIST, tipodist);
|
||
rec.put(EFF_NDIST,numdist);
|
||
TCursor cur(&rel, "", 4, &rec, &rec);
|
||
const TRecnotype items = cur.items();
|
||
cur.freeze();
|
||
|
||
TAssoc_array movs;
|
||
for (cur = 0; cur.pos() < items; ++cur)
|
||
{
|
||
movs.add(rec.get(EFF_NUMREG));
|
||
rec.zero(EFF_EFFCONT);
|
||
rec.zero(EFF_NUMREG);
|
||
rel.rewrite();
|
||
}
|
||
|
||
if (movs.items() > 0)
|
||
{
|
||
TString msg;
|
||
msg = "E' necessario cancellare i seguenti movimenti contabili:\n";
|
||
FOR_EACH_ASSOC_OBJECT(movs, hash, key, obj)
|
||
msg << key << ' ';
|
||
warning_box(msg);
|
||
}
|
||
stop_run(K_ESC);
|
||
}
|
||
}
|
||
break;
|
||
case DLG_DELREC:
|
||
if (e == fe_button && yesno_box("Confermare l'eliminazione della distinta %ld",
|
||
get_long(F_DIST)))
|
||
{
|
||
TSheet_field& sheet = sfield(F_SHEET);
|
||
FOR_EACH_SHEET_ROW(sheet, r, row)
|
||
{
|
||
row->add(" ", 0);
|
||
row->add("A", 1);
|
||
}
|
||
save_rate();
|
||
}
|
||
break;
|
||
case DLG_SAVEREC:
|
||
if (e == fe_button)
|
||
{
|
||
TEdit_field& cab = efield(F_CAB);
|
||
if (!cab.empty())
|
||
{
|
||
if (check_fields())
|
||
{
|
||
save_rate();
|
||
fill_distinta(true);
|
||
disable(F_TIPOPAG);
|
||
}
|
||
}
|
||
else
|
||
return error_box("E' necessario specificare una banca di presentazione");
|
||
}
|
||
break;
|
||
case DLG_PRINT:
|
||
if (e == fe_button)
|
||
{
|
||
print();
|
||
return FALSE;
|
||
}
|
||
break;
|
||
case F_SORT:
|
||
if (e == fe_modify)
|
||
{
|
||
TSheet_field& s = sfield(F_SHEET);
|
||
if (s.items() > 0)
|
||
{
|
||
sort_sheet();
|
||
s.force_update();
|
||
}
|
||
}
|
||
break;
|
||
case F_CLIFO:
|
||
case F_DA_DATA:
|
||
case F_A_DATA:
|
||
if (e == fe_modify)
|
||
{
|
||
if (get(F_CLIFO).not_empty() || get(F_DA_DATA).not_empty() || get(F_A_DATA).not_empty())
|
||
enable(F_AGGIORNA);
|
||
}
|
||
break;
|
||
case F_DATAPAG:
|
||
if (e == fe_close)
|
||
{
|
||
TDate datapag(o.get());
|
||
const bool attivo = get(F_TIPOCF) == "C";
|
||
|
||
if (!datapag.ok())
|
||
datapag = attivo ? o.mask().get_date(F_DATA) : get_date(F_DATADIST);
|
||
return datapag >= get_date(F_DATADIST) || yesno_box("Riga n. %d. Data pagamento precedente alla data distinta.\n Si desidera continuare", sfield(F_SHEET).selected() + 1);
|
||
}
|
||
case F_SHEET:
|
||
return on_sheet_event(o, e, jolly);
|
||
default:
|
||
if (jolly > 0)
|
||
return on_sheet_event(o, e, jolly);
|
||
break;
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
TPE_mask::TPE_mask() : TAutomask("ef0a00a")
|
||
{
|
||
_rel = new TRelation(LF_REFFETTI);
|
||
_rel->add(LF_EFFETTI, "NPROGTR==NPROGTR");
|
||
}
|
||
|
||
TPE_mask::~TPE_mask()
|
||
{ delete _rel; }
|
||
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Main Program
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TPagamento_effetti : public TSkeleton_application
|
||
{
|
||
TPE_mask* _mask;
|
||
|
||
public:
|
||
virtual bool create();
|
||
virtual void main_loop();
|
||
virtual void print();
|
||
virtual bool firm_change_enabled() const { return false; }
|
||
};
|
||
|
||
void TPagamento_effetti::main_loop()
|
||
{
|
||
open_files(LF_TABCOM, LF_TAB, LF_CLIFO, LF_CFVEN,
|
||
LF_PARTITE, LF_SCADENZE, LF_PAGSCA,
|
||
LF_EFFETTI, LF_REFFETTI, LF_CESS, 0);
|
||
enable_menu_item(M_FILE_PRINT);
|
||
_mask = new TPE_mask;
|
||
do
|
||
{
|
||
_mask->reset();
|
||
_mask->enable(-3);
|
||
_mask->enable(F_TIPOPAG);
|
||
_mask->enable(-4);
|
||
_mask->disable(-5);
|
||
_mask->disable(DLG_SAVEREC);
|
||
_mask->hide(F_UNCONTABIL);
|
||
_mask->sfield(F_SHEET).destroy();
|
||
}
|
||
while (_mask->run() != K_QUIT);
|
||
|
||
delete _mask;
|
||
_mask = NULL;
|
||
}
|
||
|
||
void TPagamento_effetti::print()
|
||
{
|
||
if (_mask)
|
||
_mask->print();
|
||
}
|
||
|
||
|
||
bool TPagamento_effetti::create()
|
||
{
|
||
if (!has_module(EPAUT))
|
||
return error_box(TR("Modulo non autorizzato"));
|
||
|
||
return TSkeleton_application::create();
|
||
}
|
||
|
||
|
||
int ef0A00(int argc, char* argv[])
|
||
{
|
||
int n = 0;
|
||
TPagamento_effetti pe;
|
||
pe.run(argc, argv, TR("Disposizioni incassi/pagamenti"));
|
||
return 0;
|
||
}
|