Files correlati : Ricompilazione Demo : [ ] Commento : GF20112 Quando un documento viene contabilizzato per la seconda volta SENZA aver cancellato il movimento preesistente, il programma giustamente sovrascrive il movimento di prima nota, ma non sistema correttamente i saldi. git-svn-id: svn://10.65.10.50/trunk@11664 c028cbd2-c16b-5b4b-a496-9718f37d4682
971 lines
27 KiB
C++
Executable File
971 lines
27 KiB
C++
Executable File
#include <tabutil.h>
|
|
|
|
#include "velib.h"
|
|
#include "sconti.h"
|
|
#include "vepriv.h"
|
|
#include "verig.h"
|
|
#include "../mg/mglib.h"
|
|
|
|
#include "rdoc.h"
|
|
|
|
// 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");
|
|
|
|
_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
|
|
_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;
|
|
|
|
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 TString16 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 TString16 codice(get("CODART"));
|
|
TString16 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;
|
|
}
|
|
|
|
// 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();
|
|
TToken_string campi("NCOLLI");
|
|
campi.add(tipo.field_qta());
|
|
campi.add(tipo.field_qtaevasa());
|
|
|
|
for (const char* c = campi.get(0); c; c = campi.get())
|
|
{
|
|
real num = r.get_real(c);
|
|
if (!num.is_zero())
|
|
{
|
|
num += get_real(c);
|
|
put(c, num);
|
|
}
|
|
}
|
|
if (!get_bool("RIGAEVASA"))
|
|
{
|
|
if (qtaresidua().is_zero()) // same as is_evasa()
|
|
put("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
|
|
{
|
|
if (ndec == AUTO_DECIMALS)
|
|
ndec = doc().decimals(TRUE);
|
|
|
|
real prezzo = get_real("PREZZO");
|
|
if (doc().tipo().calcolo_lordo())
|
|
{
|
|
if (lordo)
|
|
prezzo = iva().lordo(prezzo, ndec);
|
|
prezzo.round(ndec);
|
|
if (scontato)
|
|
prezzo = prezzo_scontato(prezzo, get("SCONTO"));
|
|
prezzo.round(ndec);
|
|
}
|
|
else
|
|
{
|
|
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;
|
|
const 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 r1;
|
|
|
|
switch (tipor)
|
|
{
|
|
case RIGA_MERCE:
|
|
c = _qtaprezzo;
|
|
break;
|
|
case RIGA_PRESTAZIONI:
|
|
case RIGA_SPESEDOC:
|
|
{
|
|
const TSpesa_prest & s = spesa();
|
|
const bool to_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;
|
|
r1 = doc().get_real(field_perc);
|
|
}
|
|
break;
|
|
case 'V':
|
|
default:
|
|
c = _valore;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case RIGA_SCONTI:
|
|
{
|
|
TCond_vendita cv(NULL, NULL);
|
|
cv.set_sconto(get("SCONTO"));
|
|
if (cv.get_sconto().not_empty())
|
|
c = _scontoperc;
|
|
else
|
|
c = _scontoimp;
|
|
r1 = cv.sconto_val();
|
|
}
|
|
break;
|
|
case RIGA_OMAGGI:
|
|
if (_iva_calc_mode > 1 || (_iva_calc_mode == 1 && get_bool("ADDIVA")))
|
|
c = _qtaprezzo;
|
|
default:
|
|
break;
|
|
}
|
|
switch (c)
|
|
{
|
|
case _qtaprezzo:
|
|
if (doc_al_lordo)
|
|
{
|
|
// Altamente impreciso: moltiplica per qta un prezzo arrotondato a priori!
|
|
// importo = prezzo(scontato, TRUE, ndec) * qta;
|
|
|
|
// Rimanda l'arrotondamento a dopo aver calcolato il totale riga!
|
|
importo = prezzo(scontato, TRUE, ALL_DECIMALS) * qta;
|
|
importo.round(ndec); // Riga inutile ma esplicatrice;
|
|
}
|
|
else
|
|
importo = prezzo(scontato, lordo, ALL_DECIMALS) * qta;
|
|
break;
|
|
case _valore:
|
|
importo = prezzo(scontato, doc_al_lordo ? TRUE : lordo, ndec);
|
|
break;
|
|
case _percentuale:
|
|
importo = r1 * get_real(RDOC_QTA) / CENTO;
|
|
break;
|
|
case _scontoimp:
|
|
importo = -prezzo(FALSE, doc_al_lordo ? TRUE : lordo, ndec);
|
|
break;
|
|
case _scontoperc:
|
|
importo = doc().basesconto() * (r1 - UNO);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
importo.round(ndec);
|
|
|
|
if (doc_al_lordo && !lordo)
|
|
iva().scorpora(importo, ndec);
|
|
|
|
return importo;
|
|
}
|
|
|
|
real TRiga_documento::iva(int ndec) const
|
|
{
|
|
real zanicchi;
|
|
if (!is_sconto())
|
|
{
|
|
if (ndec == AUTO_DECIMALS)
|
|
ndec = doc().decimals();
|
|
zanicchi = is_omaggio() ? iva_omaggio(ndec) : 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.not_empty())
|
|
{
|
|
real r;
|
|
if (is_omaggio() && _iva_calc_mode > 0)
|
|
{
|
|
TDocumento_variable_field * f = (TDocumento_variable_field *) variable_field(field);
|
|
CHECKS(f, "Field UNKNOWN : ", 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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
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_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 TString16 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).not_empty();
|
|
}
|
|
|
|
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())
|
|
{
|
|
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);
|
|
f.sheet_mask().reset(FR_LORDO);
|
|
}
|
|
put( RDOC_TIPORIGA, row.get( f.cid2index(FR_TIPORIGA )) );
|
|
TString16 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 TString16 codiva(row.get(f.cid2index(FR_CODIVA)));
|
|
if (lordo)
|
|
{
|
|
iva(codiva).scorpora(prezzo, doc().decimals(TRUE));
|
|
|
|
const TString prezzo_str(prezzo.string());
|
|
row.add(prezzo_str, prezzo_id);
|
|
f.sheet_mask().set(FR_PREZZO, prezzo_str);
|
|
}
|
|
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 )) );
|
|
TString16 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 )) );
|
|
put( RDOC_CODCMS, row.get( f.cid2index(FR_CODCMS)) );
|
|
put( RDOC_FASCMS, row.get( f.cid2index(FR_FASCMS)) );
|
|
}
|
|
}
|
|
|
|
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 TString16 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 ));
|
|
row.add( get( RDOC_PREZZO ), 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( get( RDOC_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 TString16 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));
|
|
row.add( get( RDOC_CODCMS) , f.cid2index(FR_CODCMS));
|
|
row.add( get( RDOC_FASCMS) , f.cid2index(FR_FASCMS));
|
|
}
|
|
|
|
TArticolo_giacenza * TRiga_documento::articolo() const
|
|
{
|
|
if (_articoli == NULL)
|
|
_articoli = new TCache_articoli();
|
|
|
|
const TString & codart = get(RDOC_CODARTMAG);
|
|
if (codart.empty())
|
|
return NULL;
|
|
return &(_articoli->art(codart));
|
|
}
|
|
|
|
void TRiga_documento::set_original_rdoc_key(const TRiga_documento& orig)
|
|
{
|
|
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));
|
|
}
|
|
|
|
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;
|
|
}
|