#include #include #include #include #include "sc0100.h" #include "sc0100a.h" #include HIDDEN bool gruppo_handler(TMask_field& f, KEY key) { static bool ignore = false; if (key == K_TAB && f.focusdirty()) { if (!ignore) { TEdit_field& c = f.mask().efield(F_CONTO); if (!c.empty()) { ignore = true; c.set_dirty(); c.on_key(K_TAB); ignore = false; } } } return true; } HIDDEN bool clifo_handler(TMask_field& f, KEY key) { if (key == K_TAB && f.focusdirty() && !f.empty()) { TMask& m = f.mask(); const TString& tipocf = m.get(F_TIPO); TString8 key; key.format("%d|%d", m.get_int(F_GRUPPO), m.get_int(F_CONTO)); const TString& tm = cache().get(LF_PCON, key, PCN_TMCF); if (tm != tipocf) { TString query; query << "USE PCON SELECT TMCF=\"" << tipocf << '"'; TISAM_recordset pcon(query); if (pcon.move_first()) { const TRectype& rec = pcon.cursor()->curr(); m.set(F_GRUPPO, rec.get_int(PCN_GRUPPO)); m.set(F_CONTO, rec.get_int(PCN_CONTO)); } else return error_box(TR("Conto clienti/fornitori non valido")); } } return true; } /////////////////////////////////////////////////////////// // Gestione saldaconto extra-contabile /////////////////////////////////////////////////////////// TSaldaconto_app::TSaldaconto_app() : _allow_firm(TRUE) {} bool TSaldaconto_app::create() { open_files(LF_TAB, LF_TABCOM, LF_CLIFO, LF_PCON, 0); open_files(LF_PARTITE, LF_SCADENZE, LF_PAGSCA, 0); open_files(LF_CAUSALI, LF_ATTIV, 0); load_colors(); _msk = new TMask("sc0100a"); _msk->set_handler(F_GRUPPO, gruppo_handler); _msk->set_handler(F_CLIENTE, clifo_handler); _msk->set_handler(F_FORNITORE, clifo_handler); const bool ges_sal = ini_get_bool(CONFIG_DITTA, "cg", "GesSal"); if (!ges_sal) warning_box(FR("Attenzione: La ditta %ld non ha gestione del saldaconto!"), get_firm()); return TSkeleton_application::create(); } bool TSaldaconto_app::destroy() { delete _msk; return TSkeleton_application::destroy(); } void TSaldaconto_app::on_config_change() { TConfig cnf(CONFIG_DITTA, "cg"); _ges_val = cnf.get_bool("GesVal"); TPartita::carica_allineamento(); } void TSaldaconto_app::main_loop() { TMask& m = curr_mask(); bool ok = true; while (ok) { xvtil_statbar_set(TR("Ricerca"), TRUE); m.reset(); ok = m.run() == K_ENTER; if (ok) { _allow_firm = FALSE; edit_partite(m); _allow_firm = true; } } } void TSaldaconto_app::load_colors() { TConfig conf(CONFIG_USER, "cg2"); TAssoc_array& colori = (TAssoc_array&)conf.list_variables(); for (THash_object* o = colori.get_hashobj(); o; o = colori.get_hashobj()) { const TString& key = o->key(); if (key.len() == 7 && key.compare("Color", 5, TRUE) == 0) { const COLOR col = conf.get_color(key); TString* strcol = new TString16; strcol->format("%ld", col); _colori.add(key.mid(5), strcol); } } } COLOR TSaldaconto_app::type2color(char tipor, char tipoc) { COLOR col; if (tipor > ' ') { const char key[3] = { tipoc, tipor, '\0' }; TString* colstr = (TString*)_colori.objptr(key); if (colstr == NULL) { colstr = new TString16; colstr->format("%ld", tipoc == 'B' ? NORMAL_BACK_COLOR : NORMAL_COLOR); _colori.add(key, colstr); } col = atol(*colstr); } else { col = tipoc == 'B' ? NORMAL_BACK_COLOR : NORMAL_COLOR; } return col; } void TSaldaconto_app::type2colors(char tipor, COLOR& back, COLOR& fore) { back = type2color(tipor, 'B'); fore = type2color(tipor, 'F'); } /////////////////////////////////////////////////////////// // Handlers generali /////////////////////////////////////////////////////////// #include "sc0100p.h" void TSaldaconto_app::gioca_cambi(TMask& m, int force) { if (m.get(E_VALUTA).empty()) return; const real totale = m.get_real(E_TOTALE); const real totval = m.get_real(E_TOTDOCVAL); const real cambio = m.get_real(E_CAMBIO); if ( (force == 0x1 || totale.is_zero()) && !(totval.is_zero() || cambio.is_zero()) ) { const TValuta cam(m, E_VALUTA, E_DATACAMBIO, E_CAMBIO); const real new_totale = cam.val2eur(totval); if (new_totale != totale) m.set(E_TOTALE, new_totale, TRUE); } if ( (force == 0x2 || totval.is_zero()) && !(totale.is_zero() || cambio.is_zero()) ) { const TValuta cam(m, E_VALUTA, E_DATACAMBIO, E_CAMBIO); const real new_totval = cam.eur2val(totale); if (new_totval != totval) m.set(E_TOTDOCVAL, new_totval, TRUE); } if ( (force == 0x4 || cambio.is_zero()) && !(totale.is_zero() || totval.is_zero()) ) { real new_cambio = totale / totval; new_cambio.round(5); if (new_cambio != cambio) m.set(E_CAMBIO, new_cambio, TRUE); } } /////////////////////////////////////////////////////////// int sc0100(int argc, char* argv[]) { TSaldaconto_app* salda = new TSaldaconto_app; salda->run(argc, argv, TR("Gestione Saldaconto")); delete salda; return 0; }