2005-05-11 17:29:14 +00:00
|
|
|
|
#include <applicat.h>
|
|
|
|
|
#include <execp.h>
|
2005-06-28 15:00:00 +00:00
|
|
|
|
#include <progind.h>
|
2005-05-11 17:29:14 +00:00
|
|
|
|
#include <reprint.h>
|
|
|
|
|
|
2005-07-28 17:11:11 +00:00
|
|
|
|
#include "../cg/cglib01.h"
|
|
|
|
|
|
2005-06-28 15:00:00 +00:00
|
|
|
|
#include "pconana.h"
|
2005-06-23 15:38:04 +00:00
|
|
|
|
#include "movana.h"
|
2005-05-12 17:36:31 +00:00
|
|
|
|
#include "rmovana.h"
|
|
|
|
|
|
2005-05-11 17:29:14 +00:00
|
|
|
|
#include "ca3.h"
|
2005-06-23 15:38:04 +00:00
|
|
|
|
#include "ca3200.h"
|
2005-05-11 17:29:14 +00:00
|
|
|
|
#include "calib01.h"
|
|
|
|
|
#include "calib02.h"
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
// MASCHERA
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
class TPrint_mastrini_ca_mask : public TAutomask
|
|
|
|
|
{
|
|
|
|
|
protected:
|
2005-06-23 15:38:04 +00:00
|
|
|
|
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-23 15:38:04 +00:00
|
|
|
|
bool test_compatible_report();
|
2005-05-11 17:29:14 +00:00
|
|
|
|
void create_page2();
|
2005-05-12 17:36:31 +00:00
|
|
|
|
int create_page2_sheet(int lf, int& y, short& dlg, bool required);
|
2005-05-11 17:29:14 +00:00
|
|
|
|
public:
|
|
|
|
|
TPrint_mastrini_ca_mask();
|
|
|
|
|
virtual ~TPrint_mastrini_ca_mask() {}
|
|
|
|
|
};
|
|
|
|
|
|
2005-06-29 15:12:31 +00:00
|
|
|
|
const TString& TPrint_mastrini_ca_mask::get_report_class() const
|
2005-06-23 15:38:04 +00:00
|
|
|
|
{
|
2005-06-29 15:12:31 +00:00
|
|
|
|
TString& classe = get_tmp_string();
|
|
|
|
|
classe = "ca3200a";
|
2005-06-28 15:00:00 +00:00
|
|
|
|
// const int stp = get_int(F_TIPOCONTI);
|
2005-06-29 15:12:31 +00:00
|
|
|
|
// classe << (stp == 1 ? 'a' : 'b'); // tipo di report da usare in caso di report multipli
|
|
|
|
|
return classe;
|
2005-06-23 15:38:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPrint_mastrini_ca_mask::test_compatible_report()
|
|
|
|
|
{
|
2005-06-29 15:12:31 +00:00
|
|
|
|
TFilename lib = get_report_class();
|
2005-06-23 15:38:04 +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-23 15:38:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!ok)
|
|
|
|
|
{
|
|
|
|
|
set(F_REPORT, lib);
|
|
|
|
|
lib.ext("rep");
|
|
|
|
|
ok = lib.custom_path();
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPrint_mastrini_ca_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
|
{
|
|
|
|
|
switch (o.dlg())
|
|
|
|
|
{
|
|
|
|
|
case F_TIPOCONTI:
|
|
|
|
|
if (e == fe_init || e == fe_modify)
|
|
|
|
|
{
|
2005-06-28 15:00:00 +00:00
|
|
|
|
test_compatible_report(); //in base al tipo di conti da stampare setta i report compatibili (solo nel caso di rep multipli)
|
2005-06-23 15:38:04 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_REPORT:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
2005-06-29 15:12:31 +00:00
|
|
|
|
const TString8 lib = get_report_class();
|
2005-06-23 15:38:04 +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;
|
2005-07-28 17:11:11 +00:00
|
|
|
|
case F_DATAINI:
|
|
|
|
|
case F_DATAFIN:
|
|
|
|
|
if (e == fe_close)
|
|
|
|
|
{
|
|
|
|
|
const int anno = get_int(F_ANNO);
|
|
|
|
|
if (anno > 0) //se viene selezionato un esercizio..
|
|
|
|
|
{
|
|
|
|
|
TEsercizi_contabili esc; //..le date devono essere incluse nell'esercizio selezionato!
|
|
|
|
|
const TDate data = o.get();
|
|
|
|
|
if (!data.empty() && esc.date2esc(data) != anno)
|
|
|
|
|
return error_box(TR("La data deve appartenere all'anno selezionato"));
|
|
|
|
|
}
|
|
|
|
|
else //se l'esercizio <20> vuoto le date diventano obbligatorie!!
|
|
|
|
|
{
|
|
|
|
|
if (o.empty())
|
|
|
|
|
return error_box(TR("La data <20> obbligatoria in quanto manca l'esercizio"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2005-06-23 15:38:04 +00:00
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-12 17:36:31 +00:00
|
|
|
|
int TPrint_mastrini_ca_mask::create_page2_sheet(int lf, int& y, short& dlg, bool required)
|
2005-05-11 17:29:14 +00:00
|
|
|
|
{
|
2005-05-12 17:36:31 +00:00
|
|
|
|
TSheet_field& sf = sfield(F_RIGHE);
|
|
|
|
|
TMask& sm = sf.sheet_mask();
|
2005-05-11 17:29:14 +00:00
|
|
|
|
|
2005-05-12 22:17:46 +00:00
|
|
|
|
const int h = ca_create_fields(sm, 0, lf, 1, y, dlg, dlg+50);
|
2005-05-11 17:29:14 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < h; i++)
|
|
|
|
|
{
|
2005-05-12 22:17:46 +00:00
|
|
|
|
TEdit_field& fld = sm.efield(dlg+i);
|
2005-05-11 17:29:14 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-12 17:36:31 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2005-05-12 22:17:46 +00:00
|
|
|
|
TEdit_field& dfld = sm.efield(dlg+50+i);
|
2005-05-12 17:36:31 +00:00
|
|
|
|
dfld.set_field(EMPTY_STRING); // Toglie campi che fan saltare gli output!
|
2005-05-11 17:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-05-12 17:36:31 +00:00
|
|
|
|
y += h+1;
|
2005-05-11 17:29:14 +00:00
|
|
|
|
dlg += h;
|
|
|
|
|
|
|
|
|
|
return h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TPrint_mastrini_ca_mask::create_page2()
|
|
|
|
|
{
|
2005-05-12 17:36:31 +00:00
|
|
|
|
TSheet_field& sf = sfield(F_RIGHE);
|
|
|
|
|
TMask& sm = sf.sheet_mask();
|
|
|
|
|
sm.hide(-1);
|
|
|
|
|
|
2005-05-11 17:29:14 +00:00
|
|
|
|
const TMultilevel_code_info& fasinfo = ca_multilevel_code_info(LF_FASI);
|
|
|
|
|
|
|
|
|
|
TConfig_anal ini;
|
|
|
|
|
const bool fsc_req = ini.get_bool("FscRequired");
|
|
|
|
|
|
2005-05-13 13:05:41 +00:00
|
|
|
|
int y = 1;
|
2005-05-12 17:36:31 +00:00
|
|
|
|
short dlg = S_CDC1 + 100; // id del primo campo da generare
|
2005-05-11 17:29:14 +00:00
|
|
|
|
|
|
|
|
|
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)
|
2005-05-12 17:36:31 +00:00
|
|
|
|
create_page2_sheet(LF_FASI, y, dlg, fsc_req);
|
2005-05-11 17:29:14 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const bool cdc_req = ini.get_bool("CdcRequired");
|
2005-05-12 17:36:31 +00:00
|
|
|
|
create_page2_sheet(LF_CDC, y, dlg, cdc_req);
|
2005-05-11 17:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
if (level == "CMS") // Crea commessa
|
|
|
|
|
{
|
|
|
|
|
if (fasinfo.parent() == LF_COMMESSE)
|
2005-05-12 17:36:31 +00:00
|
|
|
|
create_page2_sheet(LF_FASI, y, dlg, fsc_req);
|
2005-05-11 17:29:14 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const bool cms_req = ini.get_bool("CmsRequired");
|
2005-05-12 17:36:31 +00:00
|
|
|
|
create_page2_sheet(LF_COMMESSE, y, dlg, cms_req);
|
2005-05-11 17:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fasinfo.levels() > 0 && fasinfo.parent() <= 0)
|
2005-05-12 17:36:31 +00:00
|
|
|
|
create_page2_sheet(LF_FASI, y, dlg, fsc_req);
|
2005-05-13 13:05:41 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2005-05-11 17:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TPrint_mastrini_ca_mask::TPrint_mastrini_ca_mask()
|
2005-06-23 15:38:04 +00:00
|
|
|
|
:TAutomask("ca3200")
|
2005-05-11 17:29:14 +00:00
|
|
|
|
{
|
|
|
|
|
TConfig_anal cfg;
|
|
|
|
|
const bool use_pdcc = cfg.get_bool("UsePdcc");
|
|
|
|
|
|
|
|
|
|
const int logicnum = use_pdcc ? LF_PCON : LF_PCONANA;
|
2005-07-28 17:11:11 +00:00
|
|
|
|
const int nfields = ca_create_fields(*this, 0, logicnum, 2, 4, F_CDC1_INI, F_DES1_INI, 0x0, "#DACONTO");
|
|
|
|
|
ca_create_fields(*this, 0, logicnum, 2, 10, F_CDC1_FIN, F_DES1_FIN, 0x0, "#ACONTO");
|
2005-05-11 17:29:14 +00:00
|
|
|
|
|
|
|
|
|
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-06-28 15:00:00 +00:00
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
|
// RECORDSET PRINCIPALE (caso standard: conti movimentati)
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
2005-06-23 15:38:04 +00:00
|
|
|
|
|
|
|
|
|
class TPrint_mastrini_ca_recordset : public TISAM_recordset
|
|
|
|
|
{
|
2005-06-28 15:00:00 +00:00
|
|
|
|
protected:
|
2005-06-23 15:38:04 +00:00
|
|
|
|
int _anno;
|
|
|
|
|
int _tipoconti;
|
2005-06-24 13:09:46 +00:00
|
|
|
|
int _tipimov;
|
2005-06-23 15:38:04 +00:00
|
|
|
|
TDate _dadata, _adata;
|
|
|
|
|
long _danumreg, _anumreg;
|
|
|
|
|
TString _daconto, _aconto, _codcosto, _codcms, _codfas;
|
2005-06-24 13:09:46 +00:00
|
|
|
|
|
|
|
|
|
protected: //da libreria
|
|
|
|
|
virtual const TVariant& get(const char* column_name) const;
|
2005-06-23 15:38:04 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
static bool mov_filter(const TRelation* rel);
|
|
|
|
|
bool valid_record(const TRelation& rel) const;
|
|
|
|
|
virtual void set_custom_filter(TCursor& cur) const;
|
2005-06-24 13:09:46 +00:00
|
|
|
|
const TImporto& saldo_iniziale(const char* conto) const;
|
2005-06-23 15:38:04 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2005-06-28 15:00:00 +00:00
|
|
|
|
virtual void set_filter(const TPrint_mastrini_ca_mask& msk, int cms_row);
|
2005-06-23 15:38:04 +00:00
|
|
|
|
TPrint_mastrini_ca_recordset(const TString& sql) : TISAM_recordset(sql) { }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const TPrint_mastrini_ca_recordset* myself = NULL;
|
|
|
|
|
|
|
|
|
|
//metodo per riconoscere se il record corrente soddisfa i filtri della maschera...strafighissimo!
|
|
|
|
|
bool TPrint_mastrini_ca_recordset::valid_record(const TRelation& rel) const
|
|
|
|
|
{
|
|
|
|
|
//prima controlla la testata...
|
|
|
|
|
const TRectype& mov = rel.curr(LF_MOVANA);
|
|
|
|
|
|
2005-06-24 13:09:46 +00:00
|
|
|
|
const char tipomov = mov.get_char(MOVANA_TIPOMOV);
|
|
|
|
|
int tipomov_int = 0;
|
|
|
|
|
switch (tipomov)
|
2005-06-23 15:38:04 +00:00
|
|
|
|
{
|
2005-06-24 13:09:46 +00:00
|
|
|
|
case 'P': tipomov_int = 2; break;
|
|
|
|
|
case 'V': tipomov_int = 4; break;
|
|
|
|
|
default: tipomov_int = 1; break;
|
|
|
|
|
}
|
|
|
|
|
if ((_tipimov & tipomov_int) == 0)
|
|
|
|
|
return false;
|
2005-06-23 15:38:04 +00:00
|
|
|
|
|
|
|
|
|
//..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_mastrini_ca_recordset::mov_filter(const TRelation* rel)
|
|
|
|
|
{
|
|
|
|
|
return myself->valid_record(*rel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TPrint_mastrini_ca_recordset::set_custom_filter(TCursor& cur) const
|
|
|
|
|
{
|
|
|
|
|
//filtro sui conti selezionati sulla maschera
|
2005-06-28 15:00:00 +00:00
|
|
|
|
TRectype darec(cur.curr()), arec(cur.curr()); //record corrente (rmovana (solo movimentati))
|
|
|
|
|
darec.put(RMOVANA_CODCONTO, _daconto);
|
|
|
|
|
darec.put(RMOVANA_DATACOMP, _dadata);
|
|
|
|
|
arec.put(RMOVANA_CODCONTO, _aconto);
|
|
|
|
|
arec.put(RMOVANA_DATACOMP, _adata);
|
2005-06-23 15:38:04 +00:00
|
|
|
|
cur.setregion(darec, arec);
|
|
|
|
|
|
|
|
|
|
myself = this;
|
|
|
|
|
cur.set_filterfunction(mov_filter, true);
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-24 13:09:46 +00:00
|
|
|
|
const TImporto& TPrint_mastrini_ca_recordset::saldo_iniziale(const char* conto) const
|
|
|
|
|
{
|
2005-06-27 16:35:27 +00:00
|
|
|
|
TAnal_bill bill(conto, _codcosto, _codcms, _codfas);
|
|
|
|
|
const TSaldanal& saldo = ca_saldo(bill, _dadata, _adata, _tipimov);
|
2005-06-24 13:09:46 +00:00
|
|
|
|
return saldo._ini;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const TVariant& TPrint_mastrini_ca_recordset::get(const char* column_name) const
|
|
|
|
|
{
|
|
|
|
|
if (strncmp(column_name, "SALDOINI:", 9) == 0)
|
|
|
|
|
{
|
|
|
|
|
const TString16 sub_field = column_name+9;
|
|
|
|
|
const TString& conto = get(RMOVANA_CODCONTO).as_string();
|
|
|
|
|
const TImporto& saldo_ini = saldo_iniziale(conto);
|
|
|
|
|
|
|
|
|
|
TVariant& var = get_tmp_var();
|
|
|
|
|
if (sub_field == "DARE")
|
|
|
|
|
var = saldo_ini.sezione() == 'D' ? saldo_ini.valore() : ZERO;
|
|
|
|
|
else
|
|
|
|
|
var = saldo_ini.sezione() == 'A' ? saldo_ini.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);
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-23 15:38:04 +00:00
|
|
|
|
//metodo per caricare i valori nel recordset dalla maschera...fighissimo!!
|
|
|
|
|
void TPrint_mastrini_ca_recordset::set_filter(const TPrint_mastrini_ca_mask& msk, int cms_row)
|
|
|
|
|
{
|
|
|
|
|
_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-06-24 13:09:46 +00:00
|
|
|
|
_tipimov = 0;
|
|
|
|
|
switch (msk.get(F_TIPIMOV)[0])
|
|
|
|
|
{
|
|
|
|
|
case 'N': _tipimov = 1; break;
|
|
|
|
|
case 'P': _tipimov = 6; break;
|
|
|
|
|
default: _tipimov = 7; break;
|
|
|
|
|
}
|
2005-06-28 15:00:00 +00:00
|
|
|
|
_tipoconti = msk.get_int(F_TIPOCONTI);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// RECORDSET SECONDARIO (casi alternativi: conti con saldo != 0 e tutti i conti)
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class TPrint_mastrini_ca_alternative_recordset : public TPrint_mastrini_ca_recordset
|
|
|
|
|
{
|
|
|
|
|
TIsamtempfile* _tmp_rmovana;
|
|
|
|
|
protected:
|
|
|
|
|
const TImporto& saldo_finale(const char* conto) const;
|
|
|
|
|
virtual void set_custom_filter(TCursor& cur) const;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual void set_filter(const TPrint_mastrini_ca_mask& msk, int cms_row);
|
|
|
|
|
TPrint_mastrini_ca_alternative_recordset(const TString& sql);
|
|
|
|
|
~TPrint_mastrini_ca_alternative_recordset() { delete _tmp_rmovana; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TPrint_mastrini_ca_alternative_recordset::TPrint_mastrini_ca_alternative_recordset(const TString& sql)
|
|
|
|
|
: TPrint_mastrini_ca_recordset(sql)
|
|
|
|
|
{
|
|
|
|
|
_tmp_rmovana = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const TImporto& TPrint_mastrini_ca_alternative_recordset::saldo_finale(const char* conto) const
|
|
|
|
|
{
|
|
|
|
|
TAnal_bill bill(conto, _codcosto, _codcms, _codfas);
|
|
|
|
|
const TSaldanal& saldo = ca_saldo(bill, _dadata, _adata, _tipimov);
|
|
|
|
|
return saldo._fin;
|
|
|
|
|
}
|
2005-06-23 15:38:04 +00:00
|
|
|
|
|
2005-06-28 15:00:00 +00:00
|
|
|
|
void TPrint_mastrini_ca_alternative_recordset::set_custom_filter(TCursor& cur) const
|
|
|
|
|
{
|
|
|
|
|
//crea un file temporaneo che non viene distrutto ad inizio stampa effettiva
|
|
|
|
|
TIsamtempfile* tmp = new TIsamtempfile(LF_RMOVANA, "anal", false, false);
|
|
|
|
|
relation()->replace(tmp); //sostituisce il vero file rmovana con quello temporaneo
|
2005-06-23 15:38:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-06-28 15:00:00 +00:00
|
|
|
|
void TPrint_mastrini_ca_alternative_recordset::set_filter(const TPrint_mastrini_ca_mask& msk, int cms_row)
|
|
|
|
|
{
|
|
|
|
|
//se esiste non vuoto il file temporano con tracciato rmovana lo cancella e lo ricrea vuoto
|
|
|
|
|
if (_tmp_rmovana != NULL)
|
|
|
|
|
delete _tmp_rmovana;
|
|
|
|
|
|
|
|
|
|
_tmp_rmovana = new TIsamtempfile(LF_RMOVANA, "anal", true, true);
|
|
|
|
|
|
|
|
|
|
//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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dadata = msk.get_date(F_DATAINI);
|
|
|
|
|
_adata = msk.get_date(F_DATAFIN);
|
|
|
|
|
|
|
|
|
|
_tipimov = 0;
|
|
|
|
|
switch (msk.get(F_TIPIMOV)[0])
|
|
|
|
|
{
|
|
|
|
|
case 'N': _tipimov = 1; break;
|
|
|
|
|
case 'P': _tipimov = 6; break;
|
|
|
|
|
default: _tipimov = 7; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_tipoconti = msk.get_int(F_TIPOCONTI);
|
|
|
|
|
|
|
|
|
|
//scandisce il piano dei conti analitico creando un cursore con i conti nell'intervallo scelto sulla maschera
|
|
|
|
|
TRelation rel_pconana(LF_PCONANA);
|
|
|
|
|
|
|
|
|
|
TRectype daconto(LF_PCONANA);
|
|
|
|
|
daconto.put(PCONANA_CODCONTO, _daconto);
|
|
|
|
|
TRectype aconto(LF_PCONANA);
|
|
|
|
|
aconto.put(PCONANA_CODCONTO, _aconto);
|
|
|
|
|
|
|
|
|
|
//solo i gr/co/sottoc completi interessano!!!
|
|
|
|
|
int 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);
|
|
|
|
|
|
|
|
|
|
TString filtro;
|
|
|
|
|
filtro << "LEN(CODCONTO)==" << contolen;
|
|
|
|
|
|
|
|
|
|
TCursor cur_pconana(&rel_pconana, filtro, 1, &daconto, &aconto);
|
|
|
|
|
const long pconana_items = cur_pconana.items();
|
|
|
|
|
cur_pconana.freeze();
|
|
|
|
|
TProgind pi(pconana_items, "Scansione conti...");
|
|
|
|
|
|
|
|
|
|
//scandisce il piano dei conti..
|
|
|
|
|
for (cur_pconana = 0; cur_pconana.pos() < pconana_items; ++cur_pconana)
|
|
|
|
|
{
|
|
|
|
|
pi.addstatus(1);
|
|
|
|
|
TRectype& current_pconana_rec = cur_pconana.curr();
|
|
|
|
|
const TString conto = current_pconana_rec.get(PCONANA_CODCONTO);
|
|
|
|
|
|
|
|
|
|
bool aggiungi = true;
|
|
|
|
|
if (_tipoconti == 2) //se si <20> scelto di stampare solo quelli con saldo != 0...
|
|
|
|
|
{
|
|
|
|
|
const TImporto& saldo_fin = saldo_finale(conto);
|
|
|
|
|
aggiungi = !saldo_fin.is_zero();
|
|
|
|
|
}
|
|
|
|
|
if (aggiungi) //se il conto va aggiunto (casi: conti con saldo !=0 trovato, tutti i conti comunque)..
|
|
|
|
|
{
|
|
|
|
|
TRelation rel_rmovana(LF_RMOVANA);
|
|
|
|
|
rel_rmovana.add(LF_MOVANA, "NUMREG==NUMREG"); //aggiunge le testate x avere i tipi mov.
|
|
|
|
|
|
|
|
|
|
//..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, conto);
|
|
|
|
|
da_rmovana.put(RMOVANA_DATACOMP, _dadata);
|
|
|
|
|
TRectype a_rmovana(LF_RMOVANA);
|
|
|
|
|
a_rmovana.put(RMOVANA_CODCONTO, conto);
|
|
|
|
|
a_rmovana.put(RMOVANA_DATACOMP, _adata);
|
|
|
|
|
|
|
|
|
|
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 << "\")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TCursor cur_rmovana(&rel_rmovana, filtro, 2, &da_rmovana, &a_rmovana);
|
|
|
|
|
const long rmovana_items = cur_rmovana.items();
|
|
|
|
|
cur_rmovana.freeze();
|
|
|
|
|
bool almeno_uno_aggiunto = false;
|
|
|
|
|
if (rmovana_items > 0)
|
|
|
|
|
{
|
|
|
|
|
for (cur_rmovana = 0; cur_rmovana.pos() < rmovana_items; ++cur_rmovana)
|
|
|
|
|
{
|
|
|
|
|
//deve coincidere anche il tipomov! sarebbe stato troppo semplice...
|
|
|
|
|
const char tipomov = rel_rmovana.curr(LF_MOVANA).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)
|
|
|
|
|
{
|
|
|
|
|
_tmp_rmovana->write(cur_rmovana.curr()); // aggiunge i record al file temporaneo
|
|
|
|
|
almeno_uno_aggiunto = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//se non ha aggiunto nemmeno un record valido..
|
|
|
|
|
//crea un record di rmovana con il solo conto,datacomp e lo aggiunge al file temporaneo
|
|
|
|
|
if (!almeno_uno_aggiunto)
|
|
|
|
|
{
|
|
|
|
|
TRectype fake_rmovana_rec(LF_RMOVANA);
|
|
|
|
|
fake_rmovana_rec.put(RMOVANA_CODCONTO, conto);
|
|
|
|
|
fake_rmovana_rec.put(RMOVANA_DATACOMP, _dadata);
|
|
|
|
|
_tmp_rmovana->write(fake_rmovana_rec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} //end if aggiungi
|
|
|
|
|
|
|
|
|
|
} //end for su pconana_items
|
|
|
|
|
|
|
|
|
|
}
|
2005-06-23 15:38:04 +00:00
|
|
|
|
|
2005-05-17 16:34:19 +00:00
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
// REPORT
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
class TPrint_mastrini_ca_rep : public TAnal_report
|
|
|
|
|
{
|
2005-06-23 15:38:04 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual bool set_recordset(const TString& sql);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
void set_filter(const TPrint_mastrini_ca_mask& msk, int cms_row);
|
2005-05-17 16:34:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-06-23 15:38:04 +00:00
|
|
|
|
bool TPrint_mastrini_ca_rep::set_recordset(const TString& sql)
|
|
|
|
|
{
|
|
|
|
|
TPrint_mastrini_ca_recordset* rs = new TPrint_mastrini_ca_recordset(sql);
|
|
|
|
|
return TReport::set_recordset(rs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TPrint_mastrini_ca_rep::set_filter(const TPrint_mastrini_ca_mask& msk, int cms_row)
|
|
|
|
|
{
|
2005-06-28 15:00:00 +00:00
|
|
|
|
const int tipoconti = msk.get_int(F_TIPOCONTI);
|
|
|
|
|
|
|
|
|
|
TPrint_mastrini_ca_recordset* recset = NULL;
|
|
|
|
|
|
|
|
|
|
const char* query ="USE RMOVANA KEY 2\nJOIN MOVANA INTO NUMREG==NUMREG";
|
|
|
|
|
switch (tipoconti)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
recset = new TPrint_mastrini_ca_recordset(query);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
recset = new TPrint_mastrini_ca_alternative_recordset(query);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
recset->set_filter(msk, cms_row);
|
|
|
|
|
TAnal_report::set_recordset(recset);
|
2005-06-23 15:38:04 +00:00
|
|
|
|
}
|
2005-05-17 16:34:19 +00:00
|
|
|
|
|
2005-05-11 17:29:14 +00:00
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
// APPLICAZIONE
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
class TPrint_mastrini_ca : public TSkeleton_application
|
|
|
|
|
{
|
|
|
|
|
TPrint_mastrini_ca_mask * _mask;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool create();
|
|
|
|
|
bool destroy();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual void main_loop();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool TPrint_mastrini_ca::create()
|
|
|
|
|
{
|
|
|
|
|
_mask = new TPrint_mastrini_ca_mask;
|
|
|
|
|
return TSkeleton_application::create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPrint_mastrini_ca::destroy()
|
|
|
|
|
{
|
|
|
|
|
delete _mask;
|
|
|
|
|
return TSkeleton_application::destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TPrint_mastrini_ca::main_loop()
|
|
|
|
|
{
|
|
|
|
|
while (_mask->run() == K_ENTER)
|
|
|
|
|
{
|
2005-05-13 13:05:41 +00:00
|
|
|
|
//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 = "ca3200a";
|
2005-05-17 16:34:19 +00:00
|
|
|
|
TPrint_mastrini_ca_rep rep;
|
|
|
|
|
rep.load(path);
|
2005-05-13 13:05:41 +00:00
|
|
|
|
|
|
|
|
|
FOR_EACH_SHEET_ROW(sheet, r, row)
|
|
|
|
|
{
|
2005-06-23 15:38:04 +00:00
|
|
|
|
rep.set_filter(*_mask, r);
|
|
|
|
|
book.add(rep);
|
2005-05-13 13:05:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
book.print_or_preview(); //stampa il book dei report
|
2005-05-11 17:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ca3200(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
TPrint_mastrini_ca a;
|
|
|
|
|
a.run(argc, argv, TR("Stampa mastrini"));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|