From 662c95dc86b8c3a34a10f772a386d2b6d96c1640 Mon Sep 17 00:00:00 2001 From: luca Date: Thu, 18 Dec 2003 16:18:46 +0000 Subject: [PATCH] Patch level :2.0 partners nopatch Files correlati :cm1.exe cm1100a.frm Ricompilazione Demo : [ ] Commento :secondo step del programma stampa scaduto per commessa del CRePA git-svn-id: svn://10.65.10.50/trunk@11676 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cm/cm1100.cpp | 225 ++++++++++++++++++++++++++++++++++++++++++------- cm/cm1100.h | 1 + cm/cm1100a.frm | 52 +++++++++++- 3 files changed, 243 insertions(+), 35 deletions(-) diff --git a/cm/cm1100.cpp b/cm/cm1100.cpp index be4f09bf4..de41e334f 100755 --- a/cm/cm1100.cpp +++ b/cm/cm1100.cpp @@ -45,12 +45,14 @@ protected: virtual int compare(const TSortable& s) const; public: + int _tipo; long _codforn; TDate _datapag; TCurrency _importopagato; TString _descrpagamento; long _nreg; + TBill _conto; //gruppocontosottoconto TString _commessa; TCurrency _importocommessa; @@ -61,7 +63,21 @@ 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; + { + cmp = _tipo - pcs._tipo; + if (cmp == 0) + { + switch (_tipo) //caso pagamento o costo non saldacontato + { + case 0: + cmp = _nreg - pcs._nreg; + break; + default: + cmp = _conto.compare(pcs._conto); + break; + } + } + } return cmp; } @@ -69,15 +85,17 @@ int TPag_per_cms_struct::compare(const TSortable& s) const //form class TPag_per_cms_form : public TForm { - TArray& _pagamenti; //puntatore all'arrayone dei pagamenti + TArray& _righe; //puntatore all'arrayone dei pagamenti int _curr_pag; //pagamento corrente protected: - virtual long records() const {return _pagamenti.items();} + virtual long records() const {return _righe.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]; } + int prev_type () const; + const TPag_per_cms_struct& curr() const { return(TPag_per_cms_struct&)_righe[_curr_pag]; } + void print_title (const char * title); public: void print(const TMask& m); @@ -89,10 +107,27 @@ 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]; + const TPag_per_cms_struct& prev = (const TPag_per_cms_struct&)_righe[_curr_pag-1]; return prev._commessa; } +int TPag_per_cms_form::prev_type() const +{ + if (_curr_pag <= 0) + return 0; + const TPag_per_cms_struct& prev = (const TPag_per_cms_struct&)_righe[_curr_pag-1]; + return prev._tipo; +} + +void TPag_per_cms_form::print_title (const char * title) +{ + TPrint_section& last_head = section('H', last_page); + last_head.find_field(FR_CODCMS).set(title); + last_head.update(); + for (word i = 0; i < last_head.height(); i++) + printer().print(last_head.row(i)); +} + bool TPag_per_cms_form::validate(TForm_item &cf, TToken_string &s) { if (s == "_NEXTPAG") @@ -101,6 +136,14 @@ bool TPag_per_cms_form::validate(TForm_item &cf, TToken_string &s) return true; } + if (s == "_TIPORIGA") + { + TString8 str; + str << curr()._tipo; + cf.set(str); + return true; + } + if (s == "_CODCMS") { const TString& cms = curr()._commessa; @@ -108,12 +151,13 @@ bool TPag_per_cms_form::validate(TForm_item &cf, TToken_string &s) { if (_curr_pag > 0) printer().formfeed(); - TPrint_section& last_head = section('H', last_page); - last_head.find_field(FR_CODCMS).set(cms); - last_head.update(); - for (word i = 0; i < last_head.height(); i++) - printer().print(last_head.row(i)); - + print_title(cms); + } + else + { + const int tipo = curr()._tipo; + if (tipo > 0 && tipo != prev_type()) + print_title(tipo == 1 ? "Costi" : "Pagamenti"); } return true; } @@ -132,6 +176,30 @@ bool TPag_per_cms_form::validate(TForm_item &cf, TToken_string &s) return true; } + if (s == "_GRUPPO") + { + TString8 str; + str << curr()._conto.gruppo(); + cf.set(str); + return true; + } + + if (s == "_CONTO") + { + TString8 str; + str << curr()._conto.conto(); + cf.set(str); + return true; + } + + if (s == "_SOTTOCONTO") + { + TString8 str; + str << curr()._conto.sottoconto(); + cf.set(str); + return true; + } + if (s == "_DESCRPAG") { cf.set(curr()._descrpagamento); @@ -172,7 +240,7 @@ void TPag_per_cms_form::print(const TMask& m) TForm::print(); //chiama la vera print dopo aver azzerato il contatore } -TPag_per_cms_form::TPag_per_cms_form(TArray& pag) :TForm ("cm1100a"), _pagamenti(pag) +TPag_per_cms_form::TPag_per_cms_form(TArray& pag) :TForm ("cm1100a"), _righe(pag) { } @@ -189,7 +257,9 @@ class TPag_per_cms : public TSkeleton_application TPag_per_cms_mask* _mask; TPag_per_cms_form* _form; - TArray _pagamenti; + TArray _righe; //array delle righe da stampare in tutti i casi + TAssoc_array _costi,_pagamenti; //array che contengono i conti + TAssoc_array _righecosti,_righepagamenti; //array delle righe da stampare in caso di costi e/o pagamenti TString8 _campodata; protected: @@ -201,8 +271,14 @@ protected: 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); + void lettura_conti(const char * paragrafo, TAssoc_array& assoc); static bool part_callback(const TRelation& rel, void* pJolly); static bool mov_callback(const TRelation& rel, void* pJolly); + bool cerca_conto(const TBill& bill, const TAssoc_array& assoc) const; + bool cerca_costo(const TBill& bill) const; + bool cerca_pagamento(const TBill& bill) const; + void add_importo(TAssoc_array& assoc, const TRectype& rmov) const; + void crea_righe_stampa(TAssoc_array& assoc, const int tipo); public: void scan_pags(); @@ -303,6 +379,7 @@ void TPag_per_cms::find_commesse(const long nreg, const TRectype& riga_pag) { const real& impcms = *(real*)imp; TPag_per_cms_struct* ppcs = new TPag_per_cms_struct; + ppcs->_tipo = 0; //movimenti da saldaconto ppcs->_codforn = riga_pag.get_long(PART_SOTTOCONTO); ppcs->_datapag = riga_pag.get_date(_campodata); ppcs->_importopagato.set_num(impcms * percentuale); //pagamento nella partita @@ -313,44 +390,100 @@ void TPag_per_cms::find_commesse(const long nreg, const TRectype& riga_pag) ppcs->_commessa = k; ppcs->_importocommessa.set_num(impcms); //importo da pagare scritto sulla fattura - _pagamenti.add(ppcs); //aggiunge il pagamento all'array dei pagamenti + _righe.add(ppcs); //aggiunge il pagamento all'array dei pagamenti } } } +void TPag_per_cms::add_importo(TAssoc_array& assoc, const TRectype& rmov) const +{ + TBill conto(rmov); + TToken_string chiave; + conto.add_to(chiave, 0); + chiave.add(rmov.get(RMV_CODCMS)); + + TImporto* importo = (TImporto*)assoc.objptr(chiave); + if (importo == NULL) + { + importo = new TImporto; + assoc.add(chiave,importo); + } +//incremento l'importo del conto commessa con l'importo movimento (iportocontocms += importormov) + const char sezione = rmov.get_char(RMV_SEZIONE); + const real valore = rmov.get_real(RMV_IMPORTO); + const TImporto imp(sezione, valore); + *importo += imp; +} + 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(RMV_CODCMS); + if (cms_in_range(codcms)) { - 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; - } + const TBill conto(rmov); + if (cerca_costo(conto)) + add_importo(_righecosti, rmov); + else if (cerca_pagamento(conto)) + add_importo(_righepagamenti, rmov); } } } } + + +bool TPag_per_cms::cerca_conto(const TBill& bill, const TAssoc_array& assoc) const +{ + TToken_string key(15,'.'); + key.add(bill.gruppo()); + if (assoc.is_key(key)) + return true; + + key.add(bill.conto()); + if (assoc.is_key(key)) + return true; + + key.add(bill.sottoconto()); + if (assoc.is_key(key)) + return true; + + return false; +} + +bool TPag_per_cms::cerca_costo(const TBill& bill) const +{ + return cerca_conto(bill, _costi); +} + +bool TPag_per_cms::cerca_pagamento(const TBill& bill) const +{ + return cerca_conto(bill, _pagamenti); +} + +void TPag_per_cms::lettura_conti(const char* paragrafo, TAssoc_array& assoc) +{ + TConfig conti("cm1100a.ini",paragrafo); //paragrafo da scandire nell ini + TAssoc_array& vars = conti.list_variables(); + + FOR_EACH_ASSOC_STRING(vars, h, k, val) //riempie l'assoc con i soli valori del paragrafo dell'ini + assoc.add(val); +} + + bool TPag_per_cms::create() { _mask = new TPag_per_cms_mask; - _form = new TPag_per_cms_form(_pagamenti); + _form = new TPag_per_cms_form(_righe); + + lettura_conti("Costi", _costi); //caricamento dei conti dei costi + lettura_conti("Pagamenti", _pagamenti); // "" pagamenti return TSkeleton_application::create(); } @@ -477,6 +610,34 @@ void TPag_per_cms::scan_movs() TRelation rel(LF_MOV); TCursor cur(&rel, filtro, 2, &darec, &arec); scan_cursor(cur, "Ricerca movimenti...", mov_callback, this); + + crea_righe_stampa(_righecosti, 1); + crea_righe_stampa(_righepagamenti, 2); +} + +void TPag_per_cms::crea_righe_stampa(TAssoc_array& assoc, const int tipo) +{ + TToken_string tok; + FOR_EACH_ASSOC_OBJECT(assoc, h, k ,i) + { + tok = k; + TImporto imp = *(TImporto*)i; + imp.normalize(tipo==1 ? 'D' : 'A'); + + TPag_per_cms_struct* ppcs = new TPag_per_cms_struct; + ppcs->_tipo = tipo; //movimenti di costo/pagamento + ppcs->_codforn = 0; +// ppcs->_datapag = riga_pag.get_date(_campodata); + ppcs->_importopagato.set_num(imp.valore()); //pagamento nella partita + + ppcs->_nreg = 0; + + ppcs->_commessa = tok.get(3); + ppcs->_conto.get(tok, 0); + ppcs->_descrpagamento = ppcs->_conto.descrizione(); + + _righe.add(ppcs); //aggiunge il pagamento all'array dei pagamenti e lo spedisce in stampa + } } void TPag_per_cms::main_loop() @@ -491,13 +652,13 @@ void TPag_per_cms::main_loop() default:break; } - _pagamenti.destroy(); //azzera l'arrayone dei pagamenti + _righe.destroy(); //azzera l'arrayone dei pagamenti scan_pags(); scan_movs(); - if (_pagamenti.items() > 0) + if (_righe.items() > 0) { - _pagamenti.sort(); + _righe.sort(); _form->print(*_mask); } } diff --git a/cm/cm1100.h b/cm/cm1100.h index 534830965..e2a6bf85a 100755 --- a/cm/cm1100.h +++ b/cm/cm1100.h @@ -5,5 +5,6 @@ #define FR_DACDC 13 #define FR_ACDC 14 #define FR_CODCMS 15 +#define FR_TIPORIGA 16 diff --git a/cm/cm1100a.frm b/cm/cm1100a.frm index 64367e623..be27f09e2 100755 --- a/cm/cm1100a.frm +++ b/cm/cm1100a.frm @@ -100,12 +100,12 @@ END END // section header odd // riga con solo il codice commessa ed una riga vuota -SECTION HEADER LAST 2 +SECTION HEADER LAST 3 STRINGA FR_CODCMS BEGIN KEY "codice commessa" - PROMPT 1 1 "@b" + PROMPT 1 2 "@b" END END //section header last @@ -113,6 +113,24 @@ END //section header last // riga di stampa (utilizzata per ogni gruppo/conto/sottoconto e per tutti i totali) SECTION BODY ODD 1 +STRINGA -1 +BEGIN + KEY "tipo riga" + PROMPT 1 1 "" + MESSAGE _TIPORIGA|COPY,FR_TIPORIGA + FLAGS "H" +END + +LISTA FR_TIPORIGA +BEGIN + KEY "lista tipo riga" + PROMPT 1 1 "" + ITEM "0|0" MESSAGE ENABLE,1@|DISABLE,2@ + ITEM "1|1" MESSAGE ENABLE,2@|DISABLE,1@ + ITEM "2|2" MESSAGE ENABLE,2@|DISABLE,1@ + FLAGS "H" +END + STRINGA -1 BEGIN KEY "codice commessa" @@ -126,6 +144,7 @@ BEGIN KEY "numero registrazione" PROMPT 1 1 "" MESSAGE _NREG + GROUP 1 END DATA -1 @@ -133,6 +152,31 @@ BEGIN KEY "data pagamento" PROMPT 10 1 "" MESSAGE _DATAPAG + GROUP 1 +END + +NUMERO -1 3 +BEGIN + KEY "gruppo" + PROMPT 3 1 "" + MESSAGE _GRUPPO + GROUP 2 +END + +NUMERO -1 3 +BEGIN + KEY "conto" + PROMPT 7 1 "" + MESSAGE _CONTO + GROUP 2 +END + +NUMERO -1 6 +BEGIN + KEY "sottoconto" + PROMPT 11 1 "" + MESSAGE _SOTTOCONTO + GROUP 2 END STRINGA -1 45 @@ -147,6 +191,7 @@ BEGIN KEY "codice fornitore" PROMPT 69 1 "" MESSAGE _CODFORN + GROUP 1 END VALUTA -1 15 @@ -154,6 +199,7 @@ BEGIN KEY "totale fattura" PROMPT 77 1 "" MESSAGE _TOTDOC + GROUP 1 END VALUTA -1 15 @@ -173,7 +219,7 @@ END END // section body -SECTION FOOTER ODD 3 +SECTION FOOTER ODD 1 END END // form