diff --git a/sc/sc0300.cpp b/sc/sc0300.cpp index c3c27c109..8b6b8e73c 100644 --- a/sc/sc0300.cpp +++ b/sc/sc0300.cpp @@ -7,20 +7,27 @@ #include #include #include +#include #include #include +/////////////////////////////////////////////////////////// +// TPareggio_tree +/////////////////////////////////////////////////////////// + class TPareggio_tree : public TObject_tree { TPartite_array _games; protected: virtual TFieldtypes get_var(const TString& name, TVariant& var) const; + virtual TImage* image(bool selected) const; public: bool init(const TBill& bill, const TString& valuta, bool nc, int stato); // Stato: 1=aperte; 2=chiuse; 0 o 3 = tutte TPartita& partita(const TRectype& rec) const; + bool is_lonely_pag(const TRectype& rec) const; const TRectype* node2rec(const TString& id); }; @@ -29,6 +36,24 @@ TPartita& TPareggio_tree::partita(const TRectype& rec) const return ((TPartite_array&)_games).partita(rec); } +// Controlla se rec è una riga di tipo nota credito non associata a nessuna scadenza in una partita a sè stante +bool TPareggio_tree::is_lonely_pag(const TRectype& rec) const +{ + const tipo_movimento tm = (tipo_movimento)rec.get_int(PART_TIPOMOV); + if (tm == tm_fattura) + return false; + + const TPartita& part = partita(rec); + for (int r = part.last(); r > 0; r = part.pred(r)) + { + const tipo_movimento tm = part.riga(r).tipo(); + if (tm <= tm_fattura || tm >= tm_insoluto) + return false; + } + + return true; +} + const TRectype* TPareggio_tree::node2rec(const TString& id) { const TRectype* rec = NULL; @@ -55,7 +80,28 @@ TFieldtypes TPareggio_tree::get_var(const TString& name, TVariant& var) const { if (ft == _realfld) { - var = rec.get_real(name).stringa(0, 2); + if (name == PART_IMPORTO) + { + char sez = 'D'; + if (rec.num() == LF_SCADENZE) + { + const int nriga = rec.get_int(SCAD_NRIGA); + const TPartita& game = partita(rec); + sez = game.riga(nriga).get_char(PART_SEZ); + } else + if (rec.exist(PART_SEZ)) + sez = rec.get_char(PART_SEZ); + TImporto imp(sez, rec.get_real(name)); + if (!imp.is_zero()) + { + imp.normalize(); + TString80 str; + str << imp.valore().stringa(0, 2) << ' ' << imp.sezione(); + var = str; + } + } + else + var = rec.get_real(name).stringa(0, 2); ft = _alfafld; } else @@ -77,6 +123,18 @@ TFieldtypes TPareggio_tree::get_var(const TString& name, TVariant& var) const { var = rec.get(fld); ft = _alfafld; + if (var.is_empty() && name.ends_with(PART_DESCR)) + { + switch (rec.get_int(PART_TIPOMOV)) + { + case tm_fattura : var = TR("Fattura"); break; + case tm_nota_credito : var = TR("Nota di credito"); break; + case tm_pagamento : var = TR("Pagamento"); break; + case tm_insoluto : var = TR("Insoluto"); break; + case tm_pagamento_insoluto: var = TR("Pagamento di insoluto"); break; + default: break; + }; + } } } else if (name == "RESIDUO") @@ -102,7 +160,12 @@ TFieldtypes TPareggio_tree::get_var(const TString& name, TVariant& var) const default: break; } - var = saldo.valore().stringa(0, 2); + if (!saldo.is_zero()) + { + TString80 str; + str << saldo.valore().stringa(0, 2) << ' ' << saldo.sezione(); + var = str; + } ft = _alfafld; } } @@ -120,6 +183,43 @@ TFieldtypes TPareggio_tree::get_var(const TString& name, TVariant& var) const return ft; } +TImage* TPareggio_tree::image(bool selected) const +{ + const TObject* obj = curr_node(); + short id = 0; + if (obj != NULL) + { + if (obj->is_kind_of(CLASS_RECTYPE)) + { + const TRectype& rec = *(const TRectype*)obj; + switch (rec.num()) + { + case LF_PARTITE: + switch (rec.get_int(PART_TIPOMOV)) + { + case tm_fattura: + id = rec.get_bool(PART_CHIUSA) ? BMP_DIRDNSEL : BMP_DIRDN; + break; + case tm_pagamento_insoluto: // Alias tm_pagamento + case tm_pagamento: + id = BMP_PAGAMENTO; + break; + default: + id = BMP_INSOLUTO; + break; + } + break; + case LF_SCADENZE: + id = rec.get_bool(SCAD_PAGATA) ? BMP_DIRDNSEL : BMP_DIRDN; + break; + default: + break; + } + } + } + return id > 0 ? get_res_image(id) : TTree::image(selected); +} + bool TPareggio_tree::init(const TBill& bill, const TString& valuta, bool nc, int stato) { _games.destroy(); @@ -137,7 +237,7 @@ bool TPareggio_tree::init(const TBill& bill, const TString& valuta, bool nc, int filter << ' ' << PART_SOTTOCONTO << '=' << bill.sottoconto(); TString query; - query << "USE PART SELECT (NRIGA<9999)&&(TIPOMOV<=" << (nc ? tm_nota_credito : tm_fattura) << ')' + query << "USE PART SELECT (NRIGA<9999)&&(" << (nc ? "BETWEEN(TIPOMOV,1,3)" : "TIPOMOV=1") << ')' << "\nFROM " << filter << "\nTO " << filter; TISAM_recordset games(query); const TRectype& rec = games.cursor()->curr(); @@ -155,46 +255,45 @@ bool TPareggio_tree::init(const TBill& bill, const TString& valuta, bool nc, int if (!same_values(codval, valuta)) continue; - const tipo_movimento tm = (tipo_movimento)rec.get_int(PART_TIPOMOV); bool add_riga = true; + if (stato == 1 || stato == 2) + { + bool chiusa = rec.get_bool(PART_CHIUSA); + if (!chiusa && partita(rec).chiusa(true)) + chiusa = true; // Flag CHIUSA non affidabilissimo + + if (chiusa) + add_riga = stato == 2; + else + add_riga = stato == 1; + if (!add_riga) + continue; + } + if (nc) { - add_riga = !rec.get_bool(PART_CHIUSA); - if (add_riga) - { - // Se filtro le note di credito cerco di riconoscere le fatture negative - if (tm == tm_fattura) - { - const char sezione_positiva = bill.tipo() == 'C' ? 'D' : 'A'; - TImporto importo(rec.get_char(PART_SEZ), rec.get_real(PART_IMPORTO)); - importo.normalize(); - add_riga = sezione_positiva != importo.sezione(); // Ignora fattura positiva - } - else - { - const int nriga = rec.get_int(PART_NRIGA); - const TPartita& game = partita(rec); - add_riga = ((TPartita&)game).unassigned().exist(nriga); - } - } - } - else - { - if (stato == 1 || stato == 2) - { - const bool chiusa = rec.get_bool(PART_CHIUSA); - if (chiusa) - add_riga = stato == 2; - else - add_riga = stato == 1; - } - if (add_riga) + const tipo_movimento tm = (tipo_movimento)rec.get_int(PART_TIPOMOV); + // Se filtro le note di credito cerco di riconoscere le fatture negative + if (tm == tm_fattura) { const char sezione_positiva = bill.tipo() == 'C' ? 'D' : 'A'; TImporto importo(rec.get_char(PART_SEZ), rec.get_real(PART_IMPORTO)); importo.normalize(); - add_riga = sezione_positiva == importo.sezione(); // Ignora fattura negativa + add_riga = sezione_positiva != importo.sezione(); // Ignora fattura positiva } + else + { + const int nriga = rec.get_int(PART_NRIGA); + const TPartita& game = partita(rec); + add_riga = ((TPartita&)game).unassigned().exist(nriga) && is_lonely_pag(rec); + } + } + else + { + const char sezione_positiva = bill.tipo() == 'C' ? 'D' : 'A'; + TImporto importo(rec.get_char(PART_SEZ), rec.get_real(PART_IMPORTO)); + importo.normalize(); + add_riga = sezione_positiva == importo.sezione(); // Ignora fattura negativa } if (!add_riga) @@ -391,16 +490,17 @@ bool TPareggio_mask::ft2nc(const TRectype& rec) bool TPareggio_mask::abbuona_rata(const real& imp, const TRectype& nota, TRiga_scadenze& scad) { const TValuta valuta(scad.riga()); - const char* imp_field = valuta.in_valuta() ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO; + const bool in_valuta = valuta.in_valuta() ; + const char* imp_field = in_valuta ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO; TPartita& nc = _nc.partita(nota); TPartita& ft = scad.partita(); TRiga_partite& new_nc = ft.new_row(); new_nc.put(PART_SEZ, scad.riga().get_char(PART_SEZ) == 'D' ? 'A' : 'D'); - new_nc.put(PART_TIPOMOV, tm_nota_credito); + new_nc.put(PART_TIPOMOV, nota.get(PART_TIPOMOV)); new_nc.put(PART_NREG, nota.get(PART_NREG)); - new_nc.put(PART_NUMRIG, 1); // 24-09-2012 ! + new_nc.put(PART_NUMRIG, max(nota.get_int(PART_NUMRIG),1)); // corretto 24-09-2012 ! new_nc.put(PART_CODCAUS, nota.get(PART_CODCAUS)); new_nc.put(PART_REG, nota.get(PART_REG)); new_nc.put(PART_NUMDOC, nota.get(PART_NUMDOC)); @@ -410,8 +510,9 @@ bool TPareggio_mask::abbuona_rata(const real& imp, const TRectype& nota, TRiga_s new_pag.put(imp_field, imp); ft.modifica_pagamento(new_pag, valuta, true); ft.write(true); - - TRectype unass = nc.unassigned().row(nota.get_int(PART_NRIGA)); + + TRecord_array& unarray = nc.unassigned(); + TRectype unass = unarray.row(nota.get_int(PART_NRIGA)); if (new_nc.get(PART_SEZ) == nota.get(PART_SEZ)) unass.add(imp_field, -imp); else @@ -426,14 +527,15 @@ bool TPareggio_mask::elabora(const TRectype& nota, TPointer_array& scadenze) { CHECK(nota.num() == LF_PARTITE, "Solo partite, grazie!"); const tipo_movimento tm = (tipo_movimento)nota.get_int(PART_TIPOMOV); - if (tm == tm_fattura && !ft2nc(nota)) + if (tm == tm_fattura && !ft2nc(nota)) // Trasforma eventuale fattura negativa return false; TScad_mask ass; const TString& codval = get(F_CODVAL); ass.set(F_CODVAL, codval); + const bool in_valuta = is_true_value(codval); - real residuo_nc = abs(nota.get_real(is_true_value(codval) ? PART_IMPORTOVAL : PART_IMPORTO)); + real residuo_nc = abs(nota.get_real(in_valuta ? PART_IMPORTOVAL : PART_IMPORTO)); ass.set(F_IMPORTO, residuo_nc); TSheet_field& sheet = ass.sfield(F_TUTTE); @@ -475,9 +577,13 @@ void TPareggio_mask::refill() const short id = efield(F_FORNITORE).active() ? F_FORNITORE : (efield(F_SOTTOCONTO).active() ? F_SOTTOCONTO : F_CLIENTE); TBill bill; bill.get(*this, F_GRUPPO, F_CONTO, id, F_TIPO); + + if (bill.sottoconto() <= 0) + return; + const int tipo = get_int(F_TUTTE); const TString& codval = get(F_CODVAL); - _nc.init(bill, codval, true, 1); // Solo aperte + _nc.init(bill, codval, true, tipo); _ft.init(bill, codval, false, tipo); tfield(F_NC_TREE).set_tree(&_nc); diff --git a/sc/sc0300a.uml b/sc/sc0300a.uml index b2750aa46..69219399c 100644 --- a/sc/sc0300a.uml +++ b/sc/sc0300a.uml @@ -212,9 +212,9 @@ BEGIN DISPLAY "Partita@11" NUMPART //DISPLAY "N.@3R" NRIGA DISPLAY "Data@7" DATADOC - DISPLAY "Importo@8R" IMPORTO - DISPLAY "Residuo@8R" RESIDUO - DISPLAY "Descrizione Nota di Credito@35" PART.DESCR + DISPLAY "Importo@10R" IMPORTO + DISPLAY "Residuo@10R" RESIDUO + DISPLAY "Descrizione@35" PART.DESCR DISPLAY "P.N.@5R" NREG END @@ -224,9 +224,9 @@ BEGIN DISPLAY "Partita@11" NUMPART //DISPLAY "N.@3R" NRIGA DISPLAY "Rata@4R" NRATA - DISPLAY "Scadenza@7" DATASCAD - DISPLAY "Residuo@8R" RESIDUO - DISPLAY "Importo@8R" IMPORTO + DISPLAY "Data@7" DATASCAD + DISPLAY "Residuo@10R" RESIDUO + DISPLAY "Importo@10R" IMPORTO DISPLAY "Descrizione Fattura@35" PART.DESCR DISPLAY "P.N.@5R" PART.NREG FLAGS "M"