Patch level : 12.0 928

Files correlati     : ve0.exe ve1.exe ve5.exe ve6.exe
Commento            :

- Aggiunte funzioni sulle righe documento :

  QTACONAI(<categoria> [ <tipo calcolo (0=netto, 1=esente, 2=lordo)])
  VALCONAI(<categoria> [ <tipo calcolo (0=netto, 1=esente, 2=lordo)])
This commit is contained in:
Alessandro Bonazzi 2020-01-20 21:58:04 +01:00
parent cc4f21f1a1
commit bfee727eec
2 changed files with 117 additions and 4 deletions

View File

@ -614,7 +614,11 @@ int TExpr_documento::parse_user_func(const char * name, int nparms) const
return nparms == 2 ? _comp_qta : -1;
if (strcmp(name, "NRATE") == 0)
return nparms == 0 ? _nrate : -1;
return -1;
if (strcmp(name, "QTACONAI") == 0)
return nparms >= 1 && nparms < 3 ? _qtaconai : -1;
if (strcmp(name, "VALCONAI") == 0)
return nparms >= 1 && nparms < 3 ? _valconai : -1;
return -1;
}
void TExpr_documento::evaluate_user_func(int index, int nparms, TEval_stack & stack, TTypeexp type) const
@ -1062,7 +1066,111 @@ void TExpr_documento::evaluate_user_func(int index, int nparms, TEval_stack & st
default:
TExpression::evaluate_user_func(index, nparms, stack, type);
break;
}
case _qtaconai:
{
int sp = stack.count();
int tipo_calcolo = (nparms > 1) ? (int)stack.pop_real().integer() : 0;
TString cat = stack.pop_string();
if (stack.count() >= sp - 2)
stack.push(ZERO);
real & val = stack.peek_real();
if (_row->get_int(RDOC_NRIGA) == 9)
int i = 1;
if (_row && (_row->tipo().tipo() == RIGA_MERCE || _row->tipo().tipo() == RIGA_OMAGGI))
{
for (int i = 1; i <= FR_CMAX; i++)
{
const TString8 sottocat = _row->get(conai_sottocat_name(i));
if (sottocat.full() && sottocat.starts_with(cat))
{
const real peso = _row->get_real(conai_peso_name(i));
val += (peso * _row->get_real(RDOC_QTA));
}
}
if (tipo_calcolo < 2 && cat.full())
{
real perc_esenz;
const TDate datadoc = _doc->get(DOC_DATADOC);
const TRectype& cfven = _doc->clifor().vendite();
const TDate dataies = cfven.get(CFV_DATAICONAI);
const TDate dataees = cfven.get(CFV_DATAECONAI);
if ((datadoc >= dataies) && ((!dataees.ok()) || (datadoc <= dataees)))
perc_esenz = cfven.get_real(get_cf_esenz(cat.left(2)));
if (tipo_calcolo == 0)
val *= ((CENTO - perc_esenz) / CENTO);
else
val *= (perc_esenz / CENTO);
}
val.round(5);
}
else
val = ZERO;
}
break;
case _valconai:
{
int sp = stack.count();
int tipo_calcolo = (nparms > 1) ? (int)stack.pop_real().integer() : 0;
TString cat = stack.pop_string();
TString_array sottocat_found;
if (stack.count() >= sp - 2)
stack.push(ZERO);
real & val = stack.peek_real();
if (_row && (_row->tipo().tipo() == RIGA_MERCE || _row->tipo().tipo() == RIGA_OMAGGI))
{
for (int i = 1; i <= FR_CMAX; i++)
{
const TString8 sottocat = _row->get(conai_sottocat_name(i));
if (sottocat.full() && sottocat_found.find(sottocat) < 0)
{
sottocat_found.add(sottocat);
stack.push(sottocat);
stack.push(tipo_calcolo);
evaluate_user_func(_qtaconai, 2, stack, type);
real valqta = stack.pop_real();
if (_doc)
{
int rows = _doc->physical_rows();
const TRectype & scc = cache().get("&VESCC", sottocat);
TString conai_codart(scc.get("S1"));
for (int i = rows; i >= 1; i--)
{
const TRiga_documento& rdoc = (*_doc)[i];
//c'è la riga generata con codart di tipo conai (sia automatica che manuale)?
if (rdoc.get(RDOC_CODART) == conai_codart && (rdoc.is_spese() || rdoc.is_generata()))
{
const real prezzo = rdoc.get_real(RDOC_PREZZO);
val = valqta * prezzo;
val.round(5);
break;
}
}
}
else
val = ZERO;
}
}
}
}
break;
}
}
TObject* TExpr_documento::dup() const

View File

@ -1,9 +1,11 @@
#ifndef __VEPRIV_H
#define __VEPRIV_H
enum _formule {_somma, _bolli, _bolli_int, _spinc, _prezzo, _importo, _imponibile, _sconto, _iva,
enum _formule {
_somma, _bolli, _bolli_int, _spinc, _prezzo, _importo, _imponibile, _sconto, _iva,
_provv, _qtares, _valdoc, _tipo, _imponibili, _imposte, _totprovv, _pscontot, _ritenuta,
_tipo_ritenuta, _quant, _quantevasa, _componente, _comp_qta, _nrate};
_tipo_ritenuta, _quant, _quantevasa, _componente, _comp_qta, _nrate, _qtaconai, _valconai
};
enum TTipo_calcolo { _nessun_calcolo, _qtaprezzo, _valore, _percentuale, _scontopi};
void row_set_handler( TMask& m, const int field, const int index, TTipo_riga_documento & t, const TString & tipodoc );
@ -52,6 +54,9 @@ bool is_tipodoc_ok(const TString & tipodoc);
short conai_peso_id(int cc);
short conai_sottocat_id(int cc);
const char* get_cf_esenz(const TString& tipo_conai);
#endif