#include #include #include #include #include "conto.h" // Certified 90% TBill::TBill(TToken_string& s, int from, int mode) : _tipo_cr(-1) { const char* first = s.get(from); if (mode & 0x1) { _tipo = first ? toupper(*first) : ' '; first = s.get(); } else _tipo = ' '; #ifdef DBG if (strchr(" CF", _tipo) == NULL) { error_box("Tipo conto errato: '%c'", _tipo); _tipo = ' '; } #endif _gruppo = first ? atoi(first) : 0; _conto = s.get_int(); _sottoconto = s.get_long(); if (mode & 0x2) _descrizione = s.get(); } // Certified 100% const TBill& TBill::set(int g, int c, long s, char t, const char* d) { _tipo = (t > ' ') ? toupper(t) : ' '; _gruppo = g; _conto = c; _sottoconto = s; _descrizione = d; return *this; } const TBill& TBill::add_to(TToken_string& ts, int from, int mode) { if (mode & 0x4) { const int cr = tipo_cr(); ts.add(cr > 0 ? format("%d", cr) : " ", from++); } if (mode & 0x1) ts.add(_tipo, from++); ts.add(_gruppo, from++); ts.add(_conto, from++); ts.add(_sottoconto, from++); if (mode & 0x2) ts.add(descrizione(), from++); return *this; } // Certified 100% bool TBill::ok() const { return _gruppo != 0 && _conto != 0 && _sottoconto != 0L; } // Certified 99% int TBill::compare(const TSortable& s) const { CHECK(class_name()==s.class_name(), "Can't compare TBill with TObject"); const TBill& c = (const TBill&)s; int res = _gruppo - c._gruppo; if (res) return res; res = _conto - c._conto; if (res) return res; const long lres = _sottoconto - c._sottoconto; if (lres < 0L) res = -1; else if (lres > 0L) res = +1; return res; } // Certified 90% (uses __tmp_string && isam) const char* TBill::describe() { int err = NOERR; const char* desc = NULL; if (_tipo != 'C' && _tipo != 'F') { TLocalisamfile pcon(LF_PCON, FALSE); pcon.setkey(1); pcon.zero(); pcon.put("GRUPPO", _gruppo); pcon.put("CONTO", _conto); pcon.put("SOTTOCONTO", _sottoconto); err = pcon.read(); if (err == NOERR) { if (_sottoconto != 0) { const char c = pcon.get_char("TMCF"); _tipo = (c < ' ') ? ' ' : c; // Force correct type } if (_tipo == ' ') { _tipo_cr = pcon.get_int("TIPOSPRIC"); desc = pcon.get("DESCR"); } } } if (_tipo == 'C' || _tipo == 'F') { TLocalisamfile clifo(LF_CLIFO, FALSE); clifo.setkey(1); clifo.zero(); clifo.put("TIPOCF", _tipo); clifo.put("CODCF", _sottoconto); err = clifo.read(); if (err == NOERR) { desc = clifo.get("RAGSOC"); if (_conto == 0) { _gruppo = clifo.get_int("GRUPPO"); _conto = clifo.get_int("CONTO"); } } } return desc; } bool TBill::read(TRectype &r) { TLocalisamfile pcon(LF_PCON, FALSE); pcon.setkey(1); pcon.zero(); pcon.put("GRUPPO", _gruppo); pcon.put("CONTO", _conto); pcon.put("SOTTOCONTO", _sottoconto); const int err = pcon.read(); if (err == NOERR) { r = pcon.curr(); _tipo_cr = r.get_int("TIPOSPRIC"); _descrizione = r.get("DESCR"); } else r.zero(); return err == NOERR; } int TBill::tipo_att() { int tipo_att = 1; if (_tipo == ' ') { TRectype conto(LF_PCON); read(conto); const TIndbil ib = (TIndbil)conto.get_int("INDBIL"); if (ib == ib_passivita || ib == ib_ricavi) { const int ricser = conto.get_int("RICSER"); tipo_att = (ricser == 0) ? 2 : 1; } } return tipo_att; } // Certified 99% (describe uses __tmp_string) const TString& TBill::descrizione() { if (_descrizione.empty()) { const char* d = describe(); if (d) _descrizione = *d ? d : " "; else _descrizione = "Sconosciuto"; } return _descrizione; } int TBill::tipo_cr() { if (_tipo_cr < 0) { _descrizione = ""; descrizione(); } return _tipo_cr; } // Certified 99% (uses __tmp_string) const char* TBill::string(int mode) { TFixed_string s(&__tmp_string[256], 80); s.cut(0); if (mode & 0x4) { const int cr = tipo_cr(); s << (cr > 0 ? format("%d", cr) : " ") << '|'; } if (mode & 0x1) s << _tipo << '|'; s << _gruppo << '|' << _conto << '|' << _sottoconto; if (mode & 0x2) s << '|' << descrizione(); return s; }