diff --git a/cg/cg6900.h b/cg/cg6900.h index 20837ddfb..69b33a9cb 100755 --- a/cg/cg6900.h +++ b/cg/cg6900.h @@ -69,20 +69,22 @@ class TInv_cont : public TApplication TIsamtempfile* _tpart; TIsamtempfile* _tscad; TIsamtempfile* _tpagsca; - TArchive _arc; + TArchive _arc; + TAssoc_array _riga_interna, _ultima_rata; char _scelta; TString _control_rec, _header, _trasf, _std, _stato, _marker, _nome_simbolico; TString _files, _codcaus, _numdoc, _reg, _codpag, _tipodoc, _codcausm, _sigle; - TString _ocfpi, _ragsococc, _indocc, _capocc, _localocc, _provocc, _codvali; + TString _ocfpi, _ragsococc, _indocc, _capocc, _localocc, _provocc, _codvali, _codval; bool _esiste_ditta, _esiste_record, _inviato, _flag_bollato; long _ditta, _protiva, _uprotiva, _codcf, _numrec, _tot_rec; long _dim_tot, _dim_disk,_dittaAS; long _numrec_cau,_numrec_clifo,_numrec_pcon,_numrec_pn,_numrec_iva,_numrec_sc; int _num,_annoes; TDate _data, _datadoc, _data74ter,_datalimsk,_dataregiva,_datareg; - real _corrlire, _cambioi, _corrval; + real _corrlire, _cambioi, _corrval,_cambio; + long _ultima_nreg; public: TString _titolo; @@ -106,7 +108,7 @@ public: void codifica_ditta (TMask& m); void testata_mov_PN (); void testata_trasfer(long nreg, int nrig, TString& record); - void sola_iva(TString& record); + void sola_iva(TString& record,long nreg); bool testata_mov_IVA(long numreg); void cerca_occasionale(); void cerca_comune_occas(const TString& com); @@ -139,13 +141,21 @@ public: void scrivi_righeSCAD(char,int,int,long,int,TString&,int); void scrivi_righePAGSCA(char,int,int,long,int,TString&,int); void SC_inviato(char,int,int,long,int,TString&,int); + + int nprogre_interno(long nreg, int nrig); + void aggiorna_array_rate(TString& npart, int nrata); + int ultima_rata_partita(TString& npart); + void partita2trasfer(TString& record, bool crea_record_riferimento = TRUE); + void pagsca2trasfer (TString& record, real& importo, real& importoval); + long crea_record_riferimento_PN(); bool invio_contabilita(); bool invio_tab_cau(); bool invio_clifo (); bool invio_pcon (); bool invio_mov_PN (); - bool invio_mov_IVA(); + bool invio_mov_IVA(); + bool invio_mov_SC (); void aggiorna_header(TString& files); void aggiorna_trasfer(TString& files); diff --git a/cg/cg6901.cpp b/cg/cg6901.cpp index 88cd8e9b7..396e09ae9 100755 --- a/cg/cg6901.cpp +++ b/cg/cg6901.cpp @@ -893,18 +893,41 @@ void TLista_archivi::controlla_PNIVA(char file) printer().formfeed(); } +void TLista_archivi::ragsocCF(char tipo, long codcf, TString& ragsoc) +{ + TLocalisamfile clifo (LF_CLIFO); + + clifo.setkey(1); + clifo.zero(); + clifo.put(CLI_TIPOCF, tipo); + clifo.put(CLI_CODCF, codcf); + if (clifo.read() == NOERR) + ragsoc = clifo.get(CLI_RAGSOC); + else + ragsoc = ""; + + if (ragsoc.not_empty()) + { + TString cognome (ragsoc.mid(0,30)); + cognome.trim(); + TString nome (ragsoc.mid(30,20)); + nome.trim(); + ragsoc = ""; + ragsoc << cognome << " " << nome; + } +} + void TLista_archivi::controlla_fatture(char file) { -/* TPrintrow row; - TString str; + TString str,rec,filer; bool errore = FALSE; bool salto = FALSE; bool intesta = TRUE; bool tit_riga = FALSE; - TString_array stampa(50); - int num; - long nreg_p = 0; + TString_array stampa(50); + char tipo_p = ' '; + long sottoc_p = 0; _part->setkey(1); _part->zero(); @@ -928,370 +951,362 @@ void TLista_archivi::controlla_fatture(char file) TString numpart = _part->get (PART_NUMPART); int nriga = _part->get_int (PART_NRIGA); long nreg = _part->get_long(PART_NREG); - int + int numrig = _part->get_int (PART_NUMRIG); + + if (nriga == 9999) continue; + if (nreg > 999999) { errore = TRUE; - stampa.add(" - Rilevato un numero di registrazione composto da 7"); + stampa.add(" - Rilevato un numero di registrazione corrispondente a primanota composto da 7 cifre"); } - - TString reg = _mov->get(MOV_REG); + if (numrig > 99) + { + errore = TRUE; + stampa.add(" - Rilevato un numero di riga corrispondente a primanota composto da 3 cifre"); + } + if (nriga > 999) + { + errore = TRUE; + stampa.add(" - Rilevato un numero di riga partita composto da 4 cifre"); + } + if (gruppo > 99) + { + errore = TRUE; + stampa.add(" - Rilevato un gruppo composto da 3 cifre"); + } + if (conto > 99) + { + errore = TRUE; + stampa.add(" - Rilevato un conto composto da 3 cifre"); + } + TString reg = _part->get(PART_REG); if (!controlla_valore(reg,9,1)) { errore = TRUE; stampa.add(" - Rilevato un codice registro IVA composto da 2 o piu' cifre"); } - - const char* codcaus = _mov->get(MOV_CODCAUS); + const char* codcaus = _part->get(PART_CODCAUS); if (codcaus && *codcaus) if (!real::is_natural(codcaus)) { errore = TRUE; stampa.add(" - Rilevato un codice causale alfanumerico"); } - - TString codpag = _mov->get(MOV_CODPAG); - if (!controlla_valore(codpag,99,2)) + int gruppocl = _part->get_int(PART_GRUPPOCL); + if (gruppocl > 99) { errore = TRUE; - stampa.add(" - Rilevato un codice di pagamento composto da 3 o piu' cifre"); - } - - num = 0; + stampa.add(" - Rilevato un gruppo cliente composto da 3 cifre"); + } + int contocl = _part->get_int(PART_CONTOCL); + if (contocl > 99) + { + errore = TRUE; + stampa.add(" - Rilevato un conto cliente composto da 3 cifre"); + } bool prima = TRUE; - - _rmov->setkey(1); - _rmov->zero(); - _rmov->put(RMV_NUMREG, nreg); - - TRectype rmov (_rmov->curr()); - - for (_rmov->read(); !_rmov->eof(); _rmov->next()) - { - - if (_rmov->curr() > rmov) break; - - tit_riga = FALSE; - - soliva = FALSE; - - num++; - if (num > 99) - { - errore = TRUE; - stampa.add(" - Rilevato movimento di Primanota con numero righe superiore a 99"); - } + _scad->setkey(1); + _scad->zero(); + _scad->put(SCAD_TIPOCF, tipo); + if (gruppo != 0) + _scad->put(SCAD_GRUPPO, gruppo); + if (conto != 0) + _scad->put(SCAD_CONTO, conto); + if (sottoc != 0) + _scad->put(SCAD_SOTTOCONTO, sottoc); + _scad->put(SCAD_ANNO, anno); + _scad->put(SCAD_NUMPART, numpart); + _scad->put(SCAD_NRIGA, nriga); + + TRectype scadenza (_scad->curr()); + + for (_scad->read(_isgteq); !_scad->eof(); _scad->next()) + { + rec = scadenza.get(SCAD_NUMPART); + filer = _scad->get(SCAD_NUMPART); + + if (_scad->curr() != scadenza || filer != rec) break; - int nr = _rmov->get_int (RMV_NUMRIG); - int g = _rmov->get_int (RMV_GRUPPO); - int c = _rmov->get_int (RMV_CONTO); - int gc = _rmov->get_int (RMV_GRUPPOC); - int cc = _rmov->get_int (RMV_CONTOC); - - if (nr > 99) - { - if (prima) - { - stampa.add(" "); - stampa.add("Righe primanota"); - stampa.add(" "); - prima = FALSE; - } - errore = TRUE; - TString app; - app.format("%5s%03d", (const char*)"@b - ", nr); - app << " " << "@rRilevato numero di riga con piu' di due cifre"; - stampa.add(app); - tit_riga = TRUE; - } + tit_riga = FALSE; - if (g > 99) + int gruppo = _scad->get_int (SCAD_GRUPPO); + int conto = _scad->get_int (SCAD_CONTO); + int nriga = _scad->get_int (SCAD_NRIGA); + int nrata = _scad->get_int (SCAD_NRATA); + + if (gruppo > 99) { errore = TRUE; TString app; if (prima) { stampa.add(" "); - stampa.add("Righe primanota"); + stampa.add("Scadenze:"); stampa.add(" "); prima = FALSE; } if (tit_riga) - app << "@r Rilevato un gruppo di partita composto da 3 cifre"; + app << "@r Rilevato un gruppo composto da 3 cifre"; else { - app.format("%5s%03d", (const char*)"@b - ", nr); - app << " " << "@rRilevato un gruppo di partita composto da 3 cifre"; - } - stampa.add(app); - tit_riga = TRUE; - } - - if (c > 99) - { - errore = TRUE; - TString app; - if (prima) - { - stampa.add(" "); - stampa.add("Righe primanota"); - stampa.add(" "); - prima = FALSE; - } - if (tit_riga) - app << "@r Rilevato un conto di partita composto da 3 cifre"; - else - { - app.format("%5s%03d", (const char*)"@b - ", nr); - app << " " << "@rRilevato un conto di partita composto da 3 cifre"; - } - stampa.add(app); - } - - if (gc > 99) - { - errore = TRUE; - TString app; - if (prima) - { - stampa.add(" "); - stampa.add("Righe primanota"); - stampa.add(" "); - prima = FALSE; - } - if (tit_riga) - app << "@r Rilevato un gruppo di contropartita composto da 3 cifre"; - else - { - app.format("%5s%03d", (const char*)"@b - ", nr); - app << " " << "@rRilevato un gruppo di contropartita composto da 3 cifre"; - } - stampa.add(app); - tit_riga = TRUE; - } - - if (cc > 99) - { - errore = TRUE; - TString app; - if (prima) - { - stampa.add(" "); - stampa.add("Righe primanota"); - stampa.add(" "); - prima = FALSE; - } - if (tit_riga) - app << "@r Rilevato un conto di contropartita composto da 3 cifre"; - else - { - app.format("%5s%03d", (const char*)"@b - ", nr); - app << " " << "@rRilevato un conto di contropartita composto da 3 cifre"; - } - stampa.add(app); - } - } - - if (soliva) - { - TLocalisamfile rcaus (LF_RCAUSALI); - int g = 0; - int c = 0; - bool tit_riga = FALSE; - bool prima = TRUE; - int nr = 1; - - rcaus.setkey(1); - rcaus.zero(); - rcaus.put(RCA_CODCAUS, codcaus); - rcaus.read(); - TString codcau = rcaus.get(RCA_CODCAUS); - if (codcau == codcaus) - { - g = rcaus.get_int (RCA_GRUPPO); - c = rcaus.get_int (RCA_CONTO); - } - - - if (g > 99) - { - errore = TRUE; - TString app; - if (prima) - { - stampa.add(" "); - stampa.add("Righe primanota"); - stampa.add(" "); - prima = FALSE; - } - if (tit_riga) - app << "@r Rilevato un gruppo di partita composto da 3 cifre"; - else - { - app.format("%5s%03d", (const char*)"@b - ", nr); - app << " " << "@rRilevato un gruppo di partita composto da 3 cifre"; - } - stampa.add(app); - tit_riga = TRUE; - } - - if (c > 99) - { - errore = TRUE; - TString app; - if (prima) - { - stampa.add(" "); - stampa.add("Righe primanota"); - stampa.add(" "); - prima = FALSE; - } - if (tit_riga) - app << "@r Rilevato un conto di partita composto da 3 cifre"; - else - { - app.format("5s%03d", (const char*)"@b - ", nr); - app << " " << "@rRilevato un conto di partita composto da 3 cifre"; - } - stampa.add(app); - } - } - - num = 0; - - if (_files.find('U') != -1) - { - nreg_p = 0; - _rmoviva->setkey(1); - _rmoviva->zero(); - _rmoviva->put(RMI_NUMREG, nreg); - - TRectype rmoviva (_rmoviva->curr()); - - prima = TRUE; - - for (_rmoviva->read(); !_rmoviva->eof(); _rmoviva->next()) - { - if (_rmoviva->curr() > rmoviva) break; - - num++; - - if (num > 9) - { - errore = TRUE; - stampa.add(" - Rilevato movimento Iva con numero righe superiore a 9"); - } - - int nr = _rmoviva->get_int (RMI_NUMRIG); - int g = _rmoviva->get_int (RMI_GRUPPO); - int c = _rmoviva->get_int (RMI_CONTO); - - if (nr > 99) - { - errore = TRUE; - TString app; - if (prima) - { - stampa.add(" "); - stampa.add("Righe iva"); - stampa.add(" "); - prima = FALSE; - } - app.format("%5s%03d", (const char*)"@b - ", nr); - app << " " << "@rRilevato numero di riga con piu' di due cifre"; - stampa.add(app); - tit_riga = TRUE; - } - - if (g > 99) - { - errore = TRUE; - TString app; - if (prima) - { - stampa.add(" "); - stampa.add("Righe iva"); - stampa.add(" "); - prima = FALSE; - } - if (tit_riga) - app << "@r Rilevato un gruppo composto da 3 cifre"; - else - { - app.format("%5s%03d", (const char*)"@b - ", nr); + app.format("%5s%04d", (const char*)"@b - rata ", nrata); app << " " << "@rRilevato un gruppo composto da 3 cifre"; } stampa.add(app); tit_riga = TRUE; } - if (c > 99) + if (conto > 99) { errore = TRUE; TString app; if (prima) { stampa.add(" "); - stampa.add("Righe iva"); + stampa.add("Scadenze:"); stampa.add(" "); prima = FALSE; } if (tit_riga) - app << "@r Rilevato un conto composto da 3 cifre"; + app << "@r Rilevato un conto composto da 3 cifre"; else - { - app.format("%5s%03d", (const char*)"@b - ", nr); + { + app.format("%5s%04d", (const char*)"@b - rata ", nrata); app << " " << "@rRilevato un conto composto da 3 cifre"; } stampa.add(app); + tit_riga = TRUE; } - const char* ci = _rmoviva->get (RMI_CODIVA); - if ( ci && *ci && !real::is_natural(ci) ) + + if (nriga > 999) + { + errore = TRUE; + TString app; + if (prima) + { + stampa.add(" "); + stampa.add("Scadenze:"); + stampa.add(" "); + prima = FALSE; + } + if (tit_riga) + app << "@r Rilevato un conto composto da 3 cifre"; + else + { + app.format("%5s%04d", (const char*)"@b - rata ", nrata); + app << " " << "@rRilevato numero di riga con piu' di tre cifre"; + } + stampa.add(app); + tit_riga = TRUE; + } + + if (nrata > 99) { errore = TRUE; TString app; if (prima) { stampa.add(" "); - stampa.add("Righe iva"); + stampa.add("Scadenze:"); stampa.add(" "); prima = FALSE; } if (tit_riga) - app << "@r Rilevato un codice IVA alfanumerico"; + app << "@r Rilevato un numero di rata composto da 3 o piu' cifre"; else - { - app.format("%5s%03d", (const char*)"@b - ", nr); - app << " " << "@rRilevato un codice IVA alfanumerico"; + { + app.format("%5s%04d", (const char*)"@b - rata ", nrata); + app << " " << "@rRilevato un numero di rata composto da 3 o piu' cifre"; } stampa.add(app); tit_riga = TRUE; - } - - if (!controlla_valore(ci,99,2)) + } + const char* codpag = _scad->get(SCAD_CODPAG); + if (!controlla_valore(codpag,99,2)) { errore = TRUE; TString app; if (prima) { stampa.add(" "); - stampa.add("Righe iva"); + stampa.add("Scadenze:"); stampa.add(" "); prima = FALSE; } if (tit_riga) - app << "@r Rilevato un codice IVA composto da 3 o piu' cifre"; + app << "@r Rilevato un codice pagamento composto da 3 o piu' cifre"; else - { - app.format("%5s%03d", (const char*)"@b - ", nr); - app << " " << "@rRilevato un codice IVA composto da 3 o piu' cifre"; + { + app.format("%5s%04d", (const char*)"@b - rata ", nrata); + app << " " << "@rRilevato un codice pagamento composto da 3 o piu' cifre"; + } + stampa.add(app); + tit_riga = TRUE; + } + const char* codag = _scad->get(SCAD_CODAG); + if ( codag && *codag && !real::is_natural(codag) ) + { + errore = TRUE; + TString app; + if (prima) + { + stampa.add(" "); + stampa.add("Scadenze:"); + stampa.add(" "); + prima = FALSE; + } + if (tit_riga) + app << "@r Rilevato un codice agente alfanumerico"; + else + { + app.format("%5s%04d", (const char*)"@b - rata ", nrata); + app << " " << "@rRilevato un codice agente alfanumerico"; + } + stampa.add(app); + tit_riga = TRUE; + } + } + + _pagsca->zero(); + _pagsca->put(PAGSCA_TIPOC, tipo); + if (gruppo != 0) + _pagsca->put(PAGSCA_GRUPPO, gruppo); + if (conto != 0) + _pagsca->put(PAGSCA_CONTO, conto); + if (sottoc != 0) + _pagsca->put(PAGSCA_SOTTOCONTO, sottoc); + _pagsca->put(PAGSCA_ANNO, anno); + _pagsca->put(PAGSCA_NUMPART, numpart); + + TRectype pagsca (_pagsca->curr()); + + for (_pagsca->read(_isgteq); !_pagsca->eof(); _pagsca->next()) + { + tit_riga = FALSE; + + int nrigp = _pagsca->get_int(PAGSCA_NRIGP); + + rec = pagsca.get(PAGSCA_NUMPART); + filer = _pagsca->get(PAGSCA_NUMPART); + + if (_pagsca->curr() != pagsca || filer != rec) break; + + if (nriga != nrigp) continue; + + int gruppo = _pagsca->get_int (PAGSCA_GRUPPO); + int conto = _pagsca->get_int (PAGSCA_CONTO); + int nriga = _pagsca->get_int (PAGSCA_NRIGA); + int nrata = _pagsca->get_int (PAGSCA_NRATA); + + if (gruppo > 99) + { + errore = TRUE; + TString app; + if (prima) + { + stampa.add(" "); + stampa.add("Pagamenti scadenze:"); + stampa.add(" "); + prima = FALSE; + } + if (tit_riga) + app << "@r Rilevato un gruppo composto da 3 cifre"; + else + { + app.format("%5srata %04d riga %04d", (const char*)"@b - ", nrata, nrigp); + app << " " << "@rRilevato un gruppo composto da 3 cifre"; + } + stampa.add(app); + tit_riga = TRUE; + } + + if (conto > 99) + { + errore = TRUE; + TString app; + if (prima) + { + stampa.add(" "); + stampa.add("Pagamenti scadenze:"); + stampa.add(" "); + prima = FALSE; + } + if (tit_riga) + app << "@r Rilevato un conto composto da 3 cifre"; + else + { + app.format("%5srata %04d riga %04d", (const char*)"@b - ", nrata, nrigp); + app << " " << "@rRilevato un conto composto da 3 cifre"; + } + stampa.add(app); + } + if (nriga != 9999 && nriga > 999) + { + errore = TRUE; + TString app; + if (prima) + { + stampa.add(" "); + stampa.add("Pagamenti scadenze:"); + stampa.add(" "); + prima = FALSE; + } + if (tit_riga) + app << "@r Rilevato un conto composto da 3 cifre"; + else + { + app.format("%5srata %04d riga %04d", (const char*)"@b - ", nrata, nrigp); + app << " " << "@rRilevato numero di riga con tre o piu' cifre"; + } + stampa.add(app); + tit_riga = TRUE; + } + if (nrata != 9999 && nrata > 99) + { + errore = TRUE; + TString app; + if (prima) + { + stampa.add(" "); + stampa.add("Pagamenti scadenze:"); + stampa.add(" "); + prima = FALSE; + } + if (tit_riga) + app << "@r Rilevato un conto composto da 3 cifre"; + else + { + app.format("%5srata %04d riga %04d", (const char*)"@b - ", nrata, nrigp); + app << " " << "@rRilevato numero di rata con piu' di due cifre"; + } + stampa.add(app); + tit_riga = TRUE; + } + const char* codag = _scad->get(SCAD_CODAG); + if ( codag && *codag && !real::is_natural(codag) ) + { + errore = TRUE; + TString app; + if (prima) + { + stampa.add(" "); + stampa.add("Pagamenti scadenze:"); + stampa.add(" "); + prima = FALSE; + } + if (tit_riga) + app << "@r Rilevato un codice agente alfanumerico"; + else + { + app.format("%5srata %04d riga %04d", (const char*)"@b - ", nrata, nrigp); + app << " " << "@rRilevato un codice agente alfanumerico"; } stampa.add(app); tit_riga = TRUE; } - } } if (errore) @@ -1303,8 +1318,21 @@ void TLista_archivi::controlla_fatture(char file) setta_intestazione(file); intesta = FALSE; } - - app << "@b- Registrazione numero " << nreg; + if (tipo != tipo_p || sottoc != sottoc_p) + { + TString ragsoc; + ragsocCF(tipo,sottoc,ragsoc); + if (tipo == 'C') + app << "@b- Cliente : " << sottoc; + else + app << "@b- Fornitore : " << sottoc; + app << " " << ragsoc; + row.put(app,0); + printer().print(row); + row.reset(); + } + app = ""; + app.format("Partita %-7s riga %4d", (const char*) numpart, nriga); row.put(app,0); printer().print(row); row.reset(); @@ -1323,15 +1351,16 @@ void TLista_archivi::controlla_fatture(char file) printer().print(row); row.reset(); - errore = FALSE; - salto = TRUE; - _risposta = 1; + errore = FALSE; + salto = TRUE; + _risposta = 1; + tipo_p = tipo; + sottoc_p = sottoc; } stampa.destroy(); } if (salto) printer().formfeed(); -*/ } void TLista_archivi::setta_intestazione(char sigla) @@ -1358,6 +1387,10 @@ void TLista_archivi::setta_intestazione(char sigla) titolo = "Movimenti"; break; + case 'B': + titolo = "Movimenti Saldaconto"; + break; + default: break; } diff --git a/cg/cg6901.h b/cg/cg6901.h index e5565870a..ae537eb6b 100755 --- a/cg/cg6901.h +++ b/cg/cg6901.h @@ -52,6 +52,6 @@ public: void controlla_fatture (char sigla); void setta_intestazione(char sigla); bool controlla_valore (const TString& val,int lim, int len); - + void ragsocCF(char tipo, long codcf, TString& ragsoc); TLista_archivi() {}; }; diff --git a/cg/cg6902.cpp b/cg/cg6902.cpp index 83a5c87e3..3d01164be 100755 --- a/cg/cg6902.cpp +++ b/cg/cg6902.cpp @@ -232,7 +232,12 @@ bool TInv_cont::invio_contabilita() if (!invio_mov_IVA()) return FALSE; break; - + + case 'B': + if (!invio_mov_SC()) + return FALSE; + break; + default: break; }; @@ -1020,25 +1025,59 @@ void TInv_cont::testata_trasfer(long nreg, int nrig, TString& record) record.overwrite("0",218); //Flag di solo sezionale } -void TInv_cont::sola_iva(TString& record) +void TInv_cont::sola_iva(TString& record, long nreg) { TString str; - TLocalisamfile rcaus (LF_RCAUSALI); - int gruppo = 0; - int conto = 0; - long sottoc = 0; + TLocalisamfile cau (LF_CAUSALI); + TString tipodoc = ""; + bool cor = FALSE; + int gruppo = 0; + int conto = 0; + long sottoc = 0; + + cau.setkey(1); + cau.zero(); + cau.put(CAU_CODCAUS, _codcausm); + if (cau.read() == NOERR) + tipodoc = cau.get(CAU_TIPODOC); - rcaus.setkey(1); - rcaus.zero(); - rcaus.put(RCA_CODCAUS, _codcausm); - rcaus.read(); - TString codcau = rcaus.get(RCA_CODCAUS); - if (codcau == _codcausm) + TTable tabtpd("%TPD"); + tabtpd.put("CODTAB", tipodoc); + if (tabtpd.read() == NOERR) + cor = tabtpd.get_bool("B0"); + + if (!cor) { - gruppo = rcaus.get_int (RCA_GRUPPO); - conto = rcaus.get_int (RCA_CONTO); - sottoc = _tmov->get_long(MOV_CODCF); - } + TLocalisamfile rcaus (LF_RCAUSALI); + + rcaus.setkey(1); + rcaus.zero(); + rcaus.put(RCA_CODCAUS, _codcausm); + rcaus.read(); + TString codcau = rcaus.get(RCA_CODCAUS); + if (codcau == _codcausm) + { + gruppo = rcaus.get_int (RCA_GRUPPO); + conto = rcaus.get_int (RCA_CONTO); + sottoc = _tmov->get_long(MOV_CODCF); + } + } + else + { + TLocalisamfile riva (LF_RMOVIVA); + + riva.setkey(1); + riva.zero(); + riva.put(RMI_NUMREG, nreg); + riva.read(); + long nr = riva.get_long(RMI_NUMREG); + if (nreg == nr) + { + gruppo = riva.get_int (RMI_GRUPPO); + conto = riva.get_int (RMI_CONTO); + sottoc = riva.get_long(RMI_SOTTOCONTO); + } + } str.format("%02d", gruppo); record.overwrite(str,74); //Gruppo di partita @@ -1144,7 +1183,7 @@ bool TInv_cont::invio_mov_PN() { int nrig = 1; testata_trasfer(nreg,nrig,record); - sola_iva(record); + sola_iva(record,nreg); _numrec_pn++; _tras_file.write_control_rec(record,size); } @@ -1376,6 +1415,500 @@ bool TInv_cont::invio_mov_IVA() return TRUE; } +int TInv_cont::nprogre_interno(long numreg, int numrig) +{ + int riga = 1; + + TString key (format("%06ld%02d", numreg, numrig)); + + if (!_riga_interna.is_key(key)) + { + TString nr (format("%d", riga)); + _riga_interna.add(key,nr); + } + else + { + TString& token = (TString&)_riga_interna.find(key); + riga = atoi(token); + riga++; + token.format("%d", riga); + } + return riga; +} + +long TInv_cont::crea_record_riferimento_PN() +{ + int size = 256; + TString record(size); + TString str; + + _ultima_nreg++; + + record.spaces(); + + record.overwrite("Z1",0); //Tipo record + + str.format("%06ld", _ultima_nreg); + record.overwrite(str,2); //Numero di registrazione + + str.format("%02d", 1); + record.overwrite(str,8); //Numero di riga + + TString datareg (_tpart->get_date(PART_DATAREG)); + str = riconverti(datareg,FALSE); + str.format("%06s", (const char*) str); + record.overwrite(str,15); //Data di registrazione + + int gruppo = _tpart->get_int (PART_GRUPPOCL); + str.format("%02d", gruppo); + record.overwrite(str,74); //Gruppo di partita + + int conto = _tpart->get_int (PART_CONTOCL); + str.format("%02d", conto); + record.overwrite(str,76); //Conto di partita + + long sottoc = _tpart->get_long(PART_SOTTOCONTO); + str.format("%06ld", sottoc); + record.overwrite(str,78); //Sottoconto di partita + + record.overwrite("0000000000",85); //Sottoconto di contropartita + + record.overwrite("00000000000",97); //Importo + + str.format("%d", 1); + record.overwrite(str,218); //Flag solo sezionale (Presente solo saldaconto) + + char tipocf = _tpart->get_char(PART_TIPOCF); + str.format("%c", tipocf); + record.overwrite(str,219); //Flag Cliente / Fornitore + + _tras_file.write_control_rec(record,size); + + return _ultima_nreg; +} + +void TInv_cont::partita2trasfer(TString& record, bool crea_record_riferimento) +{ + TString str; + + record.spaces(); + + record.overwrite("B1",0); //Tipo record + + long nreg = _tpart->get_long(PART_NREG); + int nrig = _tpart->get_int (PART_NUMRIG); + + if (nreg == 0 && nrig == 0) //Se si tratta di extracontabile nreg = 0 e nrig = 0 + { //prendo come nreg l'ultimo che trovo sugli archivi + 1. + if (crea_record_riferimento) //Creo anche un record di riferimento nei mov di PN (Z1). + nreg = crea_record_riferimento_PN(); //In caso di abbuoni o diff.cambio o ritenute non e' + else //necessario creare ogni volta un record di riferimento e reperire + nreg = _ultima_nreg; //una nuova nreg, in quanto si puo' usare l'ultima nreg creata in occasione + nrig = 1; //del pagamento esploso prima. Quindi mi basta assegnare _ultima_nreg. + } + + str.format("%06ld", nreg); + record.overwrite(str,2); //Numero di registrazione + + str.format("%02d", nrig); + record.overwrite(str,8); //Numero di riga + + int nriga = nprogre_interno(nreg,nrig); + str.format("%03d", nriga); + record.overwrite(str,10); //Numero progressivo all'interno della riga + + char tipo = _tpart->get_char(PART_TIPOCF); + int tipoAS; + if (tipo == 'C') + tipoAS = 1; + else + if (tipo == 'F') + tipoAS = 2; + else + tipoAS = 3; + str.format("%d", tipoAS); + record.overwrite(str,15); //Tipo anagrafica + + int gruppo = _tpart->get_int (PART_GRUPPO); + str.format("%02d", gruppo); + record.overwrite(str,16); //Gruppo anagrafica + + int conto = _tpart->get_int (PART_CONTO); + str.format("%02d", conto); + record.overwrite(str,18); //Conto anagrafica + + long sottoc = _tpart->get_long(PART_SOTTOCONTO); + str.format("%06ld", sottoc); + record.overwrite(str,20); //Cliente o fornitore + + TString anno (format("%4d", _tpart->get_int(PART_ANNO))); + record.overwrite(anno.mid(2,2),26); //Anno partita + + str.format("%-7s", (const char*) _tpart->get(PART_NUMPART)); + record.overwrite(str,28); //Numero partita + + int tipomov = _tpart->get_int (PART_TIPOMOV); + str.format("%d", tipomov); + record.overwrite(str,37); //Tipo movimento + + TString datareg (_tpart->get_date(PART_DATAREG)); + str = riconverti(datareg,FALSE); + str.format("%06s", (const char*) str); + record.overwrite(str,38); //Data di registrazione + + TString datadoc (_tpart->get_date(PART_DATADOC)); + str = riconverti(datadoc,FALSE); + str.format("%06s", (const char*) str); + record.overwrite(str,44); //Data documento + + TString numdoc (_tpart->get(PART_NUMDOC)); + str.format("%-7s", (const char*) numdoc); + record.overwrite(str,50); //Numero documento + + TString registro; + TString reg (_tpart->get(PART_REG)); + if (real::is_natural(reg)) + { + int app = atoi(reg); + registro.format("%d", app); + } + else + registro = reg.trim(); + + record.overwrite(registro,57); //Codice registro IVA + + long protiva = _tpart->get_long(PART_PROTIVA); + str.format("%05ld", protiva); + record.overwrite(str,58); //Numero protocollo IVA + + TString codcaus (_tpart->get(PART_CODCAUS)); + str.format("%03s", (const char*)codcaus); + record.overwrite(str,63); //Codice causale + + _codval = _tpart->get(PART_CODVAL); + str.format("%-3s", (const char*) _codval); + record.overwrite(str,79); //Codice valuta + + _cambio = _tpart->get_real(PART_CAMBIO); + dec2integer(_cambio,100000); + TString cambioi = _cambio.string(); + if (_cambio.sign() < 0) + negPC2negAS(cambioi); + str.format("%011s", (const char*) cambioi); + record.overwrite(str,95); //Cambio + + TString datacam (_tpart->get_date(PART_DATACAM)); + str = riconverti(datacam,FALSE); + str.format("%06s", (const char*) str); + record.overwrite(str,106); //Data cambio + + if (tipomov != 1) + { + int tipopag = _tpart->get_int (PART_TIPOPAG); + str.format("%d", tipopag); + record.overwrite(str,114); //Tipo pagamento + + TString datapag (_tpart->get_date(PART_DATAPAG)); + str = riconverti(datapag,FALSE); + str.format("%06s", (const char*) str); + record.overwrite(str,140); //Data pagamento + } + + TString sez = _tpart->get(PART_SEZ); + str.format("%s", (const char*) sez); + record.overwrite(str,152); //Sezione partita + + int gruppocl = _tpart->get_int (PART_GRUPPOCL); + str.format("%02d", gruppocl); + record.overwrite(str,168); //Gruppo cliente + + int contocl = _tpart->get_int (PART_CONTOCL); + str.format("%02d", contocl); + record.overwrite(str,170); //Conto cliente +} + +void TInv_cont::aggiorna_array_rate(TString& numpart, int rata) +{ + TString key (format("%-7s", (const char*) numpart)); + + if (!_ultima_rata.is_key(key)) + { + TString nr (format("%2d", rata)); + _ultima_rata.add(key,nr); + } + else + { + TString& token = (TString&)_ultima_rata.find(key); + int nr = atoi(token); + if (rata > nr) + token.format("%2d", rata); + } +} + +int TInv_cont::ultima_rata_partita(TString& numpart) +{ + int rata = 1; + TString key (format("%-7s", (const char*) numpart)); + + if (!_ultima_rata.is_key(key)) + { + TString nr (format("%2d", rata)); + _ultima_rata.add(key,nr); + } + else + { + TString& token = (TString&)_ultima_rata.find(key); + rata = atoi(token); + rata++; + token.format("%2d", rata); + } + + return rata; +} + +void TInv_cont::pagsca2trasfer(TString& record,real& importo,real& importoval) +{ + TString str; + int size = 256; + + TString numpart = _tpagsca->get (PAGSCA_NUMPART); + int nriga = _tpagsca->get_int(PAGSCA_NRIGA); + int nrata = _tpagsca->get_int(PAGSCA_NRATA); + + if (nriga == 9999 && nrata == 9999) + nrata = ultima_rata_partita(numpart); + + str.format("%02d", nrata); + record.overwrite(str,35); //Numero di rata + + TString numero = importo.string(); + if (importo.sign() < 0) + negPC2negAS(numero); + str.format("%011s", (const char*) numero); + record.overwrite(str,116); //Importo in lire pagamento + + dec2integer(importoval,1000); + TString impvalstr = importoval.string(); + if (importoval.sign() < 0) + negPC2negAS(impvalstr); + str.format("%013s", (const char*) impvalstr); + record.overwrite(str,127); //Importo in valuta pagamento + + TString codag (_tpagsca->get(PAGSCA_CODAG)); + str.format("%-6s", (const char*) codag); + record.overwrite(str,172); //Codice agente + + _tras_file.write_control_rec(record,size); +} + +bool TInv_cont::invio_mov_SC() +{ + int size = 256; + TString record(size); + bool almeno_una_riga = FALSE; + + _tmov->last(); + _ultima_nreg = _tmov->get_long(MOV_NUMREG); + + _riga_interna.restart(); // Azzero l'array dove tengo lo storico del numero progressivo all'interno della riga. + _ultima_rata.restart(); // Azzero l'array dove tengo lo storico delle rate di una partita (serve per + // assegnare un numero di rata ai pagamenti non assegnati). + long cicli = _tpart->items(); + _prog = new TProgind(cicli,"Movimenti di Saldaconto: generazione file TRASFER per Sistema\nPrego attendere.",FALSE); + + _tras_file.open(_trasf,TRUE); + + for (_tpart->first(); !_tpart->eof(); _tpart->next()) + { + TString str; + + _prog->addstatus(1); + + char tipo = _tpart->get_char(PART_TIPOCF); + int gruppo = _tpart->get_int (PART_GRUPPO); + int conto = _tpart->get_int (PART_CONTO); + long sottoc = _tpart->get_long(PART_SOTTOCONTO); + int anno = _tpart->get_int (PART_ANNO); + TString numpart = _tpart->get (PART_NUMPART); + int nriga = _tpart->get_int (PART_NRIGA); + int tipomov = _tpart->get_int (PART_TIPOMOV); + + if (tipomov == 1) + { + _tscad->zero(); + _tscad->put(SCAD_TIPOCF, tipo); + if (gruppo != 0) + _tscad->put(SCAD_GRUPPO, gruppo); + if (conto != 0) + _tscad->put(SCAD_CONTO, conto); + if (sottoc != 0) + _tscad->put(SCAD_SOTTOCONTO, sottoc); + _tscad->put(SCAD_ANNO, anno); + _tscad->put(SCAD_NUMPART, numpart); + _tscad->put(SCAD_NRIGA, nriga); + + TRectype scad (_tscad->curr()); + + TString rec,file,str,codpag,ultclass,datascad,numero,codag,impvalstr,numpart; + + for (_tscad->read(_isgteq); !_tscad->eof(); _tscad->next()) + { + rec = scad.get(SCAD_NUMPART); + file = _tscad->get(SCAD_NUMPART); + + if (_tscad->curr() != scad || file != rec) break; + + partita2trasfer(record); + + int nrata = _tscad->get_int(SCAD_NRATA); + str.format("%02d", nrata); + record.overwrite(str,35); //Numero di rata + + numpart = _tscad->get(SCAD_NUMPART); + aggiorna_array_rate(numpart,nrata); + + codpag = _tscad->get(SCAD_CODPAG); + str.format("%-2s", (const char*) codpag); + record.overwrite(str,112); //Codice di pagamento + + int tipopag = _tscad->get_int(SCAD_TIPOPAG); + str.format("%d", tipopag); + record.overwrite(str,114); //Tipo pagamento + + ultclass = _tscad->get(SCAD_ULTCLASS); + str.format("%s", (const char*) ultclass); + record.overwrite(str,115); //Ulteriore classificazione + + real importo (_tscad->get_real(SCAD_IMPORTO)); + numero = importo.string(); + if (importo.sign() < 0) + negPC2negAS(numero); + str.format("%011s", (const char*) numero); + record.overwrite(str,116); //Importo in lire rata partita + + real importoval (_tscad->get_real(SCAD_IMPORTOVAL)); + dec2integer(importoval,1000); + impvalstr = importoval.string(); + if (importoval.sign() < 0) + negPC2negAS(impvalstr); + str.format("%013s", (const char*) impvalstr); + record.overwrite(str,127); //Importo in valuta rata partita + + datascad = _tscad->get_date(SCAD_DATASCAD); + str = riconverti(datascad,FALSE); + str.format("%06s", (const char*) str); + record.overwrite(str,140); //Data scadenza + + codag = _tscad->get(SCAD_CODAG); + str.format("%-6s", (const char*) codag); + record.overwrite(str,172); //Codice agente + + _tras_file.write_control_rec(record,size); + } + } + else + { + _tpagsca->zero(); + _tpagsca->put(PAGSCA_TIPOC, tipo); + if (gruppo != 0) + _tpagsca->put(PAGSCA_GRUPPO, gruppo); + if (conto != 0) + _tpagsca->put(PAGSCA_CONTO, conto); + if (sottoc != 0) + _tpagsca->put(PAGSCA_SOTTOCONTO, sottoc); + _tpagsca->put(PAGSCA_ANNO, anno); + _tpagsca->put(PAGSCA_NUMPART, numpart); + + TRectype pagsca (_tpagsca->curr()); + + TString str,rec,file; + + for (_tpagsca->read(_isgteq); !_tpagsca->eof(); _tpagsca->next()) + { + int nrigp = _tpagsca->get_int(PAGSCA_NRIGP); + + rec = pagsca.get(PAGSCA_NUMPART); + file = _tpagsca->get(PAGSCA_NUMPART); + + if (_tpagsca->curr() != pagsca || file != rec) break; + + if (nriga != nrigp) continue; + + partita2trasfer(record); + + real importo (_tpagsca->get_real(PAGSCA_IMPORTO)); + real importoval (_tpagsca->get_real(PAGSCA_IMPORTOVAL)); + pagsca2trasfer(record,importo,importoval); + + real abbuoni (_tpagsca->get_real(PAGSCA_ABBUONI)); + if (abbuoni != ZERO) + { + char sezabb; + char passat = _tpagsca->get_char(PAGSCA_PASSATT); + char sez = _tpart->get_char(PART_SEZ); + if (passat == 'A') + sezabb = 'D'; + else + if (passat == 'P') + sezabb = 'A'; + if (sezabb != sez) + abbuoni = abbuoni * -1; + real abblire = ZERO; + partita2trasfer(record,FALSE); + if (_codval.not_empty()) + { + abblire = abbuoni * _cambio; + abblire.round(); + } + str.format("%d", 4); + record.overwrite(str,37); + str.format("%c", sezabb); + record.overwrite(str,152); + pagsca2trasfer(record,abblire,abbuoni); + } + + real diffcam (_tpagsca->get_real(PAGSCA_DIFFCAM)); + if (diffcam != ZERO) + { + real imp = ZERO; + partita2trasfer(record,FALSE); + char sez = _tpart->get_char(PART_SEZ); + if (diffcam < ZERO) + { + diffcam = diffcam * -1; + if (sez == 'D') + sez = 'A'; + else + if (sez == 'A') + sez = 'D'; + } + str.format("%d", 4); + record.overwrite(str,37); + str.format("%c", sez); + record.overwrite(str,152); + pagsca2trasfer(record,diffcam,imp); + } + + real ritenute (_tpagsca->get_real(PAGSCA_RITENUTE)); + if (ritenute != ZERO) + { + real imp = ZERO; + partita2trasfer(record,FALSE); + pagsca2trasfer(record,ritenute,imp); + } + } + } + } + delete _prog; + + _riga_interna.destroy(); + _ultima_rata.destroy(); + + _tras_file.close(); + + return TRUE; +} + void TInv_cont::negPC2negAS(TString& numero) { numero.trim();