Files correlati : Ricompilazione Demo : [ ] Commento : Riportate le modifiche dalla versione 2.1 222 Si puo cominciare a fare il primo CD git-svn-id: svn://10.65.10.50/trunk@12708 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			707 lines
		
	
	
		
			20 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			707 lines
		
	
	
		
			20 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <config.h>
 | 
						|
#include <tabutil.h>
 | 
						|
 | 
						|
#include "sconti.h"
 | 
						|
 | 
						|
#ifndef __VEUML_H
 | 
						|
#include "veuml.h"
 | 
						|
#endif             
 | 
						|
 | 
						|
#ifndef __VERIG_H
 | 
						|
#include "verig.h"
 | 
						|
#endif             
 | 
						|
 | 
						|
#ifndef __VECONF_H
 | 
						|
#include "veconf.h"
 | 
						|
#endif
 | 
						|
 | 
						|
#ifndef __TABUTIL_H
 | 
						|
#include <tabutil.h>
 | 
						|
#endif               
 | 
						|
 | 
						|
#ifndef __ANAMAG_H
 | 
						|
#include "../mg/anamag.h"
 | 
						|
#endif
 | 
						|
 | 
						|
#ifndef __VEINI_H
 | 
						|
#include "veini.h"
 | 
						|
#endif
 | 
						|
 | 
						|
#ifndef __VELIB_H
 | 
						|
#include "velib.h"
 | 
						|
#endif
 | 
						|
 | 
						|
#ifndef __AGE_H
 | 
						|
#include "../pr/agenti.h"
 | 
						|
#endif
 | 
						|
 | 
						|
#ifndef __PER_H
 | 
						|
#include "../pr/percprov.h"
 | 
						|
#endif
 | 
						|
 | 
						|
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 == ZERO)
 | 
						|
    return ZERO;                
 | 
						|
//  const TString16 firm_val(TCurrency::get_firm_val());
 | 
						|
  TString16 valuta_rif(val_rif);                      
 | 
						|
  if (is_firm_value(valuta_rif))
 | 
						|
    valuta_rif.cut(0);
 | 
						|
  TString16 valuta(_testa->get(F_CODVAL));
 | 
						|
  if (is_firm_value(valuta))
 | 
						|
    valuta.cut(0);
 | 
						|
  if (valuta == valuta_rif)
 | 
						|
    return val;  
 | 
						|
    
 | 
						|
  const real cambio = _condv.get_real("CAMBIO");
 | 
						|
  const exchange_type controeuro = _condv.get_bool("CONTROEURO") ? _exchange_contro : _exchange_base;
 | 
						|
  TPrice normalized(val, valuta_rif, cambio, controeuro);                                  
 | 
						|
  const real cambio_dest = _testa->get_real(F_CAMBIO);
 | 
						|
  const exchange_type controeuro_dest = _testa->get_bool(F_CONTROEURO) ? _exchange_contro : _exchange_base;
 | 
						|
  
 | 
						|
  normalized.change_value(valuta, cambio_dest, controeuro_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->field(FR_PREZZO).active())
 | 
						|
    _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_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.empty())
 | 
						|
          return FALSE;
 | 
						|
        _condv.put("TIPO", "C");
 | 
						|
        if(config_ditta.get_bool("GESCONCC", "ve"))
 | 
						|
        {
 | 
						|
          _condv.put("TIPOCF", clifo().tipo());
 | 
						|
          _condv.put("CODCF", clifo().codice());  
 | 
						|
         }
 | 
						|
        _condv.put("COD", codcont);  
 | 
						|
      }
 | 
						|
      break;
 | 
						|
      case A_LISTINI:                                    
 | 
						|
        {
 | 
						|
          const TString16 codlist(testa().get(F_CODLIST));
 | 
						|
          
 | 
						|
          if (codlist.empty())
 | 
						|
            return FALSE;
 | 
						|
          _condv.put("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.empty())
 | 
						|
            return FALSE;
 | 
						|
          _condv.put("TIPO", "O");
 | 
						|
          _condv.put("COD", codcamp);
 | 
						|
        }
 | 
						|
        break;
 | 
						|
    }
 | 
						|
    if( _condv.read( ) == NOERR )
 | 
						|
    { 
 | 
						|
//      _rcondv.setkey( 2 );
 | 
						|
        
 | 
						|
      const bool gest_scagl = _condv.get_bool("GESTSCAGL");
 | 
						|
      const TString16 seqricrighe( _condv.get( "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.compare(codriga, cod_found.len()) == 0;
 | 
						|
              }
 | 
						|
            }
 | 
						|
            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, TLocalisamfile & 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(CFV_PERCPROVV);
 | 
						|
      break;                                              
 | 
						|
    case 'V':
 | 
						|
      {
 | 
						|
        TString16 catven(testa().get(F_CATVEN));
 | 
						|
                    
 | 
						|
        if (catven.not_empty())
 | 
						|
        {  
 | 
						|
          TTable cve("CVE");
 | 
						|
                        
 | 
						|
          cve.put("CODTAB", catven);
 | 
						|
          if (cve.read() == NOERR)
 | 
						|
            val = cve.get_real("R0");
 | 
						|
        }
 | 
						|
      }
 | 
						|
      break;
 | 
						|
    case 'O':
 | 
						|
      val = _rcondv.get_real("PERCPROVV");
 | 
						|
      break;
 | 
						|
    case '1':                    
 | 
						|
    case '2':                    
 | 
						|
    case '3':                    
 | 
						|
    case '4':                    
 | 
						|
      {
 | 
						|
        TTable apr("APR");
 | 
						|
        TString16 ord;
 | 
						|
 | 
						|
        apr.put("CODTAB",codpr);
 | 
						|
        if (apr.read() == NOERR)
 | 
						|
          ord = apr.get("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;
 | 
						|
}
 | 
						|
 | 
						|
void TCond_vendita::ricerca(bool load_um_only, bool load_scagl_only)
 | 
						|
{
 | 
						|
  const TString80 codriga = riga().get( FR_CODARTMAG );
 | 
						|
	const bool prezzo_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);
 | 
						|
    if (!load_um_only && !load_scagl_only && prezzo_lordo)
 | 
						|
      riga().set(FR_LORDO, "X");
 | 
						|
    return;
 | 
						|
  }            
 | 
						|
  
 | 
						|
  const TString16 umriga(riga().get(FR_UMQTA));
 | 
						|
  if (umriga.not_empty())
 | 
						|
  { 
 | 
						|
    _umart.setkey(2);
 | 
						|
    _umart.put("CODART", codriga);
 | 
						|
    _umart.put("UM", umriga);
 | 
						|
    if (_umart.read() != NOERR)
 | 
						|
      _umart.zero();
 | 
						|
  }                                  
 | 
						|
 | 
						|
  const bool found_condv = cerca(A_CONTRATTI) || cerca(A_OFFERTE) || cerca(A_LISTINI);
 | 
						|
  const bool cv_scagl = _condv.get_bool("GESTSCAGL");
 | 
						|
  const bool cv_um = _condv.get_bool("GESTUM");
 | 
						|
 | 
						|
  if (!load_um_only && !load_scagl_only && prezzo_lordo)
 | 
						|
    riga().set(FR_LORDO, "X");
 | 
						|
	else
 | 
						|
		riga().reset(FR_LORDO);
 | 
						|
 | 
						|
	real prezzo;
 | 
						|
	TString16 valuta;
 | 
						|
      
 | 
						|
  if (found_condv)
 | 
						|
  {
 | 
						|
    _load_mask |= load_scagl_only && cv_scagl;
 | 
						|
    _load_mask |= load_um_only && cv_um;
 | 
						|
 | 
						|
    real prezzo(_rcondv.get_real("PREZZO"));
 | 
						|
		const TString & valuta = _condv.get("CODVAL");
 | 
						|
 | 
						|
		if (prezzo_lordo)
 | 
						|
		{
 | 
						|
			TCodiceIVA iva(_anamag.get("CODIVA"));
 | 
						|
 | 
						|
			prezzo = iva.lordo(prezzo, AUTO_PRICES_DECIMALS, valuta);
 | 
						|
		}
 | 
						|
 | 
						|
	  set_prezzo(prezzo, valuta);
 | 
						|
    _load_mask = !load_um_only && !load_scagl_only;  
 | 
						|
  }
 | 
						|
  else
 | 
						|
  {
 | 
						|
    _load_mask |= load_um_only;
 | 
						|
    TString16 field_prezzo(testa().doc().tipo().field_prezzo());
 | 
						|
		real prezzo;
 | 
						|
 | 
						|
    if (field_prezzo.empty())
 | 
						|
			prezzo = _umart.get_real("PREZZO");
 | 
						|
		else
 | 
						|
			prezzo = _anamag.get_real(field_prezzo);
 | 
						|
		if (prezzo_lordo)
 | 
						|
		{
 | 
						|
			TCodiceIVA iva(_anamag.get("CODIVA"));
 | 
						|
 | 
						|
			prezzo = iva.lordo(prezzo, AUTO_PRICES_DECIMALS);
 | 
						|
		}
 | 
						|
	  set_prezzo(prezzo);
 | 
						|
  }
 | 
						|
      
 | 
						|
  if (_ivarid)
 | 
						|
    set_iva(_anamag.get(ANAMAG_CODIVAR));
 | 
						|
  else
 | 
						|
    set_iva(_anamag.get(ANAMAG_CODIVA));
 | 
						|
 | 
						|
  TConfig config_ditta(CONFIG_DITTA, "ve");
 | 
						|
  const char gestione = config_ditta.get_char( "GESSCORIGA", "ve" );                        
 | 
						|
  const bool sco_scagl =  config_ditta.get_bool("GESCOSCA", "ve");
 | 
						|
  const bool sco_um_gest =  config_ditta.get_bool("GESSCORIGAUM", "ve");
 | 
						|
      
 | 
						|
  switch (gestione)
 | 
						|
  { 
 | 
						|
    case 'N':
 | 
						|
      // Sconti di riga non gestiti
 | 
						|
      set_sconto(""); 
 | 
						|
      break;
 | 
						|
    case 'L':
 | 
						|
      // Percentuale su contratti/offerte/listini/anagrafica   
 | 
						|
      if (found_condv)
 | 
						|
      {
 | 
						|
        _load_mask |= load_scagl_only && cv_scagl;
 | 
						|
        _load_mask |= load_um_only && cv_um;
 | 
						|
        set_sconto(_rcondv.get("SCONTO"));
 | 
						|
        _load_mask = !load_um_only && !load_scagl_only;  
 | 
						|
      }
 | 
						|
      else
 | 
						|
        set_sconto(_anamag.get("SCONTO"));
 | 
						|
      break;
 | 
						|
    case 'A':
 | 
						|
      {
 | 
						|
      // Posiziono l'anagrafica
 | 
						|
        const char rigakey = config_ditta.get_char( "SCORIGAKEY", "ve" );                        
 | 
						|
  
 | 
						|
        _sconti.setkey(1);
 | 
						|
        _sconti.put("TIPO", "R");
 | 
						|
        if( config_ditta.get_bool("GESSCORIGACV", "ve"))
 | 
						|
          _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':
 | 
						|
            _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:
 | 
						|
            _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;
 | 
						|
        set_sconto(_sconti.get("SCONTO"));
 | 
						|
        _load_mask = !load_um_only && !load_scagl_only;  
 | 
						|
      }
 | 
						|
      break; 
 | 
						|
    case 'C':
 | 
						|
      set_sconto(clifo().vendite().get(CFV_SCONTO));
 | 
						|
      break;
 | 
						|
    default:
 | 
						|
      set_sconto(""); 
 | 
						|
      break;                                          
 | 
						|
  }                                  
 | 
						|
  
 | 
						|
  if (_riga && _riga->id2pos(FR_PERCPROV) >= 0 && _riga->field(FR_PERCPROV).active())
 | 
						|
  {
 | 
						|
    const TString16 codage(_testa->get(F_CODAG));                 
 | 
						|
    
 | 
						|
    if (codage.not_empty())
 | 
						|
    {                                                             
 | 
						|
      TLocalisamfile age(LF_AGENTI);
 | 
						|
                    
 | 
						|
      age.put(AGE_CODAGE, codage);
 | 
						|
      if (age.read() == NOERR)
 | 
						|
      {                           
 | 
						|
        TString16 seqric(age.get(AGE_SEQRIC));
 | 
						|
        TString16 fcodpr;
 | 
						|
        TString16 codpr;
 | 
						|
        real percprovv = ZERO;
 | 
						|
        
 | 
						|
        if (seqric[0] == '-')
 | 
						|
          seqric = config_ditta.get( "AGETIPOPERC", "ve" );
 | 
						|
        
 | 
						|
        int len = seqric.len();
 | 
						|
          
 | 
						|
        _load_mask |= load_scagl_only && cv_scagl;
 | 
						|
        _load_mask |= load_scagl_only && cv_um;
 | 
						|
        
 | 
						|
        for (int i = 0; percprovv == ZERO && i < len && seqric[i] != '-'; i++)
 | 
						|
        {              
 | 
						|
          if (isdigit(seqric[i]))
 | 
						|
          {  
 | 
						|
            fcodpr.format("CODRICPR%d", i+1);
 | 
						|
            codpr = age.get(fcodpr);
 | 
						|
          }
 | 
						|
          else
 | 
						|
            codpr.cut(0);
 | 
						|
          percprovv = get_percprovv(seqric[i], codpr, age);
 | 
						|
        }
 | 
						|
        real percalt = ZERO;
 | 
						|
        seqric = age.get(AGE_SEQALT);
 | 
						|
        for (i = 0; percalt == ZERO && i < len && seqric[i] != '-'; i++)
 | 
						|
        {
 | 
						|
          if (isdigit(seqric[i]))
 | 
						|
          {  
 | 
						|
            fcodpr.format("CODALTPR%d", i+1);
 | 
						|
            codpr = age.get(fcodpr);
 | 
						|
          }
 | 
						|
          else
 | 
						|
            codpr.cut(0);
 | 
						|
          percalt = get_percprovv(seqric[i], codpr, age);
 | 
						|
        }
 | 
						|
        percprovv += percalt;
 | 
						|
        set_provv(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();
 | 
						|
  bool update = FALSE;
 | 
						|
  
 | 
						|
  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, FALSE);
 | 
						|
      update = TRUE;
 | 
						|
    }
 | 
						|
  }        
 | 
						|
  
 | 
						|
  real qta = _riga->get(FR_QTA);
 | 
						|
  bool creata = FALSE;
 | 
						|
  
 | 
						|
  if (full || qta != ZERO)
 | 
						|
  { 
 | 
						|
    const TString80 codart_omaggio(_rcondv.get("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("Il tipo riga omaggi non risultava impostato.\n L'applicazione usera' automaticamente il tipo %s", (const char*) tipo_riga);
 | 
						|
      }
 | 
						|
    }
 | 
						|
    const real qbase = _rcondv.get_real("QBASE");
 | 
						|
    if (qbase == ZERO)
 | 
						|
      qta = ZERO;
 | 
						|
    else
 | 
						|
    {
 | 
						|
      qta /= _rcondv.get_real("QBASE");
 | 
						|
      qta.floor();
 | 
						|
      qta *= _rcondv.get_real("QOM");
 | 
						|
    }
 | 
						|
    creata = codart_omaggio.not_empty() && tipo_riga.not_empty() && qta != 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();           
 | 
						|
      TString16 codmag(_riga->get(FR_CODMAG)); codmag << _riga->get(FR_CODDEP);
 | 
						|
      r.put("CODMAG", codmag);
 | 
						|
      r.put("CODART", codart_omaggio);
 | 
						|
      r.put("UMQTA", _rcondv.get("UMOM"));
 | 
						|
      r.put("QTA", qta);
 | 
						|
      real prezzo(_rcondv.get("PROMAGGIO"));
 | 
						|
      const TString16 codval(_condv.get("CODVAL"));
 | 
						|
      const TString16 codiva_cli(clifo().vendite().get(CFV_ASSFIS));
 | 
						|
      if (codiva_cli.not_empty())
 | 
						|
        r.put("CODIVA", codiva_cli);
 | 
						|
      else
 | 
						|
        r.put("CODIVA", _rcondv.get("CODIVA"));
 | 
						|
      r.put("ADDIVA", _rcondv.get("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("PREZZO", prezzo);  
 | 
						|
      r.autoload(sh);
 | 
						|
      update = TRUE;
 | 
						|
//      curr_row.autoload(sh);            
 | 
						|
    } 
 | 
						|
  }                  
 | 
						|
  if (update) 
 | 
						|
  {
 | 
						|
    sh.force_update();
 | 
						|
    sh.select(creata ? current_doc_row : current_doc_row - 1);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
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)
 | 
						|
{
 | 
						|
}
 | 
						|
    
 |