2005-06-29 14:34:28 +00:00
|
|
|
|
#include <applicat.h>
|
|
|
|
|
#include <execp.h>
|
|
|
|
|
#include <progind.h>
|
|
|
|
|
#include <reprint.h>
|
2005-07-07 17:25:53 +00:00
|
|
|
|
#include <doc.h>
|
|
|
|
|
#include <rdoc.h>
|
|
|
|
|
#include "../ve/velib04.h"
|
2005-06-29 14:34:28 +00:00
|
|
|
|
|
|
|
|
|
#include "pconana.h"
|
|
|
|
|
#include "movana.h"
|
|
|
|
|
#include "rmovana.h"
|
|
|
|
|
|
|
|
|
|
#include "ca3.h"
|
|
|
|
|
#include "ca3700.h"
|
|
|
|
|
#include "calib01.h"
|
|
|
|
|
#include "calib02.h"
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
// MASCHERA
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
class TPrint_rendiconto_ca_mask : public TAutomask
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
2005-06-29 15:12:31 +00:00
|
|
|
|
const TString& get_report_class() const;
|
2005-06-29 14:34:28 +00:00
|
|
|
|
bool test_compatible_report();
|
|
|
|
|
void create_page2();
|
|
|
|
|
int create_page2_sheet(int lf, int& y, short& dlg, bool required);
|
|
|
|
|
public:
|
|
|
|
|
TPrint_rendiconto_ca_mask();
|
|
|
|
|
virtual ~TPrint_rendiconto_ca_mask() {}
|
|
|
|
|
};
|
|
|
|
|
|
2005-06-29 15:12:31 +00:00
|
|
|
|
const TString& TPrint_rendiconto_ca_mask::get_report_class() const
|
2005-06-29 14:34:28 +00:00
|
|
|
|
{
|
2005-06-29 15:12:31 +00:00
|
|
|
|
TString& classe = get_tmp_string();
|
|
|
|
|
classe = "ca3700a";
|
|
|
|
|
return classe;
|
2005-06-29 14:34:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPrint_rendiconto_ca_mask::test_compatible_report()
|
|
|
|
|
{
|
2005-06-29 15:12:31 +00:00
|
|
|
|
TFilename lib = get_report_class();
|
2005-06-29 14:34:28 +00:00
|
|
|
|
const TString& name = get(F_REPORT);
|
|
|
|
|
bool ok = name.not_empty();
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
TReport rep;
|
|
|
|
|
ok = rep.load(name);
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
2005-06-29 15:12:31 +00:00
|
|
|
|
const TString& classe = rep.get_class();
|
|
|
|
|
ok = classe == lib;
|
2005-06-29 14:34:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!ok)
|
|
|
|
|
{
|
|
|
|
|
set(F_REPORT, lib);
|
|
|
|
|
lib.ext("rep");
|
|
|
|
|
ok = lib.custom_path();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPrint_rendiconto_ca_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
|
{
|
|
|
|
|
switch (o.dlg())
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
case F_REPORT:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
2005-06-29 15:12:31 +00:00
|
|
|
|
const TString8 lib = get_report_class();
|
2005-06-29 14:34:28 +00:00
|
|
|
|
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;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TPrint_rendiconto_ca_mask::create_page2_sheet(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_rendiconto_ca_mask::create_page2()
|
|
|
|
|
{
|
|
|
|
|
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_page2_sheet(LF_FASI, y, dlg, fsc_req);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const bool cdc_req = ini.get_bool("CdcRequired");
|
|
|
|
|
create_page2_sheet(LF_CDC, y, dlg, cdc_req);
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
if (level == "CMS") // Crea commessa
|
|
|
|
|
{
|
|
|
|
|
if (fasinfo.parent() == LF_COMMESSE)
|
|
|
|
|
create_page2_sheet(LF_FASI, y, dlg, fsc_req);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const bool cms_req = ini.get_bool("CmsRequired");
|
|
|
|
|
create_page2_sheet(LF_COMMESSE, y, dlg, cms_req);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fasinfo.levels() > 0 && fasinfo.parent() <= 0)
|
|
|
|
|
create_page2_sheet(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_rendiconto_ca_mask::TPrint_rendiconto_ca_mask()
|
|
|
|
|
:TAutomask("ca3700")
|
|
|
|
|
{
|
|
|
|
|
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, 0, logicnum, 2, 5, F_CDC1_INI, F_DES1_INI, 0x0, "#DACONTO");
|
|
|
|
|
ca_create_fields(*this, 0, logicnum, 2, 11, F_CDC1_FIN, F_DES1_FIN, 0x0, "#ACONTO");
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nfields; i++)
|
|
|
|
|
{
|
|
|
|
|
TMask_field& daconto = field(F_CDC1_INI + i);
|
|
|
|
|
daconto.set_group(1);
|
|
|
|
|
daconto.check_type(CHECK_NORMAL);
|
|
|
|
|
TMask_field& aconto = field(F_CDC1_FIN + i);
|
|
|
|
|
aconto.set_group(2);
|
|
|
|
|
aconto.check_type(CHECK_NORMAL);
|
|
|
|
|
}
|
|
|
|
|
// creazione dei campi della seconda pagina della maschera
|
|
|
|
|
create_page2();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
2005-07-07 17:25:53 +00:00
|
|
|
|
// RECORDSET
|
2005-06-29 14:34:28 +00:00
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class TPrint_rendiconto_ca_recordset : public TISAM_recordset
|
|
|
|
|
{
|
2005-07-07 17:25:53 +00:00
|
|
|
|
TExternisamfile* _tmp;
|
|
|
|
|
|
2005-06-29 14:34:28 +00:00
|
|
|
|
protected:
|
|
|
|
|
int _anno;
|
|
|
|
|
int _tipoconti;
|
|
|
|
|
int _tipimov;
|
|
|
|
|
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:
|
|
|
|
|
static bool mov_filter(const TRelation* rel);
|
|
|
|
|
bool valid_record(const TRelation& rel) const;
|
|
|
|
|
virtual void set_custom_filter(TCursor& cur) const;
|
2005-07-07 17:25:53 +00:00
|
|
|
|
|
|
|
|
|
void crea_righe_rmovana();
|
|
|
|
|
void crea_righe_rdoc(const TPrint_rendiconto_ca_mask& msk);
|
|
|
|
|
void crea_trr(const TFilename& trr) const;
|
|
|
|
|
void salva_rmovana(const TRectype& rmovana, const TRectype& movana);
|
2005-07-11 17:45:52 +00:00
|
|
|
|
real somma_budget(const TString& codconto, const char* tipomovana);
|
2005-07-07 17:25:53 +00:00
|
|
|
|
|
2005-06-29 14:34:28 +00:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual void set_filter(const TPrint_rendiconto_ca_mask& msk, int cms_row);
|
2005-07-07 17:25:53 +00:00
|
|
|
|
|
|
|
|
|
TPrint_rendiconto_ca_recordset(const TString& sql) : TISAM_recordset(sql) { _tmp = NULL;}
|
|
|
|
|
~TPrint_rendiconto_ca_recordset() { delete _tmp; }
|
2005-06-29 14:34:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
|
2005-06-29 14:34:28 +00:00
|
|
|
|
static const TPrint_rendiconto_ca_recordset* myself = NULL;
|
|
|
|
|
|
2005-07-11 17:45:52 +00:00
|
|
|
|
TPrint_rendiconto_ca_recordset* rendiconto_recordset() { return (TPrint_rendiconto_ca_recordset* ) myself;}
|
|
|
|
|
|
2005-06-29 14:34:28 +00:00
|
|
|
|
//metodo per riconoscere se il record corrente soddisfa i filtri della maschera...strafighissimo!
|
|
|
|
|
bool TPrint_rendiconto_ca_recordset::valid_record(const TRelation& rel) const
|
|
|
|
|
{
|
|
|
|
|
//prima controlla la testata...
|
|
|
|
|
const TRectype& mov = rel.curr(LF_MOVANA);
|
|
|
|
|
|
|
|
|
|
const char tipomov = mov.get_char(MOVANA_TIPOMOV);
|
|
|
|
|
int tipomov_int = 0;
|
|
|
|
|
switch (tipomov)
|
|
|
|
|
{
|
|
|
|
|
case 'P': tipomov_int = 2; break;
|
|
|
|
|
case 'V': tipomov_int = 4; break;
|
|
|
|
|
default: tipomov_int = 1; break;
|
|
|
|
|
}
|
|
|
|
|
if ((_tipimov & tipomov_int) == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
//..poi le righe (devono comparire solo le righe con cdc/cms/fsc che appaiono nello sheet)
|
|
|
|
|
const TRectype& rmov = rel.curr(LF_RMOVANA);
|
|
|
|
|
|
|
|
|
|
if (_codcosto.not_empty())
|
|
|
|
|
{
|
|
|
|
|
const TString& cos = rmov.get(RMOVANA_CODCCOSTO);
|
|
|
|
|
if (cos != _codcosto)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (_codcms.not_empty())
|
|
|
|
|
{
|
|
|
|
|
const TString& cms = rmov.get(RMOVANA_CODCMS);
|
|
|
|
|
if (cms != _codcms)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (_codfas.not_empty())
|
|
|
|
|
{
|
|
|
|
|
const TString& fas = rmov.get(RMOVANA_CODFASE);
|
|
|
|
|
if (fas != _codfas)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPrint_rendiconto_ca_recordset::mov_filter(const TRelation* rel)
|
|
|
|
|
{
|
|
|
|
|
return myself->valid_record(*rel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TPrint_rendiconto_ca_recordset::set_custom_filter(TCursor& cur) const
|
|
|
|
|
{
|
|
|
|
|
//filtro sui conti selezionati sulla maschera
|
2005-07-11 17:45:52 +00:00
|
|
|
|
TRectype darec(cur.curr()), arec(cur.curr());
|
2005-06-29 14:34:28 +00:00
|
|
|
|
darec.put(RMOVANA_CODCONTO, _daconto);
|
|
|
|
|
darec.put(RMOVANA_DATACOMP, _dadata);
|
|
|
|
|
arec.put(RMOVANA_CODCONTO, _aconto);
|
|
|
|
|
arec.put(RMOVANA_DATACOMP, _adata);
|
|
|
|
|
cur.setregion(darec, arec);
|
|
|
|
|
|
|
|
|
|
myself = this;
|
|
|
|
|
cur.set_filterfunction(mov_filter, true);
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-11 17:45:52 +00:00
|
|
|
|
//metodo per il calcolo del budget PREVENTIVO o VARIAZIONE (sezione di raggruppamento sul report)
|
|
|
|
|
real TPrint_rendiconto_ca_recordset::somma_budget(const TString& codconto, const char* tipomovana)
|
|
|
|
|
{
|
|
|
|
|
real budget = ZERO;
|
|
|
|
|
|
|
|
|
|
TRelation rel_rmovana(LF_RMOVANA);
|
|
|
|
|
rel_rmovana.add(LF_MOVANA, "NUMREG==NUMREG");
|
|
|
|
|
|
|
|
|
|
//..crea un cursore su movana per avere solo i conti di tipo tipomovana, con il codice conto
|
|
|
|
|
//selezionato e la datacomp compresa nell'intervallo date
|
|
|
|
|
TRectype da_rmovana(LF_RMOVANA);
|
|
|
|
|
da_rmovana.put(RMOVANA_CODCONTO, codconto);
|
|
|
|
|
da_rmovana.put(RMOVANA_DATACOMP, _dadata);
|
|
|
|
|
TRectype a_rmovana(LF_RMOVANA);
|
|
|
|
|
a_rmovana.put(RMOVANA_CODCONTO, codconto);
|
|
|
|
|
a_rmovana.put(RMOVANA_DATACOMP, _adata);
|
|
|
|
|
|
|
|
|
|
TString filtro;
|
|
|
|
|
filtro << "(MOVANA_TIPODOC==" << tipomovana << ")";
|
|
|
|
|
|
|
|
|
|
TCursor cur_rmovana(&rel_rmovana, filtro, 2, &da_rmovana, &a_rmovana);
|
|
|
|
|
const long rmovana_items = cur_rmovana.items();
|
|
|
|
|
cur_rmovana.freeze();
|
|
|
|
|
|
|
|
|
|
if (rmovana_items > 0)
|
|
|
|
|
{
|
|
|
|
|
const TRectype& movana = rel_rmovana.curr(LF_MOVANA);
|
|
|
|
|
for (cur_rmovana = 0; cur_rmovana.pos() < rmovana_items; ++cur_rmovana)
|
|
|
|
|
{
|
|
|
|
|
if (movana.get_char(MOVANA_SEZIONE) == 'D')
|
|
|
|
|
budget -= movana.get_real(MOVANA_TOTDOC);
|
|
|
|
|
if (movana.get_char(MOVANA_SEZIONE) == 'A')
|
|
|
|
|
budget += movana.get_real(MOVANA_TOTDOC);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return budget;
|
|
|
|
|
}
|
2005-06-29 14:34:28 +00:00
|
|
|
|
|
|
|
|
|
const TVariant& TPrint_rendiconto_ca_recordset::get(const char* column_name) const
|
|
|
|
|
{
|
|
|
|
|
|
2005-07-11 17:45:52 +00:00
|
|
|
|
if (*column_name == '#')
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
if (strcmp(column_name, "#PREVENTIVO") == 0)
|
|
|
|
|
{
|
|
|
|
|
TVariant& var = get_tmp_var();
|
|
|
|
|
var = rendiconto_recordset()->somma_budget(get(RMOVANA_CODCONTO).as_string(), "P");
|
|
|
|
|
return var;
|
|
|
|
|
}
|
|
|
|
|
if (strcmp(column_name, "#VARIAZIONE") == 0)
|
|
|
|
|
{
|
|
|
|
|
TVariant& var = get_tmp_var();
|
|
|
|
|
var = rendiconto_recordset()->somma_budget(get(RMOVANA_CODCONTO).as_string(), "V");
|
|
|
|
|
return var;
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-06-29 14:34:28 +00:00
|
|
|
|
return TISAM_recordset::get(column_name);
|
|
|
|
|
}
|
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
void TPrint_rendiconto_ca_recordset::salva_rmovana(const TRectype& rmovana, const TRectype& movana)
|
2005-06-29 14:34:28 +00:00
|
|
|
|
{
|
2005-07-07 17:25:53 +00:00
|
|
|
|
//tipo movimento CONSUNTIVO
|
|
|
|
|
const char tipomov = movana.get_char(MOVANA_TIPOMOV);
|
|
|
|
|
if (tipomov <= ' ')
|
2005-06-29 14:34:28 +00:00
|
|
|
|
{
|
2005-07-07 17:25:53 +00:00
|
|
|
|
//scegli i campi da mettere
|
|
|
|
|
_tmp->curr().put("CONTO", rmovana.get(RMOVANA_CODCONTO)); //conto
|
2005-07-11 17:45:52 +00:00
|
|
|
|
_tmp->curr().put("CODNUM", movana.get(MOVANA_DCODNUM)); //codnum del documento che origina il movana
|
|
|
|
|
_tmp->curr().put("DATA", movana.get(MOVANA_DATAREG)); //data del movana
|
2005-07-07 17:25:53 +00:00
|
|
|
|
_tmp->curr().put("NUMREG", movana.get(MOVANA_NUMREG));
|
|
|
|
|
_tmp->curr().put("NUMDOCRIF", movana.get(MOVANA_DNDOC));
|
|
|
|
|
_tmp->curr().put("DATADOCRIF", movana.get(MOVANA_DATADOC));
|
|
|
|
|
_tmp->curr().put("DESC", movana.get(MOVANA_DESCR)); //??veramente non si sa??
|
|
|
|
|
_tmp->curr().put("NRIGA", rmovana.get(RMOVANA_NUMRIG));
|
|
|
|
|
_tmp->curr().put("DESCRIGA", movana.get(RMOVANA_DESCR));
|
|
|
|
|
_tmp->curr().put("DANDOC", movana.get(MOVANA_DNDOC));
|
|
|
|
|
|
|
|
|
|
//qui ci vuole l'algoritmo di calcolo di fatturato/maturato/impegnato in base al TIPODOC
|
|
|
|
|
//o al CODNUM (***quale campo non si sa di preciso***)
|
|
|
|
|
const TString4 tipodoc = movana.get(MOVANA_TIPODOC);
|
|
|
|
|
|
|
|
|
|
/* _tmp->curr().put("FATTURATO", movana.get(MOVANA_));
|
|
|
|
|
_tmp->curr().put("MATURATO", movana.get(MOVANA_));
|
|
|
|
|
_tmp->curr().put("IMPEGNATO", movana.get(MOVANA_));*/
|
|
|
|
|
|
|
|
|
|
_tmp->write(); // aggiunge i record al file temporaneo
|
2005-06-29 14:34:28 +00:00
|
|
|
|
}
|
2005-07-07 17:25:53 +00:00
|
|
|
|
}
|
2005-06-29 14:34:28 +00:00
|
|
|
|
|
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
void TPrint_rendiconto_ca_recordset::crea_righe_rmovana()
|
|
|
|
|
{
|
2005-06-29 14:34:28 +00:00
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
TRelation rel_rmovana(LF_RMOVANA);
|
|
|
|
|
rel_rmovana.add(LF_MOVANA, "NUMREG==NUMREG"); //aggiunge le testate x avere tipi mov e descr
|
2005-06-29 14:34:28 +00:00
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
//..crea un cursore su rmovana per vedere se i conti selezionati hanno veri movimenti che soddisfano
|
|
|
|
|
//i parametri del filtro sulla maschera
|
|
|
|
|
TRectype da_rmovana(LF_RMOVANA);
|
|
|
|
|
da_rmovana.put(RMOVANA_CODCONTO, _daconto);
|
|
|
|
|
da_rmovana.put(RMOVANA_DATACOMP, _dadata);
|
|
|
|
|
TRectype a_rmovana(LF_RMOVANA);
|
|
|
|
|
a_rmovana.put(RMOVANA_CODCONTO, _aconto);
|
|
|
|
|
a_rmovana.put(RMOVANA_DATACOMP, _adata);
|
2005-06-29 14:34:28 +00:00
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
TString filtro;
|
|
|
|
|
if (_codcosto.not_empty())
|
|
|
|
|
filtro << "(" << RMOVANA_CODCCOSTO << "==\"" << _codcosto << "\")";
|
|
|
|
|
if (_codcms.not_empty())
|
|
|
|
|
{
|
|
|
|
|
if (filtro.not_empty())
|
|
|
|
|
filtro << "&&";
|
|
|
|
|
filtro << "(" << RMOVANA_CODCMS << "==\"" << _codcms << "\")";
|
|
|
|
|
}
|
|
|
|
|
if (_codfas.not_empty())
|
|
|
|
|
{
|
|
|
|
|
if (filtro.not_empty())
|
|
|
|
|
filtro << "&&";
|
|
|
|
|
filtro << "(" << RMOVANA_CODFASE << "==\"" << _codfas << "\")";
|
|
|
|
|
}
|
2005-06-29 14:34:28 +00:00
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
TCursor cur_rmovana(&rel_rmovana, filtro, 2, &da_rmovana, &a_rmovana);
|
|
|
|
|
const long rmovana_items = cur_rmovana.items();
|
|
|
|
|
cur_rmovana.freeze();
|
2005-06-29 14:34:28 +00:00
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
if (rmovana_items > 0)
|
|
|
|
|
{
|
|
|
|
|
const TRectype& rmovana = cur_rmovana.curr();
|
|
|
|
|
const TRectype& movana = rel_rmovana.curr(LF_MOVANA);
|
|
|
|
|
for (cur_rmovana = 0; cur_rmovana.pos() < rmovana_items; ++cur_rmovana)
|
|
|
|
|
salva_rmovana(rmovana, movana);
|
|
|
|
|
}
|
2005-06-29 14:34:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
void TPrint_rendiconto_ca_recordset::crea_righe_rdoc(const TPrint_rendiconto_ca_mask& msk)
|
2005-06-29 14:34:28 +00:00
|
|
|
|
{
|
2005-07-07 17:25:53 +00:00
|
|
|
|
|
|
|
|
|
//scanning del file dei documenti alla ricerca di quelli che hanno la data ed il CODNUM
|
|
|
|
|
//validi nei filtri impostati dall'utente
|
|
|
|
|
TRelation rel_doc(LF_DOC);
|
|
|
|
|
// rel_doc.add(LF_RIGHEDOC, "CODNUM==CODNUM|ANNO==ANNO|PROVV==PROVV|NDOC==NDOC"); //aggiunge le testate
|
|
|
|
|
|
|
|
|
|
TRectype dadoc(LF_DOC);
|
|
|
|
|
TRectype adoc(LF_DOC);
|
|
|
|
|
TString filtro_date;
|
|
|
|
|
|
|
|
|
|
dadoc.put(DOC_PROVV, 'D');
|
|
|
|
|
adoc.put(DOC_PROVV, 'D');
|
|
|
|
|
|
|
|
|
|
//se siamo fortunati l'anno si pu<70> trovare cos<6F>..
|
|
|
|
|
int anno = msk.get_int(F_ANNO);
|
|
|
|
|
if (anno == 0 && _dadata.year() == _adata.year())
|
|
|
|
|
anno = _adata.year();
|
|
|
|
|
|
|
|
|
|
if (anno > 0)
|
|
|
|
|
{
|
|
|
|
|
dadoc.put(DOC_ANNO, anno);
|
|
|
|
|
adoc.put(DOC_ANNO, anno);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_dadata.ok())
|
|
|
|
|
filtro_date << "(ANSI(DATADOC)>=" << _dadata.date2ansi() << ")";
|
|
|
|
|
if (_adata.ok())
|
|
|
|
|
{
|
|
|
|
|
if (filtro_date.not_empty())
|
|
|
|
|
filtro_date << "&&";
|
|
|
|
|
|
|
|
|
|
filtro_date << "(ANSI(DATADOC)<=" << _adata.date2ansi() << ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TContabilizzazione_analitica cont_anal; //oggetto necessario per contabilizzare il documento in osservazione
|
|
|
|
|
|
|
|
|
|
//deve filtrare per i soli documenti con codnum presente nello sheet dei codnum
|
|
|
|
|
TSheet_field& sheet = msk.sfield(F_RIGHE_NUM);
|
|
|
|
|
|
|
|
|
|
FOR_EACH_SHEET_ROW(sheet, r, row)
|
|
|
|
|
{
|
|
|
|
|
const TString4 codnum(row->get(0)); //prende il codice numerazione sulla riga
|
|
|
|
|
if (anno > 0)
|
|
|
|
|
{
|
|
|
|
|
dadoc.put(DOC_CODNUM, codnum);
|
|
|
|
|
adoc.put(DOC_CODNUM, codnum);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TString filtro = filtro_date;
|
|
|
|
|
if (filtro.not_empty())
|
|
|
|
|
filtro << "&&";
|
|
|
|
|
filtro << "(CODNUM==" << codnum << ")";
|
|
|
|
|
|
|
|
|
|
TCursor cur_doc(&rel_doc, filtro, 1, &dadoc, &adoc);
|
|
|
|
|
const long doc_items = cur_doc.items();
|
|
|
|
|
cur_doc.freeze();
|
|
|
|
|
|
|
|
|
|
for (cur_doc = 0; cur_doc.pos() < doc_items; ++cur_doc)
|
|
|
|
|
{
|
|
|
|
|
TDocumento doc(cur_doc.curr());
|
|
|
|
|
TAnal_mov mov;
|
|
|
|
|
cont_anal.elabora(doc, 0, NULL, false, mov);
|
|
|
|
|
for (int i = 1; i <= mov.rows(); i++)
|
|
|
|
|
salva_rmovana(mov.body()[i], mov);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-29 14:34:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
|
|
|
|
|
void TPrint_rendiconto_ca_recordset::crea_trr(const TFilename& trr) const
|
2005-06-29 14:34:28 +00:00
|
|
|
|
{
|
2005-07-07 17:25:53 +00:00
|
|
|
|
ofstream of(trr);
|
2005-07-11 17:45:52 +00:00
|
|
|
|
of << 1000 << endl;
|
2005-07-07 17:25:53 +00:00
|
|
|
|
of << 13 << endl;
|
|
|
|
|
of << "CONTO|1|20|0|Conto analitico" << endl;
|
|
|
|
|
of << "CODNUM|1|4|0|Numerazione documento" << endl;
|
|
|
|
|
of << "DATA|5|8|0|Data movimento o documento" << endl;
|
|
|
|
|
of << "NUMREG|3|7|0|Numero registrazione o documento" << endl;
|
|
|
|
|
of << "NUMDOCRIF|1|7|0|Numero documento riferimento" << endl;
|
|
|
|
|
of << "DATADOCRIF|5|8|0|Data documento riferimento" << endl;
|
|
|
|
|
of << "DESC|1|50|0|Descrizione movimento o documento" << endl;
|
|
|
|
|
of << "NRIGA|2|3|0|Riga movimento o documento" << endl;
|
|
|
|
|
of << "DESCRIGA|1|50|0|Descrizione riga movimento o documento" << endl;
|
|
|
|
|
of << "DANDOC|3|7|0|Riferimento ordine/bolla" << endl;
|
|
|
|
|
of << "FATTURATO|4|18|5|Fatturato" << endl;
|
|
|
|
|
of << "MATURATO|4|18|5|Maturato" << endl;
|
|
|
|
|
of << "IMPEGNATO|4|18|5|Impegnato" << endl;
|
|
|
|
|
of << 1 << endl;
|
|
|
|
|
of << "CONTO+CODNUM+DATA+NUMREG" << endl;
|
2005-06-29 14:34:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
void TPrint_rendiconto_ca_recordset::set_filter(const TPrint_rendiconto_ca_mask& msk, int cms_row)
|
2005-06-29 14:34:28 +00:00
|
|
|
|
{
|
2005-07-07 17:25:53 +00:00
|
|
|
|
//se esiste il file temporano con tracciato persomalizzato lo cancella e lo ricrea vuoto
|
2005-07-11 17:45:52 +00:00
|
|
|
|
TFilename trr;
|
|
|
|
|
trr.temp("rendy");
|
|
|
|
|
TFilename dbf(trr);
|
|
|
|
|
|
|
|
|
|
trr.ext("trr");
|
|
|
|
|
dbf.ext("dbf");
|
2005-07-07 17:25:53 +00:00
|
|
|
|
|
|
|
|
|
//crea il file .trr in base ai parametri del metodo
|
|
|
|
|
crea_trr(trr);
|
|
|
|
|
|
|
|
|
|
if (_tmp != NULL)
|
|
|
|
|
delete _tmp;
|
2005-06-29 14:34:28 +00:00
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
_tmp = new TExternisamfile(dbf, trr);
|
2005-06-29 14:34:28 +00:00
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
//prende un po' di dati dalla maschera...
|
2005-06-29 14:34:28 +00:00
|
|
|
|
_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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dadata = msk.get_date(F_DATAINI);
|
|
|
|
|
_adata = msk.get_date(F_DATAFIN);
|
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
//metodo per riempire il file
|
|
|
|
|
crea_righe_rmovana();
|
2005-06-29 14:34:28 +00:00
|
|
|
|
|
2005-07-07 17:25:53 +00:00
|
|
|
|
crea_righe_rdoc(msk);
|
2005-06-29 14:34:28 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
// REPORT
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
class TPrint_rendiconto_ca_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 TPrint_rendiconto_ca_mask& msk, int cms_row);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool TPrint_rendiconto_ca_rep::get_usr_val(const TString& name, TVariant& var) const
|
|
|
|
|
{
|
|
|
|
|
return TAnal_report::get_usr_val(name, var);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPrint_rendiconto_ca_rep::set_recordset(const TString& sql)
|
|
|
|
|
{
|
|
|
|
|
TPrint_rendiconto_ca_recordset* rs = new TPrint_rendiconto_ca_recordset(sql);
|
|
|
|
|
return TReport::set_recordset(rs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TPrint_rendiconto_ca_rep::set_filter(const TPrint_rendiconto_ca_mask& msk, int cms_row)
|
|
|
|
|
{
|
|
|
|
|
const int tipoconti = 1; //stronzata per poter compilare inizialmente
|
|
|
|
|
|
|
|
|
|
TPrint_rendiconto_ca_recordset* recset = NULL;
|
|
|
|
|
|
|
|
|
|
const char* query ="USE RMOVANA KEY 2\nJOIN MOVANA INTO NUMREG==NUMREG";
|
|
|
|
|
switch (tipoconti)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
recset = new TPrint_rendiconto_ca_recordset(query);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2005-07-07 17:25:53 +00:00
|
|
|
|
recset = new TPrint_rendiconto_ca_recordset(query);
|
2005-06-29 14:34:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
recset->set_filter(msk, cms_row);
|
|
|
|
|
TAnal_report::set_recordset(recset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
// APPLICAZIONE
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
class TPrint_rendiconto_ca : public TSkeleton_application
|
|
|
|
|
{
|
|
|
|
|
TPrint_rendiconto_ca_mask * _mask;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool create();
|
|
|
|
|
bool destroy();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual void main_loop();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool TPrint_rendiconto_ca::create()
|
|
|
|
|
{
|
|
|
|
|
_mask = new TPrint_rendiconto_ca_mask;
|
|
|
|
|
return TSkeleton_application::create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPrint_rendiconto_ca::destroy()
|
|
|
|
|
{
|
|
|
|
|
delete _mask;
|
|
|
|
|
return TSkeleton_application::destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TPrint_rendiconto_ca::main_loop()
|
|
|
|
|
{
|
|
|
|
|
while (_mask->run() == K_ENTER)
|
|
|
|
|
{
|
|
|
|
|
//costruzione della query x il report in base ai parametri della maschera
|
|
|
|
|
TSheet_field& sheet = _mask->sfield(F_RIGHE);
|
|
|
|
|
const int n_righe_sheet = sheet.items();
|
|
|
|
|
//se lo sheet <20> vuoto aggiunge una riga vuota
|
|
|
|
|
if (n_righe_sheet == 0)
|
|
|
|
|
sheet.insert();
|
|
|
|
|
|
|
|
|
|
//report e book
|
|
|
|
|
TReport_book book; //book dei report
|
|
|
|
|
TString path = _mask->get(F_REPORT);
|
|
|
|
|
if (path.empty())
|
|
|
|
|
path = "ca3700a";
|
|
|
|
|
TPrint_rendiconto_ca_rep rep;
|
|
|
|
|
rep.load(path);
|
|
|
|
|
|
|
|
|
|
FOR_EACH_SHEET_ROW(sheet, r, row)
|
|
|
|
|
{
|
|
|
|
|
rep.set_filter(*_mask, r);
|
|
|
|
|
book.add(rep);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
book.print_or_preview(); //stampa il book dei report
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ca3700(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
TPrint_rendiconto_ca a;
|
|
|
|
|
a.run(argc, argv, TR("Stampa rendiconto"));
|
|
|
|
|
return 0;
|
2005-07-07 17:25:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//Prototipi di metodi di calcolo (ricordarsi di usare come importi quelli di riga)
|
|
|
|
|
COMM = impegnato
|
|
|
|
|
ACEM = maturato
|
|
|
|
|
CONS = fatturato
|
|
|
|
|
CNTBZ = checazzoneso
|
|
|
|
|
|
|
|
|
|
//Calcolatore per tipi (AN,PN),FM
|
|
|
|
|
calcolatore (const int tipo, const int classe, const int dare)
|
|
|
|
|
{
|
|
|
|
|
const int segno = classe * dare; //essendo classe e dare = + o - 1, il segno lo si ottiene direttamente
|
|
|
|
|
if (classe == 1 && dare == -1) //unico caso in cui non rispetta il prodotto dei segni
|
|
|
|
|
{
|
|
|
|
|
I_ACEM = (I_ACEM - segno * NEW_ACEMVAL) * tipo; //tipo = 1 se AN,PN; = 0 se FM
|
|
|
|
|
I_STIMA = I_STIMA - segno * NEW_STIMAVAL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
I_ACEM = (I_ACEM + segno * NEW_ACEMVAL) * tipo;
|
|
|
|
|
I_STIMA = I_STIMA + segno * NEW_STIMAVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//questa <20> comunque sempre corretta
|
|
|
|
|
I_CNTBZ = I_CNTBZ + segno * NEW_ICNTBZVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Calcolatore per tipi (OA,OV) -> impegnato, (BA,BV) -> impegnato, (FA,FN) -> impegnato,
|
|
|
|
|
calcolatore (const int tipo)
|
|
|
|
|
{
|
|
|
|
|
switch (tipo):
|
|
|
|
|
case OA:
|
|
|
|
|
case OV:
|
|
|
|
|
I_COMM = I_COMM + NEW_COMMVAL;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BA:
|
|
|
|
|
case BV:
|
|
|
|
|
I_ACEM = I_ACEM + NEW_ACEMVAL;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case FA:
|
|
|
|
|
case FN:
|
|
|
|
|
I_CONS = I_CONS + NEW_CONSVAL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/
|