519 lines
15 KiB
C++
Executable File
519 lines
15 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <config.h>
|
|
#include <mask.h>
|
|
#include <printer.h>
|
|
#include <relation.h>
|
|
#include <tabutil.h>
|
|
#include <urldefid.h>
|
|
#include <utility.h>
|
|
#include <form.h>
|
|
#include <printapp.h>
|
|
|
|
#include "..\ve\veconf.h"
|
|
#include "mglib.h"
|
|
#include "mg4200.h"
|
|
#include "mg4frm.h"
|
|
|
|
#define MAX_VAL_COLUMNS 6
|
|
class TForm_inventario : public TForm_stampemg
|
|
{
|
|
int colonne;
|
|
TConfig *conf_ditta;
|
|
TArticolo_giacenza * _curr_art;
|
|
TString16 _codlist,_catven; // codici listino e cat vendita
|
|
bool _giaceff, // flag inventario di giacenza
|
|
_valcomp; // flag valorizzzione finiti o componenti
|
|
TTipo_valorizz _valorizz_scelte[MAX_VAL_COLUMNS]; // valorizzazioni delle varie colonne
|
|
|
|
TArticolo_giacenza &curr_art();
|
|
public:
|
|
void set_parametri(const char * codcm,const char * cod,bool giaceff, bool valcomp);
|
|
bool valorizzazione(TForm_item &cf, TTipo_valorizz t);
|
|
bool validate(TForm_item &cf, TToken_string &s);
|
|
void add_colval(int tipo);
|
|
TForm_inventario(const char *name,const char *code) ;
|
|
~TForm_inventario();
|
|
};
|
|
|
|
bool TForm_inventario::validate(TForm_item &cf, TToken_string &s)
|
|
{
|
|
const TString code(s.get(0)); // prende il primo parametro, il codice del messaggio
|
|
TString subcode;
|
|
|
|
if (code=="_USER") {
|
|
TRectype & magrec=relation()->lfile(LF_MAG).curr();
|
|
TString16 annoes(magrec.get(MAG_ANNOES));
|
|
subcode=s.get();
|
|
if (subcode=="GIAC") {
|
|
real v=curr_art().giacenza_corretta(magrec,_giaceff,_valcomp);
|
|
cf.set(v.string());
|
|
}
|
|
if (subcode=="VAL1") {
|
|
valorizzazione(cf,_valorizz_scelte[0]);
|
|
}
|
|
if (subcode=="VAL2"&& colonne >=2) {
|
|
valorizzazione(cf,_valorizz_scelte[1]);
|
|
}
|
|
if (subcode=="VAL3" && colonne >=3) {
|
|
valorizzazione(cf,_valorizz_scelte[2]);
|
|
}
|
|
if (subcode=="VAL4" && colonne >=4) {
|
|
valorizzazione(cf,_valorizz_scelte[3]);
|
|
}
|
|
if (subcode=="VAL5"&& colonne >=5) {
|
|
valorizzazione(cf,_valorizz_scelte[4]);
|
|
}
|
|
if (subcode=="VAL6" && colonne >=6) {
|
|
valorizzazione(cf,_valorizz_scelte[5]);
|
|
}
|
|
if (subcode=="NAMEVAL1") {
|
|
cf.set(Nome_valorizz[_valorizz_scelte[0]]);
|
|
}
|
|
if (subcode=="NAMEVAL2"&& colonne >=2) {
|
|
cf.set(Nome_valorizz[_valorizz_scelte[1]]);
|
|
}
|
|
if (subcode=="NAMEVAL3" && colonne >=3) {
|
|
cf.set(Nome_valorizz[_valorizz_scelte[2]]);
|
|
}
|
|
if (subcode=="NAMEVAL4" && colonne >=4) {
|
|
cf.set(Nome_valorizz[_valorizz_scelte[3]]);
|
|
}
|
|
if (subcode=="NAMEVAL5"&& colonne >=5) {
|
|
cf.set(Nome_valorizz[_valorizz_scelte[4]]);
|
|
}
|
|
if (subcode=="NAMEVAL6" && colonne >=6) {
|
|
cf.set(Nome_valorizz[_valorizz_scelte[5]]);
|
|
}
|
|
if (subcode=="LINEATOTALI") {
|
|
TString l(29*colonne+12,'-');
|
|
cf.set(l);
|
|
}
|
|
}
|
|
return TForm_stampemg::validate(cf, s);
|
|
}
|
|
|
|
TArticolo_giacenza &TForm_inventario::curr_art()
|
|
{
|
|
TRectype & magrec=relation()->lfile(LF_MAG).curr();
|
|
if (_curr_art==NULL || magrec.get(MAG_CODART)!=_curr_art->codice() ) {
|
|
if (_curr_art) delete _curr_art;
|
|
_curr_art=new TArticolo_giacenza(magrec.get(MAG_CODART));
|
|
}
|
|
return *_curr_art;
|
|
}
|
|
|
|
void TForm_inventario::add_colval(int tipo)
|
|
{
|
|
TTipo_valorizz t ;
|
|
switch (tipo) {
|
|
case 1:
|
|
t=valorizz_ultcos;
|
|
break;
|
|
case 2:
|
|
t=valorizz_mediacos;
|
|
break;
|
|
case 3:
|
|
t=valorizz_przlist;
|
|
break;
|
|
case 4:
|
|
t=valorizz_coststd;
|
|
break;
|
|
case 5:
|
|
t=valorizz_costmedio;
|
|
break;
|
|
case 6:
|
|
t=valorizz_FIFOa;
|
|
break;
|
|
case 7:
|
|
t=valorizz_LIFOa;
|
|
break;
|
|
case 8:
|
|
t=valorizz_FIFO;
|
|
break;
|
|
case 9:
|
|
t=valorizz_LIFO;
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
_valorizz_scelte[colonne++]=t;
|
|
TString col;
|
|
col << colonne;
|
|
find_field('B',odd_page,FF_ENABLECOLS).set(col);
|
|
find_field('H',odd_page,FF_ENABLECOLS).set(col);
|
|
}
|
|
|
|
bool TForm_inventario::valorizzazione(TForm_item &cf, TTipo_valorizz t)
|
|
{
|
|
TRectype & magrec=relation()->lfile(LF_MAG).curr();
|
|
TString annoes(magrec.get(MAG_ANNOES));
|
|
real v;
|
|
if (t==valorizz_ultcos) {
|
|
v=curr_art().ultimo_costo(annoes).string();
|
|
}
|
|
if (t==valorizz_mediacos) {
|
|
v=curr_art().media_costi(annoes).string();
|
|
}
|
|
if (t==valorizz_przlist) {
|
|
v=curr_art().prezzo_listino(annoes,_codlist,_catven).string();
|
|
}
|
|
if (t==valorizz_coststd) {
|
|
v=curr_art().costo_standard(annoes).string();
|
|
}
|
|
if (t==valorizz_costmedio) {
|
|
const TString codmag(magrec.get(MAG_CODMAG));
|
|
const TString livello(magrec.get(MAG_LIVELLO));
|
|
v=curr_art().costo_medio(annoes,codmag,livello).string();
|
|
}
|
|
if (t==valorizz_LIFO) {
|
|
const TString codmag(magrec.get(MAG_CODMAG));
|
|
const TString livello(magrec.get(MAG_LIVELLO));
|
|
v=curr_art().LIFO(annoes,codmag,livello, _giaceff,_valcomp).string();
|
|
}
|
|
if (t==valorizz_FIFO) {
|
|
const TString codmag(magrec.get(MAG_CODMAG));
|
|
const TString livello(magrec.get(MAG_LIVELLO));
|
|
v=curr_art().FIFO(annoes,codmag,livello, _giaceff,_valcomp).string();
|
|
}
|
|
if (t==valorizz_LIFOa) {
|
|
const TString codmag(magrec.get(MAG_CODMAG));
|
|
const TString livello(magrec.get(MAG_LIVELLO));
|
|
v=curr_art().LIFO_annuale(annoes,codmag,livello, _giaceff,_valcomp).string();
|
|
}
|
|
if (t==valorizz_FIFOa) {
|
|
const TString codmag(magrec.get(MAG_CODMAG));
|
|
const TString livello(magrec.get(MAG_LIVELLO));
|
|
v=curr_art().FIFO_annuale(annoes,codmag,livello, _giaceff,_valcomp).string();
|
|
}
|
|
cf.set(((real)(v * curr_art().giacenza_corretta(magrec,_giaceff,_valcomp))).string());
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
void TForm_inventario::set_parametri(const char * codcatv,const char * codlist,bool giaceff, bool valcomp)
|
|
{
|
|
_catven=codcatv;
|
|
_codlist=codlist;
|
|
_giaceff=giaceff;
|
|
_valcomp=valcomp;
|
|
}
|
|
|
|
TForm_inventario::TForm_inventario(const char *name,const char *code) :
|
|
TForm_stampemg(name,code),_curr_art(NULL)
|
|
{
|
|
colonne=0;
|
|
}
|
|
|
|
|
|
TForm_inventario::~TForm_inventario()
|
|
{
|
|
if (_curr_art) delete _curr_art;
|
|
}
|
|
|
|
|
|
|
|
class TStampainv_mask: public TMask
|
|
{
|
|
static bool handle_ragg(TMask_field &fld, KEY k); // handler
|
|
static bool handle_liv(TMask_field &fld, KEY k); // handler
|
|
static bool handle_subord(TMask_field &fld, KEY k); // handler
|
|
public:
|
|
TStampainv_mask();
|
|
~TStampainv_mask(){};
|
|
};
|
|
|
|
TStampainv_mask::TStampainv_mask():
|
|
TMask("mg4200")
|
|
{
|
|
TConfig prassid(CONFIG_DITTA, "ve"); // apre il file di configurazione della ditta corrente
|
|
if (prassid.get_bool("GES", NULL, A_LISTINI))
|
|
field(F_CATVENLISTINO).enable(prassid.get_bool("GESLISCV"));
|
|
else {
|
|
field(F_CATVENLISTINO).disable(); field(F_CODLISTINO).disable();
|
|
}
|
|
TCodart_livelli artlev;
|
|
TCodgiac_livelli giaclev;
|
|
|
|
set_handler(F_TOLIVELLOART, handle_liv);
|
|
set_handler(F_TOLIVELLOGIAC, handle_liv);
|
|
set_handler(F_ORDINE, handle_ragg);
|
|
set_handler(F_DETTAGLIODEP, handle_ragg);
|
|
set_handler(F_DETTAGLIOMAG, handle_ragg);
|
|
set_handler(F_ORDINEART,handle_subord);
|
|
if (!artlev.enabled()) {
|
|
TMask_field &f1=field(F_RAGGCODICE);
|
|
f1.reset(); f1.check();f1.hide();
|
|
field(F_FROMLIVELLOART).hide();
|
|
field(F_TOLIVELLOART).hide();
|
|
}
|
|
if (!giaclev.enabled()) {
|
|
TMask_field &f2=field(F_RAGGLIVGIAC);
|
|
f2.reset(); f2.check();f2.hide();
|
|
field(F_FROMLIVELLOGIAC).hide();
|
|
field(F_TOLIVELLOGIAC).hide();
|
|
}
|
|
}
|
|
|
|
bool TStampainv_mask::handle_subord(TMask_field &fld, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
{
|
|
TOperable_field &fraggcod=(TOperable_field &)fld.mask().field(F_RAGGCODICE);
|
|
TOperable_field &fragggiac=(TOperable_field &)fld.mask().field(F_RAGGLIVGIAC);
|
|
switch (fld.get()[1]) {
|
|
case 'C':
|
|
if (fld.mask().get(F_ORDINE)=="A")
|
|
fraggcod.enable();
|
|
else {
|
|
if (!fld.mask().get_bool(F_DETTAGLIOMAG) || !fld.mask().get_bool(F_DETTAGLIODEP))
|
|
{
|
|
fraggcod.reset(); fraggcod.disable();
|
|
fragggiac.reset(); fragggiac.disable();
|
|
fraggcod.do_message(0);fragggiac.do_message(0);
|
|
}
|
|
}
|
|
break;
|
|
case 'M':
|
|
case 'D':
|
|
fraggcod.reset(); fraggcod.check();fraggcod.disable();
|
|
break;
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TStampainv_mask::handle_liv(TMask_field &fld, KEY k)
|
|
{
|
|
if (k == K_TAB)
|
|
{
|
|
TOperable_field &ftotmag=(TOperable_field &)fld.mask().field(F_TOTALIMAGAZZINI);
|
|
TOperable_field &fdettmag=(TOperable_field &)fld.mask().field(F_DETTAGLIOMAG);
|
|
if (fld.mask().get(F_ORDINE)=="A")
|
|
{
|
|
if (fld.mask().get_int(F_TOLIVELLOART) || fld.mask().get_int(F_TOLIVELLOGIAC))
|
|
{
|
|
// raggruppamenti prima del dettaglio magazzini
|
|
ftotmag.reset(); ftotmag.disable();ftotmag.do_message(0);
|
|
} else {
|
|
ftotmag.enable();
|
|
}
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TStampainv_mask::handle_ragg(TMask_field &fld, KEY k)
|
|
{
|
|
if (k == K_SPACE)
|
|
{
|
|
TOperable_field &ftotmag=(TOperable_field &)fld.mask().field(F_TOTALIMAGAZZINI);
|
|
TOperable_field &fraggcod=(TOperable_field &)fld.mask().field(F_RAGGCODICE);
|
|
TOperable_field &fragggiac=(TOperable_field &)fld.mask().field(F_RAGGLIVGIAC);
|
|
if (fld.mask().get(F_ORDINE)=="M")
|
|
{
|
|
ftotmag.enable();
|
|
if (!fld.mask().get_bool(F_DETTAGLIOMAG) || !fld.mask().get_bool(F_DETTAGLIODEP))
|
|
{
|
|
fraggcod.reset(); fraggcod.disable();
|
|
fragggiac.reset(); fragggiac.disable();
|
|
fraggcod.do_message(0);fragggiac.do_message(0);
|
|
return TRUE;
|
|
}
|
|
}
|
|
fraggcod.enable();
|
|
fragggiac.enable();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// STAMPA anagrafiche
|
|
class TStampa_inventario : public TPrint_application
|
|
{
|
|
TArray * _files;
|
|
TMask * _mask;
|
|
TCursor * _cur;
|
|
TForm_inventario * _form; // to be moved into TPrint_application
|
|
|
|
protected:
|
|
virtual bool print_one(int file)
|
|
{return TRUE;}
|
|
virtual bool user_create();
|
|
virtual bool user_destroy();
|
|
virtual bool set_print(int i=1);
|
|
virtual void set_page(int file,int count)
|
|
{ }
|
|
void setprint_permagazzini();
|
|
void setprint_perarticoli();
|
|
|
|
public:
|
|
TStampa_inventario() {}
|
|
};
|
|
|
|
|
|
bool TStampa_inventario::user_create()
|
|
{
|
|
_mask = new TStampainv_mask();
|
|
_files = new TArray();
|
|
// aggiunge i files per usare i tracciati record
|
|
_files->add(new TLocalisamfile(LF_ANAMAG));
|
|
_files->add(new TLocalisamfile(LF_UMART));
|
|
_files->add(new TLocalisamfile(LF_DESLIN));
|
|
_files->add(new TLocalisamfile(LF_CODCORR));
|
|
_files->add(new TLocalisamfile(LF_MAG));
|
|
_files->add(new TLocalisamfile(LF_STOMAG));
|
|
_files->add(new TLocalisamfile(LF_MOVMAG));
|
|
_files->add(new TLocalisamfile(LF_RMOVMAG));
|
|
return TRUE;
|
|
}
|
|
|
|
bool TStampa_inventario::user_destroy()
|
|
{
|
|
delete _mask;
|
|
delete _files;
|
|
return TRUE;
|
|
}
|
|
|
|
void TStampa_inventario::setprint_permagazzini()
|
|
{
|
|
char subordine=*_mask->get(F_ORDINEART);
|
|
TRectype darec(LF_MAG),arec(LF_MAG);
|
|
TString cfilter,sortexp,joinexp;
|
|
_cur = _form->cursor();
|
|
// setta il filtro sul cursore
|
|
/* if (*_mask->get(F_FILTRO)=='N')
|
|
cfilter << "(GIAC!=0)&&" ;
|
|
if (*_mask->get(F_FILTRO)=='+')
|
|
cfilter << "(GIAC>0)&&" ;*/
|
|
if (*_mask->get(F_DAART))
|
|
cfilter << "(CODART>=" <<'"' << _mask->get(F_DAART)<< "\")&&" ;
|
|
if (*_mask->get(F_AART))
|
|
cfilter << "(CODART<=" <<'"' << _mask->get(F_AART)<< "\")&&" ;
|
|
if (cfilter.not_empty())
|
|
cfilter.cut(cfilter.len()-2);
|
|
|
|
// abilita/disabilita le sezioni dei totali
|
|
_form->setdett_permag(_mask->get_int(F_FROMLIVELLOART),_mask->get_int(F_TOLIVELLOART),
|
|
_mask->get_int(F_FROMLIVELLOGIAC),_mask->get_int(F_TOLIVELLOGIAC),
|
|
TRUE,_mask->get_bool(F_DETTAGLIOMAG),_mask->get_bool(F_DETTAGLIODEP));
|
|
|
|
darec.put("ANNOES",_mask->get(F_ANNOES));
|
|
darec.put("CODMAG",_mask->get(F_DAMAG));
|
|
arec.put("ANNOES",_mask->get(F_ANNOES));
|
|
arec.put("CODMAG",_mask->get(F_AMAG));
|
|
_cur->setfilter(cfilter);
|
|
_cur->setregion(darec,arec);
|
|
}
|
|
|
|
// ORDINAMENTO
|
|
void TStampa_inventario::setprint_perarticoli()
|
|
{
|
|
TRectype darec(LF_ANAMAG),arec(LF_ANAMAG);
|
|
TString cfilter,filter,joinexp;
|
|
TString sortexp("ANNOES|CODART|LIVELLO|CODMAG");
|
|
|
|
char subordine=*_mask->get(F_ORDINEART);
|
|
_cur = _form->cursor();
|
|
/* if (*_mask->get(F_FILTRO)=='N')
|
|
filter << "(GIAC!=0)&&" ;
|
|
if (*_mask->get(F_FILTRO)=='+')
|
|
filter << "(GIAC>0)&&" ;*/
|
|
if (*_mask->get(F_DAMAG))
|
|
filter << "(CODMAG[1,3]>=" <<'"' << _mask->get(F_DAMAG)<< "\")&&" ;
|
|
if (*_mask->get(F_AMAG))
|
|
filter << "(CODMAG[1,3]<=" <<'"' << _mask->get(F_AMAG)<< "\")&&" ;
|
|
if (filter.not_empty())
|
|
filter.cut(filter.len()-2);
|
|
switch (subordine)
|
|
{
|
|
case 'C':
|
|
_cur->setkey(1);
|
|
darec.put("CODART",_mask->get(F_DAART));
|
|
arec.put("CODART",_mask->get(F_AART));
|
|
_form->find_field('B',odd_page,"H_CATMER").hide();
|
|
_form->find_field('B',odd_page,"TOT_CATMER").hide();
|
|
_form->setcatmer(FALSE);
|
|
break;
|
|
case 'D':
|
|
_cur->setkey(2);
|
|
darec.put("DESCR",_mask->get(F_DADES));
|
|
arec.put("DESCR",_mask->get(F_ADES));
|
|
_form->find_field('B',odd_page,"H_CATMER").disable();
|
|
_form->find_field('B',odd_page,"TOT_CATMER").hide();
|
|
_form->setcatmer(FALSE);
|
|
break;
|
|
case 'M':
|
|
_cur->setkey(3);
|
|
darec.put("GRMERC",_mask->get(F_DACATMER));
|
|
darec.put("CODART",_mask->get(F_DAART));
|
|
arec.put("GRMERC",_mask->get(F_ACATMER));
|
|
arec.put("CODART",_mask->get(F_AART));
|
|
_form->find_field('B',odd_page,"H_CATMER").show();
|
|
_form->find_field('B',odd_page,"TOT_CATMER").show();
|
|
_form->setcatmer(TRUE);
|
|
break;
|
|
}
|
|
_form->setdett_perart(
|
|
_mask->get_int(F_FROMLIVELLOART),
|
|
_mask->get_int(F_TOLIVELLOART),
|
|
_mask->get_int(F_FROMLIVELLOGIAC),
|
|
_mask->get_int(F_TOLIVELLOGIAC),
|
|
_mask->get_bool(F_TOTALIMAGAZZINI),
|
|
_mask->get_bool(F_TOTALIDEPOSITI));
|
|
/* if (*_mask->get(F_FILTRO)=='N')
|
|
_form->find_field('B',odd_page,"TOT_DEPOSITO").setcondition("GIAC!=0");
|
|
if (*_mask->get(F_FILTRO)=='+')
|
|
_form->find_field('B',odd_page,"TOT_DEPOSITO").setcondition("GIAC>0");
|
|
*/
|
|
|
|
|
|
joinexp << "ANNOES==" << _mask->get(F_ANNOES) << "|CODART==CODART";
|
|
|
|
TSortedfile *mag;
|
|
mag= new TSortedfile(LF_MAG,NULL,sortexp,filter,1);
|
|
_cur->relation()->replace(mag,1,joinexp);
|
|
_cur->setfilter(cfilter);
|
|
_cur->setregion(darec,arec);
|
|
}
|
|
|
|
|
|
bool TStampa_inventario::set_print(int i)
|
|
{
|
|
while (TRUE) {
|
|
if (_mask->run() != K_ENTER)
|
|
return FALSE;
|
|
|
|
if (*_mask->get(F_ORDINE)=='A')
|
|
{
|
|
_form = new TForm_inventario("mg4200a", "");
|
|
setprint_perarticoli();
|
|
} else {
|
|
_form = new TForm_inventario("mg4200b", "");
|
|
setprint_permagazzini();
|
|
}
|
|
_form->add_colval(_mask->get_int(F_VAL1));
|
|
_form->add_colval(_mask->get_int(F_VAL2));
|
|
_form->add_colval(_mask->get_int(F_VAL3));
|
|
_form->add_colval(_mask->get_int(F_VAL4));
|
|
_form->add_colval(_mask->get_int(F_VAL5));
|
|
_form->add_colval(_mask->get_int(F_VAL6));
|
|
_form->set_parametri(_mask->get(F_CATVENLISTINO),
|
|
_mask->get(F_CODLISTINO),
|
|
*_mask->get(F_REALE_GIAC)=='R',
|
|
*_mask->get(F_FIN_COMP)=='C'
|
|
);
|
|
|
|
_form->print();
|
|
delete _form;
|
|
} // while true
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
int mg4200(int argc, char* argv[])
|
|
{
|
|
TStampa_inventario a;
|
|
a.run(argc,argv,"Stampa inventario");
|
|
return 0;
|
|
}
|