dell'estratto conto. Creata la relativa maschera. git-svn-id: svn://10.65.10.50/trunk@2242 c028cbd2-c16b-5b4b-a496-9718f37d4682
654 lines
17 KiB
C++
Executable File
654 lines
17 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;
|
|
|
|
TString _lingua;
|
|
TDate _dlo, _dls;
|
|
|
|
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; }
|
|
const TString& lingua() const { return _lingua; }
|
|
|
|
bool print_game(const TPartita& game);
|
|
|
|
TEC_form(const TEC_mask& m);
|
|
virtual ~TEC_form();
|
|
};
|
|
|
|
TEC_form* TEC_form::_form = NULL;
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TEC_row
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TEC_row : public TSortable
|
|
{
|
|
TDate _data;
|
|
int _riga;
|
|
int _rata;
|
|
|
|
TString _causale;
|
|
TString _descrizione;
|
|
|
|
TDate _data_doc;
|
|
TString _num_doc;
|
|
long _num_prot;
|
|
TImporto _importo;
|
|
TImporto _importo_lire;
|
|
real _scaduto;
|
|
real _totale;
|
|
TValuta _valuta;
|
|
|
|
protected: // TSortable
|
|
virtual int compare(const TSortable& s) const;
|
|
|
|
public:
|
|
void descrizione(const char* s) { _descrizione = s; }
|
|
void scaduto(const real& s) { _scaduto = s; }
|
|
|
|
const TValuta& valuta() const { return _valuta; }
|
|
const TImporto& importo() const { return _importo; }
|
|
const TDate& data() const { return _data; }
|
|
|
|
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)
|
|
{
|
|
_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)
|
|
: _num_prot(0)
|
|
{
|
|
_descrizione = desc;
|
|
_importo = imp; _importo.normalize();
|
|
}
|
|
|
|
// Le righe dell'estratto conto sono ordinate per data, riga partita, numero rata,
|
|
// 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 = r._riga - _riga;
|
|
if (c == 0)
|
|
c = r._rata - _rata;
|
|
}
|
|
else
|
|
c = _data < r._data ? +1 : -1;
|
|
return c;
|
|
}
|
|
|
|
void TEC_row::print_on(TPrint_section& body)
|
|
{
|
|
TEC_form& form = (TEC_form&)body.form();
|
|
|
|
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')
|
|
{
|
|
dare.set(imp.string());
|
|
avere.set("");
|
|
}
|
|
else
|
|
{
|
|
avere.set(imp.string());
|
|
dare.set("");
|
|
}
|
|
|
|
TForm_item& scaduto = body.find_field(PEC_SCADUTO);
|
|
scaduto.set(_scaduto.string());
|
|
|
|
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
|
|
{
|
|
const TEC_form* _form;
|
|
|
|
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; }
|
|
void calcola_scaduto(const TRiga_scadenze& rata, real& scaduto) 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() {}
|
|
};
|
|
|
|
void TEC_array::calcola_scaduto(const TRiga_scadenze& rata, real& scaduto) const
|
|
{
|
|
const TPartita& game = rata.partita();
|
|
TImporto imp_scaduto = rata.importo(TRUE);
|
|
|
|
const char* const field = rata.in_valuta() ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
|
TImporto imp;
|
|
|
|
for (int p = rata.last(); p > 0; p = rata.pred(p))
|
|
{
|
|
const TRectype& pag = rata.row(p);
|
|
const TRiga_partite& sum = game.riga(pag.get_int(PAGSCA_NRIGP));
|
|
const tipo_movimento tm = sum.tipo();
|
|
if (tm != tm_insoluto && tm != tm_pagamento_insoluto)
|
|
{
|
|
imp.set(sum.sezione(), pag.get_real(field));
|
|
imp_scaduto += imp;
|
|
}
|
|
}
|
|
const char sezione = game.conto().tipo() == 'C' ? 'D' : 'A';
|
|
imp_scaduto.normalize(sezione);
|
|
scaduto = imp_scaduto.valore();
|
|
}
|
|
|
|
TEC_row& TEC_array::new_row(const TRiga_partite& row, const TDate& data,
|
|
const TImporto& imp, int n)
|
|
{
|
|
if (n == 0)
|
|
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 TDate data(rata.get(SCAD_DATASCAD));
|
|
if (data <= form().data_limite_operazione())
|
|
{
|
|
TEC_row& rec = new_row(row, data, rata.importo(TRUE), r);
|
|
if (data <= form().data_limite_scaduto())
|
|
{
|
|
real s;
|
|
calcola_scaduto(rata, s);
|
|
rec.scaduto(s);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
const TDate data(row.get(PART_DATAPAG));
|
|
if (data <= form().data_limite_operazione())
|
|
{
|
|
const TImporto imp(row.importo(FALSE, 0x1));
|
|
new_row(row, data, imp);
|
|
|
|
const TImporto abbuoni(row.importo(FALSE, 0x2));
|
|
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.importo(FALSE, 0x4));
|
|
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));
|
|
}
|
|
|
|
static int val_compare(const void* o1, const void* o2)
|
|
{
|
|
const THash_object* h1 = (const THash_object*)o1;
|
|
const THash_object* h2 = (const THash_object*)o2;
|
|
const TString& s1 = (const TString&)h1->obj();
|
|
const TString& s2 = (const TString&)h2->obj();
|
|
return s2.compare(s1, -1, TRUE); // same as stricmp(s1, s2) in reverse order
|
|
}
|
|
|
|
void TEC_form::ec_footer_handler(TPrinter& pr)
|
|
{
|
|
TPrint_section& foot = _form->section('F');
|
|
pr.resetfooter();
|
|
|
|
const word MAXTOT = 32;
|
|
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*), val_compare);
|
|
|
|
if (numtot > foot.height())
|
|
numtot = foot.height();
|
|
|
|
TPrint_section& body = _form->section('B');
|
|
for (word j = 0; j < numtot; j++)
|
|
{
|
|
const TString& key = tot[j]->key();
|
|
TImporto& imp = (TImporto&)tot[j]->obj();
|
|
TEC_row r(key, imp.normalize());
|
|
r.print_on(body);
|
|
const TPrintrow& ri = body.row(0);
|
|
pr.setfooterline(j, ri);
|
|
}
|
|
}
|
|
|
|
|
|
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++)
|
|
{
|
|
TEC_row& riga = righe.row(r);
|
|
|
|
if (pr.rows_left() < body.height())
|
|
pr.formfeed();
|
|
|
|
riga.print_on(body);
|
|
pr.print(body.row(0));
|
|
|
|
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 TEC_mask& m)
|
|
: TForm(BASE_EC_PROFILE, m.get_prof_code()),
|
|
_causali(LF_CAUSALI, CAU_CODCAUS, CAU_DESCR)
|
|
{
|
|
_form = this;
|
|
|
|
_lingua = m.get_prof_lang();
|
|
|
|
TCursor_sheet& cs = m.cur_sheet();
|
|
_cursore = cs.cursor();
|
|
|
|
_dlo = m.get(F_DATALIMOP);
|
|
_dls = m.get(F_DATALIMSC);
|
|
|
|
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;
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// 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 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)
|
|
{
|
|
_form = new TEC_form(m);
|
|
|
|
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().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;
|
|
|
|
// 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;
|
|
_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 m)
|
|
{
|
|
select_ec();
|
|
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;
|
|
}
|
|
|