#include #include #include #include #include #include "conto.h" // Certified 100% TConto::TConto(int g, int c, long s, char t, const char* d) : _tipo(toupper(t)), _gruppo(g), _conto(c), _sottoconto(s), _descrizione(d) {} // Certified 90% TConto::TConto(TToken_string& s, int from, int mode) { 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% TConto& TConto::set(int g, int c, long s, char t, const char* d) { _tipo = toupper(t); _gruppo = g; _conto = c; _sottoconto = s; _descrizione = d; return *this; } // Certified 100% bool TConto::ok() const { return _gruppo != 0 && _conto != 0 && _sottoconto != 0L; } // Certified 99% int TConto::compare(const TSortable& s) const { CHECK(class_name()==s.class_name(), "Can't compare TConto with TObject"); const TConto& c = (const TConto&)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* TConto::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 == ' ') 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"); } return desc; } bool TConto::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(); _descrizione = r.get("DESCR"); } else r.zero(); return err == NOERR; } // Certified 99% (describe uses __tmp_string) const TString& TConto::descrizione() { if (_descrizione.empty()) { const char* d = describe(); if (d) _descrizione = *d ? d : " "; else _descrizione = "Sconosciuto"; } return _descrizione; } // Certified 99% (uses __tmp_string) const char* TConto::string(int mode) { TFixed_string s(&__tmp_string[128], 80); s.cut(0); if (mode & 0x1) s << _tipo << '|'; s << _gruppo << '|' << _conto << '|' << _sottoconto; if (mode & 0x2) s << '|' << descrizione(); return s; }