Files correlati : ca3 Ricompilazione Demo : [ ] Commento : Aggiunta in libreria la cache dei saldi analitici git-svn-id: svn://10.65.10.50/trunk@13217 c028cbd2-c16b-5b4b-a496-9718f37d4682
546 lines
14 KiB
C++
Executable File
546 lines
14 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <execp.h>
|
|
#include <reprint.h>
|
|
|
|
#include "movana.h"
|
|
#include "pconana.h"
|
|
#include "rmovana.h"
|
|
|
|
#include "ca3.h"
|
|
#include "calib01.h"
|
|
#include "calib02.h"
|
|
|
|
#include "ca3300.h"
|
|
|
|
////////////////////////////////////////////////////////
|
|
// MASCHERA
|
|
////////////////////////////////////////////////////////
|
|
|
|
class TPrint_bilancio_ca_mask : public TAutomask
|
|
{
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
const TString& get_compatible_library() const;
|
|
bool test_compatible_report();
|
|
|
|
void create_sheet();
|
|
int create_sheet_fields(int lf, int& y, short& dlg, bool required);
|
|
public:
|
|
TPrint_bilancio_ca_mask();
|
|
virtual ~TPrint_bilancio_ca_mask() {}
|
|
};
|
|
|
|
const TString& TPrint_bilancio_ca_mask::get_compatible_library() const
|
|
{
|
|
TString& lib = get_tmp_string();
|
|
lib = "ca3300";
|
|
const char stp = get(F_TIPOSTAMPA)[0]; // Raffronto o No?
|
|
const char bil = get(F_BILANCIO)[0]; // Verifica o sezioni Contrapposte
|
|
if (bil == 'V')
|
|
lib << (stp == 'R' ? 'a' : 'b'); // Verifica
|
|
else
|
|
lib << (stp == 'R' ? 'c' : 'd'); // Sezioni contrapposte
|
|
return lib;
|
|
}
|
|
|
|
bool TPrint_bilancio_ca_mask::test_compatible_report()
|
|
{
|
|
TFilename lib = get_compatible_library();
|
|
const TString& name = get(F_REPORT);
|
|
bool ok = name.not_empty();
|
|
if (ok)
|
|
{
|
|
TReport rep;
|
|
ok = rep.load(name);
|
|
if (ok)
|
|
{
|
|
TToken_string& libraries = rep.get_libraries();
|
|
ok = libraries.get_pos(lib) >= 0;
|
|
}
|
|
}
|
|
if (!ok)
|
|
{
|
|
set(F_REPORT, lib);
|
|
lib.ext("rep");
|
|
ok = lib.custom_path();
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool TPrint_bilancio_ca_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
switch (o.dlg())
|
|
{
|
|
case F_BILANCIO:
|
|
case F_TIPOSTAMPA:
|
|
if (e == fe_init || e == fe_modify)
|
|
test_compatible_report();
|
|
break;
|
|
case F_REPORT:
|
|
if (e == fe_button)
|
|
{
|
|
const TString8 lib = get_compatible_library();
|
|
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("Impossibile trovare un report compatibile");
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
int TPrint_bilancio_ca_mask::create_sheet_fields(int lf, int& y, short& dlg, bool required)
|
|
{
|
|
TSheet_field& sf = sfield(F_RIGHE);
|
|
TMask& sm = sf.sheet_mask();
|
|
|
|
const int h = ca_create_fields(sm, 0, lf, 1, y, dlg, dlg+50);
|
|
|
|
for (int i = 0; i < h; i++)
|
|
{
|
|
TEdit_field& fld = sm.efield(dlg+i);
|
|
int logic = lf;
|
|
if (logic == LF_FASI)
|
|
{
|
|
const TMultilevel_code_info& fasinfo = ca_multilevel_code_info(LF_FASI);
|
|
if (fasinfo.parent() != 0)
|
|
{
|
|
const TMultilevel_code_info& parinfo = ca_multilevel_code_info(fasinfo.parent());
|
|
if (i < parinfo.levels())
|
|
logic = fasinfo.parent();
|
|
}
|
|
}
|
|
|
|
const char* fieldname = NULL;
|
|
switch(logic)
|
|
{
|
|
case LF_CDC : fieldname = RMOVANA_CODCCOSTO; break;
|
|
case LF_COMMESSE: fieldname = RMOVANA_CODCMS; break;
|
|
case LF_FASI : fieldname = RMOVANA_CODFASE; break;
|
|
default : fieldname = RMOVANA_CODCONTO; break;
|
|
}
|
|
TFieldref* f = (TFieldref*)fld.field();
|
|
f->set_name(fieldname);
|
|
|
|
fld.check_type(required ? CHECK_REQUIRED : CHECK_NORMAL);
|
|
|
|
TEdit_field& dfld = sm.efield(dlg+50+i);
|
|
dfld.set_field(EMPTY_STRING); // Toglie campi che fan saltare gli output!
|
|
}
|
|
|
|
y += h+1;
|
|
dlg += h;
|
|
|
|
return h;
|
|
}
|
|
|
|
void TPrint_bilancio_ca_mask::create_sheet()
|
|
{
|
|
TSheet_field& sf = sfield(F_RIGHE);
|
|
TMask& sm = sf.sheet_mask();
|
|
sm.hide(-1);
|
|
|
|
const TMultilevel_code_info& fasinfo = ca_multilevel_code_info(LF_FASI);
|
|
|
|
TConfig_anal ini;
|
|
const bool fsc_req = ini.get_bool("FscRequired");
|
|
|
|
int y = 1;
|
|
short dlg = S_CDC1 + 100; // id del primo campo da generare
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
{
|
|
const TString& level = ini.get("Level", NULL, i+1); // Legge il livello 1 o 2
|
|
if (level == "CDC") // Crea centro di costo
|
|
{
|
|
if (fasinfo.parent() == LF_CDC)
|
|
create_sheet_fields(LF_FASI, y, dlg, fsc_req);
|
|
else
|
|
{
|
|
const bool cdc_req = ini.get_bool("CdcRequired");
|
|
create_sheet_fields(LF_CDC, y, dlg, cdc_req);
|
|
}
|
|
} else
|
|
if (level == "CMS") // Crea commessa
|
|
{
|
|
if (fasinfo.parent() == LF_COMMESSE)
|
|
create_sheet_fields(LF_FASI, y, dlg, fsc_req);
|
|
else
|
|
{
|
|
const bool cms_req = ini.get_bool("CmsRequired");
|
|
create_sheet_fields(LF_COMMESSE, y, dlg, cms_req);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (fasinfo.levels() > 0 && fasinfo.parent() <= 0)
|
|
create_sheet_fields(LF_FASI, y, dlg, fsc_req);
|
|
|
|
for (short id = S_CDC12+100; id >= S_CDC1+100; id--)
|
|
{
|
|
const int pos = sm.id2pos(id);
|
|
if (pos >= 0)
|
|
{
|
|
TMask_field& f = sm.fld(pos);
|
|
const int size = f.size();
|
|
const TString& prompt = f.prompt();
|
|
sf.set_column_header(id, prompt);
|
|
sf.set_column_justify(id, f.is_kind_of(CLASS_REAL_FIELD));
|
|
sf.set_column_width(id, (max(3+size, prompt.len()+1)) * CHARX);
|
|
}
|
|
else
|
|
sf.delete_column(id);
|
|
}
|
|
}
|
|
|
|
|
|
TPrint_bilancio_ca_mask::TPrint_bilancio_ca_mask()
|
|
:TAutomask("ca3300")
|
|
{
|
|
TConfig_anal cfg;
|
|
const bool use_pdcc = cfg.get_bool("UsePdcc");
|
|
|
|
const int logicnum = use_pdcc ? LF_PCON : LF_PCONANA;
|
|
|
|
const int nfields = ca_create_fields(*this, 1, logicnum, 2, 1, F_PDC1_INI, F_DES1_INI, 0x0, PCONANA_CODCONTO);
|
|
ca_create_fields(*this, 1, logicnum, 2, 7, F_PDC1_FIN, F_DES1_FIN, 0x0, PCONANA_CODCONTO);
|
|
|
|
for (int i = 0; i < nfields; i++)
|
|
{
|
|
TMask_field& daconto = field(F_PDC1_INI + i);
|
|
daconto.set_group(1);
|
|
daconto.check_type(CHECK_NORMAL);
|
|
TMask_field& aconto = field(F_PDC1_FIN + i);
|
|
aconto.set_group(2);
|
|
aconto.check_type(CHECK_NORMAL);
|
|
}
|
|
// creazione dei campi della seconda pagina della maschera
|
|
create_sheet();
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
// Recordset
|
|
////////////////////////////////////////////////////////
|
|
|
|
class TPiano_conti_recordset : public TISAM_recordset
|
|
{
|
|
word _tipimov;
|
|
TString _da_conto, _a_conto;
|
|
int _contolen;
|
|
TString _codcms, _codfas, _codcosto;
|
|
TDate _dal, _al;
|
|
bool _movimentati, _nonnulli;
|
|
|
|
protected:
|
|
bool valid_record(const TRelation& rel) const;
|
|
static bool pianoconti_filter(const TRelation* rel);
|
|
|
|
virtual void set_custom_filter(TCursor& cursor) const;
|
|
|
|
public:
|
|
virtual const TVariant& get(const char* column_name) const;
|
|
|
|
void set_filter(const TMask& m, int r);
|
|
TPiano_conti_recordset(const char* sql);
|
|
};
|
|
|
|
const TVariant& TPiano_conti_recordset::get(const char* column_name) const
|
|
{
|
|
if (strncmp(column_name, "SALDO:", 6) == 0)
|
|
{
|
|
TString16 sub_field = column_name+6;
|
|
const char last = sub_field.right(1)[0];
|
|
int tipimov = 0;
|
|
switch (last)
|
|
{
|
|
case 'C': tipimov = 1; sub_field.rtrim(1); break; // Consuntivo
|
|
case 'P':
|
|
case 'V': tipimov = 6; sub_field.rtrim(1); break; // Preventivo o variazaione preventivo
|
|
default : tipimov = _tipimov; break;
|
|
}
|
|
const TString& conto = get(PCONANA_CODCONTO).as_string();
|
|
const TSaldanal& s = ca_saldo(conto, _codcosto, _codcms, _codfas, _dal, _al, tipimov);
|
|
|
|
TVariant& var = get_tmp_var();
|
|
if (strcmp(sub_field, "INI_DARE") == 0)
|
|
{
|
|
var = s._ini.sezione() == 'D' ? s._ini.valore() : ZERO;
|
|
} else
|
|
if (strcmp(sub_field, "INI_AVERE") == 0)
|
|
{
|
|
var = s._ini.sezione() == 'A' ? s._ini.valore() : ZERO;
|
|
} else
|
|
if (strcmp(sub_field, "MOV_DARE") == 0)
|
|
{
|
|
var = s._dare.valore();
|
|
} else
|
|
if (strcmp(sub_field, "MOV_AVERE") == 0)
|
|
{
|
|
var = s._avere.valore();
|
|
} else
|
|
if (strcmp(sub_field, "FIN_DARE") == 0)
|
|
{
|
|
var = s._fin.sezione() == 'D' ? s._fin.valore() : ZERO;
|
|
} else
|
|
if (strcmp(sub_field, "FIN_AVERE") == 0)
|
|
{
|
|
var = s._fin.sezione() == 'A' ? s._fin.valore() : ZERO;
|
|
}
|
|
return var;
|
|
}
|
|
if (strcmp(column_name, "#COSTO") == 0)
|
|
{
|
|
TVariant& var = get_tmp_var();
|
|
var = _codcosto;
|
|
return var;
|
|
}
|
|
if (strcmp(column_name, "#COMMESSA") == 0)
|
|
{
|
|
TVariant& var = get_tmp_var();
|
|
var = _codcms;
|
|
return var;
|
|
}
|
|
if (strcmp(column_name, "#FASE") == 0)
|
|
{
|
|
TVariant& var = get_tmp_var();
|
|
var = _codfas;
|
|
return var;
|
|
}
|
|
return TISAM_recordset::get(column_name);
|
|
}
|
|
|
|
bool TPiano_conti_recordset::valid_record(const TRelation& rel) const
|
|
{
|
|
const TString& conto = rel.curr().get(PCONANA_CODCONTO);
|
|
if (conto.len() < _contolen)
|
|
return false;
|
|
|
|
if (_movimentati || _nonnulli)
|
|
{
|
|
const TSaldanal& s = ca_saldo(conto, _codcosto, _codcms, _codfas, _dal, _al, _tipimov);
|
|
if (_movimentati && !s._movimentato)
|
|
return false;
|
|
if (_nonnulli && s._ini.is_zero() && s._dare.is_zero() && s._avere.is_zero())
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static const TPiano_conti_recordset* _current_recset = NULL;
|
|
|
|
bool TPiano_conti_recordset::pianoconti_filter(const TRelation* rel)
|
|
{ return _current_recset->valid_record(*rel); }
|
|
|
|
void TPiano_conti_recordset::set_custom_filter(TCursor& cursor) const
|
|
{
|
|
TRectype darec = cursor.curr();
|
|
TRectype arec = darec;
|
|
|
|
darec.zero(); darec.put(PCONANA_CODCONTO, _da_conto);
|
|
arec.zero(); arec.put(PCONANA_CODCONTO, _a_conto);
|
|
cursor.setregion(darec, arec);
|
|
|
|
_current_recset = this;
|
|
cursor.set_filterfunction(pianoconti_filter);
|
|
}
|
|
|
|
void TPiano_conti_recordset::set_filter(const TMask& m, int r)
|
|
{
|
|
_contolen = 0;
|
|
const TMultilevel_code_info& info = ca_multilevel_code_info(LF_PCONANA);
|
|
for (int l = info.levels()-1; l >= 0; l--)
|
|
_contolen += info.len(l);
|
|
|
|
for (int i = 0; m.id2pos(F_PDC1_INI+i) > 0; i++)
|
|
{
|
|
_da_conto << m.get(F_PDC1_INI+i);
|
|
_a_conto << m.get(F_PDC1_FIN+i);
|
|
}
|
|
|
|
_dal = m.get(F_DATADA);
|
|
_al = m.get(F_DATAA);
|
|
|
|
switch (m.get(F_TIPOSTAMPA)[0])
|
|
{
|
|
case 'C': _tipimov = 1; break; // Consuntivo
|
|
case 'P': _tipimov = 6; break; // Preventivo e variazioni
|
|
default : _tipimov = 7; break; // Raffronto
|
|
}
|
|
|
|
_movimentati = m.get_int(F_STAMPAV) == 1;
|
|
_nonnulli = m.get_int(F_STAMPAV) == 2;
|
|
|
|
if (r >= 0)
|
|
{
|
|
TSheet_field& sf = m.sfield(F_RIGHE);
|
|
TMask& sm = sf.sheet_mask();
|
|
sf.update_mask(r);
|
|
TRelation rel(LF_RMOVANA);
|
|
sm.autosave(rel);
|
|
const TRectype& rec = rel.curr();
|
|
_codcosto = rec.get(RMOVANA_CODCCOSTO);
|
|
_codcms = rec.get(RMOVANA_CODCMS);
|
|
_codfas = rec.get(RMOVANA_CODFASE);
|
|
}
|
|
}
|
|
|
|
TPiano_conti_recordset::TPiano_conti_recordset(const char* sql) : TISAM_recordset(sql)
|
|
{ }
|
|
|
|
////////////////////////////////////////////////////////
|
|
// Report
|
|
////////////////////////////////////////////////////////
|
|
|
|
class TReport_bilancio_ca : public TAnal_report
|
|
{
|
|
protected:
|
|
virtual bool set_recordset(const TString& sql);
|
|
|
|
public:
|
|
void set_recordset(const TMask& msk, int row);
|
|
TReport_bilancio_ca(const char* name);
|
|
};
|
|
|
|
bool TReport_bilancio_ca::set_recordset(const TString& sql)
|
|
{
|
|
TPiano_conti_recordset* rset = new TPiano_conti_recordset(sql);
|
|
return TReport::set_recordset(rset);
|
|
}
|
|
|
|
void TReport_bilancio_ca::set_recordset(const TMask& msk, int row)
|
|
{
|
|
TPiano_conti_recordset* rset = (TPiano_conti_recordset*)recordset();
|
|
rset->set_filter(msk, row);
|
|
}
|
|
|
|
TReport_bilancio_ca::TReport_bilancio_ca(const char* name)
|
|
{
|
|
load(name);
|
|
}
|
|
|
|
////////////////////////////////////////////////////////
|
|
// APPLICAZIONE
|
|
////////////////////////////////////////////////////////
|
|
class TPrint_bilancio_ca : public TSkeleton_application
|
|
{
|
|
public:
|
|
virtual void main_loop();
|
|
};
|
|
|
|
void randomov()
|
|
{
|
|
#ifdef DBG
|
|
TLocalisamfile fmov(LF_MOVANA);
|
|
if (fmov.first() != NOERR && yesno_box("Vuoi generare un po' di movimenti casuali?"))
|
|
{
|
|
const TMultilevel_code_info& info = ca_multilevel_code_info(LF_PCONANA);
|
|
TString filter;
|
|
int len = 0;
|
|
for (int l = info.levels()-1; l >= 0; l--)
|
|
len += info.len(l);
|
|
filter << "LEN(CODCONTO)==" << len;
|
|
|
|
TRelation relconti(LF_PCONANA);
|
|
TCursor curconti(&relconti, filter);
|
|
const TRecnotype conti = curconti.items();
|
|
curconti.freeze();
|
|
|
|
TRelation relcaus(LF_CAUSALI);
|
|
TCursor curcaus(&relcaus, "MOVIND=\"X\"");
|
|
const TRecnotype causali = curcaus.items();
|
|
curcaus.freeze();
|
|
|
|
TEsercizi_contabili esc;
|
|
|
|
for (int m = 0; m < 100; m++)
|
|
{
|
|
TAnal_mov mov;
|
|
|
|
TDate data(TODAY); data -= rand()%365;
|
|
mov.put(MOVANA_DATAREG, data);
|
|
mov.put(MOVANA_DATACOMP, data-1L);
|
|
mov.put(MOVANA_DATADOC, data-2L);
|
|
mov.put(MOVANA_ANNOES, esc.date2esc(data));
|
|
mov.put(MOVANA_DESCR, "Movimento random");
|
|
switch (rand() % 10)
|
|
{
|
|
case 0: mov.put(MOVANA_TIPOMOV, "P"); break;
|
|
case 1: mov.put(MOVANA_TIPOMOV, "V"); break;
|
|
default: mov.put(MOVANA_TIPOMOV, " "); break; // Alta probabilita'
|
|
}
|
|
|
|
if (causali > 0)
|
|
{
|
|
curcaus = rand() % causali;
|
|
mov.put(MOVANA_CODCAUS, curcaus.curr().get("CODCAUS"));
|
|
}
|
|
|
|
const int rows = rand()%10+1;
|
|
TImporto tot;
|
|
for (int i = 0; i < rows; i++)
|
|
{
|
|
TRectype& rmov = mov.new_row();
|
|
rmov.put(RMOVANA_DATACOMP, mov.get(MOVANA_DATACOMP));
|
|
rmov.put(RMOVANA_ANNOES, mov.get(MOVANA_ANNOES));
|
|
|
|
curconti = rand() % conti;
|
|
rmov.put(RMOVANA_CODCONTO, curconti.curr().get(PCONANA_CODCONTO));
|
|
const TImporto imp(i & 0x1 ? 'A' : 'D', real(10*(rand()%1000+1)));
|
|
rmov.put(RMOVANA_SEZIONE, imp.sezione());
|
|
rmov.put(RMOVANA_IMPORTO, imp.valore());
|
|
tot += imp;
|
|
}
|
|
|
|
tot.normalize();
|
|
mov.put(MOVANA_SEZIONE, tot.sezione());
|
|
mov.put(MOVANA_TOTDOC, tot.valore());
|
|
mov.write(fmov);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
|
|
void TPrint_bilancio_ca::main_loop()
|
|
{
|
|
randomov();
|
|
|
|
TPrint_bilancio_ca_mask mask;
|
|
while (mask.run() != K_QUIT)
|
|
{
|
|
TReport_book book;
|
|
TReport_bilancio_ca rep(mask.get(F_REPORT));
|
|
|
|
TSheet_field& sf = mask.sfield(F_RIGHE);
|
|
if (sf.empty())
|
|
sf.row(-1); // Aggiungo riga vuota
|
|
const int rows = sf.items();
|
|
for (int i = 0; i < rows; i++)
|
|
{
|
|
rep.set_recordset(mask, i);
|
|
book.add(rep);
|
|
}
|
|
|
|
book.print_or_preview();
|
|
}
|
|
}
|
|
|
|
int ca3300(int argc, char* argv[])
|
|
{
|
|
TPrint_bilancio_ca a;
|
|
a.run(argc, argv, TR("Stampa bilancio"));
|
|
return 0;
|
|
}
|