Patch level :
Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/trunk@17891 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
944e19deb7
commit
78ba4ed823
139
ps/ps0099100.cpp
139
ps/ps0099100.cpp
@ -1,16 +1,13 @@
|
||||
#include "ps0099100a.h"
|
||||
|
||||
#include <applicat.h>
|
||||
#include <automask.h>
|
||||
#include <modaut.h>
|
||||
#include <progind.h>
|
||||
#include <recarray.h>
|
||||
#include <relation.h>
|
||||
#include <reprint.h>
|
||||
#include <reputils.h>
|
||||
#include <textset.h>
|
||||
|
||||
#include "../cg/cglib01.h"
|
||||
#include "../ve/velib07.h"
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// MASCHERA
|
||||
@ -104,6 +101,8 @@ class TStatistiche_ANIVAL : public TSkeleton_application
|
||||
|
||||
protected:
|
||||
void elabora(const TMask& mask) const;
|
||||
void scrivi_csv(const TRiga_documento& riga, TStatistiche_ANIVAL_csv_recordset& csv) const;
|
||||
void compila_intestazione(TStatistiche_ANIVAL_csv_recordset& csv) const;
|
||||
|
||||
public:
|
||||
virtual bool create();
|
||||
@ -111,6 +110,75 @@ public:
|
||||
|
||||
};
|
||||
|
||||
void TStatistiche_ANIVAL::compila_intestazione(TStatistiche_ANIVAL_csv_recordset& csv) const
|
||||
{
|
||||
//riempie i campi del primo record del csv in modo da avere l'intestazione
|
||||
csv.set(0, "CODART");
|
||||
csv.set(1, "DESCRIZIONE");
|
||||
csv.set(2, "GENNAIO");
|
||||
csv.set(3, "%GEN");
|
||||
csv.set(4, "FEBBRAIO");
|
||||
csv.set(5, "%FEB");
|
||||
csv.set(6, "MARZO");
|
||||
csv.set(7, "%MAR");
|
||||
csv.set(8, "APRILE");
|
||||
csv.set(9, "%APR");
|
||||
csv.set(10, "MAGGIO");
|
||||
csv.set(11, "%MAG");
|
||||
csv.set(12, "GIUGNO");
|
||||
csv.set(13, "%GIU");
|
||||
csv.set(14, "LUGLIO");
|
||||
csv.set(15, "%LUG");
|
||||
csv.set(16, "AGOSTO");
|
||||
csv.set(17, "%AGO");
|
||||
csv.set(18, "SETTEMBRE");
|
||||
csv.set(19, "%SET");
|
||||
csv.set(20, "OTTOBRE");
|
||||
csv.set(21, "%OTT");
|
||||
csv.set(22, "NOVEMBRE");
|
||||
csv.set(23, "%NOV");
|
||||
csv.set(24, "DICEMBRE");
|
||||
csv.set(25, "%DIC");
|
||||
}
|
||||
|
||||
//metodo per la scrittura del csv
|
||||
void TStatistiche_ANIVAL::scrivi_csv(const TRiga_documento& riga, TStatistiche_ANIVAL_csv_recordset& csv) const
|
||||
{
|
||||
//creazione di un nuovo record da esportare
|
||||
csv.new_rec("");
|
||||
//riempimento del record secondo il tracciato:
|
||||
// codart+descrart+12*[impns+%incid]
|
||||
//codart
|
||||
const TString80 codart = riga.get(RDOC_CODART);
|
||||
csv.set(0, TVariant(codart));
|
||||
//descrart
|
||||
const TString& descrart = cache().get(LF_ANAMAG, codart, ANAMAG_DESCR);
|
||||
csv.set(1, TVariant(descrart));
|
||||
//datadoc (serve a stabilire in quale colonna andrà a sommarsi l'importo della riga corrente
|
||||
const TDate datadoc = riga.doc().get_date(DOC_DATADOC);
|
||||
const int mese = datadoc.month();
|
||||
const int column = mese * 2; //le colonne dei mesi sono gennaio=2,febbraio=4,marzo=6...
|
||||
//importo
|
||||
const real importo = riga.importo(true, false); //importo riga corrente
|
||||
real importone = csv.get(column).as_real(); //importo totale della colonna mese corrispondente
|
||||
importone += importo; //aggiunge l'importo riga all'importone
|
||||
csv.set(column, importone); //riscrive l'importone aggiornato nella sua colonna
|
||||
}
|
||||
|
||||
//funzione di ordinamento per il campo codart (campo 0 sul csv)
|
||||
static int compare_csv_rows_codart(const TObject** o1, const TObject** o2)
|
||||
{
|
||||
TToken_string& s1 = *(TToken_string*)*o1;
|
||||
TToken_string& s2 = *(TToken_string*)*o2;
|
||||
|
||||
//deve ordinare sul campo codart
|
||||
const TString& c1 = s1.get(0);
|
||||
const TString& c2 = s2.get(0);
|
||||
int cmp = c1.compare(c2);
|
||||
|
||||
return cmp;
|
||||
}
|
||||
|
||||
|
||||
//metodo di base per la ricerca delle righe documento che soddisfano i parametri dell'utonto
|
||||
void TStatistiche_ANIVAL::elabora(const TMask& mask) const
|
||||
@ -123,7 +191,7 @@ void TStatistiche_ANIVAL::elabora(const TMask& mask) const
|
||||
query << "FROM CODNUM=#CODNUM ANNO=#ANNO PROVV='D'\n";
|
||||
query << "TO CODNUM=#CODNUM ANNO=#ANNO PROVV='D'\n";
|
||||
|
||||
TISAM_recordset righe(query);
|
||||
TDocument_recordset righe(query);
|
||||
righe.set_var("#CODNUM", TVariant(mask.get(F_CODNUM)));
|
||||
righe.set_var("#DADATA", mask.get_date(F_DADATA));
|
||||
righe.set_var("#ADATA", mask.get_date(F_ADATA));
|
||||
@ -132,11 +200,64 @@ void TStatistiche_ANIVAL::elabora(const TMask& mask) const
|
||||
righe.set_var("#ACODART", TVariant(mask.get(F_ACODART)));
|
||||
|
||||
//se trova (si spera!) almeno una rigadoc buona comincia il bello del programma
|
||||
const long nrighe = righe.items();
|
||||
if (nrighe > 0)
|
||||
const long righe_items = righe.items();
|
||||
if (righe_items > 0)
|
||||
{
|
||||
const int cazzone = 1;
|
||||
}
|
||||
//E crea pure la progind..
|
||||
TProgind pi(righe_items, TR("Generazione file..."), true, true);
|
||||
|
||||
//creazione del csv recordset che verra' riempito dai record del recordset righe
|
||||
TStatistiche_ANIVAL_csv_recordset* csv = new TStatistiche_ANIVAL_csv_recordset;
|
||||
|
||||
//Scansione del recordset trovato
|
||||
for (bool ok = righe.move_first(); ok; ok = righe.move_next())
|
||||
{
|
||||
if (!pi.addstatus(1))
|
||||
break;
|
||||
const TDocumento& doc = righe.doc(righe.cursor()->curr());
|
||||
const int nriga = righe.get(RDOC_NRIGA).as_int();
|
||||
//scrive sul CSV i campi che servono al file di excel e al report
|
||||
scrivi_csv(doc[nriga], *csv);
|
||||
}
|
||||
|
||||
//sorting finale per codart
|
||||
csv->sort(compare_csv_rows_codart);
|
||||
|
||||
//se richiesto il file in formato excel...
|
||||
if (mask.get_bool(F_EXCEL))
|
||||
{
|
||||
//crea la riga con le intestazioni dei campi e la mette all'inizio
|
||||
csv->insert_rec(0);
|
||||
compila_intestazione(*csv);
|
||||
//salva il file come richiesto
|
||||
TString path = mask.get(F_PATH);
|
||||
path.lower();
|
||||
path << "\\statanival.csv";
|
||||
csv->save_as(path);
|
||||
|
||||
//accoppa la riga con le intestazioni dei campi
|
||||
csv->destroy(0);
|
||||
|
||||
#ifdef DBG
|
||||
xvt_sys_goto_url(path, "open");
|
||||
#endif
|
||||
}
|
||||
|
||||
//creazione del report di stampa
|
||||
TStatistiche_ANIVAL_report rep;
|
||||
bool ok = rep.load("ps0099100a");
|
||||
//setta il recordset...
|
||||
rep.set_recordset(csv);
|
||||
|
||||
if (ok)
|
||||
{
|
||||
TReport_book book;
|
||||
ok = book.add(rep);
|
||||
if (ok)
|
||||
book.print_or_preview();
|
||||
}
|
||||
|
||||
} //if(righe_items>0...
|
||||
}
|
||||
|
||||
void TStatistiche_ANIVAL::main_loop()
|
||||
|
@ -9,3 +9,5 @@
|
||||
#define F_DADESART 107
|
||||
#define F_ACODART 108
|
||||
#define F_ADESART 109
|
||||
#define F_EXCEL 110
|
||||
#define F_PATH 111
|
||||
|
@ -111,6 +111,20 @@ BEGIN
|
||||
OUTPUT F_ADESART DESCR
|
||||
END
|
||||
|
||||
BOOLEAN F_EXCEL
|
||||
BEGIN
|
||||
PROMPT 2 10 "Genera file in formato Excel (statanival.xls)"
|
||||
MESSAGE FALSE DISABLE,F_PATH
|
||||
MESSAGE TRUE ENABLE,F_PATH
|
||||
END
|
||||
|
||||
STRING F_PATH 256 50
|
||||
BEGIN
|
||||
PROMPT 2 11 "Cartella dove salvare il file "
|
||||
DSELECT
|
||||
FLAGS "M"
|
||||
END
|
||||
|
||||
ENDPAGE
|
||||
|
||||
ENDMASK
|
||||
|
Loading…
x
Reference in New Issue
Block a user