campo-sirio/ve/velib01.cpp
guy 07bcd60df8 Cominciata nuova stesura del programma di fatturazione bolle e corrette le tabelle usate.
git-svn-id: svn://10.65.10.50/trunk@3339 c028cbd2-c16b-5b4b-a496-9718f37d4682
1996-08-08 09:24:17 +00:00

202 lines
5.1 KiB
C++
Executable File

#include <clifo.h>
#include "velib01.h"
///////////////////////////////////////////////////////////
// Documento per vendite
///////////////////////////////////////////////////////////
TDocumento_vendita::TDocumento_vendita()
: _head(LF_DOC), _rows(LF_RIGHEDOC, "NRIGA")
{
}
TDocumento_vendita::TDocumento_vendita(const char* codnum, int anno, char provv, long numdoc)
: _head(LF_DOC), _rows(LF_RIGHEDOC, "NRIGA")
{
read(codnum, anno, provv, numdoc);
}
int TDocumento_vendita::read(const TRectype& rec)
{
_head = rec; // Inizializza i campi chiave in ogni caso
TLocalisamfile doc(LF_DOC);
int err = _head.read(doc);
if (err == NOERR)
{
TRectype* key = new TRectype(LF_RIGHEDOC);
key->put("CODNUM", doc.get("CODNUM"));
key->put("ANNO", doc.get("ANNO"));
key->put("PROVV", doc.get("PROVV"));
key->put("NUMDOC", doc.get("NUMDOC"));
err = _rows.read(key);
}
return err;
}
int TDocumento_vendita::read(const char* codnum, int anno, char provv, long numdoc)
{
CHECK(codnum && *codnum && anno > 0 && (provv == 'D' || provv == 'P') && numdoc > 0,
"Codice documento non valido");
_head.zero();
_head.put("CODNUM", codnum);
_head.put("ANNO", anno);
_head.put("PROVV", provv);
_head.put("NUMDOC", numdoc);
return read(_head);
}
int TDocumento_vendita::write(bool re) const
{
TLocalisamfile doc(LF_DOC);
int err = re ? _head.rewrite(doc) : _head.write(doc);
if (err != NOERR)
err = re ? _head.write(doc) : _head.rewrite(doc);
if (err == NOERR)
err = _rows.write(re);
return err;
}
int TDocumento_vendita::remove() const
{
TLocalisamfile doc(LF_DOC);
int err = _head.remove(doc);
if (err == NOERR)
err = _rows.remove();
return err;
}
///////////////////////////////////////////////////////////
// Cliente per vendite
///////////////////////////////////////////////////////////
void TLista_clienti::TCliente::init(const TRectype& rec)
{
CHECK(rec.num() == LF_CFVEN, "E' necessario un cliente per vendite");
_codice = rec.get_long(CLI_CODCF);
_agente = rec.get_long(CLI_CODAG);
_zona = rec.get_long(CLI_CODZONA);
}
bool TLista_clienti::TCliente::read(long cod)
{
TRelation clifo(LF_CLIFO);
clifo.add(LF_CFVEN, "TIPOCF=TIPOCF|CODCF=CODCF");
clifo.curr().put(CLI_TIPOCF, "C");
clifo.curr().put(CLI_CODCF, cod);
if (clifo.read() == NOERR)
init(clifo.curr(LF_CFVEN));
else
zero();
return ok();
}
TLista_clienti::TCliente::TCliente(const TRectype& rec)
{
if (rec.num() == LF_CFVEN)
init(rec);
else
{
_codice = rec.get_long(CLI_CODCF);
read(_codice);
}
}
int TLista_clienti::leggi(long dc, long ac, long da, long aa, long dz, long az)
{
TRelation clifo(LF_CLIFO);
clifo.add(LF_CFVEN, "TIPOCF=TIPOCF|CODCF=CODCF");
TRectype start(LF_CLIFO), stop(LF_CLIFO);
start.put(CLI_TIPOCF, 'C');
stop.put(CLI_TIPOCF, 'C');
if (dc > 0)
start.put(CLI_CODCF, dc);
if (ac > 0)
stop.put(CLI_CODCF, ac);
TString filter(32);
if (da > 0)
filter << '(' << LF_CFVEN << "->" << CLI_CODAG << ">=" << da << ')';
if (aa > 0)
{
if (filter.not_empty()) filter << "&&";
filter << '(' << LF_CFVEN << "->" << CLI_CODAG << "<=" << aa << ')';
}
if (dz > 0)
{
if (filter.not_empty()) filter << "&&";
filter << '(' << LF_CFVEN << "->" << CLI_CODZONA << ">=" << dz << ')';
}
if (az > 0)
{
if (filter.not_empty()) filter << "&&";
filter << '(' << LF_CFVEN << "->" << CLI_CODZONA << "<=" << az << ')';
}
TCursor cur(&clifo, filter, 1, &start, &stop);
for (cur = 0; cur.ok(); ++cur)
{
TCliente* c = new TCliente(cur.curr(LF_CFVEN));
_clienti.add(c);
}
if (dc > 0 || ac > 0) ordina_per_codice(); else
if (da > 0 || aa > 0) ordina_per_agente(); else
if (dz > 0 || az > 0) ordina_per_zona();
return _clienti.items();
}
int TLista_clienti::sort_by_code(const TObject** o1, const TObject** o2)
{
TLista_clienti::TCliente* c1 = (TLista_clienti::TCliente*)*o1;
TLista_clienti::TCliente* c2 = (TLista_clienti::TCliente*)*o2;
const long d = c1->codice() - c2->codice();
return d == 0L ? 0 : (d > 0 ? +1 : -1);
}
int TLista_clienti::sort_by_agent(const TObject** o1, const TObject** o2)
{
TLista_clienti::TCliente* c1 = (TLista_clienti::TCliente*)*o1;
TLista_clienti::TCliente* c2 = (TLista_clienti::TCliente*)*o2;
const long d = c1->agente() - c2->agente();
return d == 0L ? 0 : (d > 0 ? +1 : -1);
}
int TLista_clienti::sort_by_zone(const TObject** o1, const TObject** o2)
{
TLista_clienti::TCliente* c1 = (TLista_clienti::TCliente*)*o1;
TLista_clienti::TCliente* c2 = (TLista_clienti::TCliente*)*o2;
const long d = c1->zona() - c2->zona();
return d == 0L ? 0 : (d > 0 ? +1 : -1);
}
int TLista_clienti::ordina_per_codice()
{
_clienti.sort(sort_by_code);
return _clienti.items();
}
int TLista_clienti::ordina_per_agente()
{
_clienti.sort(sort_by_agent);
return _clienti.items();
}
int TLista_clienti::ordina_per_zona()
{
_clienti.sort(sort_by_zone);
return _clienti.items();
}