diff --git a/sc/sc0101.cpp b/sc/sc0101.cpp index 90febfa0a..e0147b45d 100755 --- a/sc/sc0101.cpp +++ b/sc/sc0101.cpp @@ -37,9 +37,10 @@ protected: void pag2sheet(); void read_scadenze(); - void write_scadenze() const; public: + void write_scadenze() const; + TFattura_mask(TRiga_partite& fattura, const TString& codpag); virtual ~TFattura_mask(); }; @@ -372,12 +373,12 @@ void TFattura_mask::write_scadenze() const const TString agente = get(FS_AGENTE); - partita.elimina_rate(); + const int old_rate = partita.rate(); for (int i = 0; i < pag.n_rate(); i++) { TToken_string& row = ps.row(i); - - TRiga_scadenze& scadenza = partita.new_row(); + + TRiga_scadenze& scadenza = i >= old_rate ? partita.new_row() : partita.rata(i+1); scadenza.put(SCAD_CODPAG, pag.code()); scadenza.put(SCAD_TIPOPAG, pag.tipo_rata(i)); scadenza.put(SCAD_ULTCLASS, pag.ulc_rata(i)); @@ -392,13 +393,24 @@ void TFattura_mask::write_scadenze() const scadenza.zero(SCAD_IMPORTOVAL); } scadenza.put(SCAD_DATASCAD, pag.data_rata(i)); - scadenza.put(SCAD_CODABIPR, row.get(6)); - scadenza.put(SCAD_CODCABPR, row.get(7)); - scadenza.put(SCAD_CODABI, row.get(8)); - scadenza.put(SCAD_CODCAB, row.get(9)); - scadenza.put(SCAD_PAGATA, pag.ratapagata(i)); + scadenza.put(SCAD_CODABIPR, row.get(7)); + scadenza.put(SCAD_CODCABPR, row.get(8)); + scadenza.put(SCAD_CODABI, row.get(9)); + scadenza.put(SCAD_CODCAB, row.get(10)); scadenza.put(SCAD_CODAG, agente); + scadenza.put(SCAD_PAGATA, pag.ratapagata(i)); } + + if (i < old_rate) + { + TPartita& game = _fattura.partita(); + const int riga = _fattura.get_int(PART_NRIGA); + for (int r = old_rate; r > i; r--) + { + game.scollega_pagamenti(riga, r); + _fattura.elimina_rata(r); + } + } } @@ -419,14 +431,22 @@ bool TGame_mask::edit_fattura(TPartita& p, int nriga) TFattura_mask fm(f, _codpag); const bool ok = fm.run() == K_ENTER; - if (nuova && !ok) - p.rimuovi_riga(nriga); + if (ok) + { + fm.write_scadenze(); + } + else + { + if (nuova) + p.rimuovi_riga(nriga); + } return ok; } -void TGame_mask::prima_nota(const long nreg) -{ +bool TGame_mask::prima_nota(const long nreg) +{ + bool ok = FALSE; bool can_run = TRUE; if (_changed) { @@ -446,12 +466,14 @@ void TGame_mask::prima_nota(const long nreg) TString16 numreg; numreg << "1|" << nreg; TMessage msg(pn, MSG_LN, numreg); msg.send(); // Messaggio di collegamento al movimento nreg - prima_nota.run(); // Lancia la prima nota + ok = prima_nota.run() == 0; // Lancia la prima nota const int anno = get_int(P_ANNO); const TString16 numero = get(P_NUMERO); fill_partite(anno, numero); // Rilegge partite } + + return ok; } /////////////////////////////////////////////////////////// diff --git a/sc/sc1200.cpp b/sc/sc1200.cpp index 6b90995d7..702f362b5 100755 --- a/sc/sc1200.cpp +++ b/sc/sc1200.cpp @@ -25,23 +25,26 @@ class TCreatepart_app : public TApplication TLocalisamfile* _scadenze; TLocalisamfile* _pagsca; + TEsercizi_contabili _esc; bool _num_cli, _num_for; + TString _desccl, _descfo; + TDate _today; protected: // Applicat + virtual void on_firm_change(); virtual void on_config_change(); -protected: - virtual bool create(); virtual bool destroy(); virtual bool menu(MENU_TAG m); - bool zap_partite(); +protected: + bool zap_partite(); + int crea_partite(int anno_es, int anno_rif, bool check); public: - char is_clifo(int g, int c, int& indbil); - TCreatepart_app() {} + TCreatepart_app() : _today(TODAY) {} virtual ~TCreatepart_app() {} }; @@ -69,6 +72,11 @@ bool TCreatepart_app::destroy() return TApplication::destroy(); } +void TCreatepart_app::on_firm_change() +{ + _esc.update(); +} + void TCreatepart_app::on_config_change() { TConfig cd(CONFIG_DITTA, "cg"); @@ -82,7 +90,6 @@ bool TCreatepart_app::zap_partite() bool first = TRUE; for (_partite->first(); !_partite->eof(); _partite->next()) { - if (first) { bool ok = yesno_box("Il saldaconto non e' vuoto." @@ -121,123 +128,163 @@ char TCreatepart_app::is_clifo(int g, int c, int& indbil) return cf; } +int TCreatepart_app::crea_partite(int anno_es, int anno_rif, bool check) +{ + TRelation saldi(LF_SALDI); + saldi.curr().put(SLD_ANNOES, anno_es); + + TCursor cur(&saldi, "", 1, &saldi.curr(), &saldi.curr()); + const long items = cur.items(); + + if (items == 0) + return -1; + + begin_wait(); + + int n_part = 0; + TProgind prind(items, "Creazione saldaconto", FALSE, TRUE, 45); + + for (cur = 0; cur.pos() < items; ++cur) + { + const int gruppo = cur.curr().get_int(SLD_GRUPPO); + const int conto = cur.curr().get_int(SLD_CONTO); + const long sottoc = cur.curr().get_long(SLD_SOTTOCONTO); + int indbil; + const char cf = is_clifo(gruppo, conto, indbil); + if (cf > ' ') + { + TSaldo sld; + + // ciuccia il saldo e vedi se e' movimentato nell'esercizio corrente + if (!sld.ultima_immissione_verifica(anno_es, gruppo, conto, sottoc, indbil, 1)) + { + // non movimentato: se e' conto patrimoniale.... + if (!(indbil == 1 || indbil == 2 || indbil == 5)) + { + prind.addstatus(1); + continue; + } + // .. vedi saldo esercizio precedente, altrimenti inkul + sld.saldofin_esprec(anno_es, gruppo, conto, sottoc); + } + + // genera importo con sezione appropriata + TImporto saldo(cur.curr().get_char(SLD_FLAGSALINI), sld.saldoini()); + TImporto pdare('D', sld.prgdare()); + TImporto pavere('A', sld.prgavere()); + + saldo += pdare; + saldo += pavere; + saldo.normalize(); + + if (!saldo.is_zero()) + { + const TBill clifo(gruppo, conto, sottoc, cf); + TString16 numero("*"); + if ((cf == 'C' && _num_cli) || (cf == 'F' && _num_for)) + numero.right_just(7); + + TPartita game(clifo, anno_rif, numero); + if (check) + { + for (int p = game.last(); p > 0; p = game.pred(p)) + { + const TRiga_partite& riga = game.riga(p); + const int g = riga.get_int(PART_GRUPPOCL); + const int c = riga.get_int(PART_CONTOCL); + if (gruppo == g && conto == c) + break; + } + if (p > 0) + continue; + } + + TRiga_partite& riga = game.new_row(); + riga.put(PART_DATAREG, _today); + riga.put(PART_DATADOC, _today); + riga.put(PART_SEZ, saldo.sezione()); + riga.put(PART_IMPORTO, saldo.valore()); + riga.put(PART_DESCR, cf == 'C' ? _desccl : _descfo); + + // cazzata dare/avere/fare/baciare/cagare + const int tipo = (cf == 'C' ? (saldo.sezione() == 'D' ? 1 : 2) : + (saldo.sezione() == 'D' ? 2 : 1)); + + riga.put(PART_TIPOMOV, tipo); + + if (tipo == 1) + { + TRiga_scadenze& scad = riga.new_row(); + scad.put(SCAD_IMPORTO, saldo.valore()); + scad.put(SCAD_DATASCAD, _today); + scad.put(SCAD_TIPOPAG, 1); + } + else + { + const int r = riga.get_int(PART_NRIGA); + TRectype& unas = game.unassigned().row(r, TRUE); + unas.put(PAGSCA_IMPORTO, saldo.valore()); + unas.put(PAGSCA_DATAPAG, _today); + unas.put(PAGSCA_ACCSAL, 'A'); + } + + if (game.write()) + n_part++; + else + { + error_box("Impossibile scrivere la partita %d *", anno_rif); + break; + } + } + } + prind.addstatus(1); + } + + end_wait(); + return n_part; +} bool TCreatepart_app::menu(MENU_TAG) { - const TDate today(TODAY); TMask m("sc1200a"); + + _desccl << "Apertura clienti al " << _today; + _descfo << "Apertura fornitori al " << _today; - TString desccl(80); desccl << "Apertura clienti al " << today.string(); - TString descfo(80); descfo << "Apertura fornitori al " << today.string(); - - m.set(F_DESCCL, desccl); - m.set(F_DESCFO, descfo); + m.set(F_DESCCL, _desccl); + m.set(F_DESCFO, _descfo); + m.set(F_ANNO, _esc.last()); while (m.run() == K_ENTER) { - const int anno = m.get_int(F_ANNO); - desccl = m.get(F_DESCCL); - descfo = m.get(F_DESCFO); + const int anno_es = m.get_int(F_ANNO); + _desccl = m.get(F_DESCCL); + _descfo = m.get(F_DESCFO); - int n_part = 0; - m.set(F_NUMPART, n_part); - // sputtana tutto il saldaculo if (!zap_partite()) continue; - - TRelation saldi(LF_SALDI); - saldi.curr().put(SLD_ANNOES, anno); - - TCursor cur(&saldi, "", 1, &saldi.curr(), &saldi.curr()); - const long items = cur.items(); - - long npart = 0L; - if (items > 0) - { - begin_wait(); - TProgind prind(items, "Creazione saldaconto", FALSE, TRUE,45); - - for (cur = 0; cur.pos() < items; ++cur) - { - const int gruppo = cur.curr().get_int(SLD_GRUPPO); - const int conto = cur.curr().get_int(SLD_CONTO); - const long sottoc = cur.curr().get_long(SLD_SOTTOCONTO); - int indbil; - const char cf = is_clifo(gruppo, conto, indbil); - if (cf > ' ') - { - TSaldo sld; - - // ciuccia il saldo e vedi se e' movimentato nell'esercizio corrente - if (!sld.ultima_immissione_verifica(anno, gruppo, conto, sottoc, indbil, 1)) - { - // non movimentato: se e' conto patrimoniale.... - if (!(indbil == 1 || indbil == 2 || indbil == 5)) - { - prind.addstatus(1); - continue; - } - // .. vedi saldo esercizio precedente, altrimenti inkul - sld.saldofin_esprec(anno, gruppo, conto, sottoc); - } - - // genera importo con sezione appropriata - TImporto saldo(cur.curr().get_char(SLD_FLAGSALINI), sld.saldoini()); - TImporto pdare('D', sld.prgdare()); - TImporto pavere('A', sld.prgavere()); - - saldo += pdare; - saldo += pavere; - saldo.normalize(); - - // (whew) - - if (!saldo.is_zero()) - { - const TBill clifo(gruppo, conto, sottoc, cf); - TString16 numero("*"); - if ((cf == 'C' && _num_cli) || (cf == 'F' && _num_for)) - numero.right_just(7); - TPartita game(clifo, anno, numero); - - TRiga_partite& riga = game.new_row(); - riga.put(PART_DATAREG, today); - riga.put(PART_DATADOC, today); - riga.put(PART_SEZ, saldo.sezione()); - riga.put(PART_IMPORTO, saldo.valore()); - riga.put(PART_DESCR, cf == 'C' ? desccl : descfo); - - // cazzata dare/avere/fare/baciare/cagare - const int tipo = (cf == 'C' ? (saldo.sezione() == 'D' ? 1 : 2) : - (saldo.sezione() == 'D' ? 2 : 1)); - - riga.put(PART_TIPOMOV, tipo); - - if (tipo == 1) - { - TRiga_scadenze& scad = riga.new_row(); - scad.put(SCAD_IMPORTO, saldo.valore()); - scad.put(SCAD_DATASCAD, today); - scad.put(SCAD_TIPOPAG, 1); - } - else - { - TRectype& unas = game.unassigned().row(riga.get_int(PART_NRIGA), TRUE); - unas.put(PAGSCA_IMPORTO, saldo.valore()); - unas.put(PAGSCA_DATAPAG, today); - unas.put(PAGSCA_ACCSAL, 'A'); - } - game.write(); - m.set(F_NUMPART, ++n_part); - } - } - prind.addstatus(1); - } - end_wait(); + + const TEsercizio& selected_es = _esc.esercizio(anno_es); + const int anno_rif = selected_es.inizio().year(); + int n_part = crea_partite(anno_es, anno_rif, FALSE); + if (n_part >= 0) + { + const int pred_es = _esc.pred(anno_es); + if (pred_es > 0) + { + const int p = crea_partite(pred_es, anno_rif, TRUE); + if (p > 0) n_part += p; + } } else - message_box("Nessun saldo presente per l'esercizio %d", anno); + message_box("Nessun saldo presente per l'esercizio %d", anno_es); + + if (n_part > 0) + m.set(F_NUMPART, n_part); + else + m.reset(F_NUMPART); + } // while run return FALSE;