Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.1 patch 766 git-svn-id: svn://10.65.10.50/trunk@14628 c028cbd2-c16b-5b4b-a496-9718f37d4682
375 lines
10 KiB
C++
Executable File
375 lines
10 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <progind.h>
|
|
#include <relation.h>
|
|
#include <recarray.h>
|
|
#include <reprint.h>
|
|
|
|
#include "../mg/anamag.h"
|
|
#include <clifo.h>
|
|
#include <comuni.h>
|
|
#include <indsp.h>
|
|
#include <doc.h>
|
|
#include <rdoc.h>
|
|
|
|
#include "pd0350.h"
|
|
|
|
//////////////////////////////
|
|
// RECORDSET
|
|
//////////////////////////////
|
|
class TPrint_consegnato_pd0350_recset : public TISAM_recordset
|
|
{
|
|
TExternisamfile* _tmp;
|
|
TDate _data_minima;
|
|
char _tipo;
|
|
|
|
protected:
|
|
void crea_trr(const TFilename& trr) const;
|
|
void create_tempfile();
|
|
void compila_dati_da_testata(TRectype& rec) const;
|
|
void fill_tempfile(const TDate& da_data);
|
|
void kill_tempfile();
|
|
|
|
public:
|
|
void set_tipo(char tipo) { _tipo = toupper(tipo);}
|
|
virtual void requery();
|
|
TPrint_consegnato_pd0350_recset(const TString& sql, char tipo);
|
|
~TPrint_consegnato_pd0350_recset();
|
|
};
|
|
|
|
//costruttore che crea anche il file di appoggio
|
|
TPrint_consegnato_pd0350_recset::TPrint_consegnato_pd0350_recset(const TString& sql, char tipo)
|
|
: TISAM_recordset(sql)
|
|
{
|
|
set_tipo(tipo);
|
|
create_tempfile();
|
|
}
|
|
|
|
TPrint_consegnato_pd0350_recset::~TPrint_consegnato_pd0350_recset()
|
|
{
|
|
kill_tempfile();
|
|
}
|
|
|
|
void TPrint_consegnato_pd0350_recset::crea_trr(const TFilename& trr) const
|
|
{
|
|
ofstream of(trr);
|
|
of << 1000 << endl;
|
|
switch (_tipo)
|
|
{
|
|
case 'A': //consegnato linea/regione/provincia (A)
|
|
{
|
|
of << 11 << endl;
|
|
of << "GRMERC|1|5|0|Codice gruppo merceologico" << endl;
|
|
of << "REGIONE|1|2|0|Regione" << endl;
|
|
of << "PROVINCIA|1|2|0|Provincia" << endl;
|
|
of << "NDOC|3|7|0|Numero documento" << endl;
|
|
of << "NRIGA|2|3|0|Numero riga" << endl;
|
|
of << "DATADOC|5|8|0|Data documento" << endl;
|
|
of << "CODNUM|1|4|0|Numerazione riga documento" << endl;
|
|
of << "ANNO|2|4|0|Anno" << endl;
|
|
of << "PROVV|1|1|0|Documento provvisiorio/definitivo" << endl;
|
|
of << "DESCR|1|50|0|Descrizione articolo" << endl;
|
|
of << "QTA|4|15|5|Quantita'" << endl;
|
|
of << 1 << endl;
|
|
of << "GRMERC+REGIONE+PROVINCIA+NDOC+NRIGA" << endl;
|
|
}
|
|
break;
|
|
case 'B': //consegnato linea/cliente (B)
|
|
{
|
|
of << 12 << endl;
|
|
of << "GRMERC|1|5|0|Codice gruppo merceologico" << endl;
|
|
of << "CLIENTE|3|6|0|Regione" << endl;
|
|
of << "REGIONE|1|2|0|Regione" << endl;
|
|
of << "PROVINCIA|1|2|0|Provincia" << endl;
|
|
of << "NDOC|3|7|0|Numero documento" << endl;
|
|
of << "NRIGA|2|3|0|Numero riga" << endl;
|
|
of << "DATADOC|5|8|0|Data documento" << endl;
|
|
of << "CODNUM|1|4|0|Numerazione riga documento" << endl;
|
|
of << "ANNO|2|4|0|Anno" << endl;
|
|
of << "PROVV|1|1|0|Documento provvisiorio/definitivo" << endl;
|
|
of << "DESCR|1|50|0|Descrizione articolo" << endl;
|
|
of << "QTA|4|15|5|Quantita'" << endl;
|
|
of << 1 << endl;
|
|
of << "GRMERC+CLIENTE+REGIONE+PROVINCIA+NDOC+NRIGA" << endl;
|
|
}
|
|
break;
|
|
case 'C': //consegnato articolo/regione/provincia (C)
|
|
{
|
|
of << 11 << endl;
|
|
of << "CODARTMAG|1|20|0|Codice articolo di magazzino" << endl;
|
|
of << "REGIONE|1|2|0|Regione" << endl;
|
|
of << "PROVINCIA|1|2|0|Provincia" << endl;
|
|
of << "NDOC|3|7|0|Numero documento" << endl;
|
|
of << "NRIGA|2|3|0|Numero riga" << endl;
|
|
of << "DATADOC|5|8|0|Data documento" << endl;
|
|
of << "CODNUM|1|4|0|Numerazione riga documento" << endl;
|
|
of << "ANNO|2|4|0|Anno" << endl;
|
|
of << "PROVV|1|1|0|Documento provvisiorio/definitivo" << endl;
|
|
of << "DESCR|1|50|0|Descrizione articolo" << endl;
|
|
of << "QTA|4|15|5|Quantita'" << endl;
|
|
of << 1 << endl;
|
|
of << "CODARTMAG+REGIONE+PROVINCIA+NDOC+NRIGA" << endl;
|
|
}
|
|
case 'D': //consegnato articolo/cliente (D)
|
|
{
|
|
of << 12 << endl;
|
|
of << "CODARTMAG|1|20|0|Codice articolo di magazzino" << endl;
|
|
of << "CLIENTE|3|6|0|Cliente" << endl;
|
|
of << "REGIONE|1|2|0|Regione" << endl;
|
|
of << "PROVINCIA|1|2|0|Provincia" << endl;
|
|
of << "NDOC|3|7|0|Numero documento" << endl;
|
|
of << "NRIGA|2|3|0|Numero riga" << endl;
|
|
of << "DATADOC|5|8|0|Data documento" << endl;
|
|
of << "CODNUM|1|4|0|Numerazione riga documento" << endl;
|
|
of << "ANNO|2|4|0|Anno" << endl;
|
|
of << "PROVV|1|1|0|Documento provvisiorio/definitivo" << endl;
|
|
of << "DESCR|1|50|0|Descrizione articolo" << endl;
|
|
of << "QTA|4|15|5|Quantita'" << endl;
|
|
of << 1 << endl;
|
|
of << "CODARTMAG+CLIENTE+REGIONE+PROVINCIA+NDOC+NRIGA" << endl;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void TPrint_consegnato_pd0350_recset::compila_dati_da_testata(TRectype& rec) const
|
|
{
|
|
TString4 stato, comune;
|
|
|
|
//dalla riga documento ricava la testata
|
|
TToken_string chiave;
|
|
chiave = rec.get(RDOC_PROVV);
|
|
chiave.add(rec.get_int(RDOC_ANNO));
|
|
chiave.add(rec.get(RDOC_CODNUM));
|
|
chiave.add(rec.get_long(RDOC_NDOC));
|
|
const TRectype& rec_doc = cache().get(LF_DOC, chiave);
|
|
//intanto prendiamo datadoc...
|
|
rec.put("DATADOC", rec_doc.get_date(DOC_DATADOC));
|
|
//...e alcuni dati che potrebbero servire in seguito senza dover fare altre cache
|
|
const char tipocf = rec_doc.get_char(DOC_TIPOCF);
|
|
const long codcf = rec_doc.get_long(DOC_CODCF);
|
|
|
|
//dalla testata prendiamo indsped
|
|
const TString4 codindsp = rec_doc.get(DOC_CODINDSP);
|
|
if (codindsp.full())
|
|
{
|
|
chiave.cut(0);
|
|
chiave.add(tipocf);
|
|
chiave.add(codcf);
|
|
chiave.add(codindsp);
|
|
const TRectype& rec_indsp = cache().get(LF_INDSP, chiave);
|
|
stato = rec_indsp.get(IND_STATO);
|
|
comune = rec_indsp.get(IND_COM);
|
|
}
|
|
if (comune.empty())
|
|
{
|
|
chiave.cut(0);
|
|
chiave.add(tipocf);
|
|
chiave.add(codcf);
|
|
const TRectype& rec_clifo = cache().get(LF_CLIFO, chiave);
|
|
stato = rec_clifo.get(CLI_STATOCF);
|
|
comune = rec_clifo.get(CLI_COMCF);
|
|
}
|
|
|
|
//se serve il cliente...
|
|
if (_tipo == 'B' || _tipo == 'D') //stampe per cliente!
|
|
rec.put("CLIENTE", codcf);
|
|
|
|
//Tutte le stampe: finalmente puo' cercare il comune sul file dedicato
|
|
chiave = stato;
|
|
chiave.add(comune, 1);
|
|
const TRectype& rec_comuni = cache().get(LF_COMUNI, chiave);
|
|
rec.put("PROVINCIA", rec_comuni.get(COM_PROVCOM));
|
|
rec.put("REGIONE", rec_comuni.get(COM_CODREG));
|
|
|
|
}
|
|
|
|
void TPrint_consegnato_pd0350_recset::create_tempfile()
|
|
{
|
|
//se esiste il file temporano con tracciato persomalizzato lo cancella e lo ricrea vuoto
|
|
TFilename trr;
|
|
trr.tempdir();
|
|
trr.add("pd0350");
|
|
TFilename dbf(trr);
|
|
trr.ext("trr");
|
|
dbf.ext("dbf");
|
|
//crea il file .trr in base ai parametri del metodo
|
|
crea_trr(trr);
|
|
|
|
//crea in memoria il nuovo file temporaneo
|
|
_tmp = new TExternisamfile(dbf, trr);
|
|
}
|
|
|
|
void TPrint_consegnato_pd0350_recset::fill_tempfile(const TDate& da_data)
|
|
{
|
|
//azzera il file temporano di appoggio (non si sa mai..)
|
|
_tmp->zap();
|
|
|
|
TISAM_recordset rdoc("USE RDOC\nSELECT (TIPORIGA='01')&&(PROVV='D')\nFROM CODNUM='B' ANNO=#ANNO\nTO CODNUM='B'");
|
|
rdoc.set_var("#ANNO", TVariant((long)da_data.year()));
|
|
TRectype& rec_tmp = _tmp->curr();
|
|
|
|
TProgind pi(rdoc.items(), "Creazione statistiche in corso.Attendere prego...", true, true);
|
|
|
|
for (bool ok = rdoc.move_first(); ok; ok = rdoc.move_next())
|
|
{
|
|
if (!pi.addstatus(1))
|
|
break;
|
|
|
|
const real qta = rdoc.get(RDOC_QTA).as_real();
|
|
if (qta != ZERO)
|
|
{
|
|
rec_tmp.put("QTA", qta);
|
|
rec_tmp.put("CODNUM", rdoc.get(RDOC_CODNUM).as_string());
|
|
rec_tmp.put("ANNO", rdoc.get(RDOC_ANNO).as_string());
|
|
rec_tmp.put("PROVV", rdoc.get(RDOC_PROVV).as_string());
|
|
rec_tmp.put("NDOC", rdoc.get(RDOC_NDOC).as_string());
|
|
rec_tmp.put("NRIGA", rdoc.get(RDOC_NRIGA).as_string());
|
|
|
|
if (_tipo == 'A' || _tipo == 'B') //stampa per linea(ovvero gruppo merceologico)
|
|
{
|
|
//codice e descrizione gruppo merceologico
|
|
const TString& codartmag = rdoc.get("CODARTMAG").as_string();
|
|
//cerchiamo 'sto gruppo merceologiccco..
|
|
const TString grmerc = cache().get(LF_ANAMAG, codartmag, ANAMAG_GRMERC);
|
|
//..e la sua descrizione
|
|
rec_tmp.put("GRMERC", grmerc);
|
|
rec_tmp.put("DESCR", cache().get("GMC", grmerc, "S0"));
|
|
}
|
|
else //stampa per articolo
|
|
{
|
|
//codice e descrizione articolo
|
|
const TString& codartmag = rdoc.get(RDOC_CODARTMAG).as_string();
|
|
rec_tmp.put("CODARTMAG", codartmag);
|
|
rec_tmp.put("DESCR", cache().get(LF_ANAMAG, codartmag, ANAMAG_DESCR));
|
|
}
|
|
|
|
//ricava datadoc,comune,provincia,regione,nazione,continente,pianeta...
|
|
compila_dati_da_testata(rec_tmp);
|
|
|
|
//scrive il record sul file
|
|
if (rec_tmp.get_date("DATADOC") >= da_data)
|
|
_tmp->write();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TPrint_consegnato_pd0350_recset::requery()
|
|
{
|
|
//controllo sulle date;prende la data inserita come data iniziale dall'utente...
|
|
const TDate da_data = get_var("#DADATA").as_date();
|
|
//se la data di partenza e' vuota la setta ad un anno prima
|
|
if (da_data.ok())
|
|
{
|
|
//il file di appoggio e' gia' stato generato
|
|
if (!_data_minima.ok() || da_data < _data_minima)
|
|
{
|
|
//riempi 'sto benedetto file
|
|
fill_tempfile(da_data);
|
|
//aggiorna la _data_minima
|
|
_data_minima = da_data;
|
|
}
|
|
}
|
|
TISAM_recordset::requery(); //deve chiamare la requery dei TISAMrecset senno' non riaggiorna la query
|
|
}
|
|
|
|
void TPrint_consegnato_pd0350_recset::kill_tempfile()
|
|
{
|
|
delete _tmp;
|
|
_tmp = NULL;
|
|
}
|
|
|
|
|
|
//////////////////////////////
|
|
// APPLICAZIONE
|
|
//////////////////////////////
|
|
class TPrint_consegnato_pd0350 : public TSkeleton_application
|
|
{
|
|
char _tipo_stampa;
|
|
|
|
virtual bool check_autorization() const {return false;}
|
|
virtual const char * extra_modules() const {return "ve";}
|
|
|
|
public:
|
|
virtual void main_loop();
|
|
void set_tipo_stampa(char tipo) { _tipo_stampa = toupper(tipo);}
|
|
TPrint_consegnato_pd0350(char ta) { set_tipo_stampa(ta); }
|
|
};
|
|
|
|
|
|
void TPrint_consegnato_pd0350::main_loop()
|
|
{
|
|
TReport rep;
|
|
bool ok = false;
|
|
switch (_tipo_stampa)
|
|
{
|
|
case 'A':
|
|
ok = rep.load("pd0350_conslinereg");
|
|
break;
|
|
case 'B':
|
|
ok = rep.load("pd0350_conslinecli");
|
|
break;
|
|
case 'C':
|
|
ok = rep.load("pd0350_consartreg");
|
|
break;
|
|
case 'D':
|
|
ok = rep.load("pd0350_consartcli");
|
|
break;
|
|
default:
|
|
error_box(TR("Manca il report selezionato !!"));
|
|
break;
|
|
}
|
|
if (ok)
|
|
{
|
|
const TString query = rep.recordset()->query_text(); //query scritta sul report!!
|
|
TPrint_consegnato_pd0350_recset* rs = new TPrint_consegnato_pd0350_recset(query, _tipo_stampa);
|
|
rep.set_recordset(rs);
|
|
}
|
|
while (ok)
|
|
{
|
|
TReport_book book;
|
|
ok = book.add(rep);
|
|
if (ok)
|
|
book.print_or_preview();
|
|
}
|
|
}
|
|
|
|
|
|
int pd0350100(int argc, char* argv[])
|
|
{
|
|
TApplication::check_parameters(argc, argv);
|
|
TString titolo;
|
|
titolo << "Stampa consegnato ";
|
|
const char ta = (toupper(*argv[2]));
|
|
switch (ta)
|
|
{
|
|
case 'A':
|
|
{
|
|
titolo << "per linea/regione";
|
|
}
|
|
break;
|
|
case 'B':
|
|
{
|
|
titolo << "per linea/cliente";
|
|
}
|
|
break;
|
|
case 'C':
|
|
{
|
|
titolo << "per articolo/regione";
|
|
}
|
|
break;
|
|
case 'D':
|
|
{
|
|
titolo << "per articolo/cliente";
|
|
}
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
TPrint_consegnato_pd0350 a(ta);
|
|
a.run(argc, argv, titolo);
|
|
return 0;
|
|
}
|