#include #include #include #include #include #include #include #include #include "ve4.h" #include "ve4300a.h" #include "../cg/cfban.h" #include #include /////////////////////////////////////////////////////////// // TAggiornaIBAN_msk /////////////////////////////////////////////////////////// class TAggiornaIBAN_msk : public TAutomask { TAssoc_array _iban; protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); const TString& get_iban(const TRectype& doc, TLog_report& log); public: bool elabora(); TAggiornaIBAN_msk() : TAutomask("ve4300a") {} }; const TString& TAggiornaIBAN_msk::get_iban(const TRectype& doc, TLog_report& log) { TToken_string key; key = doc.get(DOC_TIPOCF); key.add(doc.get(DOC_CODCF)); TString* iban = (TString*)_iban.objptr(key); if (iban != NULL) return *iban; iban = new TString80; _iban.add(key, iban); const TRectype& clifo = cache().get(LF_CLIFO, key); key.add("V"); key.add("1"); const TRectype& cfban = cache().get(LF_CFBAN, key); *iban = cfban.get(CFBAN_IBAN); if (iban->blank()) { *iban = clifo.get(CLI_IBAN); if (iban->blank()) { TString msg; msg << "Impossibile trovare un IBAN per " << clifo.get(CLI_RAGSOC); log.log(2, msg); } } return *iban; } bool TAggiornaIBAN_msk::elabora() { const bool definitiva = get_bool(F_DEFINITIVA); TLog_report log; TFast_isamfile docs(LF_DOC); TString query; query << "USE DOC SELECT BETWEEN(DATADOC,#DAL,#AL)&&BETWEEN(STATO,#STATO,#STATO)\n" << "FROM PROVV=D ANNO=#ANNO CODNUM=#CODNUM\n" << "TO PROVV=D ANNO=#ANNO CODNUM=#CODNUM"; const TDate dal = get(F_DAL); const TDate al = get(F_AL); TISAM_recordset recset(query); recset.set_var("#DAL", dal); recset.set_var("#AL", al); recset.set_var("#STATO", get(F_STATO)); recset.set_var("#ANNO", long(dal.year())); recset.set_var("#CODNUM", get(F_CODNUM)); const TRecnotype n = recset.items(); if (n > 0 && definitiva && !yesno_box("Confermare l'elaborazione di %ld documenti", n)) return false; if (n > 0) { TProgind pi(n, main_app().title()); TRectype& doc = recset.cursor()->curr(); TString msg, ibaner; TToken_string key; for (bool ok = recset.move_first(); ok; ok = recset.move_next()) { #ifdef DBG const long ndoc = doc.get_long(DOC_NDOC); if (ndoc == 82) int cazzone = 1; #endif const TString8 abi = doc.get(DOC_CODABIA); const TString8 cab = doc.get(DOC_CODCABA); const TString80 iban = doc.get(DOC_IBAN); if (abi.blank() && cab.blank()) { if (iban.full() && iban.len() < 24) { doc.zero(DOC_IBAN); if (definitiva) { int err = doc.rewrite(docs); if (err != NOERR) log.log(2, TR("Impossibile aggiornare il documento")); } } continue; } int err = iban_check(iban, ibaner); if (err == 0 && iban.starts_with("IT") && iban.mid(5, 5) == abi && iban.mid(10, 5) == cab) continue; key = doc.get(DOC_TIPOCF); key.add(doc.get(DOC_CODCF)); const TRectype& clifo = cache().get(LF_CLIFO, key); msg.cut(0) << doc.get(DOC_ANNO) << '/' << doc.get(DOC_CODNUM) << '/' << doc.get(DOC_NDOC) << ' ' << clifo.get(CLI_RAGSOC); log.log(1, msg); if (err != NOERR && iban.full()) { msg.cut(0) << '"' << iban << '"' << ' ' << ibaner; log.log(2, msg); } const TString& newiban = get_iban(doc, log); if (newiban == iban) continue; doc.put(DOC_IBAN, newiban); if (iban.starts_with("IT")) { doc.put(DOC_CODABIA, newiban.mid( 5,5)); doc.put(DOC_CODCABA, newiban.mid(10,5)); } msg.cut(0) << '"' << iban << '"' << " -> " << '"' << newiban << '"'; log.log(0, msg); if (definitiva) { err = doc.rewrite(docs); if (err != NOERR) log.log(2, TR("Impossibile aggiornare il documento")); } } } log.preview(); return true; } bool TAggiornaIBAN_msk::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case F_AL: if (e == fe_modify || e == fe_close) { const TDate dal = get(F_DAL); const TDate al = get(F_AL); if (!dal.ok() || !al.ok() || dal.year() != al.year() || dal > al) return error_box("Le date devono essere valide ed appartenere allo stesso anno"); } break; default: break; } return true; } /////////////////////////////////////////////////////////// // TAggiornaIBAN_app /////////////////////////////////////////////////////////// class TAggiornaIBAN_app : public TSkeleton_application { protected: virtual void main_loop(); }; void TAggiornaIBAN_app::main_loop() { TAggiornaIBAN_msk m; while (m.run() == K_ENTER) m.elabora(); } int ve4300(int argc, char* argv[]) { TAggiornaIBAN_app r; r.run(argc, argv, TR("Aggiornamento IBAN")); return 0; }