2005-05-11 17:29:14 +00:00
|
|
|
|
#include <applicat.h>
|
2010-03-02 16:05:52 +00:00
|
|
|
|
#include <defmask.h>
|
2005-05-11 17:29:14 +00:00
|
|
|
|
#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"
|
|
|
|
|
|
2009-07-07 13:17:27 +00:00
|
|
|
|
#include "commesse.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"
|
2005-09-06 17:58:13 +00:00
|
|
|
|
#include "camask.h"
|
2005-05-11 17:29:14 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////
|
|
|
|
|
// MASCHERA
|
|
|
|
|
////////////////////////////////////////////////////////
|
2005-09-06 17:58:13 +00:00
|
|
|
|
class TPrint_mastrini_ca_mask : public TAnal_report_mask
|
2005-05-11 17:29:14 +00:00
|
|
|
|
{
|
|
|
|
|
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-09-06 17:58:13 +00:00
|
|
|
|
|
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())
|
|
|
|
|
{
|
2010-03-02 16:05:52 +00:00
|
|
|
|
case DLG_PRINT:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
|
|
|
|
main_app().print();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case DLG_PREVIEW:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
|
|
|
|
main_app().preview();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2005-06-23 15:38:04 +00:00
|
|
|
|
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"));
|
|
|
|
|
}
|
2008-12-01 16:22:04 +00:00
|
|
|
|
break;
|
|
|
|
|
case F_ANNO:
|
|
|
|
|
if (e == fe_modify && !o.empty())
|
|
|
|
|
{
|
|
|
|
|
TEsercizi_contabili esc;
|
|
|
|
|
TDate inies, fines;
|
|
|
|
|
if (esc.code2range(atoi(o.get()), inies, fines))
|
|
|
|
|
{
|
|
|
|
|
set(F_DATAINI, inies);
|
|
|
|
|
set(F_DATAFIN, fines);
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-06-23 15:38:04 +00:00
|
|
|
|
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-11 17:29:14 +00:00
|
|
|
|
|
|
|
|
|
TPrint_mastrini_ca_mask::TPrint_mastrini_ca_mask()
|
2005-09-06 17:58:13 +00:00
|
|
|
|
:TAnal_report_mask("ca3200")
|
2005-05-11 17:29:14 +00:00
|
|
|
|
{
|
2005-09-19 10:16:43 +00:00
|
|
|
|
TConfig& cfg = ca_config();
|
2005-05-11 17:29:14 +00:00
|
|
|
|
const bool use_pdcc = cfg.get_bool("UsePdcc");
|
|
|
|
|
|
|
|
|
|
const int logicnum = use_pdcc ? LF_PCON : LF_PCONANA;
|
2005-09-06 17:58:13 +00:00
|
|
|
|
const int nfields = ca_create_fields(*this, 1, logicnum, 2, 4, F_CDC1_INI, F_DES1_INI, 0x0, "#DACONTO");
|
|
|
|
|
ca_create_fields(*this, 1, 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
|
2005-09-06 17:58:13 +00:00
|
|
|
|
create_sheet(F_RIGHE);
|
2005-05-11 17:29:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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;
|
2009-07-07 13:17:27 +00:00
|
|
|
|
default : tipomov_int = 1; break;
|
2005-06-24 13:09:46 +00:00
|
|
|
|
}
|
|
|
|
|
if ((_tipimov & tipomov_int) == 0)
|
|
|
|
|
return false;
|
2005-06-23 15:38:04 +00:00
|
|
|
|
|
2008-12-01 16:22:04 +00:00
|
|
|
|
//aggiunta 01/12/08; se non si specifica l'esercizio si DEVE tener conto della DATAREG e non della DATACOMP; quindi..
|
|
|
|
|
//..deve effettuare tale controllo e controllare se la datareg rientra nell'intervallo di date selezionato sulla maschera
|
|
|
|
|
if (_anno <= 0)
|
|
|
|
|
{
|
|
|
|
|
const TDate datareg = mov.get_date(MOVANA_DATAREG);
|
|
|
|
|
if (_dadata.ok() && datareg < _dadata)
|
|
|
|
|
return false;
|
|
|
|
|
if (_adata.ok() && datareg > _adata)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-03-31 11:09:30 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const TDate datacomp = mov.get_date(MOVANA_DATACOMP);
|
|
|
|
|
if (_dadata.ok() && datacomp < _dadata)
|
|
|
|
|
return false;
|
|
|
|
|
if (_adata.ok() && datacomp > _adata)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const TDate datafcomp = mov.get_date(MOVANA_DATAFCOMP);
|
|
|
|
|
if (datafcomp.ok() && _dadata.ok() && datafcomp < _dadata)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-12-01 16:22:04 +00:00
|
|
|
|
|
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))
|
2005-09-06 17:58:13 +00:00
|
|
|
|
|
2010-03-31 14:34:34 +00:00
|
|
|
|
if (_daconto.full())
|
2005-09-06 17:58:13 +00:00
|
|
|
|
darec.put(RMOVANA_CODCONTO, _daconto);
|
|
|
|
|
|
2010-03-31 14:34:34 +00:00
|
|
|
|
if (_aconto.full())
|
2005-09-06 17:58:13 +00:00
|
|
|
|
arec.put(RMOVANA_CODCONTO, _aconto);
|
|
|
|
|
|
2005-06-23 15:38:04 +00:00
|
|
|
|
cur.setregion(darec, arec);
|
|
|
|
|
|
|
|
|
|
myself = this;
|
2010-03-31 14:34:34 +00:00
|
|
|
|
cur.set_filterfunction(mov_filter, true); //questa gestir<69> le date
|
2005-06-23 15:38:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-31 11:09:30 +00:00
|
|
|
|
_anno = msk.get_int(F_ANNO);
|
2005-06-23 15:38:04 +00:00
|
|
|
|
_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);
|
2005-09-08 13:05:21 +00:00
|
|
|
|
// Riempie le date con valori sensati
|
|
|
|
|
if (!_dadata.ok() || !_adata.ok())
|
|
|
|
|
{
|
|
|
|
|
TEsercizi_contabili esc;
|
|
|
|
|
const int codes = msk.get_int(F_ANNO);
|
|
|
|
|
if (esc.exist(codes))
|
|
|
|
|
{
|
|
|
|
|
const TEsercizio& esercizio = esc[codes];
|
|
|
|
|
if (!_dadata.ok())
|
|
|
|
|
_dadata = esercizio.inizio();
|
|
|
|
|
if (!_adata.ok())
|
|
|
|
|
_adata = esercizio.fine();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!_adata.ok())
|
|
|
|
|
_adata = TDate(31, 12, 9999);
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-06-28 15:00:00 +00:00
|
|
|
|
|
|
|
|
|
_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
|
2005-09-06 17:58:13 +00:00
|
|
|
|
TPconana_recordset pconana;
|
|
|
|
|
|
|
|
|
|
pconana.set_filter(' ', _daconto, _aconto, _codcosto, _codcms, _codfas,
|
|
|
|
|
_dadata, _adata, _tipimov, _tipoconti==1, _tipoconti==2);
|
2005-06-28 15:00:00 +00:00
|
|
|
|
|
2005-09-06 17:58:13 +00:00
|
|
|
|
const long pconana_items = pconana.items();
|
2009-07-07 13:17:27 +00:00
|
|
|
|
TProgind pi(pconana_items, TR("Scansione conti..."));
|
2005-06-28 15:00:00 +00:00
|
|
|
|
|
2005-09-06 17:58:13 +00:00
|
|
|
|
TRelation rel_rmovana(LF_RMOVANA);
|
|
|
|
|
rel_rmovana.add(LF_MOVANA, "NUMREG==NUMREG"); //aggiunge le testate x avere i tipi mov.
|
2005-06-28 15:00:00 +00:00
|
|
|
|
|
2005-09-06 17:58:13 +00:00
|
|
|
|
TRectype da_rmovana(LF_RMOVANA);
|
|
|
|
|
da_rmovana.put(RMOVANA_DATACOMP, _dadata);
|
|
|
|
|
TRectype a_rmovana(LF_RMOVANA);
|
|
|
|
|
a_rmovana.put(RMOVANA_DATACOMP, _adata);
|
2005-06-28 15:00:00 +00:00
|
|
|
|
|
2005-09-06 17:58:13 +00:00
|
|
|
|
TString filtro;
|
|
|
|
|
if (_codcosto.not_empty())
|
2005-12-01 12:04:16 +00:00
|
|
|
|
filtro << "(" << RMOVANA_CODCCOSTO << "?=\"" << _codcosto << "*\")";
|
2005-09-06 17:58:13 +00:00
|
|
|
|
if (_codcms.not_empty())
|
|
|
|
|
{
|
|
|
|
|
if (filtro.not_empty())
|
|
|
|
|
filtro << "&&";
|
2005-12-01 12:04:16 +00:00
|
|
|
|
filtro << "(" << RMOVANA_CODCMS << "?=\"" << _codcms << "*\")";
|
2005-09-06 17:58:13 +00:00
|
|
|
|
}
|
|
|
|
|
if (_codfas.not_empty())
|
|
|
|
|
{
|
|
|
|
|
if (filtro.not_empty())
|
|
|
|
|
filtro << "&&";
|
2005-12-01 12:04:16 +00:00
|
|
|
|
filtro << "(" << RMOVANA_CODFASE << "?=\"" << _codfas << "*\")";
|
2005-09-06 17:58:13 +00:00
|
|
|
|
}
|
2005-06-28 15:00:00 +00:00
|
|
|
|
|
|
|
|
|
//scandisce il piano dei conti..
|
2009-07-07 13:17:27 +00:00
|
|
|
|
for (bool pok = pconana.move_first(); pok; pok = pconana.move_next())
|
2005-06-28 15:00:00 +00:00
|
|
|
|
{
|
2009-07-07 13:17:27 +00:00
|
|
|
|
if (!pi.addstatus(1))
|
|
|
|
|
break;
|
2005-09-06 17:58:13 +00:00
|
|
|
|
const TString& conto = pconana.get(PCONANA_CODCONTO).as_string();
|
|
|
|
|
|
|
|
|
|
//..crea un cursore su rmovana per vedere se i conti selezionati hanno veri movimenti che soddisfano
|
|
|
|
|
//i parametri del filtro sulla maschera
|
|
|
|
|
da_rmovana.put(RMOVANA_CODCONTO, conto);
|
|
|
|
|
a_rmovana.put(RMOVANA_CODCONTO, conto);
|
|
|
|
|
|
|
|
|
|
TCursor cur_rmovana(&rel_rmovana, filtro, 2, &da_rmovana, &a_rmovana);
|
|
|
|
|
const long rmovana_items = cur_rmovana.items();
|
|
|
|
|
bool almeno_uno_aggiunto = false;
|
|
|
|
|
if (rmovana_items > 0)
|
2005-06-28 15:00:00 +00:00
|
|
|
|
{
|
2009-07-07 13:17:27 +00:00
|
|
|
|
cur_rmovana.freeze();
|
2005-09-06 17:58:13 +00:00
|
|
|
|
for (cur_rmovana = 0; cur_rmovana.pos() < rmovana_items; ++cur_rmovana)
|
2005-06-28 15:00:00 +00:00
|
|
|
|
{
|
2005-09-06 17:58:13 +00:00
|
|
|
|
//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)
|
2005-06-28 15:00:00 +00:00
|
|
|
|
{
|
2005-09-06 17:58:13 +00:00
|
|
|
|
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;
|
2005-06-28 15:00:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-07 13:17:27 +00:00
|
|
|
|
cur_rmovana.freeze(false);
|
2005-09-06 17:58:13 +00:00
|
|
|
|
}
|
|
|
|
|
//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);
|
|
|
|
|
}
|
2005-06-28 15:00:00 +00:00
|
|
|
|
|
|
|
|
|
} //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-09-06 17:58:13 +00:00
|
|
|
|
TReport::set_recordset(NULL); //forza azzeramento file anal.dbf prima di ricostruirlo
|
|
|
|
|
|
2005-06-28 15:00:00 +00:00
|
|
|
|
const int tipoconti = msk.get_int(F_TIPOCONTI);
|
|
|
|
|
|
|
|
|
|
TPrint_mastrini_ca_recordset* recset = NULL;
|
|
|
|
|
|
2010-01-21 15:15:05 +00:00
|
|
|
|
const char* const query ="USE RMOVANA KEY 2\nJOIN MOVANA INTO NUMREG==NUMREG\nJOIN MOV TO MOVANA INTO NUMREG==NUMREGCG";
|
2005-06-28 15:00:00 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2010-03-02 16:05:52 +00:00
|
|
|
|
TPrint_mastrini_ca_mask* _mask;
|
|
|
|
|
|
2005-05-11 17:29:14 +00:00
|
|
|
|
protected:
|
2009-05-29 13:04:17 +00:00
|
|
|
|
virtual const char * extra_modules() const {return "cm";} //funziona anche con autorizzazione CM
|
2010-03-02 16:05:52 +00:00
|
|
|
|
|
|
|
|
|
void print_or_preview(const bool stampa);
|
|
|
|
|
virtual void print();
|
|
|
|
|
virtual void preview();
|
|
|
|
|
|
2005-05-11 17:29:14 +00:00
|
|
|
|
virtual void main_loop();
|
|
|
|
|
};
|
|
|
|
|
|
2010-03-02 16:05:52 +00:00
|
|
|
|
void TPrint_mastrini_ca::print()
|
|
|
|
|
{
|
|
|
|
|
print_or_preview(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TPrint_mastrini_ca::preview()
|
|
|
|
|
{
|
|
|
|
|
print_or_preview(false);
|
|
|
|
|
}
|
2005-10-04 11:02:22 +00:00
|
|
|
|
|
2010-03-02 16:05:52 +00:00
|
|
|
|
void TPrint_mastrini_ca::print_or_preview(const bool stampa)
|
2005-05-11 17:29:14 +00:00
|
|
|
|
{
|
2010-03-02 16:05:52 +00:00
|
|
|
|
//report e book dei report
|
|
|
|
|
TReport_book book;
|
|
|
|
|
TString path = _mask->get(F_REPORT);
|
|
|
|
|
if (path.empty())
|
|
|
|
|
path = "ca3200a";
|
|
|
|
|
TPrint_mastrini_ca_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
|
2010-03-31 11:09:30 +00:00
|
|
|
|
|
2010-03-02 16:05:52 +00:00
|
|
|
|
//stabilisce quale <20> il primo livello (tra CDC e CMS)..
|
|
|
|
|
const TMultilevel_code_info& liv1 = *ca_multilevel_code_info_by_index(0);
|
|
|
|
|
const int logic1 = liv1.logic();
|
2010-03-31 11:09:30 +00:00
|
|
|
|
|
|
|
|
|
TAssoc_array codici_buoni;
|
|
|
|
|
TString query;
|
|
|
|
|
query << "USE RMOVANA KEY 2\n";
|
|
|
|
|
query << "FROM CODCONTO=#DACONTO\n";
|
|
|
|
|
query << "TO CODCONTO=#ACONTO";
|
|
|
|
|
TISAM_recordset rmovana(query);
|
|
|
|
|
TString80 daconto, aconto;
|
|
|
|
|
for (int i = 0; _mask->id2pos(F_CDC1_INI+i) > 0; i++)
|
|
|
|
|
{
|
|
|
|
|
daconto << _mask->get(F_CDC1_INI+i);
|
|
|
|
|
aconto << _mask->get(F_CDC1_FIN+i);
|
|
|
|
|
}
|
|
|
|
|
rmovana.set_var("#DACONTO", daconto);
|
|
|
|
|
rmovana.set_var("#ACONTO", aconto);
|
2010-03-31 14:34:34 +00:00
|
|
|
|
const long items = rmovana.items();
|
|
|
|
|
if (items > 0)
|
2010-03-31 11:09:30 +00:00
|
|
|
|
{
|
2010-03-31 14:34:34 +00:00
|
|
|
|
TProgind po(items, "Analisi righe movimento analitiche...", true, true);
|
|
|
|
|
|
|
|
|
|
for (bool ok = rmovana.move_first(); ok; ok = rmovana.move_next())
|
|
|
|
|
{
|
|
|
|
|
if (!po.addstatus(1))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
const TString& codice = rmovana.get(logic1 == LF_COMMESSE ? RMOVANA_CODCMS : RMOVANA_CODCCOSTO).as_string();
|
|
|
|
|
codici_buoni.add(codice);
|
|
|
|
|
}
|
2010-03-31 11:09:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-03-02 16:05:52 +00:00
|
|
|
|
TISAM_recordset set(logic1 == LF_CDC ? "USE CDC" : "USE COMMESSE"); //..e di conseguenza scrive la use giusta
|
|
|
|
|
|
|
|
|
|
bool skip_closed = false;
|
|
|
|
|
if (logic1 == LF_COMMESSE)
|
|
|
|
|
skip_closed = !yesno_box(TR("E' stata richiesta la stampa di tutte le commesse:\n"
|
|
|
|
|
"Si desidera includere anche le commesse chiuse?"));
|
2010-03-31 11:09:30 +00:00
|
|
|
|
|
2010-03-02 16:05:52 +00:00
|
|
|
|
TProgind pi(set.items(), video_string, true, true);
|
|
|
|
|
for (bool sok = set.move_first(); sok; sok = set.move_next()) //fighissimo metodo per scandire un file in 1 riga!
|
2005-05-13 13:05:41 +00:00
|
|
|
|
{
|
2010-03-02 16:05:52 +00:00
|
|
|
|
if (!pi.addstatus(1))
|
|
|
|
|
break;
|
2005-10-04 11:02:22 +00:00
|
|
|
|
|
2010-03-02 16:05:52 +00:00
|
|
|
|
if (skip_closed && set.get(COMMESSE_CHIUSA).as_bool())
|
|
|
|
|
continue;
|
2009-07-07 13:17:27 +00:00
|
|
|
|
|
2010-03-02 16:05:52 +00:00
|
|
|
|
row = set.get(0u).as_string(); //prende il valore del primo campo del file (CDC o CMS code)
|
2010-03-31 11:09:30 +00:00
|
|
|
|
if (!codici_buoni.is_key(row))
|
|
|
|
|
continue;
|
2005-10-04 11:02:22 +00:00
|
|
|
|
|
2010-03-02 16:05:52 +00:00
|
|
|
|
//completa la stringa da visualizzare sulla progind
|
|
|
|
|
video_string.cut(0) << row << '\n' << set.get(1u);
|
|
|
|
|
pi.set_text(video_string);
|
2005-10-04 11:02:22 +00:00
|
|
|
|
|
2010-03-02 16:05:52 +00:00
|
|
|
|
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));
|
2005-10-04 11:02:22 +00:00
|
|
|
|
|
2010-03-02 16:05:52 +00:00
|
|
|
|
rep.set_filter(*_mask, 0); //fa la set filter sulla prima riga (che <20> quella usata)
|
|
|
|
|
book.add(rep);
|
2005-10-04 11:02:22 +00:00
|
|
|
|
}
|
2010-03-02 16:05:52 +00:00
|
|
|
|
sheet.destroy(); //cancella le commesse aggiunte in automatico sullo sheet
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FOR_EACH_SHEET_ROW(sheet, r, row)
|
2005-10-04 11:02:22 +00:00
|
|
|
|
{
|
2010-03-02 16:05:52 +00:00
|
|
|
|
rep.set_filter(*_mask, r);
|
|
|
|
|
book.add(rep);
|
2005-05-13 13:05:41 +00:00
|
|
|
|
}
|
2005-05-11 17:29:14 +00:00
|
|
|
|
}
|
2010-03-02 16:05:52 +00:00
|
|
|
|
|
|
|
|
|
if (stampa)
|
|
|
|
|
book.print(); //stampa il book dei report
|
|
|
|
|
else
|
|
|
|
|
book.preview(); //anteprima
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TPrint_mastrini_ca::main_loop()
|
|
|
|
|
{
|
|
|
|
|
_mask = new TPrint_mastrini_ca_mask;
|
|
|
|
|
_mask->run();
|
|
|
|
|
delete _mask;
|
|
|
|
|
_mask = NULL;
|
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;
|
|
|
|
|
}
|