diff --git a/lv/lv1100.cpp b/lv/lv1100.cpp index fbd7560dc..9ab46229d 100755 --- a/lv/lv1100.cpp +++ b/lv/lv1100.cpp @@ -4,9 +4,12 @@ #include #include -#include - #include "lv1100a.h" +#include "../ve/velib.h" + +/////////////////////////////////////////////////////////// +// TStampaBuoni_mask +/////////////////////////////////////////////////////////// class TStampaBuoni_mask: public TAutomask { @@ -18,10 +21,12 @@ public: TStampaBuoni_mask::TStampaBuoni_mask() : TAutomask("lv1100a") { + // Riutilizza astutamente il titolo dell'applicazione per la maschera const TApplication& app = main_app(); - TConfig configlv(CONFIG_DITTA, "lv"); const TString& title = app.title(); set_caption(title); + + TConfig configlv(CONFIG_DITTA, "lv"); const char tipobuoni = app.argc() > 2 ? toupper(app.argv(2)[0]) : 'C'; switch (tipobuoni) { @@ -42,33 +47,41 @@ TStampaBuoni_mask::TStampaBuoni_mask() : TAutomask("lv1100a") } bool TStampaBuoni_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) -{ - return true; -} +{ return true; } -class TStampaBuoni_app: public TSkeleton_application -{ -protected: - virtual void main_loop(); - void elabora(const TMask& mask, const char action) const; -}; +/////////////////////////////////////////////////////////// +// TStampaBuoni_set +/////////////////////////////////////////////////////////// class TStampaBuoni_set : public TISAM_recordset { protected: + static bool status_filter(const TRelation* rel); virtual void set_custom_filter(TCursor& cursor) const; public: TStampaBuoni_set(const TMask& mask); }; +// Accetta solo i documenti stampabili in definitivo +bool TStampaBuoni_set::status_filter(const TRelation* rel) +{ + const TRectype& doc = rel->curr(); + const char stato_attuale = doc.get_char(DOC_STATO); + if (stato_attuale <= ' ') + return true; + + const TTipo_documento& tipo = cached_tipodoc(doc.get(DOC_TIPODOC)); + if (stato_attuale == tipo.stato_finale_stampa()) + return false; + + const TString& stati_stampa = tipo.stati_iniziali_stampa(); + return stati_stampa.blank() || stati_stampa.find(stato_attuale) >= 0; +} + void TStampaBuoni_set::set_custom_filter(TCursor& cursor) const { - if (cursor.items() > 0) - { - cursor = 0L; - const TString4 tipodoc = cursor.curr().get(DOC_TIPODOC); - } + cursor.set_filterfunction(status_filter); } TStampaBuoni_set::TStampaBuoni_set(const TMask& mask) : TISAM_recordset("USE DOC") @@ -93,45 +106,59 @@ TStampaBuoni_set::TStampaBuoni_set(const TMask& mask) : TISAM_recordset("USE DOC set_var("#CODITI_TO", TVariant(mask.get(F_CODITI_TO))); } +/////////////////////////////////////////////////////////// +// TStampaBuoni_app +/////////////////////////////////////////////////////////// + +class TStampaBuoni_app: public TSkeleton_application +{ +protected: + virtual void main_loop(); + void elabora(const TMask& mask, const char action) const; +}; void TStampaBuoni_app::elabora(const TMask& mask, const char action) const { TStampaBuoni_set buoni(mask); TCursor* c = buoni.cursor(); - TCursor_sheet sht(c, " |NDOC|DATADOC|4->S0[1,25]|CODCF|20->RAGSOC", TR("Selezione Documenti"), - HR("@1|Numero\nDoc.@7|Data\nDoc.@10|Stato@25|Cliente|Ragione Sociale@50")); - + TCursor_sheet sht(c, " |NDOC|DATADOC|4->S0[1,25]|G1:CODITI|CODCF|20->RAGSOC", TR("Selezione Documenti"), + HR("@1|Numero\nDoc.@7|Data\nDoc.@10|Stato@25|Itinerario|Cliente|Ragione Sociale@50")); + sht.check(-1); if (sht.run() && sht.one_checked()) { - const TDate data_from = mask.get_date(F_DATA_FROM); - TString80 chiavedoc = "D|"; - chiavedoc << data_from.year() << "|" << mask.get(F_CODNUM) << "|"; + TFilename tmp; + tmp.temp("", "ini"); - TFilename tmp; tmp.temp("", "ini"); - ofstream outf(tmp); - - outf << "[Transaction]" << endl; - outf << "Action=" << action << endl; - outf << "Mode=D" << endl; - outf << "[33]" << endl; + // Ensure that the ofstream is well closed before ve1 call + if (tmp.full()) // dummy test + { + const TDate data_from = mask.get_date(F_DATA_FROM); + const TString& cod_num = mask.get(F_CODNUM); + TString16 chiavedoc; // Parte della chiave comune a tutti i documenti + chiavedoc << "D|" << data_from.year() << "|" << cod_num << "|"; - long nx=0; + ofstream outf(tmp); + outf << "[Transaction]" << endl; // Transaction header + outf << "Action=" << action << endl; // 'P'rint or 'A'nteprint + outf << "Mode=D" << endl; // Definitive (always?) + outf << endl; + outf << "[33]" << endl; // Transaction body + long nx = 0; // Document counter + FOR_EACH_CHECKED_ROW(sht, i, row) + { + outf << "Doc(" << (nx++) << ")="; + outf << chiavedoc << row->get(1) << endl; + } + } - const long items = sht.items(); - for (long i = 0L; i