1b14ec9415
git-svn-id: svn://10.65.10.50/branches/R_10_00@23236 c028cbd2-c16b-5b4b-a496-9718f37d4682
182 lines
4.8 KiB
C++
182 lines
4.8 KiB
C++
#include <applicat.h>
|
||
#include <mask.h>
|
||
#include <progind.h>
|
||
#include <recarray.h>
|
||
#include <recset.h>
|
||
|
||
#include <../mg/anamag.h>
|
||
#include <doc.h>
|
||
#include <rdoc.h>
|
||
|
||
class TStorico_consumi : public TSkeleton_application
|
||
{
|
||
protected:
|
||
TRecnotype kill_records(int anno, TAssoc_array& clifo_grmerc) const;
|
||
TRecnotype build_records(int anno, TAssoc_array& clifo_grmerc) const;
|
||
void elabora(int anno) const;
|
||
|
||
public:
|
||
virtual void main_loop();
|
||
};
|
||
|
||
TRecnotype TStorico_consumi::kill_records(int anno, TAssoc_array& clifo_grmerc) const
|
||
{
|
||
TISAM_recordset stc("&STC");
|
||
TProgind pi(stc.items(), TR("Analisi storico consumi"));
|
||
for (bool ok = stc.move_first(); ok; ok = stc.move_next())
|
||
{
|
||
if (!pi.addstatus(1))
|
||
break;
|
||
const TString& key = stc.get("CODTAB").as_string();
|
||
if (atoi(key.right(4)) == anno || key.find('@') > 0)
|
||
clifo_grmerc.add(key);
|
||
}
|
||
return clifo_grmerc.items();
|
||
}
|
||
|
||
TRecnotype TStorico_consumi::build_records(int anno, TAssoc_array& clifo_grmerc) const
|
||
{
|
||
TString query, limit;
|
||
limit << "PROVV=D ANNO=" << anno;
|
||
query << "USE RDOC KEY 3"
|
||
<< "\nFROM " << limit
|
||
<< "\nTO " << limit;
|
||
|
||
TISAM_recordset rdoc(query);
|
||
TProgind pi(rdoc.items(), TR("Scansione documenti"));
|
||
|
||
TToken_string key;
|
||
for (bool ok = rdoc.move_first(); ok; ok = rdoc.move_next())
|
||
{
|
||
if (!pi.addstatus(1))
|
||
break;
|
||
|
||
const TString4 tiporiga = rdoc.get(RDOC_TIPORIGA).as_string();
|
||
if (tiporiga != "01" && tiporiga != "09")
|
||
continue;
|
||
|
||
key = rdoc.get(RDOC_PROVV).as_string();
|
||
key.add(rdoc.get(RDOC_ANNO).as_string());
|
||
key.add(rdoc.get(RDOC_CODNUM).as_string());
|
||
key.add(rdoc.get(RDOC_NDOC).as_string());
|
||
|
||
const TRectype& doc = cache().get(LF_DOC, key);
|
||
const long codcf = doc.get_long(DOC_CODCF);
|
||
const TDate datadoc = doc.get(DOC_DATADOC);
|
||
const TString4 tipo = doc.get(DOC_TIPODOC);
|
||
|
||
const TString& b2 = cache().get("%TIP", tipo, "B2");
|
||
if (b2.blank())
|
||
continue;
|
||
|
||
const TRectype& anamag = cache().get(LF_ANAMAG, rdoc.get(RDOC_CODARTMAG).as_string());
|
||
TString4 grmerc = anamag.get(ANAMAG_GRMERC).left(3);
|
||
grmerc.left_just(3);
|
||
|
||
key.format("%06ld%s%4d", codcf, (const char*)grmerc, anno);
|
||
TRectype* rec = (TRectype*)clifo_grmerc.objptr(key);
|
||
if (rec == NULL)
|
||
{
|
||
rec = new TRectype(LF_TABMOD);
|
||
rec->put("MOD", "HA");
|
||
rec->put("COD", "STC");
|
||
rec->put("CODTAB", key);
|
||
|
||
TString16 s0;
|
||
s0.format("%s%06ld%4d", (const char*)grmerc, codcf, anno);
|
||
rec->put("S0", s0);
|
||
|
||
clifo_grmerc.add(key, rec);
|
||
}
|
||
|
||
real qta = rdoc.get(RDOC_QTA).as_real();
|
||
qta *= CENTO; qta.round(); // Salvo la quantit<69> moltiplicata per 100 ed arrotondata
|
||
|
||
const real valore = rdoc.get("RG1:IMPNS").as_real();
|
||
|
||
TString8 qta_field, val_field;
|
||
if (tiporiga == "01")
|
||
{
|
||
qta_field.format("I%d", datadoc.month());
|
||
val_field.format("R%d", datadoc.month());
|
||
}
|
||
else
|
||
{
|
||
qta_field = "I0";
|
||
val_field = "R0";
|
||
}
|
||
rec->add(qta_field, qta);
|
||
rec->add(val_field, valore);
|
||
}
|
||
|
||
return clifo_grmerc.items();
|
||
}
|
||
|
||
void TStorico_consumi::elabora(int anno) const
|
||
{
|
||
TAssoc_array old_recs, new_recs;
|
||
|
||
TRecnotype old_tot = kill_records(anno, old_recs);
|
||
const TRecnotype new_tot = build_records(anno, new_recs);
|
||
|
||
TFast_isamfile stc(LF_TABMOD);
|
||
if (new_tot)
|
||
{
|
||
TProgind pi(new_tot, TR("Salvataggio storico"));
|
||
FOR_EACH_ASSOC_OBJECT(new_recs, obj, key, rec)
|
||
{
|
||
if (!pi.addstatus(1))
|
||
break;
|
||
const TRectype& r = *(TRectype*)rec;
|
||
int err = r.rewrite_write(stc);
|
||
if (err == NOERR)
|
||
{
|
||
const TString& key = r.get("CODTAB");
|
||
old_recs.remove(key); // Tolgo il record dalla lista di quelli da cancellare
|
||
}
|
||
else
|
||
{
|
||
error_box(FR("Errore %d di scrittura sulla tabella STC"), err);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
old_tot = old_recs.items();
|
||
if (old_tot) // Cancello i record dell'anno che non esistono pi<70>
|
||
{
|
||
TProgind pi(old_tot, TR("Allineamento storico"));
|
||
TRectype& rec = stc.curr();
|
||
FOR_EACH_ASSOC_OBJECT(old_recs, obj, key, itm)
|
||
{
|
||
if (!pi.addstatus(1))
|
||
break;
|
||
rec.put("MOD", "HA");
|
||
rec.put("COD", "STC");
|
||
rec.put("CODTAB", key);
|
||
const int err = rec.remove(stc);
|
||
if (err != NOERR)
|
||
{
|
||
error_box(FR("Errore %d di cancellazione sulla tabella STC"), err);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void TStorico_consumi::main_loop()
|
||
{
|
||
TMask m(main_app().title(), 1, 24, 5);
|
||
m.add_number(101, 0, "Anno ", 1, 1, 4, "U").check_type(CHECK_REQUIRED);
|
||
m.add_button(DLG_OK, 0, "", -12, -1, 8, 2);
|
||
m.add_button(DLG_CANCEL, 0, "", -22, -1, 8, 2);
|
||
while (m.run() == K_ENTER)
|
||
elabora(m.get_int(101));
|
||
}
|
||
|
||
int ha1400(int argc, char* argv[])
|
||
{
|
||
TStorico_consumi a;
|
||
a.run(argc, argv, TR("Storico Consumi"));
|
||
return 0;
|
||
} |