#include "sc0300a.h" #include "../cg/cgsalda3.h" #include #include #include #include #include class TPareggio_tree : public TObject_tree { protected: virtual TFieldtypes get_var(const TString& name, TVariant& var) const; virtual bool marked() const { return rand() % 2 != 0; } public: bool init(const TBill& bill, const TString& valuta, bool nc, int stato); // Stato- 1=aperte; 2=chiuse; 0 o 3 = tutte }; TFieldtypes TPareggio_tree::get_var(const TString& name, TVariant& var) const { TFieldtypes ft = _nullfld; const TObject* obj = curr_node(); if (obj != NULL) { if (obj->is_kind_of(CLASS_RECTYPE)) { const TRectype& rec = *(const TRectype*)obj; ft = rec.type(name); if (ft != _nullfld) { if (ft == _realfld) { var = rec.get_real(name).stringa(0, 2); ft = _alfafld; } else var = rec.get(name); } else { if (name == PART_DATADOC) { if (rec.num() == LF_SCADENZE) { var = rec.get_date(SCAD_DATASCAD); ft = _datefld; } } else if (name == "RESIDUO") { TImporto saldo; switch (rec.num()) { case LF_SCADENZE: if (!rec.get_bool(SCAD_PAGATA)) { const TPartita game(rec); const TRiga_scadenze& s = game.rata(rec.get_int(SCAD_NRIGA), rec.get_int(SCAD_NRATA)); saldo = s.residuo(true); } break; case LF_PARTITE: if (!rec.get_bool(PART_CHIUSA)) { const TPartita game(rec); saldo = game.calcola_saldo(true); } break; default: break; } var = saldo.valore().stringa(0, 2); ft = _alfafld; } } } else { if (name == PART_NUMPART) { const real& year = *(real*)obj; var = year.integer(); ft = _intfld; } } } return ft; } bool TPareggio_tree::init(const TBill& bill, const TString& valuta, bool nc, int stato) { goto_root(); kill_node(); TString filter; if (bill.tipo() > ' ') filter << PART_TIPOCF << '=' << bill.tipo(); else { filter << PART_GRUPPO << '=' << bill.gruppo() << ' '; filter << PART_CONTO << '=' << bill.conto(); } filter << ' ' << PART_SOTTOCONTO << '=' << bill.sottoconto(); TString query; query << "USE PART SELECT (NRIGA<9999)&&(TIPOMOV<=" << (nc ? tm_nota_credito : tm_fattura) << ')' << "\nFROM " << filter << "\nTO " << filter; TISAM_recordset games(query); const TRectype& rec = games.cursor()->curr(); int last_year = 0; TString80 id_year, id_rec; for (bool ok = games.move_first(); ok; ok = games.move_next()) { const TString& codval = rec.get(PART_CODVAL); if (!same_values(codval, valuta)) continue; const tipo_movimento tm = (tipo_movimento)rec.get_int(PART_TIPOMOV); bool add_riga = true; if (nc) { add_riga = !rec.get_bool(PART_CHIUSA); // Se filtro le note di credito cerco di riconoscere le fatture negative if (add_riga && 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(); if (sezione_positiva == importo.sezione()) // Controlla se fattura positiva o negativa add_riga = false; // Ignora fattura positiva } } 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) continue; const int year = rec.get_int(PART_ANNO); if (year != last_year) { goto_root(); while(goto_rbrother()); add_rbrother(real(year)); last_year = year; curr_id(id_year); id_rec.cut(0); } if (nc) { if (id_rec.full()) { goto_node(id_rec); add_rbrother(rec); } else add_son(rec); curr_id(id_rec); } else { TPartita game(rec); const TRiga_partite& riga = game.riga(rec.get_int(PART_NRIGA)); for (int rata = 1; rata <= riga.rate(); rata++) { const TRiga_scadenze& s = riga.rata(rata); bool add_rata = true; if (stato == 1 || stato == 2) { const bool chiusa = s.get_bool(SCAD_PAGATA); if (chiusa) add_rata = stato == 2; else add_rata = stato == 1; } if (add_rata) { if (id_rec.full()) add_rbrother(s); else add_son(s); curr_id(id_rec); } } } } if (goto_node(id_year)) expand(); return goto_root(); } /////////////////////////////////////////////////////////// // TPareggio_mask /////////////////////////////////////////////////////////// class TPareggio_mask : public TAutomask { TPareggio_tree _nc, _ft; private: protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); public: TPareggio_mask(); }; bool TPareggio_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { //case F_SOTTOCONTO: case F_CLIENTE: case F_FORNITORE: case F_CODVAL: case F_TUTTE: if (e == fe_modify) { TWait_cursor hourglass; 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); const int tipo = get_int(F_TUTTE); const TString& codval = get(F_CODVAL); _nc.init(bill, codval, true, 1); // Solo aperte _ft.init(bill, codval, false, tipo); tfield(F_NC_TREE).set_tree(&_nc); tfield(F_FT_TREE).set_tree(&_ft); } break; default: break; } return true; } TPareggio_mask::TPareggio_mask() : TAutomask("sc0300a") { RCT rct_nc; field(F_NC_TREE).get_rect(rct_nc); RCT rct_ft; field(F_FT_TREE).get_rect(rct_ft); rct_nc.right = rct_ft.left-8; rct_ft.right = rct_ft.left + rct_nc.right - rct_nc.left; field(F_NC_TREE).set_rect(rct_nc); field(F_FT_TREE).set_rect(rct_ft); } /////////////////////////////////////////////////////////// // TPareggio_partite /////////////////////////////////////////////////////////// class TPareggio_partite : public TSkeleton_application { protected: virtual void main_loop(); public: }; void TPareggio_partite::main_loop() { TPareggio_mask pm; pm.run(); } /////////////////////////////////////////////////////////// // Main /////////////////////////////////////////////////////////// int sc0300(int argc, char* argv[]) { TPareggio_partite pp; pp.run(argc, argv, TR("Pareggio Partite")); return 0; }