diff --git a/cg/cg1100.cpp b/cg/cg1100.cpp index cdc4e3a26..619979158 100755 --- a/cg/cg1100.cpp +++ b/cg/cg1100.cpp @@ -72,7 +72,8 @@ class CG1100_application : public TPrintapp int _gruppo,_conto,_num_da_stamp,_num_stamp,_g_prec,_c_prec; long _sottoc,_s_prec; TString _classe_da_stampare,_classe_stampata,_codcbl_da_stamp,_codcbl_stamp; - bool _conto_classificato,_sottoc_classificato,_stampa_riga_vuota; + bool _conto_classificato,_stampa_riga_vuota; + byte _sottoc_classificato; bool _prima_volta, _stampa_g, _stampa_c; TDate _data_stampa; @@ -1041,7 +1042,7 @@ bool CG1100_application::elabora_riga() int CG1100_application::leggo_sottoc(int gruppo,int conto,long sottoc) { - TLocalisamfile pconti (LF_PCON,FALSE); + TLocalisamfile pconti (LF_PCON); char sez; int gr,co; int esito = 0; @@ -1110,7 +1111,7 @@ bool CG1100_application::preprocess_page(int file,int counter) if (sez == '0') { - _sottoc_classificato = leggo_sottoc(gruppo,conto,sottoc); + _sottoc_classificato = byte(leggo_sottoc(gruppo,conto,sottoc)); if (_sottoc_classificato == 0) _conto_classificato = TRUE; else diff --git a/cg/cg1307.cpp b/cg/cg1307.cpp index 2038384ae..55401b486 100755 --- a/cg/cg1307.cpp +++ b/cg/cg1307.cpp @@ -1,10 +1,12 @@ #include +#include #include #include #include #include #include -#include + +#include "cgsaldac.h" #include #include @@ -12,6 +14,7 @@ #include #include #include +#include #ifndef FOR_EACH_FILE_RECORD @@ -30,8 +33,11 @@ class TElimina_zoppi : public TSkeleton_application TArray _decoders; protected: - static bool test_file(int rmov, TString_array& arr); - static int kill_row(long numreg, const char* codrig); + static bool test_row_file(int rmov, TString_array& arr); + static bool test_head_file(TString_array& arr); + + static int kill_game(long numreg, int numrig); + static int kill_row(long numreg, char tipor, int numrig); static bool firm_handler(TMask_field& f, KEY k); static bool select_handler(TMask_field& f, KEY k); @@ -121,30 +127,35 @@ const char* TElimina_zoppi::decode(int num, const char* key, const char* field) return dec->decode(key); } -bool TElimina_zoppi::test_file(int lf_rmov, TString_array& arr) +bool TElimina_zoppi::test_row_file(int lf_rmov, TString_array& arr) { bool ok = TRUE; TLocalisamfile& mov = app().file(LF_MOV); - TLocalisamfile& rmov = app().file(lf_rmov); + TLocalisamfile& row = app().file(lf_rmov); TString msg; msg << "Controllo righe "; - if (lf_rmov == LF_RMOV) - msg << "contabili"; - else - msg << "iva"; - msg << ": 0"; + switch (lf_rmov) + { + case LF_RMOV : msg << "contabili"; break; + case LF_RMOVIVA: msg << "iva"; break; + case LF_PARTITE: msg << "saldaconto";break; + default: CHECKD(0, "Invalid row file %d", lf_rmov); break; + } + msg << ": 0"; msg.center_just(50); - TProgind pi(rmov.items(), msg, TRUE, TRUE, 50); + TProgind pi(row.items(), msg, TRUE, TRUE, 50); TToken_string riga, descr; - long reg, last_reg, found = 0; - bool reg_killed = TRUE; + long reg, last_reg = 0, found = 0; + bool reg_killed = FALSE; + + char tipo; int gruppo, conto; long sottoconto; - FOR_EACH_FILE_RECORD(rmov) + FOR_EACH_FILE_RECORD(row) { if (pi.iscancelled()) { @@ -153,11 +164,20 @@ bool TElimina_zoppi::test_file(int lf_rmov, TString_array& arr) } pi.addstatus(1); - reg = rmov.get_long(MOV_NUMREG); + if (lf_rmov == LF_PARTITE) + reg = row.get_long(PART_NREG); + else + reg = row.get_long(MOV_NUMREG); + if (reg != last_reg) - { - mov.put(MOV_NUMREG, reg); - reg_killed = mov.read() != NOERR; + { + if (reg > 0) + { + mov.put(MOV_NUMREG, reg); + reg_killed = mov.read() != NOERR; + } + else + reg_killed = lf_rmov != LF_PARTITE; last_reg = reg; } if (reg_killed) @@ -167,31 +187,54 @@ bool TElimina_zoppi::test_file(int lf_rmov, TString_array& arr) msg.cut(colon+2); msg << found; pi.set_text(msg); - - const int numrig = rmov.get_int(RMV_NUMRIG); - riga.format(" |%6ld|%c%3d", reg, (lf_rmov == LF_RMOV) ? 'C' : 'I', numrig); - riga.add(rmov.get(RMV_ANNOES)); - if (lf_rmov == LF_RMOV) - { - riga.add(rmov.get_real(RMV_IMPORTO).string(".")); - riga << ' ' << rmov.get(RMV_SEZIONE); + + switch (lf_rmov) + { + case LF_RMOV : + riga.format(" |%6ld|C%4d", reg, row.get_int(RMV_NUMRIG)); + riga.add(row.get(RMV_ANNOES)); + riga.add(row.get_real(RMV_IMPORTO).string(".")); + riga << ' ' << row.get(RMV_SEZIONE); + break; + case LF_RMOVIVA: + riga.format(" |%6ld|I%4d", reg, row.get_int(RMI_NUMRIG)); + riga.add(row.get(RMI_ANNOES)); + riga.add(row.get_real(RMI_IMPONIBILE).string(".")); + riga << " "; + break; + case LF_PARTITE: + riga.format(" |%6ld|S%4d", reg, row.get_int(PART_NRIGA)); + riga.add(row.get(PART_ANNO)); + riga.add(row.get_real(PART_IMPORTO).string(".")); + riga << ' ' << row.get(PART_SEZ); + break; + default: CHECKD(0, "Invalid row file %d", lf_rmov); break; + }; + + descr.cut(0); + if (lf_rmov == LF_PARTITE) + { + tipo = row.get_char(PART_TIPOCF); + gruppo = row.get_int(PART_GRUPPOCL); + conto = row.get_int(PART_CONTOCL); + sottoconto = row.get_long(PART_SOTTOCONTO); + descr = row.get(PART_DESCR); } else { - riga.add(rmov.get_real(RMI_IMPONIBILE).string(".")); - riga << " "; - } - riga.add(gruppo = rmov.get_int(RMV_GRUPPO)); - riga.add(conto = rmov.get_int(RMV_CONTO)); - riga.add(sottoconto = rmov.get_long(RMV_SOTTOCONTO)); + tipo = row.get_char(RMV_TIPOC); + gruppo = row.get_int(RMV_GRUPPO); + conto = row.get_int(RMV_CONTO); + sottoconto = row.get_long(RMV_SOTTOCONTO); + if (lf_rmov == LF_RMOV) + descr = row.get(PART_DESCR); + } + riga.add(gruppo); + riga.add(conto); + riga.add(sottoconto); - if (lf_rmov == LF_RMOV) - descr = rmov.get(RMV_DESCR); - else - descr.cut(0); if (descr.empty()) { - char tipo = rmov.get_char(RMV_TIPOC); if (tipo == 'C' || tipo == 'F') { descr << tipo << '|' << sottoconto; @@ -211,12 +254,137 @@ bool TElimina_zoppi::test_file(int lf_rmov, TString_array& arr) return ok; } -int TElimina_zoppi::kill_row(long numreg, const char* codrig) +bool TElimina_zoppi::test_head_file(TString_array& arr) +{ + bool ok = TRUE; + TLocalisamfile& mov = app().file(LF_MOV); + TLocalisamfile& rmov = app().file(LF_RMOV); + TLocalisamfile& rmoviva = app().file(LF_RMOVIVA); + + TString msg; + msg << "Controllo testate di prima nota: 0"; + msg.center_just(50); + + TProgind pi(mov.items(), msg, TRUE, TRUE, 50); + TToken_string riga, descr; + + FOR_EACH_FILE_RECORD(mov) + { + if (pi.iscancelled()) + { + ok = FALSE; + break; + } + pi.addstatus(1); + + long reg = mov.get_long(MOV_NUMREG); + int rmov_err = NOERR; + int rmoviva_err = NOERR; + if (reg > 0) + { + rmov.put(RMV_NUMREG, reg); + rmov.put(RMV_NUMRIG, 1); + rmov_err = rmov.read(); + rmoviva.put(RMI_NUMREG, reg); + rmoviva.put(RMI_NUMRIG, 1); + rmoviva_err = rmoviva.read(); + } + if (reg == 0 || rmov_err != NOERR && rmoviva_err != NOERR) + { + riga.format(" |%6ld|T", reg); + riga.add(mov.get(MOV_ANNOES)); + riga.add(mov.get_real(MOV_TOTDOC).string(".")); + riga << " | | "; + riga.add(mov.get(MOV_CODCF)); + descr = mov.get(MOV_DESCR); + if (descr.empty()) + { + char tipo = rmov.get_char(MOV_TIPO); + if (tipo == 'C' || tipo == 'F') + { + descr << tipo << '|' << mov.get(MOV_CODCF); + descr = app().decode(LF_CLIFO, descr, CLI_RAGSOC); + } + } + riga.add(descr); + arr.add(riga); + } + } + + return ok; +} + +int TElimina_zoppi::kill_game(long numreg, int numrig) +{ + TPartite_array games; + games.add_numreg(numreg); + for (TPartita* game = games.first(); game; game = games.next()) + { + bool update = FALSE; + const int fattura = game->prima_fattura(numreg); + if (fattura > 0) + { + game->scollega_pagamenti(fattura, 1); + game->rimuovi_riga(fattura); + update = TRUE; + } + + const int rigapag = game->primo_pagamento(numreg); + if (rigapag > 0) + { + for (int p = game->last(); p > 0; p = game->pred(p)) + { + TRiga_partite& part = game->riga(p); + if (part.is_fattura()) + { + for (int r = part.rate(); r > 0; r--) + { + TRiga_scadenze& scad = part.rata(r); + for (int s = scad.last(); s > 0; s = scad.pred(s)) + { + const TRiga_partite& sum = game->riga(s); + if (sum.get_long(PART_NREG) == numreg) + { + game->elimina_pagamento(p, r, s); + update = TRUE; + } + } + } + } + } + TRecord_array& unas = game->unassigned(); + for (int u = unas.last_row(); u > 0; u = unas.pred_row(u)) + { + const TRiga_partite& sum = game->riga(u); + if (sum.get_long(PART_NREG) == numreg) + { + game->elimina_pagamento(TPartita::UNASSIGNED, 0, u); + update = TRUE; + } + } + } + if (update) + game->rewrite(); + } + return NOERR; +} + +int TElimina_zoppi::kill_row(long numreg, char tipor, int numrig) { - const int lf_rmov = *codrig == 'I' ? LF_RMOVIVA : LF_RMOV; - TLocalisamfile& rmov= app().file(lf_rmov); + int lf = 0; + switch (tipor) + { + case 'C': lf = LF_RMOV; break; + case 'I': lf = LF_RMOVIVA; break; + case 'T': lf = LF_MOV; break; + case 'S': return kill_game(numreg, numrig); + default : break; + } + + TLocalisamfile& rmov= app().file(lf); rmov.put(RMV_NUMREG, numreg); - rmov.put(RMV_NUMRIG, codrig+1); + if (lf != LF_MOV) + rmov.put(RMV_NUMRIG, numrig); int err = rmov.read(); if (err == NOERR) err = rmov.remove(); @@ -228,13 +396,17 @@ bool TElimina_zoppi::select_handler(TMask_field& f, KEY k) bool ok = TRUE; if (k == K_SPACE) { - TArray_sheet sheet(-1, -1, 76, 20, APPNAME, "@1|Codice@6|Riga|Anno|Importo@20R|Grp@R|Cnt@R|Sottoc@R|Descrizione@50"); + TArray_sheet sheet(-1, -1, 76, 20, APPNAME, "@1|Codice@6|Riga@5|Anno@R|Importo@20R|Grp@R|Cnt@R|Sottoc@R|Descrizione@50"); TString_array& arr = sheet.rows_array(); - ok = test_file(LF_RMOV, arr); + ok = test_row_file(LF_RMOV, arr); if (ok) - ok = test_file(LF_RMOVIVA, arr); - arr.sort(); - + ok = test_row_file(LF_RMOVIVA, arr); + if (ok) + ok = test_head_file(arr); + if (ok) + ok = test_row_file(LF_PARTITE, arr); + if (ok) + arr.sort(); if (ok && sheet.run() == K_ENTER) { const long total = sheet.checked(); @@ -249,11 +421,15 @@ bool TElimina_zoppi::select_handler(TMask_field& f, KEY k) if (pi.iscancelled()) break; pi.addstatus(1); - - long reg = riga->get_long(1); - kill_row(reg, riga->get(2)); + + TString16 str = riga->get(2); + char tipor = str[0]; + int numrig = atoi(str.mid(1)); + kill_row(riga->get_long(1), tipor, numrig); } } + message_box("Si consiglia di eseguire il ricalcolo\n" + "dei saldi dal menu di prima nota."); } } } @@ -264,6 +440,7 @@ void TElimina_zoppi::main_loop() { open_files(LF_CLIFO, LF_NDITTE, LF_PCON, 0); open_files(LF_MOV, LF_RMOV, LF_RMOVIVA, 0); + open_files(LF_PARTITE, LF_SCADENZE, LF_PAGSCA, 0); TMask m(APPNAME, 1, 30, 5); m.add_number(DLG_USER, 0, "Codice ditta ", 1, 1, 5, "BUF"); diff --git a/cg/cg1500.cpp b/cg/cg1500.cpp index 343ce4353..5ea544950 100755 --- a/cg/cg1500.cpp +++ b/cg/cg1500.cpp @@ -2174,7 +2174,7 @@ void TStampa_bilanci::riempi_record(char t,int g,int c,long s, void TStampa_bilanci::leggi_clifo(const TArray& gccf) { TSaldo sld; - TLocalisamfile saldi(LF_SALDI, FALSE); + TLocalisamfile saldi(LF_SALDI); int g=0, c=0; long codcf=0l; TString80 ragsoc; @@ -3504,7 +3504,7 @@ print_action TStampa_bilanci::postprocess_page(int file, int counter) TDate TStampa_bilanci::UltimaData(int g, int c, long s, int anno) { TDate uldata; - TLocalisamfile saldi(LF_SALDI, FALSE); //il parametro a false permette di usare un record corrente del file saldi differente a quello del file tmp + TLocalisamfile saldi(LF_SALDI); //il parametro a false permette di usare un record corrente del file saldi differente a quello del file tmp saldi.zero(); if (_annoes != 0) @@ -3528,7 +3528,7 @@ const char* TStampa_bilanci::DescrizioneConto(int g, int c, long s, char tipocf) { TString80 ragsoc; const char* desc = NULL; - TLocalisamfile pconti(LF_PCON,FALSE); + TLocalisamfile pconti(LF_PCON); TLocalisamfile clifo (LF_CLIFO); pconti.zero(); diff --git a/cg/cg2100.cpp b/cg/cg2100.cpp index 323c07ddd..c730efd30 100755 --- a/cg/cg2100.cpp +++ b/cg/cg2100.cpp @@ -442,12 +442,6 @@ TMask* TPrimanota_application::get_mask(int mode) return load_mask(_iva == nessuna_iva ? 1 : 2); } -bool TPrimanota_application::firm_change_enabled() const -{ - const bool ok = _msk[2] == NULL && TRelation_application::firm_change_enabled(); - return ok; -} - void TPrimanota_application::on_firm_change() { TRelation_application::on_firm_change(); // May be useful, who knows? diff --git a/cg/cg2102.h b/cg/cg2102.h index 46cda7010..4509faaf8 100755 --- a/cg/cg2102.h +++ b/cg/cg2102.h @@ -168,7 +168,6 @@ protected: // TRelation_application virtual int rewrite(const TMask& m); virtual bool remove(); virtual void write_enable(bool) {} - virtual bool firm_change_enabled() const; virtual bool protected_record(TRectype& rec); protected: diff --git a/cg/cg2104.cpp b/cg/cg2104.cpp index d8d9bc9a0..81f049b09 100755 --- a/cg/cg2104.cpp +++ b/cg/cg2104.cpp @@ -1115,7 +1115,7 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa } } } // if (deleting >= 0) - + char old_ap, new_ap; TImporto old_abbuono, new_abbuono, old_diffcam, new_diffcam; const bool empty = p.modifica_pagamento(new_pag, valuta,