#include #include #include #include #include #include #include #include #include #include #include #include "ve6400a.h" #include "velib.h" /////////////////////////////////////////////////////////// // Maschera principale /////////////////////////////////////////////////////////// class TScontrino_mask : public TAutomask { bool _ini_loaded; TFilename _ini_name; protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); // Funzioni di invio ai registratori di cassa conosciuti bool send_er400_data(bool extra); bool send_scr_data(); public: bool load_ini(); bool save_ini(KEY k); bool load_profile(); bool save_profile(); bool send_data(); TScontrino_mask(); virtual ~TScontrino_mask(); }; bool TScontrino_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case DLG_SAVEREC: if (e == fe_button) { if (send_data() && _ini_loaded) stop_run(K_AUTO_ENTER); } break; default: break; } return TRUE; } bool TScontrino_mask::load_profile() { TFilename f; f =::firm2dir(-1); // Directory dati f.add("config"); // Directory config f.add(source_file()); // Nome Maschera f.ext("ini"); // Estensione TConfig ini(f, "Main"); set(F_REGISTRATORE, ini.get("Registratore")); set(F_SALUTI, ini.get("Saluti", NULL, -1, "Arrivederci Grazie!")); return TRUE; } bool TScontrino_mask::save_profile() { TFilename f; f =::firm2dir(-1); // Directory dati f.add("config"); // Directory config f.add(source_file()); // Nome Maschera f.ext("ini"); // Estensione TConfig ini(f, "Main"); ini.set("Registratore", get(F_REGISTRATORE)); ini.set("Saluti", get(F_SALUTI)); return TRUE; } bool TScontrino_mask::load_ini() { _ini_loaded = FALSE; const TApplication& a = main_app(); const int argc = a.argc(); if (argc <= 2) return FALSE; TSheet_field& sheet = sfield(F_SHEET); const TString& arg = a.argv(2); if ((arg[0] != '-' && arg[0] != '/') || (arg[1] != 'i' && arg[1] != 'I')) return FALSE; _ini_name = arg.mid(2); if (_ini_name.blank() && argc > 3) _ini_name = a.argv(3); if (!_ini_name.exist()) return FALSE; TString16 para; para.format("%d", LF_DOC); TString tmp; TDocumento doc; TConfig ini(_ini_name, para); TAssoc_array& vars = ini.list_variables(); FOR_EACH_ASSOC_STRING(vars, obj, key, str) { if (*str == '"') { tmp = str; tmp.strip("\""); str = tmp; } doc.put(key, str); } const TString& cofi = doc.clifor().get(CLI_COFI); if (cofi.not_empty()) set(F_COFI, cofi); else { const TString& piva = doc.clifor().get(CLI_PAIV); set(F_COFI, piva); } for (int i = 1; ; i++) { para.format("%d,%d", LF_RIGHEDOC, i); if (!ini.set_paragraph(para)) break; const TString& tiporiga = ini.get(RDOC_TIPORIGA); TRiga_documento& rdoc = doc.new_row(tiporiga); TAssoc_array& vars = ini.list_variables(); FOR_EACH_ASSOC_STRING(vars, obj, key, str) { if (*str == '"') { tmp = str; tmp.strip("\""); str = tmp; } rdoc.put(key, str); } if (tiporiga.not_empty() && rdoc.is_articolo()) { TToken_string& row = sheet.row(-1); row = rdoc.get(RDOC_CODARTMAG); row.add(rdoc.get(RDOC_DESCR)); row.add(rdoc.get(RDOC_QTA)); row.add(rdoc.prezzo(TRUE, TRUE).string()); row.add("1"); } } _ini_loaded = sheet.items() > 0; return _ini_loaded; } bool TScontrino_mask::save_ini(KEY k) { bool ok = _ini_loaded && _ini_name.exist(); if (ok) { TConfig ini(_ini_name, "Main"); ini.set("Result", k == K_ENTER ? "OK" : "CANCEL"); ini.set("Error", "0"); const TRectype& eld = cache().get("%ELD", ini.get("Action")); const TString& stato_finale = eld.get("S4"); if (stato_finale.not_empty()) { TString16 para; para.format("%d", LF_DOC); ini.set(DOC_STATO, stato_finale, para); } } return ok; } bool TScontrino_mask::send_er400_data(bool extra) { /* TSheet_field& sheet = sfield(F_SHEET); const int rows = sheet.items(); if (rows <= 0) return FALSE; TMask m("Modalita' di pagamento", 1, 26, 8); m.add_radio(101, 0, "", 1, 0, 24, "CASH|TICK|ASS|CARD|CRT", "Contanti|Buoni|Assegno|Carta di Credito|Credito"); m.add_button(DLG_OK, 0, "", -12, -1, 10, 2); m.add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2); if (m.run() != K_ENTER) return FALSE; const char* server = "Sidcomm95"; const char* topic = server; // Ignoranza totale delle regole di buona programmazione DDE! TDDE smart; if (!smart.initiate(server, topic)) return error_box("Impossibile stabilire una comunicazione DDE con %s", server); TString80 cmd, tmp; const int text_len = extra ? 18 : 15; TParagraph_string para("", text_len); const int pos_descr = sheet.cid2index(F_DESCART); const int pos_prezzo = sheet.cid2index(F_PREZZO); const int pos_rep = sheet.cid2index(F_REPARTO); const int pos_qta = sheet.cid2index(F_QTA); for (int r = 0; r < rows; r++) { const TToken_string& row = sheet.row(r); cmd = "[PLU,"; row.get(pos_descr, tmp); if (tmp.blank()) continue; tmp.replace(',', ' '); tmp.replace('[', '('); tmp.replace(']', ')'); para = tmp; cmd << para.get(0); real price; row.get(pos_prezzo, price); cmd << ',' << price; int rep; row.get(pos_rep, rep); if (rep <= 0 || rep > 25) rep = 1; cmd << ',' << rep; real qta; row.get(pos_qta, qta); cmd << ',' << qta << ']'; smart.execute(cmd); } if (extra) { tmp = get(F_COFI); if (tmp.not_empty()) { cmd = "[CODF,"; cmd << get(F_COFI) << ']'; smart.execute(cmd); } para = get(F_SALUTI); if (!para.blank()) { for (int i = 1; i <= 2; i++) { tmp = para.get(); tmp.replace(',', ' '); tmp.replace('[', '('); tmp.replace(']', ')'); if (!tmp.blank()) { cmd.format("[TXT%d,%s]", i, (const char*)tmp); smart.execute(cmd); } } } } cmd = "["; cmd << m.get(101) << ']'; smart.execute(cmd); smart.terminate();*/ return TRUE; } bool TScontrino_mask::send_scr_data() { TSheet_field& sheet = sfield(F_SHEET); const int rows = sheet.items(); if (rows <= 0) return FALSE; ofstream o("input.scr"); o<<"$max_num_dept=20;"<