eaf1f1a1a0
git-svn-id: svn://10.65.10.50/branches/R_10_00@22913 c028cbd2-c16b-5b4b-a496-9718f37d4682
766 lines
23 KiB
C++
Executable File
766 lines
23 KiB
C++
Executable File
#include <config.h>
|
||
#include <diction.h>
|
||
#include <utility.h>
|
||
|
||
#include "velib.h"
|
||
|
||
#include "condv.h"
|
||
#include "rcondv.h"
|
||
#include "sconti.h"
|
||
|
||
#include "veconf.h"
|
||
#include "veini.h"
|
||
#include "verig.h"
|
||
#include "veuml.h"
|
||
|
||
#include "../mg/anamag.h"
|
||
#include "../pr/agenti.h"
|
||
#include "../pr/percprov.h"
|
||
|
||
bool TCond_vendita::set_sconto(const char* exp, bool signal)
|
||
{
|
||
bool valid = scontoexpr2perc(exp, signal, _sconto, _molt_sconto);
|
||
if (_load_mask && _riga && _riga->id2pos(FR_SCONTO) >= 0 && _riga->field(FR_SCONTO).active())
|
||
_riga->set(FR_SCONTO, _sconto);
|
||
return valid;
|
||
}
|
||
|
||
real TCond_vendita::normalize_valuta(const real & val, const char * val_rif)
|
||
{
|
||
if (val.is_zero())
|
||
return ZERO;
|
||
|
||
const TString& valuta = _testa->get(F_CODVAL);
|
||
if (same_values(val_rif, valuta))
|
||
return val;
|
||
|
||
const real cambio = _condv.get_real(CONDV_CAMBIO);
|
||
TPrice normalized(val, val_rif, cambio);
|
||
|
||
const real cambio_dest = _testa->get_real(F_CAMBIO);
|
||
normalized.change_value(valuta, cambio_dest);
|
||
|
||
return normalized.get_num();
|
||
}
|
||
|
||
void TCond_vendita::set_prezzo(const real & prezzo, const char * val_rif)
|
||
{
|
||
_prezzo = normalize_valuta(prezzo, val_rif);
|
||
|
||
if (_load_mask && _riga && _riga->id2pos(FR_PREZZO) >= 0)
|
||
_riga->set(FR_PREZZO, _prezzo);
|
||
}
|
||
|
||
void TCond_vendita::set_provv(const real & provv)
|
||
|
||
{
|
||
_provv = provv;
|
||
if (_load_mask && _riga && _riga->id2pos(FR_PERCPROV) >= 0 && _riga->field(FR_PERCPROV).active())
|
||
_riga->set(FR_PERCPROV, _provv);
|
||
}
|
||
|
||
void TCond_vendita::set_provv1(const real & provv)
|
||
|
||
{
|
||
_provv1 = provv;
|
||
if (_load_mask && _riga && _riga->id2pos(FR_PERCPROV1) >= 0 && _riga->field(FR_PERCPROV1).active())
|
||
_riga->set(FR_PERCPROV1, _provv1);
|
||
}
|
||
|
||
void TCond_vendita::set_iva(const TString & codiva)
|
||
|
||
{
|
||
_codiva = codiva;
|
||
if (_load_mask && _riga && _riga->id2pos(FR_CODIVA) >= 0 && _riga->field(FR_CODIVA).active())
|
||
_riga->set(FR_CODIVA, _codiva);
|
||
}
|
||
|
||
bool TCond_vendita::cerca( int tiporicerca )
|
||
{
|
||
TConfig config_ditta(CONFIG_DITTA, "ve");
|
||
if( config_ditta.get_bool( "GES", "ve", tiporicerca ) )
|
||
{
|
||
// Se h attiva la gestione contratti ...
|
||
_condv.setkey( 1 );
|
||
_condv.zero( );
|
||
switch( tiporicerca )
|
||
{
|
||
case A_CONTRATTI:
|
||
{
|
||
const TString16 codcont = testa().get(F_CODCONT);
|
||
if (codcont.blank())
|
||
return false;
|
||
_condv.put(CONDV_TIPO, "C");
|
||
if (config_ditta.get_bool("GESCONCC", "ve"))
|
||
{
|
||
_condv.put(CONDV_TIPOCF, clifo().tipo());
|
||
_condv.put(CONDV_CODCF, clifo().codice());
|
||
}
|
||
_condv.put(CONDV_COD, codcont);
|
||
}
|
||
break;
|
||
case A_LISTINI:
|
||
{
|
||
const TString16 codlist = testa().get(F_CODLIST);
|
||
if (codlist.blank())
|
||
return false;
|
||
_condv.put(CONDV_TIPO, "L");
|
||
// Se in ditta h abilitata la gestione della categoria di vendita in chiave
|
||
// al listino, la carico con gioia
|
||
if( config_ditta.get_bool("GESLISCV", "ve"))
|
||
_condv.put("CATVEN", testa().get(F_CATVEN));
|
||
_condv.put("COD", codlist);
|
||
}
|
||
break;
|
||
case A_OFFERTE:
|
||
{
|
||
const TString16 codcamp(testa().get(F_CODCAMP));
|
||
if (codcamp.blank())
|
||
return false;
|
||
_condv.put(CONDV_TIPO, "O");
|
||
_condv.put(CONDV_COD, codcamp);
|
||
}
|
||
break;
|
||
}
|
||
if( _condv.read( ) == NOERR )
|
||
{
|
||
// _rcondv.setkey( 2 );
|
||
|
||
const bool gest_scagl = _condv.get_bool(CONDV_GESTSCAGL);
|
||
const TString16 seqricrighe( _condv.get(CONDV_SEQRIC));
|
||
bool found = FALSE;
|
||
|
||
|
||
for( int i = 0; !found && i < seqricrighe.len( ); i ++ )
|
||
{
|
||
_rcondv.zero( );
|
||
_rcondv.put( "TIPO", _condv.get( "TIPO"));
|
||
_rcondv.put( "CATVEN", _condv.get( "CATVEN"));
|
||
_rcondv.put( "TIPOCF", _condv.get( "TIPOCF"));
|
||
_rcondv.put( "CODCF", _condv.get( "CODCF"));
|
||
_rcondv.put("COD", _condv.get("COD"));
|
||
if( _condv.get_bool( "GESTUM" ) )
|
||
_rcondv.put( "UM", riga().get(FR_UMQTA));
|
||
if (gest_scagl)
|
||
_rcondv.put("NSCAGL", 1);
|
||
|
||
char ricerca = seqricrighe[ i ];
|
||
_rcondv.put( "TIPORIGA", ricerca );
|
||
switch( ricerca )
|
||
{
|
||
case 'A':
|
||
{
|
||
const TString codriga = riga().get(FR_CODARTMAG);
|
||
|
||
_rcondv.put( "CODRIGA", codriga);
|
||
if (_rcondv.read() != NOERR &&
|
||
_rcondv.prev() == NOERR &&
|
||
_rcondv.get("TIPORIGA")[0] == 'A')
|
||
{
|
||
const TString cod_found(_rcondv.get("CODRIGA"));
|
||
|
||
return cod_found == codriga;
|
||
}
|
||
}
|
||
break;
|
||
case 'R':
|
||
_rcondv.put("CODRIGA", _anamag.get( "RAGGFIS"));
|
||
_rcondv.read();
|
||
break;
|
||
case 'S':
|
||
{
|
||
_rcondv.put( "CODRIGA", _anamag.get("GRMERC"));
|
||
_rcondv.read( );
|
||
}
|
||
break;
|
||
case 'G':
|
||
{
|
||
_rcondv.put( "CODRIGA", _anamag.get("GRMERC").left(3));
|
||
_rcondv.read( );
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
found = _rcondv.good();
|
||
}
|
||
if (found && gest_scagl)
|
||
{
|
||
TRectype rec(_rcondv.curr());
|
||
int last_scagl = 0;
|
||
int scagl = _rcondv.get_int("NSCAGL");
|
||
const real qta(_riga->get_real(FR_QTA));
|
||
real qta_lim(_rcondv.get_real("QLIM"));
|
||
|
||
while (_rcondv.good() && scagl > last_scagl && qta_lim > ZERO && qta > qta_lim)
|
||
{
|
||
if (_rcondv.next() == NOERR)
|
||
{
|
||
last_scagl = scagl;
|
||
scagl = _rcondv.get_int("NSCAGL");
|
||
qta_lim =_rcondv.get_real("QLIM");
|
||
rec = _rcondv.curr();
|
||
}
|
||
}
|
||
_rcondv.read(rec);
|
||
}
|
||
|
||
return found;
|
||
}
|
||
}
|
||
// Ricerca fallita
|
||
return FALSE;
|
||
}
|
||
|
||
real TCond_vendita::get_percprovv(char tipoprovv, const TString & codpr, bool first, const TRectype & age) const
|
||
{
|
||
real val = ZERO;
|
||
|
||
switch (tipoprovv)
|
||
{
|
||
case 'A':
|
||
val = age.get_real(AGE_PERCPROVV);
|
||
break;
|
||
case 'M':
|
||
val = _anamag.get_real(ANAMAG_PERCPROVV);
|
||
break;
|
||
case 'C':
|
||
val = clifo().vendite().get_real(first ? CFV_PERCPROVV : CFV_PERCPROVV1);
|
||
break;
|
||
case 'V':
|
||
{
|
||
const TString16 catven = testa().get(F_CATVEN);
|
||
if (catven.not_empty())
|
||
val = real(cache().get("CVE", catven, "R0"));
|
||
}
|
||
break;
|
||
case 'O':
|
||
val = _rcondv.get_real("PERCPROVV");
|
||
break;
|
||
case '1':
|
||
case '2':
|
||
case '3':
|
||
case '4':
|
||
{
|
||
const TString16 ord = cache().get("APR", codpr, "S3");
|
||
|
||
int len = ord.len();
|
||
TString key;
|
||
TString80 campo;
|
||
|
||
for (int i = 0; i < len; i++)
|
||
{
|
||
switch (ord[i])
|
||
{
|
||
case 'C':
|
||
campo = clifo().get(CLI_CODCF);
|
||
campo.lpad(clifo().length(CLI_CODCF));
|
||
break;
|
||
case 'V':
|
||
campo = testa().get(F_CATVEN);
|
||
campo.rpad(testa().field(F_CATVEN).size());
|
||
break;
|
||
case 'A':
|
||
campo = testa().get(F_CODAG);
|
||
campo.rpad(testa().field(F_CODAG).size());
|
||
break;
|
||
case 'P':
|
||
campo = testa().get(F_CODPAG);
|
||
campo.rpad(testa().field(F_CODPAG).size());
|
||
break;
|
||
case 'S':
|
||
campo = clifo().vendite().get(CFV_CODSCC);
|
||
campo.rpad(clifo().length(CFV_CODSCC));
|
||
break;
|
||
case 'Z':
|
||
campo = testa().get(F_CODZON);
|
||
campo.rpad(testa().field(F_CODZON).size());
|
||
break;
|
||
case 'M':
|
||
campo = riga().get( FR_CODARTMAG );
|
||
campo.rpad(riga().field(FR_CODARTMAG).size());
|
||
break;
|
||
case 'E':
|
||
campo = _anamag.get(ANAMAG_GRMERC);
|
||
campo.rpad(_anamag.curr().length(ANAMAG_GRMERC));
|
||
campo.cut(3);
|
||
break;
|
||
case 'R':
|
||
campo = _anamag.get(ANAMAG_GRMERC);
|
||
campo.rpad(_anamag.curr().length(ANAMAG_GRMERC));
|
||
break;
|
||
case 'F':
|
||
campo = _anamag.get(ANAMAG_RAGGFIS);
|
||
campo.rpad(_anamag.curr().length(ANAMAG_RAGGFIS));
|
||
break;
|
||
default:
|
||
campo.cut(0);
|
||
break;
|
||
|
||
}
|
||
key << campo;
|
||
}
|
||
|
||
TLocalisamfile perc(LF_PERCPROV);
|
||
|
||
perc.put(PER_CODPR, codpr);
|
||
perc.put(PER_KEYORD, key);
|
||
if (perc.read() == NOERR)
|
||
val= perc.get_real(PER_PERCPROVV);
|
||
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return val;
|
||
}
|
||
|
||
bool TCond_vendita::try_sconto(char gestione, bool found_condv, bool load_um_only, bool load_scagl_only)
|
||
{
|
||
TString80 sconto;
|
||
|
||
switch (gestione)
|
||
{
|
||
case 'L':
|
||
// Percentuale su contratti/offerte/listini/anagrafica
|
||
if (found_condv)
|
||
{
|
||
const bool cv_scagl = _condv.get_bool("GESTSCAGL");
|
||
const bool cv_um = _condv.get_bool("GESTUM");
|
||
|
||
_load_mask |= load_scagl_only && cv_scagl;
|
||
_load_mask |= load_um_only && cv_um;
|
||
sconto = _rcondv.get("SCONTO");
|
||
_load_mask = !load_um_only && !load_scagl_only;
|
||
}
|
||
else
|
||
sconto = _anamag.get("SCONTO");
|
||
break;
|
||
case 'A':
|
||
{
|
||
TConfig config_ditta(CONFIG_DITTA, "ve");
|
||
const bool sco_scagl = config_ditta.get_bool("GESSCOSCA");
|
||
const bool sco_um_gest = config_ditta.get_bool("GESSCORIGAUM");
|
||
const char rigakey = config_ditta.get_char( "SCORIGAKEY");
|
||
|
||
// Posiziono l'anagrafica
|
||
_sconti.setkey(1);
|
||
_sconti.put("TIPO", "R");
|
||
if( config_ditta.get_bool("GESSCORIGACV"))
|
||
_sconti.put("CODCAT", testa().get(F_CATVEN));
|
||
if (sco_um_gest)
|
||
_sconti.put("UM", riga().get( FR_UMQTA));
|
||
_sconti.put("TIPORIGA", rigakey);
|
||
|
||
if (sco_scagl)
|
||
_sconti.put("NSCAGL", 1);
|
||
|
||
switch (rigakey)
|
||
{
|
||
case 'A':
|
||
{
|
||
const TString& codriga = riga().get(FR_CODARTMAG);
|
||
_sconti.put("CODART", codriga);
|
||
_sconti.read();
|
||
}
|
||
break;
|
||
case 'R':
|
||
_sconti.put("CODART", _anamag.get("RAGGFIS"));
|
||
_sconti.read();
|
||
break;
|
||
case 'C':
|
||
{
|
||
_sconti.put( "CODART", _anamag.get("GRMERC"));
|
||
_sconti.read( );
|
||
}
|
||
break;
|
||
case 'L':
|
||
{
|
||
_sconti.put("CODART", _anamag.get("GRMERC").left(3));
|
||
_sconti.read();
|
||
}
|
||
break;
|
||
default:
|
||
{
|
||
const TString& codriga = riga().get(FR_CODARTMAG);
|
||
_sconti.put("CODART", codriga);
|
||
_sconti.read();
|
||
}
|
||
break;
|
||
}
|
||
|
||
const bool found = _sconti.good();
|
||
if (found && sco_scagl)
|
||
{
|
||
TRectype rec(_sconti.curr());
|
||
int last_scagl = 0;
|
||
int scagl = _sconti.get_int("NSCAGL");
|
||
const real qta(_riga->get_real(FR_QTA));
|
||
real qta_lim(_sconti.get_real("QLIM"));
|
||
|
||
while (_sconti.good() && scagl > last_scagl && qta_lim > ZERO && qta > qta_lim)
|
||
{
|
||
if (_sconti.next() == NOERR)
|
||
{
|
||
last_scagl = scagl;
|
||
scagl = _sconti.get_int("NSCAGL");
|
||
qta_lim =_sconti.get_real("QLIM");
|
||
rec = _sconti.curr();
|
||
}
|
||
}
|
||
_rcondv.read(rec);
|
||
}
|
||
if (!found)
|
||
_sconti.zero();
|
||
_load_mask |= load_scagl_only && sco_scagl;
|
||
_load_mask |= load_scagl_only && sco_um_gest;
|
||
sconto = _sconti.get("SCONTO");
|
||
_load_mask = !load_um_only && !load_scagl_only;
|
||
}
|
||
break;
|
||
case 'C':
|
||
sconto = clifo().vendite().get(CFV_SCONTO);
|
||
break;
|
||
default:
|
||
sconto.cut(0);
|
||
break;
|
||
}
|
||
|
||
return set_sconto(sconto) && sconto.full();
|
||
}
|
||
|
||
|
||
void TCond_vendita::ricerca(bool load_um_only, bool load_scagl_only)
|
||
{
|
||
const TString80 codriga = riga().get( FR_CODARTMAG );
|
||
const bool doc_al_lordo = testa().doc().tipo().calcolo_lordo();
|
||
|
||
_ivarid = clifo().vendite().get_bool(CFV_IVARID);
|
||
_load_mask = !load_um_only && !load_scagl_only;
|
||
|
||
_anamag.setkey(1);
|
||
_anamag.put("CODART", codriga);
|
||
if (codriga.empty() || _anamag.read() != NOERR)
|
||
{
|
||
set_prezzo(ZERO);
|
||
set_sconto("");
|
||
set_iva("");
|
||
set_provv(ZERO);
|
||
_prov.cut(0);
|
||
return;
|
||
}
|
||
|
||
real prezzo;
|
||
bool found_prezzo = false;
|
||
const TArticolo_giacenza & art = cached_article_balances(codriga);
|
||
const TTipo_riga_documento tiporiga(riga().get(FR_TIPORIGA));;
|
||
|
||
if (tiporiga.tipo() == RIGA_OMAGGI)
|
||
{
|
||
const int annoes = esercizi().date2esc(testa().get_date(F_DATADOC));
|
||
const TString4 codmag = riga().get(FR_CODMAG);
|
||
const TString80 livello = riga().get(MAG_LIVELLO);
|
||
|
||
found_prezzo = true;
|
||
|
||
const TTipo_valorizz tvo = TTipo_valorizz(ini_get_int(CONFIG_DITTA, "ve", "PriceOmaggi") - 1);
|
||
switch (tvo)
|
||
{
|
||
case valorizz_ultcos:
|
||
prezzo = art.ultimo_costo(annoes);
|
||
break;
|
||
case valorizz_mediacos:
|
||
prezzo = art.media_costi(annoes);
|
||
break;
|
||
case valorizz_przlist:
|
||
{
|
||
const TString catven = testa().get(F_CATVEN);
|
||
const TString codlist = testa().get(F_CODLIST);
|
||
prezzo = CENTO / (CENTO + art.get_real(ANAMAG_PERCRIC)) * art.prezzo_listino(annoes, catven, codlist);
|
||
}
|
||
break;
|
||
case valorizz_coststd:
|
||
prezzo = art.costo_standard(annoes);
|
||
break;
|
||
case valorizz_costmediopond:
|
||
prezzo = art.costo_mediopond(annoes,codmag,livello);
|
||
break;
|
||
case valorizz_costmedio:
|
||
prezzo = art.costo_medio(annoes,codmag,livello);
|
||
break;
|
||
case valorizz_LIFO:
|
||
prezzo = art.LIFO(annoes,codmag,livello, false);
|
||
break;
|
||
case valorizz_FIFO:
|
||
prezzo = art.FIFO(annoes,codmag,livello, false);
|
||
break;
|
||
case valorizz_LIFOa:
|
||
prezzo = art.LIFO_annuale(annoes,codmag,livello, false);
|
||
break;
|
||
case valorizz_FIFOa:
|
||
prezzo = art.FIFO_annuale(annoes,codmag,livello, false);
|
||
break;
|
||
default :
|
||
found_prezzo = false;
|
||
break;
|
||
}
|
||
}
|
||
|
||
const TString4 umriga(riga().get(FR_UMQTA));
|
||
if (umriga.full())
|
||
{
|
||
_umart.setkey(2);
|
||
_umart.put("CODART", codriga);
|
||
_umart.put("UM", umriga);
|
||
if (_umart.read() != NOERR)
|
||
_umart.zero();
|
||
}
|
||
|
||
bool prezzo_lordo = false;
|
||
TString4 valuta;
|
||
bool found_condv = false;
|
||
const bool cv_scagl = _condv.get_bool("GESTSCAGL");
|
||
const bool cv_um = _condv.get_bool("GESTUM");
|
||
|
||
if (!found_prezzo)
|
||
{
|
||
found_condv = cerca(A_CONTRATTI) || cerca(A_OFFERTE) || cerca(A_LISTINI);
|
||
if (found_condv)
|
||
{
|
||
_load_mask |= load_scagl_only && cv_scagl;
|
||
_load_mask |= load_um_only && cv_um;
|
||
|
||
prezzo = _rcondv.get_real("PREZZO");
|
||
valuta = _condv.get("CODVAL");
|
||
prezzo_lordo = _condv.get_bool("IMPLORDI");
|
||
_prov = _condv.get(CONDV_TIPO);
|
||
}
|
||
else
|
||
{
|
||
TString16 field_prezzo = testa().doc().tipo().field_prezzo();
|
||
if (field_prezzo.blank())
|
||
prezzo = _umart.get_real("PREZZO");
|
||
else
|
||
prezzo = _anamag.get_real(field_prezzo);
|
||
_load_mask |= load_um_only;
|
||
_prov = "A";
|
||
}
|
||
}
|
||
|
||
if (doc_al_lordo)
|
||
{
|
||
if (!prezzo_lordo)
|
||
{
|
||
const TCodiceIVA iva(_anamag.get("CODIVA"));
|
||
prezzo = iva.lordo(prezzo, AUTO_PRICES_DECIMALS, valuta);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (prezzo_lordo)
|
||
{
|
||
const TCodiceIVA iva(_anamag.get("CODIVA"));
|
||
iva.scorpora(prezzo, AUTO_PRICES_DECIMALS, valuta);
|
||
}
|
||
}
|
||
|
||
set_prezzo(prezzo, valuta);
|
||
set_iva(_anamag.get(_ivarid ? ANAMAG_CODIVAR : ANAMAG_CODIVA));
|
||
|
||
// Gestione sconti di riga
|
||
const char gestione1 = ini_get_string(CONFIG_DITTA, "ve", "GESSCORIGA")[0];
|
||
if (!try_sconto(gestione1, found_condv, load_um_only, load_scagl_only) && gestione1 > ' ')
|
||
{
|
||
const char gestione2 = ini_get_string(CONFIG_DITTA, "ve", "GESSCORIGA2")[0];
|
||
if (gestione2 != gestione1 && (gestione2 == 'A' || gestione2 == 'C' || gestione2 == 'L'))
|
||
try_sconto(gestione2, found_condv, load_um_only, load_scagl_only);
|
||
}
|
||
|
||
if (_riga && _riga->id2pos(FR_PERCPROV) >= 0 && _riga->field(FR_PERCPROV).active())
|
||
{
|
||
const TString& codage = _testa->get(F_CODAG);
|
||
if (codage.full())
|
||
{
|
||
const TRectype& age = cache().get(LF_AGENTI, codage);
|
||
if (!age.empty())
|
||
{
|
||
TString16 seqric(age.get(AGE_SEQRIC));
|
||
real percprovv;
|
||
|
||
if (seqric[0] == '-')
|
||
seqric = ini_get_string(CONFIG_DITTA, "ve", "AGETIPOPERC");
|
||
|
||
int len = seqric.len();
|
||
int i;
|
||
|
||
_load_mask |= load_scagl_only && cv_scagl;
|
||
_load_mask |= load_scagl_only && cv_um;
|
||
for (i = 0; percprovv.is_zero() && seqric[i] != '\0' && seqric[i] != '-'; i++)
|
||
{
|
||
TString16 codric;
|
||
if (isdigit(seqric[i]))
|
||
codric = age.get(format("CODRICPR%d", i+1));
|
||
percprovv = get_percprovv(seqric[i], codric, true, age);
|
||
}
|
||
real percalt;
|
||
seqric = age.get(AGE_SEQALT);
|
||
for (i = 0; percalt.is_zero() && seqric[i] != '\0' && seqric[i] != '-'; i++)
|
||
{
|
||
TString16 codric;
|
||
if (isdigit(seqric[i]))
|
||
codric = age.get(format("CODALTPR%d", i+1));
|
||
percalt = get_percprovv(seqric[i], codric, true, age);
|
||
}
|
||
percprovv += percalt;
|
||
set_provv(percprovv);
|
||
}
|
||
}
|
||
}
|
||
if (_riga && _riga->id2pos(FR_PERCPROV1) >= 0 && _riga->field(FR_PERCPROV1).active())
|
||
{
|
||
const TString & codage = _testa->get(F_CODAGVIS);
|
||
|
||
if (codage.full())
|
||
{
|
||
const TRectype & age = cache().get(LF_AGENTI, codage);
|
||
|
||
if (!age.empty())
|
||
{
|
||
TString16 seqric = age.get(AGE_SEQRIC);
|
||
if (seqric[0] == '-')
|
||
seqric = ini_get_string(CONFIG_DITTA, "ve", "AGETIPOPERC");
|
||
|
||
|
||
_load_mask |= load_scagl_only && cv_scagl;
|
||
_load_mask |= load_scagl_only && cv_um;
|
||
|
||
real percprovv;
|
||
for (int i = 0; percprovv.is_zero() && seqric[i] != '\0' && seqric[i] != '-'; i++)
|
||
{
|
||
TString16 codric;
|
||
if (isdigit(seqric[i]))
|
||
codric = age.get(format("CODRICPR%d", i+1));
|
||
percprovv = get_percprovv(seqric[i], codric, false, age);
|
||
}
|
||
|
||
real percalt;
|
||
seqric = age.get(AGE_SEQALT);
|
||
for (int i = 0; percalt.is_zero() && seqric[i] != '\0' && seqric[i] != '-'; i++)
|
||
{
|
||
TString16 codric;
|
||
if (isdigit(seqric[i]))
|
||
codric = age.get(format("CODALTPR%d", i+1));
|
||
percalt = get_percprovv(seqric[i], codric, false, age);
|
||
}
|
||
percprovv += percalt;
|
||
set_provv1(percprovv);
|
||
}
|
||
}
|
||
}
|
||
if (found_condv && _testa->is_running())
|
||
update_omaggi(load_scagl_only);
|
||
}
|
||
|
||
void TCond_vendita::update_omaggi(bool full)
|
||
{
|
||
static TString16 tipo_riga("_");
|
||
TSheet_field & sh = (TSheet_field &) testa().field(F_SHEET);
|
||
int current_doc_row = sh.selected() + 1;
|
||
TDocumento & doc = testa().doc();
|
||
|
||
if (doc[current_doc_row].is_omaggio())
|
||
return;
|
||
|
||
if (current_doc_row < doc.rows())
|
||
{
|
||
TRiga_documento & r = doc[current_doc_row + 1];
|
||
|
||
if (r.is_omaggio() && r.is_generata())
|
||
{
|
||
sh.update_row(current_doc_row - 1);
|
||
doc.destroy_row(current_doc_row + 1, true);
|
||
sh.destroy(current_doc_row, true);
|
||
}
|
||
}
|
||
|
||
real qta = _riga->get(FR_QTA);
|
||
bool creata = FALSE;
|
||
|
||
if (full || qta != ZERO)
|
||
{
|
||
const TString80 codart_omaggio(_rcondv.get(RCONDV_CODARTOM));
|
||
if (tipo_riga[0] == '_')
|
||
{
|
||
TConfig cnf(CONFIG_STUDIO, "ve");
|
||
tipo_riga = cnf.get("TROMAGGI");
|
||
if (tipo_riga.empty())
|
||
{
|
||
tipo_riga = "09";
|
||
cnf.set("TROMAGGI", tipo_riga);
|
||
warning_box(FR("Il tipo riga omaggi non risultava impostato.\nL'applicazione user<65> automaticamente il tipo %s"),
|
||
(const char*) tipo_riga);
|
||
}
|
||
}
|
||
const real qbase = _rcondv.get_real("QBASE");
|
||
if (qbase.is_zero())
|
||
qta = ZERO;
|
||
else
|
||
{
|
||
qta /= _rcondv.get_real(RCONDV_QBASE);
|
||
qta.floor();
|
||
qta *= _rcondv.get_real(RCONDV_QOM);
|
||
}
|
||
creata = codart_omaggio.not_empty() && tipo_riga.not_empty() && !qta.is_zero();
|
||
|
||
if (creata)
|
||
{
|
||
TRiga_documento & curr_row = doc[current_doc_row];
|
||
TToken_string & rw = sh.row(current_doc_row - 1);
|
||
|
||
sh.update_row(current_doc_row - 1);
|
||
curr_row.autosave(sh);
|
||
|
||
TRiga_documento & r = doc.insert_row(current_doc_row + 1, tipo_riga);
|
||
|
||
r.generata();
|
||
TString8 codmag(_riga->get(FR_CODMAG)); codmag << _riga->get(FR_CODDEP);
|
||
r.put(RDOC_CODMAG, codmag);
|
||
r.put(RDOC_CODART, codart_omaggio);
|
||
r.put(RDOC_UMQTA, _rcondv.get(RCONDV_UMOM));
|
||
r.put(RDOC_QTA, qta);
|
||
real prezzo(_rcondv.get(RCONDV_PROMAGGIO));
|
||
const TString4 codval(_condv.get(CONDV_CODVAL));
|
||
const TString4 codiva_cli(doc.codesiva());
|
||
if (codiva_cli.not_empty())
|
||
r.put(RDOC_CODIVA, codiva_cli);
|
||
else
|
||
r.put(RDOC_CODIVA, _rcondv.get(RCONDV_CODIVA));
|
||
r.put(RDOC_ADDIVA, _rcondv.get(RCONDV_ADDIVA));
|
||
sh.insert(current_doc_row, false);
|
||
r.autoload(sh);
|
||
sh.check_row(current_doc_row);
|
||
r.autosave(sh);
|
||
|
||
prezzo = normalize_valuta(prezzo, codval);
|
||
r.put(RDOC_PREZZO, prezzo);
|
||
r.autoload(sh);
|
||
if (!testa().is_omaggio_enabled())
|
||
{
|
||
sh.disable_row(current_doc_row);
|
||
sh.check_row(current_doc_row);
|
||
}
|
||
sh.force_update();
|
||
}
|
||
}
|
||
}
|
||
|
||
TCond_vendita::TCond_vendita(TDocumento_mask * testa, TMask * riga)
|
||
: _testa(testa), _riga(riga),
|
||
_condv( LF_CONDV ), _rcondv( LF_RCONDV ), _sconti( LF_SCONTI ),
|
||
_anamag(LF_ANAMAG), _umart(LF_UMART),
|
||
_ivarid(FALSE), _load_mask(FALSE)
|
||
{
|
||
}
|
||
|