Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 1.7 aga patch 102 sul main trunk git-svn-id: svn://10.65.10.50/trunk@9769 c028cbd2-c16b-5b4b-a496-9718f37d4682
157 lines
3.7 KiB
C++
Executable File
157 lines
3.7 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <progind.h>
|
|
#include <relation.h>
|
|
|
|
#include "sv2.h"
|
|
#include "svlib01.h"
|
|
#include "sv2100a.h"
|
|
|
|
#include "svriep.h"
|
|
|
|
class TRicalcolo_stats : public TSkeleton_application
|
|
{
|
|
TStats_agg _agg;
|
|
|
|
protected:
|
|
virtual void main_loop();
|
|
virtual bool create();
|
|
virtual void on_config_change();
|
|
|
|
public:
|
|
static bool datein_handler(TMask_field& f, KEY k);
|
|
bool kill_stats(const TDate& dfr, const TDate& dto);
|
|
void calc_stats(const TDate& dfr, const TDate& dto);
|
|
};
|
|
|
|
bool TRicalcolo_stats::create()
|
|
{
|
|
open_files(LF_TABCOM, 0); // File comuni
|
|
open_files(LF_TAB, LF_CLIFO, LF_OCCAS, 0); // File ditta
|
|
open_files(LF_CFVEN, LF_DOC, LF_RIGHEDOC, 0); // File vendite
|
|
open_files(LF_SVRIEP, 0); // File statistiche
|
|
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
void TRicalcolo_stats::on_config_change()
|
|
{
|
|
_agg.init();
|
|
}
|
|
|
|
bool TRicalcolo_stats::kill_stats(const TDate& dfr, const TDate& dto)
|
|
{
|
|
TRelation rel(LF_SVRIEP);
|
|
|
|
TRectype recfrom(LF_SVRIEP), recto(LF_SVRIEP);
|
|
|
|
if (dfr.ok())
|
|
{
|
|
recfrom.put(SVR_ANNO, dfr.year());
|
|
recfrom.put(SVR_PERIODO, _agg.date2period(dfr));
|
|
}
|
|
if (dto.ok())
|
|
{
|
|
recto.put(SVR_ANNO, dto.year());
|
|
recto.put(SVR_PERIODO, _agg.date2period(dto));
|
|
}
|
|
|
|
TCursor cur(&rel, "", 1, &recfrom, &recto);
|
|
const long items = cur.items();
|
|
TProgind pi(items, "Azzeramento statistiche", FALSE, TRUE);
|
|
cur.freeze();
|
|
|
|
int err = NOERR;
|
|
for (cur = 0; cur.pos() < items; ++cur)
|
|
{
|
|
pi.addstatus(1);
|
|
err = cur.file().remove();
|
|
if (err != NOERR)
|
|
break;
|
|
}
|
|
|
|
return err == NOERR;
|
|
}
|
|
|
|
|
|
void TRicalcolo_stats::calc_stats(const TDate& dfr, const TDate& dto)
|
|
{
|
|
TRectype recfrom(LF_DOC), recto(LF_DOC);
|
|
if (dfr.ok())
|
|
recfrom.put(DOC_DATADOC, dfr);
|
|
if (dto.ok())
|
|
recto.put(DOC_DATADOC, dto);
|
|
|
|
TRelation rel(LF_DOC);
|
|
TCursor cur(&rel, "PROVV='D'", 3, &recfrom, &recto);
|
|
const long items = cur.items();
|
|
cur.freeze();
|
|
|
|
TProgind pi(items, "Ricalcolo statistiche", FALSE, TRUE);
|
|
|
|
TDocumento* curr = new TDocumento;
|
|
cur.file().set_curr(curr);
|
|
const TDocumento& doc = *curr;
|
|
|
|
long records = 0;
|
|
_agg.reset();
|
|
|
|
for (cur = 0; cur.pos() < items; ++cur)
|
|
{
|
|
pi.addstatus(1);
|
|
|
|
const TTipo_documento& tipodoc = doc.tipo();
|
|
if (!tipodoc.statistiche())
|
|
continue;
|
|
|
|
const bool nota_cr = tipodoc.nota_credito();
|
|
for (int r = doc.physical_rows(); r > 0; r--)
|
|
{
|
|
const TRiga_documento& rdoc = doc[r];
|
|
if (nota_cr)
|
|
_agg.sub(rdoc);
|
|
else
|
|
_agg.add(rdoc);
|
|
}
|
|
|
|
records++;
|
|
if (records % 1000 == 0)
|
|
_agg.update();
|
|
}
|
|
_agg.update();
|
|
if (_agg.empty())
|
|
message_box("Attenzione: l'archivio riepilogativo delle statistiche ora ricalcolato risulta vuoto");
|
|
}
|
|
|
|
bool TRicalcolo_stats::datein_handler(TMask_field& f, KEY k)
|
|
{
|
|
if (f.to_check(k))
|
|
{
|
|
TConfig prassid(CONFIG_DITTA, "Euro");
|
|
TDate adozione = prassid.get("DataAdozione");
|
|
TDate inizio(f.get());
|
|
if (adozione.ok() && inizio < adozione)
|
|
return f.error_box("Impossibile effettuare la ricostruzione statistiche \n a una data inferiore alla data adozione Euro") ;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void TRicalcolo_stats::main_loop()
|
|
{
|
|
TMask m("sv2100a");
|
|
m.set_handler(F_FROMDATE, datein_handler);
|
|
while (m.run() == K_ENTER)
|
|
{
|
|
const TDate dfr(m.get(F_FROMDATE));
|
|
const TDate dto(m.get(F_TODATE));
|
|
if (kill_stats(dfr, dto))
|
|
calc_stats(dfr, dto);
|
|
}
|
|
}
|
|
|
|
int sv2100(int argc, char* argv[])
|
|
{
|
|
TRicalcolo_stats app;
|
|
app.run(argc, argv, "Ricalcolo statistiche");
|
|
return 0;
|
|
}
|