3e4fc7888e
git-svn-id: svn://10.65.10.50/branches/R_10_00@23140 c028cbd2-c16b-5b4b-a496-9718f37d4682
342 lines
9.4 KiB
C++
Executable File
342 lines
9.4 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <automask.h>
|
||
#include <config.h>
|
||
#include <progind.h>
|
||
#include <reprint.h>
|
||
#include <textset.h>
|
||
|
||
#include "lvlib.h"
|
||
|
||
#include "lv2700a.h"
|
||
|
||
class TRiepBolle_recordset: public TCSV_recordset
|
||
{
|
||
int _loop;
|
||
unsigned int _max_column, _lst_column;
|
||
TArray _max_cli_col;
|
||
|
||
public:
|
||
void first_loop() { _loop = 0; }
|
||
void prev_loop() { --_loop; }
|
||
void next_loop() { ++_loop; }
|
||
void set_loop(int l) { _loop = l; }
|
||
unsigned int loops() const { return (_max_column-5)/_lst_column + 1; }
|
||
unsigned int get_curr_max_column() const ;
|
||
void set_max_column(unsigned int column);
|
||
virtual const TVariant& get(unsigned int column) const;
|
||
|
||
TRiepBolle_recordset(unsigned int last_col): TCSV_recordset("CSV(\"\t\")"), _loop(0), _max_column(0), _lst_column(last_col) {}
|
||
};
|
||
|
||
void TRiepBolle_recordset::set_max_column(unsigned int column)
|
||
{
|
||
const long codcli = get(0).as_int();
|
||
|
||
if (_max_column < column)
|
||
_max_column = column;
|
||
real* r = (real *) _max_cli_col.objptr(codcli);
|
||
if (r == NULL)
|
||
{
|
||
r = new real;
|
||
_max_cli_col.add(r, codcli);
|
||
}
|
||
if ((unsigned int)r->integer() < column)
|
||
*r = column;
|
||
}
|
||
|
||
unsigned int TRiepBolle_recordset::get_curr_max_column() const
|
||
{
|
||
const long codcli = get(0).as_int();
|
||
const real* r = (const real*)_max_cli_col.objptr(codcli);
|
||
|
||
return r == NULL ? 0u : (unsigned int)r->integer();
|
||
}
|
||
|
||
const TVariant& TRiepBolle_recordset::get(unsigned int column) const
|
||
{
|
||
if (column < 4)
|
||
return TCSV_recordset::get(column);
|
||
if (column + _loop * _lst_column >= get_curr_max_column())
|
||
return NULL_VARIANT;
|
||
return TCSV_recordset::get(column + _loop * _lst_column);
|
||
}
|
||
|
||
class TRiepBolle_mask: public TAutomask
|
||
{
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
||
public:
|
||
TRiepBolle_mask() : TAutomask("lv2700a") {}
|
||
};
|
||
|
||
bool TRiepBolle_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case F_DATA_DA:
|
||
if (e == fe_init && o.empty())
|
||
{
|
||
TDate oggi(TODAY);
|
||
oggi.set_day(1);
|
||
o.set(oggi.string());
|
||
}
|
||
break;
|
||
default: break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
class TRiepBolle_report : public TDocument_report
|
||
{
|
||
TArray _tot;
|
||
|
||
protected:
|
||
virtual bool use_mask() { return false; }
|
||
virtual bool get_usr_val(const TString& name, TVariant& var) const;
|
||
virtual bool set_usr_val(const TString& name, const TVariant& var);
|
||
|
||
public:
|
||
TRiepBolle_report();
|
||
};
|
||
|
||
bool TRiepBolle_report::get_usr_val(const TString& name, TVariant& var) const
|
||
{
|
||
if (name == "#TOT")
|
||
{
|
||
TRecordset* recset = recordset();
|
||
|
||
if (recset != NULL)
|
||
{
|
||
TVariant * v = (TVariant *) _tot.objptr(recset->current_row());
|
||
var = v != NULL ? *v : NULL_VARIANT;
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
return TDocument_report::get_usr_val(name, var);
|
||
}
|
||
|
||
bool TRiepBolle_report::set_usr_val(const TString& name, const TVariant& var)
|
||
{
|
||
if (name == "#TOT")
|
||
{
|
||
TRecordset* recset = recordset();
|
||
if (recset != NULL)
|
||
{
|
||
TVariant* v = (TVariant*)_tot.objptr(recset->current_row());
|
||
|
||
if (v == NULL)
|
||
{
|
||
v = new TVariant(ZERO);
|
||
_tot.add(v, recset->current_row());
|
||
}
|
||
*v = var;
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
return TDocument_report::set_usr_val(name, var);
|
||
}
|
||
|
||
TRiepBolle_report::TRiepBolle_report()
|
||
{
|
||
}
|
||
|
||
class TRiepBolle_app: public TSkeleton_application
|
||
{
|
||
protected:
|
||
void elabora(const TMask& mask) const;
|
||
|
||
public:
|
||
virtual void main_loop();
|
||
};
|
||
|
||
void TRiepBolle_app::elabora(const TMask& mask)const
|
||
{
|
||
TReport_book b;
|
||
const long from_cli = mask.get_long(F_CODCF_DA);
|
||
const long to_cli = mask.get_long(F_CODCF_A);
|
||
const TDate dal = mask.get_date(F_DATA_DA);
|
||
const TDate al = mask.get_date(F_DATA_A);
|
||
const long anno = dal.year();
|
||
const bool print_resi = mask.get_bool(F_PRINT_RESI);
|
||
const bool print_da_fatt = mask.get_bool(F_PRINT_FATT);
|
||
const TString4 zona = mask.get(F_ZONA);
|
||
TString query;
|
||
|
||
//Richiamo parametri della ditta di configurazione file Ditta.ini
|
||
const TString4 codnum = ini_get_string(CONFIG_DITTA, "lv", "NUM_GEN");
|
||
const TString4 tipodoc = ini_get_string(CONFIG_DITTA, "lv", "TIPODOC_GEN");
|
||
|
||
query << "USE DOC KEY 2\n";
|
||
query << "SELECT ((TIPODOC='" << tipodoc << "')&&";
|
||
if (zona.full())
|
||
query << "(ZONA='" << zona << "'))&&";
|
||
query << "(CODNUM='" << codnum << "'))\n";
|
||
query << "FROM TIPOCF='C' CODCF=#CODCF PROVV='D' ANNO='" << anno << "' DATADOC='" << dal.string() << "' CODNUM='" << codnum << "'\n";
|
||
query << "TO TIPOCF='C' CODCF=#CODCF PROVV='D' ANNO='" << anno << "' DATADOC='" << al.string() << "' CODNUM='" << codnum << "'";
|
||
|
||
TRectype from(LF_CLIFO); from.put(CLI_TIPOCF, "C");
|
||
TRectype to(from);
|
||
|
||
if (from_cli > 0L)
|
||
from.put(CLI_CODCF, from_cli);
|
||
if (to_cli > 0L)
|
||
to.put(CLI_CODCF, to_cli);
|
||
|
||
TRelation rel(LF_CLIFO);
|
||
TCursor cli(&rel, "", 1, &from, &to);
|
||
const long ncli = cli.items();
|
||
if (ncli > 0)
|
||
{
|
||
TProgress_monitor pi_cli(ncli, TR("Estrazione clienti"));
|
||
for (cli = 0L; cli.pos() < ncli && pi_cli.add_status(); ++cli)
|
||
{
|
||
const long codcli = cli.curr().get_long(CLI_CODCF);
|
||
//inserire parametri filtri
|
||
TISAM_recordset docs(query);
|
||
docs.set_var("#CODCF", codcli);
|
||
const TRecnotype docsi = docs.items();
|
||
if (docsi == 0)
|
||
continue;
|
||
|
||
TString_array nbolle;
|
||
TString_array datebolle;
|
||
TAssoc_array riepilogo;
|
||
TRiepBolle_report rep;
|
||
if (!rep.load("lv2700a"))
|
||
return;
|
||
|
||
const TReport_section& body = rep.section('B', 1);
|
||
TString4 last_fld;
|
||
for (int f = body.items()-1; f > 0; f--)
|
||
{
|
||
const TReport_field& fld = body.field(f);
|
||
const TString& src = fld.field();
|
||
if (src.len() == 2 && src > last_fld)
|
||
last_fld = src;
|
||
}
|
||
int last_col = (last_fld[0]-'A'+1)*26 + (last_fld[1]-'A'+1) - 4;
|
||
if (last_col < 66) last_col = 66;
|
||
|
||
TRiepBolle_recordset* riep_set = new TRiepBolle_recordset(last_col);
|
||
((TReport &)rep).set_recordset(riep_set);
|
||
|
||
int count = 1;
|
||
|
||
for(bool ok = docs.move_first(); ok; ok = docs.move_next())
|
||
{
|
||
const TDocumento d = docs.cursor()->curr();
|
||
|
||
int id = -1;
|
||
FOR_EACH_PHYSICAL_RDOC(d, r, rdoc)
|
||
{
|
||
const TRiga_documento& row = *rdoc;
|
||
const TCodice_articolo articolo = row.get(RDOC_CODARTMAG);
|
||
if (articolo.blank())
|
||
continue;
|
||
|
||
//se la causale <20> di reso devo leggere il ritirato e non il consegnato
|
||
const TCausale_lavanderie& cau = cached_causale_lavanderie(row.get(RDOC_CODAGG1));
|
||
real qta;
|
||
|
||
if (cau.is_reso())
|
||
{
|
||
if (print_resi)
|
||
qta = row.get_real(RDOC_QTAGG1);
|
||
}
|
||
else
|
||
{
|
||
const TCausale_magazzino& caumag = cached_causale_magazzino(cau.get("S2"));
|
||
if (!print_da_fatt || caumag.get("S2").mid(36, 2) == "+1")
|
||
qta = row.get_real(RDOC_QTA);
|
||
}
|
||
if (!qta.is_zero())
|
||
{
|
||
if (id < 0)
|
||
{
|
||
const TString8 numero = d.get(DOC_NDOC);
|
||
id = nbolle.add(numero);
|
||
|
||
const TDate data = d.get_date(DOC_DATADOC);
|
||
TString8 ggmm; ggmm.format("%02d-%02d", data.day(), data.month());
|
||
datebolle.add(ggmm, id);
|
||
}
|
||
|
||
TArray* riep_row = (TArray*)riepilogo.objptr(articolo);
|
||
if (riep_row == NULL)
|
||
riepilogo.add(articolo, riep_row = new TArray);
|
||
real* q = (real*)riep_row->objptr(id);
|
||
if (q == NULL)
|
||
riep_row->add(q = new real, id);
|
||
*q += qta;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!riepilogo.empty())
|
||
{
|
||
int maxpos = 0L;
|
||
const int cols = nbolle.items();
|
||
TString_array keys;
|
||
|
||
riepilogo.get_keys(keys);
|
||
keys.sort();
|
||
riep_set->first_loop();
|
||
FOR_EACH_ARRAY_ROW(keys, r, key)//scandisce clienti e tiene buoni solo quelli valorizzati
|
||
{
|
||
TArray * row = (TArray*)riepilogo.objptr(*key);
|
||
int col = 0;
|
||
|
||
riep_set->new_rec();
|
||
riep_set->set(col++, codcli); //CAMPO DI ROTTURA
|
||
riep_set->set(col++, codcli);
|
||
riep_set->set(col++, *key);
|
||
riep_set->set(col++, cached_article(*key).get(ANAMAG_DESCR));
|
||
FOR_EACH_ARRAY_ITEM(nbolle, c, obj)
|
||
{
|
||
riep_set->set(col++, datebolle.row(c));
|
||
riep_set->set(col++, nbolle.row(c));
|
||
const real * qta = (real *) row->objptr(c);
|
||
|
||
riep_set->set(col++, qta == NULL ? EMPTY_STRING : qta->stringa(10, 0));
|
||
riep_set->set_max_column(col);
|
||
}
|
||
}
|
||
#ifdef DBG
|
||
//Crea file che contiene il recordset per debug
|
||
riep_set->save_as("c:/temp/riepilogoBolla.txt");
|
||
#endif
|
||
|
||
//carica tutte le variabili del report.
|
||
if (riep_set->items() > 0L)
|
||
{
|
||
const int loops = riep_set->loops();
|
||
rep.mask2report(mask);
|
||
riep_set->first_loop();
|
||
for (int i = 0 ; i < loops; i++, riep_set->next_loop())
|
||
b.add(rep);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (b.pages() > 0)
|
||
b.print_or_preview(); // Stampa effettivamente
|
||
else
|
||
warning_box (TR("Nessun record estratto per i parametri inseriti"));
|
||
}
|
||
|
||
void TRiepBolle_app::main_loop()
|
||
{
|
||
TRiepBolle_mask m;
|
||
while(m.run()==K_ENTER)
|
||
elabora(m);
|
||
}
|
||
|
||
int lv2700(int argc, char* argv[])
|
||
{
|
||
TRiepBolle_app app;
|
||
app.run(argc, argv, TR("Riepilogo Bolle di Lavanderia"));
|
||
return 0;
|
||
} |