508 lines
14 KiB
C++
508 lines
14 KiB
C++
|
#include <applicat.h>
|
|||
|
#include <automask.h>
|
|||
|
#include <defmask.h>
|
|||
|
#include <execp.h>
|
|||
|
#include <progind.h>
|
|||
|
#include <reprint.h>
|
|||
|
|
|||
|
#include <mov.h>
|
|||
|
#include <partite.h>
|
|||
|
#include <rmov.h>
|
|||
|
#include <rmoviva.h>
|
|||
|
|
|||
|
#include "..\cg\cgsaldac.h"
|
|||
|
#include "..\cg\cg2103.h"
|
|||
|
#include "..\ve\velib.h"
|
|||
|
|
|||
|
#include "panapdc.h"
|
|||
|
#include "pconana.h"
|
|||
|
#include "movana.h"
|
|||
|
#include "rmovana.h"
|
|||
|
|
|||
|
#include "ca3.h"
|
|||
|
#include "ca3600.h"
|
|||
|
#include "ca3601.h"
|
|||
|
#include "calib01.h"
|
|||
|
#include "calib02.h"
|
|||
|
|
|||
|
//===============================================================================================
|
|||
|
////////////////////////////////////////////////////////
|
|||
|
// MASCHERA DI CONFIGURAZIONE
|
|||
|
////////////////////////////////////////////////////////
|
|||
|
|
|||
|
class TPag_per_cms_configmask: public TAutomask
|
|||
|
{
|
|||
|
public:
|
|||
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|||
|
void config_loader(TSheet_field& sf, const char* paragrafo);
|
|||
|
void config_setter(TSheet_field& sf, const char* paragrafo);
|
|||
|
|
|||
|
TPag_per_cms_configmask():TAutomask("ca3601")
|
|||
|
{
|
|||
|
config_loader(sfield(F_COSTI), "Costi");
|
|||
|
config_loader(sfield(F_PAGAMENTI), "Pagamenti");
|
|||
|
config_loader(sfield(F_RITFIS), "Fiscali");
|
|||
|
config_loader(sfield(F_RITSOC), "Sociali");
|
|||
|
}
|
|||
|
|
|||
|
};
|
|||
|
|
|||
|
bool TPag_per_cms_configmask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|||
|
{
|
|||
|
switch (o.dlg())
|
|||
|
{
|
|||
|
case DLG_SAVEREC:
|
|||
|
{
|
|||
|
config_setter(sfield(F_COSTI), "Costi");
|
|||
|
config_setter(sfield(F_PAGAMENTI), "Pagamenti");
|
|||
|
config_setter(sfield(F_RITFIS), "Fiscali");
|
|||
|
config_setter(sfield(F_RITSOC), "Sociali");
|
|||
|
}
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
void TPag_per_cms_configmask::config_loader(TSheet_field& sf, const char* paragrafo)
|
|||
|
{
|
|||
|
TConfig config("ca3600.ini", paragrafo);
|
|||
|
TString_array conti;
|
|||
|
|
|||
|
int n = config.list_variables(conti, true, paragrafo, true);
|
|||
|
FOR_EACH_ARRAY_ROW(conti, i, row)
|
|||
|
{
|
|||
|
TToken_string conto(row->get(1), '.'); //prende il valore della riga
|
|||
|
TBill uncle(conto, 0);
|
|||
|
uncle.add_to(sf.row(i), 0, 0x2);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void TPag_per_cms_configmask::config_setter(TSheet_field& sf, const char* paragrafo)
|
|||
|
{
|
|||
|
TConfig config("ca3600.ini", paragrafo);
|
|||
|
|
|||
|
config.remove_all(); //svuota il paragrafo sul .ini prima di ricompilarlo (se non si facesse
|
|||
|
//non si riuscirebbero ad ammazzare le righe sul .ini
|
|||
|
FOR_EACH_SHEET_ROW (sf, i, row)
|
|||
|
{
|
|||
|
TToken_string conto("", '.');
|
|||
|
conto.add(row->get(0));
|
|||
|
conto.add(row->get(1));
|
|||
|
conto.add(row->get(2));
|
|||
|
|
|||
|
config.set("conto", conto, NULL, true, i);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//===============================================================================================
|
|||
|
////////////////////////////////////////////////////////
|
|||
|
// MASCHERA PRINCIPALE
|
|||
|
////////////////////////////////////////////////////////
|
|||
|
|
|||
|
class TPag_per_cms_mask: public TAnal_report_mask
|
|||
|
{
|
|||
|
protected:
|
|||
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|||
|
const TString& get_report_class() const;
|
|||
|
bool test_compatible_report();
|
|||
|
bool esistono_riclassificazioni() const;
|
|||
|
|
|||
|
public:
|
|||
|
TPag_per_cms_mask();
|
|||
|
virtual ~TPag_per_cms_mask() {}
|
|||
|
|
|||
|
};
|
|||
|
|
|||
|
const TString& TPag_per_cms_mask::get_report_class() const
|
|||
|
{
|
|||
|
TString& classe = get_tmp_string();
|
|||
|
classe = "ca3600a";
|
|||
|
return classe;
|
|||
|
}
|
|||
|
|
|||
|
bool TPag_per_cms_mask::test_compatible_report()
|
|||
|
{
|
|||
|
const TString& cls = get_report_class();
|
|||
|
const TString& name = get(F_REPORT);
|
|||
|
bool ok = name.not_empty();
|
|||
|
if (ok)
|
|||
|
{
|
|||
|
TReport rep;
|
|||
|
ok = rep.load(name);
|
|||
|
if (ok)
|
|||
|
{
|
|||
|
const TString& classe = rep.get_class();
|
|||
|
ok = classe == cls;
|
|||
|
}
|
|||
|
}
|
|||
|
if (!ok)
|
|||
|
{
|
|||
|
set(F_REPORT, cls);
|
|||
|
TFilename path = cls;
|
|||
|
path.ext("rep");
|
|||
|
ok = path.custom_path();
|
|||
|
}
|
|||
|
return ok;
|
|||
|
}
|
|||
|
|
|||
|
bool TPag_per_cms_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|||
|
{
|
|||
|
switch (o.dlg())
|
|||
|
{
|
|||
|
case DLG_CONFIG:
|
|||
|
if (e == fe_button)
|
|||
|
{
|
|||
|
TPag_per_cms_configmask configmask; //lancia la maschera di configurazione
|
|||
|
configmask.run();
|
|||
|
}
|
|||
|
break;
|
|||
|
case F_REPORT:
|
|||
|
if (e == fe_button)
|
|||
|
{
|
|||
|
const TString8 lib = get_report_class();
|
|||
|
TFilename path = o.get();
|
|||
|
if (select_custom_file(path, "rep", lib))
|
|||
|
{
|
|||
|
path = path.name();
|
|||
|
path.ext("");
|
|||
|
o.set(path);
|
|||
|
}
|
|||
|
} else
|
|||
|
if (e == fe_close)
|
|||
|
{
|
|||
|
if (!test_compatible_report())
|
|||
|
return error_box(TR("Impossibile trovare un report compatibile"));
|
|||
|
}
|
|||
|
break;
|
|||
|
case F_PRE1:
|
|||
|
case F_PRE2:
|
|||
|
case F_PRE3:
|
|||
|
if ((e == fe_init || e == fe_modify) && o.active())
|
|||
|
{
|
|||
|
const int k = o.dlg()-F_PRE1;
|
|||
|
set(F_PAN1_INI + k, o.get(), 0x2);
|
|||
|
disable(F_PAN1_INI + k);
|
|||
|
disable(F_PANDES1_INI + k);
|
|||
|
|
|||
|
set(F_PAN1_FIN + k, o.get(), 0x2);
|
|||
|
disable(F_PAN1_FIN + k);
|
|||
|
disable(F_PANDES1_FIN + k);
|
|||
|
}
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
return TAnal_report_mask::on_field_event(o, e, jolly);
|
|||
|
}
|
|||
|
|
|||
|
bool TPag_per_cms_mask::esistono_riclassificazioni() const
|
|||
|
{
|
|||
|
TLocalisamfile ric(LF_PANAPDC);
|
|||
|
return ric.first() == NOERR;
|
|||
|
}
|
|||
|
|
|||
|
TPag_per_cms_mask::TPag_per_cms_mask()
|
|||
|
:TAnal_report_mask("ca3600")
|
|||
|
{
|
|||
|
TConfig& cfg = ca_config();
|
|||
|
const bool use_pdcc = cfg.get_bool("UsePdcc");
|
|||
|
|
|||
|
const TMultilevel_code_info& pconana_info = ca_multilevel_code_info(LF_PCONANA);
|
|||
|
const int pconana_levels = pconana_info.levels();
|
|||
|
|
|||
|
int pconana_prefix = cfg.get_int("PdcPrefix");
|
|||
|
if (pconana_prefix >= pconana_levels)
|
|||
|
pconana_prefix = pconana_levels-1;
|
|||
|
|
|||
|
disable(F_PIANO);
|
|||
|
set(F_PIANO, use_pdcc ? "C" : "A");
|
|||
|
|
|||
|
// Controllo se voglio (e posso) usare il conto analitico come prefisso di quello contabile
|
|||
|
const int pref = cfg.get_int("PdcPrefix");
|
|||
|
if (use_pdcc && pref > 0)
|
|||
|
{
|
|||
|
const TMultilevel_code_info& info = ca_multilevel_code_info(LF_PCONANA);
|
|||
|
const int levels = info.levels();
|
|||
|
if (levels >= 2 && pref < levels && esistono_riclassificazioni())
|
|||
|
{
|
|||
|
enable(F_PIANO);
|
|||
|
ca_create_fields(*this, 1, LF_PCONANA, 2, 4, F_PRE1, F_PREDES1, 0x0, PCONANA_CODCONTO);
|
|||
|
|
|||
|
// Nascondi i campi che non fanno parte del prefisso
|
|||
|
for (int i = 0; i < levels; i++)
|
|||
|
{
|
|||
|
if (i < pref)
|
|||
|
{
|
|||
|
field(F_PRE1 + i).check_type(CHECK_REQUIRED);
|
|||
|
field(F_PRE1 + i).set_group(6);
|
|||
|
field(F_PREDES1 + i).set_group(6);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
field(F_PRE1 + i).hide();
|
|||
|
field(F_PREDES1 + i).hide();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
for (int g = 5; g <= 6; g++)
|
|||
|
{
|
|||
|
const int logicnum = g == 5 ? LF_PCON : LF_PCONANA;
|
|||
|
const short da_dlg = g == 5 ? F_PDC1_INI : F_PAN1_INI;
|
|||
|
const short da_des = g == 5 ? F_PDCDES1_INI : F_PANDES1_INI;
|
|||
|
const short a_dlg = g == 5 ? F_PDC1_FIN : F_PAN1_FIN;
|
|||
|
const short a_des = g == 5 ? F_PDCDES1_FIN : F_PANDES1_FIN;
|
|||
|
|
|||
|
const int nfields = ca_create_fields(*this, 1, logicnum, 2, 10, da_dlg, da_des, 0x0, PCONANA_CODCONTO);
|
|||
|
ca_create_fields(*this, 1, logicnum, 2, 16, a_dlg, a_des, 0x0, PCONANA_CODCONTO);
|
|||
|
|
|||
|
for (int i = 0; i < nfields; i++)
|
|||
|
{
|
|||
|
TMask_field& daconto = field(da_dlg + i);
|
|||
|
daconto.set_group(1);
|
|||
|
daconto.set_group(4);
|
|||
|
daconto.set_group(g);
|
|||
|
daconto.check_type(CHECK_SEARCH);
|
|||
|
|
|||
|
field(da_des+i).set_group(4);
|
|||
|
field(da_des+i).set_group(g);
|
|||
|
|
|||
|
TMask_field& aconto = field(a_dlg + i);
|
|||
|
aconto.set_group(2);
|
|||
|
aconto.set_group(4);
|
|||
|
aconto.set_group(g);
|
|||
|
aconto.check_type(CHECK_SEARCH);
|
|||
|
|
|||
|
field(a_des+i).set_group(4);
|
|||
|
field(a_des+i).set_group(g);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
///////////////////////////////////////////////////////////////
|
|||
|
// RECORDSET
|
|||
|
///////////////////////////////////////////////////////////////
|
|||
|
class TPag_per_cms_recordset : public TISAM_recordset
|
|||
|
{
|
|||
|
TExternisamfile* _tmp;
|
|||
|
bool _riclassificato;
|
|||
|
// TString _prefix, _da_conto_riclas, _a_conto_riclas;
|
|||
|
|
|||
|
protected:
|
|||
|
// int _anno;
|
|||
|
// int _tipoconti;
|
|||
|
// TDate _dadata, _adata;
|
|||
|
// long _danumreg, _anumreg;
|
|||
|
TString _daconto, _aconto, _codcosto, _codcms, _codfas;
|
|||
|
|
|||
|
protected: //da libreria
|
|||
|
// virtual const TVariant& get(const char* column_name) const;
|
|||
|
|
|||
|
protected:
|
|||
|
void crea_trr(const TFilename& trr) const;
|
|||
|
|
|||
|
public:
|
|||
|
virtual void set_filter(const TPag_per_cms_mask& msk, int cms_row);
|
|||
|
|
|||
|
TPag_per_cms_recordset(const TString& sql) : TISAM_recordset(sql), _riclassificato(false) { _tmp = NULL;}
|
|||
|
~TPag_per_cms_recordset();
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
static TPag_per_cms_recordset* myself = NULL;
|
|||
|
|
|||
|
TPag_per_cms_recordset::~TPag_per_cms_recordset()
|
|||
|
{ }
|
|||
|
|
|||
|
|
|||
|
void TPag_per_cms_recordset::crea_trr(const TFilename& trr) const
|
|||
|
{
|
|||
|
ofstream of(trr);
|
|||
|
of << 1000 << endl;
|
|||
|
of << 14 << endl;
|
|||
|
of << "NREG|3|7|0|Numero registrazione" << endl;
|
|||
|
of << "DATAPAG|5|8|0|Data pagamento" << endl;
|
|||
|
of << "DESCRPAG|1|50|0|Descrizione pagamento" << endl;
|
|||
|
of << "CONTO|1|20|0|Conto analitico/contabile" << endl;
|
|||
|
of << "DESCONTO|1|50|0|Descrizione conto" << endl;
|
|||
|
of << "NDOC|1|6|0|Numero documento" << endl;
|
|||
|
of << "DATADOC|5|8|0|Data documento" << endl;
|
|||
|
of << "PROT|2|5|0|Protocollo iva" << endl;
|
|||
|
of << "TOTDOC|4|18|5|Totale documento" << endl;
|
|||
|
of << "TOTPAG|4|18|5|Totale pagamento" << endl;
|
|||
|
of << "TOTRES|4|18|5|Totale residuo" << endl;
|
|||
|
of << "CODFORN|3|7|0|Codice fornitore" << endl;
|
|||
|
of << "DESFORN|1|50|0|Descrizione fornitore" << endl;
|
|||
|
of << "HIDDEN|8|1|0|Record nascosto" << endl;
|
|||
|
of << 1 << endl;
|
|||
|
of << "NREG+DATAPAG" << endl;
|
|||
|
}
|
|||
|
|
|||
|
void TPag_per_cms_recordset::set_filter(const TPag_per_cms_mask& msk, int cms_row)
|
|||
|
{
|
|||
|
//se esiste il file temporano con tracciato persomalizzato lo cancella e lo ricrea vuoto
|
|||
|
TFilename trr; //file tracciato record
|
|||
|
trr.tempdir();
|
|||
|
trr.add("paid");
|
|||
|
TFilename dbf(trr); //file dati
|
|||
|
|
|||
|
trr.ext("trr");
|
|||
|
dbf.ext("dbf");
|
|||
|
|
|||
|
//crea il file .trr in base ai parametri del metodo
|
|||
|
crea_trr(trr);
|
|||
|
//svuota la memoria dal vecchio file temporaneo
|
|||
|
if (_tmp != NULL)
|
|||
|
delete _tmp;
|
|||
|
|
|||
|
//crea in memoria il nuovo file temporaneo e lo azzera (non si sa mai..)
|
|||
|
_tmp = new TExternisamfile(dbf, trr);
|
|||
|
_tmp->zap();
|
|||
|
//prende un po' di dati dalla maschera
|
|||
|
_daconto, _aconto, _codcosto = _codcms = _codfas = "";
|
|||
|
if (cms_row >= 0)
|
|||
|
{
|
|||
|
TSheet_field& sf = msk.sfield(F_RIGHE);
|
|||
|
TMask& sm = sf.sheet_mask();
|
|||
|
sf.update_mask(cms_row);
|
|||
|
TRelation rel(LF_RMOVANA);
|
|||
|
sm.autosave(rel);
|
|||
|
_codcosto = rel.curr().get(RMOVANA_CODCCOSTO);
|
|||
|
_codcms = rel.curr().get(RMOVANA_CODCMS);
|
|||
|
_codfas = rel.curr().get(RMOVANA_CODFASE);
|
|||
|
}
|
|||
|
|
|||
|
for (int i = 0; msk.id2pos(F_CDC1_INI+i) > 0; i++)
|
|||
|
{
|
|||
|
_daconto << msk.get(F_CDC1_INI+i);
|
|||
|
_aconto << msk.get(F_CDC1_FIN+i);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
////////////////////////////////////////////////////////
|
|||
|
// REPORT
|
|||
|
////////////////////////////////////////////////////////
|
|||
|
class TPag_per_cms_rep : public TAnal_report
|
|||
|
{
|
|||
|
|
|||
|
protected:
|
|||
|
virtual bool set_recordset(const TString& sql);
|
|||
|
virtual bool get_usr_val(const TString& name, TVariant& var) const;
|
|||
|
|
|||
|
public:
|
|||
|
void set_filter(const TPag_per_cms_mask& msk, int cms_row);
|
|||
|
};
|
|||
|
|
|||
|
bool TPag_per_cms_rep::get_usr_val(const TString& name, TVariant& var) const
|
|||
|
{
|
|||
|
return TAnal_report::get_usr_val(name, var);
|
|||
|
}
|
|||
|
|
|||
|
bool TPag_per_cms_rep::set_recordset(const TString& sql)
|
|||
|
{
|
|||
|
TPag_per_cms_recordset* rs = new TPag_per_cms_recordset(sql);
|
|||
|
return TAnal_report::set_recordset(rs);
|
|||
|
}
|
|||
|
|
|||
|
void TPag_per_cms_rep::set_filter(const TPag_per_cms_mask& msk, int cms_row)
|
|||
|
{
|
|||
|
TAnal_report::set_recordset(NULL);
|
|||
|
|
|||
|
const char* query ="USE 1000"; //\nJOIN MOVANA INTO NUMREG==NUMRD\nJOIN RMOVANA INTO NUMREG==NUMRD NUMRIG==NRIGA";
|
|||
|
|
|||
|
TPag_per_cms_recordset* recset = new TPag_per_cms_recordset(query);
|
|||
|
|
|||
|
recset->set_filter(msk, cms_row);
|
|||
|
TAnal_report::set_recordset(recset);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//===============================================================================================
|
|||
|
////////////////////////////////////////////////////////
|
|||
|
// APPLICAZIONE
|
|||
|
////////////////////////////////////////////////////////
|
|||
|
|
|||
|
class TPag_per_cms : public TSkeleton_application
|
|||
|
{
|
|||
|
public:
|
|||
|
const TMultilevel_code_info& get_level_one() const;
|
|||
|
virtual void main_loop();
|
|||
|
};
|
|||
|
|
|||
|
//metodo per accattarsi o' primo livello della configurazione CA
|
|||
|
const TMultilevel_code_info& TPag_per_cms::get_level_one() const
|
|||
|
{
|
|||
|
TConfig& cfg = ca_config();
|
|||
|
const TString& first_lev = cfg.get("Level(1)");
|
|||
|
const int logic = first_lev == "CDC" ? LF_CDC : LF_COMMESSE;
|
|||
|
return ca_multilevel_code_info(logic);
|
|||
|
}
|
|||
|
|
|||
|
void TPag_per_cms::main_loop()
|
|||
|
{
|
|||
|
TPag_per_cms_mask mask;
|
|||
|
while (mask.run() == K_ENTER)
|
|||
|
{
|
|||
|
//report e book dei report
|
|||
|
TReport_book book;
|
|||
|
TString path = mask.get(F_REPORT);
|
|||
|
if (path.empty())
|
|||
|
path = "ca3600a";
|
|||
|
TPag_per_cms_rep rep;
|
|||
|
rep.load(path);
|
|||
|
|
|||
|
TSheet_field& sheet = mask.sfield(F_RIGHE);
|
|||
|
TString video_string; //stringa che compare nella progind
|
|||
|
if (sheet.empty()) //se non ci sono righe sullo sheet (selezione su tutte le cms/cdc)...
|
|||
|
{
|
|||
|
TToken_string& row = sheet.row(-1); //crea la prima riga dello sheet
|
|||
|
|
|||
|
const TMultilevel_code_info& liv1 = get_level_one(); //stabilisce quale <20> il primo livello (tra CDC e CMS)..
|
|||
|
TISAM_recordset set(liv1.logic() == LF_CDC ? "USE CDC" : "USE COMMESSE"); //..e di conseguenza scrive la use giusta
|
|||
|
|
|||
|
TProgind pi(set.items(), video_string, true, true);
|
|||
|
for (int i = 0; set.move_to(i); i++) //fighissimo metodo per scandire un file in 1 riga!
|
|||
|
{
|
|||
|
pi.addstatus(1);
|
|||
|
if (pi.iscancelled())
|
|||
|
break;
|
|||
|
row = set.get((unsigned int)0).as_string(); //prende il valore del primo campo del file (CDC o CMS code)
|
|||
|
|
|||
|
video_string = TR("Scansione");
|
|||
|
video_string << " " << row; //completa la stringa da visualizzare sulla progind
|
|||
|
pi.set_text(video_string);
|
|||
|
|
|||
|
for (int l = liv1.levels()-2; l >= 0; l--) //se la struttura <20> a pi<70> livelli costruisce la tokenstring
|
|||
|
row.insert("|", liv1.total_len(l));
|
|||
|
|
|||
|
rep.set_filter(mask, 0); //fa la set filter sulla prima riga (che <20> quella usata)
|
|||
|
book.add(rep);
|
|||
|
}
|
|||
|
sheet.destroy(); //cancella le commesse aggiunte in automatico sullo sheet
|
|||
|
}
|
|||
|
else //se ha almeno una riga sullo sheet delle cms/cdc...
|
|||
|
{
|
|||
|
FOR_EACH_SHEET_ROW(sheet, r, row) //per ogni cdc/cms che appare nello sheet di pag.1 della msk..
|
|||
|
{
|
|||
|
rep.set_filter(mask, r); //..chiama il metodone globale che crea e compila il file..
|
|||
|
//..temporaneo i cui dati riempiranno il report
|
|||
|
book.add(rep); //aggiunge il report relativo alla cdc/cms corrente al book
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
book.print_or_preview(); //stampa il book dei report
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
int ca3600(int argc, char* argv[])
|
|||
|
{
|
|||
|
TPag_per_cms a;
|
|||
|
a.run(argc,argv,TR("Stampa pagato per commessa"));
|
|||
|
return 0;
|
|||
|
}
|