#include #include "../ve/ve0100.h" #include "../ve/veini.h" #include "../ve/veuml.h" #include "../ve/veuml3.h" #include "../ve/verig.h" #include "../ve/vepriv.h" #include "../ve/velib.h" #include "../ve/velib04.h" #define F_K F_USERFLD #define F_DETTAGLIO F_USERFLD+1 #define FOR_EACH_DOC_ROW_BACK(d, r, row) const TRiga_documento* row = NULL; for (int r = d.rows(); r > 0 && (row = &d[r]) != NULL; r--) ////////////////////////////////////////// //// CLASSE TGestione_preventivo_msk //// ////////////////////////////////////////// //Definizione della classe della maschera class TGestione_preventivo_msk : public TDocumento_mask { int _rule; protected: //hanlder di documento: static bool pe_data_handler(TMask_field& f, KEY k); //handler di riga: static bool pe_ritirato_handler(TMask_field& f, KEY k); static bool pe_codart_handler(TMask_field& f, KEY k); static bool pe_umart_handler(TMask_field& f, KEY k); static bool ss_notify(TSheet_field& ss, int r, KEY key); virtual void on_idle(); virtual void highlight_row(int row, bool dirty = true, bool update = true); public: virtual void user_set_handler( short fieldid, int index); virtual void user_set_row_handler(TMask& rm, short field, int index); virtual TVariable_mask * riga_mask(int numriga); virtual void doc2mask(bool reload_clifo = true, bool update = true); TGestione_preventivo_msk(const char* tipodoc); }; ////////////////////////////////////////// //// CLASSE TGestione_preventivo_APP //// ////////////////////////////////////////// // Definizione della classe dell'applicazione motore class TGestione_preventivo_app : public TMotore_application { protected: virtual TMask* get_mask( int mode ); virtual int write( const TMask& m ); virtual int rewrite( const TMask& m ); virtual int read ( TMask& m ); virtual void init_insert_mode( TMask& m ); void elimina_vuote( const TMask& m); public: TGestione_preventivo_app() {} }; inline TGestione_preventivo_app& peapp() { return (TGestione_preventivo_app &)main_app(); }; ////////////////////////////////////////// //// CLASSE TGestione_preventivo_MSK //// ////////////////////////////////////////// //////////////////////////// // HANDLER DI DOCUMENTO // //////////////////////////// void TGestione_preventivo_msk:: on_idle() { TDocumento_mask::on_idle(); } //magico metodo per settare, al cambio riga dello sheet, il focus sul campo desiderato (il campo in questione è.. //..definito nella on_idle(); ricordarsi la set_notify() nel costruttore della maschera senno' viene eseguito l'ss_notify().. //..standard e non questo qui ridefinito. Allah! bool TGestione_preventivo_msk::ss_notify(TSheet_field& ss, int r, KEY key) { TGestione_preventivo_msk& dmsk = (TGestione_preventivo_msk&) ss.mask(); TSheet_field & sh = dmsk.sfield(F_SHEET); TDocumento& doc = dmsk.doc(); TRiga_documento& row = doc[r + 1]; switch (key) { case K_ENTER: // modifica { TMask & m = sh.sheet_row_mask(r); const int level = row.get_int(RDOC_LEVEL); const bool prodfin = level == 0; const bool price_enabled = (r + 1 == doc.physical_rows()) || (level < doc[r + 2].get_int(RDOC_LEVEL)); short id; m.enable(FR_PREZZO, price_enabled); m.enable(FR_JOLLY2, price_enabled); for (id = F_CDC1; id < F_CDC12; id++) m.enable(id, prodfin); for (id = F_DESCDC1; id < F_DESCDC12; id++) m.enable(id, prodfin); } break; case K_INS: // Inserimento { const int new_sheet_r = doc.physical_rows() == 0 ? 0 : r + 1; const int new_r = new_sheet_r + 1; int level = 0; doc.insert_row(new_r, dmsk.get( F_LBTIPORIGA )); TRiga_documento & new_row = doc[new_r]; if (r > 0 && row.is_merce()) { level = row.get_int(RDOC_LEVEL); if (dmsk.get_bool(F_DETTAGLIO)) { level++; dmsk.reset(F_DETTAGLIO); } if (level > 0) { new_row.put(RDOC_CODCOSTO, row.get(RDOC_CODCOSTO)); new_row.put(RDOC_CODCMS, row.get(RDOC_CODCMS)); new_row.put(RDOC_FASCMS, row.get(RDOC_FASCMS)); short id; sh.disable_cell(r, sh.cid2index(FR_PREZZO)); sh.disable_cell(r, sh.cid2index(FR_JOLLY2)); row.zero(RDOC_PREZZO); row.zero(RDOC_K); row.autoload(sh); for (id = F_CDC1; id < F_CDC12; id++) sh.disable_cell(new_sheet_r, sh.cid2index(id)); } } new_row.put(RDOC_LEVEL, level); TString tree; if (level > 0) tree.fill(' '); tree << '+'; tree.rpad(10, '-'); row.put(RDOC_TREE, tree); } break; default: break; } return TDocumento_mask::ss_notify(ss, r, key); } void TGestione_preventivo_msk::highlight_row(int row, bool dirty, bool update) { TRiga_documento& rigadoc = doc()[row + 1]; TSheet_field& sf = sfield(F_SHEET); COLOR back1 = NORMAL_BACK_COLOR, back2 = FOCUS_BACK_COLOR; const TColor_rule * c = (TColor_rule *) color_rules().objptr(_rule); if (c != NULL) { COLOR fore; c->colors(back2, fore); } const COLOR back = blend_colors(back1, back2, ((double) rigadoc.get_int(RDOC_LEVEL)) / 10.0); sf.set_back_and_fore_color(back, COLOR_INVALID, row); TDocumento_mask::highlight_row(row, dirty, update); } TVariable_mask * TGestione_preventivo_msk::riga_mask(int numriga) { TVariable_mask* m = TDocumento_mask::riga_mask(numriga); if ( m != NULL) { const TRiga_documento& riga = doc()[numriga + 1]; TEdit_field & tree = m->add_string(FR_JOLLY1, 0, "", 30, 50, 10, "D"); TEdit_field & k = m->add_string(FR_JOLLY2, 0, "K ", 2, 20, 25); tree.set_field(RDOC_TREE); k.set_field(RDOC_K); } return m; } void TGestione_preventivo_msk::doc2mask(bool reload_clifo, bool update) { TDocumento_mask::doc2mask(reload_clifo, false); TSheet_field& s = sfield(F_SHEET); const int righe = s.items(); const TDocumento & d = doc(); for (int i = 0; i < righe; i++) { const TRiga_documento & row = d[i + 1]; const int level = row.get_int(RDOC_LEVEL); const bool prodfin = level == 0; const bool price_enabled = (i + 1 == d.physical_rows()) || (level < d[i + 2].get_int(RDOC_LEVEL)); s.enable_cell(i, s.cid2index(FR_PREZZO), price_enabled); s.enable_cell(i, s.cid2index(FR_JOLLY2), price_enabled); for (short id = F_CDC1; id < F_CDC12; id++) s.enable_cell(i, s.cid2index(id), prodfin); } //aggiorna i colori delle righe e forza l'update dello sheet highlight(); } //PE_TESTATA_HANDLER: handler che si occupa di decodificare i campi data in testata bool TGestione_preventivo_msk::pe_data_handler(TMask_field& f, KEY k) { bool ok = true; TGestione_preventivo_msk& dmsk = (TGestione_preventivo_msk&)f.mask(); return ok; } /////////////////////// // HANDLER DI RIGA // /////////////////////// //PE_RITIRATO_HANDLER: handler sul campo ritirato, che copia nel campo consegnato //lo stesso valore eventualmente arrotondato e aggiorna il campo "dotazione odierna" (sempre) //e il campo "dotazione temporanea" (se la causale è giusta) bool TGestione_preventivo_msk::pe_ritirato_handler(TMask_field& f, KEY k) { if (f.to_check(k)) { TMask& msk = f.mask(); } return true; } bool TGestione_preventivo_msk::pe_codart_handler(TMask_field& f, KEY k) { bool ok = codart_handler( f, k ); if (ok && (k == K_ENTER || k == K_TAB)) { TMask& row_mask = f.mask(); if (row_mask.field(FR_JOLLY2).active()) { TSheet_field * sh = row_mask.get_sheet(); if (sh != NULL) { TDocumento_mask & mask = (TDocumento_mask &) sh->mask(); TDocumento & doc = mask.doc(); if (f.to_check(k, true)) { const int r = sh->selected(); const TString& codart = mask.get(FR_CODARTMAG); TRiga_documento & row = doc[r + 1]; if (codart.full()) { const TArticolo_giacenza & art = cached_article(codart); TString80 k = art.get(ANAMAG_PERCRIC); if (k.blank()) { const TString catmer = art.get(ANAMAG_GRMERC); k = cache().get("GMC", catmer, "S2"); if (k.blank()) k = cache().get("GMC", catmer.left(3), "S2"); } } } } } } return ok; } bool TGestione_preventivo_msk::pe_umart_handler(TMask_field& f, KEY k) { bool ok = umart_handler( f, k ); if (ok) { TMask& row_mask = f.mask(); TSheet_field * sh = row_mask.get_sheet(); if (sh != NULL) { TDocumento_mask & mask = (TDocumento_mask &) sh->mask(); TDocumento & doc = mask.doc(); if (k == K_F8) { const int r = sh->selected(); if (r > 0) { TRiga_documento & row = doc[r + 1]; const int level = row.get_int(RDOC_LEVEL); if (level > 0) { TRiga_documento & row = doc[r]; const real qta_prec = row.get_real(RDOC_QTA); real qta(f.get()); TToken_string & shrow = sh->row(r); qta *= qta_prec; shrow.add(qta.string(), sh->cid2index(FR_UMQTA)); sh->force_update(r); f.focusdirty(); } } } if (f.to_check(k, true)) { const int r = sh->selected(); TRiga_documento & row = doc[r + 1]; const real old_qta = row.get_real(RDOC_QTA); const real qta(f.get()); const int level = row.get_int(RDOC_LEVEL); if (old_qta != qta) { const int rows = doc.physical_rows(); for (int i = r + 2; level < doc[i].get_int(RDOC_LEVEL) && i <= rows; i++) { TToken_string & shrow = sh->row(i - 1); real row_qta(shrow.get(sh->cid2index(FR_UMQTA))); row_qta *= qta; row_qta /= old_qta; shrow.add(row_qta.string(), sh->cid2index(FR_UMQTA)); doc[i].put(RDOC_QTA, row_qta); } sh->force_update(); } } } } return ok; } //metodo che setta gli handler sui campi di riga void TGestione_preventivo_msk::user_set_row_handler(TMask& rm, short field, int index) { switch(index) { case 5101: rm.set_handler(field, pe_ritirato_handler); break; case 5102: rm.set_handler(field, pe_codart_handler); break; default : TDocumento_mask::user_set_row_handler(rm, field, index); break; } } //metodo che setta l'handler di bolla void TGestione_preventivo_msk::user_set_handler( short fieldid, int index) { switch(index) { case 5101: set_field_handler(fieldid, pe_data_handler); break; default : TDocumento_mask::user_set_handler(fieldid, index); break; } } TGestione_preventivo_msk::TGestione_preventivo_msk(const char* tipodoc) : TDocumento_mask(tipodoc) { TConfig* configpe = new TConfig(CONFIG_DITTA, "pe"); sfield(F_SHEET).set_auto_append(); sfield(F_SHEET).set_notify( ss_notify ); _rule = color_rules().add(new TColor_rule("Livello", "", _numexpr, FOCUS_BACK_COLOR, FOCUS_COLOR)); } ////////////////////////////////////////// //// CLASSE TGESTIONE_PREVENTIVO_APP //// ////////////////////////////////////////// //ridefinisco il metodo get_mask delle TMotore_application TMask* TGestione_preventivo_app::get_mask( int mode ) { if (mode == MODE_INS || mode == MODE_MOD) { TString4 tipodoc; if (mode == MODE_MOD) tipodoc = get_relation()->curr().get(DOC_TIPODOC); // Lo prendo dalla relazione (Gelai) else tipodoc = TMotore_application::get_mask(MODE_QUERY)->get(F_TIPODOC); if (_doc_masks.objptr(tipodoc) == NULL) { TGestione_preventivo_msk* m = new TGestione_preventivo_msk(tipodoc); _doc_masks.add(tipodoc, m); const TTipo_documento& tdoc = m->doc().tipo(); const TString_array& handlers = tdoc.handlers(); FOR_EACH_ARRAY_ROW(handlers, i, row) { m->user_set_handler( row->get_int( 0 ), row->get_int( 1 ) ); } TSheet_field & sh = m->sfield(F_SHEET); const int y = sh.y_pos() - 1; TEdit_field & k = m->add_string(F_K, sh.page(), "K ", 2, y, 10, "D"); k.set_field(DOC_K); m->add_boolean(F_DETTAGLIO, sh.page(), "Dettaglia ", 30, y); } } return TMotore_application::get_mask(mode); } //ridefinisco il metodo write delle TMotore_application int TGestione_preventivo_app::write( const TMask& m ) { TDocumento& doc = ((TDocumento_mask&) m).doc(); const TString k = doc.get(DOC_K); for (int i = 1 ; i <= doc.physical_rows(); i++) if (doc[i].get(RDOC_K).blank()) doc[i].put(RDOC_K, k); return TMotore_application::write(m); } //ridefinisco il metodo rewrite delle TMotore_application int TGestione_preventivo_app::rewrite( const TMask& m ) { TDocumento& doc = ((TDocumento_mask&) m).doc(); const TString k = doc.get(DOC_K); for (int i = 1 ; i <= doc.physical_rows(); i++) if (doc[i].get(RDOC_K).blank()) doc[i].put(RDOC_K, k); return TMotore_application::rewrite(m); } //ridefinisco il metodo read della TMotore_application int TGestione_preventivo_app::read(TMask& m) { const int err = TMotore_application::read(m); if (err == NOERR) { TDocumento_mask& mask = (TDocumento_mask&) m; TDocumento& doc = mask.doc(); const TString k = doc.get(DOC_K); for (int i = 1 ; i <= doc.physical_rows(); i++) if (k == doc[i].get(RDOC_K)) doc[i].zero(RDOC_K); } return err; } //ridefinisco il metodo init_insert_mode della TMotore_application void TGestione_preventivo_app::init_insert_mode(TMask &m) { TGestione_preventivo_msk & mask = (TGestione_preventivo_msk&) m; TDocumento& d = mask.doc(); return TMotore_application::init_insert_mode(m); } int pe0400( int argc, char* argv[]) { TGestione_preventivo_app a; a.run( argc, argv, TR("Gestione Preventivi")); return 0; }