diff --git a/sc/sc1200.cpp b/sc/sc1200.cpp index 67082009b..dd228f5d3 100755 --- a/sc/sc1200.cpp +++ b/sc/sc1200.cpp @@ -20,16 +20,13 @@ class TCreatepart_app : public TApplication { - TLocalisamfile* _conti; - TLocalisamfile* _partite; - TLocalisamfile* _scadenze; - TLocalisamfile* _pagsca; - TEsercizi_contabili _esc; bool _num_cli, _num_for; TString _desccl, _descfo; TDate _today; + TLocalisamfile* _conti; + protected: // Applicat virtual void on_firm_change(); virtual void on_config_change(); @@ -39,7 +36,8 @@ protected: // Applicat virtual bool menu(MENU_TAG m); protected: - bool zap_partite(); + void zap_file(int logicnum) const; + bool zap_partite() const; int crea_partite(int anno_es, int anno_rif, bool check); public: @@ -52,23 +50,17 @@ public: bool TCreatepart_app::create() { TApplication::create(); - - _conti = new TLocalisamfile(LF_PCON); - _partite = new TLocalisamfile(LF_PARTITE); - _scadenze = new TLocalisamfile(LF_SCADENZE); - _pagsca = new TLocalisamfile(LF_PAGSCA); - + + _conti = new TLocalisamfile(LF_PCON); + dispatch_e_menu(BAR_ITEM(1)); return TRUE; } bool TCreatepart_app::destroy() { - delete _conti; - delete _partite; - delete _scadenze; - delete _pagsca; - + delete _conti; + return TApplication::destroy(); } @@ -85,28 +77,45 @@ void TCreatepart_app::on_config_change() TPartita::carica_allineamento(); } -bool TCreatepart_app::zap_partite() -{ - bool first = TRUE; - for (_partite->first(); !_partite->eof(); _partite->next()) - { - if (first) - { - bool ok = yesno_box("Il saldaconto non e' vuoto." - " La procedura lo azzera completamente." - " Si desidera proseguire?"); - if (ok) - ok = yesno_box("Confermare l'azzeramento del saldaconto esistente"); - if (!ok) - return FALSE; - first = FALSE; - } +void TCreatepart_app::zap_file(int logicnum) const +{ + TDir dir; + dir.get(logicnum, _lock, _nordir, _sysdirop); + dir.eod() = 0; + dir.put(logicnum, _nordir, _sysdirop); + + TSystemisamfile f(logicnum); + f.pack(); +} + +bool TCreatepart_app::zap_partite() const +{ + bool ok = TRUE; + + TSystemisamfile partite(LF_PARTITE); + partite.open(); + bool zap = partite.items() != 0; + partite.close(); + + if (zap) + { + zap = yesno_box("Il saldaconto non e' vuoto.\n" + "La procedura lo azzera completamente.\n" + "Si desidera proseguire?"); + if (zap) + zap = yesno_box("Confermare l'azzeramento del saldaconto esistente"); - TPartita game(_partite->curr()); - game.remove(); + if (zap) + { + zap_file(LF_PARTITE); + zap_file(LF_SCADENZE); + zap_file(LF_PAGSCA); + } + else + ok = FALSE; } - return TRUE; + return ok; } @@ -123,7 +132,7 @@ char TCreatepart_app::is_clifo(int g, int c, int& indbil) } const char cf = _conti->get_char(PCN_TMCF); - indbil = _conti->get_int(PCN_INDBIL); + indbil = _conti->get_int(PCN_INDBIL); return cf; } @@ -140,6 +149,11 @@ int TCreatepart_app::crea_partite(int anno_es, int anno_rif, bool check) return -1; begin_wait(); + + // Apre i files per usarli con l'oggetto TPartita + TLocalisamfile partite(LF_PARTITE); + TLocalisamfile scadenze(LF_SCADENZE); + TLocalisamfile pagamenti(LF_PAGSCA); int n_part = 0; TProgind prind(items, "Creazione saldaconto", FALSE, TRUE, 45); @@ -193,9 +207,9 @@ int TCreatepart_app::crea_partite(int anno_es, int anno_rif, bool check) const int g = riga.get_int(PART_GRUPPOCL); const int c = riga.get_int(PART_CONTOCL); if (gruppo == g && conto == c) - break; + break; // Esiste gia' una riga con questo conto } - if (p > 0) + if (p > 0) // Il cliente esiste gia', per cui ignoro il saldo continue; } @@ -208,17 +222,17 @@ int TCreatepart_app::crea_partite(int anno_es, int anno_rif, bool check) riga.put(PART_DESCR, cf == 'C' ? _desccl : _descfo); // cazzata dare/avere/fare/baciare/cagare - const int tipo = (cf == 'C' ? (saldo.sezione() == 'D' ? 1 : 2) : - (saldo.sezione() == 'D' ? 2 : 1)); + const tipo_movimento tipo = (cf == 'C' ? (saldo.sezione() == 'D' ? tm_fattura : tm_nota_credito) : + (saldo.sezione() == 'D' ? tm_nota_credito : tm_fattura)); - riga.put(PART_TIPOMOV, tipo); + riga.put(PART_TIPOMOV, (int)tipo); - if (tipo == 1) + if (tipo == tm_fattura) { TRiga_scadenze& scad = riga.new_row(); scad.put(SCAD_IMPORTO, saldo.valore()); scad.put(SCAD_DATASCAD, _today); - scad.put(SCAD_TIPOPAG, 1); + scad.put(SCAD_TIPOPAG, 1); // rimessa diretta } else { @@ -281,11 +295,10 @@ bool TCreatepart_app::menu(MENU_TAG) else message_box("Nessun saldo presente per l'esercizio %d", anno_es); - if (n_part > 0) + if (n_part > 0) // May be -1 m.set(F_NUMPART, n_part); else - m.reset(F_NUMPART); - + m.reset(F_NUMPART) ; } // while run return FALSE; diff --git a/sc/sc2100.cpp b/sc/sc2100.cpp index 1aec8233d..2b859280b 100755 --- a/sc/sc2100.cpp +++ b/sc/sc2100.cpp @@ -10,9 +10,11 @@ #include "sc2101.h" #include "sc2100a.h" +#include "sc21pec.h" #include #include +#include #include /////////////////////////////////////////////////////////// @@ -22,13 +24,13 @@ class TTotalizer : public TAssoc_array { public: - void add(const TImporto& imp, const char* val); + void add(const TImporto& imp, const TString& val); TTotalizer() { } virtual ~TTotalizer() { } }; -void TTotalizer::add(const TImporto& imp, const char* val) +void TTotalizer::add(const TImporto& imp, const TString& val) { TString16 codice(val); if (codice == "LIT") @@ -57,18 +59,25 @@ class TEC_form : public TForm TCursor* _cursore; TTotalizer _totali; TDecoder _causali; + + TString _lingua; + TDate _dlo, _dls; protected: static void ec_header_handler(TPrinter& p); static void ec_footer_handler(TPrinter& p); - + public: TTotalizer& totali() { return _totali; } TDecoder& causali() { return _causali; } + + const TDate& data_limite_operazione() const { return _dlo; } + const TDate& data_limite_scaduto() const { return _dls; } + const TString& lingua() const { return _lingua; } bool print_game(const TPartita& game); - TEC_form(const char* codice, TCursor* cursor); + TEC_form(const TEC_mask& m); virtual ~TEC_form(); }; @@ -83,6 +92,7 @@ class TEC_row : public TSortable { TDate _data; int _riga; + int _rata; TString _causale; TString _descrizione; @@ -91,50 +101,64 @@ class TEC_row : public TSortable TString _num_doc; long _num_prot; TImporto _importo; + TImporto _importo_lire; + real _scaduto; + real _totale; TValuta _valuta; - TImporto _totale_doc; protected: // TSortable virtual int compare(const TSortable& s) const; public: void descrizione(const char* s) { _descrizione = s; } + void scaduto(const real& s) { _scaduto = s; } const TValuta& valuta() const { return _valuta; } const TImporto& importo() const { return _importo; } + const TDate& data() const { return _data; } void print_on(TPrint_section& body); - TEC_row(const TRiga_partite& row, const TDate& data, const TImporto& imp, int riga); + TEC_row(const TRiga_partite& row, const TDate& data, const TImporto& imp, int rata); TEC_row(const char* desc, const TImporto& imp); virtual ~TEC_row() {} }; -TEC_row::TEC_row(const TRiga_partite& row, const TDate& data, const TImporto& imp, int riga) - : _riga(riga), _num_prot(0) -{ +TEC_row::TEC_row(const TRiga_partite& row, const TDate& data, const TImporto& imp, int rata) + : _num_prot(0) +{ + _riga = row.get_int(PART_NRIGA); + _rata = rata; + _data = data; _causale = row.get(PART_CODCAUS); _data_doc = row.get(PART_DATADOC); _num_prot = row.get_long(PART_PROTIVA); + _importo = imp; _importo.normalize(); + _totale = row.get_real(PART_IMPTOTPAG); + _valuta.get(row); - _importo = imp; -// _totale = row.get_long(???); } TEC_row::TEC_row(const char* desc, const TImporto& imp) - : _riga(0), _num_prot(0) + : _num_prot(0) { _descrizione = desc; - _importo = imp; + _importo = imp; _importo.normalize(); } +// Le righe dell'estratto conto sono ordinate per data, riga partita, numero rata, +// posizione iniziale nell'array (in caso di uguaglianza di tutto il resto) int TEC_row::compare(const TSortable& s) const { const TEC_row& r = (const TEC_row&)s; int c = 0; if (_data == r._data) + { c = r._riga - _riga; + if (c == 0) + c = r._rata - _rata; + } else c = _data < r._data ? +1 : -1; return c; @@ -144,86 +168,55 @@ void TEC_row::print_on(TPrint_section& body) { TEC_form& form = (TEC_form&)body.form(); - body.reset(); - - if (_causale.not_empty()) + TForm_item& causale = body.find_field(PEC_CODCAUS); + causale.set(_causale); + if (_causale.not_empty() && _descrizione.empty()) { - TForm_item& causale = body.find_field(201); - causale.set(_causale); - - if (_descrizione.empty()) - { - TDecoder& causali = form.causali(); - _descrizione = causali.decode(_causale); - } + TDecoder& causali = form.causali(); + _descrizione = causali.decode(_causale); } - if (_descrizione.not_empty()) - { - TForm_item& descr = body.find_field(202); - descr.set(_descrizione); - } + TForm_item& descr = body.find_field(PEC_DESCR1); + descr.set(_descrizione); - if (_data_doc.ok()) - { - TForm_item& datadoc = body.find_field(203); - datadoc.set(_data_doc.string()); - } + TForm_item& datadoc = body.find_field(PEC_DATADOC); + datadoc.set(_data_doc.string()); - if (_num_doc.not_empty()) - { - TForm_item& numdoc = body.find_field(204); - numdoc.set(_num_doc); - } + TForm_item& numdoc = body.find_field(PEC_NUMDOC); + numdoc.set(_num_doc); - if (_num_prot != 0) - { - TForm_item& numprot = body.find_field(205); - TString16 protiva; protiva << _num_prot; - numprot.set(protiva); - } + TForm_item& numprot = body.find_field(PEC_PROTIVA); + TString16 protiva; protiva << _num_prot; + numprot.set(protiva); - if (_data.ok()) - { - TForm_item& datapag = body.find_field(207); - datapag.set(_data.string()); - } + TForm_item& datapag = body.find_field(PEC_DATAPAG); + datapag.set(_data.string()); const real& imp = _importo.valore(); - if (!imp.is_zero()) - { - TForm_item& dare = body.find_field(208); - TForm_item& avere = body.find_field(209); + TForm_item& dare = body.find_field(PEC_DARE); + TForm_item& avere = body.find_field(PEC_AVERE); - if (_importo.sezione() == 'D') - { - dare.set(imp.string()); - avere.set(""); - } - else - { - avere.set(imp.string()); - dare.set(""); - } + if (_importo.sezione() == 'D') + { + dare.set(imp.string()); + avere.set(""); } + else + { + avere.set(imp.string()); + dare.set(""); + } - if (!_valuta.in_lire()) - { - TForm_item& cambio = body.find_field(212); - cambio.set(_valuta.cambio().string()); + TForm_item& scaduto = body.find_field(PEC_SCADUTO); + scaduto.set(_scaduto.string()); + + TForm_item& cambio = body.find_field(PEC_CAMBIO); + cambio.set(_valuta.cambio().string()); - if (_valuta.data().ok()) - { - TForm_item& datacambio = body.find_field(213); - datacambio.set(_valuta.data().string()); - } - } + TForm_item& datacambio = body.find_field(PEC_DATACAM); + datacambio.set(_valuta.data().string()); body.update(); - - TPrinter& pr = printer(); - for (word j = 0; j < body.height(); j++) - pr.print(body.row(j)); } /////////////////////////////////////////////////////////// @@ -235,20 +228,48 @@ class TEC_array : public TArray const TEC_form* _form; protected: - TEC_row& new_row(const TRiga_partite& row, const TDate& data, const TImporto& imp); + TEC_row& new_row(const TRiga_partite& row, const TDate& data, const TImporto& imp, int rata = 0); void add_row(const TRiga_partite& row); + + const TEC_form& form() const { return *_form; } + void calcola_scaduto(const TRiga_scadenze& rata, real& scaduto) const; public: - TEC_row& row(int r) { return (TEC_row&)operator[](r); } - const TEC_form& form() const { return *_form; } + TEC_row& row(int r) const { return (TEC_row&)operator[](r); } TEC_array(const TPartita& game, const TEC_form* f); virtual ~TEC_array() {} }; -TEC_row& TEC_array::new_row(const TRiga_partite& row, const TDate& data, const TImporto& imp) -{ - const int n = items(); +void TEC_array::calcola_scaduto(const TRiga_scadenze& rata, real& scaduto) const +{ + const TPartita& game = rata.partita(); + TImporto imp_scaduto = rata.importo(TRUE); + + const char* const field = rata.in_valuta() ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO; + TImporto imp; + + for (int p = rata.last(); p > 0; p = rata.pred(p)) + { + const TRectype& pag = rata.row(p); + const TRiga_partite& sum = game.riga(pag.get_int(PAGSCA_NRIGP)); + const tipo_movimento tm = sum.tipo(); + if (tm != tm_insoluto && tm != tm_pagamento_insoluto) + { + imp.set(sum.sezione(), pag.get_real(field)); + imp_scaduto += imp; + } + } + const char sezione = game.conto().tipo() == 'C' ? 'D' : 'A'; + imp_scaduto.normalize(sezione); + scaduto = imp_scaduto.valore(); +} + +TEC_row& TEC_array::new_row(const TRiga_partite& row, const TDate& data, + const TImporto& imp, int n) +{ + if (n == 0) + n = items(); TEC_row* riga = new TEC_row(row, data, imp, n); add(riga, n); return *riga; @@ -261,31 +282,42 @@ void TEC_array::add_row(const TRiga_partite& row) for (int r = 1; r <= row.rate(); r++) { const TRiga_scadenze& rata = row.rata(r); - const TImporto imp(row.sezione(), rata.get_real(PART_IMPORTO)); const TDate data(rata.get(SCAD_DATASCAD)); - new_row(row, data, imp); + if (data <= form().data_limite_operazione()) + { + TEC_row& rec = new_row(row, data, rata.importo(TRUE), r); + if (data <= form().data_limite_scaduto()) + { + real s; + calcola_scaduto(rata, s); + rec.scaduto(s); + } + } } } else { - const TImporto imp(row.sezione(), row.get_real(PART_IMPORTO)); const TDate data(row.get(PART_DATAPAG)); - new_row(row, data, imp); - - const TImporto abbuoni(row.get_char(PART_SEZABB), row.get_real(PART_ABBUONI)); - if (!abbuoni.is_zero()) - { - TEC_row& r = new_row(row, data, abbuoni); - const TForm_item& desc_abb = form().find_field('B', odd_page, 302); - r.descrizione(desc_abb.prompt()); - } + if (data <= form().data_limite_operazione()) + { + const TImporto imp(row.importo(FALSE, 0x1)); + new_row(row, data, imp); - const TImporto diffcam(row.get_char(PART_SEZDIFCAM), row.get_real(PART_DIFFCAM)); - if (!diffcam.is_zero()) - { - TEC_row& r = new_row(row, data, diffcam); - const TForm_item& desc_dif = form().find_field('B', odd_page, 303); - r.descrizione(desc_dif.prompt()); + const TImporto abbuoni(row.importo(FALSE, 0x2)); + if (!abbuoni.is_zero()) + { + TEC_row& r = new_row(row, data, abbuoni); + const TForm_item& desc_abb = form().find_field('B', odd_page, 302); + r.descrizione(desc_abb.prompt()); + } + + const TImporto diffcam(row.importo(FALSE, 0x4)); + if (!diffcam.is_zero()) + { + TEC_row& r = new_row(row, data, diffcam); + const TForm_item& desc_dif = form().find_field('B', odd_page, 303); + r.descrizione(desc_dif.prompt()); + } } } } @@ -306,7 +338,6 @@ TEC_array::TEC_array(const TPartita& game, const TEC_form* f) void TEC_form::ec_header_handler(TPrinter& pr) { TPrint_section& head = _form->section('H'); - head.reset(); pr.resetheader(); @@ -315,12 +346,51 @@ void TEC_form::ec_header_handler(TPrinter& pr) pr.setheaderline(j, head.row(j)); } +static int val_compare(const void* o1, const void* o2) +{ + const THash_object* h1 = (const THash_object*)o1; + const THash_object* h2 = (const THash_object*)o2; + const TString& s1 = (const TString&)h1->obj(); + const TString& s2 = (const TString&)h2->obj(); + return s2.compare(s1, -1, TRUE); // same as stricmp(s1, s2) in reverse order +} -void TEC_form::ec_footer_handler(TPrinter& p) +void TEC_form::ec_footer_handler(TPrinter& pr) { - TRACE("Stamperei un footer"); + TPrint_section& foot = _form->section('F'); + pr.resetfooter(); + + const word MAXTOT = 32; + THash_object* tot[MAXTOT]; + + // I totali sono in un assoc array disordinato per cui li copio in un array e li ordino + // alfabeticamente in base al loro codice valuta + TTotalizer& totali = _form->totali(); + totali.restart(); + + word numtot = 0; + for (THash_object* obj = totali.get_hashobj(); + numtot < MAXTOT && obj != NULL; + obj = totali.get_hashobj()) + tot[numtot++] = obj; + qsort(tot, numtot, sizeof(THash_object*), val_compare); + + if (numtot > foot.height()) + numtot = foot.height(); + + TPrint_section& body = _form->section('B'); + for (word j = 0; j < numtot; j++) + { + const TString& key = tot[j]->key(); + TImporto& imp = (TImporto&)tot[j]->obj(); + TEC_row r(key, imp.normalize()); + r.print_on(body); + const TPrintrow& ri = body.row(0); + pr.setfooterline(j, ri); + } } + bool TEC_form::print_game(const TPartita& game) { bool ok = FALSE; @@ -337,11 +407,13 @@ bool TEC_form::print_game(const TPartita& game) // Stampa le righe di partita for (int r = 0; r < righe.items(); r++) { + TEC_row& riga = righe.row(r); + if (pr.rows_left() < body.height()) pr.formfeed(); - TEC_row& riga = righe.row(r); riga.print_on(body); + pr.print(body.row(0)); totali().add(riga.importo(), riga.valuta().codice()); @@ -364,13 +436,20 @@ bool TEC_form::print_game(const TPartita& game) return ok; } -TEC_form::TEC_form(const char* codice, TCursor* cur) - : TForm(BASE_EC_PROFILE, codice), +TEC_form::TEC_form(const TEC_mask& m) + : TForm(BASE_EC_PROFILE, m.get_prof_code()), _causali(LF_CAUSALI, CAU_CODCAUS, CAU_DESCR) { _form = this; - _cursore = cur; - + + _lingua = m.get_prof_lang(); + + TCursor_sheet& cs = m.cur_sheet(); + _cursore = cs.cursor(); + + _dlo = m.get(F_DATALIMOP); + _dls = m.get(F_DATALIMSC); + TPrinter& pr = printer(); pr.setheaderhandler(ec_header_handler); @@ -430,8 +509,7 @@ class TStampaEC_application : public TApplication TFile_array _file; - TString _lingua; - TString _linprof; + TString _lingua_ditta; bool _gesval; protected: // TApplication @@ -461,8 +539,7 @@ bool TStampaEC_application::select_ec() TEC_mask& m = mask(); while (m.run() != K_ESC) { - _linprof = m.get_prof_lang(); - _form = new TEC_form(m.get_prof_code(), sheet().cursor()); + _form = new TEC_form(m); print_selected(); @@ -500,7 +577,7 @@ bool TStampaEC_application::print_selected() const bool ok = print_ec(); if (!ok) analfabeti++; } - + printer().formfeed(); printer().close(); if (analfabeti > 0) @@ -520,8 +597,8 @@ bool TStampaEC_application::print_ec() bool ok = TRUE; // make controllations per lingua profilo/CF - if ((_linprof == _lingua && !lincf.empty()) || _linprof != _lingua) - ok = lincf == _linprof; + if ((f.lingua() == _lingua_ditta && !lincf.empty()) || f.lingua() != _lingua_ditta) + ok = lincf == f.lingua(); if (!ok) // Cliente analfabeta return FALSE; @@ -611,7 +688,7 @@ void TStampaEC_application::on_firm_change() { TApplication::on_firm_change(); TConfig c(CONFIG_DITTA, "cg"); - _lingua = c.get("CodLin"); + _lingua_ditta = c.get("CodLin"); _gesval = c.get_bool("GesVal"); } @@ -622,7 +699,7 @@ bool TStampaEC_application::menu(MENU_TAG m) } TStampaEC_application::TStampaEC_application() - : _lingua(1), _linprof(1), _msk(NULL), _form(NULL) + : _lingua_ditta(1), _msk(NULL), _form(NULL) {} int sc2100(int argc, char** argv) diff --git a/sc/scselect.cpp b/sc/scselect.cpp index cd60aeb5f..2aa3b89e4 100755 --- a/sc/scselect.cpp +++ b/sc/scselect.cpp @@ -1,296 +1,299 @@ -#include "scselect.h" - -/////////////////////////////////////////////////////////////////////////////// -// TSelection_mask // -/////////////////////////////////////////////////////////////////////////////// - -TSelection_mask::TSelection_mask(const char* name) - : TMask(name), _who('C'), _key(1), _clifo_rel(NULL), - _cli_cur_k1(NULL), _cli_cur_k2(NULL), _for_cur_k1(NULL), _for_cur_k2(NULL) -{ - // crea relazioni, cursori e cursor_sheets - _clifo_rel = new TRelation(LF_CLIFO); - - _cli_cur_k1 = new TCursor(_clifo_rel, "TIPOCF=\"C\"", 1); - _cli_cur_k2 = new TCursor(_clifo_rel, "TIPOCF=\"C\"", 2); - - - _cli_sh_k1 = new TCursor_sheet(_cli_cur_k1, " |CODCF|RAGSOC", "Selezione clienti per codice", - "@1|Codice|Ragione Sociale@50"); - _cli_sh_k2 = new TCursor_sheet(_cli_cur_k2, " |RAGSOC|CODCF", "Selezione clienti per ragione sociale", - "@1|Ragione Sociale@50|Codice"); - - if (id2pos(SC_CLIFO) >= 0) - { - _for_cur_k1 = new TCursor(_clifo_rel, "TIPOCF=\"F\"", 1); - _for_cur_k2 = new TCursor(_clifo_rel, "TIPOCF=\"F\"", 2); - _for_sh_k1 = new TCursor_sheet(_for_cur_k1, " |CODCF|RAGSOC", "Selezione fornitori per codice", - "@1|Codice|Ragione Sociale@50"); - _for_sh_k2 = new TCursor_sheet(_for_cur_k2, " |RAGSOC|CODCF", "Selezione fornitori per ragione sociale", - "@1|Ragione Sociale@50|Codice"); - } - - set_handler(SC_CLIFO, rclifo_handler); - set_handler(SC_SORTCF, rsortcf_handler); - set_handler(SC_CFBUTFR, bfrom_handler); - set_handler(SC_CFBUTTO, bto_handler); - set_handler(SC_SELECT, bselect_handler); - set_handler(SC_RESET, breset_handler); - set_handler(SC_CFCODFR, ffrom_handler); - set_handler(SC_CFCODTO, fto_handler); -} - -TSelection_mask::~TSelection_mask() -{ - delete _for_sh_k2; - delete _for_sh_k1; - delete _for_cur_k2; - delete _for_cur_k1; - - delete _cli_sh_k2; - delete _cli_sh_k1; - delete _cli_cur_k2; - delete _cli_cur_k1; - - delete _clifo_rel; -} - -void TSelection_mask::set_handler(short fld_id, CONTROL_HANDLER handler) -{ - const int pos = id2pos(fld_id); - if (pos >= 0) - fld(pos).set_handler(handler); -} - -TCursor_sheet& TSelection_mask::cur_sheet() -{ - TCursor_sheet* cs; - if (get_key() == 1) cs = get_who() == 'C' ? _cli_sh_k1 : _for_sh_k1; - else cs = get_who() == 'C' ? _cli_sh_k2 : _for_sh_k2; - - CHECK(cs, "Can't use a NULL TCursor_sheet"); - return *cs; -} - -void TSelection_mask::reset_sheets() -{ - _cli_sh_k1->uncheck(-1); - _cli_sh_k2->uncheck(-1); - if (_for_sh_k1) - { - _for_sh_k1->uncheck(-1); - _for_sh_k2->uncheck(-1); - } - reset(SC_CFCODFR); - reset(SC_CFCODTO); - reset(SC_NSEL); -} - - -// Seleziona tutti i clienti con codice compreso tra due estremi -void TSelection_mask::select_clifo_range(long from, long to) -{ - TCursor_sheet& c = cur_sheet(); - const long items = c.items(); - const int key = get_key(); - - long nsel = 0; - - if (to == 0l) - to = c.row(items-1).get_long(key); - if (from == 0l) - from = c.row(0).get_long(key); - - if (from > to) - { - long tmp = to; - to = from; - from = tmp; - } - - bool go = FALSE; - bool cod1ok = FALSE, cod2ok = FALSE; - long last = 0l; - long firs = 0l; - - for (long i = 0; i < items; i++) - { - TToken_string& tt = c.row(i); - long cod = tt.get_long(key); - if (cod >= from && cod <= to) - { - c.check(i); - nsel ++; - if (firs == 0l) firs = cod; - last = cod; - } - else - { - c.uncheck(i); - } - if (cod == from) cod1ok = TRUE; - if (cod == to) cod2ok = TRUE; - } - - if (!cod1ok) from = firs; - if (!cod2ok) to = last; - - set(SC_CFCODFR, from); - set(SC_CFCODTO, to); - set(SC_NSEL, nsel); -} - -// Cerca il primo e l'ultimo cliente selezionati -void TSelection_mask::set_clifo_limits() -{ - long first = 0, last = 0, nsel = 0; - - TCursor_sheet& c = cur_sheet(); - const long items = c.items(); - const int key = get_key(); - - for (int i = 0; i < items; i++) if (c.checked(i)) - { - TToken_string& t = c.row(i); - const long kod = t.get_long(key); - if (first == 0) - { - first = last = kod; - } - else - { - if (first > kod) first = kod; - if (last < kod) last = kod; - } - - nsel++; - } - set(SC_CFCODFR, first); - set(SC_CFCODTO, last); - set(SC_NSEL, nsel); -} - -// handlers -bool TSelection_mask::bfrom_handler(TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - TSelection_mask& m = (TSelection_mask&)f.mask(); - TCursor_sheet& c = m.cur_sheet(); - - c.disable_check(); - if (c.run() == K_ENTER) - { - TToken_string& t = c.row(c.selected()); - const long cod1 = t.get_long(m.get_key()); - const long cod2 = m.get_long(SC_CFCODTO); - m.set(SC_CFCODFR, cod1); - m.select_clifo_range(cod1, cod2); - } - } - return TRUE; -} - -bool TSelection_mask::bto_handler(TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - TSelection_mask& m = (TSelection_mask&)f.mask(); - TCursor_sheet& c = m.cur_sheet(); - c.disable_check(); - if (c.run() == K_ENTER) - { - TToken_string& t = c.row(c.selected()); - const long cod2 = t.get_long(m.get_key()); - const long cod1 = m.get_long(SC_CFCODFR); - m.set(SC_CFCODTO, cod2); - m.select_clifo_range(cod1, cod2); - } - } - return TRUE; -} - -bool TSelection_mask::ffrom_handler(TMask_field& f, KEY k) -{ - TSelection_mask& m = (TSelection_mask&)f.mask(); - - if (k == K_TAB && f.focusdirty()) - { - const long cod1 = atol(f.get()); - const long cod2 = m.get_long(SC_CFCODTO); - m.select_clifo_range(cod1, cod2); - } - else - if (k == K_F9) - { - TMask_field& f = m.field(SC_CFBUTFR); - f.on_hit(); - } - - return TRUE; -} - -bool TSelection_mask::fto_handler(TMask_field& f, KEY k) -{ - TSelection_mask& m = (TSelection_mask&)f.mask(); - - if (k == K_TAB && f.focusdirty()) - { - const long cod1 = m.get_long(SC_CFCODFR); - const long cod2 = atol(f.get()); - m.select_clifo_range(cod1, cod2); - } - else - if (k == K_F9) - { - TMask_field& f = m.field(SC_CFBUTTO); - f.on_hit(); - } - return TRUE; -} - -bool TSelection_mask::breset_handler(TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - TSelection_mask& m = (TSelection_mask&)f.mask(); - m.reset_sheets(); - } - return TRUE; -} - -bool TSelection_mask::bselect_handler(TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - TSelection_mask& m = (TSelection_mask&)f.mask(); - TCursor_sheet& c = m.cur_sheet(); - c.enable_check(); - c.run(); - m.set_clifo_limits(); - } - return TRUE; -} - -bool TSelection_mask::rclifo_handler(TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - TSelection_mask& m = (TSelection_mask&)f.mask(); - m.set_who(f.get()[0]); - m.reset_sheets(); - } - return TRUE; -} - -bool TSelection_mask::rsortcf_handler(TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - TSelection_mask& m = (TSelection_mask&)f.mask(); - m.set_key(atoi(f.get())); - m.reset_sheets(); - } - return TRUE; -} - + +#include "scselect.h" + +TSelection_mask::TSelection_mask(const char* name) + : TMask(name), _who('C'), _key(1), _clifo_rel(NULL), + _cli_cur_k1(NULL), _cli_cur_k2(NULL), _for_cur_k1(NULL), _for_cur_k2(NULL) +{ + // crea relazioni, cursori e cursor_sheets + _clifo_rel = new TRelation(LF_CLIFO); + + TRectype filter(LF_CLIFO); + filter.put("TIPOCF", "C"); + _cli_cur_k1 = new TCursor(_clifo_rel, "", 1, &filter, &filter); + _cli_cur_k2 = new TCursor(_clifo_rel, "", 2, &filter, &filter); + + _cli_sh_k1 = new TCursor_sheet(_cli_cur_k1, " |CODCF|RAGSOC", "Selezione clienti per codice", + "@1|Codice|Ragione Sociale@50"); + _cli_sh_k2 = new TCursor_sheet(_cli_cur_k2, " |RAGSOC|CODCF", "Selezione clienti per ragione sociale", + "@1|Ragione Sociale@50|Codice"); + + if (id2pos(SC_CLIFO) >= 0) + { + filter.put("TIPOCF", "F"); + _for_cur_k1 = new TCursor(_clifo_rel, "", 1, &filter, &filter); + _for_cur_k2 = new TCursor(_clifo_rel, "", 2, &filter, &filter); + _for_sh_k1 = new TCursor_sheet(_for_cur_k1, " |CODCF|RAGSOC", "Selezione fornitori per codice", + "@1|Codice|Ragione Sociale@50"); + _for_sh_k2 = new TCursor_sheet(_for_cur_k2, " |RAGSOC|CODCF", "Selezione fornitori per ragione sociale", + "@1|Ragione Sociale@50|Codice"); + } + + set_handler(SC_CLIFO, rclifo_handler); + set_handler(SC_SORTCF, rsortcf_handler); + set_handler(SC_CFBUTFR, bfrom_handler); + set_handler(SC_CFBUTTO, bto_handler); + set_handler(SC_SELECT, bselect_handler); + set_handler(SC_RESET, breset_handler); + set_handler(SC_CFCODFR, ffrom_handler); + set_handler(SC_CFCODTO, fto_handler); +} + +TSelection_mask::~TSelection_mask() +{ + delete _for_sh_k2; + delete _for_sh_k1; + delete _for_cur_k2; + delete _for_cur_k1; + + delete _cli_sh_k2; + delete _cli_sh_k1; + delete _cli_cur_k2; + delete _cli_cur_k1; + + delete _clifo_rel; +} + +void TSelection_mask::set_handler(short fld_id, CONTROL_HANDLER handler) +{ + const int pos = id2pos(fld_id); + if (pos >= 0) + fld(pos).set_handler(handler); +} + +TCursor_sheet& TSelection_mask::cur_sheet() const +{ + TCursor_sheet* cs; + if (get_key() == 1) cs = get_who() == 'C' ? _cli_sh_k1 : _for_sh_k1; + else cs = get_who() == 'C' ? _cli_sh_k2 : _for_sh_k2; + + CHECK(cs, "Can't use a NULL TCursor_sheet"); + return *cs; +} + +void TSelection_mask::reset_sheets() +{ + _cli_sh_k1->uncheck(-1); + _cli_sh_k2->uncheck(-1); + if (_for_sh_k1) + { + _for_sh_k1->uncheck(-1); + _for_sh_k2->uncheck(-1); + } + reset(SC_CFCODFR); + reset(SC_CFCODTO); + reset(SC_NSEL); +} + + +// Seleziona tutti i clienti con codice compreso tra due estremi +void TSelection_mask::select_clifo_range(long from, long to) +{ + TCursor_sheet& c = cur_sheet(); + const long items = c.items(); + const int key = get_key(); + TString s_from(50), s_to(50); + + if (from > to) // Controlla limiti + { + long tmp = to; + to = from; + from = tmp; + } + + s_from = c.row(from).get(3-key); // Legge ragione sociale iniziale + s_to = c.row(to).get(3-key); // ... e finale + + bool cod1ok = FALSE, cod2ok = FALSE; + long last = 0; + long firs = 0; + + for (long i = 0; i < items; i++) + { + TToken_string& tt = c.row(i); + const long cod = tt.get_long(key); + bool add; + if (key == 2) + { + const char* s = tt.get(1); + add = s_from <= s && s_to >= s; + } + else + add = cod >= from && cod <= to; + + if (add) + { + c.check(i); + if (firs == 0) + firs = cod; + last = cod; + } + else + c.uncheck(i); + + if (cod == from) cod1ok = TRUE; + if (cod == to) cod2ok = TRUE; + } + + if (!cod1ok) from = firs; + if (!cod2ok) to = last; + + set(SC_CFCODFR, from); + set(SC_CFCODTO, to); + set(SC_NSEL, c.checked()); +} + +// Cerca il primo e l'ultimo cliente selezionati +void TSelection_mask::set_clifo_limits() +{ + long first = 0, last = 0, nsel = 0; + + TCursor_sheet& c = cur_sheet(); + const long items = c.items(); + const int key = get_key(); + + for (int i = 0; i < items; i++) if (c.checked(i)) + { + TToken_string& t = c.row(i); + const long kod = t.get_long(key); + if (first == 0) + { + first = last = kod; + } + else + { + if (first > kod) first = kod; + if (last < kod) last = kod; + } + + nsel++; + } + set(SC_CFCODFR, first); + set(SC_CFCODTO, last); + set(SC_NSEL, nsel); +} + +// handlers +bool TSelection_mask::bfrom_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + TSelection_mask& m = (TSelection_mask&)f.mask(); + TCursor_sheet& c = m.cur_sheet(); + + c.disable_check(); + if (c.run() == K_ENTER) + { + TToken_string& t = c.row(c.selected()); + const long cod1 = t.get_long(m.get_key()); + const long cod2 = m.get_long(SC_CFCODTO); + m.set(SC_CFCODFR, cod1); + m.select_clifo_range(cod1, cod2); + } + } + return TRUE; +} + +bool TSelection_mask::bto_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + TSelection_mask& m = (TSelection_mask&)f.mask(); + TCursor_sheet& c = m.cur_sheet(); + c.disable_check(); + if (c.run() == K_ENTER) + { + TToken_string& t = c.row(c.selected()); + const long cod2 = t.get_long(m.get_key()); + const long cod1 = m.get_long(SC_CFCODFR); + m.set(SC_CFCODTO, cod2); + m.select_clifo_range(cod1, cod2); + } + } + return TRUE; +} + +bool TSelection_mask::ffrom_handler(TMask_field& f, KEY k) +{ + TSelection_mask& m = (TSelection_mask&)f.mask(); + + if (k == K_TAB && f.focusdirty()) + { + const long cod1 = atol(f.get()); + const long cod2 = m.get_long(SC_CFCODTO); + m.select_clifo_range(cod1, cod2); + } + else + if (k == K_F9) + { + TMask_field& f = m.field(SC_CFBUTFR); + f.on_hit(); + } + + return TRUE; +} + +bool TSelection_mask::fto_handler(TMask_field& f, KEY k) +{ + TSelection_mask& m = (TSelection_mask&)f.mask(); + + if (k == K_TAB && f.focusdirty()) + { + const long cod1 = m.get_long(SC_CFCODFR); + const long cod2 = atol(f.get()); + m.select_clifo_range(cod1, cod2); + } + else + if (k == K_F9) + { + TMask_field& f = m.field(SC_CFBUTTO); + f.on_hit(); + } + return TRUE; +} + +bool TSelection_mask::breset_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + TSelection_mask& m = (TSelection_mask&)f.mask(); + m.reset_sheets(); + } + return TRUE; +} + +bool TSelection_mask::bselect_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + TSelection_mask& m = (TSelection_mask&)f.mask(); + TCursor_sheet& c = m.cur_sheet(); + c.enable_check(); + c.run(); + m.set_clifo_limits(); + } + return TRUE; +} + +bool TSelection_mask::rclifo_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + TSelection_mask& m = (TSelection_mask&)f.mask(); + m.set_who(f.get()[0]); + m.reset_sheets(); + } + return TRUE; +} + +bool TSelection_mask::rsortcf_handler(TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + TSelection_mask& m = (TSelection_mask&)f.mask(); + m.set_key(atoi(f.get())); + m.reset_sheets(); + } + return TRUE; +} + diff --git a/sc/scselect.h b/sc/scselect.h index 81bb97348..5acad17eb 100755 --- a/sc/scselect.h +++ b/sc/scselect.h @@ -43,7 +43,7 @@ protected: void set_who(char w) { _who = w; } void set_key (int k) { _key = k; } - virtual void reset_sheets(); + void reset_sheets(); // handlers static bool bfrom_handler(TMask_field& f, KEY k); @@ -56,7 +56,7 @@ protected: static bool rsortcf_handler(TMask_field& f, KEY k); public: - virtual TCursor_sheet& cur_sheet(); + TCursor_sheet& cur_sheet() const; char get_who() const { return _who; } int get_key() const { return _key; }