#include #include #include #include #include #include #include "cg5100a.h" class CG51_App : public TConfig_application { bool _change_pcon; TString16 _val; TArray _atts; void swap_file(int logicnum, bool tocom); void check_registers(int year); public: virtual bool preprocess_config (TMask& mask, TConfig& config); virtual bool postprocess_config (TMask& mask, TConfig& config); virtual bool postprocess_config_changed(const char* par, const char* var, const char* oldv, const char* newv); virtual bool user_create(); virtual bool user_destroy(); CG51_App() : TConfig_application(CONFIG_DITTA) {} virtual ~CG51_App() {} }; bool CG51_App::user_create() { _change_pcon = FALSE; TLocalisamfile attiv(LF_ATTIV); attiv.zero(); attiv.put(ATT_CODDITTA, get_firm()); TRectype r(attiv.curr()); for(attiv.read(_isgteq); attiv.status() == NOERR && attiv.curr() == r; attiv.next()) // istanzia array _atts on le attivita' della ditta corrente _atts.add(new TString(attiv.get(ATT_CODATT))); return TRUE; } void CG51_App::check_registers(int year) { // controlla che per ogni data attivita' esistano almeno un registro // acquisti, vendite e giornale; warning appropriato in caso negativo TTable reg("REG"); TRecfield reg_year(reg.curr(), "CODTAB", 0,3); const byte R_ACQ = 0x01; const byte R_VEN = 0x02; const byte R_ALL = R_ACQ | R_VEN; bool is_giornale = FALSE; byte flags = 0x00; for (int i = 0; i < _atts.items(); i++) { TString& att = (TString&)_atts[i]; for (reg.first(); !reg.eof(); reg.next()) { if (atoi(reg_year) == year && reg.get_int("I0") == 5) { is_giornale = TRUE; continue; } if (atoi(reg_year) != year || att != reg.get("S8")) continue; switch (reg.get_int("I0")) { case 1: // vendite flags |= R_VEN; break; case 2: // acquisti flags |= R_ACQ; break; } if (flags == R_ALL && is_giornale) break; } if (flags < R_ALL) { TString wrn("I seguenti registri non esistono per l'attivita' "); wrn << att << "(" << year << "):"; if ((flags & R_VEN) == 0x00) wrn << "\n\tregistro vendite"; if ((flags & R_ACQ) == 0x00) wrn << "\n\tregistro acquisti"; warning_box(wrn); } } // libro giornale non si controlla per attivita' if(!is_giornale) warning_box("Non esiste probabilmente nessun " "libro giornale per l'anno %d", year); } void CG51_App::swap_file(int logicnum, bool tocom) { TDir dir; TString file(16); dir.get(logicnum, _lock, _nordir, _sysdirop); file = dir.name(); file[0] = tocom ? '%' : '$'; dir.set(file, dir.eod(), dir.flags(), dir.des(), dir.expr()); dir.put(logicnum, _nordir, _sysdirop); dir.get(logicnum, _lock, (tocom ? _comdir :_nordir), _sysdirop); if (tocom) { file = dir.name(); file[0] = '%'; dir.set(file, dir.eod(), dir.flags(), dir.des(), dir.expr()); dir.put(logicnum, _comdir, _sysdirop); } if (dir.eox() == 0L) { TSystemisamfile s(logicnum); s.build(10L); } } bool CG51_App::user_destroy() { if (_change_pcon) { swap_file(LF_PCON, _val[0] == 'X'); swap_file(LF_CAUSALI, _val[0] == 'X'); swap_file(LF_RCAUSALI, _val[0] == 'X'); } return TRUE; } bool CG51_App::preprocess_config (TMask& mask, TConfig& config) { // these are disabled in normal applications TLocalisamfile mov(LF_MOV); const bool movempty = mov.empty(); mask.enable(CHK_ANCFCM, movempty); mask.enable(CHK_PCTCCM, movempty); disable_menu_item(M_FILE_NEW); disable_menu_item(M_FILE_REVERT); return TRUE; } bool CG51_App::postprocess_config(TMask& mask, TConfig& config) { enable_menu_item(M_FILE_NEW); enable_menu_item(M_FILE_REVERT); check_registers(mask.get_int(FLD_ANLIIV)); return TRUE; } bool CG51_App::postprocess_config_changed(const char* par, const char* var, const char* oldv, const char* newv) { TString v(var); if (v == "AnCfCm") { if (yesno_box("Confermi il cambiamento dell'anagrafica clienti/fornitori")) swap_file(LF_CLIFO, *newv == 'X'); else return FALSE; } else if (v == "PcTcCm") { if (yesno_box("Confermi il cambiamento del piano conti/causali")) { _change_pcon = TRUE; _val = newv; } else return FALSE; } return TRUE; } int cg5100 (int argc, char* argv[]) { CG51_App appc; appc.run(argc, argv, "Parametri Ditta"); return 0; }