#include #include #include #include #include #include #include #include #include "..\mg\mglib.h" //#include "..\cg\cglib.h" #include "..\ve\veconf.h" #include "mg1100.h" //******************** //******************** // maschera dell'applicazione "Gestione interattiva movimenti di magazzino" // class TMask_movmag: public TMask { TMov_mag * mov_mag; TMag_livelli * livelli_giac; // oggetto gestione livelli di giacenza TString price_codart; real price_quant; bool price_proposed; real proposed_price(TString codart, real quant); static bool handle_righeprezzo(TMask_field &f, KEY k); // handler delle righe static bool handle_codcaus(TMask_field &fld, KEY k); // handler della causale static bool handle_datacomp(TMask_field &, KEY); // handler del numero di registrazione public: TMask_movmag(TMag_livelli *l_m,TMov_mag * m_m); virtual ~TMask_movmag(); static void sheetrighe_put(TSheet_field &fld_righe, int item); static void sheetrighe_get(TSheet_field &fld_righe, int item); }; // costruttore della maschera anagrafica di magazzino //TMask_movmag::TMask_movmag() : TMask_movmag::TMask_movmag(TMag_livelli *l_m,TMov_mag * m_m) : TMask("mg1100") { // oggetti dell'applicazione livelli_giac= l_m; mov_mag = m_m; // setta handler e notify set_handler(F_DATACOMP, handle_datacomp); set_handler(F_CODCAUS, handle_codcaus); ((TSheet_field &)field(F_RIGHE)).sheet_mask().field(F_PREZZO).set_handler(handle_righeprezzo); ((TSheet_field &)field(F_RIGHE)).sheet_mask().field(F_CODART).set_handler(handle_righeprezzo); ((TSheet_field &)field(F_RIGHE)).sheet_mask().field(F_QUANT).set_handler(handle_righeprezzo); ((TSheet_field &)field(F_RIGHE)).set_userget(sheetrighe_get); ((TSheet_field &)field(F_RIGHE)).set_userput(sheetrighe_put); ((TSheet_field &)field(F_RIGHE)).set_lines_record(m_m->body()); // setta i campi della maschera // per la pagina giacenze TSheet_field &fld_righe= (TSheet_field &)field(F_RIGHE); // disabilita le colonne quando non sono utilizzati i livelli di giacenza if (livelli_giac->enabled(1)) { fld_righe.sheet_mask().field(F_LIV1).show(); fld_righe.set_column_header(fld_righe.cid2index(F_LIV1),livelli_giac->name(1)); fld_righe.sheet_mask().field(F_LIV1).set_prompt(livelli_giac->name(1)); } else { fld_righe.sheet_mask().field(F_LIV1).hide(); fld_righe.delete_column(fld_righe.cid2index(F_LIV1)); } if (livelli_giac->enabled(2)) { fld_righe.sheet_mask().field(F_LIV2).show(); fld_righe.set_column_header(fld_righe.cid2index(F_LIV2),livelli_giac->name(2)); fld_righe.sheet_mask().field(F_LIV2).set_prompt(livelli_giac->name(2)); } else { fld_righe.sheet_mask().field(F_LIV2).hide(); fld_righe.delete_column(fld_righe.cid2index(F_LIV2)); } if (livelli_giac->enabled(3)) { fld_righe.sheet_mask().field(F_LIV3).show(); fld_righe.set_column_header(fld_righe.cid2index(F_LIV3),livelli_giac->name(3)); fld_righe.sheet_mask().field(F_LIV3).set_prompt(livelli_giac->name(3)); } else { fld_righe.sheet_mask().field(F_LIV3).hide(); fld_righe.delete_column(fld_righe.cid2index(F_LIV3)); } if (livelli_giac->enabled(4)) { fld_righe.sheet_mask().field(F_LIV4).show(); fld_righe.set_column_header(fld_righe.cid2index(F_LIV4),livelli_giac->name(4)); fld_righe.sheet_mask().field(F_LIV4).set_prompt(livelli_giac->name(4)); } else { fld_righe.sheet_mask().field(F_LIV4).hide(); fld_righe.delete_column(fld_righe.cid2index(F_LIV4)); } TConfig prassid(CONFIG_DITTA, "ve"); // apre il file di configurazione della ditta corrente if (prassid.get_bool("GES", NULL, A_LISTINI)) field(F_CATVEN).enable(prassid.get_bool("GESLISCV")); else field(F_CATVEN).disable(); } TMask_movmag::~TMask_movmag() { } // item varies from 1 to items() void TMask_movmag::sheetrighe_get(TSheet_field &fld_righe, int item) { TMask_movmag &m=(TMask_movmag &)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("LIVGIAC") ,1),fld_righe.cid2index(F_LIV1) ); row.add( m.livelli_giac->unpack_grpcode(rec.get("LIVGIAC") ,2),fld_righe.cid2index(F_LIV2) ); row.add( m.livelli_giac->unpack_grpcode(rec.get("LIVGIAC") ,3),fld_righe.cid2index(F_LIV3) ); row.add( m.livelli_giac->unpack_grpcode(rec.get("LIVGIAC") ,4),fld_righe.cid2index(F_LIV4) ); } // item varies from 1 to items() void TMask_movmag::sheetrighe_put(TSheet_field &fld_righe, int item) { TMask_movmag &m=(TMask_movmag &)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("LIVGIAC", packedcode); } } bool TMask_movmag::handle_righeprezzo(TMask_field &f, KEY k) { TSheet_field &sh=(TSheet_field &)(*f.mask().get_sheet()); TMask_movmag &m=(TMask_movmag &)sh.mask(); if (k==K_TAB && f.focusdirty()) { m.price_proposed=FALSE; // in caso di nuova linea o prezzo nullo, propone il prezzo in base alla causale if (!f.mask().get(F_QUANT).blank() && !f.mask().get(F_CODART).blank() && f.mask().get(F_PREZZO).blank() && (m.price_proposed==FALSE)) { m.price_proposed=TRUE; real prz=m.proposed_price(f.mask().get(F_CODART), f.mask().get_real(F_QUANT)); f.mask().set(F_PREZZO,prz); } } return TRUE; } real TMask_movmag::proposed_price(TString codart, real quant) { real rv("0"); TCausale_magazzino cau(get(F_CODCAUS)); TLocalisamfile anamag(LF_ANAMAG); anamag.put("CODART",codart); anamag.read(); switch (cau.get_tipoprz()) { // prezzo case 'P': { TLocalisamfile umart(LF_UMART); TConfig cfgditta(CONFIG_DITTA); TCondizione_vendita cv(&cfgditta,&anamag,&umart); cv.put_listino(get(F_CODCONDV),get(F_CATVEN)); cv.ricerca(codart,quant); rv=cv.get_prezzo(); } break; // costo case 'C': { rv=anamag.get_real("ULTCOS1"); } break; } return rv; } bool TMask_movmag::handle_codcaus(TMask_field &fld, KEY k) { return TRUE; } bool TMask_movmag::handle_datacomp(TMask_field &fld, KEY k) { if (k == K_TAB && fld.focusdirty()) { int codes=((TMask_movmag &)fld.mask()).mov_mag->codice_esercizio(TDate(fld.get())); if (codes>0) fld.mask().field(F_ANNOES).set(codes); else { fld.error_box("La data indicata non appartiene a nessuno degli esercizi contabili inseriti ") ; return FALSE; } } return TRUE; } class TApp_movmag: public TRelation_application { TMask_movmag *_msk; // maschera principale TMag_livelli * _livelli_giac;// oggetto handler per i livelli di giacenza TRelation * _rel; // relazione contenente il file movimenti TLocalisamfile * _rmovmag; // file aperto per utilizzarne il record virtual bool user_create(); virtual bool user_destroy(); virtual TMask *get_mask(int) { return _msk; } virtual bool changing_mask(int) { return FALSE; } virtual TRelation *get_relation() const { return _rel; } virtual const char *get_next_key(); // virtual int read(TMask& m); // virtual bool remove(); // virtual int write(const TMask& m); // virtual int rewrite(const TMask& m); TString16 _nextcod; public: TApp_movmag() {}; virtual ~TApp_movmag() {}; }; inline TApp_movmag& app() { return (TApp_movmag&) main_app(); } bool TApp_movmag::user_create() { _rmovmag = new TLocalisamfile(LF_RMOVMAG); TMov_mag * m_m= new TMov_mag(); // record del movimento di magazzino m_m->enable_autoload(LF_RMOVMAG); // gestione giacenza a livelli _livelli_giac= new TMag_livelli("FCG"); // maschera specifica con gli handler dei movimenti _msk= new TMask_movmag(_livelli_giac,m_m); // relazione con un solo file (LF_MOVMAG) ma col record Head_Body _rel= new TRelation(LF_MOVMAG); _rel->lfile().set_curr(m_m); return TRUE; } bool TApp_movmag::user_destroy() { delete _rmovmag; delete _rel; delete _msk; delete _livelli_giac; return TRUE; } // autonumerazione const char *TApp_movmag::get_next_key() { return _nextcod.format("%d|%s",F_NUMREG,((TMov_mag &)_rel->curr()).get_next_key()); } int mg1100(int argc, char* argv[]) { TApp_movmag a; a.run(argc, argv, "Movimenti di magazzino"); return 0; }