Files correlati : sc2.exe pec.frm sc2200a.msk sc2300a.msk MODIFICA CRPA Possibilità di stampare il pagamento del cliente nella testata dell'estratti conto. Aggiunto filtro per ulteriore classificazione nello scadenziario. Possibilità di stampare le note delle scadenze nella stampa scaduto. Possibiltà di stampare il flag di rata bloccata e il dati di analitica e di filtrare per dati analitica nei solleciti. git-svn-id: svn://10.65.10.50/branches/R_10_00@23573 c028cbd2-c16b-5b4b-a496-9718f37d4682
2240 lines
62 KiB
C++
Executable File
2240 lines
62 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <form.h>
|
||
#include <modaut.h>
|
||
#include <printer.h>
|
||
#include <progind.h>
|
||
#include <textset.h>
|
||
|
||
#include "sc2.h"
|
||
#include "sc2101.h"
|
||
#include "sc2102.h"
|
||
|
||
#include "sc2100a.h"
|
||
#include "sc21pec.h"
|
||
|
||
#include "../ca/calib01.h"
|
||
#include "../ca/movana.h"
|
||
#include "../cg/cgsaldac.h"
|
||
#include "../pr/agenti.h"
|
||
|
||
#include <cfven.h>
|
||
#include <causali.h>
|
||
#include <mov.h>
|
||
#include <pconti.h>
|
||
|
||
class TEC_recordset : public TAS400_recordset
|
||
{
|
||
char _who;
|
||
|
||
public:
|
||
char get_who() const { return _who; }
|
||
TEC_recordset(const char who);
|
||
};
|
||
|
||
TEC_recordset::TEC_recordset(char who) : TAS400_recordset("AS400(255,0,0)"), _who(who)
|
||
{
|
||
if (who >= 'C')
|
||
{
|
||
if (who == 'F')
|
||
create_field("Fornitore", 0, 6, _longfld);
|
||
else
|
||
create_field("Cliente", 0, 6, _longfld);
|
||
create_field("RagioneSociale", -1, 50);
|
||
}
|
||
else
|
||
{
|
||
create_field("Conto", 0, 12, _alfafld);
|
||
create_field("Denominazione", -1, 50);
|
||
}
|
||
create_field("Telefono", -1, 20);
|
||
create_field("Valuta", -1, 3);
|
||
create_field("Causale", -1, 3);
|
||
create_field("Descrizione", -1, 60);
|
||
create_field("DataDoc", -1, 10, _datefld);
|
||
create_field("NumDoc" , -1, 7);
|
||
create_field("ProtIVA", -1, 6, _intfld);
|
||
create_field("DataPag", -1, 10, _datefld);
|
||
create_field("Dare", -1, 15, _realfld);
|
||
create_field("Avere", -1, 15, _realfld);
|
||
create_field("Scaduto", -1, 15, _realfld);
|
||
create_field("Esposto", -1, 15, _realfld);
|
||
create_field("SBF", -1, 1);
|
||
create_field("TotDoc", -1, 15, _realfld);
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TEC_form
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TEC_form : public TForm
|
||
{
|
||
friend class TEC_row;
|
||
|
||
static TEC_form* _form;
|
||
TEC_recordset* _recordset;
|
||
|
||
enum { MAXTOT = 16 };
|
||
|
||
TCursor* _cursore;
|
||
TTotalizer _totali;
|
||
|
||
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 _fincatura; // 0 = nessuna, 1 = testo, 2 = grafica
|
||
word _num_rip; // Numero di righe usate per i riporti
|
||
word _total_rows; // Numero di righe usate per i totali
|
||
word _maxtot; // Numero massimo di totali da stampare
|
||
bool _stampa_saldo; // Stampa il saldo di ogni partita
|
||
bool _note_scadenti; // Considera scadute le note di credito non assegnate
|
||
|
||
protected:
|
||
void init_header(const TMask& m);
|
||
word ordina_totali_per_valuta(THash_object* tot[MAXTOT]);
|
||
|
||
int find_magic(TString& s, TString& magic1, TString& magic2) const;
|
||
void change_magic_body(const TEC_row& o, TString& s);
|
||
void change_magic_footer(const THash_object& o, TString& s);
|
||
void print_total(int riga, const THash_object& o);
|
||
|
||
void stampa_testata(TPrinter& p);
|
||
void stampa_pedata();
|
||
void stampa_riporti(TPrinter& p);
|
||
|
||
static void ec_header_handler(TPrinter& p);
|
||
static void ec_footer_handler(TPrinter& p);
|
||
|
||
public:
|
||
TTotalizer& totali() { return _totali; }
|
||
|
||
virtual TRelation* relation() const { return _cursore->relation(); }
|
||
virtual TCursor* cursor() { return _cursore; }
|
||
|
||
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; }
|
||
bool note_scadenti() const { return _note_scadenti; }
|
||
|
||
const TString& lingua() const { return _lingua; }
|
||
bool in_valuta() const { return _in_valuta; }
|
||
const TString& describe(short id, char sez = 'H', pagetype pt = last_page) const;
|
||
|
||
void azzera_totali();
|
||
void ultima_pagina();
|
||
bool print_game(const TPartita& game);
|
||
bool stampa_saldo() const { return _stampa_saldo; }
|
||
void stampa_saldo(bool ss) { _stampa_saldo = ss; }
|
||
|
||
void set_agente(const TString& codag);
|
||
|
||
bool printing() const { return _recordset == NULL; }
|
||
bool exporting() const { return _recordset != NULL; }
|
||
void export_total();
|
||
|
||
void set_pagam(const TString& codpag);
|
||
|
||
TEC_recordset& recordset() const { CHECK(exporting(), "Not exporting"); return *_recordset; }
|
||
|
||
TEC_form(const TEC_mask& m, bool gesval, bool excel);
|
||
virtual ~TEC_form();
|
||
};
|
||
|
||
TEC_form* TEC_form::_form = NULL;
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TEC_row
|
||
// Rappresenta una singola riga di stampa
|
||
///////////////////////////////////////////////////////////
|
||
|
||
static char __ltipocf;
|
||
static long __lcodcf;
|
||
static int __lgruppo, __lconto;
|
||
|
||
class TEC_row : public TSortable
|
||
{
|
||
TDate _data; // Data scadenza o pagamento
|
||
int _riga; // Riga della fattura
|
||
int _rata; // Numero rata o progressivo
|
||
|
||
TString _causale; // Codice causale
|
||
TString _descrizione; // Sua descrizione
|
||
|
||
char _tipocf;
|
||
long _codcf;
|
||
int _gruppo, _conto; // Solo per conti ver, altrimenti 0
|
||
|
||
TDate _data_doc; // Data del documento
|
||
TString _num_doc; // Numero documento
|
||
long _num_prot; // Protocollo IVA
|
||
long _num_reg; // Numero registrazione
|
||
TImporto _importo; // Importo in valuta
|
||
real _importo_euro; // Valore in Euro
|
||
real _importo_val; // Valore in Valuta
|
||
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
|
||
bool _bloccata; // Rata bloccata
|
||
TString _codici_analitica; // codici analitica corrispondenti alle fatture
|
||
|
||
protected: // TSortable
|
||
virtual int compare(const TSortable& s) const;
|
||
void set_imp(TForm_item& fi, const real& imp, const char* codval) const;
|
||
|
||
TEC_form& form() const;
|
||
|
||
public:
|
||
int riga() const { return _riga; }
|
||
int rata() const { return _rata; }
|
||
|
||
void reset_uguali();
|
||
void descrizione(const char* s) { _descrizione = s; }
|
||
void importo(const TImporto& i) { _importo = i; }
|
||
void importo_euro(const real& i) { _importo_euro = i; }
|
||
void importo_valuta(const real& i) { _importo_val = 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; }
|
||
void rata_bloccata(bool rb) { _bloccata = rb; }
|
||
void codici_analitica(const char * s) { _codici_analitica = s; }
|
||
|
||
const TString& causale() const { return _causale; }
|
||
const TString& descrizione() const { return _descrizione; }
|
||
long num_reg() const { return _num_reg; }
|
||
const TDate& data() const { return _data; }
|
||
const TImporto& importo() const { return _importo; }
|
||
const real& importo_euro() const { return _importo_euro; }
|
||
const real& importo_valuta() const { return _importo_val; }
|
||
const real& scaduto() const { return _scaduto; }
|
||
const 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);
|
||
void export_to(TEC_recordset& set);
|
||
|
||
TEC_row(const TRiga_partite& row, const TDate& data, const TImporto& imp, int rata);
|
||
TEC_row(const char* desc, const TImporto& imp, const TValuta& val);
|
||
virtual ~TEC_row() {}
|
||
};
|
||
|
||
TEC_row::TEC_row(const TRiga_partite& row, const TDate& data, const TImporto& imp, int rata)
|
||
: _salvo_buon_fine(false), _bloccata(false)
|
||
{
|
||
_riga = row.get_int(PART_NRIGA);
|
||
_rata = rata;
|
||
_data = data;
|
||
_causale = row.get(PART_CODCAUS);
|
||
_data_doc = row.get(PART_DATADOC);
|
||
_num_doc = row.get(PART_NUMDOC);
|
||
_num_prot = row.get_long(PART_PROTIVA);
|
||
_num_reg = row.get_long(PART_NREG);
|
||
_importo = imp; _importo.normalize();
|
||
_descrizione = row.get(PART_DESCR);
|
||
if (_descrizione.empty())
|
||
_descrizione = cache().get(LF_CAUSALI, _causale).get(CAU_DESCR);
|
||
_valuta.get(row);
|
||
|
||
const bool valuta = form().in_valuta() && _valuta.in_valuta();
|
||
const char* const field = valuta ? PART_IMPTOTVAL : PART_IMPTOTDOC;
|
||
_totale = row.get_real(field);
|
||
__ltipocf = _tipocf = row.get_char(PART_TIPOCF);
|
||
__lcodcf = _codcf = row.get_long(PART_SOTTOCONTO);
|
||
if (_tipocf < 'C')
|
||
{
|
||
__lgruppo = _gruppo = row.get_int(PART_GRUPPO);
|
||
__lconto = _conto = row.get_int(PART_CONTO);
|
||
}
|
||
else
|
||
{
|
||
__lgruppo = _gruppo = 0;
|
||
__lconto = _conto = 0;
|
||
}
|
||
}
|
||
|
||
TEC_row::TEC_row(const char* desc, const TImporto& imp, const TValuta& val)
|
||
: _riga(9999), _rata(9999), _num_doc(0),
|
||
_num_prot(0), _num_reg(0), _salvo_buon_fine(false), _bloccata(false)
|
||
{
|
||
_descrizione = desc;
|
||
_importo = imp; _importo.normalize();
|
||
_valuta = val;
|
||
_tipocf = __ltipocf;
|
||
_codcf = __lcodcf;
|
||
_gruppo = __lgruppo;
|
||
_conto = __lconto;
|
||
}
|
||
|
||
// 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;
|
||
}
|
||
|
||
// Annulla i campi uguali alla riga precedente
|
||
void TEC_row::reset_uguali()
|
||
{
|
||
_num_doc = "";
|
||
_data_doc = botime;
|
||
_num_prot = 0;
|
||
_totale = ZERO;
|
||
}
|
||
|
||
void TEC_row::set_imp(TForm_item& fi, const real& imp, const char* cod_val) const
|
||
{
|
||
const TCurrency cur(imp, cod_val);
|
||
fi.set(cur.get_num().string());
|
||
}
|
||
|
||
TEC_form& TEC_row::form() const
|
||
{
|
||
TEC_form* f = TEC_form::_form;
|
||
CHECK(f, "NULL form");
|
||
return *f;
|
||
}
|
||
|
||
void TEC_row::print_on(TPrint_section& body)
|
||
{
|
||
TEC_form& form = (TEC_form&)body.form();
|
||
|
||
const bool show_value = form.in_valuta() && in_valuta();
|
||
const TString& cod_valuta = (show_value ? valuta().codice() : EMPTY_STRING); // Stampa nella valuta della ditta
|
||
|
||
TForm_item& campo_valuta = body.find_field(PEC_VALUTA);
|
||
campo_valuta.set(cod_valuta);
|
||
|
||
TForm_item& causale = body.find_field(PEC_CODCAUS);
|
||
causale.set(_causale);
|
||
|
||
TForm_item& descr = body.find_field(PEC_DESCR);
|
||
|
||
// Riga di partita vera e propria (non totale parziale)
|
||
if (rata() < RIGA_PAGAMENTO)
|
||
{
|
||
TString256 s = descr.prompt();
|
||
TEC_form::_form->change_magic_body(*this, s);
|
||
descr.set(s);
|
||
}
|
||
else
|
||
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);
|
||
TString8 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, cod_valuta);
|
||
avere.set("");
|
||
}
|
||
else
|
||
{
|
||
set_imp(avere, imp, cod_valuta);
|
||
dare.set("");
|
||
}
|
||
|
||
TForm_item& scaduto = body.find_field(PEC_SCADUTO);
|
||
set_imp(scaduto, _scaduto, cod_valuta);
|
||
|
||
TForm_item& esposto = body.find_field(PEC_ESPOSTO);
|
||
set_imp(esposto, _esposto, cod_valuta);
|
||
esposto.set_prompt(_salvo_buon_fine ? "*" : " ");
|
||
|
||
TForm_item& totdoc = body.find_field(PEC_TOTDOC);
|
||
set_imp(totdoc, _totale, cod_valuta);
|
||
|
||
TForm_item& euro = body.find_field(PEC_IMPEURO);
|
||
set_imp(euro, _importo_euro, ""); // In generale va espresso nella valuta della ditta
|
||
|
||
TForm_item& valimp = body.find_field(PEC_VALIMP);
|
||
valimp.set(_valuta.codice()); // Codice valuta reale, NON USARE codval che e' quello di stampa
|
||
|
||
TForm_item& impval = body.find_field(PEC_IMPVAL);
|
||
set_imp(impval, _importo_val, _valuta.codice());
|
||
|
||
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());
|
||
|
||
TForm_item& bloccata = body.find_field(PEC_BLOCCATA);
|
||
bloccata.set(_bloccata ? "X" : "");
|
||
|
||
TForm_item& analitica = body.find_field(PEC_ANALITICA);
|
||
analitica.set(_codici_analitica);
|
||
TParagraph_string p(_codici_analitica, analitica.width());
|
||
const int h = analitica.height();
|
||
int i = 0;
|
||
for (i = 0; p.get() != NULL && i < h; i++);
|
||
analitica.section().set_height(p.empty() ? 1 : i);
|
||
|
||
const TString80 old_prompt(descr.prompt());
|
||
descr.set_prompt(""); // Nasconde temporaneamente il prompt per non stampare i <magic>
|
||
|
||
body.update(); // Crea vera riga di stampa
|
||
|
||
esposto.set_prompt(" "); // Ripristina il vecchio prompt
|
||
descr.set_prompt(old_prompt);
|
||
}
|
||
|
||
void TEC_row::export_to(TEC_recordset& r)
|
||
{
|
||
r.new_rec();
|
||
if (_tipocf >= 'C')
|
||
{
|
||
r.set(0u, _codcf);
|
||
TString8 key; key.format("%c|%ld", _tipocf, _codcf);
|
||
const TString& ragsoc = cache().get(LF_CLIFO, key, CLI_RAGSOC);
|
||
r.set("RagioneSociale", TVariant(ragsoc));
|
||
|
||
TString80 telefono = cache().get(LF_CLIFO, key, CLI_PTEL);
|
||
telefono << " " << cache().get(LF_CLIFO, key, CLI_TEL);
|
||
r.set("Telefono", TVariant(telefono));
|
||
}
|
||
else
|
||
{
|
||
TString16 key; key.format("%03d%03d%06ld", _gruppo, _conto, _codcf);
|
||
r.set(0u, key);
|
||
const TString& descr = cache().get(LF_PCON, key, PCN_DESCR);
|
||
r.set(1u, descr);
|
||
}
|
||
|
||
r.set("Valuta", TVariant(_valuta.codice()));
|
||
r.set("Causale", TVariant(_causale));
|
||
r.set("Descrizione", TVariant(_descrizione));
|
||
r.set("DataDoc", TVariant(_data_doc));
|
||
r.set("NumDoc", TVariant(_num_doc));
|
||
r.set("ProtIVA", TVariant(_num_prot));
|
||
r.set("DataScad", TVariant(_data));
|
||
r.set("DataPag", TVariant(_data));
|
||
r.set(_importo.sezione() == 'D' ? "Dare" : "Avere", _importo.valore());
|
||
r.set("Scaduto", TVariant(_scaduto));
|
||
r.set("Esposto", TVariant(_esposto));
|
||
r.set("SBF", TVariant(_salvo_buon_fine ? "*" : " "));
|
||
r.set("TotDoc", TVariant(_totale));
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TEC_array
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TEC_array : public TArray
|
||
{
|
||
TArray _scaduto; // Array di importi scaduti
|
||
TDecoder _anal;
|
||
|
||
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);
|
||
bool is_unassigned(const TRiga_partite& row) const;
|
||
TImporto importo(const TPartita& game, const TRectype& pag, bool valuta) const;
|
||
|
||
static TPartita* _sort_game;
|
||
static int ordina_pag(const void* pag1, const void* pag2);
|
||
void arrange_scaduto(const TPartita& game);
|
||
|
||
public:
|
||
TEC_row& row(int r) const { return (TEC_row&)operator[](r); }
|
||
|
||
TEC_array(const TPartita& game, const TEC_form* f);
|
||
virtual ~TEC_array() {}
|
||
};
|
||
|
||
TPartita* TEC_array::_sort_game = NULL;
|
||
|
||
// 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); // Riga di fattura
|
||
const bool fat_val = fat.in_valuta();
|
||
|
||
const int nrigp = pag.get_int(PAGSCA_NRIGP);
|
||
const TRiga_partite& sum = game.riga(nrigp); // Riga di pagamento
|
||
const char sez = sum.sezione();
|
||
|
||
const char* const field = valuta && fat_val ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
||
TImporto imp(sez, pag.get_real(field)); // Importo base
|
||
|
||
if (!fat_val)
|
||
{
|
||
imp.valore() += pag.get_real(PAGSCA_RITENUTE); // Sommo le ritenute se sono il Euro
|
||
const TImporto ritsoc(sum.sezione_ritsoc(), pag.get_real(PAGSCA_RITSOC));
|
||
imp += ritsoc;
|
||
}
|
||
|
||
const real diffcam = pag.get_real(PAGSCA_DIFFCAM); // Sempre in Euro
|
||
real abb(pag.get(PAGSCA_ABBUONI)); // Nella valuta della fattura
|
||
if (!abb.is_zero() || !diffcam.is_zero())// Se il pagamento ha abbuoni o differenze cambio
|
||
{
|
||
if (!valuta && fat_val) // Se voglio gli abbuoni in Euro ma la fattura non lo e'
|
||
{
|
||
const TValuta val(sum); // Leggo il cambio dalla riga di partita
|
||
val.val2eur(abb); // Converto in Euro gli abbuoni
|
||
abb += diffcam; // Sommo l'eventuale differenza cambio (gia' in Euro)
|
||
}
|
||
imp.valore() += abb; // Sommo il tutto all'importo base (sez e' uguale per tutti i valori)
|
||
}
|
||
|
||
|
||
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;
|
||
}
|
||
|
||
// Ordina i pagamenti in ordine di DATAPAG
|
||
int TEC_array::ordina_pag(const void* pag1, const void* pag2)
|
||
{
|
||
const int r1 = (*(TRectype**)pag1)->get_int(PAGSCA_NRIGP);
|
||
const TDate d1 = _sort_game->riga(r1).get(PART_DATAPAG);
|
||
const int r2 = (*(TRectype**)pag2)->get_int(PAGSCA_NRIGP);
|
||
const TDate d2 = _sort_game->riga(r2).get(PART_DATAPAG);
|
||
const int diff = d1 == d2 ? 0 : (d1 > d2 ? +1 : -1);
|
||
return diff;
|
||
}
|
||
|
||
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(valuta);
|
||
|
||
int riga_corrente_scaduto = 0;
|
||
|
||
const int numpag = rata.rows(); // Numero totale di pagamenti sulla rata
|
||
TRectype** arrpag = NULL; // Array di puntatori ai pagamenti
|
||
if (numpag > 0)
|
||
{
|
||
arrpag = new TRectype*[numpag];
|
||
int i = 0;
|
||
for (int p = rata.last(); p > 0; p = rata.pred(p))
|
||
arrpag[i++] = (TRectype*)&rata.row(p); // Copia puntatori ai pagamenti nell'array
|
||
_sort_game = (TPartita*)&game; // Inizializza partita di appoggio al sort
|
||
qsort(arrpag, numpag, sizeof(TRectype*), ordina_pag);
|
||
}
|
||
|
||
for (int i = 0; i < numpag; i++)
|
||
{
|
||
const TRectype& pag = *arrpag[i];
|
||
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 ", nrigp);
|
||
importo_riga_scaduto(riga_corrente_scaduto) += imp;
|
||
}
|
||
else
|
||
{
|
||
scaduto_rata += imp;
|
||
}
|
||
}
|
||
|
||
if (arrpag != NULL)
|
||
delete arrpag;
|
||
|
||
scaduto_rata.normalize(sezione);
|
||
return scaduto_rata.valore();
|
||
}
|
||
|
||
// Determina se una riga pagamento o nota di credito non <20> associata ad alcuna rata
|
||
bool TEC_array::is_unassigned(const TRiga_partite& row) const
|
||
{
|
||
const TPartita& game = row.partita();
|
||
const int riga = row.get_int(PART_NRIGA);
|
||
return game.esiste(TPartita::UNASSIGNED, TPartita::UNASSIGNED, riga);
|
||
}
|
||
|
||
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();
|
||
const char sezione = row.get_char(PART_TIPOCF) == 'C' ? 'D' : 'A';
|
||
|
||
const TDate data_op(row.get(PART_DATAREG));
|
||
if (data_op <= form().data_limite_operazione())
|
||
{
|
||
TString codanal;
|
||
|
||
if (main_app().has_module(CAAUT))
|
||
{
|
||
const TString& numregcg = row.get(PART_NREG);
|
||
const long numreg = atol(_anal.decode(numregcg));
|
||
|
||
if (numreg > 0)
|
||
{
|
||
TAnal_mov anal_mov(numreg);
|
||
TRecord_array & rows = anal_mov.body();
|
||
const int nrows = rows.rows();
|
||
|
||
for (int i = 1; i <= nrows; i++)
|
||
{
|
||
const TString80 s = anal_mov.row_code(i);
|
||
if (s.full() && codanal.find(s) < 0)
|
||
{
|
||
if (codanal.full())
|
||
codanal << '\n';
|
||
if (s.full())
|
||
codanal << s;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (row.is_fattura())
|
||
{
|
||
for (int r = 1; r <= row.rate(); r++)
|
||
{
|
||
const TRiga_scadenze& rata = row.rata(r);
|
||
const TDate data_scad(rata.get(SCAD_DATASCAD));
|
||
TEC_row& rec = new_row(row, data_scad, rata.importo(in_valuta), r);
|
||
|
||
if (data_scad <= form().data_limite_scaduto())
|
||
{
|
||
const real s = calcola_scaduto(rata, in_valuta);
|
||
rec.scaduto(s);
|
||
}
|
||
if (in_valuta)
|
||
{
|
||
TImporto ie = rata.importo(false);
|
||
ie.normalize(sezione);
|
||
rec.importo_euro(ie.valore());
|
||
}
|
||
if (rata.in_valuta())
|
||
{
|
||
TImporto iv = rata.importo(true);
|
||
iv.normalize(sezione);
|
||
rec.importo_valuta(iv.valore());
|
||
}
|
||
else
|
||
rec.importo_valuta(ZERO);
|
||
rec.rata_bloccata(rata.get_bool(SCAD_BLOCCATA));
|
||
rec.codici_analitica(codanal);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
const TDate data_pag(row.get(PART_DATAPAG));
|
||
const TImporto imp(row.importo(in_valuta, 0x1)); // Importo pulito senza nient'altro
|
||
TEC_row& riga = new_row(row, data_pag, imp, RIGA_PAGAMENTO);
|
||
|
||
if (row.in_valuta())
|
||
{
|
||
const TImporto impval(row.importo(true, 0x1)); // Importo pulito senza nient'altro
|
||
riga.importo_valuta(-impval.valore());
|
||
}
|
||
riga.codici_analitica(codanal);
|
||
|
||
const int tipo_pag = row.get_int(PART_TIPOPAG);
|
||
const tipo_movimento tipo_mov = row.tipo();
|
||
|
||
// Controlla se e' un pagamento con effetti
|
||
if ((tipo_mov == tm_pagamento || tipo_mov == tm_pagamento_insoluto) &&
|
||
(tipo_pag >= 2 && tipo_pag <= 7))
|
||
{
|
||
const TDate& dls = form().data_limite_scaduto();
|
||
const TDate& dir = form().data_inizio_rischio();
|
||
|
||
bool sbf = false;
|
||
TImporto esposto(row.esposto(in_valuta, dls, dir, sbf));
|
||
bool esp = !esposto.is_zero();
|
||
|
||
if (esp)
|
||
{
|
||
const char sezione = row.get_char(PART_TIPOCF) == 'C' ? 'A' : 'D';
|
||
esposto.normalize(sezione);
|
||
riga.salvo_buon_fine(sbf); // Esposto salvo buon fine
|
||
riga.esposto(esposto.valore());
|
||
}
|
||
}
|
||
|
||
if (tipo_mov == tm_nota_credito && form().note_scadenti())
|
||
{
|
||
const TDate& dls = form().data_limite_scaduto();
|
||
if (data_pag <= dls && is_unassigned(row))
|
||
{
|
||
const int nriga = row.get_int(PART_NRIGA);
|
||
const TImporto imp = row.importo(in_valuta, 0x1); // Importo pulito senza nient'altro
|
||
importo_riga_scaduto(nriga) += imp;
|
||
}
|
||
}
|
||
|
||
const TImporto abbuoni(row.importo(in_valuta, 0x2));
|
||
if (!abbuoni.is_zero())
|
||
{
|
||
TEC_row& rec = new_row(row, data_pag, abbuoni, RIGA_ABBUONI);
|
||
rec.descrizione(form().describe(PEC_ABBUONI));
|
||
if (in_valuta)
|
||
{
|
||
TImporto ae(row.importo(false, 0x2));
|
||
ae.normalize(sezione);
|
||
rec.importo_euro(ae.valore());
|
||
}
|
||
if (row.in_valuta())
|
||
{
|
||
TImporto av(row.importo(true, 0x2));
|
||
av.normalize(sezione);
|
||
rec.importo_valuta(av.valore());
|
||
}
|
||
else
|
||
rec.importo_valuta(ZERO);
|
||
rec.codici_analitica(codanal);
|
||
}
|
||
|
||
TImporto diffcam(row.importo(false, 0x4));
|
||
if (!diffcam.is_zero() && !in_valuta)
|
||
{
|
||
TEC_row& rec = new_row(row, data_pag, TImporto('D', ZERO), RIGA_DIFFCAM);
|
||
rec.descrizione(form().describe(PEC_DIFFCAM));
|
||
rec.importo(diffcam);
|
||
rec.codici_analitica(codanal);
|
||
}
|
||
|
||
TImporto ritenute(row.importo(false, 0x8));
|
||
if (!ritenute.is_zero())
|
||
{
|
||
TEC_row& rec = new_row(row, data_pag, TImporto('D', ZERO), RIGA_RITENUTE);
|
||
rec.descrizione(form().describe(PEC_RITENUTE));
|
||
if (in_valuta)
|
||
{
|
||
ritenute.normalize(sezione);
|
||
rec.importo_euro(ritenute.valore());
|
||
}
|
||
else
|
||
rec.importo(ritenute);
|
||
rec.codici_analitica(codanal);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void TEC_array::arrange_scaduto(const TPartita& game)
|
||
{
|
||
const bool in_valuta = form().in_valuta() && row(0).in_valuta();
|
||
const char sezione = game.conto().tipo() == 'C' ? 'A' : 'D';
|
||
|
||
TImporto totpag(game.importo_pagato_unassigned(in_valuta));
|
||
totpag.normalize(sezione);
|
||
|
||
for (int r = items()-1; r >= 0; r--)
|
||
{
|
||
TEC_row& s = row(r);
|
||
const real val_scaduto = s.scaduto();
|
||
if (!val_scaduto.is_zero())
|
||
{
|
||
TImporto imp_scadenza = s.importo();
|
||
imp_scadenza.normalize(sezione == 'A' ? 'D' : 'A'); // Sezione opposta ai pagamenti!
|
||
const int segno_scadenza = imp_scadenza.valore().sign();
|
||
const int segno_scaduto = val_scaduto.sign();
|
||
if (segno_scaduto * segno_scadenza < 0)
|
||
{
|
||
totpag += TImporto(sezione, -val_scaduto);
|
||
s.scaduto(ZERO);
|
||
}
|
||
}
|
||
}
|
||
|
||
for (int r = 0; r < items() && totpag.valore() > ZERO; r++)
|
||
{
|
||
TEC_row& s = row(r);
|
||
real imp = s.scaduto();
|
||
if (imp.sign() > 0)
|
||
{
|
||
if (imp >= totpag.valore())
|
||
{
|
||
imp -= totpag.valore();
|
||
s.scaduto(imp);
|
||
totpag = TImporto(sezione, ZERO);
|
||
}
|
||
else
|
||
{
|
||
s.scaduto(ZERO);
|
||
totpag -= TImporto(sezione, imp);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
TEC_array::TEC_array(const TPartita& game, const TEC_form* f)
|
||
: _form(f), _anal(LF_MOVANA, MOVANA_NUMREG, 3)
|
||
{
|
||
int r;
|
||
for (r = game.last(); r > 0; r = game.pred(r))
|
||
add_row(game.riga(r));
|
||
if (items() > 0)
|
||
{
|
||
const char sezione = game.conto().tipo() == 'C' ? 'D' : 'A';
|
||
for (r = items()-1; r >= 0; r--)
|
||
{
|
||
TEC_row& s = row(r);
|
||
if (s.rata() == RIGA_PAGAMENTO)
|
||
{
|
||
TImporto* imp = importo_riga_scaduto_ptr(s.riga());
|
||
if (imp != NULL)
|
||
{
|
||
imp->normalize(sezione);
|
||
s.scaduto(imp->valore());
|
||
}
|
||
}
|
||
}
|
||
sort();
|
||
arrange_scaduto(game);
|
||
}
|
||
}
|
||
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Form speciale per estratti conto
|
||
///////////////////////////////////////////////////////////
|
||
|
||
void TEC_form::stampa_testata(TPrinter& pr)
|
||
{
|
||
TPrint_section& head = section('H');
|
||
|
||
TForm_item& pagina = head.find_field(PEC_PAGINA);
|
||
TString16 pg; pg << int(pr.getcurrentpage());
|
||
pagina.set(pg);
|
||
|
||
head.update();
|
||
|
||
int r = head.height()-1;
|
||
if (r > 0)
|
||
{
|
||
TPrintrow& head_row = head.row(r-1);
|
||
for (int j = 0; j <= r; 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 h1->key().compare(h2->key(), -1, true); // was stricmp
|
||
}
|
||
|
||
word TEC_form::ordina_totali_per_valuta(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& arr = totali();
|
||
arr.restart();
|
||
word num_rip = 0;
|
||
for (THash_object* obj = arr.get_hashobj();
|
||
num_rip < MAXTOT && obj != NULL;
|
||
obj = arr.get_hashobj())
|
||
tot[num_rip++] = obj;
|
||
qsort(tot, num_rip, sizeof(THash_object*), tot_compare);
|
||
return num_rip;
|
||
}
|
||
|
||
void TEC_form::stampa_riporti(TPrinter& pr)
|
||
{
|
||
THash_object* tot[MAXTOT];
|
||
_num_rip = ordina_totali_per_valuta(tot);
|
||
|
||
if (_num_rip > _maxtot)
|
||
_num_rip = _maxtot;
|
||
|
||
const TString& riporto = describe(PEC_RIPORTO);
|
||
TString desc(80);
|
||
TPrint_section& body = section('B');
|
||
for (word j = 0; j < _num_rip; j++)
|
||
{
|
||
const TString& key = tot[j]->key();
|
||
TTotal& t = (TTotal&)(tot[j]->obj());
|
||
|
||
desc = riporto;
|
||
TValuta val;
|
||
if (key.not_empty())
|
||
{
|
||
desc << ' ' << key;
|
||
TValuta val1(key,botime,ZERO); // E' una valuta fittizia, giusto per far
|
||
val = val1; // eseguire in set_imp() i calcoli per i decimali.
|
||
}
|
||
TEC_row rip(desc, t.importo().normalize(),val);
|
||
rip.scaduto(t.scaduto());
|
||
rip.esposto(t.esposto());
|
||
rip.importo_euro(t.importo_euro());
|
||
rip.print_on(body);
|
||
pr.setfooterline(j+1, body.row(0));
|
||
}
|
||
}
|
||
|
||
int TEC_form::find_magic(TString& s, TString& magic1, TString& magic2) const
|
||
{
|
||
const int pos = s.find('<', 0);
|
||
int end;
|
||
if (pos >= 0)
|
||
{
|
||
end = s.find('>', pos);
|
||
if (end > pos)
|
||
{
|
||
int p1 = pos+1;
|
||
magic1 = s.mid(p1, 2);
|
||
while (isalnum(s[p1])) p1++;
|
||
while (p1 < end && !isalnum(s[p1])) p1++;
|
||
if (p1 < end)
|
||
magic2 = s.mid(p1, 2);
|
||
else
|
||
magic2.cut(0);
|
||
}
|
||
else
|
||
end = s.len()-1;
|
||
|
||
const TString right(s.mid(end+1));
|
||
s.cut(pos); s << right;
|
||
}
|
||
return pos;
|
||
}
|
||
|
||
void TEC_form::change_magic_body(const TEC_row& row, TString& s)
|
||
{
|
||
TString magic1(4), magic2(4), val(50);
|
||
int pos;
|
||
while ((pos = find_magic(s, magic1, magic2)) >= 0)
|
||
{
|
||
val.cut(0);
|
||
if (magic1 == "PA" || magic2 == "PA")
|
||
{
|
||
val = row.descrizione();
|
||
if (val.empty())
|
||
val = cache().get(LF_CAUSALI, row.causale()).get(CAU_DESCR);
|
||
}
|
||
if (magic1 == "MO" || magic2 == "MO")
|
||
{
|
||
val = cache().get(LF_MOV, row.num_reg()).get(MOV_DESCR);
|
||
}
|
||
s.insert(val, pos);
|
||
}
|
||
}
|
||
|
||
void TEC_form::change_magic_footer(const THash_object& o, TString& s)
|
||
{
|
||
TString magic1(4), magic2(4), val(50);
|
||
int pos;
|
||
while ((pos = find_magic(s, magic1, magic2)) >= 0)
|
||
{
|
||
val.cut(0);
|
||
if (magic1 == "DA") // DATA
|
||
{
|
||
const TDate& d = magic2 == "SC" ? _dls : _dlo;
|
||
if (d != eotime)
|
||
val = d.string();
|
||
} else
|
||
if (magic1 == "VA") // CODICE VALUTA
|
||
val = o.key(); else
|
||
if (magic1 == "DE") // DESCRIZIONE VALUTA
|
||
{
|
||
val = magic2 == "VA" ? o.key() : TCurrency::get_firm_val();
|
||
if (val.not_empty())
|
||
val = cache().get("%VAL", val).get("S0");
|
||
}
|
||
s.insert(val, pos);
|
||
}
|
||
}
|
||
|
||
void TEC_form::print_total(int riga, const THash_object& o)
|
||
{
|
||
const short MAXID = 4;
|
||
const short f_id[MAXID] = { PEC_TSALDO, PEC_TSCADUTO, PEC_TESPOSTO, PEC_TIMPEURO };
|
||
TString_array prompt(MAXID);
|
||
|
||
TPrint_section& foot = section('F');
|
||
TPrint_section& body = section('B');
|
||
TForm_item& bdesc = body.find_field(PEC_DESCR);
|
||
|
||
// Sostituisce magic-names nei prompt
|
||
TString80 s;
|
||
for (int i = 0; i < MAXID; i++)
|
||
{
|
||
TForm_item& desc_field = foot.find_field(f_id[i]);
|
||
if (desc_field.shown())
|
||
{
|
||
s = desc_field.prompt();
|
||
prompt.add(s, i);
|
||
change_magic_footer(o, s);
|
||
desc_field.set_prompt(s);
|
||
if (desc_field.x() <= 0)
|
||
desc_field.set_x(bdesc.x());
|
||
}
|
||
}
|
||
|
||
const TTotal& t = (const TTotal&)o.obj();
|
||
TImporto imp = t.importo(); imp.normalize();
|
||
|
||
const bool in_valuta = o.key().not_empty();
|
||
TForm_item& dare = foot.find_field(PEC_DARE);
|
||
TForm_item& avere = foot.find_field(PEC_AVERE);
|
||
TForm_item& valuta = foot.find_field(PEC_VALUTA);
|
||
|
||
if (in_valuta)
|
||
valuta.set(o.key());
|
||
else
|
||
valuta.set("");
|
||
|
||
if (dare.x() <= 0 || avere.x() <= 0)
|
||
{
|
||
TForm_item& bdare = body.find_field(PEC_DARE);
|
||
dare.set_x(bdare.x());
|
||
dare.width() = bdare.width();
|
||
|
||
TForm_item& bavere = body.find_field(PEC_AVERE);
|
||
avere.set_x(bavere.x());
|
||
avere.width() = bavere.width();
|
||
}
|
||
|
||
if (imp.sezione() == 'D')
|
||
{
|
||
dare.set(imp.valore().string());
|
||
avere.set("");
|
||
}
|
||
else
|
||
{
|
||
dare.set("");
|
||
avere.set(imp.valore().string());
|
||
}
|
||
|
||
TForm_item& scaduto = foot.find_field(PEC_SCADUTO);
|
||
if (scaduto.x() <= 0)
|
||
{
|
||
TForm_item& bscaduto = body.find_field(PEC_SCADUTO);
|
||
scaduto.set_x(bscaduto.x());
|
||
scaduto.width() = bscaduto.width();
|
||
}
|
||
scaduto.set(t.scaduto().string());
|
||
|
||
TForm_item& esposto = foot.find_field(PEC_ESPOSTO);
|
||
if (esposto.x() <= 0)
|
||
{
|
||
TForm_item& besposto = body.find_field(PEC_ESPOSTO);
|
||
esposto.set_x(besposto.x());
|
||
esposto.width() = besposto.width();
|
||
}
|
||
esposto.set(t.esposto().string());
|
||
|
||
TForm_item& implire = foot.find_field(PEC_IMPEURO);
|
||
if (implire.x() <= 0)
|
||
{
|
||
TForm_item& bimplire = body.find_field(PEC_IMPEURO);
|
||
implire.set_x(bimplire.x());
|
||
esposto.width() = bimplire.width();
|
||
if (bimplire.shown())
|
||
implire.show();
|
||
else
|
||
implire.hide();
|
||
}
|
||
implire.set(t.importo_euro().string());
|
||
|
||
foot.update();
|
||
|
||
// Ripristina prompt originari
|
||
for (int i = 0; i < MAXID; i++)
|
||
{
|
||
const TString* p = (const TString*)prompt.objptr(i);
|
||
if (p)
|
||
{
|
||
TForm_item& desc_field = foot.find_field(f_id[i]);
|
||
desc_field.set_prompt(*p);
|
||
}
|
||
}
|
||
|
||
for (word r = 0; r < _total_rows; r++)
|
||
printer().setfooterline(riga + r, foot.row(r));
|
||
}
|
||
|
||
void TEC_form::stampa_pedata()
|
||
{
|
||
THash_object* tot[MAXTOT];
|
||
word num_rip = ordina_totali_per_valuta(tot);
|
||
|
||
if (num_rip > _maxtot)
|
||
num_rip = _maxtot;
|
||
|
||
for (word j = 0; j < num_rip; j++)
|
||
print_total(j*_total_rows+1, *tot[j]);
|
||
}
|
||
|
||
void TEC_form::export_total()
|
||
{
|
||
THash_object* tot[MAXTOT];
|
||
word num_rip = ordina_totali_per_valuta(tot);
|
||
for (word j = 0; j < num_rip; j++)
|
||
{
|
||
_recordset->new_rec();
|
||
|
||
const THash_object& o = *tot[j];
|
||
const TTotal& t = (const TTotal&)o.obj();
|
||
|
||
TString descr; descr << "*** " << TR("Totale") << ' ' << o.key();
|
||
_recordset->set("Descrizione", TVariant(descr));
|
||
_recordset->set(t.importo().sezione() == 'D' ? "Dare" : "Avere", t.importo().valore());
|
||
_recordset->set("Scaduto", t.scaduto());
|
||
_recordset->set("Esposto", t.esposto());
|
||
|
||
// _recordset->new_rec();
|
||
}
|
||
}
|
||
|
||
void TEC_form::ultima_pagina()
|
||
{
|
||
set_last_page(true);
|
||
}
|
||
|
||
void TEC_form::ec_header_handler(TPrinter& pr)
|
||
{
|
||
pr.resetheader();
|
||
_form->stampa_testata(pr);
|
||
}
|
||
|
||
void TEC_form::ec_footer_handler(TPrinter& pr)
|
||
{
|
||
pr.resetfooter();
|
||
if (_form->page(pr) > 0) // Normal page
|
||
_form->stampa_riporti(pr);
|
||
else // Last page
|
||
_form->stampa_pedata();
|
||
}
|
||
|
||
void TEC_form::azzera_totali()
|
||
{
|
||
totali().destroy(); // Azzera tutti i riporti
|
||
_num_rip = 0; // Azzera il numero di righe di riporto
|
||
set_last_page(false); // Azzera il flag di ultima pagina di stampa
|
||
|
||
if (printing())
|
||
{
|
||
TPrint_section& foot = section('F');
|
||
printer().footerlen(foot.height());
|
||
printer().setcurrentpage(1);
|
||
}
|
||
}
|
||
|
||
bool TEC_form::print_game(const TPartita& game)
|
||
{
|
||
bool ok = false;
|
||
|
||
TEC_array righe(game, this);
|
||
|
||
|
||
TPrint_section& body = section('B');
|
||
|
||
TImporto saldo;
|
||
real scaduto, esposto, implire, impval;
|
||
|
||
// Stampa le righe di partita
|
||
|
||
int ultima_riga = 0;
|
||
int ultima_rata = 0;
|
||
int r;
|
||
for (r = 0; r < righe.items(); r++)
|
||
{
|
||
if (printing())
|
||
{
|
||
TPrinter& pr = printer();
|
||
if (pr.rows_left() <= (body.height()+1)) // salto pagina
|
||
{
|
||
pr.formfeed();
|
||
for (word nr = 0; nr < _num_rip; nr++)
|
||
{
|
||
TPrintrow* fl = pr.getfooterline(nr + 1);
|
||
CHECKD(fl, "Manca la riga di riporto ", nr + 1);
|
||
pr.print(*fl);
|
||
}
|
||
}
|
||
}
|
||
|
||
TEC_row& riga = righe.row(r);
|
||
const int ri = riga.riga();
|
||
const int ra = riga.rata();
|
||
if (ri == ultima_riga && ra == ultima_rata+1)
|
||
riga.reset_uguali();
|
||
ultima_riga = ri;
|
||
ultima_rata = ra;
|
||
|
||
if (printing())
|
||
{
|
||
riga.print_on(body);
|
||
|
||
const int h = body.height();
|
||
|
||
for (int i = 0; i < h; i++)
|
||
printer().print(body.row(i));
|
||
}
|
||
else
|
||
riga.export_to(*_recordset);
|
||
|
||
TString4 codval;
|
||
if (in_valuta())
|
||
codval = riga.valuta().codice();
|
||
|
||
totali().add(riga.importo(), riga.scaduto(), riga.esposto(),
|
||
riga.importo_euro(), codval);
|
||
|
||
saldo += riga.importo();
|
||
scaduto += riga.scaduto();
|
||
esposto += riga.esposto();
|
||
implire += riga.importo_euro();
|
||
impval += riga.importo_valuta();
|
||
ok = true;
|
||
}
|
||
|
||
if (ok && stampa_saldo())
|
||
{
|
||
saldo.normalize();
|
||
|
||
const TString & dessaldo = describe(PEC_SALDO);
|
||
TString80 desc = dessaldo;
|
||
const TValuta& val = righe.row(r-1).valuta();
|
||
|
||
if (in_valuta() && val.in_valuta()) // Aggiunge alla descrizione il codice valuta se necessario
|
||
desc << ' ' << val.codice();
|
||
|
||
TEC_row sld(desc, saldo, val);
|
||
|
||
sld.scaduto(scaduto);
|
||
sld.esposto(esposto);
|
||
sld.importo_euro(implire);
|
||
sld.importo_valuta(impval);
|
||
|
||
if (printing())
|
||
{
|
||
sld.print_on(body);
|
||
printer().print(body.row(0));
|
||
}
|
||
else
|
||
sld.export_to(*_recordset);
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
const TString& TEC_form::describe(short id, char sez, pagetype pt) const
|
||
{
|
||
const TForm_item& fi = find_field(sez, pt, id);
|
||
return fi.prompt();
|
||
}
|
||
|
||
void TEC_form::init_header(const TMask& m)
|
||
{
|
||
TPrint_section& head = section('H');
|
||
|
||
TForm_item& luogo_invio = head.find_field(PEC_LUOGOIN);
|
||
luogo_invio.set(m.get(F_LUOGOSEND));
|
||
|
||
TForm_item& data_invio = head.find_field(PEC_DATAIN);
|
||
data_invio.set(m.get(F_DATASEND));
|
||
|
||
TForm_item& fi = head.find_field(PEC_MEMO);
|
||
if (fi.shown())
|
||
{
|
||
TString key;
|
||
|
||
key.format("%s|%s|H0|%d", (const char *) name(), (const char *) code(), PEC_MEMO);
|
||
|
||
const TRectype & rform = cache().get(LF_RFORM, key);
|
||
if (!rform.empty())
|
||
fi.set(rform.get("TESTO"));
|
||
}
|
||
|
||
// Sistema campi che si riferiscono a CLIFO in una stampa per Conto
|
||
if (relation()->log2ind(LF_CLIFO) < 0)
|
||
{
|
||
for (word i = 0; i < head.fields(); i++)
|
||
{
|
||
TForm_item& fi = head.field(i);
|
||
if (fi.fields() > 0 && strcmp(fi.class_name(), "STRINGA") == 0)
|
||
{
|
||
for (int f = 0; f < fi.fields(); f++)
|
||
{
|
||
TFieldref& fr = ((TForm_string&)fi).field(f);
|
||
if (fr.id() == "13")
|
||
{
|
||
fi.disable();
|
||
} else
|
||
if (fr.id() == "20")
|
||
{
|
||
if (fr.name() == CLI_RAGSOC)
|
||
{
|
||
fr.set_file(LF_PCON);
|
||
fr.set_name(PCN_DESCR);
|
||
} else
|
||
if (fr.name() == CLI_CODCF)
|
||
{
|
||
fr.set_file(LF_PCON);
|
||
fr.set_name(PCN_SOTTOCONTO);
|
||
}
|
||
else
|
||
fi.disable();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
TPrint_section& fink = section('G');
|
||
if (fink.fields() > 0)
|
||
fink.update(); // Setta il backgroud di stampa
|
||
}
|
||
|
||
void TEC_form::set_pagam(const TString& codpag)
|
||
{
|
||
const bool good = codpag.full();
|
||
|
||
TPrint_section& head = section('H');
|
||
TForm_item& pagam = head.find_field(PEC_PAGAM);
|
||
|
||
if (pagam.shown()|| pagam.enabled())
|
||
{
|
||
TString pag;
|
||
pag << codpag << ' ' << cache().get("%CPG", codpag, "S0");
|
||
|
||
if (printing())
|
||
pagam.set(pag);
|
||
else
|
||
{
|
||
_recordset->new_rec();
|
||
_recordset->set("Descrizione", pag);
|
||
_recordset->new_rec();
|
||
}
|
||
}
|
||
}
|
||
|
||
void TEC_form::set_agente(const TString& codag)
|
||
{
|
||
const bool good = codag.full();
|
||
|
||
TPrint_section& head = section('H');
|
||
TForm_item& agente = head.find_field(PEC_AGENTE);
|
||
agente.show(good);
|
||
|
||
if (good)
|
||
{
|
||
TString ag;
|
||
ag << codag << ' ' << cache().get(LF_AGENTI, codag, AGE_RAGSOC);
|
||
|
||
if (printing())
|
||
{
|
||
agente.set(ag);
|
||
}
|
||
else
|
||
{
|
||
_recordset->new_rec();
|
||
_recordset->set("Descrizione", ag);
|
||
_recordset->new_rec();
|
||
}
|
||
}
|
||
}
|
||
|
||
TEC_form::TEC_form(const TEC_mask& m, bool gesval, bool excel)
|
||
: TForm(BASE_EC_PROFILE, m.get_prof_name()), _recordset(NULL),
|
||
_in_valuta(false), _stampa_saldo(true), _num_rip(0), _total_rows(0)
|
||
{
|
||
_form = this;
|
||
|
||
TCursor_sheet& cs = m.cur_sheet();
|
||
_cursore = cs.cursor();
|
||
|
||
if (relation()->log2ind(LF_COMUNI) < 0)
|
||
{
|
||
if (relation()->file().num() == LF_CLIFO)
|
||
relation()->add(LF_COMUNI, "STATO==STATOCF|COM==COMCF");
|
||
else
|
||
relation()->add(LF_COMUNI, "COM=\"\"");
|
||
}
|
||
|
||
|
||
_lingua = m.get_prof_lang(); // Lingua profilo
|
||
_dlo = m.get(F_DATALIMOP);
|
||
if (!_dlo.ok())
|
||
_dlo = eotime;
|
||
_dls = m.get(F_DATALIMSC);
|
||
_giorni_rischio = m.get_int(F_GIORISCH);
|
||
_dir = _dls; _dir -= _giorni_rischio;
|
||
_note_scadenti = m.get_bool(F_NC_SCAD);
|
||
|
||
TForm_item& flags = find_field('H', last_page, PEC_FLAGS);
|
||
|
||
TToken_string f(flags.prompt());
|
||
_in_valuta = gesval && f.get_char(0) == 'X'; // Il profilo e' in valuta se c'e' il flag di valuta
|
||
_fincatura = f.get_int(1);
|
||
|
||
const int oem = ini_get_int(CONFIG_OEM, "MAIN", "OEM", -1);
|
||
|
||
if (oem == 0 && main_app().has_module(CAAUT))
|
||
{
|
||
TForm_item& codanal = _form->find_field('B', odd_page, PEC_ANALITICA);
|
||
codanal.show();
|
||
}
|
||
|
||
if (!excel)
|
||
{
|
||
TPrinter& pr = printer();
|
||
|
||
pr.setheaderhandler(ec_header_handler);
|
||
TPrint_section& head = section('H');
|
||
pr.headerlen(head.height());
|
||
|
||
pr.setfooterhandler(ec_footer_handler);
|
||
const TPrint_section& foot = section('F');
|
||
pr.footerlen(foot.height());
|
||
|
||
if (_fincatura > 0)
|
||
{
|
||
const int first = head.height()-2;
|
||
const int last = pr.formlen();
|
||
const int horiz[] = { first+2, last-foot.height()+1, 0 };
|
||
set_fink_mode(_fincatura == 1 ? false : true);
|
||
genera_fincatura(odd_page, first, last, horiz);
|
||
}
|
||
|
||
TForm_item& uns = section('F').find_field(PEC_UNASSIGNED);
|
||
TForm_item& tuns = section('F').find_field(PEC_TUNASSIGNED);
|
||
if (uns.shown()) uns.hide();
|
||
if (tuns.shown()) tuns.hide();
|
||
|
||
genera_intestazioni(odd_page, head.height() - 1);
|
||
init_header(m); // Set fixed text
|
||
|
||
_total_rows = 1;
|
||
for (word fi = 0; fi < foot.fields(); fi++)
|
||
{
|
||
const TForm_item& item = foot.field(fi);
|
||
if (item.shown())
|
||
{
|
||
const word y = (word)item.y();
|
||
if (y > _total_rows)
|
||
_total_rows = y;
|
||
}
|
||
}
|
||
|
||
_maxtot = f.get_int(3);
|
||
|
||
// La prima e l'ultima riga del footer devono essere lasciate libere per la fincatura
|
||
// Ogni totale occupa _total_rows righe: per cui posso calcolare il massimo di totali
|
||
// che posso stampare nel footer.
|
||
const word max = (foot.height() - 2) / _total_rows;
|
||
if (_maxtot <= 0 || _maxtot > max)
|
||
_maxtot = max;
|
||
}
|
||
else
|
||
_recordset = new TEC_recordset(m.get_who());
|
||
}
|
||
|
||
TEC_form::~TEC_form()
|
||
{
|
||
if (printing())
|
||
{
|
||
TPrinter& pr = printer();
|
||
pr.setheaderhandler(NULL);
|
||
pr.setfooterhandler(NULL);
|
||
}
|
||
else
|
||
{
|
||
delete _recordset;
|
||
}
|
||
_form = NULL;
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TEC_gamelist
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TEC_Game_list
|
||
{
|
||
TAssoc_array _games;
|
||
|
||
protected:
|
||
void signature(const TRectype& rec, TToken_string& signature) const;
|
||
|
||
public:
|
||
void add_game(const TRectype& rec);
|
||
bool has_clifo(long codcf);
|
||
bool has_game(const TRectype& rec);
|
||
};
|
||
|
||
void TEC_Game_list::signature(const TRectype& rec, TToken_string& signature) const
|
||
{
|
||
signature = rec.get(SCAD_TIPOCF);
|
||
signature.add(rec.get(SCAD_SOTTOCONTO));
|
||
signature.add(rec.get(SCAD_ANNO));
|
||
signature.add(rec.get(SCAD_NUMPART));
|
||
signature.strip_spaces();
|
||
}
|
||
|
||
void TEC_Game_list::add_game(const TRectype& rec)
|
||
{
|
||
TToken_string signat; signature(rec, signat);
|
||
_games.add(signat);
|
||
}
|
||
|
||
bool TEC_Game_list::has_clifo(long codcf)
|
||
{
|
||
TToken_string signat;
|
||
FOR_EACH_ASSOC_OBJECT(_games, obj, key, str)
|
||
{
|
||
signat = key;
|
||
if (signat.get_long(1) == codcf)
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
bool TEC_Game_list::has_game(const TRectype& rec)
|
||
{
|
||
TToken_string signat; signature(rec, signat);
|
||
return _games.is_key(signat);
|
||
}
|
||
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Stampa estratti conto
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TStampaEC_application : public TSkeleton_application
|
||
{
|
||
TEC_mask* _msk;
|
||
TEC_form* _form;
|
||
|
||
TString _lingua_ditta;
|
||
bool _gesval; // Gestione valuta
|
||
char _tiponumec; // Tipo numerazione EC ' ', 'G', 'A'
|
||
long _lastnumec; // Ultimo numero EC 'G'
|
||
TAssoc_array _lastnumcf; // Ultimo numero stampato 'A'
|
||
|
||
protected: // TSkeleton_application
|
||
virtual bool create();
|
||
virtual bool destroy();
|
||
virtual void main_loop();
|
||
virtual void on_firm_change();
|
||
virtual void on_config_change();
|
||
|
||
void find_agents_scads(TAssoc_array& agents);
|
||
void find_agents_unassigned_pags(TAssoc_array& agents);
|
||
|
||
public:
|
||
static TStampaEC_application& app() { return (TStampaEC_application&)main_app(); }
|
||
long find_agents_games(TAssoc_array& agents);
|
||
|
||
TEC_mask& mask() { return *_msk; }
|
||
TCursor_sheet& sheet() { return _msk->cur_sheet(); }
|
||
TEC_form& form() { return *_form; }
|
||
void update_numec(const TRectype& clf, int sign);
|
||
void save_numec();
|
||
|
||
bool print_selected(); // print selected items
|
||
bool print_agents(); // print selected items by agent
|
||
int print_ec(TEC_Game_list* games = NULL); // print one ec only
|
||
|
||
TStampaEC_application();
|
||
virtual ~TStampaEC_application() {}
|
||
};
|
||
|
||
bool TStampaEC_application::print_selected()
|
||
{
|
||
const char who = mask().get_who();
|
||
|
||
TCursor_sheet& s = sheet();
|
||
TCursor& c = *s.cursor(); // Il cursore del form coincide con quello dello sheet
|
||
|
||
/*
|
||
const int key = mask().get_key();
|
||
|
||
// Filtra il cursore del form in modo che diventi uguale al cursor_sheet corrente
|
||
// Qui sarebbe bello copiarsi l'indice dell'altro cursore
|
||
TCursor& fc = *form().cursor();
|
||
fc.setkey(key);
|
||
|
||
if (who >= 'C')
|
||
{
|
||
TRectype filter = fc.curr(); filter.zero();
|
||
filter.put(CLI_TIPOCF, who);
|
||
fc.setregion(filter, filter);
|
||
}
|
||
*/
|
||
|
||
form().set_agente(EMPTY_STRING); // Nascondi agente
|
||
|
||
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
|
||
const bool printing = form().printing();
|
||
const long items = c.items();
|
||
|
||
TProgress_monitor* pi = NULL;
|
||
if (printing)
|
||
printer().open();
|
||
else
|
||
pi = new TProgress_monitor(items, TR("Calcolo estratto conto"));
|
||
|
||
for (long i = 0; i < items; i++)
|
||
{
|
||
if (print_all || s.checked(i))
|
||
{
|
||
c = i; // Muove il cursore alla posizione corrente
|
||
const int ret = print_ec();
|
||
if (ret < 0)
|
||
analfabeti++;
|
||
}
|
||
|
||
if (printing)
|
||
{
|
||
if (printer().frozen())
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
if (!pi->addstatus(1))
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (printing)
|
||
{
|
||
printer().close();
|
||
if (_tiponumec > ' ' && who == 'C')
|
||
save_numec();
|
||
|
||
if (analfabeti > 0)
|
||
{
|
||
const char* anag = who == 'C' ? TR("clienti") : TR("fornitori");
|
||
warning_box(FR("%ld %s non sono stati stampati in quanto "
|
||
"il codice lingua non corrispondeva al profilo di stampa"),
|
||
analfabeti, anag);
|
||
}
|
||
}
|
||
else
|
||
delete pi;
|
||
|
||
return true;
|
||
}
|
||
|
||
void TStampaEC_application::find_agents_scads(TAssoc_array& agents)
|
||
{
|
||
const TString& fromage = mask().get(F_FROM_AGENT);
|
||
const TString& toage = mask().get(F_TO_AGENT);
|
||
const long fromcli = mask().get_long(SC_CFCODFR);
|
||
const long tocli = mask().get_long(SC_CFCODTO);
|
||
|
||
TRelation rel(LF_SCADENZE);
|
||
rel.add(LF_PAGSCA, "TIPOC==TIPOC|GRUPPO==GRUPPO|CONTO==CONTO|SOTTOCONTO==SOTTOCONTO|"
|
||
"ANNO==ANNO|NUMPART==NUMPART|NRIGA==NRIGA|NRATA==NRATA");
|
||
|
||
TRectype& curr = rel.curr();
|
||
const TRectype& pagsca = rel.curr(LF_PAGSCA);
|
||
|
||
curr.put(SCAD_TIPOCF, mask().get(SC_CLIFO));
|
||
TRectype recfr(curr), recto(curr);
|
||
if (fromcli > 0)
|
||
recfr.put(PAGSCA_SOTTOCONTO, fromcli);
|
||
if (tocli >= fromcli)
|
||
recto.put(PAGSCA_SOTTOCONTO, tocli);
|
||
|
||
TString filter;
|
||
if (!mask().get_bool(F_STAMPCHIU))
|
||
filter << "PAGATA!=\"X\"";
|
||
TCursor cur(&rel, filter, 1, &recfr, &recto);
|
||
const long items = cur.items();
|
||
cur.freeze();
|
||
|
||
TProgind pi(items, TR("Ricerca scadenze aperte per agente..."), true, true);
|
||
for (cur = 0L; cur.pos() < items; ++cur)
|
||
{
|
||
if (!pi.addstatus(1))
|
||
break;
|
||
|
||
const char* codag = pagsca.get(PAGSCA_CODAG);
|
||
if (*codag == '\0')
|
||
{
|
||
codag = curr.get(SCAD_CODAG);
|
||
if (*codag == '\0')
|
||
continue;
|
||
}
|
||
if (fromage.not_empty() && fromage > codag)
|
||
continue;
|
||
if (toage.not_empty() && toage < codag)
|
||
continue;
|
||
|
||
TEC_Game_list* games = (TEC_Game_list*)agents.objptr(codag);
|
||
if (games == NULL)
|
||
{
|
||
games = new TEC_Game_list;
|
||
agents.add(codag, (TObject*)games);
|
||
}
|
||
games->add_game(curr);
|
||
}
|
||
}
|
||
|
||
void TStampaEC_application::find_agents_unassigned_pags(TAssoc_array& agents)
|
||
{
|
||
TEC_mask& m = mask();
|
||
const char tipocf = m.get(SC_CLIFO)[0];
|
||
if (tipocf < 'C')
|
||
return;
|
||
|
||
const TString& fromage = m.get(F_FROM_AGENT);
|
||
const TString& toage = m.get(F_TO_AGENT);
|
||
const long fromcli = m.get_long(SC_CFCODFR);
|
||
const long tocli = m.get_long(SC_CFCODTO);
|
||
|
||
TRelation rel(LF_PAGSCA);
|
||
TRectype& curr = rel.curr();
|
||
curr.put(PAGSCA_TIPOC, tipocf); // Imposta C o F
|
||
|
||
TRectype recfr(curr), recto(curr);
|
||
if (fromcli > 0)
|
||
recfr.put(PAGSCA_SOTTOCONTO, fromcli); // Imposta cliente iniziale
|
||
if (tocli >= fromcli)
|
||
recto.put(PAGSCA_SOTTOCONTO, tocli); // Imposta cliente finale
|
||
|
||
TString filter;
|
||
filter << '(' << PAGSCA_NRATA <<"==9999)";
|
||
if (fromage.full())
|
||
filter << "&&(" << PAGSCA_CODAG << ">='" << fromage << "')";
|
||
else
|
||
filter << "&&(" << PAGSCA_CODAG << "!='')";
|
||
if (toage.full())
|
||
filter << "&&(" << PAGSCA_CODAG << "<='" << toage << "')";
|
||
|
||
TCursor cur(&rel, filter, 1, &recfr, &recto);
|
||
const long items = cur.items();
|
||
if (items > 0)
|
||
{
|
||
cur.freeze();
|
||
TProgind pi(items, TR("Ricerca pagamenti non assegnati per agente..."), true, true);
|
||
for (cur = 0L; cur.pos() < items; ++cur)
|
||
{
|
||
if (!pi.addstatus(1))
|
||
break;
|
||
const char* codag = curr.get(PAGSCA_CODAG);
|
||
TEC_Game_list* games = (TEC_Game_list*)agents.objptr(codag);
|
||
if (games == NULL)
|
||
{
|
||
games = new TEC_Game_list;
|
||
agents.add(codag, (TObject*)games);
|
||
}
|
||
games->add_game(curr);
|
||
}
|
||
}
|
||
}
|
||
|
||
long TStampaEC_application::find_agents_games(TAssoc_array& agents)
|
||
{
|
||
find_agents_scads(agents);
|
||
find_agents_unassigned_pags(agents);
|
||
return agents.items();
|
||
}
|
||
|
||
bool TStampaEC_application::print_agents()
|
||
{
|
||
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 modo 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 bool printing = form().printing();
|
||
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
|
||
|
||
TAssoc_array agents;
|
||
const long totag = find_agents_games(agents);
|
||
if (totag <= 0)
|
||
return false;
|
||
|
||
TRelation rel(LF_AGENTI);
|
||
TCursor cur(&rel);
|
||
const long items = cur.items();
|
||
cur.freeze();
|
||
|
||
TProgind* pi = NULL;
|
||
if (printing)
|
||
printer().open();
|
||
else
|
||
pi = new TProgind(items, "Calcolo estratto conto", true, true);
|
||
|
||
for (cur = 0L; cur.pos() < items; ++cur)
|
||
{
|
||
const TString& codag = cur.curr().get(AGE_CODAGE);
|
||
TEC_Game_list* games = (TEC_Game_list*)agents.objptr(codag);
|
||
|
||
if (games != NULL)
|
||
{
|
||
form().set_agente(codag);
|
||
form().set_pagam(fc.curr().get(CLI_CODPAG));
|
||
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 long codcf = fc.curr().get_long(CLI_CODCF);
|
||
if (games->has_clifo(codcf))
|
||
{
|
||
const int ret = print_ec(games);
|
||
if (ret < 0)
|
||
analfabeti++;
|
||
}
|
||
}
|
||
if (printing)
|
||
{
|
||
if (printer().frozen())
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
if (!pi->addstatus(1))
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if (printing)
|
||
{
|
||
printer().close();
|
||
if (_tiponumec > ' ' && who == 'C')
|
||
save_numec();
|
||
|
||
if (analfabeti > 0)
|
||
{
|
||
const char* anag = who == 'C' ? TR("clienti") : TR("fornitori");
|
||
warning_box(FR("%ld %s non sono stati stampati, avendo "
|
||
"il codice lingua non corrispondente al profilo di stampa"),
|
||
analfabeti, anag);
|
||
}
|
||
}
|
||
else
|
||
delete pi;
|
||
|
||
|
||
return true;
|
||
}
|
||
|
||
|
||
void TStampaEC_application::save_numec()
|
||
{
|
||
// Ho numerato qualche estratto conto?
|
||
if (_lastnumcf.items() > 0 && form().printing())
|
||
{
|
||
if (yesno_box(TR("Si desidera aggiornare il numero di estratto conto stampato definitivamente?")))
|
||
{
|
||
TProgind pi(_lastnumcf.items(), TR("Aggiornamento numero estratto conto..."), false, true);
|
||
const char tipocf = mask().get_who(); // Dovrebbe essere sempre 'C'
|
||
TLocalisamfile cfven(LF_CFVEN);
|
||
FOR_EACH_ASSOC_STRING(_lastnumcf, obj, key, str)
|
||
{
|
||
pi.addstatus(1);
|
||
cfven.put(CFV_TIPOCF, tipocf);
|
||
cfven.put(CFV_CODCF, key);
|
||
const int err = cfven.read();
|
||
if (err != NOERR)
|
||
{
|
||
cfven.zero();
|
||
cfven.put(CFV_TIPOCF, tipocf);
|
||
cfven.put(CFV_CODCF, key);
|
||
}
|
||
cfven.put("NUMESC", str);
|
||
cfven.put("DATAESC", mask().get(F_DATASEND));
|
||
if (err == NOERR)
|
||
cfven.rewrite();
|
||
else
|
||
cfven.write();
|
||
}
|
||
if (_tiponumec == 'G')
|
||
{
|
||
TConfig c(CONFIG_DITTA, "cg");
|
||
c.set("LastEC", _lastnumec);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// Ripristino vecchio numero di estratto conto sulla maschera
|
||
if (_tiponumec == 'G')
|
||
{
|
||
TConfig c(CONFIG_DITTA, "cg");
|
||
_lastnumec = c.get_long("LastEC");
|
||
}
|
||
}
|
||
_lastnumcf.destroy(); // Azzera comunque elenco EC stampati
|
||
}
|
||
}
|
||
|
||
void TStampaEC_application::update_numec(const TRectype& clf, int sign)
|
||
{
|
||
const char tipocf = clf.exist(CLI_TIPOCF) ? clf.get_char(CLI_TIPOCF) : ' ';
|
||
if (_tiponumec > ' ' && tipocf == 'C' && form().printing())
|
||
{
|
||
TForm_item& nec = form().find_field('H', odd_page, PEC_NUMPROG);
|
||
if (nec.shown())
|
||
{
|
||
const TString8 codcf = clf.get(CLI_CODCF);
|
||
TString16 num;
|
||
switch(_tiponumec)
|
||
{
|
||
case 'A':
|
||
if (sign > 0)
|
||
{
|
||
TString16 key;
|
||
key.format("%c|%s", tipocf, (const char*)codcf);
|
||
const TRectype& cfven = cache().get(LF_CFVEN, key);
|
||
num << (cfven.get_long("NUMESC")+1);
|
||
}
|
||
break;
|
||
case 'G':
|
||
if (sign > 0)
|
||
{
|
||
_lastnumec++;
|
||
num << _lastnumec;
|
||
}
|
||
else
|
||
_lastnumec--;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
if (num.full())
|
||
{
|
||
nec.set(num);
|
||
_lastnumcf.add(codcf, num);
|
||
}
|
||
else
|
||
_lastnumcf.remove(codcf);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
// Nuovo modo con cursore
|
||
int TStampaEC_application::print_ec(TEC_Game_list* games)
|
||
{
|
||
TWait_cursor hourglass;
|
||
|
||
TEC_form& f = form();
|
||
const bool printing = f.printing();
|
||
|
||
const TRectype& clf = f.cursor()->curr();
|
||
|
||
if (printing && clf.num() == LF_CLIFO)
|
||
{
|
||
// make controllations per lingua profilo/CF
|
||
const TString& lincf = clf.get(CLI_CODLIN);
|
||
bool ok = true;
|
||
if ((f.lingua() == _lingua_ditta && lincf.full()) ||
|
||
f.lingua() != _lingua_ditta)
|
||
ok = lincf == f.lingua();
|
||
if (!ok) // Cliente analfabeta
|
||
return -1;
|
||
}
|
||
TToken_string key(clf.get(CLI_TIPOCF));
|
||
|
||
key.add(clf.get(CLI_CODCF));
|
||
form().set_agente(cache().get(LF_CFVEN, key, CFV_CODAG));
|
||
form().set_pagam(clf.get(CLI_CODPAG));
|
||
|
||
f.azzera_totali(); // Azzera totali di fine pagina
|
||
|
||
// Filtra solo le partite del cliente selezionato
|
||
TRelation rel(LF_PARTITE);
|
||
TRectype& curr = rel.curr();
|
||
if (clf.num() == LF_CLIFO)
|
||
{
|
||
curr.put(PART_TIPOCF, clf.get(CLI_TIPOCF));
|
||
curr.put(PART_SOTTOCONTO, clf.get(CLI_CODCF));
|
||
}
|
||
else
|
||
{
|
||
curr.zero(PART_TIPOCF);
|
||
curr.put(PART_GRUPPO, clf.get(PCN_GRUPPO));
|
||
curr.put(PART_CONTO, clf.get(PCN_CONTO));
|
||
curr.put(PART_SOTTOCONTO, clf.get(PCN_SOTTOCONTO));
|
||
}
|
||
TCursor cur(&rel, "", 1, &curr, &curr);
|
||
|
||
const long items = cur.items();
|
||
cur.freeze();
|
||
|
||
const bool stampa_chiuse = mask().get_bool(F_STAMPCHIU);
|
||
const TDate data_chiuse = mask().get(F_DATACHIU);
|
||
|
||
TString status;
|
||
|
||
int printed = 0; // Non ho stampato ancora nulla
|
||
|
||
if (printing && clf.num() == LF_CLIFO)
|
||
update_numec(clf, +1); // Incrementa contatore
|
||
|
||
TString8 last_game;
|
||
int last_year = 0;
|
||
|
||
for (cur = 0; cur.pos() < items; ++cur)
|
||
{
|
||
const int curr_year = curr.get_int(PART_ANNO);
|
||
const TString& curr_game = curr.get(PART_NUMPART);
|
||
if (curr_year == last_year && curr_game == last_game)
|
||
continue;
|
||
last_game = curr_game;
|
||
last_year = curr_year;
|
||
|
||
// Non fregare i clienti agli altri agenti!
|
||
if (games != NULL && !games->has_game(curr))
|
||
continue;
|
||
|
||
TPartita game(curr);
|
||
|
||
status.cut(0);
|
||
status << game.anno() << ' ' << game.numero();
|
||
xvtil_statbar_set(status);
|
||
do_events();
|
||
|
||
const TDate& dir = f.data_inizio_rischio();
|
||
const TDate& dlo = f.data_limite_operazione();
|
||
const TDate& dls = f.data_limite_scaduto();
|
||
const TImporto saldo = game.calcola_saldo_al(f.in_valuta(), dlo, dls, dir);
|
||
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_chiuse)
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if (r == 0)
|
||
continue;
|
||
}
|
||
|
||
if (printing)
|
||
{
|
||
if (printed)
|
||
{
|
||
TPrintrow empty; // Salta una riga vuota
|
||
printer().print(empty); // (Non farlo alla fine di ogni partita!)
|
||
}
|
||
if (printer().frozen())
|
||
break;
|
||
}
|
||
|
||
if (f.print_game(game))
|
||
printed++;
|
||
}
|
||
|
||
if (printing)
|
||
{
|
||
if (printed > 0)
|
||
{
|
||
f.ultima_pagina();
|
||
printer().formfeed();
|
||
}
|
||
else
|
||
update_numec(clf, -1);
|
||
}
|
||
else
|
||
{
|
||
if (printed > 0 && f.stampa_saldo())
|
||
{
|
||
f.export_total();
|
||
// f.recordset().new_rec();
|
||
}
|
||
}
|
||
|
||
xvtil_statbar_set(NULL);
|
||
|
||
return printed;
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Generic TApplication methods
|
||
///////////////////////////////////////////////////////////
|
||
|
||
bool TStampaEC_application::create()
|
||
{
|
||
open_files(LF_TABCOM, LF_TAB, LF_CAUSALI, LF_MOV, LF_RMOV, 0);
|
||
open_files(LF_NDITTE, LF_ANAG, LF_COMUNI, LF_RFORM, 0);
|
||
open_files(LF_CLIFO, LF_PARTITE, LF_SCADENZE, LF_PAGSCA ,0);
|
||
_msk = new TEC_mask("sc2100a");
|
||
return TSkeleton_application::create();
|
||
}
|
||
|
||
bool TStampaEC_application::destroy()
|
||
{
|
||
delete _msk;
|
||
return TSkeleton_application::destroy();
|
||
}
|
||
|
||
void TStampaEC_application::on_firm_change()
|
||
{
|
||
mask().reset();
|
||
TApplication::on_firm_change();
|
||
}
|
||
|
||
void TStampaEC_application::on_config_change()
|
||
{
|
||
TConfig c(CONFIG_DITTA, "cg");
|
||
_lingua_ditta = c.get("CodLin");
|
||
_gesval = c.get_bool("GesVal");
|
||
_tiponumec = c.get_char("NumEC");
|
||
_lastnumec = c.get_long("LastEC");
|
||
}
|
||
|
||
void TStampaEC_application::main_loop()
|
||
{
|
||
TEC_mask& m = mask();
|
||
m.set(F_STAMPSALDO, "X");
|
||
|
||
while (true)
|
||
{
|
||
m.show(F_ULTIMOEC, _tiponumec == 'G');
|
||
m.set(F_ULTIMOEC, _lastnumec);
|
||
const KEY k = m.run();
|
||
if (k == K_QUIT)
|
||
break;
|
||
|
||
const bool excel = k != K_ENTER;
|
||
|
||
_form = new TEC_form(m, _gesval, excel);
|
||
|
||
_form->stampa_saldo(m.get_bool(F_STAMPSALDO));
|
||
|
||
if (!excel)
|
||
{
|
||
TForm_item& nec = _form->find_field('H', odd_page, PEC_NUMPROG);
|
||
if (nec.enabled() && nec.shown())
|
||
{
|
||
nec.show(_tiponumec > ' ' && m.get_who() == 'C');
|
||
_lastnumec = m.get_long(F_ULTIMOEC);
|
||
}
|
||
}
|
||
if (m.get_bool(F_GROUPAGENT))
|
||
print_agents();
|
||
else
|
||
print_selected();
|
||
|
||
if (excel)
|
||
{
|
||
TFilename xls; xls.tempdir(); xls.add("ec.xls");
|
||
_form->recordset().save_as(xls, fmt_html);
|
||
xvt_sys_goto_url(xls, "open");
|
||
}
|
||
|
||
delete _form;
|
||
_form = NULL;
|
||
|
||
}
|
||
}
|
||
|
||
TStampaEC_application::TStampaEC_application()
|
||
: _lingua_ditta(1), _msk(NULL), _form(NULL)
|
||
{}
|
||
|
||
int sc2100(int argc, char** argv)
|
||
{
|
||
TStampaEC_application app;
|
||
app.run(argc, argv, TR("Stampa Estratti Conto"));
|
||
return 0;
|
||
}
|
||
|