b2cce041ef
Files correlati : Ricompilazione Demo : [ ] Commento :commit di sicurezza in fase avanzamento programma rendiconto (maschera completa) git-svn-id: svn://10.65.10.50/trunk@13279 c028cbd2-c16b-5b4b-a496-9718f37d4682
1030 lines
28 KiB
C++
Executable File
1030 lines
28 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <execp.h>
|
||
#include <progind.h>
|
||
#include <reprint.h>
|
||
#include <doc.h>
|
||
#include <rdoc.h>
|
||
#include "../cg/cg2103.h"
|
||
#include "../cg/cglib01.h"
|
||
#include "../ve/velib04.h"
|
||
|
||
#include "panapdc.h"
|
||
#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);
|
||
const TString& get_report_class() const;
|
||
bool test_compatible_report();
|
||
|
||
bool esistono_riclassificazioni() const;
|
||
void create_sheet();
|
||
int create_sheet_fields(int lf, int& y, short& dlg, bool required);
|
||
|
||
public:
|
||
TPrint_rendiconto_ca_mask();
|
||
virtual ~TPrint_rendiconto_ca_mask() {}
|
||
};
|
||
|
||
const TString& TPrint_rendiconto_ca_mask::get_report_class() const
|
||
{
|
||
TString& classe = get_tmp_string();
|
||
classe = "ca3700a";
|
||
return classe;
|
||
}
|
||
|
||
bool TPrint_rendiconto_ca_mask::test_compatible_report()
|
||
{
|
||
const TString& cls = get_report_class();
|
||
const TString& name = get(F_REPORT);
|
||
bool ok = name.not_empty();
|
||
if (ok)
|
||
{
|
||
TReport rep;
|
||
ok = rep.load(name);
|
||
if (ok)
|
||
{
|
||
const TString& classe = rep.get_class();
|
||
ok = classe == cls;
|
||
}
|
||
}
|
||
if (!ok)
|
||
{
|
||
set(F_REPORT, cls);
|
||
TFilename path = cls;
|
||
path.ext("rep");
|
||
ok = path.custom_path();
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TPrint_rendiconto_ca_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case F_REPORT:
|
||
if (e == fe_button)
|
||
{
|
||
const TString8 lib = get_report_class();
|
||
TFilename path = o.get();
|
||
if (select_custom_file(path, "rep", lib))
|
||
{
|
||
path = path.name();
|
||
path.ext("");
|
||
o.set(path);
|
||
}
|
||
} else
|
||
if (e == fe_close)
|
||
{
|
||
if (!test_compatible_report())
|
||
return error_box("Impossibile trovare un report compatibile");
|
||
}
|
||
break;
|
||
case F_PRE1:
|
||
case F_PRE2:
|
||
case F_PRE3:
|
||
if ((e == fe_init || e == fe_modify) && o.active())
|
||
{
|
||
const int k = o.dlg()-F_PRE1;
|
||
set(F_PAN1_INI + k, o.get(), 0x2);
|
||
disable(F_PAN1_INI + k);
|
||
disable(F_PANDES1_INI + k);
|
||
|
||
set(F_PAN1_FIN + k, o.get(), 0x2);
|
||
disable(F_PAN1_FIN + k);
|
||
disable(F_PANDES1_FIN + k);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
int TPrint_rendiconto_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_rendiconto_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);
|
||
}
|
||
}
|
||
|
||
bool TPrint_rendiconto_ca_mask::esistono_riclassificazioni() const
|
||
{
|
||
TLocalisamfile ric(LF_PANAPDC);
|
||
return ric.first() == NOERR;
|
||
}
|
||
|
||
TPrint_rendiconto_ca_mask::TPrint_rendiconto_ca_mask()
|
||
:TAutomask("ca3700")
|
||
{
|
||
TConfig_anal cfg;
|
||
const bool use_pdcc = cfg.get_bool("UsePdcc");
|
||
|
||
const TMultilevel_code_info& pconana_info = ca_multilevel_code_info(LF_PCONANA);
|
||
const int pconana_levels = pconana_info.levels();
|
||
|
||
int pconana_prefix = cfg.get_int("PdcPrefix");
|
||
if (pconana_prefix >= pconana_levels)
|
||
pconana_prefix = pconana_levels-1;
|
||
|
||
disable(F_PIANO);
|
||
set(F_PIANO, use_pdcc ? "C" : "A");
|
||
|
||
// Controllo se voglio (e posso) usare il conto analitico come prefisso di quello contabile
|
||
const int pref = cfg.get_int("PdcPrefix");
|
||
if (use_pdcc && pref > 0)
|
||
{
|
||
const TMultilevel_code_info& info = ca_multilevel_code_info(LF_PCONANA);
|
||
const int levels = info.levels();
|
||
if (levels >= 2 && pref < levels && esistono_riclassificazioni())
|
||
{
|
||
enable(F_PIANO);
|
||
ca_create_fields(*this, 0, LF_PCONANA, 2, 4, F_PRE1, F_PREDES1, 0x0, PCONANA_CODCONTO);
|
||
|
||
// Nascondi i campi che non fanno parte del prefisso
|
||
for (int i = 0; i < levels; i++)
|
||
{
|
||
if (i < pref)
|
||
{
|
||
field(F_PRE1 + i).check_type(CHECK_REQUIRED);
|
||
field(F_PRE1 + i).set_group(6);
|
||
field(F_PREDES1 + i).set_group(6);
|
||
}
|
||
else
|
||
{
|
||
field(F_PRE1 + i).hide();
|
||
field(F_PREDES1 + i).hide();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
for (int g = 5; g <= 6; g++)
|
||
{
|
||
const int logicnum = g == 5 ? LF_PCON : LF_PCONANA;
|
||
const short da_dlg = g == 5 ? F_PDC1_INI : F_PAN1_INI;
|
||
const short da_des = g == 5 ? F_PDCDES1_INI : F_PANDES1_INI;
|
||
const short a_dlg = g == 5 ? F_PDC1_FIN : F_PAN1_FIN;
|
||
const short a_des = g == 5 ? F_PDCDES1_FIN : F_PANDES1_FIN;
|
||
|
||
const int nfields = ca_create_fields(*this, 0, logicnum, 2, 9, da_dlg, da_des, 0x0, PCONANA_CODCONTO);
|
||
ca_create_fields(*this, 0, logicnum, 2, 14, a_dlg, a_des, 0x0, PCONANA_CODCONTO);
|
||
|
||
for (int i = 0; i < nfields; i++)
|
||
{
|
||
TMask_field& daconto = field(da_dlg + i);
|
||
daconto.set_group(1);
|
||
daconto.set_group(4);
|
||
daconto.set_group(g);
|
||
daconto.check_type(CHECK_NORMAL);
|
||
|
||
field(da_des+i).set_group(4);
|
||
field(da_des+i).set_group(g);
|
||
|
||
TMask_field& aconto = field(a_dlg + i);
|
||
aconto.set_group(2);
|
||
aconto.set_group(4);
|
||
aconto.set_group(g);
|
||
aconto.check_type(CHECK_NORMAL);
|
||
|
||
field(a_des+i).set_group(4);
|
||
field(a_des+i).set_group(g);
|
||
}
|
||
}
|
||
|
||
// creazione dei campi della seconda pagina della maschera (cdc/cms/fasi)
|
||
create_sheet();
|
||
// setta gli handlers a tutti i campi generati della maschera;senza questa chiamata la on_field_event
|
||
// non puo' funzionare sui campi generati!!!
|
||
set_handlers();
|
||
|
||
//la terza pagina ha uno sheet standard e non necessita di metodi per la creazione
|
||
}
|
||
|
||
|
||
///////////////////////////////////////////////////////////////
|
||
// RECORDSET
|
||
///////////////////////////////////////////////////////////////
|
||
#define IMPEGNATO 1
|
||
#define MATURATO 2
|
||
#define FATTURATO 4
|
||
|
||
class TPrint_rendiconto_ca_recordset : public TISAM_recordset
|
||
{
|
||
TExternisamfile* _tmp;
|
||
|
||
protected:
|
||
int _anno;
|
||
int _tipoconti;
|
||
TDate _dadata, _adata;
|
||
long _danumreg, _anumreg;
|
||
TString _daconto, _aconto, _codcosto, _codcms, _codfas;
|
||
|
||
protected: //da libreria
|
||
virtual const TVariant& get(const char* column_name) const;
|
||
|
||
protected:
|
||
static bool mov_filter(const TRelation* rel);
|
||
bool valid_record(const TRelation& rel) const;
|
||
virtual void set_custom_filter(TCursor& cur) const;
|
||
|
||
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, const TDocumento* doc);
|
||
real somma_budget(const TString& codconto, const char* tipomovana);
|
||
|
||
|
||
public:
|
||
virtual void set_filter(const TPrint_rendiconto_ca_mask& msk, int cms_row);
|
||
|
||
TPrint_rendiconto_ca_recordset(const TString& sql) : TISAM_recordset(sql) { _tmp = NULL;}
|
||
~TPrint_rendiconto_ca_recordset() {}
|
||
};
|
||
|
||
|
||
static const TPrint_rendiconto_ca_recordset* myself = NULL;
|
||
|
||
TPrint_rendiconto_ca_recordset* rendiconto_recordset() { return (TPrint_rendiconto_ca_recordset* ) myself;}
|
||
|
||
//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;
|
||
case 'T': tipomov_int = 1;break;
|
||
default: tipomov_int = 1; break;
|
||
}
|
||
if ((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
|
||
{
|
||
//crea un file temporaneo che non viene distrutto ad inizio stampa effettiva
|
||
// TExternisamfile* tmp = new TExternisamfile(dbf, trr);
|
||
relation()->replace(_tmp); //sostituisce il vero file rmovana con quello temporaneo
|
||
|
||
//filtro sul file esterno (_tmp, cio<69> 1000) sui conti selezionati sulla maschera
|
||
TRectype darec(cur.curr()), arec(cur.curr()); //curr perch<63> <20> il file externisamfile
|
||
darec.put("CONTO", _daconto);
|
||
darec.put("DATA", _dadata);
|
||
arec.put("CONTO", _aconto);
|
||
arec.put("DATA", _adata);
|
||
cur.setregion(darec, arec);
|
||
|
||
myself = this;
|
||
cur.set_filterfunction(mov_filter, true);
|
||
}
|
||
|
||
//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;
|
||
}
|
||
|
||
const TVariant& TPrint_rendiconto_ca_recordset::get(const char* column_name) const
|
||
{
|
||
|
||
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;
|
||
}
|
||
}
|
||
return TISAM_recordset::get(column_name);
|
||
}
|
||
|
||
void TPrint_rendiconto_ca_recordset::salva_rmovana(const TRectype& rmovana, const TRectype& movana, const TDocumento* doc)
|
||
{
|
||
//serve un documento da cui ricavare i parametri di stampa
|
||
const bool dadoc = doc != NULL;
|
||
TDocumento* newdoc = (TDocumento*)doc;
|
||
if (newdoc == NULL && movana.get(MOVANA_DNDOC).not_empty())
|
||
{
|
||
const TString16 dacodnum = movana.get(MOVANA_DCODNUM);
|
||
newdoc = new TDocumento('D', movana.get_int(MOVANA_DANNO), dacodnum, movana.get_long(MOVANA_DNDOC));
|
||
}
|
||
|
||
//tipo movimento CONSUNTIVO
|
||
const char tipomov = movana.get_char(MOVANA_TIPOMOV);
|
||
if (tipomov <= ' ' || tipomov == 'T')
|
||
{
|
||
//compila i campi da stampare
|
||
|
||
// il conto puo' essere analitico o contabile...
|
||
//se si usa il piano dei conti contabile ed <20> compilato l'archivio di collegamento PANAPDC
|
||
//si deve usare come conto il campo codconto del panapdc!!!...
|
||
TConfig_anal ini;
|
||
const bool use_pdc = ini.get_bool("UsePdcc");
|
||
TLocalisamfile panapdc(LF_PANAPDC);
|
||
panapdc.setkey(2);
|
||
if (use_pdc && panapdc.first() == NOERR)
|
||
{
|
||
TRectype& rec_panapdc = panapdc.curr();
|
||
|
||
const int gruppo = atoi(rmovana.get(RMOVANA_CODCONTO).left(3));
|
||
|
||
const int conto = atoi(rmovana.get(RMOVANA_CODCONTO).mid(3,3));
|
||
const long sottoconto = atol(rmovana.get(RMOVANA_CODCONTO).mid(6,6));
|
||
|
||
rec_panapdc.put(PANAPDC_GRUPPO, gruppo);
|
||
rec_panapdc.put(PANAPDC_CONTO, conto);
|
||
rec_panapdc.put(PANAPDC_SOTTOCONTO, sottoconto);
|
||
int err = panapdc.read(rec_panapdc, _isgteq);
|
||
//poich<63> non puo' avere la chiave 2 completa, visto che sta cercando l'ultimo elemento..
|
||
//deve fare il confronto campo a campo dei gr/co/sottoc del record corrente con quelli
|
||
//estratti qualche riga sopra da rmovana
|
||
const int curr_gruppo = rec_panapdc.get_int(PANAPDC_GRUPPO);
|
||
if (gruppo - curr_gruppo == 0)
|
||
{
|
||
const int curr_conto = rec_panapdc.get_int(PANAPDC_CONTO);
|
||
if (conto - curr_conto == 0)
|
||
{
|
||
const long curr_sottoconto = rec_panapdc.get_long(PANAPDC_SOTTOCONTO);
|
||
if (sottoconto - curr_sottoconto == 0)
|
||
{
|
||
const TString80 codconto = rec_panapdc.get(PANAPDC_CODCONTO);
|
||
_tmp->curr().put("CONTO", codconto);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
else //...senn<6E> si usa il normale piano dei conti analitico
|
||
_tmp->curr().put("CONTO", rmovana.get(RMOVANA_CODCONTO)); //conto
|
||
|
||
//i movimenti possono essere normali o generati da documento...
|
||
if (dadoc) //movimento generato da documento
|
||
{
|
||
_tmp->curr().put("CODNUM", movana.get(MOVANA_DCODNUM)); //codnum del documento che origina il movana
|
||
_tmp->curr().put("ANNO", movana.get(MOVANA_DANNO)); //anno del doc di origine
|
||
_tmp->curr().put("NUMRD", movana.get(MOVANA_DNDOC)); //numreg del movana
|
||
_tmp->curr().put("DATA", movana.get(MOVANA_DATADOC)); //data del documento che genera movana
|
||
}
|
||
else //movimento normale
|
||
{
|
||
_tmp->curr().put("CODNUM", movana.get(MOVANA_NUMDOC));
|
||
_tmp->curr().put("ANNO", movana.get(MOVANA_ANNOES)); //anno del movimento
|
||
_tmp->curr().put("NUMRD", movana.get(MOVANA_NUMREG)); //numreg del movana
|
||
_tmp->curr().put("DATA", movana.get(MOVANA_DATACOMP)); //data del movana
|
||
}
|
||
|
||
int selettore = 0;
|
||
if (newdoc != NULL)
|
||
{
|
||
_tmp->curr().put("NUMDOCRIF", newdoc->get(DOC_NUMDOCRIF)); //docrif del documento originante il movana
|
||
_tmp->curr().put("DATADOCRIF", newdoc->get(DOC_DATADOCRIF)); //datadocrif del documento originante il movana
|
||
|
||
const int tipo_documento = newdoc->tipo().tipo();
|
||
int tipo_babbo = 0;
|
||
|
||
TString80 riferimento;
|
||
const int rows = newdoc->physical_rows();
|
||
for (int i = 1; riferimento.empty() && i <= rows; i++)
|
||
{
|
||
const TRiga_documento& riga = (*newdoc)[i];
|
||
const TRectype* babbo = riga.find_original_rdoc();
|
||
if (babbo != NULL)
|
||
{
|
||
const TString8 codnum = babbo->get(RDOC_CODNUM);
|
||
const int anno = babbo->get_int(RDOC_ANNO);
|
||
const long ndoc = babbo->get_long(RDOC_NDOC);
|
||
riferimento << codnum << '-' << anno << '-' << ndoc;
|
||
TDocumento doc_babbo('D', anno, codnum, ndoc);
|
||
tipo_babbo = doc_babbo.tipo().tipo();
|
||
}
|
||
}
|
||
|
||
switch (tipo_documento)
|
||
{
|
||
case TTipo_documento::_bolla:
|
||
selettore = MATURATO;
|
||
if (tipo_babbo != TTipo_documento::_ordine)
|
||
selettore |= IMPEGNATO;
|
||
break;
|
||
case TTipo_documento::_fattura:
|
||
selettore = FATTURATO;
|
||
if (tipo_babbo == TTipo_documento::_ordine)
|
||
selettore |= MATURATO;
|
||
else
|
||
selettore |= (IMPEGNATO | MATURATO);
|
||
break;
|
||
case TTipo_documento::_ordine:
|
||
selettore = IMPEGNATO;
|
||
break;
|
||
case TTipo_documento::_altro:
|
||
default:
|
||
break;
|
||
}
|
||
_tmp->curr().put("DOCORIG", riferimento);
|
||
}
|
||
|
||
_tmp->curr().put("DESC", movana.get(MOVANA_DESCR)); //descrizione movana
|
||
_tmp->curr().put("NRIGA", rmovana.get(RMOVANA_NUMRIG));
|
||
_tmp->curr().put("DESCRIGA", movana.get(RMOVANA_DESCR)); //descrizione rmovana
|
||
|
||
/*[Tipo documento]
|
||
O=I**
|
||
B=IM*
|
||
BO=*M*
|
||
FB=**F
|
||
FO=*MF
|
||
F=IMF*/
|
||
//****modificare il metodo per accelerare
|
||
const char sezione = rmovana.get_char(RMOVANA_SEZIONE);
|
||
|
||
TImporto imp(sezione, rmovana.get_real(RMOVANA_IMPORTO));
|
||
|
||
TCausale caus(movana.get(MOVANA_CODCAUS));
|
||
TipoIVA tipoiva = caus.iva();
|
||
char sezione_normale;
|
||
|
||
if (tipoiva == iva_vendite)
|
||
sezione_normale = 'A';
|
||
else
|
||
if (tipoiva == iva_acquisti)
|
||
sezione_normale = 'D';
|
||
else
|
||
sezione_normale = 'D'; //questo in preparazione di casi futuri
|
||
|
||
imp.normalize(sezione_normale);
|
||
|
||
if (selettore & FATTURATO)
|
||
_tmp->curr().put("FATTURATO", imp.valore());
|
||
if (selettore & MATURATO)
|
||
_tmp->curr().put("MATURATO", imp.valore());
|
||
if (selettore & IMPEGNATO)
|
||
_tmp->curr().put("IMPEGNATO", imp.valore());
|
||
|
||
_tmp->write(); // aggiunge i record al file temporaneo
|
||
}
|
||
if (!dadoc && newdoc != NULL)
|
||
delete newdoc;
|
||
}
|
||
|
||
|
||
void TPrint_rendiconto_ca_recordset::crea_righe_rmovana()
|
||
{
|
||
|
||
TRelation rel_rmovana(LF_RMOVANA);
|
||
rel_rmovana.add(LF_MOVANA, "NUMREG==NUMREG"); //aggiunge le testate x avere tipi mov e descr
|
||
|
||
//..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);
|
||
TRectype a_rmovana(LF_RMOVANA);
|
||
a_rmovana.put(RMOVANA_CODCONTO, _aconto);
|
||
|
||
TString filtro;
|
||
|
||
if (_dadata.ok())
|
||
filtro << "(ANSI(DATACOMP)>=" << _dadata.date2ansi() << ")";
|
||
if (_adata.ok())
|
||
{
|
||
if (filtro.not_empty())
|
||
filtro << "&&";
|
||
|
||
filtro << "(ANSI(DATACOMP)<=" << _adata.date2ansi() << ")";
|
||
}
|
||
|
||
if (_codcosto.not_empty())
|
||
{
|
||
if (filtro.not_empty())
|
||
filtro << "&&";
|
||
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();
|
||
|
||
//scorre le righe movimenti di analitica che soddisfano il filtro
|
||
//il join a movana serve nel caso necessitino dati di testata per la riga in questione
|
||
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, NULL);
|
||
}
|
||
}
|
||
|
||
|
||
void TPrint_rendiconto_ca_recordset::crea_righe_rdoc(const TPrint_rendiconto_ca_mask& msk)
|
||
{
|
||
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 << "\")";
|
||
filtro << "&&(PROVV==\"" << "D" << "\")";
|
||
|
||
|
||
TCursor cur_doc(&rel_doc, filtro, 1, &dadoc, &adoc);
|
||
const long doc_items = cur_doc.items();
|
||
cur_doc.freeze();
|
||
|
||
//scanning del file dei documenti alla ricerca di quelli che hanno la data ed il CODNUM
|
||
//validi nei filtri impostati dall'utente
|
||
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 j = 1; j <= mov.rows(); j++)
|
||
{
|
||
salva_rmovana(mov.body()[j], mov, &doc);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
|
||
void TPrint_rendiconto_ca_recordset::crea_trr(const TFilename& trr) const
|
||
{
|
||
ofstream of(trr);
|
||
of << 1000 << endl;
|
||
of << 14 << endl;
|
||
of << "CONTO|1|20|0|Conto analitico" << endl;
|
||
of << "CODNUM|1|4|0|Numerazione documento" << endl;
|
||
of << "ANNO|9|4|0|Anno" << endl;
|
||
of << "DATA|5|8|0|Data movimento o documento" << endl;
|
||
of << "NUMRD|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 << "DOCORIG|1|20|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+NUMRD" << endl;
|
||
}
|
||
|
||
void TPrint_rendiconto_ca_recordset::set_filter(const TPrint_rendiconto_ca_mask& msk, int cms_row)
|
||
{
|
||
//se esiste il file temporano con tracciato persomalizzato lo cancella e lo ricrea vuoto
|
||
TFilename trr; //file tracciato record
|
||
trr.tempdir();
|
||
trr.add("rendy");
|
||
TFilename dbf(trr); //file dati
|
||
|
||
trr.ext("trr");
|
||
dbf.ext("dbf");
|
||
|
||
//crea il file .trr in base ai parametri del metodo
|
||
crea_trr(trr);
|
||
|
||
if (_tmp != NULL)
|
||
delete _tmp;
|
||
|
||
_tmp = new TExternisamfile(dbf, trr);
|
||
|
||
//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);
|
||
}
|
||
|
||
const char tc = msk.get(F_PIANO)[0]; // Contabile o Analitico?
|
||
const short dlg_da = tc == 'C' ? F_PDC1_INI : F_PAN1_INI;
|
||
const short dlg_al = tc == 'C' ? F_PDC1_FIN : F_PAN1_FIN;
|
||
|
||
for (int i = 0; msk.id2pos(dlg_da+i) > 0; i++)
|
||
{
|
||
_daconto << msk.get(dlg_da+i);
|
||
_aconto << msk.get(dlg_al+i);
|
||
}
|
||
|
||
_dadata = msk.get_date(F_DATAINI);
|
||
_adata = msk.get_date(F_DATAFIN);
|
||
|
||
//metodo per riempire il file
|
||
crea_righe_rmovana();
|
||
|
||
//crea_righe_rdoc(msk);
|
||
|
||
}
|
||
|
||
////////////////////////////////////////////////////////
|
||
// 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)
|
||
{
|
||
TPrint_rendiconto_ca_recordset* recset = NULL;
|
||
|
||
const char* query ="USE 1000\nJOIN MOVANA INTO NUMREG==NUMRD\nJOIN RMOVANA INTO NUMREG==NUMRD NUMRIG==NRIGA"; //\nJOIN DOC INTO PROVV=='D' ANNO==ANNO CODNUM==CODNUM";
|
||
|
||
recset = new TPrint_rendiconto_ca_recordset(query);
|
||
|
||
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;
|
||
}
|
||
|
||
/*
|
||
//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) -> maturato, (FA,FN) -> fatturato,
|
||
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;
|
||
}
|
||
|
||
|
||
*/ |