From ab8d898625ebb8d4ec1963c1583412bf190fe51a Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 15 Dec 2003 14:07:37 +0000 Subject: [PATCH] Patch level : 2.0 nopatch Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/trunk@11662 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cm/cm0100.cpp | 25 +++-- cm/cm1100.cpp | 284 +++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 240 insertions(+), 69 deletions(-) diff --git a/cm/cm0100.cpp b/cm/cm0100.cpp index faac1c6e1..5ac83203a 100755 --- a/cm/cm0100.cpp +++ b/cm/cm0100.cpp @@ -319,28 +319,31 @@ void TContixCdc::print_footer_fsc() void TContixCdc::print_header_cms() { - _form->find_field('H', odd_page, FR_CMS).set(_oldcms); - _form->find_field('H', odd_page, FR_D_CMS).set(cache().get("CMS", _oldcms).get("S0")); + TPrint_section& h = _form->get_section('H', odd_page); + h.find_field(FR_CMS).set(_oldcms); + h.find_field(FR_D_CMS).set(cache().get("CMS", _oldcms).get("S0")); print_special_section('H', odd_page); } void TContixCdc::print_header_fsc() { - _form->find_field('H', last_page, FR_FSC).set(_oldfsc); - _form->find_field('H', last_page, FR_D_FSC).set(cache().get("FSC", _oldfsc).get("S0")); + TPrint_section& h = _form->get_section('H', last_page); + h.find_field(FR_FSC).set(_oldfsc); + h.find_field(FR_D_FSC).set(cache().get("FSC", _oldfsc).get("S0")); print_special_section('H', last_page); } void TContixCdc::set_intestazione() { // scrive l'header first, contenente i dati della ditta e dell'esercizio e le selezioni di stampa - _form->find_field('H', first_page, FR_ESERCIZIO).set(_mask->get(F_ANNO)); - _form->find_field('H', first_page, FR_DATAINI).set(_mask->get(F_DATAINI)); - _form->find_field('H', first_page, FR_DATAFIN).set(_mask->get(F_DATAFIN)); - _form->find_field('H', first_page, FR_DACDC).set(_mask->get(F_DACDC)); - _form->find_field('H', first_page, FR_DAFSC).set(_mask->get(F_DAFSC)); - _form->find_field('H', first_page, FR_ACDC).set(_mask->get(F_ACDC)); - _form->find_field('H', first_page, FR_AFSC).set(_mask->get(F_AFSC)); + TPrint_section& h = _form->get_section('H', first_page); + h.find_field(FR_ESERCIZIO).set(_mask->get(F_ANNO)); + h.find_field(FR_DATAINI).set(_mask->get(F_DATAINI)); + h.find_field(FR_DATAFIN).set(_mask->get(F_DATAFIN)); + h.find_field(FR_DACDC).set(_mask->get(F_DACDC)); + h.find_field(FR_DAFSC).set(_mask->get(F_DAFSC)); + h.find_field(FR_ACDC).set(_mask->get(F_ACDC)); + h.find_field(FR_AFSC).set(_mask->get(F_AFSC)); _form->set_testata(); _form->set_pedata(); } diff --git a/cm/cm1100.cpp b/cm/cm1100.cpp index 4817e0add..e143344c5 100755 --- a/cm/cm1100.cpp +++ b/cm/cm1100.cpp @@ -2,9 +2,11 @@ #include #include #include +#include -#include #include +#include +#include #include #include "..\cg\cgsaldac.h" @@ -36,9 +38,13 @@ bool TPag_per_cms_mask::on_field_event(TOperable_field& o, TField_event e, long } //=============================================================================================== -//struct dei dati da passare in stampa -struct TPag_per_cms_struct : public TObject +// class dei dati da passare in stampa +class TPag_per_cms_struct : public TSortable { +protected: + virtual int compare(const TSortable& s) const; + +public: long _codforn; TDate _datapag; TCurrency _importopagato; @@ -48,9 +54,17 @@ struct TPag_per_cms_struct : public TObject TString _commessa; TCurrency _importocommessa; - }; +int TPag_per_cms_struct::compare(const TSortable& s) const +{ + const TPag_per_cms_struct& pcs = (const TPag_per_cms_struct&)s; + int cmp = _commessa.compare(pcs._commessa); + if (cmp == 0) + cmp = _nreg - pcs._nreg; + return cmp; +} + //=============================================================================================== //form class TPag_per_cms_form : public TForm @@ -62,6 +76,7 @@ protected: virtual long records() const {return _pagamenti.items();} bool validate(TForm_item &cf, TToken_string &s); + const TString& prev_cms() const; const TPag_per_cms_struct& curr() const { return(TPag_per_cms_struct&)_pagamenti[_curr_pag]; } public: @@ -70,6 +85,14 @@ public: virtual ~TPag_per_cms_form(); }; +const TString& TPag_per_cms_form::prev_cms() const +{ + if (_curr_pag <= 0) + return EMPTY_STRING; + const TPag_per_cms_struct& prev = (const TPag_per_cms_struct&)_pagamenti[_curr_pag-1]; + return prev._commessa; +} + bool TPag_per_cms_form::validate(TForm_item &cf, TToken_string &s) { if (s == "_NEXTPAG") @@ -80,7 +103,18 @@ bool TPag_per_cms_form::validate(TForm_item &cf, TToken_string &s) if (s == "_CODCMS") { - cf.set(curr()._commessa); + const TString& cms = curr()._commessa; + if (cms != prev_cms()) + { + if (_curr_pag > 0) + { + TPrintrow pr; + printer().print(pr); + } + cf.set(cms); + } + else + cf.set(""); return true; } @@ -128,31 +162,37 @@ class TPag_per_cms : public TSkeleton_application TPag_per_cms_form* _form; TArray _pagamenti; + TString8 _campodata; protected: virtual void main_loop(); virtual bool create(); virtual bool destroy(); -public: - long find_movimento(const TRectype& riga_pag); - void find_commesse(const long nreg, const TRectype& riga_pag, const char * tipodata); + bool cms_in_range(const TString& codcms) const; + long find_movimento(const TRectype& riga_pag) const; + void find_commesse(const long nreg, const TRectype& riga_pag); + void find_commesse_cg(const long nreg); + static bool part_callback(const TRelation& rel, void* pJolly); + static bool mov_callback(const TRelation& rel, void* pJolly); +public: + void scan_pags(); + void scan_movs(); }; - -long TPag_per_cms::find_movimento(const TRectype& riga_pag) +long TPag_per_cms::find_movimento(const TRectype& riga_pag) const { int n_fatture = 0; //numero di fatture trovate int first_fatt = 0; //numero riga della prima fattura //scan della partita dall'ultima alla prima riga - TPartita partita(riga_pag); + const TPartita partita(riga_pag); for (int p = partita.last(); p > 0; p = partita.pred(p)) { const TRiga_partite& fatt = partita.riga(p); if (fatt.is_fattura()) { - n_fatture ++; + n_fatture++; first_fatt = p; } } @@ -177,7 +217,8 @@ long TPag_per_cms::find_movimento(const TRectype& riga_pag) } } } - first_fatt = linea_fattura; + if (linea_fattura > 0) // oppure anche (linea_fattura > first_fatt) + first_fatt = linea_fattura; } long nreg = 0; @@ -190,8 +231,20 @@ long TPag_per_cms::find_movimento(const TRectype& riga_pag) return nreg; } +bool TPag_per_cms::cms_in_range(const TString& codcms) const +{ + if (codcms.empty()) + return false; + const TString& dalla = _mask->get(F_DACDC); + if (dalla.not_empty() && codcms < dalla) + return false; + const TString& alla = _mask->get(F_ACDC); + if (alla.not_empty() && codcms > alla) + return false; + return true; +} -void TPag_per_cms::find_commesse(const long nreg, const TRectype& riga_pag, const char * tipodata) +void TPag_per_cms::find_commesse(const long nreg, const TRectype& riga_pag) { TMovimentoPN pn; pn.curr().put(MOV_NUMREG, nreg); @@ -205,8 +258,8 @@ void TPag_per_cms::find_commesse(const long nreg, const TRectype& riga_pag, cons for (int i = 0; i < pn.iva_items(); i++) { const TRectype& rmoviva = pn.iva(i); - const TString80 codcms = rmoviva.get(RMI_CODCMS); - if (codcms.not_empty()) + const TString& codcms = rmoviva.get(RMI_CODCMS); + if (cms_in_range(codcms)) { real* imp = (real*)commesse.objptr(codcms); if (imp == NULL) @@ -223,7 +276,7 @@ void TPag_per_cms::find_commesse(const long nreg, const TRectype& riga_pag, cons const real& impcms = *(real*)imp; TPag_per_cms_struct* ppcs = new TPag_per_cms_struct; ppcs->_codforn = riga_pag.get_long(PART_SOTTOCONTO); - ppcs->_datapag = riga_pag.get_date(tipodata); + ppcs->_datapag = riga_pag.get_date(_campodata); ppcs->_importopagato.set_num(impcms * percentuale); //pagamento nella partita ppcs->_descrpagamento = riga_pag.get(PART_DESCR); @@ -235,9 +288,36 @@ void TPag_per_cms::find_commesse(const long nreg, const TRectype& riga_pag, cons _pagamenti.add(ppcs); //aggiunge il pagamento all'array dei pagamenti } } - } +void TPag_per_cms::find_commesse_cg(const long nreg) +{ + TMovimentoPN pn; + pn.curr().put(MOV_NUMREG, nreg); + if (pn.read() == NOERR) + { + TAssoc_array commesse; + for (int i = 0; i < pn.cg_items(); i++) + { + const TRectype& rmov = pn.cg(i); + if (rmov.get_char(RMV_TIPOC) == 'F') + { + const TString& codcms = rmov.get(RMI_CODCMS); + if (cms_in_range(codcms)) + { + real* imp = (real*)commesse.objptr(codcms); + if (imp == NULL) + { + imp = new real; + commesse.add(codcms, imp); + } + real importo = rmov.get_real(RMV_IMPORTO); + *imp += importo; + } + } + } + } +} bool TPag_per_cms::create() { @@ -254,62 +334,150 @@ bool TPag_per_cms::destroy() return TRUE; } +// Mettere in libreria al piu' presto!!!! +typedef bool (*SCAN_FUNC)(const TRelation& rel, void* pJolly); + +bool scan_cursor(TCursor& cur, const char* msg, SCAN_FUNC func, void* pJolly) +{ + TRecnotype items = 0; // Temporarily + TProgind pi(items, msg, true, true); + + { + TWait_cursor hourglass; + items = cur.items(); + } + + bool ok = true; + if (items > 0) + { + cur.freeze(); + pi.setmax(items); + for (cur = 0; cur.pos() < items; ++cur) + { + pi.addstatus(1); + if (pi.iscancelled()) + { + ok = false; + break; + } + if (!func(*cur.relation(), pJolly)) + { + ok = false; + break; + } + } + cur.freeze(false); + } + return ok; +} + +bool TPag_per_cms::part_callback(const TRelation& rel, void* pJolly) +{ + TPag_per_cms* app = (TPag_per_cms*)pJolly; + const TRectype& riga_part_pag = rel.curr(); + + const long nreg = app->find_movimento(riga_part_pag); + if (nreg > 0) + app->find_commesse(nreg, riga_part_pag); + return true; +} + +void TPag_per_cms::scan_pags() +{ +//costruzione filtro + TString filtro = "(TIPOC==\"F\")&&(TIPOPAG>=\"3\")"; //deve essere un pagamento a fornitore!!! + const TDate dataini = _mask->get(F_DATAINI); + const TDate datafin = _mask->get(F_DATAFIN); + if (dataini.ok()) + { + TString80 f; + f.format("&&(ANSI(%s)>=\"%s\")", (const char*)_campodata, dataini.string(ANSI)); + filtro << f; + } + if (datafin.ok()) + { + TString80 f; + f.format("&&(ANSI(%s)<=\"%s\")", (const char*)_campodata, datafin.string(ANSI)); + filtro << f; + } +//applica il filtro alla relazione + TRelation rel(LF_PARTITE); + TCursor cur(&rel, filtro); + scan_cursor(cur, "Ricerca commesse...", part_callback, this); +} + +bool TPag_per_cms::mov_callback(const TRelation& rel, void* pJolly) +{ + TPag_per_cms* app = (TPag_per_cms*)pJolly; + const long nreg = rel.curr().get_long(MOV_NUMREG); + app->find_commesse_cg(nreg); + return true; +} + +void TPag_per_cms::scan_movs() +{ + if (_campodata == PART_DATAPAG) // I movimenti non hanno DATAPAG + _campodata = PART_DATAREG; + + TString filtro = "(REG==\"\")&&(TIPOMOV==\"\")"; + const TDate dataini = _mask->get(F_DATAINI); + const TDate datafin = _mask->get(F_DATAFIN); + + TRectype darec(LF_MOV), arec(LF_MOV); + if (_campodata == MOV_DATAREG) + { + if (dataini.ok()) + darec.put(MOV_DATAREG, dataini); + if (datafin.ok()) + arec.put(MOV_DATAREG, dataini); + } + else + { + TString80 f; + if (dataini.ok()) + { + f.format("&&(ANSI(%s)>=\"%s\")", (const char*)_campodata, dataini.string(ANSI)); + filtro << f; + } + if (datafin.ok()) + { + f.format("&&(ANSI(%s)<=\"%s\")", (const char*)_campodata, datafin.string(ANSI)); + filtro << f; + } + } + + TRelation rel(LF_MOV); + TCursor cur(&rel, filtro, 2, &darec, &arec); + scan_cursor(cur, "Ricerca movimenti...", mov_callback, this); +} + void TPag_per_cms::main_loop() { while (_mask->run() == K_ENTER) { -//costruzione filtro sulle date - const char * tipodata = PART_DATAREG; + _campodata = PART_DATAREG; switch(_mask->get_int(F_TIPODATA)) { - case 1:tipodata = PART_DATADOC;break; - case 2:tipodata = PART_DATAPAG;break; + case 1:_campodata = PART_DATADOC;break; + case 2:_campodata = PART_DATAPAG;break; default:break; } - TString filtro = "(TIPOC==\"F\")&&(TIPOPAG>=\"3\")"; //deve essere un pagamento a fornitore!!! - const TDate dataini = _mask->get_date(F_DATAINI); - const TDate datafin = _mask->get_date(F_DATAFIN); - if (dataini.ok()) - { - if (filtro.not_empty()) - filtro << "&&"; - TString filtrofinale; - filtrofinale.format("(ANSI(%s)>=\"%s\")", tipodata,dataini.string(ANSI)); - filtro << filtrofinale; - } - if (datafin.ok()) - { - if (filtro.not_empty()) - filtro << "&&"; - TString filtrofinale; - filtrofinale.format("(ANSI(%s)<=\"%s\")", tipodata,datafin.string(ANSI)); - filtro << filtrofinale; - } -//applica il filtro ai due file della relazione - TRelation rel(LF_PARTITE); - TCursor cur(&rel, filtro); - const TRectype& riga_part_pag = cur.curr(); //riga partita pagamento - const long items = cur.items(); - cur.freeze(); - _pagamenti.destroy(); //azzera l'arrayone dei pagamenti -//ciclo sui pagamenti selezionati per trovare i movimenti - for (cur=0; cur.pos() 0) - find_commesse(nreg, riga_part_pag, tipodata); + scan_pags(); + scan_movs(); + + if (_pagamenti.items() > 0) + { + _pagamenti.sort(); + _form->print(*_mask); } - - _form->print(*_mask); } } - int cm1100(int argc, char* argv[]) { TPag_per_cms a; a.run(argc,argv,TR("Stampa pagato per commessa")); return 0; -} \ No newline at end of file +}