Files correlati : Ricompilazione Demo : [ ] Commento :real calc_conai_qta(int type) const; metodo aggiunto alla TRiga_documento git-svn-id: svn://10.65.10.50/trunk@16216 c028cbd2-c16b-5b4b-a496-9718f37d4682
1288 lines
35 KiB
C++
Executable File
1288 lines
35 KiB
C++
Executable File
#include <tabutil.h>
|
|
|
|
#include "velib.h"
|
|
#include "sconti.h"
|
|
#include "vepriv.h"
|
|
#include "verig.h"
|
|
#include "../ca/commesse.h"
|
|
#include "../mg/mglib.h"
|
|
|
|
#include "rdoc.h"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TTipi_documento_cache
|
|
///////////////////////////////////////////////////////////
|
|
TTipi_documento_cache::TTipi_documento_cache()
|
|
: TRecord_cache("%TIP", 1)
|
|
{
|
|
test_file_changes(); // Tieni d'occhio le modifiche sul file
|
|
set_items_limit(64); // Standard
|
|
}
|
|
|
|
TObject* TTipi_documento_cache::rec2obj(const TRectype& curr) const
|
|
{
|
|
return new TTipo_documento(curr);
|
|
}
|
|
|
|
TTipo_documento & TTipi_documento_cache::tipo(const char* key)
|
|
{
|
|
TTipo_documento & tipo = (TTipo_documento &) query(key);
|
|
return tipo;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TArticolo_cache
|
|
///////////////////////////////////////////////////////////
|
|
class TCache_articoli : public TRecord_cache
|
|
{
|
|
protected:
|
|
virtual TObject* rec2obj(const TRectype& rec) const;
|
|
|
|
public:
|
|
TArticolo_giacenza& art(const char* key);
|
|
TCache_articoli();
|
|
virtual ~TCache_articoli() { }
|
|
};
|
|
|
|
TCache_articoli::TCache_articoli()
|
|
: TRecord_cache(LF_ANAMAG, 1)
|
|
{
|
|
test_file_changes(); // Tieni d'occhio le modifiche sul file
|
|
set_items_limit(256); // Standard
|
|
}
|
|
|
|
TObject* TCache_articoli::rec2obj(const TRectype& curr) const
|
|
{
|
|
return new TArticolo_giacenza(curr);
|
|
}
|
|
|
|
TArticolo_giacenza & TCache_articoli::art(const char* key)
|
|
{
|
|
TArticolo_giacenza& art = (TArticolo_giacenza&)query(key);
|
|
return art;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Tipo riga di un documento
|
|
///////////////////////////////////////////////////////////
|
|
|
|
TAssoc_array TTipo_riga_documento::_formule_riga;
|
|
|
|
TTipo_riga_documento::TTipo_riga_documento(const char* tiporig)
|
|
: TRectype(LF_TABCOM)
|
|
{
|
|
settab("TRI");
|
|
if (tiporig && *tiporig)
|
|
read(tiporig);
|
|
}
|
|
|
|
TTipo_riga_documento::TTipo_riga_documento(const TRectype& rec)
|
|
: TRectype(rec)
|
|
{
|
|
read_formule();
|
|
}
|
|
|
|
int TTipo_riga_documento::read(const char* tiporig)
|
|
{
|
|
*this = cache().get("%TRI", tiporig);
|
|
if (empty())
|
|
yesnofatal_box("Tipo riga documento errato: %s", tiporig);
|
|
else
|
|
read_formule();
|
|
return NOERR;
|
|
}
|
|
|
|
void TTipo_riga_documento::add_formula_if_needed(TConfig& profile, TString& variable,
|
|
const char* varname, const char* formula)
|
|
{
|
|
variable = profile.get(varname, "MAIN");
|
|
if (variable.empty())
|
|
variable = varname;
|
|
const TRectype& frr = cache().get("%FRR", variable);
|
|
if (frr.empty())
|
|
_formule_riga.add(variable, new TFormula_documento(_riga, variable, formula), TRUE);
|
|
if (_formule.find(variable) < 0)
|
|
_formule.add(variable);
|
|
}
|
|
|
|
const TString& TTipo_riga_documento::mask_name(TString& name) const
|
|
{
|
|
name = "verig";
|
|
name << codice();
|
|
return name;
|
|
}
|
|
|
|
const TFilename& TTipo_riga_documento::profile_name(TFilename& name) const
|
|
{
|
|
mask_name(name);
|
|
name.ext(".ini");
|
|
name.custom_path();
|
|
return name;
|
|
}
|
|
|
|
void TTipo_riga_documento::read_formule()
|
|
{
|
|
TFilename prof; profile_name(prof);
|
|
TConfig profile(prof, "MAIN");
|
|
|
|
_search_nums = profile.get("SEARCHNUMS");
|
|
_search_years = profile.get_int("SEARCHYEARS");
|
|
_max_rows_art = profile.get_int("MAXROWSART");
|
|
_no_desc = profile.get_bool("NODESC");
|
|
_formule = profile.get("CAMPICALC");
|
|
|
|
const TString& calcoli = profile.get("CALCOLI");
|
|
if (calcoli == "*")
|
|
{
|
|
TTable frr("%FRR");
|
|
for (int err = frr.first(); err == NOERR; err = frr.next())
|
|
{
|
|
const TString& formula = frr.get("CODTAB");
|
|
if (_formule.find(formula) < 0)
|
|
_formule.add(formula);
|
|
}
|
|
}
|
|
else
|
|
_formule.add(calcoli);
|
|
|
|
_field_provv = profile.get("PROVV");
|
|
_field_qta = profile.get("QTA"); // Non dare un default: ingannerebbe il tipo documento
|
|
_field_qtaevasa = profile.get("QTAEVASA"); // Non dare un default: ingannerebbe il tipo documento
|
|
_field_imposta = profile.get("IMPOSTA");
|
|
_incrp = profile.get_int("VARP+");
|
|
_decrp = profile.get_int("VARP-");
|
|
|
|
add_formula_if_needed(profile, _imponibile, "IMPONIBILE", "IMPORTO(1)");
|
|
add_formula_if_needed(profile, _quant, "QUANT", "QUANT()");
|
|
add_formula_if_needed(profile, _quantevasa, "QUANTEVASA", "QUANTEVASA()");
|
|
add_formula_if_needed(profile, _qtares, "QTARES", "QTARES()");
|
|
}
|
|
|
|
TFormula_documento * TTipo_riga_documento::succ_formula(bool restart)
|
|
{
|
|
if (restart)
|
|
_formule.restart();
|
|
const TString formula(_formule.get());
|
|
if (formula.not_empty())
|
|
{
|
|
char *expr = NULL;
|
|
const int p = formula.find('=');
|
|
if (p > 0)
|
|
{
|
|
expr = (char*)(const char*)formula + p;
|
|
*expr = '\0'; expr++;
|
|
}
|
|
TFormula_documento* o = (TFormula_documento*)_formule_riga.objptr(formula);
|
|
if (o == NULL)
|
|
{
|
|
o = new TFormula_documento(_riga, formula, expr);
|
|
_formule_riga.add(formula, o);
|
|
}
|
|
return o;
|
|
}
|
|
else
|
|
return NULL;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Riga documento per vendite
|
|
///////////////////////////////////////////////////////////
|
|
|
|
long TRiga_documento::_firm = -1;
|
|
TAssoc_array TRiga_documento::_tipi;
|
|
TAssoc_array TRiga_documento::_spese;
|
|
TAssoc_array TRiga_documento::_ive;
|
|
TCache_articoli * TRiga_documento::_articoli = NULL;
|
|
|
|
// 0=ignora IVA; 1=consedera iva solo se c'e' addebito; 2=considera sempre IVA
|
|
int TRiga_documento::_iva_calc_mode = 0;
|
|
bool TRiga_documento::_rit_calc = false;
|
|
|
|
TRiga_documento::TRiga_documento(TDocumento* doc, const char * tipo)
|
|
: TAuto_variable_rectype(LF_RIGHEDOC), _doc(doc)
|
|
{
|
|
if (tipo)
|
|
set_tipo(tipo);
|
|
}
|
|
|
|
TRiga_documento::TRiga_documento(const TRiga_documento & row)
|
|
: TAuto_variable_rectype(LF_RIGHEDOC), _doc(NULL)
|
|
|
|
{
|
|
copy(row);
|
|
}
|
|
|
|
TRiga_documento::TRiga_documento(const TRiga_documento& rec, TDocumento* doc,
|
|
const char * tipo)
|
|
: TAuto_variable_rectype(rec), _doc(doc)
|
|
{
|
|
if (tipo)
|
|
set_tipo(tipo);
|
|
}
|
|
|
|
const TTipo_riga_documento& TRiga_documento::tipo() const
|
|
{
|
|
const TString4 tiporig(get(RDOC_TIPORIGA));
|
|
CHECK(tiporig.not_empty(), "Tipo riga documento nullo");
|
|
TTipo_riga_documento* o = (TTipo_riga_documento*)_tipi.objptr(tiporig);
|
|
if (o == NULL)
|
|
{
|
|
if (_tipi.items() == 0)
|
|
{
|
|
TTable tri("%TRI"); // Tabella dei tipi riga
|
|
for (tri.first(); !tri.eof(); tri.next())
|
|
{
|
|
const TString16 codice = tri.get("CODTAB");
|
|
_tipi.add(codice, new TTipo_riga_documento(tri.curr()));
|
|
}
|
|
}
|
|
o = (TTipo_riga_documento*)_tipi.objptr(tiporig);
|
|
if (o == NULL)
|
|
{
|
|
o = new TTipo_riga_documento(tiporig);
|
|
_tipi.add(tiporig, o);
|
|
}
|
|
}
|
|
return *o;
|
|
}
|
|
|
|
const TSpesa_prest & TRiga_documento::spesa() const
|
|
{
|
|
const char tipor = tipo().tipo();
|
|
|
|
CHECK(tipor == RIGA_SPESEDOC || tipor == RIGA_PRESTAZIONI, "Tipo riga incompatibile con le spese");
|
|
|
|
test_firm();
|
|
|
|
const TString80 codice(get("CODART"));
|
|
TString80 index; index << tipor << codice;
|
|
|
|
TSpesa_prest * s = (TSpesa_prest *) _spese.objptr(index);
|
|
if (s == NULL)
|
|
{
|
|
s = new TSpesa_prest(codice, tipor);
|
|
_spese.add(index, s);
|
|
}
|
|
return *s;
|
|
}
|
|
|
|
const TCodiceIVA & TRiga_documento::iva(const char *codice)
|
|
{
|
|
TCodiceIVA * v = (TCodiceIVA *)_ive.objptr(codice);
|
|
if (v == NULL)
|
|
{
|
|
v = new TCodiceIVA(codice);
|
|
_ive.add(codice, v);
|
|
}
|
|
return *v;
|
|
}
|
|
|
|
bool TRiga_documento::sola_descrizione() const
|
|
{
|
|
char t = tipo().tipo();
|
|
if (t <= ' ' && get("QTA").empty() && get("PREZZO").empty())
|
|
t = RIGA_DESCRIZIONI;
|
|
return t == RIGA_DESCRIZIONI;
|
|
}
|
|
|
|
void TRiga_documento::forza_sola_descrizione()
|
|
{
|
|
// In realta' il test serve anche a caricare la lista dei tipi riga!
|
|
if (!tipo_valido() || !is_descrizione())
|
|
{
|
|
TString16 cod;
|
|
_tipi.restart();
|
|
for (const TObject* o = _tipi.get(); o; o = _tipi.get())
|
|
{
|
|
const TTipo_riga_documento* trd = (const TTipo_riga_documento*)o;
|
|
if (trd->tipo() == RIGA_DESCRIZIONI)
|
|
{
|
|
const TString& c = trd->codice();
|
|
if (cod.empty() || c < cod)
|
|
cod = c;
|
|
}
|
|
}
|
|
put("TIPORIGA", cod);
|
|
zero("QTA");
|
|
zero("PREZZO");
|
|
}
|
|
}
|
|
|
|
TRiga_documento & TRiga_documento::copy(const TRiga_documento & r)
|
|
{
|
|
_doc = r._doc;
|
|
operator=((TRectype &)r);
|
|
return *this;
|
|
}
|
|
|
|
void TRiga_documento::set_variables(TExpression * e) const
|
|
{
|
|
const int items = e->numvar();
|
|
for (int i = 0; i < items; i++)
|
|
{
|
|
const TFieldref field(e->varname(i), LF_RIGHEDOC);
|
|
|
|
switch (field.file())
|
|
{
|
|
case LF_ANAMAG :
|
|
{
|
|
const TArticolo_giacenza * art = articolo();
|
|
|
|
if (art != NULL)
|
|
e->setvar(i, art->get(field.name()));
|
|
}
|
|
break;
|
|
case LF_DOC :
|
|
e->setvar(i, doc().get(field.name()));
|
|
break;
|
|
case LF_CLIFO :
|
|
e->setvar(i, doc().clifor().get(field.name()));
|
|
break;
|
|
case LF_CFVEN :
|
|
e->setvar(i, doc().clifor().vendite().get(field.name()));
|
|
break;
|
|
default:
|
|
e->setvar(i, get(field.name()));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void TRiga_documento::test_firm()
|
|
{
|
|
const long new_firm = prefix().get_codditta();
|
|
|
|
if (_firm != new_firm)
|
|
{
|
|
_spese.destroy();
|
|
_firm = new_firm;
|
|
}
|
|
}
|
|
|
|
TRectype & TRiga_documento::operator =(const TRectype & r)
|
|
{
|
|
TRectype::operator=(r);
|
|
reset_fields(*this);
|
|
set_fields(*this);
|
|
return *this;
|
|
}
|
|
|
|
TRectype & TRiga_documento::operator =(const char * r)
|
|
{
|
|
TRectype::operator=(r);
|
|
reset_fields(*this);
|
|
set_fields(*this);
|
|
return *this;
|
|
}
|
|
|
|
void TRiga_documento::cost2revenue()
|
|
{
|
|
if (is_attrezzatura() || is_risorsa())
|
|
{
|
|
const TSpesa_prest & s = spesa();
|
|
const TString codice(s.revenue());
|
|
|
|
if (codice.not_empty())
|
|
{
|
|
const TString4 tipo(s.tipo());
|
|
if (tipo.not_empty())
|
|
put(RDOC_TIPORIGA, tipo);
|
|
put(RDOC_TIPORIGA, codice);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Ritorna TRUE se le due righe del documento possono essere sommate
|
|
bool TRiga_documento::raggruppabile(const TRiga_documento& r, TToken_string& campi) const
|
|
{
|
|
bool ok = TRUE;
|
|
TString campo;
|
|
for (const char* c = campi.get(0); c && ok; c = campi.get())
|
|
{
|
|
campo = get(c); // Separare le due get!
|
|
ok &= campo == r.get(c);
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
TRiga_documento& TRiga_documento::operator +=(const TRiga_documento& r)
|
|
{
|
|
const TTipo_documento& tipo = doc().tipo();
|
|
|
|
// New age mode
|
|
const char* const campi[5] = { RDOC_NCOLLI, RDOC_TARA, RDOC_PNETTO, tipo.field_qta(), tipo.field_qtaevasa() };
|
|
for (int i = 0; i < 5; i++)
|
|
add(campi[i], r.get_real(campi[i]));
|
|
|
|
if (!get_bool(RDOC_RIGAEVASA))
|
|
{
|
|
if (qtaresidua().is_zero()) // same as is_evasa()
|
|
put(RDOC_RIGAEVASA, "X");
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
|
|
void TRiga_documento::set_fields(TAuto_variable_rectype & rec)
|
|
{
|
|
if (get(RDOC_TIPORIGA).not_empty())
|
|
{
|
|
TTipo_riga_documento & tipo_riga = (TTipo_riga_documento &) tipo();
|
|
|
|
for (const TFormula_documento * f = tipo_riga.first_formula(); f; f = tipo_riga.succ_formula())
|
|
{
|
|
TExpr_documento * exp = f->expr();
|
|
if (exp)
|
|
{
|
|
exp->set_doc(_doc);
|
|
exp->set_row(this);
|
|
add_field(new TDocumento_variable_field(f->name(), *exp));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
real TRiga_documento::prezzo(bool scontato, bool lordo, int ndec) const
|
|
{
|
|
real prezzo;
|
|
if (ndec == AUTO_DECIMALS)
|
|
ndec = doc().decimals(TRUE);
|
|
|
|
if (doc().tipo().calcolo_lordo())
|
|
{
|
|
prezzo = get_real(RDOC_PREZZOL);
|
|
if (prezzo == ZERO)
|
|
{
|
|
prezzo = get_real("PREZZO");
|
|
|
|
if (scontato)
|
|
prezzo = prezzo_scontato(prezzo, get("SCONTO"));
|
|
if (lordo)
|
|
prezzo = iva().lordo(prezzo, ndec);
|
|
}
|
|
else
|
|
{
|
|
if (scontato)
|
|
prezzo = prezzo_scontato(prezzo, get("SCONTO"));
|
|
if (!lordo)
|
|
iva().scorpora(prezzo, ndec);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
prezzo = get_real("PREZZO");
|
|
if (scontato)
|
|
prezzo = prezzo_scontato(prezzo, get("SCONTO"));
|
|
// prezzo.round(ndec);
|
|
if (lordo)
|
|
prezzo = iva().lordo(prezzo, ndec);
|
|
}
|
|
prezzo.round(ndec);
|
|
return prezzo;
|
|
}
|
|
|
|
real TRiga_documento::importo(bool scontato, bool lordo, int ndec) const
|
|
{
|
|
if (ndec == AUTO_DECIMALS)
|
|
ndec = doc().decimals();
|
|
|
|
real importo;
|
|
bool doc_al_lordo = doc().tipo().calcolo_lordo();
|
|
TTipo_calcolo c = _nessun_calcolo;
|
|
const char tipor = tipo().tipo();
|
|
const real qta = get_real(RDOC_QTA);
|
|
real valore, perc;
|
|
|
|
switch (tipor)
|
|
{
|
|
case RIGA_MERCE:
|
|
c = _qtaprezzo;
|
|
break;
|
|
case RIGA_PRESTAZIONI:
|
|
case RIGA_SPESEDOC:
|
|
{
|
|
const TSpesa_prest & s = spesa();
|
|
const bool to_calc = _rit_calc || s.tipo_ritenuta() == '\0';
|
|
|
|
if (to_calc)
|
|
{
|
|
switch (s.tipo())
|
|
{
|
|
case 'Q':
|
|
c = _qtaprezzo;
|
|
break;
|
|
case 'P':
|
|
{
|
|
const TString16 field_perc(s.field_perc());
|
|
c = _percentuale;
|
|
valore = doc().get_real(field_perc);
|
|
if (doc_al_lordo)
|
|
valore = iva().lordo(valore, ALL_DECIMALS, doc().valuta());
|
|
}
|
|
break;
|
|
case 'V':
|
|
default:
|
|
c = _valore;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case RIGA_SCONTI:
|
|
c = _scontopi;
|
|
break;
|
|
case RIGA_OMAGGI:
|
|
if (_iva_calc_mode > 1 || (_iva_calc_mode == 1 && get_bool("ADDIVA")))
|
|
c = _qtaprezzo;
|
|
default:
|
|
break;
|
|
}
|
|
switch (c)
|
|
{
|
|
case _qtaprezzo:
|
|
importo = prezzo(scontato, lordo, ALL_DECIMALS) * qta;
|
|
break;
|
|
case _valore:
|
|
importo = prezzo(scontato, lordo, ndec);
|
|
break;
|
|
case _percentuale:
|
|
importo = valore * get_real(RDOC_QTA) / CENTO;
|
|
break;
|
|
case _scontopi:
|
|
{
|
|
TCond_vendita cv(NULL, NULL);
|
|
|
|
cv.set_sconto(get("SCONTO"));
|
|
if (cv.get_sconto().not_empty())
|
|
{
|
|
importo = doc().basesconto();
|
|
importo *= (cv.sconto_val() - UNO);
|
|
doc_al_lordo = false;
|
|
}
|
|
else
|
|
importo = -prezzo(false, lordo, ALL_DECIMALS);
|
|
TGeneric_distrib d(importo, ALL_DECIMALS);
|
|
TAssoc_array & table = ((TDocumento &) doc()).tabella_iva(true);
|
|
TRiepilogo_iva * aliquota;
|
|
|
|
if (doc_al_lordo)
|
|
{
|
|
if (!lordo)
|
|
{
|
|
importo = ZERO;
|
|
table.restart();
|
|
for (aliquota = (TRiepilogo_iva *) table.get(); aliquota != NULL;
|
|
aliquota = (TRiepilogo_iva *) table.get())
|
|
d.add(aliquota->imp_orig());
|
|
table.restart();
|
|
for (aliquota = (TRiepilogo_iva *) table.get(); aliquota != NULL;
|
|
aliquota = (TRiepilogo_iva *) table.get())
|
|
{
|
|
const TCodiceIVA & iva = aliquota->cod_iva();
|
|
real slice = d.get();
|
|
|
|
iva.scorpora(slice, ALL_DECIMALS, ((TDocumento &) doc()).valuta());
|
|
importo += slice;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (lordo)
|
|
{
|
|
importo = ZERO;
|
|
table.restart();
|
|
for (aliquota = (TRiepilogo_iva *) table.get(); aliquota != NULL;
|
|
aliquota = (TRiepilogo_iva *) table.get())
|
|
d.add(aliquota->imp_orig());
|
|
table.restart();
|
|
for (aliquota = (TRiepilogo_iva *) table.get(); aliquota != NULL;
|
|
aliquota = (TRiepilogo_iva *) table.get())
|
|
{
|
|
const TCodiceIVA & iva = aliquota->cod_iva();
|
|
|
|
importo += iva.lordo(d.get(), ALL_DECIMALS, ((TDocumento &) doc()).valuta());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
importo.round(ndec); // arrotondamento finale
|
|
return importo;
|
|
}
|
|
|
|
real TRiga_documento::iva(int ndec) const
|
|
{
|
|
real zanicchi;
|
|
if (!is_sconto())
|
|
{
|
|
if (is_omaggio())
|
|
zanicchi = iva_omaggio(ndec);
|
|
else
|
|
{
|
|
if (ndec == AUTO_DECIMALS)
|
|
ndec = doc().decimals();
|
|
const TString& field = tipo().imposta();
|
|
if (field.not_empty())
|
|
{
|
|
zanicchi = get_real(field);
|
|
zanicchi.round(ndec);
|
|
}
|
|
else
|
|
{
|
|
zanicchi = iva().imposta(imponibile(), ndec);
|
|
}
|
|
}
|
|
}
|
|
return zanicchi;
|
|
}
|
|
|
|
real TRiga_documento::iva_omaggio(int ndec, int tipo_iva_calc) const
|
|
{
|
|
if (ndec == AUTO_DECIMALS)
|
|
ndec = doc().decimals();
|
|
const real zanicchi = iva().imposta(imponibile_omaggio(tipo_iva_calc), ndec);
|
|
return zanicchi;
|
|
}
|
|
|
|
real TRiga_documento::imponibile_omaggio(int tipo_iva_calc) const
|
|
{
|
|
_iva_calc_mode = tipo_iva_calc;
|
|
const real imp = imponibile();
|
|
_iva_calc_mode = 0;
|
|
return imp;
|
|
}
|
|
|
|
real TRiga_documento::imponibile(bool lordo) const
|
|
{
|
|
const TString& field = tipo().imponibile();
|
|
if (field.full())
|
|
{
|
|
real r;
|
|
if (is_omaggio() && _iva_calc_mode > 0)
|
|
{
|
|
TDocumento_variable_field * f = (TDocumento_variable_field *) variable_field(field);
|
|
CHECKS(f, "Field UNKNOWN : ", (const char *) field);
|
|
f->set_dirty(TRUE);
|
|
r = get_real(field);
|
|
f->set_dirty(TRUE);
|
|
}
|
|
else
|
|
r = get_real(field);
|
|
if (lordo)
|
|
r = iva().lordo(r, doc().decimals(TRUE));
|
|
return r;
|
|
}
|
|
return importo(true, lordo, doc().decimals());
|
|
}
|
|
|
|
real TRiga_documento::imposta(bool round) const
|
|
{
|
|
return iva(round ? doc().decimals() : 20);
|
|
}
|
|
|
|
real TRiga_documento::provvigione(int ndec) const
|
|
{
|
|
real val;
|
|
|
|
if (ndec == AUTO_DECIMALS)
|
|
ndec = doc().decimals();
|
|
const TString & field = tipo().provv();
|
|
if (field.not_empty())
|
|
val = get_real(field);
|
|
else
|
|
{
|
|
const char tipo_riga = tipo().tipo();
|
|
val = importo(TRUE, FALSE, ndec);
|
|
|
|
if (tipo_riga == RIGA_MERCE || tipo_riga == RIGA_SPESEDOC || tipo_riga == RIGA_PRESTAZIONI)
|
|
{
|
|
real netto_testa;
|
|
TString80 s;
|
|
|
|
if (scontoexpr2perc(doc().get(DOC_SCONTOPERC), FALSE, s, netto_testa) && netto_testa != ZERO)
|
|
val *= netto_testa;
|
|
}
|
|
|
|
val *= get_real(RDOC_PERCPROV) / CENTO;
|
|
}
|
|
val.round(ndec);
|
|
return val;
|
|
}
|
|
|
|
real TRiga_documento::ritenuta(const char tipor, bool lordo, int ndec) const
|
|
{
|
|
real val;
|
|
|
|
if (tipo().tipo() == RIGA_SPESEDOC)
|
|
{
|
|
const char tipo_rit = spesa().tipo_ritenuta();
|
|
|
|
if ((tipor != '\0' && tipo_rit == tipor) || (tipor == '\0' && tipo_rit != '\0'))
|
|
{
|
|
_rit_calc = TRUE;
|
|
val = importo(true, lordo, ndec);
|
|
_rit_calc = FALSE;
|
|
}
|
|
}
|
|
return val;
|
|
}
|
|
|
|
const TString& TRiga_documento::field_qta() const
|
|
{
|
|
const TString& rowtype_field = tipo().field_qta();
|
|
if (rowtype_field.not_empty())
|
|
return rowtype_field;
|
|
const TString& doctype_field = doc().tipo().field_qta();
|
|
return doctype_field;
|
|
}
|
|
|
|
const TString& TRiga_documento::field_qtaevasa() const
|
|
{
|
|
const TString& rowtype_field = tipo().field_qtaevasa();
|
|
if (rowtype_field.not_empty())
|
|
return rowtype_field;
|
|
const TString& doctype_field = doc().tipo().field_qtaevasa();
|
|
return doctype_field;
|
|
}
|
|
|
|
real TRiga_documento::quantita() const
|
|
{
|
|
return get_real(field_qta());
|
|
}
|
|
|
|
real TRiga_documento::qtaevasa() const
|
|
{
|
|
return get_real(field_qtaevasa());
|
|
}
|
|
|
|
real TRiga_documento::qtaresidua() const
|
|
{
|
|
if (!get_bool(RDOC_RIGAEVASA))
|
|
{
|
|
real val = quantita() - qtaevasa();
|
|
if (val > ZERO)
|
|
return val;
|
|
}
|
|
return ZERO;
|
|
}
|
|
|
|
real TRiga_documento::calc_conai_qta(int type) const
|
|
{
|
|
const char* const __conai_art_names[] = {"CONACC", "CONALL", "CONCAR", "CONPLA", "CONLEG", "CONVET"};
|
|
real row_qta;
|
|
|
|
if (is_merce())
|
|
{
|
|
const bool has_formula = ((TTipo_riga_documento &)tipo()).has_formula(__conai_art_names[type]);
|
|
TArticolo_giacenza* art = articolo();
|
|
if (art != NULL)
|
|
{
|
|
const TString4 um = get(RDOC_UMQTA);
|
|
row_qta = art->convert_to_um(get_real(RDOC_QTA), NULL, um);
|
|
|
|
if (has_formula)
|
|
row_qta *= get_real(__conai_art_names[type]);
|
|
else
|
|
row_qta *= art->get_real(__conai_art_names[type]);
|
|
}
|
|
else
|
|
{
|
|
if (has_formula)
|
|
{
|
|
row_qta = get_real(RDOC_QTA);
|
|
row_qta *= get_real(__conai_art_names[type]);
|
|
}
|
|
}
|
|
}
|
|
|
|
return row_qta;
|
|
}
|
|
|
|
bool TRiga_documento::is_evasa() const
|
|
{
|
|
return qtaresidua().is_zero();
|
|
}
|
|
|
|
real TRiga_documento::valore(bool totale, int ndec) const
|
|
{
|
|
real val;
|
|
|
|
TString16 field_qta = tipo().field_qta();
|
|
if (field_qta.empty())
|
|
field_qta = doc().tipo().field_qta();
|
|
const bool qta_is_price = field_qta == RDOC_PREZZO;
|
|
|
|
if (totale)
|
|
{
|
|
TString16 field_qta = tipo().field_qta();
|
|
if (field_qta.empty())
|
|
field_qta = doc().tipo().field_qta();
|
|
if (qta_is_price)
|
|
field_qta = RDOC_QTA;
|
|
val = get_real(field_qta);
|
|
val *= prezzo(TRUE, FALSE, ALL_DECIMALS);
|
|
}
|
|
else
|
|
{
|
|
val = qtaresidua();
|
|
if (!qta_is_price)
|
|
val *= prezzo(TRUE, FALSE, ALL_DECIMALS);
|
|
}
|
|
|
|
if (ndec == AUTO_DECIMALS)
|
|
ndec = doc().decimals();
|
|
val.round(ndec);
|
|
|
|
return val;
|
|
}
|
|
|
|
const TString & TRiga_documento::codice_costo() const
|
|
{
|
|
const TString & cod_cos = get(RDOC_CODCOSTO);
|
|
return cod_cos.empty() ? doc().get(DOC_CODCOSTO) : cod_cos;
|
|
}
|
|
|
|
const TString & TRiga_documento::codice_commessa() const
|
|
{
|
|
const TString& cod_cms = get(RDOC_CODCMS);
|
|
return cod_cms.empty() ? doc().get(DOC_CODCMS) : cod_cms;
|
|
}
|
|
|
|
const TString & TRiga_documento::fase_commessa() const
|
|
{
|
|
const TString & fas_cms = get(RDOC_FASCMS);
|
|
return fas_cms.empty() ? doc().get(DOC_FASCMS) : fas_cms;
|
|
}
|
|
|
|
void TRiga_documento::dirty_fields(bool dirty_document)
|
|
{
|
|
for (TDocumento_variable_field * f = (TDocumento_variable_field *) first_variable_field();
|
|
f != NULL; f = (TDocumento_variable_field *) succ_variable_field())
|
|
f->set_dirty();
|
|
if (dirty_document)
|
|
((TDocumento &)doc()).dirty_fields();
|
|
}
|
|
|
|
bool TRiga_documento::doc_dependent() const
|
|
{
|
|
if (tipo_valido())
|
|
{
|
|
const char tipor = tipo().tipo();
|
|
|
|
if (tipor == RIGA_SPESEDOC)
|
|
return spesa().tipo() == 'P';
|
|
else
|
|
if (tipor == RIGA_SCONTI)
|
|
return get("SCONTO").not_empty();
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
void TRiga_documento::put_str(const char* fieldname, const char* val)
|
|
{
|
|
if (strcmp(fieldname, RDOC_TIPORIGA) == 0)
|
|
{
|
|
const TString4 v(val);
|
|
if (TRectype::get(RDOC_TIPORIGA) != v)
|
|
{
|
|
TAuto_variable_rectype::put_str(fieldname, v);
|
|
reset_fields(*this);
|
|
set_fields(*this);
|
|
}
|
|
else
|
|
dirty_fields();
|
|
}
|
|
else
|
|
{
|
|
TAuto_variable_rectype::put_str(fieldname, val);
|
|
dirty_fields();
|
|
}
|
|
}
|
|
|
|
bool TRiga_documento::is_articolo() const
|
|
{
|
|
const char t = tipo().tipo();
|
|
return (t == RIGA_MERCE || t == RIGA_OMAGGI) && get(RDOC_CODARTMAG).full();
|
|
}
|
|
|
|
void TRiga_documento::zero(const char * fieldname)
|
|
{
|
|
if (strcmp(fieldname, RDOC_TIPORIGA) == 0)
|
|
reset_fields(*this);
|
|
TAuto_variable_rectype::zero(fieldname);
|
|
dirty_fields();
|
|
}
|
|
|
|
void TRiga_documento::zero(char c)
|
|
{
|
|
reset_fields(*this);
|
|
TAuto_variable_rectype::zero(c);
|
|
}
|
|
|
|
void TRiga_documento::autosave(TSheet_field& f)
|
|
{
|
|
const int num = numero() - 1;
|
|
|
|
if (num >= 0 && num < f.items())
|
|
{
|
|
TMask& m = f.sheet_mask();
|
|
TToken_string & row = f.row(num);
|
|
|
|
/* const int lordo_id = f.cid2index(FR_LORDO);
|
|
const bool lordo = strcmp(row.get(lordo_id), "X") == 0;
|
|
if (lordo)
|
|
{
|
|
row.add(" ", lordo_id);
|
|
m.reset(FR_LORDO);
|
|
} */
|
|
put( RDOC_TIPORIGA, row.get( f.cid2index(FR_TIPORIGA )) );
|
|
TString8 codmag(row.get(f.cid2index(FR_CODMAG)));
|
|
|
|
codmag.left_just(3);
|
|
codmag << row.get( f.cid2index(FR_CODDEP ));
|
|
put( RDOC_CODMAG, codmag);
|
|
put( RDOC_CODART, row.get( f.cid2index(FR_CODART )) );
|
|
TString liv;
|
|
for (int l = 0; l<4 ; l++)
|
|
doc().livelli().pack_grpcode(liv,row.get(f.cid2index(FR_LIV1+l)),l+1);
|
|
put( RDOC_LIVELLO, liv); // da modificare
|
|
TString s = row.get(f.cid2index(FR_DESCR)); s.rtrim();
|
|
int split_pos = s.find('\n');
|
|
const int descr_len = length(RDOC_DESCR);
|
|
if (split_pos < 0 && s.len() > descr_len)
|
|
split_pos = descr_len;
|
|
if (split_pos > descr_len)
|
|
split_pos = descr_len;
|
|
if (split_pos > 0)
|
|
{
|
|
put(RDOC_DESCR, s.left(split_pos));
|
|
const TString& dest = s.mid(split_pos);
|
|
put(RDOC_DESCLUNGA, "X");
|
|
put(RDOC_DESCEST, dest);
|
|
}
|
|
else
|
|
{
|
|
put(RDOC_DESCR, s);
|
|
zero(RDOC_DESCLUNGA);
|
|
zero(RDOC_DESCEST);
|
|
}
|
|
|
|
const int prezzo_id = f.cid2index(FR_PREZZO);
|
|
real prezzo(row.get(prezzo_id));
|
|
const TString4 codiva(row.get(f.cid2index(FR_CODIVA)));
|
|
if (doc().tipo().calcolo_lordo())
|
|
{
|
|
put(RDOC_PREZZOL, prezzo);
|
|
iva(codiva).scorpora(prezzo, doc().decimals(TRUE));
|
|
}
|
|
put( RDOC_PREZZO, prezzo);
|
|
put( RDOC_UMQTA, row.get( f.cid2index(FR_UMQTA )) );
|
|
put( RDOC_QTA, row.get( f.cid2index(FR_QTA )) );
|
|
put( RDOC_QTAEVASA, row.get( f.cid2index(FR_QTAEVASA )) );
|
|
put( RDOC_RIGAEVASA, row.get( f.cid2index(FR_RIGAEVASA )) );
|
|
put( RDOC_TARA, row.get( f.cid2index(FR_TARA )) );
|
|
put( RDOC_PNETTO, row.get( f.cid2index(FR_PNETTO )) );
|
|
put( RDOC_NCOLLI, row.get( f.cid2index(FR_NCOLLI )) );
|
|
put( RDOC_DAEVADERE, row.get( f.cid2index(FR_DAEVADERE )) );
|
|
put( RDOC_SCONTO, row.get( f.cid2index(FR_SCONTO )) );
|
|
put( RDOC_PERCPROV, row.get( f.cid2index(FR_PERCPROV )) );
|
|
put( RDOC_IMPFISUN, row.get( f.cid2index(FR_IMPFISUN )) );
|
|
put( RDOC_IMPFISSO, row.get( f.cid2index(FR_IMPFISSO )) );
|
|
put( RDOC_CODIVA, codiva);
|
|
put( RDOC_ADDIVA, row.get( f.cid2index(FR_ADDIVA )) );
|
|
put( RDOC_ASPBENI, row.get( f.cid2index(FR_ASPBENI )) );
|
|
put( RDOC_CAUSMAG, row.get( f.cid2index(FR_CAUS )) );
|
|
TString8 codmagc(row.get(f.cid2index(FR_CODMAGC)));
|
|
|
|
codmagc.left_just(3);
|
|
codmagc << row.get( f.cid2index(FR_CODDEPC ));
|
|
put( RDOC_CODMAGC, codmagc);
|
|
put( RDOC_DATACONS, row.get( f.cid2index(FR_DATACONS )) );
|
|
put( RDOC_CODARTMAG, row.get( f.cid2index(FR_CODARTMAG )) );
|
|
put( RDOC_CHECKED, row.get( f.cid2index(FR_CHECKED )) );
|
|
put( RDOC_QTAGG1, row.get( f.cid2index(FR_QTAGG1 )) );
|
|
put( RDOC_QTAGG2, row.get( f.cid2index(FR_QTAGG2 )) );
|
|
put( RDOC_QTAGG3, row.get( f.cid2index(FR_QTAGG3 )) );
|
|
put( RDOC_QTAGG4, row.get( f.cid2index(FR_QTAGG4 )) );
|
|
put( RDOC_QTAGG5, row.get( f.cid2index(FR_QTAGG5 )) );
|
|
put( RDOC_IMPIANTO, row.get( f.cid2index(FR_IMPIANTO )) );
|
|
put( RDOC_LINEA, row.get( f.cid2index(FR_LINEA )) );
|
|
|
|
f.select(num); // Seleziona la riga in modo da selezionare la maschera di riga giusta
|
|
for (short cdcid = FR_CDC1; cdcid <= FR_CDC12; cdcid++)
|
|
{
|
|
const int pos = m.id2pos(cdcid);
|
|
if (pos < 0)
|
|
break;
|
|
const TMask_field& fld = m.fld(pos);
|
|
const TFieldref* fldref = fld.field();
|
|
if (fldref == NULL)
|
|
break;
|
|
fldref->write(fld.get(), *this);
|
|
}
|
|
|
|
if (m.id2pos(FR_TIPODET) >= 0 && m.field(FR_TIPODET).active()) //solo se attivo il campo di indetraibilita'...
|
|
{
|
|
const TString & tipodet = row.get( f.cid2index(FR_TIPODET));
|
|
put( RDOC_TIPODET, tipodet );
|
|
if (tipodet != "9")
|
|
{
|
|
TString codcms = get(RDOC_CODCMS); //dalla rigadoc
|
|
if (codcms.blank()) //se non la trova cerca nella maschera di testata
|
|
{
|
|
TDocumento_mask& doc_mask = (TDocumento_mask&)f.mask();
|
|
const short cms_start = doc_mask.cms_start();
|
|
const short cms_end = doc_mask.cms_end();
|
|
codcms.cut(0);
|
|
for (short j = cms_start; j <= cms_end; j++)
|
|
{
|
|
const TEdit_field& fld = doc_mask.efield(j);
|
|
TString80 str = fld.get();
|
|
str.rpad(fld.size());
|
|
codcms << str;
|
|
}
|
|
codcms.rtrim();
|
|
}
|
|
if (codcms.full() && codiva.full())
|
|
{
|
|
const TRectype& rec_cms = cache().get(LF_COMMESSE, codcms);
|
|
const TString& regiva = rec_cms.get(COMMESSE_REGIVA);
|
|
|
|
if (regiva.full())
|
|
{
|
|
put( RDOC_TIPODET, 9 );
|
|
row.add(9, f.cid2index(FR_TIPODET));
|
|
m.set(FR_TIPODET, 9);
|
|
}
|
|
}
|
|
} //if(tipodet!=9)
|
|
} //if(m.field(...
|
|
|
|
put( RDOC_CODAGG1, row.get(f.cid2index(FR_CODAGG1)) );
|
|
put( RDOC_CODAGG2, row.get(f.cid2index(FR_CODAGG2)) );
|
|
|
|
for (short jid = FR_JOLLY1; jid <= FR_JOLLY10; jid++)
|
|
{
|
|
const int pos = m.id2pos(jid);
|
|
if (pos < 0)
|
|
break;
|
|
const TMask_field& fld = m.fld(pos);
|
|
const TFieldref* fldref = fld.field();
|
|
if (fldref == NULL)
|
|
break;
|
|
fldref->write(fld.get(), *this);
|
|
}
|
|
}
|
|
}
|
|
|
|
void TRiga_documento::autoload(TSheet_field & f)
|
|
{
|
|
const int num = numero() - 1;
|
|
|
|
TToken_string & row = f.row(num);
|
|
row.cut(0);
|
|
|
|
row.add( get( RDOC_TIPORIGA ), f.cid2index(FR_TIPORIGA ));
|
|
const TString8 codmag(get(RDOC_CODMAG));
|
|
row.add( codmag.left(3), f.cid2index(FR_CODMAG ));
|
|
row.add( codmag.mid(3), f.cid2index(FR_CODDEP ));
|
|
row.add( get( RDOC_CODART ), f.cid2index(FR_CODART ));
|
|
TString16 liv(get(RDOC_LIVELLO));
|
|
|
|
for (int l = 0; l<4 ; l++)
|
|
row.add(doc().livelli().unpack_grpcode(liv,l+1), f.cid2index(FR_LIV1+l ));
|
|
TString s = get(RDOC_DESCR);
|
|
if (get_bool(RDOC_DESCLUNGA))
|
|
s << get(RDOC_DESCEST);
|
|
row.add(s, f.cid2index(FR_DESCR ));
|
|
row.add( get( RDOC_UMQTA ), f.cid2index(FR_UMQTA ));
|
|
|
|
|
|
TString8 codiva(get(RDOC_CODIVA));
|
|
real prezzo = get_real( RDOC_PREZZO );
|
|
|
|
if (doc().tipo().calcolo_lordo())
|
|
{
|
|
const real prezzol = get_real(RDOC_PREZZOL);
|
|
|
|
if (prezzol != ZERO)
|
|
prezzo = prezzol;
|
|
else
|
|
prezzo = iva(codiva).lordo(prezzo, ALL_DECIMALS);
|
|
}
|
|
|
|
row.add(prezzo.string(), f.cid2index(FR_PREZZO ));
|
|
row.add( get( RDOC_QTA ), f.cid2index(FR_QTA ));
|
|
row.add( get( RDOC_QTAEVASA ), f.cid2index(FR_QTAEVASA ));
|
|
row.add( get( RDOC_RIGAEVASA ), f.cid2index(FR_RIGAEVASA ));
|
|
row.add( get( RDOC_TARA ), f.cid2index(FR_TARA ));
|
|
row.add( get( RDOC_PNETTO ), f.cid2index(FR_PNETTO ));
|
|
row.add( get( RDOC_NCOLLI ), f.cid2index(FR_NCOLLI ));
|
|
row.add( get( RDOC_DAEVADERE ), f.cid2index(FR_DAEVADERE ));
|
|
row.add( get( RDOC_SCONTO ), f.cid2index(FR_SCONTO ));
|
|
row.add( get( RDOC_PERCPROV ), f.cid2index(FR_PERCPROV ));
|
|
row.add( get( RDOC_IMPFISUN ), f.cid2index(FR_IMPFISUN ));
|
|
row.add( get( RDOC_IMPFISSO ), f.cid2index(FR_IMPFISSO ));
|
|
row.add( codiva, f.cid2index(FR_CODIVA ));
|
|
row.add( get( RDOC_ADDIVA ), f.cid2index(FR_ADDIVA ));
|
|
row.add( get( RDOC_ASPBENI ), f.cid2index(FR_ASPBENI ));
|
|
row.add( get( RDOC_CAUSMAG ), f.cid2index(FR_CAUS ));
|
|
const TString8 codmagc(get("CODMAGC"));
|
|
row.add( codmagc.left(3), f.cid2index(FR_CODMAGC ));
|
|
row.add( codmagc.mid(3), f.cid2index(FR_CODDEPC ));
|
|
row.add( get( RDOC_DATACONS ), f.cid2index(FR_DATACONS ));
|
|
row.add( get( RDOC_CODARTMAG ), f.cid2index(FR_CODARTMAG));
|
|
row.add( get( RDOC_CHECKED ), f.cid2index(FR_CHECKED));
|
|
row.add( get( RDOC_QTAGG1), f.cid2index(FR_QTAGG1));
|
|
row.add( get( RDOC_QTAGG2), f.cid2index(FR_QTAGG2));
|
|
row.add( get( RDOC_QTAGG3), f.cid2index(FR_QTAGG3));
|
|
row.add( get( RDOC_QTAGG4) , f.cid2index(FR_QTAGG4));
|
|
row.add( get( RDOC_QTAGG5) , f.cid2index(FR_QTAGG5));
|
|
row.add( get( RDOC_IMPIANTO) , f.cid2index(FR_IMPIANTO));
|
|
row.add( get( RDOC_LINEA) , f.cid2index(FR_LINEA));
|
|
|
|
f.select(num); // Seleziona la riga in modo da selezionare la maschera di riga giusta
|
|
TMask& m = f.sheet_mask();
|
|
for (short cdcid = FR_CDC1; cdcid <= FR_CDC12; cdcid++)
|
|
{
|
|
const int pos = m.id2pos(cdcid);
|
|
if (pos < 0)
|
|
break;
|
|
TMask_field& fld = m.fld(pos);
|
|
const TFieldref* fldref = fld.field();
|
|
if (fldref == NULL)
|
|
break;
|
|
const TString& val = fldref->read(*this);
|
|
row.add(val, f.cid2index(cdcid));
|
|
}
|
|
row.add( get( RDOC_CODAGG1) , f.cid2index(FR_CODAGG1));
|
|
row.add( get( RDOC_CODAGG2) , f.cid2index(FR_CODAGG2));
|
|
row.add( get( RDOC_TIPODET) , f.cid2index(FR_TIPODET));
|
|
|
|
for (short jid = FR_JOLLY1; jid <= FR_JOLLY10; jid++)
|
|
{
|
|
const int pos = m.id2pos(jid);
|
|
if (pos < 0)
|
|
break;
|
|
TMask_field& fld = m.fld(pos);
|
|
const TFieldref* fldref = fld.field();
|
|
if (fldref == NULL)
|
|
break;
|
|
const TString& val = fldref->read(*this);
|
|
row.add(val, f.cid2index(jid));
|
|
}
|
|
}
|
|
|
|
TArticolo_giacenza* TRiga_documento::articolo() const
|
|
{
|
|
if (_articoli == NULL)
|
|
_articoli = new TCache_articoli();
|
|
|
|
const TString& codart = get(RDOC_CODARTMAG);
|
|
if (codart.blank())
|
|
|
|
return NULL;
|
|
return &(_articoli->art(codart));
|
|
}
|
|
|
|
void TRiga_documento::set_original_rdoc_key(const TRectype& orig, int depth)
|
|
{
|
|
CHECK(orig.num() == LF_RIGHEDOC, "Bad document row");
|
|
|
|
switch (depth)
|
|
{
|
|
case 0:
|
|
put(RDOC_DACODNUM, orig.get(RDOC_CODNUM));
|
|
put(RDOC_DAANNO, orig.get(RDOC_ANNO));
|
|
put(RDOC_DAPROVV, orig.get(RDOC_PROVV));
|
|
put(RDOC_DANDOC, orig.get(RDOC_NDOC));
|
|
put(RDOC_DAIDRIGA, orig.get(RDOC_IDRIGA));
|
|
break;
|
|
case 1:
|
|
put(RDOC_DACODNUM, orig.get(RDOC_DACODNUM));
|
|
put(RDOC_DAANNO, orig.get(RDOC_DAANNO));
|
|
put(RDOC_DAPROVV, orig.get(RDOC_DAPROVV));
|
|
put(RDOC_DANDOC, orig.get(RDOC_DANDOC));
|
|
put(RDOC_DAIDRIGA, orig.get(RDOC_DAIDRIGA));
|
|
break;
|
|
default:
|
|
CHECK(0, "Sorry, too deep!");
|
|
break;
|
|
}
|
|
}
|
|
|
|
void TRiga_documento::reset_original_rdoc_key()
|
|
{
|
|
zero(RDOC_DACODNUM);
|
|
zero(RDOC_DAANNO);
|
|
zero(RDOC_DAPROVV);
|
|
zero(RDOC_DANDOC);
|
|
zero(RDOC_DAIDRIGA);
|
|
}
|
|
|
|
const TRectype* TRiga_documento::find_original_rdoc() const
|
|
{
|
|
const long id = get_long(RDOC_DAIDRIGA);
|
|
if (id > 0L)
|
|
{
|
|
TToken_string key;
|
|
key.add(get(RDOC_DACODNUM));
|
|
key.add(get(RDOC_DAANNO));
|
|
key.add(get(RDOC_DAPROVV));
|
|
key.add(get(RDOC_DANDOC));
|
|
for (int r = 1; ; r++)
|
|
{
|
|
key.add(r, 4);
|
|
const TRectype& rec = cache().get(LF_RIGHEDOC, key);
|
|
if (rec.empty()) break;
|
|
if (rec.get_long(RDOC_IDRIGA) == id)
|
|
return &rec;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
const TRectype* TRiga_documento::find_original_doc() const
|
|
{
|
|
const long id = get_long(RDOC_DAIDRIGA);
|
|
if (id > 0L)
|
|
{
|
|
TToken_string key;
|
|
key.add(get(RDOC_DAPROVV));
|
|
key.add(get(RDOC_DAANNO));
|
|
key.add(get(RDOC_DACODNUM));
|
|
key.add(get(RDOC_DANDOC));
|
|
const TRectype& rec = cache().get(LF_DOC, key);
|
|
if (!rec.empty())
|
|
return &rec;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
void TTipo_riga_documento::set_defaults(TSheet_field& s, int row) const
|
|
{
|
|
if (_defaults.items() == 0) // Carica lo string_array con i defaults
|
|
{
|
|
TFilename pn; profile_name(pn);
|
|
TConfig prof(pn, "DEFAULT");
|
|
for(int i = 0; ; i++)
|
|
{
|
|
TToken_string s(prof.get("Default", NULL, i));
|
|
if (s.empty())
|
|
break;
|
|
const int field = s.get_int();
|
|
((TTipo_riga_documento*)this)->_defaults.add(s.get(), field);
|
|
}
|
|
}
|
|
// Setta i campi della maschera
|
|
TToken_string & r = s.row(row - 1);
|
|
FOR_EACH_ARRAY_ROW(_defaults, i, tt)
|
|
{
|
|
r.add(*tt, s.cid2index(i));
|
|
}
|
|
}
|