diff --git a/cg/cg0100.cpp b/cg/cg0100.cpp index 15b5f9a89..093465ba1 100755 --- a/cg/cg0100.cpp +++ b/cg/cg0100.cpp @@ -162,18 +162,47 @@ bool CG0100_application::protected_record(TRectype &rec) _saldi->put(PCN_GRUPPO, gruppo); _saldi->put(PCN_CONTO, conto); _saldi->put(PCN_SOTTOCONTO, sottoc); - _saldi->read(_isgteq); + _saldi->read(); bool ok = FALSE; if (_saldi->good()) ok = _saldi->get_real(SLD_SALDO) != ZERO || _saldi->get_real(SLD_PDARE) != ZERO || _saldi->get_real(SLD_PAVERE) != ZERO || +<<<<<<< cg0100.cpp + _saldi->get_real(SLD_SALDOFIN) != ZERO || +======= +>>>>>>> 1.22 _saldi->get_real(SLD_PDAREPRO) != ZERO || _saldi->get_real(SLD_PAVEREPRO) != ZERO; - return ok && gruppo ==_saldi->get_int(PCN_GRUPPO) && + ok &= (gruppo ==_saldi->get_int(PCN_GRUPPO) && conto ==_saldi->get_int(PCN_CONTO) && - sottoc ==_saldi->get_long(PCN_SOTTOCONTO); + sottoc ==_saldi->get_long(PCN_SOTTOCONTO)); + + if (!ok) + { + // look for scaricato + _saldi->zero(); + _saldi->put(PCN_GRUPPO, gruppo); + _saldi->put(PCN_CONTO, conto); + _saldi->put(PCN_SOTTOCONTO, sottoc); + _saldi->put(SLD_FLSCA, "X"); + _saldi->read(_isgteq); + + if (_saldi->good()) + { + ok = _saldi->get_real(SLD_SALDO) != ZERO || + _saldi->get_real(SLD_PDARE) != ZERO || + _saldi->get_real(SLD_PAVERE) != ZERO || + _saldi->get_real(SLD_SALDOFIN) != ZERO || + _saldi->get_real(SLD_PDAREPRO) != ZERO || + _saldi->get_real(SLD_PAVEREPRO) != ZERO; + ok &= (gruppo ==_saldi->get_int(PCN_GRUPPO) && + conto ==_saldi->get_int(PCN_CONTO) && + sottoc ==_saldi->get_long(PCN_SOTTOCONTO)); + } + } + if (ok) return TRUE; } get_relation()->save_status(); pconti.zero() ; @@ -216,7 +245,6 @@ HIDDEN bool tmcf_handler(TMask_field& f, KEY key) void CG0100_application::init_insert_mode(TMask& m) - { const int gruppo = atoi(m.get(FLD_CM1_GRUPPO)); const int conto = atoi(m.get(FLD_CM1_CONTO)); diff --git a/cg/cg1500.cpp b/cg/cg1500.cpp index ac7bdb342..43941e1be 100755 --- a/cg/cg1500.cpp +++ b/cg/cg1500.cpp @@ -107,6 +107,7 @@ class CG1500_application : public TPrintapp public: + TDate _inizioEs, _fineEs; bool menu (MENU_TAG m) { return TPrintapp::menu(m) ; } virtual bool user_create() ; @@ -162,7 +163,7 @@ public: CG1500_application() {} }; -HIDDEN inline CG1500_application & app() { return (CG1500_application&) main_app(); } +HIDDEN inline CG1500_application& app() { return (CG1500_application&)main_app(); } TDate InizioEsercizio(int anno) { @@ -1503,7 +1504,7 @@ if (movimentato || _stampav != 1) mov_conto_avere += _mov_periodo_avere; prg_conto_dare += _prg_prec_dare; prg_conto_avere += _prg_prec_avere; - saldo_conto += saldo_finale; // somma algebrica!!! + saldo_conto += saldo_finale; // somma pitagorica //scrivo il record relat. al sottoconto se non e' richiesto saldi di mastro if (_verifica != 2) diff --git a/cg/cg2100.cpp b/cg/cg2100.cpp index 5673f73f4..600dfbbff 100755 --- a/cg/cg2100.cpp +++ b/cg/cg2100.cpp @@ -1,4 +1,4 @@ -#include + #include #include #include #include @@ -634,8 +634,10 @@ int TPrimanota_application::read(TMask& m) } _saldi.reset(); // Azzera saldi - _saldi.set_movprovv(_rel->lfile().get_char("PROVVIS") > ' '); - _saldi.set_movap(causale().apertura()); + _saldi.set_movprovv(_rel->lfile().get_char("PROVVIS") > ' '); + tiposal tsal = causale().apertura() ? apertura : + (causale().chiusura() ? chiusura : normale); + _saldi.set_tipo_saldo(tsal); _saldi.set_anno_es(m.get_int(F_ANNOES)); _saldi.set_num_ulmov(numreg); _saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); @@ -732,7 +734,9 @@ void TPrimanota_application::mask2rel(const TMask& m) const int annoes = m.get_int(F_ANNOES); _saldi.set_movprovv(m.get(F_PROVVISORIO)[0] > ' '); - _saldi.set_movap(causale().apertura()); + tiposal tsal = causale().apertura() ? apertura : + (causale().chiusura() ? chiusura : normale); + _saldi.set_tipo_saldo(tsal); _saldi.set_anno_es(annoes); _saldi.set_num_ulmov(numreg); _saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); @@ -1183,7 +1187,7 @@ void TPrimanota_application::genera_incasso(const char* causimm) _saldi.reset(); // Inizializza saldi _saldi.set_movprovv(FALSE); - _saldi.set_movap(FALSE); + _saldi.set_tipo_saldo(normale); _saldi.set_anno_es(m.get_int(F_ANNOES)); _saldi.set_num_ulmov(_lastreg); _saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); diff --git a/cg/cg2103.cpp b/cg/cg2103.cpp index 783c7cb01..de747b1bd 100755 --- a/cg/cg2103.cpp +++ b/cg/cg2103.cpp @@ -397,6 +397,9 @@ bool TCausale::num_doc() const bool TCausale::apertura() const { return _rec.get_char(CAU_MOVAP) == 'A'; } +bool TCausale::chiusura() const +{ return _rec.get_char(CAU_MOVAP) == 'C'; } + bool TCausale::sezionale() const { return _rec.get_bool(CAU_MOVSEZ); } diff --git a/cg/cg2103.h b/cg/cg2103.h index 3fb149b91..1b8d0ac7a 100755 --- a/cg/cg2103.h +++ b/cg/cg2103.h @@ -123,6 +123,7 @@ public: bool data_doc() const; bool num_doc() const; bool apertura() const; + bool chiusura() const; bool sezionale() const; bool valuta() const; bool intra() const; diff --git a/cg/cg2200.cpp b/cg/cg2200.cpp index c2bfed35a..ef22d19fc 100755 --- a/cg/cg2200.cpp +++ b/cg/cg2200.cpp @@ -97,15 +97,18 @@ void TProvvisori_app::inizia_saldi(const TRectype& r) _saldi.reset(); - bool apertura = FALSE; + tiposal tsal = normale; const TString& c = r.get(MOV_CODCAUS); if (c.not_empty()) { _cau->put(CAU_CODCAUS, c); - if (_cau->read() == NOERR) - apertura = _cau->get_bool(CAU_MOVAP); + if (_cau->read() == NOERR) + { + if (_cau->get_char(CAU_MOVAP) == 'A') tsal = apertura; + else if (_cau->get_char(CAU_MOVAP) == 'C') tsal = chiusura; + } } - _saldi.set_movap(apertura); + _saldi.set_tipo_saldo(tsal); _saldi.set_anno_es(r.get_int(MOV_ANNOES)); _saldi.set_num_ulmov(r.get_long(MOV_NUMREG)); diff --git a/cg/cg3200.cpp b/cg/cg3200.cpp index 83a315328..75493a239 100755 --- a/cg/cg3200.cpp +++ b/cg/cg3200.cpp @@ -2900,6 +2900,11 @@ void TMastrini_application::calcola_progressivi_al() void TMastrini_application::calcola_progressivi() { + /* fv 20/3/96: aggiustato per nuova struttura saldi - modificata ricerca + * record scaricati e assegnazione dare/avere relativo - Controllare che + * non occorra considerare il saldo di chiusura (SALDOFIN) aggiunto al + * record */ + TLocalisamfile saldi(LF_SALDI, FALSE); real pdaresca,paveresca,pdarescap,paverescap; real progdare_attuale,progavere_attuale,progdare_prec,progavere_prec; @@ -2942,23 +2947,49 @@ void TMastrini_application::calcola_progressivi() if (annoes_saldi == _anno_corrente) { - pdaresca = saldi.get_real(SLD_PDARESCA); - paveresca = saldi.get_real(SLD_PAVERESCA); + pdaresca = ZERO; + paveresca = ZERO; progdare_attuale = saldi.get_real(SLD_PDARE); progavere_attuale = saldi.get_real(SLD_PAVERE); saldo = saldi.get_real(SLD_SALDO); salini = saldi.get(SLD_FLAGSALINI)[0]; _ultima_data_reg = saldi.get_date(SLD_DATAULMOV); + + // cerca eventuale record scaricati + saldi.next(); + if (!saldi.eof() && saldi.get_bool(SLD_FLSCA) && + annoes_saldi == saldi.curr().get_int(SLD_ANNOES) && + saldi.get_int(SLD_GRUPPO) == _gruppo && + saldi.get_int(SLD_CONTO) == _conto && + saldi.get_long(SLD_SOTTOCONTO) == _sottoc) + { + pdaresca = saldi.get_real(SLD_PDARE); + paveresca = saldi.get_real(SLD_PAVERE); + } + saldi.prev(); } //Calcola i progressivi dell'esercizio precedente if (annoes_saldi == _anno_precedente) { - pdarescap = saldi.get_real(SLD_PDARESCA); + pdarescap = ZERO; pdarep = saldi.get_real(SLD_PDARE); - paverescap = saldi.get_real(SLD_PAVERESCA); + paverescap = ZERO; paverep = saldi.get_real(SLD_PAVERE); + + // cerca eventuale record scaricati + saldi.next(); + if (!saldi.eof() && saldi.get_bool(SLD_FLSCA) && + annoes_saldi == saldi.curr().get_int(SLD_ANNOES) && + saldi.get_int(SLD_GRUPPO) == _gruppo && + saldi.get_int(SLD_CONTO) == _conto && + saldi.get_long(SLD_SOTTOCONTO) == _sottoc) + { + pdarescap = saldi.get_real(SLD_PDARE); + paverescap = saldi.get_real(SLD_PAVERE); + } + saldi.prev(); } // Se il saldo dell'esercizio attuale e' diverso da 0 allora significa che diff --git a/cg/cg4100.cpp b/cg/cg4100.cpp index afe7ab5a1..b2760e265 100755 --- a/cg/cg4100.cpp +++ b/cg/cg4100.cpp @@ -356,7 +356,8 @@ bool CG4100_App::sort_sal() sal.set_anno_es(year); sal.clear_saldi(year); long numreg = 0L; - bool apertura = FALSE, provvis = FALSE; + tiposal tsal = normale; + bool provvis = FALSE; TDate datareg; while (!rmov.eof()) @@ -364,10 +365,12 @@ bool CG4100_App::sort_sal() if (_year == rmov.get_int(RMV_ANNOES)) { numreg = rmov.get_long(RMV_NUMREG); - + gruppo = rmov.get_int(RMV_GRUPPO); conto = rmov.get_int(RMV_CONTO); - sottoconto = rmov.get_long(RMV_SOTTOCONTO); + sottoconto = rmov.get_long(RMV_SOTTOCONTO); + bool scaricato = FALSE; + if (numreg != oldnumreg) { if (oldnumreg !=0) @@ -381,6 +384,8 @@ bool CG4100_App::sort_sal() mov.read(); CHECK(mov.good(),"Archivi movimenti e righe inconsistenti"); + scaricato = mov.get_bool(MOV_SCARCON); + causali.zero(); const char* codcaus = mov.get(MOV_CODCAUS); // cerca causale @@ -389,15 +394,15 @@ bool CG4100_App::sort_sal() causali.put(CAU_CODCAUS, codcaus); causali.read(); CHECK(causali.good(),"Archivi causali e movimenti inconsistenti"); - apertura = causali.get(CAU_MOVAP) == "A"; + if (causali.get(CAU_MOVAP) == "A") tsal = apertura; + else if (causali.get(CAU_MOVAP) == "C") tsal = chiusura; } - else apertura = FALSE; provvis = mov.get(MOV_PROVVIS).not_empty(); datareg = mov.get_date(MOV_DATAREG); sal.reset(); sal.set_anno_es(_year); - sal.set_movap(apertura); + sal.set_tipo_saldo(tsal); sal.set_movprovv(provvis); sal.set_data_ulmov(datareg); sal.set_num_ulmov(oldnumreg); @@ -405,7 +410,7 @@ bool CG4100_App::sort_sal() const char sezione = rmov.get(RMV_SEZIONE)[0]; real importo(rmov.get(RMV_IMPORTO)); - sal.aggiorna(gruppo, conto, sottoconto, importo, sezione); + sal.aggiorna(gruppo, conto, sottoconto, importo, sezione, TRUE, scaricato); } rmov.next(); prnd.addstatus(1); diff --git a/cg/cg4100b.uml b/cg/cg4100b.uml index b7c15da09..b6242db2d 100755 --- a/cg/cg4100b.uml +++ b/cg/cg4100b.uml @@ -27,6 +27,7 @@ BEGIN DISPLAY "Data fine esercizio " D1 OUTPUT FLD_CG41_YEAR CODTAB CHECKTYPE REQUIRED + FLAGS "Z" HELP "Codice esercizio per il quale si desidera il ricalcolo dei saldi" WARNING "Il codice esercizio e' obbligatorio" END diff --git a/cg/cg4600.cpp b/cg/cg4600.cpp index d7dd42b39..6821c035b 100755 --- a/cg/cg4600.cpp +++ b/cg/cg4600.cpp @@ -614,7 +614,7 @@ bool CG4600_application::set() _sld->set_anno_es(_annoesch); _sld->set_movprovv(FALSE); - _sld->set_movap(FALSE); + _sld->set_tipo_saldo(normale); // _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. costi (); @@ -654,7 +654,7 @@ bool CG4600_application::set() _totale_saldo = ZERO; _sld->set_anno_es(_annoesap); - _sld->set_movap(TRUE); + _sld->set_tipo_saldo(apertura); _sld->set_movimentato(TRUE); // _pn->destroy_rows(_numreg); //Azzero l'oggetto pn. *_cur = 0l; diff --git a/cg/cg5100a.uml b/cg/cg5100a.uml index ac68d35ba..71d1b81f5 100755 --- a/cg/cg5100a.uml +++ b/cg/cg5100a.uml @@ -20,6 +20,11 @@ ENDPAGE PAGE "Impostazione parametri ditta" -1 -1 77 8 +GROUPBOX DLG_NULL 76 4 +BEGIN + PROMPT 2 1 "Archivi in comune" +END + NUMBER FLD_ANLIIV 4 BEGIN PROMPT 2 0 "@bANNO LIQUIDAZIONE IVA " @@ -44,11 +49,6 @@ BEGIN FIELD PcTcCm END -GROUPBOX DLG_NULL 76 4 -BEGIN - PROMPT 2 1 "Archivi in comune" -END - GROUPBOX DLG_NULL 76 8 BEGIN @@ -180,7 +180,7 @@ END ENDPAGE -PAGE "Impostazione parametri ditta" -1 -1 77 8 +PAGE "Pag. 2" -1 -1 77 8 GROUPBOX DLG_NULL 78 12 BEGIN @@ -687,7 +687,7 @@ END ENDPAGE -PAGE "Impostazione parametri ditta" -1 -1 77 8 +PAGE "Pag. 3" -1 -1 77 8 GROUPBOX DLG_NULL 78 10 BEGIN @@ -695,7 +695,7 @@ BEGIN END -RADIOBUTTON LST_RRFRAM 16 +RADIOBUTTON LST_RRFRAM 20 BEGIN PROMPT 3 2 "" HELP "Frequenza del calcolo dei ratei e risconti" diff --git a/cg/cg5200.h b/cg/cg5200.h index 0f6b2d215..7a19a2434 100755 --- a/cg/cg5200.h +++ b/cg/cg5200.h @@ -9,3 +9,4 @@ #define F_DESCR_CLIENTE 109 #define F_DESCR_FORN 110 #define F_SHEET_SALDI 111 +#define F_SCARICATO 112 \ No newline at end of file diff --git a/cg/cg5200a.uml b/cg/cg5200a.uml index f49ed39f2..482c35de1 100755 --- a/cg/cg5200a.uml +++ b/cg/cg5200a.uml @@ -24,6 +24,11 @@ BEGIN VALIDATE CHECK_FIELD F_ANNO FLAGS "Z" END + +BOOLEAN F_SCARICATO +BEGIN + PROMPT 40 1 "Solo saldi dei movimenti scaricati" +END GROUPBOX DLG_NULL 73 4 BEGIN @@ -214,8 +219,10 @@ BEGIN ITEM " Avere@15" ITEM " Saldo@15" ITEM "" - ITEM "Progr.Mov.Elim.: Dare@15" - ITEM " Avere@15" +// ITEM "Progr.Mov.Elim.: Dare@15" +// ITEM " Avere@15" + ITEM "Saldo di chiusura@15" + ITEM "" ITEM "Saldo complessivo" ITEM "" ITEM "Ult.Op.: Data" @@ -224,6 +231,8 @@ BEGIN ITEM " Avere@15" ITEM " Saldo@15" ITEM "" + ITEM "Progr.Mov.Elim.: Dare@15" + ITEM " Avere@15" END ENDPAGE @@ -285,10 +294,11 @@ BEGIN HELP "Sezione del saldo attuale del conto" END +/* ===================================================================== NUMBER 108 15 BEGIN PROMPT 1 6 "Progr.Mov.Eliminati: Dare " - HELP "Progressivi dare attuali dei moviementi eliminati" + HELP "Progressivi dare attuali dei movimenti eliminati" FLAGS "R" PICTURE "." END @@ -296,11 +306,27 @@ END NUMBER 109 15 BEGIN PROMPT 45 6 "Avere " - HELP "Progressivi avere attuali dei moviementi eliminati" + HELP "Progressivi avere attuali dei movimenti eliminati" FLAGS "R" PICTURE "." END + =======================================================================*/ +NUMBER 108 15 +BEGIN + PROMPT 1 6 " Saldo di chiusura " + HELP "Saldo di chiusura" + FLAGS "R" + PICTURE "." +END + +STRING 109 1 +BEGIN + PROMPT 44 6 "" + HELP "Sezione del saldo di chiusura" + FLAGS "R" +END + NUMBER 110 15 BEGIN PROMPT 1 7 "Saldo complessivo " @@ -333,7 +359,7 @@ END NUMBER 114 15 BEGIN PROMPT 1 10 "Progr.Mov.Provvisori: Dare " - HELP "Progressivi dare attuali dei moviementi provvisori" + HELP "Progressivi dare attuali dei movimenti provvisori" FLAGS "R" PICTURE "." END @@ -341,7 +367,7 @@ END NUMBER 115 15 BEGIN PROMPT 45 10 "Avere " - HELP "Progressivi avere attuali dei moviementi provvisori del conto" + HELP "Progressivi avere attuali dei movimenti provvisori del conto" FLAGS "R" PICTURE "." END @@ -361,6 +387,23 @@ BEGIN FLAGS "R" END +NUMBER 118 15 +BEGIN + PROMPT 1 6 "Progr.Mov.Eliminati: Dare " + HELP "Progressivi dare attuali dei movimenti eliminati" + FLAGS "R" + PICTURE "." +END + +NUMBER 119 15 +BEGIN + PROMPT 45 6 "Avere " + HELP "Progressivi avere attuali dei movimenti eliminati" + FLAGS "R" + PICTURE "." +END + + BUTTON DLG_CANCEL 9 2 BEGIN PROMPT -11 -1 "" diff --git a/cg/cg5300.cpp b/cg/cg5300.cpp index 140a34e5f..b770ea443 100755 --- a/cg/cg5300.cpp +++ b/cg/cg5300.cpp @@ -213,7 +213,7 @@ int TParaliq_app::rewrite(const TMask& m) TToken_string& tt = sf.row(i); const TString16 att = tt.get(0); const TString16 tips(tt.get(1)); - const TString16 codtab(format("%05ld%4d%s1", firm, year, (const char*)att)); + const TString16 codtab(format("%05ld%4d%s", firm, year, (const char*)att)); _pla->zero(); _pla->put("CODTAB", codtab); @@ -264,7 +264,7 @@ int TParaliq_app::rewrite(const TMask& m) lia.put("CODTAB", format("%05ld%d", firm, year)); was = lia.read() == NOERR; if (!was) lia.zero(); - m.autosave(_rel); + m.autosave(*_rel); if (err == NOERR) err = (was ? lia.rewrite() : lia.write()); if (err == NOERR && year == _yearliq) { @@ -290,7 +290,7 @@ int TParaliq_app::read(TMask& m) // legge da LIA (si istanziano i campi credito prec. e Freq. Vers // prende le attivita' una per una da _atts e // crea le righe sheet - m.autoload(get_relation()); + m.autoload(*get_relation()); const long firm = m.get_long(F_CODDITTA); const int year = m.get_int(F_YEAR); diff --git a/cg/cg5300a.uml b/cg/cg5300a.uml index a648bcee7..800d379ab 100755 --- a/cg/cg5300a.uml +++ b/cg/cg5300a.uml @@ -94,7 +94,7 @@ SPREADSHEET F_SHEET_PLA 78 6 BEGIN PROMPT 1 10 "Parametri attivita'" ITEM "Attivita'@5F" - ITEM "Tipo@1" + ITEM "Tipo@9" ITEM "% Pro-rata@6" ITEM "Plafond art.8@15" ITEM "Plafond art.8b@15" @@ -131,8 +131,8 @@ BEGIN HELP "Tipo di attivita' della ditta" FLAGS "U" ITEM " |Altre" - ITEM "E|Mista evidenziata" - ITEM "S|Servizio o mista generica" + ITEM "E|Mista evid." + ITEM "S|Serv. o mista gen." END NUMBER F_PRORATA 6 2 diff --git a/cg/cg5400a.uml b/cg/cg5400a.uml index 316545ea1..9bb0ccfdb 100755 --- a/cg/cg5400a.uml +++ b/cg/cg5400a.uml @@ -91,7 +91,7 @@ BEGIN WARNING "Registro assente" END -LIST F_TIPO +LIST F_TIPO 15 BEGIN FLAGS "HG" ITEM "1|Vendite" MESSAGE HIDE,F_ESER|SHOW,F_YEAR|HIDE,F_DAY diff --git a/cg/cg5500.cpp b/cg/cg5500.cpp index aaa208d03..05c0016b1 100755 --- a/cg/cg5500.cpp +++ b/cg/cg5500.cpp @@ -141,7 +141,7 @@ void Visliq_app::build_ditte_sheet() const char vers = d->get_char(2); bool selectable = vers == '?'; const long pos = _ditte->add(d); - if (selectable) _ditte->disable(pos); + if (selectable) _ditte->disable_row(pos); } } @@ -281,7 +281,7 @@ bool Visliq_app::set_ditta(TMask_field& f, KEY k) TToken_string& row = sh->row(i); if (ditta == row.get(0)) { - if (sh->enabled(i)) + if (sh->row_enabled(i)) { f.mask().field(F_CODDITTA).set(row.get(0)); f.mask().field(F_RAGSOC).set(row.get(1)); @@ -321,7 +321,7 @@ bool Visliq_app::set_ragsoc(TMask_field& f, KEY k) TString ts(row.get(1)); if (ts.find(ditta) != -1) { - if (sh->enabled(i)) + if (sh->row_enabled(i)) { f.mask().field(F_CODDITTA).set(row.get(0)); f.mask().field(F_RAGSOC).set(row.get(1)); @@ -601,8 +601,9 @@ bool Visliq_app::vis_one(int m) msk.field(F_YEAR).set(nomem); msk.field(F_RIMBORSO).set(rimborso.string()); if (rettifica.sign() < 0) - { - msk.field(F_RETTIFICA).set(((real) abs(rettifica)).string()); + { + real rabs = abs(rettifica); + msk.field(F_RETTIFICA).set(rabs.string()); msk.field(F_DEBCRE).set("C"); } else if (rettifica.sign() > 0) @@ -918,8 +919,9 @@ void Visliq_app::recalc_liq_data(TViswin* vsw, real& rimb, real& rett, real& ver vsw->replace(lrettc, " ", 58); } else if (rett.sign() < 0) - { - vsw->replace(lrettc, ((real) abs(rett)).string("###.###.###.###"), 58); + { + real rabs = abs(rett); + vsw->replace(lrettc, rabs.string("###.###.###.###"), 58); vsw->replace(lrettd, " ", 75); } else @@ -929,9 +931,10 @@ void Visliq_app::recalc_liq_data(TViswin* vsw, real& rimb, real& rett, real& ver } if (risul.sign() < 0) - { + { + real rabs = abs(risul); ln.overwrite("CREDITO ATTUALE", 23); - ln.overwrite(((real) abs(risul)).string("###.###.###.###"), 58); + ln.overwrite(rabs.string("###.###.###.###"), 58); } else if (risul.sign() > 0) { @@ -1029,11 +1032,14 @@ void Visliq_app::recalc_next_liq(int start_month, TSheet_field* sl, TSheet_field int sr0 = (_lim->get_real("R0")).sign(); int sr5 = (_lim->get_real("R5")).sign(); - - t.add(((real) abs(_lim->get_real("R0"))).string(),1); + + real r0abs = abs(_lim->get_real("R0")); + real r5abs = abs(_lim->get_real("R0")); + t.add(r0abs.string(),1); t.add(sr0 == 0 ? "" : (sr0 > 0 ? "D" : "C"), 2); t.add((_lim->get_real("R1")).string(),3); - t.add(((real) abs(_lim->get_real("R5"))).string(),4); + t.add(r5abs.string(),4); + t.add(sr5 == 0 ? "" : (sr5 > 0 ? "D" : "C"),5); sl->force_update(row); @@ -1131,15 +1137,17 @@ void Visliq_app::read_general(TMask& m) if (sh.items() < i) tt = new TToken_string(80); else tt = &(sh.row(i-1)); + real r0abs = abs(_lim->get_real("R0")); + real r5abs = abs(_lim->get_real("R5")); tt->add(itoname(i),0); - tt->add(((real) abs(_lim->get_real("R0"))).string(),1); + tt->add(r0abs.string(),1); int sr0 = (_lim->get_real("R0")).sign(); int sr5 = (_lim->get_real("R5")).sign(); tt->add(sr0 == 0 ? "" : (sr0 > 0 ? "D" : "C"),2); tt->add(_lim->get_real("R1").string(),3); - tt->add(((real) abs(_lim->get_real("R5"))).string(),4); + tt->add(r5abs.string(),4); tt->add(sr5 == 0 ? "" : (sr5 > 0 ? "D" : "C"),5); sh.row(i-1) = (*tt); @@ -1165,8 +1173,10 @@ void Visliq_app::read_general(TMask& m) int m = atoi(*_del_mese); if (m >= 12) - m = tipod == 7 ? 12 : 13; - + m = tipod == 7 ? 12 : 13; + // supercauto + if (m <= 0) continue; + versamenti[m-1] += _del->get_real("R0"); date[m-1] = _del->get_date("D0"); banche[m-1].add(_del->get("S7"),0); @@ -1505,10 +1515,13 @@ if (was_lim) int sr0 = (_lim->get_real("R0")).sign(); int sr5 = (_lim->get_real("R5")).sign(); - tt_ln.add(((real) abs(_lim->get_real("R0"))).string(),1); + real r0abs = abs(_lim->get_real("R0")); + real r5abs = abs(_lim->get_real("R5")); + + tt_ln.add(r0abs.string(),1); tt_ln.add(sr0 == 0 ? "" : (sr0 > 0 ? "D" : "C"), 2); tt_ln.add((_lim->get_real("R1")).string(),3); - tt_ln.add(((real) abs(_lim->get_real("R5"))).string(),4); + tt_ln.add(r5abs.string(),4); tt_ln.add(sr5 == 0 ? "" : (sr5 > 0 ? "D" : "C"),5); // sh.force_update(row); diff --git a/cg/cg5500t.h b/cg/cg5500t.h index eba13fd34..b17e0b1f4 100755 --- a/cg/cg5500t.h +++ b/cg/cg5500t.h @@ -1,12 +1,15 @@ BUTTON DLG_SAVEREC 8 2 BEGIN PROMPT -14 -1 "~Registra" +PICTURE BMP_SAVEREC +PICTURE BMP_SAVERECDN MESSAGE EXIT,K_SAVE END BUTTON DLG_RECALC 8 2 BEGIN PROMPT -24 -1 "Ri~calcola" +PICTURE BMP_RECALC MESSAGE EXIT,K_INS END diff --git a/cg/cg5600.cpp b/cg/cg5600.cpp index 57526e6a6..2424673df 100755 --- a/cg/cg5600.cpp +++ b/cg/cg5600.cpp @@ -75,7 +75,7 @@ void TRipristino_liq::build_ditte_sheet() d->insert(" |", 0); const long pos = _ditte->add(d); - if (selectable) _ditte->disable(pos); + if (selectable) _ditte->disable_row(pos); } } diff --git a/cg/cg6600.cpp b/cg/cg6600.cpp index 957565e04..66f656f59 100755 --- a/cg/cg6600.cpp +++ b/cg/cg6600.cpp @@ -1,3 +1,3040 @@ +<<<<<<< cg6600.cpp +<<<<<<< cg6600.cpp +// Ricezione dati da sistema + +#include +#include +#include +#include +#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 "cg6600.h" + +class TRic_tab : public TApplication +{ + + TTable* _tab_tra; + TLocalisamfile* _caus,*_rcaus,*_clifo,*_pcon,*_mov,*_rmov,*_rmoviva,*_saldi,*_occas; + TIsamtempfile* _tcaus,*_trcaus,*_tclifo,*_tpcon,*_tmov,*_trmov,*_triva,*_toccas; + TTable* _reg; + TTransfer_file _tras_file; + TArray _aggiorna; + char _scelta, _ric_auto; + 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,_nprot_att,_nprot_pas; + long _protiva,_uprotiva,_nprotiva,_nuprotiva,_numreg,_numreg_p,_numreg_piva,_nuovareg; + char _sez; + real _importo,_totdoc; + TString _tmpcaus,_tmprcaus,_tmpclifo,_tmpcon,_tmpmov,_tmprmov,_tmpriva,_tmpoccas; + +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 apri_file_temp(); + void chiudi_file_temp(); + + void setta_parametri_record(const TString& sigla,const TString& flag); + + void trasferimento(); + + void ricevi_causali(TString& key, char sigla); + void cancella_righe_causali(TString& codcaus); + void scrivi_righe_causali(TString& codcaus, char sigla); + void ricevi_clifo(TString& key, char sigla); + void ricevi_pcon(TString& key, char sigla); + void conto(TRectype& pcon,char flag,bool esiste); + void sottoconto(TRectype& pcon,char flag,bool esiste); + void scrivi_pcon(TRectype& pcon,bool esiste); + + void ricevi_movPN(TString& key, char sigla); + void scrivi_righePN(long numreg); + void ricevi_movIVA(TString& key, char sigla); + void scrivi_righeIVA(long numreg); + long esiste_numreg(long nreg); + void num_protocollo(); + long controlli_primanota(); + long ulnumprot_reg(int anno,TString& codreg); + long ultima_registrazione(); + void aggiorna_reg(int anno,TString& codreg,long ulnum); + char ricerca_causale(TString& field); + + bool occasionali(const TString& ocfpi); + + TRic_tab(char ric_tab_mov, char ric_auto = '\0'); +}; + +HIDDEN TRic_tab& app() { return (TRic_tab &) main_app(); } + +TRic_tab::TRic_tab(char ric_tab_mov, char ric_auto) : +_scelta(toupper(ric_tab_mov)), _ric_auto(toupper(ric_auto)) +{ + if (_scelta == 'T') + _titolo = "Ricezione tabelle"; + + if (_scelta == 'M') + _titolo = "Ricezione movimenti"; +} + +bool TRic_tab::create() +{ + TApplication::create(); + + _tab_tra = new TTable ("%TRA"); + + _reg = new TTable ("REG"); + + if (_scelta == 'T') + { + _caus = new TLocalisamfile (LF_CAUSALI); + _rcaus = new TLocalisamfile (LF_RCAUSALI); + _clifo = new TLocalisamfile (LF_CLIFO); + _pcon = new TLocalisamfile (LF_PCON); + } + else + { + _mov = new TLocalisamfile (LF_MOV); + _rmov = new TLocalisamfile (LF_RMOV); + _rmoviva = new TLocalisamfile (LF_RMOVIVA); + _saldi = new TLocalisamfile (LF_SALDI); + _occas = new TLocalisamfile (LF_OCCAS); + } + + _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; + delete _reg; + + if (_scelta == 'T') + { + delete _caus; + delete _rcaus; + delete _clifo; + delete _pcon; + } + else + { + delete _mov; + delete _rmov; + delete _rmoviva; + delete _saldi; + delete _occas; + } + + return TApplication::destroy(); +} + +void TRic_tab::leggi_record_controllo() +{ + _tras_file.read_control_rec(); + _record = _tras_file.record(); +} + +bool TRic_tab::main_loop() +{ + int posiz; + + _dittaric = get_firm(); + + if (_ric_auto == 'A') + { + leggi_trasfer(); + + if (_scelta == 'T') + { + apri_file_temp(); + + trasferimento(); + posiz = _tras_file.num('Z'); //Ritorna la posizione della sigla all'interno dell'indice + + if (posiz >= 0) + { + setta_parametri_record(" ","C"); + //message_box("Aggiornamento tabelle terminato: proseguire con controllo movimenti"); + leggi_record_controllo(); + TString str; + str.spaces(60); + _record.overwrite(str,241); + _tras_file.write_control_rec(_record,1024); + } + else + { + chiudi_file_temp(); + //message_box("Trasferimento interamente completato: proseguire per cancellare il file"); + setta_parametri_record(" ","*"); + //_tras_file.remove_all(); + //setta_parametri_record(" "," "); + } + } + else + if (_scelta == 'M') + { + apri_file_temp(); + + trasferimento(); + chiudi_file_temp(); + //message_box("Trasferimento interamente completato: proseguire per cancellare il file"); + setta_parametri_record(" ","*"); + //_tras_file.remove_all(); + //setta_parametri_record(" "," "); + } + } + else + { + if (_scelta == 'T') + { + if (video()) + { + if (_std == "") + if (!controllo_pre_ricezione()) + return FALSE; + + apri_file_temp(); + + trasferimento(); + posiz = _tras_file.num('Z'); //Ritorna la posizione della sigla all'interno dell'indice + + if (posiz >= 0) + { + setta_parametri_record(" ","C"); + message_box("Aggiornamento tabelle terminato: proseguire con controllo movimenti"); + leggi_record_controllo(); + TString str; + str.spaces(60); + _record.overwrite(str,241); + _tras_file.write_control_rec(_record,1024); + } + else + { + chiudi_file_temp(); + message_box("Trasferimento interamente completato: proseguire per cancellare il file"); + setta_parametri_record(" ","*"); + _tras_file.remove_all(); + setta_parametri_record(" "," "); + } + } + } + else + if (_scelta == 'M') + { + if (video()) + { + apri_file_temp(); + + trasferimento(); + chiudi_file_temp(); + message_box("Trasferimento interamente completato: proseguire per cancellare il file"); + setta_parametri_record(" ","*"); + _tras_file.remove_all(); + setta_parametri_record(" "," "); + } + } + } + + return FALSE; +} + +void TRic_tab::trasferimento() +{ + char uselab; + TString key = ""; + int posiz,i; + 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++) + { + long nrec = ((_tras_file.nrec(i))+1); + sigla = _tras_file.name(i)[0]; + long cicli; + + switch (sigla) + { + case 'W': + message = "Ricezione tabella causali in corso... Prego attendere."; + cicli = _tcaus->items(); + break; + case 'A': + message = "Ricezione anagrafica Clienti / Fornitori in corso... Prego attendere."; + cicli = _tclifo->items(); + break; + case 'P': + message = "Ricezione anagrafica Piano dei Conti in corso... Prego attendere."; + cicli = _tpcon->items(); + break; + case 'Z': + message = "Ricezione Movimenti di primanota in corso... Prego attendere."; + cicli = _tmov->items(); + break; + case 'U': + message = "Ricezione Movimenti iva in corso... Prego attendere."; + cicli = _tmov->items(); + break; + default: break; + } + _prog = new TProgind(cicli,message,FALSE); + + if (_scelta == 'T') + { + if (sigla == 'W') + ricevi_causali(key,sigla); + if (sigla == 'A') + ricevi_clifo(key,sigla); + if (sigla == 'P') + ricevi_pcon(key,sigla); + } + else + if (_scelta == 'M') + { + if (sigla == 'Z') + { + ricevi_movPN(key,sigla); + _sld.registra(); + } + else + if (sigla == 'U') + ricevi_movIVA(key,sigla); + } + delete _prog; + key = ""; //Altrimenti in caso di ripartenza mi ripristina sempre la situazione + } +} + +void TRic_tab::ricevi_causali(TString& key, char uselab) +{ + TString str; + + char flag = _tras_file.flg_agg(uselab); + + _tcaus->setkey(1); + + if (key.empty()) + _tcaus->first(); + else + { + TString causale (key.mid(0,3)); + _tcaus->zero(); + _tcaus->put(CAU_CODCAUS, causale); + _tcaus->read(); + } + + for(; !_tcaus->eof(); _tcaus->next()) + { + _prog->addstatus(1); + + TString codcaus = _tcaus->get(CAU_CODCAUS); + + _caus->curr() = _tcaus->curr(); + + if (_caus->read() == NOERR) // Esiste la testata + { + if (flag == 'N') + { + leggi_record_controllo(); + TString chiave; + chiave.format("%3s",(const char*) codcaus); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + continue; + } + else + if (flag == 'D') + { + TString descr = _tcaus->get(CAU_DESCR); + + _caus->put(CAU_DESCR, descr); + _caus->rewrite(); + } + else + if (flag == 'T') + { + scrivi_righe_causali(codcaus,uselab); + + _caus->zero(); + _caus->curr() = _tcaus->curr(); + _caus->rewrite(); + } + } + else + { + scrivi_righe_causali(codcaus,uselab); + + _caus->zero(); + _caus->curr() = _tcaus->curr(); + _caus->write(); + } + + leggi_record_controllo(); + TString chiave; + chiave.format("%3s",(const char*) codcaus); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + } +} + +void TRic_tab::cancella_righe_causali(TString& codcaus) +{ + _rcaus->setkey(1); + _rcaus->zero(); + _rcaus->put(RCA_CODCAUS, codcaus); + TRectype rcau (LF_RCAUSALI); + rcau = _rcaus->curr(); + for (_rcaus->read(); !_rcaus->eof(); _rcaus->next()) + { + if (_rcaus->curr() > rcau) break; + + _rcaus->remove(); + } +} + +void TRic_tab::scrivi_righe_causali(TString& codcaus, char uselab) +{ + TString str; + + cancella_righe_causali(codcaus); + + _trcaus->setkey(1); + _trcaus->zero(); + _trcaus->put(RCA_CODCAUS, codcaus); + TRectype rcau (LF_RCAUSALI); + rcau = _trcaus->curr(); + for (_trcaus->read(); !_trcaus->eof(); _trcaus->next()) + { + if (_trcaus->curr() > rcau) break; + + _rcaus->curr() = _trcaus->curr(); + _rcaus->write(); + + leggi_record_controllo(); + TString chiave; + chiave.format("%3s",(const char*) codcaus); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + } +} + +void TRic_tab::ricevi_clifo(TString& key, char uselab) +{ + TString str; + + char flag = _tras_file.flg_agg(uselab); + + _tclifo->setkey(1); + + if (key.empty()) + _tclifo->first(); + else + { + char tipo = (key.mid(0,1))[0]; + long codice = atol(key.mid(1,6)); + _tclifo->zero(); + _tclifo->put(CLI_TIPOCF, tipo); + _tclifo->put(CLI_CODCF, codice); + _tclifo->read(); + } + + for(; !_tclifo->eof(); _tclifo->next()) + { + _prog->addstatus(1); + + char tipocf = _tclifo->get_char(CLI_TIPOCF); + long codcf = _tclifo->get_long(CLI_CODCF); + + _clifo->curr() = _tclifo->curr(); + + if (_clifo->read() == NOERR) // Esiste gia' il cliente + { + if (flag == 'N') + { + leggi_record_controllo(); + TString chiave; + chiave.format("%c%06ld", tipocf,codcf); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + continue; + } + else + if (flag == 'D') + { + TString ragsoc = _tclifo->get(CLI_RAGSOC); + TString ind = _tclifo->get(CLI_INDCF); + TString civ = _tclifo->get(CLI_CIVCF); + TString com = _tclifo->get(CLI_COMCF); + TString cap = _tclifo->get(CLI_CAPCF); + TString cofi = _tclifo->get(CLI_COFI); + TString paiv = _tclifo->get(CLI_PAIV); + TString ptel = _tclifo->get(CLI_PTEL); + TString tel = _tclifo->get(CLI_TEL); + + _clifo->put(CLI_RAGSOC, ragsoc); + _clifo->put(CLI_INDCF, ind); + _clifo->put(CLI_CIVCF, civ); + _clifo->put(CLI_COMCF, com); + _clifo->put(CLI_CAPCF, cap); + _clifo->put(CLI_COFI, cofi); + _clifo->put(CLI_PAIV, paiv); + _clifo->put(CLI_PTEL, ptel); + _clifo->put(CLI_TEL, tel); + + _clifo->rewrite(); + } + else + if (flag == 'T') + { + _clifo->zero(); + _clifo->curr() = _tclifo->curr(); + _clifo->rewrite(); + } + } + else + { + _clifo->zero(); + _clifo->curr() = _tclifo->curr(); + _clifo->write(); + } + + leggi_record_controllo(); + TString chiave; + chiave.format("%c%06ld", tipocf, codcf); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + } +} + +void TRic_tab::ricevi_pcon(TString& key, char uselab) +{ + TString str; + bool esiste; + TRectype pcon (LF_PCON); + + char flag = _tras_file.flg_agg(uselab); + char f_IV = _tras_file.flg_agg_IV(uselab); + + _tpcon->setkey(1); + + if (key.empty()) + _tpcon->first(); + else + { + int gruppo = atoi(key.mid(0,3)); + int conto = atoi(key.mid(3,3)); + long sottoc = atol(key.mid(6,6)); + + _tpcon->zero(); + _tpcon->put(PCN_GRUPPO, gruppo); + if (conto != 0) + _tpcon->put(PCN_CONTO, conto); + if (sottoc != 0) + _tpcon->put(PCN_SOTTOCONTO, sottoc); + _tpcon->read(); + } + + for(; !_tpcon->eof(); _tpcon->next()) + { + _prog->addstatus(1); + + int g = _tpcon->get_int (PCN_GRUPPO); + int c = _tpcon->get_int (PCN_CONTO); + long s = _tpcon->get_long(PCN_SOTTOCONTO); + + _pcon->curr() = _tpcon->curr(); + + if (_pcon->read() == NOERR) // Esiste gia' sul Piano dei Conti + { + esiste = TRUE; + + if (flag == 'N') + { + leggi_record_controllo(); + TString chiave; + chiave.format("%03d%03d%06ld", g, c, s); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + continue; + } + else + if (flag == 'D') + { + TString descr = _tpcon->get(PCN_DESCR); + + _pcon->put(PCN_DESCR, descr); + _pcon->rewrite(); + } + else + if (flag == 'T') + scrivi_pcon(pcon,esiste); + } + else // Non esiste sull'archivio effettivo + { + esiste = FALSE; + scrivi_pcon(pcon,esiste); + } + + TRecnotype rec; + if (esiste) + rec = _pcon->recno(); + + if (f_IV == 'T') + { + if (g != 0 && c == 0) + conto(pcon,flag,esiste); + if (g != 0 && c != 0 && s != 0) + sottoconto(pcon,flag,esiste); + } + + if (esiste) + _pcon->readat(rec); + + if ( (flag == 'T' && esiste) || !esiste) + _pcon->curr() = pcon; + + if (esiste) + _pcon->rewrite(); + else + _pcon->write(); + + leggi_record_controllo(); + TString chiave; + chiave.format("%03d%03d%06ld", g, c, s); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + } +} + +void TRic_tab::scrivi_pcon(TRectype& pcon,bool esiste) +{ + int g = _tpcon->get_int (PCN_GRUPPO); + int c = _tpcon->get_int (PCN_CONTO); + long s = _tpcon->get_long(PCN_SOTTOCONTO); + TString descr = _tpcon->get (PCN_DESCR); + int indbil = _tpcon->get_int (PCN_INDBIL); + char tmcf = _tpcon->get_char(PCN_TMCF); + bool stsottbil = _tpcon->get_bool(PCN_STSOTTBIL); + bool compens = _tpcon->get_bool(PCN_COMPENS); + int tipospric = _tpcon->get_int (PCN_TIPOSPRIC); + TString codcbl = _tpcon->get (PCN_CODCBL); + bool stsottab = _tpcon->get_bool(PCN_STSOTTAB); + char sezsaldi = _tpcon->get_char(PCN_SEZSALDI); + bool sospeso = _tpcon->get_bool(PCN_SOSPESO); + int ricser = _tpcon->get_int (PCN_RICSER); + + pcon.zero(); + pcon.put(PCN_GRUPPO, g); + if (c != 0) + pcon.put(PCN_CONTO, c); + if (s != 0) + pcon.put(PCN_SOTTOCONTO, s); + pcon.put(PCN_DESCR, descr); + pcon.put(PCN_INDBIL, indbil); + pcon.put(PCN_TMCF, tmcf); + pcon.put(PCN_STSOTTBIL, stsottbil); + pcon.put(PCN_COMPENS, compens); + pcon.put(PCN_TIPOSPRIC, tipospric); + pcon.put(PCN_CODCBL, codcbl); + pcon.put(PCN_STSOTTAB, stsottab); + pcon.put(PCN_SEZSALDI, sezsaldi); + pcon.put(PCN_SOSPESO, sospeso); + pcon.put(PCN_RICSER, ricser); +} + +void TRic_tab::conto(TRectype& pcon,char flag,bool esiste) +{ + int g = _tpcon->get_int(PCN_GRUPPO); + int c = _tpcon->get_int(PCN_CONTO); + + TString sez = _tpcon->get (PCN_SEZIVD); + TString let = _tpcon->get (PCN_LETTIVD); + TString numr = _tpcon->get (PCN_NUMRIVD); + int num = _tpcon->get_int(PCN_NUMIVD); + + if (sez.not_empty()) + { + if (!esiste || (esiste && flag == 'T') ) + { + pcon.put (PCN_SEZIVD, sez); + pcon.put (PCN_LETTIVD, let); + pcon.put (PCN_NUMRIVD, numr); + pcon.put (PCN_NUMIVD, num); + pcon.zero(PCN_SEZIVDOPP); + pcon.zero(PCN_LETTIVDOPP); + pcon.zero(PCN_NUMRIVDOPP); + pcon.zero(PCN_NUMIVDOPP); + + _tras_file.annulla_classi(g,c,TRUE); + } + } + else + { + if (esiste && flag == 'T') + { + pcon.put (PCN_SEZIVD, sez); + pcon.put (PCN_LETTIVD, let); + pcon.put (PCN_NUMRIVD, numr); + pcon.put (PCN_NUMIVD, num); + pcon.zero(PCN_SEZIVDOPP); + pcon.zero(PCN_LETTIVDOPP); + pcon.zero(PCN_NUMRIVDOPP); + pcon.zero(PCN_NUMIVDOPP); + + _tras_file.annulla_classi(g,c,TRUE); + } + } +} + +void TRic_tab::sottoconto(TRectype& pcon,char flag,bool esiste) +{ + int g = _tpcon->get_int(PCN_GRUPPO); + int c = _tpcon->get_int(PCN_CONTO); + + TString sez = _tpcon->get (PCN_SEZIVD); + TString let = _tpcon->get (PCN_LETTIVD); + TString numr = _tpcon->get (PCN_NUMRIVD); + int num = _tpcon->get_int(PCN_NUMIVD); + TString sezop = _tpcon->get (PCN_SEZIVDOPP); + TString letop = _tpcon->get (PCN_LETTIVDOPP); + TString numrop = _tpcon->get (PCN_NUMRIVDOPP); + int numop = _tpcon->get_int(PCN_NUMIVDOPP); + + if (sez.not_empty()) + { + if (!esiste || (esiste && flag == 'T') ) + { + pcon.put(PCN_SEZIVD, sez); + pcon.put(PCN_LETTIVD, let); + pcon.put(PCN_NUMRIVD, numr); + pcon.put(PCN_NUMIVD, num); + pcon.put(PCN_SEZIVDOPP, sezop); + pcon.put(PCN_LETTIVDOPP, letop); + pcon.put(PCN_NUMRIVDOPP, numrop); + pcon.put(PCN_NUMIVDOPP, numop); + + _tras_file.annulla_classi(g,c,FALSE); + } + } + else + { + if (sezop.not_empty()) + { + if (!esiste || (esiste && flag == 'T') ) + { + pcon.put(PCN_SEZIVDOPP, sezop); + pcon.put(PCN_LETTIVDOPP, letop); + pcon.put(PCN_NUMRIVDOPP, numrop); + pcon.put(PCN_NUMIVDOPP, numop); + } + } + else + { + pcon.zero(PCN_SEZIVDOPP); + pcon.zero(PCN_LETTIVDOPP); + pcon.zero(PCN_NUMRIVDOPP); + pcon.zero(PCN_NUMIVDOPP); + } + } +} + +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; +} + +long TRic_tab::ultima_registrazione() +{ + if (_nreg == 0) + { + TLocalisamfile mov (LF_MOV); + + mov.last(); + return (mov.get_long(MOV_NUMREG)); + } + else + return _nreg; +} + +void TRic_tab::num_protocollo() +{ + _protiva = _tmov->get_long(MOV_PROTIVA); + _uprotiva = _tmov->get_long(MOV_UPROTIVA); + + if (_protiva == 0) + _uprotiva = 0; + + _nprotiva = _protiva; + _nuprotiva = _uprotiva; +} + +long TRic_tab::ulnumprot_reg(int anno,TString& cr) +{ + TRegistro rg (cr, anno); + + return rg.protocol(); +} + +void TRic_tab::aggiorna_reg(int anno,TString& codreg,long ulnum) +{ + TTable reg ("REG"); + TString16 dep; + + if (real::is_natural(codreg)) + dep.format("%04d%03s", anno,(const char*) codreg); + else + dep.format("%04d%-3s", anno,(const char*) codreg); + + reg.zero(); + reg.put("CODTAB", (const char*) dep); + if (reg.read() == NOERR) + { + if (_nprotiva > ulnum ) + reg.put("I5", _nprotiva); + + if (_nuprotiva > ulnum ) + reg.put("I5", _nuprotiva); + + reg.rewrite(); + } +} + +long TRic_tab::controlli_primanota() +{ + TTable tpd ("%TPD"); + bool corrisp = FALSE; + TDate datareg; + int anno; + long ulnum = 0; + TString16 tmp; + TString tipodoc,codreg; + + char tipocf = _tmov->get_char(MOV_TIPO); + int tiporeg; + if (tipocf == 'C') + tiporeg = 1; + else + if (tipocf == 'F') + tiporeg = 2; + + codreg = _tmov->get(MOV_REG); + tipodoc = _tmov->get(MOV_TIPODOC); + + datareg = _tmov->get_date(MOV_DATAREG); + anno = datareg.year(); + + tpd.zero(); + tpd.put("CODTAB", (const char*) tipodoc); + if (tpd.read() == NOERR) + corrisp = tpd.get_bool("B0"); + + if (codreg.not_empty() && !corrisp) + { + if ( ( (tiporeg == 1 && (_nprot_att || _protiva == 0) ) ) + || ( (tiporeg == 2 && (_nprot_pas || _protiva == 0) ) ) ) + { + ulnum = ulnumprot_reg(anno,codreg); + _nprotiva = ulnum + 1; + if (_uprotiva != 0) + _nuprotiva = (_nprotiva - ulnum) + _uprotiva; + } + } + + return ulnum; +} + +char TRic_tab::ricerca_causale(TString& causale) +{ + TLocalisamfile cau (LF_CAUSALI); + char movap = ' '; + + if (real::is_natural(causale)) + causale.format("%03s", (const char*) causale); + else + causale.format("%-3s", (const char*) causale); + + cau.setkey(1); + cau.zero(); + cau.put("CODCAUS", causale); + if (cau.read() == NOERR) + movap = cau.get_char("MOVAP"); + + return movap; +} + +void TRic_tab::scrivi_righePN(long numreg) +{ + TString str; + + _trmov->setkey(1); + _trmov->zero(); + _trmov->put(RMV_NUMREG, numreg); + TRectype rmov (LF_RMOV); + rmov = _trmov->curr(); + for (_trmov->read(); !_trmov->eof(); _trmov->next()) + { + if (_trmov->curr() > rmov) break; + + int g = _trmov->get_int (RMV_GRUPPO); + int c = _trmov->get_int (RMV_CONTO); + long s = _trmov->get_long(RMV_SOTTOCONTO); + char sez = _trmov->get_char(RMV_SEZIONE); + real imp ( _trmov->get_real(RMV_IMPORTO) ); + + _trmov->put(RMV_NUMREG, _nreg); + _rmov->curr() = _trmov->curr(); + _rmov->write(); + + _sld.aggiorna(g,c,s,imp,sez); + } +} + +void TRic_tab::ricevi_movPN(TString& key, char uselab) +{ + TString str; + long numulreg; + TRectype recmov (LF_MOV); + + char flag = _tras_file.flg_agg(uselab); + + _nprot_att = _tras_file.numprot_att(); + _nprot_pas = _tras_file.numprot_pas(); + + _tmov->setkey(1); + + if (key.empty()) + _tmov->first(); + else + { + long numreg = atol(key.mid(0,7)); + _tmov->zero(); + _tmov->put(MOV_NUMREG, numreg); + _tmov->read(); + } + + for(; !_tmov->eof(); _tmov->next()) + { + _prog->addstatus(1); + + long nreg = _tmov->get_long(MOV_NUMREG); + long nuova_reg = _tmov->get_long("TNUMREG" ); + + if (nuova_reg == 0) + { + numulreg = ultima_registrazione(); // reperisco il numero ultima registrazione + _nreg = esiste_numreg(numulreg); + } + else + _nreg = nuova_reg; + + TRecnotype rec = _tmov->recno(); // Salvo il nuovo numero di + _tmov->put("TNUMREG", _nreg); // registrazione sul file di lavoro + _tmov->rewrite(); + _tmov->readat(rec); + + int annoes = _tmov->get_int(MOV_ANNOES); + + recmov = _tmov->curr(); + + _mov->setkey(1); + _mov->zero(); + _mov->put(MOV_NUMREG, _nreg); + + if (_mov->read() != NOERR) // Se non esiste la testata + { + num_protocollo(); // Riattribuzione numero di protocollo + long ulnum = controlli_primanota(); + + recmov.put(MOV_NUMREG, _nreg); + recmov.put(MOV_PROTIVA, _nprotiva); + recmov.put(MOV_UPROTIVA, _nuprotiva); + + _mov->zero(); + _mov->curr() = recmov; + _mov->write(); + + TString codreg (_tmov->get (MOV_REG)); + TString codcaus (_tmov->get (MOV_CODCAUS)); + TDate datareg (_tmov->get_date(MOV_DATAREG)); + int anno = datareg.year(); + + aggiorna_reg(anno,codreg,ulnum); // Aggiorna il registro + + _sld.set_anno_es(annoes); + _sld.set_movprovv(FALSE); + _sld.set_num_ulmov(_nreg); + _sld.set_data_ulmov(datareg); + char movap = ricerca_causale(codcaus); + if (movap == 'A') + _sld.set_tipo_saldo(apertura); + + scrivi_righePN(nreg); + + _sld.registra(); + _sld.reset(); + } + + leggi_record_controllo(); + TString chiave; + chiave.format("%07ld", nreg); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + } +} + +bool TRic_tab::occasionali(const TString& ocfpi) +{ + TString chiave; + long prog = 1; + bool esiste = FALSE; + + TString nocfpi = _tmov->get("TOCFP"); + nocfpi.trim(); + + if (nocfpi.empty()) + { + _occas->setkey(1); + _occas->zero(); + _occas->put("CFPI", "RIC9999999999999"); + _occas->read(); + _occas->prev(); + TString cfpi = _occas->get(OCC_CFPI); + if (cfpi.mid(0,3) == "RIC") + { + prog = atol(cfpi.mid(3,13)); + prog++; + chiave = format("%3s%13ld", (const char*) "RIC", prog); + } + else + chiave = format("%3s%13ld", (const char*) "RIC", prog); + + esiste = FALSE; + } + else + { + _occas->setkey(1); + _occas->zero(); + _occas->put("CFPI", nocfpi); + _occas->read(); + + esiste = TRUE; + } + + _toccas->setkey(1); + _toccas->zero(); + _toccas->put(OCC_CFPI, ocfpi); + _toccas->read(); + + _occas->curr() = _toccas->curr(); + + if (esiste) + _occas->rewrite(); + else + _occas->write(); + + return TRUE; +} + +void TRic_tab::scrivi_righeIVA(long numreg) +{ + TString str; + + _triva->setkey(1); + _triva->zero(); + _triva->put(RMI_NUMREG, numreg); + TRectype riva (LF_RMOVIVA); + riva = _triva->curr(); + for (_triva->read(); !_triva->eof(); _triva->next()) + { + if (_triva->curr() > riva) break; + + _triva->put(RMI_NUMREG, _nuovareg); + _rmoviva->curr() = _triva->curr(); + _rmoviva->write(); + } +} + +void TRic_tab::ricevi_movIVA(TString& key, char uselab) +{ + TString str; + TRectype recmov (LF_MOV); + + char flag = _tras_file.flg_agg(uselab); + + _tmov->setkey(1); + + if (key.empty()) + _tmov->first(); + else + { + long numreg = atol(key.mid(0,7)); + _tmov->zero(); + _tmov->put(MOV_NUMREG, numreg); + _tmov->read(); + } + + for(; !_tmov->eof(); _tmov->next()) + { + _prog->addstatus(1); + + long nreg = _tmov->get_long(MOV_NUMREG); + + TString codreg = _tmov->get(MOV_REG); + TString codcau = _tmov->get(MOV_CODCAUS); + + if (codreg.empty() || codcau.empty()) continue; + + _nuovareg = _tmov->get_long("TNUMREG"); + TString ocfpi = _tmov->get(MOV_OCFPI); + + if (ocfpi.not_empty()) + occasionali(ocfpi); + + TDate data74ter ( _tmov->get_date(MOV_DATA74TER) ); + TString codval ( _tmov->get (MOV_CODVALI) ); + long codcf = _tmov->get_long(MOV_CODCF); + real totdoc ( _tmov->get_real(MOV_TOTDOC) ); + real cambioi ( _tmov->get_real(MOV_CAMBIOI) ); + real corrlire ( _tmov->get_real(MOV_CORRLIRE) ); + real corrval ( _tmov->get_real(MOV_CORRVALUTA) ); + int annoiva = _tmov->get_int (MOV_ANNOIVA); + + _mov->setkey(1); + _mov->zero(); + _mov->put(MOV_NUMREG, _nuovareg); + + if (_mov->read() == NOERR) // Se non esiste la testata + { + _mov->put(MOV_DATA74TER, data74ter); + _mov->put(MOV_CODVALI, codval); + _mov->put(MOV_CODCF, codcf); + _mov->put(MOV_TOTDOC, totdoc); + _mov->put(MOV_CAMBIOI, cambioi); + _mov->put(MOV_CORRLIRE, corrlire); + _mov->put(MOV_CORRVALUTA, corrval); + _mov->put(MOV_ANNOIVA, annoiva); + _mov->rewrite(); + + scrivi_righeIVA(nreg); + } + + leggi_record_controllo(); + TString chiave; + chiave.format("%07ld", nreg); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + } +} + +bool TRic_tab::leggi_trasfer() +{ + _nultras = 0; + + _trasf = _tras_file.path(_dittaric); + _trasf << HEADER; + + _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(); + _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 ("cg6600a"); + 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 = 1024; + + _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 == "*") + { + warning_box("Trasferimento interamente completato: proseguire per cancellare il file"); + _tras_file.remove_all(); + setta_parametri_record(" "," "); + return FALSE; + } + + 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"); + _tras_file.remove_all(); + setta_parametri_record(" "," "); + return FALSE; + } + } + + return TRUE; +} + +void TRic_tab::apri_file_temp() +{ + if (_scelta == 'T') + { + TString80 tmpcaus = "%"; + tmpcaus << get_firm_dir(); + tmpcaus << "\\" << TEMP_CAUS; + _tmpcaus = tmpcaus.mid(1); + _tmpcaus << ".dbf"; + if(fexist(_tmpcaus)) + _tcaus = new TIsamtempfile(LF_CAUSALI, tmpcaus, 0); + TString80 tmprcaus = "%"; + tmprcaus << get_firm_dir(); + tmprcaus << "\\" << TEMP_RCAUS; + _tmprcaus = tmprcaus.mid(1); + _tmprcaus << ".dbf"; + if (fexist(_tmprcaus)) + _trcaus = new TIsamtempfile(LF_RCAUSALI, tmprcaus, 0); + TString80 tmpclifo = "%"; + tmpclifo << get_firm_dir(); + tmpclifo << "\\" << TEMP_CLIFO; + _tmpclifo = tmpclifo.mid(1); + _tmpclifo << ".dbf"; + if (fexist(_tmpclifo)) + _tclifo = new TIsamtempfile(LF_CLIFO, tmpclifo, 0); + TString80 tmppcon = "%"; + tmppcon << get_firm_dir(); + tmppcon << "\\" << TEMP_PCON; + _tmpcon = tmppcon.mid(1); + _tmpcon << ".dbf"; + if (fexist(_tmpcon)) + _tpcon = new TIsamtempfile(LF_PCON, tmppcon, 0); + } + else + { + TString80 tmpmov = "%"; + tmpmov << get_firm_dir(); + tmpmov << "\\" << TEMP_MOV; + _tmpmov = tmpmov.mid(1); + _tmpmov << ".dbf"; + if (fexist(_tmpmov)) + _tmov = new TIsamtempfile(LF_MOV, tmpmov, 0); + TString80 tmprmov = "%"; + tmprmov << get_firm_dir(); + tmprmov << "\\" << TEMP_RMOV; + _tmprmov = tmprmov.mid(1); + _tmprmov << ".dbf"; + if (fexist(_tmprmov)) + _trmov = new TIsamtempfile(LF_RMOV, tmprmov, 0); + TString80 tmpriva = "%"; + tmpriva << get_firm_dir(); + tmpriva << "\\" << TEMP_RMOVIVA; + _tmpriva = tmpriva.mid(1); + _tmpriva << ".dbf"; + if (fexist(_tmpriva)) + _triva = new TIsamtempfile(LF_RMOVIVA, tmpriva, 0); + TString80 tmpoccas = "%"; + tmpoccas << get_firm_dir(); + tmpoccas << "\\" << TEMP_OCC; + _tmpoccas = tmpoccas.mid(1); + _tmpoccas << ".dbf"; + if (fexist(_tmpoccas)) + _toccas = new TIsamtempfile(LF_OCCAS, tmpoccas, 0); + } +} + +void TRic_tab::chiudi_file_temp() +{ + if (_scelta == 'T') + { + if (fexist(_tmpcaus)) + delete _tcaus; + if (fexist(_tmprcaus)) + delete _trcaus; + if (fexist(_tmpclifo)) + delete _tclifo; + if (fexist(_tmpcon)) + delete _tpcon; + } + else + { + if (fexist(_tmpmov)) + delete _tmov; + if (fexist(_tmprmov)) + delete _trmov; + if (fexist(_tmpriva)) + delete _triva; + if (fexist(_tmpoccas)) + delete _toccas; + } +} + +bool TRic_tab::menu(MENU_TAG m) +{ + if (m == BAR_ITEM(1)) + return main_loop(); + return FALSE; +} + +int cg6600 (int argc, char* argv[]) +{ + char p3 = '\0'; + + if (argc > 4) + p3 = *argv[3]; + + TRic_tab main_app(*argv[2],p3); + 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cglib04.h" +#include "cglib.h" +#include "cg2103.h" + +#include "cg6600.h" + +class TRic_tab : public TApplication +{ + + TTable* _tab_tra; + TLocalisamfile* _caus,*_rcaus,*_clifo,*_pcon,*_mov,*_rmov,*_rmoviva,*_saldi,*_occas; + TIsamtempfile* _tcaus,*_trcaus,*_tclifo,*_tpcon,*_tmov,*_trmov,*_triva,*_toccas; + TTable* _reg; + TTransfer_file _tras_file; + TArray _aggiorna; + char _scelta, _ric_auto; + 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,_nprot_att,_nprot_pas; + long _protiva,_uprotiva,_nprotiva,_nuprotiva,_numreg,_numreg_p,_numreg_piva,_nuovareg; + char _sez; + real _importo,_totdoc; + TString _tmpcaus,_tmprcaus,_tmpclifo,_tmpcon,_tmpmov,_tmprmov,_tmpriva,_tmpoccas; + +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 apri_file_temp(); + void chiudi_file_temp(); + + void setta_parametri_record(const TString& sigla,const TString& flag); + + void trasferimento(); + + void ricevi_causali(TString& key, char sigla); + void cancella_righe_causali(TString& codcaus); + void scrivi_righe_causali(TString& codcaus, char sigla); + void ricevi_clifo(TString& key, char sigla); + void ricevi_pcon(TString& key, char sigla); + void conto(TRectype& pcon,char flag,bool esiste); + void sottoconto(TRectype& pcon,char flag,bool esiste); + void scrivi_pcon(TRectype& pcon,bool esiste); + + void ricevi_movPN(TString& key, char sigla); + void scrivi_righePN(long numreg); + void ricevi_movIVA(TString& key, char sigla); + void scrivi_righeIVA(long numreg); + long esiste_numreg(long nreg); + void num_protocollo(); + long controlli_primanota(); + long ulnumprot_reg(int anno,TString& codreg); + long ultima_registrazione(); + void aggiorna_reg(int anno,TString& codreg,long ulnum); + char ricerca_causale(TString& field); + + bool occasionali(TString& ocfpi); + + TRic_tab(char ric_tab_mov, char ric_auto = '\0'); +}; + +HIDDEN TRic_tab& app() { return (TRic_tab &) main_app(); } + +TRic_tab::TRic_tab(char ric_tab_mov, char ric_auto) : +_scelta(toupper(ric_tab_mov)), _ric_auto(toupper(ric_auto)) +{ + if (_scelta == 'T') + _titolo = "Ricezione tabelle"; + + if (_scelta == 'M') + _titolo = "Ricezione movimenti"; +} + +bool TRic_tab::create() +{ + TApplication::create(); + + _tab_tra = new TTable ("%TRA"); + + _reg = new TTable ("REG"); + + if (_scelta == 'T') + { + _caus = new TLocalisamfile (LF_CAUSALI); + _rcaus = new TLocalisamfile (LF_RCAUSALI); + _clifo = new TLocalisamfile (LF_CLIFO); + _pcon = new TLocalisamfile (LF_PCON); + } + else + { + _mov = new TLocalisamfile (LF_MOV); + _rmov = new TLocalisamfile (LF_RMOV); + _rmoviva = new TLocalisamfile (LF_RMOVIVA); + _saldi = new TLocalisamfile (LF_SALDI); + _occas = new TLocalisamfile (LF_OCCAS); + } + + _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; + delete _reg; + + if (_scelta == 'T') + { + delete _caus; + delete _rcaus; + delete _clifo; + delete _pcon; + } + else + { + delete _mov; + delete _rmov; + delete _rmoviva; + delete _saldi; + delete _occas; + } + + return TApplication::destroy(); +} + +void TRic_tab::leggi_record_controllo() +{ + _tras_file.read_control_rec(); + _record = _tras_file.record(); +} + +bool TRic_tab::main_loop() +{ + int posiz; + + _dittaric = get_firm(); + + if (_ric_auto == 'A') + { + leggi_trasfer(); + + if (_scelta == 'T') + { + apri_file_temp(); + + trasferimento(); + posiz = _tras_file.num('Z'); //Ritorna la posizione della sigla all'interno dell'indice + + if (posiz >= 0) + { + setta_parametri_record(" ","C"); + //message_box("Aggiornamento tabelle terminato: proseguire con controllo movimenti"); + leggi_record_controllo(); + TString str; + str.spaces(60); + _record.overwrite(str,241); + _tras_file.write_control_rec(_record,1024); + } + else + { + chiudi_file_temp(); + //message_box("Trasferimento interamente completato: proseguire per cancellare il file"); + setta_parametri_record(" ","*"); + //_tras_file.remove_all(); + //setta_parametri_record(" "," "); + } + } + else + if (_scelta == 'M') + { + apri_file_temp(); + + trasferimento(); + chiudi_file_temp(); + //message_box("Trasferimento interamente completato: proseguire per cancellare il file"); + setta_parametri_record(" ","*"); + //_tras_file.remove_all(); + //setta_parametri_record(" "," "); + } + } + else + { + if (_scelta == 'T') + { + if (video()) + { + if (_std == "") + if (!controllo_pre_ricezione()) + return FALSE; + + apri_file_temp(); + + trasferimento(); + posiz = _tras_file.num('Z'); //Ritorna la posizione della sigla all'interno dell'indice + + if (posiz >= 0) + { + setta_parametri_record(" ","C"); + message_box("Aggiornamento tabelle terminato: proseguire con controllo movimenti"); + leggi_record_controllo(); + TString str; + str.spaces(60); + _record.overwrite(str,241); + _tras_file.write_control_rec(_record,1024); + } + else + { + chiudi_file_temp(); + message_box("Trasferimento interamente completato: proseguire per cancellare il file"); + setta_parametri_record(" ","*"); + _tras_file.remove_all(); + setta_parametri_record(" "," "); + } + } + } + else + if (_scelta == 'M') + { + if (video()) + { + apri_file_temp(); + + trasferimento(); + chiudi_file_temp(); + message_box("Trasferimento interamente completato: proseguire per cancellare il file"); + setta_parametri_record(" ","*"); + _tras_file.remove_all(); + setta_parametri_record(" "," "); + } + } + } + + return FALSE; +} + +void TRic_tab::trasferimento() +{ + char uselab; + TString key = ""; + int posiz,i; + 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++) + { + long nrec = ((_tras_file.nrec(i))+1); + sigla = _tras_file.name(i)[0]; + long cicli; + + switch (sigla) + { + case 'W': + message = "Ricezione tabella causali in corso... Prego attendere."; + cicli = _tcaus->items(); + break; + case 'A': + message = "Ricezione anagrafica Clienti / Fornitori in corso... Prego attendere."; + cicli = _tclifo->items(); + break; + case 'P': + message = "Ricezione anagrafica Piano dei Conti in corso... Prego attendere."; + cicli = _tpcon->items(); + break; + case 'Z': + message = "Ricezione Movimenti di primanota in corso... Prego attendere."; + cicli = _tmov->items(); + break; + case 'U': + message = "Ricezione Movimenti iva in corso... Prego attendere."; + cicli = _tmov->items(); + break; + default: break; + } + _prog = new TProgind(cicli,message,FALSE); + + if (_scelta == 'T') + { + if (sigla == 'W') + ricevi_causali(key,sigla); + if (sigla == 'A') + ricevi_clifo(key,sigla); + if (sigla == 'P') + ricevi_pcon(key,sigla); + } + else + if (_scelta == 'M') + { + if (sigla == 'Z') + { + ricevi_movPN(key,sigla); + _sld.registra(); + } + else + if (sigla == 'U') + ricevi_movIVA(key,sigla); + } + delete _prog; + key = ""; //Altrimenti in caso di ripartenza mi ripristina sempre la situazione + } +} + +void TRic_tab::ricevi_causali(TString& key, char uselab) +{ + TString str; + + char flag = _tras_file.flg_agg(uselab); + + _tcaus->setkey(1); + + if (key.empty()) + _tcaus->first(); + else + { + TString causale (key.mid(0,3)); + _tcaus->zero(); + _tcaus->put(CAU_CODCAUS, causale); + _tcaus->read(); + } + + for(; !_tcaus->eof(); _tcaus->next()) + { + _prog->addstatus(1); + + TString codcaus = _tcaus->get(CAU_CODCAUS); + + _caus->curr() = _tcaus->curr(); + + if (_caus->read() == NOERR) // Esiste la testata + { + if (flag == 'N') + { + leggi_record_controllo(); + TString chiave; + chiave.format("%3s",(const char*) codcaus); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + continue; + } + else + if (flag == 'D') + { + TString descr = _tcaus->get(CAU_DESCR); + + _caus->put(CAU_DESCR, descr); + _caus->rewrite(); + } + else + if (flag == 'T') + { + scrivi_righe_causali(codcaus,uselab); + + _caus->zero(); + _caus->curr() = _tcaus->curr(); + _caus->rewrite(); + } + } + else + { + scrivi_righe_causali(codcaus,uselab); + + _caus->zero(); + _caus->curr() = _tcaus->curr(); + _caus->write(); + } + + leggi_record_controllo(); + TString chiave; + chiave.format("%3s",(const char*) codcaus); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + } +} + +void TRic_tab::cancella_righe_causali(TString& codcaus) +{ + _rcaus->setkey(1); + _rcaus->zero(); + _rcaus->put(RCA_CODCAUS, codcaus); + TRectype rcau (LF_RCAUSALI); + rcau = _rcaus->curr(); + for (_rcaus->read(); !_rcaus->eof(); _rcaus->next()) + { + if (_rcaus->curr() > rcau) break; + + _rcaus->remove(); + } +} + +void TRic_tab::scrivi_righe_causali(TString& codcaus, char uselab) +{ + TString str; + + cancella_righe_causali(codcaus); + + _trcaus->setkey(1); + _trcaus->zero(); + _trcaus->put(RCA_CODCAUS, codcaus); + TRectype rcau (LF_RCAUSALI); + rcau = _trcaus->curr(); + for (_trcaus->read(); !_trcaus->eof(); _trcaus->next()) + { + if (_trcaus->curr() > rcau) break; + + _rcaus->curr() = _trcaus->curr(); + _rcaus->write(); + + leggi_record_controllo(); + TString chiave; + chiave.format("%3s",(const char*) codcaus); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + } +} + +void TRic_tab::ricevi_clifo(TString& key, char uselab) +{ + TString str; + + char flag = _tras_file.flg_agg(uselab); + + _tclifo->setkey(1); + + if (key.empty()) + _tclifo->first(); + else + { + char tipo = (key.mid(0,1))[0]; + long codice = atol(key.mid(1,6)); + _tclifo->zero(); + _tclifo->put(CLI_TIPOCF, tipo); + _tclifo->put(CLI_CODCF, codice); + _tclifo->read(); + } + + for(; !_tclifo->eof(); _tclifo->next()) + { + _prog->addstatus(1); + + char tipocf = _tclifo->get_char(CLI_TIPOCF); + long codcf = _tclifo->get_long(CLI_CODCF); + + _clifo->curr() = _tclifo->curr(); + + if (_clifo->read() == NOERR) // Esiste gia' il cliente + { + if (flag == 'N') + { + leggi_record_controllo(); + TString chiave; + chiave.format("%c%06ld", tipocf,codcf); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + continue; + } + else + if (flag == 'D') + { + TString ragsoc = _tclifo->get(CLI_RAGSOC); + TString ind = _tclifo->get(CLI_INDCF); + TString civ = _tclifo->get(CLI_CIVCF); + TString com = _tclifo->get(CLI_COMCF); + TString cap = _tclifo->get(CLI_CAPCF); + TString cofi = _tclifo->get(CLI_COFI); + TString paiv = _tclifo->get(CLI_PAIV); + TString ptel = _tclifo->get(CLI_PTEL); + TString tel = _tclifo->get(CLI_TEL); + + _clifo->put(CLI_RAGSOC, ragsoc); + _clifo->put(CLI_INDCF, ind); + _clifo->put(CLI_CIVCF, civ); + _clifo->put(CLI_COMCF, com); + _clifo->put(CLI_CAPCF, cap); + _clifo->put(CLI_COFI, cofi); + _clifo->put(CLI_PAIV, paiv); + _clifo->put(CLI_PTEL, ptel); + _clifo->put(CLI_TEL, tel); + + _clifo->rewrite(); + } + else + if (flag == 'T') + { + _clifo->zero(); + _clifo->curr() = _tclifo->curr(); + _clifo->rewrite(); + } + } + else + { + _clifo->zero(); + _clifo->curr() = _tclifo->curr(); + _clifo->write(); + } + + leggi_record_controllo(); + TString chiave; + chiave.format("%c%06ld", tipocf, codcf); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + } +} + +void TRic_tab::ricevi_pcon(TString& key, char uselab) +{ + TString str; + bool esiste; + TRectype pcon (LF_PCON); + + char flag = _tras_file.flg_agg(uselab); + char f_IV = _tras_file.flg_agg_IV(uselab); + + _tpcon->setkey(1); + + if (key.empty()) + _tpcon->first(); + else + { + int gruppo = atoi(key.mid(0,3)); + int conto = atoi(key.mid(3,3)); + long sottoc = atol(key.mid(6,6)); + + _tpcon->zero(); + _tpcon->put(PCN_GRUPPO, gruppo); + if (conto != 0) + _tpcon->put(PCN_CONTO, conto); + if (sottoc != 0) + _tpcon->put(PCN_SOTTOCONTO, sottoc); + _tpcon->read(); + } + + for(; !_tpcon->eof(); _tpcon->next()) + { + _prog->addstatus(1); + + int g = _tpcon->get_int (PCN_GRUPPO); + int c = _tpcon->get_int (PCN_CONTO); + long s = _tpcon->get_long(PCN_SOTTOCONTO); + + _pcon->curr() = _tpcon->curr(); + + if (_pcon->read() == NOERR) // Esiste gia' sul Piano dei Conti + { + esiste = TRUE; + + if (flag == 'N') + { + leggi_record_controllo(); + TString chiave; + chiave.format("%03d%03d%06ld", g, c, s); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + continue; + } + else + if (flag == 'D') + { + TString descr = _tpcon->get(PCN_DESCR); + + _pcon->put(PCN_DESCR, descr); + _pcon->rewrite(); + } + else + if (flag == 'T') + scrivi_pcon(pcon,esiste); + } + else // Non esiste sull'archivio effettivo + { + esiste = FALSE; + scrivi_pcon(pcon,esiste); + } + + TRecnotype rec; + if (esiste) + rec = _pcon->recno(); + + if (f_IV == 'T') + { + if (g != 0 && c == 0) + conto(pcon,flag,esiste); + if (g != 0 && c != 0 && s != 0) + sottoconto(pcon,flag,esiste); + } + + if (esiste) + _pcon->readat(rec); + + if ( (flag == 'T' && esiste) || !esiste) + _pcon->curr() = pcon; + + if (esiste) + _pcon->rewrite(); + else + _pcon->write(); + + leggi_record_controllo(); + TString chiave; + chiave.format("%03d%03d%06ld", g, c, s); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + } +} + +void TRic_tab::scrivi_pcon(TRectype& pcon,bool esiste) +{ + int g = _tpcon->get_int (PCN_GRUPPO); + int c = _tpcon->get_int (PCN_CONTO); + long s = _tpcon->get_long(PCN_SOTTOCONTO); + TString descr = _tpcon->get (PCN_DESCR); + int indbil = _tpcon->get_int (PCN_INDBIL); + char tmcf = _tpcon->get_char(PCN_TMCF); + bool stsottbil = _tpcon->get_bool(PCN_STSOTTBIL); + bool compens = _tpcon->get_bool(PCN_COMPENS); + int tipospric = _tpcon->get_int (PCN_TIPOSPRIC); + TString codcbl = _tpcon->get (PCN_CODCBL); + bool stsottab = _tpcon->get_bool(PCN_STSOTTAB); + char sezsaldi = _tpcon->get_char(PCN_SEZSALDI); + bool sospeso = _tpcon->get_bool(PCN_SOSPESO); + int ricser = _tpcon->get_int (PCN_RICSER); + + pcon.zero(); + pcon.put(PCN_GRUPPO, g); + if (c != 0) + pcon.put(PCN_CONTO, c); + if (s != 0) + pcon.put(PCN_SOTTOCONTO, s); + pcon.put(PCN_DESCR, descr); + pcon.put(PCN_INDBIL, indbil); + pcon.put(PCN_TMCF, tmcf); + pcon.put(PCN_STSOTTBIL, stsottbil); + pcon.put(PCN_COMPENS, compens); + pcon.put(PCN_TIPOSPRIC, tipospric); + pcon.put(PCN_CODCBL, codcbl); + pcon.put(PCN_STSOTTAB, stsottab); + pcon.put(PCN_SEZSALDI, sezsaldi); + pcon.put(PCN_SOSPESO, sospeso); + pcon.put(PCN_RICSER, ricser); +} + +void TRic_tab::conto(TRectype& pcon,char flag,bool esiste) +{ + int g = _tpcon->get_int(PCN_GRUPPO); + int c = _tpcon->get_int(PCN_CONTO); + + TString sez = _tpcon->get (PCN_SEZIVD); + TString let = _tpcon->get (PCN_LETTIVD); + TString numr = _tpcon->get (PCN_NUMRIVD); + int num = _tpcon->get_int(PCN_NUMIVD); + + if (sez.not_empty()) + { + if (!esiste || (esiste && flag == 'T') ) + { + pcon.put (PCN_SEZIVD, sez); + pcon.put (PCN_LETTIVD, let); + pcon.put (PCN_NUMRIVD, numr); + pcon.put (PCN_NUMIVD, num); + pcon.zero(PCN_SEZIVDOPP); + pcon.zero(PCN_LETTIVDOPP); + pcon.zero(PCN_NUMRIVDOPP); + pcon.zero(PCN_NUMIVDOPP); + + _tras_file.annulla_classi(g,c,TRUE); + } + } + else + { + if (esiste && flag == 'T') + { + pcon.put (PCN_SEZIVD, sez); + pcon.put (PCN_LETTIVD, let); + pcon.put (PCN_NUMRIVD, numr); + pcon.put (PCN_NUMIVD, num); + pcon.zero(PCN_SEZIVDOPP); + pcon.zero(PCN_LETTIVDOPP); + pcon.zero(PCN_NUMRIVDOPP); + pcon.zero(PCN_NUMIVDOPP); + + _tras_file.annulla_classi(g,c,TRUE); + } + } +} + +void TRic_tab::sottoconto(TRectype& pcon,char flag,bool esiste) +{ + int g = _tpcon->get_int(PCN_GRUPPO); + int c = _tpcon->get_int(PCN_CONTO); + + TString sez = _tpcon->get (PCN_SEZIVD); + TString let = _tpcon->get (PCN_LETTIVD); + TString numr = _tpcon->get (PCN_NUMRIVD); + int num = _tpcon->get_int(PCN_NUMIVD); + TString sezop = _tpcon->get (PCN_SEZIVDOPP); + TString letop = _tpcon->get (PCN_LETTIVDOPP); + TString numrop = _tpcon->get (PCN_NUMRIVDOPP); + int numop = _tpcon->get_int(PCN_NUMIVDOPP); + + if (sez.not_empty()) + { + if (!esiste || (esiste && flag == 'T') ) + { + pcon.put(PCN_SEZIVD, sez); + pcon.put(PCN_LETTIVD, let); + pcon.put(PCN_NUMRIVD, numr); + pcon.put(PCN_NUMIVD, num); + pcon.put(PCN_SEZIVDOPP, sezop); + pcon.put(PCN_LETTIVDOPP, letop); + pcon.put(PCN_NUMRIVDOPP, numrop); + pcon.put(PCN_NUMIVDOPP, numop); + + _tras_file.annulla_classi(g,c,FALSE); + } + } + else + { + if (sezop.not_empty()) + { + if (!esiste || (esiste && flag == 'T') ) + { + pcon.put(PCN_SEZIVDOPP, sezop); + pcon.put(PCN_LETTIVDOPP, letop); + pcon.put(PCN_NUMRIVDOPP, numrop); + pcon.put(PCN_NUMIVDOPP, numop); + } + } + else + { + pcon.zero(PCN_SEZIVDOPP); + pcon.zero(PCN_LETTIVDOPP); + pcon.zero(PCN_NUMRIVDOPP); + pcon.zero(PCN_NUMIVDOPP); + } + } +} + +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; +} + +long TRic_tab::ultima_registrazione() +{ + if (_nreg == 0) + { + TLocalisamfile mov (LF_MOV); + + mov.last(); + return (mov.get_long(MOV_NUMREG)); + } + else + return _nreg; +} + +void TRic_tab::num_protocollo() +{ + _protiva = _tmov->get_long(MOV_PROTIVA); + _uprotiva = _tmov->get_long(MOV_UPROTIVA); + + if (_protiva == 0) + _uprotiva = 0; + + _nprotiva = _protiva; + _nuprotiva = _uprotiva; +} + +long TRic_tab::ulnumprot_reg(int anno,TString& cr) +{ + TRegistro rg (cr, anno); + + return rg.protocol(); +} + +void TRic_tab::aggiorna_reg(int anno,TString& codreg,long ulnum) +{ + TTable reg ("REG"); + TString16 dep; + + if (real::is_natural(codreg)) + dep.format("%04d%03s", anno,(const char*) codreg); + else + dep.format("%04d%-3s", anno,(const char*) codreg); + + reg.zero(); + reg.put("CODTAB", (const char*) dep); + if (reg.read() == NOERR) + { + if (_nprotiva > ulnum ) + reg.put("I5", _nprotiva); + + if (_nuprotiva > ulnum ) + reg.put("I5", _nuprotiva); + + reg.rewrite(); + } +} + +long TRic_tab::controlli_primanota() +{ + TTable tpd ("%TPD"); + bool corrisp = FALSE; + TDate datareg; + int anno; + long ulnum = 0; + TString16 tmp; + TString tipodoc,codreg; + + char tipocf = _tmov->get_char(MOV_TIPO); + int tiporeg; + if (tipocf == 'C') + tiporeg = 1; + else + if (tipocf == 'F') + tiporeg = 2; + + codreg = _tmov->get(MOV_REG); + tipodoc = _tmov->get(MOV_TIPODOC); + + datareg = _tmov->get_date(MOV_DATAREG); + anno = datareg.year(); + + tpd.zero(); + tpd.put("CODTAB", (const char*) tipodoc); + if (tpd.read() == NOERR) + corrisp = tpd.get_bool("B0"); + + if (codreg.not_empty() && !corrisp) + { + if ( ( (tiporeg == 1 && (_nprot_att || _protiva == 0) ) ) + || ( (tiporeg == 2 && (_nprot_pas || _protiva == 0) ) ) ) + { + ulnum = ulnumprot_reg(anno,codreg); + _nprotiva = ulnum + 1; + if (_uprotiva != 0) + _nuprotiva = (_nprotiva - ulnum) + _uprotiva; + } + } + + return ulnum; +} + +char TRic_tab::ricerca_causale(TString& causale) +{ + TLocalisamfile cau (LF_CAUSALI); + char movap = ' '; + + if (real::is_natural(causale)) + causale.format("%03s", (const char*) causale); + else + causale.format("%-3s", (const char*) causale); + + cau.setkey(1); + cau.zero(); + cau.put("CODCAUS", causale); + if (cau.read() == NOERR) + movap = cau.get_char("MOVAP"); + + return movap; +} + +void TRic_tab::scrivi_righePN(long numreg) +{ + TString str; + + _trmov->setkey(1); + _trmov->zero(); + _trmov->put(RMV_NUMREG, numreg); + TRectype rmov (LF_RMOV); + rmov = _trmov->curr(); + for (_trmov->read(); !_trmov->eof(); _trmov->next()) + { + if (_trmov->curr() > rmov) break; + + int g = _trmov->get_int (RMV_GRUPPO); + int c = _trmov->get_int (RMV_CONTO); + long s = _trmov->get_long(RMV_SOTTOCONTO); + char sez = _trmov->get_char(RMV_SEZIONE); + real imp ( _trmov->get_real(RMV_IMPORTO) ); + + _trmov->put(RMV_NUMREG, _nreg); + _rmov->curr() = _trmov->curr(); + _rmov->write(); + + _sld.aggiorna(g,c,s,imp,sez); + } +} + +void TRic_tab::ricevi_movPN(TString& key, char uselab) +{ + TString str; + long numulreg; + TRectype recmov (LF_MOV); + + char flag = _tras_file.flg_agg(uselab); + + _nprot_att = _tras_file.numprot_att(); + _nprot_pas = _tras_file.numprot_pas(); + + _tmov->setkey(1); + + if (key.empty()) + _tmov->first(); + else + { + long numreg = atol(key.mid(0,7)); + _tmov->zero(); + _tmov->put(MOV_NUMREG, numreg); + _tmov->read(); + } + + for(; !_tmov->eof(); _tmov->next()) + { + _prog->addstatus(1); + + long nreg = _tmov->get_long(MOV_NUMREG); + long nuova_reg = _tmov->get_long("TNUMREG" ); + + if (nuova_reg == 0) + { + numulreg = ultima_registrazione(); // reperisco il numero ultima registrazione + _nreg = esiste_numreg(numulreg); + } + else + _nreg = nuova_reg; + + TRecnotype rec = _tmov->recno(); // Salvo il nuovo numero di + _tmov->put("TNUMREG", _nreg); // registrazione sul file di lavoro + _tmov->rewrite(); + _tmov->readat(rec); + + int annoes = _tmov->get_int(MOV_ANNOES); + + recmov = _tmov->curr(); + + _mov->setkey(1); + _mov->zero(); + _mov->put(MOV_NUMREG, _nreg); + + if (_mov->read() != NOERR) // Se non esiste la testata + { + num_protocollo(); // Riattribuzione numero di protocollo + long ulnum = controlli_primanota(); + + recmov.put(MOV_NUMREG, _nreg); + recmov.put(MOV_PROTIVA, _nprotiva); + recmov.put(MOV_UPROTIVA, _nuprotiva); + + _mov->zero(); + _mov->curr() = recmov; + _mov->write(); + + TString codreg (_tmov->get (MOV_REG)); + TString codcaus (_tmov->get (MOV_CODCAUS)); + TDate datareg (_tmov->get_date(MOV_DATAREG)); + int anno = datareg.year(); + + aggiorna_reg(anno,codreg,ulnum); // Aggiorna il registro + + _sld.set_anno_es(annoes); + _sld.set_movprovv(FALSE); + _sld.set_num_ulmov(_nreg); + _sld.set_data_ulmov(datareg); + char movap = ricerca_causale(codcaus); + if (movap == 'A') + _sld.set_movap(TRUE); + + scrivi_righePN(nreg); + + _sld.registra(); + _sld.reset(); + } + + leggi_record_controllo(); + TString chiave; + chiave.format("%07ld", nreg); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + } +} + +bool TRic_tab::occasionali(TString& ocfpi) +{ + TString chiave; + long prog = 0; + bool esiste = FALSE; + bool ric = TRUE; + + TString ocfpitemp = ocfpi; + + if (ocfpi.mid(0,3) == "RIC") + { +// TString nocfpi = _tmov->get("TOCFP"); +// nocfpi.trim(); + +// if (nocfpi.empty()) +// { + _occas->setkey(1); + _occas->zero(); + for (_occas->first(); !_occas->eof(); _occas->next()) + { + TString cfpi = _occas->get(OCC_CFPI); + if (cfpi.mid(0,3) == "RIC") + prog = atol(cfpi.mid(3,13)); + } + prog++; + + chiave = format("%3s%13ld", (const char*) "RIC", prog); + + esiste = FALSE; + ocfpi = chiave; + } + else + { + _occas->setkey(1); + _occas->zero(); + _occas->put("CFPI", ocfpi); + if (_occas->read() == NOERR) + { + TRecnotype rec = _occas->recno(); + _occas->setkey(1); + _occas->zero(); + for (_occas->first(); !_occas->eof(); _occas->next()) + { + TString cfpi = _occas->get(OCC_CFPI); + if (cfpi.mid(0,3) == "RIC") + prog = atol(cfpi.mid(3,13)); + } + prog++; + chiave = format("%3s%13ld", (const char*) "RIC", prog); + ocfpi = chiave; + _occas->readat(rec); + } + } +// } +// else +// { +// _occas->setkey(1); +// _occas->zero(); +// _occas->put("CFPI", nocfpi); +// _occas->read(); + +// esiste = TRUE; +// ocfpi = nocfpi; +// } + + _toccas->setkey(1); + _toccas->zero(); + _toccas->put(OCC_CFPI, ocfpitemp); + _toccas->read(); + + _occas->curr() = _toccas->curr(); + + if (esiste) + _occas->rewrite(); + else + { + _occas->put(OCC_CFPI, ocfpi); + _occas->write(); + } + + return TRUE; +} + +void TRic_tab::scrivi_righeIVA(long numreg) +{ + TString str; + + _triva->setkey(1); + _triva->zero(); + _triva->put(RMI_NUMREG, numreg); + TRectype riva (LF_RMOVIVA); + riva = _triva->curr(); + for (_triva->read(); !_triva->eof(); _triva->next()) + { + if (_triva->curr() > riva) break; + + _triva->put(RMI_NUMREG, _nuovareg); + _rmoviva->curr() = _triva->curr(); + _rmoviva->write(); + } +} + +void TRic_tab::ricevi_movIVA(TString& key, char uselab) +{ + TString str; + TRectype recmov (LF_MOV); + + char flag = _tras_file.flg_agg(uselab); + + _tmov->setkey(1); + + if (key.empty()) + _tmov->first(); + else + { + long numreg = atol(key.mid(0,7)); + _tmov->zero(); + _tmov->put(MOV_NUMREG, numreg); + _tmov->read(); + } + + for(; !_tmov->eof(); _tmov->next()) + { + _prog->addstatus(1); + + long nreg = _tmov->get_long(MOV_NUMREG); + + TString codreg = _tmov->get(MOV_REG); + TString codcau = _tmov->get(MOV_CODCAUS); + + if (codreg.empty() || codcau.empty()) continue; + + _nuovareg = _tmov->get_long("TNUMREG"); + TString ocfpi = _tmov->get(MOV_OCFPI); + + if (ocfpi.not_empty()) + occasionali(ocfpi); + +// TRecnotype rec = _tmov->recno(); // Salvo il nuovo numero di +// _tmov->put("TOCFP", ocfpi); // registrazione sul file di lavoro +// _tmov->rewrite(); +// _tmov->readat(rec); + + TDate data74ter ( _tmov->get_date(MOV_DATA74TER) ); + TString codval ( _tmov->get (MOV_CODVALI) ); + long codcf = _tmov->get_long(MOV_CODCF); + real totdoc ( _tmov->get_real(MOV_TOTDOC) ); + real cambioi ( _tmov->get_real(MOV_CAMBIOI) ); + real corrlire ( _tmov->get_real(MOV_CORRLIRE) ); + real corrval ( _tmov->get_real(MOV_CORRVALUTA) ); + int annoiva = _tmov->get_int (MOV_ANNOIVA); + + _mov->setkey(1); + _mov->zero(); + _mov->put(MOV_NUMREG, _nuovareg); + + if (_mov->read() == NOERR) // Se non esiste la testata + { + _mov->put(MOV_DATA74TER, data74ter); + _mov->put(MOV_CODVALI, codval); + _mov->put(MOV_CODCF, codcf); + _mov->put(MOV_TOTDOC, totdoc); + _mov->put(MOV_CAMBIOI, cambioi); + _mov->put(MOV_CORRLIRE, corrlire); + _mov->put(MOV_CORRVALUTA, corrval); + _mov->put(MOV_ANNOIVA, annoiva); + _mov->put(MOV_OCFPI, ocfpi); + _mov->rewrite(); + + scrivi_righeIVA(nreg); + } + + leggi_record_controllo(); + TString chiave; + chiave.format("%07ld", nreg); + TString sigla (format("%c", uselab)); + str = _record.overwrite(sigla,240); + str = _record.overwrite(chiave,241); + _tras_file.write_control_rec(str,1024); + } +} + +bool TRic_tab::leggi_trasfer() +{ + _nultras = 0; + + _trasf = _tras_file.path(_dittaric); + _trasf << HEADER; + + _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(); + _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 ("cg6600a"); + 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 = 1024; + + _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 == "*") + { + warning_box("Trasferimento interamente completato: proseguire per cancellare il file"); + _tras_file.remove_all(); + setta_parametri_record(" "," "); + return FALSE; + } + + 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"); + _tras_file.remove_all(); + setta_parametri_record(" "," "); + return FALSE; + } + } + + return TRUE; +} + +void TRic_tab::apri_file_temp() +{ + if (_scelta == 'T') + { + TString80 tmpcaus = "%"; + tmpcaus << get_firm_dir(); + tmpcaus << "\\" << TEMP_CAUS; + _tmpcaus = tmpcaus.mid(1); + _tmpcaus << ".dbf"; + if(fexist(_tmpcaus)) + _tcaus = new TIsamtempfile(LF_CAUSALI, tmpcaus, 0); + TString80 tmprcaus = "%"; + tmprcaus << get_firm_dir(); + tmprcaus << "\\" << TEMP_RCAUS; + _tmprcaus = tmprcaus.mid(1); + _tmprcaus << ".dbf"; + if (fexist(_tmprcaus)) + _trcaus = new TIsamtempfile(LF_RCAUSALI, tmprcaus, 0); + TString80 tmpclifo = "%"; + tmpclifo << get_firm_dir(); + tmpclifo << "\\" << TEMP_CLIFO; + _tmpclifo = tmpclifo.mid(1); + _tmpclifo << ".dbf"; + if (fexist(_tmpclifo)) + _tclifo = new TIsamtempfile(LF_CLIFO, tmpclifo, 0); + TString80 tmppcon = "%"; + tmppcon << get_firm_dir(); + tmppcon << "\\" << TEMP_PCON; + _tmpcon = tmppcon.mid(1); + _tmpcon << ".dbf"; + if (fexist(_tmpcon)) + _tpcon = new TIsamtempfile(LF_PCON, tmppcon, 0); + } + else + { + TString80 tmpmov = "%"; + tmpmov << get_firm_dir(); + tmpmov << "\\" << TEMP_MOV; + _tmpmov = tmpmov.mid(1); + _tmpmov << ".dbf"; + if (fexist(_tmpmov)) + _tmov = new TIsamtempfile(LF_MOV, tmpmov, 0); + TString80 tmprmov = "%"; + tmprmov << get_firm_dir(); + tmprmov << "\\" << TEMP_RMOV; + _tmprmov = tmprmov.mid(1); + _tmprmov << ".dbf"; + if (fexist(_tmprmov)) + _trmov = new TIsamtempfile(LF_RMOV, tmprmov, 0); + TString80 tmpriva = "%"; + tmpriva << get_firm_dir(); + tmpriva << "\\" << TEMP_RMOVIVA; + _tmpriva = tmpriva.mid(1); + _tmpriva << ".dbf"; + if (fexist(_tmpriva)) + _triva = new TIsamtempfile(LF_RMOVIVA, tmpriva, 0); + TString80 tmpoccas = "%"; + tmpoccas << get_firm_dir(); + tmpoccas << "\\" << TEMP_OCC; + _tmpoccas = tmpoccas.mid(1); + _tmpoccas << ".dbf"; + if (fexist(_tmpoccas)) + _toccas = new TIsamtempfile(LF_OCCAS, tmpoccas, 0); + } +} + +void TRic_tab::chiudi_file_temp() +{ + if (_scelta == 'T') + { + if (fexist(_tmpcaus)) + delete _tcaus; + if (fexist(_tmprcaus)) + delete _trcaus; + if (fexist(_tmpclifo)) + delete _tclifo; + if (fexist(_tmpcon)) + delete _tpcon; + } + else + { + if (fexist(_tmpmov)) + delete _tmov; + if (fexist(_tmprmov)) + delete _trmov; + if (fexist(_tmpriva)) + delete _triva; + if (fexist(_tmpoccas)) + delete _toccas; + } +} + +bool TRic_tab::menu(MENU_TAG m) +{ + if (m == BAR_ITEM(1)) + return main_loop(); + return FALSE; +} + +int cg6600 (int argc, char* argv[]) +{ + char p3 = '\0'; + + if (argc > 4) + p3 = *argv[3]; + + TRic_tab main_app(*argv[2],p3); + main_app.run(argc, argv,main_app._titolo); + return TRUE; +} +>>>>>>> 1.6 +======= // Ricezione dati da sistema #include @@ -1536,3 +4573,4 @@ int cg6600 (int argc, char* argv[]) main_app.run(argc, argv,main_app._titolo); return TRUE; } +>>>>>>> 1.8 diff --git a/cg/cg6900.cpp b/cg/cg6900.cpp index 38d3ab7ee..1409b61f3 100755 --- a/cg/cg6900.cpp +++ b/cg/cg6900.cpp @@ -1,1603 +1,1603 @@ -// Invio contabilita' - -#include "cg6900.h" -#include "cg6900a.h" - -TInv_cont::TInv_cont(char mov) : _scelta(toupper(mov)) -{ - switch (_scelta) - { - case 'S': - _titolo = "Invio a Sistema"; - break; - case 'P': - _titolo = "Invio a PC"; - break; - default: - break; - } -} - -bool TInv_cont::messaggio_hnd(TMask_field& f, KEY k) -{ - if (k == K_TAB) - return message_box("Rilevato STATO DI RIPARTENZA: il trasferimento ripartira' automaticamente"); - - return TRUE; -} - -bool TInv_cont::main_loop() -{ - TString str; - bool ripartenza = FALSE; - - if (!esiste_tabella_studio()) return FALSE; - - if (!esegui_controlli()) return FALSE; - - TMask msk ("cg6900a"); - KEY tasto; - - if (_ditta != 0) - { - msk.set(F_DITTAINV, _ditta); - msk.disable(F_DITTAINV); - codifica_ditta(msk); - msk.set(F_NUMULINV, _num); - msk.set(F_DATAULIN, _data.string()); - msk.set(F_STATO, _stato); - - TString uselab = _tras_file.ult_file(); - TString chiave = _tras_file.key(); - msk.set(F_USELAB, uselab); - msk.set(F_CHIAVE, chiave); - msk.set(F_DATALIM, _data.string()); - msk.disable(F_DATALIM); - - if (_scelta == 'S' && _ditta > 9999) - { - msk.show(F_DITTAAS); - msk.disable(F_DITTAAS); - long ditta = atol(_control_rec.sub(300,304)); - msk.set(F_DITTAAS, ditta); - } - else - msk.hide(F_DITTAAS); - - ripartenza = TRUE; - } - - msk.disable(F_NUMULINV); - msk.disable(F_DATAULIN); - msk.disable(F_STATO); - msk.disable(F_USELAB); - msk.disable(F_CHIAVE); - - if (!ripartenza) - msk.set_handler(F_DITTAINV, setta_maschera_hnd); - else - msk.set_handler(F_NUMULINV, messaggio_hnd); - - tasto = msk.run(); - - if (tasto != K_ENTER) return FALSE; - - _dittaAS = msk.get_long(F_DITTAAS); //Se la ditta per l'invio ad AS non viene compilata perche' trattasi di invio a PC - if (_dittaAS == 0) //o perche' il codice e' di 4, gli assegno la ditta corrente. Nel caso di invio a - _dittaAS = _ditta; //PC non servirebbe il codice aggiuntivo, ma lo metto ugualmente per avere una situazione analoga - -// Nel caso di invio PC --> SISTEMA eseguo prima la -// Lista controllo archivi per rilevare eventuali -// differenze. - - long ditta = msk.get_long(F_DITTAINV); - set_firm(ditta); - - TConfig conf(CONFIG_DITTA); - TString std = conf.get("FlStInv"); - - if (_scelta == 'S' && std != "D") - { - TString appname = "cg6 -8 L"; - TString corpo = ""; - - TDate data = msk.get(F_DATALIM); - - corpo << data.string(); - - TMessage mess (appname,"",(const char*)corpo); - TMailbox mb; - mb.send(mess); - - TExternal_app a (appname); - a.run(); - - TMailbox m; - TMessage* msg = m.next_s(""); - int subj; - - if (msg != NULL) - { - subj = atoi(msg->body()); - if (subj) - return FALSE; - } - } - - _datalimsk = msk.get(F_DATALIM); - - if (!ripartenza) - { - crea_marker(msk); //Crea il record con le informazioni sul marker - setta_parametri_record(msk,"F"); //Aggiorna parametri contabili ditta - setta_tabella_studio(msk); //Aggiorna la tabella studio per invio - setta_tabella_ditta(msk,"F"); //Aggiorna la tabella ditta per invio - crea_record_controllo(msk); //Crea il record di controllo sul file header - } - else - { - TString str,app; - - int num = msk.get_int(F_NUMULINV); - TString data (msk.get(F_DATALIM)); - if (_scelta == 'S') - { - app = riconverti(data,FALSE); - str.format("%03d%6s", num, (const char*) app); - aggiorna_marker(str,14); - } - else - if (_scelta == 'P') - { - app = riconverti(data,TRUE); - str.format("%03d%8s", num, (const char*) app); - aggiorna_marker(str,15); - } - } - - apri_file_temp(); - - if (!invio_tempfile(msk)) - return FALSE; - -// calcola_totale_record(); -// str.format("%06ld", _tot_rec); - - if (_scelta == 'S') - { -// aggiorna_marker(str,23); - - _trasf = ""; - _trasf = firm2dir(0); - _trasf << "\\trasfer"; - fremove(_trasf); - _tras_file.open(_trasf,TRUE); - -// if (std != "D") - invio_contabilita(); //Costruisce il trasfer nella directory comune - - TMask mask ("cg6900b"); - KEY k; - - k = mask.run(); - - if (k == K_ENTER) - { - int num_disk = calcola_numero_dischi(mask); - char floppy = mask.get(F_FLOPPY)[0]; - - str.format("%02d", num_disk); - aggiorna_marker(str,29); - - const TFilename from(_trasf); // File da splittare - - TFilename work; - work << floppy << ":/" << from.name(); // File su dischetto - - FILE* i = fopen(from, "rb"); - - if (i == NULL) return error_box("Impossibile aprire il file '%s'", from); - - TProgind w(_dim_tot, "Trasferimento su dischetti in corso... Prego attendere", TRUE, TRUE, 60); - - for (int j = 0; j < num_disk; j++) - { - scrivi_disco(floppy,j+1,work,i,w); - } - fclose(i); - - setta_tabella_studio(msk,FALSE); //Aggiorna la tabella studio per invio - setta_tabella_ditta(msk," ",FALSE); //Aggiorna la tabella ditta per invio - setta_parametri_record(msk," "); //Aggiorna parametri contabili ditta - - _tras_file.open(_header); - leggi_record_controllo(); - TString record(1024); - record.spaces(); - _control_rec.overwrite(record,0); - _tras_file.write_control_rec(_control_rec,1024); - - chiudi_file_temp(); - } - else - return FALSE; - } - else - if (_scelta == 'P') - { - _trasf = ""; - _trasf = firm2dir(0); - _trasf << "\\trasfer"; - fremove(_trasf); - _tras_file.open(_trasf,TRUE); - - invio_contabilita_PC(); //Costruisce il trasfer nella directory comune - - TMask mask ("cg6900b"); - KEY k; - - k = mask.run(); - - if (k == K_ENTER) - { - int num_disk = calcola_numero_dischi(mask); - char floppy = mask.get(F_FLOPPY)[0]; - - str.format("%02d", num_disk); - aggiorna_marker(str,32); - - const TFilename from(_trasf); // File da splittare - - TFilename work; - work << floppy << ":/" << from.name(); // File su dischetto - - FILE* i = fopen(from, "rb"); - - if (i == NULL) return error_box("Impossibile aprire il file '%s'", from); - - TProgind w(_dim_tot, "Trasferimento su dischetti in corso... Prego attendere", TRUE, TRUE, 60); - - for (int j = 0; j < num_disk; j++) - { - scrivi_disco(floppy,j+1,work,i,w); - } - fclose(i); - - setta_tabella_studio(msk,FALSE); //Aggiorna la tabella studio per invio - setta_tabella_ditta(msk," ",FALSE); //Aggiorna la tabella ditta per invio - setta_parametri_record(msk," "); //Aggiorna parametri contabili ditta - - _tras_file.open(_header); - leggi_record_controllo(); - TString record(1024); - record.spaces(); - _control_rec.overwrite(record,0); - _tras_file.write_control_rec(_control_rec,1024); - - chiudi_file_temp(); - } - else - return FALSE; - } - - _tras_file.remove_all(FALSE); - fremove(_marker); - _trasf = ""; - _trasf = firm2dir(0); - _trasf << "\\trasfer"; - fremove(_trasf); - - return FALSE; -} - -bool TInv_cont::create() -{ - TApplication::create(); - - _caus = new TLocalisamfile (LF_CAUSALI); - _rcaus = new TLocalisamfile (LF_RCAUSALI); - _clifo = new TLocalisamfile (LF_CLIFO); - _pcon = new TLocalisamfile (LF_PCON); - _mov = new TLocalisamfile (LF_MOV); - _rmov = new TLocalisamfile (LF_RMOV); - _rmoviva = new TLocalisamfile (LF_RMOVIVA); - _occas = new TLocalisamfile (LF_OCCAS); - _part = new TLocalisamfile (LF_PARTITE); - - dispatch_e_menu (BAR_ITEM(1)); - - return TRUE; -} - -bool TInv_cont::destroy() -{ - delete _caus; - delete _rcaus; - delete _clifo; - delete _pcon; - delete _mov; - delete _rmov; - delete _rmoviva; - delete _occas; - delete _part; - - return TApplication::destroy(); -} - -void TInv_cont::apri_file_temp() -{ - _tras_file.open(_header); - leggi_record_controllo(); - _sigle = _tras_file.sigle_file(); - _sigle.trim(); - - for (int i = 0; i < _sigle.len(); i++) - { - TString80 tmp; - char sigla = _sigle[i]; - - if (sigla == 'W') - { - TString80 tmpcaus = "%"; - tmpcaus << firm2dir(0); - tmpcaus << "\\" << TEMP_CAUS; - tmp = tmpcaus.mid(1); - tmp << ".dbf"; - if (fexist(tmp)) - _tcaus = new TIsamtempfile(LF_CAUSALI, tmpcaus, FALSE); - else - _tcaus = new TIsamtempfile(LF_CAUSALI, tmpcaus, TRUE); - TString80 tmprcaus = "%"; - tmprcaus << firm2dir(0); - tmprcaus << "\\" << TEMP_RCAUS; - tmp = tmprcaus.mid(1); - tmp << ".dbf"; - if (fexist(tmp)) - _trcaus = new TIsamtempfile(LF_RCAUSALI, tmprcaus, FALSE); - else - _trcaus = new TIsamtempfile(LF_RCAUSALI, tmprcaus, TRUE); - } - if (sigla == 'A') - { - TString80 tmpclifo = "%"; - tmpclifo << firm2dir(0); - tmpclifo << "\\" << TEMP_CLIFO; - tmp = tmpclifo.mid(1); - tmp << ".dbf"; - if (fexist(tmp)) - _tclifo = new TIsamtempfile(LF_CLIFO, tmpclifo, FALSE); - else - _tclifo = new TIsamtempfile(LF_CLIFO, tmpclifo, TRUE); - } - if (sigla == 'P') - { - TString80 tmppcon = "%"; - tmppcon << firm2dir(0); - tmppcon << "\\" << TEMP_PCON; - tmp = tmppcon.mid(1); - tmp << ".dbf"; - if (fexist(tmp)) - _tpcon = new TIsamtempfile(LF_PCON, tmppcon, FALSE); - else - _tpcon = new TIsamtempfile(LF_PCON, tmppcon, TRUE); - } - if (sigla == 'Z') - { - TString80 tmpmov = "%"; - tmpmov << firm2dir(0); - tmpmov << "\\" << TEMP_MOV; - tmp = tmpmov.mid(1); - tmp << ".dbf"; - if (fexist(tmp)) - _tmov = new TIsamtempfile(LF_MOV, tmpmov, FALSE); - else - _tmov = new TIsamtempfile(LF_MOV, tmpmov, TRUE); - TString80 tmprmov = "%"; - tmprmov << firm2dir(0); - tmprmov << "\\" << TEMP_RMOV; - tmp = tmprmov.mid(1); - tmp << ".dbf"; - if (fexist(tmp)) - _trmov = new TIsamtempfile(LF_RMOV, tmprmov, FALSE); - else - _trmov = new TIsamtempfile(LF_RMOV, tmprmov, TRUE); - } - if (sigla == 'U') - { - TString80 tmpriva = "%"; - tmpriva << firm2dir(0); - tmpriva << "\\" << TEMP_RMOVIVA; - tmp = tmpriva.mid(1); - tmp << ".dbf"; - if (fexist(tmp)) - _triva = new TIsamtempfile(LF_RMOVIVA, tmpriva, FALSE); - else - _triva = new TIsamtempfile(LF_RMOVIVA, tmpriva, TRUE); - TString80 tmpoccas = "%"; - tmpoccas << firm2dir(0); - tmpoccas << "\\" << TEMP_OCC; - tmp = tmpoccas.mid(1); - tmp << ".dbf"; - if (fexist(tmp)) - _toccas = new TIsamtempfile(LF_OCCAS, tmpoccas, FALSE); - else - _toccas = new TIsamtempfile(LF_OCCAS, tmpoccas, TRUE); - } - } -} - -void TInv_cont::chiudi_file_temp() -{ - for (int i = 0; i < _sigle.len(); i++) - { - char sigla = _sigle[i]; - - if (sigla == 'W') - { - delete _tcaus; - delete _trcaus; - } - if (sigla == 'A') - delete _tclifo; - if (sigla == 'P') - delete _tpcon; - if (sigla == 'Z') - { - delete _tmov; - delete _trmov; - } - if (sigla == 'U') - { - delete _triva; - delete _toccas; - } - } -} - -void TInv_cont::leggi_record_controllo() -{ - _tras_file.read_control_rec(); - _control_rec = _tras_file.record(); -} - -bool TInv_cont::esiste_tabella_studio() -{ - TTable ins ("%INS"); - - ins.zero(); - - if (ins.first() == NOERR) - { - if (ins.empty()) - return error_box("Codice STUDIO NON ATTIVATO in tabella invii"); - else - { - _nome_simbolico = ins.get("S0"); - long ditta = ins.get_long("I0"); - if (ditta != 0) - { - _esiste_ditta = TRUE; - _ditta = ditta; - } - else - { - _esiste_ditta = FALSE; - _ditta = 0; - } - } - } - else - return error_box("Codice STUDIO NON ATTIVATO in tabella invii"); - - return TRUE; -} - -bool TInv_cont::leggi_header() -{ - _header = ""; - _header = firm2dir(0); - _header << HEADER; - - _tras_file.open(_header); - - if (_tras_file.exist()) - { - if (_tras_file.read_control_rec()) - { - _control_rec = _tras_file.record(); - if (!record_controllo()) - return FALSE; - } - else - return FALSE; - } - else - return FALSE; - - return TRUE; -} - -bool TInv_cont::record_controllo() -{ - TString tiporecord = _control_rec.sub(0,2); - - if (tiporecord != " 1") - return FALSE; - - return TRUE; -} - -bool TInv_cont::esegui_controlli() -{ - _esiste_record = leggi_header(); - - if (!controlli()) return FALSE; - - return TRUE; -} - -void TInv_cont::setta_parametri_record(TMask& m,const TString& flag) -{ - TConfig conf (CONFIG_DITTA); - conf.set("FlStInv", flag); -} - -bool TInv_cont::controlli() -{ - if (!_esiste_ditta && !_esiste_record) return TRUE; //Mi trovo in una condizione normale - - if (_esiste_ditta && !_esiste_record) - return error_box("Rilevato stato di ripartenza con dati contradditori: programma interrotto"); - - if (!_esiste_ditta && _esiste_record) - return error_box("Rilevato stato di ripartenza con dati contradditori: programma interrotto"); - - if (_esiste_ditta && _esiste_record) - { - if (!sub_controlli()) - return error_box("Rilevato stato di ripartenza con dati contradditori: programma interrotto"); - } - - return TRUE; -} - -bool TInv_cont::sub_controlli() -{ - long ditta_trasfer = _tras_file.ditta(); - - if (_ditta == ditta_trasfer) - { - if (!prefix().exist(_ditta)) - return FALSE; - - if (!tabella_ditta()) - return FALSE; - } - else - return FALSE; - - if (!controlla_stato_invio()) - return FALSE; - - if (!numero_data()) - return FALSE; - - return TRUE; -} - -bool TInv_cont::tabella_ditta() -{ - TTable ind ("%IND"); - TString dep; - - dep.format("%05d", _ditta); - - ind.zero(); - ind.put("CODTAB", dep); - if (ind.read() == NOERR) - { - _stato = ind.get("S6"); - _num = ind.get_int("I0"); - _data = ind.get_date("D0"); - - _files = ""; - if (ind.get_bool("B0") && (_caus->items() != 0) ) - _files << "W"; - - if (ind.get_bool("B1") && (_clifo->items() != 0) ) - _files << "A"; - - if (ind.get_bool("B2") && (_pcon->items() != 0) ) - _files << "P"; - - if (ind.get_bool("B3") && (_mov->items() != 0) ) - _files << "Z"; - - if (ind.get_bool("B4") && (_rmoviva->items() != 0) ) - _files << "U"; - - if (ind.get_bool("B5") && (_part->items() != 0) ) - _files << "B"; - - _flag_bollato = ind.get_bool("B7"); - - return TRUE; - } - - return FALSE; -} - -bool TInv_cont::controlla_stato_invio() -{ - set_firm(_ditta); - - TConfig conf(CONFIG_DITTA); - _std = conf.get("FlStInv"); - - if (_stato != _std) - return FALSE; - else - { - TString uselab = _tras_file.ult_file(); - - if (_stato == "D" && uselab != "") - return FALSE; - } - - return TRUE; -} - -bool TInv_cont::numero_data() -{ - int num = _tras_file.nultras(); - TString str = _tras_file.dataultras(); - TDate data (str); - - if (_num != num || data != _data) - return FALSE; - - return TRUE; -} - -void TInv_cont::codifica_ditta(TMask& m) -{ - TLocalisamfile ditte (LF_NDITTE); - - long ditta = m.get_long(F_DITTAINV); - - ditte.setkey(1); - ditte.zero(); - ditte.put(NDT_CODDITTA, ditta); - if (ditte.read() == NOERR) - { - TString ragsoc = ditte.get(NDT_RAGSOC); - m.set(F_RAGSOC, ragsoc); - } -} - -bool TInv_cont::setta_maschera_hnd(TMask_field& f, KEY k) -{ - if ( (k == K_TAB || k == K_ENTER) && f.mask().is_running()) - { - app()._ditta = f.mask().get_long(F_DITTAINV); - if (!prefix().exist(app()._ditta)) - return error_box("La ditta indicata non e' abilitata alla contabilita'"); - - if (!app().tabella_ditta()) - return error_box("La ditta indicata non e' presente sulla tabella ditta per invio"); - - if (app()._stato != "") - return error_box("Rilevato STATO DI RIPARTENZA NON RECUPERABILE sulla ditta richiesta"); - - f.mask().set(F_DITTAINV, app()._ditta); - app().codifica_ditta(f.mask()); - f.mask().set(F_NUMULINV, app()._num); - f.mask().set(F_DATAULIN, app()._data.string()); - f.mask().set(F_STATO, app()._stato); - - long ditta = atol(f.get()); - - if (app()._scelta == 'S' && ditta > 9999) - f.mask().show(F_DITTAAS); - else - f.mask().hide(F_DITTAAS); - } - - return TRUE; -} - -void TInv_cont::crea_marker(TMask& m) -{ - TString str; - - _marker = ""; - _marker = firm2dir(0); - _marker << "\\marker"; - - FILE* i; - - const word size = 64; - TString buffer(size); - buffer.spaces(); - - if ( (i = fopen(_marker,"w+t")) != NULL) - { - if (_scelta == 'S') - { - str = format("%-10s", (const char*) _nome_simbolico); - buffer.overwrite(str,0); - long ditta = m.get_long(F_DITTAINV); - if (ditta > 9999) - ditta = _dittaAS; - str = format("%04d", ditta); - buffer.overwrite(str,10); - int num = m.get_int(F_NUMULINV); - num++; - str = format("%03d", num); - buffer.overwrite(str,14); - TString data (m.get(F_DATALIM)); - str = riconverti(data,FALSE); - buffer.overwrite(str,17); - } - else - if (_scelta == 'P') - { - str = format("%-10s", (const char*) _nome_simbolico); - buffer.overwrite(str,0); - long ditta = m.get_long(F_DITTAINV); - str = format("%05d", ditta); - buffer.overwrite(str,10); - int num = m.get_int(F_NUMULINV); - num++; - str = format("%03d", num); - buffer.overwrite(str,15); - TString data (m.get(F_DATALIM)); - str = riconverti(data,TRUE); - buffer.overwrite(str,18); - } - - buffer.cut(64); //Sicurezza: le stringhe dimensionate in realta' sono - //leggermente piu' lunghe della dimensione specificata - const word scritti = fwrite((char*)(const char*)buffer,sizeof(char),size,i); - - fclose(i); - } -} - -void TInv_cont::aggiorna_marker(TString& token, int pos) -{ - TString str; - - _marker = ""; - _marker = firm2dir(0); - _marker << "\\marker"; - - FILE* i; - - const word size = 64; - TString buffer(size); - //buffer.spaces(); - - if ( (i = fopen(_marker,"r+t")) != NULL) - { - const word letti = fread((char*)(const char*)buffer,sizeof(char),size,i); - buffer.overwrite(token,pos); - - buffer.cut(64); //Sicurezza: le stringhe dimensionate in realta' sono - //leggermente piu' lunghe della dimensione specificata - fseek(i, 0L, SEEK_SET); - const word scritti = fwrite((char*)(const char*)buffer,sizeof(char),size,i); - - fclose(i); - } -} - -void TInv_cont::calcola_totale_record() -{ - _tras_file.open(_header); - leggi_record_controllo(); - - TString sigle = _tras_file.sigle_file(); - sigle.trim(); - - _tot_rec = 0; - - for (int i = 0; i < sigle.len(); i++) - { - long tot_rec = atol(_control_rec.mid((i * 6) + 95,6)); - _tot_rec += tot_rec; - } - _tot_rec += 1; -} - -void TInv_cont::setta_tabella_studio(TMask& m,bool flag_ditta) -{ - TTable ins ("%INS"); - TString dep; - long ditta; - - if (flag_ditta) - ditta = m.get_long(F_DITTAINV); - else - ditta = 0; - - dep.format("%-3s", (const char*) "INS"); - - ins.zero(); - ins.put("CODTAB", dep); - if (ins.read() == NOERR) - { - ins.put("I0", ditta); - ins.rewrite(); - } - else - warning_box("Tabella studio per invio NON AGGIORNATA"); -} - -void TInv_cont::setta_tabella_ditta(TMask& m,const char* flag, bool comp) -{ - TTable ind ("%IND"); - TString dep; - - long ditta = m.get_long(F_DITTAINV); - - dep.format("%05d", ditta); - - ind.zero(); - ind.put("CODTAB", dep); - if (ind.read() == NOERR) - { - int num = m.get_int(F_NUMULINV); - num++; - TDate data (m.get(F_DATALIM)); - - ind.put("S6", flag); - if (comp) - { - ind.put("I0", (long)num); - ind.put("D0", data); - } - ind.rewrite(); - } - else - warning_box("Tabella ditta per invio NON AGGIORNATA"); -} - -void TInv_cont::crea_record_controllo(TMask& m) -{ - int size = 1024; - TString buffer(1024); - TString str; - - if (_tras_file.exist()) - _tras_file.open(_header); - else - { - _tras_file.open(_header,TRUE); //Metto il parametro TRUE (che di default e' FALSE), perche' voglio creare un file che non e' ancore esistente - - buffer.spaces(); - buffer.overwrite(" 1",0); //Tipo record - - str = format("%-10s", (const char*) _nome_simbolico); - buffer.overwrite(str,60); //Nome studio - - long ditta = m.get_long(F_DITTAINV); - str = format("%05d", ditta); - buffer.overwrite(str,70); //Ditta inviante - - int num = m.get_int(F_NUMULINV); - num++; - str = format("%03d", num); - buffer.overwrite(str,75); //Numero progr. invio - - TString data (m.get(F_DATALIM)); - str = riconverti(data,TRUE); - buffer.overwrite(str,78); //Data limite invio - - str = format("%-9s", (const char*) _files); - buffer.overwrite(str,86); - - str = _files.sub(0,1); - buffer.overwrite(str,240); - - str = ""; - str.format("%054d", 0); - buffer.overwrite(str,95); - - if (_scelta == 'S') - { - str.format("%04ld", _dittaAS); - buffer.overwrite(str,301); - } - else - { - str.format("%05ld", _dittaAS); - buffer.overwrite(str,301); - } - - if (!_tras_file.write_control_rec(buffer, size)) - warning_box("Il record di controllo del file trasfer non e' stato aggiornato correttamente"); - } - _tras_file.close(); -} - -const char* TInv_cont::cerca_provincia(const TString& comcf) -{ - TLocalisamfile comuni(LF_COMUNI); - - comuni.setkey(1); - comuni.zero(); - comuni.put(COM_COM, comcf); - if (comuni.read() == NOERR) - TEMP = comuni.get(COM_PROVCOM); - else - TEMP = ""; - - return TEMP; -} - -bool TInv_cont::invio_tempfile(TMask& m) -{ - char uselab; - TString record(256),key,nrec; - int posiz,i; - char sigla; - - _tras_file.open(_header); - - leggi_record_controllo(); - - uselab = (_tras_file.ult_file())[0]; - - if (uselab == '\0') //Significa che sono in caso di ripartenza ma ho - return TRUE; //gia' trasferito tutti gli archivi e devo solo fare la copia su dischi - - posiz = _files.find(uselab); //Ritorna la posizione della sigla all'interno della schiera - key = _tras_file.key(); - key.trim(); - nrec = _tras_file.nrec_file(); - - for (i = posiz; i < _files.len();i++) - { - sigla = _files[i]; - _numrec = atol(nrec.mid(i * 6,6)); - - switch (sigla) - { - case 'W': - causali2tempfile(key,m); - break; - - case 'A': - clifo2tempfile(key,m); - break; - - case 'P': - pcon2tempfile(key,m); - break; - - case 'Z': - movPN2tempfile(key,m); - break; - - case 'U': - movIVA2tempfile(key,m); - break; - - default: - break; - }; - key = ""; - } - - // Finito di trasferire tutti gli archivi pulisco la sigla ultimo file da elaborare - _tras_file.open(_header); - leggi_record_controllo(); - _control_rec.overwrite(" ",240); - _tras_file.write_control_rec(_control_rec,1024); - _tras_file.close(); - - setta_tabella_ditta(m,"D",FALSE); - setta_parametri_record(m,"D"); - - return TRUE; -} - -void TInv_cont::causali2tempfile(TString& key, TMask& m) -{ - int size = 1024; - - _tras_file.open(_header); - - long items = _caus->items(); - _prog = new TProgind(items,"Invio tabella causali in corso... Prego attendere.",FALSE); - - _caus->setkey(1); - - if (key.empty()) - _caus->first(); - else - { - TString causale (key.mid(0,3)); - _caus->zero(); - _caus->put(CAU_CODCAUS, causale); - _caus->read(); - } - - for(; !_caus->eof(); _caus->next()) - { - _prog->addstatus(1); - - TString codcaus = _caus->get(CAU_CODCAUS); - - _tcaus->curr() = _caus->curr(); - - if (_tcaus->read() == NOERR) // Esiste la testata - { - scrivi_righe_causali(codcaus,'W'); - - _tcaus->zero(); - _tcaus->curr() = _caus->curr(); - _tcaus->rewrite(); - } - else - { - scrivi_righe_causali(codcaus,'W'); - - _tcaus->zero(); - _tcaus->curr() = _caus->curr(); - _tcaus->write(); - } - - leggi_record_controllo(); - TString chiave; - chiave.format("%3s",(const char*) codcaus); - _control_rec.overwrite("W",240); - _control_rec.overwrite(chiave,241); - - _tras_file.write_control_rec(_control_rec,size); - } - delete _prog; - - //Inizializzo l'ultima sigla file elaborato su trasfer con la sigla del file successivo da inviare - //e inizializzo la chiave, altrimenti se si blocca l'invio subito dopo aver finito un file si rischia di - //ritrasferire l'ultimo record quando si riparte; inoltre non si riesce a inviare il file successivo perche' - //la chiave e' compilata con i dati del file precedente. - - leggi_record_controllo(); - TString chiave,app,sigla; - app.format("%-15s", (const char*) chiave); - char sigla_p = _tras_file.ult_file()[0]; - int posiz = _files.find(sigla_p); - TString nuova_sigla = " "; - if (posiz < _files.len()) - nuova_sigla = _files.mid(posiz+1,1); - - _control_rec.overwrite(nuova_sigla,240); - _control_rec.overwrite(app,241); - _tras_file.write_control_rec(_control_rec,size); - _tras_file.close(); - -// setta_tabella_ditta(m,"D",FALSE); -// setta_parametri_record(m,"D"); -} - -void TInv_cont::cancella_righe_causali(TString& codcaus) -{ - _trcaus->setkey(1); - _trcaus->zero(); - _trcaus->put(RCA_CODCAUS, codcaus); - TRectype rcau (LF_RCAUSALI); - rcau = _trcaus->curr(); - for (_trcaus->read(); !_trcaus->eof(); _trcaus->next()) - { - if (_trcaus->curr() > rcau) break; - - _trcaus->remove(); - } -} - -void TInv_cont::scrivi_righe_causali(TString& codcaus, char uselab) -{ - cancella_righe_causali(codcaus); - - _rcaus->setkey(1); - _rcaus->zero(); - _rcaus->put(RCA_CODCAUS, codcaus); - TRectype rcau (LF_RCAUSALI); - rcau = _rcaus->curr(); - for (_rcaus->read(); !_rcaus->eof(); _rcaus->next()) - { - if (_rcaus->curr() > rcau) break; - - _trcaus->curr() = _rcaus->curr(); - _trcaus->write(); - - leggi_record_controllo(); - TString chiave; - chiave.format("%3s",(const char*) codcaus); - TString sigla (format("%c", uselab)); - _control_rec.overwrite(sigla,240); - _control_rec.overwrite(chiave,241); - _tras_file.write_control_rec(_control_rec,1024); - } -} - -void TInv_cont::clifo2tempfile(TString& key, TMask& m) -{ - int size = 1024; - - _tras_file.open(_header); - - long items = _clifo->items(); - _prog = new TProgind(items,"Invio Clienti / Fornitori in corso... Prego attendere.",FALSE); - - _clifo->setkey(1); - - if (key.empty()) - _clifo->first(); - else - { - char tipo = (key.mid(0,1))[0]; - long codice = atol(key.mid(1,6)); - _clifo->zero(); - _clifo->put(CLI_TIPOCF, tipo); - _clifo->put(CLI_CODCF, codice); - _clifo->read(); - } - - for(; !_clifo->eof(); _clifo->next()) - { - _prog->addstatus(1); - - char tipocf = _clifo->get_char(CLI_TIPOCF); - long codcf = _clifo->get_long(CLI_CODCF); - - _tclifo->curr() = _clifo->curr(); - - if (_tclifo->read() == NOERR) // Esiste gia' il cliente - { - _tclifo->zero(); - _tclifo->curr() = _clifo->curr(); - _tclifo->rewrite(); - } - else - { - _tclifo->zero(); - _tclifo->curr() = _clifo->curr(); - _tclifo->write(); - } - - leggi_record_controllo(); - TString chiave; - chiave.format("%c%06ld", tipocf, codcf); - TString sigla (format("%c", 'A')); - _control_rec.overwrite(sigla,240); - _control_rec.overwrite(chiave,241); - - _tras_file.write_control_rec(_control_rec,size); - } - delete _prog; - - //Inizializzo l'ultima sigla file elaborato su trasfer con la sigla del file successivo da inviare - //e inizializzo la chiave, altrimenti se si blocca l'invio subito dopo aver finito un file si rischia di - //ritrasferire l'ultimo record quando si riparte; inoltre non si riesce a inviare il file successivo perche' - //la chiave e' compilata con i dati del file precedente. - - leggi_record_controllo(); - TString chiave,app,sigla; - app.format("%-15s", (const char*) chiave); - char sigla_p = _tras_file.ult_file()[0]; - int posiz = _files.find(sigla_p); - TString nuova_sigla = " "; - if (posiz < _files.len()) - nuova_sigla = _files.mid(posiz+1,1); - - _control_rec.overwrite(nuova_sigla,240); - _control_rec.overwrite(app,241); - _tras_file.write_control_rec(_control_rec,size); - _tras_file.close(); - -// setta_tabella_ditta(m,"D",FALSE); -// setta_parametri_record(m,"D"); -} - - -void TInv_cont::pcon2tempfile(TString& key, TMask& m) -{ - int size = 1024; - - _tras_file.open(_header); - - long items = _pcon->items(); - _prog = new TProgind(items,"Invio Piano dei Conti in corso... Prego attendere.",FALSE); - - _pcon->setkey(1); - - if (key.empty()) - _pcon->first(); - else - { - int gruppo = atoi(key.mid(0,3)); - int conto = atoi(key.mid(3,3)); - long sottoc = atol(key.mid(6,6)); - - _pcon->zero(); - _pcon->put(PCN_GRUPPO, gruppo); - if (conto != 0) - _pcon->put(PCN_CONTO, conto); - if (sottoc != 0) - _pcon->put(PCN_SOTTOCONTO, sottoc); - _pcon->read(); - } - - for(; !_pcon->eof(); _pcon->next()) - { - _prog->addstatus(1); - - int g = _pcon->get_int (PCN_GRUPPO); - int c = _pcon->get_int (PCN_CONTO); - long s = _pcon->get_long(PCN_SOTTOCONTO); - - _tpcon->curr() = _pcon->curr(); - - if (_tpcon->read() == NOERR) // Esiste gia' il cliente - { - _tpcon->zero(); - _tpcon->curr() = _pcon->curr(); - _tpcon->rewrite(); - } - else - { - _tpcon->zero(); - _tpcon->curr() = _pcon->curr(); - _tpcon->write(); - } - - leggi_record_controllo(); - TString chiave; - chiave.format("%3d%3d%6ld", g, c, s); - TString sigla (format("%c", 'P')); - _control_rec.overwrite(sigla,240); - _control_rec.overwrite(chiave,241); - - _tras_file.write_control_rec(_control_rec,size); - } - delete _prog; - - //Inizializzo l'ultima sigla file elaborato su trasfer con la sigla del file successivo da inviare - //e inizializzo la chiave, altrimenti se si blocca l'invio subito dopo aver finito un file si rischia di - //ritrasferire l'ultimo record quando si riparte; inoltre non si riesce a inviare il file successivo perche' - //la chiave e' compilata con i dati del file precedente. - - leggi_record_controllo(); - TString chiave,app,sigla; - app.format("%-15s", (const char*) chiave); - char sigla_p = _tras_file.ult_file()[0]; - int posiz = _files.find(sigla_p); - TString nuova_sigla = " "; - if (posiz < _files.len()) - nuova_sigla = _files.mid(posiz+1,1); - - _control_rec.overwrite(nuova_sigla,240); - _control_rec.overwrite(app,241); - _tras_file.write_control_rec(_control_rec,size); - _tras_file.close(); - -// setta_tabella_ditta(m,"D",FALSE); -// setta_parametri_record(m,"D"); -} - -void TInv_cont::primanota_inviata(long numreg) -{ - _mov->setkey(1); - _mov->zero(); - _mov->put(MOV_NUMREG, numreg); - if (_mov->read() == NOERR) - { - _mov->put(MOV_INVIATO, "X"); - if (_flag_bollato) - _mov->put(MOV_STAMPATO, "X"); - - _mov->rewrite(); - } -} - -void TInv_cont::scrivi_righePN(long numreg) -{ - int size = 1024; - - _tras_file.open(_header); - - _rmov->setkey(1); - _rmov->zero(); - _rmov->put(RMV_NUMREG, numreg); - TRectype rmov (LF_RMOV); - rmov = _rmov->curr(); - for (_rmov->read(); !_rmov->eof(); _rmov->next()) - { - if (_rmov->curr() > rmov) break; - - _trmov->zero(); - _trmov->curr() = _rmov->curr(); - _trmov->write(); - } -} - -void TInv_cont::movPN2tempfile(TString& key, TMask& m) -{ - int size = 1024; - - _tras_file.open(_header); - - long items = _mov->items(); - _prog = new TProgind(items,"Invio movimenti di Primanota in corso... Prego attendere.",FALSE); - - _mov->setkey(1); - - if (key.empty()) - _mov->first(); - else - { - long numreg = atol(key.mid(0,7)); - _mov->zero(); - _mov->put(MOV_NUMREG, numreg); - _mov->read(); - } - - for(; !_mov->eof(); _mov->next()) - { - _prog->addstatus(1); - - long nreg = _mov->get_long(MOV_NUMREG); - - TDate datareg (_mov->get_date(MOV_DATAREG)); - - if ( _mov->get_bool(MOV_INVIATO) || datareg > _datalimsk ) continue; - - _tmov->curr() = _mov->curr(); - - if (_tmov->read() == NOERR) - { - _tmov->zero(); - _tmov->curr() = _mov->curr(); - _tmov->rewrite(); - - scrivi_righePN(nreg); - } - else - { - _tmov->zero(); - _tmov->curr() = _mov->curr(); - _tmov->write(); - - scrivi_righePN(nreg); - } - - leggi_record_controllo(); - TString chiave; - chiave.format("%07ld", nreg); - TString sigla (format("%c", 'Z')); - _control_rec.overwrite(sigla,240); - _control_rec.overwrite(chiave,241); - _tras_file.write_control_rec(_control_rec,size); - - primanota_inviata(nreg); - } - delete _prog; - - //Inizializzo l'ultima sigla file elaborato su trasfer con la sigla del file successivo da inviare - //e inizializzo la chiave, altrimenti se si blocca l'invio subito dopo aver finito un file si rischia di - //ritrasferire l'ultimo record quando si riparte; inoltre non si riesce a inviare il file successivo perche' - //la chiave e' compilata con i dati del file precedente. - - leggi_record_controllo(); - TString chiave,app,sigla; - app.format("%-15s", (const char*) chiave); - char sigla_p = _tras_file.ult_file()[0]; - int posiz = _files.find(sigla_p); - TString nuova_sigla = " "; - if (posiz < _files.len()) - nuova_sigla = _files.mid(posiz+1,1); - - _control_rec.overwrite(nuova_sigla,240); - _control_rec.overwrite(app,241); - _tras_file.write_control_rec(_control_rec,size); - _tras_file.close(); - -// setta_tabella_ditta(m,"D",FALSE); -// setta_parametri_record(m,"D"); -} - -bool TInv_cont::occasionali(const TString& cfpi) -{ - TString chiave; - - _occas->setkey(1); - _occas->zero(); - _occas->put("CFPI", cfpi); - _occas->read(); - - _toccas->zero(); - _toccas->curr() = _occas->curr(); - - if (_toccas->read() == NOERR) - { - _toccas->zero(); - _toccas->curr() = _occas->curr(); - _toccas->rewrite(); - } - else - { - _toccas->zero(); - _toccas->curr() = _occas->curr(); - _toccas->write(); - } - - return TRUE; -} - -void TInv_cont::iva_inviata(long numreg) -{ - _mov->setkey(1); - _mov->zero(); - _mov->put(MOV_NUMREG, numreg); - if (_mov->read() == NOERR) - { - _mov->put(MOV_INVIVA, "X"); - if (_flag_bollato) - _mov->put(MOV_REGST, "X"); - - _mov->rewrite(); - } -} - -void TInv_cont::movIVA2tempfile(TString& key, TMask& m) -{ - TString ocfpi; - TDate datareg; - bool inviva; - int size = 1024; - - _tras_file.open(_header); - - long items = _rmoviva->items(); - _prog = new TProgind(items,"Invio movimenti Iva in corso... Prego attendere.",FALSE); - - _rmoviva->setkey(1); - - if (key.empty()) - _rmoviva->first(); - else - { - long numreg = atol(key.mid(0,7)); - _rmoviva->zero(); - _rmoviva->put(RMI_NUMREG, numreg); - _rmoviva->put(RMI_NUMRIG, 1); - _rmoviva->read(); - } - - long nreg_p = -1; - - for(; !_rmoviva->eof(); _rmoviva->next()) - { - _prog->addstatus(1); - - long nreg = _rmoviva->get_long(RMI_NUMREG); - - if (nreg != nreg_p) - { - _mov->setkey(1); - _mov->zero(); - _mov->put(MOV_NUMREG, nreg); - if (_mov->read() == NOERR) - { - datareg = _mov->get_date(MOV_DATAREG); - inviva = _mov->get_bool(MOV_INVIVA); - ocfpi = _mov->get (MOV_OCFPI); - } - } - else - inviva = FALSE; - - if ( inviva || datareg > _datalimsk ) continue; - - if (ocfpi.not_empty()) - occasionali(ocfpi); - - _triva->zero(); - _triva->curr() = _rmoviva->curr(); - - if (_triva->read() == NOERR) - { - _triva->zero(); - _triva->curr() = _rmoviva->curr(); - _triva->rewrite(); - } - else - { - _triva->zero(); - _triva->curr() = _rmoviva->curr(); - _triva->write(); - } - - leggi_record_controllo(); - TString chiave; - chiave.format("%07ld", nreg); - TString sigla (format("%c", 'U')); - _control_rec.overwrite(sigla,240); - _control_rec.overwrite(chiave,241); - - _tras_file.write_control_rec(_control_rec,size); - - if (nreg != nreg_p) - iva_inviata(nreg); - - nreg_p = nreg; - } - delete _prog; - - //Inizializzo l'ultima sigla file elaborato su trasfer con la sigla del file successivo da inviare - //e inizializzo la chiave, altrimenti se si blocca l'invio subito dopo aver finito un file si rischia di - //ritrasferire l'ultimo record quando si riparte; inoltre non si riesce a inviare il file successivo perche' - //la chiave e' compilata con i dati del file precedente. - - leggi_record_controllo(); - TString chiave,app,sigla; - app.format("%-15s", (const char*) chiave); - char sigla_p = _tras_file.ult_file()[0]; - int posiz = _files.find(sigla_p); - TString nuova_sigla = " "; - if (posiz < _files.len()) - nuova_sigla = _files.mid(posiz+1,1); - - _control_rec.overwrite(nuova_sigla,240); - _control_rec.overwrite(app,241); - _tras_file.write_control_rec(_control_rec,size); - _tras_file.close(); - -// setta_tabella_ditta(m,"D",FALSE); -// setta_parametri_record(m,"D"); -} - -bool TInv_cont::menu(MENU_TAG m) -{ - if (m == BAR_ITEM(1)) - return main_loop(); - return FALSE; -} - -int cg6900 (int argc, char* argv[]) -{ - switch (*argv[2]) - { - case 'S': - { - TInv_cont main_app(*argv[2]); - main_app.run(argc, argv,main_app._titolo); - } - break; - case 'P': - { - TInv_cont main_app(*argv[2]); - main_app.run(argc, argv,main_app._titolo); - } - break; - case 'L': - { - TLista_archivi a; - a.run(argc, argv,"Lista controllo archivi"); - } - break; - case 'R': - { - TRip_flag a; - a.run(argc, argv,"Ripristino flag movimenti"); - } - break; - default: - break; - } - - return TRUE; -} +// Invio contabilita' + +#include "cg6900.h" +#include "cg6900a.h" + +TInv_cont::TInv_cont(char mov) : _scelta(toupper(mov)) +{ + switch (_scelta) + { + case 'S': + _titolo = "Invio a Sistema"; + break; + case 'P': + _titolo = "Invio a PC"; + break; + default: + break; + } +} + +bool TInv_cont::messaggio_hnd(TMask_field& f, KEY k) +{ + if (k == K_TAB) + return message_box("Rilevato STATO DI RIPARTENZA: il trasferimento ripartira' automaticamente"); + + return TRUE; +} + +bool TInv_cont::main_loop() +{ + TString str; + bool ripartenza = FALSE; + + if (!esiste_tabella_studio()) return FALSE; + + if (!esegui_controlli()) return FALSE; + + TMask msk ("cg6900a"); + KEY tasto; + + if (_ditta != 0) + { + msk.set(F_DITTAINV, _ditta); + msk.disable(F_DITTAINV); + codifica_ditta(msk); + msk.set(F_NUMULINV, _num); + msk.set(F_DATAULIN, _data.string()); + msk.set(F_STATO, _stato); + + TString uselab = _tras_file.ult_file(); + TString chiave = _tras_file.key(); + msk.set(F_USELAB, uselab); + msk.set(F_CHIAVE, chiave); + msk.set(F_DATALIM, _data.string()); + msk.disable(F_DATALIM); + + if (_scelta == 'S' && _ditta > 9999) + { + msk.show(F_DITTAAS); + msk.disable(F_DITTAAS); + long ditta = atol(_control_rec.sub(300,304)); + msk.set(F_DITTAAS, ditta); + } + else + msk.hide(F_DITTAAS); + + ripartenza = TRUE; + } + + msk.disable(F_NUMULINV); + msk.disable(F_DATAULIN); + msk.disable(F_STATO); + msk.disable(F_USELAB); + msk.disable(F_CHIAVE); + + if (!ripartenza) + msk.set_handler(F_DITTAINV, setta_maschera_hnd); + else + msk.set_handler(F_NUMULINV, messaggio_hnd); + + tasto = msk.run(); + + if (tasto != K_ENTER) return FALSE; + + _dittaAS = msk.get_long(F_DITTAAS); //Se la ditta per l'invio ad AS non viene compilata perche' trattasi di invio a PC + if (_dittaAS == 0) //o perche' il codice e' di 4, gli assegno la ditta corrente. Nel caso di invio a + _dittaAS = _ditta; //PC non servirebbe il codice aggiuntivo, ma lo metto ugualmente per avere una situazione analoga + +// Nel caso di invio PC --> SISTEMA eseguo prima la +// Lista controllo archivi per rilevare eventuali +// differenze. + + long ditta = msk.get_long(F_DITTAINV); + set_firm(ditta); + + TConfig conf(CONFIG_DITTA); + TString std = conf.get("FlStInv"); + + if (_scelta == 'S' && std != "D") + { + TString appname = "cg6 -8 L"; + TString corpo = ""; + + TDate data = msk.get(F_DATALIM); + + corpo << data.string(); + + TMessage mess (appname,"",(const char*)corpo); + TMailbox mb; + mb.send(mess); + + TExternal_app a (appname); + a.run(); + + TMailbox m; + TMessage* msg = m.next_s(""); + int subj; + + if (msg != NULL) + { + subj = atoi(msg->body()); + if (subj) + return FALSE; + } + } + + _datalimsk = msk.get(F_DATALIM); + + if (!ripartenza) + { + crea_marker(msk); //Crea il record con le informazioni sul marker + setta_parametri_record(msk,"F"); //Aggiorna parametri contabili ditta + setta_tabella_studio(msk); //Aggiorna la tabella studio per invio + setta_tabella_ditta(msk,"F"); //Aggiorna la tabella ditta per invio + crea_record_controllo(msk); //Crea il record di controllo sul file header + } + else + { + TString str,app; + + int num = msk.get_int(F_NUMULINV); + TString data (msk.get(F_DATALIM)); + if (_scelta == 'S') + { + app = riconverti(data,FALSE); + str.format("%03d%6s", num, (const char*) app); + aggiorna_marker(str,14); + } + else + if (_scelta == 'P') + { + app = riconverti(data,TRUE); + str.format("%03d%8s", num, (const char*) app); + aggiorna_marker(str,15); + } + } + + apri_file_temp(); + + if (!invio_tempfile(msk)) + return FALSE; + +// calcola_totale_record(); +// str.format("%06ld", _tot_rec); + + if (_scelta == 'S') + { +// aggiorna_marker(str,23); + + _trasf = ""; + _trasf = firm2dir(0); + _trasf << "\\trasfer"; + fremove(_trasf); + _tras_file.open(_trasf,TRUE); + +// if (std != "D") + invio_contabilita(); //Costruisce il trasfer nella directory comune + + TMask mask ("cg6900b"); + KEY k; + + k = mask.run(); + + if (k == K_ENTER) + { + int num_disk = calcola_numero_dischi(mask); + char floppy = mask.get(F_FLOPPY)[0]; + + str.format("%02d", num_disk); + aggiorna_marker(str,29); + + const TFilename from(_trasf); // File da splittare + + TFilename work; + work << floppy << ":/" << from.name(); // File su dischetto + + FILE* i = fopen(from, "rb"); + + if (i == NULL) return error_box("Impossibile aprire il file '%s'", from); + + TProgind w(_dim_tot, "Trasferimento su dischetti in corso... Prego attendere", TRUE, TRUE, 60); + + for (int j = 0; j < num_disk; j++) + { + scrivi_disco(floppy,j+1,work,i,w); + } + fclose(i); + + setta_tabella_studio(msk,FALSE); //Aggiorna la tabella studio per invio + setta_tabella_ditta(msk," ",FALSE); //Aggiorna la tabella ditta per invio + setta_parametri_record(msk," "); //Aggiorna parametri contabili ditta + + _tras_file.open(_header); + leggi_record_controllo(); + TString record(1024); + record.spaces(); + _control_rec.overwrite(record,0); + _tras_file.write_control_rec(_control_rec,1024); + + chiudi_file_temp(); + } + else + return FALSE; + } + else + if (_scelta == 'P') + { + _trasf = ""; + _trasf = firm2dir(0); + _trasf << "\\trasfer"; + fremove(_trasf); + _tras_file.open(_trasf,TRUE); + + invio_contabilita_PC(); //Costruisce il trasfer nella directory comune + + TMask mask ("cg6900b"); + KEY k; + + k = mask.run(); + + if (k == K_ENTER) + { + int num_disk = calcola_numero_dischi(mask); + char floppy = mask.get(F_FLOPPY)[0]; + + str.format("%02d", num_disk); + aggiorna_marker(str,32); + + const TFilename from(_trasf); // File da splittare + + TFilename work; + work << floppy << ":/" << from.name(); // File su dischetto + + FILE* i = fopen(from, "rb"); + + if (i == NULL) return error_box("Impossibile aprire il file '%s'", from); + + TProgind w(_dim_tot, "Trasferimento su dischetti in corso... Prego attendere", TRUE, TRUE, 60); + + for (int j = 0; j < num_disk; j++) + { + scrivi_disco(floppy,j+1,work,i,w); + } + fclose(i); + + setta_tabella_studio(msk,FALSE); //Aggiorna la tabella studio per invio + setta_tabella_ditta(msk," ",FALSE); //Aggiorna la tabella ditta per invio + setta_parametri_record(msk," "); //Aggiorna parametri contabili ditta + + _tras_file.open(_header); + leggi_record_controllo(); + TString record(1024); + record.spaces(); + _control_rec.overwrite(record,0); + _tras_file.write_control_rec(_control_rec,1024); + + chiudi_file_temp(); + } + else + return FALSE; + } + + _tras_file.remove_all(FALSE); + fremove(_marker); + _trasf = ""; + _trasf = firm2dir(0); + _trasf << "\\trasfer"; + fremove(_trasf); + + return FALSE; +} + +bool TInv_cont::create() +{ + TApplication::create(); + + _caus = new TLocalisamfile (LF_CAUSALI); + _rcaus = new TLocalisamfile (LF_RCAUSALI); + _clifo = new TLocalisamfile (LF_CLIFO); + _pcon = new TLocalisamfile (LF_PCON); + _mov = new TLocalisamfile (LF_MOV); + _rmov = new TLocalisamfile (LF_RMOV); + _rmoviva = new TLocalisamfile (LF_RMOVIVA); + _occas = new TLocalisamfile (LF_OCCAS); + _part = new TLocalisamfile (LF_PARTITE); + + dispatch_e_menu (BAR_ITEM(1)); + + return TRUE; +} + +bool TInv_cont::destroy() +{ + delete _caus; + delete _rcaus; + delete _clifo; + delete _pcon; + delete _mov; + delete _rmov; + delete _rmoviva; + delete _occas; + delete _part; + + return TApplication::destroy(); +} + +void TInv_cont::apri_file_temp() +{ + _tras_file.open(_header); + leggi_record_controllo(); + _sigle = _tras_file.sigle_file(); + _sigle.trim(); + + for (int i = 0; i < _sigle.len(); i++) + { + TString80 tmp; + char sigla = _sigle[i]; + + if (sigla == 'W') + { + TString80 tmpcaus = "%"; + tmpcaus << firm2dir(0); + tmpcaus << "\\" << TEMP_CAUS; + tmp = tmpcaus.mid(1); + tmp << ".dbf"; + if (fexist(tmp)) + _tcaus = new TIsamtempfile(LF_CAUSALI, tmpcaus, FALSE); + else + _tcaus = new TIsamtempfile(LF_CAUSALI, tmpcaus, TRUE); + TString80 tmprcaus = "%"; + tmprcaus << firm2dir(0); + tmprcaus << "\\" << TEMP_RCAUS; + tmp = tmprcaus.mid(1); + tmp << ".dbf"; + if (fexist(tmp)) + _trcaus = new TIsamtempfile(LF_RCAUSALI, tmprcaus, FALSE); + else + _trcaus = new TIsamtempfile(LF_RCAUSALI, tmprcaus, TRUE); + } + if (sigla == 'A') + { + TString80 tmpclifo = "%"; + tmpclifo << firm2dir(0); + tmpclifo << "\\" << TEMP_CLIFO; + tmp = tmpclifo.mid(1); + tmp << ".dbf"; + if (fexist(tmp)) + _tclifo = new TIsamtempfile(LF_CLIFO, tmpclifo, FALSE); + else + _tclifo = new TIsamtempfile(LF_CLIFO, tmpclifo, TRUE); + } + if (sigla == 'P') + { + TString80 tmppcon = "%"; + tmppcon << firm2dir(0); + tmppcon << "\\" << TEMP_PCON; + tmp = tmppcon.mid(1); + tmp << ".dbf"; + if (fexist(tmp)) + _tpcon = new TIsamtempfile(LF_PCON, tmppcon, FALSE); + else + _tpcon = new TIsamtempfile(LF_PCON, tmppcon, TRUE); + } + if (sigla == 'Z') + { + TString80 tmpmov = "%"; + tmpmov << firm2dir(0); + tmpmov << "\\" << TEMP_MOV; + tmp = tmpmov.mid(1); + tmp << ".dbf"; + if (fexist(tmp)) + _tmov = new TIsamtempfile(LF_MOV, tmpmov, FALSE); + else + _tmov = new TIsamtempfile(LF_MOV, tmpmov, TRUE); + TString80 tmprmov = "%"; + tmprmov << firm2dir(0); + tmprmov << "\\" << TEMP_RMOV; + tmp = tmprmov.mid(1); + tmp << ".dbf"; + if (fexist(tmp)) + _trmov = new TIsamtempfile(LF_RMOV, tmprmov, FALSE); + else + _trmov = new TIsamtempfile(LF_RMOV, tmprmov, TRUE); + } + if (sigla == 'U') + { + TString80 tmpriva = "%"; + tmpriva << firm2dir(0); + tmpriva << "\\" << TEMP_RMOVIVA; + tmp = tmpriva.mid(1); + tmp << ".dbf"; + if (fexist(tmp)) + _triva = new TIsamtempfile(LF_RMOVIVA, tmpriva, FALSE); + else + _triva = new TIsamtempfile(LF_RMOVIVA, tmpriva, TRUE); + TString80 tmpoccas = "%"; + tmpoccas << firm2dir(0); + tmpoccas << "\\" << TEMP_OCC; + tmp = tmpoccas.mid(1); + tmp << ".dbf"; + if (fexist(tmp)) + _toccas = new TIsamtempfile(LF_OCCAS, tmpoccas, FALSE); + else + _toccas = new TIsamtempfile(LF_OCCAS, tmpoccas, TRUE); + } + } +} + +void TInv_cont::chiudi_file_temp() +{ + for (int i = 0; i < _sigle.len(); i++) + { + char sigla = _sigle[i]; + + if (sigla == 'W') + { + delete _tcaus; + delete _trcaus; + } + if (sigla == 'A') + delete _tclifo; + if (sigla == 'P') + delete _tpcon; + if (sigla == 'Z') + { + delete _tmov; + delete _trmov; + } + if (sigla == 'U') + { + delete _triva; + delete _toccas; + } + } +} + +void TInv_cont::leggi_record_controllo() +{ + _tras_file.read_control_rec(); + _control_rec = _tras_file.record(); +} + +bool TInv_cont::esiste_tabella_studio() +{ + TTable ins ("%INS"); + + ins.zero(); + + if (ins.first() == NOERR) + { + if (ins.empty()) + return error_box("Codice STUDIO NON ATTIVATO in tabella invii"); + else + { + _nome_simbolico = ins.get("S0"); + long ditta = ins.get_long("I0"); + if (ditta != 0) + { + _esiste_ditta = TRUE; + _ditta = ditta; + } + else + { + _esiste_ditta = FALSE; + _ditta = 0; + } + } + } + else + return error_box("Codice STUDIO NON ATTIVATO in tabella invii"); + + return TRUE; +} + +bool TInv_cont::leggi_header() +{ + _header = ""; + _header = firm2dir(0); + _header << HEADER; + + _tras_file.open(_header); + + if (_tras_file.exist()) + { + if (_tras_file.read_control_rec()) + { + _control_rec = _tras_file.record(); + if (!record_controllo()) + return FALSE; + } + else + return FALSE; + } + else + return FALSE; + + return TRUE; +} + +bool TInv_cont::record_controllo() +{ + TString tiporecord = _control_rec.sub(0,2); + + if (tiporecord != " 1") + return FALSE; + + return TRUE; +} + +bool TInv_cont::esegui_controlli() +{ + _esiste_record = leggi_header(); + + if (!controlli()) return FALSE; + + return TRUE; +} + +void TInv_cont::setta_parametri_record(TMask& m,const TString& flag) +{ + TConfig conf (CONFIG_DITTA); + conf.set("FlStInv", flag); +} + +bool TInv_cont::controlli() +{ + if (!_esiste_ditta && !_esiste_record) return TRUE; //Mi trovo in una condizione normale + + if (_esiste_ditta && !_esiste_record) + return error_box("Rilevato stato di ripartenza con dati contradditori: programma interrotto"); + + if (!_esiste_ditta && _esiste_record) + return error_box("Rilevato stato di ripartenza con dati contradditori: programma interrotto"); + + if (_esiste_ditta && _esiste_record) + { + if (!sub_controlli()) + return error_box("Rilevato stato di ripartenza con dati contradditori: programma interrotto"); + } + + return TRUE; +} + +bool TInv_cont::sub_controlli() +{ + long ditta_trasfer = _tras_file.ditta(); + + if (_ditta == ditta_trasfer) + { + if (!prefix().exist(_ditta)) + return FALSE; + + if (!tabella_ditta()) + return FALSE; + } + else + return FALSE; + + if (!controlla_stato_invio()) + return FALSE; + + if (!numero_data()) + return FALSE; + + return TRUE; +} + +bool TInv_cont::tabella_ditta() +{ + TTable ind ("%IND"); + TString dep; + + dep.format("%05d", _ditta); + + ind.zero(); + ind.put("CODTAB", dep); + if (ind.read() == NOERR) + { + _stato = ind.get("S6"); + _num = ind.get_int("I0"); + _data = ind.get_date("D0"); + + _files = ""; + if (ind.get_bool("B0") && (_caus->items() != 0) ) + _files << "W"; + + if (ind.get_bool("B1") && (_clifo->items() != 0) ) + _files << "A"; + + if (ind.get_bool("B2") && (_pcon->items() != 0) ) + _files << "P"; + + if (ind.get_bool("B3") && (_mov->items() != 0) ) + _files << "Z"; + + if (ind.get_bool("B4") && (_rmoviva->items() != 0) ) + _files << "U"; + + if (ind.get_bool("B5") && (_part->items() != 0) ) + _files << "B"; + + _flag_bollato = ind.get_bool("B7"); + + return TRUE; + } + + return FALSE; +} + +bool TInv_cont::controlla_stato_invio() +{ + set_firm(_ditta); + + TConfig conf(CONFIG_DITTA); + _std = conf.get("FlStInv"); + + if (_stato != _std) + return FALSE; + else + { + TString uselab = _tras_file.ult_file(); + + if (_stato == "D" && uselab != "") + return FALSE; + } + + return TRUE; +} + +bool TInv_cont::numero_data() +{ + int num = _tras_file.nultras(); + TString str = _tras_file.dataultras(); + TDate data (str); + + if (_num != num || data != _data) + return FALSE; + + return TRUE; +} + +void TInv_cont::codifica_ditta(TMask& m) +{ + TLocalisamfile ditte (LF_NDITTE); + + long ditta = m.get_long(F_DITTAINV); + + ditte.setkey(1); + ditte.zero(); + ditte.put(NDT_CODDITTA, ditta); + if (ditte.read() == NOERR) + { + TString ragsoc = ditte.get(NDT_RAGSOC); + m.set(F_RAGSOC, ragsoc); + } +} + +bool TInv_cont::setta_maschera_hnd(TMask_field& f, KEY k) +{ + if ( (k == K_TAB || k == K_ENTER) && f.mask().is_running()) + { + app()._ditta = f.mask().get_long(F_DITTAINV); + if (!prefix().exist(app()._ditta)) + return error_box("La ditta indicata non e' abilitata alla contabilita'"); + + if (!app().tabella_ditta()) + return error_box("La ditta indicata non e' presente sulla tabella ditta per invio"); + + if (app()._stato != "") + return error_box("Rilevato STATO DI RIPARTENZA NON RECUPERABILE sulla ditta richiesta"); + + f.mask().set(F_DITTAINV, app()._ditta); + app().codifica_ditta(f.mask()); + f.mask().set(F_NUMULINV, app()._num); + f.mask().set(F_DATAULIN, app()._data.string()); + f.mask().set(F_STATO, app()._stato); + + long ditta = atol(f.get()); + + if (app()._scelta == 'S' && ditta > 9999) + f.mask().show(F_DITTAAS); + else + f.mask().hide(F_DITTAAS); + } + + return TRUE; +} + +void TInv_cont::crea_marker(TMask& m) +{ + TString str; + + _marker = ""; + _marker = firm2dir(0); + _marker << "\\marker"; + + FILE* i; + + const word size = 64; + TString buffer(size); + buffer.spaces(); + + if ( (i = fopen(_marker,"w+t")) != NULL) + { + if (_scelta == 'S') + { + str = format("%-10s", (const char*) _nome_simbolico); + buffer.overwrite(str,0); + long ditta = m.get_long(F_DITTAINV); + if (ditta > 9999) + ditta = _dittaAS; + str = format("%04d", ditta); + buffer.overwrite(str,10); + int num = m.get_int(F_NUMULINV); + num++; + str = format("%03d", num); + buffer.overwrite(str,14); + TString data (m.get(F_DATALIM)); + str = riconverti(data,FALSE); + buffer.overwrite(str,17); + } + else + if (_scelta == 'P') + { + str = format("%-10s", (const char*) _nome_simbolico); + buffer.overwrite(str,0); + long ditta = m.get_long(F_DITTAINV); + str = format("%05d", ditta); + buffer.overwrite(str,10); + int num = m.get_int(F_NUMULINV); + num++; + str = format("%03d", num); + buffer.overwrite(str,15); + TString data (m.get(F_DATALIM)); + str = riconverti(data,TRUE); + buffer.overwrite(str,18); + } + + buffer.cut(64); //Sicurezza: le stringhe dimensionate in realta' sono + //leggermente piu' lunghe della dimensione specificata + const word scritti = fwrite((char*)(const char*)buffer,sizeof(char),size,i); + + fclose(i); + } +} + +void TInv_cont::aggiorna_marker(TString& token, int pos) +{ + TString str; + + _marker = ""; + _marker = firm2dir(0); + _marker << "\\marker"; + + FILE* i; + + const word size = 64; + TString buffer(size); + //buffer.spaces(); + + if ( (i = fopen(_marker,"r+t")) != NULL) + { + const word letti = fread((char*)(const char*)buffer,sizeof(char),size,i); + buffer.overwrite(token,pos); + + buffer.cut(64); //Sicurezza: le stringhe dimensionate in realta' sono + //leggermente piu' lunghe della dimensione specificata + fseek(i, 0L, SEEK_SET); + const word scritti = fwrite((char*)(const char*)buffer,sizeof(char),size,i); + + fclose(i); + } +} + +void TInv_cont::calcola_totale_record() +{ + _tras_file.open(_header); + leggi_record_controllo(); + + TString sigle = _tras_file.sigle_file(); + sigle.trim(); + + _tot_rec = 0; + + for (int i = 0; i < sigle.len(); i++) + { + long tot_rec = atol(_control_rec.mid((i * 6) + 95,6)); + _tot_rec += tot_rec; + } + _tot_rec += 1; +} + +void TInv_cont::setta_tabella_studio(TMask& m,bool flag_ditta) +{ + TTable ins ("%INS"); + TString dep; + long ditta; + + if (flag_ditta) + ditta = m.get_long(F_DITTAINV); + else + ditta = 0; + + dep.format("%-3s", (const char*) "INS"); + + ins.zero(); + ins.put("CODTAB", dep); + if (ins.read() == NOERR) + { + ins.put("I0", ditta); + ins.rewrite(); + } + else + warning_box("Tabella studio per invio NON AGGIORNATA"); +} + +void TInv_cont::setta_tabella_ditta(TMask& m,const char* flag, bool comp) +{ + TTable ind ("%IND"); + TString dep; + + long ditta = m.get_long(F_DITTAINV); + + dep.format("%05d", ditta); + + ind.zero(); + ind.put("CODTAB", dep); + if (ind.read() == NOERR) + { + int num = m.get_int(F_NUMULINV); + num++; + TDate data (m.get(F_DATALIM)); + + ind.put("S6", flag); + if (comp) + { + ind.put("I0", (long)num); + ind.put("D0", data); + } + ind.rewrite(); + } + else + warning_box("Tabella ditta per invio NON AGGIORNATA"); +} + +void TInv_cont::crea_record_controllo(TMask& m) +{ + int size = 1024; + TString buffer(1024); + TString str; + + if (_tras_file.exist()) + _tras_file.open(_header); + else + { + _tras_file.open(_header,TRUE); //Metto il parametro TRUE (che di default e' FALSE), perche' voglio creare un file che non e' ancore esistente + + buffer.spaces(); + buffer.overwrite(" 1",0); //Tipo record + + str = format("%-10s", (const char*) _nome_simbolico); + buffer.overwrite(str,60); //Nome studio + + long ditta = m.get_long(F_DITTAINV); + str = format("%05d", ditta); + buffer.overwrite(str,70); //Ditta inviante + + int num = m.get_int(F_NUMULINV); + num++; + str = format("%03d", num); + buffer.overwrite(str,75); //Numero progr. invio + + TString data (m.get(F_DATALIM)); + str = riconverti(data,TRUE); + buffer.overwrite(str,78); //Data limite invio + + str = format("%-9s", (const char*) _files); + buffer.overwrite(str,86); + + str = _files.sub(0,1); + buffer.overwrite(str,240); + + str = ""; + str.format("%054d", 0); + buffer.overwrite(str,95); + + if (_scelta == 'S') + { + str.format("%04ld", _dittaAS); + buffer.overwrite(str,301); + } + else + { + str.format("%05ld", _dittaAS); + buffer.overwrite(str,301); + } + + if (!_tras_file.write_control_rec(buffer, size)) + warning_box("Il record di controllo del file trasfer non e' stato aggiornato correttamente"); + } + _tras_file.close(); +} + +const char* TInv_cont::cerca_provincia(const TString& comcf) +{ + TLocalisamfile comuni(LF_COMUNI); + + comuni.setkey(1); + comuni.zero(); + comuni.put(COM_COM, comcf); + if (comuni.read() == NOERR) + TEMP = comuni.get(COM_PROVCOM); + else + TEMP = ""; + + return TEMP; +} + +bool TInv_cont::invio_tempfile(TMask& m) +{ + char uselab; + TString record(256),key,nrec; + int posiz,i; + char sigla; + + _tras_file.open(_header); + + leggi_record_controllo(); + + uselab = (_tras_file.ult_file())[0]; + + if (uselab == '\0') //Significa che sono in caso di ripartenza ma ho + return TRUE; //gia' trasferito tutti gli archivi e devo solo fare la copia su dischi + + posiz = _files.find(uselab); //Ritorna la posizione della sigla all'interno della schiera + key = _tras_file.key(); + key.trim(); + nrec = _tras_file.nrec_file(); + + for (i = posiz; i < _files.len();i++) + { + sigla = _files[i]; + _numrec = atol(nrec.mid(i * 6,6)); + + switch (sigla) + { + case 'W': + causali2tempfile(key,m); + break; + + case 'A': + clifo2tempfile(key,m); + break; + + case 'P': + pcon2tempfile(key,m); + break; + + case 'Z': + movPN2tempfile(key,m); + break; + + case 'U': + movIVA2tempfile(key,m); + break; + + default: + break; + }; + key = ""; + } + + // Finito di trasferire tutti gli archivi pulisco la sigla ultimo file da elaborare + _tras_file.open(_header); + leggi_record_controllo(); + _control_rec.overwrite(" ",240); + _tras_file.write_control_rec(_control_rec,1024); + _tras_file.close(); + + setta_tabella_ditta(m,"D",FALSE); + setta_parametri_record(m,"D"); + + return TRUE; +} + +void TInv_cont::causali2tempfile(TString& key, TMask& m) +{ + int size = 1024; + + _tras_file.open(_header); + + long items = _caus->items(); + _prog = new TProgind(items,"Invio tabella causali in corso... Prego attendere.",FALSE); + + _caus->setkey(1); + + if (key.empty()) + _caus->first(); + else + { + TString causale (key.mid(0,3)); + _caus->zero(); + _caus->put(CAU_CODCAUS, causale); + _caus->read(); + } + + for(; !_caus->eof(); _caus->next()) + { + _prog->addstatus(1); + + TString codcaus = _caus->get(CAU_CODCAUS); + + _tcaus->curr() = _caus->curr(); + + if (_tcaus->read() == NOERR) // Esiste la testata + { + scrivi_righe_causali(codcaus,'W'); + + _tcaus->zero(); + _tcaus->curr() = _caus->curr(); + _tcaus->rewrite(); + } + else + { + scrivi_righe_causali(codcaus,'W'); + + _tcaus->zero(); + _tcaus->curr() = _caus->curr(); + _tcaus->write(); + } + + leggi_record_controllo(); + TString chiave; + chiave.format("%3s",(const char*) codcaus); + _control_rec.overwrite("W",240); + _control_rec.overwrite(chiave,241); + + _tras_file.write_control_rec(_control_rec,size); + } + delete _prog; + + //Inizializzo l'ultima sigla file elaborato su trasfer con la sigla del file successivo da inviare + //e inizializzo la chiave, altrimenti se si blocca l'invio subito dopo aver finito un file si rischia di + //ritrasferire l'ultimo record quando si riparte; inoltre non si riesce a inviare il file successivo perche' + //la chiave e' compilata con i dati del file precedente. + + leggi_record_controllo(); + TString chiave,app,sigla; + app.format("%-15s", (const char*) chiave); + char sigla_p = _tras_file.ult_file()[0]; + int posiz = _files.find(sigla_p); + TString nuova_sigla = " "; + if (posiz < _files.len()) + nuova_sigla = _files.mid(posiz+1,1); + + _control_rec.overwrite(nuova_sigla,240); + _control_rec.overwrite(app,241); + _tras_file.write_control_rec(_control_rec,size); + _tras_file.close(); + +// setta_tabella_ditta(m,"D",FALSE); +// setta_parametri_record(m,"D"); +} + +void TInv_cont::cancella_righe_causali(TString& codcaus) +{ + _trcaus->setkey(1); + _trcaus->zero(); + _trcaus->put(RCA_CODCAUS, codcaus); + TRectype rcau (LF_RCAUSALI); + rcau = _trcaus->curr(); + for (_trcaus->read(); !_trcaus->eof(); _trcaus->next()) + { + if (_trcaus->curr() > rcau) break; + + _trcaus->remove(); + } +} + +void TInv_cont::scrivi_righe_causali(TString& codcaus, char uselab) +{ + cancella_righe_causali(codcaus); + + _rcaus->setkey(1); + _rcaus->zero(); + _rcaus->put(RCA_CODCAUS, codcaus); + TRectype rcau (LF_RCAUSALI); + rcau = _rcaus->curr(); + for (_rcaus->read(); !_rcaus->eof(); _rcaus->next()) + { + if (_rcaus->curr() > rcau) break; + + _trcaus->curr() = _rcaus->curr(); + _trcaus->write(); + + leggi_record_controllo(); + TString chiave; + chiave.format("%3s",(const char*) codcaus); + TString sigla (format("%c", uselab)); + _control_rec.overwrite(sigla,240); + _control_rec.overwrite(chiave,241); + _tras_file.write_control_rec(_control_rec,1024); + } +} + +void TInv_cont::clifo2tempfile(TString& key, TMask& m) +{ + int size = 1024; + + _tras_file.open(_header); + + long items = _clifo->items(); + _prog = new TProgind(items,"Invio Clienti / Fornitori in corso... Prego attendere.",FALSE); + + _clifo->setkey(1); + + if (key.empty()) + _clifo->first(); + else + { + char tipo = (key.mid(0,1))[0]; + long codice = atol(key.mid(1,6)); + _clifo->zero(); + _clifo->put(CLI_TIPOCF, tipo); + _clifo->put(CLI_CODCF, codice); + _clifo->read(); + } + + for(; !_clifo->eof(); _clifo->next()) + { + _prog->addstatus(1); + + char tipocf = _clifo->get_char(CLI_TIPOCF); + long codcf = _clifo->get_long(CLI_CODCF); + + _tclifo->curr() = _clifo->curr(); + + if (_tclifo->read() == NOERR) // Esiste gia' il cliente + { + _tclifo->zero(); + _tclifo->curr() = _clifo->curr(); + _tclifo->rewrite(); + } + else + { + _tclifo->zero(); + _tclifo->curr() = _clifo->curr(); + _tclifo->write(); + } + + leggi_record_controllo(); + TString chiave; + chiave.format("%c%06ld", tipocf, codcf); + TString sigla (format("%c", 'A')); + _control_rec.overwrite(sigla,240); + _control_rec.overwrite(chiave,241); + + _tras_file.write_control_rec(_control_rec,size); + } + delete _prog; + + //Inizializzo l'ultima sigla file elaborato su trasfer con la sigla del file successivo da inviare + //e inizializzo la chiave, altrimenti se si blocca l'invio subito dopo aver finito un file si rischia di + //ritrasferire l'ultimo record quando si riparte; inoltre non si riesce a inviare il file successivo perche' + //la chiave e' compilata con i dati del file precedente. + + leggi_record_controllo(); + TString chiave,app,sigla; + app.format("%-15s", (const char*) chiave); + char sigla_p = _tras_file.ult_file()[0]; + int posiz = _files.find(sigla_p); + TString nuova_sigla = " "; + if (posiz < _files.len()) + nuova_sigla = _files.mid(posiz+1,1); + + _control_rec.overwrite(nuova_sigla,240); + _control_rec.overwrite(app,241); + _tras_file.write_control_rec(_control_rec,size); + _tras_file.close(); + +// setta_tabella_ditta(m,"D",FALSE); +// setta_parametri_record(m,"D"); +} + + +void TInv_cont::pcon2tempfile(TString& key, TMask& m) +{ + int size = 1024; + + _tras_file.open(_header); + + long items = _pcon->items(); + _prog = new TProgind(items,"Invio Piano dei Conti in corso... Prego attendere.",FALSE); + + _pcon->setkey(1); + + if (key.empty()) + _pcon->first(); + else + { + int gruppo = atoi(key.mid(0,3)); + int conto = atoi(key.mid(3,3)); + long sottoc = atol(key.mid(6,6)); + + _pcon->zero(); + _pcon->put(PCN_GRUPPO, gruppo); + if (conto != 0) + _pcon->put(PCN_CONTO, conto); + if (sottoc != 0) + _pcon->put(PCN_SOTTOCONTO, sottoc); + _pcon->read(); + } + + for(; !_pcon->eof(); _pcon->next()) + { + _prog->addstatus(1); + + int g = _pcon->get_int (PCN_GRUPPO); + int c = _pcon->get_int (PCN_CONTO); + long s = _pcon->get_long(PCN_SOTTOCONTO); + + _tpcon->curr() = _pcon->curr(); + + if (_tpcon->read() == NOERR) // Esiste gia' il cliente + { + _tpcon->zero(); + _tpcon->curr() = _pcon->curr(); + _tpcon->rewrite(); + } + else + { + _tpcon->zero(); + _tpcon->curr() = _pcon->curr(); + _tpcon->write(); + } + + leggi_record_controllo(); + TString chiave; + chiave.format("%3d%3d%6ld", g, c, s); + TString sigla (format("%c", 'P')); + _control_rec.overwrite(sigla,240); + _control_rec.overwrite(chiave,241); + + _tras_file.write_control_rec(_control_rec,size); + } + delete _prog; + + //Inizializzo l'ultima sigla file elaborato su trasfer con la sigla del file successivo da inviare + //e inizializzo la chiave, altrimenti se si blocca l'invio subito dopo aver finito un file si rischia di + //ritrasferire l'ultimo record quando si riparte; inoltre non si riesce a inviare il file successivo perche' + //la chiave e' compilata con i dati del file precedente. + + leggi_record_controllo(); + TString chiave,app,sigla; + app.format("%-15s", (const char*) chiave); + char sigla_p = _tras_file.ult_file()[0]; + int posiz = _files.find(sigla_p); + TString nuova_sigla = " "; + if (posiz < _files.len()) + nuova_sigla = _files.mid(posiz+1,1); + + _control_rec.overwrite(nuova_sigla,240); + _control_rec.overwrite(app,241); + _tras_file.write_control_rec(_control_rec,size); + _tras_file.close(); + +// setta_tabella_ditta(m,"D",FALSE); +// setta_parametri_record(m,"D"); +} + +void TInv_cont::primanota_inviata(long numreg) +{ + _mov->setkey(1); + _mov->zero(); + _mov->put(MOV_NUMREG, numreg); + if (_mov->read() == NOERR) + { + _mov->put(MOV_INVIATO, "X"); + if (_flag_bollato) + _mov->put(MOV_STAMPATO, "X"); + + _mov->rewrite(); + } +} + +void TInv_cont::scrivi_righePN(long numreg) +{ + int size = 1024; + + _tras_file.open(_header); + + _rmov->setkey(1); + _rmov->zero(); + _rmov->put(RMV_NUMREG, numreg); + TRectype rmov (LF_RMOV); + rmov = _rmov->curr(); + for (_rmov->read(); !_rmov->eof(); _rmov->next()) + { + if (_rmov->curr() > rmov) break; + + _trmov->zero(); + _trmov->curr() = _rmov->curr(); + _trmov->write(); + } +} + +void TInv_cont::movPN2tempfile(TString& key, TMask& m) +{ + int size = 1024; + + _tras_file.open(_header); + + long items = _mov->items(); + _prog = new TProgind(items,"Invio movimenti di Primanota in corso... Prego attendere.",FALSE); + + _mov->setkey(1); + + if (key.empty()) + _mov->first(); + else + { + long numreg = atol(key.mid(0,7)); + _mov->zero(); + _mov->put(MOV_NUMREG, numreg); + _mov->read(); + } + + for(; !_mov->eof(); _mov->next()) + { + _prog->addstatus(1); + + long nreg = _mov->get_long(MOV_NUMREG); + + TDate datareg (_mov->get_date(MOV_DATAREG)); + + if ( _mov->get_bool(MOV_INVIATO) || datareg > _datalimsk ) continue; + + _tmov->curr() = _mov->curr(); + + if (_tmov->read() == NOERR) + { + _tmov->zero(); + _tmov->curr() = _mov->curr(); + _tmov->rewrite(); + + scrivi_righePN(nreg); + } + else + { + _tmov->zero(); + _tmov->curr() = _mov->curr(); + _tmov->write(); + + scrivi_righePN(nreg); + } + + leggi_record_controllo(); + TString chiave; + chiave.format("%07ld", nreg); + TString sigla (format("%c", 'Z')); + _control_rec.overwrite(sigla,240); + _control_rec.overwrite(chiave,241); + _tras_file.write_control_rec(_control_rec,size); + + primanota_inviata(nreg); + } + delete _prog; + + //Inizializzo l'ultima sigla file elaborato su trasfer con la sigla del file successivo da inviare + //e inizializzo la chiave, altrimenti se si blocca l'invio subito dopo aver finito un file si rischia di + //ritrasferire l'ultimo record quando si riparte; inoltre non si riesce a inviare il file successivo perche' + //la chiave e' compilata con i dati del file precedente. + + leggi_record_controllo(); + TString chiave,app,sigla; + app.format("%-15s", (const char*) chiave); + char sigla_p = _tras_file.ult_file()[0]; + int posiz = _files.find(sigla_p); + TString nuova_sigla = " "; + if (posiz < _files.len()) + nuova_sigla = _files.mid(posiz+1,1); + + _control_rec.overwrite(nuova_sigla,240); + _control_rec.overwrite(app,241); + _tras_file.write_control_rec(_control_rec,size); + _tras_file.close(); + +// setta_tabella_ditta(m,"D",FALSE); +// setta_parametri_record(m,"D"); +} + +bool TInv_cont::occasionali(const TString& cfpi) +{ + TString chiave; + + _occas->setkey(1); + _occas->zero(); + _occas->put("CFPI", cfpi); + _occas->read(); + + _toccas->zero(); + _toccas->curr() = _occas->curr(); + + if (_toccas->read() == NOERR) + { + _toccas->zero(); + _toccas->curr() = _occas->curr(); + _toccas->rewrite(); + } + else + { + _toccas->zero(); + _toccas->curr() = _occas->curr(); + _toccas->write(); + } + + return TRUE; +} + +void TInv_cont::iva_inviata(long numreg) +{ + _mov->setkey(1); + _mov->zero(); + _mov->put(MOV_NUMREG, numreg); + if (_mov->read() == NOERR) + { + _mov->put(MOV_INVIVA, "X"); + if (_flag_bollato) + _mov->put(MOV_REGST, "X"); + + _mov->rewrite(); + } +} + +void TInv_cont::movIVA2tempfile(TString& key, TMask& m) +{ + TString ocfpi; + TDate datareg; + bool inviva; + int size = 1024; + + _tras_file.open(_header); + + long items = _rmoviva->items(); + _prog = new TProgind(items,"Invio movimenti Iva in corso... Prego attendere.",FALSE); + + _rmoviva->setkey(1); + + if (key.empty()) + _rmoviva->first(); + else + { + long numreg = atol(key.mid(0,7)); + _rmoviva->zero(); + _rmoviva->put(RMI_NUMREG, numreg); + _rmoviva->put(RMI_NUMRIG, 1); + _rmoviva->read(); + } + + long nreg_p = -1; + + for(; !_rmoviva->eof(); _rmoviva->next()) + { + _prog->addstatus(1); + + long nreg = _rmoviva->get_long(RMI_NUMREG); + + if (nreg != nreg_p) + { + _mov->setkey(1); + _mov->zero(); + _mov->put(MOV_NUMREG, nreg); + if (_mov->read() == NOERR) + { + datareg = _mov->get_date(MOV_DATAREG); + inviva = _mov->get_bool(MOV_INVIVA); + ocfpi = _mov->get (MOV_OCFPI); + } + } + else + inviva = FALSE; + + if ( inviva || datareg > _datalimsk ) continue; + + if (ocfpi.not_empty()) + occasionali(ocfpi); + + _triva->zero(); + _triva->curr() = _rmoviva->curr(); + + if (_triva->read() == NOERR) + { + _triva->zero(); + _triva->curr() = _rmoviva->curr(); + _triva->rewrite(); + } + else + { + _triva->zero(); + _triva->curr() = _rmoviva->curr(); + _triva->write(); + } + + leggi_record_controllo(); + TString chiave; + chiave.format("%07ld", nreg); + TString sigla (format("%c", 'U')); + _control_rec.overwrite(sigla,240); + _control_rec.overwrite(chiave,241); + + _tras_file.write_control_rec(_control_rec,size); + + if (nreg != nreg_p) + iva_inviata(nreg); + + nreg_p = nreg; + } + delete _prog; + + //Inizializzo l'ultima sigla file elaborato su trasfer con la sigla del file successivo da inviare + //e inizializzo la chiave, altrimenti se si blocca l'invio subito dopo aver finito un file si rischia di + //ritrasferire l'ultimo record quando si riparte; inoltre non si riesce a inviare il file successivo perche' + //la chiave e' compilata con i dati del file precedente. + + leggi_record_controllo(); + TString chiave,app,sigla; + app.format("%-15s", (const char*) chiave); + char sigla_p = _tras_file.ult_file()[0]; + int posiz = _files.find(sigla_p); + TString nuova_sigla = " "; + if (posiz < _files.len()) + nuova_sigla = _files.mid(posiz+1,1); + + _control_rec.overwrite(nuova_sigla,240); + _control_rec.overwrite(app,241); + _tras_file.write_control_rec(_control_rec,size); + _tras_file.close(); + +// setta_tabella_ditta(m,"D",FALSE); +// setta_parametri_record(m,"D"); +} + +bool TInv_cont::menu(MENU_TAG m) +{ + if (m == BAR_ITEM(1)) + return main_loop(); + return FALSE; +} + +int cg6900 (int argc, char* argv[]) +{ + switch (*argv[2]) + { + case 'S': + { + TInv_cont main_app(*argv[2]); + main_app.run(argc, argv,main_app._titolo); + } + break; + case 'P': + { + TInv_cont main_app(*argv[2]); + main_app.run(argc, argv,main_app._titolo); + } + break; + case 'L': + { + TLista_archivi a; + a.run(argc, argv,"Lista controllo archivi"); + } + break; + case 'R': + { + TRip_flag a; + a.run(argc, argv,"Ripristino flag movimenti"); + } + break; + default: + break; + } + + return TRUE; +} diff --git a/cg/cglib.h b/cg/cglib.h index 07154c0fe..54f1d0823 100755 --- a/cg/cglib.h +++ b/cg/cglib.h @@ -39,14 +39,17 @@ public: }; enum tipobil { DataLimite=1, UltimaImmissione }; +enum tiposal { normale, apertura, chiusura }; + const int EsePre(const int EseCorr); class TSaldo { - real _saldo, _saldo_iniziale, _saldoiniziale; - real _prg_dare, _prg_avere, _prg_daresca, _prg_averesca; + TLocalisamfile _saldi; + + real _saldo, _saldo_iniziale, _saldoiniziale; // oh my GOSH + real _prg_dare, _prg_avere; int _indbil; - TRectype* _saldo_ep; int _annoes; TDate _inizioEs, _fineEs; TString16 _codcaus; @@ -62,14 +65,15 @@ class TSaldo protected: void InFinEs(int); - void leggi_mov(long numreg); // Leggi testata + bool leggi_mov(long numreg); // Leggi testata real calcola_saldo_iniziale(int g, int c, long s, int indbil); + bool prg_saldo(int, TConto&, real&, real&, bool); public: bool movimentato() const { return _movimentato; } bool significativo() const { return _significativo; } - bool esiste_saldo() const { return _rec_presente_ec || _rec_presente_ep;} + bool esiste_saldo() const { return _rec_presente_ec || _rec_presente_ep; } bool esiste_saldo_ep() const { return _rec_presente_ep; } int annoes () const { return _annoes; } @@ -83,22 +87,25 @@ public: bool ultima_immissione_verifica(int anno,int g,int c,long s,int indbil,int prov); bool data_limite_bilancio(int,int,int,long,const TDate&,const TDate&,int,int); - TRectype& ricerca_progr_prec(int, int, int, long); + bool ricerca_progr_prec(int, int, int, long); real saldofin_esprec(int,int,int,long); - bool prg_attuali(int,TConto&,real&,real&); - bool prg_mov_eliminati(int,TConto&,real&,real&); + bool prg_attuali(int i,TConto& c, real& p1, real& p2) + { return prg_saldo(i, c, p1, p2, FALSE); } + bool prg_mov_eliminati(int i, TConto& c, real& p1, real& p2) + { return prg_saldo(i, c, p1, p2, TRUE); } const real& saldo() const { return _saldo;} const real& saldoini() const { return _saldo_iniziale;} const real& saldoinisusaldi() const { return _saldoiniziale;} const real& prgdare() const { return _prg_dare;} const real& prgavere() const { return _prg_avere;} - const bool flagprec() { return _prec; } - bool prg_attuali(int,TConto&,int,real&,real&); - bool prg_mov_eliminati(int,TConto&,int,real&,real&); + const bool flagprec() { return _prec; } + +// bool prg_attuali(int i,TConto& c, int d, real& p1, real& p2); +// bool prg_mov_eliminati(int i,TConto& c,int d, real& p1, real& p2); + TSaldo(); - ~TSaldo(); }; @@ -107,18 +114,18 @@ class TTab_conti : public TAssoc_array { public: void aggiorna_conto(const TBill& tc, int anno_es, const TImporto& importo, - bool movap, bool provv, bool somma, bool movimentato); + tiposal movap, bool provv, bool somma, bool movimentato, bool scaricato); - TConto* add(const TBill& c, int anno); - TConto* find(const TBill& c, int anno); - void remove(const TBill& c, int anno); + TConto* add(const TBill& c, int anno, bool provv = FALSE); + TConto* find(const TBill& c, int anno, bool provv = FALSE); + void remove(const TBill& c, int anno, bool provv = FALSE); }; class TSaldo_agg : public TObject { TTab_conti _tab_conti; - bool _movap; // se e' mov. d'apertura (aggiorno SALDO e FLAGSALINI in saldi) + tiposal _movap; // se e' mov. d'apertura (aggiorno SALDO e FLAGSALINI in saldi) bool _provv; int _anno_es; // anno esercizio TDate _data_ulmov; // data ultimo movimento @@ -130,17 +137,17 @@ class TSaldo_agg : public TObject public: void clear_saldi(int year); void registra(); - void aggiorna (const TBill& tc, const TImporto& importo, bool somma=TRUE); + void aggiorna (const TBill& tc, const TImporto& importo, bool somma=TRUE, bool scaricato = FALSE); void aggiorna (int gruppo, int conto, long sottoconto, - const real& importo, char sezione, bool somma=TRUE); + const real& importo, char sezione, bool somma=TRUE, bool scaricato = FALSE); TConto* find(const TBill& c, int anno) { return _tab_conti.find(c, anno); } void set_anno_es(int anno) { _anno_es = anno; } int anno_es() const { return _anno_es; } - void set_movap (bool movap) { _movap = movap; } - bool movap() const { return _movap; } + void set_tipo_saldo (tiposal movap) { _movap = movap; } + tiposal tipo_saldo() const { return _movap; } void set_movprovv (bool p) { _provv = p; } bool movprovv() const { return _provv; } diff --git a/cg/cglib01.cpp b/cg/cglib01.cpp index 9dad4917f..392801e26 100755 --- a/cg/cglib01.cpp +++ b/cg/cglib01.cpp @@ -1,14 +1,7 @@ // cglib01.cpp // calcolo dei saldi -// La compilazione e' gia' lenta da sola: evitare include inutili (Guy) -// #include -// #include - #include - -#include "cglib.h" - #include #include #include @@ -16,15 +9,14 @@ #include #include +#include "cglib.h" /////////////////////////////////////////////////////////// // Causale /////////////////////////////////////////////////////////// -TCaus::TCaus(const char* cod) -: _rec(LF_CAUSALI) +TCaus::TCaus(const char* cod) : _rec(LF_CAUSALI) { - //if (*cod) read(cod); read(cod); } @@ -57,7 +49,6 @@ bool TCaus::apertura() const // // Cerca l'esercizio precedente di EseCorr // Se EseCorr e' gia' il primo ritorna 0 -// senno' ritorna il precedente (Stavolta meno astutamente, ma correttamente) // const int EsePre(const int EseCorr) { @@ -80,41 +71,25 @@ TSaldi_list::TSaldi_list(int gr, int co, int aec, int aep_par) if (aep_par == 0) aep = EsePre(aec); - // if (aep) cf.setkey(2); - /* else - { - cf.setkey(1); - cf.put(SLD_ANNOES,aec); - } - */ cf.put(SLD_GRUPPO,gr); cf.put(SLD_CONTO,co); - // TRectype rec(cf.curr()); for (cf.read(_isgteq);!cf.eof();cf.next()) { - // if (cf.curr() > rec) break; const int ae = cf.get_int(SLD_ANNOES); const int g = cf.get_int(SLD_GRUPPO); const int c = cf.get_int(SLD_CONTO); const long s = cf.get_long(SLD_SOTTOCONTO); if (g != gr || c != co) break; - - // if (aep) { if (ae != aec && ae != aep) continue; - // } TRectype r(cf.curr()); key.format("%3d%3d%6ld", g, c, s); // Se avevo chiesto anche l'es. prec. puo' darsi che l'abbia gia' trovato - if (aep_par) - force = FALSE; - else - force = TRUE; - + force = !aep_par; add((const char*) key, r, force); } } @@ -122,65 +97,34 @@ TSaldi_list::TSaldi_list(int gr, int co, int aec, int aep_par) TRectype* TSaldi_list::saldi() const { TObject* o = ((TAssoc_array*)this)->get(); - if (o == NULL) - return (TRectype*)NULL; - else - return (TRectype*)o; + return (TRectype*)o; } -TSaldo::TSaldo() -{ - _saldo_ep = new TRectype(LF_SALDI); - _saldo_iniziale = ZERO; - _saldoiniziale = ZERO; - _prg_dare = ZERO; - _prg_avere = ZERO; - _saldo = ZERO; - _annoes = 0; - _indbil = 0; - _prec = FALSE; - _movimentato = _significativo = FALSE; - _rec_presente_ec = _rec_presente_ep = FALSE; -} - -TSaldo::~TSaldo() -{ - delete _saldo_ep; -} +TSaldo::TSaldo() : _saldi(LF_SALDI), _saldoiniziale(ZERO), _saldo_iniziale(ZERO), + _prg_dare(ZERO), _prg_avere(ZERO), _saldo(ZERO), _annoes(0), + _indbil(0), _prec(FALSE), _movimentato(FALSE), _significativo(FALSE), + _rec_presente_ec(FALSE), _rec_presente_ep(FALSE) +{} real TSaldo::saldofin_esprec(int annoes, int g, int c, long s) { const int annoesprec = EsePre(annoes); - if (annoesprec == 0) // non ci sono esercizi prima del primo - { - _rec_presente_ep = FALSE; - _significativo = FALSE; + _significativo = FALSE; + + if (!ricerca_progr_prec(annoesprec, g, c, s)) // non ci sono esercizi prima del primo return ZERO; - } - const TRectype& app = ricerca_progr_prec(annoesprec, g, c, s); - - const char flag = app.get(SLD_FLAGSALINI)[0]; - const real saldo = app.get_real(SLD_SALDO); - const real pdare = app.get_real(SLD_PDARE); - const real pavere = app.get_real(SLD_PAVERE); - //const real pdaresca = app.get_real(SLD_PDARESCA); - //const real paveresca = app.get_real(SLD_PAVERESCA); - - /* - _significativo = (saldo != ZERO || pdare != ZERO || pavere != ZERO - || pdaresca != ZERO || paveresca != ZERO); - */ + const char flag = _saldi.get(SLD_FLAGSALINI)[0]; + const real saldo = _saldi.get_real(SLD_SALDO); + const real pdare = _saldi.get_real(SLD_PDARE); + const real pavere = _saldi.get_real(SLD_PAVERE); + _significativo = (saldo != ZERO || pdare != ZERO || pavere != ZERO); - //real tot = pdare-pavere+pdaresca-paveresca; real tot = pdare-pavere; - if (flag == 'D') - tot += saldo; - else - tot -= saldo; - + if (flag == 'D') tot += saldo; + else tot -= saldo; return tot; } @@ -188,55 +132,33 @@ real TSaldo::saldofin_esprec(int annoes, int g, int c, long s) //in realta' calcola il saldo finale es.prec real TSaldo::calcola_saldo_iniziale(int g,int c,long s,int indbil) { - real saldoini, pdaresca, paveresca, pdare, pavere; - char flag; - TLocalisamfile saldi(LF_SALDI, FALSE); - + real saldoini; _significativo = TRUE; - saldi.zero(); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - saldi.put(SLD_ANNOES,_annoes); + _saldi.zero(); + _saldi.put(SLD_GRUPPO,g); + _saldi.put(SLD_CONTO,c); + _saldi.put(SLD_SOTTOCONTO,s); + _saldi.put(SLD_ANNOES,_annoes); - if (saldi.read() == NOERR) - _rec_presente_ec = TRUE; - else - { - saldi.zero(); - _rec_presente_ec = FALSE; - } - - flag = saldi.get_char(SLD_FLAGSALINI); - saldoini = saldi.get_real(SLD_SALDO); - - _significativo = (saldoini != ZERO); + if (_rec_presente_ec = (_saldi.read() == NOERR)) + saldoini = _saldi.get_real(SLD_SALDO); + _significativo = _rec_presente_ec && saldoini != ZERO; + if (saldoini != ZERO) //non va considerato!!! Vedi appunti _saldo_iniziale = ZERO; if (saldoini == ZERO) { - if ( indbil == 1 || indbil == 2 || indbil == 5 ) + if (indbil == 1 || indbil == 2 || indbil == 5) { _prec = TRUE; saldoini = saldofin_esprec(_annoes, g, c, s); - flag = 'D'; // Il segno DEVE essere quello del saldo precedente } _saldo_iniziale = saldoini; } - -#ifdef DBG - TString sldi(saldoini.string()); -#endif - - //if (flag == 'D') - //return saldoini; return _saldo_iniziale; - //else - //return (-saldoini); - //return (-_saldo_iniziale); } const char* TSaldo::causale_chiusura_es() @@ -251,20 +173,22 @@ const char* TSaldo::causale_apertura_es() return conf.get("CoCaAp"); } -void TSaldo::leggi_mov(long nr) +bool TSaldo::leggi_mov(long nr) { TLocalisamfile mov(LF_MOV, FALSE); - + bool ok = TRUE; + mov.zero(); mov.put (MOV_NUMREG,nr); - if (mov.read() == NOERR) + if (ok = (mov.read() == NOERR)) { _codcaus = mov.get (MOV_CODCAUS); _datareg = mov.get_date(MOV_DATAREG); _provv = mov.get (MOV_PROVVIS); _datacomp = mov.get_date(MOV_DATACOMP); - } + } + return ok; } //per bilancio scalare (ovvero a sezioni contrapposte) per data limite @@ -315,40 +239,31 @@ bool TSaldo::data_limite_bilancio(int bilancio, int g, int c, long s, const TDat data_mov = _datacomp; else { - if (_annoes == 0) + if (_annoes == 0) data_mov = _datareg; else data_mov = _datacomp; } + if (data_mov < data_inf || data_mov > data_sup) continue; // "Se la causale del movimento e' uguale a quella di chiusura, // o di apertura il movimento non va considerato" - // if (_codcaus.not_empty()) - // if (_codcaus == causale_chiusura_es() || - // _codcaus == causale_apertura_es()) - // continue; - - // Modifica del 03-03-1995 - TCaus cau(_codcaus); + TCaus cau(_codcaus); if (_codcaus.not_empty()) - if (cau.chiusura()) //|| cau.apertura()) - continue; + if (cau.chiusura()) continue; - /* - if (!stp_prov && _provv.trim().not_empty()) - continue; - */ - - if (stp_prov == 1 && _provv.trim().not_empty()) //bilancio normale (non comprende i provvisori) + //bilancio normale (non comprende i provvisori) ? + if (stp_prov == 1 && _provv.trim().not_empty()) continue; - if (stp_prov == 3 && _provv.trim().empty()) //bilancio dei soli provvisori + //bilancio dei soli provvisori ? + if (stp_prov == 3 && _provv.trim().empty()) continue; - // "I mov. di puro riferimento (= con importo = 0) vanno scartati" + // I mov. di puro riferimento (= con importo = 0) vanno scartati if (importo == ZERO) continue; gcs_corr.format ("%3d%3d%6ld", gruppo, conto, sottoconto); @@ -359,10 +274,6 @@ bool TSaldo::data_limite_bilancio(int bilancio, int g, int c, long s, const TDat if (stp_prov != 3) //bilancio normale o globale _saldo = calcola_saldo_iniziale(gruppo,conto,sottoconto,indbil); } - -#ifdef DBG - TString dep1(_saldo.string()); -#endif _movimentato = TRUE; @@ -371,9 +282,6 @@ bool TSaldo::data_limite_bilancio(int bilancio, int g, int c, long s, const TDat else _saldo -= importo; } -#ifdef DBG - TString dep2(_saldo.string()); -#endif // Anche se non movimentato vado a vedere il saldo if (!_movimentato) @@ -394,47 +302,36 @@ bool TSaldo::ultima_immissione_verifica(int annoes,int g,int c,long s,int indbil real pdarepro, paverepro; bool esito = FALSE; - TLocalisamfile saldi(LF_SALDI); - _saldo_iniziale = ZERO; _saldoiniziale = ZERO; _prg_dare = ZERO; _prg_avere = ZERO; - _prg_daresca = ZERO; - _prg_averesca = ZERO; _saldo = ZERO; - saldi.zero(); + _saldi.zero(); + _saldi.put(SLD_ANNOES,annoes); + _saldi.put(SLD_GRUPPO,g); + _saldi.put(SLD_CONTO,c); + _saldi.put(SLD_SOTTOCONTO,s); - saldi.put(SLD_ANNOES,annoes); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - - if (saldi.read() == NOERR) - { - annoe = saldi.get_int(SLD_ANNOES); - gruppo = saldi.get_int(SLD_GRUPPO); - conto = saldi.get_int(SLD_CONTO); - sottoconto = saldi.get_long(SLD_SOTTOCONTO); - _saldo_iniziale = saldi.get_real(SLD_SALDO); - _prg_dare = saldi.get_real(SLD_PDARE); - _prg_avere = saldi.get_real(SLD_PAVERE); - pdarepro = saldi.get_real(SLD_PDAREPRO); - paverepro = saldi.get_real(SLD_PAVEREPRO); - sezione = saldi.get_char(SLD_FLAGSALINI); + if (_saldi.read() == NOERR) + { + annoe = _saldi.get_int(SLD_ANNOES); + gruppo = _saldi.get_int(SLD_GRUPPO); + conto = _saldi.get_int(SLD_CONTO); + sottoconto = _saldi.get_long(SLD_SOTTOCONTO); + _saldo_iniziale = _saldi.get_real(SLD_SALDO); + _prg_dare = _saldi.get_real(SLD_PDARE); + _prg_avere = _saldi.get_real(SLD_PAVERE); + pdarepro = _saldi.get_real(SLD_PDAREPRO); + paverepro = _saldi.get_real(SLD_PAVEREPRO); + sezione = _saldi.get_char(SLD_FLAGSALINI); if (stp_prov == 1) //bilancio normale (senza provvisori) if (_saldo_iniziale == ZERO && _prg_dare == ZERO && _prg_avere == ZERO) return esito; - if (stp_prov == 2) //bilancio globale (con provvisori) - if (_saldo_iniziale == ZERO && _prg_dare == ZERO && _prg_avere == ZERO - && pdarepro == ZERO && paverepro == ZERO) - return esito; - - if (stp_prov == 3) //bilancio dei soli mov. provvisori - if (pdarepro == ZERO && paverepro == ZERO) + if (stp_prov == ZERO && paverepro == ZERO) return esito; if (sezione == 'A') _saldo_iniziale = -_saldo_iniziale; @@ -476,42 +373,34 @@ bool TSaldo::ultima_immissione_bilancio(int annoes,int g,int c,long s,int indbil long sottoconto; real pdarepro, paverepro; bool esito = FALSE; - TLocalisamfile saldi(LF_SALDI, FALSE); _saldo_iniziale = ZERO; _prg_dare = ZERO; _prg_avere = ZERO; - _prg_daresca = ZERO; - _prg_averesca = ZERO; _saldo = ZERO; _rec_presente_ec = FALSE; _rec_presente_ep = FALSE; _prec = FALSE; - saldi.zero(); + _saldi.zero(); + _saldi.put(SLD_ANNOES,annoes); + _saldi.put(SLD_GRUPPO,g); + _saldi.put(SLD_CONTO,c); + _saldi.put(SLD_SOTTOCONTO,s); - saldi.put(SLD_ANNOES,annoes); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - - if (saldi.read() == NOERR) + if (_saldi.read() == NOERR) { - annoe = saldi.get_int(SLD_ANNOES); - gruppo = saldi.get_int(SLD_GRUPPO); - conto = saldi.get_int(SLD_CONTO); - sottoconto = saldi.get_long(SLD_SOTTOCONTO); - _saldo_iniziale = saldi.get_real(SLD_SALDO); - _prg_dare = saldi.get_real(SLD_PDARE); - _prg_avere = saldi.get_real(SLD_PAVERE); - pdarepro = saldi.get_real(SLD_PDAREPRO); - paverepro = saldi.get_real(SLD_PAVEREPRO); - sezione = saldi.get_char(SLD_FLAGSALINI); - - /* - esito = (_saldo_iniziale != ZERO || _prg_dare != ZERO || _prg_avere != ZERO - || _prg_daresca != ZERO || _prg_averesca != ZERO); - */ + annoe = _saldi.get_int(SLD_ANNOES); + gruppo = _saldi.get_int(SLD_GRUPPO); + conto = _saldi.get_int(SLD_CONTO); + sottoconto = _saldi.get_long(SLD_SOTTOCONTO); + _saldo_iniziale = _saldi.get_real(SLD_SALDO); + _prg_dare = _saldi.get_real(SLD_PDARE); + _prg_avere = _saldi.get_real(SLD_PAVERE); + pdarepro = _saldi.get_real(SLD_PDAREPRO); + paverepro = _saldi.get_real(SLD_PAVEREPRO); + sezione = _saldi.get_char(SLD_FLAGSALINI); + if (stp_prov == 1) //bilancio normale (senza provvisori) esito = (_saldo_iniziale != ZERO || _prg_dare != ZERO || _prg_avere != ZERO); @@ -535,7 +424,6 @@ bool TSaldo::ultima_immissione_bilancio(int annoes,int g,int c,long s,int indbil _saldo_iniziale += saldofin_esprec(annoes,g,c,s); } - //_saldo = _saldo_iniziale + _prg_dare - _prg_avere + _prg_daresca - _prg_averesca; if (stp_prov == 1) _saldo = _saldo_iniziale + _prg_dare - _prg_avere; @@ -548,123 +436,89 @@ bool TSaldo::ultima_immissione_bilancio(int annoes,int g,int c,long s,int indbil return esito; } -TRectype& TSaldo::ricerca_progr_prec (int annoesprec, int g, int c, long s) +bool TSaldo::ricerca_progr_prec (int annoesprec, int g, int c, long s) { - TLocalisamfile saldi(LF_SALDI); - -// Tre righe inutili che vengono gia' eseguite da TLocalisamfile (Guy) - const int oldkey = saldi.getkey(); - saldi.setkey(1); - saldi.zero(); - - saldi.put(SLD_ANNOES,annoesprec); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - - if (saldi.read() == NOERR) - _rec_presente_ep = TRUE; - else - { - saldi.zero(); + if (annoesprec == 0) _rec_presente_ep = FALSE; + else + { + const int oldkey = _saldi.getkey(); + _saldi.zero(); + _saldi.put(SLD_ANNOES,annoesprec); + _saldi.put(SLD_GRUPPO,g); + _saldi.put(SLD_CONTO,c); + _saldi.put(SLD_SOTTOCONTO,s); + _rec_presente_ep = _saldi.read() == NOERR; + _saldi.setkey(oldkey); } - - *_saldo_ep = saldi.curr(); - - // riposiziona... 7 righe inutili (Guy) - saldi.setkey(oldkey); - saldi.zero(); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - saldi.put(SLD_ANNOES,annoesprec+1); // Astuto anche questo (Guy) - saldi.read(_isequal); - - return (*_saldo_ep); + return _rec_presente_ep; } -//calcolo dei progressivi attuali -bool TSaldo::prg_attuali(int annoes,TConto& conto,real& prgdare,real& prgavere) +//calcolo dei progressivi attuali (normali o eliminati) +bool TSaldo::prg_saldo(int annoes, TConto& conto, real& prgdare, real& prgavere, bool scar) { - real saldoini = ZERO; - real pdare = ZERO; - real pavere = ZERO; - real pdaresca = ZERO; - real paveresca = ZERO; - char flagsalini; - int g = conto.gruppo(); - int c = conto.conto(); - long s = conto.sottoconto(); - TLocalisamfile saldi(LF_SALDI, FALSE); + _saldi.zero(); + _saldi.put(SLD_GRUPPO,conto.gruppo()); + _saldi.put(SLD_CONTO,conto.conto()); + _saldi.put(SLD_SOTTOCONTO,conto.sottoconto()); + _saldi.put(SLD_ANNOES,annoes); + + bool ok = _saldi.read() == NOERR; - saldi.zero(); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - saldi.put(SLD_ANNOES,annoes); - - if (saldi.read() == NOERR) - { - flagsalini = saldi.get_char(SLD_FLAGSALINI); - saldoini = saldi.get_real(SLD_SALDO); - pdare = saldi.get_real(SLD_PDARE); - pavere = saldi.get_real(SLD_PAVERE); - pdaresca = saldi.get_real(SLD_PDARESCA); - paveresca = saldi.get_real(SLD_PAVERESCA); + if (ok) + { + char flagsalini = _saldi.get_char(SLD_FLAGSALINI); + real saldoini = _saldi.get_real(SLD_SALDO); + real pdare = _saldi.get_real(SLD_PDARE); + real pavere = _saldi.get_real(SLD_PAVERE); + real pdaresca, paveresca; - if (flagsalini == 'D') - { - prgdare = saldoini + pdare + pdaresca; - prgavere = pavere + paveresca; - } - else - { - prgdare = pdare + pdaresca; - prgavere = saldoini + pavere + paveresca; - } - } - return TRUE; -} + // look for scaricated + _saldi.zero(); + _saldi.put(SLD_GRUPPO,conto.gruppo()); + _saldi.put(SLD_CONTO,conto.conto()); + _saldi.put(SLD_SOTTOCONTO,conto.sottoconto()); + _saldi.put(SLD_ANNOES,annoes); + _saldi.put(SLD_FLSCA, "X"); -bool TSaldo::prg_mov_eliminati(int annoes,TConto& conto,real& prgdare,real& prgavere) -{ - real saldoini = ZERO; - real pdaresca = ZERO; - real paveresca = ZERO; - char flagsalini; - int g = conto.gruppo(); - int c = conto.conto(); - long s = conto.sottoconto(); - TLocalisamfile saldi(LF_SALDI, FALSE); - - saldi.zero(); - saldi.put(SLD_GRUPPO,g); - saldi.put(SLD_CONTO,c); - saldi.put(SLD_SOTTOCONTO,s); - saldi.put(SLD_ANNOES,annoes); - - if (saldi.read() == NOERR) - { - flagsalini = saldi.get(SLD_FLAGSALINI)[0]; - saldoini = saldi.get_real(SLD_SALDO); - pdaresca = saldi.get_real(SLD_PDARESCA); - paveresca = saldi.get_real(SLD_PAVERESCA); - if (flagsalini == 'D') + if (_saldi.read() == NOERR) { - prgdare = saldoini + pdaresca; - prgavere = paveresca; + pdaresca = _saldi.get_real(SLD_PDARE); + paveresca = _saldi.get_real(SLD_PAVERE); + } + + // fill reals with proper kanker + if (scar) + { + if (flagsalini == 'D') + { + prgdare = saldoini + pdaresca; + prgavere = paveresca; + } + else + { + prgdare = pdaresca; + prgavere = saldoini + paveresca; + } } else - { - prgdare = pdaresca; - prgavere = saldoini + paveresca; + { + if (flagsalini == 'D') + { + prgdare = saldoini + pdare + pdaresca; + prgavere = pavere + paveresca; + } + else + { + prgdare = pdare + pdaresca; + prgavere = saldoini + pavere + paveresca; + } } + } - return TRUE; + return ok; } - diff --git a/cg/cglib02.cpp b/cg/cglib02.cpp index de1797ef1..94977338a 100755 --- a/cg/cglib02.cpp +++ b/cg/cglib02.cpp @@ -6,56 +6,80 @@ ///////////////////////////////////////////////////////////////////////////// #include - #include #include - -#include "cglib.h" - #include - -TConto* TTab_conti::add(const TBill& c, int anno) +#include "cglib.h" + +class TContoExt : public TConto +{ + bool _scaricato; + + public: + + bool scaricato() { return _scaricato; } + + TContoExt(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = NULL, bool sc = FALSE) + : TConto(g, c, s, t, d), _scaricato(sc) {} + TContoExt(TToken_string& tgcsd, int from, int mode = 0, bool sc = FALSE) + : TConto(tgcsd, from, mode), _scaricato(sc) {} + virtual ~TContoExt() {} +}; + +TConto* TTab_conti::add(const TBill& c, int anno, bool scar) { TString80 key; key.format("%4d%3d%3d%6ld", anno, c.gruppo(), c.conto(), c.sottoconto()); - TConto* tc = new TConto(c.gruppo(), c.conto(), c.sottoconto(), c.tipo()); + if (scar) key << "X"; + TContoExt* tc = new TContoExt(c.gruppo(), c.conto(), c.sottoconto(), + c.tipo(), NULL, scar); TAssoc_array::add(key, tc); return tc; } -TConto* TTab_conti::find(const TBill& c, int anno) +TConto* TTab_conti::find(const TBill& c, int anno, bool scar) { TString80 key; key.format("%4d%3d%3d%6ld", anno, c.gruppo(), c.conto(), c.sottoconto()); - TConto* tc = (TConto*)objptr(key); + if (scar) key << "X"; + TContoExt* tc = (TContoExt*)objptr(key); return tc; } -void TTab_conti::remove(const TBill& c, int anno) +void TTab_conti::remove(const TBill& c, int anno, bool scar) { TString80 key; key.format("%4d%3d%3d%6ld", anno, c.gruppo(), c.conto(), c.sottoconto()); + if (scar) key << "X"; TAssoc_array::remove(key); } void TTab_conti::aggiorna_conto(const TBill& tcon, - int anno_es, const TImporto& importo, bool movap, - bool provv, bool somma, bool movimentato) + int anno_es, const TImporto& importo, tiposal movap, + bool provv, bool somma, bool movimentato, bool scaricato) { - TConto* tc = find(tcon, anno_es); + TContoExt* tc = (TContoExt*)find(tcon, anno_es, scaricato); if (tc == NULL) - tc = add(tcon, anno_es); + tc = (TContoExt*)add(tcon, anno_es, scaricato); const real i(somma ? importo.valore() : -importo.valore()); - if (movap) + if (movap == apertura) { if (importo.sezione() == 'D') tc->saldo() += i; else tc->saldo() -= i; + } + else if (movap == chiusura) + { + if (importo.sezione() == 'D') + tc->saldofin() += i; + else + tc->saldofin() -= i; } else + { if (provv) { if (importo.sezione() == 'D') @@ -68,37 +92,33 @@ void TTab_conti::aggiorna_conto(const TBill& tcon, if (importo.sezione() == 'D') tc->dare() += i; else - tc->avere() += i; + tc->avere() += i; } + } // rimuovo dalla tabella il conto se dare e avere vanno a zero if (!movimentato) if (tc->dare().is_zero() && tc->avere().is_zero() && - tc->darepro().is_zero() && tc->averepro().is_zero() && - tc->saldo().is_zero()) - remove(*tc, anno_es); + tc->saldofin().is_zero() && tc->darepro().is_zero() && + tc->averepro().is_zero() && tc->saldo().is_zero()) + remove(*tc, anno_es, scaricato); } -TSaldo_agg::TSaldo_agg() -{ - _anno_es = 0; - _data_ulmov = ""; - _num_ulmov = 0l; - _movap = FALSE; - _provv = FALSE; - _movimentato = FALSE; - // reset(); // INUTILE pulizia dell'array dei conti -} +TSaldo_agg::TSaldo_agg() : _anno_es(0), _data_ulmov(""), _num_ulmov(0l), + _movap(normale), _provv(FALSE), _movimentato(FALSE) +{} -void TSaldo_agg::aggiorna(const TBill& tc, const TImporto& imp, bool somma) +void TSaldo_agg::aggiorna(const TBill& tc, const TImporto& imp, bool somma, bool scaricato) { - _tab_conti.aggiorna_conto(tc, _anno_es, imp, _movap, _provv, somma, _movimentato); + _tab_conti.aggiorna_conto(tc, _anno_es, imp, _movap, _provv, somma, _movimentato, scaricato); } -void TSaldo_agg::aggiorna(int gruppo, int conto, long sottoconto, const real& importo, char sezione, bool somma) +void TSaldo_agg::aggiorna(int gruppo, int conto, long sottoconto, const real& importo, char sezione, + bool somma, bool scaricato) { const TImporto imp(sezione, importo); - _tab_conti.aggiorna_conto(TBill(gruppo, conto, sottoconto), _anno_es, imp, _movap, _provv, somma, _movimentato); + _tab_conti.aggiorna_conto(TBill(gruppo, conto, sottoconto), _anno_es, imp, _movap, + _provv, somma, _movimentato, scaricato); } void TSaldo_agg::reset() @@ -148,8 +168,9 @@ void TSaldo_agg::clear_saldi(int year) // Scorro la tabella dei conti interna _tab_conti. // Per ogni conto cerco il record su saldi, se non c'e' lo creo. // Se c'e' gia' lo aggiorno nel seguente modo: -// +// GLOP /////////////////////////////////////////////////////////////////////////////// + void TSaldo_agg::registra() { real si, r; @@ -163,14 +184,16 @@ void TSaldo_agg::registra() for (int i = 0; i < conti; i++) { THash_object* hobj = _tab_conti.get_hashobj(); - TConto& tcon = (TConto &)hobj->obj(); - CHECK(tcon.ok(), "Tentavi di saldare un conto incompleto, eh?"); - + TContoExt& tcon = (TContoExt&)hobj->obj(); + CHECK(tcon.ok(), "Tentavi di saldare un conto incompleto, eh? Mapporcodio! Stronzone!"); + saldi.zero(); saldi.put(SLD_ANNOES, atoi(hobj->key().left(4)) ); saldi.put(SLD_GRUPPO, tcon.gruppo()); saldi.put(SLD_CONTO, tcon.conto()); - saldi.put(SLD_SOTTOCONTO, tcon.sottoconto()); + saldi.put(SLD_SOTTOCONTO, tcon.sottoconto()); + if (tcon.scaricato()) + saldi.put(SLD_FLSCA, "X"); bool update = TRUE; @@ -181,6 +204,9 @@ void TSaldo_agg::registra() saldi.put(SLD_GRUPPO, tcon.gruppo()); saldi.put(SLD_CONTO, tcon.conto()); saldi.put(SLD_SOTTOCONTO, tcon.sottoconto()); + if (tcon.scaricato()) + saldi.put(SLD_FLSCA, "X"); + si = tcon.saldo(); if (si < ZERO) { flag_salini = 'A'; si = -si; } @@ -189,10 +215,15 @@ void TSaldo_agg::registra() saldi.put(SLD_FLAGSALINI, flag_salini); saldi.put(SLD_SALDO, si); - saldi.put(SLD_PDAREPRO, tcon.darepro()); - saldi.put(SLD_PAVEREPRO, tcon.averepro()); saldi.put(SLD_PDARE, tcon.dare()); + real sf = tcon.saldofin(); + char flag_salfin = sf < ZERO ? 'A' : 'D'; + if (flag_salfin == 'A') sf = -sf; + + saldi.put(SLD_FLAGSALFIN, flag_salfin); + saldi.put(SLD_SALDOFIN, sf); + saldi.put(SLD_PAVERE, tcon.avere()); if (_num_ulmov != 0L) saldi.put(SLD_NUMULTMOV, _num_ulmov); if (_data_ulmov.ok()) saldi.put(SLD_DATAULMOV, _data_ulmov); @@ -226,12 +257,6 @@ void TSaldo_agg::registra() saldi.put(SLD_FLAGSALINI, flag_salini); saldi.put(SLD_SALDO, si); } - r = saldi.get_real(SLD_PDAREPRO); - r += tcon.darepro(); - saldi.put(SLD_PDAREPRO, r); - r = saldi.get_real(SLD_PAVEREPRO); - r += tcon.averepro(); - saldi.put(SLD_PAVEREPRO, r); r = saldi.get_real(SLD_PDARE); r += tcon.dare(); saldi.put(SLD_PDARE, r); @@ -241,10 +266,8 @@ void TSaldo_agg::registra() const int err = saldi.rewrite(); if (err != NOERR) - { yesnofatal_box("Errore %d nell'aggiornamento del saldo %d %d %ld", err, tcon.gruppo(), tcon.conto(), tcon.sottoconto()); - } } TImporto sf(flag_salini, si); diff --git a/cg/cglib04.cpp b/cg/cglib04.cpp index a774ef235..16f3a2246 100755 --- a/cg/cglib04.cpp +++ b/cg/cglib04.cpp @@ -4,6 +4,7 @@ #include #include #include +#include "cglib.h" #include "cglib04.h" const int size = 256; //Lunghezza del record del TRASFER @@ -3461,17 +3462,9 @@ const char* riconverti (TString& data_PC,bool anno_di_quattro) 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; + TEsercizi_contabili esc; + int e = esc.date2esc(d); + if (prevesc) *prevesc = esc.pred(e); + return e; } diff --git a/cg/cgtrc.ini b/cg/cgtrc.ini index fe4ad0fff..9806b4106 100755 --- a/cg/cgtrc.ini +++ b/cg/cgtrc.ini @@ -1,230 +1,230 @@ -# Istruzioni per l' uso della mappa cgtrc.ini -# -# A | B | C | D | E | F | G | H | -# -# A = Sigla di identificazione dei vari archivi all' interno del trasfer -# W1 = Tabella causali -# A1 = Clienti / Fornitori -# P1-P2-P3 = Piano dei conti -# Z1 = Movimenti di prima nota -# U1 = Movimenti Iva -# -# B = Numero progressivo del campo all'interno dell'archivio -# -# C = Posizione iniziale del campo sul record del trasfer -# -# D = Posizione finale del campo sul record del trasfer -# -# E = Numero di identificazione degli archivi su PC -# -# F = Nome del campo degli archivi su PC -# -# G = Questo e' un campo jolly che permette di eseguire determinate operazioni all'interno del programma -# e puo' assumere i seguenti valori: -# 1 -> indica quali sono i campi che devono essere trasferiti se i flag sulla -# tabella della ricezione indica di non trasferire tutto il record. -# 2 -> se il campo in questione e' una data. -# 3 -> se il campo in questione e' un reale con dei decimali. -# -# H = E' un ulteriore campo jolly da accostare ai campi reali con decimali. -# Serve per indicare il numero di decimali. ES: se il campo in questione -# e' un reale con 2 decimali il flag G deve essere 3 mentre il flag H -# deve essere 2. -# -W1|1|256|256|26|||| -W1|2|3|5|26|CODCAUS||| -W1|3|16|35|26|DESCR|1|| -W1|4|36|37|26|TIPODOC||| -W1|5|38|38|26|REG||| -W1|6|39|39|26|ALLEG||| -W1|7|40|40|26|M770||| -W1|8|41|41|26|COLLCESP||| -W1|9|207|207|26|NUMDOC||| -W1|10|208|208|26|DATADOC||| -W1|11|210|212|26|CODCAUSIM||| -W1|12|247|247|26|INTRACOM||| -W1|13|248|248|26|VALINTRA||| -W1|14|249|249|26|RITFATT||| -W1|15|250|250|26|AUTOFATT||| -W1|16|213|213|26|MOVAP||| -W1|17|3|5|27|CODCAUS||| -W1|18|42|43|27|GRUPPO||| -W1|19|44|45|27|CONTO||| -W1|20|46|51|27|SOTTOCONTO||| -W1|21|192|192|27|SEZIONE||| -W1|22|3|5|27|CODCAUS||| -W1|23|52|53|27|GRUPPO||| -W1|24|54|55|27|CONTO||| -W1|25|56|61|27|SOTTOCONTO||| -W1|26|193|193|27|SEZIONE||| -W1|27|3|5|27|CODCAUS||| -W1|28|62|63|27|GRUPPO||| -W1|29|64|65|27|CONTO||| -W1|30|66|71|27|SOTTOCONTO||| -W1|31|194|194|27|SEZIONE||| -W1|32|3|5|27|CODCAUS||| -W1|33|72|73|27|GRUPPO||| -W1|34|74|75|27|CONTO||| -W1|35|76|81|27|SOTTOCONTO||| -W1|36|195|195|27|SEZIONE||| -W1|37|3|5|27|CODCAUS||| -W1|38|82|83|27|GRUPPO||| -W1|39|84|85|27|CONTO||| -W1|40|86|91|27|SOTTOCONTO||| -W1|41|196|196|27|SEZIONE||| -W1|42|3|5|27|CODCAUS||| -W1|43|92|93|27|GRUPPO||| -W1|44|94|95|27|CONTO||| -W1|45|96|101|27|SOTTOCONTO||| -W1|46|197|197|27|SEZIONE||| -W1|47|3|5|27|CODCAUS||| -W1|48|102|103|27|GRUPPO||| -W1|49|104|105|27|CONTO||| -W1|50|106|111|27|SOTTOCONTO||| -W1|51|198|198|27|SEZIONE||| -W1|52|3|5|27|CODCAUS||| -W1|53|112|113|27|GRUPPO||| -W1|54|114|115|27|CONTO||| -W1|55|116|121|27|SOTTOCONTO||| -W1|56|199|199|27|SEZIONE||| -W1|57|3|5|27|CODCAUS||| -W1|58|122|123|27|GRUPPO||| -W1|59|124|125|27|CONTO||| -W1|60|126|131|27|SOTTOCONTO||| -W1|61|200|200|27|SEZIONE||| -W1|62|3|5|27|CODCAUS||| -W1|63|132|133|27|GRUPPO||| -W1|64|134|135|27|CONTO||| -W1|65|136|141|27|SOTTOCONTO||| -W1|66|201|201|27|SEZIONE||| -W1|67|3|5|27|CODCAUS||| -W1|68|142|143|27|GRUPPO||| -W1|69|144|145|27|CONTO||| -W1|70|146|151|27|SOTTOCONTO||| -W1|71|202|202|27|SEZIONE||| -W1|72|3|5|27|CODCAUS||| -W1|73|152|153|27|GRUPPO||| -W1|74|154|155|27|CONTO||| -W1|75|156|161|27|SOTTOCONTO||| -W1|76|203|203|27|SEZIONE||| -W1|77|3|5|27|CODCAUS||| -W1|78|162|163|27|GRUPPO||| -W1|79|164|165|27|CONTO||| -W1|80|166|171|27|SOTTOCONTO||| -W1|81|204|204|27|SEZIONE||| -W1|82|3|5|27|CODCAUS||| -W1|83|172|173|27|GRUPPO||| -W1|84|174|175|27|CONTO||| -W1|85|176|181|27|SOTTOCONTO||| -W1|86|205|205|27|SEZIONE||| -W1|87|3|5|27|CODCAUS||| -W1|88|182|183|27|GRUPPO||| -W1|89|184|185|27|CONTO||| -W1|90|186|191|27|SOTTOCONTO||| -W1|91|206|206|27|SEZIONE||| -A1|1|256|256|20|||| -A1|2|3|3|20|TIPOCF||| -A1|3|4|9|20|CODCF||| -A1|4|16|16|20|TIPOPERS||| -A1|5|17|66|20|RAGSOC|1|| -A1|6|67|77|20|PAIV|1|| -A1|7|78|93|20|COFI|1|| -A1|8|94|128|20|INDCF|1|| -A1|9|129|133|20|CAPCF||| -A1|10|134|153|20|LOCALITACF|1|| -A1|11|156|167|20|TEL|1|| -A1|12|168|168|20|ALLEG||| -A1|13|169|170|20|GRUPPORIC||| -A1|14|171|172|20|CONTORIC||| -A1|15|173|178|20|SOTTOCRIC||| -A1|16|180|185|20|CODALLEG||| -A1|17|186|187|20|CODPAG||| -P1|1|256|256|19|||| -P1|2|3|4|19|GRUPPO||| -P1|3|16|45|19|DESCR|1|| -P2|1|256|256|19|||| -P2|2|3|4|19|GRUPPO||| -P2|3|5|6|19|CONTO||| -P2|4|16|45|19|DESCR|1|| -P2|5|46|46|19|INDBIL||| -P2|6|47|47|19|TMCF||| -P2|7|48|48|19|STSOTTBIL||| -#P2|8|49|49|19|SEZIVD||| -#P2|9|50|50|19|LETTIVD||| -#P2|10|61|63|19|NUMRIVD||| -#P2|11|59|60|19|NUMIVD||| -#P2|12|64|64|19|SEZIVDOPP||| -#P2|13|65|65|19|LETTIVDOPP||| -#P2|14|76|78|19|NUMRIVDOPP||| -#P2|15|74|75|19|NUMIVDOPP||| -P3|1|256|256|19|||| -P3|2|3|4|19|GRUPPO||| -P3|3|5|6|19|CONTO||| -P3|4|7|12|19|SOTTOCONTO||| -P3|5|16|45|19|DESCR|1|| -P3|6|46|46|19|TIPOSPRIC||| -P3|7|47|47|19|RICSER||| -#P3|8|48|48|19|SEZIVD||| -#P3|9|49|49|19|LETTIVD||| -#P3|10|60|62|19|NUMRIVD||| -#P3|11|58|59|19|NUMIVD||| -#P3|12|63|63|19|SEZIVDOPP||| -#P3|13|64|64|19|LETTIVDOPP||| -#P3|14|75|77|19|NUMRIVDOPP||| -#P3|15|73|74|19|NUMIVDOPP||| -Z1|0|16|21|23|DATAREG||| -Z1|1|250|250|23|||| -Z1|2|251|256|23|||| -Z1|3|3|8|23|NUMREG||| -Z1|4|23|28|23|DATADOC|2|| -Z1|5|29|35|23|NUMDOC||| -Z1|6|36|36|23|REG||| -Z1|7|37|41|23|PROTIVA||| -Z1|8|42|44|23|CODCAUS||| -Z1|9|96|97|23|CODPAG||| -Z1|10|109|113|23|UPROTIVA||| -Z1|11|221|222|23|TIPODOC||| -Z1|12|238|248|23|TOTDOC||| -Z1|13|3|8|24|NUMREG||| -Z1|14|9|10|24|NUMRIG||| -Z1|15|45|74|24|DESCR||| -Z1|16|75|76|24|GRUPPO||| -Z1|17|77|78|24|CONTO||| -Z1|18|79|84|24|SOTTOCONTO||| -Z1|19|85|85|24|SEZIONE||| -Z1|20|86|87|24|GRUPPOC||| -Z1|21|88|89|24|CONTOC||| -Z1|22|90|95|24|SOTTOCONTC||| -Z1|23|98|108|24|IMPORTO||| -Z1|49|223|223|24|||| -Z1|50|220|220|23|||| -Z1|51|249|249|23|||| -Z1|52|22|22|23|||| -U1|1|250|250|23|||| -U1|2|251|256|23|||| -U1|3|3|8|23|NUMREG||| -U1|4|56|61|23|DATA74TER|2|| -U1|5|147|149|23|CODVALI||| -U1|6|16|21|23|CODCF||| -U1|7|238|248|23|TOTDOC||| -U1|8|150|160|23|CAMBIOI|3|5| -U1|9|136|146|23|CORRLIRE||| -U1|10|161|174|23|CORRVALUTA|3|3| -U1|11|3|8|25|NUMREG||| -U1|12|9|10|25|NUMRIG||| -U1|13|33|34|25|CODIVA||| -U1|14|22|32|25|IMPONIBILE||| -U1|15|35|43|25|IMPOSTA||| -U1|16|45|45|25|TIPODET||| -U1|17|44|44|25|TIPOCR||| -U1|18|134|134|25|TIPOATT||| -U1|19|46|47|25|GRUPPO||| -U1|20|48|49|25|CONTO||| -U1|21|50|55|25|SOTTOCONTO||| -U1|22|135|135|25|INTRA||| -U1|50|62|86||||| -U1|51|249|249|23|||| -U1|52|109|126||||| -U1|53|127|131||||| -U1|54|132|133||||| -U1|56|87|108||||| +# Istruzioni per l' uso della mappa cgtrc.ini +# +# A | B | C | D | E | F | G | H | +# +# A = Sigla di identificazione dei vari archivi all' interno del trasfer +# W1 = Tabella causali +# A1 = Clienti / Fornitori +# P1-P2-P3 = Piano dei conti +# Z1 = Movimenti di prima nota +# U1 = Movimenti Iva +# +# B = Numero progressivo del campo all'interno dell'archivio +# +# C = Posizione iniziale del campo sul record del trasfer +# +# D = Posizione finale del campo sul record del trasfer +# +# E = Numero di identificazione degli archivi su PC +# +# F = Nome del campo degli archivi su PC +# +# G = Questo e' un campo jolly che permette di eseguire determinate operazioni all'interno del programma +# e puo' assumere i seguenti valori: +# 1 -> indica quali sono i campi che devono essere trasferiti se i flag sulla +# tabella della ricezione indica di non trasferire tutto il record. +# 2 -> se il campo in questione e' una data. +# 3 -> se il campo in questione e' un reale con dei decimali. +# +# H = E' un ulteriore campo jolly da accostare ai campi reali con decimali. +# Serve per indicare il numero di decimali. ES: se il campo in questione +# e' un reale con 2 decimali il flag G deve essere 3 mentre il flag H +# deve essere 2. +# +W1|1|256|256|26|||| +W1|2|3|5|26|CODCAUS||| +W1|3|16|35|26|DESCR|1|| +W1|4|36|37|26|TIPODOC||| +W1|5|38|38|26|REG||| +W1|6|39|39|26|ALLEG||| +W1|7|40|40|26|M770||| +W1|8|41|41|26|COLLCESP||| +W1|9|207|207|26|NUMDOC||| +W1|10|208|208|26|DATADOC||| +W1|11|210|212|26|CODCAUSIM||| +W1|12|247|247|26|INTRACOM||| +W1|13|248|248|26|VALINTRA||| +W1|14|249|249|26|RITFATT||| +W1|15|250|250|26|AUTOFATT||| +W1|16|213|213|26|MOVAP||| +W1|17|3|5|27|CODCAUS||| +W1|18|42|43|27|GRUPPO||| +W1|19|44|45|27|CONTO||| +W1|20|46|51|27|SOTTOCONTO||| +W1|21|192|192|27|SEZIONE||| +W1|22|3|5|27|CODCAUS||| +W1|23|52|53|27|GRUPPO||| +W1|24|54|55|27|CONTO||| +W1|25|56|61|27|SOTTOCONTO||| +W1|26|193|193|27|SEZIONE||| +W1|27|3|5|27|CODCAUS||| +W1|28|62|63|27|GRUPPO||| +W1|29|64|65|27|CONTO||| +W1|30|66|71|27|SOTTOCONTO||| +W1|31|194|194|27|SEZIONE||| +W1|32|3|5|27|CODCAUS||| +W1|33|72|73|27|GRUPPO||| +W1|34|74|75|27|CONTO||| +W1|35|76|81|27|SOTTOCONTO||| +W1|36|195|195|27|SEZIONE||| +W1|37|3|5|27|CODCAUS||| +W1|38|82|83|27|GRUPPO||| +W1|39|84|85|27|CONTO||| +W1|40|86|91|27|SOTTOCONTO||| +W1|41|196|196|27|SEZIONE||| +W1|42|3|5|27|CODCAUS||| +W1|43|92|93|27|GRUPPO||| +W1|44|94|95|27|CONTO||| +W1|45|96|101|27|SOTTOCONTO||| +W1|46|197|197|27|SEZIONE||| +W1|47|3|5|27|CODCAUS||| +W1|48|102|103|27|GRUPPO||| +W1|49|104|105|27|CONTO||| +W1|50|106|111|27|SOTTOCONTO||| +W1|51|198|198|27|SEZIONE||| +W1|52|3|5|27|CODCAUS||| +W1|53|112|113|27|GRUPPO||| +W1|54|114|115|27|CONTO||| +W1|55|116|121|27|SOTTOCONTO||| +W1|56|199|199|27|SEZIONE||| +W1|57|3|5|27|CODCAUS||| +W1|58|122|123|27|GRUPPO||| +W1|59|124|125|27|CONTO||| +W1|60|126|131|27|SOTTOCONTO||| +W1|61|200|200|27|SEZIONE||| +W1|62|3|5|27|CODCAUS||| +W1|63|132|133|27|GRUPPO||| +W1|64|134|135|27|CONTO||| +W1|65|136|141|27|SOTTOCONTO||| +W1|66|201|201|27|SEZIONE||| +W1|67|3|5|27|CODCAUS||| +W1|68|142|143|27|GRUPPO||| +W1|69|144|145|27|CONTO||| +W1|70|146|151|27|SOTTOCONTO||| +W1|71|202|202|27|SEZIONE||| +W1|72|3|5|27|CODCAUS||| +W1|73|152|153|27|GRUPPO||| +W1|74|154|155|27|CONTO||| +W1|75|156|161|27|SOTTOCONTO||| +W1|76|203|203|27|SEZIONE||| +W1|77|3|5|27|CODCAUS||| +W1|78|162|163|27|GRUPPO||| +W1|79|164|165|27|CONTO||| +W1|80|166|171|27|SOTTOCONTO||| +W1|81|204|204|27|SEZIONE||| +W1|82|3|5|27|CODCAUS||| +W1|83|172|173|27|GRUPPO||| +W1|84|174|175|27|CONTO||| +W1|85|176|181|27|SOTTOCONTO||| +W1|86|205|205|27|SEZIONE||| +W1|87|3|5|27|CODCAUS||| +W1|88|182|183|27|GRUPPO||| +W1|89|184|185|27|CONTO||| +W1|90|186|191|27|SOTTOCONTO||| +W1|91|206|206|27|SEZIONE||| +A1|1|256|256|20|||| +A1|2|3|3|20|TIPOCF||| +A1|3|4|9|20|CODCF||| +A1|4|16|16|20|TIPOPERS||| +A1|5|17|66|20|RAGSOC|1|| +A1|6|67|77|20|PAIV|1|| +A1|7|78|93|20|COFI|1|| +A1|8|94|128|20|INDCF|1|| +A1|9|129|133|20|CAPCF||| +A1|10|134|153|20|LOCALITACF|1|| +A1|11|156|167|20|TEL|1|| +A1|12|168|168|20|ALLEG||| +A1|13|169|170|20|GRUPPORIC||| +A1|14|171|172|20|CONTORIC||| +A1|15|173|178|20|SOTTOCRIC||| +A1|16|180|185|20|CODALLEG||| +A1|17|186|187|20|CODPAG||| +P1|1|256|256|19|||| +P1|2|3|4|19|GRUPPO||| +P1|3|16|45|19|DESCR|1|| +P2|1|256|256|19|||| +P2|2|3|4|19|GRUPPO||| +P2|3|5|6|19|CONTO||| +P2|4|16|45|19|DESCR|1|| +P2|5|46|46|19|INDBIL||| +P2|6|47|47|19|TMCF||| +P2|7|48|48|19|STSOTTBIL||| +#P2|8|49|49|19|SEZIVD||| +#P2|9|50|50|19|LETTIVD||| +#P2|10|61|63|19|NUMRIVD||| +#P2|11|59|60|19|NUMIVD||| +#P2|12|64|64|19|SEZIVDOPP||| +#P2|13|65|65|19|LETTIVDOPP||| +#P2|14|76|78|19|NUMRIVDOPP||| +#P2|15|74|75|19|NUMIVDOPP||| +P3|1|256|256|19|||| +P3|2|3|4|19|GRUPPO||| +P3|3|5|6|19|CONTO||| +P3|4|7|12|19|SOTTOCONTO||| +P3|5|16|45|19|DESCR|1|| +P3|6|46|46|19|TIPOSPRIC||| +P3|7|47|47|19|RICSER||| +#P3|8|48|48|19|SEZIVD||| +#P3|9|49|49|19|LETTIVD||| +#P3|10|60|62|19|NUMRIVD||| +#P3|11|58|59|19|NUMIVD||| +#P3|12|63|63|19|SEZIVDOPP||| +#P3|13|64|64|19|LETTIVDOPP||| +#P3|14|75|77|19|NUMRIVDOPP||| +#P3|15|73|74|19|NUMIVDOPP||| +Z1|0|16|21|23|DATAREG||| +Z1|1|250|250|23|||| +Z1|2|251|256|23|||| +Z1|3|3|8|23|NUMREG||| +Z1|4|23|28|23|DATADOC|2|| +Z1|5|29|35|23|NUMDOC||| +Z1|6|36|36|23|REG||| +Z1|7|37|41|23|PROTIVA||| +Z1|8|42|44|23|CODCAUS||| +Z1|9|96|97|23|CODPAG||| +Z1|10|109|113|23|UPROTIVA||| +Z1|11|221|222|23|TIPODOC||| +Z1|12|238|248|23|TOTDOC||| +Z1|13|3|8|24|NUMREG||| +Z1|14|9|10|24|NUMRIG||| +Z1|15|45|74|24|DESCR||| +Z1|16|75|76|24|GRUPPO||| +Z1|17|77|78|24|CONTO||| +Z1|18|79|84|24|SOTTOCONTO||| +Z1|19|85|85|24|SEZIONE||| +Z1|20|86|87|24|GRUPPOC||| +Z1|21|88|89|24|CONTOC||| +Z1|22|90|95|24|SOTTOCONTC||| +Z1|23|98|108|24|IMPORTO||| +Z1|49|223|223|24|||| +Z1|50|220|220|23|||| +Z1|51|249|249|23|||| +Z1|52|22|22|23|||| +U1|1|250|250|23|||| +U1|2|251|256|23|||| +U1|3|3|8|23|NUMREG||| +U1|4|56|61|23|DATA74TER|2|| +U1|5|147|149|23|CODVALI||| +U1|6|16|21|23|CODCF||| +U1|7|238|248|23|TOTDOC||| +U1|8|150|160|23|CAMBIOI|3|5| +U1|9|136|146|23|CORRLIRE||| +U1|10|161|174|23|CORRVALUTA|3|3| +U1|11|3|8|25|NUMREG||| +U1|12|9|10|25|NUMRIG||| +U1|13|33|34|25|CODIVA||| +U1|14|22|32|25|IMPONIBILE||| +U1|15|35|43|25|IMPOSTA||| +U1|16|45|45|25|TIPODET||| +U1|17|44|44|25|TIPOCR||| +U1|18|134|134|25|TIPOATT||| +U1|19|46|47|25|GRUPPO||| +U1|20|48|49|25|CONTO||| +U1|21|50|55|25|SOTTOCONTO||| +U1|22|135|135|25|INTRA||| +U1|50|62|86||||| +U1|51|249|249|23|||| +U1|52|109|126||||| +U1|53|127|131||||| +U1|54|132|133||||| +U1|56|87|108||||| diff --git a/cg/conto.h b/cg/conto.h index 8233edc8b..54e23d064 100755 --- a/cg/conto.h +++ b/cg/conto.h @@ -85,14 +85,14 @@ enum TIndbil { ib_null, ib_attivita, ib_passivita, ib_costi, ib_ricavi, ib_conti class TConto : public TBill { - real _dare, _avere, _darepro, _averepro, _saldo; + real _dare, _avere, _darepro, _averepro, _saldofin, _saldo; TImporto _saldo_finale; public: TConto(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = NULL) : TBill(g, c, s, t, d) {} TConto (TToken_string& tgcsd, int from, int mode = 0) - : TBill(tgcsd, from, mode) {}; + : TBill(tgcsd, from, mode) {} real& dare() { return _dare; } const real& dare() const { return _dare; } @@ -105,10 +105,13 @@ public: real& averepro() { return _averepro; } const real& averepro() const { return _averepro; } - + real& saldo() { return _saldo; } const real& saldo() const { return _saldo; } + real& saldofin() { return _saldofin; } + const real& saldofin() const { return _saldofin; } + TImporto& saldo_finale() { return _saldo_finale; } const TImporto& saldo_finale() const { return _saldo_finale; } };