ba19f86e6e
git-svn-id: svn://10.65.10.50/trunk@2273 c028cbd2-c16b-5b4b-a496-9718f37d4682
884 lines
24 KiB
C++
Executable File
884 lines
24 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <config.h>
|
|
#include <form.h>
|
|
#include <printer.h>
|
|
#include <tabutil.h>
|
|
#include <urldefid.h>
|
|
|
|
#include "../cg/saldacon.h"
|
|
#include "sc2.h"
|
|
#include "sc2101.h"
|
|
#include "sc2102.h"
|
|
|
|
#include "sc2100a.h"
|
|
#include "sc21pec.h"
|
|
|
|
#include <clifo.h>
|
|
#include <causali.h>
|
|
#include <pagsca.h>
|
|
#include <scadenze.h>
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TEC_form
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TEC_form : public TForm
|
|
{
|
|
static TEC_form* _form;
|
|
|
|
TCursor* _cursore;
|
|
TTotalizer _totali;
|
|
TDecoder _causali; // Decodoficatore dei codici causale
|
|
|
|
TString _lingua; // Codice lingua del form
|
|
TDate _dlo, _dls, _dir; // Data limite operazione, scaduto e inizio rischio
|
|
int _giorni_rischio; // Numero giorni rischio nella maschera di selezione
|
|
bool _in_valuta; // Il form e' in valuta
|
|
int _footer_used; // Numero di righe per ogni valuta del footer
|
|
|
|
protected:
|
|
static void ec_header_handler(TPrinter& p);
|
|
static void ec_footer_handler(TPrinter& p);
|
|
|
|
public:
|
|
TTotalizer& totali() { return _totali; }
|
|
TDecoder& causali() { return _causali; }
|
|
|
|
const TDate& data_limite_operazione() const { return _dlo; }
|
|
const TDate& data_limite_scaduto() const { return _dls; }
|
|
int giorni_rischio() const { return _giorni_rischio; }
|
|
const TDate& data_inizio_rischio() const { return _dir; }
|
|
|
|
const TString& lingua() const { return _lingua; }
|
|
bool in_valuta() const { return _in_valuta; }
|
|
const TString& describe(short id, char sez = 'B') const;
|
|
|
|
bool print_game(const TPartita& game);
|
|
|
|
TEC_form(const TEC_mask& m);
|
|
virtual ~TEC_form();
|
|
};
|
|
|
|
TEC_form* TEC_form::_form = NULL;
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TEC_row
|
|
// Rappresenta una singola riga di stampa
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TEC_row : public TSortable
|
|
{
|
|
TDate _data; // Data scadenza o pagamento
|
|
int _riga; // Riga della fattura
|
|
int _rata; // Numero rata o progrssivo
|
|
|
|
TString _causale; // Codice causale
|
|
TString _descrizione; // Sua descrizione
|
|
|
|
TDate _data_doc; // Data del documento
|
|
TString _num_doc; // Numero documento
|
|
long _num_prot; // Protocollo IVA
|
|
TImporto _importo; // Importo in valuta
|
|
TImporto _importo_lire; // Importo in lire
|
|
real _scaduto; // Importo scaduto
|
|
real _esposto; // Importo esposto
|
|
bool _salvo_buon_fine; // Importo esposto salvo buon fine
|
|
real _totale; // Totale documento
|
|
TValuta _valuta; // Codice valuta, data cambio e cambio
|
|
|
|
protected: // TSortable
|
|
virtual int compare(const TSortable& s) const;
|
|
void set_imp(TForm_item& fi, const real& imp, bool valuta) const;
|
|
|
|
public:
|
|
int riga() const { return _riga; }
|
|
int rata() const { return _rata; }
|
|
|
|
void reset_causale() { _causale.cut(0); _descrizione.cut(0); }
|
|
void descrizione(const char* s) { _descrizione = s; }
|
|
void importo(const TImporto& i) { _importo = i; }
|
|
void scaduto(const real& s) { _scaduto = s; }
|
|
void esposto(const real& e) { _esposto = e; }
|
|
void salvo_buon_fine(bool sbf) { _salvo_buon_fine = sbf; }
|
|
|
|
const TDate& data() const { return _data; }
|
|
const TImporto& importo() const { return _importo; }
|
|
real scaduto() const { return _scaduto; }
|
|
real esposto() const { return _esposto; }
|
|
const TValuta& valuta() const { return _valuta; }
|
|
bool in_valuta() const { return _valuta.in_valuta(); }
|
|
|
|
void print_on(TPrint_section& body);
|
|
|
|
TEC_row(const TRiga_partite& row, const TDate& data, const TImporto& imp, int rata);
|
|
TEC_row(const char* desc, const TImporto& imp);
|
|
virtual ~TEC_row() {}
|
|
};
|
|
|
|
TEC_row::TEC_row(const TRiga_partite& row, const TDate& data, const TImporto& imp, int rata)
|
|
: _num_prot(0), _salvo_buon_fine(FALSE)
|
|
{
|
|
_riga = row.get_int(PART_NRIGA);
|
|
_rata = rata;
|
|
|
|
_data = data;
|
|
_causale = row.get(PART_CODCAUS);
|
|
_data_doc = row.get(PART_DATADOC);
|
|
_num_prot = row.get_long(PART_PROTIVA);
|
|
_importo = imp; _importo.normalize();
|
|
_totale = row.get_real(PART_IMPTOTPAG);
|
|
|
|
_valuta.get(row);
|
|
}
|
|
|
|
TEC_row::TEC_row(const char* desc, const TImporto& imp)
|
|
: _riga(9999), _rata(9999), _num_prot(0), _salvo_buon_fine(FALSE)
|
|
{
|
|
_descrizione = desc;
|
|
_importo = imp; _importo.normalize();
|
|
}
|
|
|
|
// Le righe dell'estratto conto sono ordinate per data, riga partita, numero rata o
|
|
// posizione iniziale nell'array (in caso di uguaglianza di tutto il resto)
|
|
int TEC_row::compare(const TSortable& s) const
|
|
{
|
|
const TEC_row& r = (const TEC_row&)s;
|
|
int c = 0;
|
|
if (_data == r._data)
|
|
{
|
|
c = _riga - r._riga;
|
|
if (c == 0)
|
|
c = _rata - r._rata;
|
|
}
|
|
else
|
|
c = _data > r._data ? +1 : -1;
|
|
return c;
|
|
}
|
|
|
|
|
|
void TEC_row::set_imp(TForm_item& fi, const real& imp, bool valuta) const
|
|
{
|
|
TString old_picture;
|
|
if (valuta)
|
|
{
|
|
old_picture = fi.picture();
|
|
|
|
TString new_picture(20);
|
|
new_picture = old_picture;
|
|
if (old_picture.find(',') > 0)
|
|
new_picture << ".###";
|
|
else
|
|
new_picture << ",###";
|
|
|
|
fi.set_picture(new_picture);
|
|
}
|
|
|
|
fi.set(imp.string());
|
|
|
|
if (valuta)
|
|
{
|
|
fi.set_picture(old_picture);
|
|
}
|
|
}
|
|
|
|
void TEC_row::print_on(TPrint_section& body)
|
|
{
|
|
TEC_form& form = (TEC_form&)body.form();
|
|
const bool valuta = form.in_valuta() && in_valuta();
|
|
|
|
TForm_item& causale = body.find_field(PEC_CODCAUS);
|
|
causale.set(_causale);
|
|
if (_causale.not_empty() && _descrizione.empty())
|
|
{
|
|
TDecoder& causali = form.causali();
|
|
_descrizione = causali.decode(_causale);
|
|
}
|
|
|
|
TForm_item& descr = body.find_field(PEC_DESCR1);
|
|
descr.set(_descrizione);
|
|
|
|
TForm_item& datadoc = body.find_field(PEC_DATADOC);
|
|
datadoc.set(_data_doc.string());
|
|
|
|
TForm_item& numdoc = body.find_field(PEC_NUMDOC);
|
|
numdoc.set(_num_doc);
|
|
|
|
TForm_item& numprot = body.find_field(PEC_PROTIVA);
|
|
TString16 protiva; protiva << _num_prot;
|
|
numprot.set(protiva);
|
|
|
|
TForm_item& datapag = body.find_field(PEC_DATAPAG);
|
|
datapag.set(_data.string());
|
|
|
|
const real& imp = _importo.valore();
|
|
TForm_item& dare = body.find_field(PEC_DARE);
|
|
TForm_item& avere = body.find_field(PEC_AVERE);
|
|
|
|
if (_importo.sezione() == 'D')
|
|
{
|
|
set_imp(dare, imp, valuta);
|
|
avere.set("");
|
|
}
|
|
else
|
|
{
|
|
set_imp(avere, imp, valuta);
|
|
dare.set("");
|
|
}
|
|
|
|
TForm_item& scaduto = body.find_field(PEC_SCADUTO);
|
|
set_imp(scaduto, _scaduto, valuta);
|
|
|
|
TForm_item& esposto = body.find_field(PEC_ESPOSTO);
|
|
set_imp(esposto, _esposto, valuta);
|
|
|
|
TForm_item& sbf = body.find_field(PEC_SBF);
|
|
sbf.set(_salvo_buon_fine ? "*" : " ");
|
|
|
|
TForm_item& cambio = body.find_field(PEC_CAMBIO);
|
|
cambio.set(_valuta.cambio().string());
|
|
|
|
TForm_item& datacambio = body.find_field(PEC_DATACAM);
|
|
datacambio.set(_valuta.data().string());
|
|
|
|
body.update();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TEC_array
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TEC_array : public TArray
|
|
{
|
|
TArray _scaduto; // Array di importi scaduti
|
|
|
|
const TEC_form* _form; // Form che contiene l'array di righe
|
|
|
|
protected:
|
|
TEC_row& new_row(const TRiga_partite& row, const TDate& data, const TImporto& imp, int rata = 0);
|
|
void add_row(const TRiga_partite& row);
|
|
|
|
const TEC_form& form() const { return *_form; }
|
|
real calcola_scaduto(const TRiga_scadenze& rata, bool valuta);
|
|
|
|
TImporto* importo_riga_scaduto_ptr(int n) const { return (TImporto*)_scaduto.objptr(n); }
|
|
TImporto& importo_riga_scaduto(int n);
|
|
|
|
TImporto importo(const TPartita& game, const TRectype& pag, bool valuta) const;
|
|
|
|
public:
|
|
TEC_row& row(int r) const { return (TEC_row&)operator[](r); }
|
|
|
|
TEC_array(const TPartita& game, const TEC_form* f);
|
|
virtual ~TEC_array() {}
|
|
};
|
|
|
|
// Calcola l'importo su di una riga di pagamento
|
|
TImporto TEC_array::importo(const TPartita& game, const TRectype& pag, bool valuta) const
|
|
{
|
|
const int nriga = pag.get_int(PAGSCA_NRIGA);
|
|
const TRiga_partite& fat = game.riga(nriga);
|
|
const bool fat_val = fat.in_valuta();
|
|
|
|
const int nrigp = pag.get_int(PAGSCA_NRIGP);
|
|
const TRiga_partite& sum = game.riga(nrigp);
|
|
const char sez = sum.sezione();
|
|
|
|
const char* const field = valuta && fat_val ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
|
TImporto imp(sez, pag.get_real(PAGSCA_IMPORTO));
|
|
|
|
if (!fat_val)
|
|
imp.valore() += pag.get_real(PAGSCA_RITENUTE);
|
|
|
|
if (pag.get_char(PAGSCA_ACCSAL) == 'S')
|
|
{
|
|
real abb(pag.get(PAGSCA_ABBUONI));
|
|
if (!valuta && fat_val)
|
|
{
|
|
const TValuta val(sum);
|
|
val.val2lit(abb);
|
|
abb += pag.get_real(PAGSCA_DIFFCAM);
|
|
}
|
|
imp.valore() += abb;
|
|
}
|
|
|
|
return imp;
|
|
}
|
|
|
|
// Certified 100%
|
|
TImporto& TEC_array::importo_riga_scaduto(int n)
|
|
{
|
|
CHECKD(n > 0 && n < 9999, "Riga scaduto errata ", n);
|
|
TImporto* imp = importo_riga_scaduto_ptr(n);
|
|
if (imp == NULL)
|
|
{
|
|
imp = new TImporto;
|
|
_scaduto.add(imp, n);
|
|
}
|
|
return *imp;
|
|
}
|
|
|
|
real TEC_array::calcola_scaduto(const TRiga_scadenze& rata, bool valuta)
|
|
{
|
|
const TPartita& game = rata.partita();
|
|
const char sezione = game.conto().tipo() == 'C' ? 'D' : 'A';
|
|
|
|
TImporto scaduto_rata = rata.importo(TRUE);
|
|
|
|
int riga_corrente_scaduto = 0;
|
|
|
|
const int lastp = rata.last(); // Ultimo pagamento sulla rata corrente
|
|
for (int p = rata.first(); p <= lastp; p = rata.succ(p)) // Qui bisogna andare in avanti!
|
|
{
|
|
const TRectype& pag = rata.row(p);
|
|
const int nrigp = pag.get_int(PAGSCA_NRIGP);
|
|
const TRiga_partite& sum = game.riga(nrigp);
|
|
TImporto imp = importo(game, pag, valuta);
|
|
|
|
tipo_movimento tm = sum.tipo(); // Determina tipo riga
|
|
|
|
// Normalmente gli utenti non usano il tipo pagamento insoluto, per cui devo
|
|
// riconoscere i pagamenti che in realta' sono a fronte di insoluti:
|
|
// 1) hanno tipo movimento = tm_pagamento
|
|
// 2) ho gia' incontrato un insoluto
|
|
// 3) il saldo della rata e' a zero o sommando l'importo arriva sotto zero
|
|
if (tm == tm_pagamento && riga_corrente_scaduto != 0)
|
|
{
|
|
if (scaduto_rata.is_zero())
|
|
{
|
|
tm = tm_pagamento_insoluto;
|
|
}
|
|
else
|
|
{
|
|
TImporto p(scaduto_rata);
|
|
p += imp;
|
|
p.normalize(sezione);
|
|
|
|
if (p.valore() < ZERO)
|
|
{
|
|
scaduto_rata.set('D', ZERO);
|
|
imp += p;
|
|
tm = tm_pagamento_insoluto;
|
|
}
|
|
}
|
|
}
|
|
if (tm == tm_insoluto || tm == tm_pagamento_insoluto)
|
|
{
|
|
if (tm == tm_insoluto)
|
|
riga_corrente_scaduto = nrigp;
|
|
else
|
|
CHECKD(riga_corrente_scaduto > 0, "Pagamento insoluto senza insoluto ", p);
|
|
importo_riga_scaduto(riga_corrente_scaduto) += imp;
|
|
}
|
|
else
|
|
{
|
|
scaduto_rata += imp;
|
|
}
|
|
}
|
|
|
|
scaduto_rata.normalize(sezione);
|
|
return scaduto_rata.valore();
|
|
}
|
|
|
|
TEC_row& TEC_array::new_row(const TRiga_partite& row, const TDate& data,
|
|
const TImporto& imp, int n)
|
|
{
|
|
CHECKD(n > 0, "Numero rata errato: ", n);
|
|
TEC_row* riga = new TEC_row(row, data, imp, n);
|
|
add(riga);
|
|
return *riga;
|
|
}
|
|
|
|
void TEC_array::add_row(const TRiga_partite& row)
|
|
{
|
|
const bool in_valuta = form().in_valuta() && row.in_valuta();
|
|
|
|
if (row.is_fattura())
|
|
{
|
|
for (int r = 1; r <= row.rate(); r++)
|
|
{
|
|
const TRiga_scadenze& rata = row.rata(r);
|
|
const TDate data(rata.get(SCAD_DATASCAD));
|
|
if (data <= form().data_limite_operazione())
|
|
{
|
|
TEC_row& rec = new_row(row, data, rata.importo(in_valuta), r);
|
|
if (data <= form().data_limite_scaduto())
|
|
{
|
|
const real s = calcola_scaduto(rata, in_valuta);
|
|
rec.scaduto(s);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
const TDate data(row.get(PART_DATAPAG));
|
|
if (data <= form().data_limite_operazione())
|
|
{
|
|
const TImporto imp(row.importo(in_valuta, 0x1)); // Importo pulito (senza abbuoni ecc.)
|
|
TEC_row& riga = new_row(row, data, imp, 1);
|
|
|
|
const int tipo_pag = row.get_int(PART_TIPOPAG);
|
|
if (tipo_pag >= 2 && tipo_pag <= 7) // Controlla se e' un pagamento con effetti
|
|
{
|
|
const TDate data_pag(row.get(PART_DATAPAG));
|
|
const TDate& dls = form().data_limite_scaduto();
|
|
const int gr = form().giorni_rischio();
|
|
|
|
bool sbf = FALSE;
|
|
if (gr > 0)
|
|
{
|
|
const TDate& dir = form().data_inizio_rischio();
|
|
sbf = data_pag > dir && data_pag <= dls;
|
|
riga.salvo_buon_fine(sbf); // Esposto salvo buon fine
|
|
}
|
|
|
|
bool esp = sbf;
|
|
if (!esp)
|
|
{
|
|
esp = gr > 0 ? data_pag >= dls : data_pag > dls; // Esposto normale
|
|
}
|
|
|
|
if (esp)
|
|
{
|
|
TImporto esposto(imp);
|
|
const char sezione = row.get_char(PART_TIPOCF) == 'C' ? 'D' : 'A';
|
|
esposto.normalize(sezione);
|
|
riga.esposto(esposto.valore());
|
|
}
|
|
}
|
|
|
|
const TImporto abbuoni(row.importo(in_valuta, 0x2));
|
|
if (!abbuoni.is_zero())
|
|
{
|
|
TEC_row& r = new_row(row, data, abbuoni, 2);
|
|
r.descrizione(form().describe(302));
|
|
}
|
|
|
|
const TImporto diffcam(row.importo(in_valuta, 0x4));
|
|
if (!diffcam.is_zero())
|
|
{
|
|
TEC_row& r = new_row(row, data, diffcam, 3);
|
|
r.descrizione(form().describe(303));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
TEC_array::TEC_array(const TPartita& game, const TEC_form* f)
|
|
: _form(f)
|
|
{
|
|
for (int r = game.last(); r > 0; r = game.pred(r))
|
|
add_row(game.riga(r));
|
|
|
|
const char sezione = game.conto().tipo() == 'C' ? 'D' : 'A';
|
|
for (r = items()-1; r >= 0; r--)
|
|
{
|
|
TEC_row& s = row(r);
|
|
if (s.rata() == 1)
|
|
{
|
|
TImporto* imp = importo_riga_scaduto_ptr(s.riga());
|
|
if (imp != NULL)
|
|
{
|
|
imp->normalize(sezione);
|
|
s.scaduto(imp->valore());
|
|
}
|
|
}
|
|
}
|
|
|
|
sort();
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Form speciale per estratti conto
|
|
///////////////////////////////////////////////////////////
|
|
|
|
void TEC_form::ec_header_handler(TPrinter& pr)
|
|
{
|
|
TPrint_section& head = _form->section('H');
|
|
head.reset();
|
|
pr.resetheader();
|
|
|
|
head.update();
|
|
for (word j = 0; j < head.height(); j++)
|
|
pr.setheaderline(j, head.row(j));
|
|
}
|
|
|
|
// Confronta due totali in valuta alfabeticamente
|
|
static int tot_compare(const void* o1, const void* o2)
|
|
{
|
|
if (o1 == o2) // Sfrutto una piccola debolezza di qsort:
|
|
return 0; // ogni tanto confronta oggetti con se stessi
|
|
|
|
const THash_object* h1 = (const THash_object*)o1;
|
|
const THash_object* h2 = (const THash_object*)o2;
|
|
return stricmp(h1->key(), h2->key());
|
|
}
|
|
|
|
void TEC_form::ec_footer_handler(TPrinter& pr)
|
|
{
|
|
TPrint_section& foot = _form->section('F');
|
|
pr.resetfooter();
|
|
|
|
const word MAXTOT = 16;
|
|
THash_object* tot[MAXTOT];
|
|
|
|
// I totali sono in un assoc array disordinato per cui li copio in un array e li ordino
|
|
// alfabeticamente in base al loro codice valuta
|
|
TTotalizer& totali = _form->totali();
|
|
totali.restart();
|
|
|
|
word numtot = 0;
|
|
for (THash_object* obj = totali.get_hashobj();
|
|
numtot < MAXTOT && obj != NULL;
|
|
obj = totali.get_hashobj())
|
|
tot[numtot++] = obj;
|
|
qsort(tot, numtot, sizeof(THash_object*), tot_compare);
|
|
|
|
const word maxtot = foot.height() / _form->_footer_used;
|
|
if (numtot > maxtot)
|
|
numtot = maxtot;
|
|
|
|
const TString& riporto = _form->describe(301, 'F');
|
|
|
|
TString desc(80);
|
|
TPrint_section& body = _form->section('B');
|
|
for (word j = 0; j < numtot; j++)
|
|
{
|
|
const word line = j * _form->_footer_used;
|
|
const TString& key = tot[j]->key();
|
|
TTotal& t = (TTotal&)(tot[j]->obj());
|
|
|
|
desc = riporto;
|
|
if (key.not_empty())
|
|
desc << ' ' << key;
|
|
TEC_row rip(desc, t.importo().normalize());
|
|
rip.scaduto(t.scaduto());
|
|
rip.esposto(t.esposto());
|
|
rip.print_on(body);
|
|
|
|
for (int fl = 0; fl < _form->_footer_used; fl++)
|
|
pr.setfooterline(line, body.row(fl));
|
|
}
|
|
}
|
|
|
|
|
|
bool TEC_form::print_game(const TPartita& game)
|
|
{
|
|
bool ok = FALSE;
|
|
|
|
TEC_array righe(game, this);
|
|
|
|
TPrinter& pr = printer();
|
|
TPrintrow prow;
|
|
|
|
TPrint_section& body = section('B');
|
|
|
|
TImporto saldo;
|
|
real scaduto, esposto;
|
|
|
|
// Stampa le righe di partita
|
|
|
|
int ultima_riga = 0;
|
|
int ultima_rata = 0;
|
|
|
|
for (int r = 0; r < righe.items(); r++)
|
|
{
|
|
TEC_row& riga = righe.row(r);
|
|
|
|
if (pr.rows_left() < body.height())
|
|
pr.formfeed();
|
|
|
|
const int ri = riga.riga();
|
|
const int ra = riga.rata();
|
|
if (ri == ultima_riga && ra == ultima_rata+1)
|
|
riga.reset_causale();
|
|
ultima_riga = ri;
|
|
ultima_rata = ra;
|
|
|
|
riga.print_on(body);
|
|
pr.print(body.row(0));
|
|
|
|
totali().add(riga.importo(), riga.scaduto(), riga.esposto(), riga.valuta().codice());
|
|
|
|
saldo += riga.importo();
|
|
scaduto += riga.scaduto();
|
|
esposto += riga.esposto();
|
|
ok = TRUE;
|
|
}
|
|
|
|
if (ok)
|
|
{
|
|
saldo.normalize();
|
|
|
|
TEC_row sld(describe(301), saldo);
|
|
sld.scaduto(scaduto);
|
|
sld.esposto(esposto);
|
|
sld.print_on(body);
|
|
pr.print(body.row(0));
|
|
|
|
// Salta una riga vuota
|
|
TPrintrow vuota;
|
|
pr.print(vuota);
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
const TString& TEC_form::describe(short id, char sez) const
|
|
{
|
|
const TForm_item& fi = find_field(sez, odd_page, id);
|
|
return fi.prompt();
|
|
}
|
|
|
|
TEC_form::TEC_form(const TEC_mask& m)
|
|
: TForm(BASE_EC_PROFILE, m.get_prof_code()),
|
|
_in_valuta(FALSE), _footer_used(1),
|
|
_causali(LF_CAUSALI, CAU_CODCAUS, CAU_DESCR)
|
|
{
|
|
_form = this;
|
|
|
|
TForm_item& imp_lire = find_field('B', odd_page, PEC_IMPLIRE);
|
|
_in_valuta = imp_lire.shown(); // Il profilo e' in valuta se c'e' la colonna importo in lire
|
|
|
|
_lingua = m.get_prof_lang(); // Lingua profilo
|
|
|
|
TCursor_sheet& cs = m.cur_sheet();
|
|
_cursore = cs.cursor();
|
|
|
|
_dlo = m.get(F_DATALIMOP);
|
|
_dls = m.get(F_DATALIMSC);
|
|
_giorni_rischio = m.get_int(F_GIORISCH);
|
|
_dir = _dls; _dir -= _giorni_rischio;
|
|
|
|
TPrinter& pr = printer();
|
|
|
|
pr.setheaderhandler(ec_header_handler);
|
|
pr.headerlen(section('H').height());
|
|
|
|
pr.setfooterhandler(ec_footer_handler);
|
|
const TPrint_section& foot = section('F');
|
|
pr.footerlen(foot.height());
|
|
|
|
for (int i = foot.fields()-1; i >= 0; i--)
|
|
{
|
|
TForm_item& fi = foot.field(i);
|
|
if (fi.y() > _footer_used)
|
|
_footer_used = fi.y();
|
|
}
|
|
}
|
|
|
|
TEC_form::~TEC_form()
|
|
{
|
|
TPrinter& pr = printer();
|
|
pr.setheaderhandler(NULL);
|
|
pr.setfooterhandler(NULL);
|
|
_form = NULL;
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Stampa estratti conto
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TStampaEC_application : public TApplication
|
|
{
|
|
TEC_mask* _msk;
|
|
TEC_form* _form;
|
|
|
|
TFile_array _file;
|
|
|
|
TString _lingua_ditta;
|
|
bool _gesval;
|
|
|
|
protected: // TApplication
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
virtual bool menu(MENU_TAG m);
|
|
virtual void on_firm_change();
|
|
|
|
public:
|
|
static TStampaEC_application& app() { return (TStampaEC_application&)main_app(); }
|
|
|
|
public:
|
|
TEC_mask& mask() { return *_msk; }
|
|
TCursor_sheet& sheet() { return _msk->cur_sheet(); }
|
|
TEC_form& form() { return *_form; }
|
|
|
|
bool print_selected(); // print selected items
|
|
bool print_ec(); // print one item
|
|
|
|
TStampaEC_application();
|
|
virtual ~TStampaEC_application() {}
|
|
};
|
|
|
|
bool TStampaEC_application::print_selected()
|
|
{
|
|
TCursor_sheet& s = sheet();
|
|
TCursor& c = *s.cursor();
|
|
|
|
const char who = mask().get_who();
|
|
const int key = mask().get_key();
|
|
|
|
// Filtra il cursore del form in mode che diventi uguale al cursor_sheet corrente
|
|
// Qui sarebbe bello copiarsi l'indice dell'altro cursore
|
|
TCursor& fc = *form().cursor();
|
|
fc.setkey(key);
|
|
TRectype filter(LF_CLIFO);
|
|
filter.put(CLI_TIPOCF, who);
|
|
fc.setregion(filter, filter);
|
|
|
|
const long print_all = !s.one_checked(); // Se non ho selezionato nulla allora li stampo tutti
|
|
long analfabeti = 0; // Persone non stampate in quanto aventi lingua errata
|
|
|
|
printer().open();
|
|
|
|
const long items = c.items();
|
|
for (long i = 0; i < items; i++) if (print_all || s.checked(i))
|
|
{
|
|
fc = i; // Muove il cursore alla posizione corrente
|
|
const bool ok = print_ec();
|
|
if (!ok) analfabeti++;
|
|
}
|
|
printer().formfeed();
|
|
printer().close();
|
|
|
|
if (analfabeti > 0)
|
|
warning_box("%ld clienti/fornitori non sono stati stampati in quanto "
|
|
"il codice lingua non corrispondeva al profilo di stampa", analfabeti);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
bool TStampaEC_application::print_ec()
|
|
{
|
|
TEC_form& f = form();
|
|
|
|
const TRectype& clf = f.cursor()->file().curr();
|
|
const TString lincf(clf.get(CLI_CODLIN));
|
|
|
|
bool ok = TRUE;
|
|
|
|
// make controllations per lingua profilo/CF
|
|
if ((f.lingua() == _lingua_ditta && !lincf.empty()) || f.lingua() != _lingua_ditta)
|
|
ok = lincf == f.lingua();
|
|
|
|
if (!ok) // Cliente analfabeta
|
|
return FALSE;
|
|
|
|
f.totali().destroy(); // Azzera totali di fine pagina
|
|
|
|
// Filtra solo le partite del cliente selezionato
|
|
TLocalisamfile& partite = _file[LF_PARTITE];
|
|
partite.zero();
|
|
partite.put(PART_TIPOCF, clf.get(CLI_TIPOCF));
|
|
partite.put(PART_SOTTOCONTO, clf.get(CLI_CODCF));
|
|
const TRectype filter(partite.curr());
|
|
|
|
const bool stampa_chiuse = mask().get_bool(F_STAMPCHIU);
|
|
const TDate data_chiuse = mask().get(F_DATACHIU);
|
|
|
|
bool one_printed = FALSE;
|
|
for (int err = partite.read(_isgteq);
|
|
err == NOERR && partite.curr() == filter;
|
|
err = partite.read(_isgreat))
|
|
{
|
|
TPartita game(partite.curr());
|
|
|
|
if (game.chiusa())
|
|
{
|
|
const TDate& dir = form().data_inizio_rischio();
|
|
const TImporto saldo = game.calcola_saldo_al(dir, TRUE);
|
|
if (saldo.is_zero())
|
|
{
|
|
int r = 0;
|
|
if (stampa_chiuse)
|
|
{
|
|
for (r = game.last(); r > 0 ; r = game.pred(r))
|
|
{
|
|
const TRiga_partite& riga = game.riga(r);
|
|
if (riga.is_fattura())
|
|
{
|
|
const TDate dd(riga.get(PART_DATADOC));
|
|
if (dd > dir)
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (r == 0)
|
|
continue;
|
|
}
|
|
}
|
|
|
|
const bool printed = form().print_game(game);
|
|
if (printed)
|
|
one_printed = TRUE;
|
|
|
|
partite.put(PART_NRIGA, 9999);
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Generic TApplication methods
|
|
///////////////////////////////////////////////////////////
|
|
|
|
bool TStampaEC_application::create()
|
|
{
|
|
TApplication::create();
|
|
|
|
_file.open(LF_TABCOM, LF_TAB, LF_CAUSALI, LF_MOV, LF_RMOV, 0);
|
|
_file.open(LF_NDITTE, LF_ANAG, LF_COMUNI, 0);
|
|
_file.open(LF_CLIFO, LF_PARTITE, LF_SCADENZE, LF_PAGSCA ,0);
|
|
|
|
_msk = new TEC_mask("sc2100a");
|
|
|
|
dispatch_e_menu(MENU_ITEM(1));
|
|
return TRUE;
|
|
}
|
|
|
|
bool TStampaEC_application::destroy()
|
|
{
|
|
delete _msk;
|
|
_file.close();
|
|
return TApplication::destroy();
|
|
}
|
|
|
|
void TStampaEC_application::on_firm_change()
|
|
{
|
|
TApplication::on_firm_change();
|
|
TConfig c(CONFIG_DITTA, "cg");
|
|
_lingua_ditta = c.get("CodLin");
|
|
_gesval = c.get_bool("GesVal");
|
|
}
|
|
|
|
bool TStampaEC_application::menu(MENU_TAG)
|
|
{
|
|
TEC_mask& m = mask();
|
|
while (m.run() != K_QUIT)
|
|
{
|
|
_form = new TEC_form(m);
|
|
|
|
print_selected();
|
|
|
|
delete _form;
|
|
_form = NULL;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
TStampaEC_application::TStampaEC_application()
|
|
: _lingua_ditta(1), _msk(NULL), _form(NULL)
|
|
{}
|
|
|
|
int sc2100(int argc, char** argv)
|
|
{
|
|
TStampaEC_application app;
|
|
app.run(argc, argv, "Stampa Estratti Conto");
|
|
return 0;
|
|
}
|
|
|