From 69029737ccfc33551aa435a82dee3977020df86f Mon Sep 17 00:00:00 2001 From: nik Date: Fri, 21 Jul 1995 10:12:15 +0000 Subject: [PATCH] Correzione errori git-svn-id: svn://10.65.10.50/trunk@1626 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cg/cg1100.cpp | 2385 ++++++++-------- cg/cg1300.cpp | 314 +- cg/cg1300.h | 60 +- cg/cg1304.cpp | 3 +- cg/cg1500.cpp | 7416 ++++++++++++++++++++++++------------------------ cg/cg4300.cpp | 1462 +++++----- cg/cg4301.cpp | 1750 ++++++++++++ cg/cg4303.cpp | 522 ++++ cg/cg4400.cpp | 6599 +++++++++++++++++++++--------------------- cg/cg4400.h | 320 +-- cg/cg4400b.uml | 116 +- cg/cg4600.cpp | 3612 +++++++++++------------ cg/cg4600a.uml | 700 ++--- cg/cglib.h | 304 +- cg/cglib01.cpp | 1346 ++++----- 15 files changed, 14593 insertions(+), 12316 deletions(-) diff --git a/cg/cg1100.cpp b/cg/cg1100.cpp index c76277414..7f3d0accb 100755 --- a/cg/cg1100.cpp +++ b/cg/cg1100.cpp @@ -1,1191 +1,1194 @@ -// cg1100.cpp -// Stampa piano dei conti - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "cg1.h" -#include "cg1100.h" - -const char * TAB_ANABIL = "%IVD"; -const char * TAB_IVD = "%IVD"; - -const int CODTABLEN = 15; - -enum stampe { - completa=1, - con_IV_direttiva, - senza_IV_direttiva, - completa_bil, - con_ana_bil, - senza_ana_bil - }; - -class CG1100_application : public TPrintapp -{ - struct bil_ivd - { - char sez; - char let; - char numr[5]; - char num[4]; - char gruppo[4]; - char conto[4]; - char sottoc[8]; - char descr[52]; - char sez_opp; - char let_opp; - char numr_opp[5]; - int num_opp; - }; - - bil_ivd* _bil; - TTable* _tab; // tabella codici IV direttiva - TRectype* _rec; - TSort* _sort; - TRelation* _rel; - TMask* _msk; - TParagraph_string _d1, _d2; // qui - const char* _buf; - stampe _tipo_stampa; - bool _salto_pag,_resetta_righe_stampa; - int _old_gruppo; - int _pcont_reclen,_i; - int _cur_c1, _cur_c2; - TString _clivd, _clivdo; - char _sez_da_stamp,_sez_stamp,_let_da_stamp,_let_stamp; - TString _numr_da_stamp,_numr_stamp; - int _gruppo,_conto,_num_da_stamp,_num_stamp,_g_prec,_c_prec; - long _sottoc,_s_prec; - TString _classe_da_stampare,_classe_stampata; - bool _conto_classificato,_sottoc_classificato,_stampa_riga_vuota; - bool _prima_volta; - TDate _data_stampa; - -public: - - virtual bool user_destroy() ; - virtual bool user_create() ; - - virtual void set_page (int,int); - virtual bool preprocess_print (int,int); - virtual bool preprocess_page (int,int); - virtual print_action postprocess_page (int,int); - virtual void postclose_print (); - - virtual bool set_print(int); - - void intesta (stampe); - - - bool elabora_riga(); // decide se fare salto pagina o no - void do_sort(); - void set_completa (); - void set_con_IV (); - void set_senza_IV (); - void set_con_ana (); - void set_senza_ana (); - void init_sort(); - const char* descrizione_numero(char, char, int, int); - // void setta_righe_descr(TParagraph_string*); - int leggo_sottoc(int,int,long); - void riempi_record(char,char,const TString&,int,int,int,long,const TString&,char,char,const TString&,int); - void set_bil_key(bil_ivd* b, char sezione, char lettera, - const char* numero_romano, int numero, - int gruppo = 0, int conto = 0, long sottoconto = 0L); - void set_bil_val(bil_ivd* b, const char* descr,char sez_opp,char let_opp, - const char* numr_opp,int num_opp); - - void process_link(int id, const char* txt); - - CG1100_application() : _clivd(8), _clivdo(8), _d1("", 30), _d2("", 40) {} -}; - -void CG1100_application::process_link(int id, const char* txt) -{ - TString ss = "1|"; ss << txt; - TMessage fs(cmd2name("cg0","-0"), MSG_LN, ss); - TMailbox m; - m.send(fs); - TExternal_app cg0("cg0 -0"); - if (cg0.run()) beep(); -} - -void CG1100_application::init_sort() -{ - switch (_tipo_stampa) - { - case con_IV_direttiva: - _sort->reset(sizeof(bil_ivd)); - - _sort -> addsortkey ((char*)&(_bil->sez) - (char*)&(_bil->sez),1); - _sort -> addsortkey ((char*)&(_bil->let) - (char*)&(_bil->sez),1); - _sort -> addsortkey ((char*)&(_bil->numr) - (char*)&(_bil->sez),4); - _sort -> addsortkey ((char*)&(_bil->num) - (char*)&(_bil->sez),2); - _sort -> addsortkey ((char*)&(_bil->gruppo) - (char*)&(_bil->sez),3); - _sort -> addsortkey ((char*)&(_bil->conto) - (char*)&(_bil->sez),3); - _sort -> addsortkey ((char*)&(_bil->sottoc) - (char*)&(_bil->sez),6); - break; - case con_ana_bil: - { - TRecfield codcbl (*_rec, PCN_CODCBL); - - _sort->reset(_rec->len()); - _sort->addsortkey (codcbl); - break; - } - default: - break; - } -} - -void CG1100_application::set_bil_key(bil_ivd* b, char sezione, char lettera, - const char* numero_romano, int numero, - int gruppo, int conto,long sottoconto) -{ - b->sez = sezione; - b->let = lettera; - strcpy(b->numr, numero_romano); - sprintf(b->num , "%2d", numero); - sprintf(b->gruppo , "%3d", gruppo); - sprintf(b->conto , "%3d", conto); - sprintf(b->sottoc , "%6ld", sottoconto); -} - -void CG1100_application::set_bil_val(bil_ivd* b, const char* descr, - char sez_opp,char let_opp, - const char* numr_opp,int num_opp) -{ - strcpy(b->descr, descr); - b->sez_opp = sez_opp; - b->let_opp = let_opp; - strcpy(b->numr_opp, numr_opp); - b->num_opp = num_opp; -} - -void CG1100_application::riempi_record(char sez,char let,const TString& numr, - int numero,int g,int c,long s, - const TString& descr,char sez_opp, - char let_opp,const TString& numr_opp, - int num_opp) -{ - set_bil_key(_bil, sez, let, numr, numero, g, c, s); - set_bil_val(_bil, descr, sez_opp, let_opp, numr_opp, num_opp); - _sort->sort ((const char*) _bil); -} - -void CG1100_application::postclose_print() -{ - // if (_tipo_stampa == con_IV_direttiva) - // delete _sort; -} - -print_action CG1100_application::postprocess_page(int file,int counter) -{ - switch (_tipo_stampa) - { - case completa: - case senza_IV_direttiva: - case senza_ana_bil: - break; - case con_IV_direttiva: - case con_ana_bil: - { - //const char * buf; - struct bil_ivd* bil = (struct bil_ivd*) _buf; - /* - if (_sez_da_stamp != _sez_stamp) - { - if (_sez_da_stamp == '5' || _sez_da_stamp == '9') - { - reset_print(); - _i = 1; - set_con_IV(); - _resetta_righe_stampa = FALSE; - } - else - _resetta_righe_stampa = TRUE; - } - else - _resetta_righe_stampa = TRUE; - */ - _sez_stamp = _sez_da_stamp; - _let_stamp = _let_da_stamp; - _numr_stamp = _numr_da_stamp; - _num_stamp = _num_da_stamp; - _classe_stampata.format("%c%c%s%2d",_sez_stamp,_let_stamp,(const char*)_numr_stamp,_num_stamp); - - - - if ( (_buf = _sort->retrieve()) != NULL) - { - bil = (struct bil_ivd*) _buf; - _sez_da_stamp = bil->sez; - _let_da_stamp = bil->let; - _numr_da_stamp = bil->numr; - _numr_da_stamp.ltrim(); - _num_da_stamp = atoi(bil->num); - _gruppo = atoi(bil->gruppo); - _conto = atoi(bil->conto); - _sottoc = atol(bil->sottoc); - _classe_da_stampare.format("%c%c%s%2d",_sez_da_stamp,_let_da_stamp,(const char*)_numr_da_stamp,_num_da_stamp); - - //set_auto_ff(FALSE); - - return REPEAT_PAGE; - } - break; - } - default: - break; - - } - return NEXT_PAGE; -} - -void CG1100_application::set_page(int file,int counter) -{ - //const char* buf; - - intesta (_tipo_stampa); - switch (_tipo_stampa) - { - case con_IV_direttiva: - { - // if (_resetta_righe_stampa) - // { - reset_print(); - _i = 1; - // } - - if (_sez_da_stamp != _sez_stamp) - // { - // if (_sez_da_stamp=='1' || _sez_da_stamp=='2') - set_con_IV (); - // if (_sez_da_stamp == '5' || _sez_da_stamp == '9') - // { - // set_row (_i,"%s",""); - // set_auto_ff(TRUE); - // } - // } - else - if (_buf != NULL) - set_con_IV(); - } - break; - case con_ana_bil: - set_con_ana(); - break; - case senza_IV_direttiva: - set_senza_IV(); - break; - case senza_ana_bil: - set_senza_ana(); - break; -default: - break; -} -} - -////////////////////////////////////////////////////////////// -// Crea sort se necessario e seleziona il cursore opportuno -////////////////////////////////////////////////////////////// -void CG1100_application::do_sort() -{ - switch (_tipo_stampa) - { - case completa: - case senza_IV_direttiva: - case senza_ana_bil: - break; - case con_IV_direttiva: - { - char sez_conto,let_conto; - TString numr_conto; - int num_conto; - bool classe_conto = FALSE; - - _sort->init(); - select_cursor (_cur_c1); - - TCursor * cursor = current_cursor(); - TRectype & rec = cursor->curr(); - - long last = cursor->items(); - - for ( *cursor = 0; cursor->pos() < last; ++(*cursor) ) - { - int g = rec.get_int(PCN_GRUPPO); - int c = rec.get_int(PCN_CONTO); - long s = rec.get_int(PCN_SOTTOCONTO); - - if (g != 0 && c == 0 && s == 0) continue; - - char sez = rec.get_char(PCN_SEZIVD); - char let = rec.get_char(PCN_LETTIVD); - TString numr = rec.get (PCN_NUMRIVD); - int num = rec.get_int (PCN_NUMIVD); - TString descr = rec.get (PCN_DESCR); - char sez_opp = rec.get_char(PCN_SEZIVDOPP); - char let_opp = rec.get_char(PCN_LETTIVDOPP); - TString numr_opp = rec.get (PCN_NUMRIVDOPP); - int num_opp = rec.get_int (PCN_NUMIVDOPP); - - if ((g != 0) && (c != 0) && (s == 0)) - { - if (sez != '\0' && sez != '0') - { - sez_conto = sez; - - if (let != '\0') - let_conto = let; - else - if ((sez == '1')||(sez == '2')) - let_conto = 'Z'; - else - let_conto = let; - - numr_conto = numr; - num_conto = num; - classe_conto = TRUE; - riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,descr,sez_opp,let_opp,numr_opp,num_opp); - } - else - classe_conto = FALSE; - } - - if ((g != 0) && (c != 0) && (s != 0)) - { - if (classe_conto) - riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,descr,sez_opp,let_opp,numr_opp,num_opp); - else - { - if (sez != '\0' && sez != '0') - { - if (let == '\0') - if ((sez == '1')||(sez == '2')) - let = 'Z'; - - riempi_record(sez,let,numr,num,g,c,s,descr,sez_opp,let_opp,numr_opp,num_opp); - } - } - } - } - - _sort->endsort(); - // delete _bil; - select_cursor (_cur_c2); - - break; - } - - case con_ana_bil: - { - _sort->init(); - - select_cursor (_cur_c1); - - TCursor * cursor = current_cursor(); - TRectype & rec = cursor->curr(); - - long last = cursor->items(); - TString c1(12); - - for ( *cursor = 0; cursor->pos() < last; ++(*cursor) ) - { - if (rec.get(PCN_CONTO).not_empty() && rec.get(PCN_SOTTOCONTO).empty()) - c1 = rec.get(PCN_CODCBL); - else - if (rec.get(PCN_SOTTOCONTO).not_empty() && rec.get(PCN_CODCBL).empty()) - rec.put(PCN_CODCBL, c1); - if (rec.get(PCN_CODCBL).not_empty() ) - _sort->sort (rec.string()); - } - - _sort->endsort(); - select_cursor (_cur_c2); - break; - } - default: - break; - } -} - -bool CG1100_application::preprocess_print (int file,int counter) -{ - do_sort(); - switch (_tipo_stampa) - { - case con_IV_direttiva: - case con_ana_bil: - { - struct bil_ivd* bil = (struct bil_ivd*) _buf; - - if ((_buf = _sort->retrieve()) != NULL) - { - bil = (struct bil_ivd*) _buf; - _sez_da_stamp = bil->sez; - _let_da_stamp = bil->let; - _numr_da_stamp = bil->numr; - _numr_da_stamp.ltrim(); - _num_da_stamp = atoi(bil->num); - _gruppo = atoi(bil->gruppo); - _conto = atoi(bil->conto); - _sottoc = atol(bil->sottoc); - _classe_da_stampare.format("%c%c%s%2d",_sez_da_stamp,_let_da_stamp,(const char*)_numr_da_stamp,_num_da_stamp); - - return TRUE; - } - else - return FALSE; - } - break; -default: - break; -} - return TRUE; -} - -void CG1100_application::set_con_IV() -{ - struct bil_ivd* bil = (struct bil_ivd*) _buf; - - TString descrizione,descr; - char sez_opp,let_opp; - int num_opp,numr_opp; - bool stampa_classe = TRUE; - int numr = atoi(_numr_da_stamp); - TString numrom = itor(numr); - - sez_opp = bil->sez_opp; - let_opp = bil->let_opp; - numr_opp = atoi(bil->numr_opp); - TString numrom_opp = itor(numr_opp); - num_opp = bil->num_opp; - - descrizione = descrizione_numero(_sez_da_stamp,_let_da_stamp,numr,_num_da_stamp); - descr = bil->descr; - - //Se la classe prelevata dal record corrente del sort e' diversa dalla classe - //prelevata dal record precedente, allora stampo la nuova classe con i relativi - //sottoconti. In caso contrario continuo a stampare solo i sottoconti. - - if (_classe_da_stampare != _classe_stampata) - { - if (_sez_da_stamp != _sez_stamp) - { - if ((_sez_da_stamp == '1')&&(_let_da_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i++,"@0gCONTI D' ORDINE ATTIVI"); - set_row (_i++,"@0g%c", app); - stampa_classe = FALSE; - } - else - if ((_sez_da_stamp == '1')&&(_let_da_stamp != 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i++,"@0gATTIVO"); - set_row (_i++,"@0g%c", app); - } - - if ((_sez_da_stamp == '2')&&(_let_da_stamp == 'Z')) - { - char app = ' '; - set_row(_i++,"@0g%c", app); - set_row (_i++,"@0gCONTI D' ORDINE PASSIVI"); - set_row(_i++,"@0g%c", app); - stampa_classe = FALSE; - } - else - if ((_sez_da_stamp == '2')&&(_let_da_stamp != 'Z')) - { - char app = ' '; - set_row(_i++,"@0g%c", app); - set_row (_i++,"@0gPASSIVO"); - set_row(_i++,"@0g%c", app); - } - - if (_sez_da_stamp == '5') - { - char app = ' '; - set_row(_i++,"@0g%c", app); - set_row (_i++,"@0gCONTI D' ORDINE"); - set_row(_i++,"@0g%c", app); - stampa_classe = FALSE; - } - - if (_sez_da_stamp == '9') - { - char app = ' '; - set_row(_i++,"@0g%c", app); - set_row (_i++,"@0gCONTO ECONOMICO"); - set_row(_i++,"@0g%c", app); - } - } - else - if ((_let_da_stamp!=_let_stamp)&&(_sez_da_stamp==_sez_stamp)) - { - if ((_sez_da_stamp == '1')&&(_let_da_stamp == 'Z')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - set_row (_i++,"@0gCONTI D' ORDINE ATTIVI"); - set_row (_i++,"@0g%c", app); - stampa_classe = FALSE; - } - if ((_sez_da_stamp == '2')&&(_let_da_stamp == 'Z')) - { - char app = ' '; - set_row(_i++,"@0g%c", app); - set_row (_i++,"@0gCONTI D' ORDINE PASSIVI"); - set_row(_i++,"@0g%c", app); - stampa_classe = FALSE; - } - } - - if (stampa_classe) - { - if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp== '9')) - { - char app = ' '; - set_row (_i++,"@0g%c", app); - if (_let_da_stamp != ' ') - set_row(_i,"@0g%c", _let_da_stamp); - - if (_numr_da_stamp != "") - set_row(_i,"@2g%8s", (const char*) numrom); - - if (_num_da_stamp != 0) - set_row(_i,"@11g%2d", _num_da_stamp); - - _d2 = (const char*) descrizione; - set_row(_i,"@14g#a", &_d2); - // setta_righe_descr(_descr); - } - } - } - set_row (_i,"@58g$[r]%3d$[n]", _gruppo); - set_row (_i,"@62g$[r]%3d$[n]", _conto); - if (_sottoc != 0) - set_row (_i,"@66g$[r]%6ld$[n]", _sottoc); - set_row (_i,"@73g%.40s", (const char*) descr); - - if (sez_opp != '0') - { - set_row (_i,"@116g%c", sez_opp); - - if (let_opp != '\0') - set_row (_i,"@118g%c", let_opp); - - if (numr_opp != 0) - set_row (_i,"@120g%8s", (const char*) numrom_opp); - - if (num_opp != 0) - set_row (_i++,"@129g%2d", num_opp); - } - else - _i++; -} - -/*void CG1100_application::setta_righe_descr(TParagraph_string* str) - { - const char* r; - - while ((r = str->get()) != NULL) - { - set_row (_i,"@14g%s",r); - _i++; - } - _i--; - } */ - -void CG1100_application::set_senza_IV() -{ - int i; - - TRectype & rec = current_cursor()->curr(); - - int gruppo = rec.get_int (PCN_GRUPPO); - int conto = rec.get_int (PCN_CONTO); - long sottoc = rec.get_long(PCN_SOTTOCONTO); - - reset_print (); - i = 1; - - if (_prima_volta) - { - _g_prec = gruppo; - _c_prec = conto; - _prima_volta = FALSE; - } - - if (sottoc == 0L) // Se si tratta di un conto - { - if (gruppo != _g_prec) - _stampa_riga_vuota = TRUE; - } - else - { - if (gruppo != _g_prec || conto != _c_prec) - _stampa_riga_vuota = TRUE; - } - - if (_stampa_riga_vuota) - { - char app = ' '; - set_row (i++,"@0g%c", app); - _stampa_riga_vuota = FALSE; - } - - set_row (i, "$[r]@pn$[n] $[r]@pn$[n] $[r]@pn$[n]", - FLD(LF_PCON, PCN_GRUPPO, "###"), FLD(LF_PCON,PCN_CONTO, "###"), - FLD(LF_PCON, PCN_SOTTOCONTO, "######")); - - - set_row (i, "@16g@50s", FLD(LF_PCON,PCN_DESCR) ); - - if (conto != 0 && sottoc == 0l) - { - set_row (i, "@76g@pn", FLD(LF_PCON, PCN_INDBIL, "##") ); - set_row (i, "@82g@1s", FLD(LF_PCON, PCN_TMCF) ); - set_row (i, "@89g@f", FLD(LF_PCON, PCN_STSOTTBIL) ); - set_row (i, "@98g@f", FLD(LF_PCON, PCN_COMPENS) ); - set_row (i, "@121g@f", FLD(LF_PCON, PCN_STSOTTAB) ); - } - if (sottoc != 0l) - { - set_row (i, "@104g@1n", FLD(LF_PCON, PCN_RICSER) ); - set_row (i, "@109g@1n", FLD(LF_PCON, PCN_TIPOSPRIC) ); - set_row (i, "@115g@1s", FLD(LF_PCON, PCN_SEZSALDI) ); - set_row (i, "@129g@f", FLD(LF_PCON, PCN_STSOTTAB) ); - } -} - -void CG1100_application::set_con_ana() -{ - // gruppo, conto e sottoconto - int g,c; - long s; - char tmcf; - int TipoSpric, IndBil; - - reset_row (1); - - g = _rec->get_int (PCN_GRUPPO); - c = _rec->get_int (PCN_CONTO); - s = _rec->get_long (PCN_SOTTOCONTO); - tmcf = _rec->get(PCN_TMCF)[0]; - TipoSpric = _rec->get_int(PCN_TIPOSPRIC); - IndBil = _rec->get_int(PCN_INDBIL); - - TString cod(_rec->get(PCN_CODCBL)); - - set_row (1, "%-10s", (const char *) cod); - - set_row (1, "@15g%-40s", "") ; /* TBI */ - set_row (1, "@60g$[r]%3d$[n] $[r]%3d$[n] $[r]%6ld$[n]", g, c, s); - _d1 = _rec->get (PCN_DESCR); - - set_row (1, "@78g#a", &_d1); - - /* const char * s2 = s1.get(); - - if (s2) - { - reset_row(2); - set_row (2, "@78g%-30s", s2); - }*/ -} - -void CG1100_application::set_senza_ana() -{ - - reset_row (1); - - set_row (1, "$[r]@pn$[n] $[r]@pn$[n] $[r]@pn$[n]", - FLD(LF_PCON, PCN_GRUPPO, "###"), FLD(LF_PCON,PCN_CONTO, "###"), - FLD(LF_PCON, PCN_SOTTOCONTO, "######")); - - set_row (1, "@16g@50s", FLD(LF_PCON,PCN_DESCR) ); - - set_row (1, "@69g@1s", FLD(LF_PCON, PCN_SEZIVD) ); - set_row (1, "@71g@1s", FLD(LF_PCON, PCN_LETTIVD) ); - set_row (1, "@73g#-8t", &_clivd); - set_row (1, "@82g@pn", FLD(LF_PCON, PCN_NUMIVD, "@@") ); - - set_row (1, "@87g@pn", FLD(LF_PCON, PCN_INDBIL, "##") ); - set_row (1, "@92g@1s", FLD(LF_PCON, PCN_TMCF) ); - set_row (1, "@99g@f", FLD(LF_PCON, PCN_STSOTTBIL) ); - set_row (1, "@107g@f", FLD(LF_PCON, PCN_COMPENS) ); - set_row (1, "@114g@1n", FLD(LF_PCON, PCN_TIPOSPRIC) ); - set_row (1, "@120g@1s", FLD(LF_PCON, PCN_SEZSALDI) ); -} - - -void CG1100_application::set_completa() -{ - TRectype & rec = current_cursor()->curr(); - char sezione; - int i; - - int gruppo = rec.get_int (PCN_GRUPPO); - int conto = rec.get_int (PCN_CONTO); - long sottoc = rec.get_long(PCN_SOTTOCONTO); - sezione = rec.get_char(PCN_SEZIVD); - TString desc = rec.get(PCN_DESCR); - - if (_prima_volta) - { - _s_prec = 0; - _prima_volta = FALSE; - } - - if (sottoc != 0l && _s_prec != 0l) - i = 1; - else - { - i = 1; - char app = ' '; - set_row (i++,"@0g%c", app); - } - - reset_print (); - - set_row (i, "$[r]@pn$[n] $[r]@pn$[n] $[r]@pn$[n]", - FLD(LF_PCON, PCN_GRUPPO, "###"), FLD(LF_PCON,PCN_CONTO, "###"), - FLD(LF_PCON, PCN_SOTTOCONTO, "######")); - - - // set_row (1, "@16g@50s", FLD(LF_PCON,PCN_DESCR) ); - set_row (i, "@16g%.40s", (const char*) desc); // ??? - - if (sezione != '0' && sezione != '9') - set_row (i, "@58g@1s", FLD(LF_PCON, PCN_SEZIVD) ); - set_row (i, "@60g@1s", FLD(LF_PCON, PCN_LETTIVD) ); - set_row (i, "@62g#-8t", &_clivd ); - set_row (i, "@71g@pn", FLD(LF_PCON, PCN_NUMIVD, "@@") ); - - if (conto != 0 && sottoc == 0l) - { - set_row (i, "@76g@pn", FLD(LF_PCON, PCN_INDBIL, "##") ); - set_row (i, "@82g@1s", FLD(LF_PCON, PCN_TMCF) ); - set_row (i, "@89g@f", FLD(LF_PCON, PCN_STSOTTBIL) ); - set_row (i, "@98g@f", FLD(LF_PCON, PCN_COMPENS) ); - set_row (i, "@121g@f", FLD(LF_PCON, PCN_STSOTTAB) ); - } - if (sottoc != 0l) - { - set_row (i, "@104g@1n", FLD(LF_PCON, PCN_RICSER) ); - set_row (i, "@109g@1n", FLD(LF_PCON, PCN_TIPOSPRIC) ); - set_row (i, "@115g@1s", FLD(LF_PCON, PCN_SEZSALDI) ); - set_row (i, "@129g@f", FLD(LF_PCON, PCN_STSOTTAB) ); - } - _s_prec = sottoc; -} - -bool CG1100_application::elabora_riga() -{ - TRectype& curr_rec = *_rec; - - switch (_tipo_stampa) - { - case completa: - case senza_IV_direttiva: - curr_rec = current_cursor()->curr(); - break; - case senza_ana_bil: - { - curr_rec = current_cursor()->curr(); - int conto = curr_rec.get_int(PCN_CONTO); - long sottoc = curr_rec.get_long(PCN_SOTTOCONTO); - if (conto != 0) - { - // se e' un sottoconto stampo sotttab in 127 - if (sottoc != 0) - { - set_row (1, "@127g@f", FLD(LF_PCON, PCN_STSOTTAB)); - set_row (1, "@117g "); - } - else - // se e' un conto stampo sotttab in 124 - { - set_row (1, "@117g@f", FLD(LF_PCON, PCN_STSOTTAB)); - set_row (1, "@127g "); - } - } - break; - } - case con_ana_bil: - case con_IV_direttiva: - curr_rec = *_rec; - break; - default: - break; - } - - // Gestione salto pagina - if (_tipo_stampa == con_ana_bil) // || _tipo_stampa == con_IV_direttiva) - return FALSE; - - int new_gruppo = curr_rec.get_int(PCN_GRUPPO); - - if (_salto_pag && new_gruppo != _old_gruppo) - { - const bool salta = _old_gruppo > 0; - _old_gruppo = new_gruppo; - return salta; - } - return FALSE; -} - -int CG1100_application::leggo_sottoc(int gruppo,int conto,long sottoc) -{ - TLocalisamfile pconti (LF_PCON,FALSE); - char sez; - int gr,co; - int esito = 0; - bool esiste_conto_classificato = FALSE; - bool esiste_conto_non_classificato = FALSE; - - pconti.zero(); - pconti.put(PCN_GRUPPO, gruppo); - pconti.put(PCN_CONTO, conto); - pconti.put(PCN_SOTTOCONTO, sottoc); - - for (pconti.read(); !pconti.eof() ;pconti.next()) - { - gr = pconti.get_int (PCN_GRUPPO); - co = pconti.get_int (PCN_CONTO); - - if (gruppo != gr || conto != co) break; - - sez = pconti.get_char(PCN_SEZIVD); - - if (sez != '0') - esiste_conto_classificato = TRUE; - - if (sez == '0') - esiste_conto_non_classificato = TRUE; - } - - if (!esiste_conto_classificato && esiste_conto_non_classificato) - esito = 0; - - if (esiste_conto_classificato && esiste_conto_non_classificato) - esito = 1; - - if (esiste_conto_classificato && !esiste_conto_non_classificato) - esito = 2; - - return esito; -} - -bool CG1100_application::preprocess_page(int file,int counter) -{ - static int c1 = 0; - static TString16 a1; - char sez; - - if (_tipo_stampa == completa) - set_completa(); - - if (_tipo_stampa == senza_IV_direttiva) - { - if (file == LF_PCON) - { - TRectype & rec = current_cursor()->curr(); - int gruppo = rec.get_int (PCN_GRUPPO); - int conto = rec.get_int (PCN_CONTO); - long sottoc = rec.get_long(PCN_SOTTOCONTO); - - force_setpage(); - - if (conto == 0) return FALSE; //Scarto i gruppi - - if (sottoc == 0L) // Se si tratta di un conto - { - sez = rec.get_char(PCN_SEZIVD); - - if (sez == '0') - { - _sottoc_classificato = leggo_sottoc(gruppo,conto,sottoc); - if (_sottoc_classificato == 0) - _conto_classificato = TRUE; - else - if (_sottoc_classificato == 1) - { - _conto_classificato = FALSE; - return FALSE; - } - else - if (_sottoc_classificato == 2) - { - _conto_classificato = TRUE; - return FALSE; - } - } - else - { - _conto_classificato = TRUE; - return FALSE; - } - } - else // Se si tratta di un sottoconto - { - if (!_conto_classificato) - { - char sezione = rec.get_char(PCN_SEZIVD); - - if (sezione != '0') - return FALSE; - } - else - return FALSE; - } - _g_prec = gruppo; - _c_prec = conto; - } - } - if (_tipo_stampa == senza_ana_bil) - { - TRectype & rec = current_cursor()->curr(); - - if (rec.get_int(PCN_CONTO) == 0) return FALSE; - if (rec.get_long(PCN_SOTTOCONTO) == 0L) - a1 = rec.get(PCN_CODCBL); - else - if (rec.get(PCN_CODCBL).empty()) - rec.put(PCN_CODCBL, a1); - if (rec.get(PCN_CODCBL).not_empty()) return FALSE; - } - if (elabora_riga()) - printer().formfeed(); - - const int c3 = atoi(_rec->get(PCN_NUMRIVD)); - const int o3 = atoi(_rec->get(PCN_NUMRIVDOPP)); - - _clivd = itor(c3); - _clivdo = itor(o3); - - return TRUE; -} - -bool CG1100_application::set_print(int) -{ - KEY tasto; - - _old_gruppo = 0; - tasto = _msk->run(); - - if (tasto == K_ENTER) - { - _tipo_stampa = (stampe)_msk->get_int(F_SCELTA_STAMPA); - _salto_pag = _msk->get_bool (F_SALTO_PAGINA); - _data_stampa = _msk->get (F_DATA_STAMPA); - - // scegli_cur(); - enable_link("Collegamento Piano dei conti : ", 'r'); - set_multiple_link(TRUE); - - _sez_stamp = ' '; - _let_stamp = ' '; - _numr_stamp = ""; - _num_stamp = 0; - _classe_stampata = ""; - - if (_tipo_stampa == senza_IV_direttiva) - { - _conto_classificato = TRUE; - _sottoc_classificato = 0; - _stampa_riga_vuota = FALSE; - _prima_volta = TRUE; - } - - switch (_tipo_stampa) - { - case completa: - case senza_IV_direttiva: - case senza_ana_bil: - select_cursor (_cur_c1); break; - case con_IV_direttiva: - case con_ana_bil: - select_cursor (_cur_c2); break; - default: - break; - } - init_sort(); - _resetta_righe_stampa = TRUE; - - printer().footerlen(5); - - return TRUE; - } - return FALSE; -} - -void CG1100_application::intesta (stampe tipo) -{ - int soh = 1; // riga d'inizio dell'intestazione - const long firm = get_firm(); - - reset_header (); - TLocalisamfile ditte(LF_NDITTE); - ditte.zero(); - ditte.put(NDT_CODDITTA, firm); - ditte.read(); - if (ditte.bad()) ditte.zero(); - - TString s(132); - s = ditte.get(NDT_RAGSOC); - TString data = _data_stampa.string(); - - set_header (soh++, "Ditta : %ld %s@110gData@115g%s Pag. @#", firm, (const char *) s, (const char*) data); - - - set_header (soh,"@0gPIANO DEI CONTI"); - - switch (tipo) - { - case completa: - set_header (soh++, "@20gStampa completa per IV direttiva"); - s.fill('-'); - set_header (soh++, (const char *) s); - set_header (soh++, "Conto @59gSez. Classe@75gTipo@86gNo Dettaglio@104gT@107gSpesa@118gDet.alleg.bil."); - set_header (soh++, "Sottoconto @16gDescrizione@61gIV dir.@75gConto@81gC/F@86gBilancio@97gComp.@104gA@107gRicavo@114gSez@118gSot.con * Mov."); - break; - - case con_IV_direttiva: - set_header (soh++, "@20gStampa conti riclassificati per IV direttiva"); - s.fill('_'); - set_header (soh++, (const char *) s); - set_header (soh++, "@58gCodici Piano@116gSez. e Classe"); - set_header (soh++, "Classe@14gDescrizione@58gdei Conti @73gDescrizione@116gdi segno opposto"); - - break; - - case senza_IV_direttiva: - set_header (soh++, "@20gStampa conti non collegati per IV direttiva"); - s.fill('_'); - set_header (soh++, (const char *) s); - set_header (soh++, "Conto @75gTipo@86gNo Dettaglio@104gT@107gSpesa@118gDet.alleg.bil."); - set_header (soh++, "Sottoconto @16gDescrizione@75gConto@81gC/F@86gBilancio@97gComp.@104gA@107gRicavo@114gSez@118gSot.con * Mov."); - break; - - case con_ana_bil: - - s.fill('_'); - set_header (soh++, (const char *) s); - set_header (soh++, "Codice @61gCodici Piano@113gDett.alleg.Bilancio"); - set_header (soh++, "Tabella@16gDescrizione@60gdei Conti @78gDescrizione @113gSot.con. * Moviment."); - - break; - - case senza_ana_bil: - s.fill('_'); - set_header (soh++, (const char *) s); - set_header (soh++, "Conto @67gSez. Classe@85gTipo@96gNo Dettaglio@112gSpesa @123gDet.bil."); - set_header (soh++, "Sottoconto @16gDescrizione@68gIV dir. @85gConto @91gC/F @96gBilancio @106gComp. @112gRicavo @119gSez"); - break; - - default: - break; - } - - set_header (soh++,(const char*)s); - set_header (soh, ""); - -} - -const char* CG1100_application::descrizione_numero(char sezione, char lettera, int numr, int numero) -{ - TTable& tabivd = *_tab; - TString dep,dep2; - - tabivd.zero(); - if (numr == 0 && numero == 0) - dep = format("%c%c",sezione,lettera); - else - if (numero == 0) - { - if (numr != 0) - dep = format("%1c%1c%04d",sezione, lettera, numr); - else - dep = format("%c%c ",sezione,lettera); - } - else - { - if (numr != 0) - dep = format("%1c%1c%04d%02d",sezione, lettera, numr,numero); - else - dep = format("%c%c %02d",sezione,lettera,numero); - } - - tabivd.put("CODTAB", dep); - tabivd.read(); - dep2 = tabivd.get("CODTAB"); - if (dep == dep2) - tmp = tabivd.get("S0"); - else - tmp = ""; - return tmp; -} - - -bool CG1100_application::user_create() -{ - _rel = new TRelation (LF_PCON); - _tab = new TTable(TAB_IVD); - _msk = new TMask ("cg1100a") ; - - TCursor *cursor = new TCursor (_rel); - - _cur_c1 = add_cursor (cursor); - - _rec = new TRectype (cursor->curr()); - - _pcont_reclen = _rec->len(); - _sort = new TSort(_pcont_reclen); - - _cur_c2 = add_cursor (NULL); - - add_file(LF_PCON); - // _descr = new TParagraph_string ("",40); - - - _tipo_stampa = completa; - _salto_pag = FALSE; - _bil = new bil_ivd; - _sort = new TSort(); - return TRUE; -} - -bool CG1100_application::user_destroy() -{ - delete _rel; - delete _tab; - delete _msk; - delete _rec; - // delete _descr; - delete _bil; - delete _sort; - return TRUE; -} - -int cg1100(int argc, char* argv[]) -{ - CG1100_application a; - a.run(argc, argv, "Stampa Piano dei Conti"); - return 0; -} +// cg1100.cpp +// Stampa piano dei conti + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "cg1.h" +#include "cg1100.h" + +const char * TAB_ANABIL = "%IVD"; +const char * TAB_IVD = "%IVD"; + +const int CODTABLEN = 15; + +enum stampe { + completa=1, + con_IV_direttiva, + senza_IV_direttiva, + completa_bil, + con_ana_bil, + senza_ana_bil + }; + +class CG1100_application : public TPrintapp +{ + struct bil_ivd + { + char sez; + char let; + char numr[5]; + char num[4]; + char gruppo[4]; + char conto[4]; + char sottoc[8]; + char descr[52]; + char sez_opp; + char let_opp; + char numr_opp[5]; + int num_opp; + }; + + bil_ivd* _bil; + TTable* _tab; // tabella codici IV direttiva + TRectype* _rec; + TSort* _sort; + TRelation* _rel; + TMask* _msk; + TParagraph_string _d1, _d2; // qui + const char* _buf; + stampe _tipo_stampa; + bool _salto_pag,_resetta_righe_stampa; + int _old_gruppo; + int _pcont_reclen,_i; + int _cur_c1, _cur_c2; + TString _clivd, _clivdo; + char _sez_da_stamp,_sez_stamp,_let_da_stamp,_let_stamp; + TString _numr_da_stamp,_numr_stamp; + int _gruppo,_conto,_num_da_stamp,_num_stamp,_g_prec,_c_prec; + long _sottoc,_s_prec; + TString _classe_da_stampare,_classe_stampata; + bool _conto_classificato,_sottoc_classificato,_stampa_riga_vuota; + bool _prima_volta; + TDate _data_stampa; + +public: + + virtual bool user_destroy() ; + virtual bool user_create() ; + + virtual void set_page (int,int); + virtual bool preprocess_print (int,int); + virtual bool preprocess_page (int,int); + virtual print_action postprocess_page (int,int); + virtual void postclose_print (); + + virtual bool set_print(int); + + void intesta (stampe); + + + bool elabora_riga(); // decide se fare salto pagina o no + void do_sort(); + void set_completa (); + void set_con_IV (); + void set_senza_IV (); + void set_con_ana (); + void set_senza_ana (); + void init_sort(); + const char* descrizione_numero(char, char, int, int); + // void setta_righe_descr(TParagraph_string*); + int leggo_sottoc(int,int,long); + void riempi_record(char,char,const TString&,int,int,int,long,const TString&,char,char,const TString&,int); + void set_bil_key(bil_ivd* b, char sezione, char lettera, + const char* numero_romano, int numero, + int gruppo = 0, int conto = 0, long sottoconto = 0L); + void set_bil_val(bil_ivd* b, const char* descr,char sez_opp,char let_opp, + const char* numr_opp,int num_opp); + + void process_link(int id, const char* txt); + + CG1100_application() : _clivd(8), _clivdo(8), _d1("", 30), _d2("", 40) {} +}; + +void CG1100_application::process_link(int id, const char* txt) +{ + TString ss = "1|"; ss << txt; + TMessage fs(cmd2name("cg0","-0"), MSG_LN, ss); + TMailbox m; + m.send(fs); + TExternal_app cg0("cg0 -0"); + if (cg0.run()) beep(); +} + +void CG1100_application::init_sort() +{ + switch (_tipo_stampa) + { + case con_IV_direttiva: + _sort->reset(sizeof(bil_ivd)); + + _sort -> addsortkey ((char*)&(_bil->sez) - (char*)&(_bil->sez),1); + _sort -> addsortkey ((char*)&(_bil->let) - (char*)&(_bil->sez),1); + _sort -> addsortkey ((char*)&(_bil->numr) - (char*)&(_bil->sez),4); + _sort -> addsortkey ((char*)&(_bil->num) - (char*)&(_bil->sez),2); + _sort -> addsortkey ((char*)&(_bil->gruppo) - (char*)&(_bil->sez),3); + _sort -> addsortkey ((char*)&(_bil->conto) - (char*)&(_bil->sez),3); + _sort -> addsortkey ((char*)&(_bil->sottoc) - (char*)&(_bil->sez),6); + break; + case con_ana_bil: + { + TRecfield codcbl (*_rec, PCN_CODCBL); + + _sort->reset(_rec->len()); + _sort->addsortkey (codcbl); + break; + } + default: + break; + } +} + +void CG1100_application::set_bil_key(bil_ivd* b, char sezione, char lettera, + const char* numero_romano, int numero, + int gruppo, int conto,long sottoconto) +{ + b->sez = sezione; + b->let = lettera; + strcpy(b->numr, numero_romano); + sprintf(b->num , "%2d", numero); + sprintf(b->gruppo , "%3d", gruppo); + sprintf(b->conto , "%3d", conto); + sprintf(b->sottoc , "%6ld", sottoconto); +} + +void CG1100_application::set_bil_val(bil_ivd* b, const char* descr, + char sez_opp,char let_opp, + const char* numr_opp,int num_opp) +{ + strcpy(b->descr, descr); + b->sez_opp = sez_opp; + b->let_opp = let_opp; + strcpy(b->numr_opp, numr_opp); + b->num_opp = num_opp; +} + +void CG1100_application::riempi_record(char sez,char let,const TString& numr, + int numero,int g,int c,long s, + const TString& descr,char sez_opp, + char let_opp,const TString& numr_opp, + int num_opp) +{ + set_bil_key(_bil, sez, let, numr, numero, g, c, s); + set_bil_val(_bil, descr, sez_opp, let_opp, numr_opp, num_opp); + _sort->sort ((const char*) _bil); +} + +void CG1100_application::postclose_print() +{ + // if (_tipo_stampa == con_IV_direttiva) + // delete _sort; +} + +print_action CG1100_application::postprocess_page(int file,int counter) +{ + switch (_tipo_stampa) + { + case completa: + case senza_IV_direttiva: + case senza_ana_bil: + break; + case con_IV_direttiva: + case con_ana_bil: + { + //const char * buf; + struct bil_ivd* bil = (struct bil_ivd*) _buf; + /* + if (_sez_da_stamp != _sez_stamp) + { + if (_sez_da_stamp == '5' || _sez_da_stamp == '9') + { + reset_print(); + _i = 1; + set_con_IV(); + _resetta_righe_stampa = FALSE; + } + else + _resetta_righe_stampa = TRUE; + } + else + _resetta_righe_stampa = TRUE; + */ + _sez_stamp = _sez_da_stamp; + _let_stamp = _let_da_stamp; + _numr_stamp = _numr_da_stamp; + _num_stamp = _num_da_stamp; + _classe_stampata.format("%c%c%s%2d",_sez_stamp,_let_stamp,(const char*)_numr_stamp,_num_stamp); + + + + if ( (_buf = _sort->retrieve()) != NULL) + { + bil = (struct bil_ivd*) _buf; + _sez_da_stamp = bil->sez; + _let_da_stamp = bil->let; + _numr_da_stamp = bil->numr; + _numr_da_stamp.ltrim(); + _num_da_stamp = atoi(bil->num); + _gruppo = atoi(bil->gruppo); + _conto = atoi(bil->conto); + _sottoc = atol(bil->sottoc); + _classe_da_stampare.format("%c%c%s%2d",_sez_da_stamp,_let_da_stamp,(const char*)_numr_da_stamp,_num_da_stamp); + + //set_auto_ff(FALSE); + + return REPEAT_PAGE; + } + break; + } + default: + break; + + } + return NEXT_PAGE; +} + +void CG1100_application::set_page(int file,int counter) +{ + //const char* buf; + + intesta (_tipo_stampa); + switch (_tipo_stampa) + { + case con_IV_direttiva: + { + // if (_resetta_righe_stampa) + // { + reset_print(); + _i = 1; + // } + + if (_sez_da_stamp != _sez_stamp) + // { + // if (_sez_da_stamp=='1' || _sez_da_stamp=='2') + set_con_IV (); + // if (_sez_da_stamp == '5' || _sez_da_stamp == '9') + // { + // set_row (_i,"%s",""); + // set_auto_ff(TRUE); + // } + // } + else + if (_buf != NULL) + set_con_IV(); + } + break; + case con_ana_bil: + set_con_ana(); + break; + case senza_IV_direttiva: + set_senza_IV(); + break; + case senza_ana_bil: + set_senza_ana(); + break; +default: + break; +} +} + +////////////////////////////////////////////////////////////// +// Crea sort se necessario e seleziona il cursore opportuno +////////////////////////////////////////////////////////////// +void CG1100_application::do_sort() +{ + switch (_tipo_stampa) + { + case completa: + case senza_IV_direttiva: + case senza_ana_bil: + break; + case con_IV_direttiva: + { + char sez_conto,let_conto; + TString numr_conto; + int num_conto; + bool classe_conto = FALSE; + + _sort->init(); + select_cursor (_cur_c1); + + TCursor * cursor = current_cursor(); + TRectype & rec = cursor->curr(); + + long last = cursor->items(); + + for ( *cursor = 0; cursor->pos() < last; ++(*cursor) ) + { + int g = rec.get_int(PCN_GRUPPO); + int c = rec.get_int(PCN_CONTO); + long s = rec.get_int(PCN_SOTTOCONTO); + + if (g != 0 && c == 0 && s == 0) continue; + + char sez = rec.get_char(PCN_SEZIVD); + char let = rec.get_char(PCN_LETTIVD); + TString numr = rec.get (PCN_NUMRIVD); + int num = rec.get_int (PCN_NUMIVD); + TString descr = rec.get (PCN_DESCR); + char sez_opp = rec.get_char(PCN_SEZIVDOPP); + char let_opp = rec.get_char(PCN_LETTIVDOPP); + TString numr_opp = rec.get (PCN_NUMRIVDOPP); + int num_opp = rec.get_int (PCN_NUMIVDOPP); + + if ((g != 0) && (c != 0) && (s == 0)) + { + if (sez != '\0' && sez != '0') + { + sez_conto = sez; + + if (let != '\0') + let_conto = let; + else + if ((sez == '1')||(sez == '2')) + let_conto = 'Z'; + else + let_conto = let; + + numr_conto = numr; + num_conto = num; + classe_conto = TRUE; + riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,descr,sez_opp,let_opp,numr_opp,num_opp); + } + else + classe_conto = FALSE; + } + + if ((g != 0) && (c != 0) && (s != 0)) + { + if (classe_conto) + riempi_record(sez_conto,let_conto,numr_conto,num_conto,g,c,s,descr,sez_opp,let_opp,numr_opp,num_opp); + else + { + if (sez != '\0' && sez != '0') + { + if (let == '\0') + if ((sez == '1')||(sez == '2')) + let = 'Z'; + + riempi_record(sez,let,numr,num,g,c,s,descr,sez_opp,let_opp,numr_opp,num_opp); + } + } + } + } + + _sort->endsort(); + // delete _bil; + select_cursor (_cur_c2); + + break; + } + + case con_ana_bil: + { + _sort->init(); + + select_cursor (_cur_c1); + + TCursor * cursor = current_cursor(); + TRectype & rec = cursor->curr(); + + long last = cursor->items(); + TString c1(12); + + for ( *cursor = 0; cursor->pos() < last; ++(*cursor) ) + { + if (rec.get(PCN_CONTO).not_empty() && rec.get(PCN_SOTTOCONTO).empty()) + c1 = rec.get(PCN_CODCBL); + else + if (rec.get(PCN_SOTTOCONTO).not_empty() && rec.get(PCN_CODCBL).empty()) + rec.put(PCN_CODCBL, c1); + if (rec.get(PCN_CODCBL).not_empty() ) + _sort->sort (rec.string()); + } + + _sort->endsort(); + select_cursor (_cur_c2); + break; + } + default: + break; + } +} + +bool CG1100_application::preprocess_print (int file,int counter) +{ + do_sort(); + switch (_tipo_stampa) + { + case con_IV_direttiva: + case con_ana_bil: + { + struct bil_ivd* bil = (struct bil_ivd*) _buf; + + if ((_buf = _sort->retrieve()) != NULL) + { + bil = (struct bil_ivd*) _buf; + _sez_da_stamp = bil->sez; + _let_da_stamp = bil->let; + _numr_da_stamp = bil->numr; + _numr_da_stamp.ltrim(); + _num_da_stamp = atoi(bil->num); + _gruppo = atoi(bil->gruppo); + _conto = atoi(bil->conto); + _sottoc = atol(bil->sottoc); + _classe_da_stampare.format("%c%c%s%2d",_sez_da_stamp,_let_da_stamp,(const char*)_numr_da_stamp,_num_da_stamp); + + return TRUE; + } + else + return FALSE; + } + break; +default: + break; +} + return TRUE; +} + +void CG1100_application::set_con_IV() +{ + struct bil_ivd* bil = (struct bil_ivd*) _buf; + + TString descrizione,descr; + char sez_opp,let_opp; + int num_opp,numr_opp; + bool stampa_classe = TRUE; + int numr = atoi(_numr_da_stamp); + TString numrom = itor(numr); + + sez_opp = bil->sez_opp; + let_opp = bil->let_opp; + numr_opp = atoi(bil->numr_opp); + TString numrom_opp = itor(numr_opp); + num_opp = bil->num_opp; + + descrizione = descrizione_numero(_sez_da_stamp,_let_da_stamp,numr,_num_da_stamp); + descr = bil->descr; + + //Se la classe prelevata dal record corrente del sort e' diversa dalla classe + //prelevata dal record precedente, allora stampo la nuova classe con i relativi + //sottoconti. In caso contrario continuo a stampare solo i sottoconti. + + if (_classe_da_stampare != _classe_stampata) + { + if (_sez_da_stamp != _sez_stamp) + { + if ((_sez_da_stamp == '1')&&(_let_da_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i++,"@0gCONTI D' ORDINE ATTIVI"); + set_row (_i++,"@0g%c", app); + stampa_classe = FALSE; + } + else + if ((_sez_da_stamp == '1')&&(_let_da_stamp != 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i++,"@0gATTIVO"); + set_row (_i++,"@0g%c", app); + } + + if ((_sez_da_stamp == '2')&&(_let_da_stamp == 'Z')) + { + char app = ' '; + set_row(_i++,"@0g%c", app); + set_row (_i++,"@0gCONTI D' ORDINE PASSIVI"); + set_row(_i++,"@0g%c", app); + stampa_classe = FALSE; + } + else + if ((_sez_da_stamp == '2')&&(_let_da_stamp != 'Z')) + { + char app = ' '; + set_row(_i++,"@0g%c", app); + set_row (_i++,"@0gPASSIVO"); + set_row(_i++,"@0g%c", app); + } + + if (_sez_da_stamp == '5') + { + char app = ' '; + set_row(_i++,"@0g%c", app); + set_row (_i++,"@0gCONTI D' ORDINE"); + set_row(_i++,"@0g%c", app); + stampa_classe = FALSE; + } + + if (_sez_da_stamp == '9') + { + char app = ' '; + set_row(_i++,"@0g%c", app); + set_row (_i++,"@0gCONTO ECONOMICO"); + set_row(_i++,"@0g%c", app); + } + } + else + if ((_let_da_stamp!=_let_stamp)&&(_sez_da_stamp==_sez_stamp)) + { + if ((_sez_da_stamp == '1')&&(_let_da_stamp == 'Z')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + set_row (_i++,"@0gCONTI D' ORDINE ATTIVI"); + set_row (_i++,"@0g%c", app); + stampa_classe = FALSE; + } + if ((_sez_da_stamp == '2')&&(_let_da_stamp == 'Z')) + { + char app = ' '; + set_row(_i++,"@0g%c", app); + set_row (_i++,"@0gCONTI D' ORDINE PASSIVI"); + set_row(_i++,"@0g%c", app); + stampa_classe = FALSE; + } + } + + if (stampa_classe) + { + if ((_sez_da_stamp=='1')||(_sez_da_stamp=='2')||(_sez_da_stamp== '9')) + { + char app = ' '; + set_row (_i++,"@0g%c", app); + if (_let_da_stamp != ' ') + set_row(_i,"@0g%c", _let_da_stamp); + + if (_numr_da_stamp != "") + set_row(_i,"@2g%8s", (const char*) numrom); + + if (_num_da_stamp != 0) + set_row(_i,"@11g%2d", _num_da_stamp); + + _d2 = (const char*) descrizione; + set_row(_i,"@14g#a", &_d2); + // setta_righe_descr(_descr); + } + } + } + set_row (_i,"@58g$[r]%3d$[n]", _gruppo); + set_row (_i,"@62g$[r]%3d$[n]", _conto); + if (_sottoc != 0) + set_row (_i,"@66g$[r]%6ld$[n]", _sottoc); + set_row (_i,"@73g%.40s", (const char*) descr); + + if (sez_opp != '0') + { + set_row (_i,"@116g%c", sez_opp); + + if (let_opp != '\0') + set_row (_i,"@118g%c", let_opp); + + if (numr_opp != 0) + set_row (_i,"@120g%8s", (const char*) numrom_opp); + + if (num_opp != 0) + set_row (_i++,"@129g%2d", num_opp); + } + else + _i++; +} + +/*void CG1100_application::setta_righe_descr(TParagraph_string* str) + { + const char* r; + + while ((r = str->get()) != NULL) + { + set_row (_i,"@14g%s",r); + _i++; + } + _i--; + } */ + +void CG1100_application::set_senza_IV() +{ + int i; + + TRectype & rec = current_cursor()->curr(); + + int gruppo = rec.get_int (PCN_GRUPPO); + int conto = rec.get_int (PCN_CONTO); + long sottoc = rec.get_long(PCN_SOTTOCONTO); + + reset_print (); + i = 1; + + if (_prima_volta) + { + _g_prec = gruppo; + _c_prec = conto; + _prima_volta = FALSE; + } + + if (sottoc == 0L) // Se si tratta di un conto + { + if (gruppo != _g_prec) + _stampa_riga_vuota = TRUE; + } + else + { + if (gruppo != _g_prec || conto != _c_prec) + _stampa_riga_vuota = TRUE; + } + + if (_stampa_riga_vuota) + { + char app = ' '; + set_row (i++,"@0g%c", app); + _stampa_riga_vuota = FALSE; + } + + set_row (i, "$[r]@pn$[n] $[r]@pn$[n] $[r]@pn$[n]", + FLD(LF_PCON, PCN_GRUPPO, "###"), FLD(LF_PCON,PCN_CONTO, "###"), + FLD(LF_PCON, PCN_SOTTOCONTO, "######")); + + + set_row (i, "@16g@50s", FLD(LF_PCON,PCN_DESCR) ); + + if (conto != 0 && sottoc == 0l) + { + //set_row (i, "@76g@pn", FLD(LF_PCON, PCN_INDBIL, "##") ); + set_row (i, "@76g@pn", FLD(LF_PCON, PCN_INDBIL, "#") ); + set_row (i, "@82g@1s", FLD(LF_PCON, PCN_TMCF) ); + set_row (i, "@89g@f", FLD(LF_PCON, PCN_STSOTTBIL) ); + set_row (i, "@98g@f", FLD(LF_PCON, PCN_COMPENS) ); + set_row (i, "@121g@f", FLD(LF_PCON, PCN_STSOTTAB) ); + } + if (sottoc != 0l) + { + set_row (i, "@104g@1n", FLD(LF_PCON, PCN_RICSER) ); + set_row (i, "@109g@1n", FLD(LF_PCON, PCN_TIPOSPRIC) ); + set_row (i, "@115g@1s", FLD(LF_PCON, PCN_SEZSALDI) ); + set_row (i, "@129g@f", FLD(LF_PCON, PCN_STSOTTAB) ); + } +} + +void CG1100_application::set_con_ana() +{ + // gruppo, conto e sottoconto + int g,c; + long s; + char tmcf; + int TipoSpric, IndBil; + + reset_row (1); + + g = _rec->get_int (PCN_GRUPPO); + c = _rec->get_int (PCN_CONTO); + s = _rec->get_long (PCN_SOTTOCONTO); + tmcf = _rec->get(PCN_TMCF)[0]; + TipoSpric = _rec->get_int(PCN_TIPOSPRIC); + IndBil = _rec->get_int(PCN_INDBIL); + + TString cod(_rec->get(PCN_CODCBL)); + + set_row (1, "%-10s", (const char *) cod); + + set_row (1, "@15g%-40s", "") ; /* TBI */ + set_row (1, "@60g$[r]%3d$[n] $[r]%3d$[n] $[r]%6ld$[n]", g, c, s); + _d1 = _rec->get (PCN_DESCR); + + set_row (1, "@78g#a", &_d1); + + /* const char * s2 = s1.get(); + + if (s2) + { + reset_row(2); + set_row (2, "@78g%-30s", s2); + }*/ +} + +void CG1100_application::set_senza_ana() +{ + + reset_row (1); + + set_row (1, "$[r]@pn$[n] $[r]@pn$[n] $[r]@pn$[n]", + FLD(LF_PCON, PCN_GRUPPO, "###"), FLD(LF_PCON,PCN_CONTO, "###"), + FLD(LF_PCON, PCN_SOTTOCONTO, "######")); + + set_row (1, "@16g@50s", FLD(LF_PCON,PCN_DESCR) ); + + set_row (1, "@69g@1s", FLD(LF_PCON, PCN_SEZIVD) ); + set_row (1, "@71g@1s", FLD(LF_PCON, PCN_LETTIVD) ); + set_row (1, "@73g#-8t", &_clivd); + set_row (1, "@82g@pn", FLD(LF_PCON, PCN_NUMIVD, "@@") ); + + //set_row (1, "@87g@pn", FLD(LF_PCON, PCN_INDBIL, "##") ); + set_row (1, "@87g@pn", FLD(LF_PCON, PCN_INDBIL, "#") ); + set_row (1, "@92g@1s", FLD(LF_PCON, PCN_TMCF) ); + set_row (1, "@99g@f", FLD(LF_PCON, PCN_STSOTTBIL) ); + set_row (1, "@107g@f", FLD(LF_PCON, PCN_COMPENS) ); + set_row (1, "@114g@1n", FLD(LF_PCON, PCN_TIPOSPRIC) ); + set_row (1, "@120g@1s", FLD(LF_PCON, PCN_SEZSALDI) ); +} + + +void CG1100_application::set_completa() +{ + TRectype & rec = current_cursor()->curr(); + char sezione; + int i; + + int gruppo = rec.get_int (PCN_GRUPPO); + int conto = rec.get_int (PCN_CONTO); + long sottoc = rec.get_long(PCN_SOTTOCONTO); + sezione = rec.get_char(PCN_SEZIVD); + TString desc = rec.get(PCN_DESCR); + + if (_prima_volta) + { + _s_prec = 0; + _prima_volta = FALSE; + } + + if (sottoc != 0l && _s_prec != 0l) + i = 1; + else + { + i = 1; + char app = ' '; + set_row (i++,"@0g%c", app); + } + + reset_print (); + + set_row (i, "$[r]@pn$[n] $[r]@pn$[n] $[r]@pn$[n]", + FLD(LF_PCON, PCN_GRUPPO, "###"), FLD(LF_PCON,PCN_CONTO, "###"), + FLD(LF_PCON, PCN_SOTTOCONTO, "######")); + + + // set_row (1, "@16g@50s", FLD(LF_PCON,PCN_DESCR) ); + set_row (i, "@16g%.40s", (const char*) desc); // ??? + + if (sezione != '0' && sezione != '9') + set_row (i, "@58g@1s", FLD(LF_PCON, PCN_SEZIVD) ); + set_row (i, "@60g@1s", FLD(LF_PCON, PCN_LETTIVD) ); + set_row (i, "@62g#-8t", &_clivd ); + set_row (i, "@71g@pn", FLD(LF_PCON, PCN_NUMIVD, "@@") ); + + if (conto != 0 && sottoc == 0l) + { + //set_row (i, "@76g@pn", FLD(LF_PCON, PCN_INDBIL, "##") ); + set_row (i, "@76g@pn", FLD(LF_PCON, PCN_INDBIL, "#") ); + set_row (i, "@82g@1s", FLD(LF_PCON, PCN_TMCF) ); + set_row (i, "@89g@f", FLD(LF_PCON, PCN_STSOTTBIL) ); + set_row (i, "@98g@f", FLD(LF_PCON, PCN_COMPENS) ); + set_row (i, "@121g@f", FLD(LF_PCON, PCN_STSOTTAB) ); + } + if (sottoc != 0l) + { + set_row (i, "@104g@1n", FLD(LF_PCON, PCN_RICSER) ); + set_row (i, "@109g@1n", FLD(LF_PCON, PCN_TIPOSPRIC) ); + set_row (i, "@115g@1s", FLD(LF_PCON, PCN_SEZSALDI) ); + set_row (i, "@129g@f", FLD(LF_PCON, PCN_STSOTTAB) ); + } + _s_prec = sottoc; +} + +bool CG1100_application::elabora_riga() +{ + TRectype& curr_rec = *_rec; + + switch (_tipo_stampa) + { + case completa: + case senza_IV_direttiva: + curr_rec = current_cursor()->curr(); + break; + case senza_ana_bil: + { + curr_rec = current_cursor()->curr(); + int conto = curr_rec.get_int(PCN_CONTO); + long sottoc = curr_rec.get_long(PCN_SOTTOCONTO); + if (conto != 0) + { + // se e' un sottoconto stampo sotttab in 127 + if (sottoc != 0) + { + set_row (1, "@127g@f", FLD(LF_PCON, PCN_STSOTTAB)); + set_row (1, "@117g "); + } + else + // se e' un conto stampo sotttab in 124 + { + set_row (1, "@117g@f", FLD(LF_PCON, PCN_STSOTTAB)); + set_row (1, "@127g "); + } + } + break; + } + case con_ana_bil: + case con_IV_direttiva: + curr_rec = *_rec; + break; + default: + break; + } + + // Gestione salto pagina + if (_tipo_stampa == con_ana_bil) // || _tipo_stampa == con_IV_direttiva) + return FALSE; + + int new_gruppo = curr_rec.get_int(PCN_GRUPPO); + + if (_salto_pag && new_gruppo != _old_gruppo) + { + const bool salta = _old_gruppo > 0; + _old_gruppo = new_gruppo; + return salta; + } + return FALSE; +} + +int CG1100_application::leggo_sottoc(int gruppo,int conto,long sottoc) +{ + TLocalisamfile pconti (LF_PCON,FALSE); + char sez; + int gr,co; + int esito = 0; + bool esiste_conto_classificato = FALSE; + bool esiste_conto_non_classificato = FALSE; + + pconti.zero(); + pconti.put(PCN_GRUPPO, gruppo); + pconti.put(PCN_CONTO, conto); + pconti.put(PCN_SOTTOCONTO, sottoc); + + for (pconti.read(); !pconti.eof() ;pconti.next()) + { + gr = pconti.get_int (PCN_GRUPPO); + co = pconti.get_int (PCN_CONTO); + + if (gruppo != gr || conto != co) break; + + sez = pconti.get_char(PCN_SEZIVD); + + if (sez != '0') + esiste_conto_classificato = TRUE; + + if (sez == '0') + esiste_conto_non_classificato = TRUE; + } + + if (!esiste_conto_classificato && esiste_conto_non_classificato) + esito = 0; + + if (esiste_conto_classificato && esiste_conto_non_classificato) + esito = 1; + + if (esiste_conto_classificato && !esiste_conto_non_classificato) + esito = 2; + + return esito; +} + +bool CG1100_application::preprocess_page(int file,int counter) +{ + static int c1 = 0; + static TString16 a1; + char sez; + + if (_tipo_stampa == completa) + set_completa(); + + if (_tipo_stampa == senza_IV_direttiva) + { + if (file == LF_PCON) + { + TRectype & rec = current_cursor()->curr(); + int gruppo = rec.get_int (PCN_GRUPPO); + int conto = rec.get_int (PCN_CONTO); + long sottoc = rec.get_long(PCN_SOTTOCONTO); + + force_setpage(); + + if (conto == 0) return FALSE; //Scarto i gruppi + + if (sottoc == 0L) // Se si tratta di un conto + { + sez = rec.get_char(PCN_SEZIVD); + + if (sez == '0') + { + _sottoc_classificato = leggo_sottoc(gruppo,conto,sottoc); + if (_sottoc_classificato == 0) + _conto_classificato = TRUE; + else + if (_sottoc_classificato == 1) + { + _conto_classificato = FALSE; + return FALSE; + } + else + if (_sottoc_classificato == 2) + { + _conto_classificato = TRUE; + return FALSE; + } + } + else + { + _conto_classificato = TRUE; + return FALSE; + } + } + else // Se si tratta di un sottoconto + { + if (!_conto_classificato) + { + char sezione = rec.get_char(PCN_SEZIVD); + + if (sezione != '0') + return FALSE; + } + else + return FALSE; + } + _g_prec = gruppo; + _c_prec = conto; + } + } + if (_tipo_stampa == senza_ana_bil) + { + TRectype & rec = current_cursor()->curr(); + + if (rec.get_int(PCN_CONTO) == 0) return FALSE; + if (rec.get_long(PCN_SOTTOCONTO) == 0L) + a1 = rec.get(PCN_CODCBL); + else + if (rec.get(PCN_CODCBL).empty()) + rec.put(PCN_CODCBL, a1); + if (rec.get(PCN_CODCBL).not_empty()) return FALSE; + } + if (elabora_riga()) + printer().formfeed(); + + const int c3 = atoi(_rec->get(PCN_NUMRIVD)); + const int o3 = atoi(_rec->get(PCN_NUMRIVDOPP)); + + _clivd = itor(c3); + _clivdo = itor(o3); + + return TRUE; +} + +bool CG1100_application::set_print(int) +{ + KEY tasto; + + _old_gruppo = 0; + tasto = _msk->run(); + + if (tasto == K_ENTER) + { + _tipo_stampa = (stampe)_msk->get_int(F_SCELTA_STAMPA); + _salto_pag = _msk->get_bool (F_SALTO_PAGINA); + _data_stampa = _msk->get (F_DATA_STAMPA); + + // scegli_cur(); + enable_link("Collegamento Piano dei conti : ", 'r'); + set_multiple_link(TRUE); + + _sez_stamp = ' '; + _let_stamp = ' '; + _numr_stamp = ""; + _num_stamp = 0; + _classe_stampata = ""; + + if (_tipo_stampa == senza_IV_direttiva) + { + _conto_classificato = TRUE; + _sottoc_classificato = 0; + _stampa_riga_vuota = FALSE; + _prima_volta = TRUE; + } + + switch (_tipo_stampa) + { + case completa: + case senza_IV_direttiva: + case senza_ana_bil: + select_cursor (_cur_c1); break; + case con_IV_direttiva: + case con_ana_bil: + select_cursor (_cur_c2); break; + default: + break; + } + init_sort(); + _resetta_righe_stampa = TRUE; + + printer().footerlen(5); + + return TRUE; + } + return FALSE; +} + +void CG1100_application::intesta (stampe tipo) +{ + int soh = 1; // riga d'inizio dell'intestazione + const long firm = get_firm(); + + reset_header (); + TLocalisamfile ditte(LF_NDITTE); + ditte.zero(); + ditte.put(NDT_CODDITTA, firm); + ditte.read(); + if (ditte.bad()) ditte.zero(); + + TString s(132); + s = ditte.get(NDT_RAGSOC); + TString data = _data_stampa.string(); + + set_header (soh++, "Ditta : %ld %s@110gData@115g%s Pag. @#", firm, (const char *) s, (const char*) data); + + + set_header (soh,"@0gPIANO DEI CONTI"); + + switch (tipo) + { + case completa: + set_header (soh++, "@20gStampa completa per IV direttiva"); + s.fill('-'); + set_header (soh++, (const char *) s); + set_header (soh++, "Conto @59gSez. Classe@75gTipo@86gNo Dettaglio@104gT@107gSpesa@118gDet.alleg.bil."); + set_header (soh++, "Sottoconto @16gDescrizione@61gIV dir.@75gConto@81gC/F@86gBilancio@97gComp.@104gA@107gRicavo@114gSez@118gSot.con * Mov."); + break; + + case con_IV_direttiva: + set_header (soh++, "@20gStampa conti riclassificati per IV direttiva"); + s.fill('_'); + set_header (soh++, (const char *) s); + set_header (soh++, "@58gCodici Piano@116gSez. e Classe"); + set_header (soh++, "Classe@14gDescrizione@58gdei Conti @73gDescrizione@116gdi segno opposto"); + + break; + + case senza_IV_direttiva: + set_header (soh++, "@20gStampa conti non collegati per IV direttiva"); + s.fill('_'); + set_header (soh++, (const char *) s); + set_header (soh++, "Conto @75gTipo@86gNo Dettaglio@104gT@107gSpesa@118gDet.alleg.bil."); + set_header (soh++, "Sottoconto @16gDescrizione@75gConto@81gC/F@86gBilancio@97gComp.@104gA@107gRicavo@114gSez@118gSot.con * Mov."); + break; + + case con_ana_bil: + + s.fill('_'); + set_header (soh++, (const char *) s); + set_header (soh++, "Codice @61gCodici Piano@113gDett.alleg.Bilancio"); + set_header (soh++, "Tabella@16gDescrizione@60gdei Conti @78gDescrizione @113gSot.con. * Moviment."); + + break; + + case senza_ana_bil: + s.fill('_'); + set_header (soh++, (const char *) s); + set_header (soh++, "Conto @67gSez. Classe@85gTipo@96gNo Dettaglio@112gSpesa @123gDet.bil."); + set_header (soh++, "Sottoconto @16gDescrizione@68gIV dir. @85gConto @91gC/F @96gBilancio @106gComp. @112gRicavo @119gSez"); + break; + + default: + break; + } + + set_header (soh++,(const char*)s); + set_header (soh, ""); + +} + +const char* CG1100_application::descrizione_numero(char sezione, char lettera, int numr, int numero) +{ + TTable& tabivd = *_tab; + TString dep,dep2; + + tabivd.zero(); + if (numr == 0 && numero == 0) + dep = format("%c%c",sezione,lettera); + else + if (numero == 0) + { + if (numr != 0) + dep = format("%1c%1c%04d",sezione, lettera, numr); + else + dep = format("%c%c ",sezione,lettera); + } + else + { + if (numr != 0) + dep = format("%1c%1c%04d%02d",sezione, lettera, numr,numero); + else + dep = format("%c%c %02d",sezione,lettera,numero); + } + + tabivd.put("CODTAB", dep); + tabivd.read(); + dep2 = tabivd.get("CODTAB"); + if (dep == dep2) + tmp = tabivd.get("S0"); + else + tmp = ""; + return tmp; +} + + +bool CG1100_application::user_create() +{ + _rel = new TRelation (LF_PCON); + _tab = new TTable(TAB_IVD); + _msk = new TMask ("cg1100a") ; + + TCursor *cursor = new TCursor (_rel); + + _cur_c1 = add_cursor (cursor); + + _rec = new TRectype (cursor->curr()); + + _pcont_reclen = _rec->len(); + _sort = new TSort(_pcont_reclen); + + _cur_c2 = add_cursor (NULL); + + add_file(LF_PCON); + + set_print_zero(); + + _tipo_stampa = completa; + _salto_pag = FALSE; + _bil = new bil_ivd; + _sort = new TSort(); + return TRUE; +} + +bool CG1100_application::user_destroy() +{ + delete _rel; + delete _tab; + delete _msk; + delete _rec; + // delete _descr; + delete _bil; + delete _sort; + return TRUE; +} + +int cg1100(int argc, char* argv[]) +{ + CG1100_application a; + a.run(argc, argv, "Stampa Piano dei Conti"); + return 0; +} diff --git a/cg/cg1300.cpp b/cg/cg1300.cpp index 9e3e97116..269fe5b32 100755 --- a/cg/cg1300.cpp +++ b/cg/cg1300.cpp @@ -1,157 +1,157 @@ -//******************************** -//* Aggiornamento Tipo Attivita' * -//******************************** -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "conto.h" -#include "cg2103.h" -#include "cg1301.h" -#include "cg1302.h" -#include "cg1303.h" -#include "cg1304.h" -#include "cg1.h" - -class TAgg_attiv : public TApplication -{ - TLocalisamfile* _pcon,* _attiv; - TTable* _reg; - -public: - virtual bool create(); - virtual bool destroy(); - virtual bool menu(MENU_TAG m); - - void elabora_mov(); - - TAgg_attiv() {}; - virtual ~TAgg_attiv() {}; -}; - -HIDDEN TAgg_attiv& app() { return (TAgg_attiv&)main_app(); } - -bool TAgg_attiv::create() -{ - TApplication::create(); - - _pcon = new TLocalisamfile(LF_PCON); - _attiv = new TLocalisamfile(LF_ATTIV); - _reg = new TTable("REG"); - - dispatch_e_menu (BAR_ITEM(1)); - - return TRUE; -} - -bool TAgg_attiv::destroy() -{ - delete _pcon; - delete _attiv; - delete _reg; - - return TApplication::destroy(); -} - -bool TAgg_attiv::menu(MENU_TAG m) -{ - TMask msk("cg1300a"); - - while (msk.run() == K_ENTER) - { - elabora_mov(); - message_box("Aggiornamento completato"); - //return TRUE; - } - return FALSE; -} - -void TAgg_attiv::elabora_mov() -{ - TRelation rel (LF_MOV); - rel.add(LF_RMOVIVA, "NUMREG=NUMREG",1); - TCursor cursor(&rel,"",1); - - TLocalisamfile& mov = rel.lfile(); - TLocalisamfile& rmoviva = rel.lfile(LF_RMOVIVA); - - long ditta = get_firm(); - cursor = 0L; - const long nitems = cursor.items(); - - TProgind p(nitems ? nitems : 1, "Aggiornamento in corso..." , TRUE, TRUE, 70); - - for (; cursor.pos() < cursor.items(); ++cursor) - { - p.addstatus(1); - const TString16 reg(mov.get(MOV_REG)); - if (reg.empty()) continue; - - const int annoiva = mov.get_int(MOV_ANNOIVA); - TRegistro registro(reg, annoiva); - const bool att_mista = registro.attivita_mista(); - - if (att_mista) - { - bool ok = rel.is_first_match(LF_RMOVIVA); - while (ok) - { - const char tipo = rmoviva.get_char("TIPOC"); - if (tipo <= ' ') - { - TBill c(rmoviva.get_int("GRUPPO"), rmoviva.get_int("CONTO"), rmoviva.get_long("SOTTOCONTO")); - int tipoatt = c.tipo_att(); - rmoviva.put("TIPOATT", tipoatt); - rmoviva.rewrite(); - } - ok = rel.next_match(LF_RMOVIVA); - } - } - } -} - -int cg1300(int argc, char* argv[]) -{ - switch (*argv[2]) - { - case 'A': - { - TAgg_attiv a; - a.run(argc, argv, "Aggiornamento tipo attivita' su movimenti iva"); - } - break; - case 'I': - { - TAgg_opintra a; - a.run(argc, argv, "Aggiornamento flag op. intracomunitarie"); - } - break; - case 'T': - { - TAgg_tconto a; - a.run(argc, argv, "Aggiornamento tipo conto"); - } - break; - case 'P': - { - TAgg_nprot a; - a.run(argc, argv,"Rinumerazione numero di protocollo"); - } - break; - case 'C': - { - TAgg_codatt a; - a.run(argc, argv,"Aggiornamento codice attivita'"); - } - break; - default: - break; - } - return TRUE; -} +//******************************** +//* Aggiornamento Tipo Attivita' * +//******************************** +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "conto.h" +#include "cg2103.h" +#include "cg1301.h" +#include "cg1302.h" +#include "cg1303.h" +#include "cg1304.h" +#include "cg1.h" + +class TAgg_attiv : public TApplication +{ + TLocalisamfile* _pcon,* _attiv; + TTable* _reg; + +public: + virtual bool create(); + virtual bool destroy(); + virtual bool menu(MENU_TAG m); + + void elabora_mov(); + + TAgg_attiv() {}; + virtual ~TAgg_attiv() {}; +}; + +HIDDEN TAgg_attiv& app() { return (TAgg_attiv&)main_app(); } + +bool TAgg_attiv::create() +{ + TApplication::create(); + + _pcon = new TLocalisamfile(LF_PCON); + _attiv = new TLocalisamfile(LF_ATTIV); + _reg = new TTable("REG"); + + dispatch_e_menu (BAR_ITEM(1)); + + return TRUE; +} + +bool TAgg_attiv::destroy() +{ + delete _pcon; + delete _attiv; + delete _reg; + + return TApplication::destroy(); +} + +bool TAgg_attiv::menu(MENU_TAG m) +{ + TMask msk("cg1300a"); + + while (msk.run() == K_ENTER) + { + elabora_mov(); + message_box("Aggiornamento completato"); + //return TRUE; + } + return FALSE; +} + +void TAgg_attiv::elabora_mov() +{ + TRelation rel (LF_MOV); + rel.add(LF_RMOVIVA, "NUMREG=NUMREG",1); + TCursor cursor(&rel,"",1); + + TLocalisamfile& mov = rel.lfile(); + TLocalisamfile& rmoviva = rel.lfile(LF_RMOVIVA); + + long ditta = get_firm(); + cursor = 0L; + const long nitems = cursor.items(); + + TProgind p(nitems ? nitems : 1, "Aggiornamento in corso..." , TRUE, TRUE, 70); + + for (; cursor.pos() < cursor.items(); ++cursor) + { + p.addstatus(1); + const TString16 reg(mov.get(MOV_REG)); + if (reg.empty()) continue; + + const int annoiva = mov.get_int(MOV_ANNOIVA); + TRegistro registro(reg, annoiva); + const bool att_mista = registro.attivita_mista(); + + if (att_mista) + { + bool ok = rel.is_first_match(LF_RMOVIVA); + while (ok) + { + const char tipo = rmoviva.get_char("TIPOC"); + if (tipo <= ' ') + { + TBill c(rmoviva.get_int("GRUPPO"), rmoviva.get_int("CONTO"), rmoviva.get_long("SOTTOCONTO")); + int tipoatt = c.tipo_att(); + rmoviva.put("TIPOATT", tipoatt); + rmoviva.rewrite(); + } + ok = rel.next_match(LF_RMOVIVA); + } + } + } +} + +int cg1300(int argc, char* argv[]) +{ + switch (*argv[2]) + { + case 'A': + { + TAgg_attiv a; + a.run(argc, argv, "Aggiornamento tipo attivita' su movimenti iva"); + } + break; + case 'I': +{ + TAgg_opintra a; + a.run(argc, argv, "Aggiornamento flag op. intracomunitarie"); +} +break; + case 'T': +{ + TAgg_tconto a; + a.run(argc, argv, "Aggiornamento tipo conto"); +} +break; + case 'P': +{ + TAgg_nprot a; + a.run(argc, argv,"Rinumerazione numero di protocollo"); +} +break; + case 'C': +{ + TAgg_codatt a; + a.run(argc, argv,"Aggiornamento codice attivita'"); +} +break; +default: +break; +} +return TRUE; +} diff --git a/cg/cg1300.h b/cg/cg1300.h index ab191c8ed..9d2502dc7 100755 --- a/cg/cg1300.h +++ b/cg/cg1300.h @@ -1,30 +1,30 @@ -#ifndef __CG1300_H -#define __CG1300_H - -#define F_CODDITTA 101 -#define F_RAGSOC 102 -#define F_ANNO 103 -#define F_REG 104 -#define F_PROT 105 -#define F_PASS 106 -#define F_DA 107 -#define F_A 108 -#define F_DENATTV 109 -#define F_DENATTN 110 -#endif // __CG1300_H - - - - - - - - - - - - - - - - +#ifndef __CG1300_H +#define __CG1300_H + +#define F_CODDITTA 101 +#define F_RAGSOC 102 +#define F_ANNO 103 +#define F_REG 104 +#define F_PROT 105 +#define F_PASS 106 +#define F_DA 107 +#define F_A 108 +#define F_DENATTV 109 +#define F_DENATTN 110 +#endif // __CG1300_H + + + + + + + + + + + + + + + + diff --git a/cg/cg1304.cpp b/cg/cg1304.cpp index 9ec46e62b..3c1de3dca 100755 --- a/cg/cg1304.cpp +++ b/cg/cg1304.cpp @@ -126,10 +126,11 @@ void TAgg_codatt::cancella_rec() TTable pla("PLA"); for (pla.first(); !pla.eof(); pla.next()) pla.remove(); - + /*** TTable rmb("RMB"); for (rmb.first(); !rmb.eof(); rmb.next()) rmb.remove(); + ***/ } void TAgg_codatt::aggiorna_att(const char* nome) diff --git a/cg/cg1500.cpp b/cg/cg1500.cpp index 0858051e7..e514f37fc 100755 --- a/cg/cg1500.cpp +++ b/cg/cg1500.cpp @@ -1,3708 +1,3708 @@ -//Stampa bilanci - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cglib.h" -#include "cg1.h" -#include "cg1500.h" - -bool my_handler (TMask_field& f, KEY k); -bool mask_anno (TMask_field& f, KEY k); -bool mask_datalim (TMask_field& f, KEY k); -bool mask_date (TMask_field& f, KEY k); -bool mask_bilancio(TMask_field& f, KEY k); -bool mask_tipost (TMask_field& f, KEY k); - -HIDDEN int date2esc(const TDate& d, int* prevesc = NULL); - -class CG1500_application : public TPrintapp -{ - friend bool mask_anno (TMask_field& f, KEY k); - friend bool mask_datalim (TMask_field& f, KEY k); - friend bool my_handler (TMask_field& f, KEY k); - friend bool mask_date (TMask_field& f, KEY k); - friend bool mask_bilancio(TMask_field& f, KEY k); - friend bool mask_tipost (TMask_field& f, KEY k); - - struct cli_for - { - char tipocf; - char gruppo[4]; - char conto[4]; - char codcf[7]; - char ragsoc[51]; - real saldodare; - real saldoavere; - real movdare; - real movavere; - real saldofinale; - TDate udata; - }; - - cli_for* _cf; - TSort * _sort; - const char* _buff; - - TRelation* _rel; - TCursor * _cur; - TProgind * _prog; - TSaldi_list* _listacf, * _lista; - TLocalisamfile* _com, * _pcn, * _mov, * _rmov, * _clifo, * _saldi, * _nditte,* _anag,* _caus; - TIsamtempfile * _tmp_saldi_att, * _tmp_saldi_pass, * _tmp_saldi_conti_uno; - TIsamtempfile * _tmp_saldi_costi, * _tmp_saldi_ricavi,* _tmp_saldi_conti_due; - TTable* _esc; - TParagraph_string* _d; - - TString _cofi,_cap,_paiva,_ragsoc,_comunefis,_provfis,_viafis; - TString _descr_dare, _descr_avere, _gc_corr_dare, _gc_corr_avere, _descr; - TString _gc_prec_dare, _gc_prec_avere, _situazione, _descr_succ; - char _tipo_conto, _tipoc_succ; - - int _annoes, _bilancio, _tipo_stampa, _tipo_stampa1,_stampa_width,_gp,_cp,_i; - int _eof1, _eof2, _gruppo_dare, _gruppo_avere, _conto_dare, _conto_avere; - int _add_file_da, _add_file_a, _indbil_dare, _indbil_avere, _indbil; - int _eof3, _eof4, _eof5, _eof6, _verifica, _stampac, _stampav, _ordinamento; - int _gruppo, _conto, _gruppo_succ, _conto_succ, _annoapp; - long _sottoconto_dare, _sottoconto_avere, _sottoconto, _sottoconto_succ; - - real _saldo_dare, _saldo_avere, _gruppo_a, _gruppo_da, _conto_a; - real _conto_da, _tot_dare, _tot_avere, _mov_periodo_dare, _saldo_ini_dare; - real _mov_periodo_avere, _saldo_ini_avere, _prg_prec_dare, _prg_prec_avere; - real _saldo_ini_conto_dare, _saldo_ini_conto_avere, _saldoini_dare; - real _saldoini_avere, _mov_dare, _mov_avere, _saldofinale; - real _saldoini_dare_succ, _saldoini_avere_succ, _mov_dare_succ; - real _mov_avere_succ, _saldofinale_succ; - real _saldo_dare_tot, _saldo_avere_tot, _mov_dare_tot, _mov_avere_tot; - real _saldo_finale_tot, _saldo_ini_gruppo_dare, _saldo_ini_gruppo_avere; - real _gruppo_da_ordine, _gruppo_a_ordine; - real _prg_saldoini_dare, _prg_saldoini_avere, _prg_inidare_ord, _prg_iniavere_ord; - real _nuovo_tot_saldo_d, _nuovo_tot_saldo_a; - - TDate _datalim, _data, _datada, _dataa, _dataini, _ultima_data, _u_max; - bool _cambiato_conto_1, _cambiato_conto_2, _add_file_avere; - bool _add_file_dare, _prima_volta, _seconda_volta, _totali, _codici, _saldo; - bool _add_dare, _add_avere, _controlla, _salto_pagina, _flag, _stampato; - bool _sottoc_dare, _sottoc_avere, _salto_pagina1, _livello_conto; - int _stampa_mov_prov; - //TString _causale_ap, _causale_chi; - TArray _clienti, _fornitori; - -public: - - TDate _inizioEs, _fineEs; - bool menu (MENU_TAG m) { return TPrintapp::menu(m) ; } - virtual bool user_create() ; - virtual bool user_destroy(); - bool set_print(int); - - void next_c(); - virtual bool preprocess_print(int,int); - virtual void preprocess_header(); - virtual bool preprocess_page(int,int); - virtual print_action postprocess_page(int,int); - virtual void postclose_print(); - virtual void set_page(int,int); - real compensazione(bool compensa, int indbil_conto, real& saldo); - //const char* causale_chiusura() { return _causale_chi;} - //const char* causale_apertura() { return _causale_ap;} - bool bil_sez_contr(); - bool bil_verifica(); - bool ricerca_sottoc_clifo(int,int,bool,int,real&); - bool ricerca_cf(int,int,char,int,real&,real&,real&,real&,real&,real&,real&); - bool calcola(int,int,long); - void leggi_pcon(); // Inizializza i TArray C/F - void crea_sort_clifo(); - void init_sort(); - void leggi_sort(); - void riempi_record(char,int,int,long,const char*,const real&, - const real&,const real&,const real&,const real&); - void get_dati_ditta(); - void scrivi_record_conto(const real&,const real&,const real&, - const real&, const real&); - void scrivi_record_gruppo(const real&,const real&,const real&, - const real&, const real&); - int stampa_record_conto(int,int,const TString&,const real&,const real&, - const real&,const real&,const real&,const char); - int stampa_intestazione_ditta(); - int cerca_indbil(int,int); - void scrivig_file_temp(); - void scrivic_file_temp(); - void scrivis_file_temp(int,int,long,real); - void leggi_files_dare (TIsamtempfile*); - void leggi_files_avere(TIsamtempfile*); - void leggi_file_tmp(); - void stampa_riga_totali(int); - void stampa_prima_colonna(int,int,long,const char*,const real&); - void stampa_seconda_colonna(int,int,long,const char*,const real&); - void stampa_totali(); - void stampa_totali_uno(const real&, const real&); - void controlla_conto(int,int); - const char* DescrizioneConto(int,int,long,char); //chiama quella di TConto - TDate UltimaData(int,int,long,int); - - CG1500_application() {} -}; - -HIDDEN inline CG1500_application & app() { return (CG1500_application&) main_app(); } - -TDate InizioEsercizio(int anno) -{ - TTable TabEs ("ESC"); - TString16 codtab; - TDate inizio_es; - - TabEs.zero(); - codtab.format ("%04d", anno); - TabEs.put ("CODTAB", codtab); - TabEs.read(); - if (TabEs.good()) - inizio_es= TabEs.get_date ("D0"); - - return inizio_es; -} - -TDate FineEsercizio(int anno) -{ - TTable TabEs ("ESC"); - TString16 codtab; - TDate fine_es; - - TabEs.zero(); - codtab.format ("%04d", anno); - TabEs.put ("CODTAB", codtab); - TabEs.read(); - if (TabEs.good()) - fine_es= TabEs.get_date ("D1"); - - return fine_es; -} - -bool IsEsercizio (const TDate& datalim, int anno_eser) -{ - TTable TabEs ("ESC"); - TString16 codtab; - TDate inizio,fine; - - TabEs.zero(); - - codtab.format ("%04d", anno_eser); - TabEs.put ("CODTAB", codtab); - TabEs.read(); - if (TabEs.good()) - { - inizio = TabEs.get_date ("D0"); - fine = TabEs.get_date ("D1"); - } - if (datalim >= inizio && datalim <= fine) - return TRUE; - - return FALSE; -} - -HIDDEN int date2esc(const TDate& d, int* prevesc) -{ - if (prevesc) *prevesc = 0; - TTable esc("ESC"); - for (int err = esc.first(); err == NOERR; err = esc.next()) - { - const TDate ia(esc.get("D0")); // Data inizio esercizio - const TDate fa(esc.get("D1")); // Data fine esercizio - const anno = esc.get_int("CODTAB"); - app()._inizioEs = ia; - app()._fineEs = fa; - if (d >= ia && d <= fa) - return anno; - if (prevesc) *prevesc = anno; - } - return 0; -} - -bool mask_anno(TMask_field& f, KEY k) -{ - if (k == K_ENTER) - { - int tipo_stampa; - int anno = f.mask().get_int(F_ANNO); - int bilancio = f.mask().get_int(F_BILANCIO); - if (bilancio == 1) - tipo_stampa = f.mask().get_int(F_STAMPA); - else - tipo_stampa = f.mask().get_int(F_STAMPA1); - if (tipo_stampa == 2) - if (anno == 0) - { - f.error_box("Indicare l'anno di esercizio"); - return FALSE; - } - } - if ( k == K_TAB || f.focusdirty()) - { - int tipo_stampa; - int anno = f.mask().get_int(F_ANNO); - int bilancio = f.mask().get_int(F_BILANCIO); - if (bilancio == 1) - tipo_stampa = f.mask().get_int(F_STAMPA); - else - tipo_stampa = f.mask().get_int(F_STAMPA1); - - if ((bilancio == 2) && (tipo_stampa == 1)) - if (anno != 0) - { - f.mask().show(F_DATADA); - f.mask().show(F_DATAA); - //f.mask().show(F_STAMPAMPROV); - f.mask().show(96); - f.mask().show(97); - f.mask().hide(98); - f.mask().hide(99); - } - else - { - f.mask().show(F_DATADA); - f.mask().show(F_DATAA); - //f.mask().show(F_STAMPAMPROV); - f.mask().show(98); - f.mask().show(99); - f.mask().hide(96); - f.mask().hide(97); - } - } - return TRUE; -} - -bool mask_bilancio(TMask_field& f, KEY k) -{ - TMask& m = f.mask(); - - if (k == K_SPACE) - { - int tipo_stampa; - int anno = m.get_int(F_ANNO); - int bilancio = m.get_int(F_BILANCIO); - if (bilancio == 1) //bilancio a sezioni contrapposte - { - tipo_stampa = m.get_int(F_STAMPA); - m.disable_page(1); - } - else - { - tipo_stampa = m.get_int(F_STAMPA1); - m.enable_page(1); - } - if ( bilancio == 1 || bilancio ==2) - if (tipo_stampa == 2) //all'ultima immissione - { - m.hide(F_DATADA); - m.hide(F_DATAA); - //m.hide(F_STAMPAMPROV); - m.hide(98); - m.hide(99); - m.hide(96); - m.hide(97); - } -else -{ - if (bilancio == 2) - if (anno != 0) - { - m.show(F_DATADA); - m.show(F_DATAA); - //m.show(F_STAMPAMPROV); - m.show(96); - m.show(97); - m.hide(98); - m.hide(99); - } - else - { - m.show(F_DATADA); - m.show(F_DATAA); - //m.show(F_STAMPAMPROV); - m.show(98); - m.show(99); - m.hide(96); - m.hide(97); - } -} -} -return TRUE; -} - - -bool mask_datalim (TMask_field& f, KEY k) -{ - if (k == K_ENTER) - { - int anno = f.mask().get_int(F_ANNO); - int bilancio = f.mask().get_int(F_BILANCIO); - TDate datalim(f.mask().get(F_DATALIM)); - if (bilancio == 1) - if (anno != 0) - { - if ( datalim.ok() ) - { - if (!IsEsercizio(datalim,anno)) - { - f.error_box ("La data limite deve appartenere all'esercizio indicato"); - return FALSE; - } - } - else - f.mask().field(F_DATALIM).set(FineEsercizio(anno)); - } - else //anno == 0 - { - if (!datalim.ok()) - { - f.error_box ("La data limite e' obbligatoria"); - return FALSE; - } - long anno = date2esc(datalim); - if (anno == 0) - { - f.error_box ("La data limite deve appartenere ad un esercizio attivo della ditta"); - return FALSE; - } - f.mask().set(F_ANNO,anno); - } - } - return TRUE; -} - -bool mask_date(TMask_field& f, KEY k) -{ - if (k == K_ENTER) - { - const short id = f.dlg(); - int anno = f.mask().get_int(F_ANNO); - int bilancio = f.mask().get_int(F_BILANCIO); - if (bilancio == 2) - { - TDate data (f.mask().get(id)); - if (anno != 0) - { - if (data.ok()) - { - if (!IsEsercizio(data,anno)) - { - f.error_box( "La data indicata deve essere all'interno dell'esercizio"); - return FALSE; - } - } - if (!data.ok()) - { - if (id == F_DATADA) - f.mask().field(F_DATADA).set(InizioEsercizio(anno)); - else if (id == F_DATAA) - f.mask().field(F_DATAA).set(FineEsercizio(anno)); - } - app()._annoapp = anno; - } - else - { - if ( !data.ok() ) - { - f.error_box("Indicare una data appartenente ad un esercizio attivo della ditta"); - return FALSE; - } - else - { - //date2esc(datada); - //const TString16 ie(app()._inizioEs.string()); - //const TString16 fe(app()._fineEs.string()); - //if (datada < app()._inizioEs || dataa > app()._fineEs) - //{ - // f.error_box("Le date devono essere comprese tra %s e %s", - // (const char*)ie, (const char*)fe); - // return FALSE; - //} - if (id == F_DATAA) - { - TDate from (f.mask().get(id - 1)); - app()._annoapp = date2esc(from); - if ( app()._annoapp != date2esc(data) ) - { - f.error_box("Le date devono appartenere ad uno stesso esercizio attivo della ditta"); - return FALSE; - } - if (from > data) - { - f.error_box("La data limite inferiore non puo' essere maggiore della data limite superiore"); - return FALSE; - } - //f.mask().set(F_ANNO, anno); - } - } - } - } - } - return TRUE; -} - -bool my_handler (TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - int tipo_stampa = atoi(f.mask().get(F_STAMPA1)); - int verifica = atoi(f.mask().get(F_VERIFICA)); - if ( (tipo_stampa == 1) && ((verifica == 1) || (verifica == 2)) ) - { - f.mask().hide (F_SITUAZIONE); - f.mask().hide (F_STAMPAC); - f.mask().hide (F_ORDINAMENTO); - f.mask().show (F_STAMPAV); - f.mask().show (F_DATADA); - f.mask().show (F_DATAA); - //f.mask().show (F_STAMPAMPROV); - } - if ( (tipo_stampa == 1) && (verifica == 3) ) - { - f.mask().show (F_SITUAZIONE); - f.mask().show (F_STAMPAC); - f.mask().show (F_ORDINAMENTO); - f.mask().show (F_DATADA); - f.mask().show (F_DATAA); - f.mask().hide (F_STAMPAV); - //f.mask().show (F_STAMPAMPROV); - } - if ( (tipo_stampa == 2) && ((verifica == 1)||(verifica == 2)) ) - { - f.mask().hide (F_SITUAZIONE); - f.mask().hide (F_STAMPAC); - f.mask().hide (F_ORDINAMENTO); - f.mask().hide (F_DATADA); - f.mask().hide (F_DATAA); - //f.mask().hide (F_STAMPAMPROV); - f.mask().show (F_STAMPAV); - } - if ( (tipo_stampa == 2) && (verifica == 3) ) - { - f.mask().show (F_SITUAZIONE); - f.mask().show (F_STAMPAC); - f.mask().show (F_ORDINAMENTO); - f.mask().hide (F_DATADA); - f.mask().hide (F_DATAA); - //f.mask().hide (F_STAMPAMPROV); - f.mask().hide (F_STAMPAV); - } - } - return TRUE; -} - -void CG1500_application::scrivig_file_temp() -{ - TIsamtempfile* tmp = NULL; - TString nome_campo(12); - real valore; - - if (!_totali) - { - if (_add_dare) - { - nome_campo = SLD_PDARE; - valore = _gruppo_da; - switch (_indbil) - { - case 1: - case 2: - tmp = _tmp_saldi_att; - break; - case 3: - case 4: - tmp = _tmp_saldi_costi; - break; - case 5: - tmp = _tmp_saldi_conti_uno; - valore = _gruppo_da_ordine; - break; - default: - break; - } - - tmp->zero(); - tmp->put(SLD_GRUPPO,_gp); - if (tmp->read() == NOERR) - { - tmp->put(SLD_CONTO,0); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(nome_campo, valore); - tmp->rewrite(); - } - else - { - tmp->put(SLD_CONTO,0); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(nome_campo, valore); - tmp->write(); - } - } - if (_add_avere) - { - nome_campo = SLD_PAVERE; - valore = _gruppo_a; - switch (_indbil) - { - case 1: - case 2: - tmp = _tmp_saldi_pass; - break; - case 3: - case 4: - tmp = _tmp_saldi_ricavi; - break; - case 5: - tmp = _tmp_saldi_conti_due; - valore = _gruppo_a_ordine; - break; - default: - break; - } - - tmp->zero(); - tmp->put(SLD_GRUPPO,_gp); - if (tmp->read() == NOERR) - { - tmp->put(SLD_CONTO,0); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(nome_campo, valore); - tmp->rewrite(); - } - else - { - tmp->put(SLD_CONTO,0); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(nome_campo, valore); - tmp->write(); - } - } - } - _add_dare = _add_avere = FALSE; -} - -void CG1500_application::scrivic_file_temp() -{ - TIsamtempfile* tmp = NULL; - TString nome_campo(12); - real valore; - - if (_add_file_dare) - { - _add_dare = TRUE; - nome_campo = SLD_PDARE; - valore = _conto_da; - if (_indbil == 1 || _indbil==2) tmp = _tmp_saldi_att; // da stampare a sx - else - if (_indbil==3 || _indbil==4) tmp = _tmp_saldi_costi; //da stampare a sx - else - if (_indbil==5) tmp = _tmp_saldi_conti_uno; - else return; - tmp->zero(); - tmp->put(SLD_GRUPPO,_gp); - tmp->put(SLD_CONTO,_cp); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(nome_campo, valore); - tmp->write(); - } - if (_add_file_avere) - { - _add_avere = TRUE; - nome_campo = SLD_PAVERE; - valore = _conto_a; - if (_indbil==2 || _indbil==1) tmp = _tmp_saldi_pass; //da stampare a dx - else - if (_indbil==4 || _indbil==3) tmp = _tmp_saldi_ricavi;//da stampare a dx - else - if (_indbil==5) tmp = _tmp_saldi_conti_due; - else return; - tmp->zero(); - tmp->put(SLD_GRUPPO,_gp); - tmp->put(SLD_CONTO,_cp); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(nome_campo, valore); - tmp->write(); - } - /* - tmp->zero(); - tmp->put(SLD_GRUPPO,_gp); - tmp->put(SLD_CONTO,_cp); - tmp->put(SLD_SOTTOCONTO,0L); - tmp->put(nome_campo, valore); - tmp->write(); - */ -} - -void CG1500_application::scrivis_file_temp(int g, int c, long s, real saldo) -{ - TIsamtempfile* tmp = NULL; - TString16 nome_campo; - - if (_indbil==1) - { - tmp = _tmp_saldi_att; - nome_campo = SLD_PDARE; - } - else - if (_indbil==2) - { - tmp = _tmp_saldi_pass; - nome_campo = SLD_PAVERE; - } - else - if (_indbil==3) - { - tmp = _tmp_saldi_costi; - nome_campo = SLD_PDARE; - } - else - if (_indbil==4) - { - tmp = _tmp_saldi_ricavi; - nome_campo = SLD_PAVERE; - } - else - if (_sottoc_dare) - { - tmp = _tmp_saldi_conti_uno; - nome_campo = SLD_PDARE; - } - else - if (_sottoc_avere) - { - tmp = _tmp_saldi_conti_due; - nome_campo = SLD_PAVERE; - } - tmp->zero(); - tmp->put(SLD_GRUPPO,g); - tmp->put(SLD_CONTO,c); - tmp->put(SLD_SOTTOCONTO,s); - tmp->put(nome_campo, saldo); - tmp->write(); -} - -real CG1500_application::compensazione(bool compensa, int indbil_conto, real& sld) -{ - real saldo = sld; - - if (!compensa) - { - switch (indbil_conto) - { - case 1: - if (saldo > ZERO) - _indbil = indbil_conto; - else - { - _indbil = 2; - saldo = -saldo; - } - break; - - case 3: - if (saldo > ZERO) - _indbil = indbil_conto; - else - { - _indbil = 4; - saldo = -saldo; - } - break; - - case 2: - if (saldo < ZERO) - { - _indbil = indbil_conto; - saldo = -saldo; - } - else - _indbil = 1; - break; - - case 4: - if (saldo < ZERO) - { - _indbil = indbil_conto; - saldo = -saldo; - } - else - _indbil = 3; - break; - case 5: - default: break; - } - } - else //e' richiesta la compensazione - if ( indbil_conto==2 || indbil_conto==4) - saldo = -saldo; - - return saldo; -} - -void CG1500_application::next_c() -{ - TRecnotype recnum = _pcn->recno(); - _pcn->next(); - if (_pcn->eof()) - { - scrivic_file_temp(); - scrivig_file_temp(); - } - _pcn->readat(recnum); -} - -bool CG1500_application::bil_sez_contr() -{ - TSaldo sld; - int indbil_conto=0; - int g, c; - long s; - char tipo_conto = ' '; - real saldo; - bool compensa=FALSE, dettaglio=FALSE, cambiato=FALSE; - bool esiste_conto=FALSE, esiste_sc = FALSE; - bool movimentato = FALSE; - - CHECK(_tmp_saldi_att == NULL, "Non posso riaprire cg01"); - _tmp_saldi_att = new TIsamtempfile(LF_SALDI, "cg01", 2); - _prog->addstatus(1); - _tmp_saldi_pass = new TIsamtempfile(LF_SALDI, "cg02", 2); - _prog->addstatus(1); - _tmp_saldi_costi = new TIsamtempfile(LF_SALDI, "cg03", 2); - _prog->addstatus(1); - _tmp_saldi_ricavi = new TIsamtempfile(LF_SALDI, "cg04", 2); - _prog->addstatus(1); - _tmp_saldi_conti_uno = new TIsamtempfile(LF_SALDI, "cg05", 2); - _prog->addstatus(1); - _tmp_saldi_conti_due = new TIsamtempfile(LF_SALDI, "cg06", 2); - _prog->addstatus(1); - - _gp=-1; - _cp=-1; - _gruppo_a = ZERO; - _gruppo_da = ZERO; - _gruppo_da_ordine = ZERO; - _gruppo_a_ordine = ZERO; - _prg_saldoini_dare = ZERO; - _prg_saldoini_avere = ZERO; - _prg_inidare_ord = ZERO; - _prg_iniavere_ord = ZERO; - _conto_a = ZERO; - _conto_da = ZERO; - _add_dare = FALSE; - _add_avere = FALSE; - - sld.set_annoes(_annoes); - - for (_pcn->first(); !_pcn->eof(); _pcn->next()) - { - _prog->addstatus(1); - g = _pcn->get_int (PCN_GRUPPO); - c = _pcn->get_int (PCN_CONTO); - s = _pcn->get_long(PCN_SOTTOCONTO); - - if (c != _cp) - cambiato = TRUE; - - if ( (((_cp != -1) && (c != _cp)) || ((_gp != -1) && (g != _gp))) && - esiste_sc ) - { - scrivic_file_temp(); - scrivig_file_temp(); - _cp = c; - esiste_conto = TRUE; - _conto_da = ZERO; - _conto_a = ZERO; - } - - if ( ((_gp != -1) && (g != _gp)) && esiste_conto ) - { - scrivig_file_temp(); - esiste_conto = FALSE; - _gp = g; - _gruppo_da = ZERO; - _gruppo_a = ZERO; - _gruppo_da_ordine = ZERO; - _gruppo_a_ordine = ZERO; - } - - if (cambiato) - { - _add_file_avere = FALSE; - _add_file_dare = FALSE; - cambiato = FALSE; - } - - if ( (s == 0) && (c != 0) ) //si tratta di un conto - { - compensa = _pcn->get_bool(PCN_COMPENS); - indbil_conto = _pcn->get_int (PCN_INDBIL); - dettaglio = !_pcn->get_bool(PCN_STSOTTBIL); - tipo_conto = _pcn->get(PCN_TMCF)[0]; - if ( (tipo_conto == 'C') || (tipo_conto == 'F') ) - { - saldo = ZERO; - esiste_sc = ricerca_sottoc_clifo(g, c, compensa, - indbil_conto, saldo); - if (esiste_sc) - { - _gp = g; - _cp = c; - } - TRecnotype recnum = _pcn->recno(); - _pcn->next(); - if (_pcn->eof()) - { - if (esiste_sc) - { - scrivic_file_temp(); - scrivig_file_temp(); - } - else if (esiste_conto) - scrivig_file_temp(); - } - _pcn->readat(recnum); - - continue; - } - } - - if ( (c == 0) || (s == 0) ) //si tratta di un conto o di un gruppo - { - esiste_sc = FALSE; - continue; - } - - if (_tipo_stampa == 1) //bil. a sez. contrapposte per data limite - movimentato = sld.data_limite_bilancio(_bilancio,g,c,s,_dataini,_datalim,indbil_conto,_stampa_mov_prov); - else - if (_tipo_stampa == 2) //bil. a sez. contrapposte all'ultima immissione es. in corso - movimentato = sld.ultima_immissione_bilancio(_annoes,g,c,s,indbil_conto,_stampa_mov_prov); - - if (!movimentato) - if (!sld.esiste_saldo() || !sld.significativo()) - { - next_c(); - continue; - } - - saldo = sld.saldo(); - real app = sld.saldoini(); - bool flag = sld.flagprec(); - - if (_saldo) //se richiesto di NON stampare i conti con saldo a zero - if (saldo == ZERO) - { - //modifica del 06/07/1995 - if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) - { - //real app = sld.saldoini(); - //bool flag = sld.flagprec(); - if (flag) - { - if (app > ZERO) - { - if (indbil_conto == 5) - _prg_inidare_ord += app; - else _prg_saldoini_dare += app; - } - else if (app < ZERO) - { - app = -app; - if (indbil_conto == 5) - _prg_iniavere_ord += app; - else _prg_saldoini_avere += app; - } - } - } - //fine - next_c(); - continue; - } - - esiste_sc = TRUE; - _indbil = indbil_conto; - - //i due flag seguenti servono solo per i conti d'ordine - _sottoc_dare = FALSE; - _sottoc_avere = FALSE; - - //error_box ("saldo = %s", saldo.string()); - - if (saldo != ZERO) - saldo = compensazione(compensa, indbil_conto, saldo); - - if (_indbil == 1 || _indbil == 2) - { - //real app = sld.saldoini(); - //bool flag = sld.flagprec(); - if (flag) - { - if (app > ZERO) - _prg_saldoini_dare += app; - else if (app < ZERO) - { - app = -app; - _prg_saldoini_avere += app; - } - } - } - - if (_indbil == 5) - { - //real app = sld.saldoini(); - if (flag) - { - if (app > ZERO) - _prg_inidare_ord += app; - else if (app < ZERO) - { - app = -app; - _prg_iniavere_ord += app; - } - } - } - - if ( _indbil==1 || _indbil==3 ) - { - _gruppo_da += saldo; - _conto_da += saldo; - _add_file_dare = TRUE; - } - - if ( _indbil==2 || _indbil==4 ) - { - _gruppo_a += saldo; - _conto_a += saldo; - _add_file_avere = TRUE; - } - - if (_indbil==5) - { - if ( saldo >= ZERO || compensa ) - { - _gruppo_da_ordine += saldo; - _conto_da += saldo; - _add_file_dare = TRUE; - _sottoc_dare = TRUE; - } - else - { - saldo = -saldo; - _gruppo_a_ordine += saldo; - _conto_a += saldo; - _add_file_avere = TRUE; - _sottoc_avere = TRUE; - } - scrivig_file_temp(); - } - if ( (dettaglio) && ( (tipo_conto != 'C') && (tipo_conto != 'F') ) ) - scrivis_file_temp(g, c, s, saldo); - - _gp = g; - _cp = c; - // } // da_considerare - - TRecnotype recnum = _pcn->recno(); - _pcn->next(); - if (_pcn->eof()) - { - scrivic_file_temp(); - scrivig_file_temp(); - } - _pcn->readat(recnum); - } - - return TRUE; -} - -bool CG1500_application::ricerca_sottoc_clifo(int g,int c, bool compensa, int indbil_conto,real& saldo) -{ - TSaldo sld; - int aep=0; - long s, items; - bool esiste_sc = FALSE; - bool movimentato = FALSE; - - if (_annoes) aep = EsePre(_annoes); - sld.set_annoes(_annoes); - _listacf = new TSaldi_list(g, c, _annoes, aep); - - items = _listacf->items(); - - for (int i = 0; i < items; i++) - { - const TRectype* r = _listacf->saldi(); - - if (r == NULL) break; - - s = r->get_long(SLD_SOTTOCONTO); - - if (_tipo_stampa == 1) //bil. a sez. contrapposte per data limite - movimentato = sld.data_limite_bilancio(_bilancio,g,c,s,_dataini,_datalim,indbil_conto,_stampa_mov_prov); - else if (_tipo_stampa == 2) //bil. a sez. contrapposte all'ultima immissione es. in corso - movimentato = sld.ultima_immissione_bilancio(_annoes,g,c,s,indbil_conto,_stampa_mov_prov); - - if (!movimentato) - if (!sld.esiste_saldo() || !sld.significativo()) - continue; - - saldo = sld.saldo(); - real app = sld.saldoini(); - bool flag = sld.flagprec(); - - if (_saldo) //se richiesto di non stampare i conti con saldo a zero - if (saldo == ZERO) - { - //modifica del 06/07/1995 - if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) - { - //real app = sld.saldoini(); - if (flag) - { - if (app > ZERO) - { - if (indbil_conto == 5) - _prg_inidare_ord += app; - else _prg_saldoini_dare += app; - } - else if (app < ZERO) - { - app = -app; - if (indbil_conto == 5) - _prg_iniavere_ord += app; - else _prg_saldoini_avere += app; - } - } - } - //fine - continue; - } - - esiste_sc = TRUE; - _indbil = indbil_conto; - - //i due flag seguenti servono solo per i conti d'ordine - _sottoc_dare = FALSE; - _sottoc_avere = FALSE; - - //error_box ("saldo = %s", saldo.string()); - - if (saldo != ZERO) - saldo = compensazione(compensa, indbil_conto, saldo); - - if (_indbil == 1 || _indbil == 2) - { - //real app = sld.saldoini(); - if (flag) - { - if (app > ZERO) - _prg_saldoini_dare += app; - else if (app < ZERO) - { - app = -app; - _prg_saldoini_avere += app; - } - } - } - - if (_indbil == 5) - { - //real app = sld.saldoini(); - if (flag) - { - if (app > ZERO) - _prg_inidare_ord += app; - else if (app < ZERO) - { - app = -app; - _prg_iniavere_ord += app; - } - } - } - - if ( (_indbil==1) || (_indbil==3) ) - { - _gruppo_da += saldo; - _conto_da += saldo; - _add_file_dare = TRUE; - } - - if ( (_indbil==2) || (_indbil==4) ) - { - _gruppo_a += saldo; - _conto_a += saldo; - _add_file_avere = TRUE; - } - - if (_indbil==5) - { - if ( (saldo >= ZERO) || (compensa) ) // il sottoconto ha saldo in dare - { - _gruppo_da_ordine += saldo; - _conto_da += saldo; - _add_file_dare = TRUE; - _sottoc_dare = TRUE; - } - else //il sottoconto ha saldo in avere - { - saldo = -saldo; - _gruppo_a_ordine += saldo; - _conto_a += saldo; - _add_file_avere = TRUE; - _sottoc_avere = TRUE; - } - scrivig_file_temp(); - } - } - delete _listacf; - return esiste_sc; -} - -bool CG1500_application::bil_verifica() -{ - TSaldo sld; - int g, c, indbil_conto = 0; - long s; - char tipo_conto = ' '; - real saldo_finale, saldo_conto, saldo_gruppo, saldo_iniziale; - real mov_conto_dare, mov_conto_avere, prg_conto_dare, prg_conto_avere; - real mov_gruppo_dare, mov_gruppo_avere, prg_gruppo_dare, prg_gruppo_avere; - bool esiste_conto = FALSE, esiste_sc = FALSE, movimentato = FALSE; - - CHECK(_tmp_saldi_att == NULL, "Non posso riaprire cg01"); - _tmp_saldi_att = new TIsamtempfile(LF_SALDI, "cg01", 2); - - _gp=-1; - _cp=-1; - - _saldo_ini_conto_dare = ZERO; - _saldo_ini_conto_avere = ZERO; - _saldo_ini_gruppo_dare = ZERO; - _saldo_ini_gruppo_avere = ZERO; - _nuovo_tot_saldo_d = ZERO; - _nuovo_tot_saldo_a = ZERO; - saldo_conto = ZERO; - mov_conto_dare = ZERO; - mov_conto_avere = ZERO; - prg_conto_dare = ZERO; - prg_conto_avere = ZERO; - saldo_gruppo = ZERO; - mov_gruppo_dare = ZERO; - mov_gruppo_avere = ZERO; - prg_gruppo_dare = ZERO; - prg_gruppo_avere = ZERO; - _u_max = 0l; - - for (_pcn->first(); !_pcn->eof(); _pcn->next()) - { - _prog->addstatus(1); - g = _pcn->get_int (PCN_GRUPPO); - c = _pcn->get_int (PCN_CONTO); - s = _pcn->get_long(PCN_SOTTOCONTO); - - if ( (((_cp != -1) && (c != _cp)) || ((_gp != -1) && (g != _gp))) && - esiste_sc ) - { - if (_verifica == 2) - if (!((_stampav == 2) && (saldo_conto == 0))) - { - real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; - if (app < ZERO) - _saldo_ini_gruppo_avere += app; - else - _saldo_ini_gruppo_dare += app; - mov_gruppo_dare += mov_conto_dare; - mov_gruppo_avere += mov_conto_avere; - prg_gruppo_dare += prg_conto_dare; - prg_gruppo_avere += prg_conto_avere; - saldo_gruppo += saldo_conto; - } - //scrivo il record del conto; - if ( (_verifica == 1)||( (_verifica == 2)&& - (!((_stampav == 2)&&(saldo_conto == 0))) ) ) - { - scrivi_record_conto(prg_conto_dare,prg_conto_avere,mov_conto_dare, - mov_conto_avere,saldo_conto); - esiste_conto = TRUE; - } - _cp = c; - _saldo_ini_conto_dare = ZERO; - _saldo_ini_conto_avere = ZERO; - saldo_conto = ZERO; - mov_conto_dare = ZERO; - mov_conto_avere = ZERO; - prg_conto_dare = ZERO; - prg_conto_avere = ZERO; - } - if (_verifica == 2) - if ( ((_gp != -1) && (g != _gp)) && (!esiste_conto) ) - { - _gp = g; - _saldo_ini_gruppo_dare = ZERO; - _saldo_ini_gruppo_avere = ZERO; - saldo_gruppo = ZERO; - mov_gruppo_dare = ZERO; - mov_gruppo_avere = ZERO; - prg_gruppo_dare = ZERO; - prg_gruppo_avere = ZERO; - } - if (_verifica == 2) - if ( ((_gp != -1) && (g != _gp)) && esiste_conto ) - { - //scrivo il record del gruppo - scrivi_record_gruppo(prg_gruppo_dare,prg_gruppo_avere,mov_gruppo_dare, - mov_gruppo_avere,saldo_gruppo); - _gp = g; - esiste_conto = FALSE; - _saldo_ini_gruppo_dare = ZERO; - _saldo_ini_gruppo_avere = ZERO; - saldo_gruppo = ZERO; - mov_gruppo_dare = ZERO; - mov_gruppo_avere = ZERO; - prg_gruppo_dare = ZERO; - prg_gruppo_avere = ZERO; - } - if ( (s == 0) && (c != 0) ) //si tratta di un conto - { - tipo_conto = _pcn->get(PCN_TMCF)[0]; - indbil_conto = _pcn->get_int(PCN_INDBIL); - if ( (tipo_conto == 'C') || (tipo_conto == 'F') ) - { - esiste_sc = ricerca_cf(g,c,tipo_conto,indbil_conto,saldo_finale,saldo_iniziale, - mov_conto_dare,mov_conto_avere,prg_conto_dare,prg_conto_avere, - saldo_conto); - if ( (_verifica == 2) && (_stampav == 2) ) - if (saldo_conto == 0) - continue; - if (esiste_sc) - { - _gp = g; - _cp = c; - TRecnotype recnum = _pcn->recno(); - _pcn->next(); - if (_pcn->eof()) - { - if (_verifica == 2) - { - real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; - if (app < ZERO) - _saldo_ini_gruppo_avere += app; - else - _saldo_ini_gruppo_dare += app; - mov_gruppo_dare += mov_conto_dare; - mov_gruppo_avere += mov_conto_avere; - prg_gruppo_dare += prg_conto_dare; - prg_gruppo_avere += prg_conto_avere; - saldo_gruppo += saldo_conto; - - scrivi_record_gruppo(prg_gruppo_dare,prg_gruppo_avere, - mov_gruppo_dare,mov_gruppo_avere,saldo_gruppo); - } - scrivi_record_conto(prg_conto_dare,prg_conto_avere,mov_conto_dare, - mov_conto_avere,saldo_conto); - } - _pcn->readat(recnum); - } - continue; - } - } - - if ( (c == 0) || (s == 0) ) - { - esiste_sc = FALSE; - continue; - } - - saldo_finale = ZERO; //saldo finale relativo a ciascun sottoconto - _indbil = indbil_conto; - if (_tipo_stampa1 == 1) //bil. di verifica per data limite - { - //modifica del 19/06/95 - movimentato = calcola(g,c,s); - if (_stampa_mov_prov != 3) - { - if (movimentato) - { - saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; - TLocalisamfile saldi(LF_SALDI); - saldi.zero(); - saldi.put(SLD_ANNOES,_annoes); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - if (saldi.read() == NOERR) - { - real ss = saldi.get_real(SLD_SALDO); - if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) - if (ss == ZERO && _annoes != 0) - saldo_iniziale += sld.saldofin_esprec(_annoes,g,c,s); - } - } - if (!movimentato) - if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) - if (_annoes != 0) - { - saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s); - if (_stampav == 1 && sld.significativo()) - movimentato = TRUE; - } - } - - //if (movimentato) - // saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; - //movimentato = calcola(g,c,s); - - if (movimentato || _stampav != 1) - { - //saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; - - _nuovo_tot_saldo_d += _mov_periodo_dare; - _nuovo_tot_saldo_a += _mov_periodo_avere; - if (saldo_iniziale > ZERO) - _nuovo_tot_saldo_d += saldo_iniziale; - else - { - real app = -saldo_iniziale; - _nuovo_tot_saldo_a += app; - } - - if (_datada == _dataini) - saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; - else if (_datada > _dataini) - { - if (saldo_iniziale > 0) - _prg_prec_dare += saldo_iniziale; - else _prg_prec_avere -= saldo_iniziale; - saldo_finale = _prg_prec_dare-_prg_prec_avere+_mov_periodo_dare- - _mov_periodo_avere; - - } - //if (saldo_finale == ZERO) - // if (_stampav == 2) - // continue; - } - //se saldo_finale < 0 verra' stampato con una A, se no con una D - } - else - { - movimentato = sld.ultima_immissione_verifica(_annoes,g,c,s,indbil_conto,_stampa_mov_prov); - - //modifica del 31/03/95 - if (_stampa_mov_prov != 3) - { - if (movimentato) - saldo_iniziale = sld.saldoini(); - if (!movimentato) - { - if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) - { - saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s); - if (_stampav == 1 && sld.significativo()) - movimentato = TRUE; - } - } - } - //fine modifica - - if (movimentato || _stampav != 1) - { - _mov_periodo_dare = sld.prgdare(); - _mov_periodo_avere = sld.prgavere(); - _prg_prec_dare = ZERO; - _prg_prec_avere = ZERO; - - saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; - } - } - - if (movimentato || _stampav != 1) - if (!(saldo_finale == ZERO && _stampav == 2)) - { - esiste_sc = TRUE; - esiste_conto = TRUE; - - if (_tipo_stampa1 == 2) - { - _nuovo_tot_saldo_d += _mov_periodo_dare; - _nuovo_tot_saldo_a += _mov_periodo_avere; - real nuovo = sld.saldoinisusaldi(); - if (nuovo > ZERO) - _nuovo_tot_saldo_d += nuovo; - else - { - nuovo = -nuovo; - _nuovo_tot_saldo_a += nuovo; - } - } - - if (saldo_iniziale < ZERO) - _saldo_ini_conto_avere += saldo_iniziale; - else - _saldo_ini_conto_dare += saldo_iniziale; - mov_conto_dare += _mov_periodo_dare; - mov_conto_avere += _mov_periodo_avere; - prg_conto_dare += _prg_prec_dare; - prg_conto_avere += _prg_prec_avere; - saldo_conto += saldo_finale; // somma algebrica!!! - - //scrivo il record relat. al sottoconto se non e' richiesto saldi di mastro - if (_verifica != 2) - { - _tmp_saldi_att->zero(); - _tmp_saldi_att->put(SLD_GRUPPO,g); - _tmp_saldi_att->put(SLD_CONTO,c); - _tmp_saldi_att->put(SLD_SOTTOCONTO,s); - _tmp_saldi_att->put(SLD_FLAGSALINI,tipo_conto); - if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) - { - if (saldo_iniziale > ZERO) //va stampato in Dare - _tmp_saldi_att->put(SLD_PDARESCA,saldo_iniziale); - else if (saldo_iniziale < ZERO) - { - saldo_iniziale = -saldo_iniziale; - _tmp_saldi_att->put(SLD_PAVERESCA,saldo_iniziale); - } - } - else if (_datada > _dataini) - { - _tmp_saldi_att->put(SLD_PDARESCA,_prg_prec_dare); - _tmp_saldi_att->put(SLD_PAVERESCA,_prg_prec_avere); - } - _tmp_saldi_att->put(SLD_PDARE,_mov_periodo_dare); - _tmp_saldi_att->put(SLD_PAVERE,_mov_periodo_avere); - _tmp_saldi_att->put(SLD_SALDO,saldo_finale); - _tmp_saldi_att->put(SLD_DATAULMOV,_u_max); - _tmp_saldi_att->write(); - } - _gp = g; - _cp = c; - } - - TRecnotype recnum = _pcn->recno(); - _pcn->next(); - if (_pcn->eof()) - { - if ( (_verifica == 2) && esiste_conto ) - { - real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; - if (app < ZERO) - _saldo_ini_gruppo_avere += app; - else - _saldo_ini_gruppo_dare += app; - mov_gruppo_dare += mov_conto_dare; - mov_gruppo_avere += mov_conto_avere; - prg_gruppo_dare += prg_conto_dare; - prg_gruppo_avere += prg_conto_avere; - saldo_gruppo += saldo_conto; - - scrivi_record_gruppo(prg_gruppo_dare,prg_gruppo_avere, - mov_gruppo_dare,mov_gruppo_avere,saldo_gruppo); - } - if (esiste_sc) - if ( (_verifica == 1)||( (_verifica == 2)&& - (!((_stampav == 2)&&(saldo_conto == 0))) ) ) - scrivi_record_conto(prg_conto_dare,prg_conto_avere,mov_conto_dare, - mov_conto_avere,saldo_conto); - } - _pcn->readat(recnum); - } - return TRUE; -} - -//bilancio di verifica per data limite -bool CG1500_application::calcola(int g, int c, long s) -{ - char sezione, provvis; - real importo; - int annoe; - long num_reg; - TDate data_reg, data, datacomp; - bool conto_mov = FALSE; - TLocalisamfile rmov(LF_RMOV); - TLocalisamfile mov(LF_MOV); - - _mov_periodo_dare = ZERO; - _mov_periodo_avere = ZERO; - _prg_prec_dare = ZERO; - _prg_prec_avere = ZERO; - _saldo_ini_dare = ZERO; - _saldo_ini_avere = ZERO; - _u_max = 0l; - - rmov.setkey(2); - rmov.zero(); - rmov.put(RMV_GRUPPO,g); - if (c != 0) - rmov.put(RMV_CONTO,c); - if (s != 0) - rmov.put(RMV_SOTTOCONTO,s); - TRectype rec(rmov.curr()); - - rmov.read(_isgteq); - for ( ; !rmov.eof(); rmov.next()) - { - if (rmov.curr() != rec) break; - - annoe = rmov.get_int(RMV_ANNOES); - data = rmov.get_date(RMV_DATAREG); - num_reg = rmov.get_long(RMV_NUMREG); - - mov.setkey(1); - mov.zero(); - mov.put(MOV_NUMREG, num_reg); - mov.read(); - if (mov.bad()) - mov.zero(); - provvis = mov.get_char(MOV_PROVVIS); - datacomp = mov.get_date(MOV_DATACOMP); - - if (_stampa_mov_prov == 1 && provvis != '\0') //bilancio normale (non comprende i provvisori) - continue; - - if (_stampa_mov_prov == 3 && provvis == '\0') //bilancio dei soli provvisori - continue; - - TString codcaus(mov.get(MOV_CODCAUS)); - - // if (codcaus.not_empty()) - // if (codcaus == causale_chiusura()) - // continue; - - // Modifica del 03-03-95 - - TCaus cau (codcaus); - - if (codcaus.not_empty()) - if (cau.chiusura()) //Si tratta di causale di chiusura - continue; - - //la causale e' uguale a quella di chiusura - //break; - - sezione = rmov.get_char(RMV_SEZIONE); - importo = rmov.get_real(RMV_IMPORTO); - - if (_annoes == 0) - data_reg = data; - else data_reg = datacomp; - - if (importo == 0) - continue; - - //calcolo i movimenti del periodo - /* - if ( data_reg >= _datada && data_reg <= _dataa) - if ((codcaus == causale_apertura() && _dataini != _datada) || - (codcaus != causale_apertura())) - { - conto_mov = TRUE; - if (sezione == 'D') - _mov_periodo_dare += importo; - else _mov_periodo_avere += importo; - _u_max = fnc_max(_u_max, data); - } - */ - // Modifica del 03-03-95 - //calcolo i movimenti del periodo - if ( data_reg >= _datada && data_reg <= _dataa) - if ((cau.apertura() && _dataini != _datada) || - (!cau.apertura())) - { - conto_mov = TRUE; - if (sezione == 'D') - _mov_periodo_dare += importo; - else _mov_periodo_avere += importo; - _u_max = fnc_max(_u_max, data); - } - - //il saldo inizio es. e' dato dall'importo dare - importo avere di quei movimenti che hanno causale == apertura e data reg >= data inizio es. e <= data limite sup. - if (_datada == _dataini) //calcolo il saldo iniziale - { - if (cau.apertura()) - if ( (data_reg >= _dataini) && (data_reg <= _dataa) ) - { - if (sezione == 'D') - _saldo_ini_dare += importo; - else _saldo_ini_avere += importo; - _u_max = fnc_max(_u_max, data); - conto_mov = TRUE; - } - } - else if (_datada > _dataini) //calcolo i progressivi precedenti - if ( (data_reg >= _dataini) && (data_reg <= _datada) ) - { - if (sezione == 'D') - _prg_prec_dare += importo; - else _prg_prec_avere += importo; - _u_max = fnc_max(_u_max, data); - conto_mov = TRUE; - } - } - return conto_mov; -} - -bool CG1500_application::ricerca_cf(int g,int c,char tipocf,int ib, real& saldo_finale,real& saldo_iniziale, - real& mov_conto_dare,real& mov_conto_avere,real& prg_conto_dare,real& prg_conto_avere,real& saldo_conto) -{ - TSaldo sld; - bool esiste_sc = FALSE; - long s; - int anno; - - if (_tipo_stampa1 == 1) - anno = _annoapp; - else anno = _annoes; - - _lista = new TSaldi_list(g, c, anno); - TRecnotype items = _lista->items(); - - for (int i = 0; i < items; i++) - { - const TRectype* r = _lista->saldi(); - if (r == NULL) break; - - s = r->get_long(SLD_SOTTOCONTO); - - saldo_finale = ZERO; //saldo finale relativo a ciascun sottoconto - - if (_tipo_stampa1 == 1) //bil. di verifica per data limite - { - /* - if ( !calcola(g,c,s) ) //il conto non e' movimentato - if (_stampav == 1 || _stampav == 3) //per i C/F anche se seleziono -tutti i conti, voglio solo quelli movimentati - continue; - */ - - //modifica del 19/06. Vedi appunti per capire - bool movimentato = calcola(g,c,s); - - if (_stampa_mov_prov != 3) - { - if (movimentato) - { - saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; - TLocalisamfile saldi(LF_SALDI); - saldi.zero(); - saldi.put(SLD_ANNOES,_annoes); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - if (saldi.read() == NOERR) - { - //se il saldo iniziale e' diverso da zero non lo devo considerare - //perche' l'ho gia' considerato nella funzione calcola - real ss = saldi.get_real(SLD_SALDO); - if (ib == 1 || ib == 2 || ib == 5) - if (ss == ZERO && _annoes != 0) //competenza!!! - saldo_iniziale += sld.saldofin_esprec(_annoes,g,c,s); - } - } - if (!movimentato) - if (ib == 1 || ib == 2 || ib == 5) - if (_annoes != 0) //cioe' se sto ragionando per competenza - { - saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s); - movimentato = sld.significativo(); - } - } - - if (!movimentato) - continue; - //fine modifica - - _nuovo_tot_saldo_d += _mov_periodo_dare; - _nuovo_tot_saldo_a += _mov_periodo_avere; - if (saldo_iniziale > ZERO) - _nuovo_tot_saldo_d += saldo_iniziale; - else - { - real app = -saldo_iniziale; - _nuovo_tot_saldo_a += app; - } - - if (_datada == _dataini) - saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; - else if (_datada > _dataini) - { - if (saldo_iniziale > 0) - _prg_prec_dare += saldo_iniziale; - else _prg_prec_avere -= saldo_iniziale; - saldo_finale = _prg_prec_dare-_prg_prec_avere+_mov_periodo_dare- - _mov_periodo_avere; - } - if (saldo_finale == ZERO) - if (_stampav == 2) - continue; - - //se saldo_finale < 0 verra' stampato con una A, se no con una D - } - else - { - //Attenzione! Nel caso di "tutti i conti" devono scendere solo i cli/for movimentati!!! - - //modifica del 31/03/1995 - bool movimentato = sld.ultima_immissione_verifica(_annoes,g,c,s,ib,_stampa_mov_prov); - - if (_stampa_mov_prov != 3) - { - saldo_iniziale = sld.saldoini(); - if (!movimentato) - { - //if (_stampav == 1) - // continue; - //vado sui saldi con l'anno precedente e calcolo saldo_finale es.prec - //se esiste tale record e almeno un valore e' significativo (indipendentemente dal valore - //del saldo iniziale calcolato, allora metto a TRUE il flag movimentato - //solo se e' un conto patrimoniale - if (ib == 1 || ib == 2 || ib == 5) - { - saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s); - movimentato = sld.significativo(); - } - } - } - - if (!movimentato) - continue; - //fine modifica 31/03/1995 - - _mov_periodo_dare = sld.prgdare(); - _mov_periodo_avere = sld.prgavere(); - _prg_prec_dare = ZERO; - _prg_prec_avere = ZERO; - - saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; - - if (saldo_finale == ZERO) - if (_stampav == 2) - continue; - - _nuovo_tot_saldo_d += _mov_periodo_dare; - _nuovo_tot_saldo_a += _mov_periodo_avere; - real nuovo = sld.saldoinisusaldi(); - if (nuovo > ZERO) - _nuovo_tot_saldo_d += nuovo; - else - { - nuovo = -nuovo; - _nuovo_tot_saldo_a += nuovo; - } - } - - esiste_sc = TRUE; - - if (saldo_iniziale < ZERO) - _saldo_ini_conto_avere += saldo_iniziale; - else - _saldo_ini_conto_dare += saldo_iniziale; - mov_conto_dare += _mov_periodo_dare; - mov_conto_avere += _mov_periodo_avere; - prg_conto_dare += _prg_prec_dare; - prg_conto_avere += _prg_prec_avere; - saldo_conto += saldo_finale; // somma algebrica!!! - - //scrivo il record relat. al sottoconto se non e' richiesto saldi di mastro - if (_verifica != 2) - { - _tmp_saldi_att->zero(); - _tmp_saldi_att->put(SLD_GRUPPO,g); - _tmp_saldi_att->put(SLD_CONTO,c); - _tmp_saldi_att->put(SLD_SOTTOCONTO,s); - _tmp_saldi_att->put(SLD_FLAGSALINI,tipocf); - if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) - { - if (saldo_iniziale > ZERO) //va stampato in Dare - _tmp_saldi_att->put(SLD_PDARESCA,saldo_iniziale); - else if (saldo_iniziale < ZERO) - { - saldo_iniziale = -saldo_iniziale; - _tmp_saldi_att->put(SLD_PAVERESCA,saldo_iniziale); - } - } - else if (_datada > _dataini) - { - _tmp_saldi_att->put(SLD_PDARESCA,_prg_prec_dare); - _tmp_saldi_att->put(SLD_PAVERESCA,_prg_prec_avere); - } - _tmp_saldi_att->put(SLD_PDARE,_mov_periodo_dare); - _tmp_saldi_att->put(SLD_PAVERE,_mov_periodo_avere); - _tmp_saldi_att->put(SLD_SALDO,saldo_finale); - _tmp_saldi_att->put(SLD_DATAULMOV, _u_max); - _tmp_saldi_att->write(); - } - } - delete _lista; - return esiste_sc; -} - -void CG1500_application::scrivi_record_gruppo(const real& prg_da, - const real& prg_a,const real& mov_da,const real& mov_a,const real& s) -{ - _tmp_saldi_att->zero(); - _tmp_saldi_att->put(SLD_GRUPPO,_gp); - _tmp_saldi_att->put(SLD_CONTO,0); - _tmp_saldi_att->put(SLD_SOTTOCONTO,0L); - if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) - { - real app = _saldo_ini_gruppo_dare + _saldo_ini_gruppo_avere; - if (app > ZERO) //va stampato in Dare - _tmp_saldi_att->put(SLD_PDARESCA,app); - else if (app < ZERO) - { - app = -app; - _tmp_saldi_att->put(SLD_PAVERESCA,app); - } - } - else if (_datada > _dataini) - { - _tmp_saldi_att->put(SLD_PDARESCA,prg_da); - _tmp_saldi_att->put(SLD_PAVERESCA,prg_a); - } - _tmp_saldi_att->put(SLD_PDARE,mov_da); - _tmp_saldi_att->put(SLD_PAVERE,mov_a); - _tmp_saldi_att->put(SLD_SALDO,s); - _tmp_saldi_att->write(); -} - -void CG1500_application::scrivi_record_conto(const real& prg_da, - const real& prg_a,const real& mov_da,const real& mov_a,const real& s) -{ - _tmp_saldi_att->zero(); - _tmp_saldi_att->put(SLD_GRUPPO,_gp); - _tmp_saldi_att->put(SLD_CONTO,_cp); - _tmp_saldi_att->put(SLD_SOTTOCONTO,0L); - if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) - { - real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; - if (app > ZERO) //va stampato in Dare - _tmp_saldi_att->put(SLD_PDARESCA,app); - else if (app < ZERO) - { - app = -app; - _tmp_saldi_att->put(SLD_PAVERESCA,app); - } - } - else if (_datada > _dataini) - { - _tmp_saldi_att->put(SLD_PDARESCA,prg_da); - _tmp_saldi_att->put(SLD_PAVERESCA,prg_a); - } - _tmp_saldi_att->put(SLD_PDARE,mov_da); - _tmp_saldi_att->put(SLD_PAVERE,mov_a); - _tmp_saldi_att->put(SLD_SALDO,s); - _tmp_saldi_att->write(); -} - -void CG1500_application::init_sort() -{ - _cf = new cli_for; - _sort = new TSort(sizeof(cli_for)); - - if (_ordinamento == 1) - { - _sort->addsortkey ((char*)&(_cf->tipocf)-(char*)&(_cf->tipocf),1); - _sort->addsortkey ((char*)&(_cf->gruppo)-(char*)&(_cf->tipocf),3); - _sort->addsortkey ((char*)&(_cf->conto)-(char*)&(_cf->tipocf),3); - _sort->addsortkey ((char*)&(_cf->codcf)-(char*)&(_cf->tipocf),6); - } - else if (_ordinamento == 2) - { - _sort->addsortkey ((char*)&(_cf->tipocf)-(char*)&(_cf->tipocf),1); - _sort->addsortkey ((char*)&(_cf->gruppo)-(char*)&(_cf->tipocf),3); - _sort->addsortkey ((char*)&(_cf->conto)-(char*)&(_cf->tipocf),3); - _sort->addsortkey ((char*)&(_cf->ragsoc)-(char*)&(_cf->tipocf),50); - } - - _sort->init(); -} - -void CG1500_application::riempi_record(char t,int g,int c,long s, - const char* rs,const real& sd,const real& sa, - const real& md,const real& ma,const real& sf) -{ - _cf->tipocf = t; - sprintf(_cf->gruppo, "%03d", g); - sprintf(_cf->conto, "%03d", c); - sprintf(_cf->codcf, "%06ld", s); - sprintf(_cf->ragsoc, "%s", rs); - if ( s == 999999L ) - { - if ( (_datada == _dataini)||(_tipo_stampa1 != 1) ) - { - real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; - if (app > ZERO) //va stampato in Dare - { - _cf->saldoavere = ZERO; - _cf->saldodare = app; - } - else if (app < ZERO) - { - app = -app; - _cf->saldodare = ZERO; - _cf->saldoavere = app; - } - } - else if (_datada > _dataini) - { - _cf->saldodare = sd; - _cf->saldoavere = sa; - } - } - else - { - _cf->saldodare = sd; - _cf->saldoavere = sa; - } - _cf->movdare = md; - _cf->movavere = ma; - _cf->saldofinale = sf; - _cf->udata = _u_max; - _sort->sort((const char*)_cf); -} - -void CG1500_application::crea_sort_clifo() -{ - TSaldo sld; - TLocalisamfile saldi(LF_SALDI, FALSE); - int g=0, c=0; - long codcf=0l; - TString80 ragsoc; - char tipocf,tipocfp,tipoa; - real saldo_finale, saldo_conto, saldo_iniziale, saldodare, saldoavere, - movdare, movavere; - real mov_conto_dare, mov_conto_avere, prg_conto_dare, prg_conto_avere; - bool esiste_sc = FALSE, movimentato = FALSE; - TArray gccf; - TRecnotype items = _cur->items(); - - _gp=-1; - _cp=-1; - tipocfp = ' '; - - _saldo_ini_conto_dare = ZERO; - _saldo_ini_conto_avere = ZERO; - saldo_conto = ZERO; - mov_conto_dare = ZERO; - mov_conto_avere = ZERO; - prg_conto_dare = ZERO; - prg_conto_avere = ZERO; - _u_max = 0l; - - init_sort(); - - int anno; - - if (_tipo_stampa1 == 1) - anno = _annoapp; - else anno = _annoes; - - *_cur = 0l; - - for (int i = 0; i < items; i++,++(*_cur)) - { - _prog->addstatus(1); - codcf = _cur->curr().get_long(CLI_CODCF); - tipocf = _cur->curr().get(CLI_TIPOCF)[0]; - ragsoc = _cur->curr().get(CLI_RAGSOC); - tipoa = _cur->curr().get_char(CLI_TIPOAPER); - if (tipoa == 'F') //persona fisica - { - TString80 cognome, nome; - cognome = ragsoc.mid(0,30); - nome = ragsoc.mid(30,20); - cognome.trim(); nome.trim(); - ragsoc = cognome; - ragsoc << " " << nome; - } - - if (tipocf == 'C') - gccf = _clienti; - else - if (tipocf == 'F') - gccf = _fornitori; - - for (int i=0; i < gccf.items(); i++) - { - int g = ((TToken_string&)gccf[i]).get_int(0); - int c = ((TToken_string&)gccf[i]).get_int(1); - - int aprec = EsePre(anno); - - saldi.zero(); - saldi.put(SLD_ANNOES, anno); - saldi.put(SLD_GRUPPO, g); - saldi.put(SLD_CONTO, c); - saldi.put(SLD_SOTTOCONTO, codcf); - - if (saldi.read() != NOERR) - if (_tipo_stampa1 == 1) //bilancio per data limite - continue; - else if (_stampac == 2) //se sono richiesti i conti movimentati - { //esco, se no... - _indbil = cerca_indbil(g,c); - if (_indbil == 1 || _indbil == 2 || _indbil == 5) - { - saldi.zero(); - saldi.put(SLD_ANNOES, aprec); - saldi.put(SLD_GRUPPO, g); - saldi.put(SLD_CONTO, c); - saldi.put(SLD_SOTTOCONTO, codcf); - if (saldi.read() != NOERR) - continue; - } - } - - if ( (((_cp != -1) && (c != _cp)) || ((_gp != -1) && (g != _gp))) && - esiste_sc ) - { - //scrivo il record del conto; - riempi_record(tipocfp,_gp,_cp,999999L,"zzzz",prg_conto_dare, - prg_conto_avere,mov_conto_dare,mov_conto_avere,saldo_conto); - tipocfp = tipocf; - _cp = c; - esiste_sc = FALSE; - _saldo_ini_conto_dare = ZERO; - _saldo_ini_conto_avere = ZERO; - saldo_conto = ZERO; - mov_conto_dare = ZERO; - mov_conto_avere = ZERO; - prg_conto_dare = ZERO; - prg_conto_avere = ZERO; - } - - saldo_finale = ZERO; - saldodare = ZERO; - saldoavere = ZERO; - movdare = ZERO; - movavere = ZERO; - - if (_tipo_stampa1 == 1) //bilancio di verifica per data limite - { - //modifica del 19/06/95 - _indbil = cerca_indbil(g,c); - movimentato = calcola(g,c,codcf); - if (_stampa_mov_prov != 3) - if (!movimentato && _stampac!=1) - if (_indbil == 1 || _indbil == 2 || _indbil == 5) - if (_annoes != 0) //cioe' se sto ragionando per competenza - saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,codcf); - - if (movimentato) - { - saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; - TLocalisamfile saldi(LF_SALDI); - saldi.zero(); - saldi.put(SLD_ANNOES,_annoes); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,codcf); - if (saldi.read() == NOERR) - { - real s = saldi.get_real(SLD_SALDO); - if (_stampa_mov_prov != 3) - if (_indbil == 1 || _indbil == 2 || _indbil == 5) - if (s == ZERO && _annoes != 0) //competenza!!! - saldo_iniziale += sld.saldofin_esprec(_annoes,g,c,codcf); - } - } - //fine modifica - //movimentato = calcola(g,c,codcf); - if (movimentato || _stampac != 1) - { - if (_datada == _dataini) - saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; - else if (_datada > _dataini) - { - //modifica del 19/06 - if (saldo_iniziale > 0) - _prg_prec_dare += saldo_iniziale; - else _prg_prec_avere -= saldo_iniziale; - //fine modifica - saldo_finale = _prg_prec_dare-_prg_prec_avere+_mov_periodo_dare - -_mov_periodo_avere; - } - } - //if (saldo_finale == ZERO) - // if (_stampac == 2) - // continue; - - //se saldo_finale < 0 verra' stampato con una A, se no con una D - } - else //bilancio di verifica all'ultima immissione - { - _indbil = cerca_indbil(g,c); - movimentato = sld.ultima_immissione_verifica(anno,g,c,codcf,_indbil,_stampa_mov_prov); - - if (_stampa_mov_prov != 3) - if (!movimentato && _stampac!=1) - if (_indbil == 1 || _indbil == 2 || _indbil == 5) - saldo_iniziale = sld.saldofin_esprec(anno,g,c,codcf); - - if (movimentato) - saldo_iniziale = sld.saldoini(); - - if (movimentato || _stampac != 1) - { - _mov_periodo_dare = sld.prgdare(); - _mov_periodo_avere = sld.prgavere(); - _prg_prec_dare = ZERO; - _prg_prec_avere = ZERO; - - saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; - } - //if (saldo_finale == ZERO) - // if (_stampac == 2) - // continue; - } - if (movimentato || _stampac != 1) - if (!(saldo_finale == ZERO && _stampac == 2)) - { - esiste_sc = TRUE; - - if (saldo_iniziale < ZERO) - _saldo_ini_conto_avere += saldo_iniziale; - else - _saldo_ini_conto_dare += saldo_iniziale; - mov_conto_dare += _mov_periodo_dare; - mov_conto_avere += _mov_periodo_avere; - prg_conto_dare += _prg_prec_dare; - prg_conto_avere += _prg_prec_avere; - saldo_conto += saldo_finale; // somma algebrica!!! - - if ( (_datada == _dataini)||(_tipo_stampa1 != 1) ) - { - if (saldo_iniziale > ZERO) //va stampato in Dare - saldodare = saldo_iniziale; - else if (saldo_iniziale < ZERO) - { - saldo_iniziale = -saldo_iniziale; - saldoavere = saldo_iniziale; - } - } - else if (_datada > _dataini) - { - saldodare = _prg_prec_dare; - saldoavere = _prg_prec_avere; - } - - movdare = _mov_periodo_dare; - movavere = _mov_periodo_avere; - - riempi_record(tipocf,g,c,codcf,ragsoc,saldodare,saldoavere,movdare, - movavere,saldo_finale); - tipocfp = tipocf; - _gp = g; - _cp = c; - } - } - } - if (esiste_sc) - riempi_record(tipocfp,_gp,_cp,999999L,"zzzz",prg_conto_dare,prg_conto_avere, - mov_conto_dare,mov_conto_avere,saldo_conto); -} - -int CG1500_application::cerca_indbil(int g, int c) -{ - TLocalisamfile pconti(LF_PCON); - - pconti.zero(); - pconti.put(PCN_GRUPPO,g); - if (c != 0) - pconti.put(PCN_CONTO,c); - pconti.put(PCN_SOTTOCONTO,0l); - - pconti.read(); - - return pconti.get_int(PCN_INDBIL); -} - -void CG1500_application::leggi_files_dare(TIsamtempfile* file) -{ - _gruppo_dare = file->get_int(SLD_GRUPPO); - _conto_dare = file->get_int(SLD_CONTO); - _sottoconto_dare = file->get_long(SLD_SOTTOCONTO); - _saldo_dare = file->get_real(SLD_PDARE); - - _descr_dare = DescrizioneConto(_gruppo_dare,_conto_dare,_sottoconto_dare,' '); - - _gc_corr_dare = format("%3d%3d", _gruppo_dare, _conto_dare); - - if (_gc_corr_dare != _gc_prec_dare) - { - _cambiato_conto_1 = TRUE; - _gc_prec_dare = _gc_corr_dare; - } - else if (_sottoconto_dare != 0l) - _cambiato_conto_1 = FALSE; -} - -void CG1500_application::leggi_files_avere(TIsamtempfile* file) -{ - _gruppo_avere = file->get_int(SLD_GRUPPO); - _conto_avere = file->get_int(SLD_CONTO); - _sottoconto_avere = file->get_long(SLD_SOTTOCONTO); - _saldo_avere = file->get_real(SLD_PAVERE); - - _descr_avere = DescrizioneConto(_gruppo_avere,_conto_avere,_sottoconto_avere, - ' '); - _gc_corr_avere = format("%3d%3d", _gruppo_avere, _conto_avere); - - if (_gc_corr_avere != _gc_prec_avere) - { - _cambiato_conto_2 = TRUE; - _gc_prec_avere = _gc_corr_avere; - } - else if (_sottoconto_avere != 0l) - _cambiato_conto_2 = FALSE; -} - -bool CG1500_application::preprocess_print(int file, int counter) -{ - set_real_picture ("###.###.###.###"); - if (_bilancio == 1) - { - set_print_zero(); - _tmp_saldi_att->setkey(2); - _tmp_saldi_pass->setkey(2); - _tmp_saldi_costi->setkey(2); - _tmp_saldi_ricavi->setkey(2); - _tmp_saldi_conti_uno->setkey(2); - _tmp_saldi_conti_due->setkey(2); - _gc_prec_avere = ""; - _prima_volta = _seconda_volta = TRUE; - _flag = _controlla = FALSE; - _salto_pagina = _salto_pagina1 = _stampato = FALSE; - _cambiato_conto_1 = TRUE; - _cambiato_conto_2 = TRUE; - _tot_dare = ZERO; - _tot_avere = ZERO; - } - else - { - //if ( (_verifica == 3) && (_ordinamento == 1) ) - // _tmp_saldi_att->setkey(2); - set_print_zero(FALSE); - _cambiato_conto_1 = FALSE; - _livello_conto = TRUE; - _saldo_dare_tot = ZERO; - _saldo_avere_tot = ZERO; - _mov_dare_tot = ZERO; - _mov_avere_tot = ZERO; - _saldo_finale_tot = ZERO; - } - return TRUE; -} - -void CG1500_application::leggi_file_tmp() -{ - if (_livello_conto) // era meglio chiamarla _livello_conto_oppure_gruppo, perche' nel caso dei saldi di mastro _livello_conto==TRUE <=> si tratta di un gruppo, mentre nel caso del bilancio _livello_conto==TRUE <=> si tratta di un conto - { - _gruppo = _tmp_saldi_att->get_int(SLD_GRUPPO); - _conto = _tmp_saldi_att->get_int(SLD_CONTO); - _sottoconto = _tmp_saldi_att->get_long(SLD_SOTTOCONTO); - _tipo_conto = _tmp_saldi_att->get_char(SLD_FLAGSALINI); - _descr = DescrizioneConto(_gruppo,_conto,_sottoconto,_tipo_conto); - _saldoini_dare = _tmp_saldi_att->get_real(SLD_PDARESCA); - _saldoini_avere = _tmp_saldi_att->get_real(SLD_PAVERESCA); - _mov_dare = _tmp_saldi_att->get_real(SLD_PDARE); - _mov_avere = _tmp_saldi_att->get_real(SLD_PAVERE); - _saldofinale = _tmp_saldi_att->get_real(SLD_SALDO); - } - _eof1 = _tmp_saldi_att->next(); - if (!_eof1) - { - _gruppo_succ = _tmp_saldi_att->get_int(SLD_GRUPPO); - _conto_succ = _tmp_saldi_att->get_int(SLD_CONTO); - _sottoconto_succ = _tmp_saldi_att->get_long(SLD_SOTTOCONTO); - _tipoc_succ = _tmp_saldi_att->get_char(SLD_FLAGSALINI); - if ( (_verifica != 2) && (_sottoconto_succ != 0) ) - if (_tipo_stampa1 == 2) - _ultima_data = UltimaData(_gruppo_succ,_conto_succ, - _sottoconto_succ,_annoes); - else _ultima_data = _tmp_saldi_att->get_date(SLD_DATAULMOV); - _descr_succ = DescrizioneConto(_gruppo_succ,_conto_succ, - _sottoconto_succ,_tipoc_succ); - _saldoini_dare_succ = _tmp_saldi_att->get_real(SLD_PDARESCA); - _saldoini_avere_succ = _tmp_saldi_att->get_real(SLD_PAVERESCA); - _mov_dare_succ = _tmp_saldi_att->get_real(SLD_PDARE); - _mov_avere_succ = _tmp_saldi_att->get_real(SLD_PAVERE); - _saldofinale_succ = _tmp_saldi_att->get_real(SLD_SALDO); - _livello_conto = FALSE; - if ( ((_verifica != 2)&&(_sottoconto_succ == 0)) || - ((_verifica == 2)&&(_conto_succ == 0)) ) - { - _livello_conto = TRUE; - _gruppo_succ = _gruppo; - _conto_succ = _conto; - _sottoconto_succ = _sottoconto; - _descr_succ = _descr; - _saldoini_dare_succ = _saldoini_dare; - _saldoini_avere_succ = _saldoini_avere; - _mov_dare_succ = _mov_dare; - _mov_avere_succ = _mov_avere; - _saldofinale_succ = _saldofinale; - } - } -} - -bool CG1500_application::preprocess_page(int file, int counter) -{ - reset_print(); - - if (_bilancio == 1) //stampa bilancio a sez. contrapposte - { - if (counter) - { - if ( (!_eof1) && (_cambiato_conto_1) ) - _eof1 = _tmp_saldi_att->next(); - - if ( (!_eof2) && (_cambiato_conto_2) ) - _eof2 = _tmp_saldi_pass->next(); - - if (_eof1 && _eof2) - { - if (_prima_volta) - { - stampa_totali_uno(_prg_saldoini_dare,_prg_saldoini_avere); - _eof3 = _tmp_saldi_costi->first(); - _eof4 = _tmp_saldi_ricavi->first(); - } - else - { - _controlla = TRUE; - - if (_salto_pagina) - { - if ( (!_eof3) && (_cambiato_conto_1) ) - _eof3 = _tmp_saldi_costi->next(); - - if ( (!_eof4) && (_cambiato_conto_2) ) - _eof4 = _tmp_saldi_ricavi->next(); - } - } - - if ( (!_eof3) && (_cambiato_conto_1) ) - leggi_files_dare(_tmp_saldi_costi); - - if ( (!_eof4) && (_cambiato_conto_2) ) - leggi_files_avere(_tmp_saldi_ricavi); - - if (_eof3 && _eof4 && _salto_pagina) - { - if (_seconda_volta) - { - stampa_totali(); - _eof5 = _tmp_saldi_conti_uno->first(); - _eof6 = _tmp_saldi_conti_due->first(); - } - else - { - _flag = TRUE; - - if (_salto_pagina1) - { - if ( (!_eof5) && (_cambiato_conto_1) ) - _eof5 = _tmp_saldi_conti_uno->next(); - - if ( (!_eof6) && (_cambiato_conto_2) ) - _eof6 = _tmp_saldi_conti_due->next(); - } - } - - if ( (!_eof5) && (_cambiato_conto_1) ) - leggi_files_dare(_tmp_saldi_conti_uno); - - if ( (!_eof6) && (_cambiato_conto_2) ) - leggi_files_avere(_tmp_saldi_conti_due); - } - } - } - else //counter = 0 - { - _gc_prec_dare = _gc_corr_avere = ""; - _eof1 = _tmp_saldi_att->first(); - _eof2 = _tmp_saldi_pass->first(); - } - - if ( (!_eof1) && (_cambiato_conto_1) ) - leggi_files_dare(_tmp_saldi_att); - - if ( (!_eof2) && (_cambiato_conto_2) ) - leggi_files_avere(_tmp_saldi_pass); - } - else //stampa bilancio di verifica - { - if (_verifica == 3) - leggi_sort(); - else - { - if (counter) - { - if (!_eof1) - leggi_file_tmp(); - } - else - { - _eof1 = _tmp_saldi_att->first(); - if (_eof1) - return FALSE; - else leggi_file_tmp(); - } - } - } - return TRUE; -} - -void CG1500_application::leggi_sort() -{ - struct cli_for* cf; - - if ( (_buff = _sort->retrieve()) != NULL) - { - cf = (struct cli_for*)_buff; - _tipo_conto = cf->tipocf; - _gruppo = atoi(cf->gruppo); - _conto = atoi(cf->conto); - _sottoconto = atol(cf->codcf); - _descr = cf->ragsoc; - if ( (_ordinamento == 2 && _descr != "zzzz") || - (_ordinamento == 1 && _sottoconto != 999999L) ) - if (_tipo_stampa1 == 2) - _ultima_data = UltimaData(_gruppo,_conto,_sottoconto,_annoes); - else _ultima_data = cf->udata; - _saldo_dare = cf->saldodare; - _saldo_avere = cf->saldoavere; - _mov_dare = cf->movdare; - _mov_avere = cf->movavere; - _saldofinale = cf->saldofinale; - } -} - -void CG1500_application::controlla_conto(int file1,int file2) -{ - char dep = '*'; - - if (!file1) - if (_cambiato_conto_1) - { - set_row(_i,"@66g%c", dep); - _cambiato_conto_1 = FALSE; - } - else - { - stampa_prima_colonna(_gruppo_dare, _conto_dare, _sottoconto_dare, - _descr_dare,_saldo_dare); - _cambiato_conto_1 = TRUE; - if (!_totali) - if ( (_conto_dare == 0) && (_sottoconto_dare == 0) ) - _tot_dare += _saldo_dare; - if (_totali) - if (_sottoconto_dare == 0) - _tot_dare += _saldo_dare; - } - - if (!file2) - if (_cambiato_conto_2) - { - set_row(_i,"@66g%c", dep); - _cambiato_conto_2 = FALSE; - } - else - { - stampa_seconda_colonna(_gruppo_avere, _conto_avere, _sottoconto_avere, - _descr_avere, _saldo_avere); - _cambiato_conto_2 = TRUE; - if (!_totali) - if ( (_conto_avere == 0) && (_sottoconto_avere == 0) ) - _tot_avere += _saldo_avere; - if (_totali) - if (_sottoconto_avere == 0) - _tot_avere += _saldo_avere; - } -} - -void CG1500_application::postclose_print() -{ - if (_bilancio == 1) - { - delete _tmp_saldi_att; _tmp_saldi_att = NULL; - delete _tmp_saldi_pass; _tmp_saldi_pass = NULL; - delete _tmp_saldi_costi; _tmp_saldi_costi = NULL; - delete _tmp_saldi_ricavi; _tmp_saldi_ricavi = NULL; - delete _tmp_saldi_conti_uno; _tmp_saldi_conti_uno = NULL; - delete _tmp_saldi_conti_due; _tmp_saldi_conti_due = NULL; - } - else - { - if (_verifica == 3) - delete _sort; - else - { - delete _tmp_saldi_att; _tmp_saldi_att = NULL; - } - } -} - -void CG1500_application::set_page(int file, int counter) -{ - TString dep = ""; - - if (_bilancio == 1) //stampa bilancio a sezioni contrapposte - { - _i = 1; - - if (!counter) - { - set_row(_i++,"@29gATTIVITA'@94gPASSIVITA'"); - set_row(_i++,"@29g---------@94g----------"); - set_row(_i++, (const char*)dep); - } - - controlla_conto(_eof1,_eof2); //stampo una riga vuota tra un gruppo e un conto altrimenti no - - if ( _eof1 && _eof2 && (!_prima_volta) && _controlla ) - if (!_salto_pagina) - { - printer().formfeed(); - set_row(_i++,"@29gCOSTI@94gRICAVI"); - set_row(_i++,"@29g-----@94g------"); - set_row(_i++, (const char*)dep); - _salto_pagina = TRUE; - - } - - if (_eof1 && _eof2 && _controlla) - { - controlla_conto(_eof3,_eof4); - - if ( _eof3 && _eof4 && (!_seconda_volta) && _flag ) - if (!_salto_pagina1) - { - if (!_tmp_saldi_conti_uno->empty() || !_tmp_saldi_conti_due->empty()) - { - printer().formfeed(); - set_row(_i++,"@59gCONTI D'ORDINE"); - set_row(_i++,"@59g--------------"); - set_row(_i++, (const char*)dep); - if (_eof5 && _eof6) - { - _stampato = TRUE; - //stampa_totali(); - stampa_totali_uno(_prg_inidare_ord,_prg_iniavere_ord); - } - } - _salto_pagina1 = TRUE; - } - - if (_eof3 && _eof4 && _flag) - { - if (!_tmp_saldi_conti_uno->empty() || !_tmp_saldi_conti_due->empty()) - { - controlla_conto(_eof5,_eof6); - if (_eof5 && _eof6) - if (!_stampato) - //stampa_totali(); - stampa_totali_uno(_prg_inidare_ord,_prg_iniavere_ord); - } - } - } - } - else //stampa bilancio di verifica - { - TString udata = _ultima_data.string(brief,'/'); - char app; - int r = 1; - - if (_verifica == 3) - { - if (_buff != NULL) - { - *_d = (const char*) _descr; - if (_saldofinale > 0) - app = 'D'; - else if (_saldofinale < 0) - { - _saldofinale = -_saldofinale; - app = 'A'; - } - if ( (_ordinamento == 2 && _descr == "zzzz") || - (_ordinamento == 1 && _sottoconto == 999999L) ) //devo stampare il conto - { - _descr = DescrizioneConto(_gruppo,_conto,0L,' '); - stampa_record_conto(_gruppo,_conto,_descr,_saldo_dare,_saldo_avere, - _mov_dare,_mov_avere,_saldofinale,app); - } - else - if (_stampa_width == 132) - { - set_row(r,"@1g%6ld",(const char*)_sottoconto); - set_row(r," %s",(const char*)udata); - set_row(r,"@18g#a@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c",_d,&_saldo_dare, - &_saldo_avere,&_mov_dare,&_mov_avere,&_saldofinale,app); - if (_descr.len() > 30) - set_row(++r, "@49g!@82g!@114g!"); - } - else if (app == 'D') - { - set_row(r,"@1g%6ld",(const char*)_sottoconto); - set_row(r," %s",(const char*)udata); - set_row(r,"@18g#a@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!",_d, - &_saldo_dare,&_saldo_avere,&_mov_dare,&_mov_avere,&_saldofinale); - if (_descr.len() > 30) - set_row(++r, "@49g!@82g!@115g!@148g!"); - } - else - { - set_row(r,"@1g%6ld",(const char*)_sottoconto); - set_row(r," %s",(const char*)udata); - set_row(r,"@18g#a@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!", - _d,&_saldo_dare,&_saldo_avere,&_mov_dare,&_mov_avere,&_saldofinale); - if (_descr.len() > 30) - set_row(++r, "@49g!@82g!@115g!@148g!"); - } - } - } - else //_verifica != 3 - { - if (!_eof1) - { - if (_saldofinale_succ > 0) - app = 'D'; - else if (_saldofinale_succ < 0) - { - _saldofinale_succ = -_saldofinale_succ; - app = 'A'; - } - - if (_livello_conto) //sto stampando un conto/gruppo - r = stampa_record_conto(_gruppo_succ,_conto_succ,_descr_succ, - _saldoini_dare_succ,_saldoini_avere_succ,_mov_dare_succ, - _mov_avere_succ,_saldofinale_succ,app); - - else //sto stampando un sottoconto/conto - { - if (_verifica == 2) - { - if (_stampa_width == 132) - { - set_row(r,"%3d",_conto_succ); - set_row(r," @8g%-.40s@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c", - (const char*)_descr_succ,&_saldoini_dare_succ,&_saldoini_avere_succ, - &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ,app); - } - else if (app == 'D') - { - set_row(r,"%3d",_conto_succ); - set_row(r," @8g%-.40s@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!", - (const char*)_descr_succ,&_saldoini_dare_succ,&_saldoini_avere_succ, - &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); - } - else - { - set_row(r,"%3d",_conto_succ); - set_row(r," @8g%-.40s@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!", - (const char*)_descr_succ,&_saldoini_dare_succ,&_saldoini_avere_succ, - &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); - } - } // _verifica != 2 - else - { - *_d = (const char*) _descr_succ; - - if (_stampa_width == 132) - { - set_row(r,"@1g%6ld",(const char*)_sottoconto_succ); - set_row(r," %s",(const char*)udata); - set_row(r,"@18g#a@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c", - _d,&_saldoini_dare_succ,&_saldoini_avere_succ, - &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ,app); - if (_descr_succ.len() > 30) - set_row(++r, "@49g!@82g!@114g!"); - } - else if (app == 'D') - { - set_row(r,"@1g%6ld",(const char*)_sottoconto_succ); - set_row(r," %s",(const char*)udata); - set_row(r,"@18g#a@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!", - _d,&_saldoini_dare_succ,&_saldoini_avere_succ, - &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); - if (_descr_succ.len() > 30) - set_row(++r, "@49g!@82g!@115g!@148g!"); - } - else - { - set_row(r,"@1g%6ld",(const char*)_sottoconto_succ); - set_row(r," %s",(const char*)udata); - set_row(r,"@18g#a@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!", - _d,&_saldoini_dare_succ,&_saldoini_avere_succ, - &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); - if (_descr_succ.len() > 30) - set_row(++r, "@49g!@82g!@115g!@148g!"); - } - } - } - } - else - { - if (_saldofinale > 0) - app = 'D'; - else if (_saldofinale < 0) - { - app = 'A'; - _saldofinale = -_saldofinale; - } - r = stampa_record_conto(_gruppo,_conto,_descr,_saldoini_dare, - _saldoini_avere,_mov_dare,_mov_avere,_saldofinale,app);//per stampare l'ultimo conto - - stampa_riga_totali(r); - } - } - } -} - -int CG1500_application::stampa_record_conto(int g,int c,const TString& d, - const real& r1,const real& r2,const real& r3,const real& r4,const real& r5, - const char app) -{ - TString dep = ""; - int r = 1; - - if (_stampa_width == 148) - { - set_row(r,"@49g!@82g!@115g!",(const char*)dep); //stampo una riga vuota - set_row(r,"@148g!",(const char*)dep); - } - else - set_row(r,"@49g!@82g!@114g!",(const char*)dep); //stampo una riga vuota - r++; - if (_verifica == 2) - { - if (_stampa_width == 132) - { - // set_row(r++,"%3d-@8g%s@49g|@50g%r@67g%r@82g|@83g%r@100g%r@115g|@116g%r%s",g,d,&r1,&r2,&r3,&r4,&r5,(const char*)app); - set_row(r,"%3d-",g); - set_row(r,"@8g%-.40s",(const char*)d); - set_row(r++,"@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c",&r1,&r2,&r3,&r4,&r5,app); - } - else - if (app == 'D') - { - // set_row(r++,"%3d-@8g%s@49g|@50g%r@67g%r@82g|@83g%r@100g%r@115g|@116g%r@148g|",g,d,&r1,&r2,&r3,&r4,&r5); - set_row(r,"%3d-",g); - set_row(r,"@8g%-.40s",(const char*)d); - set_row(r++,"@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!",&r1,&r2,&r3,&r4,&r5); - } - else - { - // set_row(r++,"%3d-@8g%s@49g|@50g%r@67g%r@82g|@83g%r@100g%r@115g|@132g%r@148g|",g,d,&r1,&r2,&r3,&r4,&r5); - set_row(r,"%3d-",g); - set_row(r,"@8g%-.40s",(const char*)d); - set_row(r++,"@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!",&r1,&r2,&r3,&r4,&r5); - } - } - else - { - *_d = (const char*) d; - - if (_stampa_width == 132) - { - // set_row(r++,"%3d-%3d ********@18g%s@49g|@50g%r@67g%r@82g|@83g%r@100g%r@115g|@116g%r%s",g,c,d,&r1,&r2,&r3,&r4,&r5,(const char*)app); - set_row(r,"%3d-",g); - set_row(r,"%3d ********",c); - set_row(r,"@18g#a",_d); - set_row(r++,"@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c",&r1,&r2,&r3,&r4,&r5,app); - if (d.len() > 30) - set_row(r+1, "@49g!@82g!@114g!"); - } - else if (app == 'D') - { - // set_row(r++,"%3d-%3d ********@18g%s@49g|@50g%r@67g%r@82g|@83g%r@100g%r@115g|@116g%r@148g|",g,c,d,&r1,&r2,&r3,&r4,&r5); - set_row(r,"%3d-",g); - set_row(r,"%3d ********",c); - set_row(r,"@18g#a",_d); - set_row(r++,"@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!",&r1,&r2,&r3,&r4,&r5); - if (d.len() > 30) - set_row(r+1, "@49g!@82g!@115g!@148g!"); - } - else - { - // set_row(r++,"%3d-%3d ********@18g%s@49g|@50g%r@67g%r@82g|@83g%r@100g%r@115g|@132g%r@148g|",g,c,d,&r1,&r2,&r3,&r4,&r5); - set_row(r,"%3d-",g); - set_row(r,"%3d ********",c); - set_row(r,"@18g#a",_d); - set_row(r++,"@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!",&r1,&r2,&r3,&r4,&r5); - if (d.len() > 30) - set_row(r+1, "@49g!@82g!@115g!@148g!"); - } - } - if (_stampa_width == 148) - { - set_row(r,"@49g!@82g!@115g!",(const char*)dep); - set_row(r,"@148g!",(const char*)dep); - } - else - set_row(r,"@49g!@82g!@114g!",(const char*)dep); - r++; - if (_stampa_width == 148) - { - set_row(r,"@49g!@82g!@115g!",(const char*)dep); - set_row(r,"@148g!",(const char*)dep); - } - else - set_row(r,"@49g!@82g!@114g!",(const char*)dep); - r++; - - if (app == 'D') - _saldo_finale_tot += r5; - else _saldo_finale_tot -= r5; - - _saldo_dare_tot += r1; - _saldo_avere_tot += r2; - _mov_dare_tot += r3; - _mov_avere_tot += r4; - - return r; -} - -void CG1500_application::stampa_riga_totali(int r) -{ - TString dep = ""; - char app = ' '; - - if (_saldo_finale_tot > 0) - app = 'D'; - else if (_saldo_finale_tot < 0) - { - _saldo_finale_tot = -_saldo_finale_tot; - app = 'A'; - } - - if (_datada == _dataini) //colonna saldo iniziale - { - real r = _saldo_dare_tot - _saldo_avere_tot; - if (r > ZERO) - { - _saldo_dare_tot = r; - _saldo_avere_tot = ZERO; - } - else - { - _saldo_avere_tot = -r; - _saldo_dare_tot = ZERO; - } - /* - if (_tipo_stampa1 == 1) - _nuovo_tot_saldo_a = -_nuovo_tot_saldo_a; - */ - } - if (_stampa_width == 148) - { - set_row(r,"@49g!@82g!@115g!",(const char*)dep); - set_row(r,"@148g!",(const char*)dep); - } - else - set_row(r,"@49g!@82g!@114g!",(const char*)dep); - r++; - if (_verifica == 2) - { - if (_stampa_width == 132) - set_row(r,"***@8gTOTALE GENERALE@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c",&_saldo_dare_tot,&_saldo_avere_tot,&_mov_dare_tot, - &_mov_avere_tot,&_saldo_finale_tot,app); - else if (app == 'D') - set_row(r,"***@8gTOTALE GENERALE@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!",&_saldo_dare_tot,&_saldo_avere_tot, - &_mov_dare_tot,&_mov_avere_tot,&_saldo_finale_tot); - else - set_row(r,"***@8gTOTALE GENERALE@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!",&_saldo_dare_tot,&_saldo_avere_tot, - &_mov_dare_tot,&_mov_avere_tot,&_saldo_finale_tot); - } - else - { - if (_stampa_width == 132) - { - set_row(r++,"@1g****** ********@18gTOTALE GENERALE@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c",&_saldo_dare_tot,&_saldo_avere_tot, - &_mov_dare_tot,&_mov_avere_tot,&_saldo_finale_tot,app); - if ((_tipo_stampa1 == 1 && _datada == _dataini) || _tipo_stampa1 == 2) - set_row(r,"@1g****** ********@18gTOTALE CON SALDI INIZIALI@49g!@82g!@83g%r@99g%r@114g!",&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a); - } - else - { - if (app == 'D') - set_row(r++,"@1g****** ********@18gTOTALE GENERALE@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!",&_saldo_dare_tot, - &_saldo_avere_tot,&_mov_dare_tot,&_mov_avere_tot, - &_saldo_finale_tot); - else - set_row(r++,"@1g****** ********@18gTOTALE GENERALE@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!",&_saldo_dare_tot, - &_saldo_avere_tot,&_mov_dare_tot,&_mov_avere_tot, - &_saldo_finale_tot); - if ((_tipo_stampa1 == 1 && _datada == _dataini) || _tipo_stampa1 == 2) - set_row(r,"@1g****** ********@18gTOTALE CON SALDI INIZIALI@49g!@82g!@83g%r@100g%r@115g!@148g!",&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a); - } - } -} - -void CG1500_application::stampa_totali() -{ - TString dep = ""; - real pareggio; - real sbilancio = _tot_dare - _tot_avere; - if (sbilancio > ZERO) //_tot_dare > _tot_avere - pareggio = _tot_avere + sbilancio; - else - { - sbilancio = -sbilancio; - pareggio = _tot_dare + sbilancio; - } - if (_prima_volta) //ho finito di stampare le attivita'/passivita' - _prima_volta = FALSE; - else - _seconda_volta = FALSE; - _gc_prec_dare = _gc_corr_avere = ""; - _cambiato_conto_1 = TRUE; - _cambiato_conto_2 = TRUE; - - set_row(_i++, (const char*)dep); - set_row(_i++, (const char*)dep); - set_row(_i++, (const char*)dep); - set_row(_i++, (const char*)dep); - set_row(_i++, "@39gTOTALE@49g%r@107gTOTALE@117g%r", - &_tot_dare, &_tot_avere); - if (_tot_dare > _tot_avere) - { - set_row(_i++, "@85gSBILANCIO ESERCIZIO IN CORSO@117g%r", - &sbilancio); - set_row(_i++, "@96gTOTALE A PAREGGIO@117g%r",&pareggio); - } - if (_tot_dare < _tot_avere) - { - set_row(_i++, "@17gSBILANCIO ESERCIZIO IN CORSO@49g%r", - &sbilancio); - set_row(_i++, "@28gTOTALE A PAREGGIO@49g%r", &pareggio); - } - _tot_dare = ZERO; - _tot_avere = ZERO; -} - -//per i conti patrimoniali stampo anche lo sbilancio es. precedente -void CG1500_application::stampa_totali_uno(const real& r1,const real& r2) -{ - TString dep = ""; - real pareggio; - real sbilancio = _tot_dare - r1 - (_tot_avere - r2); - real sbilprec = r2 - r1; - /* - if (sbilancio > ZERO) //ho un utile => va stampato tra le passivita' - { - sbilprec = -sbilprec; - pareggio = _tot_avere + sbilancio + sbilprec; - } - else if (sbilancio < ZERO) //ho una perdita => va stampato tra le attivita' cambiato di segno - { - sbilancio = -sbilancio; - pareggio = _tot_dare + sbilancio + sbilprec; - } - */ - if (_prima_volta) //ho finito di stampare le attivita'/passivita' - _prima_volta = FALSE; - else - _seconda_volta = FALSE; - _gc_prec_dare = _gc_corr_avere = ""; - _cambiato_conto_1 = TRUE; - _cambiato_conto_2 = TRUE; - - set_row(_i++, (const char*)dep); - set_row(_i++, (const char*)dep); - set_row(_i++, (const char*)dep); - set_row(_i++, (const char*)dep); - set_row(_i++, "@39gTOTALE@49g%r@107gTOTALE@117g%r", - &_tot_dare, &_tot_avere); - if (sbilancio > ZERO) //ho un utile => va stampato tra le passivita' - { - sbilprec = -sbilprec; - pareggio = _tot_avere + sbilancio + sbilprec; - if (sbilprec != ZERO) - set_row(_i++, "@83gSBILANCIO ESERCIZIO PRECEDENTE@117g%r", - &sbilprec); - set_row(_i++, "@85gSBILANCIO ESERCIZIO IN CORSO@117g%r", - &sbilancio); - set_row(_i++, "@96gTOTALE A PAREGGIO@117g%r",&pareggio); - } - else if (sbilancio < ZERO) //ho una perdita => va stampato tra le attivita' - { - sbilancio = -sbilancio; - pareggio = _tot_dare + sbilancio + sbilprec; - if (sbilprec != ZERO) - set_row(_i++, "@15gSBILANCIO ESERCIZIO PRECEDENTE@49g%r", - &sbilprec); - set_row(_i++, "@17gSBILANCIO ESERCIZIO IN CORSO@49g%r", - &sbilancio); - set_row(_i++, "@28gTOTALE A PAREGGIO@49g%r", &pareggio); - } - else //sbilancio es. in corso == 0 - { - sbilprec = -sbilprec; - if (sbilprec > ZERO) //va stampato sotto le passivita' - { - pareggio = _tot_avere + sbilprec; - set_row(_i++, "@83gSBILANCIO ESERCIZIO PRECEDENTE@117g%r", - &sbilprec); - set_row(_i++, "@96gTOTALE A PAREGGIO@117g%r", &pareggio); - } - else if (sbilprec < ZERO) - { - sbilprec = -sbilprec; - pareggio = _tot_dare + sbilprec; - set_row(_i++, "@15gSBILANCIO ESERCIZIO PRECEDENTE@49g%r", - &sbilprec); - set_row(_i++, "@28gTOTALE A PAREGGIO@49g%r",&pareggio); - } - } - _tot_dare = ZERO; - _tot_avere = ZERO; -} - -void CG1500_application::stampa_prima_colonna(int g, int c, long s, - const char* desc, const real& saldo) -{ - char dep = '*'; - - if (_codici) //sono stampate solo le descrizioni dei conti - { - if (!_totali) - { - if (c != 0 && s == 0) - set_row(_i, "%-.44s @44g *** @49g%r @66g%c", desc, &saldo, dep); - else set_row(_i, "%-.48s @49g%r @66g%c", desc, &saldo, dep); - } - else if ( !(c == 0 && s == 0) ) //se cioe' non e' un gruppo - { - if (s == 0) //se e' un conto - set_row(_i, "%-.44s @44g *** @49g%r @66g%c", desc, &saldo, dep); -else set_row(_i, "%-.48s @49g%r @66g%c", desc, &saldo, dep); - } - } -else -{ - if (_totali && c == 0 && s == 0l) - return; - else if ( c == 0 && s == 0l ) - { - set_row(_i, "%3d ", g); - set_row(_i, "@17g%-.31s @49g%r @66g%c", desc, &saldo, dep); - } - else if (s == 0l) - { - set_row(_i, "%3d ", g); - set_row(_i, "%3d ", c); - set_row(_i, "@17g%-.31s @49g%r @66g%c", desc, &saldo, dep); - } - else - { - set_row(_i, "%3d ", g); - set_row(_i, "%3d ", c); - set_row(_i, "%6ld ", s); - set_row(_i, "@17g%-.31s @49g%r @66g%c", desc, &saldo, dep); - } -} -} - -void CG1500_application::stampa_seconda_colonna(int g, int c, long s, -const char* desc, const real& saldo) -{ - char dep = '*'; - - if (_codici) //sono stampate solo le descrizioni dei conti - { - if (!_totali) - { - if (c != 0 && s == 0) - set_row(_i, "@66g%c@69g%-.43s @112g ***@117g%r", dep, desc, &saldo); - else set_row(_i, "@66g%c@69g%-.47s @117g%r", dep, desc, &saldo); - } - else if ( !(c == 0 && s == 0) ) - { - if (s == 0) //se e' un conto - set_row(_i, "@66g%c @69g%-.43s @112g *** @117g%r", dep, desc, &saldo); -else set_row(_i, "@66g%c @69g%-.47s @117g%r", dep, desc, &saldo); - } - } -else -{ - if (_totali && c == 0 && s == 0l) - return; - else if ( c == 0 && s == 0l ) - { - set_row(_i, "@66g%c@69g%3d ", dep, g); - set_row(_i, "@86g%-.30s @117g%r", desc, &saldo); - } - else if (s == 0l) - { - set_row(_i, "@66g%c@69g%3d ", dep, g); - set_row(_i, "%3d", c); - set_row(_i, "@86g%-.30s @117g%r", desc, &saldo); - } - else - { - set_row(_i, "@66g%c@69g%3d ", dep, g); - set_row(_i, "%3d ", c); - set_row(_i, "%6ld ",s); - set_row(_i, "@86g%-.30s @117g%r", desc, &saldo); - } -} -} - -print_action CG1500_application::postprocess_page(int file, int counter) -{ - if (_bilancio == 1) - { - if ( _eof1 && _eof2 && _eof3 && _eof4 && _eof5 && _eof6 && _salto_pagina1 ) - return NEXT_PAGE; - } - else //bilancio di verifica - { - if (_verifica == 3) - { - if (_buff == NULL) - return NEXT_PAGE; - } - else if (_eof1) - return NEXT_PAGE; - } - return REPEAT_PAGE; -} - -TDate CG1500_application::UltimaData(int g, int c, long s, int anno) -{ - TDate uldata; - TLocalisamfile saldi(LF_SALDI, FALSE); //il parametro a false permette di usare un record corrente del file saldi differente a quello del file tmp - - saldi.zero(); - if (_annoes != 0) - saldi.put(SLD_ANNOES, anno); - saldi.put(SLD_GRUPPO,g); - if (c != 0) - saldi.put(SLD_CONTO, c); - if (s != 0) - saldi.put(SLD_SOTTOCONTO, s); - saldi.read(); - if (saldi.bad()) - saldi.zero(); - uldata = saldi.get(SLD_DATAULMOV); - - return uldata; -} - -//Non ho potuto usare quella di TConto!!! Chiedere a me! -const char* CG1500_application::DescrizioneConto(int g, int c, long s, - char tipocf) -{ - TString80 ragsoc; - const char* desc = NULL; - TLocalisamfile pconti(LF_PCON,FALSE); - TLocalisamfile clifo (LF_CLIFO); - - pconti.zero(); - pconti.put(PCN_GRUPPO, g); - if (c != 0) - pconti.put(PCN_CONTO, c); - if (s != 0) - pconti.put(PCN_SOTTOCONTO, s); - pconti.read(); - if (pconti.good()) - tmp = pconti.get(PCN_DESCR); - else - { - clifo.setkey(1); //occorre settare la chiave 1, anche se di solito e' di default, poiche' nella create il file clifo e' stato aperto con la chiave 3 - clifo.zero(); - clifo.put(CLI_CODCF, s); - clifo.put(CLI_TIPOCF,tipocf); - if (clifo.read() == NOERR) - { - char tipoa = clifo.get_char("TIPOAPER"); - if (tipoa == 'F') //persona fisica - { - TString80 cognome, nome; - ragsoc = clifo.get("RAGSOC"); - cognome = ragsoc.mid(0,30); - nome = ragsoc.mid(30,20); - cognome.trim(); nome.trim(); - ragsoc = cognome; - ragsoc << " " << nome; - desc = ragsoc; - } - else - desc = clifo.get("RAGSOC"); - tmp = desc; - } - else - tmp = ""; - } - return tmp; -} - -bool CG1500_application::user_create() -{ - _stampa_width = 132; - _rel = new TRelation(LF_CLIFO); - _cur = new TCursor (_rel,"",3); - _mov = new TLocalisamfile(LF_MOV); - _rmov = new TLocalisamfile(LF_RMOV); - _clifo = new TLocalisamfile(LF_CLIFO); - _com = new TLocalisamfile(LF_COMUNI); - _pcn = new TLocalisamfile(LF_PCON); - _saldi = new TLocalisamfile(LF_SALDI); - _nditte = new TLocalisamfile(LF_NDITTE); - _anag = new TLocalisamfile(LF_ANAG); - _caus = new TLocalisamfile(LF_CAUSALI); - _esc = new TTable("ESC"); - _d = new TParagraph_string("",30); - _tmp_saldi_att = NULL; - _tmp_saldi_pass = NULL; - _tmp_saldi_costi = NULL; - _tmp_saldi_ricavi = NULL; - _tmp_saldi_conti_uno = NULL; - _tmp_saldi_conti_due = NULL; - return TRUE; -} - -bool CG1500_application::user_destroy() -{ - delete _rel; - delete _cur; - delete _com; - delete _pcn; - delete _mov; - delete _rmov; - delete _clifo; - delete _saldi; - delete _nditte; - delete _anag; - delete _caus; - delete _esc; - delete _d; - - if (_tmp_saldi_att) delete _tmp_saldi_att; - if (_tmp_saldi_pass) delete _tmp_saldi_pass; - if (_tmp_saldi_costi) delete _tmp_saldi_costi; - if (_tmp_saldi_ricavi) delete _tmp_saldi_ricavi; - if (_tmp_saldi_conti_uno) delete _tmp_saldi_conti_uno; - if (_tmp_saldi_conti_due) delete _tmp_saldi_conti_due; - return TRUE; -} - -void CG1500_application::leggi_pcon() -{ - TLocalisamfile pconti(LF_PCON); - TToken_string gc(10); - - for (pconti.first(); !pconti.eof(); pconti.next()) - { - gc.restart(); - int gruppo = pconti.get_int(PCN_GRUPPO); - int conto = pconti.get_int(PCN_CONTO); - long sottoconto = pconti.get_long(PCN_SOTTOCONTO); - if ( (sottoconto == 0l) && (conto != 0) ) //si tratta di un conto - { - char tipocf = pconti.get_char(PCN_TMCF); - if (tipocf == 'C') - { - gc.add(gruppo,0); - gc.add(conto,1); - _clienti.add(gc); - } - else if (tipocf == 'F') - { - gc.add(gruppo,0); - gc.add(conto,1); - _fornitori.add(gc); - } - } - } -} - -bool CG1500_application::set_print(int) -{ - TMask m ("cg1500a"); - KEY tasto; - /* - { - TConfig conf(CONFIG_DITTA); - - _causale_ap = conf.get("CoCaAp"); - _causale_chi = conf.get("CoCaCh"); - } - */ - m.set_handler (F_VERIFICA, my_handler); - m.set_handler (F_BILANCIO, mask_bilancio); - m.set_handler (F_STAMPA1, mask_bilancio); - m.set_handler (F_STAMPA, mask_bilancio); - m.set_handler (F_DATALIM, mask_datalim); - m.set_handler (F_DATADA, mask_date); - m.set_handler (F_DATAA, mask_date); - m.set_handler (F_ANNO, mask_anno); - - tasto = m.run(); - if (tasto == K_ENTER) - { - _annoes = atoi(m.get(F_ANNO)); - _bilancio = atoi(m.get(F_BILANCIO)); - _data = m.get(F_DATASTAMPA); - _stampa_mov_prov = m.get_int(F_STAMPAMPROV); - if (_bilancio == 1) - { - _prog = new TProgind(_pcn->items(),"Elaborazione in corso... prego attendere",FALSE); - _totali = (bool)(m.get(F_TOTALI) == "X"); - _codici = (bool)(m.get(F_CODICI) == "X"); - _saldo = (bool)(m.get(F_SALDO) == "X"); - _tipo_stampa = atoi(m.get(F_STAMPA)); - if (_tipo_stampa == 1) - { - if (_annoes != 0) - _dataini = InizioEsercizio(_annoes); - else _dataini = _inizioEs; - _datalim = m.get(F_DATALIM); - //_stampa_mov_prov = (bool)(m.get(F_STAMPAMPROV) == "X"); - } - bil_sez_contr(); - } - else - { - _stampa_width = atoi(m.get(F_MODULO)); - if (_stampa_width == 1) - _stampa_width = 132; - else _stampa_width = 148; //perche' questo e' in realta' il margine dx (vedi es. di stampa AS/400) - _verifica = atoi(m.get(F_VERIFICA)); - if ( (_verifica == 1)||(_verifica == 2) ) - _prog = new TProgind(_pcn->items(),"Elaborazione in corso... prego attendere",FALSE); - _tipo_stampa1 = atoi(m.get(F_STAMPA1)); - if (_tipo_stampa1 == 1) - { - if (_annoes != 0) - _dataini = InizioEsercizio(_annoes); - else _dataini = _inizioEs; - _datada = m.get(F_DATADA); - _dataa = m.get(F_DATAA); - //_stampa_mov_prov = (bool)(m.get(F_STAMPAMPROV) == "X"); - } - if ( (_verifica == 1)||(_verifica == 2) ) - { - _stampav = atoi(m.get(F_STAMPAV)); - bil_verifica(); - } - else - { - _situazione = m.get(F_SITUAZIONE); - _stampac = atoi(m.get(F_STAMPAC)); - _ordinamento = atoi(m.get(F_ORDINAMENTO)); - - // _cur->setkey(3); - - if (_situazione.not_empty()) - _cur->setfilter(format("TIPOCF = \"%s\"",(const char*)_situazione)); - else - _cur->setfilter(""); - - _prog = new TProgind(_cur->items(),"Elaborazione in corso... prego attendere",FALSE); - - _clienti.destroy(); - _fornitori.destroy(); - leggi_pcon(); - crea_sort_clifo(); - _sort->endsort(); - delete _cf; - } - } - delete _prog; - return TRUE; - } - return FALSE; -} - -TRectype& look_com (const char * cod, TLocalisamfile *comuni) -{ - comuni->zero(); - comuni->put(COM_COM, cod); - comuni->read(); - if (comuni->bad()) - comuni->zero(); - - return comuni->curr(); -} - -void CG1500_application::get_dati_ditta() -{ - TLocalisamfile nditte(LF_NDITTE); - TLocalisamfile anag(LF_ANAG); - TString codanagr; - TString tipoa; - - nditte.zero(); - nditte.put(NDT_CODDITTA, get_firm()); - nditte.read(); - - if (nditte.bad()) nditte.zero(); - - codanagr = nditte.get(NDT_CODANAGR); - tipoa = nditte.get(NDT_TIPOA); - _ragsoc = nditte.get(NDT_RAGSOC); - - anag.setkey(1); - anag.zero(); - anag.put (ANA_TIPOA, tipoa); - anag.put (ANA_CODANAGR, codanagr); - anag.read(); - if (anag.bad()) anag.zero(); - - _cofi = anag.get(ANA_COFI); - _paiva = anag.get(ANA_PAIV); - _comunefis = anag.get(ANA_COMRF); - - if (_comunefis.empty()) - _comunefis = anag.get(ANA_COMRES); - - TRectype dep = look_com (_comunefis, _com); - - _comunefis = dep.get(COM_DENCOM); - _provfis = dep.get(COM_PROVCOM); - _cap = dep.get(COM_CAPCOM); - if (_comunefis.empty()) - { - _viafis = anag.get(ANA_INDRF); - _viafis.rtrim(); - _viafis << " " << anag.get (ANA_CIVRF); - } - else - { - _viafis = anag.get(ANA_INDRES); - _viafis.rtrim(); - _viafis << " " << anag.get (ANA_CIVRES); - } -} - -int CG1500_application::stampa_intestazione_ditta() -{ - int r = 1; - TString codice_ditta; - TString riga(_stampa_width); - //TString riga(132); - - get_dati_ditta(); - codice_ditta << get_firm(); - - set_header (r, "Ditta %s %s %s %s %s %s", (const char*)codice_ditta, - (const char*)_ragsoc, (const char*)_viafis, - (const char*)_cap, (const char*)_comunefis, - (const char*)_provfis); - r++; - printer().setdate(_data); - riga = "Data @< Pag. @#"; - riga.right_just(_stampa_width-5); - //riga.right_just(127); - riga.overwrite (format ("Partita iva %s Codice fiscale %s", (const char*)_paiva, (const char*)_cofi)); - set_header (r, "%s", (const char*) riga); - r++; - - return r; -} - -void CG1500_application::preprocess_header() -{ - int r; - - reset_header(); - r = stampa_intestazione_ditta(); - - if (_bilancio == 1) //bilancio a sezioni contrapposte - { - TString riga (132); - TDate data_da; - TString data; - TString data_lim = _datalim.string(); - - set_header(r, "STAMPA BILANCIO A SEZIONI CONTRAPPOSTE"); - if (_tipo_stampa == 1) - { - data_da = _dataini.string(); - data = _datalim.string(); - set_header(r,"@41gdalla data %s alla data %s", (const char*) data_da, - (const char*) data); - } - else if (_tipo_stampa == 2) - set_header(r,"@41gall'ultima immissione Es. %d", _annoes); - //else set_header(r, "@41gall'ultima immissione Es. Precedente"); - - //modifica del 20/04/1995 - set_header(r,"@85gAnno comp. %d", _annoes); - - r++; - riga.fill('-'); - set_header(r, (const char*)riga); - r++; - riga = ""; - set_header(r, (const char*)riga); - } - else // bilancio di verifica - { - TString riga (_stampa_width); - TString16 datada = _datada.string(); - TString16 dataa = _dataa.string(); - if (_verifica == 1) - set_header(r, "STAMPA BILANCIO DI VERIFICA"); - else if (_verifica == 2) - set_header(r, "STAMPA SALDI DI MASTRO"); - else - { - if (_situazione == "C") - set_header(r, "SITUAZIONE CONTABILE CLIENTI"); - else if (_situazione == "F") - set_header(r, "SITUAZIONE CONTABILE FORNITORI"); - else set_header(r,"SITUAZIONE CONTABILE CLIENTI E FORNITORI"); - } - - if (_tipo_stampa1 == 1) - { - set_header(r,"@42gdalla data %s alla data %s", (const char*)datada, - (const char*) dataa); - //modifica del 20/04/1995 - if (_annoes != 0) //se l'anno e' 0 non si considera la competenza - set_header(r,"@86gAnno comp. %d", _annoes); - } - else if (_tipo_stampa1 == 2) - { - set_header(r,"@42gall'ultima immissione Es. %d", _annoes); - //modifica del 20/04/1995 - set_header(r,"@86gAnno comp. %d", _annoes); - } - - if ( (_verifica == 1)||(_verifica == 2) ) - { - if (_stampav == 1) - set_header(r,"@103gTutti i conti movimentati"); - else if (_stampav == 2) - set_header(r,"@103gConti con saldo <> 0"); - else set_header(r,"@103gTutti i conti"); - } - else - { - if (_stampac == 1) - set_header(r,"@103gTutti i conti movimentati"); - else set_header(r,"@103gConti con saldo <> 0"); - } - - r++; - riga.fill('-'); - set_header(r, (const char*)riga); - r++; - - if ( ((_datada == _dataini)&&(_tipo_stampa1 == 1))||(_tipo_stampa1 != 1) ) - { - if ( (_verifica == 1)||(_verifica == 3) ) - set_header(r,"@7g!@16g!@49g!@58gSALDO INIZIALE@82g!@88gMOVIMENTI DEL PERIODO"); - else - set_header(r,"@7g!@49g!@58gSALDO INIZIALE@82g!@88gMOVIMENTI DEL PERIODO"); - } - else if (_tipo_stampa1 == 1) - if ( (_verifica == 1)||(_verifica == 3) ) - set_header(r,"@7g!@16g!@49g!@55gPROGRESSIVI PRECEDENTI@82g!@88gMOVIMENTI DEL PERIODO"); - else - set_header(r,"@7g!@49g!@55gPROGRESSIVI PRECEDENTI@82g!@88gMOVIMENTI DEL PERIODO"); - - if (_stampa_width == 148) - set_header(r,"@115g!@130gSALDO@148g!"); - else - set_header(r,"@114g!"); - r++; - - if ( (_verifica == 1)||(_verifica == 3) ) - { - if (_stampa_width == 132) - { - set_header(r++,"@2gcod. ! ultima !@49g!@50g%.32s@82g!@83g%.32s@114g!@121gSALDO",(const char*)riga, (const char*)riga); - set_header(r++,"@2gconto! data ! denominazione@49g!@57gDare@66g!@73gAvere@82g!@89gDare@98g!@104gAvere@114g!"); - } - else - { - set_header(r++,"@2gcod. ! ultima !@49g!@50g%.32s@82g!@83g%.32s@115g!%.32s@148g!",(const char*)riga, (const char*)riga, (const char*)riga); - set_header(r++,"@2gconto! data ! denominazione@49g!@57gDare@66g!@73gAvere@82g!@91gDare@99g!@106gAvere@115g!@124gDare@132g!@139gAvere@148g!"); - } - } - else - { - if (_stampa_width == 132) - { - set_header(r++,"@2gcod. !@49g!@50g%.32s@82g!@83g%.32s@114g!@121gSALDO",(const char*)riga, (const char*)riga); - set_header(r++,"@1gmastro!descrizione@49g!@57gDare@66g!@73gAvere@82g!@89gDare@98g!@104gAvere@114g!"); - } - else - { - set_header(r++,"@2gcod. !@49g!@50g%.32s@82g!@83g%.32s@115g!%.32s@148g!",(const char*)riga, (const char*)riga, (const char*)riga); - set_header(r++,"@1gmastro!descrizione@49g!@57gDare@66g!@73gAvere@82g!@91gDare@99g!@106gAvere@115g!@124gDare@132g!@139gAvere@148g!"); - } - } - set_header(r, (const char*)riga); - if (_stampa_width == 148) - set_header(r,"@148g!"); - } -} - -int cg1500 (int argc, char* argv[]) -{ - - CG1500_application a; - - a.run(argc, argv, "Stampa bilanci"); - - return 0; -} - -/* - if (!compensa) - { - if ( (indbil_conto==1)||(indbil_conto==3) ) - if (saldo > ZERO) //saldo in dare - _indbil = indbil_conto; - else //saldo in avere - { - if (indbil_conto == 1) - _indbil = 2; - else _indbil = 4; - saldo = -saldo; - } - if ( (indbil_conto==2)||(indbil_conto==4) ) - if (saldo < ZERO) - { - _indbil = indbil_conto; - saldo = -saldo; - } - else - if (indbil_conto == 2) - _indbil = 1; - else _indbil = 3; - } - else //e' richiesta la compensazione - { - if ( (indbil_conto==1)||(indbil_conto==3) ) - _indbil = indbil_conto; - if ( (indbil_conto==2)||(indbil_conto==4) ) - { - _indbil = indbil_conto; - saldo = -saldo; - } - } - */ +//Stampa bilanci + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cglib.h" +#include "cg1.h" +#include "cg1500.h" + +bool my_handler (TMask_field& f, KEY k); +bool mask_anno (TMask_field& f, KEY k); +bool mask_datalim (TMask_field& f, KEY k); +bool mask_date (TMask_field& f, KEY k); +bool mask_bilancio(TMask_field& f, KEY k); +bool mask_tipost (TMask_field& f, KEY k); + +HIDDEN int date2esc(const TDate& d, int* prevesc = NULL); + +class CG1500_application : public TPrintapp +{ + friend bool mask_anno (TMask_field& f, KEY k); + friend bool mask_datalim (TMask_field& f, KEY k); + friend bool my_handler (TMask_field& f, KEY k); + friend bool mask_date (TMask_field& f, KEY k); + friend bool mask_bilancio(TMask_field& f, KEY k); + friend bool mask_tipost (TMask_field& f, KEY k); + + struct cli_for + { + char tipocf; + char gruppo[4]; + char conto[4]; + char codcf[7]; + char ragsoc[51]; + real saldodare; + real saldoavere; + real movdare; + real movavere; + real saldofinale; + TDate udata; + }; + + cli_for* _cf; + TSort * _sort; + const char* _buff; + + TRelation* _rel; + TCursor * _cur; + TProgind * _prog; + TSaldi_list* _listacf, * _lista; + TLocalisamfile* _com, * _pcn, * _mov, * _rmov, * _clifo, * _saldi, * _nditte,* _anag,* _caus; + TIsamtempfile * _tmp_saldi_att, * _tmp_saldi_pass, * _tmp_saldi_conti_uno; + TIsamtempfile * _tmp_saldi_costi, * _tmp_saldi_ricavi,* _tmp_saldi_conti_due; + TTable* _esc; + TParagraph_string* _d; + + TString _cofi,_cap,_paiva,_ragsoc,_comunefis,_provfis,_viafis; + TString _descr_dare, _descr_avere, _gc_corr_dare, _gc_corr_avere, _descr; + TString _gc_prec_dare, _gc_prec_avere, _situazione, _descr_succ; + char _tipo_conto, _tipoc_succ; + + int _annoes, _bilancio, _tipo_stampa, _tipo_stampa1,_stampa_width,_gp,_cp,_i; + int _eof1, _eof2, _gruppo_dare, _gruppo_avere, _conto_dare, _conto_avere; + int _add_file_da, _add_file_a, _indbil_dare, _indbil_avere, _indbil; + int _eof3, _eof4, _eof5, _eof6, _verifica, _stampac, _stampav, _ordinamento; + int _gruppo, _conto, _gruppo_succ, _conto_succ, _annoapp; + long _sottoconto_dare, _sottoconto_avere, _sottoconto, _sottoconto_succ; + + real _saldo_dare, _saldo_avere, _gruppo_a, _gruppo_da, _conto_a; + real _conto_da, _tot_dare, _tot_avere, _mov_periodo_dare, _saldo_ini_dare; + real _mov_periodo_avere, _saldo_ini_avere, _prg_prec_dare, _prg_prec_avere; + real _saldo_ini_conto_dare, _saldo_ini_conto_avere, _saldoini_dare; + real _saldoini_avere, _mov_dare, _mov_avere, _saldofinale; + real _saldoini_dare_succ, _saldoini_avere_succ, _mov_dare_succ; + real _mov_avere_succ, _saldofinale_succ; + real _saldo_dare_tot, _saldo_avere_tot, _mov_dare_tot, _mov_avere_tot; + real _saldo_finale_tot, _saldo_ini_gruppo_dare, _saldo_ini_gruppo_avere; + real _gruppo_da_ordine, _gruppo_a_ordine; + real _prg_saldoini_dare, _prg_saldoini_avere, _prg_inidare_ord, _prg_iniavere_ord; + real _nuovo_tot_saldo_d, _nuovo_tot_saldo_a; + + TDate _datalim, _data, _datada, _dataa, _dataini, _ultima_data, _u_max; + bool _cambiato_conto_1, _cambiato_conto_2, _add_file_avere; + bool _add_file_dare, _prima_volta, _seconda_volta, _totali, _codici, _saldo; + bool _add_dare, _add_avere, _controlla, _salto_pagina, _flag, _stampato; + bool _sottoc_dare, _sottoc_avere, _salto_pagina1, _livello_conto; + int _stampa_mov_prov; + //TString _causale_ap, _causale_chi; + TArray _clienti, _fornitori; + +public: + + TDate _inizioEs, _fineEs; + bool menu (MENU_TAG m) { return TPrintapp::menu(m) ; } + virtual bool user_create() ; + virtual bool user_destroy(); + bool set_print(int); + + void next_c(); + virtual bool preprocess_print(int,int); + virtual void preprocess_header(); + virtual bool preprocess_page(int,int); + virtual print_action postprocess_page(int,int); + virtual void postclose_print(); + virtual void set_page(int,int); + real compensazione(bool compensa, int indbil_conto, real& saldo); + //const char* causale_chiusura() { return _causale_chi;} + //const char* causale_apertura() { return _causale_ap;} + bool bil_sez_contr(); + bool bil_verifica(); + bool ricerca_sottoc_clifo(int,int,bool,int,real&); + bool ricerca_cf(int,int,char,int,real&,real&,real&,real&,real&,real&,real&); + bool calcola(int,int,long); + void leggi_pcon(); // Inizializza i TArray C/F + void crea_sort_clifo(); + void init_sort(); + void leggi_sort(); + void riempi_record(char,int,int,long,const char*,const real&, + const real&,const real&,const real&,const real&); + void get_dati_ditta(); + void scrivi_record_conto(const real&,const real&,const real&, + const real&, const real&); + void scrivi_record_gruppo(const real&,const real&,const real&, + const real&, const real&); + int stampa_record_conto(int,int,const TString&,const real&,const real&, + const real&,const real&,const real&,const char); + int stampa_intestazione_ditta(); + int cerca_indbil(int,int); + void scrivig_file_temp(); + void scrivic_file_temp(); + void scrivis_file_temp(int,int,long,real); + void leggi_files_dare (TIsamtempfile*); + void leggi_files_avere(TIsamtempfile*); + void leggi_file_tmp(); + void stampa_riga_totali(int); + void stampa_prima_colonna(int,int,long,const char*,const real&); + void stampa_seconda_colonna(int,int,long,const char*,const real&); + void stampa_totali(); + void stampa_totali_uno(const real&, const real&); + void controlla_conto(int,int); + const char* DescrizioneConto(int,int,long,char); //chiama quella di TConto + TDate UltimaData(int,int,long,int); + + CG1500_application() {} +}; + +HIDDEN inline CG1500_application & app() { return (CG1500_application&) main_app(); } + +TDate InizioEsercizio(int anno) +{ + TTable TabEs ("ESC"); + TString16 codtab; + TDate inizio_es; + + TabEs.zero(); + codtab.format ("%04d", anno); + TabEs.put ("CODTAB", codtab); + TabEs.read(); + if (TabEs.good()) + inizio_es= TabEs.get_date ("D0"); + + return inizio_es; +} + +TDate FineEsercizio(int anno) +{ + TTable TabEs ("ESC"); + TString16 codtab; + TDate fine_es; + + TabEs.zero(); + codtab.format ("%04d", anno); + TabEs.put ("CODTAB", codtab); + TabEs.read(); + if (TabEs.good()) + fine_es= TabEs.get_date ("D1"); + + return fine_es; +} + +bool IsEsercizio (const TDate& datalim, int anno_eser) +{ + TTable TabEs ("ESC"); + TString16 codtab; + TDate inizio,fine; + + TabEs.zero(); + + codtab.format ("%04d", anno_eser); + TabEs.put ("CODTAB", codtab); + TabEs.read(); + if (TabEs.good()) + { + inizio = TabEs.get_date ("D0"); + fine = TabEs.get_date ("D1"); + } + if (datalim >= inizio && datalim <= fine) + return TRUE; + + return FALSE; +} + +HIDDEN int date2esc(const TDate& d, int* prevesc) +{ + if (prevesc) *prevesc = 0; + TTable esc("ESC"); + for (int err = esc.first(); err == NOERR; err = esc.next()) + { + const TDate ia(esc.get("D0")); // Data inizio esercizio + const TDate fa(esc.get("D1")); // Data fine esercizio + const anno = esc.get_int("CODTAB"); + app()._inizioEs = ia; + app()._fineEs = fa; + if (d >= ia && d <= fa) + return anno; + if (prevesc) *prevesc = anno; + } + return 0; +} + +bool mask_anno(TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + int tipo_stampa; + int anno = f.mask().get_int(F_ANNO); + int bilancio = f.mask().get_int(F_BILANCIO); + if (bilancio == 1) + tipo_stampa = f.mask().get_int(F_STAMPA); + else + tipo_stampa = f.mask().get_int(F_STAMPA1); + if (tipo_stampa == 2) + if (anno == 0) + { + f.error_box("Indicare l'anno di esercizio"); + return FALSE; + } + } + if ( k == K_TAB || f.focusdirty()) + { + int tipo_stampa; + int anno = f.mask().get_int(F_ANNO); + int bilancio = f.mask().get_int(F_BILANCIO); + if (bilancio == 1) + tipo_stampa = f.mask().get_int(F_STAMPA); + else + tipo_stampa = f.mask().get_int(F_STAMPA1); + + if ((bilancio == 2) && (tipo_stampa == 1)) + if (anno != 0) + { + f.mask().show(F_DATADA); + f.mask().show(F_DATAA); + //f.mask().show(F_STAMPAMPROV); + f.mask().show(96); + f.mask().show(97); + f.mask().hide(98); + f.mask().hide(99); + } + else + { + f.mask().show(F_DATADA); + f.mask().show(F_DATAA); + //f.mask().show(F_STAMPAMPROV); + f.mask().show(98); + f.mask().show(99); + f.mask().hide(96); + f.mask().hide(97); + } + } + return TRUE; +} + +bool mask_bilancio(TMask_field& f, KEY k) +{ + TMask& m = f.mask(); + + if (k == K_SPACE) + { + int tipo_stampa; + int anno = m.get_int(F_ANNO); + int bilancio = m.get_int(F_BILANCIO); + if (bilancio == 1) //bilancio a sezioni contrapposte + { + tipo_stampa = m.get_int(F_STAMPA); + m.disable_page(1); + } + else + { + tipo_stampa = m.get_int(F_STAMPA1); + m.enable_page(1); + } + if ( bilancio == 1 || bilancio ==2) + if (tipo_stampa == 2) //all'ultima immissione + { + m.hide(F_DATADA); + m.hide(F_DATAA); + //m.hide(F_STAMPAMPROV); + m.hide(98); + m.hide(99); + m.hide(96); + m.hide(97); + } +else +{ + if (bilancio == 2) + if (anno != 0) + { + m.show(F_DATADA); + m.show(F_DATAA); + //m.show(F_STAMPAMPROV); + m.show(96); + m.show(97); + m.hide(98); + m.hide(99); + } + else + { + m.show(F_DATADA); + m.show(F_DATAA); + //m.show(F_STAMPAMPROV); + m.show(98); + m.show(99); + m.hide(96); + m.hide(97); + } +} +} +return TRUE; +} + + +bool mask_datalim (TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + int anno = f.mask().get_int(F_ANNO); + int bilancio = f.mask().get_int(F_BILANCIO); + TDate datalim(f.mask().get(F_DATALIM)); + if (bilancio == 1) + if (anno != 0) + { + if ( datalim.ok() ) + { + if (!IsEsercizio(datalim,anno)) + { + f.error_box ("La data limite deve appartenere all'esercizio indicato"); + return FALSE; + } + } + else + f.mask().field(F_DATALIM).set(FineEsercizio(anno)); + } + else //anno == 0 + { + if (!datalim.ok()) + { + f.error_box ("La data limite e' obbligatoria"); + return FALSE; + } + long anno = date2esc(datalim); + if (anno == 0) + { + f.error_box ("La data limite deve appartenere ad un esercizio attivo della ditta"); + return FALSE; + } + f.mask().set(F_ANNO,anno); + } + } + return TRUE; +} + +bool mask_date(TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + const short id = f.dlg(); + int anno = f.mask().get_int(F_ANNO); + int bilancio = f.mask().get_int(F_BILANCIO); + if (bilancio == 2) + { + TDate data (f.mask().get(id)); + if (anno != 0) + { + if (data.ok()) + { + if (!IsEsercizio(data,anno)) + { + f.error_box( "La data indicata deve essere all'interno dell'esercizio"); + return FALSE; + } + } + if (!data.ok()) + { + if (id == F_DATADA) + f.mask().field(F_DATADA).set(InizioEsercizio(anno)); + else if (id == F_DATAA) + f.mask().field(F_DATAA).set(FineEsercizio(anno)); + } + app()._annoapp = anno; + } + else + { + if ( !data.ok() ) + { + f.error_box("Indicare una data appartenente ad un esercizio attivo della ditta"); + return FALSE; + } + else + { + //date2esc(datada); + //const TString16 ie(app()._inizioEs.string()); + //const TString16 fe(app()._fineEs.string()); + //if (datada < app()._inizioEs || dataa > app()._fineEs) + //{ + // f.error_box("Le date devono essere comprese tra %s e %s", + // (const char*)ie, (const char*)fe); + // return FALSE; + //} + if (id == F_DATAA) + { + TDate from (f.mask().get(id - 1)); + app()._annoapp = date2esc(from); + if ( app()._annoapp != date2esc(data) ) + { + f.error_box("Le date devono appartenere ad uno stesso esercizio attivo della ditta"); + return FALSE; + } + if (from > data) + { + f.error_box("La data limite inferiore non puo' essere maggiore della data limite superiore"); + return FALSE; + } + //f.mask().set(F_ANNO, anno); + } + } + } + } + } + return TRUE; +} + +bool my_handler (TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + int tipo_stampa = atoi(f.mask().get(F_STAMPA1)); + int verifica = atoi(f.mask().get(F_VERIFICA)); + if ( (tipo_stampa == 1) && ((verifica == 1) || (verifica == 2)) ) + { + f.mask().hide (F_SITUAZIONE); + f.mask().hide (F_STAMPAC); + f.mask().hide (F_ORDINAMENTO); + f.mask().show (F_STAMPAV); + f.mask().show (F_DATADA); + f.mask().show (F_DATAA); + //f.mask().show (F_STAMPAMPROV); + } + if ( (tipo_stampa == 1) && (verifica == 3) ) + { + f.mask().show (F_SITUAZIONE); + f.mask().show (F_STAMPAC); + f.mask().show (F_ORDINAMENTO); + f.mask().show (F_DATADA); + f.mask().show (F_DATAA); + f.mask().hide (F_STAMPAV); + //f.mask().show (F_STAMPAMPROV); + } + if ( (tipo_stampa == 2) && ((verifica == 1)||(verifica == 2)) ) + { + f.mask().hide (F_SITUAZIONE); + f.mask().hide (F_STAMPAC); + f.mask().hide (F_ORDINAMENTO); + f.mask().hide (F_DATADA); + f.mask().hide (F_DATAA); + //f.mask().hide (F_STAMPAMPROV); + f.mask().show (F_STAMPAV); + } + if ( (tipo_stampa == 2) && (verifica == 3) ) + { + f.mask().show (F_SITUAZIONE); + f.mask().show (F_STAMPAC); + f.mask().show (F_ORDINAMENTO); + f.mask().hide (F_DATADA); + f.mask().hide (F_DATAA); + //f.mask().hide (F_STAMPAMPROV); + f.mask().hide (F_STAMPAV); + } + } + return TRUE; +} + +void CG1500_application::scrivig_file_temp() +{ + TIsamtempfile* tmp = NULL; + TString nome_campo(12); + real valore; + + if (!_totali) + { + if (_add_dare) + { + nome_campo = SLD_PDARE; + valore = _gruppo_da; + switch (_indbil) + { + case 1: + case 2: + tmp = _tmp_saldi_att; + break; + case 3: + case 4: + tmp = _tmp_saldi_costi; + break; + case 5: + tmp = _tmp_saldi_conti_uno; + valore = _gruppo_da_ordine; + break; + default: + break; + } + + tmp->zero(); + tmp->put(SLD_GRUPPO,_gp); + if (tmp->read() == NOERR) + { + tmp->put(SLD_CONTO,0); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(nome_campo, valore); + tmp->rewrite(); + } + else + { + tmp->put(SLD_CONTO,0); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(nome_campo, valore); + tmp->write(); + } + } + if (_add_avere) + { + nome_campo = SLD_PAVERE; + valore = _gruppo_a; + switch (_indbil) + { + case 1: + case 2: + tmp = _tmp_saldi_pass; + break; + case 3: + case 4: + tmp = _tmp_saldi_ricavi; + break; + case 5: + tmp = _tmp_saldi_conti_due; + valore = _gruppo_a_ordine; + break; + default: + break; + } + + tmp->zero(); + tmp->put(SLD_GRUPPO,_gp); + if (tmp->read() == NOERR) + { + tmp->put(SLD_CONTO,0); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(nome_campo, valore); + tmp->rewrite(); + } + else + { + tmp->put(SLD_CONTO,0); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(nome_campo, valore); + tmp->write(); + } + } + } + _add_dare = _add_avere = FALSE; +} + +void CG1500_application::scrivic_file_temp() +{ + TIsamtempfile* tmp = NULL; + TString nome_campo(12); + real valore; + + if (_add_file_dare) + { + _add_dare = TRUE; + nome_campo = SLD_PDARE; + valore = _conto_da; + if (_indbil == 1 || _indbil==2) tmp = _tmp_saldi_att; // da stampare a sx + else + if (_indbil==3 || _indbil==4) tmp = _tmp_saldi_costi; //da stampare a sx + else + if (_indbil==5) tmp = _tmp_saldi_conti_uno; + else return; + tmp->zero(); + tmp->put(SLD_GRUPPO,_gp); + tmp->put(SLD_CONTO,_cp); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(nome_campo, valore); + tmp->write(); + } + if (_add_file_avere) + { + _add_avere = TRUE; + nome_campo = SLD_PAVERE; + valore = _conto_a; + if (_indbil==2 || _indbil==1) tmp = _tmp_saldi_pass; //da stampare a dx + else + if (_indbil==4 || _indbil==3) tmp = _tmp_saldi_ricavi;//da stampare a dx + else + if (_indbil==5) tmp = _tmp_saldi_conti_due; + else return; + tmp->zero(); + tmp->put(SLD_GRUPPO,_gp); + tmp->put(SLD_CONTO,_cp); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(nome_campo, valore); + tmp->write(); + } + /* + tmp->zero(); + tmp->put(SLD_GRUPPO,_gp); + tmp->put(SLD_CONTO,_cp); + tmp->put(SLD_SOTTOCONTO,0L); + tmp->put(nome_campo, valore); + tmp->write(); + */ +} + +void CG1500_application::scrivis_file_temp(int g, int c, long s, real saldo) +{ + TIsamtempfile* tmp = NULL; + TString16 nome_campo; + + if (_indbil==1) + { + tmp = _tmp_saldi_att; + nome_campo = SLD_PDARE; + } + else + if (_indbil==2) + { + tmp = _tmp_saldi_pass; + nome_campo = SLD_PAVERE; + } + else + if (_indbil==3) + { + tmp = _tmp_saldi_costi; + nome_campo = SLD_PDARE; + } + else + if (_indbil==4) + { + tmp = _tmp_saldi_ricavi; + nome_campo = SLD_PAVERE; + } + else + if (_sottoc_dare) + { + tmp = _tmp_saldi_conti_uno; + nome_campo = SLD_PDARE; + } + else + if (_sottoc_avere) + { + tmp = _tmp_saldi_conti_due; + nome_campo = SLD_PAVERE; + } + tmp->zero(); + tmp->put(SLD_GRUPPO,g); + tmp->put(SLD_CONTO,c); + tmp->put(SLD_SOTTOCONTO,s); + tmp->put(nome_campo, saldo); + tmp->write(); +} + +real CG1500_application::compensazione(bool compensa, int indbil_conto, real& sld) +{ + real saldo = sld; + + if (!compensa) + { + switch (indbil_conto) + { + case 1: + if (saldo > ZERO) + _indbil = indbil_conto; + else + { + _indbil = 2; + saldo = -saldo; + } + break; + + case 3: + if (saldo > ZERO) + _indbil = indbil_conto; + else + { + _indbil = 4; + saldo = -saldo; + } + break; + + case 2: + if (saldo < ZERO) + { + _indbil = indbil_conto; + saldo = -saldo; + } + else + _indbil = 1; + break; + + case 4: + if (saldo < ZERO) + { + _indbil = indbil_conto; + saldo = -saldo; + } + else + _indbil = 3; + break; + case 5: + default: break; + } + } + else //e' richiesta la compensazione + if ( indbil_conto==2 || indbil_conto==4) + saldo = -saldo; + + return saldo; +} + +void CG1500_application::next_c() +{ + TRecnotype recnum = _pcn->recno(); + _pcn->next(); + if (_pcn->eof()) + { + scrivic_file_temp(); + scrivig_file_temp(); + } + _pcn->readat(recnum); +} + +bool CG1500_application::bil_sez_contr() +{ + TSaldo sld; + int indbil_conto=0; + int g, c; + long s; + char tipo_conto = ' '; + real saldo; + bool compensa=FALSE, dettaglio=FALSE, cambiato=FALSE; + bool esiste_conto=FALSE, esiste_sc = FALSE; + bool movimentato = FALSE; + + CHECK(_tmp_saldi_att == NULL, "Non posso riaprire cg01"); + _tmp_saldi_att = new TIsamtempfile(LF_SALDI, "cg01", 2); + _prog->addstatus(1); + _tmp_saldi_pass = new TIsamtempfile(LF_SALDI, "cg02", 2); + _prog->addstatus(1); + _tmp_saldi_costi = new TIsamtempfile(LF_SALDI, "cg03", 2); + _prog->addstatus(1); + _tmp_saldi_ricavi = new TIsamtempfile(LF_SALDI, "cg04", 2); + _prog->addstatus(1); + _tmp_saldi_conti_uno = new TIsamtempfile(LF_SALDI, "cg05", 2); + _prog->addstatus(1); + _tmp_saldi_conti_due = new TIsamtempfile(LF_SALDI, "cg06", 2); + _prog->addstatus(1); + + _gp=-1; + _cp=-1; + _gruppo_a = ZERO; + _gruppo_da = ZERO; + _gruppo_da_ordine = ZERO; + _gruppo_a_ordine = ZERO; + _prg_saldoini_dare = ZERO; + _prg_saldoini_avere = ZERO; + _prg_inidare_ord = ZERO; + _prg_iniavere_ord = ZERO; + _conto_a = ZERO; + _conto_da = ZERO; + _add_dare = FALSE; + _add_avere = FALSE; + + sld.set_annoes(_annoes); + + for (_pcn->first(); !_pcn->eof(); _pcn->next()) + { + _prog->addstatus(1); + g = _pcn->get_int (PCN_GRUPPO); + c = _pcn->get_int (PCN_CONTO); + s = _pcn->get_long(PCN_SOTTOCONTO); + + if (c != _cp) + cambiato = TRUE; + + if ( (((_cp != -1) && (c != _cp)) || ((_gp != -1) && (g != _gp))) && + esiste_sc ) + { + scrivic_file_temp(); + scrivig_file_temp(); + _cp = c; + esiste_conto = TRUE; + _conto_da = ZERO; + _conto_a = ZERO; + } + + if ( ((_gp != -1) && (g != _gp)) && esiste_conto ) + { + scrivig_file_temp(); + esiste_conto = FALSE; + _gp = g; + _gruppo_da = ZERO; + _gruppo_a = ZERO; + _gruppo_da_ordine = ZERO; + _gruppo_a_ordine = ZERO; + } + + if (cambiato) + { + _add_file_avere = FALSE; + _add_file_dare = FALSE; + cambiato = FALSE; + } + + if ( (s == 0) && (c != 0) ) //si tratta di un conto + { + compensa = _pcn->get_bool(PCN_COMPENS); + indbil_conto = _pcn->get_int (PCN_INDBIL); + dettaglio = !_pcn->get_bool(PCN_STSOTTBIL); + tipo_conto = _pcn->get(PCN_TMCF)[0]; + if ( (tipo_conto == 'C') || (tipo_conto == 'F') ) + { + saldo = ZERO; + esiste_sc = ricerca_sottoc_clifo(g, c, compensa, + indbil_conto, saldo); + if (esiste_sc) + { + _gp = g; + _cp = c; + } + TRecnotype recnum = _pcn->recno(); + _pcn->next(); + if (_pcn->eof()) + { + if (esiste_sc) + { + scrivic_file_temp(); + scrivig_file_temp(); + } + else if (esiste_conto) + scrivig_file_temp(); + } + _pcn->readat(recnum); + + continue; + } + } + + if ( (c == 0) || (s == 0) ) //si tratta di un conto o di un gruppo + { + esiste_sc = FALSE; + continue; + } + + if (_tipo_stampa == 1) //bil. a sez. contrapposte per data limite + movimentato = sld.data_limite_bilancio(_bilancio,g,c,s,_dataini,_datalim,indbil_conto,_stampa_mov_prov); + else + if (_tipo_stampa == 2) //bil. a sez. contrapposte all'ultima immissione es. in corso + movimentato = sld.ultima_immissione_bilancio(_annoes,g,c,s,indbil_conto,_stampa_mov_prov); + + if (!movimentato) + if (!sld.esiste_saldo() || !sld.significativo()) + { + next_c(); + continue; + } + + saldo = sld.saldo(); + real app = sld.saldoini(); + bool flag = sld.flagprec(); + + if (_saldo) //se richiesto di NON stampare i conti con saldo a zero + if (saldo == ZERO) + { + //modifica del 06/07/1995 + if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) + { + //real app = sld.saldoini(); + //bool flag = sld.flagprec(); + if (flag) + { + if (app > ZERO) + { + if (indbil_conto == 5) + _prg_inidare_ord += app; + else _prg_saldoini_dare += app; + } + else if (app < ZERO) + { + app = -app; + if (indbil_conto == 5) + _prg_iniavere_ord += app; + else _prg_saldoini_avere += app; + } + } + } + //fine + next_c(); + continue; + } + + esiste_sc = TRUE; + _indbil = indbil_conto; + + //i due flag seguenti servono solo per i conti d'ordine + _sottoc_dare = FALSE; + _sottoc_avere = FALSE; + + //error_box ("saldo = %s", saldo.string()); + + if (saldo != ZERO) + saldo = compensazione(compensa, indbil_conto, saldo); + + if (_indbil == 1 || _indbil == 2) + { + //real app = sld.saldoini(); + //bool flag = sld.flagprec(); + if (flag) + { + if (app > ZERO) + _prg_saldoini_dare += app; + else if (app < ZERO) + { + app = -app; + _prg_saldoini_avere += app; + } + } + } + + if (_indbil == 5) + { + //real app = sld.saldoini(); + if (flag) + { + if (app > ZERO) + _prg_inidare_ord += app; + else if (app < ZERO) + { + app = -app; + _prg_iniavere_ord += app; + } + } + } + + if ( _indbil==1 || _indbil==3 ) + { + _gruppo_da += saldo; + _conto_da += saldo; + _add_file_dare = TRUE; + } + + if ( _indbil==2 || _indbil==4 ) + { + _gruppo_a += saldo; + _conto_a += saldo; + _add_file_avere = TRUE; + } + + if (_indbil==5) + { + if ( saldo >= ZERO || compensa ) + { + _gruppo_da_ordine += saldo; + _conto_da += saldo; + _add_file_dare = TRUE; + _sottoc_dare = TRUE; + } + else + { + saldo = -saldo; + _gruppo_a_ordine += saldo; + _conto_a += saldo; + _add_file_avere = TRUE; + _sottoc_avere = TRUE; + } + scrivig_file_temp(); + } + if ( (dettaglio) && ( (tipo_conto != 'C') && (tipo_conto != 'F') ) ) + scrivis_file_temp(g, c, s, saldo); + + _gp = g; + _cp = c; + // } // da_considerare + + TRecnotype recnum = _pcn->recno(); + _pcn->next(); + if (_pcn->eof()) + { + scrivic_file_temp(); + scrivig_file_temp(); + } + _pcn->readat(recnum); + } + + return TRUE; +} + +bool CG1500_application::ricerca_sottoc_clifo(int g,int c, bool compensa, int indbil_conto,real& saldo) +{ + TSaldo sld; + int aep=0; + long s, items; + bool esiste_sc = FALSE; + bool movimentato = FALSE; + + if (_annoes) aep = EsePre(_annoes); + sld.set_annoes(_annoes); + _listacf = new TSaldi_list(g, c, _annoes, aep); + + items = _listacf->items(); + + for (int i = 0; i < items; i++) + { + const TRectype* r = _listacf->saldi(); + + if (r == NULL) break; + + s = r->get_long(SLD_SOTTOCONTO); + + if (_tipo_stampa == 1) //bil. a sez. contrapposte per data limite + movimentato = sld.data_limite_bilancio(_bilancio,g,c,s,_dataini,_datalim,indbil_conto,_stampa_mov_prov); + else if (_tipo_stampa == 2) //bil. a sez. contrapposte all'ultima immissione es. in corso + movimentato = sld.ultima_immissione_bilancio(_annoes,g,c,s,indbil_conto,_stampa_mov_prov); + + if (!movimentato) + if (!sld.esiste_saldo() || !sld.significativo()) + continue; + + saldo = sld.saldo(); + real app = sld.saldoini(); + bool flag = sld.flagprec(); + + if (_saldo) //se richiesto di non stampare i conti con saldo a zero + if (saldo == ZERO) + { + //modifica del 06/07/1995 + if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) + { + //real app = sld.saldoini(); + if (flag) + { + if (app > ZERO) + { + if (indbil_conto == 5) + _prg_inidare_ord += app; + else _prg_saldoini_dare += app; + } + else if (app < ZERO) + { + app = -app; + if (indbil_conto == 5) + _prg_iniavere_ord += app; + else _prg_saldoini_avere += app; + } + } + } + //fine + continue; + } + + esiste_sc = TRUE; + _indbil = indbil_conto; + + //i due flag seguenti servono solo per i conti d'ordine + _sottoc_dare = FALSE; + _sottoc_avere = FALSE; + + //error_box ("saldo = %s", saldo.string()); + + if (saldo != ZERO) + saldo = compensazione(compensa, indbil_conto, saldo); + + if (_indbil == 1 || _indbil == 2) + { + //real app = sld.saldoini(); + if (flag) + { + if (app > ZERO) + _prg_saldoini_dare += app; + else if (app < ZERO) + { + app = -app; + _prg_saldoini_avere += app; + } + } + } + + if (_indbil == 5) + { + //real app = sld.saldoini(); + if (flag) + { + if (app > ZERO) + _prg_inidare_ord += app; + else if (app < ZERO) + { + app = -app; + _prg_iniavere_ord += app; + } + } + } + + if ( (_indbil==1) || (_indbil==3) ) + { + _gruppo_da += saldo; + _conto_da += saldo; + _add_file_dare = TRUE; + } + + if ( (_indbil==2) || (_indbil==4) ) + { + _gruppo_a += saldo; + _conto_a += saldo; + _add_file_avere = TRUE; + } + + if (_indbil==5) + { + if ( (saldo >= ZERO) || (compensa) ) // il sottoconto ha saldo in dare + { + _gruppo_da_ordine += saldo; + _conto_da += saldo; + _add_file_dare = TRUE; + _sottoc_dare = TRUE; + } + else //il sottoconto ha saldo in avere + { + saldo = -saldo; + _gruppo_a_ordine += saldo; + _conto_a += saldo; + _add_file_avere = TRUE; + _sottoc_avere = TRUE; + } + scrivig_file_temp(); + } + } + delete _listacf; + return esiste_sc; +} + +bool CG1500_application::bil_verifica() +{ + TSaldo sld; + int g, c, indbil_conto = 0; + long s; + char tipo_conto = ' '; + real saldo_finale, saldo_conto, saldo_gruppo, saldo_iniziale; + real mov_conto_dare, mov_conto_avere, prg_conto_dare, prg_conto_avere; + real mov_gruppo_dare, mov_gruppo_avere, prg_gruppo_dare, prg_gruppo_avere; + bool esiste_conto = FALSE, esiste_sc = FALSE, movimentato = FALSE; + + CHECK(_tmp_saldi_att == NULL, "Non posso riaprire cg01"); + _tmp_saldi_att = new TIsamtempfile(LF_SALDI, "cg01", 2); + + _gp=-1; + _cp=-1; + + _saldo_ini_conto_dare = ZERO; + _saldo_ini_conto_avere = ZERO; + _saldo_ini_gruppo_dare = ZERO; + _saldo_ini_gruppo_avere = ZERO; + _nuovo_tot_saldo_d = ZERO; + _nuovo_tot_saldo_a = ZERO; + saldo_conto = ZERO; + mov_conto_dare = ZERO; + mov_conto_avere = ZERO; + prg_conto_dare = ZERO; + prg_conto_avere = ZERO; + saldo_gruppo = ZERO; + mov_gruppo_dare = ZERO; + mov_gruppo_avere = ZERO; + prg_gruppo_dare = ZERO; + prg_gruppo_avere = ZERO; + _u_max = 0l; + + for (_pcn->first(); !_pcn->eof(); _pcn->next()) + { + _prog->addstatus(1); + g = _pcn->get_int (PCN_GRUPPO); + c = _pcn->get_int (PCN_CONTO); + s = _pcn->get_long(PCN_SOTTOCONTO); + + if ( (((_cp != -1) && (c != _cp)) || ((_gp != -1) && (g != _gp))) && + esiste_sc ) + { + if (_verifica == 2) + if (!((_stampav == 2) && (saldo_conto == 0))) + { + real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; + if (app < ZERO) + _saldo_ini_gruppo_avere += app; + else + _saldo_ini_gruppo_dare += app; + mov_gruppo_dare += mov_conto_dare; + mov_gruppo_avere += mov_conto_avere; + prg_gruppo_dare += prg_conto_dare; + prg_gruppo_avere += prg_conto_avere; + saldo_gruppo += saldo_conto; + } + //scrivo il record del conto; + if ( (_verifica == 1)||( (_verifica == 2)&& + (!((_stampav == 2)&&(saldo_conto == 0))) ) ) + { + scrivi_record_conto(prg_conto_dare,prg_conto_avere,mov_conto_dare, + mov_conto_avere,saldo_conto); + esiste_conto = TRUE; + } + _cp = c; + _saldo_ini_conto_dare = ZERO; + _saldo_ini_conto_avere = ZERO; + saldo_conto = ZERO; + mov_conto_dare = ZERO; + mov_conto_avere = ZERO; + prg_conto_dare = ZERO; + prg_conto_avere = ZERO; + } + if (_verifica == 2) + if ( ((_gp != -1) && (g != _gp)) && (!esiste_conto) ) + { + _gp = g; + _saldo_ini_gruppo_dare = ZERO; + _saldo_ini_gruppo_avere = ZERO; + saldo_gruppo = ZERO; + mov_gruppo_dare = ZERO; + mov_gruppo_avere = ZERO; + prg_gruppo_dare = ZERO; + prg_gruppo_avere = ZERO; + } + if (_verifica == 2) + if ( ((_gp != -1) && (g != _gp)) && esiste_conto ) + { + //scrivo il record del gruppo + scrivi_record_gruppo(prg_gruppo_dare,prg_gruppo_avere,mov_gruppo_dare, + mov_gruppo_avere,saldo_gruppo); + _gp = g; + esiste_conto = FALSE; + _saldo_ini_gruppo_dare = ZERO; + _saldo_ini_gruppo_avere = ZERO; + saldo_gruppo = ZERO; + mov_gruppo_dare = ZERO; + mov_gruppo_avere = ZERO; + prg_gruppo_dare = ZERO; + prg_gruppo_avere = ZERO; + } + if ( (s == 0) && (c != 0) ) //si tratta di un conto + { + tipo_conto = _pcn->get(PCN_TMCF)[0]; + indbil_conto = _pcn->get_int(PCN_INDBIL); + if ( (tipo_conto == 'C') || (tipo_conto == 'F') ) + { + esiste_sc = ricerca_cf(g,c,tipo_conto,indbil_conto,saldo_finale,saldo_iniziale, + mov_conto_dare,mov_conto_avere,prg_conto_dare,prg_conto_avere, + saldo_conto); + if ( (_verifica == 2) && (_stampav == 2) ) + if (saldo_conto == 0) + continue; + if (esiste_sc) + { + _gp = g; + _cp = c; + TRecnotype recnum = _pcn->recno(); + _pcn->next(); + if (_pcn->eof()) + { + if (_verifica == 2) + { + real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; + if (app < ZERO) + _saldo_ini_gruppo_avere += app; + else + _saldo_ini_gruppo_dare += app; + mov_gruppo_dare += mov_conto_dare; + mov_gruppo_avere += mov_conto_avere; + prg_gruppo_dare += prg_conto_dare; + prg_gruppo_avere += prg_conto_avere; + saldo_gruppo += saldo_conto; + + scrivi_record_gruppo(prg_gruppo_dare,prg_gruppo_avere, + mov_gruppo_dare,mov_gruppo_avere,saldo_gruppo); + } + scrivi_record_conto(prg_conto_dare,prg_conto_avere,mov_conto_dare, + mov_conto_avere,saldo_conto); + } + _pcn->readat(recnum); + } + continue; + } + } + + if ( (c == 0) || (s == 0) ) + { + esiste_sc = FALSE; + continue; + } + + saldo_finale = ZERO; //saldo finale relativo a ciascun sottoconto + _indbil = indbil_conto; + if (_tipo_stampa1 == 1) //bil. di verifica per data limite + { + //modifica del 19/06/95 + movimentato = calcola(g,c,s); + if (_stampa_mov_prov != 3) + { + if (movimentato) + { + saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; + TLocalisamfile saldi(LF_SALDI); + saldi.zero(); + saldi.put(SLD_ANNOES,_annoes); + saldi.put(SLD_GRUPPO,g); + saldi.put(SLD_CONTO,c); + saldi.put(SLD_SOTTOCONTO,s); + if (saldi.read() == NOERR) + { + real ss = saldi.get_real(SLD_SALDO); + if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) + if (ss == ZERO && _annoes != 0) + saldo_iniziale += sld.saldofin_esprec(_annoes,g,c,s); + } + } + if (!movimentato) + if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) + if (_annoes != 0) + { + saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s); + if (_stampav == 1 && sld.significativo()) + movimentato = TRUE; + } + } + + //if (movimentato) + // saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; + //movimentato = calcola(g,c,s); + + if (movimentato || _stampav != 1) + { + //saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; + + _nuovo_tot_saldo_d += _mov_periodo_dare; + _nuovo_tot_saldo_a += _mov_periodo_avere; + if (saldo_iniziale > ZERO) + _nuovo_tot_saldo_d += saldo_iniziale; + else + { + real app = -saldo_iniziale; + _nuovo_tot_saldo_a += app; + } + + if (_datada == _dataini) + saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; + else if (_datada > _dataini) + { + if (saldo_iniziale > 0) + _prg_prec_dare += saldo_iniziale; + else _prg_prec_avere -= saldo_iniziale; + saldo_finale = _prg_prec_dare-_prg_prec_avere+_mov_periodo_dare- + _mov_periodo_avere; + + } + //if (saldo_finale == ZERO) + // if (_stampav == 2) + // continue; + } + //se saldo_finale < 0 verra' stampato con una A, se no con una D + } +else +{ + movimentato = sld.ultima_immissione_verifica(_annoes,g,c,s,indbil_conto,_stampa_mov_prov); + + //modifica del 31/03/95 + if (_stampa_mov_prov != 3) + { + if (movimentato) + saldo_iniziale = sld.saldoini(); + if (!movimentato) + { + if (indbil_conto == 1 || indbil_conto == 2 || indbil_conto == 5) + { + saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s); + if (_stampav == 1 && sld.significativo()) + movimentato = TRUE; + } + } + } + //fine modifica + + if (movimentato || _stampav != 1) + { + _mov_periodo_dare = sld.prgdare(); + _mov_periodo_avere = sld.prgavere(); + _prg_prec_dare = ZERO; + _prg_prec_avere = ZERO; + + saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; + } +} + +if (movimentato || _stampav != 1) + if (!(saldo_finale == ZERO && _stampav == 2)) +{ + esiste_sc = TRUE; + esiste_conto = TRUE; + + if (_tipo_stampa1 == 2) + { + _nuovo_tot_saldo_d += _mov_periodo_dare; + _nuovo_tot_saldo_a += _mov_periodo_avere; + real nuovo = sld.saldoinisusaldi(); + if (nuovo > ZERO) + _nuovo_tot_saldo_d += nuovo; + else + { + nuovo = -nuovo; + _nuovo_tot_saldo_a += nuovo; + } + } + + if (saldo_iniziale < ZERO) + _saldo_ini_conto_avere += saldo_iniziale; + else + _saldo_ini_conto_dare += saldo_iniziale; + mov_conto_dare += _mov_periodo_dare; + mov_conto_avere += _mov_periodo_avere; + prg_conto_dare += _prg_prec_dare; + prg_conto_avere += _prg_prec_avere; + saldo_conto += saldo_finale; // somma algebrica!!! + + //scrivo il record relat. al sottoconto se non e' richiesto saldi di mastro + if (_verifica != 2) + { + _tmp_saldi_att->zero(); + _tmp_saldi_att->put(SLD_GRUPPO,g); + _tmp_saldi_att->put(SLD_CONTO,c); + _tmp_saldi_att->put(SLD_SOTTOCONTO,s); + _tmp_saldi_att->put(SLD_FLAGSALINI,tipo_conto); + if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) + { + if (saldo_iniziale > ZERO) //va stampato in Dare + _tmp_saldi_att->put(SLD_PDARESCA,saldo_iniziale); + else if (saldo_iniziale < ZERO) + { + saldo_iniziale = -saldo_iniziale; + _tmp_saldi_att->put(SLD_PAVERESCA,saldo_iniziale); + } + } + else if (_datada > _dataini) + { + _tmp_saldi_att->put(SLD_PDARESCA,_prg_prec_dare); + _tmp_saldi_att->put(SLD_PAVERESCA,_prg_prec_avere); + } + _tmp_saldi_att->put(SLD_PDARE,_mov_periodo_dare); + _tmp_saldi_att->put(SLD_PAVERE,_mov_periodo_avere); + _tmp_saldi_att->put(SLD_SALDO,saldo_finale); + _tmp_saldi_att->put(SLD_DATAULMOV,_u_max); + _tmp_saldi_att->write(); + } + _gp = g; + _cp = c; +} + +TRecnotype recnum = _pcn->recno(); +_pcn->next(); +if (_pcn->eof()) +{ + if ( (_verifica == 2) && esiste_conto ) + { + real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; + if (app < ZERO) + _saldo_ini_gruppo_avere += app; + else + _saldo_ini_gruppo_dare += app; + mov_gruppo_dare += mov_conto_dare; + mov_gruppo_avere += mov_conto_avere; + prg_gruppo_dare += prg_conto_dare; + prg_gruppo_avere += prg_conto_avere; + saldo_gruppo += saldo_conto; + + scrivi_record_gruppo(prg_gruppo_dare,prg_gruppo_avere, + mov_gruppo_dare,mov_gruppo_avere,saldo_gruppo); + } + if (esiste_sc) + if ( (_verifica == 1)||( (_verifica == 2)&& + (!((_stampav == 2)&&(saldo_conto == 0))) ) ) + scrivi_record_conto(prg_conto_dare,prg_conto_avere,mov_conto_dare, + mov_conto_avere,saldo_conto); +} +_pcn->readat(recnum); +} +return TRUE; +} + +//bilancio di verifica per data limite +bool CG1500_application::calcola(int g, int c, long s) +{ + char sezione, provvis; + real importo; + int annoe; + long num_reg; + TDate data_reg, data, datacomp; + bool conto_mov = FALSE; + TLocalisamfile rmov(LF_RMOV); + TLocalisamfile mov(LF_MOV); + + _mov_periodo_dare = ZERO; + _mov_periodo_avere = ZERO; + _prg_prec_dare = ZERO; + _prg_prec_avere = ZERO; + _saldo_ini_dare = ZERO; + _saldo_ini_avere = ZERO; + _u_max = 0l; + + rmov.setkey(2); + rmov.zero(); + rmov.put(RMV_GRUPPO,g); + if (c != 0) + rmov.put(RMV_CONTO,c); + if (s != 0) + rmov.put(RMV_SOTTOCONTO,s); + TRectype rec(rmov.curr()); + + rmov.read(_isgteq); + for ( ; !rmov.eof(); rmov.next()) + { + if (rmov.curr() != rec) break; + + annoe = rmov.get_int(RMV_ANNOES); + data = rmov.get_date(RMV_DATAREG); + num_reg = rmov.get_long(RMV_NUMREG); + + mov.setkey(1); + mov.zero(); + mov.put(MOV_NUMREG, num_reg); + mov.read(); + if (mov.bad()) + mov.zero(); + provvis = mov.get_char(MOV_PROVVIS); + datacomp = mov.get_date(MOV_DATACOMP); + + if (_stampa_mov_prov == 1 && provvis != '\0') //bilancio normale (non comprende i provvisori) + continue; + + if (_stampa_mov_prov == 3 && provvis == '\0') //bilancio dei soli provvisori + continue; + + TString codcaus(mov.get(MOV_CODCAUS)); + + // if (codcaus.not_empty()) + // if (codcaus == causale_chiusura()) + // continue; + + // Modifica del 03-03-95 + + TCaus cau (codcaus); + + if (codcaus.not_empty()) + if (cau.chiusura()) //Si tratta di causale di chiusura + continue; + + //la causale e' uguale a quella di chiusura + //break; + + sezione = rmov.get_char(RMV_SEZIONE); + importo = rmov.get_real(RMV_IMPORTO); + + if (_annoes == 0) + data_reg = data; + else data_reg = datacomp; + + if (importo == 0) + continue; + + //calcolo i movimenti del periodo + /* + if ( data_reg >= _datada && data_reg <= _dataa) + if ((codcaus == causale_apertura() && _dataini != _datada) || + (codcaus != causale_apertura())) + { + conto_mov = TRUE; + if (sezione == 'D') + _mov_periodo_dare += importo; + else _mov_periodo_avere += importo; + _u_max = fnc_max(_u_max, data); + } + */ + // Modifica del 03-03-95 + //calcolo i movimenti del periodo + if ( data_reg >= _datada && data_reg <= _dataa) + if ((cau.apertura() && _dataini != _datada) || + (!cau.apertura())) + { + conto_mov = TRUE; + if (sezione == 'D') + _mov_periodo_dare += importo; + else _mov_periodo_avere += importo; + _u_max = fnc_max(_u_max, data); + } + + //il saldo inizio es. e' dato dall'importo dare - importo avere di quei movimenti che hanno causale == apertura e data reg >= data inizio es. e <= data limite sup. + if (_datada == _dataini) //calcolo il saldo iniziale + { + if (cau.apertura()) + if ( (data_reg >= _dataini) && (data_reg <= _dataa) ) + { + if (sezione == 'D') + _saldo_ini_dare += importo; + else _saldo_ini_avere += importo; + _u_max = fnc_max(_u_max, data); + conto_mov = TRUE; + } + } + else if (_datada > _dataini) //calcolo i progressivi precedenti + if ( (data_reg >= _dataini) && (data_reg <= _datada) ) + { + if (sezione == 'D') + _prg_prec_dare += importo; + else _prg_prec_avere += importo; + _u_max = fnc_max(_u_max, data); + conto_mov = TRUE; + } + } + return conto_mov; +} + +bool CG1500_application::ricerca_cf(int g,int c,char tipocf,int ib, real& saldo_finale,real& saldo_iniziale, + real& mov_conto_dare,real& mov_conto_avere,real& prg_conto_dare,real& prg_conto_avere,real& saldo_conto) +{ + TSaldo sld; + bool esiste_sc = FALSE; + long s; + int anno; + + if (_tipo_stampa1 == 1) + anno = _annoapp; + else anno = _annoes; + + _lista = new TSaldi_list(g, c, anno); + TRecnotype items = _lista->items(); + + for (int i = 0; i < items; i++) + { + const TRectype* r = _lista->saldi(); + if (r == NULL) break; + + s = r->get_long(SLD_SOTTOCONTO); + + saldo_finale = ZERO; //saldo finale relativo a ciascun sottoconto + + if (_tipo_stampa1 == 1) //bil. di verifica per data limite + { + /* + if ( !calcola(g,c,s) ) //il conto non e' movimentato + if (_stampav == 1 || _stampav == 3) //per i C/F anche se seleziono -tutti i conti, voglio solo quelli movimentati + continue; + */ + + //modifica del 19/06. Vedi appunti per capire + bool movimentato = calcola(g,c,s); + + if (_stampa_mov_prov != 3) + { + if (movimentato) + { + saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; + TLocalisamfile saldi(LF_SALDI); + saldi.zero(); + saldi.put(SLD_ANNOES,_annoes); + saldi.put(SLD_GRUPPO,g); + saldi.put(SLD_CONTO,c); + saldi.put(SLD_SOTTOCONTO,s); + if (saldi.read() == NOERR) + { + //se il saldo iniziale e' diverso da zero non lo devo considerare + //perche' l'ho gia' considerato nella funzione calcola + real ss = saldi.get_real(SLD_SALDO); + if (ib == 1 || ib == 2 || ib == 5) + if (ss == ZERO && _annoes != 0) //competenza!!! + saldo_iniziale += sld.saldofin_esprec(_annoes,g,c,s); + } + } + if (!movimentato) + if (ib == 1 || ib == 2 || ib == 5) + if (_annoes != 0) //cioe' se sto ragionando per competenza + { + saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s); + movimentato = sld.significativo(); + } + } + + if (!movimentato) + continue; + //fine modifica + + _nuovo_tot_saldo_d += _mov_periodo_dare; + _nuovo_tot_saldo_a += _mov_periodo_avere; + if (saldo_iniziale > ZERO) + _nuovo_tot_saldo_d += saldo_iniziale; + else + { + real app = -saldo_iniziale; + _nuovo_tot_saldo_a += app; + } + + if (_datada == _dataini) + saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; + else if (_datada > _dataini) + { + if (saldo_iniziale > 0) + _prg_prec_dare += saldo_iniziale; + else _prg_prec_avere -= saldo_iniziale; + saldo_finale = _prg_prec_dare-_prg_prec_avere+_mov_periodo_dare- + _mov_periodo_avere; + } + if (saldo_finale == ZERO) + if (_stampav == 2) + continue; + + //se saldo_finale < 0 verra' stampato con una A, se no con una D + } + else + { + //Attenzione! Nel caso di "tutti i conti" devono scendere solo i cli/for movimentati!!! + + //modifica del 31/03/1995 + bool movimentato = sld.ultima_immissione_verifica(_annoes,g,c,s,ib,_stampa_mov_prov); + + if (_stampa_mov_prov != 3) + { + saldo_iniziale = sld.saldoini(); + if (!movimentato) + { + //if (_stampav == 1) + // continue; + //vado sui saldi con l'anno precedente e calcolo saldo_finale es.prec + //se esiste tale record e almeno un valore e' significativo (indipendentemente dal valore + //del saldo iniziale calcolato, allora metto a TRUE il flag movimentato + //solo se e' un conto patrimoniale + if (ib == 1 || ib == 2 || ib == 5) + { + saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,s); + movimentato = sld.significativo(); + } + } + } + + if (!movimentato) + continue; + //fine modifica 31/03/1995 + + _mov_periodo_dare = sld.prgdare(); + _mov_periodo_avere = sld.prgavere(); + _prg_prec_dare = ZERO; + _prg_prec_avere = ZERO; + + saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; + + if (saldo_finale == ZERO) + if (_stampav == 2) + continue; + + _nuovo_tot_saldo_d += _mov_periodo_dare; + _nuovo_tot_saldo_a += _mov_periodo_avere; + real nuovo = sld.saldoinisusaldi(); + if (nuovo > ZERO) + _nuovo_tot_saldo_d += nuovo; + else + { + nuovo = -nuovo; + _nuovo_tot_saldo_a += nuovo; + } + } + + esiste_sc = TRUE; + + if (saldo_iniziale < ZERO) + _saldo_ini_conto_avere += saldo_iniziale; + else + _saldo_ini_conto_dare += saldo_iniziale; + mov_conto_dare += _mov_periodo_dare; + mov_conto_avere += _mov_periodo_avere; + prg_conto_dare += _prg_prec_dare; + prg_conto_avere += _prg_prec_avere; + saldo_conto += saldo_finale; // somma algebrica!!! + + //scrivo il record relat. al sottoconto se non e' richiesto saldi di mastro + if (_verifica != 2) + { + _tmp_saldi_att->zero(); + _tmp_saldi_att->put(SLD_GRUPPO,g); + _tmp_saldi_att->put(SLD_CONTO,c); + _tmp_saldi_att->put(SLD_SOTTOCONTO,s); + _tmp_saldi_att->put(SLD_FLAGSALINI,tipocf); + if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) + { + if (saldo_iniziale > ZERO) //va stampato in Dare + _tmp_saldi_att->put(SLD_PDARESCA,saldo_iniziale); + else if (saldo_iniziale < ZERO) + { + saldo_iniziale = -saldo_iniziale; + _tmp_saldi_att->put(SLD_PAVERESCA,saldo_iniziale); + } + } + else if (_datada > _dataini) + { + _tmp_saldi_att->put(SLD_PDARESCA,_prg_prec_dare); + _tmp_saldi_att->put(SLD_PAVERESCA,_prg_prec_avere); + } + _tmp_saldi_att->put(SLD_PDARE,_mov_periodo_dare); + _tmp_saldi_att->put(SLD_PAVERE,_mov_periodo_avere); + _tmp_saldi_att->put(SLD_SALDO,saldo_finale); + _tmp_saldi_att->put(SLD_DATAULMOV, _u_max); + _tmp_saldi_att->write(); + } + } + delete _lista; + return esiste_sc; +} + +void CG1500_application::scrivi_record_gruppo(const real& prg_da, + const real& prg_a,const real& mov_da,const real& mov_a,const real& s) +{ + _tmp_saldi_att->zero(); + _tmp_saldi_att->put(SLD_GRUPPO,_gp); + _tmp_saldi_att->put(SLD_CONTO,0); + _tmp_saldi_att->put(SLD_SOTTOCONTO,0L); + if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) + { + real app = _saldo_ini_gruppo_dare + _saldo_ini_gruppo_avere; + if (app > ZERO) //va stampato in Dare + _tmp_saldi_att->put(SLD_PDARESCA,app); + else if (app < ZERO) + { + app = -app; + _tmp_saldi_att->put(SLD_PAVERESCA,app); + } + } + else if (_datada > _dataini) + { + _tmp_saldi_att->put(SLD_PDARESCA,prg_da); + _tmp_saldi_att->put(SLD_PAVERESCA,prg_a); + } + _tmp_saldi_att->put(SLD_PDARE,mov_da); + _tmp_saldi_att->put(SLD_PAVERE,mov_a); + _tmp_saldi_att->put(SLD_SALDO,s); + _tmp_saldi_att->write(); +} + +void CG1500_application::scrivi_record_conto(const real& prg_da, + const real& prg_a,const real& mov_da,const real& mov_a,const real& s) +{ + _tmp_saldi_att->zero(); + _tmp_saldi_att->put(SLD_GRUPPO,_gp); + _tmp_saldi_att->put(SLD_CONTO,_cp); + _tmp_saldi_att->put(SLD_SOTTOCONTO,0L); + if ( (_datada == _dataini) || (_tipo_stampa1 != 1) ) + { + real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; + if (app > ZERO) //va stampato in Dare + _tmp_saldi_att->put(SLD_PDARESCA,app); + else if (app < ZERO) + { + app = -app; + _tmp_saldi_att->put(SLD_PAVERESCA,app); + } + } + else if (_datada > _dataini) + { + _tmp_saldi_att->put(SLD_PDARESCA,prg_da); + _tmp_saldi_att->put(SLD_PAVERESCA,prg_a); + } + _tmp_saldi_att->put(SLD_PDARE,mov_da); + _tmp_saldi_att->put(SLD_PAVERE,mov_a); + _tmp_saldi_att->put(SLD_SALDO,s); + _tmp_saldi_att->write(); +} + +void CG1500_application::init_sort() +{ + _cf = new cli_for; + _sort = new TSort(sizeof(cli_for)); + + if (_ordinamento == 1) + { + _sort->addsortkey ((char*)&(_cf->tipocf)-(char*)&(_cf->tipocf),1); + _sort->addsortkey ((char*)&(_cf->gruppo)-(char*)&(_cf->tipocf),3); + _sort->addsortkey ((char*)&(_cf->conto)-(char*)&(_cf->tipocf),3); + _sort->addsortkey ((char*)&(_cf->codcf)-(char*)&(_cf->tipocf),6); + } + else if (_ordinamento == 2) + { + _sort->addsortkey ((char*)&(_cf->tipocf)-(char*)&(_cf->tipocf),1); + _sort->addsortkey ((char*)&(_cf->gruppo)-(char*)&(_cf->tipocf),3); + _sort->addsortkey ((char*)&(_cf->conto)-(char*)&(_cf->tipocf),3); + _sort->addsortkey ((char*)&(_cf->ragsoc)-(char*)&(_cf->tipocf),50); + } + + _sort->init(); +} + +void CG1500_application::riempi_record(char t,int g,int c,long s, + const char* rs,const real& sd,const real& sa, + const real& md,const real& ma,const real& sf) +{ + _cf->tipocf = t; + sprintf(_cf->gruppo, "%03d", g); + sprintf(_cf->conto, "%03d", c); + sprintf(_cf->codcf, "%06ld", s); + sprintf(_cf->ragsoc, "%s", rs); + if ( s == 999999L ) + { + if ( (_datada == _dataini)||(_tipo_stampa1 != 1) ) + { + real app = _saldo_ini_conto_dare + _saldo_ini_conto_avere; + if (app > ZERO) //va stampato in Dare + { + _cf->saldoavere = ZERO; + _cf->saldodare = app; + } + else if (app < ZERO) + { + app = -app; + _cf->saldodare = ZERO; + _cf->saldoavere = app; + } + } + else if (_datada > _dataini) + { + _cf->saldodare = sd; + _cf->saldoavere = sa; + } + } + else + { + _cf->saldodare = sd; + _cf->saldoavere = sa; + } + _cf->movdare = md; + _cf->movavere = ma; + _cf->saldofinale = sf; + _cf->udata = _u_max; + _sort->sort((const char*)_cf); +} + +void CG1500_application::crea_sort_clifo() +{ + TSaldo sld; + TLocalisamfile saldi(LF_SALDI, FALSE); + int g=0, c=0; + long codcf=0l; + TString80 ragsoc; + char tipocf,tipocfp,tipoa; + real saldo_finale, saldo_conto, saldo_iniziale, saldodare, saldoavere, + movdare, movavere; + real mov_conto_dare, mov_conto_avere, prg_conto_dare, prg_conto_avere; + bool esiste_sc = FALSE, movimentato = FALSE; + TArray gccf; + TRecnotype items = _cur->items(); + + _gp=-1; + _cp=-1; + tipocfp = ' '; + + _saldo_ini_conto_dare = ZERO; + _saldo_ini_conto_avere = ZERO; + saldo_conto = ZERO; + mov_conto_dare = ZERO; + mov_conto_avere = ZERO; + prg_conto_dare = ZERO; + prg_conto_avere = ZERO; + _u_max = 0l; + + init_sort(); + + int anno; + + if (_tipo_stampa1 == 1) + anno = _annoapp; + else anno = _annoes; + + *_cur = 0l; + + for (int i = 0; i < items; i++,++(*_cur)) + { + _prog->addstatus(1); + codcf = _cur->curr().get_long(CLI_CODCF); + tipocf = _cur->curr().get(CLI_TIPOCF)[0]; + ragsoc = _cur->curr().get(CLI_RAGSOC); + tipoa = _cur->curr().get_char(CLI_TIPOAPER); + if (tipoa == 'F') //persona fisica + { + TString80 cognome, nome; + cognome = ragsoc.mid(0,30); + nome = ragsoc.mid(30,20); + cognome.trim(); nome.trim(); + ragsoc = cognome; + ragsoc << " " << nome; + } + + if (tipocf == 'C') + gccf = _clienti; + else + if (tipocf == 'F') + gccf = _fornitori; + + for (int i=0; i < gccf.items(); i++) + { + int g = ((TToken_string&)gccf[i]).get_int(0); + int c = ((TToken_string&)gccf[i]).get_int(1); + + int aprec = EsePre(anno); + + saldi.zero(); + saldi.put(SLD_ANNOES, anno); + saldi.put(SLD_GRUPPO, g); + saldi.put(SLD_CONTO, c); + saldi.put(SLD_SOTTOCONTO, codcf); + + if (saldi.read() != NOERR) + if (_tipo_stampa1 == 1) //bilancio per data limite + continue; + else if (_stampac == 2) //se sono richiesti i conti movimentati + { //esco, se no... + _indbil = cerca_indbil(g,c); + if (_indbil == 1 || _indbil == 2 || _indbil == 5) + { + saldi.zero(); + saldi.put(SLD_ANNOES, aprec); + saldi.put(SLD_GRUPPO, g); + saldi.put(SLD_CONTO, c); + saldi.put(SLD_SOTTOCONTO, codcf); + if (saldi.read() != NOERR) + continue; + } + } + + if ( (((_cp != -1) && (c != _cp)) || ((_gp != -1) && (g != _gp))) && + esiste_sc ) + { + //scrivo il record del conto; + riempi_record(tipocfp,_gp,_cp,999999L,"zzzz",prg_conto_dare, + prg_conto_avere,mov_conto_dare,mov_conto_avere,saldo_conto); + tipocfp = tipocf; + _cp = c; + esiste_sc = FALSE; + _saldo_ini_conto_dare = ZERO; + _saldo_ini_conto_avere = ZERO; + saldo_conto = ZERO; + mov_conto_dare = ZERO; + mov_conto_avere = ZERO; + prg_conto_dare = ZERO; + prg_conto_avere = ZERO; + } + + saldo_finale = ZERO; + saldodare = ZERO; + saldoavere = ZERO; + movdare = ZERO; + movavere = ZERO; + + if (_tipo_stampa1 == 1) //bilancio di verifica per data limite + { + //modifica del 19/06/95 + _indbil = cerca_indbil(g,c); + movimentato = calcola(g,c,codcf); + if (_stampa_mov_prov != 3) + if (!movimentato && _stampac!=1) + if (_indbil == 1 || _indbil == 2 || _indbil == 5) + if (_annoes != 0) //cioe' se sto ragionando per competenza + saldo_iniziale = sld.saldofin_esprec(_annoes,g,c,codcf); + + if (movimentato) + { + saldo_iniziale = _saldo_ini_dare - _saldo_ini_avere; + TLocalisamfile saldi(LF_SALDI); + saldi.zero(); + saldi.put(SLD_ANNOES,_annoes); + saldi.put(SLD_GRUPPO,g); + saldi.put(SLD_CONTO,c); + saldi.put(SLD_SOTTOCONTO,codcf); + if (saldi.read() == NOERR) + { + real s = saldi.get_real(SLD_SALDO); + if (_stampa_mov_prov != 3) + if (_indbil == 1 || _indbil == 2 || _indbil == 5) + if (s == ZERO && _annoes != 0) //competenza!!! + saldo_iniziale += sld.saldofin_esprec(_annoes,g,c,codcf); + } + } + //fine modifica + //movimentato = calcola(g,c,codcf); + if (movimentato || _stampac != 1) + { + if (_datada == _dataini) + saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; + else if (_datada > _dataini) + { + //modifica del 19/06 + if (saldo_iniziale > 0) + _prg_prec_dare += saldo_iniziale; + else _prg_prec_avere -= saldo_iniziale; + //fine modifica + saldo_finale = _prg_prec_dare-_prg_prec_avere+_mov_periodo_dare + -_mov_periodo_avere; + } + } + //if (saldo_finale == ZERO) + // if (_stampac == 2) + // continue; + + //se saldo_finale < 0 verra' stampato con una A, se no con una D + } + else //bilancio di verifica all'ultima immissione + { + _indbil = cerca_indbil(g,c); + movimentato = sld.ultima_immissione_verifica(anno,g,c,codcf,_indbil,_stampa_mov_prov); + + if (_stampa_mov_prov != 3) + if (!movimentato && _stampac!=1) + if (_indbil == 1 || _indbil == 2 || _indbil == 5) + saldo_iniziale = sld.saldofin_esprec(anno,g,c,codcf); + + if (movimentato) + saldo_iniziale = sld.saldoini(); + + if (movimentato || _stampac != 1) + { + _mov_periodo_dare = sld.prgdare(); + _mov_periodo_avere = sld.prgavere(); + _prg_prec_dare = ZERO; + _prg_prec_avere = ZERO; + + saldo_finale = saldo_iniziale+_mov_periodo_dare-_mov_periodo_avere; + } + //if (saldo_finale == ZERO) + // if (_stampac == 2) + // continue; + } + if (movimentato || _stampac != 1) + if (!(saldo_finale == ZERO && _stampac == 2)) + { + esiste_sc = TRUE; + + if (saldo_iniziale < ZERO) + _saldo_ini_conto_avere += saldo_iniziale; + else + _saldo_ini_conto_dare += saldo_iniziale; + mov_conto_dare += _mov_periodo_dare; + mov_conto_avere += _mov_periodo_avere; + prg_conto_dare += _prg_prec_dare; + prg_conto_avere += _prg_prec_avere; + saldo_conto += saldo_finale; // somma algebrica!!! + + if ( (_datada == _dataini)||(_tipo_stampa1 != 1) ) + { + if (saldo_iniziale > ZERO) //va stampato in Dare + saldodare = saldo_iniziale; + else if (saldo_iniziale < ZERO) + { + saldo_iniziale = -saldo_iniziale; + saldoavere = saldo_iniziale; + } + } + else if (_datada > _dataini) + { + saldodare = _prg_prec_dare; + saldoavere = _prg_prec_avere; + } + + movdare = _mov_periodo_dare; + movavere = _mov_periodo_avere; + + riempi_record(tipocf,g,c,codcf,ragsoc,saldodare,saldoavere,movdare, + movavere,saldo_finale); + tipocfp = tipocf; + _gp = g; + _cp = c; + } + } + } + if (esiste_sc) + riempi_record(tipocfp,_gp,_cp,999999L,"zzzz",prg_conto_dare,prg_conto_avere, + mov_conto_dare,mov_conto_avere,saldo_conto); +} + +int CG1500_application::cerca_indbil(int g, int c) +{ + TLocalisamfile pconti(LF_PCON); + + pconti.zero(); + pconti.put(PCN_GRUPPO,g); + if (c != 0) + pconti.put(PCN_CONTO,c); + pconti.put(PCN_SOTTOCONTO,0l); + + pconti.read(); + + return pconti.get_int(PCN_INDBIL); +} + +void CG1500_application::leggi_files_dare(TIsamtempfile* file) +{ + _gruppo_dare = file->get_int(SLD_GRUPPO); + _conto_dare = file->get_int(SLD_CONTO); + _sottoconto_dare = file->get_long(SLD_SOTTOCONTO); + _saldo_dare = file->get_real(SLD_PDARE); + + _descr_dare = DescrizioneConto(_gruppo_dare,_conto_dare,_sottoconto_dare,' '); + + _gc_corr_dare = format("%3d%3d", _gruppo_dare, _conto_dare); + + if (_gc_corr_dare != _gc_prec_dare) + { + _cambiato_conto_1 = TRUE; + _gc_prec_dare = _gc_corr_dare; + } + else if (_sottoconto_dare != 0l) + _cambiato_conto_1 = FALSE; +} + +void CG1500_application::leggi_files_avere(TIsamtempfile* file) +{ + _gruppo_avere = file->get_int(SLD_GRUPPO); + _conto_avere = file->get_int(SLD_CONTO); + _sottoconto_avere = file->get_long(SLD_SOTTOCONTO); + _saldo_avere = file->get_real(SLD_PAVERE); + + _descr_avere = DescrizioneConto(_gruppo_avere,_conto_avere,_sottoconto_avere, + ' '); + _gc_corr_avere = format("%3d%3d", _gruppo_avere, _conto_avere); + + if (_gc_corr_avere != _gc_prec_avere) + { + _cambiato_conto_2 = TRUE; + _gc_prec_avere = _gc_corr_avere; + } + else if (_sottoconto_avere != 0l) + _cambiato_conto_2 = FALSE; +} + +bool CG1500_application::preprocess_print(int file, int counter) +{ + set_real_picture ("###.###.###.###"); + if (_bilancio == 1) + { + set_print_zero(); + _tmp_saldi_att->setkey(2); + _tmp_saldi_pass->setkey(2); + _tmp_saldi_costi->setkey(2); + _tmp_saldi_ricavi->setkey(2); + _tmp_saldi_conti_uno->setkey(2); + _tmp_saldi_conti_due->setkey(2); + _gc_prec_avere = ""; + _prima_volta = _seconda_volta = TRUE; + _flag = _controlla = FALSE; + _salto_pagina = _salto_pagina1 = _stampato = FALSE; + _cambiato_conto_1 = TRUE; + _cambiato_conto_2 = TRUE; + _tot_dare = ZERO; + _tot_avere = ZERO; + } + else + { + //if ( (_verifica == 3) && (_ordinamento == 1) ) + // _tmp_saldi_att->setkey(2); + set_print_zero(FALSE); + _cambiato_conto_1 = FALSE; + _livello_conto = TRUE; + _saldo_dare_tot = ZERO; + _saldo_avere_tot = ZERO; + _mov_dare_tot = ZERO; + _mov_avere_tot = ZERO; + _saldo_finale_tot = ZERO; + } + return TRUE; +} + +void CG1500_application::leggi_file_tmp() +{ + if (_livello_conto) // era meglio chiamarla _livello_conto_oppure_gruppo, perche' nel caso dei saldi di mastro _livello_conto==TRUE <=> si tratta di un gruppo, mentre nel caso del bilancio _livello_conto==TRUE <=> si tratta di un conto + { + _gruppo = _tmp_saldi_att->get_int(SLD_GRUPPO); + _conto = _tmp_saldi_att->get_int(SLD_CONTO); + _sottoconto = _tmp_saldi_att->get_long(SLD_SOTTOCONTO); + _tipo_conto = _tmp_saldi_att->get_char(SLD_FLAGSALINI); + _descr = DescrizioneConto(_gruppo,_conto,_sottoconto,_tipo_conto); + _saldoini_dare = _tmp_saldi_att->get_real(SLD_PDARESCA); + _saldoini_avere = _tmp_saldi_att->get_real(SLD_PAVERESCA); + _mov_dare = _tmp_saldi_att->get_real(SLD_PDARE); + _mov_avere = _tmp_saldi_att->get_real(SLD_PAVERE); + _saldofinale = _tmp_saldi_att->get_real(SLD_SALDO); + } + _eof1 = _tmp_saldi_att->next(); + if (!_eof1) + { + _gruppo_succ = _tmp_saldi_att->get_int(SLD_GRUPPO); + _conto_succ = _tmp_saldi_att->get_int(SLD_CONTO); + _sottoconto_succ = _tmp_saldi_att->get_long(SLD_SOTTOCONTO); + _tipoc_succ = _tmp_saldi_att->get_char(SLD_FLAGSALINI); + if ( (_verifica != 2) && (_sottoconto_succ != 0) ) + if (_tipo_stampa1 == 2) + _ultima_data = UltimaData(_gruppo_succ,_conto_succ, + _sottoconto_succ,_annoes); + else _ultima_data = _tmp_saldi_att->get_date(SLD_DATAULMOV); + _descr_succ = DescrizioneConto(_gruppo_succ,_conto_succ, + _sottoconto_succ,_tipoc_succ); + _saldoini_dare_succ = _tmp_saldi_att->get_real(SLD_PDARESCA); + _saldoini_avere_succ = _tmp_saldi_att->get_real(SLD_PAVERESCA); + _mov_dare_succ = _tmp_saldi_att->get_real(SLD_PDARE); + _mov_avere_succ = _tmp_saldi_att->get_real(SLD_PAVERE); + _saldofinale_succ = _tmp_saldi_att->get_real(SLD_SALDO); + _livello_conto = FALSE; + if ( ((_verifica != 2)&&(_sottoconto_succ == 0)) || + ((_verifica == 2)&&(_conto_succ == 0)) ) + { + _livello_conto = TRUE; + _gruppo_succ = _gruppo; + _conto_succ = _conto; + _sottoconto_succ = _sottoconto; + _descr_succ = _descr; + _saldoini_dare_succ = _saldoini_dare; + _saldoini_avere_succ = _saldoini_avere; + _mov_dare_succ = _mov_dare; + _mov_avere_succ = _mov_avere; + _saldofinale_succ = _saldofinale; + } + } +} + +bool CG1500_application::preprocess_page(int file, int counter) +{ + reset_print(); + + if (_bilancio == 1) //stampa bilancio a sez. contrapposte + { + if (counter) + { + if ( (!_eof1) && (_cambiato_conto_1) ) + _eof1 = _tmp_saldi_att->next(); + + if ( (!_eof2) && (_cambiato_conto_2) ) + _eof2 = _tmp_saldi_pass->next(); + + if (_eof1 && _eof2) + { + if (_prima_volta) + { + stampa_totali_uno(_prg_saldoini_dare,_prg_saldoini_avere); + _eof3 = _tmp_saldi_costi->first(); + _eof4 = _tmp_saldi_ricavi->first(); + } + else + { + _controlla = TRUE; + + if (_salto_pagina) + { + if ( (!_eof3) && (_cambiato_conto_1) ) + _eof3 = _tmp_saldi_costi->next(); + + if ( (!_eof4) && (_cambiato_conto_2) ) + _eof4 = _tmp_saldi_ricavi->next(); + } + } + + if ( (!_eof3) && (_cambiato_conto_1) ) + leggi_files_dare(_tmp_saldi_costi); + + if ( (!_eof4) && (_cambiato_conto_2) ) + leggi_files_avere(_tmp_saldi_ricavi); + + if (_eof3 && _eof4 && _salto_pagina) + { + if (_seconda_volta) + { + stampa_totali(); + _eof5 = _tmp_saldi_conti_uno->first(); + _eof6 = _tmp_saldi_conti_due->first(); + } + else + { + _flag = TRUE; + + if (_salto_pagina1) + { + if ( (!_eof5) && (_cambiato_conto_1) ) + _eof5 = _tmp_saldi_conti_uno->next(); + + if ( (!_eof6) && (_cambiato_conto_2) ) + _eof6 = _tmp_saldi_conti_due->next(); + } + } + + if ( (!_eof5) && (_cambiato_conto_1) ) + leggi_files_dare(_tmp_saldi_conti_uno); + + if ( (!_eof6) && (_cambiato_conto_2) ) + leggi_files_avere(_tmp_saldi_conti_due); + } + } + } + else //counter = 0 + { + _gc_prec_dare = _gc_corr_avere = ""; + _eof1 = _tmp_saldi_att->first(); + _eof2 = _tmp_saldi_pass->first(); + } + + if ( (!_eof1) && (_cambiato_conto_1) ) + leggi_files_dare(_tmp_saldi_att); + + if ( (!_eof2) && (_cambiato_conto_2) ) + leggi_files_avere(_tmp_saldi_pass); + } + else //stampa bilancio di verifica + { + if (_verifica == 3) + leggi_sort(); + else + { + if (counter) + { + if (!_eof1) + leggi_file_tmp(); + } + else + { + _eof1 = _tmp_saldi_att->first(); + if (_eof1) + return FALSE; + else leggi_file_tmp(); + } + } + } + return TRUE; +} + +void CG1500_application::leggi_sort() +{ + struct cli_for* cf; + + if ( (_buff = _sort->retrieve()) != NULL) + { + cf = (struct cli_for*)_buff; + _tipo_conto = cf->tipocf; + _gruppo = atoi(cf->gruppo); + _conto = atoi(cf->conto); + _sottoconto = atol(cf->codcf); + _descr = cf->ragsoc; + if ( (_ordinamento == 2 && _descr != "zzzz") || + (_ordinamento == 1 && _sottoconto != 999999L) ) + if (_tipo_stampa1 == 2) + _ultima_data = UltimaData(_gruppo,_conto,_sottoconto,_annoes); + else _ultima_data = cf->udata; + _saldo_dare = cf->saldodare; + _saldo_avere = cf->saldoavere; + _mov_dare = cf->movdare; + _mov_avere = cf->movavere; + _saldofinale = cf->saldofinale; + } +} + +void CG1500_application::controlla_conto(int file1,int file2) +{ + char dep = '*'; + + if (!file1) + if (_cambiato_conto_1) + { + set_row(_i,"@66g%c", dep); + _cambiato_conto_1 = FALSE; + } + else + { + stampa_prima_colonna(_gruppo_dare, _conto_dare, _sottoconto_dare, + _descr_dare,_saldo_dare); + _cambiato_conto_1 = TRUE; + if (!_totali) + if ( (_conto_dare == 0) && (_sottoconto_dare == 0) ) + _tot_dare += _saldo_dare; + if (_totali) + if (_sottoconto_dare == 0) + _tot_dare += _saldo_dare; + } + + if (!file2) + if (_cambiato_conto_2) + { + set_row(_i,"@66g%c", dep); + _cambiato_conto_2 = FALSE; + } + else + { + stampa_seconda_colonna(_gruppo_avere, _conto_avere, _sottoconto_avere, + _descr_avere, _saldo_avere); + _cambiato_conto_2 = TRUE; + if (!_totali) + if ( (_conto_avere == 0) && (_sottoconto_avere == 0) ) + _tot_avere += _saldo_avere; + if (_totali) + if (_sottoconto_avere == 0) + _tot_avere += _saldo_avere; + } +} + +void CG1500_application::postclose_print() +{ + if (_bilancio == 1) + { + delete _tmp_saldi_att; _tmp_saldi_att = NULL; + delete _tmp_saldi_pass; _tmp_saldi_pass = NULL; + delete _tmp_saldi_costi; _tmp_saldi_costi = NULL; + delete _tmp_saldi_ricavi; _tmp_saldi_ricavi = NULL; + delete _tmp_saldi_conti_uno; _tmp_saldi_conti_uno = NULL; + delete _tmp_saldi_conti_due; _tmp_saldi_conti_due = NULL; + } + else + { + if (_verifica == 3) + delete _sort; + else + { + delete _tmp_saldi_att; _tmp_saldi_att = NULL; + } + } +} + +void CG1500_application::set_page(int file, int counter) +{ + TString dep = ""; + + if (_bilancio == 1) //stampa bilancio a sezioni contrapposte + { + _i = 1; + + if (!counter) + { + set_row(_i++,"@29gATTIVITA'@94gPASSIVITA'"); + set_row(_i++,"@29g---------@94g----------"); + set_row(_i++, (const char*)dep); + } + + controlla_conto(_eof1,_eof2); //stampo una riga vuota tra un gruppo e un conto altrimenti no + + if ( _eof1 && _eof2 && (!_prima_volta) && _controlla ) + if (!_salto_pagina) + { + printer().formfeed(); + set_row(_i++,"@29gCOSTI@94gRICAVI"); + set_row(_i++,"@29g-----@94g------"); + set_row(_i++, (const char*)dep); + _salto_pagina = TRUE; + + } + + if (_eof1 && _eof2 && _controlla) + { + controlla_conto(_eof3,_eof4); + + if ( _eof3 && _eof4 && (!_seconda_volta) && _flag ) + if (!_salto_pagina1) + { + if (!_tmp_saldi_conti_uno->empty() || !_tmp_saldi_conti_due->empty()) + { + printer().formfeed(); + set_row(_i++,"@59gCONTI D'ORDINE"); + set_row(_i++,"@59g--------------"); + set_row(_i++, (const char*)dep); + if (_eof5 && _eof6) + { + _stampato = TRUE; + //stampa_totali(); + stampa_totali_uno(_prg_inidare_ord,_prg_iniavere_ord); + } + } + _salto_pagina1 = TRUE; + } + + if (_eof3 && _eof4 && _flag) + { + if (!_tmp_saldi_conti_uno->empty() || !_tmp_saldi_conti_due->empty()) + { + controlla_conto(_eof5,_eof6); + if (_eof5 && _eof6) + if (!_stampato) + //stampa_totali(); + stampa_totali_uno(_prg_inidare_ord,_prg_iniavere_ord); + } + } + } + } + else //stampa bilancio di verifica + { + TString udata = _ultima_data.string(brief,'/'); + char app; + int r = 1; + + if (_verifica == 3) + { + if (_buff != NULL) + { + *_d = (const char*) _descr; + if (_saldofinale > 0) + app = 'D'; + else if (_saldofinale < 0) + { + _saldofinale = -_saldofinale; + app = 'A'; + } + if ( (_ordinamento == 2 && _descr == "zzzz") || + (_ordinamento == 1 && _sottoconto == 999999L) ) //devo stampare il conto + { + _descr = DescrizioneConto(_gruppo,_conto,0L,' '); + stampa_record_conto(_gruppo,_conto,_descr,_saldo_dare,_saldo_avere, + _mov_dare,_mov_avere,_saldofinale,app); + } + else + if (_stampa_width == 132) + { + set_row(r,"@1g%6ld",(const char*)_sottoconto); + set_row(r," %s",(const char*)udata); + set_row(r,"@18g#a@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c",_d,&_saldo_dare, + &_saldo_avere,&_mov_dare,&_mov_avere,&_saldofinale,app); + if (_descr.len() > 30) + set_row(++r, "@49g!@82g!@114g!"); + } + else if (app == 'D') + { + set_row(r,"@1g%6ld",(const char*)_sottoconto); + set_row(r," %s",(const char*)udata); + set_row(r,"@18g#a@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!",_d, + &_saldo_dare,&_saldo_avere,&_mov_dare,&_mov_avere,&_saldofinale); + if (_descr.len() > 30) + set_row(++r, "@49g!@82g!@115g!@148g!"); + } + else + { + set_row(r,"@1g%6ld",(const char*)_sottoconto); + set_row(r," %s",(const char*)udata); + set_row(r,"@18g#a@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!", + _d,&_saldo_dare,&_saldo_avere,&_mov_dare,&_mov_avere,&_saldofinale); + if (_descr.len() > 30) + set_row(++r, "@49g!@82g!@115g!@148g!"); + } + } + } + else //_verifica != 3 + { + if (!_eof1) + { + if (_saldofinale_succ > 0) + app = 'D'; + else if (_saldofinale_succ < 0) + { + _saldofinale_succ = -_saldofinale_succ; + app = 'A'; + } + + if (_livello_conto) //sto stampando un conto/gruppo + r = stampa_record_conto(_gruppo_succ,_conto_succ,_descr_succ, + _saldoini_dare_succ,_saldoini_avere_succ,_mov_dare_succ, + _mov_avere_succ,_saldofinale_succ,app); + + else //sto stampando un sottoconto/conto + { + if (_verifica == 2) + { + if (_stampa_width == 132) + { + set_row(r,"%3d",_conto_succ); + set_row(r," @8g%-.40s@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c", + (const char*)_descr_succ,&_saldoini_dare_succ,&_saldoini_avere_succ, + &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ,app); + } + else if (app == 'D') + { + set_row(r,"%3d",_conto_succ); + set_row(r," @8g%-.40s@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!", + (const char*)_descr_succ,&_saldoini_dare_succ,&_saldoini_avere_succ, + &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); + } + else + { + set_row(r,"%3d",_conto_succ); + set_row(r," @8g%-.40s@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!", + (const char*)_descr_succ,&_saldoini_dare_succ,&_saldoini_avere_succ, + &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); + } + } // _verifica != 2 + else + { + *_d = (const char*) _descr_succ; + + if (_stampa_width == 132) + { + set_row(r,"@1g%6ld",(const char*)_sottoconto_succ); + set_row(r," %s",(const char*)udata); + set_row(r,"@18g#a@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c", + _d,&_saldoini_dare_succ,&_saldoini_avere_succ, + &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ,app); + if (_descr_succ.len() > 30) + set_row(++r, "@49g!@82g!@114g!"); + } + else if (app == 'D') + { + set_row(r,"@1g%6ld",(const char*)_sottoconto_succ); + set_row(r," %s",(const char*)udata); + set_row(r,"@18g#a@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!", + _d,&_saldoini_dare_succ,&_saldoini_avere_succ, + &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); + if (_descr_succ.len() > 30) + set_row(++r, "@49g!@82g!@115g!@148g!"); + } + else + { + set_row(r,"@1g%6ld",(const char*)_sottoconto_succ); + set_row(r," %s",(const char*)udata); + set_row(r,"@18g#a@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!", + _d,&_saldoini_dare_succ,&_saldoini_avere_succ, + &_mov_dare_succ,&_mov_avere_succ,&_saldofinale_succ); + if (_descr_succ.len() > 30) + set_row(++r, "@49g!@82g!@115g!@148g!"); + } + } + } + } + else + { + if (_saldofinale > 0) + app = 'D'; + else if (_saldofinale < 0) + { + app = 'A'; + _saldofinale = -_saldofinale; + } + r = stampa_record_conto(_gruppo,_conto,_descr,_saldoini_dare, + _saldoini_avere,_mov_dare,_mov_avere,_saldofinale,app);//per stampare l'ultimo conto + + stampa_riga_totali(r); + } + } + } +} + +int CG1500_application::stampa_record_conto(int g,int c,const TString& d, + const real& r1,const real& r2,const real& r3,const real& r4,const real& r5, + const char app) +{ + TString dep = ""; + int r = 1; + + if (_stampa_width == 148) + { + set_row(r,"@49g!@82g!@115g!",(const char*)dep); //stampo una riga vuota + set_row(r,"@148g!",(const char*)dep); + } + else + set_row(r,"@49g!@82g!@114g!",(const char*)dep); //stampo una riga vuota + r++; + if (_verifica == 2) + { + if (_stampa_width == 132) + { + // set_row(r++,"%3d-@8g%s@49g|@50g%r@67g%r@82g|@83g%r@100g%r@115g|@116g%r%s",g,d,&r1,&r2,&r3,&r4,&r5,(const char*)app); + set_row(r,"%3d-",g); + set_row(r,"@8g%-.40s",(const char*)d); + set_row(r++,"@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c",&r1,&r2,&r3,&r4,&r5,app); + } + else + if (app == 'D') + { + // set_row(r++,"%3d-@8g%s@49g|@50g%r@67g%r@82g|@83g%r@100g%r@115g|@116g%r@148g|",g,d,&r1,&r2,&r3,&r4,&r5); + set_row(r,"%3d-",g); + set_row(r,"@8g%-.40s",(const char*)d); + set_row(r++,"@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!",&r1,&r2,&r3,&r4,&r5); + } + else + { + // set_row(r++,"%3d-@8g%s@49g|@50g%r@67g%r@82g|@83g%r@100g%r@115g|@132g%r@148g|",g,d,&r1,&r2,&r3,&r4,&r5); + set_row(r,"%3d-",g); + set_row(r,"@8g%-.40s",(const char*)d); + set_row(r++,"@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!",&r1,&r2,&r3,&r4,&r5); + } + } + else + { + *_d = (const char*) d; + + if (_stampa_width == 132) + { + // set_row(r++,"%3d-%3d ********@18g%s@49g|@50g%r@67g%r@82g|@83g%r@100g%r@115g|@116g%r%s",g,c,d,&r1,&r2,&r3,&r4,&r5,(const char*)app); + set_row(r,"%3d-",g); + set_row(r,"%3d ********",c); + set_row(r,"@18g#a",_d); + set_row(r++,"@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c",&r1,&r2,&r3,&r4,&r5,app); + if (d.len() > 30) + set_row(r+1, "@49g!@82g!@114g!"); + } + else if (app == 'D') + { + // set_row(r++,"%3d-%3d ********@18g%s@49g|@50g%r@67g%r@82g|@83g%r@100g%r@115g|@116g%r@148g|",g,c,d,&r1,&r2,&r3,&r4,&r5); + set_row(r,"%3d-",g); + set_row(r,"%3d ********",c); + set_row(r,"@18g#a",_d); + set_row(r++,"@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!",&r1,&r2,&r3,&r4,&r5); + if (d.len() > 30) + set_row(r+1, "@49g!@82g!@115g!@148g!"); + } + else + { + // set_row(r++,"%3d-%3d ********@18g%s@49g|@50g%r@67g%r@82g|@83g%r@100g%r@115g|@132g%r@148g|",g,c,d,&r1,&r2,&r3,&r4,&r5); + set_row(r,"%3d-",g); + set_row(r,"%3d ********",c); + set_row(r,"@18g#a",_d); + set_row(r++,"@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!",&r1,&r2,&r3,&r4,&r5); + if (d.len() > 30) + set_row(r+1, "@49g!@82g!@115g!@148g!"); + } + } + if (_stampa_width == 148) + { + set_row(r,"@49g!@82g!@115g!",(const char*)dep); + set_row(r,"@148g!",(const char*)dep); + } + else + set_row(r,"@49g!@82g!@114g!",(const char*)dep); + r++; + if (_stampa_width == 148) + { + set_row(r,"@49g!@82g!@115g!",(const char*)dep); + set_row(r,"@148g!",(const char*)dep); + } + else + set_row(r,"@49g!@82g!@114g!",(const char*)dep); + r++; + + if (app == 'D') + _saldo_finale_tot += r5; + else _saldo_finale_tot -= r5; + + _saldo_dare_tot += r1; + _saldo_avere_tot += r2; + _mov_dare_tot += r3; + _mov_avere_tot += r4; + + return r; +} + +void CG1500_application::stampa_riga_totali(int r) +{ + TString dep = ""; + char app = ' '; + + if (_saldo_finale_tot > 0) + app = 'D'; + else if (_saldo_finale_tot < 0) + { + _saldo_finale_tot = -_saldo_finale_tot; + app = 'A'; + } + + if (_datada == _dataini) //colonna saldo iniziale + { + real r = _saldo_dare_tot - _saldo_avere_tot; + if (r > ZERO) + { + _saldo_dare_tot = r; + _saldo_avere_tot = ZERO; + } + else + { + _saldo_avere_tot = -r; + _saldo_dare_tot = ZERO; + } + /* + if (_tipo_stampa1 == 1) + _nuovo_tot_saldo_a = -_nuovo_tot_saldo_a; + */ + } + if (_stampa_width == 148) + { + set_row(r,"@49g!@82g!@115g!",(const char*)dep); + set_row(r,"@148g!",(const char*)dep); + } + else + set_row(r,"@49g!@82g!@114g!",(const char*)dep); + r++; + if (_verifica == 2) + { + if (_stampa_width == 132) + set_row(r,"***@8gTOTALE GENERALE@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c",&_saldo_dare_tot,&_saldo_avere_tot,&_mov_dare_tot, + &_mov_avere_tot,&_saldo_finale_tot,app); + else if (app == 'D') + set_row(r,"***@8gTOTALE GENERALE@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!",&_saldo_dare_tot,&_saldo_avere_tot, + &_mov_dare_tot,&_mov_avere_tot,&_saldo_finale_tot); + else + set_row(r,"***@8gTOTALE GENERALE@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!",&_saldo_dare_tot,&_saldo_avere_tot, + &_mov_dare_tot,&_mov_avere_tot,&_saldo_finale_tot); + } + else + { + if (_stampa_width == 132) + { + set_row(r++,"@1g****** ********@18gTOTALE GENERALE@49g!@50g%r@67g%r@82g!@83g%r@99g%r@114g!@115g%r %c",&_saldo_dare_tot,&_saldo_avere_tot, + &_mov_dare_tot,&_mov_avere_tot,&_saldo_finale_tot,app); + if ((_tipo_stampa1 == 1 && _datada == _dataini) || _tipo_stampa1 == 2) + set_row(r,"@1g****** ********@18gTOTALE CON SALDI INIZIALI@49g!@82g!@83g%r@99g%r@114g!",&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a); + } + else + { + if (app == 'D') + set_row(r++,"@1g****** ********@18gTOTALE GENERALE@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@116g%r@148g!",&_saldo_dare_tot, + &_saldo_avere_tot,&_mov_dare_tot,&_mov_avere_tot, + &_saldo_finale_tot); + else + set_row(r++,"@1g****** ********@18gTOTALE GENERALE@49g!@50g%r@67g%r@82g!@83g%r@100g%r@115g!@132g%r@148g!",&_saldo_dare_tot, + &_saldo_avere_tot,&_mov_dare_tot,&_mov_avere_tot, + &_saldo_finale_tot); + if ((_tipo_stampa1 == 1 && _datada == _dataini) || _tipo_stampa1 == 2) + set_row(r,"@1g****** ********@18gTOTALE CON SALDI INIZIALI@49g!@82g!@83g%r@100g%r@115g!@148g!",&_nuovo_tot_saldo_d,&_nuovo_tot_saldo_a); + } + } +} + +void CG1500_application::stampa_totali() +{ + TString dep = ""; + real pareggio; + real sbilancio = _tot_dare - _tot_avere; + if (sbilancio > ZERO) //_tot_dare > _tot_avere + pareggio = _tot_avere + sbilancio; + else + { + sbilancio = -sbilancio; + pareggio = _tot_dare + sbilancio; + } + if (_prima_volta) //ho finito di stampare le attivita'/passivita' + _prima_volta = FALSE; + else + _seconda_volta = FALSE; + _gc_prec_dare = _gc_corr_avere = ""; + _cambiato_conto_1 = TRUE; + _cambiato_conto_2 = TRUE; + + set_row(_i++, (const char*)dep); + set_row(_i++, (const char*)dep); + set_row(_i++, (const char*)dep); + set_row(_i++, (const char*)dep); + set_row(_i++, "@39gTOTALE@49g%r@107gTOTALE@117g%r", + &_tot_dare, &_tot_avere); + if (_tot_dare > _tot_avere) + { + set_row(_i++, "@85gSBILANCIO ESERCIZIO IN CORSO@117g%r", + &sbilancio); + set_row(_i++, "@96gTOTALE A PAREGGIO@117g%r",&pareggio); + } + if (_tot_dare < _tot_avere) + { + set_row(_i++, "@17gSBILANCIO ESERCIZIO IN CORSO@49g%r", + &sbilancio); + set_row(_i++, "@28gTOTALE A PAREGGIO@49g%r", &pareggio); + } + _tot_dare = ZERO; + _tot_avere = ZERO; +} + +//per i conti patrimoniali stampo anche lo sbilancio es. precedente +void CG1500_application::stampa_totali_uno(const real& r1,const real& r2) +{ + TString dep = ""; + real pareggio; + real sbilancio = _tot_dare - r1 - (_tot_avere - r2); + real sbilprec = r2 - r1; + /* + if (sbilancio > ZERO) //ho un utile => va stampato tra le passivita' + { + sbilprec = -sbilprec; + pareggio = _tot_avere + sbilancio + sbilprec; + } + else if (sbilancio < ZERO) //ho una perdita => va stampato tra le attivita' cambiato di segno + { + sbilancio = -sbilancio; + pareggio = _tot_dare + sbilancio + sbilprec; + } + */ + if (_prima_volta) //ho finito di stampare le attivita'/passivita' + _prima_volta = FALSE; + else + _seconda_volta = FALSE; + _gc_prec_dare = _gc_corr_avere = ""; + _cambiato_conto_1 = TRUE; + _cambiato_conto_2 = TRUE; + + set_row(_i++, (const char*)dep); + set_row(_i++, (const char*)dep); + set_row(_i++, (const char*)dep); + set_row(_i++, (const char*)dep); + set_row(_i++, "@39gTOTALE@49g%r@107gTOTALE@117g%r", + &_tot_dare, &_tot_avere); + if (sbilancio > ZERO) //ho un utile => va stampato tra le passivita' + { + sbilprec = -sbilprec; + pareggio = _tot_avere + sbilancio + sbilprec; + if (sbilprec != ZERO) + set_row(_i++, "@83gSBILANCIO ESERCIZIO PRECEDENTE@117g%r", + &sbilprec); + set_row(_i++, "@85gSBILANCIO ESERCIZIO IN CORSO@117g%r", + &sbilancio); + set_row(_i++, "@96gTOTALE A PAREGGIO@117g%r",&pareggio); + } + else if (sbilancio < ZERO) //ho una perdita => va stampato tra le attivita' + { + sbilancio = -sbilancio; + pareggio = _tot_dare + sbilancio + sbilprec; + if (sbilprec != ZERO) + set_row(_i++, "@15gSBILANCIO ESERCIZIO PRECEDENTE@49g%r", + &sbilprec); + set_row(_i++, "@17gSBILANCIO ESERCIZIO IN CORSO@49g%r", + &sbilancio); + set_row(_i++, "@28gTOTALE A PAREGGIO@49g%r", &pareggio); + } + else //sbilancio es. in corso == 0 + { + sbilprec = -sbilprec; + if (sbilprec > ZERO) //va stampato sotto le passivita' + { + pareggio = _tot_avere + sbilprec; + set_row(_i++, "@83gSBILANCIO ESERCIZIO PRECEDENTE@117g%r", + &sbilprec); + set_row(_i++, "@96gTOTALE A PAREGGIO@117g%r", &pareggio); + } + else if (sbilprec < ZERO) + { + sbilprec = -sbilprec; + pareggio = _tot_dare + sbilprec; + set_row(_i++, "@15gSBILANCIO ESERCIZIO PRECEDENTE@49g%r", + &sbilprec); + set_row(_i++, "@28gTOTALE A PAREGGIO@49g%r",&pareggio); + } + } + _tot_dare = ZERO; + _tot_avere = ZERO; +} + +void CG1500_application::stampa_prima_colonna(int g, int c, long s, + const char* desc, const real& saldo) +{ + char dep = '*'; + + if (_codici) //sono stampate solo le descrizioni dei conti + { + if (!_totali) + { + if (c != 0 && s == 0) + set_row(_i, "%-.44s @44g *** @49g%r @66g%c", desc, &saldo, dep); + else set_row(_i, "%-.48s @49g%r @66g%c", desc, &saldo, dep); + } + else if ( !(c == 0 && s == 0) ) //se cioe' non e' un gruppo + { + if (s == 0) //se e' un conto + set_row(_i, "%-.44s @44g *** @49g%r @66g%c", desc, &saldo, dep); +else set_row(_i, "%-.48s @49g%r @66g%c", desc, &saldo, dep); + } + } +else +{ + if (_totali && c == 0 && s == 0l) + return; + else if ( c == 0 && s == 0l ) + { + set_row(_i, "%3d ", g); + set_row(_i, "@17g%-.31s @49g%r @66g%c", desc, &saldo, dep); + } + else if (s == 0l) + { + set_row(_i, "%3d ", g); + set_row(_i, "%3d ", c); + set_row(_i, "@17g%-.31s @49g%r @66g%c", desc, &saldo, dep); + } + else + { + set_row(_i, "%3d ", g); + set_row(_i, "%3d ", c); + set_row(_i, "%6ld ", s); + set_row(_i, "@17g%-.31s @49g%r @66g%c", desc, &saldo, dep); + } +} +} + +void CG1500_application::stampa_seconda_colonna(int g, int c, long s, +const char* desc, const real& saldo) +{ + char dep = '*'; + + if (_codici) //sono stampate solo le descrizioni dei conti + { + if (!_totali) + { + if (c != 0 && s == 0) + set_row(_i, "@66g%c@69g%-.43s @112g ***@117g%r", dep, desc, &saldo); + else set_row(_i, "@66g%c@69g%-.47s @117g%r", dep, desc, &saldo); + } + else if ( !(c == 0 && s == 0) ) + { + if (s == 0) //se e' un conto + set_row(_i, "@66g%c @69g%-.43s @112g *** @117g%r", dep, desc, &saldo); +else set_row(_i, "@66g%c @69g%-.47s @117g%r", dep, desc, &saldo); + } + } +else +{ + if (_totali && c == 0 && s == 0l) + return; + else if ( c == 0 && s == 0l ) + { + set_row(_i, "@66g%c@69g%3d ", dep, g); + set_row(_i, "@86g%-.30s @117g%r", desc, &saldo); + } + else if (s == 0l) + { + set_row(_i, "@66g%c@69g%3d ", dep, g); + set_row(_i, "%3d", c); + set_row(_i, "@86g%-.30s @117g%r", desc, &saldo); + } + else + { + set_row(_i, "@66g%c@69g%3d ", dep, g); + set_row(_i, "%3d ", c); + set_row(_i, "%6ld ",s); + set_row(_i, "@86g%-.30s @117g%r", desc, &saldo); + } +} +} + +print_action CG1500_application::postprocess_page(int file, int counter) +{ + if (_bilancio == 1) + { + if ( _eof1 && _eof2 && _eof3 && _eof4 && _eof5 && _eof6 && _salto_pagina1 ) + return NEXT_PAGE; + } + else //bilancio di verifica + { + if (_verifica == 3) + { + if (_buff == NULL) + return NEXT_PAGE; + } + else if (_eof1) + return NEXT_PAGE; + } + return REPEAT_PAGE; +} + +TDate CG1500_application::UltimaData(int g, int c, long s, int anno) +{ + TDate uldata; + TLocalisamfile saldi(LF_SALDI, FALSE); //il parametro a false permette di usare un record corrente del file saldi differente a quello del file tmp + + saldi.zero(); + if (_annoes != 0) + saldi.put(SLD_ANNOES, anno); + saldi.put(SLD_GRUPPO,g); + if (c != 0) + saldi.put(SLD_CONTO, c); + if (s != 0) + saldi.put(SLD_SOTTOCONTO, s); + saldi.read(); + if (saldi.bad()) + saldi.zero(); + uldata = saldi.get(SLD_DATAULMOV); + + return uldata; +} + +//Non ho potuto usare quella di TConto!!! Chiedere a me! +const char* CG1500_application::DescrizioneConto(int g, int c, long s, + char tipocf) +{ + TString80 ragsoc; + const char* desc = NULL; + TLocalisamfile pconti(LF_PCON,FALSE); + TLocalisamfile clifo (LF_CLIFO); + + pconti.zero(); + pconti.put(PCN_GRUPPO, g); + if (c != 0) + pconti.put(PCN_CONTO, c); + if (s != 0) + pconti.put(PCN_SOTTOCONTO, s); + pconti.read(); + if (pconti.good()) + tmp = pconti.get(PCN_DESCR); + else + { + clifo.setkey(1); //occorre settare la chiave 1, anche se di solito e' di default, poiche' nella create il file clifo e' stato aperto con la chiave 3 + clifo.zero(); + clifo.put(CLI_CODCF, s); + clifo.put(CLI_TIPOCF,tipocf); + if (clifo.read() == NOERR) + { + char tipoa = clifo.get_char("TIPOAPER"); + if (tipoa == 'F') //persona fisica + { + TString80 cognome, nome; + ragsoc = clifo.get("RAGSOC"); + cognome = ragsoc.mid(0,30); + nome = ragsoc.mid(30,20); + cognome.trim(); nome.trim(); + ragsoc = cognome; + ragsoc << " " << nome; + desc = ragsoc; + } + else + desc = clifo.get("RAGSOC"); + tmp = desc; + } + else + tmp = ""; + } + return tmp; +} + +bool CG1500_application::user_create() +{ + _stampa_width = 132; + _rel = new TRelation(LF_CLIFO); + _cur = new TCursor (_rel,"",3); + _mov = new TLocalisamfile(LF_MOV); + _rmov = new TLocalisamfile(LF_RMOV); + _clifo = new TLocalisamfile(LF_CLIFO); + _com = new TLocalisamfile(LF_COMUNI); + _pcn = new TLocalisamfile(LF_PCON); + _saldi = new TLocalisamfile(LF_SALDI); + _nditte = new TLocalisamfile(LF_NDITTE); + _anag = new TLocalisamfile(LF_ANAG); + _caus = new TLocalisamfile(LF_CAUSALI); + _esc = new TTable("ESC"); + _d = new TParagraph_string("",30); + _tmp_saldi_att = NULL; + _tmp_saldi_pass = NULL; + _tmp_saldi_costi = NULL; + _tmp_saldi_ricavi = NULL; + _tmp_saldi_conti_uno = NULL; + _tmp_saldi_conti_due = NULL; + return TRUE; +} + +bool CG1500_application::user_destroy() +{ + delete _rel; + delete _cur; + delete _com; + delete _pcn; + delete _mov; + delete _rmov; + delete _clifo; + delete _saldi; + delete _nditte; + delete _anag; + delete _caus; + delete _esc; + delete _d; + + if (_tmp_saldi_att) delete _tmp_saldi_att; + if (_tmp_saldi_pass) delete _tmp_saldi_pass; + if (_tmp_saldi_costi) delete _tmp_saldi_costi; + if (_tmp_saldi_ricavi) delete _tmp_saldi_ricavi; + if (_tmp_saldi_conti_uno) delete _tmp_saldi_conti_uno; + if (_tmp_saldi_conti_due) delete _tmp_saldi_conti_due; + return TRUE; +} + +void CG1500_application::leggi_pcon() +{ + TLocalisamfile pconti(LF_PCON); + TToken_string gc(10); + + for (pconti.first(); !pconti.eof(); pconti.next()) + { + gc.restart(); + int gruppo = pconti.get_int(PCN_GRUPPO); + int conto = pconti.get_int(PCN_CONTO); + long sottoconto = pconti.get_long(PCN_SOTTOCONTO); + if ( (sottoconto == 0l) && (conto != 0) ) //si tratta di un conto + { + char tipocf = pconti.get_char(PCN_TMCF); + if (tipocf == 'C') + { + gc.add(gruppo,0); + gc.add(conto,1); + _clienti.add(gc); + } + else if (tipocf == 'F') + { + gc.add(gruppo,0); + gc.add(conto,1); + _fornitori.add(gc); + } + } + } +} + +bool CG1500_application::set_print(int) +{ + TMask m ("cg1500a"); + KEY tasto; + /* + { + TConfig conf(CONFIG_DITTA); + + _causale_ap = conf.get("CoCaAp"); + _causale_chi = conf.get("CoCaCh"); + } + */ + m.set_handler (F_VERIFICA, my_handler); + m.set_handler (F_BILANCIO, mask_bilancio); + m.set_handler (F_STAMPA1, mask_bilancio); + m.set_handler (F_STAMPA, mask_bilancio); + m.set_handler (F_DATALIM, mask_datalim); + m.set_handler (F_DATADA, mask_date); + m.set_handler (F_DATAA, mask_date); + m.set_handler (F_ANNO, mask_anno); + + tasto = m.run(); + if (tasto == K_ENTER) + { + _annoes = atoi(m.get(F_ANNO)); + _bilancio = atoi(m.get(F_BILANCIO)); + _data = m.get(F_DATASTAMPA); + _stampa_mov_prov = m.get_int(F_STAMPAMPROV); + if (_bilancio == 1) + { + _prog = new TProgind(_pcn->items(),"Elaborazione in corso... prego attendere",FALSE); + _totali = (bool)(m.get(F_TOTALI) == "X"); + _codici = (bool)(m.get(F_CODICI) == "X"); + _saldo = (bool)(m.get(F_SALDO) == "X"); + _tipo_stampa = atoi(m.get(F_STAMPA)); + if (_tipo_stampa == 1) + { + if (_annoes != 0) + _dataini = InizioEsercizio(_annoes); + else _dataini = _inizioEs; + _datalim = m.get(F_DATALIM); + //_stampa_mov_prov = (bool)(m.get(F_STAMPAMPROV) == "X"); + } + bil_sez_contr(); + } + else + { + _stampa_width = atoi(m.get(F_MODULO)); + if (_stampa_width == 1) + _stampa_width = 132; + else _stampa_width = 148; //perche' questo e' in realta' il margine dx (vedi es. di stampa AS/400) + _verifica = atoi(m.get(F_VERIFICA)); + if ( (_verifica == 1)||(_verifica == 2) ) + _prog = new TProgind(_pcn->items(),"Elaborazione in corso... prego attendere",FALSE); + _tipo_stampa1 = atoi(m.get(F_STAMPA1)); + if (_tipo_stampa1 == 1) + { + if (_annoes != 0) + _dataini = InizioEsercizio(_annoes); + else _dataini = _inizioEs; + _datada = m.get(F_DATADA); + _dataa = m.get(F_DATAA); + //_stampa_mov_prov = (bool)(m.get(F_STAMPAMPROV) == "X"); + } + if ( (_verifica == 1)||(_verifica == 2) ) + { + _stampav = atoi(m.get(F_STAMPAV)); + bil_verifica(); + } + else + { + _situazione = m.get(F_SITUAZIONE); + _stampac = atoi(m.get(F_STAMPAC)); + _ordinamento = atoi(m.get(F_ORDINAMENTO)); + + // _cur->setkey(3); + + if (_situazione.not_empty()) + _cur->setfilter(format("TIPOCF = \"%s\"",(const char*)_situazione)); + else + _cur->setfilter(""); + + _prog = new TProgind(_cur->items(),"Elaborazione in corso... prego attendere",FALSE); + + _clienti.destroy(); + _fornitori.destroy(); + leggi_pcon(); + crea_sort_clifo(); + _sort->endsort(); + delete _cf; + } + } + delete _prog; + return TRUE; + } + return FALSE; +} + +TRectype& look_com (const char * cod, TLocalisamfile *comuni) +{ + comuni->zero(); + comuni->put(COM_COM, cod); + comuni->read(); + if (comuni->bad()) + comuni->zero(); + + return comuni->curr(); +} + +void CG1500_application::get_dati_ditta() +{ + TLocalisamfile nditte(LF_NDITTE); + TLocalisamfile anag(LF_ANAG); + TString codanagr; + TString tipoa; + + nditte.zero(); + nditte.put(NDT_CODDITTA, get_firm()); + nditte.read(); + + if (nditte.bad()) nditte.zero(); + + codanagr = nditte.get(NDT_CODANAGR); + tipoa = nditte.get(NDT_TIPOA); + _ragsoc = nditte.get(NDT_RAGSOC); + + anag.setkey(1); + anag.zero(); + anag.put (ANA_TIPOA, tipoa); + anag.put (ANA_CODANAGR, codanagr); + anag.read(); + if (anag.bad()) anag.zero(); + + _cofi = anag.get(ANA_COFI); + _paiva = anag.get(ANA_PAIV); + _comunefis = anag.get(ANA_COMRF); + + if (_comunefis.empty()) + _comunefis = anag.get(ANA_COMRES); + + TRectype dep = look_com (_comunefis, _com); + + _comunefis = dep.get(COM_DENCOM); + _provfis = dep.get(COM_PROVCOM); + _cap = dep.get(COM_CAPCOM); + if (_comunefis.empty()) + { + _viafis = anag.get(ANA_INDRF); + _viafis.rtrim(); + _viafis << " " << anag.get (ANA_CIVRF); + } + else + { + _viafis = anag.get(ANA_INDRES); + _viafis.rtrim(); + _viafis << " " << anag.get (ANA_CIVRES); + } +} + +int CG1500_application::stampa_intestazione_ditta() +{ + int r = 1; + TString codice_ditta; + TString riga(_stampa_width); + //TString riga(132); + + get_dati_ditta(); + codice_ditta << get_firm(); + + set_header (r, "Ditta %s %s %s %s %s %s", (const char*)codice_ditta, + (const char*)_ragsoc, (const char*)_viafis, + (const char*)_cap, (const char*)_comunefis, + (const char*)_provfis); + r++; + printer().setdate(_data); + riga = "Data @< Pag. @#"; + riga.right_just(_stampa_width-5); + //riga.right_just(127); + riga.overwrite (format ("Partita iva %s Codice fiscale %s", (const char*)_paiva, (const char*)_cofi)); + set_header (r, "%s", (const char*) riga); + r++; + + return r; +} + +void CG1500_application::preprocess_header() +{ + int r; + + reset_header(); + r = stampa_intestazione_ditta(); + + if (_bilancio == 1) //bilancio a sezioni contrapposte + { + TString riga (132); + TDate data_da; + TString data; + TString data_lim = _datalim.string(); + + set_header(r, "STAMPA BILANCIO A SEZIONI CONTRAPPOSTE"); + if (_tipo_stampa == 1) + { + data_da = _dataini.string(); + data = _datalim.string(); + set_header(r,"@41gdalla data %s alla data %s", (const char*) data_da, + (const char*) data); + } + else if (_tipo_stampa == 2) + set_header(r,"@41gall'ultima immissione Es. %d", _annoes); + //else set_header(r, "@41gall'ultima immissione Es. Precedente"); + + //modifica del 20/04/1995 + set_header(r,"@85gAnno comp. %d", _annoes); + + r++; + riga.fill('-'); + set_header(r, (const char*)riga); + r++; + riga = ""; + set_header(r, (const char*)riga); + } + else // bilancio di verifica + { + TString riga (_stampa_width); + TString16 datada = _datada.string(); + TString16 dataa = _dataa.string(); + if (_verifica == 1) + set_header(r, "STAMPA BILANCIO DI VERIFICA"); + else if (_verifica == 2) + set_header(r, "STAMPA SALDI DI MASTRO"); + else + { + if (_situazione == "C") + set_header(r, "SITUAZIONE CONTABILE CLIENTI"); + else if (_situazione == "F") + set_header(r, "SITUAZIONE CONTABILE FORNITORI"); + else set_header(r,"SITUAZIONE CONTABILE CLIENTI E FORNITORI"); + } + + if (_tipo_stampa1 == 1) + { + set_header(r,"@42gdalla data %s alla data %s", (const char*)datada, + (const char*) dataa); + //modifica del 20/04/1995 + if (_annoes != 0) //se l'anno e' 0 non si considera la competenza + set_header(r,"@86gAnno comp. %d", _annoes); + } + else if (_tipo_stampa1 == 2) + { + set_header(r,"@42gall'ultima immissione Es. %d", _annoes); + //modifica del 20/04/1995 + set_header(r,"@86gAnno comp. %d", _annoes); + } + + if ( (_verifica == 1)||(_verifica == 2) ) + { + if (_stampav == 1) + set_header(r,"@103gTutti i conti movimentati"); + else if (_stampav == 2) + set_header(r,"@103gConti con saldo <> 0"); + else set_header(r,"@103gTutti i conti"); + } + else + { + if (_stampac == 1) + set_header(r,"@103gTutti i conti movimentati"); + else set_header(r,"@103gConti con saldo <> 0"); + } + + r++; + riga.fill('-'); + set_header(r, (const char*)riga); + r++; + + if ( ((_datada == _dataini)&&(_tipo_stampa1 == 1))||(_tipo_stampa1 != 1) ) + { + if ( (_verifica == 1)||(_verifica == 3) ) + set_header(r,"@7g!@16g!@49g!@58gSALDO INIZIALE@82g!@88gMOVIMENTI DEL PERIODO"); + else + set_header(r,"@7g!@49g!@58gSALDO INIZIALE@82g!@88gMOVIMENTI DEL PERIODO"); + } + else if (_tipo_stampa1 == 1) + if ( (_verifica == 1)||(_verifica == 3) ) + set_header(r,"@7g!@16g!@49g!@55gPROGRESSIVI PRECEDENTI@82g!@88gMOVIMENTI DEL PERIODO"); + else + set_header(r,"@7g!@49g!@55gPROGRESSIVI PRECEDENTI@82g!@88gMOVIMENTI DEL PERIODO"); + + if (_stampa_width == 148) + set_header(r,"@115g!@130gSALDO@148g!"); + else + set_header(r,"@114g!"); + r++; + + if ( (_verifica == 1)||(_verifica == 3) ) + { + if (_stampa_width == 132) + { + set_header(r++,"@2gcod. ! ultima !@49g!@50g%.32s@82g!@83g%.32s@114g!@121gSALDO",(const char*)riga, (const char*)riga); + set_header(r++,"@2gconto! data ! denominazione@49g!@57gDare@66g!@73gAvere@82g!@89gDare@98g!@104gAvere@114g!"); + } + else + { + set_header(r++,"@2gcod. ! ultima !@49g!@50g%.32s@82g!@83g%.32s@115g!%.32s@148g!",(const char*)riga, (const char*)riga, (const char*)riga); + set_header(r++,"@2gconto! data ! denominazione@49g!@57gDare@66g!@73gAvere@82g!@91gDare@99g!@106gAvere@115g!@124gDare@132g!@139gAvere@148g!"); + } + } + else + { + if (_stampa_width == 132) + { + set_header(r++,"@2gcod. !@49g!@50g%.32s@82g!@83g%.32s@114g!@121gSALDO",(const char*)riga, (const char*)riga); + set_header(r++,"@1gmastro!descrizione@49g!@57gDare@66g!@73gAvere@82g!@89gDare@98g!@104gAvere@114g!"); + } + else + { + set_header(r++,"@2gcod. !@49g!@50g%.32s@82g!@83g%.32s@115g!%.32s@148g!",(const char*)riga, (const char*)riga, (const char*)riga); + set_header(r++,"@1gmastro!descrizione@49g!@57gDare@66g!@73gAvere@82g!@91gDare@99g!@106gAvere@115g!@124gDare@132g!@139gAvere@148g!"); + } + } + set_header(r, (const char*)riga); + if (_stampa_width == 148) + set_header(r,"@148g!"); + } +} + +int cg1500 (int argc, char* argv[]) +{ + + CG1500_application a; + + a.run(argc, argv, "Stampa bilanci"); + + return 0; +} + +/* + if (!compensa) + { + if ( (indbil_conto==1)||(indbil_conto==3) ) + if (saldo > ZERO) //saldo in dare + _indbil = indbil_conto; + else //saldo in avere + { + if (indbil_conto == 1) + _indbil = 2; + else _indbil = 4; + saldo = -saldo; + } + if ( (indbil_conto==2)||(indbil_conto==4) ) + if (saldo < ZERO) + { + _indbil = indbil_conto; + saldo = -saldo; + } + else + if (indbil_conto == 2) + _indbil = 1; + else _indbil = 3; + } + else //e' richiesta la compensazione + { + if ( (indbil_conto==1)||(indbil_conto==3) ) + _indbil = indbil_conto; + if ( (indbil_conto==2)||(indbil_conto==4) ) + { + _indbil = indbil_conto; + saldo = -saldo; + } + } + */ diff --git a/cg/cg4300.cpp b/cg/cg4300.cpp index acfeae560..dca3378f8 100755 --- a/cg/cg4300.cpp +++ b/cg/cg4300.cpp @@ -1,731 +1,731 @@ -// ------------------------------------------------------------ -// Calcolo liquidazioni -// Part 1: interfaccia -// fv 21-1-94 -// ------------------------------------------------------------ - -#include -#include -#include -#include -#include -#include - -#include "cg4300.h" -#include "cg4300a.h" - -#include - -real TLiquidazione_app::CENTO(100.0); - -inline TLiquidazione_app& app() -{ return (TLiquidazione_app&)main_app(); } - -TLiquidazione_app::TLiquidazione_app(int m) : -_ditte(NULL), _selected(10000), -_year(4), _nomiditte(100), _menu(m), _firm_bookmark(-1) -{ - _isprint = _is_interactive = _canprint = TRUE; - _isplafond = _printonly = _is_visliq = FALSE; - _isvent = _isagricolo = _isbenzinaro = _isviaggio = FALSE; - _row = 1; _what = all; _comp_acconto = FALSE; - _isriepilogo = FALSE; _calcall = FALSE; - _isfinal = _isregis = FALSE; - _recalc = needed; -} - -bool TLiquidazione_app::user_create() -{ - // vediamo se c'e' il messaggio per calcolare in batch - TMailbox mail; - TProgind* pnd = NULL; - TMessage* msg = mail.next_s("RCL"); - TToken_string subj(36); - _is_interactive = msg == NULL; - _recalc_only = FALSE; - bool is_header = TRUE; - int headerlen; - TDate printdate; - TString filename; - long ditta; - bool nocalc = FALSE; - - _prind = NULL; - - if (msg != NULL) subj = msg->body(); - - if (_is_interactive) - pnd = new TProgind (3,"Preparazione archivi\nPrego attendere", - FALSE, TRUE, 30); - else begin_wait(); - - _nditte = new TRelation(LF_NDITTE); - _nditte->add(LF_ATTIV,"CODDITTA=CODDITTA"); - _nditte_r = &(_nditte->curr()); - _att_r = &(_nditte->curr(LF_ATTIV)); - - _ditte = new TArray_sheet(-1, -1, 0, 0, "Selezione Ditte", - "@1|Cod.@5R|Ragione Sociale@50|Vers."); - _n_ditte = 0l; - - // prevediamo la data che usera'; se calcola la liq. di un altro anno - // si fottera' la frequenza versamenti - - if (_is_interactive) - { - TDate oggi(TODAY); - _year.format("%d",oggi.year()); - } - else // parse messaggio - { - _year = subj.get(0); - _month = subj.get_int(1); - ditta = subj.get_long(2); - char rcl = *(subj.get(3)); - _recalc_only = rcl == 'C'; - _is_visliq = rcl == 'V'; - // S/s = stampa senza ricalcolo (minuscolo = definitivo) - // L/l = stampa con ricalcolo se necessario (minuscolo = definitivo) - // C = solo ricalcolo - // V = stampa ed ev. ricalcolo per visualizzazione - // s o l minuscoli = registro bollato (setta B1) - _isregis = (rcl == 'l' || rcl == 'L' || - rcl == 'S' || rcl == 's'); // stampa per registri - _isfinal = rcl == 'l' || rcl == 's'; // se l minuscolo, definitivo - nocalc = rcl == 'S' || rcl == 's'; - printdate = subj.get(4); - filename = subj.get(5); - headerlen = subj.get_int(6); - is_header = subj.items() == 7; - //modifica del 5/07/1995 - int f = printer().formlen(); - printer().formlen(f - headerlen); - //fine - } - - if(pnd) pnd->addstatus(1); - - _rel = new TRelation(LF_MOV); - _rel->add(LF_RMOVIVA,"NUMREG=NUMREG"); - _rel->add(LF_CAUSALI,"CODCAUS=CODCAUS"); - - _cur = new TCursor(_rel, "", 2); - - _pim = new TTable("PIM"); - _pum = new TTable("PUM"); - _pam = new TTable("PAM"); - _pom = new TTable("POM"); - _ppa = new TTable("PPA"); - _plm = new TTable("PLM"); - _lim = new TTable("LIM"); - _lam = new TTable("LAM"); - _pla = new TTable("%PLA"); - _reg = new TTable("REG"); - _iva = new TTable("%IVA"); - _del = new TTable("%DEL"); - _lia = new TTable("%LIA"); - - _mov = &_cur->file(LF_MOV); - _rmoviva = &_cur->file(LF_RMOVIVA); - - _pim_r = &(_pim->curr()); - _plm_r = &(_plm->curr()); - _pum_r = &(_pum->curr()); - _pam_r = &(_pam->curr()); - _pom_r = &(_pom->curr()); - _iva_r = &(_iva->curr()); - _del_r = &(_del->curr()); - _lim_r = &(_lim->curr()); - _lam_r = &(_lam->curr()); - _pla_r = &(_pla->curr()); - _ppa_r = &(_ppa->curr()); - _reg_r = &(_reg->curr()); - _rmoviva_r = &(_cur->curr(LF_RMOVIVA)); - _mov_r = &(_mov->curr()); - - // ACHTUNG: tutti i _codatt (codici attivita') sono - // in realta' composti dal codice attivita' piu' il - // tipo attivita' (1 o 2) - // sarebbe piu' saggio fare 2 campi ma ci vuole 1 vita - - _pim_anno = new TRecfield(*_pim_r,"CODTAB",0,3); - _pim_codatt = new TRecfield(*_pim_r,"CODTAB",4,9); - _pim_codreg = new TRecfield(*_pim_r,"CODTAB",10,12); - _pim_mese = new TRecfield(*_pim_r,"CODTAB",13,14); - _pim_tipocr = new TRecfield(*_pim_r,"CODTAB",15,15); - _pim_codiva = new TRecfield(*_pim_r,"CODTAB",16,19); - _pim_tipodet = new TRecfield(*_pim_r,"CODTAB",20,20); - _pum_anno = new TRecfield(*_pum_r,"CODTAB",0,3); - _pum_codatt = new TRecfield(*_pum_r,"CODTAB",4,9); - _pum_mese = new TRecfield(*_pum_r,"CODTAB",10,11); - _pam_anno = new TRecfield(*_pam_r,"CODTAB",0,3); - _pam_codatt = new TRecfield(*_pam_r,"CODTAB",4,9); - _pam_mese = new TRecfield(*_pam_r,"CODTAB",10,11); - _pom_anno = new TRecfield(*_pom_r,"CODTAB",0,3); - _pom_codatt = new TRecfield(*_pom_r,"CODTAB",4,9); - _pom_mese = new TRecfield(*_pom_r,"CODTAB",10,11); - _ppa_year = new TRecfield(*_ppa_r,"CODTAB",0,3); - _ppa_codatt = new TRecfield(*_ppa_r,"CODTAB",4,9); - _ppa_month = new TRecfield(*_ppa_r,"CODTAB",10,11); - _ppa_kind = new TRecfield(*_ppa_r,"CODTAB",12,12); - - _plm_anno = new TRecfield(*_plm_r,"CODTAB",0,3); - _plm_codatt = new TRecfield(*_plm_r,"CODTAB",4,9); - _plm_mese = new TRecfield(*_plm_r,"CODTAB",10,11); - - _pla_ditta = new TRecfield(*_pla_r,"CODTAB",0,4); - _pla_anno = new TRecfield(*_pla_r,"CODTAB",5,8); - _pla_codatt = new TRecfield(*_pla_r,"CODTAB",9,14); - - _del_ditta = new TRecfield(*_del_r,"CODTAB",0,4); - _del_anno = new TRecfield(*_del_r,"CODTAB",5,8); - _del_mese = new TRecfield(*_del_r,"CODTAB",9,10); - _del_tipo = new TRecfield(*_del_r,"CODTAB",11,11); - - _lim_anno = new TRecfield(*_lim_r,"CODTAB",0,3); - _lim_mese = new TRecfield(*_lim_r,"CODTAB",4,6); - - _lam_anno = new TRecfield(*_lam_r,"CODTAB",0,3); - _lam_mese = new TRecfield(*_lam_r,"CODTAB",4,6); - - __firm = TApplication::get_firm(); - - if (pnd) pnd->addstatus(1); - - if (_is_interactive) - { - build_nomiditte(pnd); - build_ditte_sheet(all); - } - - if (pnd) pnd->addstatus(1); - - TApplication::set_firm(__firm); - set_real_picture(REAL_PICTURE); - - if (!_is_interactive) - { - TTemp_window w(TASK_WIN); - if (_recalc_only) - _isprint = FALSE; - //else printer().set_export_file(filename, is_header, headerlen); - else printer().set_export_file(filename, is_header); - - // calcola liquidazione - printer().setdate(printdate); - _recalc = nocalc ? never : needed; - TApplication::set_firm(ditta); - - if (!look_lia()) - { end_wait(); return FALSE; } - - _nditte->zero(); - _nditte_r->put("CODDITTA", ditta); - _nditte->read(); - _freqviva = _lia->get("S7"); - - TRectype& mov = _cur->curr(); - TRectype from(_cur->curr()); from.zero(); - TRectype to(from); - TDate f(1, 1, atoi(_year)); - TDate t(1, _month == 13 ? 12 : _month, atoi(_year)); - t.set_end_month(); - from.put(MOV_DATAREG, f); - to.put(MOV_DATAREG, t); - _cur->setregion(from, to); - _canprint = is_month_ok_strict(_month) || _month == 13; - - //modifica del 03/05/1995 - int need_refresh = FALSE; - for (int m = 1; m < _month; m++) - if (is_month_ok_strict(m) && (!look_lim(m) || !_lim->get_bool("B0"))) - { - need_refresh = TRUE; - break; - } - - if (need_refresh) _recalc = ever; - - for (int mese = 1; mese < _month; mese++) // fino a 13 compreso - if (is_month_plain(mese) || _recalc == ever) - update_firm(mese); - - if (is_month_plain(_month) || _month == 13) - update_firm(_month); - - if (_isprint && _descr_arr.items() > 0) - print(); - - // se ci sono altri mesi dopo l'ultimo calcolato, invalida il - // flag 'calcolato' del primo, per causare il ricalcolo dei - // successivi (evitando problemi per credito precedente) - for (m = _month+1; m <= 13; m++) - if (look_lim(m)) - { - _lim->put("B0",""); - _lim->rewrite(); - break; - } - - TApplication::set_firm(__firm); - end_wait(); - } - else delete pnd; - - return _is_interactive; -} - -bool TLiquidazione_app::user_destroy() -{ - delete _ditte; - - delete _pim_anno; - delete _pim_codreg; - delete _pim_mese; - delete _pim_tipocr; - delete _pim_codiva; - delete _ppa_year; - delete _ppa_codatt; - delete _ppa_month; - delete _ppa_kind; - delete _plm_anno; - delete _plm_codatt; - delete _plm_mese; - delete _pum_anno; - delete _pum_codatt; - delete _pum_mese; - delete _pam_codatt; - delete _pam_anno; - delete _pam_mese; - delete _pom_codatt; - delete _pom_anno; - delete _pom_mese; - delete _lim_anno; - delete _lim_mese; - delete _lam_anno; - delete _lam_mese; - delete _pla_anno; - delete _pla_codatt; - delete _pim_codatt; - delete _del_ditta; - delete _del_anno; - delete _del_mese; - delete _del_tipo; - - delete _pim; - delete _pum; - delete _pam; - delete _pom; - delete _ppa; - delete _plm; - delete _lim; - delete _lam; - delete _pla; - delete _del; - - delete _nditte; - delete _rel; - delete _cur; - - return TRUE; -} - -bool TLiquidazione_app::set_print(int) -{ - _descr_arr.destroy(); - _errors.destroy(); - - switch(_menu) - { - case 1: // liquidazione - _isprint = TRUE; - while (set_liquidazione()) - { - if (_selected.ones() > 0l) - { - TRectype& mov = _cur->curr(); - TRectype from(_cur->curr()); from.zero(); - TRectype to(from); - TDate f(1, 1, atoi(_year)); - TDate t(1, _month == 13 ? 12 : _month, atoi(_year)); - t.set_end_month(); - from.put(MOV_DATAREG, f); - to.put(MOV_DATAREG, t); - _cur->setregion(from, to); - - return recalc_all() && _isprint; - } - else warning_box("Nessuna ditta selezionata!"); - } - break; - case 2: // estrazione deleghe - _isprint = FALSE; - build_ditte_sheet(all); - while (set_deleghe()) - { - if (_calcall || _selected.ones() > 0l) - { - TRectype & mov = _cur->curr(); - TRectype from(_cur->curr()); from.zero(); - TRectype to(from); - TDate f(1, _recalc == one ? _month : 1, atoi(_year)); - TDate t(1, _month == 13 ? 12 : _month, atoi(_year)); - t.set_end_month(); - from.put(MOV_DATAREG, f); - to.put(MOV_DATAREG, t); - _cur->setregion(from, to); - extract_deleghe(); - return _isprint; - } - else warning_box("Nessuna ditta selezionata!"); - } - break; - case 3: // calcolo acconto - _isprint = TRUE; - build_ditte_sheet(all); - real inf; real ina; // cotale obbrobrio non fu da me cercato, ne' mai condiviso - while (set_acconto(inf, ina)) - { - if (_calcall || _selected.ones() > 0l) - { - TRectype & mov = _cur->curr(); - TRectype from(_cur->curr()); from.zero(); - TRectype to(from); - TDate f(1, _recalc == one ? _month : 1, atoi(_year)); - TDate t(1, _month == 13 ? 12 : _month, atoi(_year)); - t.set_end_month(); - from.put(MOV_DATAREG, f); - to.put(MOV_DATAREG, t); - _cur->setregion(from, to); - recalc_acconti(inf, ina); - return _isprint; - } - else warning_box("Nessuna ditta selezionata!"); - } - break; - } - return FALSE; -} - -long TLiquidazione_app::select_firm_range(long from, long to, wht freq) -{ - if (to == 0l) to = 99999L; - - for (int i = 0; i < _ditte->items(); i++) - { - if (_ditte->disabled(i)) - continue; - - TToken_string& d = _ditte->row(i); - const char vers = d.get_char(3); - if (vers == '?' || (freq == mnt && vers == 'T') || (freq == trimestre && vers == 'M')) - continue; - - const long cod = d.get_long(1); - if (cod >= from && cod <= to) - { - _selected.set(i); - _ditte->check(i); - } - else - { - _selected.set(i,FALSE); - _ditte->uncheck(i); - } - } - - return _selected.ones(); -} - -// ----------------------------------------------- handlers - -bool TLiquidazione_app::ch_year_handler(TMask_field& f, KEY key) -{ - if (key == K_TAB && f.focusdirty()) - { - app().begin_wait(); - app().set_year(f.get()); - app().build_nomiditte(); - app().build_ditte_sheet(f.mask().source_file() == "cg4300a.msk" ? - (wht)atoi(f.mask().get(CG43_RDB_VERS)) : - all); - app().end_wait(); - } - return TRUE; -} - -void TLiquidazione_app::build_nomiditte(TProgind* pnd) -{ - _nomiditte.destroy(); - // ricostruire _nomiditte e rifare build_ditte_sheet - TLocalisamfile& dt = _nditte->lfile(); - - for (dt.first(); !dt.eof(); dt.next()) - { - // check no archivi - bool good = prefix().exist(dt.get_long("CODDITTA")); - - if (good) - { - // check no parametri liquidazione - if (!look_lia(dt.get_long("CODDITTA"))) good = FALSE; - } - else continue; - - TToken_string* d = new TToken_string(64); - - // add record - d->add(dt.get("CODDITTA")); - d->add(dt.get("RAGSOC")); - if (good) d->add(_lia->get("S7")); - else d->add("??"); - - _nomiditte.add(d); - } - if (pnd) pnd->addstatus(1); -} - -bool TLiquidazione_app::to_ditt_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask(); - if (key == K_F9) - { - app().to_butt_handler(m.field(CG43_BUT_DTO), K_SPACE); - } - if (key == K_TAB && f.focusdirty()) - { - const long l = app().select_firm_range(m.get_long(CG43_FLD_DFR), - m.get_long(CG43_FLD_DTO), - (wht)m.get_int(CG43_RDB_VERS)); - app().set_choice_limits(m); - m.field(CG43_FLD_SELECTED).set(format("%ld", l)); - } - return TRUE; -} - -bool TLiquidazione_app::fr_ditt_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask(); - if (key == K_F9) - { - app().fr_butt_handler(m.field(CG43_BUT_DFR), K_SPACE); - } - else if (key == K_TAB && f.focusdirty()) - { - const long l = app().select_firm_range(m.get_long(CG43_FLD_DFR), - m.get_long(CG43_FLD_DTO), - (wht)m.get_int(CG43_RDB_VERS)); - - app().set_choice_limits(m); - m.set(CG43_FLD_SELECTED, l); - } - return TRUE; -} - -bool TLiquidazione_app::to_butt_handler(TMask_field& f, KEY key) -{ - if (key == K_SPACE) - { - TArray_sheet* sh = app().get_ditte_sheet(); - TMask& m = f.mask(); - - sh->disable_check(); - if (sh->run() == K_ENTER) - { - app().select_firm_range(m.get_long(CG43_FLD_DFR),sh->row(sh->selected()).get_long(1), - (wht)m.get_int(CG43_RDB_VERS)); - app().set_choice_limits(m); - } - } - return TRUE; -} - -bool TLiquidazione_app::fr_butt_handler(TMask_field& f, KEY key) -{ - if (key == K_SPACE) - { - TMask& m = f.mask(); - TArray_sheet* sh = ((TLiquidazione_app&)main_app()).get_ditte_sheet(); - - sh->disable_check(); - if (sh->run() == K_ENTER) - { - app().select_firm_range(sh->row(sh->selected()).get_long(1), m.get_long(CG43_FLD_DTO), - (wht)m.get_int(CG43_RDB_VERS)); - app().set_choice_limits(m); - } - } - return TRUE; -} - -bool TLiquidazione_app::what_freq_handler(TMask_field& f, KEY key) -{ - if (key == K_SPACE && f.dirty()) - { - if (f.get()[0] == '3') // trimestre intelligente - { - int month = f.mask().get_int(CG43_LST_MESE); - if (month > 3) - while (!is_trim(month)) month--; - else month = 3; - - f.mask().field(CG43_LST_TRIM).set(format("%d",month)); - } - app().reset_choices(f.mask()); - app().build_ditte_sheet((wht)atoi(f.get())); - } - return TRUE; -} - -void TLiquidazione_app::reset_choices(TMask& m) -{ - _selected.reset(); - m.reset(CG43_FLD_SELECTED); - m.reset(CG43_FLD_DFR); - m.reset(CG43_FLD_DTO); - _ditte->check(-1, FALSE); -} - -void TLiquidazione_app::set_choice_limits(TMask& m) -{ - long first = -1l, last = -1l; - for (int i = 0; i < _ditte->items(); i++) - { - if (_selected[i]) - { - const long dit = _ditte->row(i).get_long(1); - if (first == -1l) first = dit; - if (last < dit) last = dit; - } - } - if (first != -1) m.set(CG43_FLD_DFR, first); - if (last != -1) m.set(CG43_FLD_DTO, last); - m.set(CG43_FLD_SELECTED, _selected.ones()); -} - -void TLiquidazione_app::build_ditte_sheet(wht what) -{ - // build sheet - _ditte->destroy(); - _what = what; - for (int i = 0; i < _nomiditte.items(); i++) - { - TToken_string* d = new TToken_string(64); - *d = (TToken_string&)_nomiditte[i]; - const char vers = d->get_char(2); - - bool unselectable = vers == '?'; - if ((what == mnt && vers == 'T') || (what == trimestre && vers == 'M')) - continue; - - d->insert(" |", 0); - - const long pos = _ditte->add(d); - if (unselectable) _ditte->disable(pos); - else if (_selected[i]) _ditte->check(pos); - } -} - - -// ---------------------------------------------------- - -bool TLiquidazione_app::set_liquidazione() -{ - TMask m("cg4300a.msk"); - - m.set_handler(CG43_FLD_DTO, to_ditt_handler); - m.set_handler(CG43_FLD_DFR, fr_ditt_handler); - m.set_handler(CG43_BUT_DTO, to_butt_handler); - m.set_handler(CG43_BUT_DFR, fr_butt_handler); - m.set_handler(CG43_RDB_VERS, what_freq_handler); - m.set_handler(CG43_FLD_ANNO, ch_year_handler); - - m.field(CG43_FLD_SELECTED).set(format("%ld",_selected.ones())); - m.field(CG43_FLD_ANNO).set(_year); - set_choice_limits(m); - - KEY k; - // stampa abilitata per default - m.set(CG43_CHK_STAMPA,"X"); - - _month = m.get_int(CG43_LST_MESE); - - do - { - m.field(CG43_RDB_VERS).set(format("%d",(int)_what)); - - if ((k = m.run()) == K_ESC) break; - - // handlers have set everything - - _month = _what == trimestre ? m.get_int(CG43_LST_TRIM) : - m.get_int(CG43_LST_MESE); - - _year = m.get(CG43_FLD_ANNO); - _date = m.get(CG43_FLD_DATA); - _isprint = m.get_bool(CG43_CHK_STAMPA); - _recalc = (recalc)m.get_long(CG43_LST_CALC); - _printonly = m.get_bool(CG43_CHK_FINAL); - - if (_isprint) printer().setdate(_date); - if (_printonly) _recalc = never; - - // ------------------------------------------------ - m.first_focus(k); - - switch(k) - { - case DLG_SELECT: - _ditte->enable_check(); - // seleziona e aggiungi alle gia' selezionate - if (_ditte->run() == K_ENTER) - { - for (long j = 0l; j < _ditte->items(); j++) - _selected.set(j, _ditte->checked(j)); - set_choice_limits(m); - } - break; - - case CG43_BUT_ANN: - reset_choices(m); - break; - } - } - while (k != K_ENTER && k != K_ESC); - - return k == K_ENTER; -} - -int cg4300(int argc, char* argv[]) -{ - TApplication::check_parameters(argc, argv); - - const char* title = "Liquidazione IVA"; - int menu = 1; - - if (argc > 2) - { - const char mode = argv[2][1]; - switch (mode) - { - case 'A': - menu = 3; - break; - case 'C': - title = "Ricalcolo progressivi IVA"; - break; - case 'D': - menu = 2; - break; - case 'S': - title = "Stampa liquidazione"; - break; - default: - break; - } - } - - TLiquidazione_app main_app(menu); - main_app.run(argc, argv, title); - return TRUE; -} +// ------------------------------------------------------------ +// Calcolo liquidazioni +// Part 1: interfaccia +// fv 21-1-94 +// ------------------------------------------------------------ + +#include +#include +#include +#include +#include +#include + +#include "cg4300.h" +#include "cg4300a.h" + +#include + +real TLiquidazione_app::CENTO(100.0); + +inline TLiquidazione_app& app() +{ return (TLiquidazione_app&)main_app(); } + +TLiquidazione_app::TLiquidazione_app(int m) : +_ditte(NULL), _selected(10000), +_year(4), _nomiditte(100), _menu(m), _firm_bookmark(-1) +{ + _isprint = _is_interactive = _canprint = TRUE; + _isplafond = _printonly = _is_visliq = FALSE; + _isvent = _isagricolo = _isbenzinaro = _isviaggio = FALSE; + _row = 1; _what = all; _comp_acconto = FALSE; + _isriepilogo = FALSE; _calcall = FALSE; + _isfinal = _isregis = FALSE; + _recalc = needed; +} + +bool TLiquidazione_app::user_create() +{ + // vediamo se c'e' il messaggio per calcolare in batch + TMailbox mail; + TProgind* pnd = NULL; + TMessage* msg = mail.next_s("RCL"); + TToken_string subj(36); + _is_interactive = msg == NULL; + _recalc_only = FALSE; + bool is_header = TRUE; + int headerlen; + TDate printdate; + TString filename; + long ditta; + bool nocalc = FALSE; + + _prind = NULL; + + if (msg != NULL) subj = msg->body(); + + if (_is_interactive) + pnd = new TProgind (3,"Preparazione archivi\nPrego attendere", + FALSE, TRUE, 30); + else begin_wait(); + + _nditte = new TRelation(LF_NDITTE); + _nditte->add(LF_ATTIV,"CODDITTA=CODDITTA"); + _nditte_r = &(_nditte->curr()); + _att_r = &(_nditte->curr(LF_ATTIV)); + + _ditte = new TArray_sheet(-1, -1, 0, 0, "Selezione Ditte", + "@1|Cod.@5R|Ragione Sociale@50|Vers."); + _n_ditte = 0l; + + // prevediamo la data che usera'; se calcola la liq. di un altro anno + // si fottera' la frequenza versamenti + + if (_is_interactive) + { + TDate oggi(TODAY); + _year.format("%d",oggi.year()); + } + else // parse messaggio + { + _year = subj.get(0); + _month = subj.get_int(1); + ditta = subj.get_long(2); + char rcl = *(subj.get(3)); + _recalc_only = rcl == 'C'; + _is_visliq = rcl == 'V'; + // S/s = stampa senza ricalcolo (minuscolo = definitivo) + // L/l = stampa con ricalcolo se necessario (minuscolo = definitivo) + // C = solo ricalcolo + // V = stampa ed ev. ricalcolo per visualizzazione + // s o l minuscoli = registro bollato (setta B1) + _isregis = (rcl == 'l' || rcl == 'L' || + rcl == 'S' || rcl == 's'); // stampa per registri + _isfinal = rcl == 'l' || rcl == 's'; // se l minuscolo, definitivo + nocalc = rcl == 'S' || rcl == 's'; + printdate = subj.get(4); + filename = subj.get(5); + headerlen = subj.get_int(6); + is_header = subj.items() == 7; + //modifica del 5/07/1995 + int f = printer().formlen(); + printer().formlen(f - headerlen); + //fine + } + + if(pnd) pnd->addstatus(1); + + _rel = new TRelation(LF_MOV); + _rel->add(LF_RMOVIVA,"NUMREG=NUMREG"); + _rel->add(LF_CAUSALI,"CODCAUS=CODCAUS"); + + _cur = new TCursor(_rel, "", 2); + + _pim = new TTable("PIM"); + _pum = new TTable("PUM"); + _pam = new TTable("PAM"); + _pom = new TTable("POM"); + _ppa = new TTable("PPA"); + _plm = new TTable("PLM"); + _lim = new TTable("LIM"); + _lam = new TTable("LAM"); + _pla = new TTable("%PLA"); + _reg = new TTable("REG"); + _iva = new TTable("%IVA"); + _del = new TTable("%DEL"); + _lia = new TTable("%LIA"); + + _mov = &_cur->file(LF_MOV); + _rmoviva = &_cur->file(LF_RMOVIVA); + + _pim_r = &(_pim->curr()); + _plm_r = &(_plm->curr()); + _pum_r = &(_pum->curr()); + _pam_r = &(_pam->curr()); + _pom_r = &(_pom->curr()); + _iva_r = &(_iva->curr()); + _del_r = &(_del->curr()); + _lim_r = &(_lim->curr()); + _lam_r = &(_lam->curr()); + _pla_r = &(_pla->curr()); + _ppa_r = &(_ppa->curr()); + _reg_r = &(_reg->curr()); + _rmoviva_r = &(_cur->curr(LF_RMOVIVA)); + _mov_r = &(_mov->curr()); + + // ACHTUNG: tutti i _codatt (codici attivita') sono + // in realta' composti dal codice attivita' piu' il + // tipo attivita' (1 o 2) + // sarebbe piu' saggio fare 2 campi ma ci vuole 1 vita + + _pim_anno = new TRecfield(*_pim_r,"CODTAB",0,3); + _pim_codatt = new TRecfield(*_pim_r,"CODTAB",4,9); + _pim_codreg = new TRecfield(*_pim_r,"CODTAB",10,12); + _pim_mese = new TRecfield(*_pim_r,"CODTAB",13,14); + _pim_tipocr = new TRecfield(*_pim_r,"CODTAB",15,15); + _pim_codiva = new TRecfield(*_pim_r,"CODTAB",16,19); + _pim_tipodet = new TRecfield(*_pim_r,"CODTAB",20,20); + _pum_anno = new TRecfield(*_pum_r,"CODTAB",0,3); + _pum_codatt = new TRecfield(*_pum_r,"CODTAB",4,9); + _pum_mese = new TRecfield(*_pum_r,"CODTAB",10,11); + _pam_anno = new TRecfield(*_pam_r,"CODTAB",0,3); + _pam_codatt = new TRecfield(*_pam_r,"CODTAB",4,9); + _pam_mese = new TRecfield(*_pam_r,"CODTAB",10,11); + _pom_anno = new TRecfield(*_pom_r,"CODTAB",0,3); + _pom_codatt = new TRecfield(*_pom_r,"CODTAB",4,9); + _pom_mese = new TRecfield(*_pom_r,"CODTAB",10,11); + _ppa_year = new TRecfield(*_ppa_r,"CODTAB",0,3); + _ppa_codatt = new TRecfield(*_ppa_r,"CODTAB",4,9); + _ppa_month = new TRecfield(*_ppa_r,"CODTAB",10,11); + _ppa_kind = new TRecfield(*_ppa_r,"CODTAB",12,12); + + _plm_anno = new TRecfield(*_plm_r,"CODTAB",0,3); + _plm_codatt = new TRecfield(*_plm_r,"CODTAB",4,9); + _plm_mese = new TRecfield(*_plm_r,"CODTAB",10,11); + + _pla_ditta = new TRecfield(*_pla_r,"CODTAB",0,4); + _pla_anno = new TRecfield(*_pla_r,"CODTAB",5,8); + _pla_codatt = new TRecfield(*_pla_r,"CODTAB",9,14); + + _del_ditta = new TRecfield(*_del_r,"CODTAB",0,4); + _del_anno = new TRecfield(*_del_r,"CODTAB",5,8); + _del_mese = new TRecfield(*_del_r,"CODTAB",9,10); + _del_tipo = new TRecfield(*_del_r,"CODTAB",11,11); + + _lim_anno = new TRecfield(*_lim_r,"CODTAB",0,3); + _lim_mese = new TRecfield(*_lim_r,"CODTAB",4,6); + + _lam_anno = new TRecfield(*_lam_r,"CODTAB",0,3); + _lam_mese = new TRecfield(*_lam_r,"CODTAB",4,6); + + __firm = TApplication::get_firm(); + + if (pnd) pnd->addstatus(1); + + if (_is_interactive) + { + build_nomiditte(pnd); + build_ditte_sheet(all); + } + + if (pnd) pnd->addstatus(1); + + TApplication::set_firm(__firm); + set_real_picture(REAL_PICTURE); + + if (!_is_interactive) + { + TTemp_window w(TASK_WIN); + if (_recalc_only) + _isprint = FALSE; + //else printer().set_export_file(filename, is_header, headerlen); + else printer().set_export_file(filename, is_header); + + // calcola liquidazione + printer().setdate(printdate); + _recalc = nocalc ? never : needed; + TApplication::set_firm(ditta); + + if (!look_lia()) + { end_wait(); return FALSE; } + + _nditte->zero(); + _nditte_r->put("CODDITTA", ditta); + _nditte->read(); + _freqviva = _lia->get("S7"); + + TRectype& mov = _cur->curr(); + TRectype from(_cur->curr()); from.zero(); + TRectype to(from); + TDate f(1, 1, atoi(_year)); + TDate t(1, _month == 13 ? 12 : _month, atoi(_year)); + t.set_end_month(); + from.put(MOV_DATAREG, f); + to.put(MOV_DATAREG, t); + _cur->setregion(from, to); + _canprint = is_month_ok_strict(_month) || _month == 13; + + //modifica del 03/05/1995 + int need_refresh = FALSE; + for (int m = 1; m < _month; m++) + if (is_month_ok_strict(m) && (!look_lim(m) || !_lim->get_bool("B0"))) + { + need_refresh = TRUE; + break; + } + + if (need_refresh) _recalc = ever; + + for (int mese = 1; mese < _month; mese++) // fino a 13 compreso + if (is_month_plain(mese) || _recalc == ever) + update_firm(mese); + + if (is_month_plain(_month) || _month == 13) + update_firm(_month); + + if (_isprint && _descr_arr.items() > 0) + print(); + + // se ci sono altri mesi dopo l'ultimo calcolato, invalida il + // flag 'calcolato' del primo, per causare il ricalcolo dei + // successivi (evitando problemi per credito precedente) + for (m = _month+1; m <= 13; m++) + if (look_lim(m)) + { + _lim->put("B0",""); + _lim->rewrite(); + break; + } + + TApplication::set_firm(__firm); + end_wait(); + } + else delete pnd; + + return _is_interactive; +} + +bool TLiquidazione_app::user_destroy() +{ + delete _ditte; + + delete _pim_anno; + delete _pim_codreg; + delete _pim_mese; + delete _pim_tipocr; + delete _pim_codiva; + delete _ppa_year; + delete _ppa_codatt; + delete _ppa_month; + delete _ppa_kind; + delete _plm_anno; + delete _plm_codatt; + delete _plm_mese; + delete _pum_anno; + delete _pum_codatt; + delete _pum_mese; + delete _pam_codatt; + delete _pam_anno; + delete _pam_mese; + delete _pom_codatt; + delete _pom_anno; + delete _pom_mese; + delete _lim_anno; + delete _lim_mese; + delete _lam_anno; + delete _lam_mese; + delete _pla_anno; + delete _pla_codatt; + delete _pim_codatt; + delete _del_ditta; + delete _del_anno; + delete _del_mese; + delete _del_tipo; + + delete _pim; + delete _pum; + delete _pam; + delete _pom; + delete _ppa; + delete _plm; + delete _lim; + delete _lam; + delete _pla; + delete _del; + + delete _nditte; + delete _rel; + delete _cur; + + return TRUE; +} + +bool TLiquidazione_app::set_print(int) +{ + _descr_arr.destroy(); + _errors.destroy(); + + switch(_menu) + { + case 1: // liquidazione + _isprint = TRUE; + while (set_liquidazione()) + { + if (_selected.ones() > 0l) + { + TRectype& mov = _cur->curr(); + TRectype from(_cur->curr()); from.zero(); + TRectype to(from); + TDate f(1, 1, atoi(_year)); + TDate t(1, _month == 13 ? 12 : _month, atoi(_year)); + t.set_end_month(); + from.put(MOV_DATAREG, f); + to.put(MOV_DATAREG, t); + _cur->setregion(from, to); + + return recalc_all() && _isprint; + } + else warning_box("Nessuna ditta selezionata!"); + } + break; + case 2: // estrazione deleghe + _isprint = FALSE; + build_ditte_sheet(all); + while (set_deleghe()) + { + if (_calcall || _selected.ones() > 0l) + { + TRectype & mov = _cur->curr(); + TRectype from(_cur->curr()); from.zero(); + TRectype to(from); + TDate f(1, _recalc == one ? _month : 1, atoi(_year)); + TDate t(1, _month == 13 ? 12 : _month, atoi(_year)); + t.set_end_month(); + from.put(MOV_DATAREG, f); + to.put(MOV_DATAREG, t); + _cur->setregion(from, to); + extract_deleghe(); + return _isprint; + } + else warning_box("Nessuna ditta selezionata!"); + } + break; + case 3: // calcolo acconto + _isprint = TRUE; + build_ditte_sheet(all); + real inf; real ina; // cotale obbrobrio non fu da me cercato, ne' mai condiviso + while (set_acconto(inf, ina)) + { + if (_calcall || _selected.ones() > 0l) + { + TRectype & mov = _cur->curr(); + TRectype from(_cur->curr()); from.zero(); + TRectype to(from); + TDate f(1, _recalc == one ? _month : 1, atoi(_year)); + TDate t(1, _month == 13 ? 12 : _month, atoi(_year)); + t.set_end_month(); + from.put(MOV_DATAREG, f); + to.put(MOV_DATAREG, t); + _cur->setregion(from, to); + recalc_acconti(inf, ina); + return _isprint; + } + else warning_box("Nessuna ditta selezionata!"); + } + break; + } + return FALSE; +} + +long TLiquidazione_app::select_firm_range(long from, long to, wht freq) +{ + if (to == 0l) to = 99999L; + + for (int i = 0; i < _ditte->items(); i++) + { + if (_ditte->disabled(i)) + continue; + + TToken_string& d = _ditte->row(i); + const char vers = d.get_char(3); + if (vers == '?' || (freq == mnt && vers == 'T') || (freq == trimestre && vers == 'M')) + continue; + + const long cod = d.get_long(1); + if (cod >= from && cod <= to) + { + _selected.set(i); + _ditte->check(i); + } + else + { + _selected.set(i,FALSE); + _ditte->uncheck(i); + } + } + + return _selected.ones(); +} + +// ----------------------------------------------- handlers + +bool TLiquidazione_app::ch_year_handler(TMask_field& f, KEY key) +{ + if (key == K_TAB && f.focusdirty()) + { + app().begin_wait(); + app().set_year(f.get()); + app().build_nomiditte(); + app().build_ditte_sheet(f.mask().source_file() == "cg4300a.msk" ? + (wht)atoi(f.mask().get(CG43_RDB_VERS)) : + all); + app().end_wait(); + } + return TRUE; +} + +void TLiquidazione_app::build_nomiditte(TProgind* pnd) +{ + _nomiditte.destroy(); + // ricostruire _nomiditte e rifare build_ditte_sheet + TLocalisamfile& dt = _nditte->lfile(); + + for (dt.first(); !dt.eof(); dt.next()) + { + // check no archivi + bool good = prefix().exist(dt.get_long("CODDITTA")); + + if (good) + { + // check no parametri liquidazione + if (!look_lia(dt.get_long("CODDITTA"))) good = FALSE; + } + else continue; + + TToken_string* d = new TToken_string(64); + + // add record + d->add(dt.get("CODDITTA")); + d->add(dt.get("RAGSOC")); + if (good) d->add(_lia->get("S7")); + else d->add("??"); + + _nomiditte.add(d); + } + if (pnd) pnd->addstatus(1); +} + +bool TLiquidazione_app::to_ditt_handler(TMask_field& f, KEY key) +{ + TMask& m = f.mask(); + if (key == K_F9) + { + app().to_butt_handler(m.field(CG43_BUT_DTO), K_SPACE); + } + if (key == K_TAB && f.focusdirty()) + { + const long l = app().select_firm_range(m.get_long(CG43_FLD_DFR), + m.get_long(CG43_FLD_DTO), + (wht)m.get_int(CG43_RDB_VERS)); + app().set_choice_limits(m); + m.field(CG43_FLD_SELECTED).set(format("%ld", l)); + } + return TRUE; +} + +bool TLiquidazione_app::fr_ditt_handler(TMask_field& f, KEY key) +{ + TMask& m = f.mask(); + if (key == K_F9) + { + app().fr_butt_handler(m.field(CG43_BUT_DFR), K_SPACE); + } + else if (key == K_TAB && f.focusdirty()) + { + const long l = app().select_firm_range(m.get_long(CG43_FLD_DFR), + m.get_long(CG43_FLD_DTO), + (wht)m.get_int(CG43_RDB_VERS)); + + app().set_choice_limits(m); + m.set(CG43_FLD_SELECTED, l); + } + return TRUE; +} + +bool TLiquidazione_app::to_butt_handler(TMask_field& f, KEY key) +{ + if (key == K_SPACE) + { + TArray_sheet* sh = app().get_ditte_sheet(); + TMask& m = f.mask(); + + sh->disable_check(); + if (sh->run() == K_ENTER) + { + app().select_firm_range(m.get_long(CG43_FLD_DFR),sh->row(sh->selected()).get_long(1), + (wht)m.get_int(CG43_RDB_VERS)); + app().set_choice_limits(m); + } + } + return TRUE; +} + +bool TLiquidazione_app::fr_butt_handler(TMask_field& f, KEY key) +{ + if (key == K_SPACE) + { + TMask& m = f.mask(); + TArray_sheet* sh = ((TLiquidazione_app&)main_app()).get_ditte_sheet(); + + sh->disable_check(); + if (sh->run() == K_ENTER) + { + app().select_firm_range(sh->row(sh->selected()).get_long(1), m.get_long(CG43_FLD_DTO), + (wht)m.get_int(CG43_RDB_VERS)); + app().set_choice_limits(m); + } + } + return TRUE; +} + +bool TLiquidazione_app::what_freq_handler(TMask_field& f, KEY key) +{ + if (key == K_SPACE && f.dirty()) + { + if (f.get()[0] == '3') // trimestre intelligente + { + int month = f.mask().get_int(CG43_LST_MESE); + if (month > 3) + while (!is_trim(month)) month--; + else month = 3; + + f.mask().field(CG43_LST_TRIM).set(format("%d",month)); + } + app().reset_choices(f.mask()); + app().build_ditte_sheet((wht)atoi(f.get())); + } + return TRUE; +} + +void TLiquidazione_app::reset_choices(TMask& m) +{ + _selected.reset(); + m.reset(CG43_FLD_SELECTED); + m.reset(CG43_FLD_DFR); + m.reset(CG43_FLD_DTO); + _ditte->check(-1, FALSE); +} + +void TLiquidazione_app::set_choice_limits(TMask& m) +{ + long first = -1l, last = -1l; + for (int i = 0; i < _ditte->items(); i++) + { + if (_selected[i]) + { + const long dit = _ditte->row(i).get_long(1); + if (first == -1l) first = dit; + if (last < dit) last = dit; + } + } + if (first != -1) m.set(CG43_FLD_DFR, first); + if (last != -1) m.set(CG43_FLD_DTO, last); + m.set(CG43_FLD_SELECTED, _selected.ones()); +} + +void TLiquidazione_app::build_ditte_sheet(wht what) +{ + // build sheet + _ditte->destroy(); + _what = what; + for (int i = 0; i < _nomiditte.items(); i++) + { + TToken_string* d = new TToken_string(64); + *d = (TToken_string&)_nomiditte[i]; + const char vers = d->get_char(2); + + bool unselectable = vers == '?'; + if ((what == mnt && vers == 'T') || (what == trimestre && vers == 'M')) + continue; + + d->insert(" |", 0); + + const long pos = _ditte->add(d); + if (unselectable) _ditte->disable(pos); + else if (_selected[i]) _ditte->check(pos); + } +} + + +// ---------------------------------------------------- + +bool TLiquidazione_app::set_liquidazione() +{ + TMask m("cg4300a.msk"); + + m.set_handler(CG43_FLD_DTO, to_ditt_handler); + m.set_handler(CG43_FLD_DFR, fr_ditt_handler); + m.set_handler(CG43_BUT_DTO, to_butt_handler); + m.set_handler(CG43_BUT_DFR, fr_butt_handler); + m.set_handler(CG43_RDB_VERS, what_freq_handler); + m.set_handler(CG43_FLD_ANNO, ch_year_handler); + + m.field(CG43_FLD_SELECTED).set(format("%ld",_selected.ones())); + m.field(CG43_FLD_ANNO).set(_year); + set_choice_limits(m); + + KEY k; + // stampa abilitata per default + m.set(CG43_CHK_STAMPA,"X"); + + _month = m.get_int(CG43_LST_MESE); + + do + { + m.field(CG43_RDB_VERS).set(format("%d",(int)_what)); + + if ((k = m.run()) == K_ESC) break; + + // handlers have set everything + + _month = _what == trimestre ? m.get_int(CG43_LST_TRIM) : + m.get_int(CG43_LST_MESE); + + _year = m.get(CG43_FLD_ANNO); + _date = m.get(CG43_FLD_DATA); + _isprint = m.get_bool(CG43_CHK_STAMPA); + _recalc = (recalc)m.get_long(CG43_LST_CALC); + _printonly = m.get_bool(CG43_CHK_FINAL); + + if (_isprint) printer().setdate(_date); + if (_printonly) _recalc = never; + + // ------------------------------------------------ + m.first_focus(k); + + switch(k) + { + case DLG_SELECT: + _ditte->enable_check(); + // seleziona e aggiungi alle gia' selezionate + if (_ditte->run() == K_ENTER) + { + for (long j = 0l; j < _ditte->items(); j++) + _selected.set(j, _ditte->checked(j)); + set_choice_limits(m); + } + break; + + case CG43_BUT_ANN: + reset_choices(m); + break; + } + } + while (k != K_ENTER && k != K_ESC); + + return k == K_ENTER; +} + +int cg4300(int argc, char* argv[]) +{ + TApplication::check_parameters(argc, argv); + + const char* title = "Liquidazione IVA"; + int menu = 1; + + if (argc > 2) + { + const char mode = argv[2][1]; + switch (mode) + { + case 'A': + menu = 3; + break; + case 'C': + title = "Ricalcolo progressivi IVA"; + break; + case 'D': + menu = 2; + break; + case 'S': + title = "Stampa liquidazione"; + break; + default: + break; + } + } + + TLiquidazione_app main_app(menu); + main_app.run(argc, argv, title); + return TRUE; +} diff --git a/cg/cg4301.cpp b/cg/cg4301.cpp index 3fb9af63c..9fe1ab1ef 100755 --- a/cg/cg4301.cpp +++ b/cg/cg4301.cpp @@ -1,3 +1,1752 @@ +<<<<<<< cg4301.cpp +// ------------------------------------------------------------ +// Calcolo liquidazioni +// Part 2: calcolo +// fv 21-1-94 +// ------------------------------------------------------------ + +#include +#include +#include +#include +#include "cg4300.h" + +// -------------------- QUI comincia l'avventura -------------------------- +// Datemi un punto di appoggio ****************** +// e mi ci appoggero' ****************** +// ----------------------------------------------------- ****************** + +bool TLiquidazione_app::recalc_all() +{ + _prind = new TProgind(_selected.ones()*2, _printonly ? + " Stampa liquidazione... \n" + " Preparazione archivi \n" + " " : + " Calcolo liquidazione... \n" + " Preparazione archivi \n" + " ", + TRUE,TRUE,45); + + for (int l = 0; l < _ditte->items(); l++) + { + if (_prind->iscancelled()) + break; + + if (_selected[(long)l]) + { + TToken_string& nomeditta = _ditte->row(l); + int save_month = _month; + + /* ------------------------------------------------------------- + * leggi parametri ditta necessari; stabilisci se annuale, + * se si' metti _month a 13 + * istanzia _freqviva, _isbenzinaro, _isannual, _isriepilogo + * -------------------------------------------------------------- + */ + + _nditte->zero(); + _nditte->curr().put("CODDITTA",nomeditta.get_long(1)); + _nditte->read(); + _freqviva = nomeditta.get(3); + bool mens = _freqviva == "M"; + + // determina attivita' prevalente e istanzia cazzuole + // per vedere che Kazzo di liquidazione calcolare + TString attprev = _nditte->curr().get("CODATTPREV"); + TLocalisamfile& atts = _nditte->lfile(LF_ATTIV); + atts.zero(); + atts.put("CODDITTA",nomeditta.get_long(1)); + atts.put("CODATT", attprev); + if (atts.read() != NOERR) atts.zero(); + // istanzia benzinaro + _isbenzinaro = atts.get_bool("ART74/4"); + + // riaggiusta relazione + _nditte->read(); + + // decidi per stocazzo di annuale + // ***************** Previous kasin *************************** + // per QUALSIASI annuale il mese diventa 13 +// _isannual = (_month == 12 && !mens && !_isbenzinaro) || +// (_month == 13 && (mens || _isbenzinaro)); +// _isriepilogo = _month == 13 && !mens; +// if (_isannual) _month = 13; // che ti piaccia o no + // ************************************************************ + + // strasemplificato: per l'annuale si sceglie annuale, altrimenti + // e' la 12ma anche per le trimestrali. + _isannual = _isriepilogo = _month == 13; + + TApplication::set_firm(nomeditta.get_long(1)); + _prind->addstatus(1); + + /* + * trimestrali impropriamente selezionate per mesi intermedi + * provocano il ricalcolo dei progressivi mensili ma non la stampa + */ + _canprint = is_month_ok_strict(_month) || _month == 13; + + /* -------------------------------------------------------------- + * Ricalcola i mesi necessari, tutti se annuale + * -------------------------------------------------------------- + */ + + int need_refresh = FALSE; + if (_recalc != ever) + { + for (int m = 1; m < _month; m++) + if (is_month_ok_strict(m) && (!look_lim(m) || !_lim->get_bool("B0"))) + { + need_refresh = TRUE; + break; + } + + if (need_refresh && yesno_box("Alcuni mesi precedenti non " + "risultano ricalcolati. E' consigliabile il ricalcolo. " + "Si desidera eseguirlo?")) + _recalc = ever; + } + + for (int m = 1; m <= _month; m++) // fino a 13 compreso + if (is_month_plain(m) || _recalc == ever) + { + if (_prind->iscancelled()) break; + update_firm(m); + } + + // se ci sono altri mesi dopo l'ultimo calcolato, invalida il + // flag 'calcolato' del primo, per causare il ricalcolo dei + // successivi (evitando problemi per credito precedente) + for (m = _month+1; m <= 13; m++) + if (look_lim(m)) + { + _lim->put("B0",""); + _lim->rewrite(); + break; + } + + _month = save_month; + } + } + bool canc = _prind->iscancelled(); + if (!canc) _prind->addstatus(1); + + TApplication::set_firm(__firm); + delete _prind; _prind = NULL; + + return !canc; +} + +bool TLiquidazione_app::update_firm(int month, bool recalc) +{ + // Se recalc e' TRUE considera la necessita' di ricalcolare e le + // opzioni utente. Se FALSE se ne impipa dell'utente e ricalcola + // se necessario (serve nelle chiamate ricorsive) + // Ritorna FALSE soltanto se il ricalcolo era necessario e non e' + // stato effettuato per scelta dello stronzo commercialista. + + look_lim(liq_month(month), TRUE); + + if (_isfinal && _lim->get_bool("B1") && _month != 13) + return TRUE; + + TConfig cnf(CONFIG_DITTA, "cg"); + _isdifferita = cnf.get_bool("GeLiDi") && _month != 13; + _isintr = !cnf.get_bool("InTrTr") && _freqviva != "M"; + // controlla che il periodo corrente non sia l'inizio dell'attivita' + // nel caso, differita va a FALSE + TDate inatt(_nditte->lfile().get("DINIZIOATT")); + if (is_in_liq_period(inatt)) _isdifferita = FALSE; + + TConfig cnf1(CONFIG_STUDIO, "cg"); + _isricacq = cnf1.get_bool("RicAcq"); + + // ricalcolo normale + // lim c'e' solo per i trimestri + bool ok = _lim->get_bool("B0"); + if (ok && !recalc) return TRUE; + bool calc = (_recalc == ever || (_recalc == one && is_month_ok(month,_month))); + if (!calc && _recalc != never) calc = !ok; + bool gheravergot = FALSE; + bool quater = FALSE; + + TToken_string atts; + TToken_string cattivs; + + // azzera rimborsi + zero_firm(month); + + // casini per stampa minchie in coda ai registri + bool riepliq = FALSE; + bool stliq = FALSE; + + _nditte->save_status(); + if (_nditte->is_first_match(LF_ATTIV)) + { + char buf[256]; + do + { + TString16 codatt = _nditte->curr(LF_ATTIV).get("CODATT"); + TString80 desatt = _nditte->curr(LF_ATTIV).get("DESCR"); + quater = _nditte->curr().get_bool("FLIVA11Q"); + + // attivita' mista: ce ne sono in realta' due + // viene calcolato nel ciclo su tipoatt (che viene ripetuto solo + // se diventa TRUE); + _mixed = FALSE; + + sprintf (buf, _printonly ? "Stampa liquidazione (%d)...\n%s: %s\n" : + "Calcolo liquidazione (%d)...\n%s: %s\n", + month, + (const char*)_nditte_r->get("RAGSOC"), + (const char*)desatt); + + if (_prind) _prind->set_text(buf); + + // se ricalcola l'annuale si tiene tutte le vendite e corrispettivi di + // tutti i lerci mesi + if (!(_month == 13 && month > 1)) + { + _vend_arr.destroy(); + _corr_arr.destroy(); + } + + cattivs = ""; + + for (int tipoatt = 1; tipoatt <= (_mixed ? 2 : 1); tipoatt++) + { + TString cattiv(codatt); bool waspla; + + cattiv << tipoatt; + if (tipoatt == 1 && (waspla = look_pla(cattiv, FALSE))) + { + _p8 = _pla->get_real("R5"); + _p8b = _pla->get_real("R6"); + _p9 = _pla->get_real("R7"); + _prorata = _pla->get_real("R8"); + _isplafond = !(_p8.is_zero() && _p8b.is_zero() && + _p9.is_zero()); + _isservizio = _pla->get("S7") == "S"; + _mixed = _pla->get("S7") == "M" || _pla->get("S7") == "E"; + } + else + _isservizio = _nditte->curr(LF_ATTIV).get("TIPOATT") == "S"; + + _isviaggio = _nditte->curr(LF_ATTIV).get_bool("REG74TER"); + _isagricolo = _nditte->curr(LF_ATTIV).get_bool("REGAGR"); + _isvent = FALSE; + + if (tipoatt == 1 && waspla && month == 13) + { + // azzera pla dove serve + _pla->put("R0",""); + _pla->put("R1",""); + _pla->put("R2",""); + _pla->put("R3",""); + _pla->put("R4",""); + _pla->put("R13",""); + _pla->put("R9",""); + _pla->put("R10",""); + _pla->put("R11",""); + _pla->put("R12",""); + _pla->put("R14",""); + _pla->put("S1","0"); + _pla->put("S2","0"); + _pla->put("S3","0"); + _pla->rewrite(); + } + + + for (_reg->first(); _reg->good(); _reg->next()) + { + if (codatt == _reg->get("S8") || quater) + { + if (!riepliq) riepliq = _reg->get_bool("B6"); + if (!stliq) stliq = _reg->get_bool("B7"); + if (_reg->get_int("I0") == 2) + if (!_isvent) _isvent = _reg->get_bool("B3"); + } + } + + if (!_isregis) + stliq = riepliq = TRUE; + + if (calc || !recalc) + if (!update_att(month, cattiv) && stliq) + describe_error("Attivita' non ricalcolate: possibili errori", + codatt); + + // vediamo se c'e' qualcosa da raccontare + gheravergot = _isannual || _isriepilogo; + if (!gheravergot) + { + look_plm(month,cattiv); + gheravergot = !_plm->get_real("R0").is_zero() || + !_plm->get_real("R1").is_zero(); + } + + if (month == _month && riepliq) + describe_att(month, cattiv, gheravergot, + '0' + (_mixed ? tipoatt : 0)); + + atts.add(cattiv); + cattivs.add(cattiv); + } // for tipoatt + + // se attivita' mista stampa riepilogo + if (_mixed && month == _month && riepliq) + describe_att(month,cattivs, TRUE, 'M'); + } + while (_nditte->next_match(LF_ATTIV)); + + // se quater stampa riepilogo + if (quater && month == _month && riepliq) + describe_att(month,atts, TRUE, 'Q'); + + // occorre poterla chiamare altre volte con mesi diversi + _nditte->restore_status(); + + // aggiorna le liquidazioni + if (calc || !recalc) + if (is_month_ok_strict(month) || month == 13) + write_liq(month, atts); + + // rimborso infraannuale + _DescrItem* rimb_d = NULL; + if (month == _month) + { + // unica nel suo genere, recalc_rimborso ritorna + // un bel descritem (NULL se non si rimborsa un cas) + // da passare a describe_liq + rimb_d = recalc_rimborso(month,atts, stliq); + } + + if (month == _month && stliq) + { + describe_firm(month); + describe_liq(_month, atts, _isregis ? NULL : rimb_d); + } + } + return ok || calc; +} + +bool TLiquidazione_app::update_att(int month, const char* codatt, + bool recalc) + // viene passato un codice attivita' con codatt+tipoatt + // vedi update_firm per il burdel dei calc e recalc + // occhecasino. Se _comp_acconto e' TRUE, i movimenti considerati + // saranno solo quelli di dicembre per data <= 20/12; + // il ricalcolo e' FORZATO da _recalc messo a one +{ + look_plm(month, codatt, TRUE); + bool ok = _plm->get_bool("B0"); + if (ok && !recalc) return TRUE; + bool calc = _recalc == ever || (_recalc == one && is_month_ok(month,_month)); + if (!calc && _recalc != never) calc = !ok; + + if (calc || !recalc) + { + zero_att(month,codatt); + recalc_att(month,codatt); + if (!_isagricolo) + { + recalc_ventilation(month, codatt); + recalc_corrispettivi(month, codatt); + } + if (month == 13) + recalc_annual(codatt); + } + return ok || calc; +} + +void TLiquidazione_app::zero_firm(int month) +{ + // nothing more, left for sicurezz +} + +void TLiquidazione_app::zero_att(int month, const char* codatt) +{ + for (_pim->first(); !_pim->eof(); _pim->next()) + { + int m = atoi(*_pim_mese); + TString att = (const char*)*_pim_codatt; + if (m == month && att == codatt && (_year == *_pim_anno)) + { + _pim->put("R0",""); + _pim->put("R1",""); + _pim->put("R2",""); + _pim->put("R3",""); + _pim->put("R4",""); + _pim->put("R5",""); + _pim->put("R6",""); + _pim->put("R7",""); + _pim->put("R8",""); + _pim->put("R9",""); + _pim->put("R10",""); + _pim->put("R11",""); + _pim->put("R12",""); + _pim->put("R13",""); + _pim->put("R14",""); + _pim->put("S1",""); + _pim->put("S2",""); + _pim->rewrite(); + } + } + if (look_plm(month, codatt)) + { + // zero PLM, POM, PAM, PUM + TString codtab(_plm->get("CODTAB")); + _plm->zero(); + _pom->zero(); + _pam->zero(); + _pum->zero(); + _plm->put("CODTAB", codtab); + _pom->put("CODTAB", codtab); + _pam->put("CODTAB", codtab); + _pum->put("CODTAB", codtab); + _plm->rewrite(); + _pam->rewrite(); + _pom->rewrite(); + _pum->rewrite(); + } + if (_isplafond && month != 13) + zero_plafond(month,codatt); +} + +void TLiquidazione_app::recalc_att(int month, const char* codatt) + // il codatt passato e' codice att + tipo att ( IN {1|2} ) + // occhecasino. Se _comp_acconto e' TRUE, i movimenti considerati + // saranno solo quelli di dicembre per data <= 20/12; +{ + real totintra = 0.0; + real nond19_imp = 0.0; + real nond19_iva = 0.0; + real ammort_det = 0.0; + real ammort_det_iva = 0.0; + real ammort_indet = 0.0; + real ammort_indet_iva = 0.0; + real ammort_6 = 0.0; + real ammort_6_iva = 0.0; + real acq_riv = 0.0; + real acq_riv_iva = 0.0; + real leasing = 0.0; + real leasing_iva = 0.0; + real cess_amm = 0.0; + real cess_amm_iva = 0.0; + real acquisti = 0.0; + real acquisti_iva = 0.0; + real vendite = 0.0; + real vendite_iva = 0.0; + real esenti_b1 = 0.0; + real esenti_b2 = 0.0; + real esenti_b3 = 0.0; + real esenti_b14 = 0.0; + real esni_rimb = 0.0; // ci sommo tutti esenti e ni validi per rimborso + real corr_CEE = 0.0; + real corr_noCEE = 0.0; + real acq_CEE = 0.0; + real acq_noCEE = 0.0; + real corr_misCEE = 0.0; + real acq_misCEE = 0.0; + real acq_misnoCEE = 0.0; + real agr_1i = 0.0; + real agr_2i = 0.0; + real agr_1 = 0.0; + real agr_2 = 0.0; + real agr_3 = 0.0; + real agr_4 = 0.0; + real agr_5 = 0.0; + real agr_6 = 0.0; + real agr_7 = 0.0; + real acq_ies = 0.0; + real acq_ies_iva = 0.0; + real ult_detr = 0.0; + real acq_pint = 0.0; + real acq_pint_iva = 0.0; + real spgen = 0.0; + real spgen_iva = 0.0; + real assp_imp = 0.0; + real assp_iva = 0.0; + real vssp_imp = 0.0; + real vssp_iva = 0.0; + real bdog_imp = 0.0; + real bdog_iva = 0.0; + + *_cur = 0; + long items = _cur->items(); + TString trueatt(codatt); + int tipatt = atoi(trueatt.sub(5)); + trueatt = trueatt.left(5); + + for (; _cur->pos() < items; ++(*_cur)) + { + TDate date(_mov->get("DATAREG")); + TString16 reg = _mov->get("REG"); + bool isreg = look_reg(_mov->get("REG")); + TString16 tipodoc = _mov->get("TIPODOC"); + /* + * check register present, rmoviva present and date OK + */ + const bool dok = !is_date_ok(date, month); + const bool sreg = !isreg; + const bool rs8 = _reg->get("S8") != trueatt; + const bool cmt = !_cur->is_first_match(LF_RMOVIVA); + const bool sosp_imp = _reg->get_bool("B1"); + const TRectype& rcs = _cur->curr(LF_CAUSALI); + const bool fattrit = rcs.get_bool("RITFATT"); + + if (dok || sreg || rs8 || cmt) continue; + + /* + * Tipo documento da eliminare (Scudler 1994) + * Trattasi per lo piu' di non incassati + * Da oggi vengono sommati nei real di S2 in pim + * assieme alle FS per stampa registri + */ + bool noninc = (tipodoc == "SN" || tipodoc == "CN" || tipodoc == "RN" || + tipodoc == "IN" || tipodoc == "PG"); + + /* + * check date: se si calcola l'acconto, solo da 1/12 a 20/12 + */ + int accmonth = _isdifferita ? 11 : 12; + if (_comp_acconto && date.month() != accmonth && date.day() > 20) + continue; + + bool corrisp = _reg->get_bool("B0"); + tiporeg tipomov = (tiporeg)_reg->get_long("I0"); + + do + { + look_iva(_rmoviva->get("CODIVA")); + + // totali parziali registrati nei pim per motivi ignoti + real bolld_imp = 0.0; // imponibile bolle doganali + real bolld_iva = 0.0; // imposta bolle doganali + real asimp_imp = 0.0; // imponibile acquisti sosp. imposta + real asimp_iva = 0.0; // imposta acquisti sosp. imposta + real vsimp_imp = 0.0; // imponibile vendite sosp. imposta + real vsimp_iva = 0.0; // imposta vendite sosp. imposta + real rit_imp = 0.0; // imponibile fatture in ritardo + real rit_iva = 0.0; // imposta fatture in ritardo + real nin_imp = 0.0; // imponibile non incassati + real nin_iva = 0.0; // imposta non incassati + + TString codiva = _iva->get("CODTAB"); + TString tipoiva = _iva->get("S1"); + TString riga11_v = _iva->get("S0"); + int tipoes_v = (int)_iva->get_long("I3"); + int tipoes_a = (int)_iva->get_long("I4"); + int tipoagr = atoi(_iva->get("S4")); + int tipoag = atoi(_iva->get("S5")); + int tipopla = atoi(_iva->get("S3")); + int tipodet = atoi(_rmoviva->get("TIPODET")); + bool isrimbinfr = _iva->get_bool("B3"); // vale per calcolo rimborso se ES o NI + bool ivarimb = !_iva->get_bool("B4"); // non escluso calcolo rimb. per al. media + TString tipocr_s = _rmoviva->get("TIPOCR"); + int tipocr = atoi(tipocr_s); + real imponibile = _rmoviva->get_real("IMPONIBILE"); + real imposta = _rmoviva->get_real("IMPOSTA"); + bool intra = _rmoviva->get_bool("INTRA"); + int tipoatt = _rmoviva->get_int("TIPOATT"); + int rigaimp = _rmoviva->get_int("RIGAIMP"); + // autofatture art. 17 per non residenti, con trattamento + // speciale in liquidazione annuale + bool autodafe = (tipodoc == "AF" && tipocr == 4); + // indica acquisti per rivendita; viene messo in B4 di PIM per + // indicare che e' soggetto al ricalcolo IVA (se voluto) in modo + // da evitare di dover controllare mese e anno sul PIM + bool was_riv = FALSE; + /* + * puo' capitare per motivi brutalmente prassici + * SENSU Sergio 1995, Guido + */ + if (tipoatt == 0) tipoatt = 1; + + if(tipoatt != tipatt) continue; + + /* + * Riga imponibile > 9 = ritenute; non si + * considerano (Scudler 1994) + */ + if(rigaimp > 9) continue; + + /* + * In liq. annuale si totalizzano + * solo le stranezze che seguono + */ + if (month == 13) + { + // si contano soltanto le vendite. + bool okc = tipomov == vendita; + // purche' ... + bool cond1 = (rcs.get_bool("AUTOFATT") && tipoiva == "NS" && tipodoc == "AF"); + // oppure ... + bool cond2 = (rcs.get_bool("AUTOFATT") && tipoiva == "NS" && tipodoc != "AF" && + rcs.get_bool("INTRACOM") && rcs.get_bool("VALINTRA")); + /* + * Fatture in ritardo vengono considerate solo in dichiarazione + * annuale, ma vanno comunque sommate per i porci registri + */ + if (!(okc && (cond1 || cond2)) && !fattrit) + continue; + } + + if (noninc) // non incassati: non devono entrare in nessun altro calcolo + { + nin_imp = imponibile; + nin_iva = imposta; + } + else if (sosp_imp) // sospensione di imposta + { + if (tipomov == vendita) + { + vsimp_imp = imponibile; + vsimp_iva = imposta; + } + else + { + asimp_imp = imponibile; + asimp_iva = imposta; + } + assp_imp += asimp_imp; + assp_iva += asimp_iva; + vssp_imp += vsimp_imp; + vssp_iva += vsimp_iva; + } + else if (fattrit && month != 13) + { + rit_imp = imponibile; + rit_iva = imposta; + } + else if (!fattrit) // normale + { + + // ***************************************** + // casi particolari + // ***************************************** + + // imposta acquisti intracomunitari + if (tipomov == acquisto && intra) + totintra += imposta; + + // Altre cose di cui tener conto + if (tipomov == acquisto && (tipocr == 1 || tipocr == 5)) + /* + * Acquisto beni per rivendita + */ + { + acq_riv += imponibile; + acq_riv_iva += imposta; + was_riv = TRUE; + } + + else if (tipomov == acquisto && tipocr == 2 && tipodet == 0) + // Acquisto beni ammortizzabili detraibili + { + ammort_det += imponibile; + ammort_det_iva += imposta; + } + else if (tipomov == acquisto && tipocr == 2 && tipodet != 0) + // Acquisto beni ammortizzabili indetraibili + { + ammort_indet += imponibile; + ammort_indet_iva += imposta; + } + else if (tipomov == acquisto && tipocr == 3) + // Acquisto beni ammortizzabili detr. 6% + { + ammort_6 += imponibile; + ammort_6_iva += imposta; + ult_detr += imponibile * real(DETRAZIONE_6PERCENTO); + } + else if (tipomov == vendita && tipocr == 4) + /* + * Vendite strum. art 17 (cess. amm.) + * Comprende anche autofatture, anche nell'annuale + * (Sergio 1995) + */ + { + cess_amm += imponibile; + cess_amm_iva += imposta; + } + else if (tipomov == acquisto && tipocr == 8) + // Acquisto beni strum. acquisiti in leasing + { + leasing += imponibile; + leasing_iva += imposta; + } + else if (tipomov == acquisto && tipocr == 9) + // Spese generali + { + spgen += imponibile; + spgen_iva += imposta; + } + + // operazioni per calcolo rimborso infraanale + // Scudler 1995 e molti dopo di lei + // La breve estate vissuta dal metodo del 51% rende + // oramai superflua la tabella rimborsi, eliminata + // senza entusiasmo ed interrogandomi sul senso della vita + if (ivarimb) + { + bool ok = _isagricolo ? tipoagr == 2 : FALSE; + + if (tipomov == acquisto && !ok) + ok = (tipocr == 0 || tipocr == 1 || tipocr == 5 || tipocr == 9); + + if (tipomov == vendita && !ok) + ok = tipoiva != "NS" && tipocr != 4; + + ivarimb = ok; + } + + // operazioni esenti + if (tipoiva == "ES") + { + if (tipomov == vendita) + { + switch(tipoes_v) + { + case 1: + esenti_b1 += imponibile; + break; + case 2: + esenti_b2 += imponibile; + break; + case 3: + esenti_b3 += imponibile; + break; + } + // se e' il caso sommare esenti per rimborso + if (isrimbinfr) + esni_rimb += imponibile; + } + else if (tipoes_a == 14) + esenti_b14 += imponibile; + } + + // non imponibili per rimborso + if (tipoiva == "NI" && tipomov == vendita && isrimbinfr) + esni_rimb += imponibile; + + // bolle doganali + if (tipodoc == "BD") + { + bolld_imp = imponibile; + bolld_iva = imposta; + + bdog_imp += bolld_imp; + bdog_iva += bolld_iva; + } + + // plafond + if (_isplafond && tipomov == acquisto && month != 13 && + tipoiva == "NI" && tipopla != 0) + { + add_plafond(month, codatt, tipopla, imponibile, tipodoc == "BD"); + } + + // agenzie viaggio (CHECK imponibili etc.) + if (_isviaggio) + switch (tipoag) + { + case 1: + if (tipomov == acquisto) acq_CEE += imponibile + imposta; + else corr_CEE += imponibile + imposta; + break; + case 2: + if (tipomov == acquisto) acq_noCEE += imponibile + imposta; + else corr_noCEE += imponibile + imposta; + break; + case 3: corr_misCEE += imponibile + imposta; break; + case 4: acq_misCEE += imponibile + imposta; break; + case 5: acq_misnoCEE += imponibile + imposta; break; + } + + + if (_isagricolo) + { + /* + * rifatto sensu Scudler 1995 con invidiabile sicurezza + * senza porsi domande e mettendo NUMERI uguali + * al TIPO RECORD del frigorifero + */ + if (tipomov == vendita) + { + if (tipoagr == 1 || tipoagr == 3) + { + agr_1 += imposta; + agr_1i += imponibile; + } + else if (tipoagr == 2) + { + agr_2 += imposta; + agr_2i += imponibile; + } + } + else if (tipodet == 0) + { + if (tipoagr == 2) + { + if (tipocr != 2 && tipocr != 3 && tipocr != 8) + agr_3 += imposta; + else + agr_4 += imposta; + } + else if (tipoagr == 3) + { + if (tipocr != 2 && tipocr != 3 && tipocr != 8) + agr_7 += imposta; + } + else // ne' 2 ne' 3 + { + if (tipocr != 2 && tipocr != 3 && tipocr != 8) + agr_5 += imposta; + else + agr_6 += imposta; + } + } + } + + if (tipodet == 1) // acquisti indeducibili su ricavi esenti art. 10 + { + acq_ies += imponibile; + acq_ies_iva += imposta; + } + + if (tipodet == 3) // passaggi interni (solo per ventilaz) + { + acq_pint += imponibile; + acq_pint_iva += imposta; + } + + // acquisti non detraibili art. 19 + // possono valere per la ventilazione + if (tipodet == 9) + { + nond19_imp += imponibile; + nond19_iva += imposta; + } + + // ***************************************** + // Fine casi particolari + // Non che i casi normali siano tanto meglio + // ***************************************** + } // non sosp_imp ne' altre casistiche che escludono la liq. + /* + * Calcolo e aggiornamento + * cerca o crea progressivo IVA + */ + look_pim(month, codatt, reg, tipocr_s, codiva, tipodet, TRUE); + + /* + * se ign == TRUE non bisogna neppure PROGRESSIVARLI + */ + bool ign = sosp_imp || (fattrit && month != 13) || noninc; + + /* + * se liq == FALSE gli importi non contano ai fini + * del calcolo liquidazione + */ + bool liq = !(tipodet == 1 || tipodet == 3 || tipodet == 9 || ign); + + + real imp = _pim->get_real("R0"); // imponibile + real ivp = _pim->get_real("R1"); // IVA su imp. + real lor = _pim->get_real("R2"); // lordo + + /* + * le maledette fatture con scontrino sono sul registro dei + * corrispettivi, ma vanno riportate nelle vendite in stampa; + * dunque, le sommiamo in R5 e R6 di PIM anche se continuiamo + * a sommarle anche in R0 e R1. La stampa (describe_pim) + * dovra' scorporarle + */ + real ifs = _pim->get_real("R5"); // imponibile fatture con scontrino + real vfs = _pim->get_real("R6"); // IVA fatt. con scontrino + + /* + * le maledette autofatture non residenti art. 17 + * vedi al calcolo if (autodafe) si tengono da parte + * La stampa le scorpora solo IN SEDE di dichiarazione annuale + * NELL'OTTICA di una PIU' CORRETTA e CONSONA ...................... + */ + real adf = _pim->get_real("R7"); + real adi = _pim->get_real("R8"); + + /* le fottute fatture in sospensione di imposta */ + real fsi = _pim->get_real("R11"); + real fsv = _pim->get_real("R12"); + + /* le putride bolle doganali */ + real bdi = _pim->get_real("R9"); + real bdv = _pim->get_real("R10"); + + /* i luridi falsi corrispettivi */ + real fci = _pim->get_real("R13"); + real fcv = _pim->get_real("R14"); + + /* le porche fatture in ritardo */ + TToken_string fr(_pim->get("S1")); + real rti(fr.get(0)); + real rtv(fr.get(1)); + + /* + * la stramadonna dei corrispettivi gia' scorporati + * Gli si aggiungono i non incassati, sperando in bene + */ + TToken_string cs(_pim->get("S2")); + real csi(cs.get(0)); + real csv(cs.get(1)); + /* incrociamm'e dituozz' */ + csi += nin_imp; + csv += nin_iva; + + rti += rit_imp; + rtv += rit_iva; + + if (tipomov == vendita) + { + fsi += vsimp_imp; + fsv += vsimp_iva; + } + else + { + fsi += asimp_imp; + fsv += asimp_iva; + bdi += bolld_imp; + bdv += bolld_iva; + } + + if (liq && tipomov == vendita && !corrisp) + // i corrispettivi sono gestiti a parte + { + // totale vendite + vendite += imponibile; + vendite_iva += imposta; + } + else if (liq && tipomov == acquisto) + { + // totale acquisti + acquisti += imponibile; + acquisti_iva += imposta; + } + + // corrispettivi + bool true_corrisp = FALSE; + if (corrisp) + { + /* + * ennesimo casino: non tutti i corrispettivi sono + * corrispettivi; in effetti, alcuni corrispettivi + * non sono corrispettivi. Ci si potrebbe domandare + * se gli altri corrispettivi sono corrispettivi o + * no; ebbene, gli altri corrispettivi risultano + * fortunatamente essere corrispettivi, a meno di + * indicazioni contrarie. + */ + if (tipodoc == "CR" || tipodoc == "RF" || tipodoc == "SC") + { + true_corrisp = TRUE; + _pim->put("I0",LORDO); + // questi sono corrispettivi davvero; comportamento normale + if (tipoiva == "VE") // da ventilare + { + lor += imponibile; + add_vendite(month, reg, tipodet, imponibile); + } + else // non da ventilare, con imposta gia' conteggiata + { + real perc = _iva->get_real("R0")/CENTO; + lor += imponibile + imposta; + real tot = imponibile+imposta; + if (liq) add_corrisp(month, reg, tot, perc, tipodet, codiva, codatt); + } + } + else if (tipodoc == "FS") + { + // queste sono fatture che seguono scontrino, il lordo va detratto + // perche' si e' gia' registrato lo scontrino medesimo + true_corrisp = TRUE; // non e' vero ma non devono essere sommate ai falsi + // corrispettivi + if (tipoiva == "VE") + { + real rr = imponibile + imposta; + imp += rr; + if (liq) + vendite += rr; + add_vendite(month, reg, tipodet, rr); + } + imp -= imponibile; + ivp -= imposta; + lor -= imponibile + imposta; + ifs += imponibile; + vfs += imposta; + csi += imponibile; + csv += imposta; + } + else // vendite normali a tutti gli effetti + { + if (liq) + { + vendite += imponibile; + vendite_iva += imposta; + } + imp += imponibile; + ivp += imposta; + fci += imponibile; + fcv += imposta; + csi += imponibile; + csv += imposta; + _pim->put("I0",NETTO); + } + } // if corrisp + else // non corrisp + { // imponibile e imposta separata + imp += imponibile; + ivp += imposta; + _pim->put("I0",NETTO); + } + + if (autodafe) // autofatture non residenti art, 17 + { + /* + * Si devono riportare a parte in annuale + * e non comparire nel riepilogo del codice IVA + * corrispondente, solo se la liq. e' annuale + * Li metto in R7/R8 di pim e li sommo anche nelle + * vendite; la describe_pim() dovra' sommarli su tutti i + * pim, scorporarli dalle rispettive vendite + * e assegnarli al codice IVA A35 in caso di liq. annuale + */ + adf += imponibile; + adi += imposta; + } + + if (corrisp && !true_corrisp) + { + fci += imponibile; + fcv += imposta; + } + + if (!ign) + { + _pim->put("R0",imp); + _pim->put("R1",ivp); + _pim->put("R2",lor); + _pim->put("R5",ifs); + _pim->put("R6",vfs); + _pim->put("R7",adf); + _pim->put("R8",adi); + _pim->put("R9",bdi); + _pim->put("R10",bdv); + _pim->put("R13",fci); + _pim->put("R14",fcv); + } + + // questi servono per i ricalcoli altrui (classify_pim) o + // per trucchetti di ricalcolo successivi + _pim->put("R11",fsi); + _pim->put("R12",fsv); + _pim->put("I1", (long)tipomov); + _pim->put("B3", ivarimb ? "X" : ""); + _pim->put("B4", (_isricacq && was_riv) ? "X" : ""); + _pim->put("S5", tipoiva); + + // fatture in ritardo + fr.add(rti.string(), 0); + fr.add(rtv.string(), 1); + _pim->put("S1",fr); + + // corrispettivi gia' scorporati; anche questi servono per + // non cannare la stampa dei registri; contengono anche + // tutti i non incassati (vedi definizione di bool nonimp) + cs.add(csi.string(), 0); + cs.add(csv.string(), 1); + _pim->put("S2",cs); + _pim->rewrite(); + } + while (_cur->next_match(LF_RMOVIVA)); + } // fine calcolo progressivi IVA + + /* + * calcolati tutti i movimenti e aggiornati i pim + * se necessario risistema le imposte acquisti beni + * per rivendita + */ + + if (_isricacq) // flag settato parametri studio + { + for (_pim->first(); !_pim->eof(); _pim->next()) + { + // this is much furber than doing all of the checks + if (_pim->get_bool("B4")) + { + // ricalcola l'imposta a partire dal codice IVA + look_iva(*_pim_codiva); + real old_iva = _pim->get_real("R1"); + real perc = _iva->get_real("R0"); + + real new_iva = (_pim->get_real("R0") * perc)/CENTO; + new_iva.ceil(ROUND_LIRA); // TBC check ceil + + if (new_iva != old_iva) + { + // ricalcola: acquisti_iva, acq_riv_iva + acquisti_iva -= old_iva; + acquisti_iva += new_iva; + acq_riv_iva -= old_iva; + acq_riv_iva += new_iva; + _pim->put("R1", new_iva); + // resetta in modo da non vederlo il mese dopo + _pim->put("B4", ""); + _pim->rewrite(); + } + } + } + } + + /* + * calcola il lercio prorata + * solo se liq. periodica + */ + real prorata; + if (!_prorata.is_zero() && month != 13) + { + prorata = acquisti_iva * (_prorata / CENTO); + prorata.round(ROUND_LIRA); + acquisti_iva -= prorata; + } + look_plm(month, codatt, TRUE); + + /* + * ACHTUNG: l'iva sulle vendite e' calcolata sommando anche i + * corrispettivi che sono corrispettivi, a differenza dei corrispettivi + * che non sono corrispettivi, ma tanto quelli (come si sa) non sono + * corrispettivi. Dunque, non si tiene conto delle imposte calcolate + * con la ventilazione (che vanno sottratte) ne' di quelle + * calcolate per le agenzie di viaggio (che sembra non vadano + * comunque sottratte nel calcolo del volume di affari) + */ + + _plm->put("R2", prorata); + + if (_isviaggio) + { + real deb_mens = 0.0; + _plm->put("R5", corr_CEE); + _plm->put("R6", corr_noCEE); + _plm->put("R7", acq_CEE); + _plm->put("R8", acq_noCEE); + _plm->put("R9", corr_misCEE); + _plm->put("R10",acq_misCEE); + _plm->put("R11",acq_misnoCEE); + + // ---- NOTA BENE ------------------------ + // l'iva vendite nei plm non comprende + // l'iva agenzie di viaggio, calcolata + // in liquidazione (mensile o trimestrale) + // --------------------------------------- + // Mod 7/7/95: calcolo effettuato anche qui, in modo da + // avere l'IVA dovuta per riportarla nei progressivi + // Dato che il resto funziona non tocco nulla, ovvero + // duplico il calcolo di write_liq, nella remota ipotesi + // che ci siano due o piu' attivita' e siano tutte + // agenzie di viaggio + real perc_r = (acq_misCEE * CENTO)/(acq_misCEE + acq_misnoCEE); + real ivm = (corr_misCEE * perc_r)/CENTO; ivm.round(ROUND_LIRA); + real tc = (corr_CEE + ivm); + real ta = (acq_CEE + acq_misCEE); + real bi = tc - ta - credito_costo_prec(month); + + if (bi.sign() > 0) + { + deb_mens = (bi /((CENTO + aliquota_agvia())/CENTO)) * + (aliquota_agvia()/CENTO); + deb_mens.ceil(ROUND_LIRA); // ceil voluto MI3074 + } + _pom->put("R13", deb_mens); + } + else if (_isagricolo) + { + _plm->put("R5", agr_1); + _plm->put("R6", agr_2); + _plm->put("R7", agr_3); + _plm->put("R8", agr_4); + _plm->put("R9", agr_5); + _plm->put("R10", agr_6); + _plm->put("R11", agr_7); + _pum->put("R10", agr_1i); + _pum->put("R11", agr_2i); + + // Il porco agricoltore spende poco e paga meno + vendite_iva = agr_2; + acquisti_iva = agr_3; + + // nuovo calcolo IVA detraibile + if (!agr_7.is_zero()) + { + real pdetr = (agr_2i / (agr_1i + agr_2i)); + pdetr.round(2); + acquisti_iva += agr_7 * pdetr; + acquisti_iva.round(ROUND_LIRA); + } + } + + _plm->put("R0", vendite_iva); + _plm->put("R1", acquisti_iva); + _plm->put("R3", ult_detr); + // probabilmente R4 serviva per il decalage e non si usera' + _plm->put("R12", _prorata); // per comodita' in stampa + _plm->put("B0", "X"); // calcolato (invalidato dalla primanota) + _pom->put("R9", acq_ies); + _pom->put("R10", acq_ies_iva); + _pum->put("R8", acq_pint); + _pum->put("R9", acq_pint_iva); + _pam->put("R10", spgen); + _pam->put("R11", spgen_iva); + _pom->put("R0", totintra); + _pom->put("R1", nond19_imp); + _pom->put("R2", nond19_iva); + _pom->put("R3", ammort_det); + _pom->put("R4", ammort_det_iva); + _pom->put("R5", acq_riv); + _pom->put("R6", acq_riv_iva); + _pom->put("R7", leasing); + _pom->put("R8", leasing_iva); + _pom->put("R11", ammort_indet); + _pom->put("R12", ammort_indet_iva); + _pum->put("R0", cess_amm); + _pum->put("R1", cess_amm_iva); + _pum->put("R2", ammort_6); + _pum->put("R3", ammort_6_iva); + _pum->put("R4", esenti_b1); + _pum->put("R5", esenti_b2); + _pum->put("R6", esenti_b3); + _pum->put("R7", esenti_b14); + _pum->put("R12", esni_rimb); + _pam->put("R0", acquisti); + _pam->put("R1", vendite); + _pam->put("R6", assp_imp); + _pam->put("R7", assp_iva); + _pam->put("R8", vssp_imp); + _pam->put("R9", vssp_iva); + _pam->put("R4", bdog_imp); + _pam->put("R5", bdog_iva); + + _plm->rewrite(); + _pam->rewrite(); + _pum->rewrite(); + _pom->rewrite(); +} + + +void TLiquidazione_app::write_liq(int month, const char* codatts) + // Calcolo liq. mensili e liq. annuali +{ + TToken_string atts(codatts); + const char* tmpatt; + + // liq. differita: considera mese precedente (solo per i risultati) + int deltam = month; + if (_isdifferita && !is_first_month(month) && month != 13) + month -= (_freqviva == "T" ? 3 : 1); + deltam -= month; + + real risultato = 0.0; + real detrazioni = 0.0; + real versamenti = 0.0; + real vers_int = 0.0; + real rimborsi = 0.0; + real rettifiche = 0.0; + real res_debt = 0.0; + real res_cred = 0.0; + real cred_prec = 0.0; + real debt_precd = 0.0; + real acc_dec = 0.0; + real iva_vend = 0.0; + real iva_acq = 0.0; + + // totali per agenzie viaggio + real c_iCEE = 0.0; + real c_eCEE = 0.0; + real a_iCEE = 0.0; + real a_eCEE = 0.0; + real c_mCEE = 0.0; + real a_mCEE = 0.0; + real a_meCEE = 0.0; + real cred_cost = 0.0; + real deb_mens = 0.0; + real perc_r = 0.0; + + // totali per annuali + real vol_aff_1 = 0.0; + real vol_aff_2 = 0.0; + real vol_aff_t = 0.0; + real vol_aff_l = 0.0; + real tot_cong = 0.0; + + bool differita = FALSE; + int attc = 0; // counter attivita' + + while ((tmpatt = atts.get()) != NULL) + { + TString att(tmpatt); + + if (_isdifferita && is_first_month(month)) + { + // usa i totali del mese di dicembre dell'anno + // precedente + differita = TRUE; + TString yr(_year); + _year = format("%d", atoi(_year)-1); + if (!look_lim(12)) + { + _year = yr; + differita = FALSE; + } + } + if (differita) + { + if (attc == 0) + { + risultato = result_liq(12); + deb_mens = _lim->get_real("R3"); + detrazioni = _lim->get_real("R6"); + perc_r = _lim->get_real("R4"); + cred_cost = _lim->get_real("R2"); + rettifiche = _lim->get_real("R5"); + rimborsi = _lim->get_real("R1"); + // leggi anche tutti gli altri totali + acc_dec = _lim->get_real("R11"); + res_cred = _lim->get_real("R12"); + res_debt = _lim->get_real("R13"); + iva_vend = _lam->get_real("R0"); + iva_acq = _lam->get_real("R1"); + cred_prec = _lam->get_real("R2"); + debt_precd = _lam->get_real("R3"); + _year = format("%d", atoi(_year)+1); + } + } + else + { + for (int m = 1; m <= 13; m++) + { + // ciclo su tutti i mesi del caso (1 o 3; + // tutti se annuale) + if (!is_month_ok(m, month)) + continue; + + look_plm(m, att); + bool is_lim = look_lim(m); + + // gia' conteggiato: prorata + // da conteggiare: IVA vendite ag. viaggio + // a debito: IVA vendite, debito precedente + // a credito: IVA acquisti, ulteriori detrazioni 1 e 2 + + iva_vend += _plm->get_real("R0"); + iva_acq += _plm->get_real("R1"); + risultato += (_plm->get_real("R0") - _plm->get_real("R1")); + detrazioni+= (_plm->get_real("R3") + _plm->get_real("R4")); + res_debt += _plm->get_real("R0"); + res_cred += _plm->get_real("R1"); + + // detrazioni solo non in regime agricolo + if (!_isagricolo) + { + risultato -= (_plm->get_real("R3") + _plm->get_real("R4")); + res_cred += (_plm->get_real("R3") + _plm->get_real("R4")); + } + /* se annuale, somma versamenti mesi 1-12 + * solo una volta (non per tutte le attivita') + */ + if (attc == 0 && month == 13) + { + // l'acconto a dicembre si conteggia a parte solo + // nei casi previsti e non in annuale (vedi sotto) + real vs(versamenti_IVA(m , m == 12 ? "1" : "1|7")); + real vi(versamenti_IVA(m,"5")); + versamenti += vs; + vers_int += vi; + res_cred += vs + vi; + } + + /* + * rimborso se chiesto e previsto + */ + if (attc == 0 && is_lim) + { + risultato += _lim->get_real("R1"); + rimborsi += _lim->get_real("R1"); + res_debt += _lim->get_real("R1"); + } + /* + * rettifiche gia' col loro bravo segno + */ + if (attc == 0 && is_lim) + { + // se sono per benzinaro le conta solo in annuale, + // se no vanno solo in periodica + TString descrett(_lim->get("S0")); + bool isforbenzinaro = descrett[0] == '$' || + (descrett[0] == '>' && descrett[1] == '>'); + + if ((isforbenzinaro && _isannual) || + (!isforbenzinaro && !_isannual)) + { + risultato += _lim->get_real("R5"); + rettifiche += _lim->get_real("R5"); + if (_lim->get_real("R5").sign() < 0) + res_cred += abs(_lim->get_real("R5")); + else + res_debt += abs(_lim->get_real("R5")); + } + } + + /* totalizza importi 74 ter */ + if (_isviaggio) + { + // somma totali per calcolo successivo + c_iCEE += _plm->get_real("R5"); + c_eCEE += _plm->get_real("R6"); + a_iCEE += _plm->get_real("R7"); + a_eCEE += _plm->get_real("R8"); + c_mCEE += _plm->get_real("R9"); + a_mCEE += _plm->get_real("R10"); + a_meCEE += _plm->get_real("R11"); + } + } // fine ciclo sul mese + // counter attivita' per evitare troppi versamenti + attc++; + } // fine ciclo su attivita' + + if (!(_isdifferita && is_first_month(month))) + { + if (_isviaggio) + { + // calcolo credito costo, debito mensile, perc. ripart. + perc_r = (a_mCEE * CENTO)/(a_mCEE + a_meCEE); + real ivm = (c_mCEE * perc_r)/CENTO; ivm.round(ROUND_LIRA); + real tc = (c_iCEE + ivm); + real ta = (a_iCEE + a_mCEE); + real bi = tc - ta - credito_costo_prec(month); + + if (bi.sign() < 0) + // credito di costo + { + cred_cost = abs(bi); + cred_cost.round(ROUND_LIRA); + } + else + { + deb_mens = (bi /((CENTO + aliquota_agvia())/CENTO)) * + (aliquota_agvia()/CENTO); + deb_mens.ceil(ROUND_LIRA); // ceil voluto MI3074 + risultato += deb_mens; + res_debt += deb_mens; + iva_vend += deb_mens; + } + } + } + } + + if (!(_isdifferita && is_first_month(month))) + { + if (month < 13) + { + // toglie credito precedente + cred_prec = credito_prec(month); + risultato -= cred_prec; + res_cred += cred_prec; + // vedi se c'era un debito precedente per debiti < 50.000 + debt_precd = debt_prec(month); + risultato += debt_precd; + res_debt += debt_precd; + } + else + { + // per l'annuale considera solo il credito a inizio anno + cred_prec = credito_prec(1); + risultato -= cred_prec; + res_cred += cred_prec; + } + } + else if (_isdifferita && !is_first_month(month) && month < 13) + { + // toglie credito precedente + cred_prec = credito_prec(month); + risultato -= cred_prec; + res_cred += cred_prec; + // vedi se c'era un debito precedente per debiti < 50.000 + debt_precd = debt_prec(month); + risultato += debt_precd; + res_debt += debt_precd; + + // folie bergere: se il mese precedente, che e' poi questo che ho calcolato, + // era a credito, devo tener conto del credito precedente che e' quello di + // questo mese (Vladimiro MI3170), ovvero devo RADDOPPIARE il credito, il che + // e' semplicemente roba da matti + if (!cred_prec.is_zero()) + { + risultato -= cred_prec; + res_cred += cred_prec; + cred_prec += cred_prec; // AH AH UAH IH UHU + } + } + + if (month == 13) + { + // totalizza volumi affari e calcola nuovo prorata + // per tutte le attivita' + atts.restart(); + while ((tmpatt = atts.get()) != NULL) + { + TString att(tmpatt); + int tipoatt = att[att.len() -1] - '0'; + if (tipoatt == 1) // su PLA l'attivita' e' sempre 1 + { + look_pla(att); + real vf1 = _pla->get_real("R14"); + real vf2(_pla->get("S1")); + real iaq = _pla->get_real("R11"); // IVA acquisti + real ppg = _pla->get_real("R12"); // pro-rata pagato + + vol_aff_1 += vf1; + vol_aff_2 += vf2; + vol_aff_t = vf1 + vf2; + vol_aff_l += _pla->get_real("R0"); // volume affari lordo + + real es_b1 = _pla->get_real("R1"); + real es_b2 = _pla->get_real("R2"); + real es_b3 = _pla->get_real("R3"); + real csamm = _pla->get_real("R4"); + + // calcola nuovo prorata per ogni attivita' (miste: 1+2) + real ris = vol_aff_t - csamm - es_b3; + real prorata(0.0); + if (!ris.is_zero()) + prorata = (es_b1/ris) * CENTO; + real conguaglio = 0.0; + prorata.round(ROUND_LIRA); + if (prorata != _prorata) + { + // calcolo conguaglio -- se positivo e' a debito + real topay = iaq * (prorata / CENTO); + conguaglio = topay - ppg; + conguaglio.round(ROUND_LIRA); + } + _pla->put("R9", conguaglio); + _pla->put("R10",prorata); + tot_cong += conguaglio; + _pla->rewrite(); + + // scrivi nuovo prorata in tabella anno successivo + TString yr = _year; + _year = format("%d", atoi(_year) + 1); + look_pla(att, TRUE); + _pla->put("R8", prorata); + _pla->rewrite(); + _year = yr; + } + } + + look_lia(); + _lia->put("R1", vol_aff_l); + _lia->put("R2", vol_aff_1); + _lia->put("R3", vol_aff_2); + _lia->put("R4", acc_dec); + _lia->put("R5", cred_cost); + _lia->rewrite(); + } + + // comprende anche il conguaglio prorata + risultato += tot_cong; + if (tot_cong.sign() > 0) res_debt += tot_cong; + if (tot_cong.sign() < 0) res_cred += abs(tot_cong); + + look_lim(month+deltam,TRUE); + // azzeriamo tutto (tranne r1, r5, s1, s0, s7) + TString codtab = _lim->get("CODTAB"); + + real r5 = _lim->get("R5"); + real r1 = _lim->get("R1"); + TString s7 = _lim->get("S7"); + TString s0 = _lim->get("S0"); + TString s1 = _lim->get("S1"); + bool wasb0 = _lim->get_bool("B0"); + bool wasb1 = _lim->get_bool("B1"); + + _lim->zero(); + _lim->put("CODTAB", codtab); + _lim->put("R1", r1); + _lim->put("R5", r5); + _lim->put("S0", s0); + _lim->put("S1", s1); + _lim->put("S7", s7); + _lim->put("B0", wasb0 ? "X" : ""); + _lim->put("B1", wasb1 ? "X" : ""); + + /* + * versamenti effettuati: si conteggiano in R0, + * sono > 0 solo se andavano calcolati (vedi sopra) + */ + risultato -= versamenti + vers_int; + /* + * acconto dicembre se previsto + */ + if ((month == 12 && _isbenzinaro) || + (month >= 12 && _freqviva == "M")) + { + risultato -= versamenti_IVA(12,"7"); + acc_dec = versamenti_IVA(12,"7"); + res_cred += acc_dec; + } + + // in annuale si arrotondera' a 1000 in stampa + // se no il conguaglio prorata fa casino + risultato.round(ROUND_LIRA); + + _lim->put("R0",risultato); + _lim->put("R2",cred_cost); + _lim->put("R3",deb_mens); + _lim->put("R4",perc_r); + + if (!_isagricolo) + _lim->put("R6",detrazioni); + else // per evitare sbagli nei ricalcoli esterni + _lim->put("R6",""); + + if (month == 13 || differita) + { + // scrivi totali rettifiche e rimborsi + // nella finale oppure se copiati da + // anno precedente + _lim->put("R1",rimborsi); + _lim->put("R5",rettifiche); + } + + /* + * Interessi dovuti solo da trimestrali in periodica, + * Era anche non benzinari, smentito da Cinzia (MI0853); + * Ora gestito esplicitamente nei parametri ditta, forzato + * FALSE per ditte mensili e liq. annuale + */ + if (_isintr && month < 13) + { + real interesse = interesse_trimestrale(_month); + real ivi = risultato * (interesse / CENTO); + ivi.ceil(ROUND_LIRA); + _lim->put("R14", ivi); + } + + // questo serve anche per la visualizzazione e per l'estrazione deleghe + if (_isintr && month < 13) + _lim->put("R10",interesse_trimestrale(_month)); + + // totale conguaglio su tutte le attivita' + _lim->put("R7", tot_cong); + _lim->put("R8", versamenti); + _lim->put("R9", vers_int); + _lam->put("R0", iva_vend); + _lam->put("R1", iva_acq); + _lam->put("R2", cred_prec); + _lam->put("R3", debt_precd); + _lim->put("R11", acc_dec); + _lim->put("R12", res_cred); + _lim->put("R13", res_debt); + + + if (!_recalc_only) + _lim->put("B0","X"); + if (_isfinal) _lim->put("B1", "X"); + + _lim->rewrite(); + _lam->rewrite(); +} + +void TLiquidazione_app::recalc_annual(const char* att) +{ + // viene chiamata 2 volte per le att. miste; PLA e' stata + // azzerata dove serve da update_firm se siamo all'annuale + real es_b1 = 0.0; + real es_b2 = 0.0; + real es_b3 = 0.0; + real cess_amm = 0.0; + real vendite = 0.0; + real pro_pag = 0.0; + real iva_acq = 0.0; + real ven_lrd = 0.0; + real volaff1 = 0.0; + real volaff2 = 0.0; + + int tipoatt = att[strlen(att) -1] - '0'; + TString aaa(att); + + look_pla(aaa); + volaff1 = _pla->get_real("R14"); + volaff2 = (const char*)_pla->get("S1"); + vendite = _pla->get_real("R0"); + es_b1 = _pla->get_real("R1"); + es_b2 = _pla->get_real("R2"); + es_b3 = _pla->get_real("R3"); + cess_amm = _pla->get_real("R4"); + pro_pag = _pla->get_real("R12"); + iva_acq = _pla->get_real("R11"); + + for (_pim->first(); !_pim->eof(); _pim->next()) + { + if (_year != *_pim_anno) continue; + + int tipocr = atoi(*_pim_tipocr); + TString16 codiva = *_pim_codiva; + TString16 reg = *_pim_codreg; + look_iva(codiva); look_reg(reg); + + if ( // ESCLUSI: + strcmp(att,*_pim_codatt) != 0 || + (int)_reg->get_long("I0") != vendita || // non vendite + tipocr == 4 || // cessioni beni ammortizzabili + _iva->get("S1") == "NS" || // non soggetti + _iva->get("S0") == "B3" || // bi tre + _reg->get_bool("B1")) // sospensione di imposta + continue; + + if (tipoatt == 1) volaff1 += _pim->get_real("R0"); + else volaff2 += _pim->get_real("R0"); + } + + // calcola esenti, cessioni, lordo vendite, prorata pagato + // e IVA acquisti dai plm/ptm/pum/pam/pom + + for (int i = 1; i <= 13; i++) + { + if (!look_plm(i,aaa)) + continue; + + vendite += _pam->get_real("R1"); + iva_acq += _plm->get_real("R1"); + es_b1 += _pum->get_real("R4"); + es_b2 += _pum->get_real("R5"); + es_b3 += _pum->get_real("R6"); + cess_amm += _pum->get_real("R0"); + pro_pag += _plm->get_real("R2"); + } + + _pla->put("R0", vendite); + _pla->put("R1", es_b1); + _pla->put("R2", es_b2); + _pla->put("R3", es_b3); + _pla->put("R4", cess_amm); + _pla->put("R11", iva_acq); + _pla->put("R12", pro_pag); + _pla->put("R14", volaff1); + _pla->put("S1", volaff2.string()); + _pla->rewrite(); +} + +======= // ------------------------------------------------------------ // Calcolo liquidazioni // Part 2: calcolo @@ -1724,3 +3473,4 @@ void TLiquidazione_app::recalc_annual(const char* att) _pla->rewrite(); } +>>>>>>> 1.100 diff --git a/cg/cg4303.cpp b/cg/cg4303.cpp index c470dd9e4..419511bae 100755 --- a/cg/cg4303.cpp +++ b/cg/cg4303.cpp @@ -1,3 +1,524 @@ +<<<<<<< cg4303.cpp +// ----------------------------------------------------------------- +// Calcolo liquidazione +// part 4: casi particolari +// fv 2-2-94 +// ----------------------------------------------------------------- + +#include "cg4300.h" + +void TLiquidazione_app::add_plafond(int month, const char* codatt, int type, + real& howmuch, bool intra) +{ + look_ppa(month,codatt,type); + + TString att(codatt); + + real r0 = _ppa_r->get_real("R0"); + real r1 = _ppa_r->get_real("R1"); + real r2 = _ppa_r->get_real("R2"); + + if (intra) r1 += howmuch; + else r0 += howmuch; + + if (r2 < (r0+r1)) + describe_error("Acquisti in eccesso rispetto al plafond disponibile", + att.cut(5)); + _ppa_r->put("R0",r0); + _ppa_r->put("R1",r1); + _ppa->rewrite(); +} + +void TLiquidazione_app::zero_plafond (int month, const char* codatt) +{ + for (int jj = 1; jj <= 3; jj++) // three types of plafond + { + real r; + look_ppa(month,codatt,jj,TRUE); + if (is_first_month(month)) + { + r = (jj == 1 ? _p8 : (jj == 2 ? _p8b : _p9)); + } + else + { + long rn = _ppa->recno(); + + // se non c'e' quello del mese prima c'e' poco da fare, + // si ricalcola tutto + if (!look_ppa(previous_month(month),codatt,jj)) + // mazza che bella chiamata ricorsiva + { + if (_recalc != needed) + { + describe_error("Progressivi plafond non ricalcolati per " + "i mesi precedenti: possibili errori", + codatt); + } + else + { + if (!update_att(previous_month(month),codatt, FALSE)) + describe_error("Progressivi plafond non ricalcolati per " + "i mesi precedenti: possibili errori", + codatt); + look_ppa(previous_month(month),codatt,jj); + } + } + r = _ppa_r->get_real("R2") - + _ppa_r->get_real("R0") - + _ppa_r->get_real("R1"); + + _ppa->readat(rn); + } + _ppa_r->put("R2",r); + _ppa_r->put("R0",""); + _ppa_r->put("R1",""); + _ppa->rewrite(); + } // for tipo esenzione plafond +} + +// ricalcolo dei corrispettivi +void TLiquidazione_app::recalc_corrispettivi(int month, const char* codatt) +{ + if (_corr_arr.items() == 0) return; + // ricalcola (solo per il mese in corso!) operando sull'array + for (int i = 0; i < _corr_arr.items(); i++) + { + _CorrItem* ci = (_CorrItem*)&_corr_arr[i]; + if (ci->_month != month || ci->_codatt != codatt) + continue; + + real imposta = (abs(ci->_totale) * ci->_aliquota)/(ci->_aliquota + 1.00); + imposta.ceil(); + if (ci->_totale.sign() < 0) imposta = -imposta; + real imponibile = ci->_totale - imposta; + + // aggiusto l'IVA vendite nei plm + look_plm(month, codatt); + real ive = _plm->get_real("R0"); + ive += imposta; + _plm->put("R0",ive); + _plm->rewrite(); + // .. e il volume di affari nei pam + real vaf = _pam->get_real("R1"); + vaf += imponibile; + _pam->put("R1", vaf); + _pam->rewrite(); + + // Aggiorno i luridi pim + look_pim(month, codatt, ci->_codreg, "", ci->_codiva, ci->_tipodet, TRUE); + + imponibile += _pim->get_real("R0"); + imposta += _pim->get_real("R1"); + _pim->put("R0", imponibile); + _pim->put("R1", imposta); + _pim->rewrite(); + + } +} + +// ricalcolo della malefica ventilazione +void TLiquidazione_app::recalc_ventilation(int month, const char* codatt) +{ + if (!_isvent || _isagricolo || _isviaggio || _vend_arr.items() == 0) return; + + TString att(codatt); + + // 1) ricalcola i pim dei mesi dal primo al corrente se necessario + recalc rcl = _recalc; + _recalc = needed; + for (int m = 1; m < month; m++) + update_att(m,codatt, FALSE); + _recalc = rcl; + + _vent_arr.destroy(); + + for (m = 1; m <= month; m++) + { + // aggiunge gli acquisti del mese m operando sui pim + for (_pim->first(); !_pim->eof(); _pim->next()) + { + if (_year != *_pim_anno) continue; + + // se e' acquisto beni per rivendita + int tipocr = atoi(*_pim_tipocr); + int mese = atoi(*_pim_mese); + int tipodet = atoi(*_pim_tipodet); + look_iva(*_pim_codiva); + // base di riparto solo se non esente, non soggetto, non imponibile + TString16 tipoiva(_iva->get("S1")); + TString16 reg = *_pim_codreg; + + + /* + * caso particolare SENSU Vladimiro (1995) #MI3001 + * questi vengono pero' conteggiati nel totale + * acquisti per rivendita + */ + if (tipocr == 5 && tipodet == 3) + continue; + + TString att(codatt); + + if (tipocr == 1 && (mese == m) && + att == (const char*)(*_pim_codatt)) + { + if (tipoiva != "NS" && tipoiva != "NI" && tipoiva != "ES") + { + real lurd = _pim->get_real("R0"); + lurd += _pim->get_real("R1"); + real perc = _iva->get_real("R0"); + TString other = _iva->get("S6"); + if (!other.empty()) + { + // ventila a un altro codice + look_iva(other); + perc = _iva->get_real("R0"); + } + add_ventilation(perc / CENTO, lurd, *_pim_codiva, other); + } + } + } + } + + // 2) calcola totale acquisti su tutte le aliquote + real totacq = 0.0; + real totven = 0.0; + + for (int j = 0; j < _vent_arr.items(); j++) + { + _VentItem& vv = (_VentItem&)_vent_arr[j]; + totacq += vv._totale; + } + + // 3) ricalcola (solo per il mese in corso!) operando sull'array + for (int i = 0; i < _vend_arr.items(); i++) + { + _VendItem* vi = (_VendItem*)&_vend_arr[i]; + if (vi->_month != month) + continue; + + // questo serve solo per il prospettino di m. + totven += vi->_totale; + + // 3.2) calcola percentuali di ripartizione e prepara l'affettatrice + TDistrib dst(vi->_totale,ROUND_LIRA); + for (j = 0; j < _vent_arr.items(); j++) + { + _VentItem* vv = (_VentItem*)&_vent_arr[j]; + dst.add(vv->_totale/totacq); + } + + // 3.3) affetta l'importo + for (j = 0; j < _vent_arr.items(); j++) + { + _VentItem* vv = (_VentItem*)&_vent_arr[j]; + real imponibile = dst.get(); + real div(1.0); div += vv->_aliquota; + real imposta = imponibile - (imponibile/div); + imposta.ceil(ROUND_LIRA); + imponibile -= imposta; + + // aggiusto l'IVA vendite nei plm + look_plm(month, codatt); + real ive = _plm->get_real("R0"); + ive += imposta; + _plm->put("R0",ive); + _plm->rewrite(); + // .. e il volume di affari nei pam + real vaf = _pam->get_real("R1"); + vaf += imponibile; + _pam->put("R1", vaf); + _pam->rewrite(); + + // Aggiorno i luridi pim + look_pim(month, codatt, vi->_codreg, "0", vv->_codiva, vi->_tipodet, TRUE); + + imponibile += _pim->get_real("R0"); + imposta += _pim->get_real("R1"); + _pim->put("R0", imponibile); + _pim->put("R1", imposta); + _pim->put("S4", vv->_other); + // segnale per comodita' + _pim->put("B1","X"); + _pim->rewrite(); + } + } + + // memorizza totali per il prospettino di m. + look_plm(month, codatt); + + // PAM e PUM + _pam->put("R2",totacq); + _pam->put("R3",totven); + _pam->rewrite(); +} + + +// questa serve per il rimborso secondo le +// nuove cazzonorme +class rObj : public TObject +{ +public: + real _imp; + real _iva; + real _perc; + + rObj() {} + virtual ~rObj() {} +}; + + +// defines per stabilire quale cazzo di metodo piace oggi alla prassi +// ------------------------------------------------------------------ +// Considera tutti i mesi del trimestre fino a quello indicato +// se lasciato indefinito usa solo il mese passato +#define OGGI_GLI_TIRA_DI_USARE_TRE_MESI + +_DescrItem* TLiquidazione_app::recalc_rimborso(int month, const char* codatts, + bool stliq) +{ + // calcola condizioni per il diritto al rimborso infracazzuale + // chiamata soltanto per i trimestri anche se annuale + // aggiornata a normative per anno liq. > 1994 + + bool rimborsami = FALSE; + _DescrItem* d = NULL; + TToken_string atts(codatts); + const char* tmpatt; + TString att; + + real es_ni = 0.0; + real vol_aff = 0.0;; + + while ((tmpatt = atts.get()) != NULL) + { + att = tmpatt; +#ifdef OGGI_GLI_TIRA_DI_USARE_TRE_MESI + for (int m = (month == 13 ? 1 : (next_trim(month)-2)); m <= month; m++) + { +#else + int m = month; +#endif + if (!look_plm(m,att)) continue; + + vol_aff += _pam->get_real("R1"); + es_ni += _pum->get_real("R12"); +#ifdef OGGI_GLI_TIRA_DI_USARE_TRE_MESI + } +#endif + } + + // condizione 1 + real prc = es_ni/vol_aff; prc.round(2); + + if (stliq && !vol_aff.is_zero() && prc > MIN_PARTE_ESENTE) + { + rimborsami = TRUE; + d = new _DescrItem(RIMBORSO); + d->_f0 = TRUE; + d->_r0 = es_ni; + d->_r1 = vol_aff; + } + + // ---------------------- condizione 2 + // u' casinu pazzescu d'u nuiu guvernu + + real vtot = 0.0; + real atot = 0.0; + real ivav = 0.0; + real ivaa = 0.0; + + real alv = 0.0; // aliquota media vendite + real ala = 0.0; // aliquota media acquisti + + /*********************************************************************** + Sembra che sia stato annullato subito dopo che ho finito di scrivere + queste 150 righe di casino + *********************************************************************** + // due array dove ficcare i totali per + // codiva in ordine di imponibile + TArray varr, aarr; + + // scorri i bellissimi progressivi mensili rimborso + for (_rmb->first(); !_rmb->eof(); _rmb->next()) + { + int year = atoi((const char*)_year); + int ryear = atoi((const char*)(*_rmb_anno)); + int rmese = atoi((const char*)(*_rmb_mese)); + + if (year != ryear || (rmese < (month - 2) || rmese > month)) + continue; + + real imp = _rmb->get("R0"); + real iva = _rmb->get("R1"); + real per = _rmb->get("R2"); + + rObj* rb = new rObj; + rb->_imp = imp; + rb->_iva = iva; + rb->_perc = per; + + TArray& arr = (tiporeg)atoi((const char*)(*_rmb_tiporeg)) == vendita ? varr : aarr; + + for (int i = 0; i < arr.items(); i++) + { + rObj& robj = (rObj&)arr[i]; + if (robj._imp < imp) + break; + } + arr.insert(rb, i); + + // totali imponibili + if ((tiporeg)atoi((const char*)(*_rmb_tiporeg)) == vendita) + vtot += imp; + else + atot += imp; + } + + // se ci sono due o piu' imponibili uguali devo + // sostituire l'imposta con la media delle aliquote + // ciclo uguale sui due array + for (int w = 0; w < 2; w++) + { + TArray& arr = w == 0 ? varr : aarr; + for (int i = 0; i < arr.items(); i++) + { + rObj& robj = (rObj&)arr[i]; + real impref = robj._imp; + real perc = robj._perc; + + for (int j = i+1; j < arr.items(); j++) + { + rObj& rbj = (rObj&)arr[j]; + if (rbj._imp != impref) + break; + perc += rbj._perc; + } + // riaggiustesbimo + if (j > i+1) + { + // funzionerebbe comunque ma risparmiamo una + // divisione per 1 + real ndiv(j-i); + perc /= ndiv; + for (; i < j; i++) + { + rObj& rbj = (rObj&)arr[i]; + rbj._iva = rbj._imp * (perc/CENTO); + rbj._iva.round(ROUND_LIRA); + } + i --; + } + } + } + + // 51 per cento + vtot *= PERC_IMP_RIMBORSABILE; + atot *= PERC_IMP_RIMBORSABILE; + + for (w = 0; w < 2; w++) + { + TArray& arr = w == 0 ? varr : aarr; + real timp = w == 0 ? vtot : atot; + real tiva = 0.0; + + for (int i = 0; i < arr.items(); i++) + { + rObj& robj = (rObj&)arr[i]; + if (timp >= robj._imp) + { + tiva += robj._iva; + timp -= robj._imp; + } + else + { + real perc = timp/robj._imp; + if (!perc.is_zero()) + { + real ttiv = robj._iva * perc; + ttiv.round(ROUND_LIRA); + tiva += ttiv; + } + break; + } + } + if (w == 0) ivav = tiva; + else ivaa = tiva; + } + + **************************************************************************/ + + // scorri i bellissimi progressivi mensili + for (_pim->first(); !_pim->eof(); _pim->next()) + { + int year = atoi((const char*)_year); + int ryear = atoi(*_pim_anno); + int rmese = atoi(*_pim_mese); + + // B3 significa che e' acq. o vendita valido per rimb. per aliquota + if (!_pim->get_bool("B3")) continue; + +#ifdef OGGI_GLI_TIRA_DI_USARE_TRE_MESI + if (year != ryear || + (month != 13 && (rmese < (next_trim(month)-2) || rmese > month))) + continue; +#else + if (year != ryear || (month != rmese)) + continue; +#endif + + int tipomov = (tiporeg)_pim->get_long("I1"); + + real imp = _pim->get("R0"); + real iva = _pim->get("R1"); + + // totali imponibili + if (tipomov == vendita) + { + vtot += imp; + ivav += iva; + } + else + { + atot += imp; + ivaa += iva; + } + } + + // finalmente + alv = ivav/vtot; alv.round(4); + ala = ivaa/atot; ala.round(4); + + // vedi condizioni + rimborsami = ala > alv; + if (rimborsami) + { + // vedi di quanto ala eccede alv; deve essere > 10% + real ecc = ((ala/alv) - real(1.0)); + rimborsami = (ecc >= SOGLIA_MAGGIORE_ALIQUOTA_DEL_CAZZO_PER_AVER_DIRITTO_AL_RIMBORSO); + } + + if (stliq && rimborsami) + { + if (d == NULL) d = new _DescrItem(RIMBORSO); + d->_f1 = TRUE; + d->_r2 = vtot; + d->_r3 = atot; + d->_r4 = ivav; + d->_r5 = ivaa; + d->_r6 = alv * CENTO; + d->_r7 = ala * CENTO; + } + + if (rimborsami && is_month_ok_strict(month)) + { + look_lim(month); + _lim->put("B2", "X"); + _lim->rewrite(); + } + return d; +} +======= // ----------------------------------------------------------------- // Calcolo liquidazione // part 4: casi particolari @@ -536,3 +1057,4 @@ _DescrItem* TLiquidazione_app::recalc_rimborso(int month, const char* codatts, } return d; } +>>>>>>> 1.41 diff --git a/cg/cg4400.cpp b/cg/cg4400.cpp index 982b0b7b8..6b7178f83 100755 --- a/cg/cg4400.cpp +++ b/cg/cg4400.cpp @@ -1,3299 +1,3300 @@ -// cg4400.cpp -// Stampa registri IVA -#include "cg4.h" -#include "cg4400.h" -#include "cg4400a.h" -#include "cg4400b.h" - -static TString256 TMP; - -inline CG4400_application& app() { return (CG4400_application&)main_app(); } - -bool CG4400_application::filter_func (const TRelation * r) -{ - TLocalisamfile& mov = r->lfile(LF_MOV); - TString16 codreg = mov.get(MOV_REG); - TDate datareg = mov.get_date(MOV_DATAREG); - int annoiva = mov.get_int(MOV_ANNOIVA); - bool regst = mov.get_bool(MOV_REGST); - - if (codreg != (app()._codreg) || annoiva != (app()._annoes)) - return FALSE; - - if (app()._data_da.string() != "" && app()._data_a.string() != "") - if ( (datareg < app()._data_da || datareg > app()._data_a ) || (!datareg.ok()) ) - return FALSE; - - if (app()._tipo_stampa != 1) //stampa di bollato - if (regst) //il movimento e' gia' stato stampato in forma definitiva - return FALSE; - - if (datareg.month() < app()._stampa_mese) - app()._stampa_mese = datareg.month(); - return TRUE; -} - -HIDDEN int compare_rows(const TObject** o1, const TObject** o2) -{ - TRiga* r1 = (TRiga*)*o1; - TRiga* r2 = (TRiga*)*o2; - - return (strcmp((const char*)r1->_codiva, (const char*)r2->_codiva)); -} - -HIDDEN int compare_fields(const TObject** o1, const TObject** o2) -{ - TRigaiva* r1 = (TRigaiva*)*o1; - TRigaiva* r2 = (TRigaiva*)*o2; - TString16 campo1; - TString16 campo2; - - campo1.format("%d%4s", r1->_tipodet, (const char*)r1->_codiva); - campo2.format("%d%4s", r2->_tipodet, (const char*)r2->_codiva); - return strcmp(campo1, campo2); -} - -bool CG4400_application::stampa_totali_finali() -{ - TConfig conf(CONFIG_DITTA); - return conf.get_bool("StTfFr"); -} - -bool CG4400_application::stampa_datareg() -{ - TConfig conf(CONFIG_STUDIO); - return conf.get_bool("NoDtRg"); -} - -bool CG4400_application::mask_select (TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - app()._ditte->enable_check(); - // seleziona e aggiungi alle gia' selezionate - if (app()._ditte->run() == K_ENTER) - { - for (long j = 0l; j < app()._ditte->items(); j++) - app()._selected.set(j, app()._ditte->checked(j)); - app().set_choice_limits(f.mask()); - } - } - return TRUE; -} - -bool CG4400_application::mask_azzera (TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - app()._selected.reset(); - f.mask().reset(F_SELECT); - f.mask().reset(DA_CODICE); - f.mask().reset(A_CODICE); - app()._ditte->check(-1, FALSE); - } - return TRUE; -} - -bool CG4400_application::mask_tipo_stampa(TMask_field& f, KEY k) -{ - TMask& m = f.mask(); - - if (k == K_SPACE) - { - int tipo_stampa = m.get_int(TIPO_STAMPA); - if (tipo_stampa == 3) //stampa su libro unico - { - m.enable_page(1); - TMask_field& cc = f.mask().field(CODICE_LIB_UN); - cc.set_dirty(); - } - else - m.disable_page(1); - } - return TRUE; -} - -bool CG4400_application::mask_mese (TMask_field& f, KEY k) -{ - if (k == K_SPACE) - { - const short id = f.dlg(); - int mese; - if (id == MESE) //Per stampa su libro unico - mese = f.mask().get_int(MESE); - if (id == FINO_A_MESE) - mese = f.mask().get_int(FINO_A_MESE); //Per stampa su bollato - if (id == MESE) - { - if (mese == 12) - { - f.mask().show (TIPO_RIEPILOGATIVO); - f.mask().show (RIF_VID); - } - else - { - f.mask().hide (TIPO_RIEPILOGATIVO); - f.mask().hide (RIF_VID); - } - //TMask_field& cc = f.mask().field(CODICE_LIB_UN); - //cc.set_dirty(); - } - if (id == FINO_A_MESE) - { - if (mese == 12) - f.mask().show (TIPO_RIEPILOGATIVO); - else f.mask().hide (TIPO_RIEPILOGATIVO); - } - } - if (k==K_TAB && f.mask().is_running()) - { - const short id = f.dlg(); - if (id == MESE) - f.mask().send_key(K_TAB, CODICE_LIBRO_IVA); - } - return TRUE; -} - -bool CG4400_application::look_reg(int i, int anno, TString& codlib, int m, const char* cod, int* umese, long ditta) -{ - TString16 y; - - y << anno << cod; - _tabreg->zero(); - _tabreg->put("CODTAB", y); - - if (_tabreg->read() == NOERR) - { - int tipo = _tabreg->get_int("I0"); - if (tipo == 1 || tipo == 2) - { - TString16 cod_lib_un = _tabreg->get("S6"); - TDate u_data = _tabreg->get_date("D3"); - TDate sca_vid = _tabreg->get_date("D1"); - if (codlib != cod_lib_un) - { - if (_selected.ones() == 1L) - if (_selected[i]) - message_box("Ditta %ld: il codice libro unico del registro non e' uguale al codice libro unico indicato", ditta); - return FALSE; - } - if (m < *umese) - { - if (_selected.ones() == 1L) - if (_selected[i]) - message_box("Ditta %ld: il mese indicato e' inferiore al mese dell'ultima data di stampa del registro", ditta); - return FALSE; - } - if (u_data.ok()) - *umese = u_data.month(); - else *umese = 0; - - if (sca_vid.ok()) - if (sca_vid.month() < m) - { - if (_selected.ones() == 1L) - if (_selected[i]) - message_box("Ditta %ld: la data scadenza di vidimazione del registro non deve essere inferiore al mese indicato", ditta); - return FALSE; - } - } - return TRUE; - } - return FALSE; -} - -bool CG4400_application::look_regs(int anno, TString& codlib, int m, int* umese, long ditta, bool* st) -{ - int a, tipo; - TString16 codtab; - bool ok = FALSE; - *umese = 13; - - for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) - { - tipo = _tabreg->get_int("I0"); - codtab = _tabreg->get("CODTAB"); - a = atoi(codtab.mid(0,4)); - if (a > anno) - break; - if (a == anno) - if ( tipo == 1 || tipo == 2 ) //registro iva - { - TString16 cod_lib_un = _tabreg->get("S6"); - TDate sca_vid = _tabreg->get_date("D1"); - TDate u_data = _tabreg->get_date("D3"); - if (codlib != cod_lib_un) - continue; - if (u_data.ok()) - if (m < u_data.month()) - continue; - if (u_data.ok()) - *umese = (*umese < u_data.month()) ? *umese : u_data.month(); - if (sca_vid.ok()) - if (sca_vid.month() < m) - continue; - int month; - if (!u_data.ok()) - month = 0; - else month = u_data.month(); - if (month < m - 1) - { - app().set_firm(__firm); - *st = FALSE; - return error_box("Ditta %ld: Stampare i registri dei mesi precedenti", ditta); - } - ok = TRUE; - } - } - return ok; -} - -bool CG4400_application::mask_libun (TMask_field& f, KEY k) -{ - static bool can_print = TRUE; - - if (k == K_ENTER) return can_print; - - if (k==K_TAB && f.mask().is_running()) - { - TString16 cod(f.mask().get(CODICE_LIBRO_IVA)); - TString16 codlib(f.mask().get(CODICE_LIB_UN)); - //modifica del 26/04/1995 - if (codlib.empty()) - { - app()._test = TRUE; - return f.error_box("Inserire il codice del libro unico"); - } - //fine modifica - int fino_a_mese = f.mask().get_int(MESE); - int anno = f.mask().get_int(ANNO); - bool ok = FALSE; - can_print = TRUE; - int last_mese = 13; - int mese = 0; - - app().__firm = app().get_firm(); - - for (int i = 0; i < app()._ditte->items(); i++) - { - long ditta = app()._ditte->row(i).get_long(1); - if (prefix().exist(ditta)) - { - app().set_firm(ditta); - if (cod.not_empty()) - { - ok = app().look_reg(i,anno,codlib,fino_a_mese,cod,&mese,ditta); - if (!ok) - { - //modifica del 21/04/1995 suggerita da Cinzia!!! - if (app()._selected.ones() == 1L) //solo se ho selezionato 1 ditta devo dare il messaggio - if (app()._selected[i]) - f.message_box("Ditta %ld: il registro %s non soddisfa i parametri indicati", ditta, (const char*)cod); - continue; - } - //if (mese != 0 && mese < fino_a_mese - 1) //indipendentemente se si tratta di una ditta selezionata oppure no - if (mese < fino_a_mese - 1) //indipendentemente se si tratta di una ditta selezionata oppure no - { - app().set_firm(app().__firm); - can_print = FALSE; - return error_box("Ditta %ld: Stampare i registri dei mesi precedenti", ditta); - } - //modifica del 30/06/1995 - } - else - { - ok = app().look_regs(anno,codlib,fino_a_mese,&mese,ditta,&can_print); - //if ( app()._selected[i] && !ok ) - if (!ok) - { - if (!can_print) - return FALSE; - if (app()._selected.ones() == 1L) //solo se ho selezionato 1 ditta devo dare il messaggio - if (app()._selected[i]) - f.message_box("Ditta %ld: nessun registro soddisfa i parametri indicati", ditta); - continue; - } - } - //if (app()._selected[i]) - last_mese = (last_mese < mese) ? last_mese : mese; - } - } - app().set_firm(app().__firm); - - if (last_mese == 13) - last_mese = 0; //l'ultima data di stampa sul/sui registri specificati e' vuota (cioe' non sono ancora stati stampati sul libro unico specificato per l'anno specificato) - const char* me = ""; - me = format("%02d", last_mese); - f.mask().set(ULTIMO_MESE, me); - } - return TRUE; -} - -bool CG4400_application::mask_cod (TMask_field& f, KEY k) -{ - //if (k == K_TAB || f.focusdirty()) - if (k == K_TAB) - { - TTable TabLbu ("%LBU"); - TString codtab; - int anno; - - TString16 codlib(f.get()); - anno = f.mask().get_int(ANNO); - TabLbu.zero(); - codtab.format ("%04d%-3s", anno, (const char*)codlib); - TabLbu.put ("CODTAB", codtab); - TabLbu.read(); - if ( TabLbu.good() ) - { - //f.mask().set(ULTIMO_MESE,TabLbu.get_long("I0")); - f.mask().set(ULTIMA_PAGINA,TabLbu.get_long("I1")); - app()._codice_vidi = TabLbu.get("S4"); - } - //modifica del 26/04/1995 - if (app()._test) - { - f.mask().send_key(K_TAB, CODICE_LIBRO_IVA); - app()._test = FALSE; - } - //fine modifica - } - return TRUE; -} - -bool CG4400_application::mask_data (TMask_field& f, KEY k) -{ - if (k == K_TAB && f.mask().is_running()) - { - const int anno = f.mask().get_int(ANNO); - TDate data(f.get()); - if (data.ok()) - if (data.year() != anno) - { - f.warning_box("L'anno delle date limite deve essere uguale all'anno iva specificato"); - return FALSE; - } - if (f.dlg() == A_DATA) - if (data.ok) - { - if ( data.day() == 31 && data.month() == 12 ) - f.mask().show (TIPO_RIEPILOGATIVO); - else f.mask().hide (TIPO_RIEPILOGATIVO); - } - } - return TRUE; -} - -const char * CG4400_application::descr_doc() -{ - TTable tab_tpd("%TPD"); - TString codtab(format("%-2s",(const char*) _tipodoc)); - - tab_tpd.zero(); - tab_tpd.put("CODTAB", codtab); - if (tab_tpd.read()==NOERR) - TMP = tab_tpd.get("S0"); - else - TMP = ""; - - return TMP; -} - -const char * CG4400_application::descr_iva(const char * cod) -{ - TTable tab_iva("%IVA"); - TString codtab(format ("%-4s", cod)); - - tab_iva.zero(); - tab_iva.put("CODTAB", codtab); - if (tab_iva.read()==NOERR) - TMP = tab_iva.get("S0"); - else - TMP = ""; - - return TMP; -} - -const char * CG4400_application::tipo_attivita() -{ - TLocalisamfile attiv (LF_ATTIV); - - attiv.zero(); - attiv.put("CODDITTA", get_firm()); - attiv.put("CODATT", _codatt); - if (attiv.read() == NOERR) - TMP = attiv.get("TIPOATT"); - else TMP = ""; - return TMP; -} - -const char * CG4400_application::desc_attivita() -{ - TTable attiv ("%AIS"); - - attiv.zero(); - attiv.put("CODTAB", _codatt); - if (attiv.read()==NOERR) - TMP = attiv.get("S0"); - else - TMP = ""; - return TMP; -} - -TRectype& CG4400_application::ricerca_cf(char tipocf, long codcf) -{ - _clifo->zero(); - _clifo->put(CLI_TIPOCF, tipocf); - _clifo->put(CLI_CODCF, codcf); - _clifo->read(); - if (_clifo->bad()) - _clifo->zero(); - - return _clifo->curr(); -} - -TRectype& CG4400_application::ricerca_occ(const char * occ) -{ - TLocalisamfile occas (LF_OCCAS); - occas.zero(); - occas.put(OCC_CFPI, occ); - occas.read(); - if (occas.bad()) - occas.zero(); - - return occas.curr(); -} - -bool CG4400_application::year_handler(TMask_field& f, KEY key) -{ - if (key == K_TAB && f.focusdirty()) - { - app().begin_wait(); - app().set_year(atoi(f.get())); - app().build_nomiditte(); - app().build_ditte_sheet(); - app().end_wait(); - } - return TRUE; -} - -void CG4400_application::build_ditte_sheet() -{ - // build sheet - _ditte->destroy(); - for (int i = 0; i < _nomiditte.items(); i++) - { - TToken_string* d = new TToken_string(64); - *d = (TToken_string&)_nomiditte[i]; - const char vers = d->get_char(2); - bool selectable = vers == '?'; - d->insert(" |", 0); - const long pos = _ditte->add(d); - if (selectable) - _ditte->disable(pos); - else if (_selected[i]) - _ditte->check(pos); - } -} - -// --------------------------- handlers per selezione ditte - -bool CG4400_application::to_ditt_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask(); - if (key == K_F9) - app().to_butt_handler(m.field(BUT_DTO), K_SPACE); - if (key == K_TAB && f.focusdirty()) - { - const long l = app().select_firm_range(m.get_long(DA_CODICE), m.get_long(A_CODICE)); - app().set_choice_limits(m); - m.field(F_SELECT).set(format("%ld", l)); - } - return TRUE; -} - -bool CG4400_application::fr_ditt_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask(); - if (key == K_F9) - app().fr_butt_handler(m.field(BUT_DFR), K_SPACE); - else if (key == K_TAB && f.focusdirty()) - { - const long l = app().select_firm_range(m.get_long(DA_CODICE), m.get_long(A_CODICE)); - app().set_choice_limits(m); - m.field(F_SELECT).set(format("%ld", l)); - } - return TRUE; -} - -bool CG4400_application::to_butt_handler(TMask_field& f, KEY key) -{ - if (key == K_SPACE) - { - TArray_sheet* sh = app().get_ditte_sheet(); - TMask& m = f.mask(); - - sh->disable_check(); - if (sh->run() == K_ENTER) - { - app().select_firm_range(m.get_long(DA_CODICE),sh->row(sh->selected()).get_long(1)); - app().set_choice_limits(m); - } - } - return TRUE; -} - -bool CG4400_application::fr_butt_handler(TMask_field& f, KEY key) -{ - if (key == K_SPACE) - { - TMask& m = f.mask(); - TArray_sheet* sh = app().get_ditte_sheet(); - - sh->disable_check(); - if (sh->run() == K_ENTER) - { - app().select_firm_range(sh->row(sh->selected()).get_long(1), m.get_long(A_CODICE)); - app().set_choice_limits(m); - } - } - return TRUE; -} - -void CG4400_application::set_choice_limits(TMask& m) -{ - long first = -1l, last = -1l; - for (int i = 0; i < _ditte->items(); i++) - { - if (_selected[i]) - { - long dit = _ditte->row(i).get_long(1); - if (first == -1l) first = dit; - if (last < dit) last = dit; - } - } - if (first != -1) m.field(DA_CODICE).set(format("%ld",first)); - if (last != -1) m.field(A_CODICE).set(format("%ld",last)); - m.set(F_SELECT, _selected.ones()); - //modifica del 02/06/1995 - if (m.is_running()) - if (first != -1l) app().set_firm(first); - //fine -} - -long CG4400_application::select_firm_range(long from, long to) -{ - if (to == 0l) to = 99999L; - for (int i = 0; i < _ditte->items(); i++) - { - if (_ditte->disabled(i)) - continue; - - TToken_string& d = _ditte->row(i); - const char vers = d.get_char(3); - if (vers == '?') - continue; - - const long cod = d.get_long(1); - if (cod >= from && cod <= to) - { - _selected.set(i); - _ditte->check(i); - } - else - { - _selected.set(i,FALSE); - _ditte->uncheck(i); - } - } - return _selected.ones(); -} - -void CG4400_application::build_nomiditte(TProgind* pnd) -{ - _nomiditte.destroy(); - // ricostruire _nomiditte e rifare build_ditte_sheet - TLocalisamfile& dt = _nditte->lfile(); - - for (dt.first(); !dt.eof(); dt.next()) - { - // check no archivi - bool good = prefix().exist(dt.get_long("CODDITTA")); - if (good) - { - // check no parametri liquidazione - //TApplication::set_firm(dt.get_long("CODDITTA")); - if (!look_lia(dt.get_long("CODDITTA"))) good = FALSE; - } - _n_ditte++; - TToken_string* d = new TToken_string(64); - d->add(dt.get("CODDITTA")); - d->add(dt.get("RAGSOC")); - if (good) d->add(_tablia->get("S7")); - else d->add("??"); - - _nomiditte.add(d); - } - //if (pnd) pnd->addstatus(1); - //TApplication::set_firm(__firm); -} - -bool CG4400_application::user_create() -{ - //TProgind* pnd = NULL; - - //pnd = new TProgind (2,"Preparazione archivi\nPrego attendere", - // FALSE, TRUE, 30); - - _com = new TLocalisamfile(LF_COMUNI); - _anag = new TLocalisamfile(LF_ANAG); - _unloc = new TLocalisamfile(LF_UNLOC); - _attiv = new TLocalisamfile(LF_ATTIV); - _tab = new TLocalisamfile(LF_TAB); - _tabcom = new TLocalisamfile(LF_TABCOM); - _indlib = new TLocalisamfile(LF_INDLIB); - _tabreg = new TTable("REG"); - _tabiva = new TTable("%IVA"); - _tablbu = new TTable("%LBU"); - _tablim = new TTable("LIM"); - _tabpim = new TTable("PIM"); - _tablia = new TTable("%LIA"); - _tabpla = new TTable("%PLA"); - _tabppa = new TTable("PPA"); - _tabvid = new TTable("%VID"); - _clifo = new TLocalisamfile(LF_CLIFO); - _occas = new TLocalisamfile(LF_OCCAS); - - _desc27 = new TParagraph_string("", 27); - - _nditte = new TRelation(LF_NDITTE); - - _rel = new TRelation (LF_MOV); - _rel->add(LF_CAUSALI,"CODCAUS=CODCAUS",1,LF_MOV); - _rel->add(LF_RMOVIVA,"NUMREG=NUMREG",1,LF_MOV); - - _cur = new TCursor(_rel, "", 2); - - _ditte = new TArray_sheet(-1, -1, 0, 0, "Selezione Ditte", - "@1|Cod.@5R|Ragione Sociale@50|Vers."); - - //if (pnd) pnd->addstatus(1); - - _n_ditte = 0l; - __firm = TApplication::get_firm(); - - TDate oggi(TODAY); - _annoes = oggi.year(); - - build_nomiditte(); - build_ditte_sheet(); - - add_cursor(_cur); - add_file(LF_MOV); - add_file(LF_RMOVIVA); - - //delete pnd; - - return TRUE; -} - -bool CG4400_application::user_destroy() -{ - delete _ditte; - delete _nditte; - delete _com; - delete _unloc; - delete _anag; - delete _attiv; - delete _indlib; - delete _tab; - delete _tabcom; - delete _tabreg; - delete _tabiva; - delete _tablbu; - delete _tablim; - delete _tabpim; - delete _tablia; - delete _tabpla; - delete _tabppa; - delete _tabvid; - delete _clifo; - delete _occas; - delete _cur; - delete _rel; - delete _desc27; - - return TRUE; -} - -void CG4400_application::calcola_progressivi() -{ - TTable pim ("PIM"); - TString80 chiave; - int i, num=0; - - if (_tipo_stampa == 3) - num = _fino_a_mese; - if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) - num = _datareg.month(); - - //il discorso e' indipendente dalla frequenza! - //if (_frequiva == 'T') - // if (num%3 != 0) - // num = num - (num%3); - - //calcolo i totali del periodo - - chiave = ""; - //_codatt e' gia' Z perche' lo leggo dal registro - chiave << _annoes << _codatt; - pim.zero(); - pim.put ("CODTAB", chiave); - TRectype r (pim.curr()); - pim.read(_isgteq); - for (; !pim.eof(); pim.next()) - { - if (pim.curr() != r) break; - - TString80 codtab = pim.get("CODTAB"); - TString16 codreg = codtab.mid(10,3); - int mese = atoi(codtab.mid(13,2)); - if (_codreg == codreg.trim() && mese == num) - { - TString16 codiva = codtab.mid(16,4); - int tipodet = atoi(codtab.mid(20,1)); - real impo = pim.get_real("R0"); - real impos = pim.get_real("R1"); - real implo = pim.get_real("R2"); - //se il registro e' corrispettivi l'imponibile e l'iva li trovo in S2 - if (_corrispettivi) - { - TToken_string cs (pim.get("S2")); - impo = cs.get(0); - impos = cs.get(1); - } - //se in sospensione d'imposta l'imponibile e l'iva li trovo in R11 e R12 - if (_sosp_imposta) //in genere non sara' mai un corrispettivo - { - impo = pim.get_real("R11"); - impos = pim.get_real("R12"); - } - TToken_string fatt_rit (pim.get("S1")); //e' sempre un acquisto - real im (fatt_rit.get(0)); - real is (fatt_rit.get(1)); - impo += im; - impos += is; - implo += im+is; // potrei percio' ignorare l'importo lordo - if (impo != ZERO || impos != ZERO || implo != ZERO) - _tot_iva_array.add_riga(impo,impos,implo,ZERO,ZERO,ZERO,codiva); - if (_tipo_reg == 2) //registro acquisti - if (impo != ZERO || impos != ZERO) - _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,TRUE); - } - } - - //calcolo i totali progressivi - if (_tipo_stampa == 3) - num = _fino_a_mese; - if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) - num = _datareg.month(); - - for (i=1; i<=num; i++) - { - chiave = ""; - chiave << _annoes << _codatt; - pim.zero(); - pim.put("CODTAB", chiave); - TRectype r (pim.curr()); - pim.read(_isgteq); - for (; !pim.eof(); pim.next()) - { - if (pim.curr() != r) break; - TString80 codtab = pim.get("CODTAB"); - TString16 codreg = codtab.mid(10,3); - int mese = atoi(codtab.mid(13,2)); - if (_codreg == codreg.trim() && mese == i) - { - TString16 codiva = codtab.mid(16,4); - int tipodet = atoi(codtab.mid(20,1)); - real impo = pim.get_real("R0"); - real impos = pim.get_real("R1"); - real implo = pim.get_real("R2"); - //se il registro e' corrispettivi l'imponibile e l'iva li trovo in S2 - if (_corrispettivi) - { - TToken_string cs (pim.get("S2")); - impo = cs.get(0); - impos = cs.get(1); - } - //se in sospensione d'imposta l'imponibile e l'iva li trovo in R11 e R12 - if (_sosp_imposta) - { - impo = pim.get_real("R11"); - impos = pim.get_real("R12"); - } - TToken_string fatt_rit (pim.get("S1")); - real im (fatt_rit.get(0)); - real is (fatt_rit.get(1)); - impo += im; - impos += is; - implo += im+is; - if (impo != ZERO || impos != ZERO || implo != ZERO) - _tot_iva_array.add_riga(ZERO,ZERO,ZERO,impo,impos,implo,codiva); - if (_tipo_reg == 2) //registro acquisti - if (impo != ZERO || impos != ZERO) - _iva_array.add_riga(ZERO,ZERO,impo,impos,codiva,tipodet,0,TRUE); - } - } - } -} - -int CG4400_application::riga_rmoviva() -{ - TString codiva; - real impo, impos; - int tipodet, tipocr, tipoatt; - bool intra; - - TLocalisamfile& rmoviva = _cur->file(LF_RMOVIVA); - bool ok = _cur->is_first_match(LF_RMOVIVA); - int nrec = 0; - - TRecnotype nr = rmoviva.recno(); - - while (ok) - { - nrec++; - TRectype iva (rmoviva.curr()); - tipodet = iva.get_int (RMI_TIPODET); - tipocr = iva.get_int (RMI_TIPOCR); - impo = iva.get_real(RMI_IMPONIBILE); - impos = iva.get_real(RMI_IMPOSTA); - codiva = iva.get(RMI_CODIVA); - intra = iva.get_bool(RMI_INTRA); - tipoatt = iva.get_int("TIPOATT"); - - _riga_rmi.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,tipocr,intra,tipoatt); - - if (_tipo_stampa == 1) //stampa di prova - { - if (_tipodoc == "FS") - { - real somma = -(impo + impos); - _tot_iva_array.add_riga(ZERO,ZERO,somma,ZERO,ZERO,ZERO,codiva); - } - else if (_tipodoc == "CR" || _tipodoc == "RF" || _tipodoc == "SC") - _tot_iva_array.add_riga(ZERO,ZERO,impo+impos,ZERO,ZERO,ZERO,codiva); - if (_tipodoc != "CR" && _tipodoc != "SC" && _tipodoc != "RF") - _tot_iva_array.add_riga(impo,impos,ZERO,ZERO,ZERO,ZERO,codiva); - - if (_tipo_reg == 2) //registro acquisti (non ha senso parlare di importi lordi) - _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,TRUE); - } - - ok = _cur->next_match(LF_RMOVIVA); - } - rmoviva.readat(nr); - - return nrec; -} - -int CG4400_application::setta_riga(int r, const TRigaiva& riga, real& tot1, - real& tot2, real& tot3, real& tot4) -{ - set_row(r, "%4s", (const char*)riga._codiva); - TString descr = descr_iva(riga._codiva); - set_row(r, "@5g%-.21s",(const char*)descr); - if (riga._imponibile != ZERO) - set_row(r, "@25g%r", &riga._imponibile); - if (riga._imposta != ZERO) - set_row(r, "@41g%r", &riga._imposta); - if (_tipo_stampa != 1) - { - if (riga._imponibilep != ZERO) - set_row(r, "@81g%r", &riga._imponibilep); - if (riga._impostap != ZERO) - set_row(r++, "@98g%r", &riga._impostap); - } - else r++; - tot1 += riga._imponibile; - tot2 += riga._imposta; - tot3 += riga._imponibilep; - tot4 += riga._impostap; - - return r; -} - -messaggio CG4400_application::controlla_b0() -{ - TTable lim ("LIM"); - TString16 chiave = ""; - TString16 ditta = ""; - int i, mese; - ditta << get_firm(); - - if (_tipo_stampa == 1) //stampa di prova - mese = _data_a.month(); - else - mese = _fino_a_mese; - - if (_tipo_riepilogativo == ' ' || _tipo_riepilogativo == 'P') - { - if (_frequiva == 'T') //nella tabella LIM ho solo i mesi 3, 6, 9, 12 - { - for (i=3; i<=mese; i+=3) - { - chiave = ""; - TString16 m (format("%02d", i)); - chiave << _annoes << m; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - if (! lim.get_bool("B0")) - return no_liquidazione; - } - else return no_liquidazione; - } - } - if (_frequiva == 'M') - { - for (i=1 ; i<=mese; i++) - { - chiave = ""; - TString16 m (format("%02d", i)); - chiave << _annoes << m; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - if (! lim.get_bool("B0")) - return no_liquidazione; - } - else return no_liquidazione; - } - } - } - else if (_tipo_riepilogativo == 'A') - //if (_riep_liq) - { - chiave = ""; - chiave << _annoes << 13; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - if (! lim.get_bool("B0")) - return no_liquidazione; - } - else return no_liquidazione; - } - return B0_settato; -} - -messaggio CG4400_application::controlla_liquidazione() -{ - TTable lim ("LIM"); - TString mesi_cal = ""; - TString16 chiave = ""; - TString16 ditta = ""; - int i, mese; - bool continua; - ditta << get_firm(); - - if (_tipo_stampa == 1) //stampa di prova - mese = _data_a.month(); - else - mese = _fino_a_mese; - - if (_tipo_riepilogativo == ' ' || _tipo_riepilogativo == 'P') - { - if (_frequiva == 'T') //nella tabella LIM ho solo i mesi 3, 6, 9, 12 - { - for (i=3; i<=mese; i+=3) - { - chiave = ""; - TString16 m (format("%02d", i)); - chiave << _annoes << m; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - if (! lim.get_bool("B0")) - mesi_cal << itom(i) << "\n"; - } - else mesi_cal << itom(i) << "\n"; - } - } - if (_frequiva == 'M') - { - for (i=1 ; i<=mese; i++) - { - chiave = ""; - TString16 m (format("%02d", i)); - chiave << _annoes << m; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - if (! lim.get_bool("B0")) - mesi_cal << itom(i) << "\n"; - } - else mesi_cal << itom(i) << "\n"; - } - } - if (mesi_cal.not_empty()) - { - warning_box ("Ditta %s: la liquidazione da stampare sul registro %s relativa ai mesi di \n %s non e' stata ancora calcolata", (const char*)ditta, (const char*) _codreg, (const char *)mesi_cal); - continua = yesno_box("Si desidera ugualmente proseguire?"); - if (!continua) return non_proseguire; - continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa di liquidazione)"); - if (!continua) return prosegui_stampa; - return prosegui_cal_stampa; - } - } - else if (_tipo_riepilogativo == 'A') - //if (_riep_liq) - { - chiave = ""; - chiave << _annoes << 13; - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - if (! lim.get_bool("B0")) - { - continua = yesno_box("Ditta %s: non eseguito calcolo liquidazione annuale da stampare sul registro %s. Si desidera ugualmente proseguire?", (const char*)ditta, (const char*) _codreg); - if (!continua) return non_proseguire; - continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa di liquidazione)"); - if (!continua) return prosegui_stampa; - return prosegui_cal_stampa; - } - } - else - { - continua = yesno_box("Ditta %s: non eseguito calcolo liquidazione annuale da stampare sul registro %s. Si desidera ugualmente proseguire?", (const char*)ditta, (const char*) _codreg); - if (!continua) return non_proseguire; - continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa di liquidazione)"); - if (!continua) return prosegui_stampa; - return prosegui_cal_stampa; - } - } - return B0_settato; -} - -//controlla che i movimenti con anno data di registrazione < dell'anno indicato a video siano stati gia' stampati in forma definitiva*/ -//questo controllo viene fatto solo per stampa di bollato (non su libro unico) -bool CG4400_application::controlla_mov() -{ - TLocalisamfile mov (LF_MOV); - bool ok = TRUE; - byte tipo; - TString16 ditta = ""; - TRecnotype rec = _tabreg->recno(); - for (mov.first(); !mov.eof(); mov.next()) - { - TString16 reg = mov.get(MOV_REG); - if (reg.empty()) continue; //non e' un movimento iva - TDate datareg = mov.get_date(MOV_DATAREG); - if (_stampa_tutti_i_registri) - cerca_reg (reg, &tipo); - if ( (_stampa_tutti_i_registri && (tipo == 1 || tipo == 2)) - || (!_stampa_tutti_i_registri && reg == _codreg) ) - { - bool stampato = mov.get_bool(MOV_REGST); - if ( datareg.year() < _annoes ) - { - long numreg = mov.get_long(MOV_NUMREG); - if (!stampato) - ok = FALSE; - } - } - } - _tabreg->readat(rec); - return ok; -} - -bool CG4400_application::cerca_libro_gio(TString& datas, bool* good) -{ - TString app(4); - app = format("%04d", _annoes); - - *good = TRUE; - TRecnotype rec = _tabreg->recno(); - _tabreg->zero(); - _tabreg->put ("CODTAB", app); - TRectype r (_tabreg->curr()); - _tabreg->read(_isgteq); - for (; !_tabreg->eof(); _tabreg->next()) - { - if (_tabreg->curr() != r) break; - - int tiporeg = _tabreg->get_int("I0"); - if (tiporeg == 5) //libro giornale - { - const TDate& data = _tabreg->get_date("D3"); - if (data > _data_a) - { -// datas = format("%02/%02d/%4d", data.day(), data.month(), data.year()); - datas = data; // Meglio cosi' - *good = FALSE; - return FALSE; - } - return TRUE; - } - } - _tabreg->readat(rec); - //return TRUE; - return FALSE; -} - -void CG4400_application::cerca_reg(const TString& c, byte* t) -{ - TString16 cod = ""; - - cod << _annoes << c; - _tabreg->zero(); - _tabreg->put("CODTAB", cod); - if (_tabreg->read() == NOERR) - *t = _tabreg->get_int ("I0"); -} - -bool CG4400_application::ventilazione(const char* iva) -{ - TTable tabiva ("%IVA"); - TString16 chiave = ""; - chiave << iva; - tabiva.put("CODTAB", chiave); - if (tabiva.read()==NOERR) - { - TString16 vent = tabiva.get("S1"); - if (vent == "VE") - return TRUE; - } - return FALSE; -} - -int CG4400_application::stampa_prospetto() -{ - TString riga(_stampa_width); - int r=1, rr=0; - - reset_print(); - riga.fill('-'); - set_row(r, "%s", (const char*)riga); - r++; - set_row(r, "Legenda Tipo Operazione: 1=operazione intracomunitaria 2=AF art.34 comma 3"); - if (_auto_intraf) - set_row(r, "@78g3=operazione intracomunitaria e AF art.34 comma 3"); - r++; - - _stampa = stampa_totali_finali(); - if (_stampa) - { - set_row(++r, "Tipo documento@54gTotale documento"); - r+=2; - for (int j = 0; j < _doc_array.items(); j++) - { - TTipodoc& doc = (TTipodoc&)_doc_array[j]; - rr = r+j; - set_row(rr, "%2s", (const char*) doc._tipodoc); - set_row(rr, "@3g%s", (const char*) doc._descrdoc); - set_row(rr, "@54g%r", &doc._totdoc); - } - _doc_array.destroy(); - } - - if (rr > 0) - rr++; - else - rr = r; - - if (_stampa && _tipo_reg == 2) - { - if (_stampa_cred_pre && _mese_credito==0 && _credito > ZERO) - { - set_row (++rr, "** CREDITO INIZIO ANNO @39g%r", &_credito); - rr++; - } - } - - if (_esiste_riga_iva && _stampa) - { - if (_tipo_reg == 1 && _corrispettivi) - set_row(++rr, "@26g------------------ P E R I O D O -------------------"); - else - set_row(++rr, "@26g---------- P E R I O D O -----------"); - if (_tipo_stampa != 1) - { - if (_tipo_reg == 1 && _corrispettivi) - set_row(rr,"@84g----------- P R O G R E S S I V I --------------"); - else - set_row(rr,"@82g------ P R O G R E S S I V I ------"); - } - rr++; - set_row(rr, "Cod."); - if (_tipo_reg == 2) - { - set_row(rr, "@36gA C Q U I S T I"); - if (_tipo_stampa != 1) - set_row(rr, "@92gA C Q U I S T I"); - } - if (_tipo_reg == 1) //un registro corrispettivi puo' solo essere un registro vendite - { - set_row(rr, "@37gV E N D I T E"); - if (_corrispettivi) - set_row(rr, "@63gCORRISPETTIVI"); - if (_tipo_stampa != 1) - { - if (_corrispettivi) - set_row(rr, "@94gV E N D I T E@118gCORRISPETTIVI"); - else - set_row(rr, "@93gV E N D I T E"); - } - } - rr++; - set_row(rr, "iva Descrizione@30gImponibile@49gImposta"); - if (_tipo_reg == 1 && _corrispettivi) - set_row(rr, "@63gImporti lordi"); - if (_tipo_stampa != 1) - { - if (_tipo_reg == 1 && _corrispettivi) - set_row(rr++, "@87gImponibile@107gImposta@118gImporti Lordi"); - else - set_row(rr++, "@86gImponibile@106gImposta"); - } - else rr++; - rr++; - } - return rr; -} - -//la stampa "tipi di indetraibilita'" viene fatta solo per gli acquisti -int CG4400_application::stampa_acquisti(int row) -{ - real tot_imponib, tot_imposta, tot_imponibp, tot_impostap; - row+=2; - int tdetprec = -1; - int rw = row; - tot_imponib = tot_imposta = tot_imponibp = tot_impostap = ZERO; - - _iva_array.sort(compare_fields); - for (int s = 0; s < _iva_array.items(); s++) - { - TRigaiva& riga = (TRigaiva&)_iva_array[s]; - switch (riga._tipodet) - { - case 1: if (riga._tipodet != tdetprec) - { - set_row(rw++, "----- Indetraibile su op.es. -----"); - set_row(rw, "Cod."); - rw++; - set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); - if (_tipo_stampa != 1) - set_row(rw++, "@86gImponibile@106gImposta"); - else rw++; - rw++; - } - rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); - tdetprec = riga._tipodet; - break; - case 3: if (tdetprec == 1) - { - //set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - set_row(++rw, "TOTALE"); - if (tot_imponib != ZERO) - set_row(rw, "@25g%r", &tot_imponib); - if (tot_imposta != ZERO) - set_row(rw, "@41g%r", &tot_imposta); - - if (_tipo_stampa != 1) - { - //set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - if (tot_imponibp != ZERO) - set_row(rw, "@81g%r", &tot_imponibp); - if (tot_impostap != ZERO) - set_row(rw, "@98g%r", &tot_impostap); - } - tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; - rw+=2; - } - if (riga._tipodet != tdetprec) - { - set_row(rw++, "----- Passaggi interni -----"); - set_row(rw, "Cod."); - rw++; - set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); - if (_tipo_stampa != 1) - set_row(rw++, "@86gImponibile@106gImposta"); - else rw++; - rw++; - } - rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); - tdetprec = riga._tipodet; - break; - case 9: if ( (tdetprec == 1) || (tdetprec == 3) ) - { - //set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - set_row(++rw, "TOTALE"); - if (tot_imponib != ZERO) - set_row(rw, "@25g%r", &tot_imponib); - if (tot_imposta != ZERO) - set_row(rw, "@41g%r", &tot_imposta); - if (_tipo_stampa != 1) - { - //set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - if (tot_imponibp != ZERO) - set_row(rw, "@81g%r", &tot_imponibp); - if (tot_impostap != ZERO) - set_row(rw, "@98g%r", &tot_impostap); - } - tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; - rw+=2; - } - if (riga._tipodet != tdetprec) - { - set_row(rw++, "----- N.D. 9 - acquisti indeducibili per ART.19 -----"); - set_row(rw, "Cod."); - rw++; - set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); - if (_tipo_stampa != 1) - set_row(rw++, "@86gImponibile@106gImposta"); - else rw++; - rw++; - } - rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); - tdetprec = riga._tipodet; - break; - default: break; - } - } - if (_iva_array.items() > 0) - if (tdetprec == 9) - { - //set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - set_row(++rw, "TOTALE"); - if (tot_imponib != ZERO) - set_row(rw, "@25g%r", &tot_imponib); - if (tot_imposta != ZERO) - set_row(rw, "@41g%r", &tot_imposta); - if (_tipo_stampa != 1) - { - //set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - if (tot_imponibp != ZERO) - set_row(rw, "@81g%r", &tot_imponibp); - if (tot_impostap != ZERO) - set_row(rw, "@98g%r", &tot_impostap); - } - } - _iva_array.destroy(); - rw++; - return rw; -} - -void CG4400_application::set_page_tot_reg() -{ - int rr=0; - - rr = stampa_prospetto(); - - if (_esiste_riga_iva && _stampa) - { - real tot_imponib, tot_imposta, tot_lordo, tot_imponibp, tot_impostap, tot_lordop; - tot_imponib = tot_imposta = tot_lordo = tot_imponibp = tot_impostap = tot_lordop = ZERO; - - _tot_iva_array.sort(compare_rows); //viene ordinato per codice iva - - for (int k = 0; k < _tot_iva_array.items(); k++) - { - TRiga& riga = (TRiga&)_tot_iva_array[k]; - //row = rr+k; - set_row(rr, "%4s", (const char*)riga._codiva); - TString80 descr = descr_iva(riga._codiva); - set_row(rr, "@5g%-.21s",(const char*)descr); - if (riga._imponibile != ZERO) - set_row(rr, "@25g%r", &riga._imponibile); - if (riga._imposta != ZERO) - set_row(rr, "@41g%r", &riga._imposta); - if (_tipo_reg == 1 && _corrispettivi) - if (riga._implordo != ZERO) - set_row(rr, "@61g%r", &riga._implordo); - if (_tipo_stampa != 1) - { - if (riga._imponibilep != ZERO) - set_row(rr, "@81g%r", &riga._imponibilep); - if (riga._impostap != ZERO) - set_row(rr, "@98g%r", &riga._impostap); - if (_tipo_reg == 1 && _corrispettivi) - if (riga._implordop != ZERO) - set_row(rr, "@115g%r", &riga._implordop); - } - rr++; - tot_imponib += riga._imponibile; - tot_imposta += riga._imposta; - tot_lordo += riga._implordo; - tot_imponibp+= riga._imponibilep; - tot_impostap+= riga._impostap; - tot_lordop += riga._implordop; - } - _tot_iva_array.destroy(); - rr++; - //set_row(rr, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); - set_row(rr, "TOTALE"); - if (tot_imponib != ZERO) - set_row(rr, "@25g%r", &tot_imponib); - if (tot_imposta != ZERO) - set_row(rr, "@41g%r", &tot_imposta); - if (_tipo_reg == 1 && _corrispettivi) - if (tot_lordo != ZERO) - set_row(rr, "@61g%r", &tot_lordo); - if (_tipo_stampa != 1) - { - //set_row(rr, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); - if (tot_imponibp != ZERO) - set_row(rr, "@81g%r", &tot_imponibp); - if (tot_impostap != ZERO) - set_row(rr, "@98g%r", &tot_impostap); - if (_tipo_reg == 1 && _corrispettivi) - if (tot_lordop != ZERO) - set_row(rr, "@115g%r", &tot_lordop); - } - - if (_tipo_reg == 2) rr = stampa_acquisti(rr); - } - if (_tipo_reg == 2 && _tipo_stampa != 1) - stampa_plafonds(rr); -} - -void CG4400_application::stampa_plafonds(int r) -{ - TTable pla ("%PLA"); - TTable ppa ("PPA"); - TString80 chiave; - int num; - real r1, r2, r3; - - r1 = r2 = r3 = ZERO; - - if (_tipo_stampa == 3) - num = _fino_a_mese; - if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) - num = _datareg.month(); - - TString16 nm (format("%02d", num)); - - // forza il tipoatt a 1 - //char buf[10]; strcpy(buf,_codatt); - //buf[strlen(buf) - 1] = '1'; - - chiave = ""; - //chiave << _annoes << buf; - - chiave.format("%05ld", get_firm()); - chiave << _annoes; - chiave << _codatt << "1"; - pla.put("CODTAB", chiave); - - if (pla.read() == NOERR) - { - r1 = pla.get_real("R5"); //totali esp. art.8 - r2 = pla.get_real("R6"); //totali esp. art.8 bis - r3 = pla.get_real("R7"); //totali esp. art 9 - } - - if (r1 > ZERO || r2 > ZERO || r3 > ZERO) - { - set_row(++r, "QUADRO RELATIVO ALLA DISPONIBILITA' E UTILIZZAZIONE MENSILE DEI PLAFONDS"); - r++; - TString mese(9); - mese = itom(num); - mese.right_just(); - set_row(++r, "%s", (const char*) mese); - set_row(++r, ""); - r++; - } - else return; - - if (r1 > ZERO) - { - real r8 = ZERO; - r8 = stampa_valori_plafonds(r1, num, ppa, "1"); - if (r8 > ZERO) - { - real pri = ZERO; - real pre = ZERO; - chiave = ""; - chiave << _annoes << _codatt << "1" << nm << "1"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri = ppa.get_real("R0"); - pre = ppa.get_real("R1"); - } - chiave = ""; - chiave << _annoes << _codatt << "2" << nm << "1"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri += ppa.get_real("R0"); - pre += ppa.get_real("R1"); - } - real x = r8 - pri - pre; - set_row(r++, "ART. 8 1° comma lettere a-b Disponibile %r", &r8); - set_row(r++, "Utilizzato all'interno@44g%r", &pri); - set_row(r++, "Utilizzato per l'importazione@44g%r riporto %r", &pre, &x); - } - } - - if (r2 > ZERO) - { - real r8b = ZERO; - r8b = stampa_valori_plafonds(r2, num, ppa, "2"); - if (r8b > ZERO) - { - real pri = ZERO; - real pre = ZERO; - chiave = ""; - chiave << _annoes << _codatt << "1" << nm << "2"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri = ppa.get_real("R0"); - pre = ppa.get_real("R1"); - } - chiave = ""; - chiave << _annoes << _codatt << "2" << nm << "2"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri += ppa.get_real("R0"); - pre += ppa.get_real("R1"); - } - real x = r8b - pri - pre; - r++; - set_row(r++, "ART. 8 bis 1° comma Disponibile %r", &r8b); - set_row(r++, "Utilizzato all'interno@44g%r", &pri); - set_row(r++, "Utilizzato per l'importazione@44g%r riporto %r", &pre, &x); - } - } - - if (r3 > ZERO) - { - real r9 = ZERO; - r9 = stampa_valori_plafonds(r3, num, ppa, "3"); - if (r9 > ZERO) - { - real pri = ZERO; - real pre = ZERO; - chiave = ""; - chiave << _annoes << _codatt << "1" << nm << "3"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri = ppa.get_real("R0"); - pre = ppa.get_real("R1"); - } - chiave = ""; - chiave << _annoes << _codatt << "2" << nm << "3"; - ppa.put("CODTAB", chiave); - if (ppa.read() == NOERR) - { - pri += ppa.get_real("R0"); - pre += ppa.get_real("R1"); - } - real x = r9 - pri - pre; - r++; - set_row(r++, "ART. 8 bis 1° comma Disponibile %r", &r9); - set_row(r++, "Utilizzato all'interno@44g%r", &pri); - set_row(r++, "Utilizzato per l'importazione@44g%r riporto %r", &pre, &x); - } - } -} - -real CG4400_application::stampa_valori_plafonds(const real& r1, const int mese, TTable& ppa, const char* tipo) -{ - real r, si8, se8; - TString80 chiave; - int i; - - r = r1; - si8 = se8 = ZERO; - if (mese > 1) - { - for (i=1; ifirst(); - if (!_tabreg->eof()) - { - codtab = _tabreg->get("CODTAB"); - anno = atoi(codtab.mid(0,4)); - if (anno > _annoes) - { - if (_tipo_stampa != 3) //per il libro unico e' gia' stato controllato nell'handler - warning_box("Non esistono registri IVA della Ditta %ld per l'anno %d", - _ditta, _annoes); - return FALSE; - } - } - } - else // stampa un solo registro - { - _stampa_tutti_i_registri = FALSE; - codtab << _annoes << _codreg; - _tabreg->zero(); - _tabreg->put("CODTAB", codtab); - if (_tabreg->read() != NOERR) - { - if (_tipo_stampa != 3) - warning_box("Il registro IVA specificato non esiste nella \n Ditta %ld", _ditta); - return FALSE; - } - else - { - _tipo_reg = _tabreg->get_int("I0"); - if (_tipo_reg == 1 || _tipo_reg == 2) //registro iva - { - cod_lib_un = _tabreg->get("S6"); - sca_vid = _tabreg->get_date("D1"); - if (_tipo_stampa != 1) - _u_data = _tabreg->get_date ("D3"); - if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) - { - if (cod_lib_un.not_empty()) - { - warning_box ("Ditta %ld: sul registro non deve essere indicato il codice del libro unico", _ditta); - return FALSE; - } - if (sca_vid.ok()) - if (sca_vid.month() < _fino_a_mese) - { - warning_box ("Ditta %ld: il mese della data scadenza vidimazione riportata sul registro non deve essere inferiore al mese indicato", _ditta); - return FALSE; - } - if (_u_data.ok()) - if (_data_a < _u_data) - { -// TString16 datas = format("%02d/%02d/%4d", _u_data.day(), _u_data.month(), _u_data.year()); -// warning_box ("Ditta %ld: la data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", _ditta, (const char*)datas); -// return FALSE; - return warning_box ("Ditta %ld: la data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", _ditta, (const char*)_u_data.string()); - } - if (_tipo_stampa == 4) //stampa con riferimenti al libro giornale - { - TString16 datas; - bool good; - bool ok = cerca_libro_gio(datas,&good); - if (!ok) - { - if (!good) - warning_box ("Ditta %ld: la data indicata non deve essere superiore al %s (ultima data di stampa del libro giornale)", _ditta, (const char*)datas); - return FALSE; - } - } - } - _pagine_stampate = _tabreg->get_long("I1"); - _numini = _pagine_stampate; - _corrispettivi = _tabreg->get_bool("B0"); - _sosp_imposta = _tabreg->get_bool("B1"); - _liquidazione = _tabreg->get_bool("B7"); - _riep_liq = _tabreg->get_bool("B6"); - _stampa_cred_pre = _tabreg->get_bool("B4"); - _stampa_ind_ditta = _tabreg->get_bool("B9"); - _stampa_ind_comp = _tabreg->get_bool("B5"); - _cod_un_loc = _tabreg->get_int ("I7"); - _mese_credito = _tabreg->get_int ("I8"); //campo nascosto sulla tabella dei registri: mese di stampa credito anno precedente - _mese_ultima_liq = _tabreg->get_int ("I4"); - _codatt = _tabreg->get("S8"); - _tipoatt = tipo_attivita(); - _attivita = desc_attivita(); - _desc_lib = _tabreg->get ("S0"); - } - else return FALSE; - } - } - return TRUE; -} - -bool CG4400_application::compila_lib() -{ - TTable tab_lib ("%LBU"); - TString16 cod; - - cod << _annoes << _codlib; - tab_lib.zero(); - tab_lib.put("CODTAB", cod); - - if (tab_lib.read() == NOERR) - { - _stampa_ind_ditta = tab_lib.get_bool("B1"); - return TRUE; - } - return FALSE; -} - -bool CG4400_application::preprocess_print(int file, int counter) -{ - if (file == LF_MOV) - { - long items = _cur->items(); - if (!items) - return FALSE; - _iva_array.destroy(); - _riga_rmi.destroy(); - _tot_iva_array.destroy(); - _doc_array.destroy(); - _dataregp = ""; - _esiste_riga_iva = FALSE; - _auto_intraf = FALSE; - _intesta_liq = FALSE; - set_print_zero(); - } - return TRUE; -} - -bool CG4400_application::preprocess_page(int file, int counter) -{ - if (file == LF_MOV) - { - if (counter) return TRUE; - - reset_print(); - int rr = 0, riga = 0; - bool intra; - TString80 comune, prov, comcf, capcf, civcf; - TString80 viacf; - TString ragsoc; - TString tipo_op = ""; - - TLocalisamfile& mov = _cur->file(LF_MOV); - TLocalisamfile& caus = _cur->file(LF_CAUSALI); - - _datareg = mov.get_date(MOV_DATAREG); - - if (_tipo_stampa != 3 && _liquidazione) - { - int da; - if (_tipo_stampa == 1) - da = _data_da.month(); - else da = 1; - int a = _datareg.month(); - for (int m = da; m < a; m++) - { - if (!_st_liq[m]) - if (stampo_liquidazione(m)) - { -// _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header (intestazione per la stampa liquidazione) - _datareg = TDate(1, m, _annoes); // Meglio cosi' - TFilename t; - t.temp("reg"); - if (_scelta == B0_settato || _scelta == prosegui_stampa) - { - if (_tipo_stampa == 1) - send_message('S',t, m); - else send_message('s',t, m); - } - else //_scelta == prosegui_cal_stampa - { - if (_tipo_stampa == 1) - send_message('L', t, m); - else send_message('l', t, m); - } - //TString80 nomef; nomef = t.path(); nomef << "\\" << t.name(); - //if (fexist(nomef)) - if (fexist(t)) - { - _intesta_liq = TRUE; - //printer().footerlen(0); - merge_export_file(t,FALSE,TRUE); - printer().formfeed(); - _intesta_liq = FALSE; - reset_print(); - remove(t); - } - } - _st_liq[m] = TRUE; - } - } - - _datareg = mov.get_date(MOV_DATAREG); - _mov_empty = FALSE; - - if ( _datareg.month() != _dataregp.month() && _dataregp.ok() ) - { - _auto_intraf = FALSE; - printer().formfeed(); - //printer().footerlen(5); //devo rimetterlo cosi' - } - - _dataregp = _datareg; - - TDate datadoc = mov.get_date(MOV_DATADOC); - long numreg = mov.get_long(MOV_NUMREG); - long protiva = mov.get_long(MOV_PROTIVA); - long uprotiva = mov.get_long(MOV_UPROTIVA); - real totdoc = mov.get_real(MOV_TOTDOC); - TString16 numdoc = mov.get(MOV_NUMDOC); - char tipocf = mov.get(MOV_TIPO)[0]; - TString16 ocfpi = mov.get(MOV_OCFPI); - long codcf = mov.get_long(MOV_CODCF); - long numgio = mov.get_long(MOV_NUMGIO); - bool stampato = mov.get_bool(MOV_REGST); - TString16 codval = mov.get(MOV_CODVALI); - real corrval = mov.get_real(MOV_CORRVALUTA); - //bool intra = caus.get_bool(CAU_INTRACOM); //da prendere sul movimento - bool autof = caus.get_bool(CAU_AUTOFATT); - TString80 descrcau = caus.get(CAU_DESCR); - - if (_cur->pos() == 0) - _uprotivap = uprotiva ? uprotiva : protiva; - - //aggiornamento di mov - if (_tipo_stampa != 1) - if (!stampato) - { - mov.put(MOV_REGST,TRUE); - mov.rewrite(); - } - - if (codcf == 0l) - ragsoc = descrcau; - else - { - if (ocfpi.trim().empty()) - { - TRectype dep = ricerca_cf(tipocf, codcf); - ragsoc = dep.get (CLI_RAGSOC); - viacf = dep.get (CLI_INDCF); - civcf = dep.get (CLI_CIVCF); - capcf = dep.get (CLI_CAPCF); - comcf = dep.get (CLI_COMCF); - char tipoa = dep.get_char(CLI_TIPOAPER); - if (tipoa == 'F') - { - TString80 cognome, nome; - cognome = ragsoc.mid(0,30); - nome = ragsoc.mid(30,20); - cognome.trim(); nome.trim(); - ragsoc = cognome; - ragsoc << " " << nome; - } - } - else - { - TRectype dep = ricerca_occ(ocfpi); - ragsoc = dep.get (OCC_RAGSOC); - viacf = dep.get (OCC_INDIR); - civcf = dep.get (OCC_CIV); - capcf = dep.get (OCC_CAP); - comcf = dep.get (OCC_COM); - } - TRectype com = look_comuni(comcf); - comune = com.get(COM_DENCOM); - prov = com.get(COM_PROVCOM); - } - - _tipodoc = mov.get(MOV_TIPODOC); - _descr_doc = descr_doc(); - TString app(datadoc.string(brief, '/')); - - if (stampa_totali_finali()) - _doc_array.add_riga(_tipodoc,_descr_doc,totdoc); - - //setto le righe di stampa - _r = 1; - if (!_stampa_data_reg) - set_row(_r, "%s", (const char* ) _datareg.string(brief, '/')); - set_row(_r, "@9g%5ld", protiva); - if (datadoc.ok()) - set_row(_r, "@15g%s", (const char*) app); - set_row(_r, "@24g%s", (const char*) numdoc); - if (codcf != 0l) - set_row(_r, "@31g%6ld", codcf); - *_desc27 = (const char*) ragsoc; - //set_row(_r, "@38g#a", _desc25); - set_row(_r, "@68g%2s", (const char*) _tipodoc); - if (_stampa_width == 132) - set_row(_r, "@70g%r", &totdoc); - else set_row(_r, "@78g%r", &totdoc); - - if (_tipo_stampa == 1) //in caso di stampa di prova - if (! (_tipo_reg == 1 && _corrispettivi)) //e se non si tratta di registro vendite corrispettivi - if (! (_cur->pos()==0)) //il primo movimento non va controllato - { - if (protiva != _uprotivap + 1) - { - set_row(_r+1, "@2g*** NUM.PROT.FUORI SEQUENZA"); - riga = _r+2; - } - _uprotivap = uprotiva ? uprotiva : protiva; - } - - const char* r; - int i = 1; - while ((r = _desc27->get()) != NULL) - { - set_row (i, "@38g%s", r); - i++; - } - if (i > riga) riga = i; - - if (codcf != 0l && _stampa_ind_comp) - { - //set_row(_r, "@38g%-.27s", (const char*)ragsoc); - if (viacf.not_empty()) //se la via non e' vuota non puo' essere vuoto il comune - { - set_row (/*_r+1*/ i++, "@38g%-.23s %-3s",(const char *)viacf, (const char *)civcf); - set_row (/*_r+2*/ i++, "@38g%s %-.21s", (const char *)capcf, (const char *)comune); - riga = /*_r+3*/ i; - } - else if (comune.not_empty()) - { - set_row (/*_r+1*/ i++, "@38g%s %-.21s", (const char *)capcf, (const char *)comune); - riga = /*_r+2*/ i; - } - } - - _nrec = riga_rmoviva(); - if (_nrec > 0) - { - _esiste_riga_iva = TRUE; - for (int j = 0; j < _riga_rmi.items(); j++) - { - TRigaiva& riga = (TRigaiva&)_riga_rmi[j]; - rr = _r+j; - intra = riga._intra; - if (_stampa_width == 132) - { - set_row(rr, "@85g%r", &riga._imponibile); - set_row(rr, "@101g%4s",(const char*)riga._codiva); - if (_tipo_reg == 2) - set_row(rr, "@106g%d", riga._tipodet); - set_row(rr, "@107g%r", &riga._imposta); - set_row(rr, "@123g%d", riga._tipocr); - if (_tipoatt == "E" && _tipo_reg != 2) - set_row(rr, "@125g%d", riga._tipoatt); - if (_tipo_stampa == 4) //stampa con riferimento al libro giornale - set_row(rr, "@126g%5ld", numgio); - } - else //stampa a 198 - { - set_row(rr, "@93g%r", &riga._imponibile); - set_row(rr, "@109g%4s",(const char*)riga._codiva); - if (_tipo_reg == 2) - set_row(rr, "@114g%d", riga._tipodet); - set_row(rr, "@116g%r", &riga._imposta); - if (_tipoatt == "E" && _tipo_reg != 2) - set_row(rr, "@132g%d", riga._tipoatt); - set_row(rr, "@134g%d", riga._tipocr); - if (_tipo_stampa == 4) //stampa con riferimento al libro giornale - set_row(rr, "@136g%7ld", numgio); - } - } - _riga_rmi.destroy(); - } - - if ( intra && autof) - { - _auto_intraf = TRUE; - tipo_op = "3"; - } - else if (intra) - tipo_op = "1"; - else if (autof) - tipo_op = "2"; - - set_row(_r, "@66g%s", (const char*) tipo_op); - - if (_tipo_stampa == 1) //stampa di prova - { - if (_stampa_width == 132) - { - set_row(_r, "@126g%5ld", numreg); - if (stampato) - set_row(_r, "@131g*"); //solo in stampa di prova! - } - else //198 - { - set_row(_r, "@136g%7ld", numreg); - if (stampato) - set_row(_r, "@144g*"); - } - } - if (_tipo_stampa == 4 && _stampa_width == 198) - { - TLocalisamfile rmoviva (LF_RMOVIVA); - rmoviva.zero(); - rmoviva.put(RMI_NUMREG,numreg); - TRectype rec(rmoviva.curr()); - rmoviva.read(_isgteq); - for ( ; !rmoviva.eof(); rmoviva.next()) - { - if (rmoviva.curr() != rec) break; - - int gruppo = rmoviva.get_int("GRUPPO"); - int conto = rmoviva.get_int("CONTO"); - long sottoc = rmoviva.get_long("SOTTOCONTO"); - TConto tc (gruppo,conto,sottoc); - TString80 descr = tc.descrizione(); - set_row(_r, "@144g%3d %3d %6d", gruppo, conto, sottoc); - set_row(_r, "@159g%-.39s", (const char*) descr); - break; - } - } - - if (riga <= rr) riga = ++rr; - - if (corrval != ZERO) - { - TString vall (corrval.string("###.###.###.###,@@")); - set_row(riga, "@24gCodice valuta %-3s Corrispettivo in valuta %s", (const char*) codval, (const char*) vall); - } - } - return TRUE; -} - -void CG4400_application::scrivi_reg() -{ - TString16 codtab; - TTable Tabreg ("REG"); - - codtab << _annoes << _codreg; - Tabreg.zero(); - Tabreg.put("CODTAB", codtab); - if (Tabreg.read() == NOERR) - { - const TDate d = Tabreg.get_date("D3"); - if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina - { -// TDate ultima_data = format("%02d/%02d/%4d", _datareg.last_day(_datareg.month(), _annoes), _datareg.month(), _annoes); - TDate ultima_data(_datareg); - ultima_data.set_end_month(); // Meglio cosi' - - if (ultima_data > d) - Tabreg.put("D3", ultima_data); - } - else if (_data_a > d) - Tabreg.put("D3", _data_a); - - if (_tipo_reg == 2 && _stampa_cred_pre) - if (_mese_credito == 0 && _credito > ZERO) - if (_mov_empty) - Tabreg.put("I8", (long)_fino_a_mese); - else Tabreg.put("I8", (long)_datareg.month()); - - Tabreg.rewrite(); - } - - if (_tipo_stampa == 3) - { - TString16 cod = ""; - TTable lbu ("%LBU"); - - cod << _annoes << _codlib; - lbu.zero(); - lbu.put("CODTAB", cod); - if (lbu.read() == NOERR) - { - lbu.put("I0", (long) _fino_a_mese); - lbu.rewrite(); - } - } -} - -void CG4400_application::aggiorna_reg(const bool aggiorna_vidi) -{ - TString16 codtab; - TTable Tabreg ("REG"); - TLocalisamfile IndBil (LF_INDLIB); - - codtab << _annoes << _codreg; - Tabreg.zero(); - Tabreg.put("CODTAB", codtab); - if (Tabreg.read() == NOERR) - { - TDate d = Tabreg.get_date("D3"); - if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina - { -// TDate ultima_data = format("%02d/%02d/%4d", _datareg.last_day(_datareg.month(), _annoes), _datareg.month(), _annoes); - TDate ultima_data(_datareg); - ultima_data.set_end_month(); // Meglio cosi' - - if (ultima_data > d) - Tabreg.put("D3", ultima_data); - } - else if (_data_a > d) - Tabreg.put("D3", _data_a); - - Tabreg.put("I1", _pagine_stampate); - - if (_intesta_liq) - if (_tipo_riepilogativo == 'A') - Tabreg.put("I4", 13L); - else Tabreg.put("I4", (long)_datareg.month()); - - if (_tipo_reg == 2 && _stampa_cred_pre) - if (_mese_credito == 0 && _credito > ZERO) - if (_mov_empty) - Tabreg.put("I8", (long)_fino_a_mese); - else Tabreg.put("I8", (long)_datareg.month()); - - Tabreg.rewrite(); - } - - if (_tipo_stampa == 3) //stampa su libro unico - - // sul file indlib (indice libro unico) devo generare una riga per ogni - // registro stampato (ricordarsi che la stampa su libro unico deve - // avvenire mese per mese!) - // inoltre non posso stampare due volte lo stesso mese perche' la stampa - // avviene a fine mese - - { - long numero_riga = 1L; - if (!aggiorna_vidi) - { - bool trovato = FALSE; - //long ditta = get_firm(); - - IndBil.zero(); - - TRectype nuovo (IndBil.curr()); - - IndBil.put("ANNO", _annoes); - IndBil.put("CODLIB", _codlib); - TRectype rec (IndBil.curr()); - - for (IndBil.read(_isgteq); !IndBil.eof(); IndBil.next()) - { - if (IndBil.curr() != rec) break; - - int annoreg = IndBil.get_int("ANNOREG"); - int mesereg = IndBil.get_int("MESEREG"); - long cditta = IndBil.get_long("CODDITTA"); - TString16 codreg = IndBil.get("CODREG"); - TString16 codvid = IndBil.get("CODVID"); - if (_annoes == annoreg && _fino_a_mese == mesereg - && _ditta == cditta && codreg == _codreg && _codice_vidi == codvid) - { - trovato = TRUE; - numero_riga = IndBil.get_long("NUMREG"); - break; - } - else numero_riga = IndBil.get_long("NUMREG") + 1; - // cosi' mi posiziono su quel mese (altrimenti rischio di generare - // due righe per lo stesso mese e registro => la stampa di vidimazione - // mi sballa tutta!!! - } - nuovo.put("ANNO", _annoes); - nuovo.put("CODLIB", _codlib); - nuovo.put("NUMREG", numero_riga); - - nuovo.put("ANNOREG", _annoes); - nuovo.put("MESEREG", _fino_a_mese); // su libro unico ho un solo mese in gioco! - nuovo.put("PAGINI", _primast + 1); // numero iniziale pagina libro unico - nuovo.put("PAGFIN", _u_stampata); // numero finale pagina libro unico - nuovo.put("CODDITTA", _ditta); - nuovo.put("CODREG", _codreg); - nuovo.put("CODVID", _codice_vidi); - nuovo.put("PAGINIUT", _numini + 1); - nuovo.put("PAGFINUT", _pagine_stampate); - - if (!trovato) - IndBil.write(nuovo); - else IndBil.rewrite(nuovo); - } - //_primast = _u_stampata; //per la numerazione dei registri successivi - aggiorna_lib(); - } -} - -void CG4400_application::aggiorna_lib() -{ - TString16 cod = ""; - TTable lbu ("%LBU"); - - cod << _annoes << _codlib; - lbu.zero(); - lbu.put("CODTAB", cod); - if (lbu.read() == NOERR) - { - lbu.put("I0", (long) _fino_a_mese); - lbu.put("I1", (long) _u_stampata); - lbu.rewrite(); - } -} - -bool CG4400_application::stampo_liquidazione(int mese) -{ - //test tradotti alla lettera da AS/400 - //assolutamente incongruenti !!! - if (_tipo_stampa == 1) - { - if ( (_frequiva == 'T' && (mese == 3 || mese == 6 || mese == 9 || mese == 12)) - || _frequiva != 'T' || (mese == 12 && _tipo_riepilogativo == 'A') ) - return TRUE; - } - else - { - if ( (_frequiva == 'T' && (mese == 3 || mese == 6 || mese == 9 || mese == 12)) - || _frequiva != 'T' || (mese == 12 && _tipo_riepilogativo == 'A') ) - if ( (mese == 12 && _tipo_riepilogativo == 'A' && _mese_ultima_liq != 13) - || (mese != 12 && mese > _mese_ultima_liq) - || (mese == 12 && _tipo_riepilogativo != 'A' && mese > _mese_ultima_liq) ) - return TRUE; - } - return FALSE; -} - -void CG4400_application::stampa_vidi() -{ - TLocalisamfile IndBil (LF_INDLIB); - TTable TabVid ("%VID"); - TString16 codreg; - TString16 vid; - long ditta, pagfin, pagfinut; - int mese; - TPrintrow row; - - _ok_vidi = FALSE; - - if (!printer().isopen()) - printer().open(); - - IndBil.zero(); - IndBil.put("ANNO", _annoes); - IndBil.put("CODLIB", _codlib); - TRectype rec (IndBil.curr()); - IndBil.read (_isgteq); - for (; !IndBil.eof(); IndBil.next()) - { - if (IndBil.curr() != rec) break; - ditta = IndBil.get_long("CODDITTA"); - codreg = IndBil.get("CODREG"); - if (ditta == _ditta && codreg == _codreg) - { - if (!_ok_vidi) - { - ++_u_stampata; - ++_pagine_stampate; - _ok_vidi = TRUE; - } - mese = IndBil.get_int("MESEREG"); - pagfin = IndBil.get_long("PAGFIN"); - pagfinut = IndBil.get_long("PAGFINUT"); - if (mese == 12) - { - ++pagfin; - ++pagfinut; - TRectype nuovo (IndBil.curr()); - nuovo.put("PAGFIN", pagfin); - nuovo.put("PAGFINUT", pagfinut); - IndBil.rewrite(nuovo); - } - row.reset(); - row.put(format("%s", itom(mese)), 0); - row.put(format("%5ld", IndBil.get_long("PAGINI")), 10); - row.put(format("%5ld", pagfin), 17); - row.put(format("%5ld", IndBil.get_long("PAGINIUT")), 25); - row.put(format("%5ld", pagfinut), 32); - vid = IndBil.get("CODVID"); - TabVid.zero(); - TabVid.put("CODTAB", vid); - if (TabVid.read() == NOERR) - { - row.put(format("%s", (const char*)TabVid.get("S0")), 39); - row.put(format("%7d",TabVid.get_long("I0")), 71); - row.put(format("%7d",TabVid.get_long("I1")), 79); - row.put(format("%7d",TabVid.get_long("I2")), 87); - TDate d(TabVid.get_long("D0")); - row.put(format("%s", (const char*)d.string()), 95); - row.put(format("%s", (const char*)TabVid.get("S1")), 106); - } - printer().print(row); - } - } - printer().close(); -} - -void CG4400_application::liq_b0_settato() -{ - TFilename f; - f.temp("rg"); - if (_tipo_stampa == 1) - send_message('S',f, _datareg.month()); - else send_message('s',f, _datareg.month()); - //TString80 nomef; - //nomef = f.path(); nomef << "\\" << f.name(); - //if (fexist(nomef)) - if (fexist(f)) - { - printer().formfeed(); - _intesta_liq = TRUE; - //printer().footerlen(0); - merge_export_file(f,FALSE,TRUE); - _intesta_liq = FALSE; - remove(f); - } -} - -void CG4400_application::liq_other_case() -{ - if (_scelta == prosegui_cal_stampa) - { - if (stampo_liquidazione(_datareg.month())) - { - _t.temp("reg"); - if (_tipo_stampa == 1) - send_message('L', _t, _datareg.month()); - else send_message('l', _t, _datareg.month()); - } - else //se chiamo la liquidazione con L o l mi calcola anche i progressivi - if (_tipo_stampa != 1) - { - TFilename app; - app.temp(); - send_message('C', app, _datareg.month()); - } - } - if (_scelta == prosegui_stampa) - { - if (stampo_liquidazione(_datareg.month())) - { - _t.temp("reg"); - if (_tipo_stampa == 1) - send_message('S', _t, _datareg.month()); - else send_message('s', _t, _datareg.month()); - } - if (_tipo_stampa != 1) //in stampa di prova i progressivi me li calcolo io!!! - { //Why??? - TFilename app; - app.temp(); - send_message('C', app, _datareg.month()); - } - } - if (_scelta == no_liquidazione && _tipo_stampa != 1) - { - TFilename app; - app.temp(); - send_message('C', app, _datareg.month()); - } -} - -print_action CG4400_application::postprocess_page (int file, int counter) -{ - if (file == LF_MOV) - { - if (counter) //dopo aver fatto un REPEAT_PAGE (cioe' dopo aver stampato le righe settate in set_page_tot_reg()), in pratica a rottura di mese o alla fine - { - reset_print(); - if (_liquidazione) - if (!_st_liq[_datareg.month()] && stampo_liquidazione(_datareg.month())) - { - _st_liq[_datareg.month()] = TRUE; - if (_scelta == B0_settato) - liq_b0_settato(); - if (_scelta == prosegui_stampa || _scelta == prosegui_cal_stampa) - { - if (fexist(_t)) - { - printer().formfeed(); - _intesta_liq = TRUE; - //printer().footerlen(0); - merge_export_file(_t,FALSE,TRUE); - _intesta_liq = FALSE; - remove(_t); - } - } - } - } - if (!counter) - { - bool FINITO = FALSE; - TRecnotype pos = _cur->pos(); - long items = _cur->items(); - - FINITO = (pos == items-1); - - if ( FINITO ) - { - liq_other_case(); - if (_tipo_stampa != 1) - calcola_progressivi(); - set_page_tot_reg(); - return REPEAT_PAGE; - } - else - { - TLocalisamfile& mov = _cur->file(LF_MOV); - _cur->save_status(); - ++(*_cur); - _dataregs = mov.get_date(MOV_DATAREG); - --(*_cur); - _cur->restore_status(); - - if (_dataregs.month() != _dataregp.month()) - { - liq_other_case(); - if (_tipo_stampa != 1) - calcola_progressivi(); - set_page_tot_reg(); - return REPEAT_PAGE; - } - } - } - } - return NEXT_PAGE; -} - -bool CG4400_application::set_print(int n) -{ - printer().read_configuration(); // Ripristina stampante standard - - TMask m ("cg4400a"); - int giorni_del_mese; - bool ok; - - m.set_handler (TIPO_STAMPA, mask_tipo_stampa); - m.set_handler (DA_DATA, mask_data); - m.set_handler (A_DATA, mask_data); - m.set_handler (MESE, mask_mese); - m.set_handler (FINO_A_MESE, mask_mese); - m.set_handler (CODICE_LIB_UN, mask_cod); - m.set_handler (CODICE_LIBRO_IVA, mask_libun); - m.set_handler (DLG_SELECT, mask_select); - m.set_handler (F_ANNULLA, mask_azzera); - m.set_handler (A_CODICE, to_ditt_handler); - m.set_handler (DA_CODICE, fr_ditt_handler); - m.set_handler (BUT_DTO, to_butt_handler); - m.set_handler (BUT_DFR, fr_butt_handler); - m.set_handler (ANNO, year_handler); - - m.set(F_SELECT, _selected.ones()); - set_choice_limits(m); - - //printer().footerlen(5); - set_real_picture("###.###.###.###"); - - while (ok = set_ditte(m)) - { - if (_selected.ones() > 0l) - { - _annoes = m.get_int(ANNO);//in realta' e' l'anno IVA !!! - _tipo_stampa = m.get_int(TIPO_STAMPA); - _stampa_width = m.get_int(STAMPA_WIDTH); - _stampa_len = m.get_int(STAMPA_LEN); - if (_stampa_width == 1) - _stampa_width = 132; - else _stampa_width = 198; - if (_stampa_len != 0) - printer().formlen(_stampa_len); - //Se stampa di prova l'utente indica data_da e data_a - if (_tipo_stampa == 1) - { - _data_stampa = m.get(DATA_STAMPA); - _data_da = m.get(DA_DATA); - _data_a = m.get(A_DATA); - - if (!_data_da.ok()) -// _data_da = format("01/01/%4d", _annoes); - _data_da = TDate(1, 1, _annoes); // Meglio cosi' - - if (!_data_a.ok()) -// _data_a = format("31/12/%4d", _annoes); - _data_a = TDate(31, 12, _annoes); // Meglio cosi' - - const TDate d(31,12,_annoes); - if (_data_a == d) - _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0]; - else _tipo_riepilogativo = ' '; - printer().setdate(_data_stampa); - } - else //stampe definitive - { - if ( (_tipo_stampa == 2) || (_tipo_stampa == 4) ) - { - _fino_a_mese = m.get_int(FINO_A_MESE); -// _data_da = format("01/01/%4d", _annoes); //e non ultima data di stampa del registro (come invece verrebbe spontaneo di pensare) - _data_da = TDate(1, 1, _annoes); // Meglio cosi' - } - else //stampa su libro unico - { - _codlib = m.get(CODICE_LIB_UN); - _fino_a_mese = m.get_int(MESE); - _u_stampata = m.get_int(ULTIMA_PAGINA); - _rif_vid = m.get_bool(RIF_VID); - _primast = _u_stampata; -// _data_da = format("01/%02d/%04d", _fino_a_mese, _annoes); - _data_da = TDate(1, _fino_a_mese, _annoes); // Meglio cosi' - } - if (_fino_a_mese == 12) - { - giorni_del_mese = 31; - _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0]; - } - else - { - _tipo_riepilogativo = ' '; -// TDate primo = format("01/%02d/%4d", _fino_a_mese+1, _annoes); -// --primo; - TDate primo(1, _fino_a_mese, _annoes); - primo.set_end_month(); // Meglio cosi' - - giorni_del_mese = primo.day(); - } -// _data_a=format("%02d/%02d/%4d",giorni_del_mese,_fino_a_mese,_annoes); - _data_a = TDate(giorni_del_mese, _fino_a_mese, _annoes); // Meglio cosi' - } - _stampa_data_reg = stampa_datareg(); - if (_tipo_stampa == 3) - compila_lib(); - stampa_registri_IVA(m); - } - else - { - warning_box("Nessuna ditta selezionata!"); - continue; - } - } - return FALSE; -} - -bool CG4400_application::look_lia(long ditta) -{ - if (ditta == 0l) ditta = get_firm(); - - TString16 y; y.format("%05ld%04d", ditta, _annoes); - - _tablia->zero(); - _tablia->put("CODTAB", y); - _tablia->read(); - const bool ok = _tablia->good(); - if (ok) - _credito = _tablia->get_real("R0"); - else _credito = ZERO; - return ok; -} - -void CG4400_application::look_reg() -{ - _liquidazione = _tabreg->get_bool("B7"); - _riep_liq = _tabreg->get_bool("B6"); - _corrispettivi = _tabreg->get_bool("B0"); - _sosp_imposta = _tabreg->get_bool("B1"); - _pagine_stampate = _tabreg->get_long("I1"); - _numini = _pagine_stampate; - _cod_un_loc = _tabreg->get_int("I7"); - _mese_ultima_liq = _tabreg->get_int("I4"); - _mese_credito = _tabreg->get_int("I8"); - _codatt = _tabreg->get("S8"); - _tipoatt = tipo_attivita(); - _attivita = desc_attivita(); - _desc_lib = _tabreg->get ("S0"); - _stampa_ind_ditta = _tabreg->get_bool ("B9"); - _stampa_ind_comp = _tabreg->get_bool ("B5"); - _stampa_cred_pre = _tabreg->get_bool ("B4"); -} - -void CG4400_application::clear_stliq() -{ - for (int i=0; i <= 12; i++) - _st_liq[i] = FALSE; -} - -bool CG4400_application::setta_mask(long i) -{ - if (_stampa_mese == 13) _stampa_mese = 0; - if (_tipo_stampa == 2 || _tipo_stampa == 4) - { - TMask mb("cg4400b"); - mb.set(F_CODDITTA, _ditta); - mb.set(F_RAGSOC, _ditte->row(i).get(2)); - mb.set(COD_LIB, _codreg); - const char* m = ""; - m = format("%02d", _stampa_mese); - mb.set(U_MESE, m); - mb.set(U_PAGINA, _pagine_stampate); - if (_u_data.ok()) - mb.set(U_DATA, _u_data.string()); - KEY tasto = mb.run(); - if (tasto != K_ENTER) return FALSE; - } - return TRUE; -} - -void CG4400_application::no_movimenti() -{ - _mov_empty = TRUE; - if (_liquidazione) - { - int da, a; - //stampo la liquidazione per tutti i mesi fino a _fino_a_mese - if (_tipo_stampa == 2 || _tipo_stampa == 4) - da = 1; - if (_tipo_stampa == 3) - da = _fino_a_mese; - if (_tipo_stampa == 1) - da = _data_da.month(); - if (_tipo_stampa == 1) - a = _data_a.month(); - else a = _fino_a_mese; - for (int m = da; m <= a; m++) - { - if (! printer().isopen()) - printer().open(); - if (stampo_liquidazione(m)) - { - TFilename f; - f.temp("rgp"); -// _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header - _datareg = TDate(1, m, _annoes); // Meglio cosi' - - if (_scelta == B0_settato || _scelta == prosegui_stampa) - { - if (_tipo_stampa == 1) - send_message('S',f, m); - else send_message('s',f, m); - } - else //_scelta == prosegui_cal_stampa - { - if (_tipo_stampa == 1) - send_message('L', f, m); - else send_message('l', f, m); - } - if (fexist(f)) - { - _intesta_liq = TRUE; - //printer().footerlen(0); - merge_export_file(f,FALSE,TRUE); - printer().formfeed(); - _intesta_liq = FALSE; - remove(f); - } - } - } - if (printer().isopen()) printer().close(); - } - if (_tipo_stampa != 1) scrivi_reg(); //aggiorno il registro anche se non ho stampato proprio nulla per quel mese! -} - -bool CG4400_application::stampa_registri_IVA(const TMask& m) -{ - bool ok = FALSE; - for (int i = 0; i < _ditte->items(); i++) - { - if (_selected[(long)i]) - { - bool msg = TRUE; - _ditta = _ditte->row(i).get_long(1); - _frequiva = _ditte->row(i).get_char(3); - _intesta_liq = FALSE; - _intesta_vidi = FALSE; - _primast = _u_stampata; - _ok_vidi = FALSE; - _stampa_mese = 13; - - TApplication::set_firm(_ditta); - look_lia(); - ok = compila_reg(m); - if (!ok) continue; - if (_tipo_stampa == 2 || _tipo_stampa == 4) - if (!controlla_mov()) - { - TApplication::set_firm(__firm); - return fatal_box("Finire di stampare registri anno precedente"); - } - if (!_stampa_tutti_i_registri) - { - _scelta = controlla_b0(); - _cur->set_filterfunction(filter_func); - ok = setta_mask(i); - if (!ok) continue; - if (_liquidazione) - { - if (_tipo_stampa == 2 || _tipo_stampa == 4) - _size_header = _stampa_ind_ditta ? 3 : 2; - else _size_header = 3; - clear_stliq(); - _scelta = controlla_liquidazione(); - if (_scelta == non_proseguire) - return FALSE; - } - - (*_cur) = 0L; //la filter function viene chiamata quando posiziono il cursore - const long item = _cur->items(); - - // 17.5.95 Leggo parametri di stampa del registro - TString16 config; - const long codditta = get_firm(); - const char* reg = (const char*)_codreg; - config.format("REG%05ld%03s", codditta, reg); - printer().read_configuration(config); - - if (item > 0l) - { - print(); - - if (is_cancelled()) return FALSE; - - if (_tipo_stampa != 3 && _liquidazione) - stampa_liq_mesi_succ(); - } - //non ci sono movimenti da stampare nel periodo richiesto! - else no_movimenti(); - - if (_tipo_stampa == 3 && _rif_vid) - { - _intesta_vidi = TRUE; - stampa_vidi(); //stampa riferimenti vidimazione - } - } - else //stampa tutti i registri - { - TString16 codtab, cod_lib_un; - int anno; - TDate sca_vid; - for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) - { - _tipo_reg = _tabreg->get_int("I0"); - codtab = _tabreg->get("CODTAB"); - anno = atoi(codtab.mid(0,4)); - if (anno > _annoes) - break; - if (anno == _annoes) - if ( _tipo_reg == 1 || _tipo_reg == 2 ) //registro iva - { - _codreg = codtab.mid(4,3); - cod_lib_un = _tabreg->get("S6"); - sca_vid = _tabreg->get_date("D1"); - _stampa_ind_ditta = _tabreg->get_bool("B9"); - _liquidazione = _tabreg->get_bool("B7"); - if (_tipo_stampa != 1) - _u_data = _tabreg->get_date("D3"); - if (_tipo_stampa == 2 || _tipo_stampa == 4) - { - if (cod_lib_un.not_empty()) - continue; - if (sca_vid.ok()) - if (sca_vid.month() < _fino_a_mese) - continue; - if (_u_data.ok()) - if (_data_a < _u_data) - { - message_box("Ditta %ld: Il registro %s e' gia' stato stampato come bollato di %s", _ditta, (const char*) _codreg, itom(_fino_a_mese)); - continue; - } - } - if (_tipo_stampa == 4) //stampa con riferimenti al libro giornale - { - TString16 d; - bool good; - TRecnotype rec = _tabreg->recno(); - bool trovato = cerca_libro_gio(d, &good); - _tabreg->readat(rec); - if (!trovato) - continue; - } - if (_tipo_stampa == 3) //stampa su libro unico - { - if (cod_lib_un != _codlib) - continue; - if (sca_vid.ok()) - if (sca_vid.month() < _fino_a_mese) - continue; - if (_u_data.ok()) - if (_fino_a_mese < _u_data.month()) //significa che e' gia' - continue; - } - msg = FALSE; - - look_reg(); - - _intesta_liq = FALSE; - _intesta_vidi = FALSE; - _primast = _u_stampata; //per la numerazione dei registri successivi - _ok_vidi = FALSE; - _stampa_mese = 13; - _scelta = controlla_b0(); //sul registro non va stampata la liq. ma comunque - //va richiamata per il calcolo progressivi (a seconda di b0) - //se non e' stampa di prova - ok = setta_mask(i); - if (!ok) continue; - - if (_liquidazione) - { - if (_tipo_stampa == 2 || _tipo_stampa == 4) - _size_header = _stampa_ind_ditta ? 3 : 2; - else _size_header = 3; - clear_stliq(); - _scelta = controlla_liquidazione(); - if (_scelta == non_proseguire) - return FALSE; - } - - _cur->set_filterfunction(NULL); - _cur->set_filterfunction(filter_func); - - // Vado a vedere se ci sono movimenti - (*_cur) = 0L; - const long items = _cur->items(); - - // 17.5.95 Leggo parametri di stampa del registro - TString16 config; - const long codditta = get_firm(); - const char* reg = (const char*)_codreg; - config.format("REG%05ld%03s", codditta, reg); - printer().read_configuration(config); - - if (items > 0l) - { - print(); - - if (is_cancelled()) return FALSE; - - if (_tipo_stampa != 3 && _liquidazione) - stampa_liq_mesi_succ(); - } - else - no_movimenti(); - - if (_tipo_stampa == 3 && _rif_vid) - { - _intesta_vidi = TRUE; - stampa_vidi(); //stampa riferimenti vidimazione - } - } - } //for - if (msg) - //if ( (_tipo_stampa != 3) || (_tipo_stampa == 3 && _fino_a_mese == 1) ) - if ( (_tipo_stampa != 3) || (_tipo_stampa == 3 && _fino_a_mese == 1 && _selected.ones() == 1L) ) //il messaggio seguente, nel caso di stampa su libro unico, - message_box("Ditta %ld: nessun registro soddisfa i parametri indicati", _ditta); //viene gia' dato nell'handler (che scatta pero' se il mese di - } //stampa e' diverso da gennaio - } - } - TApplication::set_firm(__firm); - return TRUE; -} - - -void CG4400_application::stampa_liq_mesi_succ() -{ - int da = _datareg.month() + 1; - int a = _data_a.month(); - for (int m = da; m <= a; m++) - { - if (!printer().isopen()) - printer().open(); - if (stampo_liquidazione(m)) - { -// _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header (intestazione per la stampa liquidazione) - _datareg = TDate(1, m, _annoes); // Meglio cosi' - TFilename t; - t.temp("iva"); - if (_tipo_stampa == 1) - send_message('L',t, m); //prima era S ma non andava bene! - else send_message('l',t,m); //prima era s - //TString80 nomef; nomef = t.path(); nomef << "\\" << t.name(); - //if (fexist(nomef)) - if (fexist(t)) - { - _intesta_liq = TRUE; - if (m > da) printer().formfeed(); - //printer().footerlen(0); - merge_export_file(t,FALSE,TRUE); - _intesta_liq = FALSE; - remove(t); - } - } - } - if (printer().isopen()) printer().close(); -} - -void CG4400_application::send_message(char tipo, const TFilename& nome, int mese) -{ - const char* app; - - if (tipo == 'S' || tipo == 's') - app = "cg4 -2 -S"; - else if (tipo == 'C') - app = "cg4 -2 -C"; - else app = "cg4 -2"; - - TToken_string ss(10); - - ss.add(_annoes); - if (_tipo_riepilogativo == 'A' && mese == 12) - ss.add(13); - else ss.add(mese); - ss.add(_ditta); - ss.add(tipo); - ss.add(_data_stampa.string()); - ss.add(nome); - ss.add(_size_header); - //ss.add("x"); - - TMessage liq (app, "RCL", ss); - liq.send(); - - TExternal_app pn(app); - pn.run(); -} - -bool CG4400_application::set_ditte(TMask& m) -{ - /* - _selected.reset(); - m.field(F_SELECT).set("0"); - m.field(DA_CODICE).set(""); - m.field(A_CODICE).set(""); - */ - m.field(TIPO_STAMPA).set("1"); - m.field(DA_DATA).set(""); - m.field(A_DATA).set(""); - m.field(CODICE_LIBRO_PROVA).set(""); - - KEY tasto; - tasto = m.run(); - // m.first_focus(tasto); - return tasto == K_ENTER; -} - -TRectype& CG4400_application::look_comuni (const char * cod) -{ - _com->zero(); - _com->put(COM_COM, cod); - _com->read(); - if (_com->bad()) - _com->zero(); - - return _com->curr(); -} - -void CG4400_application::get_dati_ditta() -{ - TLocalisamfile nditte(LF_NDITTE); - TLocalisamfile anag(LF_ANAG); - TLocalisamfile unloc(LF_UNLOC); - TString codanagr; - TString tipoa; - - nditte.zero(); - nditte.put(NDT_CODDITTA, get_firm()); - nditte.read(); - - if (nditte.bad()) nditte.zero(); - - codanagr = nditte.get(NDT_CODANAGR); - tipoa = nditte.get(NDT_TIPOA); - _ragsoc = nditte.get(NDT_RAGSOC); - - anag.setkey(1); - anag.zero(); - anag.put (ANA_TIPOA, tipoa); - anag.put (ANA_CODANAGR, codanagr); - anag.read(); - if (anag.bad()) anag.zero(); - - _cofi = anag.get(ANA_COFI); - _paiva = anag.get(ANA_PAIV); - _comunefis = anag.get(ANA_COMRF); - - if (_comunefis.empty()) - _comunefis = anag.get(ANA_COMRES); - - TRectype dep = look_comuni (_comunefis); - - _comunefis = dep.get(COM_DENCOM); - _provfis = dep.get(COM_PROVCOM); - _cap = dep.get(COM_CAPCOM); - if (_comunefis.empty()) - { - _viafis = anag.get(ANA_INDRF); - _viafis.rtrim(); - _viafis << " " << anag.get (ANA_CIVRF); - } - else - { - _viafis = anag.get(ANA_INDRES); - _viafis.rtrim(); - _viafis << " " << anag.get (ANA_CIVRES); - } - - if (_cod_un_loc) - { - unloc.zero(); - unloc.put(ULC_CODDITTA, get_firm()); - unloc.put(ULC_CODULC, _cod_un_loc); - unloc.read(); - if (unloc.read() == NOERR) - { - TRectype dep = look_comuni (unloc.get(ULC_COMULC)); - _comunefis = dep.get(COM_DENCOM); - _provfis = dep.get(COM_PROVCOM); - _cap = dep.get(COM_CAPCOM); - _viafis = unloc.get(ULC_INDULC); - _viafis.rtrim(); - _viafis << " " << unloc.get(ULC_CIVULC); - } - } -} - -int CG4400_application::stampa_intestazione() -{ - int r = 1; - TString codice_ditta; - TString riga(_stampa_width); - - get_dati_ditta(); - codice_ditta << get_firm(); - - set_header (r, "Ditta %s %s %s %s %s %s", (const char*)codice_ditta, - (const char*)_ragsoc, (const char*)_viafis, - (const char*)_cap, (const char*)_comunefis, - (const char*)_provfis); - r++; - //printer().setdate(_data); - if (_tipo_stampa == 1) - { - riga = "REGISTRO DI PROVA Data @<"; - riga.right_just(_stampa_width-6); - } - riga.overwrite (format("Partita iva %s Codice fiscale %s", (const char*)_paiva, (const char*)_cofi)); - set_header (r, riga); - - return r; -} - -void CG4400_application::preprocess_header() -{ - int r=1; - char cor, nd1, nd2; - char tipo = ' '; - char type = ' '; - int mese, anno; - TString riga(_stampa_width); - TString data(30); - - riga.fill('-'); - - if (_tipo_stampa != 3) - { - mese = _datareg.month(); - anno = _datareg.year(); - } - else //se _tipo_stampa == 3 (su libro unico) sto stampando un solo mese - { - mese = _fino_a_mese; - anno = _annoes; - } - - data.format("%s %s %d", "mese di", itom(mese), anno); - - reset_header(); - - if (_tipo_stampa == 2 || _tipo_stampa == 4) - { - if (_stampa_ind_ditta) - r = stampa_intestazione(); - } - else // se stampa di prova o su libro unico l'intestazione della ditta - // va sempre stampata - r = stampa_intestazione(); - - if (_tipo_stampa == 3 && !_intesta_vidi) - { - ++_u_stampata; - ++_pagine_stampate; - } - - if (_tipo_stampa == 2 || _tipo_stampa == 4) - ++_pagine_stampate; - - if (_tipo_stampa == 3) - set_header(r, "@94gProgr.Studio %ld@114gProgr.Utente %ld", _u_stampata, _pagine_stampate); - - // cosi' sono sicura che l'aggiornamento viene fatto ad ogni salto pagina - // (cioe' a rottura di mese) - if (_tipo_stampa != 1) aggiorna_reg(_ok_vidi); - - r++; - - /* - if (!_intesta_vidi) - set_header(r, "Registro IVA: %s %s %s Attivita\' %s %s", - (const char *) _codreg, (const char *) _desc_lib, - (const char *) data, (const char *) _codatt, - (const char *) _attivita); - */ - if (!_intesta_vidi) - { - if (_intesta_liq) - set_header(r, "Registro IVA: %s %s %s", (const char*)_codreg, - (const char*)_desc_lib, (const char*) data); - else set_header(r, "Registro IVA: %s %s %s Attivita\' %s %s", - (const char*) _codreg, (const char*) _desc_lib, - (const char*) data, (const char*) _codatt, - (const char*) _attivita); - } - else - { - set_header(r++, "Registro IVA: %s %s", (const char *) _codreg, (const char *) _desc_lib); - set_header(r, "RIFERIMENTI VIDIMAZIONE"); - } - - if (_intesta_liq) - { - /* - r++; - set_header(r++, "CALCOLO LIQUIDAZIONE IVA"); - set_header(r++,riga); - TString title (80); - title << "Liquidazione IVA "; - if (_tipo_riepilogativo == 'A' && mese == 12) - title << "Annuale " << format("%d", anno); - else - { - title << "del periodo"; - title << format(" %s %d", itom(mese), anno); - } - set_header(r++, "%s@102g Frequenza %s", (const char*) title, _frequiva == 'T' ? "T" : "M"); - set_header(r++,riga); - set_header(r,""); - */ - } - else //non sto stampando la liquidazione - { - r++; - set_header(r, riga); - r++; - if (_tipo_reg == 1) //registro vendite - { - cor = 'R'; - nd1 = ' '; - nd2 = ' '; - } - if (_tipo_reg == 2) - { - cor = 'C'; - nd1 = 'N'; - nd2 = 'D'; - } - if (_tipoatt == "E") //attivita' mista - { - tipo = 'A'; - type = 'T'; - } - /* - if ((!_stampa_data_reg) && _stampa_width == 132) - set_header(r,"Data I/P"); - */ - if (_tipo_stampa == 1) //stampa di prova (_intesta_vidi e' di sicuro FALSE) - { - if (_stampa_width == 132) - { - set_header(r,"@10gNum.@19gDocumento@66gT Tipo@102gCod %c@123gT %c@128gNum", nd1, tipo); - r++; - set_header(r, "Data reg. prot.@17gData@24gNumero Codice Ragione sociale/descrizione@66gO Doc.@74gTotale doc.@90gImponibile Iva %c@115gImposta@123g%c %c@128gReg", nd2, cor, type); - r++; - } - else //stampa a 198 - { - set_header(r,"Registrazione Documento@66gT Tipo@110gCod %c@132g%c T@139gNum.", nd1, tipo, cor); - r++; - set_header(r, "Data Protocollo Data@24gNumero Codice Ragione sociale/descrizione@66gO Documento@80gTot.Documento@98gImponibile Iva %c@124gImposta@132g%c %c@139gReg.", nd2, type, cor); - r++; - } - } - else if (!_intesta_vidi) - { - if (_stampa_width == 132) - { - set_header(r,"@10gNum.@19gDocumento@66gT Tipo@102gCod %c@123gT %c", nd1, tipo); - if (_tipo_stampa == 4) //stampa definitiva con rif. al libro giornale - set_header(r, "@128gNum."); - r++; - set_header(r, "Data reg. prot.@17gData@24gNumero Codice Ragione sociale/descrizione@66gO Doc.@74gTotale doc.@90gImponibile Iva %c@115gImposta@123g%c %c", - nd2, cor, type); - if (_tipo_stampa == 4) - set_header(r, "@128gop."); - r++; - } - else //stampa a 198 - { - set_header(r,"Registrazione Documento@66gT Tipo@110gCod %c@132g%c T", nd1, tipo); - if (_tipo_stampa == 4) - set_header(r, "@139gNum."); - r++; - set_header(r, "Data Protocollo Data@24gNumero Codice Ragione sociale/descrizione@66gO Documento@80gTot.Documento@98gImponibile Iva %c@124gImposta@132g%c %c", nd2, type, cor); - if (_tipo_stampa == 4) - set_header(r, "@139gop. @144gCodice conto @159gDescrizione sottoconto"); - r++; - } - } - else if (_tipo_stampa == 3 && _intesta_vidi) - { - TString tr(52); - tr.fill('-'); - set_header(r++,"@10gPagine studio Pagine utente ---------------- V I D I M A Z I O N E %s", (const char*)tr); - set_header(r++,"Mese@12gda@20ga@27gda@35ga Intestatario@71gN.fogli Pag.in. Pag.fin. Data Ufficio"); - } - if (_stampa_ind_comp && !_intesta_vidi) - set_header(r++, "@38gGeneralita'"); - - set_header(r, riga); - } -} - -int cg4400 (int argc, char * argv[]) -{ - CG4400_application a; - a.run(argc, argv, "Stampa registri IVA"); - return 0; -} - - - - - - - - - - - - - - +// ******************* +// Stampa registri IVA +// ******************* +#include "cg4.h" +#include "cg4400.h" +#include "cg4400a.h" +#include "cg4400b.h" + +static TString256 TMP; + +inline CG4400_application& app() { return (CG4400_application&)main_app(); } + +bool CG4400_application::filter_func (const TRelation * r) +{ + TLocalisamfile& mov = r->lfile(LF_MOV); + TString16 codreg = mov.get(MOV_REG); + TDate datareg = mov.get_date(MOV_DATAREG); + int annoiva = mov.get_int(MOV_ANNOIVA); + bool regst = mov.get_bool(MOV_REGST); + + if (codreg != (app()._codreg) || annoiva != (app()._annoes)) + return FALSE; + + if (app()._data_da.string() != "" && app()._data_a.string() != "") + if ( (datareg < app()._data_da || datareg > app()._data_a ) || (!datareg.ok()) ) + return FALSE; + + if (app()._tipo_stampa != 1) //stampa di bollato + if (regst) //il movimento e' gia' stato stampato in forma definitiva + return FALSE; + + if (datareg.month() < app()._stampa_mese) + app()._stampa_mese = datareg.month(); + return TRUE; +} + +HIDDEN int compare_rows(const TObject** o1, const TObject** o2) +{ + TRiga* r1 = (TRiga*)*o1; + TRiga* r2 = (TRiga*)*o2; + + return (strcmp((const char*)r1->_codiva, (const char*)r2->_codiva)); +} + +HIDDEN int compare_fields(const TObject** o1, const TObject** o2) +{ + TRigaiva* r1 = (TRigaiva*)*o1; + TRigaiva* r2 = (TRigaiva*)*o2; + TString16 campo1; + TString16 campo2; + + campo1.format("%d%4s", r1->_tipodet, (const char*)r1->_codiva); + campo2.format("%d%4s", r2->_tipodet, (const char*)r2->_codiva); + return strcmp(campo1, campo2); +} + +bool CG4400_application::stampa_totali_finali() +{ + TConfig conf(CONFIG_DITTA); + return conf.get_bool("StTfFr"); +} + +bool CG4400_application::stampa_datareg() +{ + TConfig conf(CONFIG_STUDIO); + return conf.get_bool("NoDtRg"); +} + +bool CG4400_application::mask_select (TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + app()._ditte->enable_check(); + // seleziona e aggiungi alle gia' selezionate + if (app()._ditte->run() == K_ENTER) + { + for (long j = 0l; j < app()._ditte->items(); j++) + app()._selected.set(j, app()._ditte->checked(j)); + app().set_choice_limits(f.mask()); + } + } + return TRUE; +} + +bool CG4400_application::mask_azzera (TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + app()._selected.reset(); + f.mask().reset(F_SELECT); + f.mask().reset(DA_CODICE); + f.mask().reset(A_CODICE); + app()._ditte->check(-1, FALSE); + } + return TRUE; +} + +bool CG4400_application::mask_tipo_stampa(TMask_field& f, KEY k) +{ + TMask& m = f.mask(); + + if (k == K_SPACE) + { + int tipo_stampa = m.get_int(TIPO_STAMPA); + if (tipo_stampa == 3) //stampa su libro unico + { + m.enable_page(1); + TMask_field& cc = f.mask().field(CODICE_LIB_UN); + cc.set_dirty(); + } + else + m.disable_page(1); + } + return TRUE; +} + +bool CG4400_application::mask_mese (TMask_field& f, KEY k) +{ + if (k == K_SPACE) + { + const short id = f.dlg(); + int mese; + if (id == MESE) //Per stampa su libro unico + mese = f.mask().get_int(MESE); + if (id == FINO_A_MESE) + mese = f.mask().get_int(FINO_A_MESE); //Per stampa su bollato + if (id == MESE) + { + if (mese == 12) + { + f.mask().show (TIPO_RIEPILOGATIVO); + f.mask().show (RIF_VID); + } + else + { + f.mask().hide (TIPO_RIEPILOGATIVO); + f.mask().hide (RIF_VID); + } + } + if (id == FINO_A_MESE) + { + if (mese == 12) + f.mask().show (TIPO_RIEPILOGATIVO); + else f.mask().hide (TIPO_RIEPILOGATIVO); + } + } + if (k==K_TAB && f.mask().is_running()) + { + const short id = f.dlg(); + if (id == MESE) + f.mask().send_key(K_TAB, CODICE_LIBRO_IVA); + } + return TRUE; +} + +bool CG4400_application::look_reg(int i, int anno, TString& codlib, int m, const char* cod, int* umese, long ditta) +{ + TString16 y; + + y << anno << cod; + _tabreg->zero(); + _tabreg->put("CODTAB", y); + + if (_tabreg->read() == NOERR) + { + int tipo = _tabreg->get_int("I0"); + if (tipo == 1 || tipo == 2) + { + TString16 cod_lib_un = _tabreg->get("S6"); + TDate u_data = _tabreg->get_date("D3"); + TDate sca_vid = _tabreg->get_date("D1"); + if (codlib != cod_lib_un) + { + if (_selected.ones() == 1L) + if (_selected[i]) + message_box("Ditta %ld: il codice libro unico del registro non e' uguale al codice libro unico indicato", ditta); + return FALSE; + } + if (m < *umese) + { + if (_selected.ones() == 1L) + if (_selected[i]) + message_box("Ditta %ld: il mese indicato e' inferiore al mese dell'ultima data di stampa del registro", ditta); + return FALSE; + } + if (u_data.ok()) + *umese = u_data.month(); + else *umese = 0; + + if (sca_vid.ok()) + if (sca_vid.month() < m) + { + if (_selected.ones() == 1L) + if (_selected[i]) + message_box("Ditta %ld: la data scadenza di vidimazione del registro non deve essere inferiore al mese indicato", ditta); + return FALSE; + } + } + return TRUE; + } + return FALSE; +} + +bool CG4400_application::look_regs(int anno, TString& codlib, int m, int* umese, long ditta, TProgind* prog) +{ + int a, tipo; + TString16 codtab; + bool ok = FALSE; + *umese = 13; + + for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) + { + tipo = _tabreg->get_int("I0"); + codtab = _tabreg->get("CODTAB"); + a = atoi(codtab.mid(0,4)); + if (a > anno) + break; + if (a == anno) + if ( tipo == 1 || tipo == 2 ) //registro iva + { + TString16 cod_lib_un = _tabreg->get("S6"); + TDate sca_vid = _tabreg->get_date("D1"); + TDate u_data = _tabreg->get_date("D3"); + if (codlib != cod_lib_un) + continue; + if (u_data.ok()) + if (m < u_data.month()) + continue; + if (u_data.ok()) + *umese = (*umese < u_data.month()) ? *umese : u_data.month(); + if (sca_vid.ok()) + if (sca_vid.month() < m) + continue; + int month; + if (!u_data.ok()) + month = 0; + else month = u_data.month(); + if (month < m - 1) + { + app().set_firm(__firm); + delete prog; + error_box("Ditta %ld: Stampare i registri dei mesi precedenti", ditta); + app().stop_run(); + } + ok = TRUE; + } + } + return ok; +} + +bool CG4400_application::mask_libun (TMask_field& f, KEY k) +{ + if (k==K_TAB && f.mask().is_running()) + { + TString16 codlib(f.mask().get(CODICE_LIB_UN)); + //modifica del 26/04/1995 + if (codlib.empty()) + { + app()._test = TRUE; + return FALSE; + } + //fine modifica + + if (app()._selected.ones() == 0l) return FALSE; + + TProgind* p = new TProgind(app()._ditte->items()/2,"Verifica parametri in corso...",FALSE,TRUE,30); + + TString16 cod(f.mask().get(CODICE_LIBRO_IVA)); + int fino_a_mese = f.mask().get_int(MESE); + int anno = f.mask().get_int(ANNO); + bool ok = FALSE; + int last_mese = 13; + int mese = 0; + + app().__firm = app().get_firm(); + + for (int i = 0; i < app()._ditte->items(); i++) + { + //p->addstatus(1); + long ditta = app()._ditte->row(i).get_long(1); + if (prefix().exist(ditta)) + { + p->addstatus(1); + app().set_firm(ditta); + if (cod.not_empty()) + { + ok = app().look_reg(i,anno,codlib,fino_a_mese,cod,&mese,ditta); + if (!ok) + { + //modifica del 21/04/1995 suggerita da Cinzia!!! + /*****Rimodifica del 19/07/95 MI0817 + if (app()._selected.ones() == 1L) //solo se ho selezionato 1 ditta devo dare il messaggio + if (app()._selected[i]) + f.message_box("Ditta %ld: il registro %s non soddisfa i parametri indicati", ditta, (const char*)cod); + *****/ + continue; + } + if (mese < fino_a_mese - 1) //indipendentemente se si tratta di una ditta selezionata oppure no + { + app().set_firm(app().__firm); + delete p; + f.error_box("Ditta %ld: Stampare i registri dei mesi precedenti", ditta); + app().stop_run(); + } + } + else + { + ok = app().look_regs(anno,codlib,fino_a_mese,&mese,ditta,p); + if (!ok) + { + if (app()._selected.ones() == 1L) //solo se ho selezionato 1 ditta devo dare il messaggio + if (app()._selected[i]) + f.message_box("Ditta %ld: nessun registro soddisfa i parametri indicati", ditta); + continue; + } + } + //if (app()._selected[i]) + last_mese = (last_mese < mese) ? last_mese : mese; + } + } + app().set_firm(app().__firm); + + if (last_mese == 13) + last_mese = 0; //l'ultima data di stampa sul/sui registri specificati e' vuota (cioe' non sono ancora stati stampati sul libro unico specificato per l'anno specificato) + const char* me = ""; + me = format("%02d", last_mese); + f.mask().set(ULTIMO_MESE, me); + delete p; + } + return TRUE; +} + +bool CG4400_application::mask_cod (TMask_field& f, KEY k) +{ + if (k == K_TAB) + { + TTable TabLbu ("%LBU"); + TString codtab; + int anno; + + TString16 codlib(f.get()); + anno = f.mask().get_int(ANNO); + TabLbu.zero(); + codtab.format ("%04d%-3s", anno, (const char*)codlib); + TabLbu.put ("CODTAB", codtab); + TabLbu.read(); + if ( TabLbu.good() ) + { + //f.mask().set(ULTIMO_MESE,TabLbu.get_long("I0")); + f.mask().set(ULTIMA_PAGINA,TabLbu.get_long("I1")); + app()._codice_vidi = TabLbu.get("S4"); + } + //modifica del 26/04/1995 + if (app()._test) + { + f.mask().send_key(K_TAB, CODICE_LIBRO_IVA); + app()._test = FALSE; + } + //fine modifica + } + return TRUE; +} + +bool CG4400_application::mask_data (TMask_field& f, KEY k) +{ + if (k == K_TAB && f.mask().is_running()) + { + const int anno = f.mask().get_int(ANNO); + TDate data(f.get()); + if (data.ok()) + if (data.year() != anno) + { + f.warning_box("L'anno delle date limite deve essere uguale all'anno iva specificato"); + return FALSE; + } + if (f.dlg() == A_DATA) + if (data.ok) + { + if ( data.day() == 31 && data.month() == 12 ) + f.mask().show (TIPO_RIEPILOGATIVO); + else f.mask().hide (TIPO_RIEPILOGATIVO); + } + } + return TRUE; +} + +const char * CG4400_application::descr_doc() +{ + TTable tab_tpd("%TPD"); + TString codtab(format("%-2s",(const char*) _tipodoc)); + + tab_tpd.zero(); + tab_tpd.put("CODTAB", codtab); + if (tab_tpd.read()==NOERR) + TMP = tab_tpd.get("S0"); + else + TMP = ""; + + return TMP; +} + +const char * CG4400_application::descr_iva(const char * cod) +{ + TTable tab_iva("%IVA"); + TString codtab(format ("%-4s", cod)); + + tab_iva.zero(); + tab_iva.put("CODTAB", codtab); + if (tab_iva.read()==NOERR) + TMP = tab_iva.get("S0"); + else + TMP = ""; + + return TMP; +} + +const char * CG4400_application::tipo_attivita() +{ + TLocalisamfile attiv (LF_ATTIV); + + attiv.zero(); + attiv.put("CODDITTA", get_firm()); + attiv.put("CODATT", _codatt); + if (attiv.read() == NOERR) + TMP = attiv.get("TIPOATT"); + else TMP = ""; + return TMP; +} + +const char * CG4400_application::desc_attivita() +{ + TTable attiv ("%AIS"); + + attiv.zero(); + attiv.put("CODTAB", _codatt); + if (attiv.read()==NOERR) + TMP = attiv.get("S0"); + else + TMP = ""; + return TMP; +} + +TRectype& CG4400_application::ricerca_cf(char tipocf, long codcf) +{ + _clifo->zero(); + _clifo->put(CLI_TIPOCF, tipocf); + _clifo->put(CLI_CODCF, codcf); + _clifo->read(); + if (_clifo->bad()) + _clifo->zero(); + + return _clifo->curr(); +} + +TRectype& CG4400_application::ricerca_occ(const char * occ) +{ + TLocalisamfile occas (LF_OCCAS); + occas.zero(); + occas.put(OCC_CFPI, occ); + occas.read(); + if (occas.bad()) + occas.zero(); + + return occas.curr(); +} + +bool CG4400_application::year_handler(TMask_field& f, KEY key) +{ + if (key == K_TAB && f.focusdirty()) + { + app().begin_wait(); + app().set_year(atoi(f.get())); + app().build_nomiditte(); + app().build_ditte_sheet(); + app().end_wait(); + } + return TRUE; +} + +void CG4400_application::build_ditte_sheet() +{ + // build sheet + _ditte->destroy(); + for (int i = 0; i < _nomiditte.items(); i++) + { + TToken_string* d = new TToken_string(64); + *d = (TToken_string&)_nomiditte[i]; + const char vers = d->get_char(2); + bool selectable = vers == '?'; + d->insert(" |", 0); + const long pos = _ditte->add(d); + if (selectable) + _ditte->disable(pos); + else if (_selected[i]) + _ditte->check(pos); + } +} + +// --------------------------- handlers per selezione ditte + +bool CG4400_application::to_ditt_handler(TMask_field& f, KEY key) +{ + TMask& m = f.mask(); + if (key == K_F9) + app().to_butt_handler(m.field(BUT_DTO), K_SPACE); + if (key == K_TAB && f.focusdirty()) + { + const long l = app().select_firm_range(m.get_long(DA_CODICE), m.get_long(A_CODICE)); + app().set_choice_limits(m); + m.field(F_SELECT).set(format("%ld", l)); + } + return TRUE; +} + +bool CG4400_application::fr_ditt_handler(TMask_field& f, KEY key) +{ + TMask& m = f.mask(); + if (key == K_F9) + app().fr_butt_handler(m.field(BUT_DFR), K_SPACE); + else if (key == K_TAB && f.focusdirty()) + { + const long l = app().select_firm_range(m.get_long(DA_CODICE), m.get_long(A_CODICE)); + app().set_choice_limits(m); + m.field(F_SELECT).set(format("%ld", l)); + } + return TRUE; +} + +bool CG4400_application::to_butt_handler(TMask_field& f, KEY key) +{ + if (key == K_SPACE) + { + TArray_sheet* sh = app().get_ditte_sheet(); + TMask& m = f.mask(); + + sh->disable_check(); + if (sh->run() == K_ENTER) + { + app().select_firm_range(m.get_long(DA_CODICE),sh->row(sh->selected()).get_long(1)); + app().set_choice_limits(m); + } + } + return TRUE; +} + +bool CG4400_application::fr_butt_handler(TMask_field& f, KEY key) +{ + if (key == K_SPACE) + { + TMask& m = f.mask(); + TArray_sheet* sh = app().get_ditte_sheet(); + + sh->disable_check(); + if (sh->run() == K_ENTER) + { + app().select_firm_range(sh->row(sh->selected()).get_long(1), m.get_long(A_CODICE)); + app().set_choice_limits(m); + } + } + return TRUE; +} + +void CG4400_application::set_choice_limits(TMask& m) +{ + long first = -1l, last = -1l; + for (int i = 0; i < _ditte->items(); i++) + { + if (_selected[i]) + { + long dit = _ditte->row(i).get_long(1); + if (first == -1l) first = dit; + if (last < dit) last = dit; + } + } + if (first != -1) m.field(DA_CODICE).set(format("%ld",first)); + if (last != -1) m.field(A_CODICE).set(format("%ld",last)); + m.set(F_SELECT, _selected.ones()); + //modifica del 02/06/1995 + if (m.is_running()) + if (first != -1l) app().set_firm(first); + //fine +} + +long CG4400_application::select_firm_range(long from, long to) +{ + if (to == 0l) to = 99999L; + for (int i = 0; i < _ditte->items(); i++) + { + if (_ditte->disabled(i)) + continue; + + TToken_string& d = _ditte->row(i); + const char vers = d.get_char(3); + if (vers == '?') + continue; + + const long cod = d.get_long(1); + if (cod >= from && cod <= to) + { + _selected.set(i); + _ditte->check(i); + } + else + { + _selected.set(i,FALSE); + _ditte->uncheck(i); + } + } + return _selected.ones(); +} + +void CG4400_application::build_nomiditte(TProgind* pnd) +{ + _nomiditte.destroy(); + // ricostruire _nomiditte e rifare build_ditte_sheet + TLocalisamfile& dt = _nditte->lfile(); + + for (dt.first(); !dt.eof(); dt.next()) + { + // check no archivi + bool good = prefix().exist(dt.get_long("CODDITTA")); + if (good) + { + // check no parametri liquidazione + //TApplication::set_firm(dt.get_long("CODDITTA")); + if (!look_lia(dt.get_long("CODDITTA"))) good = FALSE; + } + _n_ditte++; + TToken_string* d = new TToken_string(64); + d->add(dt.get("CODDITTA")); + d->add(dt.get("RAGSOC")); + if (good) d->add(_tablia->get("S7")); + else d->add("??"); + + _nomiditte.add(d); + } + //if (pnd) pnd->addstatus(1); + //TApplication::set_firm(__firm); +} + +bool CG4400_application::user_create() +{ + //TProgind* pnd = NULL; + + //pnd = new TProgind (2,"Preparazione archivi\nPrego attendere", + // FALSE, TRUE, 30); + + _com = new TLocalisamfile(LF_COMUNI); + _anag = new TLocalisamfile(LF_ANAG); + _unloc = new TLocalisamfile(LF_UNLOC); + _attiv = new TLocalisamfile(LF_ATTIV); + _tab = new TLocalisamfile(LF_TAB); + _tabcom = new TLocalisamfile(LF_TABCOM); + _indlib = new TLocalisamfile(LF_INDLIB); + _tabreg = new TTable("REG"); + _tabiva = new TTable("%IVA"); + _tablbu = new TTable("%LBU"); + _tablim = new TTable("LIM"); + _tabpim = new TTable("PIM"); + _tablia = new TTable("%LIA"); + _tabpla = new TTable("%PLA"); + _tabppa = new TTable("PPA"); + _tabvid = new TTable("%VID"); + _clifo = new TLocalisamfile(LF_CLIFO); + _occas = new TLocalisamfile(LF_OCCAS); + + _desc27 = new TParagraph_string("", 27); + + _nditte = new TRelation(LF_NDITTE); + + _rel = new TRelation (LF_MOV); + _rel->add(LF_CAUSALI,"CODCAUS=CODCAUS",1,LF_MOV); + _rel->add(LF_RMOVIVA,"NUMREG=NUMREG",1,LF_MOV); + + _cur = new TCursor(_rel, "", 2); + + _ditte = new TArray_sheet(-1, -1, 0, 0, "Selezione Ditte", + "@1|Cod.@5R|Ragione Sociale@50|Vers."); + + //if (pnd) pnd->addstatus(1); + + _n_ditte = 0l; + __firm = TApplication::get_firm(); + + TDate oggi(TODAY); + _annoes = oggi.year(); + + build_nomiditte(); + build_ditte_sheet(); + + add_cursor(_cur); + add_file(LF_MOV); + add_file(LF_RMOVIVA); + + //delete pnd; + + return TRUE; +} + +bool CG4400_application::user_destroy() +{ + delete _ditte; + delete _nditte; + delete _com; + delete _unloc; + delete _anag; + delete _attiv; + delete _indlib; + delete _tab; + delete _tabcom; + delete _tabreg; + delete _tabiva; + delete _tablbu; + delete _tablim; + delete _tabpim; + delete _tablia; + delete _tabpla; + delete _tabppa; + delete _tabvid; + delete _clifo; + delete _occas; + delete _cur; + delete _rel; + delete _desc27; + + return TRUE; +} + +void CG4400_application::calcola_progressivi() +{ + TTable pim ("PIM"); + TString80 chiave; + int i, num=0; + + if (_tipo_stampa == 3) + num = _fino_a_mese; + if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) + num = _datareg.month(); + + //il discorso e' indipendente dalla frequenza! + //if (_frequiva == 'T') + // if (num%3 != 0) + // num = num - (num%3); + + //calcolo i totali del periodo + + chiave = ""; + //_codatt e' gia' Z perche' lo leggo dal registro + chiave << _annoes << _codatt; + pim.zero(); + pim.put ("CODTAB", chiave); + TRectype r (pim.curr()); + pim.read(_isgteq); + for (; !pim.eof(); pim.next()) + { + if (pim.curr() != r) break; + + TString80 codtab = pim.get("CODTAB"); + TString16 codreg = codtab.mid(10,3); + int mese = atoi(codtab.mid(13,2)); + if (_codreg == codreg.trim() && mese == num) + { + TString16 codiva = codtab.mid(16,4); + int tipodet = atoi(codtab.mid(20,1)); + real impo = pim.get_real("R0"); + real impos = pim.get_real("R1"); + real implo = pim.get_real("R2"); + //se il registro e' corrispettivi l'imponibile e l'iva li trovo in S2 + if (_corrispettivi) + { + TToken_string cs (pim.get("S2")); + impo = cs.get(0); + impos = cs.get(1); + } + //se in sospensione d'imposta l'imponibile e l'iva li trovo in R11 e R12 + if (_sosp_imposta) //in genere non sara' mai un corrispettivo + { + impo = pim.get_real("R11"); + impos = pim.get_real("R12"); + } + TToken_string fatt_rit (pim.get("S1")); //e' sempre un acquisto + real im (fatt_rit.get(0)); + real is (fatt_rit.get(1)); + impo += im; + impos += is; + implo += im+is; // potrei percio' ignorare l'importo lordo + if (impo != ZERO || impos != ZERO || implo != ZERO) + _tot_iva_array.add_riga(impo,impos,implo,ZERO,ZERO,ZERO,codiva); + if (_tipo_reg == 2) //registro acquisti + if (impo != ZERO || impos != ZERO) + _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,TRUE); + } + } + + //calcolo i totali progressivi + if (_tipo_stampa == 3) + num = _fino_a_mese; + if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) + num = _datareg.month(); + + for (i=1; i<=num; i++) + { + chiave = ""; + chiave << _annoes << _codatt; + pim.zero(); + pim.put("CODTAB", chiave); + TRectype r (pim.curr()); + pim.read(_isgteq); + for (; !pim.eof(); pim.next()) + { + if (pim.curr() != r) break; + TString80 codtab = pim.get("CODTAB"); + TString16 codreg = codtab.mid(10,3); + int mese = atoi(codtab.mid(13,2)); + if (_codreg == codreg.trim() && mese == i) + { + TString16 codiva = codtab.mid(16,4); + int tipodet = atoi(codtab.mid(20,1)); + real impo = pim.get_real("R0"); + real impos = pim.get_real("R1"); + real implo = pim.get_real("R2"); + //se il registro e' corrispettivi l'imponibile e l'iva li trovo in S2 + if (_corrispettivi) + { + TToken_string cs (pim.get("S2")); + impo = cs.get(0); + impos = cs.get(1); + } + //se in sospensione d'imposta l'imponibile e l'iva li trovo in R11 e R12 + if (_sosp_imposta) + { + impo = pim.get_real("R11"); + impos = pim.get_real("R12"); + } + TToken_string fatt_rit (pim.get("S1")); + real im (fatt_rit.get(0)); + real is (fatt_rit.get(1)); + impo += im; + impos += is; + implo += im+is; + if (impo != ZERO || impos != ZERO || implo != ZERO) + _tot_iva_array.add_riga(ZERO,ZERO,ZERO,impo,impos,implo,codiva); + if (_tipo_reg == 2) //registro acquisti + if (impo != ZERO || impos != ZERO) + _iva_array.add_riga(ZERO,ZERO,impo,impos,codiva,tipodet,0,TRUE); + } + } + } +} + +int CG4400_application::riga_rmoviva() +{ + TString codiva; + real impo, impos; + int tipodet, tipocr, tipoatt; + bool intra; + + TLocalisamfile& rmoviva = _cur->file(LF_RMOVIVA); + bool ok = _cur->is_first_match(LF_RMOVIVA); + int nrec = 0; + + TRecnotype nr = rmoviva.recno(); + + while (ok) + { + nrec++; + TRectype iva (rmoviva.curr()); + tipodet = iva.get_int (RMI_TIPODET); + tipocr = iva.get_int (RMI_TIPOCR); + impo = iva.get_real(RMI_IMPONIBILE); + impos = iva.get_real(RMI_IMPOSTA); + codiva = iva.get(RMI_CODIVA); + intra = iva.get_bool(RMI_INTRA); + tipoatt = iva.get_int("TIPOATT"); + + _riga_rmi.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,tipocr,intra,tipoatt); + + if (_tipo_stampa == 1) //stampa di prova + { + if (_tipodoc == "FS") + { + real somma = -(impo + impos); + _tot_iva_array.add_riga(ZERO,ZERO,somma,ZERO,ZERO,ZERO,codiva); + } + else if (_tipodoc == "CR" || _tipodoc == "RF" || _tipodoc == "SC") + _tot_iva_array.add_riga(ZERO,ZERO,impo+impos,ZERO,ZERO,ZERO,codiva); + if (_tipodoc != "CR" && _tipodoc != "SC" && _tipodoc != "RF") + _tot_iva_array.add_riga(impo,impos,ZERO,ZERO,ZERO,ZERO,codiva); + + if (_tipo_reg == 2) //registro acquisti (non ha senso parlare di importi lordi) + _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,TRUE); + } + + ok = _cur->next_match(LF_RMOVIVA); + } + rmoviva.readat(nr); + + return nrec; +} + +int CG4400_application::setta_riga(int r, const TRigaiva& riga, real& tot1, + real& tot2, real& tot3, real& tot4) +{ + set_row(r, "%4s", (const char*)riga._codiva); + TString descr = descr_iva(riga._codiva); + set_row(r, "@5g%-.21s",(const char*)descr); + if (riga._imponibile != ZERO) + set_row(r, "@25g%r", &riga._imponibile); + if (riga._imposta != ZERO) + set_row(r, "@41g%r", &riga._imposta); + if (_tipo_stampa != 1) + { + if (riga._imponibilep != ZERO) + set_row(r, "@81g%r", &riga._imponibilep); + if (riga._impostap != ZERO) + set_row(r++, "@98g%r", &riga._impostap); + } + else r++; + tot1 += riga._imponibile; + tot2 += riga._imposta; + tot3 += riga._imponibilep; + tot4 += riga._impostap; + + return r; +} + +messaggio CG4400_application::controlla_b0() +{ + TTable lim ("LIM"); + TString16 chiave = ""; + TString16 ditta = ""; + int i, mese; + ditta << get_firm(); + + if (_tipo_stampa == 1) //stampa di prova + mese = _data_a.month(); + else + mese = _fino_a_mese; + + if (_tipo_riepilogativo == ' ' || _tipo_riepilogativo == 'P') + { + if (_frequiva == 'T') //nella tabella LIM ho solo i mesi 3, 6, 9, 12 + { + for (i=3; i<=mese; i+=3) + { + chiave = ""; + TString16 m (format("%02d", i)); + chiave << _annoes << m; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + if (! lim.get_bool("B0")) + return no_liquidazione; + } + else return no_liquidazione; + } + } + if (_frequiva == 'M') + { + for (i=1 ; i<=mese; i++) + { + chiave = ""; + TString16 m (format("%02d", i)); + chiave << _annoes << m; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + if (! lim.get_bool("B0")) + return no_liquidazione; + } + else return no_liquidazione; + } + } + } + else if (_tipo_riepilogativo == 'A') + //if (_riep_liq) + { + chiave = ""; + chiave << _annoes << 13; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + if (! lim.get_bool("B0")) + return no_liquidazione; + } + else return no_liquidazione; + } + return B0_settato; +} + +messaggio CG4400_application::controlla_liquidazione() +{ + TTable lim ("LIM"); + TString mesi_cal = ""; + TString16 chiave = ""; + TString16 ditta = ""; + int i, mese; + bool continua; + ditta << get_firm(); + + if (_tipo_stampa == 1) //stampa di prova + mese = _data_a.month(); + else + mese = _fino_a_mese; + + if (_tipo_riepilogativo == ' ' || _tipo_riepilogativo == 'P') + { + if (_frequiva == 'T') //nella tabella LIM ho solo i mesi 3, 6, 9, 12 + { + for (i=3; i<=mese; i+=3) + { + chiave = ""; + TString16 m (format("%02d", i)); + chiave << _annoes << m; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + if (! lim.get_bool("B0")) + mesi_cal << itom(i) << "\n"; + } + else mesi_cal << itom(i) << "\n"; + } + } + if (_frequiva == 'M') + { + for (i=1 ; i<=mese; i++) + { + chiave = ""; + TString16 m (format("%02d", i)); + chiave << _annoes << m; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + if (! lim.get_bool("B0")) + mesi_cal << itom(i) << "\n"; + } + else mesi_cal << itom(i) << "\n"; + } + } + if (mesi_cal.not_empty()) + { + warning_box ("Ditta %s: la liquidazione da stampare sul registro %s relativa ai mesi di \n %s non e' stata ancora calcolata", (const char*)ditta, (const char*) _codreg, (const char *)mesi_cal); + continua = yesno_box("Si desidera ugualmente proseguire?"); + if (!continua) return non_proseguire; + continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa di liquidazione)"); + if (!continua) return prosegui_stampa; + return prosegui_cal_stampa; + } + } + else if (_tipo_riepilogativo == 'A') + //if (_riep_liq) + { + chiave = ""; + chiave << _annoes << 13; + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + if (! lim.get_bool("B0")) + { + continua = yesno_box("Ditta %s: non eseguito calcolo liquidazione annuale da stampare sul registro %s. Si desidera ugualmente proseguire?", (const char*)ditta, (const char*) _codreg); + if (!continua) return non_proseguire; + continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa di liquidazione)"); + if (!continua) return prosegui_stampa; + return prosegui_cal_stampa; + } + } + else + { + continua = yesno_box("Ditta %s: non eseguito calcolo liquidazione annuale da stampare sul registro %s. Si desidera ugualmente proseguire?", (const char*)ditta, (const char*) _codreg); + if (!continua) return non_proseguire; + continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa di liquidazione)"); + if (!continua) return prosegui_stampa; + return prosegui_cal_stampa; + } + } + return B0_settato; +} + +//controlla che i movimenti con anno data di registrazione < dell'anno indicato a video siano stati gia' stampati in forma definitiva*/ +//questo controllo viene fatto solo per stampa di bollato (non su libro unico) +bool CG4400_application::controlla_mov() +{ + TLocalisamfile mov (LF_MOV); + bool ok = TRUE; + byte tipo; + TString16 ditta = ""; + TRecnotype rec = _tabreg->recno(); + for (mov.first(); !mov.eof(); mov.next()) + { + TString16 reg = mov.get(MOV_REG); + if (reg.empty()) continue; //non e' un movimento iva + TDate datareg = mov.get_date(MOV_DATAREG); + if (_stampa_tutti_i_registri) + cerca_reg (reg, &tipo); + if ( (_stampa_tutti_i_registri && (tipo == 1 || tipo == 2)) + || (!_stampa_tutti_i_registri && reg == _codreg) ) + { + bool stampato = mov.get_bool(MOV_REGST); + if ( datareg.year() < _annoes ) + { + long numreg = mov.get_long(MOV_NUMREG); + if (!stampato) + ok = FALSE; + } + } + } + _tabreg->readat(rec); + return ok; +} + +bool CG4400_application::cerca_libro_gio(TString& datas, bool* good) +{ + TString app(4); + app = format("%04d", _annoes); + + *good = TRUE; + TRecnotype rec = _tabreg->recno(); + _tabreg->zero(); + _tabreg->put ("CODTAB", app); + TRectype r (_tabreg->curr()); + _tabreg->read(_isgteq); + for (; !_tabreg->eof(); _tabreg->next()) + { + if (_tabreg->curr() != r) break; + + int tiporeg = _tabreg->get_int("I0"); + if (tiporeg == 5) //libro giornale + { + const TDate& data = _tabreg->get_date("D3"); + if (data > _data_a) + { +// datas = format("%02/%02d/%4d", data.day(), data.month(), data.year()); + datas = data; // Meglio cosi' + *good = FALSE; + return FALSE; + } + return TRUE; + } + } + _tabreg->readat(rec); + //return TRUE; + return FALSE; +} + +void CG4400_application::cerca_reg(const TString& c, byte* t) +{ + TString16 cod = ""; + + cod << _annoes << c; + _tabreg->zero(); + _tabreg->put("CODTAB", cod); + if (_tabreg->read() == NOERR) + *t = _tabreg->get_int ("I0"); +} + +bool CG4400_application::ventilazione(const char* iva) +{ + TTable tabiva ("%IVA"); + TString16 chiave = ""; + chiave << iva; + tabiva.put("CODTAB", chiave); + if (tabiva.read()==NOERR) + { + TString16 vent = tabiva.get("S1"); + if (vent == "VE") + return TRUE; + } + return FALSE; +} + +int CG4400_application::stampa_prospetto() +{ + TString riga(_stampa_width); + int r=1, rr=0; + + reset_print(); + riga.fill('-'); + set_row(r, "%s", (const char*)riga); + r++; + set_row(r, "Legenda Tipo Operazione: 1=operazione intracomunitaria 2=AF art.34 comma 3"); + if (_auto_intraf) + set_row(r, "@78g3=operazione intracomunitaria e AF art.34 comma 3"); + r++; + + _stampa = stampa_totali_finali(); + if (_stampa) + { + set_row(++r, "Tipo documento@54gTotale documento"); + r+=2; + for (int j = 0; j < _doc_array.items(); j++) + { + TTipodoc& doc = (TTipodoc&)_doc_array[j]; + rr = r+j; + set_row(rr, "%2s", (const char*) doc._tipodoc); + set_row(rr, "@3g%s", (const char*) doc._descrdoc); + set_row(rr, "@54g%r", &doc._totdoc); + } + _doc_array.destroy(); + } + + if (rr > 0) + rr++; + else + rr = r; + + if (_stampa && _tipo_reg == 2) + { + if (_stampa_cred_pre && _mese_credito==0 && _credito > ZERO) + { + set_row (++rr, "** CREDITO INIZIO ANNO @39g%r", &_credito); + rr++; + } + } + + if (_esiste_riga_iva && _stampa) + { + if (_tipo_reg == 1 && _corrispettivi) + set_row(++rr, "@26g------------------ P E R I O D O -------------------"); + else + set_row(++rr, "@26g---------- P E R I O D O -----------"); + if (_tipo_stampa != 1) + { + if (_tipo_reg == 1 && _corrispettivi) + set_row(rr,"@84g----------- P R O G R E S S I V I --------------"); + else + set_row(rr,"@82g------ P R O G R E S S I V I ------"); + } + rr++; + set_row(rr, "Cod."); + if (_tipo_reg == 2) + { + set_row(rr, "@36gA C Q U I S T I"); + if (_tipo_stampa != 1) + set_row(rr, "@92gA C Q U I S T I"); + } + if (_tipo_reg == 1) //un registro corrispettivi puo' solo essere un registro vendite + { + set_row(rr, "@37gV E N D I T E"); + if (_corrispettivi) + set_row(rr, "@63gCORRISPETTIVI"); + if (_tipo_stampa != 1) + { + if (_corrispettivi) + set_row(rr, "@94gV E N D I T E@118gCORRISPETTIVI"); + else + set_row(rr, "@93gV E N D I T E"); + } + } + rr++; + set_row(rr, "iva Descrizione@30gImponibile@49gImposta"); + if (_tipo_reg == 1 && _corrispettivi) + set_row(rr, "@63gImporti lordi"); + if (_tipo_stampa != 1) + { + if (_tipo_reg == 1 && _corrispettivi) + set_row(rr++, "@87gImponibile@107gImposta@118gImporti Lordi"); + else + set_row(rr++, "@86gImponibile@106gImposta"); + } + else rr++; + rr++; + } + return rr; +} + +//la stampa "tipi di indetraibilita'" viene fatta solo per gli acquisti +int CG4400_application::stampa_acquisti(int row) +{ + real tot_imponib, tot_imposta, tot_imponibp, tot_impostap; + row+=2; + int tdetprec = -1; + int rw = row; + tot_imponib = tot_imposta = tot_imponibp = tot_impostap = ZERO; + + _iva_array.sort(compare_fields); + for (int s = 0; s < _iva_array.items(); s++) + { + TRigaiva& riga = (TRigaiva&)_iva_array[s]; + switch (riga._tipodet) + { + case 1: if (riga._tipodet != tdetprec) + { + set_row(rw++, "----- Indetraibile su op.es. -----"); + set_row(rw, "Cod."); + rw++; + set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); + if (_tipo_stampa != 1) + set_row(rw++, "@86gImponibile@106gImposta"); + else rw++; + rw++; + } + rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); + tdetprec = riga._tipodet; + break; + case 3: if (tdetprec == 1) + { + //set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + set_row(++rw, "TOTALE"); + if (tot_imponib != ZERO) + set_row(rw, "@25g%r", &tot_imponib); + if (tot_imposta != ZERO) + set_row(rw, "@41g%r", &tot_imposta); + + if (_tipo_stampa != 1) + { + //set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + if (tot_imponibp != ZERO) + set_row(rw, "@81g%r", &tot_imponibp); + if (tot_impostap != ZERO) + set_row(rw, "@98g%r", &tot_impostap); + } + tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; + rw+=2; + } + if (riga._tipodet != tdetprec) + { + set_row(rw++, "----- Passaggi interni -----"); + set_row(rw, "Cod."); + rw++; + set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); + if (_tipo_stampa != 1) + set_row(rw++, "@86gImponibile@106gImposta"); + else rw++; + rw++; + } + rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); + tdetprec = riga._tipodet; + break; + case 9: if ( (tdetprec == 1) || (tdetprec == 3) ) + { + //set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + set_row(++rw, "TOTALE"); + if (tot_imponib != ZERO) + set_row(rw, "@25g%r", &tot_imponib); + if (tot_imposta != ZERO) + set_row(rw, "@41g%r", &tot_imposta); + if (_tipo_stampa != 1) + { + //set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + if (tot_imponibp != ZERO) + set_row(rw, "@81g%r", &tot_imponibp); + if (tot_impostap != ZERO) + set_row(rw, "@98g%r", &tot_impostap); + } + tot_imponib = tot_imposta = tot_imponibp = tot_impostap = 0.00; + rw+=2; + } + if (riga._tipodet != tdetprec) + { + set_row(rw++, "----- N.D. 9 - acquisti indeducibili per ART.19 -----"); + set_row(rw, "Cod."); + rw++; + set_row(rw, "iva Descrizione@30gImponibile@49gImposta"); + if (_tipo_stampa != 1) + set_row(rw++, "@86gImponibile@106gImposta"); + else rw++; + rw++; + } + rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap); + tdetprec = riga._tipodet; + break; + default: break; + } + } + if (_iva_array.items() > 0) + if (tdetprec == 9) + { + //set_row(++rw, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + set_row(++rw, "TOTALE"); + if (tot_imponib != ZERO) + set_row(rw, "@25g%r", &tot_imponib); + if (tot_imposta != ZERO) + set_row(rw, "@41g%r", &tot_imposta); + if (_tipo_stampa != 1) + { + //set_row(rw, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + if (tot_imponibp != ZERO) + set_row(rw, "@81g%r", &tot_imponibp); + if (tot_impostap != ZERO) + set_row(rw, "@98g%r", &tot_impostap); + } + } + _iva_array.destroy(); + rw++; + return rw; +} + +void CG4400_application::set_page_tot_reg() +{ + int rr=0; + + rr = stampa_prospetto(); + + if (_esiste_riga_iva && _stampa) + { + real tot_imponib, tot_imposta, tot_lordo, tot_imponibp, tot_impostap, tot_lordop; + tot_imponib = tot_imposta = tot_lordo = tot_imponibp = tot_impostap = tot_lordop = ZERO; + + _tot_iva_array.sort(compare_rows); //viene ordinato per codice iva + + for (int k = 0; k < _tot_iva_array.items(); k++) + { + TRiga& riga = (TRiga&)_tot_iva_array[k]; + //row = rr+k; + set_row(rr, "%4s", (const char*)riga._codiva); + TString80 descr = descr_iva(riga._codiva); + set_row(rr, "@5g%-.21s",(const char*)descr); + if (riga._imponibile != ZERO) + set_row(rr, "@25g%r", &riga._imponibile); + if (riga._imposta != ZERO) + set_row(rr, "@41g%r", &riga._imposta); + if (_tipo_reg == 1 && _corrispettivi) + if (riga._implordo != ZERO) + set_row(rr, "@61g%r", &riga._implordo); + if (_tipo_stampa != 1) + { + if (riga._imponibilep != ZERO) + set_row(rr, "@81g%r", &riga._imponibilep); + if (riga._impostap != ZERO) + set_row(rr, "@98g%r", &riga._impostap); + if (_tipo_reg == 1 && _corrispettivi) + if (riga._implordop != ZERO) + set_row(rr, "@115g%r", &riga._implordop); + } + rr++; + tot_imponib += riga._imponibile; + tot_imposta += riga._imposta; + tot_lordo += riga._implordo; + tot_imponibp+= riga._imponibilep; + tot_impostap+= riga._impostap; + tot_lordop += riga._implordop; + } + _tot_iva_array.destroy(); + rr++; + //set_row(rr, "TOTALE@25g%r@41g%r", &tot_imponib, &tot_imposta); + set_row(rr, "TOTALE"); + if (tot_imponib != ZERO) + set_row(rr, "@25g%r", &tot_imponib); + if (tot_imposta != ZERO) + set_row(rr, "@41g%r", &tot_imposta); + if (_tipo_reg == 1 && _corrispettivi) + if (tot_lordo != ZERO) + set_row(rr, "@61g%r", &tot_lordo); + if (_tipo_stampa != 1) + { + //set_row(rr, "@81g%r@98g%r", &tot_imponibp, &tot_impostap); + if (tot_imponibp != ZERO) + set_row(rr, "@81g%r", &tot_imponibp); + if (tot_impostap != ZERO) + set_row(rr, "@98g%r", &tot_impostap); + if (_tipo_reg == 1 && _corrispettivi) + if (tot_lordop != ZERO) + set_row(rr, "@115g%r", &tot_lordop); + } + + if (_tipo_reg == 2) rr = stampa_acquisti(rr); + } + if (_tipo_reg == 2 && _tipo_stampa != 1) + stampa_plafonds(rr); +} + +void CG4400_application::stampa_plafonds(int r) +{ + TTable pla ("%PLA"); + TTable ppa ("PPA"); + TString80 chiave; + int num; + real r1, r2, r3; + + r1 = r2 = r3 = ZERO; + + if (_tipo_stampa == 3) + num = _fino_a_mese; + if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) + num = _datareg.month(); + + TString16 nm (format("%02d", num)); + + // forza il tipoatt a 1 + //char buf[10]; strcpy(buf,_codatt); + //buf[strlen(buf) - 1] = '1'; + + chiave = ""; + //chiave << _annoes << buf; + + chiave.format("%05ld", get_firm()); + chiave << _annoes; + chiave << _codatt << "1"; + pla.put("CODTAB", chiave); + + if (pla.read() == NOERR) + { + r1 = pla.get_real("R5"); //totali esp. art.8 + r2 = pla.get_real("R6"); //totali esp. art.8 bis + r3 = pla.get_real("R7"); //totali esp. art 9 + } + + if (r1 > ZERO || r2 > ZERO || r3 > ZERO) + { + set_row(++r, "QUADRO RELATIVO ALLA DISPONIBILITA' E UTILIZZAZIONE MENSILE DEI PLAFONDS"); + r++; + TString mese(9); + mese = itom(num); + mese.right_just(); + set_row(++r, "%s", (const char*) mese); + set_row(++r, ""); + r++; + } + else return; + + if (r1 > ZERO) + { + real r8 = ZERO; + r8 = stampa_valori_plafonds(r1, num, ppa, "1"); + //if (r8 > ZERO) + if (!r8.is_zero()) + { + real pri = ZERO; + real pre = ZERO; + chiave = ""; + chiave << _annoes << _codatt << "1" << nm << "1"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri = ppa.get_real("R0"); + pre = ppa.get_real("R1"); + } + chiave = ""; + chiave << _annoes << _codatt << "2" << nm << "1"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri += ppa.get_real("R0"); + pre += ppa.get_real("R1"); + } + real x = r8 - pri - pre; + set_row(r++, "ART. 8 1° comma lettere a-b Disponibile %r", &r8); + set_row(r++, "Utilizzato all'interno@44g%r", &pri); + set_row(r++, "Utilizzato per l'importazione@44g%r riporto %r", &pre, &x); + } + } + + if (r2 > ZERO) + { + real r8b = ZERO; + r8b = stampa_valori_plafonds(r2, num, ppa, "2"); + //if (r8b > ZERO) + if (!r8b.is_zero()) + { + real pri = ZERO; + real pre = ZERO; + chiave = ""; + chiave << _annoes << _codatt << "1" << nm << "2"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri = ppa.get_real("R0"); + pre = ppa.get_real("R1"); + } + chiave = ""; + chiave << _annoes << _codatt << "2" << nm << "2"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri += ppa.get_real("R0"); + pre += ppa.get_real("R1"); + } + real x = r8b - pri - pre; + r++; + set_row(r++, "ART. 8 bis 1° comma Disponibile %r", &r8b); + set_row(r++, "Utilizzato all'interno@44g%r", &pri); + set_row(r++, "Utilizzato per l'importazione@44g%r riporto %r", &pre, &x); + } + } + + if (r3 > ZERO) + { + real r9 = ZERO; + r9 = stampa_valori_plafonds(r3, num, ppa, "3"); + //if (r9 > ZERO) + if (!r9.is_zero()) + { + real pri = ZERO; + real pre = ZERO; + chiave = ""; + chiave << _annoes << _codatt << "1" << nm << "3"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri = ppa.get_real("R0"); + pre = ppa.get_real("R1"); + } + chiave = ""; + chiave << _annoes << _codatt << "2" << nm << "3"; + ppa.put("CODTAB", chiave); + if (ppa.read() == NOERR) + { + pri += ppa.get_real("R0"); + pre += ppa.get_real("R1"); + } + real x = r9 - pri - pre; + r++; + set_row(r++, "ART. 9 1° comma Disponibile %r", &r9); + set_row(r++, "Utilizzato all'interno@44g%r", &pri); + set_row(r++, "Utilizzato per l'importazione@44g%r riporto %r", &pre, &x); + } + } +} + +real CG4400_application::stampa_valori_plafonds(const real& r1, const int mese, TTable& ppa, const char* tipo) +{ + real r, si8, se8; + TString80 chiave; + int i; + + r = r1; + si8 = se8 = ZERO; + if (mese > 1) + { + for (i=1; ifirst(); + if (!_tabreg->eof()) + { + codtab = _tabreg->get("CODTAB"); + anno = atoi(codtab.mid(0,4)); + if (anno > _annoes) + { + if (_tipo_stampa != 3) //per il libro unico e' gia' stato controllato nell'handler + warning_box("Non esistono registri IVA della Ditta %ld per l'anno %d", + _ditta, _annoes); + return FALSE; + } + } + } + else // stampa un solo registro + { + _stampa_tutti_i_registri = FALSE; + codtab << _annoes << _codreg; + _tabreg->zero(); + _tabreg->put("CODTAB", codtab); + if (_tabreg->read() != NOERR) + { + if (_tipo_stampa != 3) + warning_box("Il registro IVA specificato non esiste nella \n Ditta %ld", _ditta); + return FALSE; + } + else + { + _tipo_reg = _tabreg->get_int("I0"); + if (_tipo_reg == 1 || _tipo_reg == 2) //registro iva + { + cod_lib_un = _tabreg->get("S6"); + sca_vid = _tabreg->get_date("D1"); + if (_tipo_stampa != 1) + _u_data = _tabreg->get_date ("D3"); + if ( _tipo_stampa == 2 || _tipo_stampa == 4 ) + { + if (cod_lib_un.not_empty()) + { + warning_box ("Ditta %ld: sul registro non deve essere indicato il codice del libro unico", _ditta); + return FALSE; + } + if (sca_vid.ok()) + if (sca_vid.month() < _fino_a_mese) + { + warning_box ("Ditta %ld: il mese della data scadenza vidimazione riportata sul registro non deve essere inferiore al mese indicato", _ditta); + return FALSE; + } + if (_u_data.ok()) + if (_data_a < _u_data) + { +// TString16 datas = format("%02d/%02d/%4d", _u_data.day(), _u_data.month(), _u_data.year()); +// warning_box ("Ditta %ld: la data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", _ditta, (const char*)datas); +// return FALSE; + return warning_box ("Ditta %ld: la data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", _ditta, (const char*)_u_data.string()); + } + if (_tipo_stampa == 4) //stampa con riferimenti al libro giornale + { + TString16 datas; + bool good; + bool ok = cerca_libro_gio(datas,&good); + if (!ok) + { + if (!good) + warning_box ("Ditta %ld: la data indicata non deve essere superiore al %s (ultima data di stampa del libro giornale)", _ditta, (const char*)datas); + return FALSE; + } + } + } + _pagine_stampate = _tabreg->get_long("I1"); + _numini = _pagine_stampate; + _corrispettivi = _tabreg->get_bool("B0"); + _sosp_imposta = _tabreg->get_bool("B1"); + _liquidazione = _tabreg->get_bool("B7"); + _riep_liq = _tabreg->get_bool("B6"); + _stampa_cred_pre = _tabreg->get_bool("B4"); + _stampa_ind_ditta = _tabreg->get_bool("B9"); + _stampa_ind_comp = _tabreg->get_bool("B5"); + _cod_un_loc = _tabreg->get_int ("I7"); + _mese_credito = _tabreg->get_int ("I8"); //campo nascosto sulla tabella dei registri: mese di stampa credito anno precedente + _mese_ultima_liq = _tabreg->get_int ("I4"); + _codatt = _tabreg->get("S8"); + _tipoatt = tipo_attivita(); + _attivita = desc_attivita(); + _desc_lib = _tabreg->get ("S0"); + } + else return FALSE; + } + } + return TRUE; +} + +bool CG4400_application::compila_lib() +{ + TTable tab_lib ("%LBU"); + TString16 cod; + + cod << _annoes << _codlib; + tab_lib.zero(); + tab_lib.put("CODTAB", cod); + + if (tab_lib.read() == NOERR) + { + _stampa_ind_ditta = tab_lib.get_bool("B1"); + return TRUE; + } + return FALSE; +} + +bool CG4400_application::preprocess_print(int file, int counter) +{ + if (file == LF_MOV) + { + long items = _cur->items(); + if (!items) + return FALSE; + _iva_array.destroy(); + _riga_rmi.destroy(); + _tot_iva_array.destroy(); + _doc_array.destroy(); + _dataregp = ""; + _esiste_riga_iva = FALSE; + _auto_intraf = FALSE; + _intesta_liq = FALSE; + set_print_zero(); + } + return TRUE; +} + +bool CG4400_application::preprocess_page(int file, int counter) +{ + if (file == LF_MOV) + { + if (counter) return TRUE; + + reset_print(); + int rr = 0, riga = 0; + bool intra; + TString80 comune, prov, comcf, capcf, civcf; + TString80 viacf; + TString ragsoc; + TString tipo_op = ""; + + TLocalisamfile& mov = _cur->file(LF_MOV); + TLocalisamfile& caus = _cur->file(LF_CAUSALI); + + _datareg = mov.get_date(MOV_DATAREG); + + if (_tipo_stampa != 3 && _liquidazione) + { + int da; + if (_tipo_stampa == 1) + da = _data_da.month(); + else da = 1; + int a = _datareg.month(); + for (int m = da; m < a; m++) + { + if (!_st_liq[m]) + if (stampo_liquidazione(m)) + { +// _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header (intestazione per la stampa liquidazione) + _datareg = TDate(1, m, _annoes); // Meglio cosi' + TFilename t; + t.temp("reg"); + if (_scelta == B0_settato || _scelta == prosegui_stampa) + { + if (_tipo_stampa == 1) + send_message('S',t, m); + else send_message('s',t, m); + } + else //_scelta == prosegui_cal_stampa + { + if (_tipo_stampa == 1) + send_message('L', t, m); + else send_message('l', t, m); + } + //TString80 nomef; nomef = t.path(); nomef << "\\" << t.name(); + //if (fexist(nomef)) + if (fexist(t)) + { + _intesta_liq = TRUE; + //printer().footerlen(0); + merge_export_file(t,FALSE,TRUE); + printer().formfeed(); + _intesta_liq = FALSE; + reset_print(); + remove(t); + } + } + _st_liq[m] = TRUE; + } + } + + _datareg = mov.get_date(MOV_DATAREG); + _mov_empty = FALSE; + + if ( _datareg.month() != _dataregp.month() && _dataregp.ok() ) + { + _auto_intraf = FALSE; + printer().formfeed(); + //printer().footerlen(5); //devo rimetterlo cosi' + } + + _dataregp = _datareg; + + TDate datadoc = mov.get_date(MOV_DATADOC); + long numreg = mov.get_long(MOV_NUMREG); + long protiva = mov.get_long(MOV_PROTIVA); + long uprotiva = mov.get_long(MOV_UPROTIVA); + real totdoc = mov.get_real(MOV_TOTDOC); + TString16 numdoc = mov.get(MOV_NUMDOC); + char tipocf = mov.get(MOV_TIPO)[0]; + TString16 ocfpi = mov.get(MOV_OCFPI); + long codcf = mov.get_long(MOV_CODCF); + long numgio = mov.get_long(MOV_NUMGIO); + bool stampato = mov.get_bool(MOV_REGST); + TString16 codval = mov.get(MOV_CODVALI); + real corrval = mov.get_real(MOV_CORRVALUTA); + //bool intra = caus.get_bool(CAU_INTRACOM); //da prendere sul movimento + bool autof = caus.get_bool(CAU_AUTOFATT); + TString80 descrcau = caus.get(CAU_DESCR); + + if (_cur->pos() == 0) + _uprotivap = uprotiva ? uprotiva : protiva; + + //aggiornamento di mov + if (_tipo_stampa != 1) + if (!stampato) + { + mov.put(MOV_REGST,TRUE); + mov.rewrite(); + } + + if (codcf == 0l) + ragsoc = descrcau; + else + { + if (ocfpi.trim().empty()) + { + TRectype dep = ricerca_cf(tipocf, codcf); + ragsoc = dep.get (CLI_RAGSOC); + viacf = dep.get (CLI_INDCF); + civcf = dep.get (CLI_CIVCF); + capcf = dep.get (CLI_CAPCF); + comcf = dep.get (CLI_COMCF); + char tipoa = dep.get_char(CLI_TIPOAPER); + if (tipoa == 'F') + { + TString80 cognome, nome; + cognome = ragsoc.mid(0,30); + nome = ragsoc.mid(30,20); + cognome.trim(); nome.trim(); + ragsoc = cognome; + ragsoc << " " << nome; + } + } + else + { + TRectype dep = ricerca_occ(ocfpi); + ragsoc = dep.get (OCC_RAGSOC); + viacf = dep.get (OCC_INDIR); + civcf = dep.get (OCC_CIV); + capcf = dep.get (OCC_CAP); + comcf = dep.get (OCC_COM); + } + TRectype com = look_comuni(comcf); + comune = com.get(COM_DENCOM); + prov = com.get(COM_PROVCOM); + } + + _tipodoc = mov.get(MOV_TIPODOC); + _descr_doc = descr_doc(); + TString app(datadoc.string(brief, '/')); + + if (stampa_totali_finali()) + _doc_array.add_riga(_tipodoc,_descr_doc,totdoc); + + //setto le righe di stampa + _r = 1; + if (!_stampa_data_reg) + set_row(_r, "%s", (const char* ) _datareg.string(brief, '/')); + set_row(_r, "@9g%5ld", protiva); + if (datadoc.ok()) + set_row(_r, "@15g%s", (const char*) app); + set_row(_r, "@24g%s", (const char*) numdoc); + if (codcf != 0l) + set_row(_r, "@31g%6ld", codcf); + *_desc27 = (const char*) ragsoc; + //set_row(_r, "@38g#a", _desc25); + set_row(_r, "@68g%2s", (const char*) _tipodoc); + if (_stampa_width == 132) + set_row(_r, "@70g%r", &totdoc); + else set_row(_r, "@78g%r", &totdoc); + + if (_tipo_stampa == 1) //in caso di stampa di prova + if (! (_tipo_reg == 1 && _corrispettivi)) //e se non si tratta di registro vendite corrispettivi + if (! (_cur->pos()==0)) //il primo movimento non va controllato + { + if (protiva != _uprotivap + 1) + { + set_row(_r+1, "@2g*** NUM.PROT.FUORI SEQUENZA"); + riga = _r+2; + } + _uprotivap = uprotiva ? uprotiva : protiva; + } + + const char* r; + int i = 1; + while ((r = _desc27->get()) != NULL) + { + set_row (i, "@38g%s", r); + i++; + } + if (i > riga) riga = i; + + if (codcf != 0l && _stampa_ind_comp) + { + //set_row(_r, "@38g%-.27s", (const char*)ragsoc); + if (viacf.not_empty()) //se la via non e' vuota non puo' essere vuoto il comune + { + set_row (/*_r+1*/ i++, "@38g%-.23s %-3s",(const char *)viacf, (const char *)civcf); + set_row (/*_r+2*/ i++, "@38g%s %-.21s", (const char *)capcf, (const char *)comune); + riga = /*_r+3*/ i; + } + else if (comune.not_empty()) + { + set_row (/*_r+1*/ i++, "@38g%s %-.21s", (const char *)capcf, (const char *)comune); + riga = /*_r+2*/ i; + } + } + + _nrec = riga_rmoviva(); + if (_nrec > 0) + { + _esiste_riga_iva = TRUE; + for (int j = 0; j < _riga_rmi.items(); j++) + { + TRigaiva& riga = (TRigaiva&)_riga_rmi[j]; + rr = _r+j; + intra = riga._intra; + if (_stampa_width == 132) + { + set_row(rr, "@85g%r", &riga._imponibile); + set_row(rr, "@101g%4s",(const char*)riga._codiva); + if (_tipo_reg == 2) + set_row(rr, "@106g%d", riga._tipodet); + set_row(rr, "@107g%r", &riga._imposta); + set_row(rr, "@123g%d", riga._tipocr); + if (_tipoatt == "E" && _tipo_reg != 2) + set_row(rr, "@125g%d", riga._tipoatt); + if (_tipo_stampa == 4) //stampa con riferimento al libro giornale + set_row(rr, "@126g%5ld", numgio); + } + else //stampa a 198 + { + set_row(rr, "@93g%r", &riga._imponibile); + set_row(rr, "@109g%4s",(const char*)riga._codiva); + if (_tipo_reg == 2) + set_row(rr, "@114g%d", riga._tipodet); + set_row(rr, "@116g%r", &riga._imposta); + if (_tipoatt == "E" && _tipo_reg != 2) + set_row(rr, "@132g%d", riga._tipoatt); + set_row(rr, "@134g%d", riga._tipocr); + if (_tipo_stampa == 4) //stampa con riferimento al libro giornale + set_row(rr, "@136g%7ld", numgio); + } + } + _riga_rmi.destroy(); + } + + if ( intra && autof) + { + _auto_intraf = TRUE; + tipo_op = "3"; + } + else if (intra) + tipo_op = "1"; + else if (autof) + tipo_op = "2"; + + set_row(_r, "@66g%s", (const char*) tipo_op); + + if (_tipo_stampa == 1) //stampa di prova + { + if (_stampa_width == 132) + { + set_row(_r, "@126g%5ld", numreg); + if (stampato) + set_row(_r, "@131g*"); //solo in stampa di prova! + } + else //198 + { + set_row(_r, "@136g%7ld", numreg); + if (stampato) + set_row(_r, "@144g*"); + } + } + if (_tipo_stampa == 4 && _stampa_width == 198) + { + TLocalisamfile rmoviva (LF_RMOVIVA); + rmoviva.zero(); + rmoviva.put(RMI_NUMREG,numreg); + TRectype rec(rmoviva.curr()); + rmoviva.read(_isgteq); + for ( ; !rmoviva.eof(); rmoviva.next()) + { + if (rmoviva.curr() != rec) break; + + int gruppo = rmoviva.get_int("GRUPPO"); + int conto = rmoviva.get_int("CONTO"); + long sottoc = rmoviva.get_long("SOTTOCONTO"); + TConto tc (gruppo,conto,sottoc); + TString80 descr = tc.descrizione(); + set_row(_r, "@144g%3d %3d %6d", gruppo, conto, sottoc); + set_row(_r, "@159g%-.39s", (const char*) descr); + break; + } + } + + if (riga <= rr) riga = ++rr; + + if (corrval != ZERO) + { + TString vall (corrval.string("###.###.###.###,@@")); + set_row(riga, "@24gCodice valuta %-3s Corrispettivo in valuta %s", (const char*) codval, (const char*) vall); + } + } + return TRUE; +} + +void CG4400_application::scrivi_reg() +{ + TString16 codtab; + TTable Tabreg ("REG"); + + codtab << _annoes << _codreg; + Tabreg.zero(); + Tabreg.put("CODTAB", codtab); + if (Tabreg.read() == NOERR) + { + const TDate d = Tabreg.get_date("D3"); + if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina + { +// TDate ultima_data = format("%02d/%02d/%4d", _datareg.last_day(_datareg.month(), _annoes), _datareg.month(), _annoes); + TDate ultima_data(_datareg); + ultima_data.set_end_month(); // Meglio cosi' + + if (ultima_data > d) + Tabreg.put("D3", ultima_data); + } + else if (_data_a > d) + Tabreg.put("D3", _data_a); + + if (_tipo_reg == 2 && _stampa_cred_pre) + if (_mese_credito == 0 && _credito > ZERO) + if (_mov_empty) + Tabreg.put("I8", (long)_fino_a_mese); + else Tabreg.put("I8", (long)_datareg.month()); + + Tabreg.rewrite(); + } + + if (_tipo_stampa == 3) + { + TString16 cod = ""; + TTable lbu ("%LBU"); + + cod << _annoes << _codlib; + lbu.zero(); + lbu.put("CODTAB", cod); + if (lbu.read() == NOERR) + { + lbu.put("I0", (long) _fino_a_mese); + lbu.rewrite(); + } + } +} + +void CG4400_application::aggiorna_reg(const bool aggiorna_vidi) +{ + TString16 codtab; + TTable Tabreg ("REG"); + TLocalisamfile IndBil (LF_INDLIB); + + codtab << _annoes << _codreg; + Tabreg.zero(); + Tabreg.put("CODTAB", codtab); + if (Tabreg.read() == NOERR) + { + TDate d = Tabreg.get_date("D3"); + if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina + { +// TDate ultima_data = format("%02d/%02d/%4d", _datareg.last_day(_datareg.month(), _annoes), _datareg.month(), _annoes); + TDate ultima_data(_datareg); + ultima_data.set_end_month(); // Meglio cosi' + + if (ultima_data > d) + Tabreg.put("D3", ultima_data); + } + else if (_data_a > d) + Tabreg.put("D3", _data_a); + + Tabreg.put("I1", _pagine_stampate); + + if (_intesta_liq) + if (_tipo_riepilogativo == 'A') + Tabreg.put("I4", 13L); + else Tabreg.put("I4", (long)_datareg.month()); + + if (_tipo_reg == 2 && _stampa_cred_pre) + if (_mese_credito == 0 && _credito > ZERO) + if (_mov_empty) + Tabreg.put("I8", (long)_fino_a_mese); + else Tabreg.put("I8", (long)_datareg.month()); + + Tabreg.rewrite(); + } + + if (_tipo_stampa == 3) //stampa su libro unico + + // sul file indlib (indice libro unico) devo generare una riga per ogni + // registro stampato (ricordarsi che la stampa su libro unico deve + // avvenire mese per mese!) + // inoltre non posso stampare due volte lo stesso mese perche' la stampa + // avviene a fine mese + + { + long numero_riga = 1L; + if (!aggiorna_vidi) + { + bool trovato = FALSE; + //long ditta = get_firm(); + + IndBil.zero(); + + TRectype nuovo (IndBil.curr()); + + IndBil.put("ANNO", _annoes); + IndBil.put("CODLIB", _codlib); + TRectype rec (IndBil.curr()); + + for (IndBil.read(_isgteq); !IndBil.eof(); IndBil.next()) + { + if (IndBil.curr() != rec) break; + + int annoreg = IndBil.get_int("ANNOREG"); + int mesereg = IndBil.get_int("MESEREG"); + long cditta = IndBil.get_long("CODDITTA"); + TString16 codreg = IndBil.get("CODREG"); + TString16 codvid = IndBil.get("CODVID"); + if (_annoes == annoreg && _fino_a_mese == mesereg + && _ditta == cditta && codreg == _codreg && _codice_vidi == codvid) + { + trovato = TRUE; + numero_riga = IndBil.get_long("NUMREG"); + break; + } + else numero_riga = IndBil.get_long("NUMREG") + 1; + // cosi' mi posiziono su quel mese (altrimenti rischio di generare + // due righe per lo stesso mese e registro => la stampa di vidimazione + // mi sballa tutta!!! + } + nuovo.put("ANNO", _annoes); + nuovo.put("CODLIB", _codlib); + nuovo.put("NUMREG", numero_riga); + + nuovo.put("ANNOREG", _annoes); + nuovo.put("MESEREG", _fino_a_mese); // su libro unico ho un solo mese in gioco! + nuovo.put("PAGINI", _primast + 1); // numero iniziale pagina libro unico + nuovo.put("PAGFIN", _u_stampata); // numero finale pagina libro unico + nuovo.put("CODDITTA", _ditta); + nuovo.put("CODREG", _codreg); + nuovo.put("CODVID", _codice_vidi); + nuovo.put("PAGINIUT", _numini + 1); + nuovo.put("PAGFINUT", _pagine_stampate); + + if (!trovato) + IndBil.write(nuovo); + else IndBil.rewrite(nuovo); + } + //_primast = _u_stampata; //per la numerazione dei registri successivi + aggiorna_lib(); + } +} + +void CG4400_application::aggiorna_lib() +{ + TString16 cod = ""; + TTable lbu ("%LBU"); + + cod << _annoes << _codlib; + lbu.zero(); + lbu.put("CODTAB", cod); + if (lbu.read() == NOERR) + { + lbu.put("I0", (long) _fino_a_mese); + lbu.put("I1", (long) _u_stampata); + lbu.rewrite(); + } +} + +bool CG4400_application::stampo_liquidazione(int mese) +{ + //test tradotti alla lettera da AS/400 + //assolutamente incongruenti !!! + if (_tipo_stampa == 1) + { + if ( (_frequiva == 'T' && (mese == 3 || mese == 6 || mese == 9 || mese == 12)) + || _frequiva != 'T' || (mese == 12 && _tipo_riepilogativo == 'A') ) + return TRUE; + } + else + { + if ( (_frequiva == 'T' && (mese == 3 || mese == 6 || mese == 9 || mese == 12)) + || _frequiva != 'T' || (mese == 12 && _tipo_riepilogativo == 'A') ) + if ( (mese == 12 && _tipo_riepilogativo == 'A' && _mese_ultima_liq != 13) + || (mese != 12 && mese > _mese_ultima_liq) + || (mese == 12 && _tipo_riepilogativo != 'A' && mese > _mese_ultima_liq) ) + return TRUE; + } + return FALSE; +} + +void CG4400_application::stampa_vidi() +{ + TLocalisamfile IndBil (LF_INDLIB); + TTable TabVid ("%VID"); + TString16 codreg; + TString16 vid; + long ditta, pagfin, pagfinut; + int mese; + TPrintrow row; + + _ok_vidi = FALSE; + + if (!printer().isopen()) + printer().open(); + + IndBil.zero(); + IndBil.put("ANNO", _annoes); + IndBil.put("CODLIB", _codlib); + TRectype rec (IndBil.curr()); + IndBil.read (_isgteq); + for (; !IndBil.eof(); IndBil.next()) + { + if (IndBil.curr() != rec) break; + ditta = IndBil.get_long("CODDITTA"); + codreg = IndBil.get("CODREG"); + if (ditta == _ditta && codreg == _codreg) + { + if (!_ok_vidi) + { + ++_u_stampata; + ++_pagine_stampate; + _ok_vidi = TRUE; + } + mese = IndBil.get_int("MESEREG"); + pagfin = IndBil.get_long("PAGFIN"); + pagfinut = IndBil.get_long("PAGFINUT"); + if (mese == 12) + { + ++pagfin; + ++pagfinut; + TRectype nuovo (IndBil.curr()); + nuovo.put("PAGFIN", pagfin); + nuovo.put("PAGFINUT", pagfinut); + IndBil.rewrite(nuovo); + } + row.reset(); + row.put(format("%s", itom(mese)), 0); + row.put(format("%5ld", IndBil.get_long("PAGINI")), 10); + row.put(format("%5ld", pagfin), 17); + row.put(format("%5ld", IndBil.get_long("PAGINIUT")), 25); + row.put(format("%5ld", pagfinut), 32); + vid = IndBil.get("CODVID"); + TabVid.zero(); + TabVid.put("CODTAB", vid); + if (TabVid.read() == NOERR) + { + row.put(format("%s", (const char*)TabVid.get("S0")), 39); + row.put(format("%7d",TabVid.get_long("I0")), 71); + row.put(format("%7d",TabVid.get_long("I1")), 79); + row.put(format("%7d",TabVid.get_long("I2")), 87); + TDate d(TabVid.get_long("D0")); + row.put(format("%s", (const char*)d.string()), 95); + row.put(format("%s", (const char*)TabVid.get("S1")), 106); + } + printer().print(row); + } + } + printer().close(); +} + +void CG4400_application::liq_b0_settato() +{ + TFilename f; + f.temp("rg"); + if (_tipo_stampa == 1) + send_message('S',f, _datareg.month()); + else send_message('s',f, _datareg.month()); + //TString80 nomef; + //nomef = f.path(); nomef << "\\" << f.name(); + //if (fexist(nomef)) + if (fexist(f)) + { + printer().formfeed(); + _intesta_liq = TRUE; + //printer().footerlen(0); + merge_export_file(f,FALSE,TRUE); + _intesta_liq = FALSE; + remove(f); + } +} + +void CG4400_application::liq_other_case() +{ + if (_scelta == prosegui_cal_stampa) + { + if (stampo_liquidazione(_datareg.month())) + { + _t.temp("reg"); + if (_tipo_stampa == 1) + send_message('L', _t, _datareg.month()); + else send_message('l', _t, _datareg.month()); + } + else //se chiamo la liquidazione con L o l mi calcola anche i progressivi + if (_tipo_stampa != 1) + { + TFilename app; + app.temp(); + send_message('C', app, _datareg.month()); + } + } + if (_scelta == prosegui_stampa) + { + if (stampo_liquidazione(_datareg.month())) + { + _t.temp("reg"); + if (_tipo_stampa == 1) + send_message('S', _t, _datareg.month()); + else send_message('s', _t, _datareg.month()); + } + if (_tipo_stampa != 1) //in stampa di prova i progressivi me li calcolo io!!! + { //Why??? + TFilename app; + app.temp(); + send_message('C', app, _datareg.month()); + } + } + if (_scelta == no_liquidazione && _tipo_stampa != 1) + { + TFilename app; + app.temp(); + send_message('C', app, _datareg.month()); + } +} + +print_action CG4400_application::postprocess_page (int file, int counter) +{ + if (file == LF_MOV) + { + if (counter) //dopo aver fatto un REPEAT_PAGE (cioe' dopo aver stampato le righe settate in set_page_tot_reg()), in pratica a rottura di mese o alla fine + { + reset_print(); + if (_liquidazione) + if (!_st_liq[_datareg.month()] && stampo_liquidazione(_datareg.month())) + { + _st_liq[_datareg.month()] = TRUE; + if (_scelta == B0_settato) + liq_b0_settato(); + if (_scelta == prosegui_stampa || _scelta == prosegui_cal_stampa) + { + if (fexist(_t)) + { + printer().formfeed(); + _intesta_liq = TRUE; + //printer().footerlen(0); + merge_export_file(_t,FALSE,TRUE); + _intesta_liq = FALSE; + remove(_t); + } + } + } + } + if (!counter) + { + bool FINITO = FALSE; + TRecnotype pos = _cur->pos(); + long items = _cur->items(); + + FINITO = (pos == items-1); + + if ( FINITO ) + { + liq_other_case(); + if (_tipo_stampa != 1) + calcola_progressivi(); + set_page_tot_reg(); + return REPEAT_PAGE; + } + else + { + TLocalisamfile& mov = _cur->file(LF_MOV); + _cur->save_status(); + ++(*_cur); + _dataregs = mov.get_date(MOV_DATAREG); + --(*_cur); + _cur->restore_status(); + + if (_dataregs.month() != _dataregp.month()) + { + liq_other_case(); + if (_tipo_stampa != 1) + calcola_progressivi(); + set_page_tot_reg(); + return REPEAT_PAGE; + } + } + } + } + return NEXT_PAGE; +} + +bool CG4400_application::set_print(int n) +{ + TMask m ("cg4400a"); + int giorni_del_mese; + bool ok; + + m.set_handler (TIPO_STAMPA, mask_tipo_stampa); + m.set_handler (DA_DATA, mask_data); + m.set_handler (A_DATA, mask_data); + m.set_handler (MESE, mask_mese); + m.set_handler (FINO_A_MESE, mask_mese); + m.set_handler (CODICE_LIB_UN, mask_cod); + m.set_handler (CODICE_LIBRO_IVA, mask_libun); + m.set_handler (DLG_SELECT, mask_select); + m.set_handler (F_ANNULLA, mask_azzera); + m.set_handler (A_CODICE, to_ditt_handler); + m.set_handler (DA_CODICE, fr_ditt_handler); + m.set_handler (BUT_DTO, to_butt_handler); + m.set_handler (BUT_DFR, fr_butt_handler); + m.set_handler (ANNO, year_handler); + + m.field(F_SELECT).set(format("%ld",_selected.ones())); + set_choice_limits(m); + + //printer().footerlen(5); + set_real_picture("###.###.###.###"); + + while (ok = set_ditte(m)) + { + if (_selected.ones() > 0l) + { + _annoes = m.get_int(ANNO);//in realta' e' l'anno IVA !!! + _tipo_stampa = m.get_int(TIPO_STAMPA); + _stampa_width = m.get_int(STAMPA_WIDTH); + _stampa_len = m.get_int(STAMPA_LEN); + if (_stampa_width == 1) + _stampa_width = 132; + else _stampa_width = 198; + if (_stampa_len != 0) + printer().formlen(_stampa_len); + //Se stampa di prova l'utente indica data_da e data_a + if (_tipo_stampa == 1) + { + _data_stampa = m.get(DATA_STAMPA); + _data_da = m.get(DA_DATA); + _data_a = m.get(A_DATA); + + if (!_data_da.ok()) +// _data_da = format("01/01/%4d", _annoes); + _data_da = TDate(1, 1, _annoes); // Meglio cosi' + + if (!_data_a.ok()) +// _data_a = format("31/12/%4d", _annoes); + _data_a = TDate(31, 12, _annoes); // Meglio cosi' + + const TDate d(31,12,_annoes); + if (_data_a == d) + _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0]; + else _tipo_riepilogativo = ' '; + printer().setdate(_data_stampa); + } + else //stampe definitive + { + if ( (_tipo_stampa == 2) || (_tipo_stampa == 4) ) + { + _fino_a_mese = m.get_int(FINO_A_MESE); +// _data_da = format("01/01/%4d", _annoes); //e non ultima data di stampa del registro (come invece verrebbe spontaneo di pensare) + _data_da = TDate(1, 1, _annoes); // Meglio cosi' + } + else //stampa su libro unico + { + _codlib = m.get(CODICE_LIB_UN); + _fino_a_mese = m.get_int(MESE); + _u_stampata = m.get_int(ULTIMA_PAGINA); + _rif_vid = m.get_bool(RIF_VID); + _primast = _u_stampata; +// _data_da = format("01/%02d/%04d", _fino_a_mese, _annoes); + _data_da = TDate(1, _fino_a_mese, _annoes); // Meglio cosi' + } + if (_fino_a_mese == 12) + { + giorni_del_mese = 31; + _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0]; + } + else + { + _tipo_riepilogativo = ' '; +// TDate primo = format("01/%02d/%4d", _fino_a_mese+1, _annoes); +// --primo; + TDate primo(1, _fino_a_mese, _annoes); + primo.set_end_month(); // Meglio cosi' + + giorni_del_mese = primo.day(); + } +// _data_a=format("%02d/%02d/%4d",giorni_del_mese,_fino_a_mese,_annoes); + _data_a = TDate(giorni_del_mese, _fino_a_mese, _annoes); // Meglio cosi' + } + _stampa_data_reg = stampa_datareg(); + if (_tipo_stampa == 3) + compila_lib(); + stampa_registri_IVA(m); + } + else + { + warning_box("Nessuna ditta selezionata!"); + continue; + } + } + return FALSE; +} + +bool CG4400_application::look_lia(long ditta) +{ + if (ditta == 0l) ditta = get_firm(); + + TString16 y; y.format("%05ld%04d", ditta, _annoes); + + _tablia->zero(); + _tablia->put("CODTAB", y); + _tablia->read(); + const bool ok = _tablia->good(); + if (ok) + _credito = _tablia->get_real("R0"); + else _credito = ZERO; + return ok; +} + +void CG4400_application::look_reg() +{ + _liquidazione = _tabreg->get_bool("B7"); + _riep_liq = _tabreg->get_bool("B6"); + _corrispettivi = _tabreg->get_bool("B0"); + _sosp_imposta = _tabreg->get_bool("B1"); + _pagine_stampate = _tabreg->get_long("I1"); + _numini = _pagine_stampate; + _cod_un_loc = _tabreg->get_int("I7"); + _mese_ultima_liq = _tabreg->get_int("I4"); + _mese_credito = _tabreg->get_int("I8"); + _codatt = _tabreg->get("S8"); + _tipoatt = tipo_attivita(); + _attivita = desc_attivita(); + _desc_lib = _tabreg->get ("S0"); + _stampa_ind_ditta = _tabreg->get_bool ("B9"); + _stampa_ind_comp = _tabreg->get_bool ("B5"); + _stampa_cred_pre = _tabreg->get_bool ("B4"); +} + +void CG4400_application::clear_stliq() +{ + for (int i=0; i <= 12; i++) + _st_liq[i] = FALSE; +} + +bool CG4400_application::setta_mask(long i) +{ + if (_stampa_mese == 13) _stampa_mese = 0; + if (_tipo_stampa == 2 || _tipo_stampa == 4) + { + TMask mb("cg4400b"); + mb.set(F_CODDITTA, _ditta); + mb.set(F_RAGSOC, _ditte->row(i).get(2)); + mb.set(COD_LIB, _codreg); + const char* m = ""; + m = format("%02d", _stampa_mese); + mb.set(U_MESE, m); + mb.set(U_PAGINA, _pagine_stampate); + if (_u_data.ok()) + mb.set(U_DATA, _u_data.string()); + KEY tasto = mb.run(); + if (tasto != K_ENTER) return FALSE; + } + return TRUE; +} + +void CG4400_application::no_movimenti() +{ + _mov_empty = TRUE; + if (_liquidazione) + { + int da, a; + //stampo la liquidazione per tutti i mesi fino a _fino_a_mese + if (_tipo_stampa == 2 || _tipo_stampa == 4) + da = 1; + if (_tipo_stampa == 3) + da = _fino_a_mese; + if (_tipo_stampa == 1) + da = _data_da.month(); + if (_tipo_stampa == 1) + a = _data_a.month(); + else a = _fino_a_mese; + for (int m = da; m <= a; m++) + { + if (stampo_liquidazione(m)) + { + if (! printer().isopen()) + printer().open(); + TFilename f; + f.temp("rgp"); +// _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header + _datareg = TDate(1, m, _annoes); // Meglio cosi' + + if (_scelta == B0_settato || _scelta == prosegui_stampa) + { + if (_tipo_stampa == 1) + send_message('S',f, m); + else send_message('s',f, m); + } + else //_scelta == prosegui_cal_stampa + { + if (_tipo_stampa == 1) + send_message('L', f, m); + else send_message('l', f, m); + } + if (fexist(f)) + { + _intesta_liq = TRUE; + //printer().footerlen(0); + merge_export_file(f,FALSE,TRUE); + printer().formfeed(); + _intesta_liq = FALSE; + remove(f); + } + } + } + if (printer().isopen()) printer().close(); + } + if (_tipo_stampa != 1) scrivi_reg(); //aggiorno il registro anche se non ho stampato proprio nulla per quel mese! +} + +bool CG4400_application::stampa_registri_IVA(const TMask& m) +{ + bool ok = FALSE; + for (int i = 0; i < _ditte->items(); i++) + { + if (_selected[(long)i]) + { + bool msg = TRUE; + _ditta = _ditte->row(i).get_long(1); + _frequiva = _ditte->row(i).get_char(3); + _intesta_liq = FALSE; + _intesta_vidi = FALSE; + _primast = _u_stampata; + _ok_vidi = FALSE; + _stampa_mese = 13; + + TApplication::set_firm(_ditta); + look_lia(); + ok = compila_reg(m); + if (!ok) continue; + if (_tipo_stampa == 2 || _tipo_stampa == 4) + if (!controlla_mov()) + { + TApplication::set_firm(__firm); + return fatal_box("Finire di stampare registri anno precedente"); + } + if (!_stampa_tutti_i_registri) + { + _scelta = controlla_b0(); + _cur->set_filterfunction(filter_func); + ok = setta_mask(i); + if (!ok) continue; + if (_liquidazione) + { + if (_tipo_stampa == 2 || _tipo_stampa == 4) + _size_header = _stampa_ind_ditta ? 3 : 2; + else _size_header = 3; + clear_stliq(); + _scelta = controlla_liquidazione(); + if (_scelta == non_proseguire) + return FALSE; + } + + (*_cur) = 0L; //la filter function viene chiamata quando posiziono il cursore + const long item = _cur->items(); + + // 17.5.95 Leggo parametri di stampa del registro + TString16 config; + const long codditta = get_firm(); + const char* reg = (const char*)_codreg; + config.format("REG%05ld%03s", codditta, reg); + printer().read_configuration(config); + + if (item > 0l) + { + print(); + + if (is_cancelled()) return FALSE; + + if (_tipo_stampa != 3 && _liquidazione) + stampa_liq_mesi_succ(); + } + //non ci sono movimenti da stampare nel periodo richiesto! + else no_movimenti(); + + if (_tipo_stampa == 3 && _rif_vid) + { + _intesta_vidi = TRUE; + stampa_vidi(); //stampa riferimenti vidimazione + } + } + else //stampa tutti i registri + { + TString16 codtab, cod_lib_un; + int anno; + TDate sca_vid; + for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) + { + _tipo_reg = _tabreg->get_int("I0"); + codtab = _tabreg->get("CODTAB"); + anno = atoi(codtab.mid(0,4)); + if (anno > _annoes) + break; + if (anno == _annoes) + if ( _tipo_reg == 1 || _tipo_reg == 2 ) //registro iva + { + _codreg = codtab.mid(4,3); + cod_lib_un = _tabreg->get("S6"); + sca_vid = _tabreg->get_date("D1"); + _stampa_ind_ditta = _tabreg->get_bool("B9"); + _liquidazione = _tabreg->get_bool("B7"); + if (_tipo_stampa != 1) + _u_data = _tabreg->get_date("D3"); + if (_tipo_stampa == 2 || _tipo_stampa == 4) + { + if (cod_lib_un.not_empty()) + continue; + if (sca_vid.ok()) + if (sca_vid.month() < _fino_a_mese) + continue; + if (_u_data.ok()) + if (_data_a < _u_data) + { + message_box("Ditta %ld: Il registro %s e' gia' stato stampato come bollato di %s", _ditta, (const char*) _codreg, itom(_fino_a_mese)); + continue; + } + } + if (_tipo_stampa == 4) //stampa con riferimenti al libro giornale + { + TString16 d; + bool good; + TRecnotype rec = _tabreg->recno(); + bool trovato = cerca_libro_gio(d, &good); + _tabreg->readat(rec); + if (!trovato) + continue; + } + if (_tipo_stampa == 3) //stampa su libro unico + { + if (cod_lib_un != _codlib) + continue; + if (sca_vid.ok()) + if (sca_vid.month() < _fino_a_mese) + continue; + if (_u_data.ok()) + if (_fino_a_mese < _u_data.month()) //significa che e' gia' + continue; //stato stampato + } + msg = FALSE; + + look_reg(); + + _intesta_liq = FALSE; + _intesta_vidi = FALSE; + _primast = _u_stampata; //per la numerazione dei registri successivi + _ok_vidi = FALSE; + _stampa_mese = 13; + _scelta = controlla_b0(); //sul registro non va stampata la liq. ma comunque + //va richiamata per il calcolo progressivi (a seconda di b0) + //se non e' stampa di prova + ok = setta_mask(i); + if (!ok) continue; + + if (_liquidazione) + { + if (_tipo_stampa == 2 || _tipo_stampa == 4) + _size_header = _stampa_ind_ditta ? 3 : 2; + else _size_header = 3; + clear_stliq(); + _scelta = controlla_liquidazione(); + if (_scelta == non_proseguire) + return FALSE; + } + + _cur->set_filterfunction(NULL); + _cur->set_filterfunction(filter_func); + + // Vado a vedere se ci sono movimenti + (*_cur) = 0L; + const long items = _cur->items(); + + // 17.5.95 Leggo parametri di stampa del registro + TString16 config; + const long codditta = get_firm(); + const char* reg = (const char*)_codreg; + config.format("REG%05ld%03s", codditta, reg); + printer().read_configuration(config); + + if (items > 0l) + { + print(); + + if (is_cancelled()) return FALSE; + + if (_tipo_stampa != 3 && _liquidazione) + stampa_liq_mesi_succ(); + } + else + no_movimenti(); + + if (_tipo_stampa == 3 && _rif_vid) + { + _intesta_vidi = TRUE; + stampa_vidi(); //stampa riferimenti vidimazione + } + } + } //for + if (msg) + //if ( (_tipo_stampa != 3) || (_tipo_stampa == 3 && _fino_a_mese == 1 && _selected.ones() == 1L) ) //il messaggio seguente, nel caso di stampa su libro unico, + if(_tipo_stampa == 3 && _fino_a_mese == 1 && _selected.ones() == 1L) + message_box("Ditta %ld: nessun registro soddisfa i parametri indicati", _ditta); //viene gia' dato nell'handler + } //da Gennaio) + } + } + TApplication::set_firm(__firm); + return TRUE; +} + + +void CG4400_application::stampa_liq_mesi_succ() +{ + int da = _datareg.month() + 1; + int a = _data_a.month(); + for (int m = da; m <= a; m++) + { + if (stampo_liquidazione(m)) + { + if (!printer().isopen()) + printer().open(); +// _datareg = format("01/%02d/%4d", m, _annoes); //serve per la preprocess_header (intestazione per la stampa liquidazione) + _datareg = TDate(1, m, _annoes); // Meglio cosi' + TFilename t; + t.temp("iva"); + if (_tipo_stampa == 1) + send_message('L',t, m); //prima era S ma non andava bene! + else send_message('l',t,m); //prima era s + //TString80 nomef; nomef = t.path(); nomef << "\\" << t.name(); + //if (fexist(nomef)) + if (fexist(t)) + { + _intesta_liq = TRUE; + if (m > da) printer().formfeed(); + //printer().footerlen(0); + merge_export_file(t,FALSE,TRUE); + _intesta_liq = FALSE; + remove(t); + } + } + } + if (printer().isopen()) printer().close(); +} + +void CG4400_application::send_message(char tipo, const TFilename& nome, int mese) +{ + const char* app; + + if (tipo == 'S' || tipo == 's') + app = "cg4 -2 -S"; + else if (tipo == 'C') + app = "cg4 -2 -C"; + else app = "cg4 -2"; + + TToken_string ss(10); + + ss.add(_annoes); + if (_tipo_riepilogativo == 'A' && mese == 12) + ss.add(13); + else ss.add(mese); + ss.add(_ditta); + ss.add(tipo); + ss.add(_data_stampa.string()); + ss.add(nome); + ss.add(_size_header); + //ss.add("x"); + + TMessage liq (app, "RCL", ss); + liq.send(); + + TExternal_app pn(app); + pn.run(); +} + +bool CG4400_application::set_ditte(TMask& m) +{ + /* + _selected.reset(); + m.field(F_SELECT).set("0"); + m.field(DA_CODICE).set(""); + m.field(A_CODICE).set(""); + */ + m.field(TIPO_STAMPA).set("1"); + m.field(DA_DATA).set(""); + m.field(A_DATA).set(""); + m.field(CODICE_LIBRO_PROVA).set(""); + + KEY tasto; + tasto = m.run(); + // m.first_focus(tasto); + return tasto == K_ENTER; +} + +TRectype& CG4400_application::look_comuni (const char * cod) +{ + _com->zero(); + _com->put(COM_COM, cod); + _com->read(); + if (_com->bad()) + _com->zero(); + + return _com->curr(); +} + +void CG4400_application::get_dati_ditta() +{ + TLocalisamfile nditte(LF_NDITTE); + TLocalisamfile anag(LF_ANAG); + TLocalisamfile unloc(LF_UNLOC); + TString codanagr; + TString tipoa; + + nditte.zero(); + nditte.put(NDT_CODDITTA, get_firm()); + nditte.read(); + + if (nditte.bad()) nditte.zero(); + + codanagr = nditte.get(NDT_CODANAGR); + tipoa = nditte.get(NDT_TIPOA); + _ragsoc = nditte.get(NDT_RAGSOC); + + anag.setkey(1); + anag.zero(); + anag.put (ANA_TIPOA, tipoa); + anag.put (ANA_CODANAGR, codanagr); + anag.read(); + if (anag.bad()) anag.zero(); + + _cofi = anag.get(ANA_COFI); + _paiva = anag.get(ANA_PAIV); + _comunefis = anag.get(ANA_COMRF); + + if (_comunefis.empty()) + _comunefis = anag.get(ANA_COMRES); + + TRectype dep = look_comuni (_comunefis); + + _comunefis = dep.get(COM_DENCOM); + _provfis = dep.get(COM_PROVCOM); + _cap = dep.get(COM_CAPCOM); + if (_comunefis.empty()) + { + _viafis = anag.get(ANA_INDRF); + _viafis.rtrim(); + _viafis << " " << anag.get (ANA_CIVRF); + } + else + { + _viafis = anag.get(ANA_INDRES); + _viafis.rtrim(); + _viafis << " " << anag.get (ANA_CIVRES); + } + + if (_cod_un_loc) + { + unloc.zero(); + unloc.put(ULC_CODDITTA, get_firm()); + unloc.put(ULC_CODULC, _cod_un_loc); + unloc.read(); + if (unloc.read() == NOERR) + { + TRectype dep = look_comuni (unloc.get(ULC_COMULC)); + _comunefis = dep.get(COM_DENCOM); + _provfis = dep.get(COM_PROVCOM); + _cap = dep.get(COM_CAPCOM); + _viafis = unloc.get(ULC_INDULC); + _viafis.rtrim(); + _viafis << " " << unloc.get(ULC_CIVULC); + } + } +} + +int CG4400_application::stampa_intestazione() +{ + int r = 1; + TString codice_ditta; + TString riga(_stampa_width); + + get_dati_ditta(); + codice_ditta << get_firm(); + + set_header (r, "Ditta %s %s %s %s %s %s", (const char*)codice_ditta, + (const char*)_ragsoc, (const char*)_viafis, + (const char*)_cap, (const char*)_comunefis, + (const char*)_provfis); + r++; + //printer().setdate(_data); + if (_tipo_stampa == 1) + { + riga = "REGISTRO DI PROVA Data @<"; + riga.right_just(_stampa_width-6); + } + riga.overwrite (format("Partita iva %s Codice fiscale %s", (const char*)_paiva, (const char*)_cofi)); + set_header (r, riga); + + return r; +} + +void CG4400_application::preprocess_header() +{ + int r=1; + char cor, nd1, nd2; + char tipo = ' '; + char type = ' '; + int mese, anno; + TString riga(_stampa_width); + TString data(30); + + riga.fill('-'); + + if (_tipo_stampa != 3) + { + mese = _datareg.month(); + anno = _datareg.year(); + } + else //se _tipo_stampa == 3 (su libro unico) sto stampando un solo mese + { + mese = _fino_a_mese; + anno = _annoes; + } + + data.format("%s %s %d", "mese di", itom(mese), anno); + + reset_header(); + + if (_tipo_stampa == 2 || _tipo_stampa == 4) + { + if (_stampa_ind_ditta) + r = stampa_intestazione(); + } + else // se stampa di prova o su libro unico l'intestazione della ditta + // va sempre stampata + r = stampa_intestazione(); + + if (_tipo_stampa == 3 && !_intesta_vidi) + { + ++_u_stampata; + ++_pagine_stampate; + } + + if (_tipo_stampa == 2 || _tipo_stampa == 4) + ++_pagine_stampate; + + if (_tipo_stampa == 3) + set_header(r, "@94gProgr.Studio %ld@114gProgr.Utente %ld", _u_stampata, _pagine_stampate); + + // cosi' sono sicura che l'aggiornamento viene fatto ad ogni salto pagina + // (cioe' a rottura di mese) + if (_tipo_stampa != 1) aggiorna_reg(_ok_vidi); + + r++; + + /* + if (!_intesta_vidi) + set_header(r, "Registro IVA: %s %s %s Attivita\' %s %s", + (const char *) _codreg, (const char *) _desc_lib, + (const char *) data, (const char *) _codatt, + (const char *) _attivita); + */ + if (!_intesta_vidi) + { + if (_intesta_liq) + set_header(r, "Registro IVA: %s %s %s", (const char*)_codreg, + (const char*)_desc_lib, (const char*) data); + else set_header(r, "Registro IVA: %s %s %s Attivita\' %s %s", + (const char*) _codreg, (const char*) _desc_lib, + (const char*) data, (const char*) _codatt, + (const char*) _attivita); + } + else + { + set_header(r++, "Registro IVA: %s %s", (const char *) _codreg, (const char *) _desc_lib); + set_header(r, "RIFERIMENTI VIDIMAZIONE"); + } + + if (_intesta_liq) + { + /* + r++; + set_header(r++, "CALCOLO LIQUIDAZIONE IVA"); + set_header(r++,riga); + TString title (80); + title << "Liquidazione IVA "; + if (_tipo_riepilogativo == 'A' && mese == 12) + title << "Annuale " << format("%d", anno); + else + { + title << "del periodo"; + title << format(" %s %d", itom(mese), anno); + } + set_header(r++, "%s@102g Frequenza %s", (const char*) title, _frequiva == 'T' ? "T" : "M"); + set_header(r++,riga); + set_header(r,""); + */ + } + else //non sto stampando la liquidazione + { + r++; + set_header(r, riga); + r++; + if (_tipo_reg == 1) //registro vendite + { + cor = 'R'; + nd1 = ' '; + nd2 = ' '; + } + if (_tipo_reg == 2) + { + cor = 'C'; + nd1 = 'N'; + nd2 = 'D'; + } + if (_tipoatt == "E") //attivita' mista + { + tipo = 'A'; + type = 'T'; + } + /* + if ((!_stampa_data_reg) && _stampa_width == 132) + set_header(r,"Data I/P"); + */ + if (_tipo_stampa == 1) //stampa di prova (_intesta_vidi e' di sicuro FALSE) + { + if (_stampa_width == 132) + { + set_header(r,"@10gNum.@19gDocumento@66gT Tipo@102gCod %c@123gT %c@128gNum", nd1, tipo); + r++; + set_header(r, "Data reg. prot.@17gData@24gNumero Codice Ragione sociale/descrizione@66gO Doc.@74gTotale doc.@90gImponibile Iva %c@115gImposta@123g%c %c@128gReg", nd2, cor, type); + r++; + } + else //stampa a 198 + { + set_header(r,"Registrazione Documento@66gT Tipo@110gCod %c@132g%c T@139gNum.", nd1, tipo, cor); + r++; + set_header(r, "Data Protocollo Data@24gNumero Codice Ragione sociale/descrizione@66gO Documento@80gTot.Documento@98gImponibile Iva %c@124gImposta@132g%c %c@139gReg.", nd2, type, cor); + r++; + } + } + else if (!_intesta_vidi) + { + if (_stampa_width == 132) + { + set_header(r,"@10gNum.@19gDocumento@66gT Tipo@102gCod %c@123gT %c", nd1, tipo); + if (_tipo_stampa == 4) //stampa definitiva con rif. al libro giornale + set_header(r, "@128gNum."); + r++; + set_header(r, "Data reg. prot.@17gData@24gNumero Codice Ragione sociale/descrizione@66gO Doc.@74gTotale doc.@90gImponibile Iva %c@115gImposta@123g%c %c", + nd2, cor, type); + if (_tipo_stampa == 4) + set_header(r, "@128gop."); + r++; + } + else //stampa a 198 + { + set_header(r,"Registrazione Documento@66gT Tipo@110gCod %c@132g%c T", nd1, tipo); + if (_tipo_stampa == 4) + set_header(r, "@139gNum."); + r++; + set_header(r, "Data Protocollo Data@24gNumero Codice Ragione sociale/descrizione@66gO Documento@80gTot.Documento@98gImponibile Iva %c@124gImposta@132g%c %c", nd2, type, cor); + if (_tipo_stampa == 4) + set_header(r, "@139gop. @144gCodice conto @159gDescrizione sottoconto"); + r++; + } + } + else if (_tipo_stampa == 3 && _intesta_vidi) + { + TString tr(52); + tr.fill('-'); + set_header(r++,"@10gPagine studio Pagine utente ---------------- V I D I M A Z I O N E %s", (const char*)tr); + set_header(r++,"Mese@12gda@20ga@27gda@35ga Intestatario@71gN.fogli Pag.in. Pag.fin. Data Ufficio"); + } + if (_stampa_ind_comp && !_intesta_vidi) + set_header(r++, "@38gGeneralita'"); + + set_header(r, riga); + } +} + +int cg4400 (int argc, char * argv[]) +{ + CG4400_application a; + a.run(argc, argv, "Stampa registri IVA"); + return 0; +} + + + + + + + + + + + + + + diff --git a/cg/cg4400.h b/cg/cg4400.h index 3cd3db56a..0d26a80b5 100755 --- a/cg/cg4400.h +++ b/cg/cg4400.h @@ -1,160 +1,160 @@ -// -// cg4400.h -// -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "cglib03.h" -#include "cglib04.h" -#include "conto.h" - -enum messaggio { - no_liquidazione, - B0_settato, - non_proseguire, - prosegui_stampa, - prosegui_cal_stampa - }; - -class CG4400_application : public TPrintapp -{ - TCursor * _cur; - TRelation *_rel, *_nditte; - TLocalisamfile *_clifo, *_occas, *_tab, *_tabcom, *_com, *_anag, *_unloc, *_attiv, *_indlib; - TTable *_tabreg, *_tablbu, *_tablim, *_tabpim, *_tablia, *_tabiva; - TTable *_tabpla, *_tabppa, *_tabvid; - TRigaiva_array _iva_array, _riga_rmi; - TTipodoc_array _doc_array; - TRiga_array _tot_iva_array; - TBit_array _selected; - TArray_sheet *_ditte; - TArray _nomiditte; - bool _st_liq[13]; - bool _test; - TRecnotype _nrec; - bool _mov_empty, _stampa_ind_ditta, _stampa_tutti_i_registri, _auto_intraf, _stampa; - bool _corrispettivi, _liquidazione, _riep_liq, _stampa_ind_comp, _esiste_riga_iva, _stampa_cred_pre; - bool _rif_vid, _intesta_vidi, _intesta_liq, _stampa_data_reg, _ok_vidi; - bool _sosp_imposta; - char _frequiva, _tipo_riepilogativo; - TDate _data_da, _data_a, _data_stampa, _dataregp, _dataregs, _datareg; - TDate _u_data; - long _n_ditte, _u_stampata, _primast, __firm, _uprotivap, _ditta; - long _numini, _pagine_stampate; - int _fino_a_mese, _tipo_reg, _tipo_stampa, _cod_un_loc; - int _annoes, _r, _stampa_width, _mese_ultima_liq, _mese_credito; - int _stampa_len, _stampa_mese, _size_header; - real _totale_doc, _credito; - TString _codreg, _desc_lib, _codatt, _attivita, _tipoatt; - TString _tipodoc, _descr_doc, _codlib, _codice_vidi; - TString _cofi,_cap,_paiva,_ragsoc,_comunefis,_provfis,_viafis; - TFilename _t, _pippo; - - TParagraph_string* _desc27; - messaggio _scelta; - -protected: - - static bool filter_func (const TRelation * r); - static bool mask_tipo_stampa (TMask_field&, KEY); - static bool to_ditt_handler (TMask_field&, KEY); - static bool fr_ditt_handler (TMask_field&, KEY); - static bool to_butt_handler (TMask_field&, KEY); - static bool fr_butt_handler (TMask_field&, KEY); - static bool mask_cod (TMask_field&, KEY); - static bool mask_libun (TMask_field&, KEY); - static bool mask_data (TMask_field&, KEY); - static bool mask_mese (TMask_field&, KEY); - static bool mask_fino_a_mese (TMask_field&, KEY); - static bool mask_select (TMask_field&, KEY); - static bool mask_azzera (TMask_field&, KEY); - static bool year_handler (TMask_field&, KEY); - -public: - - const char* desc_attivita (); - const char* tipo_attivita (); - const char* descr_doc (); - const char* descr_iva (const char *); - TRectype& ricerca_occ(const char*); - TRectype& ricerca_cf (char, long); - TRectype& look_comuni(const char*); - TArray_sheet* get_ditte_sheet() { return _ditte; } - int setta_riga (int, const TRigaiva&, real&, real&, real&, real&); - int riga_rmoviva(); - bool set_print(int); - bool set_ditte(TMask&); - bool compila_reg(const TMask&); - bool compila_lib(); - messaggio controlla_liquidazione(); - messaggio controlla_b0(); - bool controlla_mov(); - bool stampo_liquidazione(int); - bool ventilazione(const char*); - bool cerca_libro_gio(TString&, bool*); - bool look_reg (int, int, TString&, int, const char*, int*, long); - bool look_regs(int, TString&, int, int*, long, bool*); - bool stampa_totali_finali(); - bool stampa_datareg(); - bool stampa_registri_IVA(const TMask&); - bool look_lia(long ditta = 0l); - bool ricerca_mese(TString&,TString&,int,int,TMask_field&); - void set_choice_limits(TMask&); - void build_ditte_sheet(); - void cerca_reg(const TString&, byte*); - void set_page_tot_reg(); - void send_message(char, const TFilename&,int); - void aggiorna_reg(const bool aggiorna_vidi); - void aggiorna_lib(); - void calcola_progressivi(); - void stampa_liq_mesi_succ(); - void look_reg(); - void no_movimenti(); - void liq_b0_settato(); - void liq_other_case(); - bool setta_mask(long); - bool preprocess_page(int, int); - int stampa_intestazione(); - int stampa_prospetto(); - long select_firm_range(long,long); - void stampa_plafonds(int); - void get_dati_ditta(); - void stampa_vidi(); - void scrivi_reg(); - int stampa_acquisti(int); - real stampa_valori_plafonds(const real&, const int, TTable&, const char*); - void build_nomiditte(TProgind* pnd = NULL); - void set_year(int y) { _annoes = y; } - void clear_stliq(); - virtual bool preprocess_print(int, int); - virtual bool user_create(); - virtual bool user_destroy(); - virtual print_action postprocess_page (int, int); - virtual void preprocess_header(); - - CG4400_application() : TPrintapp(), _ditte(NULL), _selected(10000), _nomiditte(100), _test(FALSE) {} - virtual ~CG4400_application() {} -}; - - - - +// +// cg4400.h +// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "cglib03.h" +#include "cglib04.h" +#include "conto.h" + +enum messaggio { + no_liquidazione, + B0_settato, + non_proseguire, + prosegui_stampa, + prosegui_cal_stampa + }; + +class CG4400_application : public TPrintapp +{ + TCursor * _cur; + TRelation *_rel, *_nditte; + TLocalisamfile *_clifo, *_occas, *_tab, *_tabcom, *_com, *_anag, *_unloc, *_attiv, *_indlib; + TTable *_tabreg, *_tablbu, *_tablim, *_tabpim, *_tablia, *_tabiva; + TTable *_tabpla, *_tabppa, *_tabvid; + TRigaiva_array _iva_array, _riga_rmi; + TTipodoc_array _doc_array; + TRiga_array _tot_iva_array; + TBit_array _selected; + TArray_sheet *_ditte; + TArray _nomiditte; + bool _st_liq[13]; + bool _test; + TRecnotype _nrec; + bool _mov_empty, _stampa_ind_ditta, _stampa_tutti_i_registri, _auto_intraf, _stampa; + bool _corrispettivi, _liquidazione, _riep_liq, _stampa_ind_comp, _esiste_riga_iva, _stampa_cred_pre; + bool _rif_vid, _intesta_vidi, _intesta_liq, _stampa_data_reg, _ok_vidi; + bool _sosp_imposta; + char _frequiva, _tipo_riepilogativo; + TDate _data_da, _data_a, _data_stampa, _dataregp, _dataregs, _datareg; + TDate _u_data; + long _n_ditte, _u_stampata, _primast, __firm, _uprotivap, _ditta; + long _numini, _pagine_stampate; + int _fino_a_mese, _tipo_reg, _tipo_stampa, _cod_un_loc; + int _annoes, _r, _stampa_width, _mese_ultima_liq, _mese_credito; + int _stampa_len, _stampa_mese, _size_header; + real _totale_doc, _credito; + TString _codreg, _desc_lib, _codatt, _attivita, _tipoatt; + TString _tipodoc, _descr_doc, _codlib, _codice_vidi; + TString _cofi,_cap,_paiva,_ragsoc,_comunefis,_provfis,_viafis; + TFilename _t, _pippo; + + TParagraph_string* _desc27; + messaggio _scelta; + +protected: + + static bool filter_func (const TRelation * r); + static bool mask_tipo_stampa (TMask_field&, KEY); + static bool to_ditt_handler (TMask_field&, KEY); + static bool fr_ditt_handler (TMask_field&, KEY); + static bool to_butt_handler (TMask_field&, KEY); + static bool fr_butt_handler (TMask_field&, KEY); + static bool mask_cod (TMask_field&, KEY); + static bool mask_libun (TMask_field&, KEY); + static bool mask_data (TMask_field&, KEY); + static bool mask_mese (TMask_field&, KEY); + static bool mask_fino_a_mese (TMask_field&, KEY); + static bool mask_select (TMask_field&, KEY); + static bool mask_azzera (TMask_field&, KEY); + static bool year_handler (TMask_field&, KEY); + +public: + + const char* desc_attivita (); + const char* tipo_attivita (); + const char* descr_doc (); + const char* descr_iva (const char *); + TRectype& ricerca_occ(const char*); + TRectype& ricerca_cf (char, long); + TRectype& look_comuni(const char*); + TArray_sheet* get_ditte_sheet() { return _ditte; } + int setta_riga (int, const TRigaiva&, real&, real&, real&, real&); + int riga_rmoviva(); + bool set_print(int); + bool set_ditte(TMask&); + bool compila_reg(const TMask&); + bool compila_lib(); + messaggio controlla_liquidazione(); + messaggio controlla_b0(); + bool controlla_mov(); + bool stampo_liquidazione(int); + bool ventilazione(const char*); + bool cerca_libro_gio(TString&, bool*); + bool look_reg (int, int, TString&, int, const char*, int*, long); + bool look_regs(int, TString&, int, int*, long, TProgind*); + bool stampa_totali_finali(); + bool stampa_datareg(); + bool stampa_registri_IVA(const TMask&); + bool look_lia(long ditta = 0l); + bool ricerca_mese(TString&,TString&,int,int,TMask_field&); + void set_choice_limits(TMask&); + void build_ditte_sheet(); + void cerca_reg(const TString&, byte*); + void set_page_tot_reg(); + void send_message(char, const TFilename&,int); + void aggiorna_reg(const bool aggiorna_vidi); + void aggiorna_lib(); + void calcola_progressivi(); + void stampa_liq_mesi_succ(); + void look_reg(); + void no_movimenti(); + void liq_b0_settato(); + void liq_other_case(); + bool setta_mask(long); + bool preprocess_page(int, int); + int stampa_intestazione(); + int stampa_prospetto(); + long select_firm_range(long,long); + void stampa_plafonds(int); + void get_dati_ditta(); + void stampa_vidi(); + void scrivi_reg(); + int stampa_acquisti(int); + real stampa_valori_plafonds(const real&, const int, TTable&, const char*); + void build_nomiditte(TProgind* pnd = NULL); + void set_year(int y) { _annoes = y; } + void clear_stliq(); + virtual bool preprocess_print(int, int); + virtual bool user_create(); + virtual bool user_destroy(); + virtual print_action postprocess_page (int, int); + virtual void preprocess_header(); + + CG4400_application() : TPrintapp(), _ditte(NULL), _selected(10000), _nomiditte(100), _test(FALSE) {} + virtual ~CG4400_application() {} +}; + + + + diff --git a/cg/cg4400b.uml b/cg/cg4400b.uml index 439a60293..1085aa888 100755 --- a/cg/cg4400b.uml +++ b/cg/cg4400b.uml @@ -1,59 +1,59 @@ -#include "cg4400b.h" - -PAGE "Stampa registri IVA" -1 -1 78 14 - -GROUPBOX DLG_NULL 78 3 -BEGIN - PROMPT 1 0 "" -END - -NUMBER F_CODDITTA 5 -BEGIN - PROMPT 3 1 "Ditta " - FLAGS "D" -END - -STRING F_RAGSOC 50 -BEGIN - PROMPT 17 1 "Ragione " - FLAGS "D" -END - -STRING COD_LIB 3 -BEGIN - PROMPT 3 4 "Codice Libro " - FLAGS "D" -END - -LISTBOX U_MESE 10 -BEGIN - PROMPT 3 5 "Stampa mese " - FLAGS "MD" - ITEM "00|Nessuno" -END - -NUMBER U_PAGINA 4 -BEGIN - PROMPT 3 6 "Ult.num.pagina stampata libro ditta " - FLAGS "R" -END - -DATE U_DATA -BEGIN - PROMPT 3 7 "Ultima data di stampa " - FLAGS "D" -END - -BUTTON DLG_OK 9 2 -BEGIN - PROMPT -12 -1 "" -END - -BUTTON DLG_CANCEL 9 2 -BEGIN - PROMPT -22 -1 "" -END - -ENDPAGE - +#include "cg4400b.h" + +PAGE "Stampa registri IVA" -1 -1 78 12 + +GROUPBOX DLG_NULL 78 3 +BEGIN + PROMPT 1 0 "" +END + +NUMBER F_CODDITTA 5 +BEGIN + PROMPT 3 1 "Ditta " + FLAGS "D" +END + +STRING F_RAGSOC 50 +BEGIN + PROMPT 17 1 "Ragione " + FLAGS "D" +END + +STRING COD_LIB 3 +BEGIN + PROMPT 3 4 "Codice Libro " + FLAGS "D" +END + +LISTBOX U_MESE 10 +BEGIN + PROMPT 3 5 "Stampa mese " + FLAGS "MD" + ITEM "00|Nessuno" +END + +NUMBER U_PAGINA 4 +BEGIN + PROMPT 3 6 "Ult.num.pagina stampata libro ditta " + FLAGS "R" +END + +DATE U_DATA +BEGIN + PROMPT 3 7 "Ultima data di stampa " + FLAGS "D" +END + +BUTTON DLG_OK 9 2 +BEGIN + PROMPT -12 -1 "" +END + +BUTTON DLG_CANCEL 9 2 +BEGIN + PROMPT -22 -1 "" +END + +ENDPAGE + ENDMASK \ No newline at end of file diff --git a/cg/cg4600.cpp b/cg/cg4600.cpp index 479b27ff6..70ece54f0 100755 --- a/cg/cg4600.cpp +++ b/cg/cg4600.cpp @@ -1,1806 +1,1806 @@ -// Chiusura/Apertura Conti - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cglib.h" -#include "cg4.h" -#include "cg4600.h" -#include "cg2101.h" - -#include -#include -#include -#include - -bool mask_datac (TMask_field&, KEY); -bool mask_dataap (TMask_field&, KEY); -bool mask_distinti (TMask_field&, KEY); -bool attivo_passivo(TMask_field&, KEY); -bool costi_ricavi (TMask_field&, KEY); - -#define MAX 98 - -class CG4600_application : public TApplication -{ - friend bool mask_datac (TMask_field&, KEY); - friend bool mask_dataap (TMask_field&, KEY); - friend bool mask_distinti (TMask_field&, KEY); - - TTable* _esc, * _reg; - TRelation* _rel; - TMovimentoPN* _pn; - TLocalisamfile* _saldi; - TRectype* _rec; - TLocalisamfile* _mov; - TCursor* _cur; - TSaldo_agg* _sld; - TSaldo* _sale; - TProgind* _prog; - TConto _tcbilch,_tcproper,_tcbilap,_tcutilp,_tcperdp,_tcutile,_tcperde, _conto_corrente; - - real _saldo, _totale_saldo, _capitale_netto; - int _annoesch, _annoesap; - long _numreg; - TDate _dataregap, _dataregch; - TString _codcausap, _codcausch; - -public: - virtual bool create(); - virtual bool destroy(); - virtual bool menu(MENU_TAG m); - void costi (); - void ricavi(); - void chiudi_attivita(); - void chiudi_passivita(); - void apri_attivita(); - void apri_passivita(); - void rmov_proper (int, long, TDate&, TRectype&, TConto&, real&, bool); - void ultima_registrazione(); - void compila_testata(int,TDate&,TString&); - void chiusura_conto_economico(); - void chiusura_conto_patrimoniale(); - void apertura_capitale_netto(); - bool set(); - // bool epilogo_conti(); - - CG4600_application() {} -}; - -HIDDEN bool abilita_anni(TMask& m, KEY k) -{ - if (k == K_SHIFT+K_F12) - { - m.enable(F_ANNOCH); - m.enable(F_ANNO); - } - - return TRUE; -} - -HIDDEN bool anni_contigui (int annoch, int annoap) -{ - TString16 dep(format("%04d", annoch)); - - TTable esc ("ESC"); - - esc.zero(); - esc.put("CODTAB", dep); - esc.read(); - esc.next(); - int anno = atoi(esc.get("CODTAB")); - if (anno != annoap) - return warning_box("I due esercizi indicati non risultano contigui"); - - return TRUE; -} - -HIDDEN TRectype& cerca_esercizio(int anno) -{ - TTable TabEs ("ESC"); - TString16 dep (format("%04d", anno)); - - TabEs.zero(); - TabEs.put("CODTAB", dep); - if (TabEs.read() == NOERR) - return TabEs.curr(); - else - warning_box("Esercizio non presente in tabella esercizi"); - - TabEs.zero(); - - return TabEs.curr(); -} - -bool mask_datac (TMask_field& f, KEY k) -{ - //TTable TabEs ("ESC"); - TTable TabReg("REG"); - TString annos (4); - int anno = 0;; - bool ok = TRUE; - - if ( (k == K_ENTER) && f.to_check(k) ) - { - int annoch = f.mask().get_int(F_ANNOCH); - int annoap = f.mask().get_int(F_ANNO); - - if (!anni_contigui(annoch,annoap)) - return FALSE; - - TRectype TabEsch = cerca_esercizio(annoap); - TDate inizio = TabEsch.get_date("D0"); - TDate fine = TabEsch.get_date("D1"); - TDate scarico = TabEsch.get_date("D2"); - - TRectype TabEsap = cerca_esercizio(annoch); - TDate iniziop = TabEsap.get_date("D0"); - TDate finep = TabEsap.get_date("D1"); - TDate data = f.get(); -/* - TabEs.last(); - TDate inizio = TabEs.get_date("D0"); - TDate fine = TabEs.get_date("D1"); - TDate scarico = TabEs.get_date("D2"); - TabEs.prev(); - TDate iniziop = TabEs.get_date("D0"); - TDate finep = TabEs.get_date("D1"); - TDate data = f.get(); -*/ - TString istr = inizio.string(); - TString fstr = fine.string(); - - TString ipstr = iniziop.string(); - TString fpstr = finep.string(); - - TString scastr = scarico.string(); - - TString datastr = f.get(); - - if (data < finep) - { - f.warning_box ("La data di chiusura non puo' essere inferiore alla data di fine esercizio precedente"); - return FALSE; - } - if (data > fine) - { - f.warning_box ("La data di chiusura non puo' essere superiore alla data di fine esercizio in corso"); - return FALSE; - } - if ( scarico.ok() && (data <= scarico) ) - { - f.warning_box ("La data di chiusura non puo' essere inferiore o uguale alla data di scarico"); - return FALSE; - } - if ( (data >= inizio) && (data <= fine) ) //la data di chiusura e' cioe' relativa all'esercizio in corso - anno = fine.year(); - else if ( (data >= iniziop) && (data <= finep) ) //la data di chiusura e' cioe' relativa all'esercizio precedente - anno = finep.year(); - - TabReg.zero(); - annos = format ("%04d", anno); - TabReg.put ("CODTAB", annos); - TRectype r (TabReg.curr()); - TabReg.read(_isgteq); - for (; !TabReg.eof(); TabReg.next()) - { - if (TabReg.curr() != r) break; - - int tiporeg = TabReg.get_int("I0"); - if (tiporeg == 5) - { - TDate datast = TabReg.get_date("D3"); - if (data < datast.string()) - { - ok = FALSE; - break; - } - } - } - if (!ok) - { - f.warning_box("La data di chiusura non puo' essere inferiore alla data ultima stampa bollato"); - return FALSE; - } - } - return TRUE; -} - -bool mask_dataap (TMask_field& f, KEY k) -{ - TTable TabEs ("ESC"); - TTable TabReg("REG"); - int anno = 0; - TString annos (4); - bool ok = TRUE; - - if ( (k == K_ENTER) && f.to_check(k) ) - { - int annoch = f.mask().get_int(F_ANNOCH); - int annoap = f.mask().get_int(F_ANNO); - - if (!anni_contigui(annoch,annoap)) - return FALSE; - - TRectype TabEsch = cerca_esercizio(annoap); - TDate inizio = TabEsch.get_date("D0"); - TDate fine = TabEsch.get_date("D1"); - TDate scarico = TabEsch.get_date("D2"); - - TRectype TabEsap = cerca_esercizio(annoch); - TDate iniziop = TabEsap.get_date("D0"); - TDate finep = TabEsap.get_date("D1"); - TDate data = f.get(); -/* - TabEs.last(); - TDate inizio = TabEs.get_date("D0"); - TDate fine = TabEs.get_date("D1"); - TDate scarico = TabEs.get_date("D2"); - TabEs.prev(); - TDate iniziop = TabEs.get_date("D0"); - TDate finep = TabEs.get_date("D1"); - TDate data = f.get(); -*/ - TString istr = inizio.string(); - TString fstr = fine.string(); - - TString ipstr = iniziop.string(); - TString fpstr = finep.string(); - - TString scastr = scarico.string(); - - TString datastr = f.get(); - - if (data < inizio) - { - f.warning_box ("La data di apertura non puo' essere inferiore alla data di inizio esercizio in corso"); - return FALSE; - } - if (data > fine) - { - f.warning_box ("La data di apertura non puo' essere superiore alla data di fine esercizio in corso"); - return FALSE; - } - if ( scarico.ok() && (data <= scarico) ) - { - f.warning_box ("La data di apertura non puo' essere inferiore o uguale alla data di scarico"); - return FALSE; - } - - if ( (data >= inizio) && (data <= fine) ) //la data di apertura e' cioe' relativa all'esercizio in corso - anno = fine.year(); - else if( (data >= iniziop) && (data <= finep) ) //la data di apertura e' cioe' relativa all'esercizio precedente - anno = finep.year(); - - TabReg.zero(); - annos = format ("%04d", anno); - TabReg.put ("CODTAB", annos); - TRectype r (TabReg.curr()); - TabReg.read(_isgteq); - for (; !TabReg.eof(); TabReg.next()) - { - if (TabReg.curr() != r) break; - - int tiporeg = TabReg.get_int("I0"); - if (tiporeg == 5) - { - TDate datast = TabReg.get_date("D3"); - if (data < datast) - { - ok = FALSE; - break; - } - } - } - if (!ok) - { - f.warning_box("La data di apertura non puo' essere inferiore alla data ultima stampa bollato"); - return FALSE; - } - } - return TRUE; -} - -bool mask_distinti (TMask_field& f, KEY k) -{ - int idg,idc,ids,idg1,idc1,ids1; - - if (k == K_ENTER) - { - idg = 108; - idc = 109; - ids = 110; - - for (int i = 0; i < 7; i++) - { - int g = f.mask().get_int(idg); - int c = f.mask().get_int(idc); - long s = f.mask().get_long(ids); - - idg1 = idg; - idc1 = idc; - ids1 = ids; - - for (int j = i+1; j < 7; j++) - { - idg1 = idg1 + 3; - idc1 = idc1 + 3; - ids1 = ids1 + 3; - - int gruppo = f.mask().get_int(idg1); - int conto = f.mask().get_int(idc1); - long sottoc = f.mask().get_long(ids1); - - if ((g == gruppo)&&(c == conto)&&(s == sottoc)) - { - f.warning_box("Nessun sottoconto puo' essere ripetuto!"); - return FALSE; - } - } - - idg = idg + 3; - idc = idc + 3; - ids = ids + 3; - - } - } - return TRUE; -} - -bool attivo_passivo (TMask_field& f, KEY k) -{ - TLocalisamfile pcon (LF_PCON); - - if (k == K_ENTER) - { - int g,c; - int id = f.dlg(); - - if (id == F_UTILPC) - g = f.mask().get_int(F_UTILPG); - else - if (id == F_PERDPC) - g = f.mask().get_int(F_PERDPG); - - c = atoi(f.get()); - - pcon.setkey(1); - pcon.zero(); - pcon.put(PCN_GRUPPO, g); - pcon.put(PCN_CONTO, c); - if (pcon.read() == NOERR) - { - int indbil = pcon.get_int(PCN_INDBIL); - if (indbil != 1 && indbil != 2 && indbil != 5) - return f.warning_box("Indicatore di bilancio errato"); - } - } - return TRUE; -} - -bool costi_ricavi (TMask_field& f, KEY k) -{ - TLocalisamfile pcon (LF_PCON); - - if (k == K_ENTER) - { - int g,c; - int id = f.dlg(); - - if (id == F_UTILEC) - g = f.mask().get_int(F_UTILEG); - else - if (id == F_PERDEC) - g = f.mask().get_int(F_PERDEG); - - c = atoi(f.get()); - - pcon.setkey(1); - pcon.zero(); - pcon.put(PCN_GRUPPO, g); - pcon.put(PCN_CONTO, c); - if (pcon.read() == NOERR) - { - int indbil = pcon.get_int(PCN_INDBIL); - if (indbil != 3 && indbil != 4) - return f.warning_box("Indicatore di bilancio errato"); - } - } - return TRUE; -} - -bool CG4600_application::create() -{ - TApplication::create(); - - _rel = new TRelation (LF_PCON); - - _cur = new TCursor(_rel,"((GRUPPO!=\"\")&&(CONTO!=\"\")&&(SOTTOCONTO==\"\"))",1); - - _pn = new TMovimentoPN(); - _saldi = new TLocalisamfile (LF_SALDI); - _rec = new TRectype(LF_SALDI); - _mov = new TLocalisamfile (LF_MOV); - _esc = new TTable ("ESC"); - _reg = new TTable ("REG"); - _sld = new TSaldo_agg(); - _sale = new TSaldo(); - - _capitale_netto = ZERO; - - dispatch_e_menu (BAR_ITEM(1)); - - return TRUE; -} - -bool CG4600_application::destroy() -{ - delete _saldi; - delete _sale; - delete _mov; - delete _esc; - delete _reg; - delete _pn; - delete _rel; - delete _cur; - delete _sld; - delete _rec; - - return TApplication::destroy(); -} - -void CG4600_application::ultima_registrazione() -{ - long numregmov; - - _mov->setkey(1); //Leggo il numero di registrazione - _mov->last(); //dell'ultimo record di mov, e lo - numregmov = _mov->get_long(MOV_NUMREG); //incremento di uno per ottenere - _numreg = numregmov + 1; //un numero di registrazione - //sicuramente non esistente. -} - -bool CG4600_application::set() -{ - TTable TabEs ("ESC"); - TMask m ("cg4600a"); - KEY tasto; - int gbilch, cbilch , gproper, cproper, gbilap, cbilap, gutilp; - int cutilp, gperdp, cperdp, gutile, cutile, gperde, cperde; - long sbilch, sproper, sbilap, sutilp, sperdp, sutile, sperde; - - - TConfig conf(CONFIG_DITTA); - - m.set(F_CHIUSURA, conf.get("CoCaCh")); - m.set(F_APERTURA, conf.get("CoCaAp")); - - TabEs.last(); - int annoap = TabEs.get_int ("CODTAB"); - TDate inizio = TabEs.get_date("D0"); //data inizio es. in corso - TabEs.prev(); - int annoch = TabEs.get_int ("CODTAB"); - TDate fine = TabEs.get_date("D1"); //data fine es. precedente - m.set(F_ANNO, annoap); - m.set(F_ANNOCH, annoch); - m.set(F_DATAC, fine.string()); - m.set(F_DATAAP,inizio.string()); - - m.set(F_BILCHG, conf.get("CsBiChG")); - m.set(F_BILCHC, conf.get("CsBiChC")); - m.set(F_BILCHS, conf.get("CsBiChS")); - m.set(F_PROPERG, conf.get("CsPrPeG")); - m.set(F_PROPERC, conf.get("CsPrPeC")); - m.set(F_PROPERS, conf.get("CsPrPeS")); - m.set(F_BILAPG, conf.get("CsBiApG")); - m.set(F_BILAPC, conf.get("CsBiApC")); - m.set(F_BILAPS, conf.get("CsBiApS")); - m.set(F_UTILPG, conf.get("CsUeCpG")); - m.set(F_UTILPC, conf.get("CsUeCpC")); - m.set(F_UTILPS, conf.get("CsUeCpS")); - m.set(F_PERDPG, conf.get("CsPeCpG")); - m.set(F_PERDPC, conf.get("CsPeCpC")); - m.set(F_PERDPS, conf.get("CsPeCpS")); - m.set(F_UTILEG, conf.get("CsUeCeG")); - m.set(F_UTILEC, conf.get("CsUeCeC")); - m.set(F_UTILES, conf.get("CsUeCeS")); - m.set(F_PERDEG, conf.get("CsPeCeG")); - m.set(F_PERDEC, conf.get("CsPeCeC")); - m.set(F_PERDES, conf.get("CsPeCeS")); - - m.set_handler (F_DATAC, mask_datac); - m.set_handler (F_DATAAP, mask_dataap); - m.set_handler (F_PERDES, mask_distinti); - m.set_handler (F_UTILPC, attivo_passivo); - m.set_handler (F_PERDPC, attivo_passivo); - m.set_handler (F_UTILEC, costi_ricavi); - m.set_handler (F_PERDEC, costi_ricavi); - m.set_handler (abilita_anni); - - tasto = m.run(); - - if (tasto == K_ENTER) - { - _annoesch = m.get_int(F_ANNOCH); - _annoesap = m.get_int(F_ANNO); - _dataregch = m.get (F_DATAC); - _codcausch = m.get (F_CHIUSURA); - _dataregap = m.get (F_DATAAP); - _codcausap = m.get (F_APERTURA); - gbilch = m.get_int (F_BILCHG); - cbilch = m.get_int (F_BILCHC); - sbilch = m.get_long(F_BILCHS); - gproper = m.get_int (F_PROPERG); - cproper = m.get_int (F_PROPERC); - sproper = m.get_long(F_PROPERS); - gbilap = m.get_int (F_BILAPG); - cbilap = m.get_int (F_BILAPC); - sbilap = m.get_long(F_BILAPS); - gutilp = m.get_int (F_UTILPG); - cutilp = m.get_int (F_UTILPC); - sutilp = m.get_long(F_UTILPS); - gperdp = m.get_int (F_PERDPG); - cperdp = m.get_int (F_PERDPC); - sperdp = m.get_long(F_PERDPS); - gutile = m.get_int (F_UTILEG); - cutile = m.get_int (F_UTILEC); - sutile = m.get_long(F_UTILES); - gperde = m.get_int (F_PERDEG); - cperde = m.get_int (F_PERDEC); - sperde = m.get_long(F_PERDES); - - _tcbilch.set (gbilch,cbilch,sbilch); - _tcproper.set(gproper,cproper,sproper); - _tcbilap.set (gbilap,cbilap,sbilap); - _tcutilp.set (gutilp,cutilp,sutilp); - _tcperdp.set (gperdp,cperdp,sperdp); - _tcutile.set (gutile,cutile,sutile); - _tcperde.set (gperde,cperde,sperde); - - long cicli = (_cur->items() * 6) + 4; - _prog = new TProgind(cicli,"Chiusura/Apertura conti in corso... Prego attendere",FALSE); - - //ultima_registrazione(); - // anno_ese_precedente(); - - _numreg = 0; - - (*_cur) = 0L; - - _sld->set_anno_es(_annoesch); - _sld->set_movprovv(FALSE); - _sld->set_movap(FALSE); - - _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. - costi (); - - //_sld->reset(); //Azzera la tabella dei conti dell'oggetto TSaldo_agg - //ultima_registrazione(); - _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. - *_cur = 0l; - - ricavi(); - //_sld->reset(); - - chiusura_conto_economico(); - _totale_saldo = ZERO; - //_sld->reset(); - - //ultima_registrazione(); - _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. - *_cur = 0l; - - chiudi_attivita(); - //_sld->reset(); - - //ultima_registrazione(); - _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. - *_cur = 0l; - - chiudi_passivita(); - //_sld->reset(); - chiusura_conto_patrimoniale(); - _totale_saldo = ZERO; - - _sld->set_anno_es(_annoesap); - _sld->set_movap(TRUE); - _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. - *_cur = 0l; - - apri_attivita(); - - _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. - *_cur = 0l; - - apri_passivita(); - - apertura_capitale_netto(); - - _sld->registra(); - - delete _prog; - - message_box("Apertura/chiusura conti completata"); - - return FALSE; - } //K_ENTER - return FALSE; -} - -void CG4600_application::compila_testata(int annoes,TDate& datareg,TString& codcaus) -{ - _pn->lfile().zero(); - _pn->lfile().put(MOV_ANNOES, annoes); //Viene generato un movimento - _pn->lfile().put(MOV_DATAREG, datareg); //a rottura di conto - _pn->lfile().put(MOV_CODCAUS, codcaus); - _pn->lfile().put(MOV_NUMREG, _numreg); - _pn->lfile().put(MOV_DATACOMP, datareg); -} - -void CG4600_application::rmov_proper(int anno,long numrig,TDate& datareg,TRectype& rmov, - TConto& tc,real& tot_saldo,bool sezione_opposta) -{ - char sez_rmov = ' '; - char sezione = ' '; - real totale = tot_saldo; - - rmov.zero(); - rmov.put(RMV_ANNOES, anno); - rmov.put(RMV_NUMREG, _numreg); - rmov.put(RMV_NUMRIG, numrig); - rmov.put(RMV_DATAREG, datareg); - rmov.put(RMV_GRUPPO, tc.gruppo()); - rmov.put(RMV_CONTO, tc.conto()); - rmov.put(RMV_SOTTOCONTO, tc.sottoconto()); - - if (totale > ZERO) - { - sez_rmov = 'A'; - sezione = 'D'; - } - else - if (totale < ZERO) - { - sez_rmov = 'D'; - sezione = 'A'; - totale = -totale; - } - - if (sezione_opposta) - { - rmov.put(RMV_SEZIONE, sez_rmov); - _sld->aggiorna(tc,TImporto(sez_rmov,totale)); //Aggiorno anche i saldi con - // l'oggetto TSaldo_agg - } - else - { - rmov.put(RMV_SEZIONE, sezione); - _sld->aggiorna(tc,TImporto(sezione,totale)); //Aggiorno anche i saldi con - //l'oggetto TSaldo_agg - } - rmov.put(RMV_IMPORTO, totale); -} - -void CG4600_application::costi() -{ - bool compila_mov = TRUE; - long s; - char sez_rmov = ' ', sezione = ' '; - real tot_saldo; - long numrig = 0; - TSaldo& sale = *_sale; - int j = 0; - - _totale_saldo = ZERO; - tot_saldo = ZERO; - - TRecnotype items_pcon = _cur->items(); - - for (int i = 0; i < items_pcon; i++, ++(*_cur)) - { - int indbil = _cur->curr().get_int(PCN_INDBIL); - int g = _cur->curr().get_int(PCN_GRUPPO); - int c = _cur->curr().get_int(PCN_CONTO); - TString tmcf = _cur->curr().get (PCN_TMCF); - - _prog->addstatus(1); - - if (indbil == 3) - { - compila_mov = TRUE; - - _saldi->setkey(1); - _saldi->zero(); - _saldi->put(SLD_ANNOES, _annoesch); - _saldi->put(SLD_GRUPPO, g); - _saldi->put(SLD_CONTO, c); - - (*_rec) = _saldi->curr(); - - j = 0; - numrig = 0; - - for (_saldi->read(); ; _saldi->next()) - { - _saldo = ZERO; - - if (_saldi->curr() > (*_rec) || _saldi->eof()) - { - // Aggiungo un ulteriore riga di movimento contenente la somma - // di tutti i saldi aventi lo stesso conto, indicandola - // con una sezione opposta al risultato (della somma). - - if (j >= 1) - { - numrig++; - if (tot_saldo != ZERO) - rmov_proper(_annoesch,numrig,_dataregch,_pn->cg(j),_tcproper,tot_saldo,FALSE); - - tot_saldo = ZERO; - } - break; - } - - if (compila_mov) - { - ultima_registrazione(); - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 1 Chiusura Costi - compila_mov = FALSE; - } - - //numrig++; - s = _saldi->get_long(SLD_SOTTOCONTO); - //sale.calcola_ultima_immissione(_annoesch,0,g,c,s,indbil); - sale.ultima_immissione_bilancio(_annoesch,g,c,s,indbil, 1); - _saldo = sale.saldo(); - - if (_saldo.is_zero()) continue; - - numrig++; - - if (j >= MAX || _saldi->eof()) - { - // Aggiungo un ulteriore riga di movimento contenente la somma - // di tutti i saldi aventi lo stesso sottoconto, indicandola - // con una sezione opposta al risultato (della somma). - - // numrig++; - if (tot_saldo != ZERO) - rmov_proper (_annoesch,numrig,_dataregch,_pn->cg(j),_tcproper,tot_saldo,FALSE); - _pn->write(); - _pn->destroy_rows(0); //Azzero l'oggetto pn. - - j = 0; - numrig = 1; - ultima_registrazione(); - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 1 Chiusura Costi - compila_mov = FALSE; - tot_saldo = ZERO; - } - - if (_saldo > ZERO) - sezione = 'D'; - else - if (_saldo < ZERO) - { - sezione = 'A'; - _saldo = -_saldo; - } - - if (sezione == 'D') // ---> Tengo una variabile in cui salvo gli - { // importi trovati sui saldi. Quando ho - sez_rmov = 'A'; // finito di leggere i sottoconti, oppure - tot_saldo += _saldo; // quando ho raggiunto un massimo di 99 - _totale_saldo += _saldo; - } // righe di movimento, genero un' altra - else // riga con importo di sezione opposta - if (sezione == 'A') // alla somma, mandando a zero - { // il saldo di quel movimento. - sez_rmov = 'D'; - tot_saldo -= _saldo; - _totale_saldo -= _saldo; - } - - if (!_saldi->eof()) - { - TRectype& rmov = _pn->cg(j); - - rmov.zero(); - rmov.put(RMV_ANNOES, _annoesch); //Compilo una riga di movimento - rmov.put(RMV_DATAREG, _dataregch); //per ogni sottoconto che leggo - rmov.put(RMV_GRUPPO, g); //sui saldi. Siccome queste - rmov.put(RMV_CONTO, c); //righe servono per mandare a 0 - rmov.put(RMV_SOTTOCONTO, s); //il saldo dei movimenti, la - rmov.put(RMV_SEZIONE, sez_rmov); //sezione sara' opposta a - rmov.put(RMV_IMPORTO, _saldo); //quella letta sui saldi. - rmov.put(RMV_NUMREG, _numreg); - rmov.put(RMV_NUMRIG, numrig); - rmov.put(RMV_TIPOC, tmcf); - - TBill tc(g,c,s); - _sld->aggiorna(tc,TImporto(sez_rmov,_saldo)); //l'oggetto TSaldo_agg - j++; - } - if (_saldi->eof()) break; - } //for saldi - if (j >= 1) - { - _pn->write(); - //_sld->registra(); - j = 0; - _pn->destroy_rows(0); //Azzero l'oggetto pn. - } - } // if (indbil == 3) - } // for pcon -} - -void CG4600_application::ricavi() -{ - bool compila_mov = TRUE; - long s; - char sez_rmov = ' ', sezione = ' '; - real tot_saldo; - long numrig = 0; - TSaldo& sale = *_sale; - int j = 0; - - tot_saldo = ZERO; - - TRecnotype items_pcon = _cur->items(); - - for (int i = 0; i < items_pcon; i++, ++(*_cur)) - { - int indbil = _cur->curr().get_int(PCN_INDBIL); - int g = _cur->curr().get_int(PCN_GRUPPO); - int c = _cur->curr().get_int(PCN_CONTO); - TString tmcf = _cur->curr().get (PCN_TMCF); - - _prog->addstatus(1); - - if (indbil == 4) - { - compila_mov = TRUE; - - _saldi->setkey(1); - _saldi->zero(); - _saldi->put(SLD_ANNOES, _annoesch); - _saldi->put(SLD_GRUPPO, g); - _saldi->put(SLD_CONTO, c); - - (*_rec) = _saldi->curr(); - - j = 0; - numrig = 0; - - for (_saldi->read(); ; _saldi->next()) - { - _saldo = ZERO; - - if (_saldi->curr() > (*_rec) || _saldi->eof()) - { - // Aggiungo un ulteriore riga di movimento contenente la somma - // di tutti i saldi aventi lo stesso conto, indicandola - // con una sezione opposta al risultato (della somma). - - if (j >= 1) - { - numrig++; - if (tot_saldo != ZERO) - rmov_proper(_annoesch,numrig,_dataregch,_pn->cg(j),_tcproper,tot_saldo,FALSE); - - tot_saldo = ZERO; - } - break; - } - - if (compila_mov) - { - ultima_registrazione(); - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 2 Chiusura Ricavi - compila_mov = FALSE; - } - - //numrig++; - s = _saldi->get_long(SLD_SOTTOCONTO); - //sale.calcola_ultima_immissione(_annoesch,0,g,c,s,indbil); - sale.ultima_immissione_bilancio(_annoesch,g,c,s,indbil, 1); - _saldo = sale.saldo(); - - if (_saldo.is_zero()) continue; - - numrig++; - - if (j >= MAX || _saldi->eof()) - { - // Aggiungo un ulteriore riga di movimento contenente la somma - // di tutti i saldi aventi lo stesso sottoconto, indicandola - // con una sezione opposta al risultato (della somma). - - // numrig++; - if (tot_saldo != ZERO) - rmov_proper (_annoesch,numrig,_dataregch,_pn->cg(j),_tcproper,tot_saldo,FALSE); - _pn->write(); - _pn->destroy_rows(0); //Azzero l'oggetto pn. - - j = 0; - numrig = 1; - ultima_registrazione(); - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 2 Chiusura Ricavi - compila_mov = FALSE; - tot_saldo = ZERO; - } - - if (_saldo > ZERO) - sezione = 'D'; - else - if (_saldo < ZERO) - { - sezione = 'A'; - _saldo = -_saldo; - } - - if (sezione == 'D') // ---> Tengo una variabile in cui salvo gli - { // importi trovati sui saldi. Quando ho - sez_rmov = 'A'; // finito di leggere i sottoconti, oppure - tot_saldo += _saldo; // quando ho raggiunto un massimo di 99 - _totale_saldo += _saldo; - } // righe di movimento, genero un' altra - else // riga con importo di sezione opposta - if (sezione == 'A') // alla somma, mandando a zero - { // il saldo di quel movimento. - sez_rmov = 'D'; - tot_saldo -= _saldo; - _totale_saldo -= _saldo; - } - - if (!_saldi->eof()) - { - TRectype& rmov = _pn->cg(j); - - rmov.zero(); - rmov.put(RMV_ANNOES, _annoesch); //Compilo una riga di movimento - rmov.put(RMV_DATAREG, _dataregch); //per ogni sottoconto che leggo - rmov.put(RMV_GRUPPO, g); //sui saldi. Siccome queste - rmov.put(RMV_CONTO, c); //righe servono per mandare a 0 - rmov.put(RMV_SOTTOCONTO, s); //il saldo dei movimenti, la - rmov.put(RMV_SEZIONE, sez_rmov); //sezione sara' opposta a - rmov.put(RMV_IMPORTO, _saldo); //quella letta sui saldi. - rmov.put(RMV_NUMREG, _numreg); - rmov.put(RMV_NUMRIG, numrig); - rmov.put(RMV_TIPOC, tmcf); - - TBill tc(g,c,s); - _sld->aggiorna(tc,TImporto(sez_rmov,_saldo)); //l'oggetto TSaldo_agg - j++; - } - if (_saldi->eof()) break; - } //for saldi - if (j >= 1) - { - _pn->write(); - //_sld->registra(); - j = 0; - _pn->destroy_rows(0); //Azzero l'oggetto pn. - } - } // if (indbil == 4) - } // for pcon -} - -void CG4600_application::chiusura_conto_economico() -{ - _capitale_netto = _totale_saldo; //Mi serve per fare la riapertura del capitae netto - - if (_totale_saldo > ZERO) - { - int j; - - //Compilo la testata per perdite di es. c.economico a Profitti e Perdite - //Chiusura conto economico - - j = 0; - ultima_registrazione(); - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 3 Chiusura Conto Economico - - TRectype& rmov1 = _pn->cg(j); - long numrig = 1; - rmov_proper(_annoesch,numrig,_dataregch,rmov1,_tcproper,_totale_saldo,TRUE); - numrig++; - j++; - TRectype& rmov2 = _pn->cg(j); - rmov_proper(_annoesch,numrig,_dataregch,rmov2,_tcperde,_totale_saldo,FALSE); - - _pn->write(); - //_sld->registra(); - //_sld->reset(); - - //Compilo la testata per perdite di es. c.patrimon. a Perdita di es. c. econom. - //Chiusura capitale netto - - j = 0; - ultima_registrazione(); - _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. - - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 4 Chiusura Capitale netto - - TRectype& rmov3 = _pn->cg(j); - numrig = 1; - rmov_proper(_annoesch,numrig,_dataregch,rmov3,_tcperde,_totale_saldo,TRUE); - numrig++; - j++; - TRectype& rmov4 = _pn->cg(j); - rmov_proper(_annoesch,numrig,_dataregch,rmov4,_tcperdp,_totale_saldo,FALSE); - - _pn->write(); - } - else - if (_totale_saldo < ZERO) - { - int j; - - //Compilo la testata per Profitti e perdite a Utile di es. c.economico - //Chiusura conto economico - - j = 0; - ultima_registrazione(); - _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 3 Chiusura Conto Economico - - TRectype& rmov1 = _pn->cg(j); - long numrig = 1; - rmov_proper(_annoesch,numrig,_dataregch,rmov1,_tcutile,_totale_saldo,FALSE); - numrig++; - j++; - TRectype& rmov2 = _pn->cg(j); - rmov_proper(_annoesch,numrig,_dataregch,rmov2,_tcproper,_totale_saldo,TRUE); - - _pn ->write(); - //_sld->registra(); - //_sld->reset(); - - //Compilo la testata per Utile di es. c.economico a Utile di es. c.patrimoniale - //Chiusura capitale netto - - j = 0; - ultima_registrazione(); - _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 4 Chiusura Capitale netto - - TRectype& rmov3 = _pn->cg(j); - numrig = 1; - rmov_proper(_annoesch,numrig,_dataregch,rmov3,_tcutilp,_totale_saldo,FALSE); - numrig++; - j++; - TRectype& rmov4 = _pn->cg(j); - rmov_proper(_annoesch,numrig,_dataregch,rmov4,_tcutile,_totale_saldo,TRUE); - - _pn ->write(); - } -} - -void CG4600_application::chiudi_attivita() -{ - bool compila_mov = TRUE; - long s; - char sez_rmov = ' ', sezione = ' '; - real tot_saldo; - long numrig = 0; - TSaldo& sale = *_sale; - int j = 0; - - tot_saldo = ZERO; - - TRecnotype items_pcon = _cur->items(); - - for (int i = 0; i < items_pcon; i++, ++(*_cur)) - { - int indbil = _cur->curr().get_int(PCN_INDBIL); - int g = _cur->curr().get_int(PCN_GRUPPO); - int c = _cur->curr().get_int(PCN_CONTO); - TString tmcf = _cur->curr().get (PCN_TMCF); - - _prog->addstatus(1); - - if (indbil == 1) - { - compila_mov = TRUE; - - _saldi->setkey(1); - _saldi->zero(); - _saldi->put(SLD_ANNOES, _annoesch); - _saldi->put(SLD_GRUPPO, g); - _saldi->put(SLD_CONTO, c); - -// TRectype rec (_saldi->curr()); - *_rec = _saldi->curr(); - - j = 0; - numrig = 0; - - for (_saldi->read(_isgteq); ; _saldi->next()) - { - if (_saldi->curr() > (*_rec) || _saldi->eof()) - { - // Aggiungo un ulteriore riga di movimento contenente la somma - // di tutti i saldi aventi lo stesso conto, indicandola - // con una sezione opposta al risultato (della somma). - - if (j >= 1) - { - numrig++; - if (tot_saldo != ZERO) - rmov_proper(_annoesch,numrig,_dataregch,_pn->cg(j),_tcbilch,tot_saldo,FALSE); //Chiusura - - tot_saldo = ZERO; - } - break; - } - - if (compila_mov) - { - ultima_registrazione(); - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 5 Chiusura Attivita' - compila_mov = FALSE; - } - - //numrig++; - s = _saldi->get_long(SLD_SOTTOCONTO); - //sale.calcola_ultima_immissione(_annoesch,0,g,c,s,indbil); - sale.ultima_immissione_bilancio(_annoesch,g,c,s,indbil, 1); - _saldo = sale.saldo(); - //_saldo = ZERO; - const int dbkey = _saldi->getkey(); - _saldi->setkey(1); -// TString sldstr = _saldo.string(); - - if (_saldo == ZERO) continue; - - numrig++; - - if (j >= MAX || _saldi->eof()) - { - // Aggiungo un ulteriore riga di movimento contenente la somma - // di tutti i saldi aventi lo stesso sottoconto, indicandola - // con una sezione opposta al risultato (della somma). - - // numrig++; - if (tot_saldo != ZERO) - rmov_proper (_annoesch,numrig,_dataregch,_pn->cg(j),_tcbilch,tot_saldo,FALSE); //Chiusura - _pn->write(); - _pn->destroy_rows(0); //Azzero l'oggetto pn. - - j = 0; - numrig = 1; - ultima_registrazione(); - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 5 Chiusura Attivita' - compila_mov = FALSE; - tot_saldo = ZERO; - } - - if (_saldo > ZERO) - sezione = 'D'; - else - if (_saldo < ZERO) - { - sezione = 'A'; - _saldo = -_saldo; - } - - if (sezione == 'D') // ---> Tengo una variabile in cui salvo gli - { // importi trovati sui saldi. Quando ho - sez_rmov = 'A'; // finito di leggere i sottoconti, oppure - tot_saldo += _saldo; // quando ho raggiunto un massimo di 99 - _totale_saldo += _saldo; - } // righe di movimento, genero un' altra - else // riga con importo di sezione opposta - if (sezione == 'A') // alla somma, mandando a zero - { // il saldo di quel movimento. - sez_rmov = 'D'; - tot_saldo -= _saldo; - _totale_saldo -= _saldo; - } - - if (!_saldi->eof()) - { - TRectype& rmov = _pn->cg(j); - - rmov.zero(); - rmov.put(RMV_ANNOES, _annoesch); //Compilo una riga di movimento - rmov.put(RMV_DATAREG, _dataregch); //per ogni sottoconto che leggo - rmov.put(RMV_GRUPPO, g); //sui saldi. Siccome queste - rmov.put(RMV_CONTO, c); //righe servono per mandare a 0 - rmov.put(RMV_SOTTOCONTO, s); //il saldo dei movimenti, la - rmov.put(RMV_SEZIONE, sez_rmov); //sezione sara' opposta a - rmov.put(RMV_IMPORTO, _saldo); //quella letta sui saldi. - rmov.put(RMV_NUMREG, _numreg); - rmov.put(RMV_NUMRIG, numrig); - rmov.put(RMV_TIPOC, tmcf); - - TBill tc(g,c,s); - _sld->aggiorna(tc,TImporto(sez_rmov,_saldo)); //l'oggetto TSaldo_agg - - j++; - } - if (_saldi->eof()) break; - } //for saldi - if (j >= 1) - { - _pn->write(); - //_sld->registra(); - //_sld->reset(); - j = 0; - _pn->destroy_rows(0); //Azzero l'oggetto pn. - } - } // if (indbil == 1) - } // for pcon -} - -void CG4600_application::chiudi_passivita() -{ - bool compila_mov = TRUE; - long s; - char sez_rmov = ' ', sezione = ' '; - real tot_saldo; - long numrig = 0; - TSaldo& sale = *_sale; - int j = 0; - - tot_saldo = ZERO; - - TRecnotype items_pcon = _cur->items(); - - for (int i = 0; i < items_pcon; i++, ++(*_cur)) - { - int indbil = _cur->curr().get_int(PCN_INDBIL); - int g = _cur->curr().get_int(PCN_GRUPPO); - int c = _cur->curr().get_int(PCN_CONTO); - TString tmcf = _cur->curr().get (PCN_TMCF); - - _prog->addstatus(1); - - if (indbil == 2) - { - compila_mov = TRUE; - - _saldi->setkey(1); - _saldi->zero(); - _saldi->put(SLD_ANNOES, _annoesch); - _saldi->put(SLD_GRUPPO, g); - _saldi->put(SLD_CONTO, c); - - TRectype rec (_saldi->curr()); - - j = 0; - numrig = 0; - - for (_saldi->read(); ; _saldi->next()) - { - if (_saldi->curr() > rec || _saldi->eof()) - { - // Aggiungo un ulteriore riga di movimento contenente la somma - // di tutti i saldi aventi lo stesso conto, indicandola - // con una sezione opposta al risultato (della somma). - - if (j >= 1) - { - numrig++; - if (tot_saldo != ZERO) - rmov_proper(_annoesch,numrig,_dataregch,_pn->cg(j),_tcbilch,tot_saldo,FALSE); //Chiusura - - tot_saldo = ZERO; - } - break; - } - - if (compila_mov) - { - ultima_registrazione(); - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 6 Chiusura Passivita' - compila_mov = FALSE; - } - - //numrig++; - s = _saldi->get_long(SLD_SOTTOCONTO); - //sale.calcola_ultima_immissione(_annoesch,0,g,c,s,indbil); - sale.ultima_immissione_bilancio(_annoesch,g,c,s,indbil, 1); - _saldo = sale.saldo(); - - if (_saldo.is_zero()) continue; - - numrig++; - - if (j >= MAX || _saldi->eof()) - { - // Aggiungo un ulteriore riga di movimento contenente la somma - // di tutti i saldi aventi lo stesso sottoconto, indicandola - // con una sezione opposta al risultato (della somma). - - // numrig++; - if (tot_saldo != ZERO) - rmov_proper (_annoesch,numrig,_dataregch,_pn->cg(j),_tcbilch,tot_saldo,FALSE); //Chiusura - _pn->write(); - _pn->destroy_rows(0); //Azzero l'oggetto pn. - - j = 0; - numrig = 1; - ultima_registrazione(); - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 6 Chiusura Passivita' - compila_mov = FALSE; - tot_saldo = ZERO; - } - - if (_saldo > ZERO) - sezione = 'D'; - else - if (_saldo < ZERO) - { - sezione = 'A'; - _saldo = -_saldo; - } - - if (sezione == 'D') // ---> Tengo una variabile in cui salvo gli - { // importi trovati sui saldi. Quando ho - sez_rmov = 'A'; // finito di leggere i sottoconti, oppure - tot_saldo += _saldo; // quando ho raggiunto un massimo di 99 - _totale_saldo += _saldo; - } // righe di movimento, genero un' altra - else // riga con importo di sezione opposta - if (sezione == 'A') // alla somma, mandando a zero - { // il saldo di quel movimento. - sez_rmov = 'D'; - tot_saldo -= _saldo; - _totale_saldo -= _saldo; - } - - if (!_saldi->eof()) - { - TRectype& rmov = _pn->cg(j); - - rmov.zero(); - rmov.put(RMV_ANNOES, _annoesch); //Compilo una riga di movimento - rmov.put(RMV_DATAREG, _dataregch); //per ogni sottoconto che leggo - rmov.put(RMV_GRUPPO, g); //sui saldi. Siccome queste - rmov.put(RMV_CONTO, c); //righe servono per mandare a 0 - rmov.put(RMV_SOTTOCONTO, s); //il saldo dei movimenti, la - rmov.put(RMV_SEZIONE, sez_rmov); //sezione sara' opposta a - rmov.put(RMV_IMPORTO, _saldo); //quella letta sui saldi. - rmov.put(RMV_NUMREG, _numreg); - rmov.put(RMV_NUMRIG, numrig); - rmov.put(RMV_TIPOC, tmcf); - - TBill tc(g,c,s); - _sld->aggiorna(tc,TImporto(sez_rmov,_saldo)); //l'oggetto TSaldo_agg - - j++; - } - if (_saldi->eof()) break; - } //for saldi - if (j >= 1) - { - _pn->write(); - //_sld->registra(); - //_sld->reset(); - j = 0; - _pn->destroy_rows(0); - } - } // if (indbil == 2) - } // for pcon -} - -void CG4600_application::chiusura_conto_patrimoniale() -{ - int j; - long numrig; - - if (_totale_saldo > ZERO) - { - //Compilo la testata per Bilancio di chiusura a Perdita di es. c. patrimoniale - //Chiusura conto patrimoniale - - j = 0; - ultima_registrazione(); - _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 7 Chiusura Conto Patrimoniale - - TRectype& rmov1 = _pn->cg(j); - numrig = 1; - rmov_proper(_annoesch,numrig,_dataregch,rmov1,_tcutilp,_totale_saldo,FALSE); - numrig++; - j++; - TRectype& rmov2 = _pn->cg(j); - rmov_proper(_annoesch,numrig,_dataregch,rmov2,_tcbilch,_totale_saldo,TRUE); - - _pn->write(); - //_sld->registra(); - - } -else - if (_totale_saldo < ZERO) - { - //Compilo la testata per Utile di es. c.patrimon. a Bilancio di chiusura - //Chiusura conto patrimoniale - - j = 0; - ultima_registrazione(); - _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. - compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 7 Chiusura Conto Patrimoniale - - TRectype& rmov1 = _pn->cg(j); - numrig = 1; - rmov_proper(_annoesch,numrig,_dataregch,rmov1,_tcbilch,_totale_saldo,TRUE); - numrig++; - j++; - TRectype& rmov2 = _pn->cg(j); - rmov_proper(_annoesch,numrig,_dataregch,rmov2,_tcperdp,_totale_saldo,FALSE); - - _pn ->write(); - //_sld->registra(); - } -} - -void CG4600_application::apri_attivita() -{ - bool compila_mov = TRUE; - long s; - char sezione = ' '; - real tot_saldo; - long numrig = 0; - TSaldo& sale = *_sale; - int j = 0; - - tot_saldo = ZERO; - - TRecnotype items_pcon = _cur->items(); - - for (int i = 0; i < items_pcon; i++, ++(*_cur)) - { - int indbil = _cur->curr().get_int(PCN_INDBIL); - int g = _cur->curr().get_int(PCN_GRUPPO); - int c = _cur->curr().get_int(PCN_CONTO); - TString tmcf = _cur->curr().get (PCN_TMCF); - - _prog->addstatus(1); - - if (indbil == 1) - { - compila_mov = TRUE; - - _saldi->setkey(1); - _saldi->zero(); - _saldi->put(SLD_ANNOES, _annoesch); - _saldi->put(SLD_GRUPPO, g); - _saldi->put(SLD_CONTO, c); - - TRectype rec (_saldi->curr()); - - j = 0; - numrig = 0; - - for (_saldi->read(); ; _saldi->next()) - { - if (_saldi->curr() > rec || _saldi->eof()) - { - // Aggiungo un ulteriore riga di movimento contenente la somma - // di tutti i saldi aventi lo stesso conto, indicandola - // con una sezione opposta al risultato (della somma). - - if (j >= 1) - { - numrig++; - if (tot_saldo != ZERO) - rmov_proper(_annoesap,numrig,_dataregap,_pn->cg(j),_tcbilap,tot_saldo,TRUE); //Apertura - - tot_saldo = ZERO; - } - break; - } - - if (compila_mov) - { - ultima_registrazione(); - compila_testata(_annoesap,_dataregap,_codcausap); //Reg. 8 Apertura Attivita' - compila_mov = FALSE; - } - - //numrig++; - s = _saldi->get_long(SLD_SOTTOCONTO); - sale.ultima_immissione_bilancio(_annoesch,g,c,s,indbil, 1); - _saldo = sale.saldo(); - - if (_saldo == ZERO) continue; - - numrig++; - - if (j >= MAX || _saldi->eof()) - { - // Aggiungo un ulteriore riga di movimento contenente la somma - // di tutti i saldi aventi lo stesso sottoconto, indicandola - // con una sezione opposta al risultato (della somma). - - if (tot_saldo != ZERO) - rmov_proper (_annoesap,numrig,_dataregap,_pn->cg(j),_tcbilap,tot_saldo,TRUE); //Chiusura - _pn->write(); - _pn->destroy_rows(0); //Azzero l'oggetto pn. - - j = 0; - numrig = 1; - ultima_registrazione(); - compila_testata(_annoesap,_dataregap,_codcausap); //Reg. 8 Apertura Attivita' - compila_mov = FALSE; - tot_saldo = ZERO; - } - - if (_saldo > ZERO) - sezione = 'D'; - else - if (_saldo < ZERO) - { - sezione = 'A'; - _saldo = -_saldo; - } - - if (sezione == 'D') // ---> Tengo una variabile in cui salvo gli - { // importi trovati sui saldi. Quando ho - tot_saldo += _saldo; // quando ho raggiunto un massimo di 99 - _totale_saldo += _saldo; - } // righe di movimento, genero un' altra - else // riga con importo di sezione opposta - if (sezione == 'A') // alla somma, mandando a zero - { // il saldo di quel movimento. - tot_saldo -= _saldo; - _totale_saldo -= _saldo; - } - - if (!_saldi->eof()) - { - TRectype& rmov = _pn->cg(j); - - rmov.zero(); - rmov.put(RMV_ANNOES, _annoesap); //Compilo una riga di movimento - rmov.put(RMV_DATAREG, _dataregap); //per ogni sottoconto che leggo - rmov.put(RMV_GRUPPO, g); //sui saldi. Siccome queste - rmov.put(RMV_CONTO, c); //righe servono per mandare a 0 - rmov.put(RMV_SOTTOCONTO, s); //il saldo dei movimenti, la - rmov.put(RMV_SEZIONE, sezione); //sezione sara' opposta a - rmov.put(RMV_IMPORTO, _saldo); //quella letta sui saldi. - rmov.put(RMV_NUMREG, _numreg); - rmov.put(RMV_NUMRIG, numrig); - rmov.put(RMV_TIPOC, tmcf); - - TBill tc(g,c,s); - _sld->aggiorna(tc,TImporto(sezione,_saldo)); //l'oggetto TSaldo_agg - - j++; - } - if (_saldi->eof()) break; - } //for saldi - if (j >= 1) - { - _pn->write(); - j = 0; - _pn->destroy_rows(0); //Azzero l'oggetto pn. - } - } // if (indbil == 1) - } // for pcon -} - -void CG4600_application::apri_passivita() -{ - bool compila_mov = TRUE; - long s; - char sezione = ' '; - real tot_saldo; - long numrig = 0; - TSaldo& sale = *_sale; - int j = 0; - - tot_saldo = ZERO; - - TRecnotype items_pcon = _cur->items(); - - for (int i = 0; i < items_pcon; i++, ++(*_cur)) - { - int indbil = _cur->curr().get_int(PCN_INDBIL); - int g = _cur->curr().get_int(PCN_GRUPPO); - int c = _cur->curr().get_int(PCN_CONTO); - TString tmcf = _cur->curr().get (PCN_TMCF); - - _prog->addstatus(1); - - if (indbil == 2) - { - compila_mov = TRUE; - - _saldi->setkey(1); - _saldi->zero(); - _saldi->put(SLD_ANNOES, _annoesch); - _saldi->put(SLD_GRUPPO, g); - _saldi->put(SLD_CONTO, c); - - TRectype rec (_saldi->curr()); - - j = 0; - numrig = 0; - - for (_saldi->read(); ; _saldi->next()) - { - if (_saldi->curr() > rec || _saldi->eof()) - { - // Aggiungo un ulteriore riga di movimento contenente la somma - // di tutti i saldi aventi lo stesso conto, indicandola - // con una sezione opposta al risultato (della somma). - - if (j >= 1) - { - numrig++; - if (tot_saldo != ZERO) - rmov_proper(_annoesap,numrig,_dataregap,_pn->cg(j),_tcbilap,tot_saldo,TRUE); //Apertura - - tot_saldo = ZERO; - } - break; - } - - if (compila_mov) - { - ultima_registrazione(); - compila_testata(_annoesap,_dataregap,_codcausap); //Reg. 9 Apertura Passivita' - compila_mov = FALSE; - } - - //numrig++; - s = _saldi->get_long(SLD_SOTTOCONTO); - sale.ultima_immissione_bilancio(_annoesch,g,c,s,indbil, 1); - _saldo = sale.saldo(); - - if (_saldo.is_zero()) continue; - - numrig++; - - if (j >= MAX || _saldi->eof()) - { - // Aggiungo un ulteriore riga di movimento contenente la somma - // di tutti i saldi aventi lo stesso sottoconto, indicandola - // con una sezione opposta al risultato (della somma). - - if (tot_saldo != ZERO) - rmov_proper (_annoesap,numrig,_dataregap,_pn->cg(j),_tcbilap,tot_saldo,TRUE); //Apertura - _pn->write(); - _pn->destroy_rows(0); //Azzero l'oggetto pn. - - j = 0; - numrig = 1; - ultima_registrazione(); - compila_testata(_annoesap,_dataregap,_codcausap); //Reg. 9 Apertura Passivita' - compila_mov = FALSE; - tot_saldo = ZERO; - } - - if (_saldo > ZERO) - sezione = 'D'; - else - if (_saldo < ZERO) - { - sezione = 'A'; - _saldo = -_saldo; - } - - if (sezione == 'D') // ---> Tengo una variabile in cui salvo gli - { // importi trovati sui saldi. Quando ho - tot_saldo += _saldo; // finito di leggere i sottoconti, oppure - _totale_saldo += _saldo; // quando ho raggiunto un massimo di 99 - } // righe di movimento, genero un' altra - else // riga con importo di sezione opposta - if (sezione == 'A') // alla somma, mandando a zero - { // il saldo di quel movimento. - tot_saldo -= _saldo; - _totale_saldo -= _saldo; - } - - if (!_saldi->eof()) - { - TRectype& rmov = _pn->cg(j); - - rmov.zero(); - rmov.put(RMV_ANNOES, _annoesap); //Compilo una riga di movimento - rmov.put(RMV_DATAREG, _dataregap); //per ogni sottoconto che leggo - rmov.put(RMV_GRUPPO, g); //sui saldi. Siccome queste - rmov.put(RMV_CONTO, c); //righe servono per mandare a 0 - rmov.put(RMV_SOTTOCONTO, s); //il saldo dei movimenti, la - rmov.put(RMV_SEZIONE, sezione); //sezione sara' opposta a - rmov.put(RMV_IMPORTO, _saldo); //quella letta sui saldi. - rmov.put(RMV_NUMREG, _numreg); - rmov.put(RMV_NUMRIG, numrig); - rmov.put(RMV_TIPOC, tmcf); - - TBill tc(g,c,s); - _sld->aggiorna(tc,TImporto(sezione,_saldo)); //l'oggetto TSaldo_agg - - j++; - } - if (_saldi->eof()) break; - } //for saldi - if (j >= 1) - { - _pn->write(); - j = 0; - _pn->destroy_rows(0); - } - } // if (indbil == 2) - } // for pcon -} - -void CG4600_application::apertura_capitale_netto() -{ - int numrig; - - if (_capitale_netto > ZERO) - { - //Compilo la testata per Perdita es. c/to patrimoniale a Bilancio di apertura - //Apertura capitale netto - - int j = 0; - ultima_registrazione(); - _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. - - compila_testata(_annoesap,_dataregap,_codcausap); //Reg. 10 Apertura Capitale netto - - TRectype& rmov1 = _pn->cg(j); - numrig = 1; - rmov_proper(_annoesap,numrig,_dataregap,rmov1,_tcbilap,_capitale_netto,TRUE); - numrig++; - j++; - TRectype& rmov2 = _pn->cg(j); - rmov_proper(_annoesap,numrig,_dataregap,rmov2,_tcperdp,_capitale_netto,FALSE); - - _pn->write(); - } - else - if (_capitale_netto < ZERO) - { - //Compilo la testata per Bilancio di apertura a Utile es. c/to patrimoniale - //Apertura capitale netto - - int j = 0; - ultima_registrazione(); - _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. - - compila_testata(_annoesap,_dataregap,_codcausap); //Reg. 10 Apertura Capitale netto - - TRectype& rmov1 = _pn->cg(j); - numrig = 1; - rmov_proper(_annoesap,numrig,_dataregap,rmov1,_tcbilap,_capitale_netto,TRUE); - numrig++; - j++; - TRectype& rmov2 = _pn->cg(j); - rmov_proper(_annoesap,numrig,_dataregap,rmov2,_tcutilp,_capitale_netto,FALSE); - - _pn->write(); - } -} - -bool CG4600_application::menu(MENU_TAG m) -{ - if (m == BAR_ITEM(1)) - return set(); - return FALSE; -} - -int cg4600 (int argc, char* argv[]) -{ - CG4600_application main_app; - main_app.run(argc, argv, "Apertura/Chiusura Conti"); - return TRUE; -} - - - - - - - +// Chiusura/Apertura Conti + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cglib.h" +#include "cg4.h" +#include "cg4600.h" +#include "cg2101.h" + +#include +#include +#include +#include + +bool mask_datac (TMask_field&, KEY); +bool mask_dataap (TMask_field&, KEY); +bool mask_distinti (TMask_field&, KEY); +bool attivo_passivo(TMask_field&, KEY); +bool costi_ricavi (TMask_field&, KEY); + +#define MAX 98 + +class CG4600_application : public TApplication +{ + friend bool mask_datac (TMask_field&, KEY); + friend bool mask_dataap (TMask_field&, KEY); + friend bool mask_distinti (TMask_field&, KEY); + + TTable* _esc, * _reg; + TRelation* _rel; + TMovimentoPN* _pn; + TLocalisamfile* _saldi; + TRectype* _rec; + TLocalisamfile* _mov; + TCursor* _cur; + TSaldo_agg* _sld; + TSaldo* _sale; + TProgind* _prog; + TConto _tcbilch,_tcproper,_tcbilap,_tcutilp,_tcperdp,_tcutile,_tcperde, _conto_corrente; + + real _saldo, _totale_saldo, _capitale_netto; + int _annoesch, _annoesap; + long _numreg; + TDate _dataregap, _dataregch; + TString _codcausap, _codcausch; + +public: + virtual bool create(); + virtual bool destroy(); + virtual bool menu(MENU_TAG m); + void costi (); + void ricavi(); + void chiudi_attivita(); + void chiudi_passivita(); + void apri_attivita(); + void apri_passivita(); + void rmov_proper (int, long, TDate&, TRectype&, TConto&, real&, bool); + void ultima_registrazione(); + void compila_testata(int,TDate&,TString&); + void chiusura_conto_economico(); + void chiusura_conto_patrimoniale(); + void apertura_capitale_netto(); + bool set(); + // bool epilogo_conti(); + + CG4600_application() {} +}; + +HIDDEN bool abilita_anni(TMask& m, KEY k) +{ + if (k == K_SHIFT+K_F12) + { + m.enable(F_ANNOCH); + m.enable(F_ANNO); + } + + return TRUE; +} + +HIDDEN bool anni_contigui (int annoch, int annoap) +{ + TString16 dep(format("%04d", annoch)); + + TTable esc ("ESC"); + + esc.zero(); + esc.put("CODTAB", dep); + esc.read(); + esc.next(); + int anno = atoi(esc.get("CODTAB")); + if (anno != annoap) + return warning_box("I due esercizi indicati non risultano contigui"); + + return TRUE; +} + +HIDDEN TRectype& cerca_esercizio(int anno) +{ + TTable TabEs ("ESC"); + TString16 dep (format("%04d", anno)); + + TabEs.zero(); + TabEs.put("CODTAB", dep); + if (TabEs.read() == NOERR) + return TabEs.curr(); + else + warning_box("Esercizio non presente in tabella esercizi"); + + TabEs.zero(); + + return TabEs.curr(); +} + +bool mask_datac (TMask_field& f, KEY k) +{ + //TTable TabEs ("ESC"); + TTable TabReg("REG"); + TString annos (4); + int anno = 0;; + bool ok = TRUE; + + if ( (k == K_ENTER) && f.to_check(k) ) + { + int annoch = f.mask().get_int(F_ANNOCH); + int annoap = f.mask().get_int(F_ANNO); + + if (!anni_contigui(annoch,annoap)) + return FALSE; + + TRectype TabEsch = cerca_esercizio(annoap); + TDate inizio = TabEsch.get_date("D0"); + TDate fine = TabEsch.get_date("D1"); + TDate scarico = TabEsch.get_date("D2"); + + TRectype TabEsap = cerca_esercizio(annoch); + TDate iniziop = TabEsap.get_date("D0"); + TDate finep = TabEsap.get_date("D1"); + TDate data = f.get(); +/* + TabEs.last(); + TDate inizio = TabEs.get_date("D0"); + TDate fine = TabEs.get_date("D1"); + TDate scarico = TabEs.get_date("D2"); + TabEs.prev(); + TDate iniziop = TabEs.get_date("D0"); + TDate finep = TabEs.get_date("D1"); + TDate data = f.get(); +*/ + TString istr = inizio.string(); + TString fstr = fine.string(); + + TString ipstr = iniziop.string(); + TString fpstr = finep.string(); + + TString scastr = scarico.string(); + + TString datastr = f.get(); + + if (data < finep) + { + f.warning_box ("La data di chiusura non puo' essere inferiore alla data di fine esercizio precedente"); + return FALSE; + } + if (data > fine) + { + f.warning_box ("La data di chiusura non puo' essere superiore alla data di fine esercizio in corso"); + return FALSE; + } + if ( scarico.ok() && (data <= scarico) ) + { + f.warning_box ("La data di chiusura non puo' essere inferiore o uguale alla data di scarico"); + return FALSE; + } + if ( (data >= inizio) && (data <= fine) ) //la data di chiusura e' cioe' relativa all'esercizio in corso + anno = fine.year(); + else if ( (data >= iniziop) && (data <= finep) ) //la data di chiusura e' cioe' relativa all'esercizio precedente + anno = finep.year(); + + TabReg.zero(); + annos = format ("%04d", anno); + TabReg.put ("CODTAB", annos); + TRectype r (TabReg.curr()); + TabReg.read(_isgteq); + for (; !TabReg.eof(); TabReg.next()) + { + if (TabReg.curr() != r) break; + + int tiporeg = TabReg.get_int("I0"); + if (tiporeg == 5) + { + TDate datast = TabReg.get_date("D3"); + if (data < datast.string()) + { + ok = FALSE; + break; + } + } + } + if (!ok) + { + f.warning_box("La data di chiusura non puo' essere inferiore alla data ultima stampa bollato"); + return FALSE; + } + } + return TRUE; +} + +bool mask_dataap (TMask_field& f, KEY k) +{ + TTable TabEs ("ESC"); + TTable TabReg("REG"); + int anno = 0; + TString annos (4); + bool ok = TRUE; + + if ( (k == K_ENTER) && f.to_check(k) ) + { + int annoch = f.mask().get_int(F_ANNOCH); + int annoap = f.mask().get_int(F_ANNO); + + if (!anni_contigui(annoch,annoap)) + return FALSE; + + TRectype TabEsch = cerca_esercizio(annoap); + TDate inizio = TabEsch.get_date("D0"); + TDate fine = TabEsch.get_date("D1"); + TDate scarico = TabEsch.get_date("D2"); + + TRectype TabEsap = cerca_esercizio(annoch); + TDate iniziop = TabEsap.get_date("D0"); + TDate finep = TabEsap.get_date("D1"); + TDate data = f.get(); +/* + TabEs.last(); + TDate inizio = TabEs.get_date("D0"); + TDate fine = TabEs.get_date("D1"); + TDate scarico = TabEs.get_date("D2"); + TabEs.prev(); + TDate iniziop = TabEs.get_date("D0"); + TDate finep = TabEs.get_date("D1"); + TDate data = f.get(); +*/ + TString istr = inizio.string(); + TString fstr = fine.string(); + + TString ipstr = iniziop.string(); + TString fpstr = finep.string(); + + TString scastr = scarico.string(); + + TString datastr = f.get(); + + if (data < inizio) + { + f.warning_box ("La data di apertura non puo' essere inferiore alla data di inizio esercizio in corso"); + return FALSE; + } + if (data > fine) + { + f.warning_box ("La data di apertura non puo' essere superiore alla data di fine esercizio in corso"); + return FALSE; + } + if ( scarico.ok() && (data <= scarico) ) + { + f.warning_box ("La data di apertura non puo' essere inferiore o uguale alla data di scarico"); + return FALSE; + } + + if ( (data >= inizio) && (data <= fine) ) //la data di apertura e' cioe' relativa all'esercizio in corso + anno = fine.year(); + else if( (data >= iniziop) && (data <= finep) ) //la data di apertura e' cioe' relativa all'esercizio precedente + anno = finep.year(); + + TabReg.zero(); + annos = format ("%04d", anno); + TabReg.put ("CODTAB", annos); + TRectype r (TabReg.curr()); + TabReg.read(_isgteq); + for (; !TabReg.eof(); TabReg.next()) + { + if (TabReg.curr() != r) break; + + int tiporeg = TabReg.get_int("I0"); + if (tiporeg == 5) + { + TDate datast = TabReg.get_date("D3"); + if (data < datast) + { + ok = FALSE; + break; + } + } + } + if (!ok) + { + f.warning_box("La data di apertura non puo' essere inferiore alla data ultima stampa bollato"); + return FALSE; + } + } + return TRUE; +} + +bool mask_distinti (TMask_field& f, KEY k) +{ + int idg,idc,ids,idg1,idc1,ids1; + + if (k == K_ENTER) + { + idg = 108; + idc = 109; + ids = 110; + + for (int i = 0; i < 7; i++) + { + int g = f.mask().get_int(idg); + int c = f.mask().get_int(idc); + long s = f.mask().get_long(ids); + + idg1 = idg; + idc1 = idc; + ids1 = ids; + + for (int j = i+1; j < 7; j++) + { + idg1 = idg1 + 3; + idc1 = idc1 + 3; + ids1 = ids1 + 3; + + int gruppo = f.mask().get_int(idg1); + int conto = f.mask().get_int(idc1); + long sottoc = f.mask().get_long(ids1); + + if ((g == gruppo)&&(c == conto)&&(s == sottoc)) + { + f.warning_box("Nessun sottoconto puo' essere ripetuto!"); + return FALSE; + } + } + + idg = idg + 3; + idc = idc + 3; + ids = ids + 3; + + } + } + return TRUE; +} + +bool attivo_passivo (TMask_field& f, KEY k) +{ + TLocalisamfile pcon (LF_PCON); + + if (k == K_ENTER) + { + int g,c; + int id = f.dlg(); + + if (id == F_UTILPC) + g = f.mask().get_int(F_UTILPG); + else + if (id == F_PERDPC) + g = f.mask().get_int(F_PERDPG); + + c = atoi(f.get()); + + pcon.setkey(1); + pcon.zero(); + pcon.put(PCN_GRUPPO, g); + pcon.put(PCN_CONTO, c); + if (pcon.read() == NOERR) + { + int indbil = pcon.get_int(PCN_INDBIL); + if (indbil != 1 && indbil != 2 && indbil != 5) + return f.warning_box("Indicatore di bilancio errato"); + } + } + return TRUE; +} + +bool costi_ricavi (TMask_field& f, KEY k) +{ + TLocalisamfile pcon (LF_PCON); + + if (k == K_ENTER) + { + int g,c; + int id = f.dlg(); + + if (id == F_UTILEC) + g = f.mask().get_int(F_UTILEG); + else + if (id == F_PERDEC) + g = f.mask().get_int(F_PERDEG); + + c = atoi(f.get()); + + pcon.setkey(1); + pcon.zero(); + pcon.put(PCN_GRUPPO, g); + pcon.put(PCN_CONTO, c); + if (pcon.read() == NOERR) + { + int indbil = pcon.get_int(PCN_INDBIL); + if (indbil != 3 && indbil != 4) + return f.warning_box("Indicatore di bilancio errato"); + } + } + return TRUE; +} + +bool CG4600_application::create() +{ + TApplication::create(); + + _rel = new TRelation (LF_PCON); + + _cur = new TCursor(_rel,"((GRUPPO!=\"\")&&(CONTO!=\"\")&&(SOTTOCONTO==\"\"))",1); + + _pn = new TMovimentoPN(); + _saldi = new TLocalisamfile (LF_SALDI); + _rec = new TRectype(LF_SALDI); + _mov = new TLocalisamfile (LF_MOV); + _esc = new TTable ("ESC"); + _reg = new TTable ("REG"); + _sld = new TSaldo_agg(); + _sale = new TSaldo(); + + _capitale_netto = ZERO; + + dispatch_e_menu (BAR_ITEM(1)); + + return TRUE; +} + +bool CG4600_application::destroy() +{ + delete _saldi; + delete _sale; + delete _mov; + delete _esc; + delete _reg; + delete _pn; + delete _rel; + delete _cur; + delete _sld; + delete _rec; + + return TApplication::destroy(); +} + +void CG4600_application::ultima_registrazione() +{ + long numregmov; + + _mov->setkey(1); //Leggo il numero di registrazione + _mov->last(); //dell'ultimo record di mov, e lo + numregmov = _mov->get_long(MOV_NUMREG); //incremento di uno per ottenere + _numreg = numregmov + 1; //un numero di registrazione + //sicuramente non esistente. +} + +bool CG4600_application::set() +{ + TTable TabEs ("ESC"); + TMask m ("cg4600a"); + KEY tasto; + int gbilch, cbilch , gproper, cproper, gbilap, cbilap, gutilp; + int cutilp, gperdp, cperdp, gutile, cutile, gperde, cperde; + long sbilch, sproper, sbilap, sutilp, sperdp, sutile, sperde; + + + TConfig conf(CONFIG_DITTA); + + m.set(F_CHIUSURA, conf.get("CoCaCh")); + m.set(F_APERTURA, conf.get("CoCaAp")); + + TabEs.last(); + int annoap = TabEs.get_int ("CODTAB"); + TDate inizio = TabEs.get_date("D0"); //data inizio es. in corso + TabEs.prev(); + int annoch = TabEs.get_int ("CODTAB"); + TDate fine = TabEs.get_date("D1"); //data fine es. precedente + m.set(F_ANNO, annoap); + m.set(F_ANNOCH, annoch); + m.set(F_DATAC, fine.string()); + m.set(F_DATAAP,inizio.string()); + + m.set(F_BILCHG, conf.get("CsBiChG")); + m.set(F_BILCHC, conf.get("CsBiChC")); + m.set(F_BILCHS, conf.get("CsBiChS")); + m.set(F_PROPERG, conf.get("CsPrPeG")); + m.set(F_PROPERC, conf.get("CsPrPeC")); + m.set(F_PROPERS, conf.get("CsPrPeS")); + m.set(F_BILAPG, conf.get("CsBiApG")); + m.set(F_BILAPC, conf.get("CsBiApC")); + m.set(F_BILAPS, conf.get("CsBiApS")); + m.set(F_UTILPG, conf.get("CsUeCpG")); + m.set(F_UTILPC, conf.get("CsUeCpC")); + m.set(F_UTILPS, conf.get("CsUeCpS")); + m.set(F_PERDPG, conf.get("CsPeCpG")); + m.set(F_PERDPC, conf.get("CsPeCpC")); + m.set(F_PERDPS, conf.get("CsPeCpS")); + m.set(F_UTILEG, conf.get("CsUeCeG")); + m.set(F_UTILEC, conf.get("CsUeCeC")); + m.set(F_UTILES, conf.get("CsUeCeS")); + m.set(F_PERDEG, conf.get("CsPeCeG")); + m.set(F_PERDEC, conf.get("CsPeCeC")); + m.set(F_PERDES, conf.get("CsPeCeS")); + + m.set_handler (F_DATAC, mask_datac); + m.set_handler (F_DATAAP, mask_dataap); + m.set_handler (F_PERDES, mask_distinti); + m.set_handler (F_UTILPC, attivo_passivo); + m.set_handler (F_PERDPC, attivo_passivo); + m.set_handler (F_UTILEC, costi_ricavi); + m.set_handler (F_PERDEC, costi_ricavi); + m.set_handler (abilita_anni); + + tasto = m.run(); + + if (tasto == K_ENTER) + { + _annoesch = m.get_int(F_ANNOCH); + _annoesap = m.get_int(F_ANNO); + _dataregch = m.get (F_DATAC); + _codcausch = m.get (F_CHIUSURA); + _dataregap = m.get (F_DATAAP); + _codcausap = m.get (F_APERTURA); + gbilch = m.get_int (F_BILCHG); + cbilch = m.get_int (F_BILCHC); + sbilch = m.get_long(F_BILCHS); + gproper = m.get_int (F_PROPERG); + cproper = m.get_int (F_PROPERC); + sproper = m.get_long(F_PROPERS); + gbilap = m.get_int (F_BILAPG); + cbilap = m.get_int (F_BILAPC); + sbilap = m.get_long(F_BILAPS); + gutilp = m.get_int (F_UTILPG); + cutilp = m.get_int (F_UTILPC); + sutilp = m.get_long(F_UTILPS); + gperdp = m.get_int (F_PERDPG); + cperdp = m.get_int (F_PERDPC); + sperdp = m.get_long(F_PERDPS); + gutile = m.get_int (F_UTILEG); + cutile = m.get_int (F_UTILEC); + sutile = m.get_long(F_UTILES); + gperde = m.get_int (F_PERDEG); + cperde = m.get_int (F_PERDEC); + sperde = m.get_long(F_PERDES); + + _tcbilch.set (gbilch,cbilch,sbilch); + _tcproper.set(gproper,cproper,sproper); + _tcbilap.set (gbilap,cbilap,sbilap); + _tcutilp.set (gutilp,cutilp,sutilp); + _tcperdp.set (gperdp,cperdp,sperdp); + _tcutile.set (gutile,cutile,sutile); + _tcperde.set (gperde,cperde,sperde); + + long cicli = (_cur->items() * 6) + 4; + _prog = new TProgind(cicli,"Chiusura/Apertura conti in corso... Prego attendere",FALSE); + + //ultima_registrazione(); + // anno_ese_precedente(); + + _numreg = 0; + + (*_cur) = 0L; + + _sld->set_anno_es(_annoesch); + _sld->set_movprovv(FALSE); + _sld->set_movap(FALSE); + + _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. + costi (); + + //_sld->reset(); //Azzera la tabella dei conti dell'oggetto TSaldo_agg + //ultima_registrazione(); + _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. + *_cur = 0l; + + ricavi(); + //_sld->reset(); + + chiusura_conto_economico(); + _totale_saldo = ZERO; + //_sld->reset(); + + //ultima_registrazione(); + _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. + *_cur = 0l; + + chiudi_attivita(); + //_sld->reset(); + + //ultima_registrazione(); + _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. + *_cur = 0l; + + chiudi_passivita(); + //_sld->reset(); + chiusura_conto_patrimoniale(); + _totale_saldo = ZERO; + + _sld->set_anno_es(_annoesap); + _sld->set_movap(TRUE); + _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. + *_cur = 0l; + + apri_attivita(); + + _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. + *_cur = 0l; + + apri_passivita(); + + apertura_capitale_netto(); + + _sld->registra(); + + delete _prog; + + message_box("Apertura/chiusura conti completata"); + + return FALSE; + } //K_ENTER + return FALSE; +} + +void CG4600_application::compila_testata(int annoes,TDate& datareg,TString& codcaus) +{ + _pn->lfile().zero(); + _pn->lfile().put(MOV_ANNOES, annoes); //Viene generato un movimento + _pn->lfile().put(MOV_DATAREG, datareg); //a rottura di conto + _pn->lfile().put(MOV_CODCAUS, codcaus); + _pn->lfile().put(MOV_NUMREG, _numreg); + _pn->lfile().put(MOV_DATACOMP, datareg); +} + +void CG4600_application::rmov_proper(int anno,long numrig,TDate& datareg,TRectype& rmov, + TConto& tc,real& tot_saldo,bool sezione_opposta) +{ + char sez_rmov = ' '; + char sezione = ' '; + real totale = tot_saldo; + + rmov.zero(); + rmov.put(RMV_ANNOES, anno); + rmov.put(RMV_NUMREG, _numreg); + rmov.put(RMV_NUMRIG, numrig); + rmov.put(RMV_DATAREG, datareg); + rmov.put(RMV_GRUPPO, tc.gruppo()); + rmov.put(RMV_CONTO, tc.conto()); + rmov.put(RMV_SOTTOCONTO, tc.sottoconto()); + + if (totale > ZERO) + { + sez_rmov = 'A'; + sezione = 'D'; + } + else + if (totale < ZERO) + { + sez_rmov = 'D'; + sezione = 'A'; + totale = -totale; + } + + if (sezione_opposta) + { + rmov.put(RMV_SEZIONE, sez_rmov); + _sld->aggiorna(tc,TImporto(sez_rmov,totale)); //Aggiorno anche i saldi con + // l'oggetto TSaldo_agg + } + else + { + rmov.put(RMV_SEZIONE, sezione); + _sld->aggiorna(tc,TImporto(sezione,totale)); //Aggiorno anche i saldi con + //l'oggetto TSaldo_agg + } + rmov.put(RMV_IMPORTO, totale); +} + +void CG4600_application::costi() +{ + bool compila_mov = TRUE; + long s; + char sez_rmov = ' ', sezione = ' '; + real tot_saldo; + long numrig = 0; + TSaldo& sale = *_sale; + int j = 0; + + _totale_saldo = ZERO; + tot_saldo = ZERO; + + TRecnotype items_pcon = _cur->items(); + + for (int i = 0; i < items_pcon; i++, ++(*_cur)) + { + int indbil = _cur->curr().get_int(PCN_INDBIL); + int g = _cur->curr().get_int(PCN_GRUPPO); + int c = _cur->curr().get_int(PCN_CONTO); + TString tmcf = _cur->curr().get (PCN_TMCF); + + _prog->addstatus(1); + + if (indbil == 3) + { + compila_mov = TRUE; + + _saldi->setkey(1); + _saldi->zero(); + _saldi->put(SLD_ANNOES, _annoesch); + _saldi->put(SLD_GRUPPO, g); + _saldi->put(SLD_CONTO, c); + + (*_rec) = _saldi->curr(); + + j = 0; + numrig = 0; + + for (_saldi->read(); ; _saldi->next()) + { + _saldo = ZERO; + + if (_saldi->curr() > (*_rec) || _saldi->eof()) + { + // Aggiungo un ulteriore riga di movimento contenente la somma + // di tutti i saldi aventi lo stesso conto, indicandola + // con una sezione opposta al risultato (della somma). + + if (j >= 1) + { + numrig++; + if (tot_saldo != ZERO) + rmov_proper(_annoesch,numrig,_dataregch,_pn->cg(j),_tcproper,tot_saldo,FALSE); + + tot_saldo = ZERO; + } + break; + } + + if (compila_mov) + { + ultima_registrazione(); + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 1 Chiusura Costi + compila_mov = FALSE; + } + + //numrig++; + s = _saldi->get_long(SLD_SOTTOCONTO); + //sale.calcola_ultima_immissione(_annoesch,0,g,c,s,indbil); + sale.ultima_immissione_bilancio(_annoesch,g,c,s,indbil, 1); + _saldo = sale.saldo(); + + if (_saldo.is_zero()) continue; + + numrig++; + + if (j >= MAX || _saldi->eof()) + { + // Aggiungo un ulteriore riga di movimento contenente la somma + // di tutti i saldi aventi lo stesso sottoconto, indicandola + // con una sezione opposta al risultato (della somma). + + // numrig++; + if (tot_saldo != ZERO) + rmov_proper (_annoesch,numrig,_dataregch,_pn->cg(j),_tcproper,tot_saldo,FALSE); + _pn->write(); + _pn->destroy_rows(0); //Azzero l'oggetto pn. + + j = 0; + numrig = 1; + ultima_registrazione(); + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 1 Chiusura Costi + compila_mov = FALSE; + tot_saldo = ZERO; + } + + if (_saldo > ZERO) + sezione = 'D'; + else + if (_saldo < ZERO) + { + sezione = 'A'; + _saldo = -_saldo; + } + + if (sezione == 'D') // ---> Tengo una variabile in cui salvo gli + { // importi trovati sui saldi. Quando ho + sez_rmov = 'A'; // finito di leggere i sottoconti, oppure + tot_saldo += _saldo; // quando ho raggiunto un massimo di 99 + _totale_saldo += _saldo; + } // righe di movimento, genero un' altra + else // riga con importo di sezione opposta + if (sezione == 'A') // alla somma, mandando a zero + { // il saldo di quel movimento. + sez_rmov = 'D'; + tot_saldo -= _saldo; + _totale_saldo -= _saldo; + } + + if (!_saldi->eof()) + { + TRectype& rmov = _pn->cg(j); + + rmov.zero(); + rmov.put(RMV_ANNOES, _annoesch); //Compilo una riga di movimento + rmov.put(RMV_DATAREG, _dataregch); //per ogni sottoconto che leggo + rmov.put(RMV_GRUPPO, g); //sui saldi. Siccome queste + rmov.put(RMV_CONTO, c); //righe servono per mandare a 0 + rmov.put(RMV_SOTTOCONTO, s); //il saldo dei movimenti, la + rmov.put(RMV_SEZIONE, sez_rmov); //sezione sara' opposta a + rmov.put(RMV_IMPORTO, _saldo); //quella letta sui saldi. + rmov.put(RMV_NUMREG, _numreg); + rmov.put(RMV_NUMRIG, numrig); + rmov.put(RMV_TIPOC, tmcf); + + TBill tc(g,c,s); + _sld->aggiorna(tc,TImporto(sez_rmov,_saldo)); //l'oggetto TSaldo_agg + j++; + } + if (_saldi->eof()) break; + } //for saldi + if (j >= 1) + { + _pn->write(); + //_sld->registra(); + j = 0; + _pn->destroy_rows(0); //Azzero l'oggetto pn. + } + } // if (indbil == 3) + } // for pcon +} + +void CG4600_application::ricavi() +{ + bool compila_mov = TRUE; + long s; + char sez_rmov = ' ', sezione = ' '; + real tot_saldo; + long numrig = 0; + TSaldo& sale = *_sale; + int j = 0; + + tot_saldo = ZERO; + + TRecnotype items_pcon = _cur->items(); + + for (int i = 0; i < items_pcon; i++, ++(*_cur)) + { + int indbil = _cur->curr().get_int(PCN_INDBIL); + int g = _cur->curr().get_int(PCN_GRUPPO); + int c = _cur->curr().get_int(PCN_CONTO); + TString tmcf = _cur->curr().get (PCN_TMCF); + + _prog->addstatus(1); + + if (indbil == 4) + { + compila_mov = TRUE; + + _saldi->setkey(1); + _saldi->zero(); + _saldi->put(SLD_ANNOES, _annoesch); + _saldi->put(SLD_GRUPPO, g); + _saldi->put(SLD_CONTO, c); + + (*_rec) = _saldi->curr(); + + j = 0; + numrig = 0; + + for (_saldi->read(); ; _saldi->next()) + { + _saldo = ZERO; + + if (_saldi->curr() > (*_rec) || _saldi->eof()) + { + // Aggiungo un ulteriore riga di movimento contenente la somma + // di tutti i saldi aventi lo stesso conto, indicandola + // con una sezione opposta al risultato (della somma). + + if (j >= 1) + { + numrig++; + if (tot_saldo != ZERO) + rmov_proper(_annoesch,numrig,_dataregch,_pn->cg(j),_tcproper,tot_saldo,FALSE); + + tot_saldo = ZERO; + } + break; + } + + if (compila_mov) + { + ultima_registrazione(); + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 2 Chiusura Ricavi + compila_mov = FALSE; + } + + //numrig++; + s = _saldi->get_long(SLD_SOTTOCONTO); + //sale.calcola_ultima_immissione(_annoesch,0,g,c,s,indbil); + sale.ultima_immissione_bilancio(_annoesch,g,c,s,indbil, 1); + _saldo = sale.saldo(); + + if (_saldo.is_zero()) continue; + + numrig++; + + if (j >= MAX || _saldi->eof()) + { + // Aggiungo un ulteriore riga di movimento contenente la somma + // di tutti i saldi aventi lo stesso sottoconto, indicandola + // con una sezione opposta al risultato (della somma). + + // numrig++; + if (tot_saldo != ZERO) + rmov_proper (_annoesch,numrig,_dataregch,_pn->cg(j),_tcproper,tot_saldo,FALSE); + _pn->write(); + _pn->destroy_rows(0); //Azzero l'oggetto pn. + + j = 0; + numrig = 1; + ultima_registrazione(); + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 2 Chiusura Ricavi + compila_mov = FALSE; + tot_saldo = ZERO; + } + + if (_saldo > ZERO) + sezione = 'D'; + else + if (_saldo < ZERO) + { + sezione = 'A'; + _saldo = -_saldo; + } + + if (sezione == 'D') // ---> Tengo una variabile in cui salvo gli + { // importi trovati sui saldi. Quando ho + sez_rmov = 'A'; // finito di leggere i sottoconti, oppure + tot_saldo += _saldo; // quando ho raggiunto un massimo di 99 + _totale_saldo += _saldo; + } // righe di movimento, genero un' altra + else // riga con importo di sezione opposta + if (sezione == 'A') // alla somma, mandando a zero + { // il saldo di quel movimento. + sez_rmov = 'D'; + tot_saldo -= _saldo; + _totale_saldo -= _saldo; + } + + if (!_saldi->eof()) + { + TRectype& rmov = _pn->cg(j); + + rmov.zero(); + rmov.put(RMV_ANNOES, _annoesch); //Compilo una riga di movimento + rmov.put(RMV_DATAREG, _dataregch); //per ogni sottoconto che leggo + rmov.put(RMV_GRUPPO, g); //sui saldi. Siccome queste + rmov.put(RMV_CONTO, c); //righe servono per mandare a 0 + rmov.put(RMV_SOTTOCONTO, s); //il saldo dei movimenti, la + rmov.put(RMV_SEZIONE, sez_rmov); //sezione sara' opposta a + rmov.put(RMV_IMPORTO, _saldo); //quella letta sui saldi. + rmov.put(RMV_NUMREG, _numreg); + rmov.put(RMV_NUMRIG, numrig); + rmov.put(RMV_TIPOC, tmcf); + + TBill tc(g,c,s); + _sld->aggiorna(tc,TImporto(sez_rmov,_saldo)); //l'oggetto TSaldo_agg + j++; + } + if (_saldi->eof()) break; + } //for saldi + if (j >= 1) + { + _pn->write(); + //_sld->registra(); + j = 0; + _pn->destroy_rows(0); //Azzero l'oggetto pn. + } + } // if (indbil == 4) + } // for pcon +} + +void CG4600_application::chiusura_conto_economico() +{ + _capitale_netto = _totale_saldo; //Mi serve per fare la riapertura del capitae netto + + if (_totale_saldo > ZERO) + { + int j; + + //Compilo la testata per perdite di es. c.economico a Profitti e Perdite + //Chiusura conto economico + + j = 0; + ultima_registrazione(); + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 3 Chiusura Conto Economico + + TRectype& rmov1 = _pn->cg(j); + long numrig = 1; + rmov_proper(_annoesch,numrig,_dataregch,rmov1,_tcproper,_totale_saldo,TRUE); + numrig++; + j++; + TRectype& rmov2 = _pn->cg(j); + rmov_proper(_annoesch,numrig,_dataregch,rmov2,_tcperde,_totale_saldo,FALSE); + + _pn->write(); + //_sld->registra(); + //_sld->reset(); + + //Compilo la testata per perdite di es. c.patrimon. a Perdita di es. c. econom. + //Chiusura capitale netto + + j = 0; + ultima_registrazione(); + _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. + + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 4 Chiusura Capitale netto + + TRectype& rmov3 = _pn->cg(j); + numrig = 1; + rmov_proper(_annoesch,numrig,_dataregch,rmov3,_tcperde,_totale_saldo,TRUE); + numrig++; + j++; + TRectype& rmov4 = _pn->cg(j); + rmov_proper(_annoesch,numrig,_dataregch,rmov4,_tcperdp,_totale_saldo,FALSE); + + _pn->write(); + } + else + if (_totale_saldo < ZERO) + { + int j; + + //Compilo la testata per Profitti e perdite a Utile di es. c.economico + //Chiusura conto economico + + j = 0; + ultima_registrazione(); + _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 3 Chiusura Conto Economico + + TRectype& rmov1 = _pn->cg(j); + long numrig = 1; + rmov_proper(_annoesch,numrig,_dataregch,rmov1,_tcutile,_totale_saldo,FALSE); + numrig++; + j++; + TRectype& rmov2 = _pn->cg(j); + rmov_proper(_annoesch,numrig,_dataregch,rmov2,_tcproper,_totale_saldo,TRUE); + + _pn ->write(); + //_sld->registra(); + //_sld->reset(); + + //Compilo la testata per Utile di es. c.economico a Utile di es. c.patrimoniale + //Chiusura capitale netto + + j = 0; + ultima_registrazione(); + _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 4 Chiusura Capitale netto + + TRectype& rmov3 = _pn->cg(j); + numrig = 1; + rmov_proper(_annoesch,numrig,_dataregch,rmov3,_tcutilp,_totale_saldo,FALSE); + numrig++; + j++; + TRectype& rmov4 = _pn->cg(j); + rmov_proper(_annoesch,numrig,_dataregch,rmov4,_tcutile,_totale_saldo,TRUE); + + _pn ->write(); + } +} + +void CG4600_application::chiudi_attivita() +{ + bool compila_mov = TRUE; + long s; + char sez_rmov = ' ', sezione = ' '; + real tot_saldo; + long numrig = 0; + TSaldo& sale = *_sale; + int j = 0; + + tot_saldo = ZERO; + + TRecnotype items_pcon = _cur->items(); + + for (int i = 0; i < items_pcon; i++, ++(*_cur)) + { + int indbil = _cur->curr().get_int(PCN_INDBIL); + int g = _cur->curr().get_int(PCN_GRUPPO); + int c = _cur->curr().get_int(PCN_CONTO); + TString tmcf = _cur->curr().get (PCN_TMCF); + + _prog->addstatus(1); + + if (indbil == 1) + { + compila_mov = TRUE; + + _saldi->setkey(1); + _saldi->zero(); + _saldi->put(SLD_ANNOES, _annoesch); + _saldi->put(SLD_GRUPPO, g); + _saldi->put(SLD_CONTO, c); + +// TRectype rec (_saldi->curr()); + *_rec = _saldi->curr(); + + j = 0; + numrig = 0; + + for (_saldi->read(_isgteq); ; _saldi->next()) + { + if (_saldi->curr() > (*_rec) || _saldi->eof()) + { + // Aggiungo un ulteriore riga di movimento contenente la somma + // di tutti i saldi aventi lo stesso conto, indicandola + // con una sezione opposta al risultato (della somma). + + if (j >= 1) + { + numrig++; + if (tot_saldo != ZERO) + rmov_proper(_annoesch,numrig,_dataregch,_pn->cg(j),_tcbilch,tot_saldo,FALSE); //Chiusura + + tot_saldo = ZERO; + } + break; + } + + if (compila_mov) + { + ultima_registrazione(); + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 5 Chiusura Attivita' + compila_mov = FALSE; + } + + //numrig++; + s = _saldi->get_long(SLD_SOTTOCONTO); + //sale.calcola_ultima_immissione(_annoesch,0,g,c,s,indbil); + sale.ultima_immissione_bilancio(_annoesch,g,c,s,indbil, 1); + _saldo = sale.saldo(); + //_saldo = ZERO; + const int dbkey = _saldi->getkey(); + _saldi->setkey(1); +// TString sldstr = _saldo.string(); + + if (_saldo == ZERO) continue; + + numrig++; + + if (j >= MAX || _saldi->eof()) + { + // Aggiungo un ulteriore riga di movimento contenente la somma + // di tutti i saldi aventi lo stesso sottoconto, indicandola + // con una sezione opposta al risultato (della somma). + + // numrig++; + if (tot_saldo != ZERO) + rmov_proper (_annoesch,numrig,_dataregch,_pn->cg(j),_tcbilch,tot_saldo,FALSE); //Chiusura + _pn->write(); + _pn->destroy_rows(0); //Azzero l'oggetto pn. + + j = 0; + numrig = 1; + ultima_registrazione(); + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 5 Chiusura Attivita' + compila_mov = FALSE; + tot_saldo = ZERO; + } + + if (_saldo > ZERO) + sezione = 'D'; + else + if (_saldo < ZERO) + { + sezione = 'A'; + _saldo = -_saldo; + } + + if (sezione == 'D') // ---> Tengo una variabile in cui salvo gli + { // importi trovati sui saldi. Quando ho + sez_rmov = 'A'; // finito di leggere i sottoconti, oppure + tot_saldo += _saldo; // quando ho raggiunto un massimo di 99 + _totale_saldo += _saldo; + } // righe di movimento, genero un' altra + else // riga con importo di sezione opposta + if (sezione == 'A') // alla somma, mandando a zero + { // il saldo di quel movimento. + sez_rmov = 'D'; + tot_saldo -= _saldo; + _totale_saldo -= _saldo; + } + + if (!_saldi->eof()) + { + TRectype& rmov = _pn->cg(j); + + rmov.zero(); + rmov.put(RMV_ANNOES, _annoesch); //Compilo una riga di movimento + rmov.put(RMV_DATAREG, _dataregch); //per ogni sottoconto che leggo + rmov.put(RMV_GRUPPO, g); //sui saldi. Siccome queste + rmov.put(RMV_CONTO, c); //righe servono per mandare a 0 + rmov.put(RMV_SOTTOCONTO, s); //il saldo dei movimenti, la + rmov.put(RMV_SEZIONE, sez_rmov); //sezione sara' opposta a + rmov.put(RMV_IMPORTO, _saldo); //quella letta sui saldi. + rmov.put(RMV_NUMREG, _numreg); + rmov.put(RMV_NUMRIG, numrig); + rmov.put(RMV_TIPOC, tmcf); + + TBill tc(g,c,s); + _sld->aggiorna(tc,TImporto(sez_rmov,_saldo)); //l'oggetto TSaldo_agg + + j++; + } + if (_saldi->eof()) break; + } //for saldi + if (j >= 1) + { + _pn->write(); + //_sld->registra(); + //_sld->reset(); + j = 0; + _pn->destroy_rows(0); //Azzero l'oggetto pn. + } + } // if (indbil == 1) + } // for pcon +} + +void CG4600_application::chiudi_passivita() +{ + bool compila_mov = TRUE; + long s; + char sez_rmov = ' ', sezione = ' '; + real tot_saldo; + long numrig = 0; + TSaldo& sale = *_sale; + int j = 0; + + tot_saldo = ZERO; + + TRecnotype items_pcon = _cur->items(); + + for (int i = 0; i < items_pcon; i++, ++(*_cur)) + { + int indbil = _cur->curr().get_int(PCN_INDBIL); + int g = _cur->curr().get_int(PCN_GRUPPO); + int c = _cur->curr().get_int(PCN_CONTO); + TString tmcf = _cur->curr().get (PCN_TMCF); + + _prog->addstatus(1); + + if (indbil == 2) + { + compila_mov = TRUE; + + _saldi->setkey(1); + _saldi->zero(); + _saldi->put(SLD_ANNOES, _annoesch); + _saldi->put(SLD_GRUPPO, g); + _saldi->put(SLD_CONTO, c); + + TRectype rec (_saldi->curr()); + + j = 0; + numrig = 0; + + for (_saldi->read(); ; _saldi->next()) + { + if (_saldi->curr() > rec || _saldi->eof()) + { + // Aggiungo un ulteriore riga di movimento contenente la somma + // di tutti i saldi aventi lo stesso conto, indicandola + // con una sezione opposta al risultato (della somma). + + if (j >= 1) + { + numrig++; + if (tot_saldo != ZERO) + rmov_proper(_annoesch,numrig,_dataregch,_pn->cg(j),_tcbilch,tot_saldo,FALSE); //Chiusura + + tot_saldo = ZERO; + } + break; + } + + if (compila_mov) + { + ultima_registrazione(); + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 6 Chiusura Passivita' + compila_mov = FALSE; + } + + //numrig++; + s = _saldi->get_long(SLD_SOTTOCONTO); + //sale.calcola_ultima_immissione(_annoesch,0,g,c,s,indbil); + sale.ultima_immissione_bilancio(_annoesch,g,c,s,indbil, 1); + _saldo = sale.saldo(); + + if (_saldo.is_zero()) continue; + + numrig++; + + if (j >= MAX || _saldi->eof()) + { + // Aggiungo un ulteriore riga di movimento contenente la somma + // di tutti i saldi aventi lo stesso sottoconto, indicandola + // con una sezione opposta al risultato (della somma). + + // numrig++; + if (tot_saldo != ZERO) + rmov_proper (_annoesch,numrig,_dataregch,_pn->cg(j),_tcbilch,tot_saldo,FALSE); //Chiusura + _pn->write(); + _pn->destroy_rows(0); //Azzero l'oggetto pn. + + j = 0; + numrig = 1; + ultima_registrazione(); + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 6 Chiusura Passivita' + compila_mov = FALSE; + tot_saldo = ZERO; + } + + if (_saldo > ZERO) + sezione = 'D'; + else + if (_saldo < ZERO) + { + sezione = 'A'; + _saldo = -_saldo; + } + + if (sezione == 'D') // ---> Tengo una variabile in cui salvo gli + { // importi trovati sui saldi. Quando ho + sez_rmov = 'A'; // finito di leggere i sottoconti, oppure + tot_saldo += _saldo; // quando ho raggiunto un massimo di 99 + _totale_saldo += _saldo; + } // righe di movimento, genero un' altra + else // riga con importo di sezione opposta + if (sezione == 'A') // alla somma, mandando a zero + { // il saldo di quel movimento. + sez_rmov = 'D'; + tot_saldo -= _saldo; + _totale_saldo -= _saldo; + } + + if (!_saldi->eof()) + { + TRectype& rmov = _pn->cg(j); + + rmov.zero(); + rmov.put(RMV_ANNOES, _annoesch); //Compilo una riga di movimento + rmov.put(RMV_DATAREG, _dataregch); //per ogni sottoconto che leggo + rmov.put(RMV_GRUPPO, g); //sui saldi. Siccome queste + rmov.put(RMV_CONTO, c); //righe servono per mandare a 0 + rmov.put(RMV_SOTTOCONTO, s); //il saldo dei movimenti, la + rmov.put(RMV_SEZIONE, sez_rmov); //sezione sara' opposta a + rmov.put(RMV_IMPORTO, _saldo); //quella letta sui saldi. + rmov.put(RMV_NUMREG, _numreg); + rmov.put(RMV_NUMRIG, numrig); + rmov.put(RMV_TIPOC, tmcf); + + TBill tc(g,c,s); + _sld->aggiorna(tc,TImporto(sez_rmov,_saldo)); //l'oggetto TSaldo_agg + + j++; + } + if (_saldi->eof()) break; + } //for saldi + if (j >= 1) + { + _pn->write(); + //_sld->registra(); + //_sld->reset(); + j = 0; + _pn->destroy_rows(0); + } + } // if (indbil == 2) + } // for pcon +} + +void CG4600_application::chiusura_conto_patrimoniale() +{ + int j; + long numrig; + + if (_totale_saldo > ZERO) + { + //Compilo la testata per Bilancio di chiusura a Perdita di es. c. patrimoniale + //Chiusura conto patrimoniale + + j = 0; + ultima_registrazione(); + _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 7 Chiusura Conto Patrimoniale + + TRectype& rmov1 = _pn->cg(j); + numrig = 1; + rmov_proper(_annoesch,numrig,_dataregch,rmov1,_tcutilp,_totale_saldo,FALSE); + numrig++; + j++; + TRectype& rmov2 = _pn->cg(j); + rmov_proper(_annoesch,numrig,_dataregch,rmov2,_tcbilch,_totale_saldo,TRUE); + + _pn->write(); + //_sld->registra(); + + } +else + if (_totale_saldo < ZERO) + { + //Compilo la testata per Utile di es. c.patrimon. a Bilancio di chiusura + //Chiusura conto patrimoniale + + j = 0; + ultima_registrazione(); + _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. + compila_testata(_annoesch,_dataregch,_codcausch); //Reg. 7 Chiusura Conto Patrimoniale + + TRectype& rmov1 = _pn->cg(j); + numrig = 1; + rmov_proper(_annoesch,numrig,_dataregch,rmov1,_tcbilch,_totale_saldo,TRUE); + numrig++; + j++; + TRectype& rmov2 = _pn->cg(j); + rmov_proper(_annoesch,numrig,_dataregch,rmov2,_tcperdp,_totale_saldo,FALSE); + + _pn ->write(); + //_sld->registra(); + } +} + +void CG4600_application::apri_attivita() +{ + bool compila_mov = TRUE; + long s; + char sezione = ' '; + real tot_saldo; + long numrig = 0; + TSaldo& sale = *_sale; + int j = 0; + + tot_saldo = ZERO; + + TRecnotype items_pcon = _cur->items(); + + for (int i = 0; i < items_pcon; i++, ++(*_cur)) + { + int indbil = _cur->curr().get_int(PCN_INDBIL); + int g = _cur->curr().get_int(PCN_GRUPPO); + int c = _cur->curr().get_int(PCN_CONTO); + TString tmcf = _cur->curr().get (PCN_TMCF); + + _prog->addstatus(1); + + if (indbil == 1) + { + compila_mov = TRUE; + + _saldi->setkey(1); + _saldi->zero(); + _saldi->put(SLD_ANNOES, _annoesch); + _saldi->put(SLD_GRUPPO, g); + _saldi->put(SLD_CONTO, c); + + TRectype rec (_saldi->curr()); + + j = 0; + numrig = 0; + + for (_saldi->read(); ; _saldi->next()) + { + if (_saldi->curr() > rec || _saldi->eof()) + { + // Aggiungo un ulteriore riga di movimento contenente la somma + // di tutti i saldi aventi lo stesso conto, indicandola + // con una sezione opposta al risultato (della somma). + + if (j >= 1) + { + numrig++; + if (tot_saldo != ZERO) + rmov_proper(_annoesap,numrig,_dataregap,_pn->cg(j),_tcbilap,tot_saldo,TRUE); //Apertura + + tot_saldo = ZERO; + } + break; + } + + if (compila_mov) + { + ultima_registrazione(); + compila_testata(_annoesap,_dataregap,_codcausap); //Reg. 8 Apertura Attivita' + compila_mov = FALSE; + } + + //numrig++; + s = _saldi->get_long(SLD_SOTTOCONTO); + sale.ultima_immissione_bilancio(_annoesch,g,c,s,indbil, 1); + _saldo = sale.saldo(); + + if (_saldo == ZERO) continue; + + numrig++; + + if (j >= MAX || _saldi->eof()) + { + // Aggiungo un ulteriore riga di movimento contenente la somma + // di tutti i saldi aventi lo stesso sottoconto, indicandola + // con una sezione opposta al risultato (della somma). + + if (tot_saldo != ZERO) + rmov_proper (_annoesap,numrig,_dataregap,_pn->cg(j),_tcbilap,tot_saldo,TRUE); //Chiusura + _pn->write(); + _pn->destroy_rows(0); //Azzero l'oggetto pn. + + j = 0; + numrig = 1; + ultima_registrazione(); + compila_testata(_annoesap,_dataregap,_codcausap); //Reg. 8 Apertura Attivita' + compila_mov = FALSE; + tot_saldo = ZERO; + } + + if (_saldo > ZERO) + sezione = 'D'; + else + if (_saldo < ZERO) + { + sezione = 'A'; + _saldo = -_saldo; + } + + if (sezione == 'D') // ---> Tengo una variabile in cui salvo gli + { // importi trovati sui saldi. Quando ho + tot_saldo += _saldo; // quando ho raggiunto un massimo di 99 + _totale_saldo += _saldo; + } // righe di movimento, genero un' altra + else // riga con importo di sezione opposta + if (sezione == 'A') // alla somma, mandando a zero + { // il saldo di quel movimento. + tot_saldo -= _saldo; + _totale_saldo -= _saldo; + } + + if (!_saldi->eof()) + { + TRectype& rmov = _pn->cg(j); + + rmov.zero(); + rmov.put(RMV_ANNOES, _annoesap); //Compilo una riga di movimento + rmov.put(RMV_DATAREG, _dataregap); //per ogni sottoconto che leggo + rmov.put(RMV_GRUPPO, g); //sui saldi. Siccome queste + rmov.put(RMV_CONTO, c); //righe servono per mandare a 0 + rmov.put(RMV_SOTTOCONTO, s); //il saldo dei movimenti, la + rmov.put(RMV_SEZIONE, sezione); //sezione sara' opposta a + rmov.put(RMV_IMPORTO, _saldo); //quella letta sui saldi. + rmov.put(RMV_NUMREG, _numreg); + rmov.put(RMV_NUMRIG, numrig); + rmov.put(RMV_TIPOC, tmcf); + + TBill tc(g,c,s); + _sld->aggiorna(tc,TImporto(sezione,_saldo)); //l'oggetto TSaldo_agg + + j++; + } + if (_saldi->eof()) break; + } //for saldi + if (j >= 1) + { + _pn->write(); + j = 0; + _pn->destroy_rows(0); //Azzero l'oggetto pn. + } + } // if (indbil == 1) + } // for pcon +} + +void CG4600_application::apri_passivita() +{ + bool compila_mov = TRUE; + long s; + char sezione = ' '; + real tot_saldo; + long numrig = 0; + TSaldo& sale = *_sale; + int j = 0; + + tot_saldo = ZERO; + + TRecnotype items_pcon = _cur->items(); + + for (int i = 0; i < items_pcon; i++, ++(*_cur)) + { + int indbil = _cur->curr().get_int(PCN_INDBIL); + int g = _cur->curr().get_int(PCN_GRUPPO); + int c = _cur->curr().get_int(PCN_CONTO); + TString tmcf = _cur->curr().get (PCN_TMCF); + + _prog->addstatus(1); + + if (indbil == 2) + { + compila_mov = TRUE; + + _saldi->setkey(1); + _saldi->zero(); + _saldi->put(SLD_ANNOES, _annoesch); + _saldi->put(SLD_GRUPPO, g); + _saldi->put(SLD_CONTO, c); + + TRectype rec (_saldi->curr()); + + j = 0; + numrig = 0; + + for (_saldi->read(); ; _saldi->next()) + { + if (_saldi->curr() > rec || _saldi->eof()) + { + // Aggiungo un ulteriore riga di movimento contenente la somma + // di tutti i saldi aventi lo stesso conto, indicandola + // con una sezione opposta al risultato (della somma). + + if (j >= 1) + { + numrig++; + if (tot_saldo != ZERO) + rmov_proper(_annoesap,numrig,_dataregap,_pn->cg(j),_tcbilap,tot_saldo,TRUE); //Apertura + + tot_saldo = ZERO; + } + break; + } + + if (compila_mov) + { + ultima_registrazione(); + compila_testata(_annoesap,_dataregap,_codcausap); //Reg. 9 Apertura Passivita' + compila_mov = FALSE; + } + + //numrig++; + s = _saldi->get_long(SLD_SOTTOCONTO); + sale.ultima_immissione_bilancio(_annoesch,g,c,s,indbil, 1); + _saldo = sale.saldo(); + + if (_saldo.is_zero()) continue; + + numrig++; + + if (j >= MAX || _saldi->eof()) + { + // Aggiungo un ulteriore riga di movimento contenente la somma + // di tutti i saldi aventi lo stesso sottoconto, indicandola + // con una sezione opposta al risultato (della somma). + + if (tot_saldo != ZERO) + rmov_proper (_annoesap,numrig,_dataregap,_pn->cg(j),_tcbilap,tot_saldo,TRUE); //Apertura + _pn->write(); + _pn->destroy_rows(0); //Azzero l'oggetto pn. + + j = 0; + numrig = 1; + ultima_registrazione(); + compila_testata(_annoesap,_dataregap,_codcausap); //Reg. 9 Apertura Passivita' + compila_mov = FALSE; + tot_saldo = ZERO; + } + + if (_saldo > ZERO) + sezione = 'D'; + else + if (_saldo < ZERO) + { + sezione = 'A'; + _saldo = -_saldo; + } + + if (sezione == 'D') // ---> Tengo una variabile in cui salvo gli + { // importi trovati sui saldi. Quando ho + tot_saldo += _saldo; // finito di leggere i sottoconti, oppure + _totale_saldo += _saldo; // quando ho raggiunto un massimo di 99 + } // righe di movimento, genero un' altra + else // riga con importo di sezione opposta + if (sezione == 'A') // alla somma, mandando a zero + { // il saldo di quel movimento. + tot_saldo -= _saldo; + _totale_saldo -= _saldo; + } + + if (!_saldi->eof()) + { + TRectype& rmov = _pn->cg(j); + + rmov.zero(); + rmov.put(RMV_ANNOES, _annoesap); //Compilo una riga di movimento + rmov.put(RMV_DATAREG, _dataregap); //per ogni sottoconto che leggo + rmov.put(RMV_GRUPPO, g); //sui saldi. Siccome queste + rmov.put(RMV_CONTO, c); //righe servono per mandare a 0 + rmov.put(RMV_SOTTOCONTO, s); //il saldo dei movimenti, la + rmov.put(RMV_SEZIONE, sezione); //sezione sara' opposta a + rmov.put(RMV_IMPORTO, _saldo); //quella letta sui saldi. + rmov.put(RMV_NUMREG, _numreg); + rmov.put(RMV_NUMRIG, numrig); + rmov.put(RMV_TIPOC, tmcf); + + TBill tc(g,c,s); + _sld->aggiorna(tc,TImporto(sezione,_saldo)); //l'oggetto TSaldo_agg + + j++; + } + if (_saldi->eof()) break; + } //for saldi + if (j >= 1) + { + _pn->write(); + j = 0; + _pn->destroy_rows(0); + } + } // if (indbil == 2) + } // for pcon +} + +void CG4600_application::apertura_capitale_netto() +{ + int numrig; + + if (_capitale_netto > ZERO) + { + //Compilo la testata per Perdita es. c/to patrimoniale a Bilancio di apertura + //Apertura capitale netto + + int j = 0; + ultima_registrazione(); + _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. + + compila_testata(_annoesap,_dataregap,_codcausap); //Reg. 10 Apertura Capitale netto + + TRectype& rmov1 = _pn->cg(j); + numrig = 1; + rmov_proper(_annoesap,numrig,_dataregap,rmov1,_tcbilap,_capitale_netto,TRUE); + numrig++; + j++; + TRectype& rmov2 = _pn->cg(j); + rmov_proper(_annoesap,numrig,_dataregap,rmov2,_tcperdp,_capitale_netto,FALSE); + + _pn->write(); + } + else + if (_capitale_netto < ZERO) + { + //Compilo la testata per Bilancio di apertura a Utile es. c/to patrimoniale + //Apertura capitale netto + + int j = 0; + ultima_registrazione(); + _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. + + compila_testata(_annoesap,_dataregap,_codcausap); //Reg. 10 Apertura Capitale netto + + TRectype& rmov1 = _pn->cg(j); + numrig = 1; + rmov_proper(_annoesap,numrig,_dataregap,rmov1,_tcbilap,_capitale_netto,TRUE); + numrig++; + j++; + TRectype& rmov2 = _pn->cg(j); + rmov_proper(_annoesap,numrig,_dataregap,rmov2,_tcutilp,_capitale_netto,FALSE); + + _pn->write(); + } +} + +bool CG4600_application::menu(MENU_TAG m) +{ + if (m == BAR_ITEM(1)) + return set(); + return FALSE; +} + +int cg4600 (int argc, char* argv[]) +{ + CG4600_application main_app; + main_app.run(argc, argv, "Apertura/Chiusura Conti"); + return TRUE; +} + + + + + + + diff --git a/cg/cg4600a.uml b/cg/cg4600a.uml index f894d5dbe..946e0c4f9 100755 --- a/cg/cg4600a.uml +++ b/cg/cg4600a.uml @@ -1,350 +1,350 @@ -#include "cg4600.h" - -PAGE "" -1 -1 76 20 - -NUMBER F_CODDITTA 5 -BEGIN - PROMPT 2 1 "Ditta " - FLAGS "FRD" - USE LF_NDITTE KEY 1 - CHECKTYPE REQUIRED - INPUT CODDITTA F_CODDITTA - DISPLAY "Codice" CODDITTA - DISPLAY "Ragione sociale @50" RAGSOC - OUTPUT F_CODDITTA CODDITTA - OUTPUT F_RAGSOC RAGSOC -END - - -STRING F_RAGSOC 50 -BEGIN - PROMPT 2 2 "Ragione sociale " - FLAGS "D" -END - -STRING F_CHIUSURA 3 -BEGIN - PROMPT 2 4 "Codice causale chiusura " - HELP "Codice causale che genera il movimento di chiusura" - USE LF_CAUSALI KEY 1 SELECT MOVAP="C" - FLAGS "UZ" - DISPLAY "Codice" CODCAUS - DISPLAY "Descrizione @50" DESCR - OUTPUT F_CHIUSURA CODCAUS - INPUT CODCAUS F_CHIUSURA - CHECKTYPE REQUIRED -END - -STRING F_APERTURA 3 -BEGIN - PROMPT 2 5 "Codice causale apertura " - HELP "Codice causale che genera il movimento di apertura" - USE LF_CAUSALI KEY 1 SELECT MOVAP="A" - FLAGS "UZ" - COPY DISPLAY F_CHIUSURA - OUTPUT F_APERTURA CODCAUS - INPUT CODCAUS F_APERTURA -END - -DATE F_DATAC -BEGIN - PROMPT 36 4 "Data/Anno chiusura " - HELP "Data in cui effettuare il movimento di chiusura" -END - -DATE F_DATAAP -BEGIN - PROMPT 36 5 "Data/Anno apertura " - HELP "Data in cui effettuare il movimento di apertura" - WARNING "Inserire una data non inferiore alla data di chiusura" - VALIDATE DATE_CMP_FUNC >= F_DATAC -END - -NUMBER F_ANNOCH 4 -BEGIN - PROMPT 69 4 "" - USE ESC - INPUT CODTAB F_ANNOCH - DISPLAY "Anno" CODTAB - DISPLAY "Inizio Es.@12" D0 - DISPLAY "Fine Es.@12" D1 - DISPLAY "Scarico@12" D2 - OUTPUT F_ANNOCH CODTAB - OUTPUT F_DATAC D1 - CHECKTYPE REQUIRED - WARNING "Anno non presente in tabella esercizi" - FLAGS "GRZD" -END - -NUMBER F_ANNO 4 -BEGIN - PROMPT 69 5 "" - COPY USE F_ANNOCH - INPUT CODTAB F_ANNO - COPY DISPLAY F_ANNOCH - OUTPUT F_ANNO CODTAB - OUTPUT F_DATAAP D0 - CHECKTYPE REQUIRED - WARNING "Anno non presente in tabella esercizi" - FLAGS "GRZD" -END - - -GROUPBOX DLG_NULL 60 10 -BEGIN - PROMPT 2 7 "Codici sottoconto" -END - -NUMBER F_BILCHG 3 -BEGIN - PROMPT 3 9 "Bilancio di chiusura " - HELP "Codice conto di riepilogo del bilancio di chiusura" - USE LF_PCON KEY 1 SELECT SOTTOCONTO!="" - CHECKTYPE REQUIRED - DISPLAY "Gruppo" GRUPPO - DISPLAY "Conto" CONTO - DISPLAY "Sottoconto" SOTTOCONTO - DISPLAY "Descrizione @50" DESCR - OUTPUT F_BILCHG GRUPPO - OUTPUT F_BILCHC CONTO - OUTPUT F_BILCHS SOTTOCONTO - INPUT GRUPPO F_BILCHG - INPUT CONTO F_BILCHC - INPUT SOTTOCONTO F_BILCHS -END - -NUMBER F_BILCHC 3 -BEGIN - PROMPT 44 9 "" - HELP "Codice conto di riepilogo del bilancio di chiusura" - COPY ALL F_BILCHG - CHECKTYPE REQUIRED -END - -NUMBER F_BILCHS 6 -BEGIN - PROMPT 51 9 "" - HELP "Codice conto di riepilogo del bilancio di chiusura" - COPY ALL F_BILCHG - CHECKTYPE REQUIRED - -END - -NUMBER F_PROPERG 3 -BEGIN - PROMPT 3 10 "Profitti e perdite " - HELP "Codice conto di riepilogo del Profitti e perdite" - COPY USE F_BILCHG - CHECKTYPE REQUIRED - COPY DISPLAY F_BILCHG - OUTPUT F_PROPERG GRUPPO - OUTPUT F_PROPERC CONTO - OUTPUT F_PROPERS SOTTOCONTO - INPUT GRUPPO F_PROPERG - INPUT CONTO F_PROPERC - INPUT SOTTOCONTO F_PROPERS -END - -NUMBER F_PROPERC 3 -BEGIN - PROMPT 44 10 "" - HELP "Codice conto di riepilogo del Profitti e perdite" - COPY USE F_BILCHG - CHECKTYPE REQUIRED - COPY DISPLAY F_BILCHG - COPY OUTPUT F_PROPERG - COPY INPUT F_PROPERG -END - -NUMBER F_PROPERS 6 -BEGIN - PROMPT 51 10 "" - HELP "Codice conto di riepilogo del Profitti e perdite" - COPY ALL F_PROPERC - CHECKTYPE REQUIRED -END - -NUMBER F_BILAPG 3 -BEGIN - PROMPT 3 11 "Bilancio di apertura " - HELP "Codice conto di riepilogo del Bilancio di apertura" - COPY USE F_BILCHG - CHECKTYPE REQUIRED - COPY DISPLAY F_BILCHG - OUTPUT F_BILAPG GRUPPO - OUTPUT F_BILAPC CONTO - OUTPUT F_BILAPS SOTTOCONTO - INPUT GRUPPO F_BILAPG - INPUT CONTO F_BILAPC - INPUT SOTTOCONTO F_BILAPS -END - -NUMBER F_BILAPC 3 -BEGIN - PROMPT 44 11 "" - HELP "Codice conto di riepilogo del Bilancio di apertura" - COPY USE F_BILCHG - CHECKTYPE REQUIRED - COPY DISPLAY F_BILCHG - COPY OUTPUT F_BILAPG - COPY INPUT F_BILAPG -END - -NUMBER F_BILAPS 6 -BEGIN - PROMPT 51 11 "" - HELP "Codice conto di riepilogo del Bilancio di apertura" - COPY ALL F_BILAPC - CHECKTYPE REQUIRED -END - -NUMBER F_UTILPG 3 -BEGIN - PROMPT 3 12 "Utile d'esercizio c/to patrim. " - HELP "Codice conto patrimoniale in cui ripilogare l'utile d'esercizio" - USE LF_PCON KEY 1 SELECT (SOTTOCONTO!="") - CHECKTYPE REQUIRED - COPY DISPLAY F_BILCHG - OUTPUT F_UTILPG GRUPPO - OUTPUT F_UTILPC CONTO - OUTPUT F_UTILPS SOTTOCONTO - INPUT GRUPPO F_UTILPG - INPUT CONTO F_UTILPC - INPUT SOTTOCONTO F_UTILPS -END - -NUMBER F_UTILPC 3 -BEGIN - PROMPT 44 12 "" - HELP "Codice conto patrimoniale in cui ripilogare l'utile d'esercizio" - COPY USE F_UTILPG - CHECKTYPE REQUIRED - COPY DISPLAY F_BILCHG - COPY OUTPUT F_UTILPG - COPY INPUT F_UTILPG -END - -NUMBER F_UTILPS 6 -BEGIN - PROMPT 51 12 "" - HELP "Codice conto patrimoniale in cui ripilogare l'utile d'esercizio" - COPY ALL F_UTILPC - CHECKTYPE REQUIRED -END - -NUMBER F_PERDPG 3 -BEGIN - PROMPT 3 13 "Perdita d'esercizio c/to patr. " - HELP "Codice conto patrimoniale in cui ripilogare la perdita d'esercizio" - USE LF_PCON KEY 1 SELECT (SOTTOCONTO!="") - CHECKTYPE REQUIRED - COPY DISPLAY F_BILCHG - OUTPUT F_PERDPG GRUPPO - OUTPUT F_PERDPC CONTO - OUTPUT F_PERDPS SOTTOCONTO - INPUT GRUPPO F_PERDPG - INPUT CONTO F_PERDPC - INPUT SOTTOCONTO F_PERDPS -END - -NUMBER F_PERDPC 3 -BEGIN - PROMPT 44 13 "" - HELP "Codice conto patrimoniale in cui ripilogare la perdita d'esercizio" - COPY USE F_PERDPG - CHECKTYPE REQUIRED - COPY DISPLAY F_BILCHG - COPY OUTPUT F_PERDPG - COPY INPUT F_PERDPG -END - -NUMBER F_PERDPS 6 -BEGIN - PROMPT 51 13 "" - HELP "Codice conto patrimoniale in cui ripilogare la perdita d'esercizio" - COPY ALL F_PERDPC - CHECKTYPE REQUIRED -END - -NUMBER F_UTILEG 3 -BEGIN - PROMPT 3 14 "Utile d'esercizio c/to econom. " - HELP "Codice conto economico in cui ripilogare l'utile d'esercizio" - USE LF_PCON KEY 1 SELECT (SOTTOCONTO!="") - CHECKTYPE REQUIRED - COPY DISPLAY F_BILCHG - OUTPUT F_UTILEG GRUPPO - OUTPUT F_UTILEC CONTO - OUTPUT F_UTILES SOTTOCONTO - INPUT GRUPPO F_UTILEG - INPUT CONTO F_UTILEC - INPUT SOTTOCONTO F_UTILES -END - -NUMBER F_UTILEC 3 -BEGIN - PROMPT 44 14 "" - HELP "Codice conto economico in cui ripilogare l'utile d'esercizio" - COPY USE F_UTILEG - CHECKTYPE REQUIRED - COPY DISPLAY F_BILCHG - COPY OUTPUT F_UTILEG - COPY INPUT F_UTILEG -END - -NUMBER F_UTILES 6 -BEGIN - PROMPT 51 14 "" - HELP "Codice conto economico in cui ripilogare l'utile d'esercizio" - COPY ALL F_UTILEC - CHECKTYPE REQUIRED -END - -NUMBER F_PERDEG 3 -BEGIN - PROMPT 3 15 "Perdita d'esercizio c/to econ. " - HELP "Codice conto economico in cui ripilogare la perdita d'esercizio" - USE LF_PCON KEY 1 SELECT (SOTTOCONTO!="") - CHECKTYPE REQUIRED - COPY DISPLAY F_BILCHG - OUTPUT F_PERDEG GRUPPO - OUTPUT F_PERDEC CONTO - OUTPUT F_PERDES SOTTOCONTO - INPUT GRUPPO F_PERDEG - INPUT CONTO F_PERDEC - INPUT SOTTOCONTO F_PERDES - -END - -NUMBER F_PERDEC 3 -BEGIN - PROMPT 44 15 "" - HELP "Codice conto economico in cui ripilogare la perdita d'esercizio" - COPY USE F_PERDEG - CHECKTYPE REQUIRED - COPY DISPLAY F_BILCHG - COPY OUTPUT F_PERDEG - COPY INPUT F_PERDEG -END - -NUMBER F_PERDES 6 -BEGIN - PROMPT 51 15 "" - HELP "Codice conto economico in cui ripilogare la perdita d'esercizio" - COPY ALL F_PERDEC - CHECKTYPE REQUIRED -END - -BUTTON DLG_OK 9 2 -BEGIN - PROMPT -12 -1 "" -END - -BUTTON DLG_QUIT 9 2 -BEGIN - PROMPT -22 -1 "" -END - -ENDPAGE - -ENDMASK +#include "cg4600.h" + +PAGE "" -1 -1 76 20 + +NUMBER F_CODDITTA 5 +BEGIN + PROMPT 2 1 "Ditta " + FLAGS "FRD" + USE LF_NDITTE KEY 1 + CHECKTYPE REQUIRED + INPUT CODDITTA F_CODDITTA + DISPLAY "Codice" CODDITTA + DISPLAY "Ragione sociale @50" RAGSOC + OUTPUT F_CODDITTA CODDITTA + OUTPUT F_RAGSOC RAGSOC +END + + +STRING F_RAGSOC 50 +BEGIN + PROMPT 2 2 "Ragione sociale " + FLAGS "D" +END + +STRING F_CHIUSURA 3 +BEGIN + PROMPT 2 4 "Codice causale chiusura " + HELP "Codice causale che genera il movimento di chiusura" + USE LF_CAUSALI KEY 1 SELECT MOVAP="C" + FLAGS "UZ" + DISPLAY "Codice" CODCAUS + DISPLAY "Descrizione @50" DESCR + OUTPUT F_CHIUSURA CODCAUS + INPUT CODCAUS F_CHIUSURA + CHECKTYPE REQUIRED +END + +STRING F_APERTURA 3 +BEGIN + PROMPT 2 5 "Codice causale apertura " + HELP "Codice causale che genera il movimento di apertura" + USE LF_CAUSALI KEY 1 SELECT MOVAP="A" + FLAGS "UZ" + COPY DISPLAY F_CHIUSURA + OUTPUT F_APERTURA CODCAUS + INPUT CODCAUS F_APERTURA +END + +DATE F_DATAC +BEGIN + PROMPT 36 4 "Data/Anno chiusura " + HELP "Data in cui effettuare il movimento di chiusura" +END + +DATE F_DATAAP +BEGIN + PROMPT 36 5 "Data/Anno apertura " + HELP "Data in cui effettuare il movimento di apertura" + WARNING "Inserire una data non inferiore alla data di chiusura" + VALIDATE DATE_CMP_FUNC >= F_DATAC +END + +NUMBER F_ANNOCH 4 +BEGIN + PROMPT 69 4 "" + USE ESC + INPUT CODTAB F_ANNOCH + DISPLAY "Anno" CODTAB + DISPLAY "Inizio Es.@12" D0 + DISPLAY "Fine Es.@12" D1 + DISPLAY "Scarico@12" D2 + OUTPUT F_ANNOCH CODTAB + OUTPUT F_DATAC D1 + CHECKTYPE REQUIRED + WARNING "Anno non presente in tabella esercizi" + FLAGS "GRZD" +END + +NUMBER F_ANNO 4 +BEGIN + PROMPT 69 5 "" + COPY USE F_ANNOCH + INPUT CODTAB F_ANNO + COPY DISPLAY F_ANNOCH + OUTPUT F_ANNO CODTAB + OUTPUT F_DATAAP D0 + CHECKTYPE REQUIRED + WARNING "Anno non presente in tabella esercizi" + FLAGS "GRZD" +END + + +GROUPBOX DLG_NULL 60 10 +BEGIN + PROMPT 2 7 "Codici sottoconto" +END + +NUMBER F_BILCHG 3 +BEGIN + PROMPT 3 9 "Bilancio di chiusura " + HELP "Codice conto di riepilogo del bilancio di chiusura" + USE LF_PCON KEY 1 SELECT SOTTOCONTO!="" + CHECKTYPE REQUIRED + DISPLAY "Gruppo" GRUPPO + DISPLAY "Conto" CONTO + DISPLAY "Sottoconto" SOTTOCONTO + DISPLAY "Descrizione @50" DESCR + OUTPUT F_BILCHG GRUPPO + OUTPUT F_BILCHC CONTO + OUTPUT F_BILCHS SOTTOCONTO + INPUT GRUPPO F_BILCHG + INPUT CONTO F_BILCHC + INPUT SOTTOCONTO F_BILCHS +END + +NUMBER F_BILCHC 3 +BEGIN + PROMPT 44 9 "" + HELP "Codice conto di riepilogo del bilancio di chiusura" + COPY ALL F_BILCHG + CHECKTYPE REQUIRED +END + +NUMBER F_BILCHS 6 +BEGIN + PROMPT 51 9 "" + HELP "Codice conto di riepilogo del bilancio di chiusura" + COPY ALL F_BILCHG + CHECKTYPE REQUIRED + +END + +NUMBER F_PROPERG 3 +BEGIN + PROMPT 3 10 "Profitti e perdite " + HELP "Codice conto di riepilogo del Profitti e perdite" + COPY USE F_BILCHG + CHECKTYPE REQUIRED + COPY DISPLAY F_BILCHG + OUTPUT F_PROPERG GRUPPO + OUTPUT F_PROPERC CONTO + OUTPUT F_PROPERS SOTTOCONTO + INPUT GRUPPO F_PROPERG + INPUT CONTO F_PROPERC + INPUT SOTTOCONTO F_PROPERS +END + +NUMBER F_PROPERC 3 +BEGIN + PROMPT 44 10 "" + HELP "Codice conto di riepilogo del Profitti e perdite" + COPY USE F_BILCHG + CHECKTYPE REQUIRED + COPY DISPLAY F_BILCHG + COPY OUTPUT F_PROPERG + COPY INPUT F_PROPERG +END + +NUMBER F_PROPERS 6 +BEGIN + PROMPT 51 10 "" + HELP "Codice conto di riepilogo del Profitti e perdite" + COPY ALL F_PROPERC + CHECKTYPE REQUIRED +END + +NUMBER F_BILAPG 3 +BEGIN + PROMPT 3 11 "Bilancio di apertura " + HELP "Codice conto di riepilogo del Bilancio di apertura" + COPY USE F_BILCHG + CHECKTYPE REQUIRED + COPY DISPLAY F_BILCHG + OUTPUT F_BILAPG GRUPPO + OUTPUT F_BILAPC CONTO + OUTPUT F_BILAPS SOTTOCONTO + INPUT GRUPPO F_BILAPG + INPUT CONTO F_BILAPC + INPUT SOTTOCONTO F_BILAPS +END + +NUMBER F_BILAPC 3 +BEGIN + PROMPT 44 11 "" + HELP "Codice conto di riepilogo del Bilancio di apertura" + COPY USE F_BILCHG + CHECKTYPE REQUIRED + COPY DISPLAY F_BILCHG + COPY OUTPUT F_BILAPG + COPY INPUT F_BILAPG +END + +NUMBER F_BILAPS 6 +BEGIN + PROMPT 51 11 "" + HELP "Codice conto di riepilogo del Bilancio di apertura" + COPY ALL F_BILAPC + CHECKTYPE REQUIRED +END + +NUMBER F_UTILPG 3 +BEGIN + PROMPT 3 12 "Utile d'esercizio c/to patrim. " + HELP "Codice conto patrimoniale in cui ripilogare l'utile d'esercizio" + USE LF_PCON KEY 1 SELECT (SOTTOCONTO!="") + CHECKTYPE REQUIRED + COPY DISPLAY F_BILCHG + OUTPUT F_UTILPG GRUPPO + OUTPUT F_UTILPC CONTO + OUTPUT F_UTILPS SOTTOCONTO + INPUT GRUPPO F_UTILPG + INPUT CONTO F_UTILPC + INPUT SOTTOCONTO F_UTILPS +END + +NUMBER F_UTILPC 3 +BEGIN + PROMPT 44 12 "" + HELP "Codice conto patrimoniale in cui ripilogare l'utile d'esercizio" + COPY USE F_UTILPG + CHECKTYPE REQUIRED + COPY DISPLAY F_BILCHG + COPY OUTPUT F_UTILPG + COPY INPUT F_UTILPG +END + +NUMBER F_UTILPS 6 +BEGIN + PROMPT 51 12 "" + HELP "Codice conto patrimoniale in cui ripilogare l'utile d'esercizio" + COPY ALL F_UTILPC + CHECKTYPE REQUIRED +END + +NUMBER F_PERDPG 3 +BEGIN + PROMPT 3 13 "Perdita d'esercizio c/to patr. " + HELP "Codice conto patrimoniale in cui ripilogare la perdita d'esercizio" + USE LF_PCON KEY 1 SELECT (SOTTOCONTO!="") + CHECKTYPE REQUIRED + COPY DISPLAY F_BILCHG + OUTPUT F_PERDPG GRUPPO + OUTPUT F_PERDPC CONTO + OUTPUT F_PERDPS SOTTOCONTO + INPUT GRUPPO F_PERDPG + INPUT CONTO F_PERDPC + INPUT SOTTOCONTO F_PERDPS +END + +NUMBER F_PERDPC 3 +BEGIN + PROMPT 44 13 "" + HELP "Codice conto patrimoniale in cui ripilogare la perdita d'esercizio" + COPY USE F_PERDPG + CHECKTYPE REQUIRED + COPY DISPLAY F_BILCHG + COPY OUTPUT F_PERDPG + COPY INPUT F_PERDPG +END + +NUMBER F_PERDPS 6 +BEGIN + PROMPT 51 13 "" + HELP "Codice conto patrimoniale in cui ripilogare la perdita d'esercizio" + COPY ALL F_PERDPC + CHECKTYPE REQUIRED +END + +NUMBER F_UTILEG 3 +BEGIN + PROMPT 3 14 "Utile d'esercizio c/to econom. " + HELP "Codice conto economico in cui ripilogare l'utile d'esercizio" + USE LF_PCON KEY 1 SELECT (SOTTOCONTO!="") + CHECKTYPE REQUIRED + COPY DISPLAY F_BILCHG + OUTPUT F_UTILEG GRUPPO + OUTPUT F_UTILEC CONTO + OUTPUT F_UTILES SOTTOCONTO + INPUT GRUPPO F_UTILEG + INPUT CONTO F_UTILEC + INPUT SOTTOCONTO F_UTILES +END + +NUMBER F_UTILEC 3 +BEGIN + PROMPT 44 14 "" + HELP "Codice conto economico in cui ripilogare l'utile d'esercizio" + COPY USE F_UTILEG + CHECKTYPE REQUIRED + COPY DISPLAY F_BILCHG + COPY OUTPUT F_UTILEG + COPY INPUT F_UTILEG +END + +NUMBER F_UTILES 6 +BEGIN + PROMPT 51 14 "" + HELP "Codice conto economico in cui ripilogare l'utile d'esercizio" + COPY ALL F_UTILEC + CHECKTYPE REQUIRED +END + +NUMBER F_PERDEG 3 +BEGIN + PROMPT 3 15 "Perdita d'esercizio c/to econ. " + HELP "Codice conto economico in cui ripilogare la perdita d'esercizio" + USE LF_PCON KEY 1 SELECT (SOTTOCONTO!="") + CHECKTYPE REQUIRED + COPY DISPLAY F_BILCHG + OUTPUT F_PERDEG GRUPPO + OUTPUT F_PERDEC CONTO + OUTPUT F_PERDES SOTTOCONTO + INPUT GRUPPO F_PERDEG + INPUT CONTO F_PERDEC + INPUT SOTTOCONTO F_PERDES + +END + +NUMBER F_PERDEC 3 +BEGIN + PROMPT 44 15 "" + HELP "Codice conto economico in cui ripilogare la perdita d'esercizio" + COPY USE F_PERDEG + CHECKTYPE REQUIRED + COPY DISPLAY F_BILCHG + COPY OUTPUT F_PERDEG + COPY INPUT F_PERDEG +END + +NUMBER F_PERDES 6 +BEGIN + PROMPT 51 15 "" + HELP "Codice conto economico in cui ripilogare la perdita d'esercizio" + COPY ALL F_PERDEC + CHECKTYPE REQUIRED +END + +BUTTON DLG_OK 9 2 +BEGIN + PROMPT -12 -1 "" +END + +BUTTON DLG_QUIT 9 2 +BEGIN + PROMPT -22 -1 "" +END + +ENDPAGE + +ENDMASK diff --git a/cg/cglib.h b/cg/cglib.h index 97c5a991e..68a95043d 100755 --- a/cg/cglib.h +++ b/cg/cglib.h @@ -1,152 +1,152 @@ -#ifndef __CGLIB_H -#define __CGLIB_H - -#ifndef __ISAM_H -#include -#endif - -#include -#include "conto.h" -#include "cg2103.h" // per TCausale - - -class TCaus : public TCausale -{ -private: - TRectype _rec; - -public: - bool chiusura() const; - bool apertura() const; - virtual bool read(const char* cod); - - TCaus(const char* cod); - ~TCaus() {} -}; - -class TSaldi_list : public TAssoc_array -{ -public: - TSaldi_list (int g, int c, int aec, int aep=0); - TRectype* saldi() const; -}; - -enum tipobil { DataLimite=1, UltimaImmissione }; -const int EsePre(const int EseCorr); - -class TSaldo -{ - real _saldo, _saldo_iniziale, _saldoiniziale; - real _prg_dare, _prg_avere, _prg_daresca, _prg_averesca; - int _indbil; - TRectype* _saldo_ep; - int _annoes; - TDate _inizioEs, _fineEs; - TString16 _codcaus; - TDate _datareg; - TDate _datacomp; - TString _provv; - - bool _movimentato; - bool _significativo; - bool _rec_presente_ec; - bool _rec_presente_ep; - bool _prec; - -protected: - void InFinEs(int); - void leggi_mov(long numreg); // Leggi testata - real calcola_saldo_iniziale(int g, int c, long s, int indbil); - -public: - - bool movimentato() const { return _movimentato; } - bool significativo() const { return _significativo; } - bool esiste_saldo() const { return _rec_presente_ec || _rec_presente_ep;} - bool esiste_saldo_ep() const { return _rec_presente_ep; } - - int annoes () const { return _annoes; } - void set_annoes (int anno) { _annoes = anno; } - - bool causale_mov(long, const TDate&, const TDate&, TString&); - const char* causale_chiusura_es(); - const char* causale_apertura_es(); - - bool ultima_immissione_bilancio(int anno,int g,int c,long s,int indbil,int prov); - bool ultima_immissione_verifica(int anno,int g,int c,long s,int indbil,int prov); - bool data_limite_bilancio(int,int,int,long,const TDate&,const TDate&,int,int); - - TRectype& ricerca_progr_prec(int, int, int, long); - - real saldofin_esprec(int,int,int,long); - bool prg_attuali(int,TConto&,real&,real&); - bool prg_mov_eliminati(int,TConto&,real&,real&); - - const real& saldo() const { return _saldo;} - const real& saldoini() const { return _saldo_iniziale;} - const real& saldoinisusaldi() const { return _saldoiniziale;} - const real& prgdare() const { return _prg_dare;} - const real& prgavere() const { return _prg_avere;} - const bool flagprec() { return _prec; } - bool prg_attuali(int,TConto&,int,real&,real&); - bool prg_mov_eliminati(int,TConto&,int,real&,real&); - TSaldo(); - ~TSaldo(); -}; - - - -class TTab_conti : public TAssoc_array -{ -public: - void aggiorna_conto(const TBill& tc, int anno_es, const TImporto& importo, - bool movap, bool provv, bool somma); - - TConto* add(const TBill& c, int anno); - TConto* find(const TBill& c, int anno); - void remove(const TBill& c, int anno); -}; - - -class TSaldo_agg : public TObject -{ - TTab_conti _tab_conti; - bool _movap; // se e' mov. d'apertura (aggiorno SALDO e FLAGSALINI in - // saldi) - bool _provv; - int _anno_es; // anno esercizio - TDate _data_ulmov; // data ultimo movimento - long _num_ulmov; // numero ultimo movimento - TRectype * _rec; // record corrente sui saldi - -public: - void clear_saldi(int year); - void registra(); - void aggiorna (const TBill& tc, const TImporto& importo, bool somma=TRUE); - void aggiorna (int gruppo, int conto, long sottoconto, - const real& importo, char sezione, bool somma=TRUE); - - TConto* find(const TBill& c, int anno) { return _tab_conti.find(c, anno); } - - void set_anno_es(int anno) { _anno_es = anno; } - int anno_es() const { return _anno_es; } - - void set_movap (bool movap) { _movap = movap; } - bool movap() const { return _movap; } - - void set_movprovv (bool p) { _provv = p; } - bool movprovv() const { return _provv; } - - void set_data_ulmov (const TDate& data) { _data_ulmov = data; } - const TDate& data_ulmov() const { return _data_ulmov; } - - void set_num_ulmov (long num) { _num_ulmov = num; } - long num_ulmov() const { return _num_ulmov; } - - void reset(); // pulisce l'array dei conti - TSaldo_agg(); - int items() const { return _tab_conti.items();} -}; - -#endif - +#ifndef __CGLIB_H +#define __CGLIB_H + +#ifndef __ISAM_H +#include +#endif + +#include +#include "conto.h" +#include "cg2103.h" // per TCausale + + +class TCaus : public TCausale +{ +private: + TRectype _rec; + +public: + bool chiusura() const; + bool apertura() const; + virtual bool read(const char* cod); + + TCaus(const char* cod); + ~TCaus() {} +}; + +class TSaldi_list : public TAssoc_array +{ +public: + TSaldi_list (int g, int c, int aec, int aep=0); + TRectype* saldi() const; +}; + +enum tipobil { DataLimite=1, UltimaImmissione }; +const int EsePre(const int EseCorr); + +class TSaldo +{ + real _saldo, _saldo_iniziale, _saldoiniziale; + real _prg_dare, _prg_avere, _prg_daresca, _prg_averesca; + int _indbil; + TRectype* _saldo_ep; + int _annoes; + TDate _inizioEs, _fineEs; + TString16 _codcaus; + TDate _datareg; + TDate _datacomp; + TString _provv; + + bool _movimentato; + bool _significativo; + bool _rec_presente_ec; + bool _rec_presente_ep; + bool _prec; + +protected: + void InFinEs(int); + void leggi_mov(long numreg); // Leggi testata + real calcola_saldo_iniziale(int g, int c, long s, int indbil); + +public: + + bool movimentato() const { return _movimentato; } + bool significativo() const { return _significativo; } + bool esiste_saldo() const { return _rec_presente_ec || _rec_presente_ep;} + bool esiste_saldo_ep() const { return _rec_presente_ep; } + + int annoes () const { return _annoes; } + void set_annoes (int anno) { _annoes = anno; } + + bool causale_mov(long, const TDate&, const TDate&, TString&); + const char* causale_chiusura_es(); + const char* causale_apertura_es(); + + bool ultima_immissione_bilancio(int anno,int g,int c,long s,int indbil,int prov); + bool ultima_immissione_verifica(int anno,int g,int c,long s,int indbil,int prov); + bool data_limite_bilancio(int,int,int,long,const TDate&,const TDate&,int,int); + + TRectype& ricerca_progr_prec(int, int, int, long); + + real saldofin_esprec(int,int,int,long); + bool prg_attuali(int,TConto&,real&,real&); + bool prg_mov_eliminati(int,TConto&,real&,real&); + + const real& saldo() const { return _saldo;} + const real& saldoini() const { return _saldo_iniziale;} + const real& saldoinisusaldi() const { return _saldoiniziale;} + const real& prgdare() const { return _prg_dare;} + const real& prgavere() const { return _prg_avere;} + const bool flagprec() { return _prec; } + bool prg_attuali(int,TConto&,int,real&,real&); + bool prg_mov_eliminati(int,TConto&,int,real&,real&); + TSaldo(); + ~TSaldo(); +}; + + + +class TTab_conti : public TAssoc_array +{ +public: + void aggiorna_conto(const TBill& tc, int anno_es, const TImporto& importo, + bool movap, bool provv, bool somma); + + TConto* add(const TBill& c, int anno); + TConto* find(const TBill& c, int anno); + void remove(const TBill& c, int anno); +}; + + +class TSaldo_agg : public TObject +{ + TTab_conti _tab_conti; + bool _movap; // se e' mov. d'apertura (aggiorno SALDO e FLAGSALINI in + // saldi) + bool _provv; + int _anno_es; // anno esercizio + TDate _data_ulmov; // data ultimo movimento + long _num_ulmov; // numero ultimo movimento + TRectype * _rec; // record corrente sui saldi + +public: + void clear_saldi(int year); + void registra(); + void aggiorna (const TBill& tc, const TImporto& importo, bool somma=TRUE); + void aggiorna (int gruppo, int conto, long sottoconto, + const real& importo, char sezione, bool somma=TRUE); + + TConto* find(const TBill& c, int anno) { return _tab_conti.find(c, anno); } + + void set_anno_es(int anno) { _anno_es = anno; } + int anno_es() const { return _anno_es; } + + void set_movap (bool movap) { _movap = movap; } + bool movap() const { return _movap; } + + void set_movprovv (bool p) { _provv = p; } + bool movprovv() const { return _provv; } + + void set_data_ulmov (const TDate& data) { _data_ulmov = data; } + const TDate& data_ulmov() const { return _data_ulmov; } + + void set_num_ulmov (long num) { _num_ulmov = num; } + long num_ulmov() const { return _num_ulmov; } + + void reset(); // pulisce l'array dei conti + TSaldo_agg(); + int items() const { return _tab_conti.items();} +}; + +#endif + diff --git a/cg/cglib01.cpp b/cg/cglib01.cpp index 6bdf9cfdc..c7c93bbd1 100755 --- a/cg/cglib01.cpp +++ b/cg/cglib01.cpp @@ -1,673 +1,673 @@ -// cglib01.cpp -// calcolo dei saldi - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "cglib.h" - -/////////////////////////////////////////////////////////// -// Causale -/////////////////////////////////////////////////////////// - -TCaus::TCaus(const char* cod) -: _rec(LF_CAUSALI) -{ - //if (*cod) read(cod); - read(cod); -} - - -// Legge le righe della causale attualmente selezionata sulla maschera -bool TCaus::read(const char* cod) -{ - TLocalisamfile caus(LF_CAUSALI); - - _rec = caus.curr(); _rec.zero(); // Delete header - - if (*cod > ' ') - { - caus.setkey(1); - caus.put(CAU_CODCAUS, cod); - - int err = caus.read(); - if (err != NOERR) return FALSE; - _rec = caus.curr(); - } - return TRUE; -} - -bool TCaus::chiusura() const -{ return _rec.get_char("MOVAP") == 'C'; } - -bool TCaus::apertura() const -{ return _rec.get_char("MOVAP") == 'A'; } - -// -// Cerca l'esercizio precedente di EseCorr -// Se EseCorr e' gia' il primo ritorna 0 -// senno' ritorna, astutamente, EseCorr - 1 -// -const int EsePre(const int EseCorr) -{ - TTable ese("ESC"); - TString first(30); - TString16 codtab; - - ese.first(); - first = ese.get("CODTAB"); - - codtab.format("%04d", EseCorr); - - if (codtab == first) - return 0; - - return EseCorr - 1; -} - -// aep e' l'esercizio precedente -TSaldi_list::TSaldi_list(int gr, int co, int aec, int aep_par) -{ - TLocalisamfile cf(LF_SALDI, FALSE); - bool force; - TString16 key; - int aep = aep_par; - - destroy(); - cf.zero(); - - // Se non passo l'anno precedente lo devo comunque calcolare - if (aep_par == 0) - aep = EsePre(aec); - - // if (aep) - cf.setkey(2); - /* else - { - cf.setkey(1); - cf.put(SLD_ANNOES,aec); - } - */ - cf.put(SLD_GRUPPO,gr); - cf.put(SLD_CONTO,co); - // TRectype rec(cf.curr()); - - for (cf.read(_isgteq);!cf.eof();cf.next()) - { - // if (cf.curr() > rec) break; - const int ae = cf.get_int(SLD_ANNOES); - const int g = cf.get_int(SLD_GRUPPO); - const int c = cf.get_int(SLD_CONTO); - const long s = cf.get_long(SLD_SOTTOCONTO); - - if (g != gr || c != co) break; - - // if (aep) { - if (ae != aec && ae != aep) continue; - // } - - TRectype r(cf.curr()); - key.format("%3d%3d%6ld", g, c, s); - - // Se avevo chiesto anche l'es. prec. puo' darsi che l'abbia gia' trovato - if (aep_par) - force = FALSE; - else - force = TRUE; - - add((const char*) key, r, force); - } -} - -TRectype* TSaldi_list::saldi() const -{ - TObject* o = ((TAssoc_array*)this)->get(); - if (o == NULL) - return (TRectype*)NULL; - else - return (TRectype*)o; -} - -TSaldo::TSaldo() -{ - _saldo_ep = new TRectype(LF_SALDI); - _saldo_iniziale = ZERO; - _saldoiniziale = ZERO; - _prg_dare = ZERO; - _prg_avere = ZERO; - _saldo = ZERO; - _annoes = 0; - _indbil = 0; - _prec = FALSE; - _movimentato = _significativo = FALSE; - _rec_presente_ec = _rec_presente_ep = FALSE; -} - -TSaldo::~TSaldo() -{ - delete _saldo_ep; -} - -real TSaldo::saldofin_esprec(int annoes, int g, int c, long s) -{ - const int annoesprec = EsePre(annoes); - if (annoesprec == 0) // non ci sono esercizi prima del primo - { - _rec_presente_ep = FALSE; - _significativo = FALSE; - return ZERO; - } - - const TRectype& app = ricerca_progr_prec(annoesprec, g, c, s); - - const char flag = app.get(SLD_FLAGSALINI)[0]; - const real saldo = app.get_real(SLD_SALDO); - const real pdare = app.get_real(SLD_PDARE); - const real pavere = app.get_real(SLD_PAVERE); - //const real pdaresca = app.get_real(SLD_PDARESCA); - //const real paveresca = app.get_real(SLD_PAVERESCA); - - /* - _significativo = (saldo != ZERO || pdare != ZERO || pavere != ZERO - || pdaresca != ZERO || paveresca != ZERO); - */ - _significativo = (saldo != ZERO || pdare != ZERO || pavere != ZERO); - - //real tot = pdare-pavere+pdaresca-paveresca; - real tot = pdare-pavere; - - if (flag == 'D') - tot += saldo; - else - tot -= saldo; - - return tot; -} - -//richiamata nel bilancio a sez.contr per data limite -//in realta' calcola il saldo finale es.prec -real TSaldo::calcola_saldo_iniziale(int g,int c,long s,int indbil) -{ - real saldoini, pdaresca, paveresca, pdare, pavere; - char flag; - TLocalisamfile saldi(LF_SALDI, FALSE); - - _significativo = TRUE; - - saldi.zero(); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - saldi.put(SLD_ANNOES,_annoes); - - if (saldi.read() == NOERR) - _rec_presente_ec = TRUE; - else - { - saldi.zero(); - _rec_presente_ec = FALSE; - } - - flag = saldi.get_char(SLD_FLAGSALINI); - saldoini = saldi.get_real(SLD_SALDO); - - _significativo = (saldoini != ZERO); - - if (saldoini != ZERO) //non va considerato!!! Vedi appunti - _saldo_iniziale = ZERO; - - if (saldoini == ZERO) - { - if ( indbil == 1 || indbil == 2 || indbil == 5 ) - { - _prec = TRUE; - saldoini = saldofin_esprec(_annoes, g, c, s); - flag = 'D'; // Il segno DEVE essere quello del saldo precedente - } - _saldo_iniziale = saldoini; - } - -#ifdef DBG - TString sldi(saldoini.string()); -#endif - - //if (flag == 'D') - //return saldoini; - return _saldo_iniziale; - //else - //return (-saldoini); - //return (-_saldo_iniziale); -} - -const char* TSaldo::causale_chiusura_es() -{ - TConfig conf(CONFIG_DITTA); - return conf.get("CoCaCh"); -} - -const char* TSaldo::causale_apertura_es() -{ - TConfig conf(CONFIG_DITTA); - return conf.get("CoCaAp"); -} - -void TSaldo::leggi_mov(long nr) -{ - TLocalisamfile mov(LF_MOV, FALSE); - - mov.zero(); - mov.put (MOV_NUMREG,nr); - - if (mov.read() == NOERR) - { - _codcaus = mov.get (MOV_CODCAUS); - _datareg = mov.get_date(MOV_DATAREG); - _provv = mov.get (MOV_PROVVIS); - _datacomp = mov.get_date(MOV_DATACOMP); - } -} - -//per bilancio scalare (ovvero a sezioni contrapposte) per data limite -bool TSaldo::data_limite_bilancio(int bilancio, int g, int c, long s, const TDate& data_inf, - const TDate& data_sup, int indbil, int stp_prov) -{ - TString16 gcs_corr, gcs_prec; - int gruppo, conto, annoe; - long sottoconto, num_reg; - real importo; - TDate data_mov; - char sezione; - - TLocalisamfile rmov(LF_RMOV, FALSE); - - _saldo_iniziale = ZERO; - _saldo = ZERO; - _movimentato = FALSE; - _rec_presente_ep = FALSE; - _rec_presente_ec = FALSE; - _prec = FALSE; - - gcs_prec = ""; - - rmov.setkey(2); - rmov.zero(); - rmov.put(RMV_GRUPPO,g); - rmov.put(RMV_CONTO,c); - rmov.put(RMV_SOTTOCONTO,s); - TRectype rec(rmov.curr()); - - for (rmov.read(_isgteq); !rmov.eof(); rmov.next()) - { - if (rmov.curr() != rec) break; - - annoe = rmov.get_int(RMV_ANNOES); - gruppo = rmov.get_int(RMV_GRUPPO); - conto = rmov.get_int(RMV_CONTO); - sottoconto = rmov.get_long(RMV_SOTTOCONTO); - num_reg = rmov.get_long(RMV_NUMREG); - sezione = rmov.get_char(RMV_SEZIONE); - importo = rmov.get_real(RMV_IMPORTO); - - // Leggo la testata - leggi_mov(num_reg); - - if (bilancio == DataLimite) - data_mov = _datacomp; - else - { - if (_annoes == 0) - data_mov = _datareg; - else - data_mov = _datacomp; - } - if (data_mov < data_inf || data_mov > data_sup) - continue; - - // "Se la causale del movimento e' uguale a quella di chiusura, - // o di apertura il movimento non va considerato" - // if (_codcaus.not_empty()) - // if (_codcaus == causale_chiusura_es() || - // _codcaus == causale_apertura_es()) - // continue; - - // Modifica del 03-03-1995 - TCaus cau(_codcaus); - - if (_codcaus.not_empty()) - if (cau.chiusura()) //|| cau.apertura()) - continue; - - /* - if (!stp_prov && _provv.trim().not_empty()) - continue; - */ - - if (stp_prov == 1 && _provv.trim().not_empty()) //bilancio normale (non comprende i provvisori) - continue; - - if (stp_prov == 3 && _provv.trim().empty()) //bilancio dei soli provvisori - continue; - - // "I mov. di puro riferimento (= con importo = 0) vanno scartati" - if (importo == ZERO) continue; - - gcs_corr = format ("%3d%3d%6ld", gruppo, conto, sottoconto); - - if (gcs_corr != gcs_prec) - { - gcs_prec = gcs_corr; - if (stp_prov != 3) //bilancio normale o globale - _saldo = calcola_saldo_iniziale(gruppo,conto,sottoconto,indbil); - } - -#ifdef DBG - TString dep1(_saldo.string()); -#endif - - _movimentato = TRUE; - - if (sezione == 'D') - _saldo += importo; - else - _saldo -= importo; - } -#ifdef DBG - TString dep2(_saldo.string()); -#endif - - // Anche se non movimentato vado a vedere il saldo - if (!_movimentato) - if (stp_prov != 3) - _saldo = calcola_saldo_iniziale(g,c,s,indbil); - - return _movimentato; -} - - -//per bilancio di verifica all'ultima immissione -bool TSaldo::ultima_immissione_verifica(int annoes,int g,int c,long s,int indbil,int stp_prov) -{ - //Si considerano i saldi e non piu' i movimenti - char sezione; - int gruppo, conto, annoe; - long sottoconto; - real pdarepro, paverepro; - bool esito = FALSE; - TLocalisamfile saldi(LF_SALDI, FALSE); - - _saldo_iniziale = ZERO; - _saldoiniziale = ZERO; - _prg_dare = ZERO; - _prg_avere = ZERO; - _prg_daresca = ZERO; - _prg_averesca = ZERO; - _saldo = ZERO; - - saldi.zero(); - - saldi.put(SLD_ANNOES,annoes); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - - if (saldi.read() == NOERR) - { - annoe = saldi.get_int(SLD_ANNOES); - gruppo = saldi.get_int(SLD_GRUPPO); - conto = saldi.get_int(SLD_CONTO); - sottoconto = saldi.get_long(SLD_SOTTOCONTO); - _saldo_iniziale = saldi.get_real(SLD_SALDO); - _prg_dare = saldi.get_real(SLD_PDARE); - _prg_avere = saldi.get_real(SLD_PAVERE); - pdarepro = saldi.get_real(SLD_PDAREPRO); - paverepro = saldi.get_real(SLD_PAVEREPRO); - sezione = saldi.get_char(SLD_FLAGSALINI); - - if (stp_prov == 1) //bilancio normale (senza provvisori) - if (_saldo_iniziale == ZERO && _prg_dare == ZERO && _prg_avere == ZERO) - return esito; - - if (stp_prov == 2) //bilancio globale (con provvisori) - if (_saldo_iniziale == ZERO && _prg_dare == ZERO && _prg_avere == ZERO - && pdarepro == ZERO && paverepro == ZERO) - return esito; - - if (stp_prov == 3) //bilancio dei soli mov. provvisori - if (pdarepro == ZERO && paverepro == ZERO) - return esito; - - if (sezione == 'A') _saldo_iniziale = -_saldo_iniziale; - - _saldoiniziale = _saldo_iniziale; //saldo iniziale presente sul record saldi - //non comprensivo del saldo finale es.precedente - - if (stp_prov != 3) - if (indbil == 1 || indbil == 2 || indbil == 5) - if (_saldo_iniziale == ZERO) - _saldo_iniziale += saldofin_esprec(annoes,gruppo,conto,sottoconto); - - esito = TRUE; - - if (stp_prov == 1) - _saldo = _saldo_iniziale + _prg_dare - _prg_avere; - - if (stp_prov == 2) - _saldo = _saldo_iniziale + _prg_dare - _prg_avere + pdarepro - paverepro; - - if (stp_prov == 3) - _saldo = pdarepro - paverepro; - } - return esito; -} - -//per bilancio a sezioni contrapposte all'ultima immissione -bool TSaldo::ultima_immissione_bilancio(int annoes,int g,int c,long s,int indbil,int stp_prov) -{ - //Si considerano i saldi e non piu' i movimenti - char sezione; - int gruppo, conto, annoe; - long sottoconto; - real pdarepro, paverepro; - bool esito = FALSE; - TLocalisamfile saldi(LF_SALDI, FALSE); - - _saldo_iniziale = ZERO; - _prg_dare = ZERO; - _prg_avere = ZERO; - _prg_daresca = ZERO; - _prg_averesca = ZERO; - _saldo = ZERO; - _rec_presente_ec = FALSE; - _rec_presente_ep = FALSE; - _prec = FALSE; - - saldi.zero(); - - saldi.put(SLD_ANNOES,annoes); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - - if (saldi.read() == NOERR) - { - annoe = saldi.get_int(SLD_ANNOES); - gruppo = saldi.get_int(SLD_GRUPPO); - conto = saldi.get_int(SLD_CONTO); - sottoconto = saldi.get_long(SLD_SOTTOCONTO); - _saldo_iniziale = saldi.get_real(SLD_SALDO); - _prg_dare = saldi.get_real(SLD_PDARE); - _prg_avere = saldi.get_real(SLD_PAVERE); - pdarepro = saldi.get_real(SLD_PDAREPRO); - paverepro = saldi.get_real(SLD_PAVEREPRO); - sezione = saldi.get_char(SLD_FLAGSALINI); - - /* - esito = (_saldo_iniziale != ZERO || _prg_dare != ZERO || _prg_avere != ZERO - || _prg_daresca != ZERO || _prg_averesca != ZERO); - */ - if (stp_prov == 1) //bilancio normale (senza provvisori) - esito = (_saldo_iniziale != ZERO || _prg_dare != ZERO || _prg_avere != ZERO); - - if (stp_prov == 2) //bilancio globale (con provvisori) - esito = (_saldo_iniziale != ZERO || _prg_dare != ZERO || _prg_avere != ZERO - || pdarepro != ZERO || paverepro != ZERO); - - if (stp_prov == 3) //bilancio dei soli mov. provvisori - esito = (pdarepro != ZERO || paverepro != ZERO); - - if (sezione == 'A') _saldo_iniziale = -_saldo_iniziale; - - _rec_presente_ec = esito; - } - - if (stp_prov != 3) - if (indbil == 1 || indbil == 2 || indbil == 5) - if (_saldo_iniziale == ZERO) - { - _prec = TRUE; - _saldo_iniziale += saldofin_esprec(annoes,g,c,s); - } - - //_saldo = _saldo_iniziale + _prg_dare - _prg_avere + _prg_daresca - _prg_averesca; - if (stp_prov == 1) - _saldo = _saldo_iniziale + _prg_dare - _prg_avere; - - if (stp_prov == 2) - _saldo = _saldo_iniziale + _prg_dare - _prg_avere + pdarepro - paverepro; - - if (stp_prov == 3) - _saldo = pdarepro - paverepro; - - return esito; -} - -TRectype& TSaldo::ricerca_progr_prec (int annoesprec, int g, int c, long s) -{ - TLocalisamfile saldi(LF_SALDI, FALSE); - - const int oldkey = saldi.getkey(); - - saldi.setkey(1); - saldi.zero(); - - saldi.put(SLD_ANNOES,annoesprec); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - - if (saldi.read() == NOERR) - _rec_presente_ep = TRUE; - else - { - saldi.zero(); - _rec_presente_ep = FALSE; - } - - (*_saldo_ep) = saldi.curr(); - saldi.setkey(oldkey); - -// riposiziona... - saldi.zero(); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - saldi.put(SLD_ANNOES,annoesprec+1); - saldi.read(_isequal); - - return (*_saldo_ep); -} - -//calcolo dei progressivi attuali -bool TSaldo::prg_attuali(int annoes,TConto& conto,real& prgdare,real& prgavere) -{ - real saldoini = ZERO; - real pdare = ZERO; - real pavere = ZERO; - real pdaresca = ZERO; - real paveresca = ZERO; - char flagsalini; - int g = conto.gruppo(); - int c = conto.conto(); - long s = conto.sottoconto(); - TLocalisamfile saldi(LF_SALDI, FALSE); - - saldi.zero(); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - saldi.put(SLD_ANNOES,annoes); - - if (saldi.read() == NOERR) - { - flagsalini = saldi.get_char(SLD_FLAGSALINI); - saldoini = saldi.get_real(SLD_SALDO); - pdare = saldi.get_real(SLD_PDARE); - pavere = saldi.get_real(SLD_PAVERE); - pdaresca = saldi.get_real(SLD_PDARESCA); - paveresca = saldi.get_real(SLD_PAVERESCA); - - if (flagsalini == 'D') - { - prgdare = saldoini + pdare + pdaresca; - prgavere = pavere + paveresca; - } - else - { - prgdare = pdare + pdaresca; - prgavere = saldoini + pavere + paveresca; - } - } - return TRUE; -} - -bool TSaldo::prg_mov_eliminati(int annoes,TConto& conto,real& prgdare,real& prgavere) -{ - real saldoini = ZERO; - real pdaresca = ZERO; - real paveresca = ZERO; - char flagsalini; - int g = conto.gruppo(); - int c = conto.conto(); - long s = conto.sottoconto(); - TLocalisamfile saldi(LF_SALDI, FALSE); - - saldi.zero(); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - saldi.put(SLD_ANNOES,annoes); - - if (saldi.read() == NOERR) - { - flagsalini = saldi.get(SLD_FLAGSALINI)[0]; - saldoini = saldi.get_real(SLD_SALDO); - pdaresca = saldi.get_real(SLD_PDARESCA); - paveresca = saldi.get_real(SLD_PAVERESCA); - if (flagsalini == 'D') - { - prgdare = saldoini + pdaresca; - prgavere = paveresca; - } - else - { - prgdare = pdaresca; - prgavere = saldoini + paveresca; - } - } - return TRUE; -} - - - - - +// cglib01.cpp +// calcolo dei saldi + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "cglib.h" + +/////////////////////////////////////////////////////////// +// Causale +/////////////////////////////////////////////////////////// + +TCaus::TCaus(const char* cod) +: _rec(LF_CAUSALI) +{ + //if (*cod) read(cod); + read(cod); +} + + +// Legge le righe della causale attualmente selezionata sulla maschera +bool TCaus::read(const char* cod) +{ + TLocalisamfile caus(LF_CAUSALI); + + _rec = caus.curr(); _rec.zero(); // Delete header + + if (*cod > ' ') + { + caus.setkey(1); + caus.put(CAU_CODCAUS, cod); + + int err = caus.read(); + if (err != NOERR) return FALSE; + _rec = caus.curr(); + } + return TRUE; +} + +bool TCaus::chiusura() const +{ return _rec.get_char("MOVAP") == 'C'; } + +bool TCaus::apertura() const +{ return _rec.get_char("MOVAP") == 'A'; } + +// +// Cerca l'esercizio precedente di EseCorr +// Se EseCorr e' gia' il primo ritorna 0 +// senno' ritorna, astutamente, EseCorr - 1 +// +const int EsePre(const int EseCorr) +{ + TTable ese("ESC"); + TString first(30); + TString16 codtab; + + ese.first(); + first = ese.get("CODTAB"); + + codtab.format("%04d", EseCorr); + + if (codtab == first) + return 0; + + return EseCorr - 1; +} + +// aep e' l'esercizio precedente +TSaldi_list::TSaldi_list(int gr, int co, int aec, int aep_par) +{ + TLocalisamfile cf(LF_SALDI, FALSE); + bool force; + TString16 key; + int aep = aep_par; + + destroy(); + cf.zero(); + + // Se non passo l'anno precedente lo devo comunque calcolare + if (aep_par == 0) + aep = EsePre(aec); + + // if (aep) + cf.setkey(2); + /* else + { + cf.setkey(1); + cf.put(SLD_ANNOES,aec); + } + */ + cf.put(SLD_GRUPPO,gr); + cf.put(SLD_CONTO,co); + // TRectype rec(cf.curr()); + + for (cf.read(_isgteq);!cf.eof();cf.next()) + { + // if (cf.curr() > rec) break; + const int ae = cf.get_int(SLD_ANNOES); + const int g = cf.get_int(SLD_GRUPPO); + const int c = cf.get_int(SLD_CONTO); + const long s = cf.get_long(SLD_SOTTOCONTO); + + if (g != gr || c != co) break; + + // if (aep) { + if (ae != aec && ae != aep) continue; + // } + + TRectype r(cf.curr()); + key.format("%3d%3d%6ld", g, c, s); + + // Se avevo chiesto anche l'es. prec. puo' darsi che l'abbia gia' trovato + if (aep_par) + force = FALSE; + else + force = TRUE; + + add((const char*) key, r, force); + } +} + +TRectype* TSaldi_list::saldi() const +{ + TObject* o = ((TAssoc_array*)this)->get(); + if (o == NULL) + return (TRectype*)NULL; + else + return (TRectype*)o; +} + +TSaldo::TSaldo() +{ + _saldo_ep = new TRectype(LF_SALDI); + _saldo_iniziale = ZERO; + _saldoiniziale = ZERO; + _prg_dare = ZERO; + _prg_avere = ZERO; + _saldo = ZERO; + _annoes = 0; + _indbil = 0; + _prec = FALSE; + _movimentato = _significativo = FALSE; + _rec_presente_ec = _rec_presente_ep = FALSE; +} + +TSaldo::~TSaldo() +{ + delete _saldo_ep; +} + +real TSaldo::saldofin_esprec(int annoes, int g, int c, long s) +{ + const int annoesprec = EsePre(annoes); + if (annoesprec == 0) // non ci sono esercizi prima del primo + { + _rec_presente_ep = FALSE; + _significativo = FALSE; + return ZERO; + } + + const TRectype& app = ricerca_progr_prec(annoesprec, g, c, s); + + const char flag = app.get(SLD_FLAGSALINI)[0]; + const real saldo = app.get_real(SLD_SALDO); + const real pdare = app.get_real(SLD_PDARE); + const real pavere = app.get_real(SLD_PAVERE); + //const real pdaresca = app.get_real(SLD_PDARESCA); + //const real paveresca = app.get_real(SLD_PAVERESCA); + + /* + _significativo = (saldo != ZERO || pdare != ZERO || pavere != ZERO + || pdaresca != ZERO || paveresca != ZERO); + */ + _significativo = (saldo != ZERO || pdare != ZERO || pavere != ZERO); + + //real tot = pdare-pavere+pdaresca-paveresca; + real tot = pdare-pavere; + + if (flag == 'D') + tot += saldo; + else + tot -= saldo; + + return tot; +} + +//richiamata nel bilancio a sez.contr per data limite +//in realta' calcola il saldo finale es.prec +real TSaldo::calcola_saldo_iniziale(int g,int c,long s,int indbil) +{ + real saldoini, pdaresca, paveresca, pdare, pavere; + char flag; + TLocalisamfile saldi(LF_SALDI, FALSE); + + _significativo = TRUE; + + saldi.zero(); + saldi.put(SLD_GRUPPO,g); + saldi.put(SLD_CONTO,c); + saldi.put(SLD_SOTTOCONTO,s); + saldi.put(SLD_ANNOES,_annoes); + + if (saldi.read() == NOERR) + _rec_presente_ec = TRUE; + else + { + saldi.zero(); + _rec_presente_ec = FALSE; + } + + flag = saldi.get_char(SLD_FLAGSALINI); + saldoini = saldi.get_real(SLD_SALDO); + + _significativo = (saldoini != ZERO); + + if (saldoini != ZERO) //non va considerato!!! Vedi appunti + _saldo_iniziale = ZERO; + + if (saldoini == ZERO) + { + if ( indbil == 1 || indbil == 2 || indbil == 5 ) + { + _prec = TRUE; + saldoini = saldofin_esprec(_annoes, g, c, s); + flag = 'D'; // Il segno DEVE essere quello del saldo precedente + } + _saldo_iniziale = saldoini; + } + +#ifdef DBG + TString sldi(saldoini.string()); +#endif + + //if (flag == 'D') + //return saldoini; + return _saldo_iniziale; + //else + //return (-saldoini); + //return (-_saldo_iniziale); +} + +const char* TSaldo::causale_chiusura_es() +{ + TConfig conf(CONFIG_DITTA); + return conf.get("CoCaCh"); +} + +const char* TSaldo::causale_apertura_es() +{ + TConfig conf(CONFIG_DITTA); + return conf.get("CoCaAp"); +} + +void TSaldo::leggi_mov(long nr) +{ + TLocalisamfile mov(LF_MOV, FALSE); + + mov.zero(); + mov.put (MOV_NUMREG,nr); + + if (mov.read() == NOERR) + { + _codcaus = mov.get (MOV_CODCAUS); + _datareg = mov.get_date(MOV_DATAREG); + _provv = mov.get (MOV_PROVVIS); + _datacomp = mov.get_date(MOV_DATACOMP); + } +} + +//per bilancio scalare (ovvero a sezioni contrapposte) per data limite +bool TSaldo::data_limite_bilancio(int bilancio, int g, int c, long s, const TDate& data_inf, + const TDate& data_sup, int indbil, int stp_prov) +{ + TString16 gcs_corr, gcs_prec; + int gruppo, conto, annoe; + long sottoconto, num_reg; + real importo; + TDate data_mov; + char sezione; + + TLocalisamfile rmov(LF_RMOV, FALSE); + + _saldo_iniziale = ZERO; + _saldo = ZERO; + _movimentato = FALSE; + _rec_presente_ep = FALSE; + _rec_presente_ec = FALSE; + _prec = FALSE; + + gcs_prec = ""; + + rmov.setkey(2); + rmov.zero(); + rmov.put(RMV_GRUPPO,g); + rmov.put(RMV_CONTO,c); + rmov.put(RMV_SOTTOCONTO,s); + TRectype rec(rmov.curr()); + + for (rmov.read(_isgteq); !rmov.eof(); rmov.next()) + { + if (rmov.curr() != rec) break; + + annoe = rmov.get_int(RMV_ANNOES); + gruppo = rmov.get_int(RMV_GRUPPO); + conto = rmov.get_int(RMV_CONTO); + sottoconto = rmov.get_long(RMV_SOTTOCONTO); + num_reg = rmov.get_long(RMV_NUMREG); + sezione = rmov.get_char(RMV_SEZIONE); + importo = rmov.get_real(RMV_IMPORTO); + + // Leggo la testata + leggi_mov(num_reg); + + if (bilancio == DataLimite) + data_mov = _datacomp; + else + { + if (_annoes == 0) + data_mov = _datareg; + else + data_mov = _datacomp; + } + if (data_mov < data_inf || data_mov > data_sup) + continue; + + // "Se la causale del movimento e' uguale a quella di chiusura, + // o di apertura il movimento non va considerato" + // if (_codcaus.not_empty()) + // if (_codcaus == causale_chiusura_es() || + // _codcaus == causale_apertura_es()) + // continue; + + // Modifica del 03-03-1995 + TCaus cau(_codcaus); + + if (_codcaus.not_empty()) + if (cau.chiusura()) //|| cau.apertura()) + continue; + + /* + if (!stp_prov && _provv.trim().not_empty()) + continue; + */ + + if (stp_prov == 1 && _provv.trim().not_empty()) //bilancio normale (non comprende i provvisori) + continue; + + if (stp_prov == 3 && _provv.trim().empty()) //bilancio dei soli provvisori + continue; + + // "I mov. di puro riferimento (= con importo = 0) vanno scartati" + if (importo == ZERO) continue; + + gcs_corr = format ("%3d%3d%6ld", gruppo, conto, sottoconto); + + if (gcs_corr != gcs_prec) + { + gcs_prec = gcs_corr; + if (stp_prov != 3) //bilancio normale o globale + _saldo = calcola_saldo_iniziale(gruppo,conto,sottoconto,indbil); + } + +#ifdef DBG + TString dep1(_saldo.string()); +#endif + + _movimentato = TRUE; + + if (sezione == 'D') + _saldo += importo; + else + _saldo -= importo; + } +#ifdef DBG + TString dep2(_saldo.string()); +#endif + + // Anche se non movimentato vado a vedere il saldo + if (!_movimentato) + if (stp_prov != 3) + _saldo = calcola_saldo_iniziale(g,c,s,indbil); + + return _movimentato; +} + + +//per bilancio di verifica all'ultima immissione +bool TSaldo::ultima_immissione_verifica(int annoes,int g,int c,long s,int indbil,int stp_prov) +{ + //Si considerano i saldi e non piu' i movimenti + char sezione; + int gruppo, conto, annoe; + long sottoconto; + real pdarepro, paverepro; + bool esito = FALSE; + TLocalisamfile saldi(LF_SALDI, FALSE); + + _saldo_iniziale = ZERO; + _saldoiniziale = ZERO; + _prg_dare = ZERO; + _prg_avere = ZERO; + _prg_daresca = ZERO; + _prg_averesca = ZERO; + _saldo = ZERO; + + saldi.zero(); + + saldi.put(SLD_ANNOES,annoes); + saldi.put(SLD_GRUPPO,g); + saldi.put(SLD_CONTO,c); + saldi.put(SLD_SOTTOCONTO,s); + + if (saldi.read() == NOERR) + { + annoe = saldi.get_int(SLD_ANNOES); + gruppo = saldi.get_int(SLD_GRUPPO); + conto = saldi.get_int(SLD_CONTO); + sottoconto = saldi.get_long(SLD_SOTTOCONTO); + _saldo_iniziale = saldi.get_real(SLD_SALDO); + _prg_dare = saldi.get_real(SLD_PDARE); + _prg_avere = saldi.get_real(SLD_PAVERE); + pdarepro = saldi.get_real(SLD_PDAREPRO); + paverepro = saldi.get_real(SLD_PAVEREPRO); + sezione = saldi.get_char(SLD_FLAGSALINI); + + if (stp_prov == 1) //bilancio normale (senza provvisori) + if (_saldo_iniziale == ZERO && _prg_dare == ZERO && _prg_avere == ZERO) + return esito; + + if (stp_prov == 2) //bilancio globale (con provvisori) + if (_saldo_iniziale == ZERO && _prg_dare == ZERO && _prg_avere == ZERO + && pdarepro == ZERO && paverepro == ZERO) + return esito; + + if (stp_prov == 3) //bilancio dei soli mov. provvisori + if (pdarepro == ZERO && paverepro == ZERO) + return esito; + + if (sezione == 'A') _saldo_iniziale = -_saldo_iniziale; + + _saldoiniziale = _saldo_iniziale; //saldo iniziale presente sul record saldi + //non comprensivo del saldo finale es.precedente + + if (stp_prov != 3) + if (indbil == 1 || indbil == 2 || indbil == 5) + if (_saldo_iniziale == ZERO) + _saldo_iniziale += saldofin_esprec(annoes,gruppo,conto,sottoconto); + + esito = TRUE; + + if (stp_prov == 1) + _saldo = _saldo_iniziale + _prg_dare - _prg_avere; + + if (stp_prov == 2) + _saldo = _saldo_iniziale + _prg_dare - _prg_avere + pdarepro - paverepro; + + if (stp_prov == 3) + _saldo = pdarepro - paverepro; + } + return esito; +} + +//per bilancio a sezioni contrapposte all'ultima immissione +bool TSaldo::ultima_immissione_bilancio(int annoes,int g,int c,long s,int indbil,int stp_prov) +{ + //Si considerano i saldi e non piu' i movimenti + char sezione; + int gruppo, conto, annoe; + long sottoconto; + real pdarepro, paverepro; + bool esito = FALSE; + TLocalisamfile saldi(LF_SALDI, FALSE); + + _saldo_iniziale = ZERO; + _prg_dare = ZERO; + _prg_avere = ZERO; + _prg_daresca = ZERO; + _prg_averesca = ZERO; + _saldo = ZERO; + _rec_presente_ec = FALSE; + _rec_presente_ep = FALSE; + _prec = FALSE; + + saldi.zero(); + + saldi.put(SLD_ANNOES,annoes); + saldi.put(SLD_GRUPPO,g); + saldi.put(SLD_CONTO,c); + saldi.put(SLD_SOTTOCONTO,s); + + if (saldi.read() == NOERR) + { + annoe = saldi.get_int(SLD_ANNOES); + gruppo = saldi.get_int(SLD_GRUPPO); + conto = saldi.get_int(SLD_CONTO); + sottoconto = saldi.get_long(SLD_SOTTOCONTO); + _saldo_iniziale = saldi.get_real(SLD_SALDO); + _prg_dare = saldi.get_real(SLD_PDARE); + _prg_avere = saldi.get_real(SLD_PAVERE); + pdarepro = saldi.get_real(SLD_PDAREPRO); + paverepro = saldi.get_real(SLD_PAVEREPRO); + sezione = saldi.get_char(SLD_FLAGSALINI); + + /* + esito = (_saldo_iniziale != ZERO || _prg_dare != ZERO || _prg_avere != ZERO + || _prg_daresca != ZERO || _prg_averesca != ZERO); + */ + if (stp_prov == 1) //bilancio normale (senza provvisori) + esito = (_saldo_iniziale != ZERO || _prg_dare != ZERO || _prg_avere != ZERO); + + if (stp_prov == 2) //bilancio globale (con provvisori) + esito = (_saldo_iniziale != ZERO || _prg_dare != ZERO || _prg_avere != ZERO + || pdarepro != ZERO || paverepro != ZERO); + + if (stp_prov == 3) //bilancio dei soli mov. provvisori + esito = (pdarepro != ZERO || paverepro != ZERO); + + if (sezione == 'A') _saldo_iniziale = -_saldo_iniziale; + + _rec_presente_ec = esito; + } + + if (stp_prov != 3) + if (indbil == 1 || indbil == 2 || indbil == 5) + if (_saldo_iniziale == ZERO) + { + _prec = TRUE; + _saldo_iniziale += saldofin_esprec(annoes,g,c,s); + } + + //_saldo = _saldo_iniziale + _prg_dare - _prg_avere + _prg_daresca - _prg_averesca; + if (stp_prov == 1) + _saldo = _saldo_iniziale + _prg_dare - _prg_avere; + + if (stp_prov == 2) + _saldo = _saldo_iniziale + _prg_dare - _prg_avere + pdarepro - paverepro; + + if (stp_prov == 3) + _saldo = pdarepro - paverepro; + + return esito; +} + +TRectype& TSaldo::ricerca_progr_prec (int annoesprec, int g, int c, long s) +{ + TLocalisamfile saldi(LF_SALDI, FALSE); + + const int oldkey = saldi.getkey(); + + saldi.setkey(1); + saldi.zero(); + + saldi.put(SLD_ANNOES,annoesprec); + saldi.put(SLD_GRUPPO,g); + saldi.put(SLD_CONTO,c); + saldi.put(SLD_SOTTOCONTO,s); + + if (saldi.read() == NOERR) + _rec_presente_ep = TRUE; + else + { + saldi.zero(); + _rec_presente_ep = FALSE; + } + + (*_saldo_ep) = saldi.curr(); + saldi.setkey(oldkey); + + // riposiziona... + saldi.zero(); + saldi.put(SLD_GRUPPO,g); + saldi.put(SLD_CONTO,c); + saldi.put(SLD_SOTTOCONTO,s); + saldi.put(SLD_ANNOES,annoesprec+1); + saldi.read(_isequal); + + return (*_saldo_ep); +} + +//calcolo dei progressivi attuali +bool TSaldo::prg_attuali(int annoes,TConto& conto,real& prgdare,real& prgavere) +{ + real saldoini = ZERO; + real pdare = ZERO; + real pavere = ZERO; + real pdaresca = ZERO; + real paveresca = ZERO; + char flagsalini; + int g = conto.gruppo(); + int c = conto.conto(); + long s = conto.sottoconto(); + TLocalisamfile saldi(LF_SALDI, FALSE); + + saldi.zero(); + saldi.put(SLD_GRUPPO,g); + saldi.put(SLD_CONTO,c); + saldi.put(SLD_SOTTOCONTO,s); + saldi.put(SLD_ANNOES,annoes); + + if (saldi.read() == NOERR) + { + flagsalini = saldi.get_char(SLD_FLAGSALINI); + saldoini = saldi.get_real(SLD_SALDO); + pdare = saldi.get_real(SLD_PDARE); + pavere = saldi.get_real(SLD_PAVERE); + pdaresca = saldi.get_real(SLD_PDARESCA); + paveresca = saldi.get_real(SLD_PAVERESCA); + + if (flagsalini == 'D') + { + prgdare = saldoini + pdare + pdaresca; + prgavere = pavere + paveresca; + } + else + { + prgdare = pdare + pdaresca; + prgavere = saldoini + pavere + paveresca; + } + } + return TRUE; +} + +bool TSaldo::prg_mov_eliminati(int annoes,TConto& conto,real& prgdare,real& prgavere) +{ + real saldoini = ZERO; + real pdaresca = ZERO; + real paveresca = ZERO; + char flagsalini; + int g = conto.gruppo(); + int c = conto.conto(); + long s = conto.sottoconto(); + TLocalisamfile saldi(LF_SALDI, FALSE); + + saldi.zero(); + saldi.put(SLD_GRUPPO,g); + saldi.put(SLD_CONTO,c); + saldi.put(SLD_SOTTOCONTO,s); + saldi.put(SLD_ANNOES,annoes); + + if (saldi.read() == NOERR) + { + flagsalini = saldi.get(SLD_FLAGSALINI)[0]; + saldoini = saldi.get_real(SLD_SALDO); + pdaresca = saldi.get_real(SLD_PDARESCA); + paveresca = saldi.get_real(SLD_PAVERESCA); + if (flagsalini == 'D') + { + prgdare = saldoini + pdaresca; + prgavere = paveresca; + } + else + { + prgdare = pdaresca; + prgavere = saldoini + paveresca; + } + } + return TRUE; +} + + + + +