campo-sirio/mg/mg4200.cpp
guy 9abac455f4 cosmesi da TString80 a TCodice_articolo
git-svn-id: svn://10.65.10.50/branches/R_10_00@23043 c028cbd2-c16b-5b4b-a496-9718f37d4682
2015-02-24 08:37:50 +00:00

1199 lines
38 KiB
C++
Executable File
Raw Blame History

#include <applicat.h>
#include <progind.h>
#include "../cg/cglib01.h"
#include "../ve/veconf.h"
#include "mglib.h"
#include "mg4200.h"
#include "mg4200a.h"
#include "mg4frm.h"
static const char* and_connect(const TString & expr)
{
return expr.full() ? "&&" : "";
}
static const char* or_connect(TString & expr)
{
return expr.full() ? "||" : "";
}
TCursor* TForm_inventario::cursor() const
{
if (_use_alternate_cursor) // Se e' settata la stampa per ragg. fisc ritorna il cursore appropriato
return _sortcur;
return TForm_stampemg::cursor();
}
bool TForm_inventario::validate(TForm_item &cf, TToken_string &s)
{
const TString80 code = s.get(0); // prende il primo parametro, il codice del messaggio
if (code=="_USER")
{
const TRectype& magrec=relation()->curr(LF_MAG);
const TFixed_string subcode=s.get();
if (subcode=="GIAC")
{
real v=curr_art().giacenza_corretta(magrec, false,_valcomp);
cf.set(v.string());
return true;
}
else
if (subcode=="VAL1")
return valorizzazione(cf,_valorizz_scelte[0]);
else
if (subcode=="VAL2" && _colonne >=2)
return valorizzazione(cf,_valorizz_scelte[1]);
else
if (subcode=="VAL3" && _colonne >=3)
return valorizzazione(cf,_valorizz_scelte[2]);
else
if (subcode=="VAL4" && _colonne >=4)
return valorizzazione(cf,_valorizz_scelte[3]);
else
if (subcode=="VAL5"&& _colonne >=5)
return valorizzazione(cf,_valorizz_scelte[4]);
else
if (subcode=="VAL6" && _colonne >=6)
return valorizzazione(cf,_valorizz_scelte[5]);
else
if (subcode == "LINEATOTALI")
{
const TString l(29*_colonne+12,'_');
cf.set(l);
return true;
}
else
if (subcode == "DESCR")
{
if (_user1.blank())
_user1 = ANAMAG_DESCR;
const TString& desc = relation()->curr(LF_ANAMAG).get(_user1);
cf.set(desc);
return true;
}
}
else
if (code == "_ANNO")
{
TString4 anno; anno << _annoes;
cf.set(anno);
return true;
}
return TForm_stampemg::validate(cf, s);
}
TArticolo_giacenza_loadable &TForm_inventario::curr_art()
{
const TString80 newcode(relation()->curr(LF_ANAMAG).get(ANAMAG_CODART));
if (_curr_art==NULL || newcode != _curr_art->codice())
{
if (_curr_art) delete _curr_art;
_curr_art = new TArticolo_giacenza_loadable(newcode);
if (_alladata)
_curr_art->load((TIsamtempfile&)(relation()->lfile(LF_MAG)));
}
return *_curr_art;
}
void TForm_inventario::add_colval(int tipo)
{
TTipo_valorizz t = (TTipo_valorizz )tipo;
if (t>=valorizz_ultcos && tipo <= valorizz_LIFOr)
{
// Accende le colonne totali del Footer Last...
find_field('F', last_page, FF_BASEFL + (_colonne * 2)).show();
if (t < valorizz_FIFOa)
find_field('F', last_page, FF_BASEFL + (_colonne * 2) +1).show();
_valorizz_scelte[_colonne++] = t;
TString8 col; col << _colonne;
find_field('B',odd_page,FF_ENABLECOLS).set(col);
// Accende le colonne per l'intestazione
const int base_col = 2*(_colonne-1);
find_field('B',odd_page,FF_COL1HEADER + base_col).show(); // Colonna valore
find_field('B',odd_page,FF_COL1HEADER + base_col+1).show(t < valorizz_FIFOa); // Colonna valore unitario (abilitata solo se ! FIFO/LIFO)
// Nasconde la colonna del valore unitario se il tipo di valorizzazzione e' FIFO/LIFO
if (t >= valorizz_FIFOa && t <= valorizz_LIFOr)
// Abilita i campi necessari per "nascondere" le colonne del prezzo unitario in tutto il form.
find_field('B', odd_page, FF_DISABLEUNIT1 + _colonne - 1).enable();
}
}
bool TForm_inventario::valorizzazione(TForm_item &cf, TTipo_valorizz t)
{
const TRectype& magrec = relation()->curr(LF_MAG);
const TString4 annoes = magrec.get(MAG_ANNOES);
const real giac_corretta = curr_art().giacenza_corretta(magrec, false,_valcomp);
real p;
switch (t)
{
case valorizz_ultcos:
{
const TPrice prezzo(curr_art().ultimo_costo(annoes));
p = prezzo.get_num();
}
break;
case valorizz_mediacos:
{
const TPrice prezzo(curr_art().media_costi(annoes));
p = prezzo.get_num();
}
break;
case valorizz_przlist:
{
const TPrice prezzo(CENTO / (CENTO + curr_art().get_real(ANAMAG_PERCRIC)) * curr_art().prezzo_listino(annoes,_catven,_codlist));
p = prezzo.get_num();
}
break;
case valorizz_coststd:
{
const TPrice prezzo(curr_art().costo_standard(annoes));
p = prezzo.get_num();
}
break;
case valorizz_costmediopond:
{
const TString4 codmag = magrec.get(MAG_CODMAG).left(3);
const TString16 livello(magrec.get(MAG_LIVELLO));
const TPrice prezzo(curr_art().costo_mediopond(annoes,codmag,livello));
p = prezzo.get_num();
}
break;
case valorizz_costmedio:
{
const TString4 codmag = magrec.get(MAG_CODMAG).left(3);
const TString16 livello(magrec.get(MAG_LIVELLO));
const TPrice prezzo(curr_art().costo_medio(annoes,codmag,livello));
p = prezzo.get_num();
}
break;
case valorizz_LIFO:
{
const TString4 codmag = magrec.get(MAG_CODMAG).left(3);
const TString16 livello(magrec.get(MAG_LIVELLO));
p = curr_art().LIFO(annoes,codmag,livello, false,_valcomp);
}
break;
case valorizz_FIFO:
{
const TString4 codmag = magrec.get(MAG_CODMAG).left(3);
const TString16 livello(magrec.get(MAG_LIVELLO));
p = curr_art().FIFO(annoes,codmag,livello, false,_valcomp);
}
break;
case valorizz_LIFOa:
{
const TString4 codmag = magrec.get(MAG_CODMAG).left(3);
const TString16 livello(magrec.get(MAG_LIVELLO));
p = curr_art().LIFO_annuale(annoes,codmag,livello, false, _valcomp);
}
break;
case valorizz_FIFOa:
{
const TString4 codmag = magrec.get(MAG_CODMAG).left(3);
const TString16 livello(magrec.get(MAG_LIVELLO));
p = curr_art().FIFO_annuale(annoes,codmag,livello, false, _valcomp);
}
break;
default:
break;
}
const TCurrency valore(real(p * giac_corretta));
cf.set(valore.get_num().string());
return true;
}
bool TForm_inventario::genera_intestazione_supplementare(pagetype p, short y)
{
TPrint_section* body = exist('B', p);
if (body == NULL || !body->columnwise())
return false;
TPrint_section* header = exist('H', p);
if (header == NULL)
return false;
TForm_string* s;
TString des;
for (int j = 0; j < _colonne; j++)
{
TForm_item& fi = body->find_field(FF_COL1HEADER+j*2);
des = nome_valorizz(_valorizz_scelte[j]);
int w = fi.width();
if (_valorizz_scelte[j] < valorizz_FIFOa)
w *= 2;
des.center_just(w);
s = new TForm_string(header);
s->id() = -1;
s->set_x(fi.x());
s->y() = y;
s->set_prompt(des);
s->temp() = true;
header->add_field(s);
}
return true;
}
void TForm_inventario::set_parametri(const char * codcatv,const char * codlist,bool giaceff, bool valcomp, bool alladata, int annoes)
{
_catven = codcatv;
_codlist = codlist;
_giaceff = giaceff;
_valcomp = valcomp;
_alladata = alladata;
_annoes = annoes;
}
TForm_inventario::TForm_inventario(const char *name) :
TForm_stampemg(name, ""), _curr_art(NULL), _sortcur(NULL)
{
_sortcur = new TSorted_cursor(relation(),"RAGGFIS|CODART");
_use_alternate_cursor = false;
_colonne = 0;
}
TForm_inventario::~TForm_inventario()
{
if (_curr_art != NULL)
delete _curr_art;
if (_sortcur != NULL)
delete _sortcur;
}
class TStampainv_mask: public TStampemg_mask
{
protected:
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
static bool handle_codlist(TMask_field &fld, KEY k); // handler
public:
TStampainv_mask();
virtual ~TStampainv_mask() {}
};
TStampainv_mask::TStampainv_mask()
:TStampemg_mask("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();
}
if (prassid.get_bool("CHK_USER", "ve", 1))
{
const TString& user1 = prassid.get("PROMPT_USER", "ve", 1);
field(F_DAUSR).set_prompt(user1);
show(F_DAUSR); show(F_AUSR);
}
set_handler(F_TOLIVELLOART, handle_liv);
set_handler(F_TOLIVELLOGIAC, handle_liv);
set_handler(F_ORDINE, handle_ragg);
set_handler(F_DETTAGLIOMAG, handle_ragg);
set_handler(F_SUBORDINE,handle_subord);
set_handler(F_CODLISTINO, handle_codlist);
}
bool TStampainv_mask::handle_subord(TMask_field &fld, KEY k)
{
if (k == K_SPACE)
{
const TMask & m = fld.mask();
TOperable_field & fraggcod = (TOperable_field &) m.field(F_RAGGCODICE);
TOperable_field & fragggiac = (TOperable_field &) m.field(F_RAGGLIVGIAC);
const char subord = fld.get()[0];
const char ordine = m.get(F_ORDINE)[0];
switch (subord)
{
case 'C':
case 'P':
if (ordine == 'A')
fraggcod.enable();
else
{
if (!m.get_bool(F_DETTAGLIODEP))
{
fraggcod.reset();
fraggcod.disable();
fragggiac.reset();
fragggiac.disable();
fraggcod.do_message(0);
fragggiac.do_message(0);
}
}
break;
case 'M':
case 'S':
case 'R':
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)
{
const TMask & m = fld.mask();
TOperable_field & ftotmag = (TOperable_field &) m.field(F_TOTALIMAGAZZINI);
const char ordine = m.get(F_ORDINE)[0];
if (ordine == 'A')
{
if (m.get_int(F_TOLIVELLOART) > 0 || m.get_int(F_TOLIVELLOGIAC) > 0)
{
// 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)
{
const TMask & m = fld.mask();
TOperable_field & ftotmag = (TOperable_field &) m.field(F_TOTALIMAGAZZINI);
TOperable_field & fraggcod = (TOperable_field &) m.field(F_RAGGCODICE);
TOperable_field & fragggiac = (TOperable_field &) m.field(F_RAGGLIVGIAC);
const char ordine = m.get(F_ORDINE)[0];
if (ordine == 'M')
{
ftotmag.enable();
if (!m.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;
}
bool TStampainv_mask::handle_codlist(TMask_field &fld, KEY k)
{
if (k == K_ENTER)
{
if (fld.empty())
{
TMask & m=fld.mask();
if (m.get_int(F_VAL1)-1==valorizz_przlist ||
m.get_int(F_VAL2)-1==valorizz_przlist ||
m.get_int(F_VAL3)-1==valorizz_przlist ||
m.get_int(F_VAL4)-1==valorizz_przlist ||
m.get_int(F_VAL5)-1==valorizz_przlist ||
m.get_int(F_VAL6)-1==valorizz_przlist)
return fld.error_box(TR("Occorre specificare il listino per la valorizzazione"));
}
}
return true;
}
// STAMPA anagrafiche
void TStampa_inventario ::on_firm_change()
{
_mask->enable_livellicodice();
}
bool TStampa_inventario::create()
{
_mask = new TStampainv_mask();
return TSkeleton_application::create();
}
bool TStampa_inventario::destroy()
{
delete _mask;
return true;
}
TIsamtempfile * TStampa_inventario::crea_tempmag(const bool valcomp)
{
TMask & m = mask();
TIsamtempfile *temp_mag = new TIsamtempfile(LF_MAG, "tmpmag");
TRectype darec(LF_ANAMAG), arec(LF_ANAMAG);
darec.put(ANAMAG_CODART, m.get(F_DAART));
arec.put(ANAMAG_CODART, m.get(F_AART));
TRelation ana_rel(LF_ANAMAG);
TCursor ana_cur(&ana_rel, "", 1, &darec, &arec);
const TRecnotype items = ana_cur.items();
ana_cur.freeze();
ana_rel.lfile().set_curr(new TArticolo_giacenza);
const TArticolo_giacenza & art_giac = (TArticolo_giacenza & ) ana_cur.curr();
const TString4 annoes(m.get(F_ANNOES));
TString msg;
msg << "Creazione giacenze temporanee anno " << annoes;
TProgind pi(items, msg, false, true);
for (ana_cur = 0; temp_mag->good() && ana_cur.pos() < items; ++ana_cur)
{
TRecord_array& mag = art_giac.mag(annoes);
pi.addstatus(1);
// Scrive i records sul file temporaneo
for (int i = mag.last_row(); temp_mag->good() && i > 0; i = mag.pred_row(i))
{
TRectype& magrec = (TRectype&)mag.row(i);
const real v = art_giac.giacenza_corretta(magrec, true, valcomp);
magrec.put(MAG_GIAC, v);
magrec.write(*temp_mag);
}
}
if (temp_mag->good())
return temp_mag;
else
{
error_box(FR("Errore %d in creazione file temporaneo per saldi di magazzino"), temp_mag->status());
delete temp_mag;
return NULL;
}
}
TIsamtempfile* TStampa_inventario::calcola_giacenze(const bool giaceff, const bool valcomp, const TDate & al, const char subordine)
{
//Scorre l'anagrafica di magazzino e calcola per ognuno la giacenza alla data indicata
//Memorizzando i records in un file temporaneo che avr<76> lo stesso tracciato di LF_MAG
TIsamtempfile* temp_mag = new TIsamtempfile(LF_MAG, "tmpmag");
TRectype darec(LF_ANAMAG), arec(LF_ANAMAG);
TMask& m = mask();
int ordine = 1; // aggiunto da cristina (far vedere a guy) insieme al parametro subordine
int tilde = 0x2; // aggiunto da guy (far vedere a cristina)
if (subordine == 'C')
{
darec.put(ANAMAG_CODART, m.get(F_DAART));
const TString& aart = m.get(F_AART);
arec.put(ANAMAG_CODART, aart);
if (aart.blank() || cache().get(LF_ANAMAG, aart).empty())
tilde = 0x0;
} else
if (subordine == 'D')
{
darec.put(ANAMAG_DESCR, m.get(F_DADES));
arec.put(ANAMAG_DESCR, m.get(F_ADES));
ordine = 2;
} else
if (subordine == 'M' || subordine == 'S')
{
TString8 m1 = m.get(F_DACATMER); if (m1.not_empty()) m1.left_just(3);
TString8 m2 = m.get(F_ACATMER); if (m2.not_empty()) m2.left_just(3);
ordine = 3;
if (subordine == 'S')
{
m1 << m.get(F_DASCATMER);
m2 << m.get(F_ASCATMER);
}
darec.put(ANAMAG_GRMERC, m1);
arec.put(ANAMAG_GRMERC, m2);
}
TRelation ana_rel(LF_ANAMAG);
TCursor ana_cur(&ana_rel, "", ordine, &darec, &arec, tilde);
const TRecnotype items = ana_cur.items();
ana_cur.freeze();
const TEsercizi_contabili esc;
const int anno = esc.date2esc(al);
TString4 annoes; annoes.format("%04d", anno);
TString msg;
msg << TR("Elaborazione saldi al ") << al << " ...";
TProgind pi(items, msg, true, true);
for (ana_cur = 0L; temp_mag->good() && ana_cur.pos() < items; ++ana_cur)
{
if (!pi.addstatus(1))
break;
TArticolo_giacenza_data art_giac(ana_cur.curr());
art_giac.al(al); // Calcola la giacenza alla data per questo articolo
// Scrive i records sul file temporaneo
TRecord_array& mag = art_giac.mag(annoes);
for (int i = mag.last_row(); temp_mag->good() && i > 0; i = mag.pred_row(i))
{
TRectype& magrec = (TRectype&)mag.row(i);
if (giaceff)
{
const real v = art_giac.giacenza_corretta(magrec, true, valcomp);
magrec.put(MAG_GIAC, v);
}
magrec.write(*temp_mag);
}
}
// Se il file <20> ok lo sostituisce all'interno della relazione del form
if (temp_mag->good())
return temp_mag;
error_box(FR("Errore %d in creazione file temporaneo per saldi di magazzino alla data indicata."), temp_mag->status());
delete temp_mag;
return NULL;
}
void TStampa_inventario::setprint_permagazzini(const char subordine, const bool alladata, const bool giaceff, bool valcomp, const TDate & al)
{
TMask & m = mask();
const bool totdep = m.get_bool(F_TOTALIDEPOSITI);
TRectype darec(LF_MAG),arec(LF_MAG);
TString cfilter, espr1, espr2;
TSorted_cursor & cur = (TSorted_cursor &) * _form->cursor();
const char filtro = m.get(F_FILTRO)[0];
// setta il filtro sul cursore
switch (filtro)
{
case '0': cfilter = "(STR(GIAC!=\"0\"))"; break;
case 'N': cfilter = "(STR(GIAC<\"0\"))"; break; // negativi
case '+': cfilter = "(STR(GIAC>\"0\"))"; break;
default : break;
}
if (m.get(F_DAART).full())
cfilter << and_connect(cfilter) << "(CODART>=" <<'"' << m.get(F_DAART)<< "\")" ;
if (m.get(F_AART).full())
cfilter << and_connect(cfilter) << "(CODART<=" << '"' << m.get(F_AART)<< "\")" ;
if (!totdep)
_form->find_field('B',odd_page,"GRUPPI_DEPOSITO").setcondition("CODMAG[1,3]",_strexpr);
else
_form->find_field('B',odd_page,"GRUPPI_DEPOSITO").setcondition("CODMAG[1,5]",_strexpr);
if (!m.field(F_FORNITORE).empty())
cfilter << and_connect(cfilter) << "(47->CODFORN==\"" << m.get(F_FORNITORE) << "\")" ;
if (!m.field(F_DASTAGIONE).empty() || !m.field(F_ASTAGIONE).empty())
cfilter << and_connect(cfilter) << "(BETWEEN(47->STAGIONE,\"" << m.get(F_DASTAGIONE) << "\",\"" << m.get(F_ASTAGIONE) <<"\"))" ;
switch (subordine)
{
case 'C':
_form->find_field('B',odd_page,"H_CATMER").hide();
_form->find_field('B',odd_page,"TOT_CATMER").hide();
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
if (!totdep)
espr1 = "ANNOES|CODMAG[1,3]|CODART|LIVELLO|CODMAG[4,5]";
else
espr1 = "ANNOES|CODMAG|CODART|LIVELLO";
//_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODART",_strexpr);
//_form->set_ordering(mg_normale);
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODMAG+CODART",_strexpr);
_form->find_field('B',odd_page,"GRUPPI_CATMER").setcondition("CODMAG+CODART",_strexpr);
break;
case 'D':
_form->find_field('B',odd_page,"H_CATMER").hide();
_form->find_field('B',odd_page,"TOT_CATMER").hide();
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
if (!totdep)
espr1 = "ANNOES|CODMAG[1,3]|UPPER(47->DESCR)|LIVELLO|CODMAG[4,5]";
else
espr1 = "ANNOES|CODMAG|UPPER(47->DESCR)|LIVELLO";
//_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODART",_strexpr);
//_form->set_ordering(mg_normale);
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODMAG+CODART",_strexpr);
_form->find_field('B',odd_page,"GRUPPI_CATMER").setcondition("CODMAG+CODART",_strexpr);
if (m.get(F_DADES).full())
cfilter << and_connect(cfilter) << "(UPPER(47->DESCR)>=\"" << m.get(F_DADES) << "\")";
if (m.get(F_ADES).full())
cfilter << and_connect(cfilter) << "(UPPER(47->DESCR)<=\"" << m.get(F_ADES) << "~\")";
break;
case 'S':
case 'M':
{
TString16 m1,m2;
m1 = m.get(F_DACATMER); if (m1.not_empty()) m1.left_just(3);
m2 = m.get(F_ACATMER); if (m2.not_empty()) m2.left_just(3);
_form->find_field('B',odd_page,"H_CATMER").show();
_form->find_field('B',odd_page,"TOT_CATMER").show();
int index_grmerc = 3;
if (subordine == 'S')
index_grmerc = 5;
if (!totdep)
espr1.format("ANNOES|CODMAG[1,3]|%d->GRMERC[1,%d]|CODART|LIVELLO|CODMAG[4,5]", LF_ANAMAG, index_grmerc);
else
espr1.format("ANNOES|CODMAG|%d->GRMERC[1,%d]|CODART|LIVELLO", LF_ANAMAG, index_grmerc);
_form->set_ordering(mg_cat_merc);
espr2.format("CODMAG[1,3]+CODMAG[1,5]+%d->GRMERC[1,3]", LF_ANAMAG);
// espr2.format("%d->GRMERC[1,3]", LF_ANAMAG);
_form->find_field('B',odd_page,"GRUPPI_CATMER").setcondition(espr2,_strexpr);
TString16 fmerc;
if (subordine == 'S')
{
fmerc = "GRMERC";
_form->find_field('B',odd_page,"H_SCATMER").show();
_form->find_field('B',odd_page,"TOT_SCATMER").show();
m1 << m.get(F_DASCATMER);
m2 << m.get(F_ASCATMER);
}
else
{
fmerc = "GRMERC[1,3]";
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
}
if (m1.not_empty())
{
espr2.format("(%d->%s >= \"%s\")", LF_ANAMAG, (const char *)fmerc, (const char*)m1);
cfilter << and_connect(cfilter) << espr2;
}
if (m2.not_empty())
{
espr2.format("(%d->%s <= \"%s\")", LF_ANAMAG, (const char *)fmerc, (const char*)m2);
cfilter << and_connect(cfilter) << espr2;
}
espr2.format("CODMAG[1,3]+CODMAG[1,5]+%d->GRMERC", LF_ANAMAG);
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition(espr2,_strexpr);
}
break;
case 'R':
_form->find_field('B',odd_page,"H_CATMER").show();
_form->find_field('B',odd_page,"TOT_CATMER").show();
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
if (!totdep)
espr1.format("ANNOES|CODMAG[1,3]|%d->RAGGFIS|CODART|LIVELLO|CODMAG[4,5]",LF_ANAMAG);
else
espr1.format("ANNOES|CODMAG|%d->RAGGFIS|CODART|LIVELLO|CODMAG[4,5]",LF_ANAMAG);
_form->set_ordering(mg_ragg_fisc);
espr2.format("CODMAG[1,3]+CODMAG[1,5]+%d->RAGGFIS", LF_ANAMAG);
_form->find_field('B',odd_page,"GRUPPI_CATMER").setcondition(espr2,_strexpr);
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition(espr2,_strexpr);
if (m.get(F_DARAGFIS).not_empty())
{
espr2.format("(%d->RAGGFIS>=\"%s\")", LF_ANAMAG, (const char*) m.get(F_DARAGFIS));
cfilter << and_connect(cfilter) << espr2;
}
if (m.get(F_ARAGFIS).not_empty())
{
espr2.format("(%d->RAGGFIS<=\"%s\")", LF_ANAMAG, (const char*) m.get(F_ARAGFIS));
cfilter << and_connect(cfilter) << espr2;
}
break;
default:
break;
}
//m.set_livellicodice();
// abilita/disabilita le sezioni dei totali
_form->setdett_permag(
m.get_bool(F_RAGGCODICE),m.get_int(F_FROMLIVELLOART),m.get_int(F_TOLIVELLOART),
m.get_bool(F_RAGGLIVGIAC),m.get_int(F_FROMLIVELLOGIAC),m.get_int(F_TOLIVELLOGIAC),
true,m.get_bool(F_TOTALIDEPOSITI),m.get_bool(F_DETTAGLIODEP));
TIsamtempfile * temp = NULL;
if (alladata)
temp = calcola_giacenze(giaceff, valcomp, al, subordine);
else
if (giaceff)
temp = crea_tempmag(valcomp);
if (temp != NULL)
_form->relation()->replace(temp);
cur.change_order(espr1);
darec.put("ANNOES",m.get(F_ANNOES));
darec.put("CODMAG",m.get(F_DAMAG));
arec.put("ANNOES",m.get(F_ANNOES));
arec.put("CODMAG",m.get(F_AMAG));
cur.setfilter(cfilter, true);
cur.setregion(darec,arec);
}
// ORDINAMENTO
void TStampa_inventario::setprint_perarticoli(const char subordine, const bool alladata, const bool giaceff, bool valcomp, const TDate & al)
{
TMask & m = mask();
TRectype darec(LF_MAG),arec(LF_MAG);
TString cfilter, espr1, espr2;
TSorted_cursor & cur = (TSorted_cursor &) * _form->cursor();
const char filtro = m.get(F_FILTRO)[0];
// setta il filtro sul cursore
switch (filtro)
{
case '0': cfilter = "(STR(GIAC!=\"0\"))"; break;
case 'N': cfilter = "(STR(GIAC<\"0\"))"; break; // negativi
case '+': cfilter = "(STR(GIAC>\"0\"))"; break;
default : break;
}
if (!m.field(F_FORNITORE).empty())
cfilter << and_connect(cfilter) << "(47->CODFORN==\"" << m.get(F_FORNITORE) << "\")" ;
if (!m.field(F_DASTAGIONE).empty() || !m.field(F_ASTAGIONE).empty())
cfilter << and_connect(cfilter) << "(BETWEEN(47->STAGIONE,\"" << m.get(F_DASTAGIONE) << "\",\"" << m.get(F_ASTAGIONE) <<"\"))" ;
switch (subordine)
{
case 'C':
_form->find_field('B',odd_page,"H_CATMER").hide();
_form->find_field('B',odd_page,"TOT_CATMER").hide();
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
espr1 = "ANNOES|CODART|LIVELLO|CODMAG";
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODART",_strexpr);
_form->set_ordering(mg_normale);
if (m.get(F_DAART).full())
cfilter << and_connect(cfilter) << "(CODART>=\"" << m.get(F_DAART) << "\")";
if (m.get(F_AART).full())
cfilter << and_connect(cfilter) << "(CODART<=\"" << m.get(F_AART) << "\")";
break;
case 'D':
_form->find_field('B',odd_page,"H_CATMER").hide();
_form->find_field('B',odd_page,"TOT_CATMER").hide();
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
espr1.format("ANNOES|UPPER(%d->DESCR)|LIVELLO|CODMAG", LF_ANAMAG);
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODART",_strexpr);
_form->set_ordering(mg_normale);
if (m.get(F_DADES).full())
cfilter << and_connect(cfilter) << "(UPPER(47->DESCR)>=\"" << m.get(F_DADES) << "\")";
if (m.get(F_ADES).full())
cfilter << and_connect(cfilter) << "(UPPER(47->DESCR)<=\"" << m.get(F_ADES) << "~\")";
break;
case 'S':
case 'M':
{
TString16 m1,m2;
m1 = m.get(F_DACATMER);
m2 = m.get(F_ACATMER);
_form->find_field('B',odd_page,"H_CATMER").show();
_form->find_field('B',odd_page,"TOT_CATMER").show();
if (subordine == 'S')
espr1.format("ANNOES|%d->GRMERC|CODART|LIVELLO|CODMAG", LF_ANAMAG);
else
espr1.format("ANNOES|%d->GRMERC[1,3]|CODART|LIVELLO|CODMAG", LF_ANAMAG);
_form->set_ordering(mg_cat_merc);
espr2.format("%d->GRMERC[1,3]", LF_ANAMAG);
_form->find_field('B',odd_page,"GRUPPI_CATMER").setcondition(espr2,_strexpr);
if (m.get(F_DAART).full())
cfilter << and_connect(cfilter) << "(CODART>=\"" << m.get(F_DAART) << "\")";
if (m.get(F_AART).full())
cfilter << and_connect(cfilter) << "(CODART<=\"" << m.get(F_AART) << "\")";
if (subordine == 'S')
{
_form->find_field('B',odd_page,"H_SCATMER").show();
_form->find_field('B',odd_page,"TOT_SCATMER").show();
m1.left_just(3) << m.get(F_DASCATMER);
m2.left_just(3) << m.get(F_ASCATMER);
if (m1.full())
{
espr2.format("(%d->GRMERC>=\"%s\")", LF_ANAMAG, (const char*)m1);
cfilter << and_connect(cfilter) << espr2;
}
if (m2.full())
{
espr2.format("(%d->GRMERC<=\"%s\")", LF_ANAMAG, (const char*)m2);
cfilter << and_connect(cfilter) << espr2;
}
espr2.format("%d->GRMERC", LF_ANAMAG);
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition(espr2,_strexpr);
}
else
{
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
if (m1.full())
{
espr2.format("(TRIM(%d->GRMERC[1,3])>=\"%s\")", LF_ANAMAG, (const char*)m1);
cfilter << and_connect(cfilter) << espr2;
}
if (m2.full())
{
espr2.format("(TRIM(%d->GRMERC[1,3])<=\"%s\")", LF_ANAMAG, (const char*)m2);
cfilter << and_connect(cfilter) << espr2;
}
}
}
break;
case 'R':
_form->find_field('B',odd_page,"H_CATMER").show();
_form->find_field('B',odd_page,"TOT_CATMER").show();
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
espr1.format("ANNOES|%d->RAGGFIS|CODART|LIVELLO|CODMAG",LF_ANAMAG);
_form->set_ordering(mg_ragg_fisc);
espr2.format("%d->RAGGFIS", LF_ANAMAG);
_form->find_field('B',odd_page,"GRUPPI_CATMER").setcondition(espr2,_strexpr);
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition(espr2,_strexpr);
if (m.get(F_DARAGFIS).full())
{
espr2.format("(%d->RAGGFIS>=\"%s\")", LF_ANAMAG, (const char*) m.get(F_DARAGFIS));
cfilter << and_connect(cfilter) << espr2;
}
if (m.get(F_ARAGFIS).full())
{
espr2.format("(%d->RAGGFIS<=\"%s\")", LF_ANAMAG, (const char*) m.get(F_ARAGFIS));
cfilter << and_connect(cfilter) << espr2;
}
break;
case 'P':
_form->set_description_field(ANAMAG_USER1);
_form->find_field('B',odd_page,"H_CATMER").hide();
_form->find_field('B',odd_page,"TOT_CATMER").hide();
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
espr1.format("ANNOES|%d->USER1|LIVELLO|CODMAG", LF_ANAMAG);
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODART",_strexpr);
_form->set_ordering(mg_normale);
if (m.get(F_DAUSR).full())
cfilter << and_connect(cfilter) << "(47->USER1>=\"" << m.get(F_DAUSR) << "\")";
if (m.get(F_AUSR).full())
cfilter << and_connect(cfilter) << "(47->USER1<=\"" << m.get(F_AUSR) << "~\")";
break;
default: break;
}
_form->setdett_perart(
m.get_bool(F_RAGGCODICE),m.get_int(F_FROMLIVELLOART),m.get_int(F_TOLIVELLOART),
m.get_bool(F_RAGGLIVGIAC),m.get_int(F_FROMLIVELLOGIAC),m.get_int(F_TOLIVELLOGIAC),
m.get_bool(F_TOTALIMAGAZZINI),m.get_bool(F_DETTAGLIOMAG));
TIsamtempfile * temp = NULL;
if (alladata)
temp = calcola_giacenze(giaceff, valcomp, al, subordine);
else
if (giaceff)
temp = crea_tempmag(valcomp);
if (temp != NULL)
_form->relation()->replace(temp);
cur.change_order(espr1);
darec.put("ANNOES",m.get(F_ANNOES));
darec.put("CODMAG",m.get(F_DAMAG));
arec.put("ANNOES",m.get(F_ANNOES));
arec.put("CODMAG", m.get(F_AMAG));
cur.setfilter(cfilter, subordine != 'C');
cur.setregion(darec,arec);
}
void TStampa_inventario::setprint_perarticoli_all(const char subordine, bool alladata, bool giaceff, bool valcomp, const TDate & al)
{
TMask & m = mask();
TRectype darec(LF_ANAMAG),arec(LF_ANAMAG);
TString cfilter,filter,joinexp;
if (m.get(F_DAMAG).full())
filter << and_connect(filter) << "(CODMAG[1,3]>=" <<'"' << m.get(F_DAMAG)<< "\")" ;
if (m.get(F_AMAG).full())
filter << and_connect(filter) << "(CODMAG[1,3]<=" <<'"' << m.get(F_AMAG)<< "\")" ;
if (!m.field(F_FORNITORE).empty())
cfilter << and_connect(cfilter) << "(CODFORN==\"" << m.get(F_FORNITORE) << "\")" ;
if (!m.field(F_DASTAGIONE).empty() || !m.field(F_ASTAGIONE).empty())
cfilter << and_connect(cfilter) << "(BETWEEN(STAGIONE,\"" << m.get(F_DASTAGIONE) << "\",\"" << m.get(F_ASTAGIONE) <<"\"))" ;
//m.set_livellicodice();
TString sortexp;
switch (subordine)
{
case 'C':
_form->cursor()->setkey(1); sortexp = ANAMAG_CODART;
darec.put("CODART",m.get(F_DAART));
arec.put("CODART",m.get(F_AART));
_form->find_field('B',odd_page,"H_CATMER").hide();
_form->find_field('B',odd_page,"TOT_CATMER").hide();
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODART",_strexpr);
_form->set_ordering(mg_normale);
break;
case 'D':
_form->cursor()->setkey(2); sortexp = ANAMAG_DESCR;
darec.put("DESCR",m.get(F_DADES));
arec.put("DESCR",m.get(F_ADES));
_form->find_field('B',odd_page,"H_CATMER").disable();
_form->find_field('B',odd_page,"TOT_CATMER").hide();
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODART",_strexpr);
_form->set_ordering(mg_normale);
break;
case 'S':
case 'M':
{
TString16 m1,m2; sortexp = ANAMAG_GRMERC;
m1 = m.get(F_DACATMER);
m2 = m.get(F_ACATMER);
if (subordine == 'S')
{
m1.left_just(3) << m.get(F_DASCATMER);
m2.left_just(3) << m.get(F_ASCATMER);
}
// Siccome GRMERC e' il primo campo della chiave, se e' settato l'articolo di fine intervallo
// ed esso non e' vuoto, mentre la categoria merc. lo e'... la setregion() del cursore non ha effetti,
// Quindi se non viene indicata alcuna categoria merc. di fine interv, va preimpostata
// Alla ultima stringa possibile
if (m2.empty() && m.get(F_AART).not_empty())
m2.fill('\254',subordine == 'S' ? 5 : 3);
_form->cursor()->setkey(3);
if (m1.full())
darec.put("GRMERC", m1);
if (m.get(F_DAART).full())
darec.put("CODART",m.get(F_DAART));
if (m2.full())
arec.put("GRMERC", m2);
if (m.get(F_AART).full())
arec.put("CODART", m.get(F_AART));
_form->find_field('B',odd_page,"H_CATMER").show();
_form->find_field('B',odd_page,"TOT_CATMER").show();
_form->set_ordering(mg_cat_merc);
if (subordine == 'S')
{
_form->find_field('B',odd_page,"H_SCATMER").show();
_form->find_field('B',odd_page,"TOT_SCATMER").show();
TString16 espr ; espr.format("%d->GRMERC", LF_ANAMAG);
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition(espr, _strexpr);
}
else
{
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODART", _strexpr);
}
}
break;
case 'R':
{
_form->set_ordering(mg_ragg_fisc);// Setta la subsection in modo da raggruppare per RAGGFIS
_form->use_alternate_cursor();
_form->cursor()->setkey(1); sortexp = ANAMAG_RAGGFIS;
_form->find_field('B',odd_page,"H_CATMER").show();
_form->find_field('B',odd_page,"TOT_CATMER").show();
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("RAGGFIS",_strexpr);
if (m.get(F_DARAGFIS).full())
cfilter.format("(RAGGFIS>=\"%s\")",(const char*)m.get(F_DARAGFIS));
if (cfilter.not_empty() && m.get(F_ARAGFIS).full())
cfilter << and_connect(cfilter) << "(RAGGFIS<=\"" << m.get(F_ARAGFIS) << "\")";
_form->cursor()->setfilter(cfilter);
}
break;
case 'P':
_form->cursor()->setkey(1); sortexp = ANAMAG_USER1;
_form->set_description_field(ANAMAG_USER1);
_form->find_field('B',odd_page,"H_CATMER").hide();
_form->find_field('B',odd_page,"TOT_CATMER").hide();
_form->find_field('B',odd_page,"H_SCATMER").hide();
_form->find_field('B',odd_page,"TOT_SCATMER").hide();
_form->find_field('B',odd_page,"GRUPPI_SCATMER").setcondition("CODART",_strexpr);
_form->set_ordering(mg_normale);
if (m.get(F_DAUSR).full())
cfilter << and_connect(cfilter) << "(USER1>=\"" << m.get(F_DAUSR) << "\")";
if (m.get(F_AUSR).full())
cfilter << and_connect(cfilter) << "(USER1<=\"" << m.get(F_AUSR) << "~\")";
break;
default:
break;
}
_form->setdett_perart(
m.get_bool(F_RAGGCODICE),m.get_int(F_FROMLIVELLOART),m.get_int(F_TOLIVELLOART),
m.get_bool(F_RAGGLIVGIAC),m.get_int(F_FROMLIVELLOGIAC),m.get_int(F_TOLIVELLOGIAC),
m.get_bool(F_TOTALIMAGAZZINI),m.get_bool(F_DETTAGLIOMAG));
joinexp << "ANNOES==\"" << m.get(F_ANNOES) << "\"|CODART==CODART";
TSortedfile *mag;
TRelation *rel = NULL;
TIsamtempfile* temp = NULL;
if (alladata)
{
temp = calcola_giacenze(giaceff, valcomp, al, subordine);
if (temp != NULL)
rel = new TRelation(temp);
}
else
{
if (giaceff)
{
temp = crea_tempmag(valcomp);
if (temp != NULL)
rel = new TRelation(temp);
}
}
// !?!?!! ATTENZIONE : Modifica temporanea
mag = new TSortedfile(LF_MAG, rel, "ANNOES|CODART|LIVELLO|CODMAG", "", 1);
// il filtro viene qui settato DOPO la creazione del Sortedfile a causa di una bug
// sulla libreria nei TSorted_file / TCursor
mag->cursor().setfilter(filter);
// FINE MODIFICA ; rimettere il filtro nel costruttore quando il bug sar<61> risolto
TSorted_cursor & cur = (TSorted_cursor &) * _form->cursor();
cur.relation()->replace(mag,1,joinexp);
cur.setfilter(cfilter);
cur.setregion(darec,arec,0x2);
cur.change_order(sortexp);
}
void TStampa_inventario::main_loop()
{
TStampemg_mask & m = mask();
while (m.run() == K_ENTER)
{
if (m.magazz_ini().gestmag(true))
{
if (m.get(F_DAMAG).blank() && m.get(F_AMAG).blank())
{
bool empty = false;
if (m.get(F_SUBORDINE) == "D")
empty = m.get(F_DADES).blank() && m.get(F_ADES).blank();
else
empty = m.get(F_DAART).blank() && m.get(F_AART).blank();
if (empty && !yesno_box(TR("Sono stati selezionati tutti gli articoli. Confermare la stampa?")))
continue;
}
const bool alla_data = m.get_bool(F_ALLADATA);
const bool giac_reale = m.get(F_REALE_GIAC)[0] == 'R';
const bool ordine_articoli = m.get(F_ORDINE)[0] == 'A';
const bool val_componenti = m.get(F_FIN_COMP)[0] == 'C';
const TDate data_limite(m.get_date(F_DATALIM));
const char subordine = m.get(F_SUBORDINE)[0];
if (ordine_articoli)
{
const bool tutti = m.get(F_FILTRO)[0] == 'T'; // tutti gli articoli
if (tutti)
{
_form = new TForm_inventario("mg4200aa");
setprint_perarticoli_all(subordine, alla_data, giac_reale, val_componenti, data_limite);
}
else
{
_form = new TForm_inventario("mg4200a");
setprint_perarticoli(subordine, alla_data, giac_reale, val_componenti, data_limite);
}
}
else
if (subordine != 'P')
{
_form = new TForm_inventario("mg4200b");
setprint_permagazzini(subordine, alla_data, giac_reale, val_componenti, data_limite);
}
_form->set_parametri(m.get(F_CATVENLISTINO),
m.get(F_CODLISTINO),
giac_reale, val_componenti, alla_data,
m.get_int(F_ANNOES));
_form->add_colval(m.get_int(F_VAL1)-1);
_form->add_colval(m.get_int(F_VAL2)-1);
_form->add_colval(m.get_int(F_VAL3)-1);
_form->add_colval(m.get_int(F_VAL4)-1);
_form->add_colval(m.get_int(F_VAL5)-1);
_form->add_colval(m.get_int(F_VAL6)-1);
_form->genera_intestazioni(odd_page, 5);
_form->genera_intestazione_supplementare(odd_page, 4); // Nomi valorizzazioni applicate per colonna
set_def_valuta(*_form);
if (data_limite.ok())
{
TForm_item & f = _form->find_field('H',odd_page,4);
TString prompt = f.prompt();
prompt << TR("al ") << data_limite.string() << TR(" ");
f.set_prompt(prompt);
}
_form->print();
delete _form;
}
} // while true
return ;
}
int mg4200(int argc, char* argv[])
{
TStampa_inventario a;
a.run(argc,argv,TR("Stampa inventario"));
return 0;
}