From 094571b2e0d22799e3228d43656b3386554d442a Mon Sep 17 00:00:00 2001 From: Simone Palacino Date: Thu, 27 Feb 2020 18:32:08 +0100 Subject: [PATCH] Patch level : 12.0 no-patch Files correlati : ps6215.exe Commento : Comari partite aperte --- src/ps/ps6215100.cpp | 406 ++++++++++++++++++++++++++++++++++++++--- src/ps/ps6215partite.h | 40 +++- 2 files changed, 416 insertions(+), 30 deletions(-) diff --git a/src/ps/ps6215100.cpp b/src/ps/ps6215100.cpp index 32bc7ee90..7a863f829 100644 --- a/src/ps/ps6215100.cpp +++ b/src/ps/ps6215100.cpp @@ -14,10 +14,103 @@ #include "sqlset.h" #include #include "ps6215partite.h" +#include +#include "scadenze.h" #define CLIFO_RECLEN 730 +struct part +{ + char _tipocf; + int _anno; + TString _numpart; + part(const char tipocf, const int anno, const TString numpart) : _tipocf(tipocf), _anno(anno), _numpart(numpart) { } +}; +//namespace Elem { +// +//struct mov_t +//{ +// // Keys +// int n_reg; +// TDate data_reg; +// // Attributes +// int tipo_mov; +// real importo; +//}; +// +//struct part_t +//{ +// // Keys +// int year; +// TString num; +// // Attributes +// mov_t capo_part; +// vector movs; +//}; +// +//} +// +//class TPartite_aperte +//{ +// +// /* Uso la chiave della partita stessa */ +// std::map, Elem::part_t> _parts; +// +//public: +// TPartite_aperte(); +//}; +// +// +///* Vogliono esportare solo le partite aperte al 31.12.2019. Quindi devo controllare +// * che le partite che risultano chiuse non abbiano delle registrazioni superiori al 31.12.2019 +// * altrimenti non devo tener conto di quel pagamento, e controllare poi se veramente chiusa. +// * Ma se semplicemente controllassi i movimenti senza prenderli copiarmeli?? +// */ +//TPartite_aperte::TPartite_aperte() +//{ +// TLocalisamfile part(LF_PARTITE); +// part.read(); +// for(bool ok = part.first(); ok; ok = part.next()) +// { +// if (part.get(PART_NUMPART) == "9999") // Salto la riga di saldo +// continue; +// +// Elem::part_t p; +// p.num = part.get(PART_NUMPART); +// p.year = part.get_int(PART_ANNO); +// +// std::pair key = { p.num, p.year }; +// auto it = _parts.find(key); +// // Se non esiste gia' la partita vuol dire che non ho ancora iniziato a caricarla +// if(it == _parts.end()) +// { +// _parts.insert({ key, p }); +// +// if ((it = _parts.find(key)) == _parts.end()) +// fatal_box("ERROR IN %s, %s", __FILE__, __LINE__); +// +// Elem::part_t& pa = it->second; +// // Leggo il capo partita (se c'e') +// const int tipo = part.get_int(PART_TIPOMOV); +// if (tipo == 1 || tipo == 2) // Fattura o NC +// { +// const Elem::mov_t m = { part.get_int(PART_NREG), part.get_int(PART_DATAREG), tipo, part.get_real(PART_IMPORTO) }; +// pa.capo_part = m; +// } +// } +// else +// { +// Elem::part_t& pa = it->second; +// const int tipo = part.get_int(PART_TIPOMOV); +// const Elem::mov_t m = { part.get_int(PART_NREG), part.get_int(PART_DATAREG), tipo, part.get_real(PART_IMPORTO) }; +// +// pa.movs.insert(pa.movs.end(), m); +// } +// } +// +// +//} class TFixed_record { @@ -228,19 +321,25 @@ void TComariExport_mask::load_all() class TComariExport_app : public TSkeleton_application { TString _fld_dest; + std::vector> _exported; + std::vector _chiuse; - bool export_all() const; + bool export_all(); static void add_to_record(char* record, TString& str, int len, int& index); static void export_clifo(ofstream& fout); - static void export_parti(ofstream& fout); - bool export_table(short id) const; + static void create_rec(int items, TLocalisamfile& part_rec, const char** fields, std::shared_ptr& rec); + void write_chiuse(ofstream& fout, int items, const int* dim_fields, const char** fields); + void add_chiusa(const TISAM_recordset& part_rec); + void export_parti(ofstream& fout); + void export_scadenze(ofstream& fout); + bool export_table(short id); public: bool create() override; void main_loop() override; TComariExport_app() = default; }; -bool TComariExport_app::export_all() const +bool TComariExport_app::export_all() { return export_table(F_CLIFOR) && @@ -414,12 +513,60 @@ void TComariExport_app::export_clifo(ofstream& fout) } } +void TComariExport_app::create_rec(int items, TLocalisamfile& part_rec, const char** fields, std::shared_ptr& rec) +{ + for (int _Idx = 0; _Idx < items; ++_Idx) + { + if (_Idx >= I_DATAREG && _Idx <= I_DATAPAG) + { + TDate date(part_rec.get(part_rec.get_date(fields[_Idx]))); + rec->set_str(_Idx, TString(date.date2ansi())); + } + else if (_Idx >= I_IMPORTO && _Idx <= I_RITSOC || _Idx == I_ABBUONI || _Idx == I_DIFFCAM) + rec->set_str(_Idx, part_rec.get_real(fields[_Idx]).string()); + else + rec->set_str(_Idx, part_rec.get(fields[_Idx])); + } +} + +void TComariExport_app::write_chiuse(ofstream& fout, int items, const int* dim_fields, const char** fields) +{ + std::shared_ptr rec = std::make_shared(items, dim_fields, fields); + for(auto& it : _chiuse) + { + TLocalisamfile part(LF_PARTITE); + part.setkey(1); + part.put(PART_TIPOCF, it._tipocf); + part.put(PART_ANNO, it._anno); + part.put(PART_NUMPART, it._numpart); + part.read(); + for(bool ok = true; ok; ok = part.next() == NOERR) + { + if(part.get_date(PART_DATAREG) > TDate(31, 12, 2019) || + part.get_int(PART_NRIGA) == 9999) // Per sicurezza :'( + break; + create_rec(items, part, fields, rec); + + fout << rec->get_line() << endl; + _exported.insert(_exported.end(), rec); + } + } +} + +void TComariExport_app::add_chiusa(const TISAM_recordset& part_rec) +{ + const int anno = part_rec.get(part_rec.find_column(PART_ANNO)).as_int(); + const TString npart = part_rec.get(part_rec.find_column(PART_NUMPART)).as_string(); + const char tipocf = part_rec.get(part_rec.find_column(PART_TIPOCF)).as_string()[0]; + _chiuse.insert(_chiuse.end(), part(tipocf, anno, npart)); +} + void TComariExport_app::export_parti(ofstream& fout) { const char* fields[] = { PART_ANNO, PART_NUMPART, PART_NRIGA, PART_TIPOCF, PART_SOTTOCONTO, PART_TIPOMOV, PART_TIPOPAG, PART_NREG, PART_NUMRIG, PART_DATAREG, PART_DATADOC, PART_DATAPAG, PART_NUMDOC, PART_REG, PART_PROTIVA, PART_CODCAUS, PART_SEZ, PART_IMPORTO, PART_IMPOSTA, PART_SPESE, PART_IMPTOTDOC, PART_RITENUTE, - PART_RITSOC, PART_SEZABB, PART_ABBUONI, PART_SEZDIFCAM, PART_DIFFCAM, PART_GRUPPOCL, PART_CONTOCL + PART_RITSOC, PART_SEZABB, PART_ABBUONI, PART_SEZDIFCAM, PART_DIFFCAM, PART_GRUPPOCL, PART_CONTOCL, PART_CHIUSA }; const int dim_fields[] = { D_ANNO, D_NUMPART, D_NRIGA, D_TIPOC, D_SOTTOCONTO, D_TIPOMOV, D_TIPOPAG, D_NREG, D_NUMRIG, D_DATAREG, D_DATADOC, @@ -428,51 +575,243 @@ void TComariExport_app::export_parti(ofstream& fout) }; TString4 last_game = ini_get_string(CONFIG_DITTA, "ps6215", "last_year_open_game", "2019"); - const string year = (const char*)last_game; + const string year((const char*)last_game); const int y = stol(year); if (y < 2000 || y > 2029) last_game = "2019"; ini_set_string(CONFIG_DITTA, "ps6215", "last_game", last_game); const int items = (int)(sizeof dim_fields / sizeof *dim_fields); - TString sql; sql << "SELECT "; - for (int i = 0; i < items - 1; ++i) - sql << fields[i] << ", "; - sql << fields[items - 1] << '\n'; - sql << " FROM part WHERE CHIUSA<>'X' AND ANNO <=" << last_game << ";"; - TSQL_recordset openpart(sql); + //TString sql; sql << "SELECT "; + //for (int i = 0; i < items - 1 + 1; ++i) // +1 perche' c'e' anche la colonna CHIUSA in fields + // sql << fields[i] << ", "; + //sql << fields[items - 1 +1] << '\n'; + //sql << "FROM part WHERE ANNO <=" << last_game << ";"; + //TSQL_recordset openpart(sql); + TISAM_recordset part_rec(R"(USE PART SELECT (ANNO<=2019)&&((CHIUSA!="X")||((CHIUSA=="X")&&(DATAREG>"31-12-2019")))&&(NRIGA!=9999))"); + + const int part_items = part_rec.items(); - if (!openpart.items()) + if (!part_items) message_box("Non ci sono partite aperte al %s da esportare.", (const char*)last_game); - else if(openpart.move_first()) + else if (part_rec.move_first()) { - TProgress_monitor bar(openpart.items(), "Esportazione Partite Aperte"); - for(bool ok = true; ok; ok = openpart.move_next()) + TProgress_monitor bar(part_items, "Esportazione Partite Aperte"); + std::vector> saved; + for (bool ok = true; ok; ok = part_rec.move_next()) { if (!bar.add_status()) break; - TFixed_record rec(items, dim_fields, fields); - for (int i = 0; i < items; ++i) + auto rec = std::make_shared(items, dim_fields, fields); + for (int idx = 0; idx < items; ++idx) { - if (openpart.column_info(i)._type == _datefld) + if (idx >= I_DATAREG && idx <= I_DATAPAG) { - TString ansi; ansi << TDate(openpart.get(i).as_date()).date2ansi(); - if(ansi != "0") // Butto le date "vuote" - rec.set_str(i, ansi); + TDate date(part_rec.get(part_rec.find_column(fields[idx])).as_date()); + rec->set_str(idx, TString(date.date2ansi())); } - else if(i >= I_IMPORTO && i <= I_RITSOC || i == I_ABBUONI || i == I_DIFFCAM) // reali (non so perche' ma becca come reali anche gli interi...) - rec.set_str(i, TString(openpart.get(i).as_real().string(18, 3, ' '))); + else if (idx >= I_IMPORTO && idx <= I_RITSOC || idx == I_ABBUONI || idx == I_DIFFCAM) + rec->set_str(idx, part_rec.get(part_rec.find_column(fields[idx])).as_real().string()); else - rec.set_str(i, openpart.get(i).as_string()); + rec->set_str(idx, part_rec.get(part_rec.find_column(fields[idx])).as_string()); } - fout << rec.get_line() << endl; + + if(!part_rec.get(part_rec.find_column(PART_CHIUSA)).as_bool()) + { + fout << rec->get_line() << endl; // Caso normale in cui e' aperta + _exported.insert(_exported.end(), rec); + } + else + add_chiusa(part_rec); + + //if (part_rec.get(PART_CHIUSA).as_bool()) // se partita chiusa controllo che la riga non superi il limite + //{ + // if (part_rec.get(PART_DATAREG).as_date() > TDate(31, 12, 2019)) + // { + // // La partita in realta' e' aperta + // // Non salvo questa ma scrivo tutte le altre; + // for (auto it = saved.begin(); it != saved.end(); ++it) + // fout << (*it)->get_line() << endl; + // _exported.insert(_exported.end(), saved.begin(), saved.end()); + // saved.clear(); // Svuoto il vettore temporaneo. + // // Mi sposto avanti finche' non trovo la riga di saldo. + // part_rec.move_next(); + // if (!bar.add_status()) + // break; + // while (part_rec.get(PART_NRIGA).as_int() != 9999) + // { + // part_rec.move_next(); + // if (!bar.add_status()) + // break; + // } + // continue; + // } + // if (part_rec.get(PART_NRIGA).as_int() == 9999) // Balzo, purtoppo puo' capitare di finire in questo caso... + // saved.clear(); // Svuoto il vettore temporaneo. + // else + // { + // // Quando e' chiusa e non supera il limite invece me le salvo momentaneamente + // saved.insert(saved.end(), rec); // Verranno scritte solo se in realta' e' aperta + // continue; + // } + //} + //if (part_rec.get(PART_NRIGA).as_int() == 9999) // Balzo + // continue; + + //if (part_rec.get(PART_DATAREG).as_date() <= TDate(31, 12, 2019)) + //{ + // fout << rec->get_line() << endl; // Caso normale in cui e' aperta + // _exported.insert(_exported.end(), rec); + //} } + write_chiuse(fout, items, dim_fields, fields); } else warning_box(TR("Impossibile leggere file partite aperte.")); + + //if (!openpart.items()) + // message_box("Non ci sono partite aperte al %s da esportare.", (const char*)last_game); + //else if(openpart.move_first()) + //{ + // TProgress_monitor bar(openpart.items(), "Esportazione Partite Aperte"); + // std::vector> saved; + // for (bool ok = true; ok; ok = openpart.move_next()) + // { + // if (!bar.add_status()) + // break; + // /*if (openpart.get(openpart.find_column(PART_CHIUSA)).as_bool() && + // openpart.get(openpart.find_column(PART_DATAREG)).as_date() > TDate(31, 12, 2019)) + // bool simo = true;*/ + // /* Esporto solo le righe che non sono registrazioni con datareg superiore al limite + // * e che non sono righe di saldo + // */ + // // Uso uno shared ptr altrimenti non potrei salvare nulla nel vector perche' a ogni ciclo il record verrebbe distrutto con tutti i suoi puntatori + // // in questo modo se ne occupa lo smart pointer di distruggerlo quando non ci sono piu' riferimenti. + // std::shared_ptr rec = std::make_shared(items, dim_fields, fields); + + // for (int i = 0; i < items; ++i) + // { + // if (openpart.column_info(i)._type == _datefld) + // { + // TString ansi; ansi << TDate(openpart.get(i).as_date()).date2ansi(); + // if (ansi != "0") // Butto le date "vuote" + // rec->set_str(i, ansi); + // } + // else if (i >= I_IMPORTO && i <= I_RITSOC || i == I_ABBUONI || i == I_DIFFCAM) // reali (non so perche' ma becca come reali anche gli interi...) + // rec->set_str(i, TString(openpart.get(i).as_real().string(18, 3, ' '))); + // else + // rec->set_str(i, openpart.get(i).as_string()); + // } + // if (openpart.get(openpart.find_column(PART_CHIUSA)).as_bool()) // se partita chiusa controllo che la riga non superi il limite + // { + // if (openpart.get(openpart.find_column(PART_DATAREG)).as_date() > TDate(31, 12, 2019)) + // { + // // La partita in realta' e' aperta + // // Non salvo questa ma scrivo tutte le altre; + // for(auto it = saved.begin(); it != saved.end(); ++it) + // fout << (*it)->get_line() << endl; + // _exported.insert(_exported.end(), saved.begin(), saved.end()); + // saved.clear(); // Svuoto il vettore temporaneo. + // // Mi sposto avanti finche' non trovo la riga di saldo. + // ok = openpart.move_next(); + // if (!bar.add_status()) + // break; + // while (ok && openpart.get(openpart.find_column(PART_NRIGA)).as_int() != 9999) + // { + // ok = openpart.move_next(); + // if (!bar.add_status()) + // break; + // } + // continue; + // } + // if (openpart.get(openpart.find_column(PART_NRIGA)).as_int() == 9999) // Balzo, purtoppo puo' capitare di finire in questo caso... + // saved.clear(); // Svuoto il vettore temporaneo. + // else + // { + // // Quando e' chiusa e non supera il limite invece me le salvo momentaneamente + // saved.insert(saved.end(), rec); // Verranno scritte solo se in realta' e' aperta + // continue; + // } + // } + // if (openpart.get(openpart.find_column(PART_NRIGA)).as_int() == 9999) // Balzo + // continue; + + // if (openpart.get(openpart.find_column(PART_DATAREG)).as_date() <= TDate(31, 12, 2019)) + // { + // fout << rec->get_line() << endl; // Caso normale in cui e' aperta + // _exported.insert(_exported.end(), rec); + // } + // } + //} + //else + // warning_box(TR("Impossibile leggere file partite aperte.")); } -bool TComariExport_app::export_table(const short id) const +void TComariExport_app::export_scadenze(ofstream& fout) +{ + const char* fields[] = { + SCAD_ANNO, SCAD_NUMPART, SCAD_NRIGA, SCAD_NRATA, SCAD_CODPAG, SCAD_TIPOPAG, SCAD_IMPORTO, SCAD_DATASCAD, SCAD_TIPOCF, + SCAD_SOTTOCONTO, SCAD_GGRIT, SCAD_PAGATA, SCAD_IMPORTOPAG, SCAD_IMPORTOANT, SCAD_CODABIPR, SCAD_CODCABPR, SCAD_CODABI, SCAD_CODCAB + }; + const int dim_fields[] = { + DS_ANNO, DS_NUMPART, DS_NRIGA, DS_NRATA, DS_CODPAG, DS_TIPOPAG, DS_IMPORTO, DS_DATASCAD, DS_TIPOCF, + DS_SOTTOCONTO, DS_GGRIT, DS_PAGATA, DS_IMPORTOPAG, DS_IMPORTOANT, DS_CODABIPR, DS_CODCABPR, DS_CODABI, DS_CODCAB + }; + // Esporto le scadenze per i documenti che ho esportato dalle partite + if(!_exported.empty()) + { + const int items = (int)(sizeof dim_fields / sizeof *dim_fields); + TProgress_monitor bar(_exported.size(), "Esportazione Scadenze"); + TString sql_fields; + for (int i = 0; i < items - 1; ++i) + sql_fields << fields[i] << ", "; + sql_fields << fields[items - 1] << '\n'; + for (auto it = _exported.begin(); it != _exported.end(); ++it) + { + if (!bar.add_status()) + break; + TFixed_record& part = *(*it); + const TFixed_string& tipocf = part[3]; + const TFixed_string& anno = part[0]; + TString numpart = (const char*)part[1]; + numpart.trim(); + const TFixed_string& nriga = part[2]; + TString sql; sql << "SELECT " << sql_fields << + "FROM scad WHERE TIPOC = '" << tipocf << "' AND ANNO = " << anno << " AND NRIGA = " << nriga << ";"; + TSQL_recordset scad(sql); + bool found = false; + for(bool ok = scad.move_first(); ok; ok = scad.move_next()) + { + if (scad.get(1).as_string() == numpart) + { + found = true; + TFixed_record rec(items, dim_fields, fields); + for (int i = 0; i < items; ++i) + { + if (scad.column_info(i)._type == _datefld) + { + TString ansi; ansi << TDate(scad.get(i).as_date()).date2ansi(); + if (ansi != "0") // Butto le date "vuote" + rec.set_str(i, ansi); + } + else if (i == IS_IMPORTO || i == IS_IMPORTOPAG || i == IS_IMPORTOANT) // reali (non so perche' ma becca come reali anche gli interi...) + rec.set_str(i, TString(scad.get(i).as_real().string(18, 3, ' '))); + else + rec.set_str(i, scad.get(i).as_string()); + } + fout << rec.get_line() << std::endl; + } + else + { + if (found) + break; + } + } + } + } +} + +bool TComariExport_app::export_table(const short id) { bool ok = false; ofstream fout; @@ -501,7 +840,16 @@ bool TComariExport_app::export_table(const short id) const export_parti(fout); fout.close(); } - name = "Clienti Fornitori"; + name_file = "scadenze.txt"; + path = _fld_dest; + path << "\\" << name_file; + fout.open(path, ios_base::out); + if ((ok = fout.is_open())) + { + export_scadenze(fout); + fout.close(); + } + name = "Partite aperte"; break; case F_PIANOCONTI: // Not implemented name_file = "pianoconti.txt"; @@ -516,7 +864,7 @@ bool TComariExport_app::export_table(const short id) const name = "Mastri"; break; } - TString msg; msg << "Esportazione " << name << (ok ? " " : " non ") << "completata.\nFile: " << (ok ? path : name_file); + TString msg; msg << "Esportazione " << name << (ok ? " " : " non ") << "completata."; if (ok) message_box(msg); else diff --git a/src/ps/ps6215partite.h b/src/ps/ps6215partite.h index f61bdb50f..8bc1d76ac 100644 --- a/src/ps/ps6215partite.h +++ b/src/ps/ps6215partite.h @@ -59,4 +59,42 @@ #define I_SEZDIFCAM 25 #define I_DIFFCAM 26 #define I_GRUPPOCL 27 -#define I_CONTOCL 28 \ No newline at end of file +#define I_CONTOCL 28 + +#define DS_ANNO 4 +#define DS_NUMPART 7 +#define DS_NRIGA 4 +#define DS_NRATA 4 +#define DS_CODPAG 4 +#define DS_TIPOPAG 1 +#define DS_IMPORTO 18 +#define DS_DATASCAD 8 +#define DS_TIPOCF 1 +#define DS_SOTTOCONTO 6 +#define DS_GGRIT 4 +#define DS_PAGATA 1 +#define DS_IMPORTOPAG 18 +#define DS_IMPORTOANT 18 +#define DS_CODABIPR 5 +#define DS_CODCABPR 5 +#define DS_CODABI 5 +#define DS_CODCAB 5 + +#define IS_ANNO 0 +#define IS_NUMPART 1 +#define IS_NRIGA 2 +#define IS_NRATA 3 +#define IS_CODPAG 4 +#define IS_TIPOPAG 5 +#define IS_IMPORTO 6 +#define IS_DATASCAD 7 +#define IS_TIPOCF 8 +#define IS_SOTTOCONTO 9 +#define IS_GGRIT 10 +#define IS_PAGATA 11 +#define IS_IMPORTOPAG 12 +#define IS_IMPORTOANT 13 +#define IS_CODABIPR 14 +#define IS_CODCABPR 15 +#define IS_CODABI 16 +#define IS_CODCAB 17