2009-09-22 09:38:38 +00:00
# include <applicat.h>
# include <diction.h>
1998-08-25 18:07:30 +00:00
# include <dongle.h>
1999-04-06 15:34:39 +00:00
# include <modaut.h>
2008-02-01 06:39:03 +00:00
# include <tabutil.h>
1998-08-25 18:07:30 +00:00
# include <utility.h>
1998-05-04 09:54:49 +00:00
2006-12-15 09:26:08 +00:00
# include "../cg/cg2103.h"
# include "../db/dblib.h"
# include "../pr/prlib.h"
# include "../sv/svlib01.h"
2008-08-27 23:23:05 +00:00
# include "../li/letint.h"
2006-12-15 09:26:08 +00:00
1999-04-06 15:34:39 +00:00
# include "veini.h"
1997-06-03 15:56:27 +00:00
# include "velib.h"
2011-06-24 12:28:23 +00:00
# include "sconti.h"
1997-06-03 15:56:27 +00:00
# include "vepriv.h"
# include "veuml.h"
1997-09-26 15:22:39 +00:00
2008-10-07 00:50:22 +00:00
///////////////////////////////////////////////////////////
// TTipo_documento_cache
///////////////////////////////////////////////////////////
2009-09-24 15:27:38 +00:00
2008-10-07 00:50:22 +00:00
class TTipo_documento_cache : public TRecord_cache
{
protected :
virtual TObject * rec2obj ( const TRectype & rec ) const ;
public :
TTipo_documento & tipo ( const char * key ) ;
TTipo_documento_cache ( ) ;
virtual ~ TTipo_documento_cache ( ) { }
} ;
TTipo_documento_cache : : TTipo_documento_cache ( )
: TRecord_cache ( " %TIP " , 1 )
{
2008-10-10 08:10:51 +00:00
test_file_changes ( ) ; // Tieni d'occhio le modifiche sul file
set_items_limit ( 59 ) ; // Standard
2008-10-07 00:50:22 +00:00
}
TObject * TTipo_documento_cache : : rec2obj ( const TRectype & curr ) const
{
return new TTipo_documento ( curr ) ;
}
2014-03-07 14:42:05 +00:00
TTipo_documento & TTipo_documento_cache : : tipo ( const char * key )
2008-10-07 00:50:22 +00:00
{
2014-03-07 14:42:05 +00:00
TString8 k ; k < < " TIP| " < < key ;
return ( TTipo_documento & ) query ( k ) ;
2008-10-07 00:50:22 +00:00
}
2014-03-07 14:42:05 +00:00
const TTipo_documento & cached_tipodoc ( const char * tipodoc )
2008-10-07 00:50:22 +00:00
{
HIDDEN TTipo_documento_cache __cache_tipi_documento ;
return __cache_tipi_documento . tipo ( tipodoc ) ;
}
///////////////////////////////////////////////////////////
// TTipo_numerazione_cache
///////////////////////////////////////////////////////////
class TNumerazione_cache : public TRecord_cache
{
protected :
virtual TObject * rec2obj ( const TRectype & rec ) const ;
public :
TCodice_numerazione & num ( const char * key ) ;
TNumerazione_cache ( ) ;
} ;
TNumerazione_cache : : TNumerazione_cache ( )
: TRecord_cache ( " %NUM " , 1 )
{
test_file_changes ( ) ; // Tieni d'occhio le modifiche sul file
2009-12-22 16:56:14 +00:00
set_items_limit ( 59 ) ; // Standard
2008-10-07 00:50:22 +00:00
}
TObject * TNumerazione_cache : : rec2obj ( const TRectype & curr ) const
{
return new TCodice_numerazione ( curr ) ;
}
TCodice_numerazione & TNumerazione_cache : : num ( const char * key )
{
2014-03-07 14:42:05 +00:00
TString8 k ; k < < " NUM| " < < key ;
return ( TCodice_numerazione & ) query ( k ) ;
2008-10-07 00:50:22 +00:00
}
2008-10-08 12:39:45 +00:00
const TCodice_numerazione & cached_numerazione ( const char * codnum )
2008-10-07 00:50:22 +00:00
{
HIDDEN TNumerazione_cache __cache_numerazioni ;
return __cache_numerazioni . num ( codnum ) ;
}
1998-11-04 18:04:26 +00:00
// calcola il prezzo per le spese
2012-02-24 15:00:45 +00:00
void sppr_calc ( const TRectype & rec , const TString & valuta_doc , const real & cambio , real & prezzo )
1998-11-04 18:04:26 +00:00
{
2012-07-02 13:08:20 +00:00
const TString & sppr_valuta = rec . get ( " S4 " ) ;
if ( ! same_values ( sppr_valuta , valuta_doc ) )
2000-05-05 15:25:49 +00:00
{
const bool prezzo_un = rec . get_char ( " S6 " ) = = ' Q ' ;
2012-07-02 13:08:20 +00:00
/* Non capisco bene il cambio in gioco ...
2000-05-05 15:25:49 +00:00
if ( prezzo_un )
1998-11-04 18:04:26 +00:00
{
2000-05-05 15:25:49 +00:00
TPrice val ( prezzo , sppr_valuta ) ;
2012-02-24 15:00:45 +00:00
val . change_value ( valuta_doc , cambio ) ;
2000-05-05 15:25:49 +00:00
prezzo = val . get_num ( ) ;
}
else
{
2012-07-02 13:08:20 +00:00
TCurrency val ( prezzo , sppr_valuta ) ;
2012-02-24 15:00:45 +00:00
val . change_value ( valuta_doc , cambio ) ;
2000-05-05 15:25:49 +00:00
prezzo = val . get_num ( ) ;
}
2012-07-02 13:08:20 +00:00
*/
// ... ma mi adeguo
TCurrency val ( prezzo , sppr_valuta , ZERO , prezzo_un ) ;
val . change_value ( valuta_doc , cambio ) ;
prezzo = val . get_num ( ) ;
1998-11-04 18:04:26 +00:00
}
}
1997-06-27 09:21:13 +00:00
///////////////////////////////////////////////////////////
// Movimento di magazzino
///////////////////////////////////////////////////////////
1999-04-06 15:34:39 +00:00
1997-06-27 09:21:13 +00:00
class TMov_mag_doc : public TMov_mag
{
1999-04-06 15:34:39 +00:00
TString_array _codmagc ;
1997-06-27 09:21:13 +00:00
protected :
2010-01-28 15:22:15 +00:00
virtual const char * codmag_rauto ( int r ) const ;
1997-06-27 09:21:13 +00:00
1998-11-04 18:04:26 +00:00
public :
2010-01-28 15:22:15 +00:00
void add_magc ( const char * magc )
{
2010-01-30 12:42:37 +00:00
CHECKS ( magc & & strlen ( magc ) < = 5 , " Invalid CODMAG " , magc ) ;
2010-01-28 15:22:15 +00:00
_codmagc . add ( magc ) ;
}
2010-02-21 08:43:38 +00:00
void reset_magc ( int r ) { _codmagc . add ( " " , r - 1 ) ; }
void destroy_magc ( int r ) { _codmagc . destroy ( r - 1 ) ; }
1997-06-27 09:21:13 +00:00
} ;
1999-04-06 15:34:39 +00:00
const char * TMov_mag_doc : : codmag_rauto ( int r ) const
1998-11-04 18:04:26 +00:00
{
2010-01-28 15:22:15 +00:00
const char * codmagc = NULL ;
const int num_magc = _codmagc . items ( ) ;
if ( num_magc > 0 ) // Impossibile trovare un codmagc
{
const TRecord_array & b = body ( ) ;
if ( r > 0 & & r < = b . rows ( ) ) // Can't check non-existent rows
{
const char tr = b [ r ] . get_char ( RMOVMAG_TIPORIGA ) ;
if ( tr = = ' D ' | | tr = = ' A ' ) // These are customer's added rows
{
int j = - 1 ; // Indice per reperire il mag. collegato da _codmagc
for ( int i = r ; i > 0 ; i - - ) // Scorre dalla riga r in su e conta quante righe D
if ( b [ i ] . get_char ( RMOVMAG_TIPORIGA ) = = ' D ' )
j + + ;
if ( j > = 0 & & j < num_magc )
codmagc = _codmagc . row ( j ) ;
}
}
}
return codmagc ;
1997-06-27 09:21:13 +00:00
}
1998-11-04 18:04:26 +00:00
1997-08-21 16:47:14 +00:00
/////////////////////////////////////////////////////////////
// TRiepilogo IVA
/////////////////////////////////////////////////////////////
TRiepilogo_iva & TRiepilogo_iva : : copy ( const TRiepilogo_iva & a )
{
2009-12-22 16:56:14 +00:00
_codiva = a . cod_iva ( ) ;
1997-08-21 16:47:14 +00:00
_imp = a . _imp ;
2007-03-07 11:36:57 +00:00
_imp_orig = a . _imp_orig ;
1997-08-21 16:47:14 +00:00
_imp_spese = a . _imp_spese ;
2003-09-12 14:20:25 +00:00
_imp_spese_row = a . _imp_spese_row ;
1997-08-21 16:47:14 +00:00
_iva = a . _iva ;
_iva_spese = a . _iva_spese ;
2003-09-12 14:20:25 +00:00
_sconto_perc = a . _sconto_perc ;
_sconto_imp = a . _sconto_imp ;
_iva_sconto = a . _iva_sconto ;
1997-08-21 16:47:14 +00:00
_tipo = a . _tipo ;
return * this ;
}
2000-05-05 15:25:49 +00:00
TRiepilogo_iva : : TRiepilogo_iva ( const TCodiceIVA & codiva ) : _codiva ( codiva )
1997-08-21 16:47:14 +00:00
{
2006-01-09 01:15:53 +00:00
const TString & t = _codiva . tipo ( ) ;
1997-08-21 16:47:14 +00:00
if ( t = = " VE " )
2006-01-09 01:15:53 +00:00
_tipo = 2 ; else
if ( t = = " ES " )
_tipo = 4 ; else
if ( t = = " NI " )
_tipo = 8 ; else
if ( t = = " NS " )
_tipo = 16 ;
1997-08-21 16:47:14 +00:00
else
2006-01-09 01:15:53 +00:00
_tipo = 1 ;
1997-08-21 16:47:14 +00:00
}
1997-10-29 11:08:40 +00:00
///////////////////////////////////////////////////////////
// Agenti
///////////////////////////////////////////////////////////
class TAgenti_cache : public TRecord_cache
{
protected :
virtual TObject * rec2obj ( const TRectype & rec ) const { return new TAgente ( rec ) ; }
public :
const TAgente & agente ( const char * chiave ) { return ( const TAgente & ) get ( chiave ) ; }
TAgenti_cache ( ) : TRecord_cache ( LF_AGENTI ) { }
virtual ~ TAgenti_cache ( ) { }
} ;
2002-07-30 14:11:47 +00:00
HIDDEN TAgenti_cache * _agenti = NULL ;
1997-10-29 11:08:40 +00:00
1997-06-03 15:56:27 +00:00
///////////////////////////////////////////////////////////
// Documento per vendite
///////////////////////////////////////////////////////////
1997-08-26 12:38:08 +00:00
long TDocumento : : _firm = - 1 ;
2006-01-09 01:15:53 +00:00
TString4 TDocumento : : _codiva_spese ;
TString4 TDocumento : : _codiva_bolli ;
1998-05-04 09:54:49 +00:00
short TDocumento : : _has_mag = 3 ;
short TDocumento : : _has_stat_ven = 3 ;
short TDocumento : : _has_provv = 3 ;
1999-07-16 14:59:11 +00:00
TCodgiac_livelli * TDocumento : : _livelli = NULL ;
1997-06-03 15:56:27 +00:00
2002-02-26 16:20:19 +00:00
// HIDDEN TStats_agg _st_agg;
1998-11-04 18:04:26 +00:00
HIDDEN TAssoc_array _docs_to_agg ;
void TDocumento : : init ( )
{
2007-09-17 15:33:04 +00:00
add_file ( LF_RIGHEDOC , RDOC_NRIGA ) ;
1998-11-04 18:04:26 +00:00
set_memo_fld ( " G1 " ) ;
2013-05-06 08:57:55 +00:00
_tipocf = new TRecfield ( * this , DOC_TIPOCF ) ;
_codcf = new TRecfield ( * this , DOC_CODCF ) ;
2007-09-17 15:33:04 +00:00
_cod_occas = new TRecfield ( * this , DOC_OCFPI ) ;
2007-03-07 15:35:38 +00:00
1998-11-04 18:04:26 +00:00
_sconto = _esenzione = NULL ;
_stato_originale = ' ' ;
2006-07-17 13:50:22 +00:00
_dirty_deny = false ;
1998-11-04 18:04:26 +00:00
1997-09-26 15:22:39 +00:00
check_modules ( ) ;
1998-08-25 18:07:30 +00:00
}
1997-06-03 15:56:27 +00:00
2012-07-02 13:08:20 +00:00
TDocumento : : TDocumento ( ) : TMultiple_rectype ( LF_DOC )
1998-11-04 18:04:26 +00:00
{
init ( ) ;
}
1997-08-06 12:31:10 +00:00
TDocumento : : TDocumento ( const TDocumento & d )
1998-11-04 18:04:26 +00:00
: TMultiple_rectype ( LF_DOC )
1997-08-06 12:31:10 +00:00
{
1998-11-04 18:04:26 +00:00
init ( ) ;
1998-06-10 16:38:58 +00:00
copy ( d ) ;
1997-08-06 12:31:10 +00:00
}
1998-08-25 18:07:30 +00:00
TDocumento : : TDocumento ( char provv , int anno , const char * codnum , long numdoc )
1998-11-04 18:04:26 +00:00
: TMultiple_rectype ( LF_DOC )
1997-06-03 15:56:27 +00:00
{
1998-11-04 18:04:26 +00:00
init ( ) ;
1997-06-03 15:56:27 +00:00
if ( numdoc < = 0 )
{
numdoc = 0 ;
set_key ( * this , provv , anno , codnum , numdoc ) ;
}
else
read ( provv , anno , codnum , numdoc ) ;
}
1998-08-25 18:07:30 +00:00
TDocumento : : TDocumento ( const TRectype & rec )
1998-11-04 18:04:26 +00:00
: TMultiple_rectype ( LF_DOC )
1997-06-03 15:56:27 +00:00
{
1998-11-04 18:04:26 +00:00
init ( ) ;
1997-06-03 15:56:27 +00:00
read ( rec ) ;
}
TDocumento : : ~ TDocumento ( )
{
1997-06-12 16:26:22 +00:00
delete _tipocf ;
delete _codcf ;
delete _cod_occas ;
1998-11-04 18:04:26 +00:00
1997-06-03 15:56:27 +00:00
if ( _sconto ! = NULL ) delete _sconto ;
if ( _esenzione ! = NULL ) delete _esenzione ;
}
2002-07-02 16:21:23 +00:00
const TString & TDocumento : : codiva_spese ( ) const
1997-10-23 10:55:09 +00:00
{ ( ( TDocumento * ) this ) - > test_firm ( ) ; return _codiva_spese ; }
2002-07-02 16:21:23 +00:00
const TString & TDocumento : : codiva_bolli ( ) const
1997-10-23 10:55:09 +00:00
{ ( ( TDocumento * ) this ) - > test_firm ( ) ; return _codiva_bolli ; }
1997-09-26 15:22:39 +00:00
void TDocumento : : check_modules ( )
{
if ( _has_mag = = 3 )
2013-05-06 08:57:55 +00:00
{
const TDongle & din = dongle ( ) ;
_has_mag = din . active ( MGAUT ) ;
_has_stat_ven = din . active ( SVAUT ) ;
_has_provv = din . active ( PRAUT ) ;
1997-09-26 15:22:39 +00:00
}
}
1999-04-06 15:34:39 +00:00
void TDocumento : : set_variables ( TExpression * e ) const
{
2010-06-21 14:23:50 +00:00
CHECK ( e , " Null expression " ) ;
1999-04-06 15:34:39 +00:00
const int items = e - > numvar ( ) ;
for ( int i = 0 ; i < items ; i + + )
{
const TFieldref field ( e - > varname ( i ) , LF_DOC ) ;
switch ( field . file ( ) )
{
2014-03-07 14:42:05 +00:00
case LF_CLIFO :
e - > setvar ( i , clifor ( ) . get ( field . name ( ) ) ) ;
break ;
case LF_CFVEN :
e - > setvar ( i , clifor ( ) . vendite ( ) . get ( field . name ( ) ) ) ;
break ;
default :
e - > setvar ( i , get ( field . name ( ) ) ) ;
break ;
1999-04-06 15:34:39 +00:00
}
}
}
1997-08-21 16:47:14 +00:00
void TDocumento : : test_firm ( )
{
const long new_firm = prefix ( ) . get_codditta ( ) ;
if ( _firm ! = new_firm )
{
1998-11-04 18:04:26 +00:00
TConfig conf ( CONFIG_DITTA , " ve " ) ;
_codiva_spese = conf . get ( " SPINCODIVA " ) ;
_codiva_bolli = conf . get ( " SPBOCODIVA " ) ;
1997-08-21 16:47:14 +00:00
_firm = new_firm ;
}
1997-08-26 12:38:08 +00:00
}
2007-09-17 15:33:04 +00:00
real TDocumento : : spese_incasso ( real & imp , int ndec , TTipo_importo t ) const
1997-06-03 15:56:27 +00:00
{
static TArray spese_inc ;
2007-09-17 15:33:04 +00:00
static real maxadd , spadd ;
2005-09-19 12:45:16 +00:00
real imp_spese ;
const real percentuale = get ( DOC_PERCSPINC ) ;
1997-06-03 15:56:27 +00:00
if ( percentuale > ZERO )
{
1997-10-02 16:57:49 +00:00
if ( ndec = = AUTO_DECIMALS )
2000-05-05 15:25:49 +00:00
ndec = decimals ( ) ;
2008-03-26 11:24:36 +00:00
if ( spese_inc . objptr ( _rim_dir ) = = NULL ) // Inizializzo le spese d'incasso se necessario
1997-06-03 15:56:27 +00:00
{
2002-10-23 14:14:55 +00:00
TConfig conf ( CONFIG_STUDIO , " ve " ) ;
2005-09-19 12:45:16 +00:00
for ( TTipo_pag p = _rim_dir ; p < _nessun_pag ; p = TTipo_pag ( ( int ) p + 1 ) )
1997-05-23 14:26:19 +00:00
{
2005-09-19 12:45:16 +00:00
const real r ( conf . get ( " IMPSPINC " , " ve " , p ) ) ;
1997-06-03 15:56:27 +00:00
spese_inc . add ( r , p ) ;
1997-05-23 14:26:19 +00:00
}
2007-09-17 15:33:04 +00:00
maxadd = ( real ) conf . get ( " MAXADD " ) ;
spadd = ( real ) conf . get ( " SPADD " ) ;
1997-06-03 15:56:27 +00:00
}
2006-04-13 17:56:02 +00:00
// Calcola l'eventuale importo minimo per effetti (solitamente zero)
const TRectype & cfven = clifor ( ) . vendite ( ) ;
const real impmineff = cfven . get_real ( CFV_IMPMINEFF ) ;
// Somma le spese di ogni singola rata
const TPagamento & pag = ( ( TDocumento * ) this ) - > pagamento ( ) ;
1997-06-03 15:56:27 +00:00
const int nrate = pag . n_rate ( ) ;
2007-09-17 15:33:04 +00:00
1997-06-03 15:56:27 +00:00
for ( int i = 0 ; i < nrate ; i + + )
{
2006-04-13 17:56:02 +00:00
if ( pag . importo_rata ( i ) > = impmineff ) // Se la rata supera il minimo contrattuale
{
2006-07-10 13:30:29 +00:00
const TTipo_pag tp = ( TTipo_pag ) pag . tipo_rata ( i ) ;
2011-02-26 22:49:55 +00:00
if ( spese_inc . objptr ( tp ) ! = NULL )
2006-04-13 17:56:02 +00:00
imp_spese + = ( const real & ) spese_inc [ tp ] ;
}
2007-09-17 15:33:04 +00:00
}
if ( imp_spese > ZERO & & imp < maxadd )
imp_spese + = spadd ;
2005-09-19 12:45:16 +00:00
imp_spese = imp_spese * percentuale / CENTO ;
1997-06-03 15:56:27 +00:00
1999-06-18 15:35:05 +00:00
if ( t = = _lordo | | t = = _imposta )
{
2006-04-13 17:56:02 +00:00
TString4 codiva_es ; iva_esente ( codiva_es ) ;
2013-03-15 11:08:44 +00:00
const real iva_spese = TRiga_documento : : iva ( codiva_es . full ( ) ? ( const TString & ) codiva_es : codiva_spese ( ) ) . imposta ( imp_spese , ndec ) ;
1999-07-16 14:59:11 +00:00
if ( t = = _lordo )
imp_spese + = iva_spese ;
else
if ( t = = _imposta )
imp_spese = iva_spese ;
}
2002-10-23 14:14:55 +00:00
2005-09-19 12:45:16 +00:00
const real cambio = get ( DOC_CAMBIO ) ;
2002-10-23 14:14:55 +00:00
if ( ! cambio . is_zero ( ) )
{
2006-04-13 17:56:02 +00:00
// Converte le spese nella valuta del documento
2012-02-24 15:00:45 +00:00
imp_spese = change_currency ( imp_spese , " " , ZERO , get ( DOC_CODVAL ) , cambio , - 1 ) ;
2002-10-23 14:14:55 +00:00
}
2006-04-13 17:56:02 +00:00
1997-06-03 15:56:27 +00:00
imp_spese . round ( ndec ) ;
}
2007-09-17 15:33:04 +00:00
1997-06-03 15:56:27 +00:00
return imp_spese ;
}
1999-06-18 15:35:05 +00:00
2006-04-13 17:56:02 +00:00
void TDocumento : : iva_esente ( TString & codiva_es ) const
1999-06-18 15:35:05 +00:00
{
1999-07-16 14:59:11 +00:00
codiva_es . cut ( 0 ) ;
2006-04-13 17:56:02 +00:00
const int rows = physical_rows ( ) ;
1999-07-16 14:59:11 +00:00
for ( int r = 1 ; codiva_es . empty ( ) & & r < = rows ; r + + )
1999-06-18 15:35:05 +00:00
{
const TRiga_documento & riga = ( ( TDocumento * ) this ) - > row ( r ) ;
2013-03-15 11:08:44 +00:00
const TString4 str_codiva = riga . get ( RDOC_CODIVA ) ;
1999-07-16 14:59:11 +00:00
2006-04-13 17:56:02 +00:00
if ( str_codiva . full ( ) )
1999-07-16 14:59:11 +00:00
{
2000-05-05 15:25:49 +00:00
const TCodiceIVA codiva ( str_codiva ) ;
2006-04-13 17:56:02 +00:00
const TString & tipoiva = codiva . tipo ( ) ;
1999-10-22 10:00:18 +00:00
if ( tipoiva . empty ( ) )
break ;
if ( tipoiva = = " NI " )
2006-04-13 17:56:02 +00:00
codiva_es = str_codiva ;
1999-10-22 10:00:18 +00:00
}
}
1999-06-18 15:35:05 +00:00
}
1997-06-03 15:56:27 +00:00
real TDocumento : : bolli ( real & imp , int ndec , TTipo_importo t ) const
{
real tot_bolli ;
static TArray sca_bolli ;
static TArray imp_bolli ;
1999-04-06 15:34:39 +00:00
static real bolli_es ;
1999-04-26 15:58:05 +00:00
static real impmin_bolli ;
1997-06-03 15:56:27 +00:00
static int nscagl ;
if ( get_bool ( " ADDBOLLI " ) )
{
1999-04-06 15:34:39 +00:00
if ( sca_bolli . objptr ( 0 ) = = NULL )
{
2006-04-13 17:56:02 +00:00
TConfig conf ( CONFIG_STUDIO , " ve " ) ;
1999-04-06 15:34:39 +00:00
bolli_es = ( real ) conf . get ( " BOLLIES " , " ve " ) ;
1999-04-26 15:58:05 +00:00
impmin_bolli = ( real ) conf . get ( " IMPMINBOLLI " , " ve " ) ;
1999-04-06 15:34:39 +00:00
for ( nscagl = 0 ; nscagl < 7 ; nscagl + + )
{
real s ( conf . get ( " SPBOSCA " , " ve " , nscagl + 1 ) ) ;
real i ( conf . get ( " SPBOIMP " , " ve " , nscagl + 1 ) ) ;
if ( s = = ZERO & & i = = ZERO )
break ;
sca_bolli . add ( s , nscagl ) ;
imp_bolli . add ( i , nscagl ) ;
}
}
1997-10-02 16:57:49 +00:00
if ( ndec = = AUTO_DECIMALS )
2000-05-05 15:25:49 +00:00
ndec = decimals ( ) ;
2002-10-23 14:14:55 +00:00
TCurrency_documento imp_val ( imp ) ;
imp_val . change_to_firm_val ( ) ;
real importo = imp_val . get_num ( ) ;
1997-06-03 15:56:27 +00:00
TPagamento & pag = ( ( TDocumento * ) this ) - > pagamento ( ) ;
const int nrate = pag . n_rate ( ) ;
real old_bolli = - 1.00 ;
real iva_bolli ;
2002-10-23 14:14:55 +00:00
TCurrency_documento imp_orig_val ( imposta ( ) ) ;
imp_orig_val . change_to_firm_val ( ) ;
const real imp_orig = imp_orig_val . get_num ( ) ;
TCurrency_documento spese_val ( spese ( ) ) ;
spese_val . change_to_firm_val ( ) ;
const real sp_orig = spese_val . get_num ( ) ;
2002-12-20 16:15:03 +00:00
bool estero = FALSE ; // Assumiamo per ora non estero
2007-09-17 15:33:04 +00:00
TString4 codiva_es ;
2004-06-04 11:20:51 +00:00
iva_esente ( codiva_es ) ;
2002-12-20 16:15:03 +00:00
1997-12-10 12:18:52 +00:00
for ( int j = 0 ; j < 5 & & tot_bolli + iva_bolli ! = old_bolli ; j + + )
1997-06-03 15:56:27 +00:00
{
old_bolli = tot_bolli + iva_bolli ;
2002-10-23 14:14:55 +00:00
const real imposte = imp_orig + iva_bolli ;
const real imp_spese = sp_orig + tot_bolli - iva_bolli ;
1997-06-03 15:56:27 +00:00
const real imponibile = importo - imposte - imp_spese ;
tot_bolli = ZERO ;
1999-10-22 10:00:18 +00:00
if ( ! tipo ( ) . nota_credito ( ) )
1999-06-18 15:35:05 +00:00
{
1999-10-22 10:00:18 +00:00
real imponibile_esente ;
for ( int r = physical_rows ( ) ; r > 0 ; r - - )
{
const TRiga_documento & riga = ( ( TDocumento * ) this ) - > row ( r ) ;
2000-05-05 15:25:49 +00:00
const TCodiceIVA codiva ( riga . get ( RDOC_CODIVA ) ) ;
1999-10-22 10:00:18 +00:00
if ( codiva . tipo ( ) . not_empty ( ) )
imponibile_esente + = riga . imponibile ( ) ;
}
if ( imponibile_esente > = impmin_bolli )
tot_bolli = bolli_es ;
}
1997-06-03 15:56:27 +00:00
pag . set_total ( imponibile , imposte , imp_spese ) ;
pag . set_rate_auto ( ) ;
for ( int i = 0 ; i < nrate ; i + + )
1997-05-23 14:26:19 +00:00
{
1997-06-03 15:56:27 +00:00
const TTipo_pag p = ( TTipo_pag ) pag . tipo_rata ( i ) ;
real imp = pag . importo_rata ( i ) ;
1997-05-23 14:26:19 +00:00
1997-06-03 15:56:27 +00:00
switch ( p )
{
case _ric_ban :
1997-05-23 14:26:19 +00:00
{
2004-04-28 22:23:16 +00:00
int i ;
for ( i = 0 ; i < nscagl - 1 ; i + + )
1997-06-03 15:56:27 +00:00
if ( ( real & ) sca_bolli [ i ] > = imp )
break ;
if ( imp_bolli . items ( ) > 0 )
tot_bolli + = ( real & ) imp_bolli [ i ] ;
1997-05-23 14:26:19 +00:00
}
break ;
1997-06-03 15:56:27 +00:00
case _tratta :
case _tratta_acc :
{
2002-12-20 16:15:03 +00:00
if ( j = = 0 ) // Dobbiamo inizializzare la variabile 'estero'
{
TString16 key ;
key . format ( " %c|%ld " , get_char ( DOC_TIPOCF ) , get_long ( DOC_CODCF ) ) ;
const TRectype & clifo = cache ( ) . get ( LF_CLIFO , key ) ;
const TString & stato_iva = clifo . get ( CLI_STATOPAIV ) ;
estero = stato_iva . not_empty ( ) & & stato_iva ! = " IT " ;
1997-06-03 15:56:27 +00:00
if ( ! estero )
2002-12-20 16:15:03 +00:00
{
const TString & stato_cf = clifo . get ( CLI_STATOCF ) ;
estero = ( stato_cf . not_empty ( ) & & stato_cf ! = " IT " ) | | clifo . get_char ( CLI_COMCF ) = = ' Z ' ;
}
1997-06-03 15:56:27 +00:00
}
real r ( imp ) ;
2002-12-20 16:15:03 +00:00
const int ndec = decimals ( ) ;
r . ceil ( ndec = = 0 ? - 3 : 0 ) ;
1997-06-03 15:56:27 +00:00
if ( estero )
r * = 0.009 ;
else
r * = 0.012 ;
2002-12-20 16:15:03 +00:00
r . round ( ndec = = 0 ? - 2 : ndec ) ;
1997-06-03 15:56:27 +00:00
tot_bolli + = r ;
1997-05-23 14:26:19 +00:00
}
break ;
1997-06-03 15:56:27 +00:00
case _cessione :
case _paghero :
case _let_cred :
case _rim_dir :
case _rid :
case _bonfico :
1997-05-23 14:26:19 +00:00
default :
break ;
}
1997-06-03 15:56:27 +00:00
}
2006-04-13 17:56:02 +00:00
iva_bolli = TRiga_documento : : iva ( codiva_bolli ( ) ) . imposta ( tot_bolli , ndec ) ;
1997-06-03 15:56:27 +00:00
importo + = ( tot_bolli + iva_bolli - old_bolli ) ;
}
if ( t = = _lordo )
tot_bolli + = iva_bolli ;
else
if ( t = = _imposta )
tot_bolli = iva_bolli ;
2002-10-23 14:14:55 +00:00
2002-12-20 16:15:03 +00:00
if ( in_valuta ( ) )
2002-10-23 14:14:55 +00:00
{
2008-11-10 12:07:11 +00:00
const real cambio = get_real ( DOC_CAMBIO ) ;
2012-02-24 15:00:45 +00:00
tot_bolli = change_currency ( tot_bolli , " " , ZERO , get ( DOC_CODVAL ) , cambio , - 1 ) ;
2002-10-23 14:14:55 +00:00
}
1997-06-03 15:56:27 +00:00
tot_bolli . round ( ndec ) ;
1997-05-23 14:26:19 +00:00
}
1997-06-03 15:56:27 +00:00
return tot_bolli ;
1997-05-23 14:26:19 +00:00
}
1997-08-18 16:06:51 +00:00
2006-05-04 17:44:58 +00:00
const TString & TDocumento : : commessa_principale ( ) const
{
if ( codice_commessa ( ) . blank ( ) )
{
const int row = physical_rows ( ) ;
for ( int i = 1 ; i < = rows ( ) ; i + + )
{
const TRiga_documento & r = ( ( TRiga_documento & ) ( ( TDocumento * ) this ) - > row ( i ) ) ;
if ( ! r . codice_commessa ( ) . blank ( ) )
return r . codice_commessa ( ) ;
}
}
return codice_commessa ( ) ;
}
1997-08-18 16:06:51 +00:00
bool TDocumento : : modificabile ( ) const
{
const char stato_attuale = stato ( ) ;
if ( stato_attuale < = ' ' )
2011-04-11 13:56:36 +00:00
return true ;
1997-08-18 16:06:51 +00:00
2000-05-05 15:25:49 +00:00
const TString & stati_modifica = tipo ( ) . stati_iniziali_modifica ( ) ;
return stati_modifica . blank ( ) | | stati_modifica . find ( stato_attuale ) > = 0 ;
1997-08-18 16:06:51 +00:00
}
bool TDocumento : : cancellabile ( ) const
{
const char stato_attuale = stato ( ) ;
if ( stato_attuale < = ' ' )
2011-04-11 13:56:36 +00:00
return true ;
1997-08-18 16:06:51 +00:00
2000-05-05 15:25:49 +00:00
const TString & stati_cancellazione = tipo ( ) . stati_iniziali_cancellazione ( ) ;
return stati_cancellazione . blank ( ) | | stati_cancellazione . find ( stato_attuale ) > = 0 ;
1997-08-18 16:06:51 +00:00
}
bool TDocumento : : stampabile ( ) const
{
const char stato_attuale = stato ( ) ;
if ( stato_attuale < = ' ' )
2009-11-18 11:17:58 +00:00
return true ;
2000-05-05 15:25:49 +00:00
if ( stato_attuale = = tipo ( ) . stato_finale_stampa ( ) )
2009-11-18 11:17:58 +00:00
return false ;
1997-08-18 16:06:51 +00:00
2003-12-19 10:42:43 +00:00
const TString & stati_stampa = tipo ( ) . stati_iniziali_stampa ( ) ;
2000-05-05 15:25:49 +00:00
return stati_stampa . blank ( ) | | stati_stampa . find ( stato_attuale ) > = 0 ;
}
bool TDocumento : : bloccato ( ) const
{
const char stato_attuale = stato ( ) ;
if ( stato_attuale < = ' ' )
2007-03-07 11:36:57 +00:00
return false ;
2000-05-05 15:25:49 +00:00
char stato_bloccato = tipo ( ) . stato_bloccato ( ) ;
if ( stato_bloccato < = ' ' )
2007-03-07 11:36:57 +00:00
return false ;
return stato_attuale > = stato_bloccato ;
}
bool TDocumento : : chiuso ( ) const
{
2007-09-17 15:33:04 +00:00
if ( ! tipo ( ) . is_scontrino ( ) )
return false ;
2007-03-07 11:36:57 +00:00
const char stato_attuale = stato ( ) ;
if ( stato_attuale < = ' ' )
return false ;
2007-09-17 15:33:04 +00:00
char stato_chiuso = tipo ( ) . stato_chiuso ( ) ;
2007-03-07 11:36:57 +00:00
2007-09-17 15:33:04 +00:00
if ( stato_chiuso < = ' ' )
2007-03-07 11:36:57 +00:00
return false ;
2000-05-05 15:25:49 +00:00
2007-09-17 15:33:04 +00:00
return stato_attuale > = stato_chiuso ;
1997-08-18 16:06:51 +00:00
}
1997-06-03 15:56:27 +00:00
// Funzione statica utile a tutti gli utenti di LF_DOC e LF_RIGHEDOC
void TDocumento : : set_key ( TRectype & rec , char provv , int anno , const char * codnum , long numdoc )
1997-05-23 14:26:19 +00:00
{
1997-06-03 15:56:27 +00:00
CHECK ( provv = = ' D ' | | provv = = ' P ' , " Provvisorio o Definitivo? " ) ;
CHECKD ( anno > 1900 , " Anno non valido: " , anno ) ;
CHECK ( codnum & & * codnum , " Codice numerazione nullo " ) ;
CHECKD ( numdoc > = 0 , " Numero documento non valido " , numdoc ) ;
2006-04-13 17:56:02 +00:00
rec . put ( DOC_PROVV , provv ) ;
rec . put ( DOC_ANNO , anno ) ;
rec . put ( DOC_CODNUM , codnum ) ;
rec . put ( DOC_NDOC , numdoc ) ;
1997-06-03 15:56:27 +00:00
}
// Funzione statica utile a tutti gli utenti di LF_DOC e LF_RIGHEDOC
void TDocumento : : copy_data ( TRectype & dst , const TRectype & src )
{
2006-07-10 13:30:29 +00:00
const bool is_riga = dst . num ( ) = = LF_RIGHEDOC ;
1997-06-03 15:56:27 +00:00
// Memorizza tutti i campi chiave
2002-02-26 16:20:19 +00:00
const char provv = dst . get_char ( RDOC_PROVV ) ;
const int anno = dst . get_int ( RDOC_ANNO ) ;
2010-02-21 08:43:38 +00:00
const TString4 codnum = dst . get ( RDOC_CODNUM ) ;
2002-02-26 16:20:19 +00:00
const long numdoc = dst . get_long ( RDOC_NDOC ) ;
2006-07-10 13:30:29 +00:00
const int nriga = is_riga ? dst . get_int ( RDOC_NRIGA ) : 0 ;
const long idriga = is_riga ? dst . get_long ( RDOC_IDRIGA ) : 0 ;
2000-05-05 15:25:49 +00:00
// Copia tutto il record
dst = src ;
1997-06-03 15:56:27 +00:00
// Ripristina tutti i campi chiave
set_key ( dst , provv , anno , codnum , numdoc ) ;
2006-04-13 17:56:02 +00:00
dst . init_memo ( RECORD_NON_FISICO ) ;
2006-07-10 13:30:29 +00:00
if ( is_riga )
1998-11-04 18:04:26 +00:00
{
2002-02-26 16:20:19 +00:00
dst . put ( RDOC_NRIGA , nriga ) ;
dst . put ( RDOC_IDRIGA , idriga ) ;
1998-11-04 18:04:26 +00:00
dst . zero ( RDOC_MOVMAG ) ;
2002-09-13 14:06:05 +00:00
const TString memo = src . get ( RDOC_DESCEST ) ;
2002-02-26 16:20:19 +00:00
dst . put ( RDOC_DESCEST , memo ) ;
2009-04-22 16:01:06 +00:00
const TString g1 = src . get ( RDOC_RG1 ) ;
dst . put ( RDOC_RG1 , g1 ) ;
2009-05-12 23:28:00 +00:00
( ( TRiga_documento & ) dst ) . load_memo ( ) ;
}
1998-11-04 18:04:26 +00:00
else
2006-07-10 13:30:29 +00:00
{
dst . zero ( DOC_MOVMAG ) ;
dst . zero ( DOC_NUMREG ) ;
dst . zero ( DOC_NUMREGCA ) ;
2010-03-03 13:42:20 +00:00
dst . put ( DOC_NOTE , src . get ( DOC_NOTE ) ) ;
2006-07-10 13:30:29 +00:00
}
1997-06-03 15:56:27 +00:00
}
2002-09-13 14:06:05 +00:00
// Funzione statica utile a tutti gli utenti di LF_RIGHEDOC
void TDocumento : : copy_data ( TRiga_documento & dst , const TRiga_documento & src )
{
copy_data ( ( TRectype & ) dst , ( const TRectype & ) src ) ;
dst . put ( RDOC_CODCMS , src . codice_commessa ( ) ) ;
dst . put ( RDOC_FASCMS , src . fase_commessa ( ) ) ;
2005-05-17 13:45:22 +00:00
dst . put ( RDOC_CODCOSTO , src . codice_costo ( ) ) ;
2002-09-13 14:06:05 +00:00
}
1997-05-23 14:26:19 +00:00
2006-04-13 17:56:02 +00:00
void TDocumento : : copy_contents ( const TDocumento & src , bool copy_header )
1997-06-03 15:56:27 +00:00
{
2006-04-13 17:56:02 +00:00
if ( copy_header )
copy_data ( head ( ) , src . head ( ) ) ;
1997-06-03 15:56:27 +00:00
destroy_rows ( ) ;
1999-04-06 15:34:39 +00:00
const int rows = src . physical_rows ( ) ;
for ( int i = 1 ; i < = rows ; i + + )
1997-05-23 14:26:19 +00:00
{
1999-04-06 15:34:39 +00:00
const TRiga_documento & s = src [ i ] ;
1997-06-03 15:56:27 +00:00
TRiga_documento & r = new_row ( s . tipo ( ) . codice ( ) ) ;
copy_data ( r , s ) ;
1999-10-22 10:00:18 +00:00
r . set_original_rdoc_key ( s ) ;
1997-06-03 15:56:27 +00:00
}
}
TRiga_documento & TDocumento : : insert_row ( int row , const char * tipo )
{
2006-04-13 17:56:02 +00:00
TRiga_documento & r = ( TRiga_documento & ) TMultiple_rectype : : insert_row ( row ) ;
2006-01-09 01:15:53 +00:00
if ( tipo & & * tipo )
1998-11-04 18:04:26 +00:00
r . set_tipo ( tipo ) ;
1997-08-18 16:06:51 +00:00
return r ;
1997-06-03 15:56:27 +00:00
}
TRiga_documento & TDocumento : : new_row ( const char * tipo )
{
2006-04-13 17:56:02 +00:00
TRiga_documento & r = ( TRiga_documento & ) TMultiple_rectype : : new_row ( ) ;
2008-11-26 10:47:53 +00:00
r . set_doc ( this ) ;
2006-01-09 01:15:53 +00:00
if ( tipo & & * tipo )
1998-11-04 18:04:26 +00:00
r . set_tipo ( tipo ) ;
1997-06-03 15:56:27 +00:00
return r ;
}
1997-06-12 16:26:22 +00:00
int TDocumento : : read ( TBaseisamfile & f , word op , word lockop )
1999-05-24 13:34:11 +00:00
{
2013-05-06 08:57:55 +00:00
int err = TMultiple_rectype : : read ( f , op , lockop ) ;
1998-11-04 18:04:26 +00:00
1997-06-12 16:26:22 +00:00
_cli_for . zero ( ) ;
_occas . zero ( ) ;
1998-11-04 18:04:26 +00:00
1997-06-03 15:56:27 +00:00
set_riga_sconto ( ) ;
if ( is_fattura ( ) )
set_riga_esenzione ( ) ;
1997-08-28 17:11:17 +00:00
_stato_originale = stato ( ) ;
1998-08-25 18:07:30 +00:00
2013-05-06 08:57:55 +00:00
if ( err = = NOERR & & _has_stat_ven & & tipo_valido ( ) & & tipo ( ) . statistiche ( ) )
1997-09-26 15:22:39 +00:00
{
2013-05-06 08:57:55 +00:00
const TDoc_key key ( head ( ) ) ;
2006-04-13 17:56:02 +00:00
TObject * o = _docs_to_agg . objptr ( key ) ;
2000-05-05 15:25:49 +00:00
const bool is_nota_credito = tipo ( ) . nota_credito ( ) ;
2013-05-06 08:57:55 +00:00
if ( lockop > = _lock & & o = = NULL )
1997-09-26 15:22:39 +00:00
{
2013-05-06 08:57:55 +00:00
TStats_agg * st_agg = new TStats_agg ;
1997-09-26 15:22:39 +00:00
for ( int i = physical_rows ( ) ; i > 0 ; i - - )
2013-05-06 08:57:55 +00:00
{
2000-05-05 15:25:49 +00:00
if ( is_nota_credito )
2002-02-26 16:20:19 +00:00
st_agg - > add ( row ( i ) ) ;
2000-05-05 15:25:49 +00:00
else
2002-02-26 16:20:19 +00:00
st_agg - > sub ( row ( i ) ) ;
2013-05-06 08:57:55 +00:00
}
2011-04-11 13:56:36 +00:00
_docs_to_agg . add ( key , st_agg , true ) ;
1997-09-26 15:22:39 +00:00
}
else
2013-05-06 08:57:55 +00:00
{
1997-09-26 15:22:39 +00:00
if ( lockop = = _unlock & & o ! = NULL )
_docs_to_agg . remove ( key ) ;
2013-05-06 08:57:55 +00:00
}
1997-09-26 15:22:39 +00:00
}
1999-07-16 14:59:11 +00:00
2009-03-10 14:31:20 +00:00
_old_agente . cut ( 0 ) ;
_old_agente1 . cut ( 0 ) ;
if ( err = = NOERR & & _has_provv )
{
1999-07-16 14:59:11 +00:00
_old_agente = get ( DOC_CODAG ) ;
2009-03-10 14:31:20 +00:00
_old_agente1 = get ( DOC_CODAGVIS ) ;
}
1998-11-04 18:04:26 +00:00
1997-06-03 15:56:27 +00:00
return err ;
}
1997-06-12 16:26:22 +00:00
int TDocumento : : read ( char provv , int anno , const char * codnum , long numdoc , word op , word lockop )
1997-06-03 15:56:27 +00:00
{
1997-08-18 16:06:51 +00:00
CHECK ( numdoc > 0 , " Numero documento nullo. " ) ;
zero ( ) ;
1997-06-12 16:26:22 +00:00
set_key ( * this , provv , anno , codnum , numdoc ) ;
return read ( op , lockop ) ;
1997-06-03 15:56:27 +00:00
}
1997-08-18 16:06:51 +00:00
long TDocumento : : renum_ndoc ( long numdoc )
1997-06-03 15:56:27 +00:00
{
if ( numdoc < = 0 )
{
2003-12-19 10:42:43 +00:00
const char tn = tipo_numerazione ( ) ;
const int an = anno ( ) ;
const TString4 nu = numerazione ( ) ;
1997-06-03 15:56:27 +00:00
numdoc = get_next_key ( tn , an , nu ) ;
}
2008-11-26 10:47:53 +00:00
put ( DOC_NDOC , numdoc ) ; // Aggiorna testata
1997-08-18 16:06:51 +00:00
TMultiple_rectype : : renum_key ( ) ; // Aggiorna righe ok
1997-06-03 15:56:27 +00:00
return numdoc ;
}
void TDocumento : : set_riga_sconto ( )
{
2010-02-07 17:16:19 +00:00
const TString80 sconto ( get ( DOC_SCONTOPERC ) ) ;
1997-06-03 15:56:27 +00:00
2010-05-03 11:19:29 +00:00
if ( ! is_real_discount ( sconto ) )
1997-06-03 15:56:27 +00:00
{
if ( _sconto ! = NULL )
delete _sconto ;
_sconto = NULL ;
1997-05-23 14:26:19 +00:00
}
else
1997-06-03 15:56:27 +00:00
{
if ( _sconto = = NULL )
{
2008-03-26 11:24:36 +00:00
static TString4 _tipo_riga_sc ;
1997-06-03 15:56:27 +00:00
if ( _tipo_riga_sc . empty ( ) )
{
2000-05-05 15:25:49 +00:00
TConfig conf ( CONFIG_STUDIO , " ve " ) ;
1997-06-03 15:56:27 +00:00
_tipo_riga_sc = conf . get ( " TRSCONTI " , " ve " ) ;
1998-08-25 18:07:30 +00:00
// Se non esiste il tipo riga lo cerca, lo setta di default ed avvisa
if ( _tipo_riga_sc . empty ( ) )
{
2000-05-05 15:25:49 +00:00
_tipo_riga_sc = " 08 " ;
conf . set ( " TRSCONTI " , _tipo_riga_sc ) ;
2013-03-15 11:08:44 +00:00
warning_box ( FR ( " Il tipo riga sconti di testa non risultava impostato. \n L'applicazione user<65> automaticamente il tipo %s " ) , ( const char * ) _tipo_riga_sc ) ;
1998-08-25 18:07:30 +00:00
}
1997-06-03 15:56:27 +00:00
}
_sconto = new TRiga_documento ( this , _tipo_riga_sc ) ;
2008-03-26 11:24:36 +00:00
_sconto - > put ( RDOC_DESCR , TR ( " Sconto " ) ) ;
1997-06-03 15:56:27 +00:00
}
2008-03-26 11:24:36 +00:00
_sconto - > put ( RDOC_SCONTO , sconto ) ;
1997-06-03 15:56:27 +00:00
}
}
1997-05-23 14:26:19 +00:00
2011-06-24 12:28:22 +00:00
void TDocumento : : update_esenzione ( )
{
if ( clifor ( ) . use_lettere ( ) )
{
bool to_update = false ;
2013-03-15 11:08:44 +00:00
const TString4 codiva = codesiva ( ) ;
2011-06-24 12:28:22 +00:00
for ( int i = physical_rows ( ) ; ! to_update & & i > 0 ; i - - )
{
const TString & cod = row ( i ) . get ( RDOC_CODIVA ) ;
to_update = cod . full ( ) & & cod ! = codiva ;
}
2013-03-15 11:08:44 +00:00
2011-06-24 12:28:22 +00:00
if ( to_update )
2013-03-15 11:08:44 +00:00
for ( int i = physical_rows ( ) ; i > 0 ; i - - )
2011-06-24 12:28:22 +00:00
{
TRiga_documento & rdoc = row ( i ) ;
2013-03-15 11:08:44 +00:00
const TString & cod = rdoc . get ( RDOC_CODIVA ) ;
2011-06-24 12:28:22 +00:00
if ( cod . full ( ) )
{
if ( codiva . full ( ) )
rdoc . put ( RDOC_CODIVA , codiva ) ;
else
{
2013-03-15 11:08:44 +00:00
const TCodiceIVA i ( cod ) ;
2011-06-24 12:28:22 +00:00
const bool plafond = i . get_int ( " S3 " ) > 0 ;
if ( plafond )
{
2013-03-15 11:08:44 +00:00
TString4 codivarow ;
2011-06-24 12:28:22 +00:00
if ( rdoc . is_merce ( ) )
codivarow = cached_article ( rdoc . get ( RDOC_CODARTMAG ) ) . get ( ANAMAG_CODIVA ) ;
else
if ( rdoc . is_spese ( ) )
{
2013-03-15 11:08:44 +00:00
const TSpesa_prest s ( rdoc . get ( RDOC_CODART ) ) ;
2011-06-24 12:28:22 +00:00
codivarow = s . cod_iva ( ) ;
}
else
if ( rdoc . is_prestazione ( ) )
{
2013-03-15 11:08:44 +00:00
TSpesa_prest p ( rdoc . get ( RDOC_CODART ) , ' P ' ) ;
2011-06-24 12:28:22 +00:00
codivarow = p . cod_iva ( ) ;
}
else
if ( rdoc . is_risorsa ( ) )
{
2013-03-15 11:08:44 +00:00
TSpesa_prest r ( rdoc . get ( RDOC_CODART ) , ' R ' ) ;
2011-06-24 12:28:22 +00:00
codivarow = r . cod_iva ( ) ;
}
else
if ( rdoc . is_attrezzatura ( ) )
{
2013-03-15 11:08:44 +00:00
TSpesa_prest a ( rdoc . get ( RDOC_CODART ) , ' A ' ) ;
2011-06-24 12:28:22 +00:00
codivarow = a . cod_iva ( ) ;
}
if ( codivarow . full ( ) )
rdoc . put ( RDOC_CODIVA , codivarow ) ;
}
}
}
}
}
}
1997-06-03 15:56:27 +00:00
void TDocumento : : set_riga_esenzione ( )
{
1997-06-12 16:26:22 +00:00
TCli_for & c = clifor ( ) ;
2000-05-05 15:25:49 +00:00
const TCodiceIVA codes ( c . vendite ( ) . get ( CFV_ASSFIS ) ) ;
2008-08-27 23:23:05 +00:00
TString16 v_esenzione ;
TString16 v_data_esenzione ;
TString16 n_registrazione ;
TString16 n_data_registrazione ;
if ( codes . codice ( ) . full ( ) )
get_protocolli_esenzione ( v_esenzione , v_data_esenzione , n_registrazione , n_data_registrazione ) ;
1997-06-03 15:56:27 +00:00
bool esente = codes . tipo ( ) . not_empty ( ) & & v_esenzione . not_empty ( ) & &
v_data_esenzione . not_empty ( ) & & n_registrazione . not_empty ( ) & &
n_data_registrazione . not_empty ( ) ;
if ( esente )
1997-05-23 14:26:19 +00:00
{
2003-10-17 13:48:47 +00:00
esente = false ;
2013-03-15 11:08:44 +00:00
const TString4 codiva = codes . codice ( ) ;
1997-06-03 15:56:27 +00:00
for ( int i = physical_rows ( ) ; ! esente & & i > 0 ; i - - )
2003-10-17 13:48:47 +00:00
esente = row ( i ) . get ( RDOC_CODIVA ) = = codiva ;
}
1997-05-23 14:26:19 +00:00
1997-06-03 15:56:27 +00:00
if ( ! esente )
{
2013-03-15 11:08:44 +00:00
if ( _esenzione ! = NULL )
{
1997-06-03 15:56:27 +00:00
delete _esenzione ;
2013-03-15 11:08:44 +00:00
_esenzione = NULL ;
}
1997-06-03 15:56:27 +00:00
}
else
{
2003-10-17 13:48:47 +00:00
static TString4 _tipo_riga_es ;
2002-02-26 16:20:19 +00:00
static TString80 _des_esenz ;
1997-06-03 15:56:27 +00:00
static real _bollo_es ;
if ( _tipo_riga_es . empty ( ) )
{
2000-05-05 15:25:49 +00:00
TConfig conf ( CONFIG_STUDIO , " ve " ) ;
1997-06-03 15:56:27 +00:00
_tipo_riga_es = conf . get ( " TRESENZ " , " ve " ) ;
_bollo_es = ( real ) conf . get ( " BOLLIES " , " ve " ) ;
2000-05-05 15:25:49 +00:00
if ( _tipo_riga_es . empty ( ) )
{
_tipo_riga_es = " 05 " ;
conf . set ( " TRESENZ " , _tipo_riga_es ) ;
warning_box ( " Il tipo riga esenzione non risultava impostato. \n L'applicazione usera' automaticamente il tipo %s " , ( const char * ) _tipo_riga_es ) ;
2002-02-26 16:20:19 +00:00
}
_des_esenz = conf . get ( " DESESENZ " , " ve " ) ;
if ( _des_esenz . not_empty ( ) )
_des_esenz . insert ( " " ) ;
_des_esenz . insert ( " Fattura non imponibile " ) ;
1997-06-03 15:56:27 +00:00
}
if ( _esenzione = = NULL )
_esenzione = new TRiga_documento ( this , _tipo_riga_es ) ;
2002-02-26 16:20:19 +00:00
TString d ( 256 ) ; d = _des_esenz ;
1997-06-03 15:56:27 +00:00
2002-02-26 16:20:19 +00:00
d < < format ( " come da vostra dichiarazione n. %s del %s da noi annotata al n. %s il %s. " ,
( const char * ) v_esenzione , ( const char * ) v_data_esenzione ,
( const char * ) n_registrazione , ( const char * ) n_data_registrazione ) ;
2003-12-15 14:25:45 +00:00
_esenzione - > put ( RDOC_DESCR , d . left ( 50 ) ) ;
_esenzione - > put ( RDOC_DESCLUNGA , " X " ) ;
_esenzione - > put ( RDOC_DESCEST , d . mid ( 50 ) ) ;
1997-05-23 14:26:19 +00:00
}
1997-06-03 15:56:27 +00:00
}
void TDocumento : : dirty_fields ( )
{
1999-06-18 15:35:05 +00:00
if ( ! _dirty_deny )
1997-06-03 15:56:27 +00:00
{
1999-06-18 15:35:05 +00:00
for ( TDocumento_variable_field * f = ( TDocumento_variable_field * ) first_variable_field ( ) ;
f ! = NULL ; f = ( TDocumento_variable_field * ) succ_variable_field ( ) )
f - > set_dirty ( ) ;
dirty_tabella_iva ( ) ;
2006-01-09 01:15:53 +00:00
2006-02-07 18:25:20 +00:00
if ( loaded_rows ( LF_RIGHEDOC ) ) // Se ho gia' caricato delle righe in memoria
{
TRecord_array & righe = body ( LF_RIGHEDOC ) ;
for ( int i = righe . last_row ( ) ; i > 0 ; i = righe . pred_row ( i ) )
{
TRiga_documento & r = ( TRiga_documento & ) righe [ i ] ;
r . dirty_fields ( FALSE ) ;
}
}
2005-06-24 17:05:02 +00:00
_dirty_deny = true ;
1999-06-18 15:35:05 +00:00
}
1997-06-03 15:56:27 +00:00
}
2009-11-10 14:46:54 +00:00
static TToken_string * __key ;
HIDDEN int sort_doc_rows ( const TObject * * r0 , const TObject * * r1 )
{
2009-11-16 15:58:36 +00:00
TRiga_documento * row0 = ( TRiga_documento * ) * r0 ;
TRiga_documento * row1 = ( TRiga_documento * ) * r1 ;
2009-11-10 14:46:54 +00:00
int res = 0 ;
2009-11-16 15:58:36 +00:00
TString val0 , val1 ;
TToken_string valist ( 50 , ' , ' ) ;
2009-11-10 14:46:54 +00:00
2009-11-16 15:58:36 +00:00
FOR_EACH_STR_TOKEN ( * __key , fldname )
{
int direction = + 1 ;
if ( fldname [ 0 ] = = ' - ' )
{
direction = - 1 ;
fldname . ltrim ( 1 ) ;
}
const int par = fldname . find ( ' ( ' ) ;
if ( par > 0 )
{
valist = fldname . mid ( par + 1 ) ;
valist . strip ( " () " ) ;
fldname . cut ( par ) ;
}
else
valist . cut ( 0 ) ;
2009-11-10 14:46:54 +00:00
const TFieldref fld ( fldname , 0 ) ;
val0 = fld . read ( * row0 ) ;
val1 = fld . read ( * row1 ) ;
switch ( row0 - > type ( fld . name ( ) ) )
{
case _intfld :
case _longfld :
case _realfld :
case _wordfld :
{
const real r0 = val0 ;
const real r1 = val1 ;
if ( r0 ! = r1 )
2009-11-16 15:58:36 +00:00
res = ( r0 < r1 ? - 1 : 1 ) * direction ;
2009-11-10 14:46:54 +00:00
}
break ;
case _datefld :
{
const TDate d0 = val0 ;
const TDate d1 = val1 ;
if ( d0 ! = d1 )
2009-11-16 15:58:36 +00:00
res = ( d0 < d1 ? - 1 : 1 ) * direction ;
2009-11-10 14:46:54 +00:00
}
break ;
default :
if ( val0 ! = val1 )
2009-11-16 15:58:36 +00:00
{
if ( valist . full ( ) )
{
int pos0 = valist . get_pos ( val0 ) ; if ( pos0 < 0 ) pos0 = valist . items ( ) ;
int pos1 = valist . get_pos ( val1 ) ; if ( pos1 < 0 ) pos1 = valist . items ( ) ;
res = ( pos0 - pos1 ) * direction ;
}
else
res = xvt_str_compare_ignoring_case ( val0 , val1 ) * direction ;
}
2009-11-10 14:46:54 +00:00
break ;
}
if ( res ! = 0 )
break ;
}
return res ;
}
2009-11-16 15:58:36 +00:00
void TDocumento : : sort_rows ( const char * key )
2009-11-10 14:46:54 +00:00
{
__key = new TToken_string ( key ) ;
body ( ) . sort ( sort_doc_rows ) ;
delete __key ;
__key = NULL ;
}
2009-12-23 14:25:37 +00:00
static real doc_inventory_qta ( const TCausale_magazzino & cau , const TString & codart , const TString & codmag ,
const TString & livello , int anno , const real & qta )
{
const real giac = cached_article_balances ( codart ) . giacenza_anno ( codmag , livello , anno ) ;
real q = qta - giac ;
switch ( cau . sgn ( s_giac ) )
{
2014-03-07 14:42:05 +00:00
case 1 : break ;
case - 1 : q = - q ; break ;
default : break ;
2009-12-23 14:25:37 +00:00
}
return q ;
}
1997-06-12 16:26:22 +00:00
int TDocumento : : write_rewrite ( TBaseisamfile & f , bool re ) const
2009-11-10 14:46:54 +00:00
{
2007-09-17 15:33:04 +00:00
TDocumento & myself = * ( ( TDocumento * ) this ) ;
1997-08-18 16:06:51 +00:00
const bool new_doc = nuovo ( ) | | numero ( ) < = 0 ; // E' nuovo di zecca!
2009-11-10 14:46:54 +00:00
1997-08-18 16:06:51 +00:00
if ( new_doc )
{
char stato_finale = tipo ( ) . stato_finale_inserimento ( ) ;
2001-05-02 13:40:49 +00:00
if ( stato ( ) = = ' \0 ' & & stato_finale > ' ' )
1997-08-18 16:06:51 +00:00
myself . stato ( stato_finale ) ;
}
else
1997-08-28 17:11:17 +00:00
myself . _stato_originale = stato ( ) ;
1997-08-18 16:06:51 +00:00
2000-05-05 15:25:49 +00:00
const bool doc_bloccato = bloccato ( ) ;
1997-08-18 16:06:51 +00:00
const char stato_doc ( stato ( ) ) ;
2000-05-05 15:25:49 +00:00
int err = NOERR ;
1997-06-27 09:21:13 +00:00
2000-05-05 15:25:49 +00:00
if ( ! doc_bloccato )
1997-08-01 09:20:02 +00:00
{
2008-01-17 11:12:05 +00:00
if ( tipo ( ) . spese_aut ( ) & & ! get_bool ( DOC_SPESEUPD ) )
2000-05-05 15:25:49 +00:00
{
2008-03-26 11:24:36 +00:00
char name [ 8 ] = " CODSP0 " ;
2000-05-05 15:25:49 +00:00
TString_array spese ;
2013-12-13 09:44:56 +00:00
const TRectype & ven_rec = clifor ( ) . vendite ( ) ;
2000-05-05 15:25:49 +00:00
for ( int i = 1 ; i < = 4 ; i + + )
{
2008-03-26 11:24:36 +00:00
name [ 5 ] = ' 0 ' + i ;
2008-01-17 11:12:05 +00:00
const TString & s = ven_rec . get ( name ) ;
2007-05-30 16:46:56 +00:00
if ( s . full ( ) )
2000-05-05 15:25:49 +00:00
spese . add ( s ) ;
}
myself . update_spese_aut ( spese ) ;
}
myself . update_conai ( ) ;
2008-03-26 11:24:36 +00:00
myself . update_raee ( ) ;
2000-05-05 15:25:49 +00:00
myself . set_row_ids ( ) ;
2013-12-13 09:44:56 +00:00
myself . put ( DOC_UTENTE , user ( ) ) ;
myself . put ( DOC_DATAAGG , TDate ( TODAY ) ) ;
1997-06-27 09:21:13 +00:00
2013-05-06 08:57:55 +00:00
const bool check_movmag = _has_mag & & tipo ( ) . mov_mag ( ) ;
2000-05-05 15:25:49 +00:00
if ( check_movmag )
{
2013-12-13 09:44:56 +00:00
const bool do_movmag = tipo ( ) . stato_with_mov_mag ( stato_doc ) & & get ( DOC_CAUSMAG ) . full ( ) ;
2006-12-13 16:22:33 +00:00
long num_movmag = get_long ( DOC_MOVMAG ) ;
2009-12-23 14:25:37 +00:00
bool diff_inv = get_bool ( " DIFFINV " ) ;
2002-05-08 16:25:49 +00:00
2000-05-05 15:25:49 +00:00
TMov_mag_doc mov ;
TLocalisamfile m ( LF_MOVMAG ) ;
mov . zero ( ) ;
2011-09-12 14:13:15 +00:00
if ( ! new_doc & & do_movmag & & num_movmag < = 0 )
2011-02-26 22:49:55 +00:00
{
m . setkey ( 6 ) ;
m . zero ( ) ;
m . put ( MOVMAG_DOCPROVV , myself . get ( DOC_PROVV ) ) ;
m . put ( MOVMAG_ANNODOC , myself . anno ( ) ) ;
m . put ( MOVMAG_CODNUM , myself . numerazione ( ) ) ;
m . put ( MOVMAG_NUMDOC , myself . numero ( ) ) ;
if ( m . read ( _isequal ) = = NOERR )
{
num_movmag = m . get_long ( MOVMAG_NUMREG ) ;
myself . put ( DOC_MOVMAG , num_movmag ) ;
}
m . setkey ( 1 ) ;
m . zero ( ) ;
}
if ( do_movmag & & num_movmag < = 0 )
1997-08-18 16:06:51 +00:00
{
2000-05-05 15:25:49 +00:00
err = mov . write ( m ) ;
if ( err ! = NOERR )
return err ;
2006-12-13 16:22:33 +00:00
num_movmag = mov . get_long ( MOVMAG_NUMREG ) ;
myself . put ( DOC_MOVMAG , num_movmag ) ;
2000-05-05 15:25:49 +00:00
}
2006-12-13 16:22:33 +00:00
if ( num_movmag > 0 )
2000-05-05 15:25:49 +00:00
{
const bool scarica_residuo = tipo ( ) . scarica_residuo ( ) ;
1998-08-25 18:07:30 +00:00
2006-12-13 16:22:33 +00:00
mov . put ( MOVMAG_NUMREG , num_movmag ) ;
2000-05-05 15:25:49 +00:00
while ( mov . read ( m , _isequal , _testandlock ) = = _islocked )
2006-12-29 14:16:28 +00:00
message_box ( " Movimento di magazzino n. %ld in uso da parte di un'altro utente " , num_movmag ) ;
2000-05-05 15:25:49 +00:00
if ( do_movmag )
{
TRecord_array & b = mov . body ( ) ;
2004-04-28 22:23:16 +00:00
const int mag_rows = mov . rows ( ) ;
2006-12-29 14:16:28 +00:00
int i ;
2004-04-28 22:23:16 +00:00
for ( i = mag_rows ; i > 0 ; i - - )
2000-05-05 15:25:49 +00:00
{
TRectype & r = b [ i ] ;
if ( r . get_char ( RMOVMAG_TIPORIGA ) = = riga_dadocumento )
{
b . destroy_row ( i ) ;
if ( b . exist ( i + 1 ) & &
b [ i + 1 ] . get_char ( RMOVMAG_TIPORIGA ) = = riga_automatica )
b . destroy_row ( i + 1 ) ;
}
else
if ( r . get_bool ( RMOVMAG_ESPLOSA ) )
b . destroy_row ( i ) ;
}
b . pack ( ) ;
2006-12-13 16:22:33 +00:00
const TDate d ( get ( DOC_DATADOC ) ) ;
TString4 codes ; codes . format ( " %04d " , mov . codice_esercizio ( d ) ) ;
2003-02-25 14:39:02 +00:00
mov . put ( MOVMAG_ANNOES , codes ) ;
2000-05-05 15:25:49 +00:00
mov . put ( MOVMAG_DATAREG , d ) ;
mov . put ( MOVMAG_DATACOMP , d ) ;
2006-12-13 16:22:33 +00:00
mov . put ( MOVMAG_DOCPROVV , get ( DOC_PROVV ) ) ;
2009-12-23 14:25:37 +00:00
mov . put ( MOVMAG_ANNODOC , get ( DOC_ANNO ) ) ;
2006-12-13 16:22:33 +00:00
mov . put ( MOVMAG_CODNUM , get ( DOC_CODNUM ) ) ;
long numdoc = get_long ( DOC_NDOC ) ;
2001-05-02 13:40:49 +00:00
if ( numdoc < = 0L )
numdoc = myself . renum_ndoc ( numdoc ) ;
2000-05-05 15:25:49 +00:00
mov . put ( MOVMAG_NUMDOC , numdoc ) ;
2006-12-13 16:22:33 +00:00
const long ex_numdoc = get_long ( DOC_NUMDOCRIF ) ;
2000-05-05 15:25:49 +00:00
if ( ex_numdoc = = 0 )
1997-06-27 09:21:13 +00:00
{
2000-05-05 15:25:49 +00:00
mov . put ( MOVMAG_EXNUMDOC , numdoc ) ;
mov . put ( MOVMAG_EXDATADOC , d ) ;
1997-06-27 09:21:13 +00:00
}
1999-04-06 15:34:39 +00:00
else
2000-05-05 15:25:49 +00:00
{
mov . put ( MOVMAG_EXNUMDOC , ex_numdoc ) ;
const TDate ex_d ( get ( " DATADOCRIF " ) ) ;
mov . put ( MOVMAG_EXDATADOC , ex_d ) ;
}
mov . put ( MOVMAG_CATVEN , get ( " CATVEN " ) ) ;
mov . put ( MOVMAG_CODLIST , get ( " CODLIST " ) ) ;
mov . put ( MOVMAG_CODCONT , get ( " CODCONT " ) ) ;
mov . put ( MOVMAG_CODCAMP , get ( " CODCAMP " ) ) ;
mov . put ( MOVMAG_CODCAUS , get ( " CAUSMAG " ) ) ;
2006-07-10 13:30:29 +00:00
const TString4 codnum ( numerazione ( ) ) ;
2006-12-13 16:22:33 +00:00
2000-05-05 15:25:49 +00:00
mov . put ( MOVMAG_DESCR , format ( " %s %s n. %ld del %s " , ( const char * ) tipo ( ) . get ( " S1 " ) , ( const char * ) codnum , numdoc , ( const char * ) d . string ( ) ) ) ;
mov . put ( MOVMAG_TIPOCF , get ( " TIPOCF " ) ) ;
mov . put ( MOVMAG_CODCF , get ( " CODCF " ) ) ;
2009-12-03 15:32:33 +00:00
if ( ini_get_bool ( CONFIG_DITTA , " mg " , " MOV_INDSPED " ) )
mov . put ( MOVMAG_CODINDSP , get ( DOC_CODINDSP ) ) ;
2000-05-05 15:25:49 +00:00
int j = 1 ;
real cambio = ZERO ;
if ( get ( DOC_CODVAL ) . not_empty ( ) )
cambio = get_real ( DOC_CAMBIO ) ;
if ( cambio = = ZERO )
cambio = 1.0 ;
2006-07-11 13:12:41 +00:00
const TString8 cod_caus ( mov . get ( MOVMAG_CODCAUS ) ) ;
2009-11-19 12:16:06 +00:00
const TCausale_magazzino & caus = cached_causale_magazzino ( cod_caus ) ;
2006-07-11 13:12:41 +00:00
const bool esplodente = caus . esplodente ( ) ;
const bool scarica_alt = caus . scarica_alternativi ( ) ;
2006-12-13 16:22:33 +00:00
TString8 cod_caus_riga ;
2000-05-05 15:25:49 +00:00
TDistinta_tree dist ;
2006-12-13 16:22:33 +00:00
TCodice_articolo codart ;
2009-12-23 14:25:37 +00:00
const int anno = get_int ( DOC_ANNO ) ;
1997-06-27 09:21:13 +00:00
2006-04-13 17:56:02 +00:00
for ( i = 1 ; i < = physical_rows ( ) ; i + + )
2000-05-05 15:25:49 +00:00
{
TRiga_documento & r = myself . row ( i ) ;
const bool articolo = r . is_articolo ( ) ;
2006-07-11 13:12:41 +00:00
bool valid_row = articolo ;
2007-09-17 15:33:04 +00:00
cod_caus_riga = r . get ( RDOC_CAUSMAG ) ;
2006-07-11 13:12:41 +00:00
if ( articolo )
2007-09-17 15:33:04 +00:00
codart = r . get ( RDOC_CODARTMAG ) ;
2006-07-11 13:12:41 +00:00
else
{
2007-09-17 15:33:04 +00:00
codart = r . get ( RDOC_CODART ) ;
2008-10-07 00:50:22 +00:00
if ( codart . full ( ) & & ( cod_caus_riga . full ( ) ? cached_causale_magazzino ( cod_caus_riga ) . esplodente ( ) : esplodente ) )
2006-12-13 16:22:33 +00:00
valid_row = dist . set_root ( codart ) ;
2006-07-11 13:12:41 +00:00
}
if ( valid_row )
2000-05-05 15:25:49 +00:00
{
2006-12-13 16:22:33 +00:00
long r_num = r . get_long ( RDOC_MOVMAG ) ;
2000-05-05 15:25:49 +00:00
if ( r_num = = 0 )
{
2006-12-13 16:22:33 +00:00
r_num = num_movmag ;
r . put ( RDOC_MOVMAG , r_num ) ;
2000-05-05 15:25:49 +00:00
}
2009-12-23 14:25:37 +00:00
real qta = scarica_residuo ? r . qtaresidua_mag ( ) : r . quantita_mag ( ) ;
2000-05-05 15:25:49 +00:00
2006-12-13 16:22:33 +00:00
if ( r_num = = num_movmag & & ! qta . is_zero ( ) )
2000-05-05 15:25:49 +00:00
{
TRectype & rm = mov . insert_row ( j + + ) ;
1998-11-04 18:04:26 +00:00
2007-09-17 15:33:04 +00:00
mov . add_magc ( r . get ( RDOC_CODMAGC ) ) ;
1998-11-04 18:04:26 +00:00
2007-09-17 15:33:04 +00:00
rm . put ( RMOVMAG_IMPIANTO , r . get ( RDOC_IMPIANTO ) ) ;
rm . put ( RMOVMAG_LINEA , r . get ( RDOC_LINEA ) ) ;
2009-12-23 14:25:37 +00:00
const TString8 codmag = r . get ( RDOC_CODMAG ) ;
rm . put ( RMOVMAG_CODMAG , codmag ) ;
2008-10-07 00:50:22 +00:00
if ( articolo & & ( cod_caus_riga . full ( ) ? cached_causale_magazzino ( cod_caus_riga ) . scarica_alternativi ( ) : scarica_alt ) )
2006-07-11 13:12:41 +00:00
{
const TRectype art = cache ( ) . get ( LF_ANAMAG , codart ) ;
const TString & alt = art . get ( ANAMAG_CODARTALT ) ;
if ( alt . full ( ) )
codart = alt ;
}
2000-05-05 15:25:49 +00:00
rm . put ( RMOVMAG_CODART , codart ) ;
2009-12-23 14:25:37 +00:00
const TString livello = r . get ( RDOC_LIVELLO ) ;
rm . put ( RMOVMAG_LIVGIAC , livello ) ;
2007-09-17 15:33:04 +00:00
rm . put ( RMOVMAG_UM , r . get ( RDOC_UMQTA ) ) ;
1998-08-25 18:07:30 +00:00
2009-12-23 14:25:37 +00:00
if ( diff_inv )
qta = doc_inventory_qta ( ( cod_caus_riga . full ( ) ? cached_causale_magazzino ( cod_caus_riga ) : caus ) , codart ,
codmag , livello , anno , qta ) ;
2000-05-05 15:25:49 +00:00
rm . put ( RMOVMAG_QUANT , qta ) ;
2011-04-11 13:56:36 +00:00
TCurrency_documento prezzo ( r . prezzo ( true , FALSE ) , * this , true ) ;
2000-05-05 15:25:49 +00:00
prezzo . change_to_firm_val ( ) ;
rm . put ( RMOVMAG_PREZZO , prezzo . get_num ( ) ) ;
2006-07-11 13:12:41 +00:00
rm . put ( RMOVMAG_CODCAUS , cod_caus_riga ) ;
2000-05-05 15:25:49 +00:00
rm . put ( RMOVMAG_TIPORIGA , ( char ) riga_dadocumento ) ;
}
2008-10-28 20:15:28 +00:00
if ( main_app ( ) . has_module ( LVAUT ) )
{
const TString & codcauslav = r . get ( RDOC_CODAGG1 ) ;
const TRectype & caulav = cache ( ) . get ( " &LVCAU " , codcauslav ) ;
if ( ! caulav . empty ( ) )
{
2010-01-31 13:20:35 +00:00
if ( ! qta . is_zero ( ) & & ( j > 1 ) )
2009-12-16 23:36:31 +00:00
{
const TString & causcons = caulav . get ( " S2 " ) ;
2008-10-28 20:15:28 +00:00
2010-01-31 13:20:35 +00:00
if ( causcons . full ( ) )
2010-02-21 08:43:38 +00:00
{
2010-01-31 13:20:35 +00:00
mov [ LF_RMOVMAG ] [ j - 1 ] . put ( RMOVMAG_CODCAUS , causcons ) ;
2010-02-21 22:42:20 +00:00
mov [ LF_RMOVMAG ] [ j - 1 ] . put ( RMOVMAG_CODMAG , r . get ( RDOC_CODMAGC ) ) ;
2010-02-21 08:43:38 +00:00
mov . reset_magc ( j - 1 ) ;
}
2010-01-31 13:20:35 +00:00
else
2010-02-21 08:43:38 +00:00
{
2010-01-31 13:20:35 +00:00
mov . destroy_row ( - - j , true ) ;
2010-02-21 08:43:38 +00:00
mov . destroy_magc ( j ) ;
}
2009-12-16 23:36:31 +00:00
}
2008-10-28 20:15:28 +00:00
2009-12-16 23:36:31 +00:00
const real qtarit = r . get ( RDOC_QTAGG1 ) ;
const TString & causrit = caulav . get ( " S1 " ) ;
if ( r_num = = num_movmag & & ! qtarit . is_zero ( ) & & causrit . full ( ) )
2008-10-28 20:15:28 +00:00
{
TRectype & rm = mov . insert_row ( j + + ) ;
2010-02-21 08:43:38 +00:00
mov . add_magc ( " " ) ;
2008-10-28 20:15:28 +00:00
rm . put ( RMOVMAG_IMPIANTO , r . get ( RDOC_IMPIANTO ) ) ;
rm . put ( RMOVMAG_LINEA , r . get ( RDOC_LINEA ) ) ;
2010-02-21 22:42:20 +00:00
rm . put ( RMOVMAG_CODMAG , r . get ( RDOC_CODMAG ) ) ;
2008-10-28 20:15:28 +00:00
if ( articolo & & ( causrit . full ( ) ? cached_causale_magazzino ( causrit ) . scarica_alternativi ( ) : scarica_alt ) )
{
const TRectype art = cache ( ) . get ( LF_ANAMAG , codart ) ;
const TString & alt = art . get ( ANAMAG_CODARTALT ) ;
if ( alt . full ( ) )
codart = alt ;
}
rm . put ( RMOVMAG_CODART , codart ) ;
rm . put ( RMOVMAG_LIVGIAC , r . get ( RDOC_LIVELLO ) ) ;
rm . put ( RMOVMAG_UM , r . get ( RDOC_UMQTA ) ) ;
2009-12-16 23:36:31 +00:00
rm . put ( RMOVMAG_QUANT , qtarit ) ;
2008-10-28 20:15:28 +00:00
rm . put ( RMOVMAG_CODCAUS , causrit ) ;
rm . put ( RMOVMAG_TIPORIGA , ( char ) riga_dadocumento ) ;
}
}
}
}
2008-02-01 06:39:03 +00:00
const TString & indetr = r . get ( RDOC_TIPODET ) ;
if ( indetr . full ( ) )
{
const TRectype & det = cache ( ) . get ( " %DET " , indetr ) ;
if ( ! det . empty ( ) & & ! det . get_bool ( " FPC " ) )
{
TTable tab ( " %DET " ) ;
tab . curr ( ) = det ;
tab . curr ( ) . put ( " FPC " , " X " ) ;
tab . rewrite ( ) ;
}
}
1997-06-27 09:21:13 +00:00
}
2000-05-05 15:25:49 +00:00
mov . rewrite ( m ) ;
2002-05-08 16:25:49 +00:00
}
else
{
mov . remove ( m ) ;
2006-04-13 17:56:02 +00:00
for ( int i = physical_rows ( ) ; i > 0 ; i - - )
2002-05-08 16:25:49 +00:00
{
TRiga_documento & r = myself . row ( i ) ;
2006-12-13 16:22:33 +00:00
r . zero ( RDOC_MOVMAG ) ;
2000-05-05 15:25:49 +00:00
}
2006-12-13 16:22:33 +00:00
myself . zero ( DOC_MOVMAG ) ;
1997-06-27 09:21:13 +00:00
}
2000-05-05 15:25:49 +00:00
}
}
}
1997-08-26 12:38:08 +00:00
{
1997-06-27 09:21:13 +00:00
TLocalisamfile anamag ( LF_ANAMAG ) ;
TLocalisamfile codalt ( LF_CODCORR ) ;
codalt . setkey ( 2 ) ;
2011-04-11 13:56:36 +00:00
bool docevaso = true ;
2002-02-26 16:20:19 +00:00
const TDate datacons ( get_date ( DOC_DATACONS ) ) ;
const TString80 codcms ( get ( DOC_CODCMS ) ) ;
const TString80 fascms ( get ( DOC_FASCMS ) ) ;
2005-05-05 10:37:07 +00:00
const TString80 codcos ( get ( DOC_CODCOSTO ) ) ;
1998-08-25 18:07:30 +00:00
2006-04-13 17:56:02 +00:00
for ( int i = physical_rows ( ) ; i > 0 ; i - - )
1997-06-27 09:21:13 +00:00
{
2000-10-03 13:45:12 +00:00
TRiga_documento & r = myself . row ( i ) ;
2005-05-16 23:44:23 +00:00
if ( ( r . is_merce ( ) | | r . is_omaggio ( ) ) & & ! r . is_checked ( ) )
{
if ( r . get ( RDOC_CODARTMAG ) = = NULL_CODART )
r . put ( RDOC_CODARTMAG , " " ) ;
else
{
const TString & codart = r . get ( " CODART " ) ;
anamag . put ( " CODART " , codart ) ;
if ( anamag . read ( ) = = NOERR )
r . put ( " CODARTMAG " , codart ) ;
else
{
codalt . put ( " CODARTALT " , codart ) ;
if ( codalt . read ( ) = = NOERR )
r . put ( " CODARTMAG " , codalt . get ( " CODART " ) ) ;
}
r . checked ( ) ;
}
1997-06-27 09:21:13 +00:00
}
2013-12-13 09:44:56 +00:00
if ( r . is_evadibile ( ) & & datacons . ok ( ) ) // on 27-9-2013 was if (r.is_evadibile() && is_ordine())
1998-08-25 18:07:30 +00:00
{
2002-10-23 14:14:55 +00:00
docevaso & = r . is_evasa ( ) ;
2004-04-28 22:23:16 +00:00
const TDate dcons = r . get_date ( RDOC_DATACONS ) ;
1998-08-25 18:07:30 +00:00
if ( ! dcons . ok ( ) )
r . put ( RDOC_DATACONS , datacons ) ;
2002-02-26 16:20:19 +00:00
}
2013-12-13 09:44:56 +00:00
/* dal 27-9-2013 considero singolarmente i campi di analitica replicati sulle righe
2005-05-05 10:37:07 +00:00
if ( r . get ( RDOC_CODCMS ) . blank ( ) & & r . get ( RDOC_FASCMS ) . blank ( ) & & r . get ( RDOC_CODCOSTO ) . blank ( ) )
{
2002-02-26 16:20:19 +00:00
r . put ( RDOC_CODCMS , codcms ) ;
r . put ( RDOC_FASCMS , fascms ) ;
2005-05-05 10:37:07 +00:00
r . put ( RDOC_CODCOSTO , codcos ) ;
}
2013-12-13 09:44:56 +00:00
*/
if ( r . get ( RDOC_CODCMS ) . blank ( ) ) r . put ( RDOC_CODCMS , codcms ) ;
if ( r . get ( RDOC_FASCMS ) . blank ( ) ) r . put ( RDOC_FASCMS , fascms ) ;
if ( r . get ( RDOC_CODCOSTO ) . blank ( ) ) r . put ( RDOC_CODCOSTO , codcos ) ;
1997-06-27 09:21:13 +00:00
}
1998-08-25 18:07:30 +00:00
if ( is_ordine ( ) )
( ( TDocumento * ) this ) - > put ( DOC_DOCEVASO , docevaso ) ; // Tutte le righe evase -> doc evaso
} // Almeno una riga aperta -> doc aperto
1997-06-27 09:21:13 +00:00
1997-08-18 16:06:51 +00:00
err = TMultiple_rectype : : write_rewrite ( f , re ) ;
1997-06-12 16:26:22 +00:00
2000-05-05 15:25:49 +00:00
if ( ! doc_bloccato & & err = = NOERR )
1997-06-12 16:26:22 +00:00
{
1997-10-29 11:08:40 +00:00
if ( clifor ( ) . occasionale ( ) )
1997-08-04 13:52:55 +00:00
{
1997-10-29 11:08:40 +00:00
if ( get ( " OCFPI " ) . not_empty ( ) )
{
TLocalisamfile o ( LF_OCCAS ) ;
TOccasionale & occ = occas ( ) ;
err = occ . write ( o ) ;
if ( err = = _isreinsert )
err = occ . rewrite ( o ) ;
}
1997-08-04 13:52:55 +00:00
}
1998-01-23 09:57:34 +00:00
if ( _has_provv & & tipo ( ) . provvigioni ( ) & & tipo ( ) . stato_provvigioni ( ) < = stato ( ) )
2009-03-10 14:31:20 +00:00
myself . update_provvigioni ( false ) ;
2013-05-06 08:57:55 +00:00
if ( _has_stat_ven & & tipo ( ) . statistiche ( ) )
2000-05-05 15:25:49 +00:00
{
2013-05-06 08:57:55 +00:00
const TDoc_key key ( myself . head ( ) ) ;
TStats_agg * st_agg = ( TStats_agg * ) _docs_to_agg . objptr ( key ) ;
2000-05-05 15:25:49 +00:00
const bool is_nota_credito = tipo ( ) . nota_credito ( ) ;
1997-09-26 15:22:39 +00:00
2002-02-26 16:20:19 +00:00
if ( st_agg = = NULL )
{
st_agg = new TStats_agg ;
2011-04-11 13:56:36 +00:00
_docs_to_agg . add ( key , st_agg , true ) ;
2002-02-26 16:20:19 +00:00
}
2004-04-28 22:23:16 +00:00
2013-05-06 08:57:55 +00:00
for ( int i = physical_rows ( ) ; i > 0 ; i - - )
{
2000-05-05 15:25:49 +00:00
if ( is_nota_credito )
2002-02-26 16:20:19 +00:00
st_agg - > sub ( myself . row ( i ) ) ;
else
st_agg - > add ( myself . row ( i ) ) ;
2013-05-06 08:57:55 +00:00
}
2002-02-26 16:20:19 +00:00
st_agg - > update ( ) ;
2013-05-06 08:57:55 +00:00
for ( int i = physical_rows ( ) ; i > 0 ; i - - )
{
2002-02-26 16:20:19 +00:00
if ( is_nota_credito )
st_agg - > add ( myself . row ( i ) ) ;
2000-05-05 15:25:49 +00:00
else
2002-02-26 16:20:19 +00:00
st_agg - > sub ( myself . row ( i ) ) ;
2013-05-06 08:57:55 +00:00
}
2000-05-05 15:25:49 +00:00
}
1997-09-26 15:22:39 +00:00
}
1997-06-03 15:56:27 +00:00
return err ;
}
1997-06-27 09:21:13 +00:00
// eliminare anche il mov di mag. ??????
1997-06-12 16:26:22 +00:00
int TDocumento : : remove ( TBaseisamfile & f ) const
1997-06-03 15:56:27 +00:00
{
2003-06-27 15:01:34 +00:00
if ( ! cancellabile ( ) & & ! yesno_box ( " Documento non cancellabile, \n Continuare ugualmente " ) )
1997-08-18 16:06:51 +00:00
return NOERR ;
2013-05-06 08:57:55 +00:00
const bool check_movmag = _has_mag & & tipo ( ) . mov_mag ( ) ;
2005-10-07 13:41:20 +00:00
const bool doc_bloccato = bloccato ( ) ;
1997-08-04 13:52:55 +00:00
1997-08-18 16:06:51 +00:00
if ( check_movmag )
{
const long num = get_long ( " MOVMAG " ) ;
1997-08-04 13:52:55 +00:00
1997-08-18 16:06:51 +00:00
if ( num > 0 )
{
1999-04-06 15:34:39 +00:00
TMov_mag_doc mov ;
1997-08-18 16:06:51 +00:00
TLocalisamfile m ( LF_MOVMAG ) ;
mov . put ( MOVMAG_NUMREG , num ) ;
while ( mov . read ( m , _isequal , _testandlock ) = = _islocked )
message_box ( " Movimento di magazzino in uso da parte di un'altro utente " ) ;
2005-10-07 13:41:20 +00:00
if ( doc_bloccato )
{
const int rows = mov . rows ( ) ;
for ( int i = 1 ; i < = rows ; i + + )
mov . body ( ) [ i ] . zero ( RMOVMAG_TIPORIGA ) ;
mov . rewrite ( m ) ;
}
else
mov . remove ( m ) ;
1997-08-04 13:52:55 +00:00
}
}
2005-10-07 13:41:20 +00:00
if ( ! doc_bloccato )
{
2013-05-06 08:57:55 +00:00
if ( _has_stat_ven & & tipo ( ) . statistiche ( ) )
2005-10-07 13:41:20 +00:00
{
2013-05-06 08:57:55 +00:00
const TDoc_key key ( head ( ) ) ;
TStats_agg * st_agg = ( TStats_agg * ) _docs_to_agg . objptr ( key ) ;
2005-10-07 13:41:20 +00:00
if ( st_agg ! = NULL )
{
st_agg - > update ( ) ;
_docs_to_agg . remove ( key ) ;
}
}
if ( _has_provv & & tipo ( ) . provvigioni ( ) )
{
2009-03-10 14:31:20 +00:00
TDocumento & myself = * ( ( TDocumento * ) this ) ;
myself . update_provvigioni ( true ) ;
2005-10-07 13:41:20 +00:00
}
}
1997-10-13 15:22:11 +00:00
return TMultiple_rectype : : remove ( f ) ;
}
2000-05-05 15:25:49 +00:00
int TDocumento : : decimals ( bool price ) const
{
2005-05-16 23:44:23 +00:00
const TString4 codval ( get ( DOC_CODVAL ) ) ;
2004-01-12 08:48:58 +00:00
const TExchange exc ( codval ) ;
const int ndec = exc . decimals ( price ) ;
2000-05-05 15:25:49 +00:00
return ndec ;
}
1999-06-18 15:35:05 +00:00
void TDocumento : : flush_rows ( )
{
remove_body ( LF_RIGHEDOC ) ;
}
2009-03-10 14:31:20 +00:00
void TDocumento : : calc_provvigione ( TProvvigioni_agente & provv , const TString & key , bool first , bool generata )
1997-10-13 15:22:11 +00:00
{
1999-04-06 15:34:39 +00:00
const int anno = TDocumento : : anno ( ) ;
2009-03-10 14:31:20 +00:00
const TString4 codnum = numerazione ( ) ;
1999-04-06 15:34:39 +00:00
const long ndoc = numero ( ) ;
2009-03-10 14:31:20 +00:00
const TDate datadoc ( data ( ) ) ;
1997-10-13 15:22:11 +00:00
2009-03-10 14:31:20 +00:00
while ( provv . read ( key , anno , codnum , ndoc ) = = _islocked ) // Legge le provvigioni per questo documento
if ( ! yesno_box ( " Dati agente %s in uso da un altro utente. Riprovare? " , ( const char * ) key ) )
return ;
1998-01-23 09:57:34 +00:00
2000-05-05 15:25:49 +00:00
const real change ( cambio ( ) ) ;
2009-03-10 14:31:20 +00:00
const real perc = provv . perc_fatt ( ) ;
2000-05-05 15:25:49 +00:00
TCurrency_documento tot_doc ( totale_doc ( ) , * this ) ;
TCurrency_documento tot_netto ( totale_netto ( ) , * this ) ;
2009-03-10 14:31:20 +00:00
TCurrency_documento tot_provv ( provvigione ( first ) , * this ) ;
2000-05-05 15:25:49 +00:00
TCurrency_documento provv_fat ( ( tot_provv . get_num ( ) / 100.0 ) * perc , * this ) ; // Provvigione sul fatturato (rata 0)
TCurrency_documento provv_pag = tot_provv - provv_fat ; // Provvigione sul pagato (da suddivere secondo il pagamento)
1999-07-16 14:59:11 +00:00
const bool valuta = in_valuta ( ) ;
1997-10-13 15:22:11 +00:00
// Calcolo rate per provvigioni e documento
TPagamento & pag1 = pagamento ( ) ; // Per rate documento
TPagamento * pag2 = new TPagamento ( pag1 . code ( ) , datadoc . string ( ) ) ; // Per rate documento
1999-07-16 14:59:11 +00:00
// Rilegge il pagamento, nel caso in cui venga chiamata la scrittura del documento
// corrente dopo che <20> stata effettuata una contabilizzazione; la contabilizzazione
// nel caso di anticipo aggiunge una rata in pi<70>
if ( pag1 . n_rate ( ) > pag2 - > n_rate ( ) )
pag1 . read ( ) ;
2000-05-05 15:25:49 +00:00
TCurrency_documento totspese ( spese ( ) , * this ) ;
TCurrency_documento totimposte ( imposta ( ) , * this ) ;
TCurrency_documento totimponibili ( tot_doc - totimposte - totspese ) ;
TCurrency_documento anticipo ( get_real ( DOC_IMPPAGATO ) , * this ) ;
1998-08-25 18:07:30 +00:00
1999-04-06 15:34:39 +00:00
if ( is_nota_credito ( ) ) // Se il documento e' una nota di credito, cambia segno
{
tot_doc = - tot_doc ;
tot_netto = - tot_netto ;
tot_provv = - tot_provv ;
provv_fat = - provv_fat ;
provv_pag = - provv_pag ;
totspese = - totspese ;
totimposte = - totimposte ;
totimponibili = - totimponibili ;
1998-08-25 18:07:30 +00:00
}
1999-07-16 14:59:11 +00:00
// Considera l'anticipo, come in contabilizzazione ed in generazione effetti
//
// Un anticipo su di una nota di credito non dovrebbe comunque mai esistere, non ha senso.
// Se esiste <20> un errore in inserimento da parte del cliente.
2000-05-05 15:25:49 +00:00
if ( anticipo . get_num ( ) < abs ( tot_doc . get_num ( ) ) )
1997-10-13 15:22:11 +00:00
{
2000-05-05 15:25:49 +00:00
TGeneric_distrib d ( anticipo . get_num ( ) , decimals ( ) ) ;
1999-07-16 14:59:11 +00:00
2000-05-05 15:25:49 +00:00
d . add ( totimponibili . get_num ( ) ) ;
d . add ( totimposte . get_num ( ) ) ;
d . add ( totspese . get_num ( ) ) ;
1999-07-16 14:59:11 +00:00
2000-05-05 15:25:49 +00:00
const TCurrency_documento pagtotimponibili ( totimponibili . get_num ( ) - d . get ( ) , * this ) ;
const TCurrency_documento pagtotimposte ( totimposte . get_num ( ) - d . get ( ) , * this ) ;
const TCurrency_documento pagtotspese ( totspese . get_num ( ) - d . get ( ) , * this ) ;
1999-07-16 14:59:11 +00:00
2000-05-05 15:25:49 +00:00
TCurrency zero ( ZERO ) ;
1999-07-16 14:59:11 +00:00
if ( valuta )
{
2000-05-05 15:25:49 +00:00
TCurrency_documento val2 ( pagtotimposte ) ; val2 . change_to_firm_val ( ) ;
TCurrency_documento val3 ( pagtotspese ) ; val3 . change_to_firm_val ( ) ;
TCurrency_documento val1 ( tot_doc ) ; val1 . change_to_firm_val ( ) ; val1 - = val2 - val3 ;
pag1 . set_total_valuta ( pagtotimponibili , pagtotimposte , pagtotspese , val1 , val2 , val3 ) ;
TCurrency_documento provv_pag_base ( provv_pag ) ; provv_pag_base . change_to_firm_val ( ) ;
pag2 - > set_total_valuta ( provv_pag , zero , zero , provv_pag_base , zero , zero ) ;
1999-07-16 14:59:11 +00:00
}
else
{
pag1 . set_total ( pagtotimponibili , pagtotimposte , pagtotspese ) ;
2000-05-05 15:25:49 +00:00
pag2 - > set_total ( provv_pag , zero , zero ) ;
1999-07-16 14:59:11 +00:00
}
pag1 . set_rate_auto ( ) ;
pag2 - > set_rate_auto ( ) ;
1997-10-13 15:22:11 +00:00
}
else
{
1999-07-16 14:59:11 +00:00
pag1 . zap_rate ( ) ;
pag2 - > zap_rate ( ) ;
}
2000-05-05 15:25:49 +00:00
const bool is_anticipo = anticipo . get_num ( ) > ZERO ;
1999-07-16 14:59:11 +00:00
if ( is_anticipo )
{
pag1 . add_rata ( ) ;
TDate first_scad ( pag1 . data_rata ( 0 ) ) ;
if ( datadoc = = first_scad )
pag1 . set_datarata ( 0 , + + first_scad ) ;
for ( int k = pag1 . n_rate ( ) - 1 ; k > 0 ; k - - )
pag1 . rata ( k ) = pag1 . rata ( k - 1 ) ;
if ( anticipo > = tot_doc )
anticipo = tot_doc ;
2000-05-05 15:25:49 +00:00
TCurrency_documento anticipo_base ( anticipo ) ; anticipo_base . change_to_firm_val ( ) ;
1999-07-16 14:59:11 +00:00
2000-05-05 15:25:49 +00:00
pag1 . set_rata ( 0 , valuta ? anticipo . get_num ( ) : ZERO , anticipo_base . get_num ( ) , datadoc , 1 , " " , FALSE ) ;
1997-10-13 15:22:11 +00:00
}
// Crea le nuove rate provvigionali
2009-03-10 14:31:20 +00:00
const bool isnew = provv . items ( ) = = 0 ; // Il documento non ha righe provvigionali
2011-04-11 13:56:36 +00:00
TRate_doc & rd = provv . rate ( anno , codnum , ndoc , isnew ? true : FALSE ) ;
1999-07-16 14:59:11 +00:00
1997-10-13 15:22:11 +00:00
// A questo punto rd e' vuoto: settiamo i dati del documento:
TToken_string t ;
t . add ( anno ) ; t . add ( codnum ) ; t . add ( ndoc ) ;
1998-08-25 18:07:30 +00:00
t . add ( datadoc . string ( ) ) ; t . add ( tot_doc . string ( ) ) ;
t . add ( tot_provv . string ( ) ) ; t . add ( tot_netto . string ( ) ) ;
1997-10-23 09:21:54 +00:00
t . add ( codcf ( ) ) ;
1997-10-13 15:22:11 +00:00
t . add ( TDocumento : : valuta ( ) ) ; t . add ( change . string ( ) ) ;
t . add ( get ( DOC_DATACAMBIO ) ) ;
rd . set ( t ) ;
// Adesso si possono aggiungere le rate (per quelle gia' esistenti sostituisce solo alcuni valori)
// - Rata 0 : importo rata = 0; importo provvigione = provvigione all'atto della fattura (percentuale sugli agenti)
// data scadenza viene settata uguale alla data documento
// la provvigione rimanente va suddivisa in rate a seconda del codice pagamento
1999-07-16 14:59:11 +00:00
// Nel caso si ha un anticipo documento, l'importo della rata non sar<61> 0 ma eguale all'anticipo stesso
// Se poi abbiamo il caso in cui l'anticipo paga completamente il documento
// non avremo alcuna rata e tutto l'importo della provvigione del doc. andr<64> comunque
// sulla rata 0, anche se la provvigione sul fatturato <20> 0 (% a 0)
const int nrate = pag1 . n_rate ( ) ;
if ( nrate = = 1 & & is_anticipo ) // significa che l'anticipo paga tutto ora, quindi provv_fat vale tutta la provvigione del documento
provv_fat = tot_provv ;
2000-05-05 15:25:49 +00:00
const bool first_rata_ok = provv_fat . get_num ( ) ! = ZERO ;
1999-07-16 14:59:11 +00:00
// Impostazione prima rata solo se la provvigione sul fatturato <20> diversa da 0
if ( first_rata_ok )
{
2011-04-11 13:56:36 +00:00
TRata & rt = rd . row ( 0 , true ) ;
1999-07-16 14:59:11 +00:00
rt . set_rata ( 0 ) ; rt . set_datascad ( datadoc ) ; rt . set_tipopag ( 1 ) ;
2000-05-05 15:25:49 +00:00
rt . set_imprata ( anticipo . get_num ( ) ) ; rt . set_impprovv ( provv_fat . get_num ( ) ) ;
2009-03-10 14:31:20 +00:00
rt . set_generata ( generata ) ;
1999-07-16 14:59:11 +00:00
}
// Setta le rate rimanenti
2004-04-28 22:23:16 +00:00
int i ;
for ( i = 1 ; i < = nrate ; i + + )
1997-10-13 15:22:11 +00:00
{
1999-07-16 14:59:11 +00:00
if ( i = = nrate & & is_anticipo )
break ;
const int index = is_anticipo ? i : i - 1 ;
2011-04-11 13:56:36 +00:00
TRata & rt = rd . row ( first_rata_ok ? i : i - 1 , true ) ;
1997-10-13 15:22:11 +00:00
rt . set_rata ( i ) ;
1999-07-16 14:59:11 +00:00
rt . set_datascad ( pag1 . data_rata ( index ) ) ;
rt . set_tipopag ( pag1 . tipo_rata ( index ) ) ;
2011-04-11 13:56:36 +00:00
rt . set_imprata ( pag1 . importo_rata ( index , valuta ? true : FALSE ) ) ;
rt . set_impprovv ( pag2 - > importo_rata ( i - 1 , valuta ? true : FALSE ) ) ;
2009-03-10 14:31:20 +00:00
rt . set_generata ( generata ) ;
1997-10-13 15:22:11 +00:00
}
1999-07-16 14:59:11 +00:00
1997-10-13 15:22:11 +00:00
// Rimuove eventuali righe in eccesso
1998-01-23 09:57:34 +00:00
const int rd_items = rd . items ( ) ; // Rate precedenti
2002-12-20 16:15:03 +00:00
for ( i = first_rata_ok ? nrate + 1 : nrate ; i < rd_items ; i + + )
1997-10-13 15:22:11 +00:00
rd . remove_rata ( i ) ;
delete pag2 ;
1997-06-03 15:56:27 +00:00
}
2009-03-10 14:31:20 +00:00
int TDocumento : : update_provvigione ( bool remove , const bool first )
{
TProvvigioni_agente provv ;
const TString8 old = first ? _old_agente : _old_agente1 ;
const TString8 agente = first ? get ( DOC_CODAG ) : get ( DOC_CODAGVIS ) ;
const int anno = TDocumento : : anno ( ) ;
const TString & codnum = numerazione ( ) ;
const long ndoc = numero ( ) ;
const TDate datadoc ( data ( ) ) ;
int err = NOERR ;
if ( remove | | old ! = agente )
{
while ( provv . read ( old , anno , codnum , ndoc ) = = _islocked ) // Legge le provvigioni per questo documento
if ( ! yesno_box ( " Dati agente %s in uso da un altro utente. Riprovare? " , ( const char * ) old ) )
return err ;
if ( err ! = NOERR )
return err ;
err = provv . remove ( ) ;
if ( remove )
return err ;
}
if ( agente . blank ( ) )
return NOERR ;
calc_provvigione ( provv , agente , first ) ;
return provv . write ( ) ;
}
int TDocumento : : update_provvigioni ( bool remove )
{
int err ;
if ( ( err = update_provvigione ( remove ) ) = = NOERR )
err = update_provvigione ( remove , false ) ;
return err ;
}
2006-02-07 12:17:10 +00:00
1997-08-18 15:24:00 +00:00
bool TDocumento : : in_valuta ( ) const
1997-06-03 15:56:27 +00:00
{
const TString & val = valuta ( ) ;
2002-05-31 10:35:40 +00:00
return is_true_value ( val ) ;
1997-06-03 15:56:27 +00:00
}
1999-07-16 14:59:11 +00:00
TCodgiac_livelli & TDocumento : : livelli ( ) const
{
2002-05-31 10:35:40 +00:00
if ( _livelli = = NULL )
_livelli = new TCodgiac_livelli ( ) ;
1999-07-16 14:59:11 +00:00
return * _livelli ;
}
1997-08-18 16:06:51 +00:00
TRiga_documento & TDocumento : : row ( int index )
{
TRecord_array & b = body ( ) ;
2009-02-14 17:13:09 +00:00
const int nrows = b . last_row ( ) ;
1997-06-03 15:56:27 +00:00
TRiga_documento * r = NULL ;
1997-05-23 14:26:19 +00:00
1997-06-03 15:56:27 +00:00
if ( index < = nrows )
1997-08-18 15:24:00 +00:00
{
2009-02-14 17:13:09 +00:00
# ifdef DBG
if ( ! b . exist ( index ) )
{
const long ndoc = get_long ( DOC_NDOC ) ;
const int anno = get_int ( DOC_ANNO ) ;
const char * codnum = get ( DOC_CODNUM ) ;
error_box ( " Riga documento %d non esistente nel documento %d %s %ld " , index , anno , codnum , ndoc ) ;
insert_row ( index , " 05 " ) ;
}
# endif
1997-08-18 16:06:51 +00:00
r = & ( ( TRiga_documento & ) b . row ( index , FALSE ) ) ;
1997-08-18 15:24:00 +00:00
}
1997-06-03 15:56:27 +00:00
else
{
2013-12-13 09:44:56 +00:00
CHECKD ( ( index = = nrows + 1 & & ( _sconto ! = NULL | | _esenzione ! = NULL ) ) | | ( index = = nrows + 2 & & _sconto ! = NULL & & _esenzione ! = NULL ) ,
1997-06-03 15:56:27 +00:00
" Riga documento non esistente " , index ) ;
if ( index = = nrows + 1 )
{
r = _sconto ! = NULL ? _sconto : _esenzione ;
2009-02-27 16:55:21 +00:00
} else
1997-06-03 15:56:27 +00:00
if ( index = = nrows + 2 )
r = _esenzione ;
}
return * r ;
}
1998-08-25 18:07:30 +00:00
const TRiga_documento & TDocumento : : physical_row ( int index ) const
{
2013-12-13 09:44:56 +00:00
TRecord_array & b = body ( ) ;
return ( TRiga_documento & ) b . row ( index , false ) ;
1998-08-25 18:07:30 +00:00
}
1997-06-03 15:56:27 +00:00
long TDocumento : : get_next_key ( char provv , int anno , const char * codnum ) const
{
1998-08-25 18:07:30 +00:00
long n = 0 ;
1997-06-03 15:56:27 +00:00
1998-08-25 18:07:30 +00:00
TLocalisamfile doc ( LF_DOC ) ;
TRectype & curr = doc . curr ( ) ;
set_key ( curr , provv , anno , codnum , 9999999L ) ;
const int err = doc . read ( _isgreat ) ;
if ( err ! = _isemptyfile )
1997-05-23 14:26:19 +00:00
{
1998-08-25 18:07:30 +00:00
if ( err = = NOERR )
doc . prev ( ) ;
if ( curr . get_char ( " PROVV " ) = = provv & &
curr . get_int ( " ANNO " ) = = anno & &
curr . get ( " CODNUM " ) = = codnum )
n = curr . get_long ( " NDOC " ) ;
}
1997-06-03 15:56:27 +00:00
n + + ;
return n ;
}
1997-08-04 14:15:45 +00:00
const TTipo_documento & TDocumento : : tipo ( ) const
{
2006-01-31 15:33:00 +00:00
TString4 tipodoc ( get ( DOC_TIPODOC ) ) ;
# ifdef DBG
if ( tipodoc . blank ( ) ) // Test necessario per lavorare anche su dati rovinati
{
const TCodice_numerazione & codnum = codice_numerazione ( ) ;
tipodoc = codnum . tipo_doc ( 0 ) ;
yesnofatal_box ( " Tipo documento nullo su %d %s %ld \n forzato a %s " ,
get_int ( DOC_ANNO ) , ( const char * ) get ( DOC_CODNUM ) , get_long ( DOC_NDOC ) , ( const char * ) tipodoc ) ;
( ( TDocumento * ) this ) - > set_tipo ( tipodoc ) ;
}
# endif
2008-10-07 00:50:22 +00:00
return cached_tipodoc ( tipodoc ) ;
1997-08-18 15:24:00 +00:00
}
2009-02-27 16:55:21 +00:00
const TCodice_numerazione & TDocumento : : codice_numerazione ( const char * numerazione )
{
return cached_numerazione ( numerazione ) ;
}
2003-02-25 14:39:02 +00:00
const TCodice_numerazione & TDocumento : : codice_numerazione ( ) const
{
2008-10-07 00:50:22 +00:00
return cached_numerazione ( numerazione ( ) ) ;
2003-02-25 14:39:02 +00:00
}
1997-06-03 15:56:27 +00:00
bool TDocumento : : raggruppabile ( const TDocumento & doc , TToken_string & campi ) const
{
bool ok = raggruppabile ( ) & & doc . raggruppabile ( ) ;
if ( ok )
{
TString campo ;
for ( const char * c = campi . get ( 0 ) ; c & & ok ; c = campi . get ( ) )
{
2004-09-03 13:41:34 +00:00
if ( strncmp ( c , " CODABI " , 6 ) = = 0 | | strncmp ( c , " CODCAB " , 6 ) = = 0 )
{
long cod = get_long ( c ) ;
ok & = ( cod = = doc . get_long ( c ) ) ;
}
else
{
campo = get ( c ) ;
ok & = campo = = doc . get ( c ) ;
}
1997-06-03 15:56:27 +00:00
}
}
return ok ;
}
void TDocumento : : set_fields ( TAuto_variable_rectype & rec )
{
if ( tipo_valido ( ) )
{
2009-12-22 16:56:14 +00:00
TTipo_documento & tipo_doc = ( TTipo_documento & ) tipo ( ) ; // first_formula() is NOT const
const TString & tot_doc = tipo_doc . totale_doc ( ) ;
1997-05-23 14:26:19 +00:00
1998-11-04 18:04:26 +00:00
for ( const TFormula_documento * f = tipo_doc . first_formula ( ) ; f ; f = tipo_doc . succ_formula ( ) )
1997-06-03 15:56:27 +00:00
{
2009-12-22 16:56:14 +00:00
TExpr_documento * exp = f - > expr ( ) ;
2005-05-16 23:44:23 +00:00
if ( exp ! = NULL ) // Puo' succedere che sia NULL con dati incoerenti
{
if ( tot_doc = = f - > name ( ) )
{
TString16 tot_doc_netto ( tot_doc ) ;
tot_doc_netto . insert ( " _ " ) ;
2002-12-20 16:15:03 +00:00
2005-05-16 23:44:23 +00:00
const TFixed_string netto_def ( exp - > string ( ) ) ;
TExpr_documento netto_exp ( netto_def , _numexpr , this ) ;
1997-06-03 15:56:27 +00:00
2005-05-16 23:44:23 +00:00
add_field ( new TDocumento_variable_field ( tot_doc_netto , netto_exp ) ) ;
1997-06-03 15:56:27 +00:00
2005-05-16 23:44:23 +00:00
if ( netto_def = = " IMPONIBILI()+IMPOSTE() " )
{
TExpr_documento tot_exp ( " IMPONIBILI(1) + IMPOSTE ( 1 ) " , _numexpr, this) ;
add_field ( new TDocumento_variable_field ( tot_doc , tot_exp ) ) ;
}
else
{
TExpr_documento tot_exp ( format ( " %s + _BOLLI(%s) " , ( const char * ) tot_doc_netto ,
2009-12-22 16:56:14 +00:00
( const char * ) tot_doc_netto ) , _numexpr , this ) ;
2005-05-16 23:44:23 +00:00
add_field ( new TDocumento_variable_field ( tot_doc , tot_exp ) ) ;
}
2002-02-26 16:20:19 +00:00
}
else
2003-02-25 14:39:02 +00:00
{
exp - > set_doc ( this ) ;
add_field ( new TDocumento_variable_field ( f - > name ( ) , * exp ) ) ;
1997-10-02 16:57:49 +00:00
}
2005-05-16 23:44:23 +00:00
}
2007-03-07 11:36:57 +00:00
}
2008-11-26 10:47:53 +00:00
2009-12-22 16:56:14 +00:00
for ( TVariable_field * src_field = rec . first_variable_field ( ) ;
2007-03-07 11:36:57 +00:00
src_field ! = NULL ; src_field = rec . succ_variable_field ( ) )
{
2009-12-22 16:56:14 +00:00
const char * fieldname = src_field - > name ( ) ;
2008-11-14 14:40:28 +00:00
if ( src_field - > expression ( ) = = NULL )
2007-03-07 11:36:57 +00:00
put ( fieldname , rec . get ( fieldname ) ) ;
}
1997-05-23 14:26:19 +00:00
}
}
1997-06-03 15:56:27 +00:00
real TDocumento : : imponibile ( bool spese , int ndec ) const
1997-05-23 14:26:19 +00:00
{
1997-06-03 15:56:27 +00:00
real val ;
1999-05-24 13:34:11 +00:00
if ( physical_rows ( ) > 0 )
{
2009-12-22 16:56:14 +00:00
TAssoc_array & table = ( ( TDocumento * ) this ) - > tabella_iva ( ) ;
2009-11-30 10:42:00 +00:00
table . restart ( ) ;
for ( TRiepilogo_iva * ri = ( TRiepilogo_iva * ) table . get ( ) ; ri ! = NULL ; ri = ( TRiepilogo_iva * ) table . get ( ) )
1999-05-24 13:34:11 +00:00
val + = ri - > imponibile ( spese ) ;
2002-12-20 16:15:03 +00:00
if ( ndec = = AUTO_DECIMALS )
ndec = decimals ( ) ;
1999-06-18 15:35:05 +00:00
val . round ( ndec ) ;
1999-05-24 13:34:11 +00:00
}
1997-06-03 15:56:27 +00:00
return val ;
}
1999-10-22 10:00:18 +00:00
void TDocumento : : calc_iva_fattura_commerciale ( )
{
// Calcolo iva per fatture commerciali:
// 1) effettua la sommatoria di tutti i real per ogni elementi di _tabella_iva in un TRiepilogo_iva unico
// 2) azzera _tabella_iva
// 3) scorpora in % a seconda di cio' che e' indicato in configurazione, e mette i nuovi elementi in _tabella_iva
// 4) per ogni nuovo elemento di _tabella_iva, ricalcola la relativa imposta.
TAssoc_array & table = _tabella_iva ;
TRiepilogo_iva t ;
static TString_array tabella_ripartizione ;
2000-05-05 15:25:49 +00:00
const int ndec = decimals ( ) ;
1999-10-22 10:00:18 +00:00
if ( tabella_ripartizione . items ( ) = = 0 )
{
2002-12-20 16:15:03 +00:00
TConfig cnf ( CONFIG_STUDIO , " ve " ) ;
1999-10-22 10:00:18 +00:00
for ( int k = 1 ; k < = MAX_IVA_SLICES ; k + + )
{
TToken_string * tt = new TToken_string ( ) ;
2002-12-20 16:15:03 +00:00
tt - > add ( cnf . get ( " EXCLUDE_PERC " , NULL , k ) ) ;
tt - > add ( cnf . get ( " EXCLUDE_IVA " , NULL , k ) ) ;
1999-10-22 10:00:18 +00:00
tabella_ripartizione . add ( tt ) ;
}
}
// 1)
table . restart ( ) ;
for ( TRiepilogo_iva * ri = ( TRiepilogo_iva * ) table . get ( ) ; ri ! = NULL ;
ri = ( TRiepilogo_iva * ) table . get ( ) )
{
t . imp ( ) + = ri - > imp ( ) ;
t . imp_spese ( ) + = ri - > imp_spese ( ) ;
t . imp_spese_row ( ) + = ri - > imp_spese_row ( ) ;
t . iva_spese ( ) + = ri - > iva_spese ( ) ;
t . iva_sconto ( ) + = ri - > iva_sconto ( ) ;
t . sconto_perc ( ) + = ri - > sconto_perc ( ) ;
t . sconto_imp ( ) + = ri - > sconto_imp ( ) ;
}
// 2)
table . destroy ( ) ;
// 3)
TArray tda ;
tda . add ( new TDistrib ( t . imp ( ) , ndec ) ) ;
tda . add ( new TDistrib ( t . imp_spese ( ) , ndec ) ) ;
tda . add ( new TDistrib ( t . imp_spese_row ( ) , ndec ) ) ;
tda . add ( new TDistrib ( t . iva_spese ( ) , ndec ) ) ;
tda . add ( new TDistrib ( t . iva_sconto ( ) , ndec ) ) ;
tda . add ( new TDistrib ( t . sconto_perc ( ) , ndec ) ) ;
tda . add ( new TDistrib ( t . sconto_imp ( ) , ndec ) ) ;
2004-04-28 22:23:16 +00:00
int k ;
1999-10-22 10:00:18 +00:00
2004-04-28 22:23:16 +00:00
for ( k = 0 ; k < MAX_IVA_SLICES ; k + + )
1999-10-22 10:00:18 +00:00
for ( int j = 0 ; j < 7 ; j + + )
{
const real p ( tabella_ripartizione . row ( k ) . get ( 0 ) ) ;
TDistrib & td = ( TDistrib & ) tda [ j ] ;
td . add ( p ) ;
}
// 4)
for ( k = 0 ; k < MAX_IVA_SLICES ; k + + )
{
TString16 cod ( tabella_ripartizione . row ( k ) . get ( 1 ) ) ;
2013-12-13 09:44:56 +00:00
cod . trim ( ) ;
1999-10-22 10:00:18 +00:00
if ( cod . empty ( ) )
continue ;
2000-05-05 15:25:49 +00:00
const TCodiceIVA civa ( cod ) ;
1999-10-22 10:00:18 +00:00
TRiepilogo_iva * rp = ( TRiepilogo_iva * ) table . objptr ( cod ) ;
if ( rp = = NULL )
{
rp = new TRiepilogo_iva ( civa ) ;
table . add ( cod , rp ) ;
}
2013-12-13 09:44:56 +00:00
for ( int j = 0 ; j < tda . items ( ) ; j + + )
1999-10-22 10:00:18 +00:00
{
2013-12-13 09:44:56 +00:00
TDistrib & td = ( TDistrib & ) tda [ j ] ;
1999-10-22 10:00:18 +00:00
const real rr = td . get ( ) ;
switch ( j )
{
2009-12-22 16:56:14 +00:00
case 0 :
rp - > imp ( ) = rr ;
rp - > iva ( ) = civa . imposta ( rr , ndec ) ;
break ;
case 1 :
rp - > imp_spese ( ) = rr ;
break ;
case 2 :
rp - > imp_spese_row ( ) = rr ;
break ;
case 3 :
rp - > iva_spese ( ) = rr ;
break ;
case 4 :
rp - > iva_sconto ( ) = rr ;
break ;
case 5 :
rp - > sconto_perc ( ) = rr ;
break ;
case 6 :
rp - > sconto_imp ( ) = rr ;
break ;
default :
break ;
1999-10-22 10:00:18 +00:00
}
}
}
}
2007-03-07 11:36:57 +00:00
void TDocumento : : update_tabella_iva ( bool solo_imponibili )
1997-08-21 16:47:14 +00:00
{
2007-05-22 10:27:58 +00:00
static bool __solo_imponibili = false ;
1997-08-21 16:47:14 +00:00
const int items = rows ( ) ;
TAssoc_array & table = _tabella_iva ;
2007-03-07 11:36:57 +00:00
if ( items = = 0 )
{
table . destroy ( ) ;
return ;
}
2007-05-22 10:27:58 +00:00
if ( __solo_imponibili ! = solo_imponibili )
{
table . destroy ( ) ;
__solo_imponibili = solo_imponibili ;
}
2007-03-07 11:36:57 +00:00
if ( table . items ( ) > 0 )
1997-08-21 16:47:14 +00:00
{
2006-01-09 01:15:53 +00:00
if ( items = = 0 )
table . destroy ( ) ;
return ;
1997-08-21 16:47:14 +00:00
}
2007-03-07 11:36:57 +00:00
const bool doc_al_lordo = tipo ( ) . calcolo_lordo ( ) ;
const int ndec = decimals ( ) ;
2012-12-21 06:58:13 +00:00
// Test di consistenza solitamente inutile, ma fallisce in ve1 -0 L
const int r1 = body ( LF_RIGHEDOC ) . first_row ( ) ;
if ( r1 > 0 & & row ( r1 ) . get_int ( RDOC_NRIGA ) ! = r1 )
remove_body ( LF_RIGHEDOC ) ; // Forza il caricamento ex-novo delle righe
2009-02-14 17:13:09 +00:00
2012-12-21 06:58:13 +00:00
FOR_EACH_PHYSICAL_RDOC ( * this , j , rowptr )
2007-03-07 11:36:57 +00:00
{
2012-12-21 06:58:13 +00:00
const TRiga_documento & r = * rowptr ;
2007-03-07 11:36:57 +00:00
if ( ! r . is_sconto ( ) & & ! r . is_descrizione ( ) )
{
const TCodiceIVA & iva = r . iva ( ) ;
if ( iva . ok ( ) )
{
const TString & cod = iva . codice ( ) ;
2009-05-29 10:06:03 +00:00
TRiepilogo_iva * aliquota = ( TRiepilogo_iva * ) table . objptr ( cod ) ;
2007-03-07 11:36:57 +00:00
if ( aliquota = = NULL )
{
aliquota = new TRiepilogo_iva ( iva ) ;
table . add ( cod , aliquota ) ;
}
const real imponibile = doc_al_lordo ? r . importo ( true , true , ndec ) : r . imponibile ( ) ;
2009-05-29 10:06:03 +00:00
aliquota - > imp_orig ( ) + = imponibile ;
2007-03-07 11:36:57 +00:00
}
}
}
if ( solo_imponibili )
return ;
1997-08-21 16:47:14 +00:00
real tot_doc ;
real tot_sconti ;
1997-09-01 14:32:34 +00:00
real tot_sconti_perc ;
2007-03-07 11:36:57 +00:00
TArray imponibili ;
2002-12-20 16:15:03 +00:00
const bool fatt_comm = tipo ( ) . fattura_commerciale ( ) ;
2006-01-09 01:15:53 +00:00
2014-03-07 14:42:05 +00:00
TString4 codiva_es ; iva_esente ( codiva_es ) ;
2009-02-27 16:55:21 +00:00
for ( int i = items ; i > 0 ; i - - )
1997-08-21 16:47:14 +00:00
{
const TRiga_documento & r = row ( i ) ;
2007-03-07 11:36:57 +00:00
const real imponibile = doc_al_lordo ? r . importo ( true , true , ndec ) : r . imponibile ( ) ;
tot_doc + = imponibile ;
if ( r . is_sconto ( ) )
1997-09-01 14:32:34 +00:00
{
tot_sconti + = imponibile ;
if ( r . is_sconto_perc ( ) )
tot_sconti_perc + = imponibile ;
}
1997-08-21 16:47:14 +00:00
else
if ( ! r . is_descrizione ( ) )
{
2014-03-07 14:42:05 +00:00
const real imposta = doc_al_lordo ? ZERO : r . imposta ( false ) ;
// Aggiorna o aggiunge l'elemento se non esiste
2000-05-05 15:25:49 +00:00
const TCodiceIVA & iva = r . iva ( ) ;
2007-03-07 11:36:57 +00:00
if ( iva . ok ( ) )
1997-08-21 16:47:14 +00:00
{
2007-03-07 11:36:57 +00:00
const TString & cod = iva . codice ( ) ;
2009-05-29 10:06:03 +00:00
TRiepilogo_iva * aliquota = ( TRiepilogo_iva * ) table . objptr ( cod ) ;
2000-05-05 15:25:49 +00:00
if ( aliquota = = NULL )
{
aliquota = new TRiepilogo_iva ( iva ) ;
table . add ( cod , aliquota ) ;
2007-03-07 11:36:57 +00:00
}
2000-05-05 15:25:49 +00:00
aliquota - > imp ( ) + = imponibile ;
if ( r . is_spese ( ) & & iva . tipo ( ) . not_empty ( ) )
aliquota - > imp_spese_row ( ) + = imponibile ;
aliquota - > iva ( ) + = imposta ;
}
1997-08-21 16:47:14 +00:00
tot_doc + = imposta ;
}
}
1999-10-22 10:00:18 +00:00
2014-03-07 14:42:05 +00:00
if ( table . empty ( ) )
2000-05-05 15:25:49 +00:00
return ;
1997-08-21 16:47:14 +00:00
if ( tot_sconti ! = ZERO )
{
1998-11-04 18:04:26 +00:00
TGeneric_distrib d ( tot_sconti , ndec ) ;
real tot_sconti_imp = tot_sconti - tot_sconti_perc ;
1997-08-21 16:47:14 +00:00
2009-02-27 16:55:21 +00:00
if ( ! table . empty ( ) )
2007-03-07 11:36:57 +00:00
{
FOR_EACH_ASSOC_OBJECT ( table , obj , key , o )
{
2013-12-13 09:44:56 +00:00
TRiepilogo_iva * aliquota = ( TRiepilogo_iva * ) o ;
2014-03-07 14:42:05 +00:00
const real i = aliquota - > imp ( ) - aliquota - > imp_spese_row ( ) ;
d . add ( i ) ;
2007-03-07 11:36:57 +00:00
}
}
1997-08-21 16:47:14 +00:00
2007-03-07 11:36:57 +00:00
FOR_EACH_ASSOC_OBJECT ( table , obj , key , o )
1997-08-21 16:47:14 +00:00
{
2014-03-07 14:42:05 +00:00
TRiepilogo_iva & aliquota = * ( TRiepilogo_iva * ) o ;
const TCodiceIVA & ci = aliquota . cod_iva ( ) ;
const real i = d . get ( ) ;
real & imponibile = aliquota . imp ( ) ;
1997-08-28 17:11:17 +00:00
imponibile + = i ;
1998-11-04 18:04:26 +00:00
TGeneric_distrib s ( i , ndec ) ;
1997-09-01 14:32:34 +00:00
s . add ( tot_sconti_imp ) ;
s . add ( tot_sconti_perc ) ;
2014-03-07 14:42:05 +00:00
aliquota . sconto_imp ( ) = s . get ( ) ;
aliquota . sconto_perc ( ) = s . get ( ) ;
1997-09-01 14:32:34 +00:00
2014-03-07 14:42:05 +00:00
real & iva = aliquota . iva ( ) ;
1997-09-01 14:32:34 +00:00
2007-03-07 11:36:57 +00:00
/* if (doc_al_lordo)
1999-05-24 13:34:11 +00:00
{
2000-05-05 15:25:49 +00:00
const real imposta ( ci . imposta ( i , ndec ) ) ;
1999-05-24 13:34:11 +00:00
2004-01-12 08:48:58 +00:00
TGeneric_distrib iva ( imposta , ndec ) ;
iva . add ( tot_sconti_imp ) ;
iva . add ( tot_sconti_perc ) ;
1999-06-18 15:35:05 +00:00
imponibile + = imposta ;
2007-03-07 11:36:57 +00:00
aliquota - > sconto_imp ( ) + = iva . get ( ) ;
aliquota - > sconto_perc ( ) + = iva . get ( ) ;
2004-01-12 08:48:58 +00:00
1999-06-18 15:35:05 +00:00
tot_doc + = imposta ;
1999-05-24 13:34:11 +00:00
}
2007-03-07 11:36:57 +00:00
else */
if ( ! doc_al_lordo )
1999-05-24 13:34:11 +00:00
{
2007-03-07 11:36:57 +00:00
const real imposta ( ci . imposta ( i , ndec ) ) ;
1997-08-21 16:47:14 +00:00
1999-06-18 15:35:05 +00:00
iva + = imposta ;
2014-03-07 14:42:05 +00:00
aliquota . iva_sconto ( ) = imposta ;
1999-06-18 15:35:05 +00:00
tot_doc + = imposta ;
}
1997-08-21 16:47:14 +00:00
}
}
1997-12-10 12:18:52 +00:00
1999-10-22 10:00:18 +00:00
if ( fatt_comm )
calc_iva_fattura_commerciale ( ) ;
2007-09-17 15:33:04 +00:00
const real rit = ritenute ( ) ;
real val = spese_incasso ( real ( tot_doc - rit ) , ALL_DECIMALS , doc_al_lordo ? _lordo : _netto ) ;
1997-12-10 12:18:52 +00:00
2005-09-19 12:45:16 +00:00
if ( ! val . is_zero ( ) )
1997-12-10 12:18:52 +00:00
{
2013-03-15 11:08:44 +00:00
const TString & codiva = codiva_es . full ( ) ? ( const TString & ) codiva_es : codiva_spese ( ) ;
2002-10-23 14:14:55 +00:00
TRiepilogo_iva * ri = ( TRiepilogo_iva * ) table . objptr ( codiva ) ;
2006-07-11 13:12:41 +00:00
if ( ri = = NULL & & codiva . full ( ) )
1997-12-10 12:18:52 +00:00
{
2000-05-05 15:25:49 +00:00
ri = new TRiepilogo_iva ( TCodiceIVA ( codiva ) ) ;
1997-12-10 12:18:52 +00:00
table . add ( codiva , ri ) ;
}
2006-07-11 13:12:41 +00:00
if ( ri ! = NULL )
ri - > imp_spese ( ) + = val ;
1997-12-10 12:18:52 +00:00
tot_doc + = val ;
2002-10-23 14:14:55 +00:00
if ( ! doc_al_lordo )
{
2007-09-17 15:33:04 +00:00
val = spese_incasso ( real ( tot_doc - rit ) , ALL_DECIMALS , _imposta ) ;
2006-07-11 13:12:41 +00:00
if ( ri ! = NULL )
ri - > iva_spese ( ) + = val ;
2002-10-23 14:14:55 +00:00
tot_doc + = val ;
}
1997-12-10 12:18:52 +00:00
}
2004-06-04 11:20:51 +00:00
val = bolli ( real ( tot_doc - rit ) , ALL_DECIMALS , doc_al_lordo ? _lordo : _netto ) ;
1997-12-10 12:18:52 +00:00
if ( val ! = ZERO )
{
2006-07-11 13:12:41 +00:00
const TString & codiva = codiva_bolli ( ) ;
if ( codiva . full ( ) )
1997-12-10 12:18:52 +00:00
{
2006-07-11 13:12:41 +00:00
TRiepilogo_iva * ri = ( TRiepilogo_iva * ) table . objptr ( codiva ) ;
if ( ri = = NULL )
{
ri = new TRiepilogo_iva ( TCodiceIVA ( codiva ) ) ;
table . add ( codiva , ri ) ;
}
if ( ! doc_al_lordo )
{
real valiva = bolli ( real ( tot_doc - rit ) , ALL_DECIMALS , _imposta ) ;
ri - > iva_spese ( ) + = valiva ;
tot_doc + = valiva ;
}
ri - > imp_spese ( ) + = val ;
2002-10-23 14:14:55 +00:00
}
2006-07-11 13:12:41 +00:00
2004-06-04 11:20:51 +00:00
tot_doc + = val ;
1999-05-24 13:34:11 +00:00
}
// SCORPORO
1999-06-18 15:35:05 +00:00
if ( doc_al_lordo )
{
2007-03-07 11:36:57 +00:00
FOR_EACH_ASSOC_OBJECT ( table , obj , key , o )
{
TRiepilogo_iva * aliquota = ( TRiepilogo_iva * ) o ;
const TCodiceIVA & iva = aliquota - > cod_iva ( ) ;
1999-05-24 13:34:11 +00:00
2007-03-07 11:36:57 +00:00
aliquota - > iva ( ) = iva . scorpora ( aliquota - > imp ( ) , ndec ) ;
aliquota - > iva_spese ( ) = iva . scorpora ( aliquota - > imp_spese ( ) , ndec ) ;
iva . scorpora ( aliquota - > imp_spese_row ( ) , ndec ) ;
1999-05-24 13:34:11 +00:00
2007-03-07 11:36:57 +00:00
aliquota - > iva_sconto ( ) = iva . scorpora ( aliquota - > sconto_imp ( ) , ndec ) ;
aliquota - > iva_sconto ( ) + = iva . scorpora ( aliquota - > sconto_perc ( ) , ndec ) ;
1999-05-24 13:34:11 +00:00
}
1999-06-18 15:35:05 +00:00
}
1997-08-21 16:47:14 +00:00
}
1997-06-03 15:56:27 +00:00
real TDocumento : : imposta ( bool spese , int ndec ) const
1998-02-09 12:06:44 +00:00
{
real val = ZERO ;
if ( physical_rows ( ) > 0 )
{
2009-12-22 16:56:14 +00:00
TAssoc_array & table = ( ( TDocumento * ) this ) - > tabella_iva ( ) ;
1998-02-09 12:06:44 +00:00
if ( ndec = = AUTO_DECIMALS )
2000-05-05 15:25:49 +00:00
ndec = decimals ( ) ;
1998-02-09 12:06:44 +00:00
for ( TRiepilogo_iva * ri = ( TRiepilogo_iva * ) table . get ( ) ; ri ! = NULL ;
ri = ( TRiepilogo_iva * ) table . get ( ) )
{
real iva = ri - > imposta ( spese ) ;
2000-05-05 15:25:49 +00:00
if ( ndec = = 0 )
{
if ( iva < ZERO )
iva . floor ( ndec ) ;
else
iva . ceil ( ndec ) ;
}
else
iva . round ( ndec ) ;
1998-02-09 12:06:44 +00:00
val + = iva ;
}
1997-06-03 15:56:27 +00:00
}
return val ;
1997-05-23 14:26:19 +00:00
}
1997-06-03 15:56:27 +00:00
real TDocumento : : totale_doc ( ) const
1997-05-23 14:26:19 +00:00
{
2006-01-09 01:15:53 +00:00
/* A pag.1 c'e' scritto di non fare cosi'
1997-06-03 15:56:27 +00:00
const TString16 field ( tipo ( ) . totale_doc ( ) ) ;
if ( field . not_empty ( ) )
return get_real ( field ) ;
else
{
real r = imponibile ( ) + imposta ( ) ;
2000-05-05 15:25:49 +00:00
const int ndec = decimals ( ) ;
2007-09-17 15:33:04 +00:00
r + = spese_incasso ( r - ritenute ( ) ) , ndec ) ;
2004-06-04 11:20:51 +00:00
r + = bolli ( real ( r - ritenute ( ) ) , ndec ) ;
1997-06-03 15:56:27 +00:00
return r ;
}
2006-01-09 01:15:53 +00:00
*/
// Cosi' e' piu' ordinato, strutturato e veloce
real r ;
const TString & field = tipo ( ) . totale_doc ( ) ;
if ( field . blank ( ) )
{
const int ndec = decimals ( ) ;
2007-03-07 11:36:57 +00:00
const bool lordo = tipo ( ) . calcolo_lordo ( ) ;
r = imponibile ( lordo ) ;
if ( ! lordo )
r + = imposta ( ) ;
2007-09-17 15:33:04 +00:00
r + = spese_incasso ( real ( r - ritenute ( ) ) , ndec ) ;
2006-01-09 01:15:53 +00:00
r + = bolli ( real ( r - ritenute ( ) ) , ndec ) ;
}
else
r = get_real ( field ) ;
return r ;
1997-05-23 14:26:19 +00:00
}
1997-06-03 15:56:27 +00:00
real TDocumento : : totale_netto ( ) const
1997-05-23 14:26:19 +00:00
{
2002-12-20 16:15:03 +00:00
const TString & field = tipo ( ) . totale_netto ( ) ;
2013-06-20 13:24:20 +00:00
if ( field . full ( ) )
1997-06-03 15:56:27 +00:00
return get_real ( field ) ;
else
return imponibile ( ) + imposta ( ) ;
1997-05-23 14:26:19 +00:00
}
1997-06-03 15:56:27 +00:00
real TDocumento : : basesconto ( ) const
1997-05-23 14:26:19 +00:00
{
2002-12-20 16:15:03 +00:00
const TString & field = tipo ( ) . basesconto ( ) ;
2013-12-13 09:44:56 +00:00
return field . full ( ) ? get_real ( field ) : ZERO ;
1997-05-23 14:26:19 +00:00
}
1997-06-03 15:56:27 +00:00
real TDocumento : : spese ( ) const
{
2002-12-20 16:15:03 +00:00
const TString & field = tipo ( ) . spese ( ) ;
2013-12-13 09:44:56 +00:00
return field . full ( ) ? get_real ( field ) : ZERO ;
1997-06-03 15:56:27 +00:00
}
2004-06-04 11:20:51 +00:00
real TDocumento : : ritenute ( const char tipo , bool lordo , int ndec ) const
{
real val ;
2013-12-13 09:44:56 +00:00
for ( int i = rows ( ) ; i > 0 ; i - - )
2004-06-04 11:20:51 +00:00
{
2009-12-22 16:56:14 +00:00
const TRiga_documento & r = operator [ ] ( i ) ;
2004-06-04 11:20:51 +00:00
val + = r . ritenuta ( tipo , lordo , ndec ) ;
}
return val ;
}
1999-04-06 15:34:39 +00:00
TPagamento & TDocumento : : pagamento ( )
1997-06-03 15:56:27 +00:00
{
1999-04-06 15:34:39 +00:00
const char tipocf = get_char ( DOC_TIPOCF ) ;
const long codcf = get_long ( DOC_CODCF ) ;
_pag . set_clifo ( codcf , tipocf ) ;
TDate data_in = get_date ( DOC_DATAINSC ) ;
if ( data_in . empty ( ) )
data_in = get_date ( DOC_DATADOC ) ;
2002-07-02 16:21:23 +00:00
const TString8 codpag ( get ( DOC_CODPAG ) ) ;
1997-06-03 15:56:27 +00:00
if ( codpag ! = _pag . code ( ) )
{
_pag . set_code ( codpag ) ;
_pag . read ( ) ;
2011-04-11 13:56:36 +00:00
_pag . set_inizio ( data_in ) ; // Perche' rispetta rate true?
1997-06-03 15:56:27 +00:00
}
1999-06-18 15:35:05 +00:00
else
{
if ( data_in ! = _pag . get_datadoc ( ) )
2011-04-11 13:56:36 +00:00
_pag . set_inizio ( data_in ) ; // Perche' rispetta rate true?
1999-06-18 15:35:05 +00:00
}
1999-04-06 15:34:39 +00:00
1997-06-03 15:56:27 +00:00
return _pag ;
}
2009-03-10 14:31:20 +00:00
real TDocumento : : provvigione ( bool first , int ndec ) const
1997-10-02 16:57:49 +00:00
{
2009-03-10 14:31:20 +00:00
TString16 field = agente ( first ) . campoprovv ( ) ;
1997-10-29 11:08:40 +00:00
if ( field . empty ( ) )
2009-03-10 14:31:20 +00:00
field = first ? tipo ( ) . totprovv ( ) : tipo ( ) . totprovv1 ( ) ;
1997-10-02 16:57:49 +00:00
2002-07-02 16:21:23 +00:00
real val ;
1997-10-02 16:57:49 +00:00
if ( field . not_empty ( ) )
2002-07-02 16:21:23 +00:00
val = get_real ( field ) ;
1997-10-02 16:57:49 +00:00
else
2002-07-02 16:21:23 +00:00
{
if ( ndec = = AUTO_DECIMALS )
ndec = decimals ( ) ;
2009-05-29 10:06:03 +00:00
for ( int i = physical_rows ( ) ; i > 0 ; i - - )
val + = physical_row ( i ) . provvigione ( first , ndec ) ;
2002-07-02 16:21:23 +00:00
}
1997-10-02 16:57:49 +00:00
return val ;
}
2008-11-12 11:25:59 +00:00
real TDocumento : : valore ( bool totale , bool lordo , int ndec ) const
1998-08-25 18:07:30 +00:00
{
real val ;
2009-11-30 10:42:00 +00:00
TDocumento & doc = * ( TDocumento * ) this ;
FOR_EACH_PHYSICAL_RDOC_BACK ( doc , i , r )
1998-08-25 18:07:30 +00:00
{
2009-11-30 10:42:00 +00:00
const char t = r - > tipo ( ) . tipo ( ) ;
if ( strchr ( " MSPRA " , t ) ! = NULL ) // Merce, Spese, Prestazioni, Risorse, Attrezzature
val + = r - > valore ( totale , lordo , ndec ) ;
1998-08-25 18:07:30 +00:00
}
return val ;
}
1997-06-03 15:56:27 +00:00
void TDocumento : : put_str ( const char * fieldname , const char * val )
{
2005-09-19 12:45:16 +00:00
if ( strcmp ( fieldname , DOC_TIPODOC ) = = 0 )
1997-08-26 12:38:08 +00:00
{
2009-06-11 14:54:42 +00:00
const TString4 v ( val ) ;
2005-09-19 12:45:16 +00:00
if ( TRectype : : get ( DOC_TIPODOC ) ! = v )
1997-08-26 12:38:08 +00:00
{
TAuto_variable_rectype : : put_str ( fieldname , v ) ;
reset_fields ( * this ) ;
set_fields ( * this ) ;
}
else
dirty_fields ( ) ;
1997-06-03 15:56:27 +00:00
}
1997-06-12 16:26:22 +00:00
else
2008-03-26 11:24:36 +00:00
if ( strcmp ( fieldname , DOC_CODCF ) = = 0 )
{
2009-05-29 10:06:03 +00:00
const TString8 v ( val ) ;
2008-03-26 12:44:04 +00:00
put ( DOC_SPESEUPD , TRectype : : get ( DOC_CODCF ) = = v ) ;
2008-03-26 11:24:36 +00:00
TAuto_variable_rectype : : put_str ( fieldname , v ) ;
dirty_fields ( ) ;
}
else
2008-03-26 12:44:04 +00:00
{
TAuto_variable_rectype : : put_str ( fieldname , val ) ;
dirty_fields ( ) ;
if ( strcmp ( fieldname , DOC_SCONTOPERC ) = = 0 )
set_riga_sconto ( ) ;
}
1997-06-03 15:56:27 +00:00
}
1999-06-18 15:35:05 +00:00
const TString & TDocumento : : get_str ( const char * fieldname ) const
{
if ( _dirty_deny & & variable_field ( fieldname ) ! = NULL )
2005-09-19 12:45:16 +00:00
( bool & ) _dirty_deny = false ;
1999-06-18 15:35:05 +00:00
return TMultiple_rectype : : get_str ( fieldname ) ;
}
1997-06-03 15:56:27 +00:00
void TDocumento : : zero ( const char * fieldname )
1997-05-23 14:26:19 +00:00
{
2008-03-26 11:24:36 +00:00
if ( strcmp ( fieldname , DOC_TIPODOC ) = = 0 )
1997-06-03 15:56:27 +00:00
reset_fields ( * this ) ;
2008-03-26 11:24:36 +00:00
TAuto_variable_rectype : : zero ( fieldname ) ;
1997-06-03 15:56:27 +00:00
dirty_fields ( ) ;
1997-05-23 14:26:19 +00:00
}
2010-03-17 16:04:48 +00:00
TCli_for & TDocumento : : clifor ( bool force_reload ) const
1997-06-12 16:26:22 +00:00
{
const char tipo = tipocf ( ) ;
const long codice = codcf ( ) ;
2010-03-17 16:04:48 +00:00
TCli_for & cf = ( TCli_for & ) _cli_for ;
if ( force_reload | | cf . empty ( ) | | cf . tipo ( ) ! = tipo | | cf . codice ( ) ! = codice )
cf . read ( tipo , codice ) ;
return cf ;
1997-06-12 16:26:22 +00:00
}
2007-09-17 15:33:04 +00:00
TOccasionale & TDocumento : : occas ( ) const
1997-06-12 16:26:22 +00:00
{
2007-09-17 15:33:04 +00:00
const TString16 occ_code = cod_occas ( ) ; // Codice occasionale in testata
1997-06-12 16:26:22 +00:00
2012-08-09 14:31:57 +00:00
TOccasionale & rec = ( TOccasionale & ) _occas ;
if ( occ_code ! = rec . codice ( ) )
1997-06-12 16:26:22 +00:00
{
TLocalisamfile o ( LF_OCCAS ) ;
2012-08-09 14:31:57 +00:00
rec . put ( OCC_CFPI , occ_code ) ;
if ( rec . read ( o ) ! = NOERR )
{
rec . zero ( ) ;
rec . put ( OCC_CFPI , occ_code ) ;
}
1997-06-12 16:26:22 +00:00
}
2012-08-09 14:31:57 +00:00
return rec ;
1997-06-12 16:26:22 +00:00
}
1997-10-29 11:08:40 +00:00
2009-03-10 14:31:20 +00:00
const TAgente & TDocumento : : agente ( bool first ) const
2002-07-30 14:11:47 +00:00
{
if ( _agenti = = NULL )
_agenti = new TAgenti_cache ;
2009-03-10 14:31:20 +00:00
return _agenti - > agente ( first ? get ( DOC_CODAG ) : get ( DOC_CODAGVIS ) ) ;
1997-10-29 11:08:40 +00:00
}
1997-06-12 16:26:22 +00:00
1997-08-06 12:31:10 +00:00
TDocumento & TDocumento : : copy ( const TDocumento & d )
1997-06-03 15:56:27 +00:00
{
1997-08-18 16:06:51 +00:00
TMultiple_rectype : : operator = ( ( TMultiple_rectype & ) d ) ;
2007-03-07 11:36:57 +00:00
reset_fields ( * this ) ;
set_fields ( ( TAuto_variable_rectype & ) d ) ;
1997-08-06 12:31:10 +00:00
for ( int i = physical_rows ( ) ; i > 0 ; i - - )
{
2008-11-26 10:47:53 +00:00
TRiga_documento & r = row ( i ) ;
r . set_doc ( this ) ;
r . reset_fields ( r ) ;
r . set_fields ( ( ( TAuto_variable_rectype & ) d [ i ] ) ) ;
1997-08-06 12:31:10 +00:00
}
1997-06-03 15:56:27 +00:00
set_riga_sconto ( ) ;
if ( is_fattura ( ) )
set_riga_esenzione ( ) ;
1998-11-04 18:04:26 +00:00
_occas = d . occas ( ) ;
1997-06-03 15:56:27 +00:00
return * this ;
}
TRectype & TDocumento : : operator = ( const TRectype & r )
{
1997-08-18 16:06:51 +00:00
return TMultiple_rectype : : operator = ( r ) ;
1997-06-03 15:56:27 +00:00
}
TRectype & TDocumento : : operator = ( const char * r )
{
1997-08-18 16:06:51 +00:00
return TMultiple_rectype : : operator = ( r ) ;
1997-06-03 15:56:27 +00:00
}
1997-05-23 14:26:19 +00:00
1999-10-22 10:00:18 +00:00
TRecord_array & TDocumento : : body ( int logicnum ) const
2013-12-13 09:44:56 +00:00
{
logicnum = LF_RIGHEDOC ; // logicnum may be 0!
2000-10-03 13:45:12 +00:00
const bool reset_data_cons = loaded_rows ( logicnum ) = = 0 ;
2005-09-19 12:45:16 +00:00
if ( reset_data_cons )
( ( TDocumento * ) this ) - > _dirty_deny = true ;
1999-10-22 10:00:18 +00:00
TRecord_array & r = TMultiple_rectype : : body ( logicnum ) ;
2002-02-26 16:20:19 +00:00
if ( reset_data_cons )
1999-10-22 10:00:18 +00:00
{
2005-09-19 12:45:16 +00:00
const TDate datacons ( get ( DOC_DATACONS ) ) ;
2002-02-26 16:20:19 +00:00
const TString80 codcms ( get ( DOC_CODCMS ) ) ;
const TString80 fascms ( get ( DOC_FASCMS ) ) ;
2005-05-05 10:37:07 +00:00
const TString80 codcos ( get ( DOC_CODCOSTO ) ) ;
2013-12-13 09:44:56 +00:00
const bool order = datacons . ok ( ) ; // on 27-09-2013 was order=is_ordine();
const bool can_reset_ca = ( codcms . full ( ) | | codcos . full ( ) ) & & ini_get_string ( CONFIG_DITTA , " ca " , " FathFasi " ) . blank ( ) ;
2005-09-19 12:45:16 +00:00
2006-01-09 01:15:53 +00:00
for ( int i = r . last_row ( ) ; i > 0 ; i = r . pred_row ( i ) )
1999-10-22 10:00:18 +00:00
{
2005-05-05 10:37:07 +00:00
TRectype & rec = r [ i ] ;
1999-10-22 10:00:18 +00:00
TRecfield dcons ( rec , RDOC_DATACONS ) ;
2005-09-19 12:45:16 +00:00
if ( order & & datacons = = dcons )
1999-10-22 10:00:18 +00:00
dcons = " " ;
2013-12-13 09:44:56 +00:00
if ( can_reset_ca )
2005-05-05 10:37:07 +00:00
{
2013-12-13 09:44:56 +00:00
TRecfield ccms ( rec , RDOC_CODCMS ) ;
TRecfield fcms ( rec , RDOC_FASCMS ) ;
TRecfield ccos ( rec , RDOC_CODCOSTO ) ;
if ( codcms = = ccms ) ccms = " " ;
if ( fascms = = fcms ) fcms = " " ;
if ( codcos = = ccos ) ccos = " " ;
2005-05-05 10:37:07 +00:00
}
1999-10-22 10:00:18 +00:00
}
2005-09-19 12:45:16 +00:00
( ( TDocumento * ) this ) - > _dirty_deny = false ;
1999-10-22 10:00:18 +00:00
}
return r ;
}
2008-03-26 11:24:36 +00:00
void TDocumento : : update_raee ( )
{
const TString & r_cod = tipo ( ) . raee_cod ( ) ;
const TString & r_fld = tipo ( ) . raee_fld ( ) ;
2008-03-26 12:44:04 +00:00
if ( r_cod . full ( ) & & r_fld . full ( ) & & tipo ( ) . stati_iniziali_modifica ( ) . find ( stato ( ) ) > = 0 )
2008-03-26 11:24:36 +00:00
{
TSpesa_prest sp ( r_cod ) ;
TString4 cod_iva_cli ;
TLocalisamfile cfven ( LF_CFVEN ) ;
cfven . put ( " TIPOCF " , get ( " TIPOCF " ) ) ;
cfven . put ( " CODCF " , get ( " CODCF " ) ) ;
if ( cfven . read ( ) = = NOERR )
cod_iva_cli = cfven . get ( " ASSFIS " ) ;
int nrows = physical_rows ( ) ;
int i ;
for ( i = nrows ; i > 0 ; i - - )
{
TRiga_documento & r = row ( i ) ;
if ( r . tipo ( ) . tipo ( ) = = RIGA_SPESEDOC & & r . is_generata ( ) & & r . get ( " GENTIPO " ) = = " R " )
destroy_row ( i , true ) ;
}
nrows = physical_rows ( ) ;
for ( i = nrows ; i > 0 ; i - - )
{
TRiga_documento & r = row ( i ) ;
if ( r . is_articolo ( ) )
{
2008-10-07 00:50:22 +00:00
TArticolo & art = r . articolo ( ) ;
2008-03-26 11:24:36 +00:00
real tax = art . get_real ( r_fld ) ;
if ( tax ! = ZERO )
{
const TCurrency_documento val ( tax , * this , true ) ;
TString16 t ( sp . tipo_riga ( ) ) ;
TRiga_documento & r1 = insert_row ( i + 1 , t ) ;
copy_data ( r1 , r ) ;
r1 . set_tipo ( t ) ;
r1 . put ( RDOC_CODART , r_cod ) ;
TString d ( sp . descrizione ( ) ) ;
if ( d . full ( ) )
d < < " - " ;
d < < r1 . get ( RDOC_DESCR ) ;
d < < r1 . get ( RDOC_DESCEST ) ;
r1 . put ( RDOC_DESCR , d . left ( 50 ) ) ;
if ( d . len ( ) > 50 )
{
r1 . put ( RDOC_DESCLUNGA , " X " ) ;
r1 . put ( RDOC_DESCEST , d . mid ( 50 ) ) ;
}
else
{
r1 . zero ( RDOC_DESCLUNGA ) ;
r1 . zero ( RDOC_DESCEST ) ;
}
const TString & um = sp . um ( ) ;
if ( um . full ( ) )
r1 . put ( RDOC_UMQTA , um ) ;
if ( cod_iva_cli . blank ( ) )
{
2013-03-15 11:08:44 +00:00
const TString & codiva = sp . cod_iva ( ) ;
2008-03-26 11:24:36 +00:00
if ( codiva . full ( ) )
r1 . put ( RDOC_CODIVA , codiva ) ;
}
else
r1 . put ( RDOC_CODIVA , cod_iva_cli ) ;
tax = val . get_num ( ) ;
r1 . put ( RDOC_PREZZO , tax ) ;
if ( tipo ( ) . calcolo_lordo ( ) )
{
tax = r1 . iva ( ) . lordo ( tax , ALL_DECIMALS ) ;
r1 . put ( RDOC_PREZZOL , tax ) ;
}
r1 . generata ( ) ;
2013-12-13 09:44:56 +00:00
r1 . put ( RDOC_GENTIPO , " R " ) ;
2008-03-26 11:24:36 +00:00
}
}
}
}
}
2014-03-07 14:42:05 +00:00
void TDocumento : : update_spese_aut ( TString_array & spese_aut , bool preserve_old , TSheet_field * sh )
1997-06-03 15:56:27 +00:00
{
2008-03-26 12:44:04 +00:00
const bool updated = get_bool ( DOC_SPESEUPD ) ;
2007-03-07 15:35:38 +00:00
if ( updated )
1997-08-01 09:20:02 +00:00
return ;
const bool interactive = sh ! = NULL ;
1997-06-03 15:56:27 +00:00
if ( tipo ( ) . spese_aut ( ) )
{
1997-08-18 16:06:51 +00:00
const int nrows = physical_rows ( ) ;
2004-04-28 22:23:16 +00:00
int i ;
for ( i = nrows ; i > 0 ; i - - )
1997-06-03 15:56:27 +00:00
{
TRiga_documento & r = row ( i ) ;
2013-12-13 09:44:56 +00:00
bool tipo_spese = r . get ( RDOC_GENTIPO ) . empty ( ) ;
1997-06-03 15:56:27 +00:00
1999-04-06 15:34:39 +00:00
if ( r . tipo ( ) . tipo ( ) = = RIGA_SPESEDOC & & r . is_generata ( ) & & tipo_spese )
1997-06-03 15:56:27 +00:00
{
if ( preserve_old )
return ;
2011-04-11 13:56:36 +00:00
destroy_row ( i , true ) ;
1997-06-03 15:56:27 +00:00
if ( interactive )
sh - > destroy ( i - 1 ) ;
}
}
2006-07-11 13:12:41 +00:00
TString4 cod_iva_cli ;
1997-06-03 15:56:27 +00:00
const int nspese = spese_aut . items ( ) ;
2006-07-11 13:12:41 +00:00
1997-06-03 15:56:27 +00:00
if ( nspese > 0 )
{
1998-04-30 14:04:19 +00:00
TSpesa_prest sp ;
2008-08-28 10:07:33 +00:00
cod_iva_cli = codesiva ( ) ;
1997-06-03 15:56:27 +00:00
for ( i = 0 ; i < nspese ; i + + )
{
2006-02-02 17:59:02 +00:00
const TString & s = spese_aut . row ( i ) ;
1997-06-03 15:56:27 +00:00
1998-04-30 14:04:19 +00:00
if ( sp . read ( s ) ! = NOERR )
2014-03-07 14:42:05 +00:00
warning_box ( " Codice spesa '%s' assente " , ( const char * ) s ) ;
1998-04-30 14:04:19 +00:00
else
{
2006-02-02 17:59:02 +00:00
const TString4 tipo ( sp . tipo_riga ( ) ) ;
TRiga_documento & riga = new_row ( tipo ) ;
1998-04-30 14:04:19 +00:00
2005-06-29 13:04:06 +00:00
riga . put ( RDOC_CODART , s ) ;
1998-04-30 14:04:19 +00:00
riga . generata ( ) ;
2005-06-29 13:04:06 +00:00
riga . put ( RDOC_DESCR , sp . descrizione ( ) ) ;
2008-03-26 11:24:36 +00:00
if ( cod_iva_cli . blank ( ) )
riga . put ( RDOC_CODIVA , sp . cod_iva ( ) ) ;
else
riga . put ( RDOC_CODIVA , cod_iva_cli ) ;
1998-04-30 14:04:19 +00:00
switch ( sp . tipo ( ) )
{
2014-03-07 14:42:05 +00:00
case ' Q ' :
{
real qta = sp . qta ( ) ;
if ( qta = = ZERO )
qta = UNO ;
riga . put ( " QTA " , qta ) ;
}
// Continua perche' e' quantita' e valore
case ' V ' :
{
const real cambio = get_real ( DOC_CAMBIO ) ;
const TString4 valuta = get ( DOC_CODVAL ) ;
real prezzo = sp . prezzo ( ) ;
1998-04-30 14:04:19 +00:00
2014-03-07 14:42:05 +00:00
sppr_calc ( sp , valuta , cambio , prezzo ) ;
if ( this - > tipo ( ) . calcolo_lordo ( ) )
{
prezzo = riga . iva ( ) . lordo ( prezzo , ALL_DECIMALS ) ;
riga . put ( RDOC_PREZZOL , prezzo ) ;
}
riga . put ( RDOC_PREZZO , prezzo ) ;
riga . put ( RDOC_UMQTA , sp . um ( ) ) ;
}
break ;
case ' P ' :
default :
riga . put ( RDOC_QTA , sp . perc ( ) ) ;
break ;
1998-04-30 14:04:19 +00:00
}
if ( cod_iva_cli . empty ( ) )
2006-02-02 17:59:02 +00:00
riga . put ( RDOC_CODIVA , sp . cod_iva ( ) ) ;
1998-04-30 14:04:19 +00:00
else
2006-02-02 17:59:02 +00:00
riga . put ( RDOC_CODIVA , cod_iva_cli ) ;
riga . put ( RDOC_CODCOSTO , sp . cdc ( ) ) ;
riga . put ( RDOC_CODCMS , sp . cms ( ) ) ;
riga . put ( RDOC_FASCMS , sp . fase ( ) ) ;
2010-05-13 15:59:46 +00:00
riga . cms2tipodet ( ) ;
2006-02-02 17:59:02 +00:00
1998-04-30 14:04:19 +00:00
if ( interactive )
{
const int nrow = sh - > insert ( - 1 , FALSE ) ;
riga . autoload ( * sh ) ;
2000-05-05 15:25:49 +00:00
sh - > check_row ( nrow ) ;
1998-04-30 14:04:19 +00:00
}
}
}
2002-02-26 16:20:19 +00:00
}
1997-06-03 15:56:27 +00:00
}
2008-03-26 12:44:04 +00:00
put ( DOC_SPESEUPD , true ) ;
1997-06-03 15:56:27 +00:00
}
2010-01-13 15:59:05 +00:00
// Calcola il peso in Kg degli imballaggi di una data categoria CONAI
2010-01-14 11:57:43 +00:00
real TDocumento : : calc_conai_qta ( TCONAI_class cc )
2010-01-13 16:19:06 +00:00
{
2006-04-13 17:56:02 +00:00
real qta ;
2010-01-14 11:57:43 +00:00
if ( conai_configured_class ( cc ) )
2010-01-13 16:19:06 +00:00
{
FOR_EACH_PHYSICAL_RDOC ( * this , i , r ) if ( r - > is_merce ( ) | | r - > is_omaggio ( ) )
2010-01-14 11:57:43 +00:00
{
const real rowqty = r - > calc_conai_qta ( cc ) ;
qta + = rowqty ;
2010-01-13 15:59:05 +00:00
}
2010-01-14 11:57:43 +00:00
qta . round ( 5 ) ; // Arrotondamento al centigrammo
2009-12-22 16:56:14 +00:00
}
1999-04-06 15:34:39 +00:00
return qta ;
}
void TDocumento : : update_conai ( )
{
2009-12-22 16:56:14 +00:00
if ( main_app ( ) . has_module ( DCAUT , CHK_DONGLE ) & & tipo ( ) . add_conai ( ) & & tipo ( ) . stati_iniziali_modifica ( ) . find ( stato ( ) ) > = 0 )
1999-04-06 15:34:39 +00:00
{
2007-09-17 15:33:04 +00:00
const TRectype & cfven = clifor ( ) . vendite ( ) ;
const bool cli_add_conai = cfven . get_bool ( " ADDCONAI " ) ;
2006-04-13 17:56:02 +00:00
const char * const __conai_cf_names [ ] = { " ESACC " , " ESALL " , " ESCAR " , " ESPLA " , " ESLEG " , " ESVET " } ;
2007-09-17 15:33:04 +00:00
2006-04-13 17:56:02 +00:00
const TDate datadoc = get ( DOC_DATADOC ) ;
2007-09-17 15:33:04 +00:00
const TDate dataes = cfven . get ( CFV_DATAECONAI ) ;
2006-04-13 17:56:02 +00:00
bool esponi_esenti = false ;
2009-09-24 15:27:38 +00:00
TString_array conai_sp ( CONAI_CLASSES ) ; // Codici spesa conai
1999-04-06 15:34:39 +00:00
{
2009-09-24 15:27:38 +00:00
const char * const conai_cod [ CONAI_CLASSES ] = { " CODACC " , " CODALL " , " CODCAR " , " CODPLA " , " CODLEG " , " CODVET " } ;
1999-10-22 10:00:18 +00:00
TConfig c ( CONFIG_DITTA , " ve " ) ;
2009-12-22 16:56:14 +00:00
for ( int i = 0 ; i < CONAI_CLASSES ; i + + )
1999-10-22 10:00:18 +00:00
conai_sp . add ( c . get ( conai_cod [ i ] ) ) ;
2006-04-13 17:56:02 +00:00
esponi_esenti = c . get_bool ( " ESPONIESENTI " ) ;
1999-04-06 15:34:39 +00:00
}
2009-09-24 15:27:38 +00:00
bool updated [ CONAI_CLASSES ] = { false , false , false , false , false , false } ;
2009-09-22 09:38:38 +00:00
for ( int i = physical_rows ( ) ; i > 0 ; i - - )
1999-04-06 15:34:39 +00:00
{
1999-10-22 10:00:18 +00:00
TRiga_documento & r = row ( i ) ;
1999-04-06 15:34:39 +00:00
const bool tipo_conai = r . get_char ( " GENTIPO " ) = = ' C ' ;
1999-10-22 10:00:18 +00:00
// Elimina righe generate
2006-04-13 17:56:02 +00:00
if ( tipo_conai )
1999-04-06 15:34:39 +00:00
{
2006-04-13 17:56:02 +00:00
const TString & cod = r . get ( RDOC_CODART ) ;
2009-09-24 15:27:38 +00:00
const TCONAI_class pos = ( TCONAI_class ) conai_sp . find ( cod ) ;
2009-09-22 09:38:38 +00:00
if ( pos > = CONAI_FIRST & & pos < = CONAI_LAST )
2006-04-13 17:56:02 +00:00
{
if ( cli_add_conai )
{
2007-09-17 15:33:04 +00:00
real perc_esenz = cfven . get_real ( __conai_cf_names [ pos ] ) ;
2006-04-13 17:56:02 +00:00
real qta = calc_conai_qta ( pos ) ;
if ( dataes . ok ( ) & & datadoc > dataes )
perc_esenz = ZERO ;
2009-12-22 17:29:07 +00:00
const bool cli_esente = esponi_esenti & & ( perc_esenz > = CENTO ) ;
2009-12-22 16:56:14 +00:00
if ( ! cli_esente & & ! perc_esenz . is_zero ( ) )
2007-09-17 15:33:04 +00:00
qta = qta * ( CENTO - perc_esenz ) / CENTO ; // More precise
2006-04-13 17:56:02 +00:00
if ( qta > ZERO )
{
r . put ( RDOC_QTA , qta ) ;
if ( cli_esente )
r . zero ( RDOC_PREZZO ) ;
}
else
destroy_row ( i , true ) ;
}
else
destroy_row ( i , true ) ;
updated [ pos ] = true ;
}
1999-04-06 15:34:39 +00:00
}
1999-10-22 10:00:18 +00:00
}
// Genera nuove righe
1999-04-06 15:34:39 +00:00
if ( cli_add_conai )
{
2013-03-15 11:08:44 +00:00
const TString4 cod_iva_cli = codesiva ( ) ;
1999-04-26 15:58:05 +00:00
TSpesa_prest sp ;
2009-12-22 17:29:07 +00:00
FOR_EACH_CONFIGURED_CONAI_CLASS ( ct ) if ( ! updated [ ct ] )
2006-04-13 17:56:02 +00:00
{
2009-12-22 17:29:07 +00:00
const real perc_esenz = cfven . get_real ( __conai_cf_names [ ct ] ) ;
2010-01-13 16:19:06 +00:00
const bool cli_esente = ( esponi_esenti ) & & ( perc_esenz > = CENTO ) ;
const real qta_lorda = calc_conai_qta ( ct ) ;
real qta = qta_lorda ;
if ( ! cli_esente & & ! qta_lorda . is_zero ( ) & & ! perc_esenz . is_zero ( ) )
{
2010-01-14 11:57:43 +00:00
qta = qta_lorda * ( CENTO - perc_esenz ) / CENTO ;
qta . round ( 5 ) ;
2010-01-13 16:19:06 +00:00
}
2010-01-13 15:59:05 +00:00
if ( qta > ZERO )
2006-04-13 17:56:02 +00:00
{
2009-12-22 17:29:07 +00:00
const TString & s = conai_sp . row ( ct ) ;
if ( sp . read ( s ) ! = NOERR )
2013-03-15 11:08:44 +00:00
message_box ( FR ( " Il codice spesa CONAI %s specificato nei parametri ditta <20> assente: '%s' " ) ,
2009-12-22 17:29:07 +00:00
conai_material ( ct ) , ( const char * ) s ) ;
else
{
const TString4 tipo = sp . tipo_riga ( ) ;
TRiga_documento & riga = new_row ( tipo ) ;
riga . put ( RDOC_CODART , s ) ;
riga . generata ( ) ;
2011-10-04 14:55:35 +00:00
riga . put ( RDOC_GENTIPO , ' C ' ) ;
2009-12-22 17:29:07 +00:00
riga . put ( RDOC_DESCR , sp . descrizione ( ) ) ;
riga . put ( RDOC_QTA , qta ) ;
const real cambio = get_real ( DOC_CAMBIO ) ;
const TString4 valuta = get ( DOC_CODVAL ) ;
real prezzo = cli_esente ? ZERO : sp . prezzo ( ) ;
2012-02-24 15:00:45 +00:00
sppr_calc ( sp , valuta , cambio , prezzo ) ;
2009-12-22 17:29:07 +00:00
if ( this - > tipo ( ) . calcolo_lordo ( ) )
prezzo = riga . iva ( ) . lordo ( prezzo , ALL_DECIMALS ) ;
riga . put ( RDOC_PREZZO , prezzo ) ;
riga . put ( RDOC_UMQTA , sp . um ( ) ) ;
if ( cod_iva_cli . empty ( ) )
riga . put ( RDOC_CODIVA , sp . cod_iva ( ) ) ;
else
riga . put ( RDOC_CODIVA , cod_iva_cli ) ;
}
}
2006-04-13 17:56:02 +00:00
}
2009-12-22 17:29:07 +00:00
}
1999-04-06 15:34:39 +00:00
}
}
1998-08-25 18:07:30 +00:00
bool TDocumento : : is_evaso ( ) const
{
2000-10-03 13:45:12 +00:00
bool ok = is_ordine ( ) | | is_bolla ( ) | | is_generic ( ) ;
1998-08-25 18:07:30 +00:00
for ( int r = 1 ; ok & & r < = physical_rows ( ) ; r + + )
{
const TRiga_documento & riga = physical_row ( r ) ;
if ( riga . is_evadibile ( ) )
2002-10-23 14:14:55 +00:00
ok = riga . is_evasa ( ) ;
1998-08-25 18:07:30 +00:00
}
return ok ;
}
1999-04-06 15:34:39 +00:00
bool TDocumento : : is_nota_credito ( ) const
2000-10-03 13:45:12 +00:00
{
2009-02-23 11:46:10 +00:00
bool swap = false ;
1999-04-06 15:34:39 +00:00
// Controlla prima l'esistenza del flag nota-credito sul tipo documento;
// se non e' settato controlla la causale
if ( tipo ( ) . nota_credito ( ) )
2009-02-23 11:46:10 +00:00
swap = true ;
1999-04-06 15:34:39 +00:00
else
2000-10-03 13:45:12 +00:00
{
2009-02-23 11:46:10 +00:00
const TString4 codcaus ( tipo ( ) . causale ( ) ) ;
if ( codcaus . full ( ) )
1999-04-06 15:34:39 +00:00
{
TCausale c ( codcaus , data ( ) . year ( ) ) ;
const char sez = c . sezione_clifo ( ) ;
2010-02-08 16:48:48 +00:00
//controllo ulteriore sull'iva
TipoIVA tiva = c . reg ( ) . iva ( ) ;
const char tcf = tipocf ( ) ;
if ( tiva = = nessuna_iva & & tcf > ' ' )
tiva = tcf = = ' C ' ? iva_vendite : iva_acquisti ;
if ( tiva ! = nessuna_iva )
swap = ( ( tiva = = iva_vendite ) ^ ( sez = = ' D ' ) ) ;
1999-04-06 15:34:39 +00:00
}
2000-10-03 13:45:12 +00:00
}
1999-04-06 15:34:39 +00:00
return swap ;
}
1999-10-22 10:00:18 +00:00
2000-05-05 15:25:49 +00:00
TCurrency_documento : : TCurrency_documento ( const real & num , const TDocumento & doc , bool price )
2012-02-24 15:00:45 +00:00
: TCurrency ( ZERO , " " , ZERO , price )
2000-05-05 15:25:49 +00:00
{
2009-02-23 11:46:10 +00:00
const TString4 val = doc . get ( DOC_CODVAL ) ;
2012-02-24 15:00:45 +00:00
force_value ( val , doc . get_real ( DOC_CAMBIO ) ) ;
2000-05-05 15:25:49 +00:00
set_num ( num ) ;
}
1999-10-22 10:00:18 +00:00
int TDocumento : : set_row_ids ( )
{
const int phrw = physical_rows ( ) ;
long maxid = 0L ;
2013-12-13 09:44:56 +00:00
int first_needed = 0 ;
for ( int r = 1 ; r < = phrw ; r + + )
1999-10-22 10:00:18 +00:00
{
const TRiga_documento & row = physical_row ( r ) ;
const long id = row . get_long ( RDOC_IDRIGA ) ;
if ( id > maxid )
maxid = id ;
else
{
2013-12-13 09:44:56 +00:00
if ( first_needed = = 0 & & id < = 0 )
1999-10-22 10:00:18 +00:00
first_needed = r ;
}
}
if ( first_needed > 0 )
{
2013-12-13 09:44:56 +00:00
for ( int r = first_needed ; r < = phrw ; r + + )
1999-10-22 10:00:18 +00:00
{
TRiga_documento & row = ( TRiga_documento & ) physical_row ( r ) ;
const long id = row . get_long ( RDOC_IDRIGA ) ;
if ( id < = 0 )
row . put ( RDOC_IDRIGA , + + maxid ) ;
}
}
return phrw ;
}
const TRiga_documento * TDocumento : : get_row_id ( long id ) const
{
2009-11-18 11:17:58 +00:00
TDocumento & doc = * ( TDocumento * ) this ;
FOR_EACH_PHYSICAL_RDOC_BACK ( doc , r , row )
1999-10-22 10:00:18 +00:00
{
2009-11-18 11:17:58 +00:00
if ( row - > get_long ( RDOC_IDRIGA ) = = id )
return row ;
1999-10-22 10:00:18 +00:00
}
return NULL ;
2005-10-27 13:07:20 +00:00
}
2011-01-21 10:56:22 +00:00
int TDocumento : : id2rownum ( long id ) const
{
const TRiga_documento * rdoc = get_row_id ( id ) ;
return rdoc ? rdoc - > get_int ( RDOC_NRIGA ) : - 1 ;
}
2005-10-27 13:07:20 +00:00
int TDocumento : : tipo_riclassificato ( ) const
{
int tipo_riclassificato = tipo ( ) . tipo ( ) ;
if ( tipo_riclassificato = = TTipo_documento : : _altro )
{
const TCodice_numerazione & num = codice_numerazione ( ) ;
if ( num . fattura_emettere_ricevere ( ) )
tipo_riclassificato = TTipo_documento : : _bolla ;
else
tipo_riclassificato = TTipo_documento : : _fattura ;
}
return tipo_riclassificato ;
2008-03-26 11:24:36 +00:00
}
2008-08-27 23:23:05 +00:00
2009-02-23 11:46:10 +00:00
const TString & TDocumento : : codesiva ( ) const
2008-08-27 23:23:05 +00:00
{
2009-02-23 11:46:10 +00:00
TCli_for & c = clifor ( ) ;
2013-03-15 11:08:44 +00:00
const TString & codiva = c . vendite ( ) . get ( CFV_ASSFIS ) ;
if ( ! c . use_lettere ( ) )
return codiva ;
const TCodiceIVA i ( codiva ) ;
if ( ! i . has_plafond ( ) ) // Era presente nella 3.x, poi <20> sparito nella 10, ora torna nella 11.0 (7-3-2013)
return codiva ;
const TDate datadoc = get ( DOC_DATADOC ) ;
if ( c . read_lettera ( datadoc ) )
return c . vendite ( ) . get ( CFV_ASSFIS ) ; // codiva may be lost
2010-06-21 14:23:50 +00:00
2013-03-15 11:08:44 +00:00
return EMPTY_STRING ;
2008-08-27 23:23:05 +00:00
}
2013-03-15 11:08:44 +00:00
void TDocumento : : get_protocolli_esenzione ( TString & esenzione , TString & data_esenzione ,
TString & registrazione , TString & data_registrazione ) const
2008-08-27 23:23:05 +00:00
{
2009-02-23 11:46:10 +00:00
TCli_for & c = clifor ( ) ;
2008-08-27 23:23:05 +00:00
if ( c . use_lettere ( ) )
{
2009-02-23 11:46:10 +00:00
if ( c . read_lettera ( get_date ( DOC_DATADOC ) , true ) )
2008-08-27 23:23:05 +00:00
{
2009-02-23 11:46:10 +00:00
const TRectype & rec = c . lettera ( ) ;
2008-08-27 23:23:05 +00:00
esenzione = rec . get ( LETINT_VSPROT ) ;
data_esenzione = rec . get ( LETINT_VSDATA ) ;
registrazione = rec . get ( LETINT_NUMPROT ) ;
data_registrazione = rec . get ( LETINT_DATAREG ) ;
}
}
else
{
esenzione = c . vendite ( ) . get ( CFV_VSPROT ) ;
data_esenzione = c . vendite ( ) . get ( CFV_VSDATAREG ) ;
registrazione = c . vendite ( ) . get ( CFV_NSPROT ) ;
data_registrazione = c . vendite ( ) . get ( CFV_NSDATAREG ) ;
}
}