2005-06-01 17:27:27 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
#include <automask.h>
|
|
|
|
#include <reprint.h>
|
|
|
|
|
|
|
|
#include "ci1200.h"
|
|
|
|
|
|
|
|
#include "../ca/calib01.h"
|
|
|
|
#include "../ca/rmovana.h"
|
2005-06-06 14:51:54 +00:00
|
|
|
#include "../ve/vereplib.h"
|
2005-06-01 17:27:27 +00:00
|
|
|
|
|
|
|
#include "../include/doc.h"
|
|
|
|
#include "../include/rdoc.h"
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2005-06-07 09:26:43 +00:00
|
|
|
// TRiepiloghi_mask
|
2005-06-01 17:27:27 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
class TRiepiloghi_mask : public TAutomask
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
int create_sheet_fields(int lf, int& y, short& dlg, bool required = false);
|
2005-06-01 17:27:27 +00:00
|
|
|
void create_sheet();
|
|
|
|
|
|
|
|
public:
|
2005-06-07 09:26:43 +00:00
|
|
|
TRiepiloghi_mask();
|
2005-06-01 17:27:27 +00:00
|
|
|
};
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
int TRiepiloghi_mask::create_sheet_fields(int lf, int& y, short& dlg, bool required)
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
|
|
|
TSheet_field& sf = sfield(F_COMMESSE);
|
|
|
|
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);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
void TRiepiloghi_mask::create_sheet()
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
|
|
|
TSheet_field& sf = sfield(F_COMMESSE);
|
|
|
|
TMask& sm = sf.sheet_mask();
|
|
|
|
sm.hide(-1);
|
|
|
|
|
|
|
|
const TMultilevel_code_info& fasinfo = ca_multilevel_code_info(LF_FASI);
|
|
|
|
|
|
|
|
TConfig_anal ini;
|
|
|
|
|
|
|
|
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)
|
2005-06-07 09:26:43 +00:00
|
|
|
create_sheet_fields(LF_FASI, y, dlg);
|
2005-06-01 17:27:27 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
const bool cdc_req = ini.get_bool("CdcRequired");
|
2005-06-07 09:26:43 +00:00
|
|
|
create_sheet_fields(LF_CDC, y, dlg);
|
2005-06-01 17:27:27 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
if (level == "CMS") // Crea commessa
|
|
|
|
{
|
|
|
|
if (fasinfo.parent() == LF_COMMESSE)
|
2005-06-07 09:26:43 +00:00
|
|
|
create_sheet_fields(LF_FASI, y, dlg);
|
2005-06-01 17:27:27 +00:00
|
|
|
else
|
|
|
|
{
|
2005-06-07 09:26:43 +00:00
|
|
|
create_sheet_fields(LF_COMMESSE, y, dlg);
|
2005-06-01 17:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fasinfo.levels() > 0 && fasinfo.parent() <= 0)
|
2005-06-07 09:26:43 +00:00
|
|
|
create_sheet_fields(LF_FASI, y, dlg);
|
2005-06-01 17:27:27 +00:00
|
|
|
|
|
|
|
for (short id = S_CDC12; id >= S_CDC1; id--)
|
|
|
|
{
|
|
|
|
const int pos = sm.id2pos(id+100);
|
|
|
|
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);
|
|
|
|
sm.hide(id); // Nasconde il campo "segnaposto"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
bool TRiepiloghi_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
TRiepiloghi_mask::TRiepiloghi_mask() : TAutomask("ci1200")
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
|
|
|
create_sheet();
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2005-06-07 09:26:43 +00:00
|
|
|
// TRiepiloghi_recordset
|
2005-06-01 17:27:27 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
class TRiepiloghi_recordset : public TDocument_recordset
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
|
|
|
TDate _da_data, _a_data;
|
|
|
|
long _da_clifo, _a_clifo;
|
|
|
|
TString _da_codart, _a_codart;
|
|
|
|
TString _codcosto, _codcms, _codfas;
|
|
|
|
TString_array _tipidoc;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static bool rdoc_filter(const TRelation* rel);
|
|
|
|
bool valid_record(const TRelation& rel) const;
|
|
|
|
|
|
|
|
virtual void set_custom_filter(TCursor& cur) const;
|
|
|
|
|
|
|
|
public:
|
2005-06-07 09:26:43 +00:00
|
|
|
void set_filter(const TRiepiloghi_mask& msk, int cms_row);
|
|
|
|
TRiepiloghi_recordset(const TString& sql) : TDocument_recordset(sql) { }
|
2005-06-01 17:27:27 +00:00
|
|
|
};
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
static const TRiepiloghi_recordset* myself = NULL;
|
2005-06-01 17:27:27 +00:00
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
bool TRiepiloghi_recordset::valid_record(const TRelation& rel) const
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
|
|
|
const TRectype& doc = rel.curr(LF_DOC);
|
|
|
|
|
|
|
|
const TDate data = doc.get(DOC_DATADOC);
|
|
|
|
if (data < _da_data || (_a_data.ok() && data > _a_data))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const long clifo = doc.get_long(DOC_CODCF);
|
|
|
|
if (clifo < _da_clifo || (_a_clifo > 0 && clifo > _a_clifo))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const TRectype& rdoc = rel.curr(LF_RIGHEDOC);
|
|
|
|
const TString& codart = rdoc.get(RDOC_CODART);
|
|
|
|
if (codart < _da_codart || (_a_codart.not_empty() && codart.compare(_a_codart, _a_codart.len()) > 0))
|
|
|
|
return false;
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
if (!_tipidoc.empty())
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
|
|
|
const TString4 codnum = doc.get(DOC_CODNUM);
|
|
|
|
const TString4 tipodoc = doc.get(DOC_TIPODOC);
|
2005-06-08 11:16:57 +00:00
|
|
|
const TString4 stato = doc.get(DOC_STATO);
|
|
|
|
|
2005-06-01 17:27:27 +00:00
|
|
|
bool found = false;
|
|
|
|
FOR_EACH_ARRAY_ROW(_tipidoc, i, row)
|
|
|
|
{
|
|
|
|
const TString4 cn = row->get(0);
|
|
|
|
const TString4 td = row->get();
|
|
|
|
if ((cn.blank() || cn == codnum) && (td.blank() || td == tipodoc))
|
|
|
|
{
|
2005-06-08 11:16:57 +00:00
|
|
|
const TString4 si = row->get();
|
|
|
|
const TString4 sf = row->get();
|
|
|
|
|
|
|
|
if ((si.blank() || stato >= si) && (sf.blank() || stato <= sf))
|
|
|
|
{
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
2005-06-01 17:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_codcosto.not_empty())
|
|
|
|
{
|
|
|
|
const TString& cos = rdoc.get(RDOC_CODCOSTO);
|
|
|
|
if (cos != _codcosto)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (_codcms.not_empty())
|
|
|
|
{
|
|
|
|
const TString& cms = rdoc.get(RDOC_CODCMS);
|
|
|
|
if (cms != _codcms)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (_codfas.not_empty())
|
|
|
|
{
|
|
|
|
const TString& fas = rdoc.get(RDOC_FASCMS);
|
|
|
|
if (fas != _codfas)
|
|
|
|
return false;
|
2005-06-09 11:43:36 +00:00
|
|
|
}
|
2005-06-01 17:27:27 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
bool TRiepiloghi_recordset::rdoc_filter(const TRelation* rel)
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
|
|
|
return myself->valid_record(*rel);
|
|
|
|
}
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
void TRiepiloghi_recordset::set_custom_filter(TCursor& cur) const
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
|
|
|
myself = this;
|
|
|
|
cur.set_filterfunction(rdoc_filter, true);
|
|
|
|
}
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
void TRiepiloghi_recordset::set_filter(const TRiepiloghi_mask& msk, int cms_row)
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
|
|
|
_codcosto = _codcms = _codfas = "";
|
|
|
|
if (cms_row >= 0)
|
|
|
|
{
|
|
|
|
TSheet_field& sf = msk.sfield(F_COMMESSE);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
set_var("#S_CMS", TVariant(_codcms), true);
|
|
|
|
|
|
|
|
_tipidoc.destroy();
|
|
|
|
TSheet_field& sf = msk.sfield(F_TIPI);
|
|
|
|
FOR_EACH_SHEET_ROW(sf, i, row)
|
|
|
|
{
|
|
|
|
TToken_string str;
|
|
|
|
str.add(row->get(0), 0);
|
|
|
|
str.add(row->get(2), 1);
|
2005-06-08 11:16:57 +00:00
|
|
|
str.add(row->get(4), 2);
|
|
|
|
str.add(row->get(5), 3);
|
2005-06-01 17:27:27 +00:00
|
|
|
_tipidoc.add(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
_da_data = msk.get_date(F_DA_DATA);
|
|
|
|
_a_data = msk.get_date(F_A_DATA);
|
|
|
|
set_var("#S_DATEFROM", _da_data, true);
|
|
|
|
set_var("#S_DATETO", _a_data, true);
|
|
|
|
|
|
|
|
_da_clifo = msk.get_long(F_DA_CLIFO);
|
|
|
|
_a_clifo = msk.get_long(F_A_CLIFO);
|
|
|
|
|
|
|
|
_da_codart = msk.get(F_DA_CODART);
|
|
|
|
_a_codart = msk.get(F_A_CODART);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2005-06-07 09:26:43 +00:00
|
|
|
// TRiepiloghi_report
|
2005-06-01 17:27:27 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
class TRiepiloghi_report : public TReport
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual bool set_recordset(const TString& sql);
|
|
|
|
|
|
|
|
public:
|
2005-06-07 09:26:43 +00:00
|
|
|
void set_filter(const TRiepiloghi_mask& msk, int cms_row);
|
|
|
|
TRiepiloghi_report() { }
|
2005-06-01 17:27:27 +00:00
|
|
|
};
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
bool TRiepiloghi_report::set_recordset(const TString& sql)
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
2005-06-07 09:26:43 +00:00
|
|
|
TRiepiloghi_recordset* rs = new TRiepiloghi_recordset(sql);
|
2005-06-01 17:27:27 +00:00
|
|
|
return TReport::set_recordset(rs);
|
|
|
|
}
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
void TRiepiloghi_report::set_filter(const TRiepiloghi_mask& msk, int cms_row)
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
2005-06-07 09:26:43 +00:00
|
|
|
TRiepiloghi_recordset* rs = (TRiepiloghi_recordset*)recordset();
|
2005-06-01 17:27:27 +00:00
|
|
|
rs->set_filter(msk, cms_row);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2005-06-07 09:26:43 +00:00
|
|
|
// TRiepiloghi_app
|
2005-06-01 17:27:27 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
class TRiepiloghi_app : public TSkeleton_application
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual void main_loop();
|
|
|
|
};
|
|
|
|
|
2005-06-07 09:26:43 +00:00
|
|
|
void TRiepiloghi_app::main_loop()
|
2005-06-01 17:27:27 +00:00
|
|
|
{
|
2005-06-07 09:26:43 +00:00
|
|
|
TRiepiloghi_mask m;
|
2005-06-01 17:27:27 +00:00
|
|
|
while (m.run() != K_QUIT)
|
|
|
|
{
|
|
|
|
TReport_book book;
|
2005-06-07 09:26:43 +00:00
|
|
|
TRiepiloghi_report rep;
|
2005-06-01 17:27:27 +00:00
|
|
|
const TString& repname = m.get(F_REPORT);
|
|
|
|
rep.load(repname);
|
|
|
|
|
|
|
|
TSheet_field& sf = m.sfield(F_COMMESSE);
|
|
|
|
if (sf.items() == 0)
|
|
|
|
sf.row(-1);
|
|
|
|
for (int i = 0; i < sf.items(); i++)
|
|
|
|
{
|
|
|
|
rep.set_filter(m, i);
|
|
|
|
book.add(rep);
|
|
|
|
}
|
|
|
|
|
|
|
|
book.print_or_preview();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ci1200(int argc, char* argv[])
|
|
|
|
{
|
2005-06-07 09:26:43 +00:00
|
|
|
TRiepiloghi_app sd;
|
|
|
|
sd.run(argc, argv, "Stampa riepiloghi");
|
2005-06-01 17:27:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|