diff --git a/cg/cg0200.cpp b/cg/cg0200.cpp index bb9b1cf45..ef98ab5ae 100755 --- a/cg/cg0200.cpp +++ b/cg/cg0200.cpp @@ -237,15 +237,21 @@ bool TClifo_application::percip_handler(TMask_field& f, KEY key) if (f.to_check(key) && m.get(F_CODANAGPER).not_empty()) { - TLocalisamfile anag(LF_ANAG); + const TRectype& anag = m.efield(F_CODANAGPER).browse()->cursor()->file().curr(); TString80 c(m.get(F_COFI)), p(m.get(F_PAIV)); if ((c.not_empty() && c != anag.get(ANA_COFI)) || - (p.not_empty() && p != anag.get(ANA_PAIV))) return error_box("Percipiente non corretto"); - TString80 r(anag.get(ANA_RAGSOC)); - if (m.get(F_RAGSOC).empty() || - (key == K_TAB && yesno_box("Ragione sociale differente correggo in %s", (const char*) r))) - m.set(F_RAGSOC, r, TRUE); + (p.not_empty() && p != anag.get(ANA_PAIV))) + return error_box("Percipiente non corretto: codice fiscale o partita IVA diversa"); + + const TString80 r(anag.get(ANA_RAGSOC)); + if (key == K_TAB && m.get(F_RAGSOC).empty() && + yesno_box("Ragione sociale mancante: assumo %s", (const char*)r)) + { + m.set(F_RAGSOC, r.left(30), TRUE); + m.set(F_RAGSOCA, r.mid(30), TRUE); + } + if (m.get(F_INDCF).empty()) m.set(F_INDCF, anag.get(ANA_INDRES)); if (m.get(F_CIVCF).empty()) m.set(F_CIVCF, anag.get(ANA_CIVRES)); if (m.get(F_CAPCF).empty()) m.set(F_CAPCF, anag.get(ANA_CAPRES)); @@ -265,14 +271,13 @@ bool TClifo_application::percip_handler(TMask_field& f, KEY key) fis.zero(); fis.put(ANF_CODANAGR, anag.get(ANA_CODANAGR)); - fis.read(); - if (fis.good()) + if (fis.read() == NOERR) { if (m.get(F_DATANASC).empty()) m.set(F_DATANASC, fis.get(ANF_DATANASC)); if (m.get(F_COMNASC).empty()) { - m.set(F_STATONASC, fis.get(ANF_STATONASC)); - m.set(F_COMNASC, fis.get(ANF_COMNASC)); + m.set(F_STATONASC, fis.get(ANF_STATONASC), TRUE); + m.set(F_COMNASC, fis.get(ANF_COMNASC), TRUE); } } } diff --git a/cg/cg2100s.uml b/cg/cg2100s.uml index f2abf07d8..7ee119f9b 100755 --- a/cg/cg2100s.uml +++ b/cg/cg2100s.uml @@ -190,7 +190,7 @@ END TEXT DLG_NULL BEGIN - PROMPT 2 12 "@bConto di contropartita" + PROMPT 2 12 "@bContropartita" END LIST S_TIPO 1 12 diff --git a/cg/cg2102.h b/cg/cg2102.h index 11133ca1b..b441c6306 100755 --- a/cg/cg2102.h +++ b/cg/cg2102.h @@ -211,7 +211,7 @@ protected: bool edit_partite(int riga); bool edit_scadenze(int riga, const TBill& b, int anno, const char* num); - bool edit_pagamento(const TRectype& parbas, const TRectype& scaden, TRectype& part); + bool edit_pagamento(TRectype& parbas, TRectype& scaden, TRectype& part); static TPrimanota_application& app() { return (TPrimanota_application&)main_app(); } diff --git a/cg/cg2104.cpp b/cg/cg2104.cpp index 922bcf562..d024e3828 100755 --- a/cg/cg2104.cpp +++ b/cg/cg2104.cpp @@ -498,9 +498,13 @@ bool TPrimanota_application::edit_partite(int riga) { begin_wait(); + const long curreg = curr_mask().get_long(F_NUMREG); // Numero registrazione + TToken_string& cgr = cgs().row(riga); const TBill b(cgr, 2, 0x3); // Legge il conto della riga selezionata + TImporto soldi; soldi = cgr; // Importo della riga selezionata + TString80 caption("Partite aperte del conto "); caption << b.gruppo() << ' ' << b.conto() << ' ' << b.sottoconto(); @@ -521,6 +525,7 @@ bool TPrimanota_application::edit_partite(int riga) int ult, anno; // Anno ultima partita TString16 last, num; // Ultimo numero partita e numero corrente + long nreg; TString desc; // Descrizione prima partita del gruppo TImporto saldo; // Saldo ultima parita TToken_string r(80); @@ -529,19 +534,28 @@ bool TPrimanota_application::edit_partite(int riga) { num = partita.get(PART_NUMPART); anno = partita.get_int(PART_ANNO); + nreg = partita.get_long(PART_NREG); + if (num == last && anno == ult) // Se la partita e' la stessa ... { const TImporto i(partita.get_char(PART_SEZ), partita.get_real(PART_IMPORTO)); saldo += i; // ... incrementa totale + + if (nreg == curreg) + { + const int numrig = partita.get_int(PART_NUMRIG); + if (numrig == (riga+1)) + soldi -= i; + } } else { - if (!saldo.is_zero()) // Se il saldo non e' nullo allora e' aperta + if (!saldo.is_zero() || nreg == curreg) // Se il saldo non e' nullo allora e' aperta { r.cut(0); r.add(ult); r.add(last); r.add(desc); r.add(saldo.valore().string(".")); r.add(saldo.sezione()); - a.add(r); // Aggiunge partita alla lista + a.add(r); // Aggiunge partita alla lista } ult = anno; last = num; @@ -550,7 +564,7 @@ bool TPrimanota_application::edit_partite(int riga) } } - if (!saldo.is_zero()) // Aggiunge ultima partita se aperta + if (!saldo.is_zero() || nreg == curreg) // Aggiunge ultima partita se aperta { r.cut(0); r.add(ult); r.add(last); r.add(desc); @@ -584,7 +598,7 @@ bool TPrimanota_application::edit_scadenze(int currig, const TBill& b, int anno, TLocalisamfile scadenza(LF_SCADENZE); scadenza.zero(); scadenza.put(SCAD_ANNO, anno); scadenza.put(SCAD_NUMPART, num); - const TRectype recsca(scadenza.curr()); + const TRectype recsca(scadenza.curr()); // Filtra scadenze su anno partita TToken_string r(80); for (int err = scadenza.read(_isgteq); @@ -592,11 +606,11 @@ bool TPrimanota_application::edit_scadenze(int currig, const TBill& b, int anno, err = scadenza.next()) { r.cut(0); - r.add(scadenza.get(SCAD_NRATA)); - r.add(scadenza.get(SCAD_DATASCAD)); - r.add(scadenza.get(SCAD_IMPORTO)); - r.add(""); - r.add(""); + r.add(scadenza.get(SCAD_NRATA)); // Numero rata + r.add(scadenza.get(SCAD_DATASCAD)); // Data scadenza rata + r.add(scadenza.get(SCAD_IMPORTO)); // Importo rata + r.add(""); // Descrizione movimento + r.add(""); // Tipo movimento a.add(r); } @@ -608,7 +622,7 @@ bool TPrimanota_application::edit_scadenze(int currig, const TBill& b, int anno, const TString16 curreg(curr_mask().get(F_NUMREG)); // Numero registrazione corrente TString desc; // Descrizione di default - TRectype parbas(recpar); + TRectype parbas(recpar); // Partita base for (err = partita.read(_isgteq); err == NOERR && partita.curr() == recpar; err = partita.next()) { @@ -622,13 +636,13 @@ bool TPrimanota_application::edit_scadenze(int currig, const TBill& b, int anno, for (int i = 0; i < a.items(); i++) { TToken_string& t = a.row(i); - if (t.get(3)[0] <= ' ') - t.add(desc, 3); + const TFixed_string d(t.get(3)); + if (d.blank()) t.add(desc, 3); } } if (rata < 1 || partita.get(PART_REG).not_empty()) - continue; + continue; // Ignora chi non e' un pagamento for (long i = a.items()-1; i >= 0; i--) // Cerca scadenza corrispondente if (a.row(i).get_int(0) == rata) break; @@ -643,8 +657,9 @@ bool TPrimanota_application::edit_scadenze(int currig, const TBill& b, int anno, r.add(desc); r.add(partita.get(PART_NRIGA)); i = a.insert(r, i >= 0 ? i+1 : -1); - - if (partita.get(PART_NREG) != curreg || partita.get_int(PART_NRIGA) != currig) + + // Disabilita la righe che non riguardano la riga cliccata + if (partita.get(PART_NREG) != curreg || partita.get_int(PART_NUMRIG) != (currig+1)) a.disable(i); } @@ -662,13 +677,13 @@ bool TPrimanota_application::edit_scadenze(int currig, const TBill& b, int anno, scadenza.put(SCAD_NUMPART, num); scadenza.put(SCAD_NRATA, rata); err = scadenza.read(); - CHECKD(err == NOERR, "Non ritrovo piu' la rata ", rata); + CHECKD(err == NOERR, "Non ritrovo piu' la scadenza della rata ", rata); int urig = 1; int nrig = a.row().get_int(4); if (nrig == 0) // Ho cliccato su una scadenza { - for (pos = a.selected()+1; pos < a.items(); pos++) // Cerca pagamento + for (pos = a.selected()+1; pos < a.items(); pos++) // Cerca pagamento { const int nr = a.row(pos).get_int(4); if (nr) urig = nr; @@ -682,7 +697,7 @@ bool TPrimanota_application::edit_scadenze(int currig, const TBill& b, int anno, const bool nuovo = nrig == 0; TRectype part(parbas); - if (nuovo) // Inserimento di un nuovo pagamento + if (nuovo) // Inserimento di un nuovo pagamento { // PART_ANNO viene preso dalla partita base // PART_NUMPART viene preso dalla partita base @@ -692,8 +707,9 @@ bool TPrimanota_application::edit_scadenze(int currig, const TBill& b, int anno, part.put(PART_TIPOMOV, causale().tipomov()); // Dati causale corrente part.put(PART_CODCAUS, causale().codice()); - - part.put(PART_NUMRIG, currig); // Riga su cui ho cliccato + + part.put(PART_NREG, curreg); // Numero operazione + part.put(PART_NUMRIG, currig+1); // Riga su cui ho cliccato // Copia dati movimento corrente part.put(PART_DATAREG, curr_mask().get(F_DATAREG)); @@ -843,7 +859,7 @@ static bool importopag_handler(TMask_field& f, KEY k) } -bool TPrimanota_application::edit_pagamento(const TRectype& parbas, const TRectype& scaden, TRectype& part) +bool TPrimanota_application::edit_pagamento(TRectype& parbas, TRectype& scaden, TRectype& part) { TMask m("cg2100s"); m.set_handler(S_IMPORTOPAG, importopag_handler); @@ -853,10 +869,9 @@ bool TPrimanota_application::edit_pagamento(const TRectype& parbas, const TRecty partita.curr() = part; m.autoload(&rel); // Load current record on mask - const real importo(scaden.get(SCAD_IMPORTO)); - const real importopag(part.get(SCAD_IMPORTO)); - const real ritenute(part.get(PART_RITENUTE)); - const real residuo = importo - importopag; + const real dapagare(scaden.get(SCAD_IMPORTO)); + const real pagato(scaden.get(SCAD_IMPORTOPAG)); + const real residuo = dapagare - pagato; // Dati del documento (fattura) che ha generato la scadenza m.set(S_NUMDOC, parbas.get(PART_NUMDOC)); // Numero documento @@ -867,11 +882,15 @@ bool TPrimanota_application::edit_pagamento(const TRectype& parbas, const TRecty // Dati della scadenza che ha generato la partita m.set(S_RESIDUO, residuo.string()); // Residuo da pagare m.set(S_DATASCAD, scaden.get(SCAD_DATASCAD)); // Data della scadenza - m.set(S_IMPORTO, scaden.get(SCAD_IMPORTO)); // Importo della rata + m.set(S_IMPORTO, dapagare.string()); // Importo della rata m.set(S_IMPORTOVAL, scaden.get(SCAD_IMPORTOVAL)); // " in valuta m.set(S_RATA, scaden.get(SCAD_NRATA)); - if (importopag.is_zero()) + // Memorizza importi prima di eventuali variazioni + const real importo(part.get(PART_IMPORTO)); + const real ritenute(part.get(PART_RITENUTE)); + + if (importo.is_zero()) m.set(S_IMPORTOPAG, residuo.string()); const KEY key = m.run(); @@ -879,6 +898,9 @@ bool TPrimanota_application::edit_pagamento(const TRectype& parbas, const TRecty { m.autosave(&rel); part = partita.curr(); + + const real imp(m.get(S_IMPORTOPAG)); + scaden.put(SCAD_IMPORTOPAG, pagato-importo+imp); } return key == K_ENTER; diff --git a/cg/cg2600.cpp b/cg/cg2600.cpp index b27f7466b..fa15a1b86 100755 --- a/cg/cg2600.cpp +++ b/cg/cg2600.cpp @@ -1,1746 +1,1741 @@ -// Ricezione dati da sistema - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cglib04.h" -#include "cglib.h" -#include "cg2103.h" - -#include "cg2600.h" - -const int CAMPI_RCAUS = 6; -HIDDEN TString80 TEMP; - -HIDDEN int date2esc(const TDate& d, int* prevesc = NULL); - -class TRic_tab : public TApplication -{ - - TTable* _tab_tra; - TTransfer_file _tras_file; - TArray _aggiorna; - char _scelta; - TSaldo_agg _sld; - TProgind* _prog; - - int _numinv,_nultras,_annoes,_g,_c; - TString _trasf,_ragsoc_dittar,_sigle_file,_std,_key,_nomeid,_dittainv; - long _dittaric,_numrec,_nreg,_s,_ndoc,_npiva,_nupiva; - TDate _dataultras,_datareg,_dreg,_ddoc; - TString _uselab,_record,_nrec_file,_creg,_ccau,_tdoc,_cod_com; - bool _prima_volta; - long _protiva,_uprotiva,_nprotiva,_nuprotiva,_numreg,_numreg_p,_numreg_piva; - char _sez; - real _importo,_totdoc; - -public: - TString _titolo; - - virtual bool create(); - virtual bool destroy(); - virtual bool menu(MENU_TAG m); - bool main_loop(); - bool video(); - bool leggi_trasfer(); - bool controlli(); - void ditta_ricevente(); - bool controllo_pre_ricezione(); - void leggi_record_controllo(); - - void setta_parametri_record(const TString& sigla,const TString& flag); - - void trasferimento(); - - void scrivi_record_tab(TString& record,long rec); - int trasfer_data_tab(TLocalisamfile& file, TRectype& dep, const TString& sigla); - int trasfer_data_conto(TLocalisamfile& file, TRectype& dep); - int trasfer_data_sottoc(TLocalisamfile& file, TRectype& dep); - - void scrivi_record_mov(TString& record,long rec); - int trasfer_data_mov(TLocalisamfile& file, TRectype& dep); - long esiste_numreg(long nreg); - void num_protocollo(TString& record); - void controlli_prima_nota(TString& record); - long ulnumprot_reg(int anno,char codreg); - long ultima_registrazione(); - void aggiorna_reg(int anno,char codreg,long ulnum); - int annoes_datacomp(const TString& record,TDate& datacomp); - void datafine_esprec(const int annop,TDate& datacomp); - char ricerca_causale(const TString& field); - void prepara_saldi(const TString& fname,const TString& field); - - void scrivi_record_moviva(TString& record,long rec); - void aggiorna_temp_file(long numreg, long nreg); - long numreg_PN(long numreg); - long numrec_PN(long numreg); - void recupera_dati_testata(long numreg); - bool occasionali(const TString& record); - void scrivi_occasionali(const TString& record, long num); - void ricerca_comune(const TString& com); - int cerca_annoes(long numreg); - int trasfer_data_moviva(TLocalisamfile& file, TRectype& dep, int ln); - void salva_dati_testata(); - - const char* converti (TString& data_AS400); - const char* riconverti(TString& data_PC); - - TRic_tab(char ric_tab_mov); -}; - -HIDDEN TRic_tab& app() { return (TRic_tab &) main_app(); } - -TRic_tab::TRic_tab(char ric_tab_mov) : _scelta(toupper(ric_tab_mov)) -{ - if (_scelta == 'T') - _titolo = "Ricezione tabelle"; - - if (_scelta == 'M') - _titolo = "Ricezione movimenti"; -} - -bool TRic_tab::create() -{ - TApplication::create(); - - _tab_tra = new TTable ("%TRA"); - - _numrec = 1; - _prima_volta = TRUE; - _aggiorna.destroy(); - _numreg_p = 0; - _numreg_piva = 0; - _nreg = 0; - _sld.reset(); - - dispatch_e_menu (BAR_ITEM(1)); - - return TRUE; -} - -bool TRic_tab::destroy() -{ - delete _tab_tra; - - return TApplication::destroy(); -} - -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"); - if (d >= ia && d <= fa) - return anno; - if (prevesc) *prevesc = anno; - } - return 0; -} - -void TRic_tab::leggi_record_controllo() -{ - _tras_file.read_control_rec(); - _record = _tras_file.record(); -} - -const char* TRic_tab::converti (TString& data_AS400) -{ - TEMP = data_AS400.mid(4,2); - TEMP << "-" <= 0) - { - setta_parametri_record(" ","C"); - message_box("Aggiornamento tabelle terminato: proseguire con controllo movimenti"); - leggi_record_controllo(); - TString str (_record.overwrite(" ",241)); - _tras_file.write_control_rec(str,256); - } - else - { - setta_parametri_record(" ","*"); - fremove(_trasf); - setta_parametri_record(" "," "); - } - } - } - else - if (_scelta == 'M') - { - if (video()) - { - trasferimento(); - setta_parametri_record(" ","*"); - fremove(_trasf); - setta_parametri_record(" "," "); - } - } - - return FALSE; -} - -void TRic_tab::trasferimento() -{ - char uselab; - TString record(256),key; - int posiz,i; - long rec; - int last_tab; - char sigla; - TString message; - - uselab = (_tras_file.ult_file())[0]; - posiz = _tras_file.num(uselab); //Ritorna la posizione della sigla all'interno dell'indice - key = _tras_file.key(); - key.trim(); - - if (_scelta == 'T') - last_tab = _tras_file.last_tab(); - else - if (_scelta == 'M') - last_tab = _tras_file.last_mov(); - - for (i = posiz; i < last_tab;i++) - { - if (key == "") - rec = _tras_file.rec(i); - else - rec = atol(key.mid(2,6)); - - long nrec = ((_tras_file.nrec(i))+1); - sigla = _tras_file.name(i)[0]; - long cicli = nrec - rec; - - switch (sigla) - { - case 'W': message = "Ricezione tabella causali in corso... Prego attendere."; - break; - case 'A': message = "Ricezione anagrafica Clienti / Fornitori in corso... Prego attendere."; - break; - case 'P': message = "Ricezione anagrafica Piano dei Conti in corso... Prego attendere."; - break; - case 'Z': message = "Ricezione Movimenti di primanota in corso... Prego attendere."; - break; - case 'U': message = "Ricezione Movimenti iva in corso... Prego attendere."; - break; - default: break; - } - _prog = new TProgind(cicli,message,FALSE); - - for (long j = rec; j < nrec; j++) - { - _tras_file.read_rec_trasfer(j); - record = _tras_file.read_rec(); - - if (_scelta == 'T') - scrivi_record_tab(record,j); - else - if (_scelta == 'M') - { - if (sigla == 'Z') - { - scrivi_record_mov(record,j); - if (j == (nrec - 1)) - _sld.registra(); - } - else - if (sigla == 'U') - { - scrivi_record_moviva(record,j); - } - } - - } - delete _prog; - key = ""; //Altrimenti in caso di ripartenza mi ripristina sempre la situazione - } -} - -void TRic_tab::scrivi_record_tab(TString& record,long rec) -{ - TString sigla,key,str; - int numfield = 2; //Per le tabelle il primo campo della mappa non e' significativo - //ai fini del trasferimento (flag di record gia trasferito). - TMappa_trc& trc = _tras_file.mappa(); - TLocalisamfile* file = NULL; - TRectype* dep = NULL; - char gia_trasf; - int logicnum; - int campi_righe = 0; - int num_riga = 1; - TToken_string data; - - sigla = record.mid(0,2); - gia_trasf = record.mid(255,1)[0]; - - if (gia_trasf == ' ') - { - key.format("%2s%d", (const char*)sigla,numfield); - - if (trc.is_key((const char *) key)) - { - int logicnum_p = 0; - - do - { - logicnum = trc.logicnum(key); - - if (logicnum != logicnum_p) - { - if (logicnum_p) - { - _prog->addstatus(1); - trasfer_data_tab(*file, *dep, sigla); - delete file; - delete dep; - } - - file = new TLocalisamfile(logicnum); - dep = new TRectype (logicnum); - dep->zero(); - } - - logicnum_p = logicnum; - - if (logicnum == LF_RCAUSALI) - { - campi_righe++; - - if (campi_righe == CAMPI_RCAUS) - { - TString16 gruppo(dep->get("GRUPPO")); - // - // scarta le righe non significative - // -------------------- NB ----------------------- - // supponiamo il GRUPPO INDISPENSABILE !!!!!!!!!!!!! - // - if (gruppo.not_empty()) - { - dep->put("NRIGA", num_riga++); - - trasfer_data_tab(*file, *dep, sigla); - } - campi_righe = 1; - } - } - - int from = trc.from(key); - int to = trc.to(key); - TString fname = trc.field_name(key); - int flag = trc.flag(key); - TString field = record.sub(from-1,to); - - //Il nostro codice registro IVA e' lungo 3: se il loro registro (lungo 1) e' alfanumerico - //devo allinearlo a sinistra, mentre se e' numerico devo allinearlo a destra riempendolo con degli zero. - if (logicnum == LF_CAUSALI && fname == "REG") - { - char f = field[0]; - if (isdigit(f)) - field.format("%03c", f); - else - field.format("%-3c", f); - } - - //Il tipo cliente/fornitore presente su AS400 puo' assumere come valori 1 o 2 - //mentre quello su PC C o F; devo fare la conversione. - if (sigla == "A1") - { - if (fname == "TIPOCF") - { - if (field == "1") - field = "C"; - - if (field == "2") - field = "F"; - } - - //Il codice pagamento su AS400 e' un alfanumerico di due, mentre su PC e' un - //alfanumerico di 4 trattato con il flag Z. Dunque in ricezione se si tratta - //di un numero va riempito con degli 0. Se si tratta di un alfa va allineato a destra. - if (fname == "CODPAG") - { - TString f = field; - if (real::is_natural(f)) - field.format("%04s", (const char*) f); - else - field.format("%-4s", (const char*) f); - } - } - - if (flag) - { - data = ""; - data.add(fname); - data.add(field); - - _aggiorna.add(data); - } - - //Quando ricevo la IV direttiva del piano dei conti per evitare che nell'archivio, - //in caso di numero romano vuoto, venga memorizzato la stringa letta sul trasfer ("000"), - //vuoto la stringa prima di fare la put. - if ( (sigla == "P2" || sigla == "P3") && (fname == "NUMRIVD" || fname == "NUMRIVDOPP") ) - if (field == "000") - field = ""; - - dep->put(fname, (const char*)field); - - numfield++; - key.format("%2s%d", (const char*) sigla,numfield); - } - while (trc.is_key((const char*) key)); - - if (logicnum == LF_RCAUSALI) - { - campi_righe++; - - if (campi_righe == CAMPI_RCAUS) - { - TString16 gruppo(dep->get("GRUPPO")); - // - // scarta le righe non significative - // -------------------- NB ----------------------- - // supponiamo il GRUPPO INDISPENSABILE !!!!!!!!!!!!! - // - if (gruppo.not_empty()) - { - dep->put("NRIGA", num_riga++); - trasfer_data_tab(*file, *dep, sigla); - } - campi_righe = 1; - } - } - else - { - _prog->addstatus(1); - trasfer_data_tab(*file, *dep, sigla); - } - - delete file; - delete dep; - - _tras_file.writeat("*",1,1,sigla); - leggi_record_controllo(); - TString chiave; - chiave.format("%2s%d", (const char*) sigla,rec); - str = _record.overwrite(sigla,240); - str = _record.overwrite(chiave,241); - _tras_file.write_control_rec(str,256); - - } // if (trc.is_key((const char*) key)) - } // if (gia_trasf == ' ') -} - -int TRic_tab::trasfer_data_tab(TLocalisamfile& file, TRectype& dep, const TString& sigla) -{ - char flag; - - if (sigla == "P2") - { - trasfer_data_conto(file,dep); - } - else - if (sigla == "P3") - { - trasfer_data_sottoc(file,dep); - } - else - { - file.zero(); - file.curr() = dep; - - if (file.read() == NOERR) - { - flag = _tras_file.flg_agg(); - - if (flag == 'T') - { - file.zero(); - file.curr() = dep; - file.rewrite(); - } - if (flag == 'D') - { - for (int i = 0; i < _aggiorna.items(); i++) - { - TToken_string& data = (TToken_string&)_aggiorna[i]; - TString fname = data.get(0); - TString field = data.get(1); - file.put(fname,field); - } - file.rewrite(); - } - } - else - { - file.zero(); - file.curr() = dep; - file.write(); - } - } - - return 0; -} - -int TRic_tab::trasfer_data_conto(TLocalisamfile& file, TRectype& dep) -{ - char flag,flag_IV; - int g,c; - - flag_IV = _tras_file.flg_agg_IV(); - - file.zero(); - file.curr() = dep; - - if (file.read() == NOERR) - { - flag = _tras_file.flg_agg(); - flag_IV = _tras_file.flg_agg_IV(); - - if (flag == 'T') - { - g = dep.get_int(PCN_GRUPPO); - c = dep.get_int(PCN_CONTO); - - if (flag_IV == 'T') - { - file.zero(); - file.curr() = dep; - file.rewrite(); - } - else - { - dep.zero(PCN_SEZIVD); - dep.zero(PCN_LETTIVD); - dep.zero(PCN_NUMRIVD); - dep.zero(PCN_NUMIVD); - dep.zero(PCN_SEZIVDOPP); - dep.zero(PCN_LETTIVDOPP); - dep.zero(PCN_NUMRIVDOPP); - dep.zero(PCN_NUMIVDOPP); - file.curr() = dep; - file.rewrite(); - } - _tras_file.annulla_classi(g,c,TRUE); - } - if (flag == 'D') - { - for (int i = 0; i < _aggiorna.items(); i++) - { - TToken_string& data = (TToken_string&)_aggiorna[i]; - TString fname = data.get(0); - TString field = data.get(1); - file.put(fname,field); - } - file.rewrite(); - } - } - else - { - g = dep.get_int(PCN_GRUPPO); - c = dep.get_int(PCN_CONTO); - - if (flag_IV == 'T') - { - file.zero(); - file.curr() = dep; - file.write(); - } - else - { - g = dep.get_int(PCN_GRUPPO); - c = dep.get_int(PCN_CONTO); - - dep.zero(PCN_SEZIVD); - dep.zero(PCN_LETTIVD); - dep.zero(PCN_NUMRIVD); - dep.zero(PCN_NUMIVD); - dep.zero(PCN_SEZIVDOPP); - dep.zero(PCN_LETTIVDOPP); - dep.zero(PCN_NUMRIVDOPP); - dep.zero(PCN_NUMIVDOPP); - file.curr() = dep; - file.write(); - } - _tras_file.annulla_classi(g,c,TRUE); - } - return 0; -} - -int TRic_tab::trasfer_data_sottoc(TLocalisamfile& file, TRectype& dep) -{ - char flag,flag_IV; - int g,c; - char sez; - - sez = dep.get_char(PCN_SEZIVD); - flag_IV = _tras_file.flg_agg_IV(); - - file.zero(); - file.curr() = dep; - - if (file.read() == NOERR) - { - flag = _tras_file.flg_agg(); - flag_IV = _tras_file.flg_agg_IV(); - - if (flag == 'T') - { - g = dep.get_int(PCN_GRUPPO); - c = dep.get_int(PCN_CONTO); - - if (flag_IV == 'T') - { - if (sez != '\0') - _tras_file.annulla_classi(g,c,FALSE); - - file.zero(); - file.curr() = dep; - file.rewrite(); - } - else - { - dep.zero(PCN_SEZIVD); - dep.zero(PCN_LETTIVD); - dep.zero(PCN_NUMRIVD); - dep.zero(PCN_NUMIVD); - dep.zero(PCN_SEZIVDOPP); - dep.zero(PCN_LETTIVDOPP); - dep.zero(PCN_NUMRIVDOPP); - dep.zero(PCN_NUMIVDOPP); - file.curr() = dep; - file.rewrite(); - } - } - if (flag == 'D') - { - for (int i = 0; i < _aggiorna.items(); i++) - { - TToken_string& data = (TToken_string&)_aggiorna[i]; - TString fname = data.get(0); - TString field = data.get(1); - file.put(fname,field); - } - file.rewrite(); - } - } - else - { - g = dep.get_int(PCN_GRUPPO); - c = dep.get_int(PCN_CONTO); - - if (flag_IV == 'T') - { - if (sez != '\0') - _tras_file.annulla_classi(g,c,FALSE); - - file.zero(); - file.curr() = dep; - file.write(); - } - else - { - g = dep.get_int(PCN_GRUPPO); - c = dep.get_int(PCN_CONTO); - - dep.zero(PCN_SEZIVD); - dep.zero(PCN_LETTIVD); - dep.zero(PCN_NUMRIVD); - dep.zero(PCN_NUMIVD); - dep.zero(PCN_SEZIVDOPP); - dep.zero(PCN_LETTIVDOPP); - dep.zero(PCN_NUMRIVDOPP); - dep.zero(PCN_NUMIVDOPP); - file.curr() = dep; - file.write(); - } - } - return 0; -} - -long TRic_tab::esiste_numreg(long numulreg) -{ - TLocalisamfile mov (LF_MOV); - - do - { - numulreg++; - - mov.setkey(1); - mov.zero(); - mov.put(MOV_NUMREG, numulreg); - } - while (mov.read() == NOERR); - - return numulreg; -} - -void TRic_tab::num_protocollo(TString& record) -{ - _protiva = atol(record.sub(36,41)); - _uprotiva = atol(record.sub(108,113)); - - if (_protiva == 0) - _uprotiva = 0; - - _nprotiva = _protiva; - _nuprotiva = _uprotiva; -} - -long TRic_tab::ulnumprot_reg(int anno,char codreg) -{ - /* - TTable reg ("REG"); - TString16 dep; - long num = 0; - - dep.format("%04d%s", anno,(const char*) codreg); - - reg.zero(); - reg.put("CODTAB", (const char*) dep); - if (reg.read() == NOERR) - num = reg.get_long("I5"); - */ - TString cr = format("%c", codreg); - TRegistro rg (cr, anno); - - return rg.protocol(); -} - -void TRic_tab::aggiorna_reg(int anno,char codreg,long ulnum) -{ - TTable reg ("REG"); - TString16 dep; - - if (isdigit(codreg)) - dep.format("%04d%03c", anno,codreg); - else - dep.format("%04d%-3c", anno,codreg); - - reg.zero(); - reg.put("CODTAB", (const char*) dep); - if (reg.read() == NOERR) - { - if (_nprotiva > (ulnum + 1) ) - reg.put("I5", _nprotiva); - - if (_nuprotiva > (ulnum + 1) ) - reg.put("I5", _nuprotiva); - - reg.rewrite(); - } -} - -void TRic_tab::controlli_prima_nota(TString& record) -{ - TTable tpd ("%TPD"); - bool corrisp; - TDate datareg; - int anno; - long ulnum; - TString16 tmp; - char codreg; - TString tipodoc; - - // char codreg = record.sub(35,36)[0]; - // TString tipodoc = record.sub(220,222); - - int tiporeg = atoi(record.sub(222,223)); - - TString80 tmpmov = "%"; - tmpmov << _tras_file.path(_dittaric); - tmpmov << "\\" << TEMP_MOV; - - TIsamtempfile tmp_mov (LF_MOV, tmpmov, FALSE); - - tmp_mov.zero(); - tmp_mov.put(MOV_NUMREG, _numreg); - if (tmp_mov.read() == NOERR) - { - codreg = tmp_mov.get_char(MOV_REG); - tipodoc = tmp_mov.get (MOV_TIPODOC); - } - - tmp = record.sub(15,21); - TString data = converti(tmp); - datareg = data; - anno = datareg.year(); - - bool numprot_att = _tras_file.numprot_att(); - bool numprot_pas = _tras_file.numprot_pas(); - - tpd.zero(); - tpd.put("CODTAB", (const char*) tipodoc); - if (tpd.read() == NOERR) - corrisp = tpd.get_bool("B0"); - - if (codreg != ' ' && !corrisp) - { - if ( ( (tiporeg == 1 && (numprot_att || _protiva == 0) ) ) - || ( (tiporeg == 2 && (numprot_pas || _protiva == 0) ) ) ) - { - ulnum = ulnumprot_reg(anno,codreg); - _nprotiva = ulnum + 1; - if (_uprotiva != 0) - _nuprotiva = (_nprotiva - ulnum) + _uprotiva; - } - } - - aggiorna_reg(anno,codreg,ulnum); -} - -void TRic_tab::datafine_esprec(const int aep, TDate& datacomp) -{ - TTable esc("ESC"); - for (int err = esc.first(); err == NOERR; err = esc.next()) - { - const anno = esc.get_int("CODTAB"); - if (anno == aep) - datacomp = esc.get("D1"); - } -} - -int TRic_tab::annoes_datacomp(const TString& record, TDate& datacomp) -{ - TString tmp; - int segn; - int ae = 0; - - tmp = record.sub(15,21); - TString data = converti(tmp); - _datareg = data; - segn = atoi(record.sub(21,22)); - - ae = date2esc(_datareg); - if (segn == 0) - datacomp = _datareg; - - if (segn == 1) - { - ae -= 1; - datafine_esprec(ae,datacomp); - } - return ae; -} - -long TRic_tab::ultima_registrazione() -{ - if (_nreg == 0) - { - TLocalisamfile mov (LF_MOV); - - mov.last(); - return (mov.get_long(MOV_NUMREG)); - } - else - return _nreg; -} - -char TRic_tab::ricerca_causale(const TString& causale) -{ - TLocalisamfile cau (LF_CAUSALI); - TString codcau; - char movap = ' '; - - long caus = atol(causale); - codcau.format("%03d", caus); - - cau.setkey(1); - cau.zero(); - cau.put("CODCAUS", codcau); - if (cau.read() == NOERR) - movap = cau.get_char("MOVAP"); - - return movap; -} - -void TRic_tab::prepara_saldi(const TString& fname,const TString& field) -{ - if (fname == "GRUPPO") - _g = atoi(field); - - if (fname == "CONTO") - _c = atoi(field); - - if (fname == "SOTTOCONTO") - _s = atol(field); - - if (fname == "SEZIONE") - _sez = field[0]; - - if (fname == "IMPORTO") - { - real imp = real::ita2eng(field); - _importo = imp; - TString i = _importo.string(); - } -} - -void TRic_tab::scrivi_record_mov(TString& record,long rec) -{ - TString sigla,key,str; - int numfield = 3; //Per i movimenti i primi due campi della mappa non sono significativi - //ai fini del trasferimento (flag record gia trasferito e nuovo ultimo numero di registrazione). - TMappa_trc& trc = _tras_file.mappa(); - TLocalisamfile* file = NULL; - TRectype* dep = NULL; - char gia_trasf,annullato; - int logicnum; - long numulreg; - TDate datacomp; - TString nreg; - int fnrmov = 14; - - sigla = record.mid(0,2); - annullato = record.mid(248,1)[0]; - - if (annullato == ' ') - { - key.format("%2s%d", (const char*)sigla,numfield); - - if (trc.is_key((const char *) key)) - { - int logicnum_p = 0; - - _numreg = atol(record.sub(2,8)); - - if (_numreg != _numreg_p) - { - if (_numreg_p != 0) - { - _sld.registra(); - _sld.reset(); - } - - long nuovareg = atol(record.sub(250,256)); - - if (nuovareg == 0) - { - numulreg = ultima_registrazione(); //reperisco il numero ultima registrazione - _nreg = esiste_numreg(numulreg); - num_protocollo(record); - controlli_prima_nota(record); - } - else - { - _nreg = nuovareg; - numfield = fnrmov; - key.format("%2s%d", (const char*)sigla,numfield); - } - } - else - { - numfield = fnrmov; - key.format("%2s%d", (const char*)sigla,numfield); - } - - _annoes = annoes_datacomp(record,datacomp); - _numreg_p = _numreg; - gia_trasf = record.sub(249,250)[0]; - - if (gia_trasf == ' ') - { - do - { - logicnum = trc.logicnum(key); - - if (logicnum != logicnum_p) - { - if (logicnum_p) - { - trasfer_data_mov(*file, *dep); - nreg.format("%6d",_nreg); - _tras_file.writeat(nreg,6,2,sigla); - aggiorna_temp_file(_numreg,_nreg); - delete file; - delete dep; - } - - file = new TLocalisamfile(logicnum); - dep = new TRectype (logicnum); - dep->zero(); - } - - logicnum_p = logicnum; - - if (logicnum == 24 && numfield == 26) - { - numfield++; - key.format("%2s%d", (const char*) sigla,numfield); - continue; - } - - int from = trc.from(key); - int to = trc.to(key); - TString fname = trc.field_name(key); - TString field = record.sub(from-1,to); - int flag = trc.flag(key); - - //Il nostro codice registro IVA e' lungo 3: se il loro registro (lungo 1) e' alfanumerico - //devo allinearlo a sinistra, mentre se e' numerico devo allinearlo a destra riempendolo con degli zero. - if (logicnum == LF_MOV) - { - if (fname == "REG") - { - char f = field[0]; - if (isdigit(f)) - field.format("%03c", f); - else - field.format("%-3c", f); - } - - //Il codice pagamento su AS400 e' un alfanumerico di due, mentre su PC e' un - //alfanumerico di 4 trattato con il flag Z. Dunque in ricezione se si tratta - //di un numero va riempito con degli 0. Se si tratta di un alfa va allineato a destra. - if (fname == "CODPAG") - { - TString f = field; - if (real::is_natural(f)) - field.format("%04s", (const char*) f); - else - field.format("%-4s", (const char*) f); - } - } - - if (logicnum == LF_RMOV) - prepara_saldi(fname,field); - - if (fname == "PROTIVA") - { - char var[6]; - sprintf(var,"%5d",_nprotiva); - field = var; - } - if (fname == "UPROTIVA") - { - char var[6]; - sprintf(var,"%5d",_nuprotiva); - field = var; - } - - - if (logicnum == LF_MOV && fname == "CODCAUS") - { - _sld.set_anno_es(_annoes); - _sld.set_movprovv(FALSE); - _sld.set_num_ulmov(_nreg); - _sld.set_data_ulmov(_datareg); - char movap = ricerca_causale(field); - if (movap == 'A') - _sld.set_movap(TRUE); - } - - if (logicnum == LF_MOV && (fname == "NUMREG" || flag == 1) ) - { - if (fname == "NUMREG") - { - dep->put(MOV_ANNOES, _annoes); - dep->put(MOV_NUMREG, _nreg); - dep->put(MOV_DATAREG, _datareg); - dep->put(MOV_DATACOMP, datacomp); - } - if (flag == 1) - { - TString f = converti(field); - dep->put(fname,f); - } - } - else - if (logicnum == LF_RMOV && (fname == "NUMREG" || fname == "NUMRIG") ) - { - if (fname == "NUMREG") - { - dep->put(RMV_ANNOES, _annoes); - dep->put(RMV_NUMREG, _nreg); - } - - if (fname == "NUMRIG") - { - dep->put(RMV_NUMRIG, field); - dep->put(RMV_DATAREG, _datareg); - } - } - else - dep->put(fname, (const char*)field); - - numfield++; - key.format("%2s%d", (const char*) sigla,numfield); - } - while (trc.is_key((const char*) key)); - - _prog->addstatus(1); - trasfer_data_mov(*file, *dep); - TString impor = _importo.string(); - _sld.aggiorna(_g,_c,_s,_importo,_sez); - - delete file; - delete dep; - - _tras_file.writeat("*",1,1,sigla); - nreg.format("%6d",_nreg); - _tras_file.writeat(nreg,6,2,sigla); - //aggiorna_temp_file(_numreg,_nreg); - leggi_record_controllo(); - TString chiave; - chiave.format("%2s%d", (const char*) sigla,rec); - str = _record.overwrite(sigla,240); - str = _record.overwrite(chiave,241); - _tras_file.write_control_rec(str,256); - } // if (gia_trasf == ' ') - } // if (trc.is_key((const char*) key)) - } // if (gia_trasf == ' ') -} - -int TRic_tab::trasfer_data_mov(TLocalisamfile& file, TRectype& dep) -{ - file.zero(); - file.curr() = dep; - - if (file.read() == NOERR) - { - file.zero(); - file.curr() = dep; - file.rewrite(); - } - else - { - file.zero(); - file.curr() = dep; - file.write(); - } - return 0; -} - -void TRic_tab::aggiorna_temp_file(long numreg, long nreg) -{ - TString80 tmpmov = "%"; - tmpmov << _tras_file.path(_dittaric); - tmpmov << "\\" << TEMP_MOV; - - TIsamtempfile tmp_mov (LF_MOV, tmpmov, FALSE); - - tmp_mov.zero(); - tmp_mov.put(MOV_NUMREG, numreg); - if (tmp_mov.read() == NOERR) - { - tmp_mov.put(MOV_CODCF, nreg); - tmp_mov.rewrite(); - } -} - -long TRic_tab::numrec_PN(long numreg) -{ - long num = 0; - - TString80 tmpmov = "%"; - tmpmov << _tras_file.path(_dittaric); - tmpmov << "\\" << TEMP_MOV; - - TIsamtempfile tmp_mov (LF_MOV, tmpmov, FALSE); - - tmp_mov.zero(); - tmp_mov.put(MOV_NUMREG, numreg); - if (tmp_mov.read() == NOERR) - num = tmp_mov.get_long(MOV_NUMGIO); - - return num; -} - -long TRic_tab::numreg_PN(long numreg) -{ - long num = 0; - - TString80 tmpmov = "%"; - tmpmov << _tras_file.path(_dittaric); - tmpmov << "\\" << TEMP_MOV; - - TIsamtempfile tmp_mov (LF_MOV, tmpmov, FALSE); - - tmp_mov.zero(); - tmp_mov.put(MOV_NUMREG, numreg); - if (tmp_mov.read() == NOERR) - num = tmp_mov.get_long(MOV_CODCF); - - return num; -} - -void TRic_tab::recupera_dati_testata(long numreg) -{ - TLocalisamfile mov (LF_MOV); - - mov.setkey(1); - mov.zero(); - mov.put(MOV_NUMREG, numreg); - if (mov.read() == NOERR) - { - _dreg = mov.get_date(MOV_DATAREG); - _ddoc = mov.get_date(MOV_DATADOC); - _ndoc = mov.get_long(MOV_NUMDOC); - _creg = mov.get (MOV_REG); - _ccau = mov.get (MOV_CODCAUS); - _tdoc = mov.get (MOV_TIPODOC); - _npiva = mov.get_long(MOV_PROTIVA); - _nupiva = mov.get_long(MOV_UPROTIVA); - _totdoc = mov.get_real(MOV_TOTDOC); - } -} - -bool TRic_tab::occasionali(const TString& record) -{ - TLocalisamfile occas (LF_OCCAS); - TString ragsoc; - long num; - - ragsoc = record.sub(61,86); - ragsoc.trim(); - - if (ragsoc == "") return FALSE; - - occas.setkey(1); - occas.zero(); - occas.put("CFPI", "RIC999999"); - if (occas.read() == NOERR) - num = 0; - else - if ( (occas.get("CFPI")).len() > 9) - { - occas.prev(); - if ( (occas.get("CFPI")).len() > 9) - num = 0; - else - { - TString cfpi = occas.get("CFPI"); - - if (cfpi.mid(0,3) == "RIC" && cfpi.len() == 9) - { - num = atol(cfpi.mid(3,6)); - num += 1; - } - else - num = 0; - } - } - else - { - TString cfpi = occas.get("CFPI"); - - if (cfpi.mid(0,3) == "RIC" && cfpi.len() == 9) - { - num = atol(cfpi.mid(3,6)); - num += 1; - } - else - num = 0; - } - - scrivi_occasionali(record,num); - - return TRUE; -} - -void TRic_tab::scrivi_occasionali(const TString& record, long num) -{ - TLocalisamfile occas (LF_OCCAS); - TString cfpi,ragsoc,ind,com,cap,app; - int err; - - app = "RIC"; - cfpi.format("%3s%6d", (const char*)app,num); - ragsoc = record.sub(61,86); - ind = record.sub(86,108); - com = record.sub(108,126); - cap = record.sub(126,131); - - ricerca_comune(com); - - occas.setkey(1); - occas.zero(); - occas.put("CFPI", cfpi); - occas.put("RAGSOC", ragsoc); - occas.put("INDIR", ind); - occas.put("CAP", cap); - if (_cod_com != "") - occas.put("COM", _cod_com); - - err = occas.write(); - - if (err == _isreinsert) - err = occas.rewrite(); -} - -void TRic_tab::ricerca_comune(const TString& com) -{ - TLocalisamfile comuni (LF_COMUNI); - - comuni.setkey(2); - comuni.zero(); - comuni.put(COM_DENCOM, com); - if (comuni.read() == NOERR) - _cod_com = comuni.get(COM_COM); - else - _cod_com = ""; -} - -int TRic_tab::cerca_annoes(long numreg) -{ - TLocalisamfile mov (LF_MOV); - int anno = 0; - - mov.setkey(1); - mov.zero(); - mov.put(MOV_NUMREG, numreg); - if (mov.read() == NOERR) - anno = mov.get_int(MOV_ANNOES); - - return anno; -} - -void TRic_tab::salva_dati_testata() -{ - TString str,app; - long numrec; - - numrec = numrec_PN(_numreg); - numrec += _tras_file.start('Z'); - - _tras_file.read_rec_trasfer(numrec); //Leggo il record della prima nota - - app = _dreg.string(); - str = riconverti(app); - _tras_file.put(str,"Z1",0,numrec); - app = _ddoc.string(); - str = riconverti(app); - _tras_file.put(str,"Z1",4,numrec); - str = format("%ld", _ndoc); - _tras_file.put(str,"Z1",5,numrec); - _tras_file.put(_creg,"Z1",6,numrec); - _tras_file.put(_ccau,"Z1",8,numrec); - _tras_file.put(_tdoc,"Z1",12,numrec); - str = format("%ld", _npiva); - _tras_file.put(str,"Z1",7,numrec); - str = format("%ld", _nupiva); - _tras_file.put(str,"Z1",10,numrec); - str = _totdoc.string(); - _tras_file.put(str,"Z1",13,numrec); - _tras_file.write(numrec); -} - -void TRic_tab::scrivi_record_moviva(TString& record,long rec) -{ - TString sigla,key,str; - int numfield = 3; //Per i movimenti i primi due campi della mappa non sono significativi - //ai fini del trasferimento (flag record gia trasferito e nuovo ultimo numero di registrazione). - TMappa_trc& trc = _tras_file.mappa(); - TLocalisamfile* file = NULL; - TRectype* dep = NULL; - char gia_trasf,annullato; - int logicnum; - TString nreg; - int fnrmiva = 11; - - sigla = record.mid(0,2); - annullato = record.mid(248,1)[0]; - - if (annullato == ' ') - { - key.format("%2s%d", (const char*)sigla,numfield); - - if (trc.is_key((const char *) key)) - { - int logicnum_p = 0; - - _numreg = atol(record.sub(2,8)); - - if (_numreg != _numreg_piva) - { - long nuovareg = atol(record.sub(250,256)); - - if (nuovareg == 0) - _nreg = numreg_PN(_numreg); - else - { - _nreg = nuovareg; - //recupera_dati_testata(_nreg); - numfield = fnrmiva; - key.format("%2s%d", (const char*)sigla,numfield); - } - recupera_dati_testata(_nreg); - } - else - { - numfield = fnrmiva; - key.format("%2s%d", (const char*)sigla,numfield); - } - - _numreg_piva = _numreg; - gia_trasf = record.sub(249,250)[0]; - - if (gia_trasf == ' ' || _ccau != "000") - { - - occasionali(record); - - do - { - logicnum = trc.logicnum(key); - - if (logicnum != logicnum_p) - { - if (logicnum_p) - { - trasfer_data_moviva(*file, *dep, logicnum_p); - nreg.format("%6d",_nreg); - _tras_file.writeat(nreg,6,2,sigla); - salva_dati_testata(); - delete file; - delete dep; - } - - file = new TLocalisamfile(logicnum); - dep = new TRectype (logicnum); - dep->zero(); - } - - logicnum_p = logicnum; - - int from = trc.from(key); - int to = trc.to(key); - TString fname = trc.field_name(key); - TString field = record.sub(from-1,to); - int flag = trc.flag(key); - - if (logicnum == LF_MOV && fname == "CAMBIOI" && flag == 5) - { - int l = field.len(); - int p = l - flag; - field.insert(".",p); - } - - if (logicnum == LF_MOV && fname == "CORRVALUTA" && flag == 5) - { - int l = field.len(); - int p = l -flag; - field.insert(".",p); - } - - if (logicnum == LF_MOV && ( fname == "NUMREG" || flag == 1 ) ) - { - if (fname == "NUMREG") - dep->put("NUMREG", _nreg); - - if (flag == 1) - { - TString f = converti(field); - dep->put(fname,f); - } - } - else - if (logicnum == LF_RMOVIVA && fname == "NUMREG") - { - int annoes = cerca_annoes(_nreg); - dep->put("ANNOES", annoes); - dep->put("NUMREG", _nreg); - } - else - dep->put(fname, (const char*)field); - - numfield++; - key.format("%2s%d", (const char*) sigla,numfield); - } - while (trc.is_key((const char*) key)); - - _prog->addstatus(1); - trasfer_data_moviva(*file, *dep, logicnum_p); - TString impor = _importo.string(); - - delete file; - delete dep; - - _tras_file.read_rec_trasfer(rec); //Per essere sicuro di essere posizionato sul record giusto dell'iva sul trasfer - _tras_file.writeat("*",1,1,sigla); - nreg.format("%6d",_nreg); - _tras_file.writeat(nreg,6,2,sigla); - leggi_record_controllo(); - TString chiave; - chiave.format("%2s%d", (const char*) sigla,rec); - str = _record.overwrite(sigla,240); - str = _record.overwrite(chiave,241); - _tras_file.write_control_rec(str,256); - } // if (gia_trasf == ' ') - } // if (trc.is_key((const char*) key)) - } // if (gia_trasf == ' ') -} - -int TRic_tab::trasfer_data_moviva(TLocalisamfile& file, TRectype& dep, int ln) -{ - file.zero(); - file.curr() = dep; - - if (file.read() == NOERR) - { - if (ln == LF_MOV) - { - TDate data74ter (dep.get_date(MOV_DATA74TER)); - TString codval (dep.get (MOV_CODVAL)); - long codcf = dep.get_long(MOV_CODCF); - real totdoc (dep.get_real(MOV_TOTDOC)); - real cambioi (dep.get_real(MOV_CAMBIOI)); - real corrlire (dep.get_real(MOV_CORRLIRE)); - real corrvaluta(dep.get_real(MOV_CORRVALUTA)); - - file.put(MOV_DATA74TER, data74ter); - file.put(MOV_CODVAL, codval); - file.put(MOV_CODCF, codcf); - file.put(MOV_TOTDOC, totdoc); - file.put(MOV_CAMBIOI, cambioi); - file.put(MOV_CORRLIRE, corrlire); - file.put(MOV_CORRVALUTA,corrvaluta); - - file.rewrite(); - } - else - { - file.zero(); - file.curr() = dep; - file.rewrite(); - } - } - else - { - file.zero(); - file.curr() = dep; - file.write(); - } - - return 0; -} - -bool TRic_tab::leggi_trasfer() -{ - _nultras = 0; - - _trasf = _tras_file.path(_dittaric); - _trasf << "\\trasfer"; - - _tras_file.open(_trasf); - - if (_tras_file.exist()) - { - if (_tras_file.read_control_rec()) - { - _nultras = _tras_file.nultras(); - _dataultras = _tras_file.dataultras(); - _sigle_file = _tras_file.sigle_file(); - _nrec_file = _tras_file.nrec_file(); - // La fill_index e' richiamata dentro a read_control_rec - // _tras_file.fill_index(_sigle_file,_nrec_file); - _uselab = _tras_file.ult_file(); - _key = _tras_file.key(); - _record = _tras_file.record(); - } -else - return error_box("Rilevati gravi errori negli archivi:procedura interrotta"); - } -else - return error_box("Al momento non presenti trasferimenti attivi sulla ditta selezionata"); - - return TRUE; -} - -bool TRic_tab::video() -{ - TConfig conf(CONFIG_DITTA); - - _std = conf.get("FlStTra"); - - if (!leggi_trasfer()) - return FALSE; - - TMask msk ("cg2600a"); - KEY tasto; - - ditta_ricevente(); - - msk.set(F_CODDITTA, _dittaric); - msk.set(F_RAGSOC, _ragsoc_dittar); - msk.set(F_NULTRAS, _nultras); - TString data1 = _dataultras.string(); - msk.set(F_DATAULTRAS, data1); - msk.set(F_STD, _std); - msk.set(F_USELAB, _uselab); - msk.set(F_STATO, _key); - - tasto = msk.run(); - - if (tasto != K_ENTER) - return FALSE; - - if (!prefix().exist(_dittaric)) - return error_box("Rilevati gravi errori negli archivi: procedura interrotta"); - - if (!controlli()) - return FALSE; - - return TRUE; -} - -void TRic_tab::setta_parametri_record(const TString& sigla,const TString& flag) -{ - TConfig conf (CONFIG_DITTA); - - conf.set("FlStTra", flag); - - leggi_record_controllo(); - _record.overwrite(sigla,240); - - const int size = 256; - - _tras_file.write_control_rec(_record, size); -} - -bool TRic_tab::controllo_pre_ricezione() -{ - TString flag; - - TString sigla = _sigle_file.mid(0,1); - - if (sigla == " ") - { - flag = "*"; - setta_parametri_record(sigla,flag); - fremove(_trasf); - return FALSE; - } - - if (sigla == "Z") - { - flag = "C"; - setta_parametri_record(sigla,flag); - return error_box("Aggiornamento tabelle terminato: proseguire con controllo movimenti"); - } - - if (sigla != "Z") - { - flag = "T"; - setta_parametri_record(sigla,flag); - return TRUE; - } - - return TRUE; -} - -void TRic_tab::ditta_ricevente() -{ - TLocalisamfile nditte (LF_NDITTE); - - nditte.setkey(1); - nditte.zero(); - nditte.put(NDT_CODDITTA, _dittaric); - if (nditte.read() == NOERR) - _ragsoc_dittar = nditte.get(NDT_RAGSOC); -} - -bool TRic_tab::controlli() -{ - if (_scelta == 'T') - { - if (_std == "C") - return error_box("Aggiornamento tabelle gia' effettuato: richiamare Controllo movimenti"); - - if (_std == "M") - return error_box("Aggiornamento tabelle gia' effettuato: richiamare Trasferimento movimenti"); - - if (_std != "" && _std != "T") - return error_box("Rilevati gravi errori negli archivi: procedura interrotta"); - - if ( (_std == "" || _std == "T") && (_uselab == "Z" || _uselab == "U") ) - return error_box("Rilevati gravi errori negli archivi: procedura interrotta"); - } - else - if (_scelta == 'M') - { - if (_std == "" || _std == "T") - return error_box("Aggiornamento tabelle NON EFFETTUATO: richiamare il programma relativo"); - - if (_std == "C") - return error_box("Controllo movimenti non effettuato o rilevati errori gravi"); - - if (_std == "M" && (_uselab != "Z" && _uselab != "U" && _uselab != "B") ) - return error_box("Rilevati GRAVI ERRORI negli archivi: procedura interrotta"); - - if (_std != "" && _std != "M") - error_box("Rilevati GRAVI ERRORI negli archivi: procedura interrotta"); - } - - if (_std == "*") - { - warning_box("Trasferimento interamente completato: proseguire per cancellare il file"); - fremove(_trasf); - return FALSE; - } - - return TRUE; -} - -bool TRic_tab::menu(MENU_TAG m) -{ - if (m == BAR_ITEM(1)) - return main_loop(); - return FALSE; -} - -int cg2600 (int argc, char* argv[]) -{ - TRic_tab main_app(*argv[2]); - main_app.run(argc, argv,main_app._titolo); - return TRUE; -} +// Ricezione dati da sistema + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "cglib04.h" +#include "cglib.h" +#include "cg2103.h" + +#include "cg2600.h" + +const int CAMPI_RCAUS = 6; +HIDDEN TString80 TEMP; + +HIDDEN int date2esc(const TDate& d, int* prevesc = NULL); + +class TRic_tab : public TApplication +{ + + TTable* _tab_tra; + TTransfer_file _tras_file; + TArray _aggiorna; + char _scelta; + TSaldo_agg _sld; + TProgind* _prog; + + int _numinv,_nultras,_annoes,_g,_c; + TString _trasf,_ragsoc_dittar,_sigle_file,_std,_key,_nomeid,_dittainv; + long _dittaric,_numrec,_nreg,_s,_ndoc,_npiva,_nupiva; + TDate _dataultras,_datareg,_dreg,_ddoc; + TString _uselab,_record,_nrec_file,_creg,_ccau,_tdoc,_cod_com; + bool _prima_volta; + long _protiva,_uprotiva,_nprotiva,_nuprotiva,_numreg,_numreg_p,_numreg_piva; + char _sez; + real _importo,_totdoc; + +public: + TString _titolo; + + virtual bool create(); + virtual bool destroy(); + virtual bool menu(MENU_TAG m); + bool main_loop(); + bool video(); + bool leggi_trasfer(); + bool controlli(); + void ditta_ricevente(); + bool controllo_pre_ricezione(); + void leggi_record_controllo(); + + void setta_parametri_record(const TString& sigla,const TString& flag); + + void trasferimento(); + + void scrivi_record_tab(TString& record,long rec); + int trasfer_data_tab(TLocalisamfile& file, TRectype& dep, const TString& sigla); + int trasfer_data_conto(TLocalisamfile& file, TRectype& dep); + int trasfer_data_sottoc(TLocalisamfile& file, TRectype& dep); + + void scrivi_record_mov(TString& record,long rec); + int trasfer_data_mov(TLocalisamfile& file, TRectype& dep); + long esiste_numreg(long nreg); + void num_protocollo(TString& record); + void controlli_prima_nota(TString& record); + long ulnumprot_reg(int anno,char codreg); + long ultima_registrazione(); + void aggiorna_reg(int anno,char codreg,long ulnum); + int annoes_datacomp(const TString& record,TDate& datacomp); + void datafine_esprec(const int annop,TDate& datacomp); + char ricerca_causale(const TString& field); + void prepara_saldi(const TString& fname,const TString& field); + + void scrivi_record_moviva(TString& record,long rec); + void aggiorna_temp_file(long numreg, long nreg); + long numreg_PN(long numreg); + long numrec_PN(long numreg); + void recupera_dati_testata(long numreg); + bool occasionali(const TString& record); + void scrivi_occasionali(const TString& record, long num); + void ricerca_comune(const TString& com); + int cerca_annoes(long numreg); + int trasfer_data_moviva(TLocalisamfile& file, TRectype& dep, int ln); + void salva_dati_testata(); + + const char* converti (TString& data_AS400); + const char* riconverti(TString& data_PC); + + TRic_tab(char ric_tab_mov); +}; + +HIDDEN TRic_tab& app() { return (TRic_tab &) main_app(); } + +TRic_tab::TRic_tab(char ric_tab_mov) : _scelta(toupper(ric_tab_mov)) +{ + if (_scelta == 'T') + _titolo = "Ricezione tabelle"; + + if (_scelta == 'M') + _titolo = "Ricezione movimenti"; +} + +bool TRic_tab::create() +{ + TApplication::create(); + + _tab_tra = new TTable ("%TRA"); + + _numrec = 1; + _prima_volta = TRUE; + _aggiorna.destroy(); + _numreg_p = 0; + _numreg_piva = 0; + _nreg = 0; + _sld.reset(); + + dispatch_e_menu (BAR_ITEM(1)); + + return TRUE; +} + +bool TRic_tab::destroy() +{ + delete _tab_tra; + + return TApplication::destroy(); +} + +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"); + if (d >= ia && d <= fa) + return anno; + if (prevesc) *prevesc = anno; + } + return 0; +} + +void TRic_tab::leggi_record_controllo() +{ + _tras_file.read_control_rec(); + _record = _tras_file.record(); +} + +const char* TRic_tab::converti (TString& data_AS400) +{ + TEMP = data_AS400.mid(4,2); + TEMP << "-" <= 0) + { + setta_parametri_record(" ","C"); + message_box("Aggiornamento tabelle terminato: proseguire con controllo movimenti"); + leggi_record_controllo(); + TString str (_record.overwrite(" ",241)); + _tras_file.write_control_rec(str,256); + } + else + { + setta_parametri_record(" ","*"); + fremove(_trasf); + setta_parametri_record(" "," "); + } + } + } + else + if (_scelta == 'M') + { + if (video()) + { + trasferimento(); + setta_parametri_record(" ","*"); + fremove(_trasf); + setta_parametri_record(" "," "); + } + } + + return FALSE; +} + +void TRic_tab::trasferimento() +{ + char uselab; + TString record(256),key; + int posiz,i; + long rec; + int last_tab; + char sigla; + TString message; + + uselab = (_tras_file.ult_file())[0]; + posiz = _tras_file.num(uselab); //Ritorna la posizione della sigla all'interno dell'indice + key = _tras_file.key(); + key.trim(); + + if (_scelta == 'T') + last_tab = _tras_file.last_tab(); + else + if (_scelta == 'M') + last_tab = _tras_file.last_mov(); + + for (i = posiz; i < last_tab;i++) + { + if (key == "") + rec = _tras_file.rec(i); + else + rec = atol(key.mid(2,6)); + + long nrec = ((_tras_file.nrec(i))+1); + sigla = _tras_file.name(i)[0]; + long cicli = nrec - rec; + + switch (sigla) + { + case 'W': message = "Ricezione tabella causali in corso... Prego attendere."; + break; + case 'A': message = "Ricezione anagrafica Clienti / Fornitori in corso... Prego attendere."; + break; + case 'P': message = "Ricezione anagrafica Piano dei Conti in corso... Prego attendere."; + break; + case 'Z': message = "Ricezione Movimenti di primanota in corso... Prego attendere."; + break; + case 'U': message = "Ricezione Movimenti iva in corso... Prego attendere."; + break; + default: break; + } + _prog = new TProgind(cicli,message,FALSE); + + for (long j = rec; j < nrec; j++) + { + _tras_file.read_rec_trasfer(j); + record = _tras_file.read_rec(); + + if (_scelta == 'T') + scrivi_record_tab(record,j); + else + if (_scelta == 'M') + { + if (sigla == 'Z') + { + scrivi_record_mov(record,j); + if (j == (nrec - 1)) + _sld.registra(); + } + else + if (sigla == 'U') + { + scrivi_record_moviva(record,j); + } + } + + } + delete _prog; + key = ""; //Altrimenti in caso di ripartenza mi ripristina sempre la situazione + } +} + +void TRic_tab::scrivi_record_tab(TString& record,long rec) +{ + TString sigla,key,str; + int numfield = 2; //Per le tabelle il primo campo della mappa non e' significativo + //ai fini del trasferimento (flag di record gia trasferito). + TMappa_trc& trc = _tras_file.mappa(); + TLocalisamfile* file = NULL; + TRectype* dep = NULL; + char gia_trasf; + int logicnum; + int campi_righe = 0; + int num_riga = 1; + TToken_string data; + + sigla = record.mid(0,2); + gia_trasf = record.mid(255,1)[0]; + + if (gia_trasf == ' ') + { + key.format("%2s%d", (const char*)sigla,numfield); + + if (trc.is_key((const char *) key)) + { + int logicnum_p = 0; + + do + { + logicnum = trc.logicnum(key); + + if (logicnum != logicnum_p) + { + if (logicnum_p) + { + _prog->addstatus(1); + trasfer_data_tab(*file, *dep, sigla); + delete file; + delete dep; + } + + file = new TLocalisamfile(logicnum); + dep = new TRectype (logicnum); + dep->zero(); + } + + logicnum_p = logicnum; + + if (logicnum == LF_RCAUSALI) + { + campi_righe++; + + if (campi_righe == CAMPI_RCAUS) + { + TString16 gruppo(dep->get("GRUPPO")); + // + // scarta le righe non significative + // -------------------- NB ----------------------- + // supponiamo il GRUPPO INDISPENSABILE !!!!!!!!!!!!! + // + if (gruppo.not_empty()) + { + dep->put("NRIGA", num_riga++); + + trasfer_data_tab(*file, *dep, sigla); + } + campi_righe = 1; + } + } + + int from = trc.from(key); + int to = trc.to(key); + TString fname = trc.field_name(key); + int flag = trc.flag(key); + TString field = record.sub(from-1,to); + + //Il nostro codice registro IVA e' lungo 3: se il loro registro (lungo 1) e' alfanumerico + //devo allinearlo a sinistra, mentre se e' numerico devo allinearlo a destra riempendolo con degli zero. + if (logicnum == LF_CAUSALI && fname == "REG") + { + char f = field[0]; + if (isdigit(f)) + field.format("%03c", f); + else + field.format("%-3c", f); + } + + //Il tipo cliente/fornitore presente su AS400 puo' assumere come valori 1 o 2 + //mentre quello su PC C o F; devo fare la conversione. + if (sigla == "A1") + { + if (fname == "TIPOCF") + { + if (field == "1") + field = "C"; + + if (field == "2") + field = "F"; + } + + //Il codice pagamento su AS400 e' un alfanumerico di due, mentre su PC e' un + //alfanumerico di 4 trattato con il flag Z. Dunque in ricezione se si tratta + //di un numero va riempito con degli 0. Se si tratta di un alfa va allineato a destra. + if (fname == "CODPAG") + { + TString f = field; + if (real::is_natural(f)) + field.format("%04s", (const char*) f); + else + field.format("%-4s", (const char*) f); + } + } + + if (flag) + { + data = ""; + data.add(fname); + data.add(field); + + _aggiorna.add(data); + } + + //Quando ricevo la IV direttiva del piano dei conti per evitare che nell'archivio, + //in caso di numero romano vuoto, venga memorizzato la stringa letta sul trasfer ("000"), + //vuoto la stringa prima di fare la put. + if ( (sigla == "P2" || sigla == "P3") && (fname == "NUMRIVD" || fname == "NUMRIVDOPP") ) + if (field == "000") + field = ""; + + dep->put(fname, (const char*)field); + + numfield++; + key.format("%2s%d", (const char*) sigla,numfield); + } + while (trc.is_key((const char*) key)); + + if (logicnum == LF_RCAUSALI) + { + campi_righe++; + + if (campi_righe == CAMPI_RCAUS) + { + TString16 gruppo(dep->get("GRUPPO")); + // + // scarta le righe non significative + // -------------------- NB ----------------------- + // supponiamo il GRUPPO INDISPENSABILE !!!!!!!!!!!!! + // + if (gruppo.not_empty()) + { + dep->put("NRIGA", num_riga++); + trasfer_data_tab(*file, *dep, sigla); + } + campi_righe = 1; + } + } + else + { + _prog->addstatus(1); + trasfer_data_tab(*file, *dep, sigla); + } + + delete file; + delete dep; + + _tras_file.writeat("*",1,1,sigla); + leggi_record_controllo(); + TString chiave; + chiave.format("%2s%d", (const char*) sigla,rec); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,256); + + } // if (trc.is_key((const char*) key)) + } // if (gia_trasf == ' ') +} + +int TRic_tab::trasfer_data_tab(TLocalisamfile& file, TRectype& dep, const TString& sigla) +{ + char flag; + + if (sigla == "P2") + { + trasfer_data_conto(file,dep); + } + else + if (sigla == "P3") + { + trasfer_data_sottoc(file,dep); + } + else + { + file.zero(); + file.curr() = dep; + + if (file.read() == NOERR) + { + flag = _tras_file.flg_agg(); + + if (flag == 'T') + { + file.zero(); + file.curr() = dep; + file.rewrite(); + } + if (flag == 'D') + { + for (int i = 0; i < _aggiorna.items(); i++) + { + TToken_string& data = (TToken_string&)_aggiorna[i]; + TString fname = data.get(0); + TString field = data.get(1); + file.put(fname,field); + } + file.rewrite(); + } + } + else + { + file.zero(); + file.curr() = dep; + file.write(); + } + } + + return 0; +} + +int TRic_tab::trasfer_data_conto(TLocalisamfile& file, TRectype& dep) +{ + char flag,flag_IV; + int g,c; + + flag_IV = _tras_file.flg_agg_IV(); + + file.zero(); + file.curr() = dep; + + if (file.read() == NOERR) + { + flag = _tras_file.flg_agg(); + flag_IV = _tras_file.flg_agg_IV(); + + if (flag == 'T') + { + g = dep.get_int(PCN_GRUPPO); + c = dep.get_int(PCN_CONTO); + + if (flag_IV == 'T') + { + file.zero(); + file.curr() = dep; + file.rewrite(); + } + else + { + dep.zero(PCN_SEZIVD); + dep.zero(PCN_LETTIVD); + dep.zero(PCN_NUMRIVD); + dep.zero(PCN_NUMIVD); + dep.zero(PCN_SEZIVDOPP); + dep.zero(PCN_LETTIVDOPP); + dep.zero(PCN_NUMRIVDOPP); + dep.zero(PCN_NUMIVDOPP); + file.curr() = dep; + file.rewrite(); + } + _tras_file.annulla_classi(g,c,TRUE); + } + if (flag == 'D') + { + for (int i = 0; i < _aggiorna.items(); i++) + { + TToken_string& data = (TToken_string&)_aggiorna[i]; + TString fname = data.get(0); + TString field = data.get(1); + file.put(fname,field); + } + file.rewrite(); + } + } + else + { + g = dep.get_int(PCN_GRUPPO); + c = dep.get_int(PCN_CONTO); + + if (flag_IV == 'T') + { + file.zero(); + file.curr() = dep; + file.write(); + } + else + { + g = dep.get_int(PCN_GRUPPO); + c = dep.get_int(PCN_CONTO); + + dep.zero(PCN_SEZIVD); + dep.zero(PCN_LETTIVD); + dep.zero(PCN_NUMRIVD); + dep.zero(PCN_NUMIVD); + dep.zero(PCN_SEZIVDOPP); + dep.zero(PCN_LETTIVDOPP); + dep.zero(PCN_NUMRIVDOPP); + dep.zero(PCN_NUMIVDOPP); + file.curr() = dep; + file.write(); + } + _tras_file.annulla_classi(g,c,TRUE); + } + return 0; +} + +int TRic_tab::trasfer_data_sottoc(TLocalisamfile& file, TRectype& dep) +{ + char flag,flag_IV; + int g,c; + char sez; + + sez = dep.get_char(PCN_SEZIVD); + flag_IV = _tras_file.flg_agg_IV(); + + file.zero(); + file.curr() = dep; + + if (file.read() == NOERR) + { + flag = _tras_file.flg_agg(); + flag_IV = _tras_file.flg_agg_IV(); + + if (flag == 'T') + { + g = dep.get_int(PCN_GRUPPO); + c = dep.get_int(PCN_CONTO); + + if (flag_IV == 'T') + { + if (sez != '\0') + _tras_file.annulla_classi(g,c,FALSE); + + file.zero(); + file.curr() = dep; + file.rewrite(); + } + else + { + dep.zero(PCN_SEZIVD); + dep.zero(PCN_LETTIVD); + dep.zero(PCN_NUMRIVD); + dep.zero(PCN_NUMIVD); + dep.zero(PCN_SEZIVDOPP); + dep.zero(PCN_LETTIVDOPP); + dep.zero(PCN_NUMRIVDOPP); + dep.zero(PCN_NUMIVDOPP); + file.curr() = dep; + file.rewrite(); + } + } + if (flag == 'D') + { + for (int i = 0; i < _aggiorna.items(); i++) + { + TToken_string& data = (TToken_string&)_aggiorna[i]; + TString fname = data.get(0); + TString field = data.get(1); + file.put(fname,field); + } + file.rewrite(); + } + } + else + { + g = dep.get_int(PCN_GRUPPO); + c = dep.get_int(PCN_CONTO); + + if (flag_IV == 'T') + { + if (sez != '\0') + _tras_file.annulla_classi(g,c,FALSE); + + file.zero(); + file.curr() = dep; + file.write(); + } + else + { + g = dep.get_int(PCN_GRUPPO); + c = dep.get_int(PCN_CONTO); + + dep.zero(PCN_SEZIVD); + dep.zero(PCN_LETTIVD); + dep.zero(PCN_NUMRIVD); + dep.zero(PCN_NUMIVD); + dep.zero(PCN_SEZIVDOPP); + dep.zero(PCN_LETTIVDOPP); + dep.zero(PCN_NUMRIVDOPP); + dep.zero(PCN_NUMIVDOPP); + file.curr() = dep; + file.write(); + } + } + return 0; +} + +long TRic_tab::esiste_numreg(long numulreg) +{ + TLocalisamfile mov (LF_MOV); + + do + { + numulreg++; + + mov.setkey(1); + mov.zero(); + mov.put(MOV_NUMREG, numulreg); + } + while (mov.read() == NOERR); + + return numulreg; +} + +void TRic_tab::num_protocollo(TString& record) +{ + _protiva = atol(record.sub(36,41)); + _uprotiva = atol(record.sub(108,113)); + + if (_protiva == 0) + _uprotiva = 0; + + _nprotiva = _protiva; + _nuprotiva = _uprotiva; +} + +long TRic_tab::ulnumprot_reg(int anno,char codreg) +{ + /* + TTable reg ("REG"); + TString16 dep; + long num = 0; + + dep.format("%04d%s", anno,(const char*) codreg); + + reg.zero(); + reg.put("CODTAB", (const char*) dep); + if (reg.read() == NOERR) + num = reg.get_long("I5"); + */ + TString cr = format("%c", codreg); + TRegistro rg (cr, anno); + + return rg.protocol(); +} + +void TRic_tab::aggiorna_reg(int anno,char codreg,long ulnum) +{ + TTable reg ("REG"); + TString16 dep; + + if (isdigit(codreg)) + dep.format("%04d%03c", anno,codreg); + else + dep.format("%04d%-3c", anno,codreg); + + reg.zero(); + reg.put("CODTAB", (const char*) dep); + if (reg.read() == NOERR) + { + if (_nprotiva > (ulnum + 1) ) + reg.put("I5", _nprotiva); + + if (_nuprotiva > (ulnum + 1) ) + reg.put("I5", _nuprotiva); + + reg.rewrite(); + } +} + +void TRic_tab::controlli_prima_nota(TString& record) +{ + TTable tpd ("%TPD"); + bool corrisp; + TDate datareg; + int anno; + long ulnum; + TString16 tmp; + char codreg; + TString tipodoc; + + // char codreg = record.sub(35,36)[0]; + // TString tipodoc = record.sub(220,222); + + int tiporeg = atoi(record.sub(222,223)); + + TString80 tmpmov = "%"; + tmpmov << _tras_file.path(_dittaric); + tmpmov << "\\" << TEMP_MOV; + + TIsamtempfile tmp_mov (LF_MOV, tmpmov, FALSE); + + tmp_mov.zero(); + tmp_mov.put(MOV_NUMREG, _numreg); + if (tmp_mov.read() == NOERR) + { + codreg = tmp_mov.get_char(MOV_REG); + tipodoc = tmp_mov.get (MOV_TIPODOC); + } + + tmp = record.sub(15,21); + TString data = converti(tmp); + datareg = data; + anno = datareg.year(); + + bool numprot_att = _tras_file.numprot_att(); + bool numprot_pas = _tras_file.numprot_pas(); + + tpd.zero(); + tpd.put("CODTAB", (const char*) tipodoc); + if (tpd.read() == NOERR) + corrisp = tpd.get_bool("B0"); + + if (codreg != ' ' && !corrisp) + { + if ( ( (tiporeg == 1 && (numprot_att || _protiva == 0) ) ) + || ( (tiporeg == 2 && (numprot_pas || _protiva == 0) ) ) ) + { + ulnum = ulnumprot_reg(anno,codreg); + _nprotiva = ulnum + 1; + if (_uprotiva != 0) + _nuprotiva = (_nprotiva - ulnum) + _uprotiva; + } + } + + aggiorna_reg(anno,codreg,ulnum); +} + +void TRic_tab::datafine_esprec(const int aep, TDate& datacomp) +{ + TTable esc("ESC"); + for (int err = esc.first(); err == NOERR; err = esc.next()) + { + const anno = esc.get_int("CODTAB"); + if (anno == aep) + datacomp = esc.get("D1"); + } +} + +int TRic_tab::annoes_datacomp(const TString& record, TDate& datacomp) +{ + TString tmp; + int segn; + int ae = 0; + + tmp = record.sub(15,21); + TString data = converti(tmp); + _datareg = data; + segn = atoi(record.sub(21,22)); + + ae = date2esc(_datareg); + if (segn == 0) + datacomp = _datareg; + + if (segn == 1) + { + ae -= 1; + datafine_esprec(ae,datacomp); + } + return ae; +} + +long TRic_tab::ultima_registrazione() +{ + if (_nreg == 0) + { + TLocalisamfile mov (LF_MOV); + + mov.last(); + return (mov.get_long(MOV_NUMREG)); + } + else + return _nreg; +} + +char TRic_tab::ricerca_causale(const TString& causale) +{ + TLocalisamfile cau (LF_CAUSALI); + TString codcau; + char movap = ' '; + + long caus = atol(causale); + codcau.format("%03d", caus); + + cau.setkey(1); + cau.zero(); + cau.put("CODCAUS", codcau); + if (cau.read() == NOERR) + movap = cau.get_char("MOVAP"); + + return movap; +} + +void TRic_tab::prepara_saldi(const TString& fname,const TString& field) +{ + if (fname == "GRUPPO") + _g = atoi(field); + + if (fname == "CONTO") + _c = atoi(field); + + if (fname == "SOTTOCONTO") + _s = atol(field); + + if (fname == "SEZIONE") + _sez = field[0]; + + if (fname == "IMPORTO") + { + real imp = real::ita2eng(field); + _importo = imp; + TString i = _importo.string(); + } +} + +void TRic_tab::scrivi_record_mov(TString& record,long rec) +{ + TString sigla,key,str; + int numfield = 3; //Per i movimenti i primi due campi della mappa non sono significativi + //ai fini del trasferimento (flag record gia trasferito e nuovo ultimo numero di registrazione). + TMappa_trc& trc = _tras_file.mappa(); + TLocalisamfile* file = NULL; + TRectype* dep = NULL; + char gia_trasf,annullato; + int logicnum; + long numulreg; + TDate datacomp; + TString nreg; + int fnrmov = 14; + + sigla = record.mid(0,2); + annullato = record.mid(248,1)[0]; + + if (annullato == ' ') + { + key.format("%2s%d", (const char*)sigla,numfield); + + if (trc.is_key((const char *) key)) + { + int logicnum_p = 0; + + _numreg = atol(record.sub(2,8)); + + if (_numreg != _numreg_p) + { + if (_numreg_p != 0) + { + _sld.registra(); + _sld.reset(); + } + + long nuovareg = atol(record.sub(250,256)); + + if (nuovareg == 0) + { + numulreg = ultima_registrazione(); //reperisco il numero ultima registrazione + _nreg = esiste_numreg(numulreg); + num_protocollo(record); + controlli_prima_nota(record); + } + else + { + _nreg = nuovareg; + numfield = fnrmov; + key.format("%2s%d", (const char*)sigla,numfield); + } + } + else + { + numfield = fnrmov; + key.format("%2s%d", (const char*)sigla,numfield); + } + + _annoes = annoes_datacomp(record,datacomp); + _numreg_p = _numreg; + gia_trasf = record.sub(249,250)[0]; + + if (gia_trasf == ' ') + { + do + { + logicnum = trc.logicnum(key); + + if (logicnum != logicnum_p) + { + if (logicnum_p) + { + trasfer_data_mov(*file, *dep); + nreg.format("%6d",_nreg); + _tras_file.writeat(nreg,6,2,sigla); + aggiorna_temp_file(_numreg,_nreg); + delete file; + delete dep; + } + + file = new TLocalisamfile(logicnum); + dep = new TRectype (logicnum); + dep->zero(); + } + + logicnum_p = logicnum; + + if (logicnum == 24 && numfield == 26) + { + numfield++; + key.format("%2s%d", (const char*) sigla,numfield); + continue; + } + + int from = trc.from(key); + int to = trc.to(key); + TString fname = trc.field_name(key); + TString field = record.sub(from-1,to); + int flag = trc.flag(key); + + //Il nostro codice registro IVA e' lungo 3: se il loro registro (lungo 1) e' alfanumerico + //devo allinearlo a sinistra, mentre se e' numerico devo allinearlo a destra riempendolo con degli zero. + if (logicnum == LF_MOV) + { + if (fname == "REG") + { + char f = field[0]; + if (isdigit(f)) + field.format("%03c", f); + else + field.format("%-3c", f); + } + + //Il codice pagamento su AS400 e' un alfanumerico di due, mentre su PC e' un + //alfanumerico di 4 trattato con il flag Z. Dunque in ricezione se si tratta + //di un numero va riempito con degli 0. Se si tratta di un alfa va allineato a destra. + if (fname == "CODPAG") + { + TString f = field; + if (real::is_natural(f)) + field.format("%04s", (const char*) f); + else + field.format("%-4s", (const char*) f); + } + } + + if (logicnum == LF_RMOV) + prepara_saldi(fname,field); + + if (fname == "PROTIVA") + { + char var[6]; + sprintf(var,"%5d",_nprotiva); + field = var; + } + if (fname == "UPROTIVA") + { + char var[6]; + sprintf(var,"%5d",_nuprotiva); + field = var; + } + + + if (logicnum == LF_MOV && fname == "CODCAUS") + { + _sld.set_anno_es(_annoes); + _sld.set_movprovv(FALSE); + _sld.set_num_ulmov(_nreg); + _sld.set_data_ulmov(_datareg); + char movap = ricerca_causale(field); + if (movap == 'A') + _sld.set_movap(TRUE); + } + + if (logicnum == LF_MOV && (fname == "NUMREG" || flag == 1) ) + { + if (fname == "NUMREG") + { + dep->put(MOV_ANNOES, _annoes); + dep->put(MOV_NUMREG, _nreg); + dep->put(MOV_DATAREG, _datareg); + dep->put(MOV_DATACOMP, datacomp); + } + if (flag == 1) + { + TString f = converti(field); + dep->put(fname,f); + } + } + else + if (logicnum == LF_RMOV && (fname == "NUMREG" || fname == "NUMRIG") ) + { + if (fname == "NUMREG") + { + dep->put(RMV_ANNOES, _annoes); + dep->put(RMV_NUMREG, _nreg); + } + + if (fname == "NUMRIG") + { + dep->put(RMV_NUMRIG, field); + dep->put(RMV_DATAREG, _datareg); + } + } + else + dep->put(fname, (const char*)field); + + numfield++; + key.format("%2s%d", (const char*) sigla,numfield); + } + while (trc.is_key((const char*) key)); + + _prog->addstatus(1); + trasfer_data_mov(*file, *dep); + TString impor = _importo.string(); + _sld.aggiorna(_g,_c,_s,_importo,_sez); + + delete file; + delete dep; + + _tras_file.writeat("*",1,1,sigla); + nreg.format("%6d",_nreg); + _tras_file.writeat(nreg,6,2,sigla); + //aggiorna_temp_file(_numreg,_nreg); + leggi_record_controllo(); + TString chiave; + chiave.format("%2s%d", (const char*) sigla,rec); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,256); + } // if (gia_trasf == ' ') + } // if (trc.is_key((const char*) key)) + } // if (gia_trasf == ' ') +} + +int TRic_tab::trasfer_data_mov(TLocalisamfile& file, TRectype& dep) +{ + file.zero(); + file.curr() = dep; + + if (file.read() == NOERR) + { + file.zero(); + file.curr() = dep; + file.rewrite(); + } + else + { + file.zero(); + file.curr() = dep; + file.write(); + } + return 0; +} + +void TRic_tab::aggiorna_temp_file(long numreg, long nreg) +{ + TString80 tmpmov = "%"; + tmpmov << _tras_file.path(_dittaric); + tmpmov << "\\" << TEMP_MOV; + + TIsamtempfile tmp_mov (LF_MOV, tmpmov, FALSE); + + tmp_mov.zero(); + tmp_mov.put(MOV_NUMREG, numreg); + if (tmp_mov.read() == NOERR) + { + tmp_mov.put(MOV_CODCF, nreg); + tmp_mov.rewrite(); + } +} + +long TRic_tab::numrec_PN(long numreg) +{ + long num = 0; + + TString80 tmpmov = "%"; + tmpmov << _tras_file.path(_dittaric); + tmpmov << "\\" << TEMP_MOV; + + TIsamtempfile tmp_mov (LF_MOV, tmpmov, FALSE); + + tmp_mov.zero(); + tmp_mov.put(MOV_NUMREG, numreg); + if (tmp_mov.read() == NOERR) + num = tmp_mov.get_long(MOV_NUMGIO); + + return num; +} + +long TRic_tab::numreg_PN(long numreg) +{ + long num = 0; + + TString80 tmpmov = "%"; + tmpmov << _tras_file.path(_dittaric); + tmpmov << "\\" << TEMP_MOV; + + TIsamtempfile tmp_mov (LF_MOV, tmpmov, FALSE); + + tmp_mov.zero(); + tmp_mov.put(MOV_NUMREG, numreg); + if (tmp_mov.read() == NOERR) + num = tmp_mov.get_long(MOV_CODCF); + + return num; +} + +void TRic_tab::recupera_dati_testata(long numreg) +{ + TLocalisamfile mov (LF_MOV); + + mov.setkey(1); + mov.zero(); + mov.put(MOV_NUMREG, numreg); + if (mov.read() == NOERR) + { + _dreg = mov.get_date(MOV_DATAREG); + _ddoc = mov.get_date(MOV_DATADOC); + _ndoc = mov.get_long(MOV_NUMDOC); + _creg = mov.get (MOV_REG); + _ccau = mov.get (MOV_CODCAUS); + _tdoc = mov.get (MOV_TIPODOC); + _npiva = mov.get_long(MOV_PROTIVA); + _nupiva = mov.get_long(MOV_UPROTIVA); + _totdoc = mov.get_real(MOV_TOTDOC); + } +} + +bool TRic_tab::occasionali(const TString& record) +{ + TLocalisamfile occas (LF_OCCAS); + TString ragsoc; + long num; + + ragsoc = record.sub(61,86); + ragsoc.trim(); + + if (ragsoc == "") return FALSE; + + occas.setkey(1); + occas.zero(); + occas.put("CFPI", "RIC999999"); + if (occas.read() == NOERR) + num = 0; + else + if ( (occas.get("CFPI")).len() > 9) + { + occas.prev(); + if ( (occas.get("CFPI")).len() > 9) + num = 0; + else + { + TString cfpi = occas.get("CFPI"); + + if (cfpi.mid(0,3) == "RIC" && cfpi.len() == 9) + { + num = atol(cfpi.mid(3,6)); + num += 1; + } + else + num = 0; + } + } + else + { + TString cfpi = occas.get("CFPI"); + + if (cfpi.mid(0,3) == "RIC" && cfpi.len() == 9) + { + num = atol(cfpi.mid(3,6)); + num += 1; + } + else + num = 0; + } + + scrivi_occasionali(record,num); + + return TRUE; +} + +void TRic_tab::scrivi_occasionali(const TString& record, long num) +{ + TLocalisamfile occas (LF_OCCAS); + TString cfpi,ragsoc,ind,com,cap,app; + int err; + + app = "RIC"; + cfpi.format("%3s%6d", (const char*)app,num); + ragsoc = record.sub(61,86); + ind = record.sub(86,108); + com = record.sub(108,126); + cap = record.sub(126,131); + + ricerca_comune(com); + + occas.setkey(1); + occas.zero(); + occas.put("CFPI", cfpi); + occas.put("RAGSOC", ragsoc); + occas.put("INDIR", ind); + occas.put("CAP", cap); + if (_cod_com != "") + occas.put("COM", _cod_com); + + err = occas.write(); + + if (err == _isreinsert) + err = occas.rewrite(); +} + +void TRic_tab::ricerca_comune(const TString& com) +{ + TLocalisamfile comuni (LF_COMUNI); + + comuni.setkey(2); + comuni.zero(); + comuni.put(COM_DENCOM, com); + if (comuni.read() == NOERR) + _cod_com = comuni.get(COM_COM); + else + _cod_com = ""; +} + +int TRic_tab::cerca_annoes(long numreg) +{ + TLocalisamfile mov (LF_MOV); + int anno = 0; + + mov.setkey(1); + mov.zero(); + mov.put(MOV_NUMREG, numreg); + if (mov.read() == NOERR) + anno = mov.get_int(MOV_ANNOES); + + return anno; +} + +void TRic_tab::salva_dati_testata() +{ + TString str,app; + long numrec; + + numrec = numrec_PN(_numreg); + numrec += _tras_file.start('Z'); + + _tras_file.read_rec_trasfer(numrec); //Leggo il record della prima nota + + app = _dreg.string(); + str = riconverti(app); + _tras_file.put(str,"Z1",0,numrec); + app = _ddoc.string(); + str = riconverti(app); + _tras_file.put(str,"Z1",4,numrec); + str = format("%ld", _ndoc); + _tras_file.put(str,"Z1",5,numrec); + _tras_file.put(_creg,"Z1",6,numrec); + _tras_file.put(_ccau,"Z1",8,numrec); + _tras_file.put(_tdoc,"Z1",12,numrec); + str = format("%ld", _npiva); + _tras_file.put(str,"Z1",7,numrec); + str = format("%ld", _nupiva); + _tras_file.put(str,"Z1",10,numrec); + str = _totdoc.string(); + _tras_file.put(str,"Z1",13,numrec); + _tras_file.write(numrec); +} + +void TRic_tab::scrivi_record_moviva(TString& record,long rec) +{ + TString sigla,key,str; + int numfield = 3; //Per i movimenti i primi due campi della mappa non sono significativi + //ai fini del trasferimento (flag record gia trasferito e nuovo ultimo numero di registrazione). + TMappa_trc& trc = _tras_file.mappa(); + TLocalisamfile* file = NULL; + TRectype* dep = NULL; + char gia_trasf,annullato; + int logicnum; + TString nreg; + int fnrmiva = 11; + + sigla = record.mid(0,2); + annullato = record.mid(248,1)[0]; + + if (annullato == ' ') + { + key.format("%2s%d", (const char*)sigla,numfield); + + if (trc.is_key((const char *) key)) + { + int logicnum_p = 0; + + _numreg = atol(record.sub(2,8)); + + if (_numreg != _numreg_piva) + { + long nuovareg = atol(record.sub(250,256)); + + if (nuovareg == 0) + _nreg = numreg_PN(_numreg); + else + { + _nreg = nuovareg; + //recupera_dati_testata(_nreg); + numfield = fnrmiva; + key.format("%2s%d", (const char*)sigla,numfield); + } + recupera_dati_testata(_nreg); + } + else + { + numfield = fnrmiva; + key.format("%2s%d", (const char*)sigla,numfield); + } + + _numreg_piva = _numreg; + gia_trasf = record.sub(249,250)[0]; + + if (gia_trasf == ' ' || _ccau != "000") + { + + occasionali(record); + + do + { + logicnum = trc.logicnum(key); + + if (logicnum != logicnum_p) + { + if (logicnum_p) + { + trasfer_data_moviva(*file, *dep, logicnum_p); + nreg.format("%6d",_nreg); + _tras_file.writeat(nreg,6,2,sigla); + salva_dati_testata(); + delete file; + delete dep; + } + + file = new TLocalisamfile(logicnum); + dep = new TRectype (logicnum); + dep->zero(); + } + + logicnum_p = logicnum; + + int from = trc.from(key); + int to = trc.to(key); + TString fname = trc.field_name(key); + TString field = record.sub(from-1,to); + int flag = trc.flag(key); + + if (logicnum == LF_MOV && fname == "CAMBIOI" && flag == 5) + { + int l = field.len(); + int p = l - flag; + field.insert(".",p); + } + + if (logicnum == LF_MOV && fname == "CORRVALUTA" && flag == 5) + { + int l = field.len(); + int p = l -flag; + field.insert(".",p); + } + + if (logicnum == LF_MOV && ( fname == "NUMREG" || flag == 1 ) ) + { + if (fname == "NUMREG") + dep->put("NUMREG", _nreg); + + if (flag == 1) + { + TString f = converti(field); + dep->put(fname,f); + } + } + else + if (logicnum == LF_RMOVIVA && fname == "NUMREG") + { + int annoes = cerca_annoes(_nreg); + dep->put("ANNOES", annoes); + dep->put("NUMREG", _nreg); + } + else + dep->put(fname, (const char*)field); + + numfield++; + key.format("%2s%d", (const char*) sigla,numfield); + } + while (trc.is_key((const char*) key)); + + _prog->addstatus(1); + trasfer_data_moviva(*file, *dep, logicnum_p); + TString impor = _importo.string(); + + delete file; + delete dep; + + _tras_file.read_rec_trasfer(rec); //Per essere sicuro di essere posizionato sul record giusto dell'iva sul trasfer + _tras_file.writeat("*",1,1,sigla); + nreg.format("%6d",_nreg); + _tras_file.writeat(nreg,6,2,sigla); + leggi_record_controllo(); + TString chiave; + chiave.format("%2s%d", (const char*) sigla,rec); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,256); + } // if (gia_trasf == ' ') + } // if (trc.is_key((const char*) key)) + } // if (gia_trasf == ' ') +} + +int TRic_tab::trasfer_data_moviva(TLocalisamfile& file, TRectype& dep, int ln) +{ + file.zero(); + file.curr() = dep; + + if (file.read() == NOERR) + { + if (ln == LF_MOV) + { + TDate data74ter (dep.get_date(MOV_DATA74TER)); + TString codval (dep.get (MOV_CODVAL)); + long codcf = dep.get_long(MOV_CODCF); + real totdoc (dep.get_real(MOV_TOTDOC)); + real cambioi (dep.get_real(MOV_CAMBIOI)); + real corrlire (dep.get_real(MOV_CORRLIRE)); + real corrvaluta(dep.get_real(MOV_CORRVALUTA)); + + file.put(MOV_DATA74TER, data74ter); + file.put(MOV_CODVAL, codval); + file.put(MOV_CODCF, codcf); + file.put(MOV_TOTDOC, totdoc); + file.put(MOV_CAMBIOI, cambioi); + file.put(MOV_CORRLIRE, corrlire); + file.put(MOV_CORRVALUTA,corrvaluta); + + file.rewrite(); + } + else + { + file.zero(); + file.curr() = dep; + file.rewrite(); + } + } + else + { + file.zero(); + file.curr() = dep; + file.write(); + } + + return 0; +} + +bool TRic_tab::leggi_trasfer() +{ + _nultras = 0; + + _trasf = _tras_file.path(_dittaric); + _trasf << "\\trasfer"; + + _tras_file.open(_trasf); + + if (_tras_file.exist()) + { + if (_tras_file.read_control_rec()) + { + _nultras = _tras_file.nultras(); + _dataultras = _tras_file.dataultras(); + _sigle_file = _tras_file.sigle_file(); + _nrec_file = _tras_file.nrec_file(); + // La fill_index e' richiamata dentro a read_control_rec + // _tras_file.fill_index(_sigle_file,_nrec_file); + _uselab = _tras_file.ult_file(); + _key = _tras_file.key(); + _record = _tras_file.record(); + } +else + return error_box("Rilevati gravi errori negli archivi:procedura interrotta"); + } +else + return error_box("Al momento non presenti trasferimenti attivi sulla ditta selezionata"); + + return TRUE; +} + +bool TRic_tab::video() +{ + TConfig conf(CONFIG_DITTA); + + _std = conf.get("FlStTra"); + + if (!leggi_trasfer()) + return FALSE; + + TMask msk ("cg2600a"); + KEY tasto; + + ditta_ricevente(); + + msk.set(F_CODDITTA, _dittaric); + msk.set(F_RAGSOC, _ragsoc_dittar); + msk.set(F_NULTRAS, _nultras); + TString data1 = _dataultras.string(); + msk.set(F_DATAULTRAS, data1); + msk.set(F_STD, _std); + msk.set(F_USELAB, _uselab); + msk.set(F_STATO, _key); + + tasto = msk.run(); + + if (tasto != K_ENTER) + return FALSE; + + if (!prefix().exist(_dittaric)) + return error_box("Rilevati gravi errori negli archivi: procedura interrotta"); + + if (!controlli()) + return FALSE; + + return TRUE; +} + +void TRic_tab::setta_parametri_record(const TString& sigla,const TString& flag) +{ + TConfig conf (CONFIG_DITTA); + + conf.set("FlStTra", flag); + + leggi_record_controllo(); + _record.overwrite(sigla,240); + + const int size = 256; + + _tras_file.write_control_rec(_record, size); +} + +bool TRic_tab::controllo_pre_ricezione() +{ + TString flag; + + TString sigla = _sigle_file.mid(0,1); + + if (sigla == " ") + { + flag = "*"; + setta_parametri_record(sigla,flag); + fremove(_trasf); + return FALSE; + } + + if (sigla == "Z") + { + flag = "C"; + setta_parametri_record(sigla,flag); + return error_box("Aggiornamento tabelle terminato: proseguire con controllo movimenti"); + } + + if (sigla != "Z") + { + flag = "T"; + setta_parametri_record(sigla,flag); + return TRUE; + } + + return TRUE; +} + +void TRic_tab::ditta_ricevente() +{ + TLocalisamfile nditte (LF_NDITTE); + + nditte.setkey(1); + nditte.zero(); + nditte.put(NDT_CODDITTA, _dittaric); + if (nditte.read() == NOERR) + _ragsoc_dittar = nditte.get(NDT_RAGSOC); +} + +bool TRic_tab::controlli() +{ + if (_scelta == 'T') + { + if (_std == "C") + return error_box("Aggiornamento tabelle gia' effettuato: richiamare Controllo movimenti"); + + if (_std == "M") + return error_box("Aggiornamento tabelle gia' effettuato: richiamare Trasferimento movimenti"); + + if (_std != "" && _std != "T") + return error_box("Rilevati gravi errori negli archivi: procedura interrotta"); + + if ( (_std == "" || _std == "T") && (_uselab == "Z" || _uselab == "U") ) + return error_box("Rilevati gravi errori negli archivi: procedura interrotta"); + } + else + if (_scelta == 'M') + { + if (_std == "" || _std == "T") + return error_box("Aggiornamento tabelle NON EFFETTUATO: richiamare il programma relativo"); + + if (_std == "C") + return error_box("Controllo movimenti non effettuato o rilevati errori gravi"); + + if (_std == "M" && (_uselab != "Z" && _uselab != "U" && _uselab != "B") ) + return error_box("Rilevati GRAVI ERRORI negli archivi: procedura interrotta"); + + if (_std != "" && _std != "M") + error_box("Rilevati GRAVI ERRORI negli archivi: procedura interrotta"); + } + + if (_std == "*") + { + warning_box("Trasferimento interamente completato: proseguire per cancellare il file"); + fremove(_trasf); + return FALSE; + } + + return TRUE; +} + +bool TRic_tab::menu(MENU_TAG m) +{ + if (m == BAR_ITEM(1)) + return main_loop(); + return FALSE; +} + +int cg2600 (int argc, char* argv[]) +{ + TRic_tab main_app(*argv[2]); + main_app.run(argc, argv,main_app._titolo); + return TRUE; +}