campo-sirio/db/db2400.cpp
alex 3a770ee656 Patch level : XX.648
Files correlati     :
Ricompilazione Demo : [ ]
Commento            : Riportata la versione 01.05 patch 648


git-svn-id: svn://10.65.10.50/trunk@8633 c028cbd2-c16b-5b4b-a496-9718f37d4682
1999-10-22 10:00:18 +00:00

339 lines
7.7 KiB
C++
Executable File

#include <applicat.h>
#include <browfile.h>
#include <automask.h>
#include <defmask.h>
#include <execp.h>
#include <mailbox.h>
#include <progind.h>
#include <relation.h>
#include <tabutil.h>
#include <viswin.h>
#include "db2.h"
#include "dblib.h"
#include "../mg/mglib.h"
#include "db2400a.h"
///////////////////////////////////////////////////////////
// TValorizzazione_mask
///////////////////////////////////////////////////////////
class TValorizzazione_mask : public TAutomask
{
TAssoc_array _valori;
TAssoc_array _risultati;
TDistinta_tree _tree;
int _tipoval;
TString4 _annoes,_catven, _codlist ;
TString8 _codmag;
protected:
virtual bool on_field_event(TOperable_field& f, TField_event e, long jolly);
public:
real valore(const TCodice_articolo& dis, const char* liv = NULL);
void elabora();
void salva();
TValorizzazione_mask();
virtual ~TValorizzazione_mask() { }
};
real TValorizzazione_mask::valore(const TCodice_articolo& dis, const char* liv)
{
real total;
if (dis.not_empty())
{
TString80 cod = dis;
if (liv && *liv)
cod << ',' << liv;
real* val = (real*)_valori.objptr(cod);
if (val == NULL)
{
if (_tree.set_root(dis))
{
TArray boom;
// Esplosione ai materiali di base
// raggruppati alla unita' di misura di riferimento
_tree.explode(boom, TRUE, RAGGR_EXP_BASE);
for (int r = boom.last(); r >= 0; r--)
{
const TRiga_esplosione& esp = (const TRiga_esplosione&)boom[r];
const real value = esp.val() * valore(esp.articolo(), esp.giacenza());
total += value;
}
if (!total.is_zero())
_risultati.add(cod, total);
}
else
{
const char tipo = _tree.get_type(dis);
switch (tipo)
{
case 'A':
{
TArticolo_giacenza art(dis);
switch (_tipoval)
{
case 0: total = art.ultimo_costo(_annoes); break;
case 1: total = art.media_costi(_annoes); break;
case 2: total = art.prezzo_listino(_annoes, _catven, _codlist); break;
case 3: total = art.costo_standard(_annoes); break;
case 4: total = art.costo_medio(_annoes, _codmag, liv); break;
case 5: total = art.costo_mediopond(_annoes, _codmag, liv); break;
case 6: total = art.LIFO_annuale(_annoes, _codmag, liv); break;
case 7: total = art.FIFO_annuale(_annoes, _codmag, liv); break;
case 8: total = art.LIFO(_annoes, _codmag, liv); break;
case 9: total = art.FIFO(_annoes, _codmag, liv); break;
default: NFCHECK("Tipo valorizzazione errato: %d", _tipoval);
}
}
break;
case 'L':
{
TDecoder val("LAV", "R0");
total = real(val.decode(dis));
}
break;
default :
{
TDecoder dist(LF_DIST, "PREZZO");
total = real(dist.decode(dis));
}
break;
}
_valori.add(cod, total);
}
}
else
total = *val;
}
return total;
}
void TValorizzazione_mask::elabora()
{
TRectype rec_from(LF_DIST), rec_to(LF_DIST);
rec_from.put("CODDIST", get(F_DIST_FROM));
rec_to.put ("CODDIST", get(F_DIST_TO));
_annoes = get(F_ANNOES);
_tipoval = get_int(F_TIPO);
_catven = get(F_CATVEN_LIST);
_codlist = get(F_CODLIST);
TRelation rel(LF_DIST);
TCursor cur(&rel, "", 1, &rec_from, &rec_to);
const long items = cur.items();
TProgind pi(items, "Valorizzazione in corso...", TRUE, TRUE);
TBrowsefile_field& bf = (TBrowsefile_field&)field(F_PREVIEW);
TViswin& vw = bf.vis_win();
vw.destroy_lines();
_valori.destroy();
_risultati.destroy();
TString line, num;
line = "@bCodice distinta Valore";
bf.add_line(line);
cur.freeze(TRUE);
for (cur = 0; cur.pos() < items; ++cur)
{
pi.addstatus(1);
if (pi.iscancelled())
break;
TCodice_articolo art = cur.curr().get("CODDIST");
real value = valore(art);
switch(_tree.get_type(art))
{
case 'A': line = "$[r,w]"; break;
case 'L': line = "$[v,w]"; break;
case 'V': line = "$[b,w]"; break;
default : line = "$[n,w]"; break;
}
line << art << "$[n,w]";
line.left_just(30);
num = value.string(".3");
num.right_just(22);
line << num;
bf.add_line(line);
}
if (pi.isfinished())
enable(DLG_SAVEREC);
vw.goto_top();
}
void TValorizzazione_mask::salva()
{
const TDate oggi = get(F_DATA);
const bool ultimo = get(F_VALORIZZA) == "1";
TProgind pi(_risultati.items(), "Registrazione in corso...", TRUE, TRUE);
TLocalisamfile dis(LF_DIST);
TTable lav("LAV");
FOR_EACH_ASSOC_OBJECT(_risultati, obj, key, item)
{
pi.addstatus(1);
if (pi.iscancelled())
break;
const real& val = (const real&)*item;
if (!val.is_zero())
{
switch(_tree.get_type(key))
{
case 'A':
{
TArticolo_giacenza art(key);
if (ultimo)
art.put_ultimo_costo(val, oggi);
else
art.put_costo_standard(val);
art.rewrite();
}
break;
case 'L':
lav.put("CODTAB", key);
if (lav.read(_isequal, _lock) == NOERR)
{
lav.put("R0", val);
lav.rewrite();
}
break;
case 'G':
case 'V':
dis.put("CODDIST", key);
if (dis.read(_isequal, _lock) == NOERR)
{
dis.put("PREZZO", val);
dis.rewrite();
}
break;
default :break;
}
}
}
if (pi.isfinished())
{
_valori.destroy();
_risultati.destroy();
disable(DLG_SAVEREC);
}
}
bool TValorizzazione_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
{
switch (f.dlg())
{
case DLG_ELABORA:
if (e == fe_button)
elabora();
break;
case DLG_SAVEREC:
if (e == fe_button)
salva();
break;
case DLG_QUIT:
if (e == fe_button)
{
if (_risultati.items() > 0)
return yesno_box("I risultati dell'ultima elaborazione\n"
"non sono stati registrati:\n"
"Si desidera uscire ugualmente?");
}
break;
default:
break;
}
return TRUE;
}
static const char* link_handler(TMask&, int id, const char* str, bool)
{
const char* app = NULL;
switch(id)
{
case 0: app = "ve2 -3"; break;
case 1: app = "ba3 -0 LAV"; break;
case 2: app = "db0 -4"; break;
default: break;
}
if (app)
{
TString ss = "1|"; ss << str;
TMessage fs(app, MSG_LN, ss);
fs.send();
TExternal_app prg(app);
prg.run();
}
return "";
}
TValorizzazione_mask::TValorizzazione_mask()
: TAutomask("db2400a")
{
TBrowsefile_field& bf = (TBrowsefile_field&)field(F_PREVIEW);
bf.enable_link("Articolo ", 'r');
bf.enable_link("Lavorazione ", 'v');
bf.enable_link("Distinta ", 'b');
bf.set_link_handler(link_handler);
disable(DLG_SAVEREC);
}
///////////////////////////////////////////////////////////
// TValorizzazione
///////////////////////////////////////////////////////////
class TValorizzazione : public TSkeleton_application
{
protected:
virtual bool create();
public:
virtual void main_loop();
};
bool TValorizzazione::create()
{
open_files(LF_MAG,LF_STOMAG,0);
return TSkeleton_application::create();
}
void TValorizzazione::main_loop()
{
TValorizzazione_mask m;
TConfig conf(CONFIG_DITTA, "mg");
const bool listini = conf.get_bool("GES", "ve", 1);
m.enable(-G_LISTINO, listini);
m.enable(F_CATVEN_LIST, listini && conf.get_bool("GESLISCV", "ve"));
m.run();
}
int db2400(int argc, char* argv[])
{
TValorizzazione app;
app.run(argc, argv, "Valorizzazione");
return 0;
}