Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/trunk@17188 c028cbd2-c16b-5b4b-a496-9718f37d4682
483 lines
14 KiB
C++
Executable File
483 lines
14 KiB
C++
Executable File
#include <modaut.h>
|
|
#include <progind.h>
|
|
#include <relapp.h>
|
|
#include <reputils.h>
|
|
#include <tabutil.h>
|
|
#include <urldefid.h>
|
|
|
|
#include "../ve/velib.h"
|
|
|
|
#include "mg0400a.h"
|
|
#include "clifogiac.h"
|
|
|
|
//---------------------------------------------------
|
|
// MASCHERA
|
|
//---------------------------------------------------
|
|
class TClifo_giac_mask : public TMask
|
|
{
|
|
TRelation* _rel; // relazione principale
|
|
|
|
TCodgiac_livelli* livelli_giac;// oggetto handler per i livelli di giacenza
|
|
TCodart_livelli* livelli_art;// oggetto handler per i livelli di anagraficca
|
|
int last_annogiac;
|
|
|
|
TString4 _um_principale;
|
|
TMagazzini *_magazzini;
|
|
TEsercizi_contabili *_esercizi_contabili;
|
|
|
|
static bool notify_sheet_giac(TSheet_field & s, int r, KEY k); // notify delle giacenze
|
|
static bool handle_sheet_giac_valgiac(TMask_field &, KEY); // handler
|
|
static bool handle_autoinsert_livgiac(TMask_field &, KEY); // handler del campo
|
|
|
|
static void sheetgiac_get(TSheet_field &fld_righe, int item);
|
|
static void sheetgiac_put(TSheet_field &fld_righe, int item);
|
|
|
|
public:
|
|
void set_parametered_fields();
|
|
void ricalcola_giacenze();
|
|
|
|
TCodart_livelli* get_livelli_art() const { return livelli_art; }
|
|
TMagazzini& magazzini() { return *_magazzini; }
|
|
TEsercizi_contabili &esercizi_contabili() { return *_esercizi_contabili; }
|
|
|
|
TClifo_giac_mask(TRelation * rel);
|
|
virtual ~TClifo_giac_mask() {}
|
|
};
|
|
|
|
|
|
|
|
bool TClifo_giac_mask::notify_sheet_giac(TSheet_field &f, int i, KEY k)
|
|
{
|
|
TClifo_giac_mask & m = (TClifo_giac_mask&)f.mask();
|
|
|
|
const bool gestmag = main_app().has_module(MGAUT) && m.magazzini().gestmag();
|
|
if (gestmag)
|
|
{
|
|
switch (k)
|
|
{
|
|
case (K_ENTER): // fine modifica
|
|
{
|
|
real ck(f.cell(i,f.cid2index(F_RIM)));
|
|
ck+=real(f.cell(i,f.cid2index(F_ACQ)));
|
|
ck+=real(f.cell(i,f.cid2index(F_ENTR)));
|
|
ck-=real(f.cell(i,f.cid2index(F_VEN)));
|
|
ck-=real(f.cell(i,f.cid2index(F_USC)));
|
|
ck-=real(f.cell(i,f.cid2index(F_ACL)));
|
|
ck+=real(f.cell(i,f.cid2index(F_INCL)));
|
|
ck-=real(f.cell(i,f.cid2index(F_INPRODF)));
|
|
ck+=real(f.cell(i,f.cid2index(F_INPRODC)));
|
|
ck-=real(f.cell(i,f.cid2index(F_SCARTI)));
|
|
ck-=real(f.cell(i,f.cid2index(F_GIAC)));
|
|
|
|
if (!ck.is_zero())
|
|
{
|
|
f.error_box("La giacenza deve essere pari a RIM+(ACQ+ENTR)-(VEN+USC)-(ACL-INCL)-(PRODF-PRODC) - SCARTI)");
|
|
return FALSE;
|
|
}
|
|
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
} //if(gestmag...
|
|
|
|
//campi presi da altri campi della maschera per..
|
|
//..essere visualizzati nella pag. giacenze
|
|
if (k == K_TAB)
|
|
{
|
|
TMask& sm = f.sheet_mask(); //maschera delle giacenze
|
|
|
|
if (sm.field(F_LIV1).hidden()) //l'articolo appare solo se mancano i livelli di giacenza senno'..
|
|
{ //..si sovrappongono
|
|
sm.show(F_CODARTR);
|
|
sm.show(F_DESCRR);
|
|
sm.set(F_CODARTR, m.get(F_CODART));
|
|
sm.set(F_DESCRR, m.get(F_DESART));
|
|
}
|
|
else
|
|
{
|
|
sm.hide(F_CODARTR);
|
|
sm.hide(F_DESCRR);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
bool TClifo_giac_mask::handle_sheet_giac_valgiac(TMask_field &f, KEY k)
|
|
{
|
|
if (k==K_TAB && f.dirty())
|
|
{
|
|
TMask& m = f.mask();
|
|
real q=m.get_real(F_RIM)+m.get_real(F_ACQ);
|
|
if (q.is_zero())
|
|
f.set(q.string());
|
|
else
|
|
{
|
|
q=(m.get_real(F_VRIM)+m.get_real(F_VACQ))/q;
|
|
TPrice r(q);
|
|
f.set(r.get_num().string());
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool TClifo_giac_mask::handle_autoinsert_livgiac(TMask_field &fld, KEY k)
|
|
{
|
|
if (k == K_TAB && fld.focusdirty() && !fld.empty())
|
|
{
|
|
TClifo_giac_mask & mask = (TClifo_giac_mask&)fld.mask().get_sheet()->mask();
|
|
const int levnum=fld.dlg()-F_LIV1+1;
|
|
return mask.livelli_giac->autoinsert(levnum, fld);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void TClifo_giac_mask::sheetgiac_get(TSheet_field &fld_righe, int item)
|
|
{
|
|
TClifo_giac_mask &m = (TClifo_giac_mask&)fld_righe.mask();
|
|
// prende il record della riga corrente dal record array
|
|
TRectype &rec= fld_righe.record()->row(item, TRUE);
|
|
TToken_string &row= fld_righe.row(item-1);
|
|
// codici di livello
|
|
row.add( m.livelli_giac->unpack_grpcode(rec.get("LIVELLO") ,1),fld_righe.cid2index(F_LIV1) );
|
|
row.add( m.livelli_giac->unpack_grpcode(rec.get("LIVELLO") ,2),fld_righe.cid2index(F_LIV2) );
|
|
row.add( m.livelli_giac->unpack_grpcode(rec.get("LIVELLO") ,3),fld_righe.cid2index(F_LIV3) );
|
|
row.add( m.livelli_giac->unpack_grpcode(rec.get("LIVELLO") ,4),fld_righe.cid2index(F_LIV4) );
|
|
}
|
|
|
|
|
|
// item varies from 1 to items()
|
|
void TClifo_giac_mask::sheetgiac_put(TSheet_field &fld_righe, int item)
|
|
{
|
|
TClifo_giac_mask &m = (TClifo_giac_mask&)fld_righe.mask();
|
|
TToken_string &row= fld_righe.row(item-1);
|
|
|
|
TRectype &recrighe= fld_righe.record()->row(item, TRUE);
|
|
// codici livello
|
|
if (m.livelli_giac->enabled()) {
|
|
TString16 packedcode;
|
|
m.livelli_giac->pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV1)),1);
|
|
m.livelli_giac->pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV2)),2);
|
|
m.livelli_giac->pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV3)),3);
|
|
m.livelli_giac->pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV4)),4);
|
|
recrighe.put("LIVELLO", packedcode);
|
|
}
|
|
}
|
|
|
|
|
|
void TClifo_giac_mask::set_parametered_fields()
|
|
{
|
|
// abilitazioni parametriche
|
|
if (livelli_giac)
|
|
delete livelli_giac;
|
|
if (livelli_art)
|
|
delete livelli_art;
|
|
if (_esercizi_contabili)
|
|
delete _esercizi_contabili;
|
|
if (_magazzini)
|
|
delete _magazzini;
|
|
|
|
_esercizi_contabili = new TEsercizi_contabili;
|
|
_magazzini = new TMagazzini;
|
|
|
|
// imposta il puntatore al gestore livelli giacenze
|
|
livelli_giac= new TCodgiac_livelli();
|
|
livelli_art= new TCodart_livelli();
|
|
// imposta il valore dell'anno per le giacenze
|
|
last_annogiac = -1;
|
|
|
|
// Abilita la pagina delle giacenze
|
|
const bool gestmag = main_app().has_module(MGAUT) && magazzini().gestmag();
|
|
|
|
// sheet giacenze
|
|
TSheet_field& sgiac = sfield(F_SHEETGIAC);
|
|
sgiac.set_userget(sheetgiac_get);
|
|
sgiac.set_userput(sheetgiac_put);
|
|
sgiac.sheet_mask().set_handler(F_VALGIAC, handle_sheet_giac_valgiac);
|
|
|
|
// setta i campi della maschera per la pagina giacenze
|
|
TSheet_field &fld_giac = sfield(F_SHEETGIAC);
|
|
fld_giac.set_notify(notify_sheet_giac);
|
|
|
|
// disabilita le colonne quando non sono utilizzati i livelli di giacenza
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
livelli_giac->set_sheetcolumn(fld_giac,F_LIV1+i,i+1);
|
|
if (livelli_giac->autoinsert(i+1))
|
|
{
|
|
// codice autoinseribile
|
|
TMask_field & campo_liv = fld_giac.sheet_mask().field(F_LIV1+i);
|
|
|
|
campo_liv.check_type(CHECK_SEARCH);
|
|
campo_liv.set_handler(gestmag ? handle_autoinsert_livgiac : NULL);
|
|
}
|
|
}
|
|
|
|
// abilita la gestione delle ubicazioni (manuale/su tabella)
|
|
const bool ubi = gestmag && magazzini().gestubi_man();
|
|
fld_giac.sheet_mask().field(F_UBICAZ).show(!ubi);
|
|
fld_giac.sheet_mask().field(F_UBICAZD).show(!ubi);
|
|
fld_giac.sheet_mask().field(F_UBICAZ2).show(ubi);
|
|
|
|
}
|
|
|
|
|
|
|
|
// costruttore della maschera anagrafica di magazzino
|
|
TClifo_giac_mask::TClifo_giac_mask(TRelation * rel) : TMask("mg0400a")
|
|
{
|
|
_rel = rel;
|
|
|
|
livelli_giac = NULL;
|
|
livelli_art = NULL;
|
|
_esercizi_contabili = NULL;
|
|
_magazzini = NULL;
|
|
|
|
set_parametered_fields();
|
|
}
|
|
|
|
//--------------------------------------------
|
|
// APPLICAZIONE
|
|
//--------------------------------------------
|
|
class TClifo_giac : public TRelation_application
|
|
{
|
|
TClifo_giac_mask *_msk; // maschera principale
|
|
TRelation *_rel; // relazione principale di un solo file clifogiac
|
|
|
|
protected:
|
|
virtual bool user_create();
|
|
virtual bool user_destroy();
|
|
virtual TMask *get_mask(int) { return _msk; }
|
|
|
|
TISAM_recordset recset_giacenze(const char tipocf, const long codcf, const TString& codart, const int annoes);
|
|
|
|
virtual int read(TMask& m);
|
|
void fill_giacenze(const char tipocf, const long codcf, const TString& codart, const int annoes);
|
|
|
|
virtual bool remove();
|
|
int remove_giacenze(const char tipocf, const long codcf, const TString& codart, const int annoes);
|
|
|
|
virtual int write(const TMask& m);
|
|
virtual int rewrite(const TMask& m);
|
|
int write_giacenze(TSheet_field& sheet_giac, const char tipocf, const long codcf, const TString& codart, const int annoes);
|
|
|
|
public:
|
|
virtual TRelation *get_relation() const { return _rel; }
|
|
TClifo_giac() { _rel = NULL; _msk = NULL;}
|
|
virtual ~TClifo_giac() {}
|
|
};
|
|
|
|
//-------------------------------------------
|
|
// Metodo comune per riempire un recordset
|
|
//-------------------------------------------
|
|
TISAM_recordset TClifo_giac::recset_giacenze(const char tipocf, const long codcf, const TString& codart, const int annoes)
|
|
{
|
|
TISAM_recordset giacenze("USE CLIFOGIAC\nSELECT CODART=#CODART\nFROM TIPOCF=#TIPOCF CODCF=#CODCF ANNOES=#ANNOES\nTO TIPOCF=#TIPOCF CODCF=#CODCF ANNOES=#ANNOES");
|
|
giacenze.set_var("#CODART", TVariant(codart));
|
|
TString4 str_tipocf; str_tipocf << tipocf;
|
|
giacenze.set_var("#TIPOCF", TVariant(str_tipocf));
|
|
giacenze.set_var("#CODCF", codcf);
|
|
giacenze.set_var("#ANNOES", (long)annoes);
|
|
|
|
return giacenze;
|
|
}
|
|
|
|
//------------------
|
|
// Metodi READ
|
|
//------------------
|
|
//FILL_GIACENZE: metodo x riempire lo sheet della maschera con tutti i record che soddisfano la chiave incompleta
|
|
void TClifo_giac::fill_giacenze(const char tipocf, const long codcf, const TString& codart, const int annoes)
|
|
{
|
|
//e usiamo 'sti recordset che sono comodi e capibili...quasi
|
|
TISAM_recordset giacenze = recset_giacenze(tipocf, codcf, codart, annoes);
|
|
|
|
TProgind pi(giacenze.items(), TR("Ricerca giacenze per indirizzo di spedizione..."), true, true);
|
|
|
|
TSheet_field& sheet = _msk->sfield(F_SHEETGIAC);
|
|
TMask& sheetmask = sheet.sheet_mask();
|
|
TRelation& rel = *giacenze.cursor()->relation(); //accesso alle righe
|
|
|
|
sheet.destroy();
|
|
|
|
if (giacenze.items() > 0)
|
|
{
|
|
for (bool ok = giacenze.move_first(); ok; ok = giacenze.move_next())
|
|
{
|
|
if (!pi.addstatus(1))
|
|
break;
|
|
|
|
TToken_string& row = sheet.row(-1); //crea una nuova riga dello sheet
|
|
|
|
//scandisco nella maschera tutti i campi che hanno un field
|
|
FOR_EACH_MASK_FIELD(sheetmask, i, f)
|
|
{
|
|
const TFieldref* fr = f->field(); //leggo il valore dalla relation
|
|
if (fr != NULL)
|
|
row.add(fr->read(rel),sheet.cid2index(f->dlg())); //metto il valore letto nella posizione corretta nella TToken_string
|
|
}
|
|
sheet.check_row(sheet.items()-1); //fa fare alla maschera la decodifica dei codici e aggiorna la TToken_string
|
|
}
|
|
sheet.force_update(); //forza l'update dello sheet, in modo da rendere visibili i cambiamneti fatti
|
|
}
|
|
return;
|
|
}
|
|
|
|
int TClifo_giac::read(TMask& m)
|
|
{
|
|
// int err = TRelation_application::read(m);
|
|
// return err;
|
|
|
|
//recupero i dati della testata
|
|
const char tipocf = m.get(F_TIPOCF)[0];
|
|
const long codcf = m.get_long(F_CODCF);
|
|
const TString80 codart = m.get(F_CODART);
|
|
const int annoes = m.get_int(F_ANNOES);
|
|
|
|
fill_giacenze(tipocf, codcf, codart, annoes);
|
|
|
|
return NOERR;
|
|
}
|
|
|
|
//------------------
|
|
// Metodi WRITE
|
|
//------------------
|
|
//WRITE_GIACENZE:scrive i dati sul file 166 (CLIFOGIAC)
|
|
int TClifo_giac::write_giacenze(TSheet_field& sheet_giac, const char tipocf, const long codcf, const TString& codart,
|
|
const int annoes)
|
|
{
|
|
TISAM_recordset giacenze = recset_giacenze(tipocf, codcf, codart, annoes);
|
|
int items = giacenze.items();
|
|
int err = NOERR;
|
|
|
|
TLocalisamfile& clifogiac = giacenze.cursor()->file();
|
|
|
|
//Maschera di sheet
|
|
TMask& msk = sheet_giac.sheet_mask();
|
|
|
|
//per ogni riga dello sheet
|
|
FOR_EACH_SHEET_ROW(sheet_giac, r, row)
|
|
{
|
|
clifogiac.zero();
|
|
//dati comuni a tutte le righe dello sheet
|
|
clifogiac.put(CLIFOGIAC_TIPOCF, tipocf);
|
|
clifogiac.put(CLIFOGIAC_CODCF, codcf);
|
|
clifogiac.put(CLIFOGIAC_ANNOES, annoes);
|
|
clifogiac.put(CLIFOGIAC_CODART, codart);
|
|
|
|
|
|
//per ogno campo della maschera di sheet
|
|
FOR_EACH_MASK_FIELD(msk, i, f)
|
|
{
|
|
//prendo il FIELD a cui si riferiscono
|
|
const TFieldref*fr = f->field();
|
|
|
|
//se efftivamente il campo ha un field di riferimento
|
|
if (fr != NULL)
|
|
{
|
|
const int pos = sheet_giac.cid2index(f->dlg()); //salvo la sua posizione all'inetrno dello sheet
|
|
fr->write(row->get(pos), clifogiac.curr()); //scrivo il valore che sto leggendo nel record corrente del file
|
|
}
|
|
}
|
|
|
|
//o faccio la rewrite, o faccio la write
|
|
err = clifogiac.rewrite_write();
|
|
}
|
|
return err;
|
|
}
|
|
|
|
|
|
int TClifo_giac::write(const TMask& m)
|
|
{
|
|
//int err = TRelation_application::write(m);
|
|
//return err;
|
|
|
|
const char tipocf = m.get(F_TIPOCF)[0];
|
|
const long codcf = m.get_long(F_CODCF);
|
|
const TString80 codart = m.get(F_CODART);
|
|
const int annoes = m.get_int(F_ANNOES);
|
|
|
|
TSheet_field& sheet_giac = m.sfield(F_SHEETGIAC);
|
|
|
|
return write_giacenze(sheet_giac, tipocf, codcf, codart, annoes);
|
|
}
|
|
|
|
int TClifo_giac::rewrite(const TMask& m)
|
|
{
|
|
//int err = TRelation_application::rewrite(m);
|
|
//return err;
|
|
|
|
const char tipocf = m.get(F_TIPOCF)[0];
|
|
const long codcf = m.get_long(F_CODCF);
|
|
const TString80 codart = m.get(F_CODART);
|
|
const int annoes = m.get_int(F_ANNOES);
|
|
|
|
TSheet_field& sheet_giac = m.sfield(F_SHEETGIAC);
|
|
|
|
return write_giacenze(sheet_giac, tipocf, codcf, codart, annoes);
|
|
}
|
|
|
|
//------------------
|
|
// Metodi REMOVE
|
|
//------------------
|
|
//REMOVE_GIACENZE: elimina tutte le righe dello sheet per il clifo,l'articolo e l'anno passati
|
|
int TClifo_giac::remove_giacenze(const char tipocf, const long codcf, const TString& codart, const int annoes)
|
|
{
|
|
TISAM_recordset giacenze = recset_giacenze(tipocf, codcf, codart, annoes);
|
|
int items = giacenze.items();
|
|
int err = NOERR;
|
|
|
|
//l'accoppamento delle righe va fatto proprio sul file, quindi sotto con il localisamfile..
|
|
TLocalisamfile& clifogiac = giacenze.cursor()->file();
|
|
|
|
//per ogni riga del recordset
|
|
for (bool ok = giacenze.move_first(); ok; ok = giacenze.move_next())
|
|
{
|
|
err = clifogiac.remove();
|
|
}
|
|
return err;
|
|
}
|
|
bool TClifo_giac::remove()
|
|
{
|
|
//bool ok = TRelation_application::remove();
|
|
//return ok;
|
|
|
|
//recupero i dati della testata
|
|
const char tipocf = _msk->get(F_TIPOCF)[0];
|
|
const long codcf = _msk->get_long(F_CODCF);
|
|
const TString80 codart = _msk->get(F_CODART);
|
|
const int annoes = _msk->get_int(F_ANNOES);
|
|
|
|
//variabili per lavorare sugli sheet
|
|
TSheet_field& sheet_giac = _msk->sfield(F_SHEETGIAC);
|
|
|
|
return remove_giacenze(tipocf, codcf, codart, annoes) > 0;
|
|
}
|
|
|
|
//---------------------
|
|
// Metodi GENERICI
|
|
//---------------------
|
|
bool TClifo_giac::user_create()
|
|
{
|
|
_rel = new TRelation(LF_CLIFOGIAC);
|
|
|
|
_msk = new TClifo_giac_mask(_rel);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TClifo_giac::user_destroy()
|
|
{
|
|
delete _rel;
|
|
delete _msk;
|
|
|
|
return true;
|
|
}
|
|
|
|
int mg0400(int argc, char* argv[])
|
|
{
|
|
TClifo_giac a;
|
|
a.run(argc, argv, "Giacenze per Clienti/Fornitori");
|
|
return 0;
|
|
} |