635 lines
15 KiB
C++
Executable File
635 lines
15 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 "sc2100a.h"
|
|
|
|
#include <clifo.h>
|
|
#include <causali.h>
|
|
#include <scadenze.h>
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Totalizzatore
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TTotalizer : public TAssoc_array
|
|
{
|
|
public:
|
|
void add(const TImporto& imp, const char* val);
|
|
|
|
TTotalizer() { }
|
|
virtual ~TTotalizer() { }
|
|
};
|
|
|
|
void TTotalizer::add(const TImporto& imp, const char* val)
|
|
{
|
|
TString16 codice(val);
|
|
if (codice == "LIT")
|
|
codice.cut(0);
|
|
|
|
TObject* obj = objptr(codice);
|
|
if (obj != NULL)
|
|
{
|
|
TImporto& tot = (TImporto&)*obj;
|
|
tot += imp;
|
|
}
|
|
else
|
|
{
|
|
TAssoc_array::add(codice, new TImporto(imp));
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TEC_form
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TEC_form : public TForm
|
|
{
|
|
static TEC_form* _form;
|
|
|
|
TCursor* _cursore;
|
|
TTotalizer _totali;
|
|
TDecoder _causali;
|
|
|
|
protected:
|
|
static void ec_header_handler(TPrinter& p);
|
|
static void ec_footer_handler(TPrinter& p);
|
|
|
|
public:
|
|
TTotalizer& totali() { return _totali; }
|
|
TDecoder& causali() { return _causali; }
|
|
|
|
bool print_game(const TPartita& game);
|
|
|
|
TEC_form(const char* codice, TCursor* cursor);
|
|
virtual ~TEC_form();
|
|
};
|
|
|
|
TEC_form* TEC_form::_form = NULL;
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TEC_row
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TEC_row : public TSortable
|
|
{
|
|
TDate _data;
|
|
int _riga;
|
|
|
|
TString _causale;
|
|
TString _descrizione;
|
|
|
|
TDate _data_doc;
|
|
TString _num_doc;
|
|
long _num_prot;
|
|
TImporto _importo;
|
|
TValuta _valuta;
|
|
TImporto _totale_doc;
|
|
|
|
protected: // TSortable
|
|
virtual int compare(const TSortable& s) const;
|
|
|
|
public:
|
|
void descrizione(const char* s) { _descrizione = s; }
|
|
|
|
const TValuta& valuta() const { return _valuta; }
|
|
const TImporto& importo() const { return _importo; }
|
|
|
|
void print_on(TPrint_section& body);
|
|
|
|
TEC_row(const TRiga_partite& row, const TDate& data, const TImporto& imp, int riga);
|
|
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 riga)
|
|
: _riga(riga), _num_prot(0)
|
|
{
|
|
_data = data;
|
|
_causale = row.get(PART_CODCAUS);
|
|
_data_doc = row.get(PART_DATADOC);
|
|
_num_prot = row.get_long(PART_PROTIVA);
|
|
_valuta.get(row);
|
|
_importo = imp;
|
|
// _totale = row.get_long(???);
|
|
}
|
|
|
|
TEC_row::TEC_row(const char* desc, const TImporto& imp)
|
|
: _riga(0), _num_prot(0)
|
|
{
|
|
_descrizione = desc;
|
|
_importo = imp;
|
|
}
|
|
|
|
int TEC_row::compare(const TSortable& s) const
|
|
{
|
|
const TEC_row& r = (const TEC_row&)s;
|
|
int c = 0;
|
|
if (_data == r._data)
|
|
c = r._riga - _riga;
|
|
else
|
|
c = _data < r._data ? +1 : -1;
|
|
return c;
|
|
}
|
|
|
|
void TEC_row::print_on(TPrint_section& body)
|
|
{
|
|
TEC_form& form = (TEC_form&)body.form();
|
|
|
|
body.reset();
|
|
|
|
if (_causale.not_empty())
|
|
{
|
|
TForm_item& causale = body.find_field(201);
|
|
causale.set(_causale);
|
|
|
|
if (_descrizione.empty())
|
|
{
|
|
TDecoder& causali = form.causali();
|
|
_descrizione = causali.decode(_causale);
|
|
}
|
|
}
|
|
|
|
if (_descrizione.not_empty())
|
|
{
|
|
TForm_item& descr = body.find_field(202);
|
|
descr.set(_descrizione);
|
|
}
|
|
|
|
if (_data_doc.ok())
|
|
{
|
|
TForm_item& datadoc = body.find_field(203);
|
|
datadoc.set(_data_doc.string());
|
|
}
|
|
|
|
if (_num_doc.not_empty())
|
|
{
|
|
TForm_item& numdoc = body.find_field(204);
|
|
numdoc.set(_num_doc);
|
|
}
|
|
|
|
if (_num_prot != 0)
|
|
{
|
|
TForm_item& numprot = body.find_field(205);
|
|
TString16 protiva; protiva << _num_prot;
|
|
numprot.set(protiva);
|
|
}
|
|
|
|
if (_data.ok())
|
|
{
|
|
TForm_item& datapag = body.find_field(207);
|
|
datapag.set(_data.string());
|
|
}
|
|
|
|
const real& imp = _importo.valore();
|
|
if (!imp.is_zero())
|
|
{
|
|
TForm_item& dare = body.find_field(208);
|
|
TForm_item& avere = body.find_field(209);
|
|
|
|
if (_importo.sezione() == 'D')
|
|
{
|
|
dare.set(imp.string());
|
|
avere.set("");
|
|
}
|
|
else
|
|
{
|
|
avere.set(imp.string());
|
|
dare.set("");
|
|
}
|
|
}
|
|
|
|
if (!_valuta.in_lire())
|
|
{
|
|
TForm_item& cambio = body.find_field(212);
|
|
cambio.set(_valuta.cambio().string());
|
|
|
|
if (_valuta.data().ok())
|
|
{
|
|
TForm_item& datacambio = body.find_field(213);
|
|
datacambio.set(_valuta.data().string());
|
|
}
|
|
}
|
|
|
|
body.update();
|
|
|
|
TPrinter& pr = printer();
|
|
for (word j = 0; j < body.height(); j++)
|
|
pr.print(body.row(j));
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TEC_array
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TEC_array : public TArray
|
|
{
|
|
const TEC_form* _form;
|
|
|
|
protected:
|
|
TEC_row& new_row(const TRiga_partite& row, const TDate& data, const TImporto& imp);
|
|
void add_row(const TRiga_partite& row);
|
|
|
|
public:
|
|
TEC_row& row(int r) { return (TEC_row&)operator[](r); }
|
|
const TEC_form& form() const { return *_form; }
|
|
|
|
TEC_array(const TPartita& game, const TEC_form* f);
|
|
virtual ~TEC_array() {}
|
|
};
|
|
|
|
TEC_row& TEC_array::new_row(const TRiga_partite& row, const TDate& data, const TImporto& imp)
|
|
{
|
|
const int n = items();
|
|
TEC_row* riga = new TEC_row(row, data, imp, n);
|
|
add(riga, n);
|
|
return *riga;
|
|
}
|
|
|
|
void TEC_array::add_row(const TRiga_partite& row)
|
|
{
|
|
if (row.is_fattura())
|
|
{
|
|
for (int r = 1; r <= row.rate(); r++)
|
|
{
|
|
const TRiga_scadenze& rata = row.rata(r);
|
|
const TImporto imp(row.sezione(), rata.get_real(PART_IMPORTO));
|
|
const TDate data(rata.get(SCAD_DATASCAD));
|
|
new_row(row, data, imp);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
const TImporto imp(row.sezione(), row.get_real(PART_IMPORTO));
|
|
const TDate data(row.get(PART_DATAPAG));
|
|
new_row(row, data, imp);
|
|
|
|
const TImporto abbuoni(row.get_char(PART_SEZABB), row.get_real(PART_ABBUONI));
|
|
if (!abbuoni.is_zero())
|
|
{
|
|
TEC_row& r = new_row(row, data, abbuoni);
|
|
const TForm_item& desc_abb = form().find_field('B', odd_page, 302);
|
|
r.descrizione(desc_abb.prompt());
|
|
}
|
|
|
|
const TImporto diffcam(row.get_char(PART_SEZDIFCAM), row.get_real(PART_DIFFCAM));
|
|
if (!diffcam.is_zero())
|
|
{
|
|
TEC_row& r = new_row(row, data, diffcam);
|
|
const TForm_item& desc_dif = form().find_field('B', odd_page, 303);
|
|
r.descrizione(desc_dif.prompt());
|
|
}
|
|
}
|
|
}
|
|
|
|
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));
|
|
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));
|
|
}
|
|
|
|
|
|
void TEC_form::ec_footer_handler(TPrinter& p)
|
|
{
|
|
TRACE("Stamperei un footer");
|
|
}
|
|
|
|
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;
|
|
|
|
// Stampa le righe di partita
|
|
for (int r = 0; r < righe.items(); r++)
|
|
{
|
|
if (pr.rows_left() < body.height())
|
|
pr.formfeed();
|
|
|
|
TEC_row& riga = righe.row(r);
|
|
riga.print_on(body);
|
|
|
|
totali().add(riga.importo(), riga.valuta().codice());
|
|
|
|
saldo += riga.importo();
|
|
ok = TRUE;
|
|
}
|
|
|
|
if (ok)
|
|
{
|
|
saldo.normalize();
|
|
|
|
const TForm_item& desc_sld = body.find_field(301);
|
|
TEC_row sld(desc_sld.prompt(), saldo);
|
|
sld.print_on(body);
|
|
|
|
// Salta una riga vuota
|
|
TPrintrow vuota;
|
|
pr.print(vuota);
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
TEC_form::TEC_form(const char* codice, TCursor* cur)
|
|
: TForm(BASE_EC_PROFILE, codice),
|
|
_causali(LF_CAUSALI, CAU_CODCAUS, CAU_DESCR)
|
|
{
|
|
_form = this;
|
|
_cursore = cur;
|
|
|
|
TPrinter& pr = printer();
|
|
|
|
pr.setheaderhandler(ec_header_handler);
|
|
pr.headerlen(section('H').height());
|
|
|
|
pr.setfooterhandler(ec_footer_handler);
|
|
pr.footerlen(section('F').height());
|
|
}
|
|
|
|
TEC_form::~TEC_form()
|
|
{
|
|
TPrinter& pr = printer();
|
|
pr.setheaderhandler(NULL);
|
|
pr.setfooterhandler(NULL);
|
|
_form = NULL;
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TFilearray
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TFile_array
|
|
{
|
|
TArray _file;
|
|
|
|
public:
|
|
void open(int num, ...);
|
|
TLocalisamfile& file(int num) const { return (TLocalisamfile&)_file[num]; }
|
|
TLocalisamfile& operator[](int num) const { return file(num); }
|
|
|
|
TFile_array() {}
|
|
virtual ~TFile_array() {}
|
|
};
|
|
|
|
void TFile_array::open(int logicnum, ...)
|
|
{
|
|
va_list marker;
|
|
va_start(marker, logicnum);
|
|
while (logicnum > 0)
|
|
{
|
|
CHECKD(_file.objptr(logicnum) == NULL, "File gia' aperto: ", logicnum);
|
|
_file.add(new TLocalisamfile(logicnum), logicnum);
|
|
logicnum = va_arg(marker, int);
|
|
}
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Stampa estratti conto
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TStampaEC_application : public TApplication
|
|
{
|
|
TEC_mask* _msk;
|
|
TEC_form* _form;
|
|
|
|
TFile_array _file;
|
|
|
|
TString _lingua;
|
|
TString _linprof;
|
|
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 select_ec(); // starting point
|
|
bool print_selected(); // print selected items
|
|
bool print_ec(); // print one item
|
|
|
|
TStampaEC_application();
|
|
virtual ~TStampaEC_application() {}
|
|
};
|
|
|
|
bool TStampaEC_application::select_ec()
|
|
{
|
|
TEC_mask& m = mask();
|
|
while (m.run() != K_ESC)
|
|
{
|
|
_linprof = m.get_prof_lang();
|
|
_form = new TEC_form(m.get_prof_code(), sheet().cursor());
|
|
|
|
print_selected();
|
|
|
|
delete _form;
|
|
_form = NULL;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
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().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 ((_linprof == _lingua && !lincf.empty()) || _linprof != _lingua)
|
|
ok = lincf == _linprof;
|
|
|
|
if (!ok) // Cliente analfabeta
|
|
return FALSE;
|
|
|
|
// 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);
|
|
const TDate data_scaduto = mask().get(F_DATALIMSC);
|
|
const int giorni_rischio = mask().get_int(F_GIORISCH);
|
|
|
|
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())
|
|
{
|
|
TDate data_rischio = data_scaduto; data_rischio -= giorni_rischio;
|
|
const TImporto saldo = game.calcola_saldo_al(data_rischio, 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 > data_rischio)
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (r == 0)
|
|
continue;
|
|
}
|
|
}
|
|
|
|
const bool printed = form().print_game(game);
|
|
if (printed)
|
|
one_printed = TRUE;
|
|
|
|
partite.put(PART_NRIGA, 9999);
|
|
}
|
|
|
|
if (one_printed)
|
|
printer().formfeed();
|
|
|
|
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;
|
|
return TApplication::destroy();
|
|
}
|
|
|
|
void TStampaEC_application::on_firm_change()
|
|
{
|
|
TApplication::on_firm_change();
|
|
TConfig c(CONFIG_DITTA, "cg");
|
|
_lingua = c.get("CodLin");
|
|
_gesval = c.get_bool("GesVal");
|
|
}
|
|
|
|
bool TStampaEC_application::menu(MENU_TAG m)
|
|
{
|
|
select_ec();
|
|
return FALSE;
|
|
}
|
|
|
|
TStampaEC_application::TStampaEC_application()
|
|
: _lingua(1), _linprof(1), _msk(NULL), _form(NULL)
|
|
{}
|
|
|
|
int sc2100(int argc, char** argv)
|
|
{
|
|
TStampaEC_application app;
|
|
app.run(argc, argv, "Stampa Estratti Conto");
|
|
return 0;
|
|
}
|
|
|