campo-sirio/ve/vereplib.cpp
alex 8e33ba67ef Patch level : 2.2 382
Files correlati     :   ve1.exe ci1.exe
Ricompilazione Demo : [ ]
Commento            :

Aggiunta la variabile TIPOCR =  C|R per definire i documenti come costi o ricavi inipendentemente dal cliente o fornitore


git-svn-id: svn://10.65.10.50/trunk@13859 c028cbd2-c16b-5b4b-a496-9718f37d4682
2006-03-22 13:54:33 +00:00

147 lines
3.7 KiB
C++
Executable File

#include <xvt.h>
#include "vereplib.h"
///////////////////////////////////////////////////////////
// TDocument_cache
///////////////////////////////////////////////////////////
class TDocument_cache : TCache
{
protected:
virtual TObject* key2obj(const char* key);
public:
TDocumento& doc(const TRectype& rec);
TDocument_cache() : TCache(23) { }
virtual ~TDocument_cache() { }
};
TObject* TDocument_cache::key2obj(const char* key)
{
TToken_string k(key);
const char provv = *k.get(0);
const int anno = k.get_int();
const TString4 codnum= k.get();
const long ndoc = k.get_long();
return new TDocumento(provv, anno, codnum, ndoc);
}
TDocumento& TDocument_cache::doc(const TRectype& rec)
{
TToken_string key;
key = rec.get(DOC_PROVV);
key.add(rec.get(DOC_ANNO));
key.add(rec.get(DOC_CODNUM));
key.add(rec.get(DOC_NDOC));
TDocumento& d = *(TDocumento*)objptr(key);
return d;
}
const TDocumento& rec2doc(const TRectype& rec)
{
static TDocument_cache* _cache = NULL;
if (_cache == NULL)
_cache = new TDocument_cache;
return _cache->doc(rec);
}
///////////////////////////////////////////////////////////
// TDocument_recordset
///////////////////////////////////////////////////////////
const TVariant& TDocument_recordset::get(int num, const char* field) const
{
const int idx = relation()->log2ind(num);
if (idx < 0)
return NULL_VARIANT;
const TRectype& rec = relation()->file(idx).curr();
const int logic = rec.num();
// Se non e' un campo standard, ma e' calcolato da una formula...
if ((logic == LF_DOC || logic == LF_RIGHEDOC) && rec.type(field) == _nullfld)
{
TVariant& var = get_tmp_var();
const TDocumento& doc = rec2doc(rec);
if (xvt_str_compare_ignoring_case(field, "SEGNO") == 0)
{
var = doc.is_nota_credito() ? -UNO : UNO;
} else
if (xvt_str_compare_ignoring_case(field, "IS_COSTO") == 0)
{
bool costo = (doc.tipo().is_costo()) || (!doc.tipo().is_ricavo() && doc.get_char(DOC_TIPOCF)=='F');
var = costo ? UNO : ZERO;
} else
if (xvt_str_compare_ignoring_case(field, "IS_RICAVO") == 0)
{
bool ricavo = (doc.tipo().is_ricavo()) || (!doc.tipo().is_costo() && doc.get_char(DOC_TIPOCF)=='C');
var = ricavo ? UNO : ZERO;
}
else
{
const TFieldref ref(field, logic);
if (logic == LF_DOC)
{
var = ref.read(doc);
}
else
{
const int nriga = rec.get_int(RDOC_NRIGA);
if (nriga > 0 && nriga <= doc.rows())
{
const TRiga_documento& rdoc = doc[nriga];
var = ref.read(rdoc);
}
else
var = NULL_VARIANT;
}
}
return var;
}
return TISAM_recordset::get(num, field);
}
TDocument_recordset::TDocument_recordset(const char* use)
: TISAM_recordset(use)
{ }
TDocument_recordset::~TDocument_recordset()
{ }
///////////////////////////////////////////////////////////
// TDocument_report
///////////////////////////////////////////////////////////
bool TDocument_report::set_recordset(const TString& query)
{
return TReport::set_recordset(new TDocument_recordset(query));
}
bool TDocument_report::load(const char* name)
{
const bool ok = TReport::load(name);
if (ok)
{
// Purtroppo il recordset delle sottosezioni deve essere reimpostato a mano
for (int i = 11; i <= 999; i++)
{
TReport_section* sec = find_section('B', i);
if (sec != NULL)
{
TRecordset* recset = sec->recordset();
if (recset != NULL)
{
const TString use = recset->query_text();
recset = new TDocument_recordset(use);
sec->set_recordset(recset);
}
}
}
}
return ok;
}