1998-08-25 18:07:30 +00:00
# include <dongle.h>
1998-05-04 09:54:49 +00:00
# include <prefix.h>
1998-08-25 18:07:30 +00:00
# include <tabutil.h>
# include <modaut.h>
# include <utility.h>
1998-05-04 09:54:49 +00:00
1997-06-03 15:56:27 +00:00
# include "velib.h"
# include "vepriv.h"
1998-05-04 09:54:49 +00:00
# include <clifo.h>
1997-08-21 16:47:14 +00:00
1997-06-03 15:56:27 +00:00
# include "veuml.h"
# include "veini.h"
1997-06-27 09:21:13 +00:00
# include "../mg/mglib.h"
1997-05-23 14:26:19 +00:00
1997-06-03 15:56:27 +00:00
# ifndef __SCONTI_H
# include "sconti.h"
# endif
1997-05-23 14:26:19 +00:00
1997-09-26 15:22:39 +00:00
# ifndef __SVLIB01_H
# include "../sv/svlib01.h"
# endif
1998-04-30 14:04:19 +00:00
# ifndef __CGLIB01_H
# include "../cg/cglib01.h"
# endif
1998-08-25 18:07:30 +00:00
# ifndef __CG2103_H
# include "../cg/cg2103.h"
# endif
1997-10-29 11:08:40 +00:00
# ifndef __PRLIB_H
# include "../pr/prlib.h"
# endif
1997-07-25 08:58:30 +00:00
# include "../mg/movmag.h"
1998-08-25 18:07:30 +00:00
1998-11-04 18:04:26 +00:00
// calcola il prezzo per le spese
void sppr_calc ( TRectype & rec , const TString & valuta_doc , const real & cambio , real & prezzo )
{
const TString16 sppr_valuta ( rec . get ( " S4 " ) ) ;
if ( sppr_valuta ! = valuta_doc )
{
TTable val ( " %VAL " ) ;
val . put ( " CODTAB " , sppr_valuta ) ;
if ( val . read ( ) = = NOERR )
{
const real sppr_cambio = val . get_real ( " R10 " ) ;
if ( sppr_cambio ! = ZERO )
prezzo * = sppr_cambio ;
}
if ( cambio ! = ZERO )
prezzo / = cambio ;
}
}
1997-06-27 09:21:13 +00:00
///////////////////////////////////////////////////////////
// Movimento di magazzino
///////////////////////////////////////////////////////////
class TMov_mag_doc : public TMov_mag
{
const TDocumento * _doc ;
1998-11-04 18:04:26 +00:00
TString_array _codmagc ;
1997-06-27 09:21:13 +00:00
protected :
virtual const char * codmag_rauto ( int r ) const ;
1998-11-04 18:04:26 +00:00
public :
void add_magc ( const char * magc ) { _codmagc . add ( magc ) ; }
1997-06-27 09:21:13 +00:00
TMov_mag_doc ( const TDocumento * d ) : _doc ( d ) { }
virtual ~ TMov_mag_doc ( ) { }
} ;
const char * TMov_mag_doc : : codmag_rauto ( int r ) const
1998-11-04 18:04:26 +00:00
{
TRecord_array & b = body ( ) ;
if ( r > b . rows ( ) ) // Can't check non-existant rows
return NULL ;
TRectype & row = b [ r ] ;
const char tr = row . get_char ( RMOVMAG_TIPORIGA ) ;
if ( tr ! = ' D ' & & tr ! = ' A ' ) // These are customer's added rows
1997-06-27 09:21:13 +00:00
return NULL ;
1998-11-04 18:04:26 +00:00
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 + + ;
return j > = 0 ? _codmagc . row ( j ) : NULL ;
1997-06-27 09:21:13 +00:00
}
1998-11-04 18:04:26 +00:00
1997-06-03 15:56:27 +00:00
///////////////////////////////////////////////////////////
// Tipo documento
///////////////////////////////////////////////////////////
1997-05-23 14:26:19 +00:00
1997-06-03 15:56:27 +00:00
TAssoc_array TTipo_documento : : _formule_documento ;
TTipo_documento : : TTipo_documento ( const char * tipodoc )
1998-11-04 18:04:26 +00:00
: TRectype ( LF_TABCOM ) , _tipocf ( ' \0 ' )
1997-05-23 14:26:19 +00:00
{
1997-06-03 15:56:27 +00:00
settab ( " TIP " ) ;
if ( tipodoc & & * tipodoc )
read ( tipodoc ) ;
}
TTipo_documento : : TTipo_documento ( const TRectype & rec )
1998-11-04 18:04:26 +00:00
: TRectype ( rec ) , _tipocf ( ' \0 ' )
1997-05-23 14:26:19 +00:00
{
1997-06-03 15:56:27 +00:00
read_formule ( ) ;
}
TTipo_documento : : ~ TTipo_documento ( )
1998-08-25 18:07:30 +00:00
{
}
1997-06-03 15:56:27 +00:00
int TTipo_documento : : read ( const char * tipodoc )
{
TTable t ( " %TIP " ) ;
put ( " CODTAB " , tipodoc ) ;
int err = TRectype : : read ( t ) ;
_formule = " " ;
if ( err = = NOERR )
read_formule ( ) ;
else
yesnofatal_box ( " Tipo documento errato: %s " , tipodoc ) ;
return err ;
}
1998-11-04 18:04:26 +00:00
const char TTipo_documento : : tipocf ( )
{
if ( _tipocf = = ' \0 ' )
{
TFilename pn = profile_name ( ) ;
pn . ext ( " ini " ) ;
TConfig prof ( pn ) ;
_tipocf = prof . get_char ( " TIPOCF " , " MAIN " ) ;
}
return _tipocf ;
}
const TString_array & TTipo_documento : : keys_descrs ( )
{
if ( _keys_descrs . items ( ) = = 0 )
{
TString16 var , tiporiga ;
TFilename pn ( profile_name ( ) ) ;
pn . ext ( " ini " ) ;
TConfig prof ( pn ) ;
const int numtr = prof . get_int ( " NTIPIRIGA " , " RIGHE " ) ;
TTipo_riga_documento tr ;
_keys_descrs . add ( " " ) ;
_keys_descrs . add ( " " ) ;
TToken_string & k = ( TToken_string & ) _keys_descrs [ 0 ] ;
TToken_string & d = ( TToken_string & ) _keys_descrs [ 1 ] ;
for ( int i = 1 ; i < = numtr ; i + + )
{
var . format ( " %d " , i ) ;
tiporiga = prof . get ( var , " RIGHE " ) ;
tr . read ( tiporiga ) ;
k . add ( tr . codice ( ) ) ;
d . add ( tr . descrizione ( ) ) ;
}
}
return _keys_descrs ;
}
const TString_array & TTipo_documento : : sheet_columns ( )
{
if ( _sheet_columns . items ( ) = = 0 )
{
TString16 col ;
TFilename pn ( profile_name ( ) ) ;
pn . ext ( " ini " ) ;
TConfig prof ( pn ) ;
int ncols = prof . get_int ( " NCOLS " , " SHEET " ) ;
for ( int i = 1 ; i < = ncols ; i + + )
{
col . format ( " %d " , i ) ;
_sheet_columns . add ( prof . get ( col , " SHEET " ) ) ;
}
}
return _sheet_columns ;
}
const TString_array & TTipo_documento : : handlers ( )
1998-08-25 18:07:30 +00:00
{
1998-11-04 18:04:26 +00:00
if ( _handlers . items ( ) = = 0 )
1998-08-25 18:07:30 +00:00
{
1998-11-04 18:04:26 +00:00
TString16 chiave ;
TFilename pn = profile_name ( ) ;
pn . ext ( " ini " ) ;
TConfig prof ( pn ) ;
int numhandler = prof . get_int ( " NHANDLER " , " HANDLERS " ) ; // prof
for ( int i = 1 ; i < = numhandler ; i + + )
{
chiave . format ( " %d " , i ) ;
_handlers . add ( prof . get ( chiave , " HANDLERS " ) ) ;
}
}
return _handlers ;
}
const TString & TTipo_documento : : sconto_riga ( )
{
if ( _sconto_riga . empty ( ) )
{
1998-08-25 18:07:30 +00:00
TFilename pn = profile_name ( ) ;
pn . ext ( " ini " ) ;
1998-11-04 18:04:26 +00:00
TConfig prof ( pn ) ;
_sconto_riga = prof . get ( " GESSCORIGA " ) ;
if ( _sconto_riga . empty ( ) )
_sconto_riga = " N " ;
}
return _sconto_riga ;
}
void TTipo_documento : : set_defaults ( TMask & m )
{
const int items = _defaults . items ( ) ;
if ( items = = 0 ) // Carica lo string_array con i defaults
{
TString16 chiave ;
TFilename pn ( profile_name ( ) ) ;
pn . ext ( " ini " ) ;
TConfig prof ( pn ) ;
const int ndefaults = prof . get_int ( " NDEFAULTS " , " DEFAULT " ) ;
for ( int i = 1 ; i < = ndefaults ; i + + )
{
chiave . format ( " %d " , i ) ;
_defaults . add ( prof . get ( chiave , " DEFAULT " ) ) ;
}
}
for ( int i = 0 ; i < items ; i + + ) // Setta i campi della maschera
{
TToken_string & tt = ( TToken_string & ) _defaults [ i ] ;
const int ncampo = tt . get_int ( 0 ) ;
m . set ( ncampo , tt . get ( 1 ) , TRUE ) ;
1998-08-25 18:07:30 +00:00
}
}
1997-06-03 15:56:27 +00:00
1998-08-25 18:07:30 +00:00
void TTipo_documento : : read_formule ( )
1997-06-03 15:56:27 +00:00
{
1998-11-04 18:04:26 +00:00
TFilename profile ( profile_name ( ) ) ;
profile . ext ( " ini " ) ;
TConfig prof ( profile ) ;
1997-06-03 15:56:27 +00:00
1998-08-25 18:07:30 +00:00
_formule = prof . get ( " CAMPICALC " , " MAIN " ) ;
_formule . add ( prof . get ( " CALCOLI " , " MAIN " ) ) ;
_totale = prof . get ( " TOTALE " , " MAIN " ) ;
1997-06-03 15:56:27 +00:00
if ( _totale . empty ( ) )
1997-08-22 08:39:02 +00:00
_totale = " TOTDOC " ;
TTable frd ( " %FRD " ) ;
frd . put ( " CODTAB " , _totale ) ;
if ( frd . read ( ) ! = NOERR )
_formule_documento . add ( _totale , new TFormula_documento ( _documento , _totale , " IMPONIBILI()+IMPOSTE() " ) , TRUE ) ;
1997-08-21 16:47:14 +00:00
if ( _formule . find ( _totale ) < 0 )
_formule . add ( _totale ) ;
1997-06-03 15:56:27 +00:00
_totale_netto = " _ " ;
_totale_netto < < _totale ;
1997-08-21 16:47:14 +00:00
1998-08-25 18:07:30 +00:00
_basesconto = prof . get ( " BASESCONTO " , " MAIN " ) ;
1997-06-03 15:56:27 +00:00
if ( _basesconto . empty ( ) )
_basesconto = " BASESCONTO " ;
1997-08-22 08:39:02 +00:00
frd . put ( " CODTAB " , _basesconto ) ;
if ( frd . read ( ) ! = NOERR )
_formule_documento . add ( _basesconto , new TFormula_documento ( _documento , _basesconto , " SOMMA( \" IMPONIBILE() \" , \" (TIPO() != 'S') && (TIPO() != 'C') \" ) " ) , TRUE ) ;
1997-08-21 16:47:14 +00:00
if ( _formule . find ( _basesconto ) < 0 )
_formule . add ( _basesconto ) ;
1998-08-25 18:07:30 +00:00
_spese = prof . get ( " SPESE " , " MAIN " ) ;
1997-06-03 15:56:27 +00:00
if ( _spese . empty ( ) )
_spese = " SPESE " ;
1997-08-22 08:39:02 +00:00
frd . put ( " CODTAB " , _spese ) ;
if ( frd . read ( ) ! = NOERR )
_formule_documento . add ( _spese , new TFormula_documento ( _documento , _spese , " SOMMA( \" IMPONIBILE() \" , \" TIPO() == 'S' \" ) " ) , TRUE ) ;
1997-08-21 16:47:14 +00:00
if ( _formule . find ( _spese ) < 0 )
_formule . add ( _spese ) ;
1998-08-25 18:07:30 +00:00
_totvalres = prof . get ( " TOTVALRES " , " MAIN " ) ;
if ( _totvalres . empty ( ) )
_totvalres = " TOTVALRES " ;
_totvalore = prof . get ( " TOTVALORE " , " MAIN " ) ;
if ( _totvalore . empty ( ) )
_totvalore = " TOTVALORE " ;
frd . put ( " CODTAB " , _totvalres ) ;
if ( frd . read ( ) ! = NOERR )
_formule_documento . add ( _totvalres , new TFormula_documento ( _documento , _totvalres , " VALDOC(0) " ) , TRUE ) ;
if ( _formule . find ( _totvalres ) < 0 )
_formule . add ( _totvalres ) ;
frd . put ( " CODTAB " , _totvalore ) ;
if ( frd . read ( ) ! = NOERR )
_formule_documento . add ( _totvalore , new TFormula_documento ( _documento , _totvalore , " VALDOC(1) " ) , TRUE ) ;
if ( _formule . find ( _totvalore ) < 0 )
_formule . add ( _totvalore ) ;
1997-10-02 16:57:49 +00:00
if ( provvigioni ( ) )
{
1998-08-25 18:07:30 +00:00
TString80 campo ( prof . get ( " TOTPROVV " , " MAIN " ) ) ;
1997-10-29 11:08:40 +00:00
if ( campo . empty ( ) )
campo = " TOTPROVV " ;
1997-10-02 16:57:49 +00:00
1997-10-29 11:08:40 +00:00
frd . put ( " CODTAB " , campo ) ;
_totprovv = " _ " ;
_totprovv < < campo ;
1997-10-02 16:57:49 +00:00
if ( frd . read ( ) ! = NOERR )
1997-10-29 11:08:40 +00:00
frd . zero ( ) ;
TString80 expr ( frd . get ( " S1 " ) ) ;
if ( expr . empty ( ) )
expr = " SOMMA( \" PROVV() \" ) " ;
_formule_documento . add ( _totprovv , new TFormula_documento ( _documento , _totprovv , expr , TRUE ) ) ;
if ( _formule . find ( campo ) < 0 )
_formule . add ( campo ) ;
_formule . add ( _totprovv ) ;
_formule_documento . add ( campo , new TFormula_documento ( _documento , campo , " TOTPROVV() " ) , TRUE ) ;
}
1997-06-03 15:56:27 +00:00
}
1997-05-23 14:26:19 +00:00
1997-08-18 16:06:51 +00:00
bool TTipo_documento : : stato_with_mov_mag ( const char stato ) const
1997-07-29 09:53:35 +00:00
{
if ( ! mov_mag ( ) )
return FALSE ;
1997-08-18 16:06:51 +00:00
const char stato_finale ( stato_mov_finale ( ) ) ;
if ( stato_finale > ' ' & & stato > stato_finale )
1997-07-29 09:53:35 +00:00
return FALSE ;
1997-08-18 16:06:51 +00:00
const char stato_iniziale ( stato_mov_iniziale ( ) ) ;
1997-07-29 09:53:35 +00:00
return stato > = stato_iniziale ;
}
1997-06-03 15:56:27 +00:00
TFormula_documento * TTipo_documento : : succ_formula ( bool restart )
{
if ( restart )
_formule . restart ( ) ;
1998-11-04 18:04:26 +00:00
TString formula = _formule . get ( ) ;
while ( formula . not_empty ( ) )
{
if ( formula . blank ( ) )
formula = _formule . get ( ) ;
else
break ;
}
1997-06-03 15:56:27 +00:00
if ( formula . not_empty ( ) )
{
char * expr = NULL ;
1998-11-04 18:04:26 +00:00
const int p = formula . find ( ' = ' ) ;
1997-06-03 15:56:27 +00:00
if ( p > 0 )
{
expr = ( char * ) ( const char * ) formula + p ;
* expr = ' \0 ' ; expr + + ;
}
TFormula_documento * o = ( TFormula_documento * ) _formule_documento . objptr ( formula ) ;
if ( o = = NULL )
1997-05-23 14:26:19 +00:00
{
1997-06-03 15:56:27 +00:00
o = new TFormula_documento ( _documento , formula , expr ) ;
_formule_documento . add ( formula , o ) ;
}
return o ;
}
1998-11-04 18:04:26 +00:00
return NULL ;
1997-06-03 15:56:27 +00:00
}
1997-08-21 16:47:14 +00:00
/////////////////////////////////////////////////////////////
// TRiepilogo IVA
/////////////////////////////////////////////////////////////
TRiepilogo_iva & TRiepilogo_iva : : copy ( const TRiepilogo_iva & a )
{
1997-08-22 08:39:02 +00:00
( TRectype & ) _codiva = ( TRectype & ) a . _codiva ;
1997-08-21 16:47:14 +00:00
_imp = a . _imp ;
_imp_spese = a . _imp_spese ;
_iva = a . _iva ;
_iva_spese = a . _iva_spese ;
_tipo = a . _tipo ;
return * this ;
}
TRiepilogo_iva : : TRiepilogo_iva ( const TIVA & codiva ) : _codiva ( codiva )
{
const TString & t = _codiva . tipo ( ) ;
if ( t = = " VE " )
_tipo = 2 ;
else
if ( t = = " ES " )
_tipo = 4 ;
else
if ( t = = " NI " )
_tipo = 8 ;
else
if ( t = = " NS " )
_tipo = 16 ;
else
_tipo = 1 ;
}
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 ( ) { }
} ;
HIDDEN TAgenti_cache _agenti ;
1998-11-04 18:04:26 +00:00
///////////////////////////////////////////////////////////
// Espressione documento
///////////////////////////////////////////////////////////
TExpr_documento : : TExpr_documento ( const char * expression , TTypeexp type ,
TDocumento * doc , TRiga_documento * row )
: TExpression ( type ) , _doc ( doc ) , _row ( row )
{
if ( ! set ( expression , type ) )
error_box ( " Wrong expression : %s " , expression ) ;
}
int TExpr_documento : : parse_user_func ( const char * name , int nparms ) const
{
if ( strcmp ( name , " SOMMA " ) = = 0 )
return nparms > 0 | | nparms < 3 ? _somma : - 1 ;
if ( strcmp ( name , " BOLLI " ) = = 0 )
return nparms > 0 | | nparms < 4 ? _bolli : - 1 ;
if ( strcmp ( name , " _BOLLI " ) = = 0 )
return nparms > 0 | | nparms < 3 ? _bolli_int : - 1 ;
if ( strcmp ( name , " SPESEINC " ) = = 0 )
return nparms > 0 | | nparms < 4 ? _spinc : - 1 ;
if ( strcmp ( name , " PREZZO " ) = = 0 )
return nparms < 4 ? _prezzo : - 1 ;
if ( strcmp ( name , " IMPORTO " ) = = 0 )
return nparms < 4 ? _importo : - 1 ;
if ( strcmp ( name , " SCONTO " ) = = 0 )
return nparms < 2 ? _sconto : - 1 ;
if ( strcmp ( name , " IMPONIBILE " ) = = 0 )
return nparms = = 0 ? _imponibile : - 1 ;
if ( strcmp ( name , " IVA " ) = = 0 )
return nparms = = 0 ? _iva : - 1 ;
if ( strcmp ( name , " PROVV " ) = = 0 )
return nparms < 2 ? _provv : - 1 ;
if ( strcmp ( name , " QTARES " ) = = 0 )
return nparms < 2 ? _qtares : - 1 ;
if ( strcmp ( name , " VALDOC " ) = = 0 )
return nparms < 3 ? _valdoc : - 1 ;
if ( strcmp ( name , " TIPO " ) = = 0 )
return nparms = = 0 ? _tipo : - 1 ;
if ( strcmp ( name , " IMPONIBILI " ) = = 0 )
return nparms < 3 ? _imponibili : - 1 ;
if ( strcmp ( name , " IMPOSTE " ) = = 0 )
return nparms < 3 ? _imposte : - 1 ;
if ( strcmp ( name , " TOTPROVV " ) = = 0 )
return nparms < 3 ? _totprovv : - 1 ;
return - 1 ;
}
void TExpr_documento : : evaluate_user_func ( int index , int nparms , TEval_stack & stack , TTypeexp type ) const
{
switch ( index )
{
case _somma :
{
const TString cond ( nparms = = 2 ? stack . pop_string ( ) : " STR(1) " ) ;
const TString & field = stack . pop_string ( ) ;
real somma ;
if ( _doc ! = NULL )
{
TExpr_documento cond_expr ( cond , _strexpr , _doc ) ;
const int cond_nvars = cond_expr . numvar ( ) ;
TExpr_documento expr ( field , _numexpr , _doc ) ;
const int nvars = expr . numvar ( ) ;
const int nrows = _doc - > rows ( ) ;
for ( int i = nrows ; i > 0 ; i - - )
{
TRiga_documento & riga = ( TRiga_documento & ) ( * _doc ) [ i ] ;
for ( int j = cond_nvars - 1 ; j > = 0 ; j - - )
{
const char * s = cond_expr . varname ( j ) ;
TFieldref f ( s , 0 ) ;
cond_expr . setvar ( j , f . read ( riga ) ) ;
}
cond_expr . set_row ( & riga ) ;
if ( ( bool ) cond_expr )
{
for ( j = nvars - 1 ; j > = 0 ; j - - )
{
const char * s = expr . varname ( j ) ;
TFieldref f ( s , 0 ) ;
expr . setvar ( j , f . read ( riga ) ) ;
}
expr . set_row ( & riga ) ;
somma + = expr . as_real ( ) ;
}
}
}
stack . push ( somma ) ;
}
break ;
case _spinc :
{
int ndec = AUTO_DECIMALS ;
bool netto = FALSE ;
if ( nparms > 2 )
ndec = ( int ) stack . pop_real ( ) . integer ( ) ;
if ( nparms > 1 )
netto = ! stack . pop_real ( ) . is_zero ( ) ;
real & r = stack . peek_real ( ) ;
if ( _doc )
r = _doc - > spese_incasso ( r , ndec , netto ? _netto : _lordo ) ;
else
r = ZERO ;
}
break ;
case _bolli :
{
int ndec = AUTO_DECIMALS ;
bool netto = FALSE ;
if ( nparms > 2 )
ndec = ( int ) stack . pop_real ( ) . integer ( ) ;
if ( nparms > 1 )
netto = ! stack . pop_real ( ) . is_zero ( ) ;
real & r = stack . peek_real ( ) ;
if ( _doc )
{
r + = _doc - > spese_incasso ( r , ndec ) ;
r = _doc - > bolli ( r , ndec , netto ? _netto : _lordo ) ;
}
else
r = ZERO ;
}
break ;
case _bolli_int :
{
int ndec = AUTO_DECIMALS ;
if ( nparms > 2 )
ndec = ( int ) stack . pop_real ( ) . integer ( ) ;
real & r = stack . peek_real ( ) ;
if ( _doc )
{
real r1 = _doc - > spese_incasso ( r , ndec ) ;
r + = r1 ;
r1 + = _doc - > bolli ( r , ndec ) ;
r = r1 ;
}
else
r = ZERO ;
}
break ;
case _prezzo :
{
int ndec = AUTO_DECIMALS ;
bool lordo = FALSE ;
bool scontato = FALSE ;
if ( nparms > 2 )
ndec = ( int ) stack . pop_real ( ) . integer ( ) ;
if ( nparms > 1 )
lordo = ! stack . pop_real ( ) . is_zero ( ) ;
if ( nparms > 0 )
scontato = ! stack . peek_real ( ) . is_zero ( ) ;
else
stack . push ( ZERO ) ;
real & val = stack . peek_real ( ) ;
if ( _row )
val = _row - > prezzo ( scontato , lordo , ndec ) ;
else
val = ZERO ;
}
break ;
case _importo :
{
int ndec = AUTO_DECIMALS ;
bool lordo = FALSE ;
bool scontato = FALSE ;
if ( nparms > 2 )
ndec = ( int ) stack . pop_real ( ) . integer ( ) ;
if ( nparms > 1 )
lordo = ! stack . pop_real ( ) . is_zero ( ) ;
if ( nparms > 0 )
scontato = ! stack . peek_real ( ) . is_zero ( ) ;
else
stack . push ( ZERO ) ;
real & val = stack . peek_real ( ) ;
if ( _row )
val = _row - > importo ( scontato , lordo , ndec ) ;
else
val = ZERO ;
}
break ;
case _imponibile :
{
real r ;
if ( _row )
r = _row - > imponibile ( ) ;
stack . push ( r ) ;
}
break ;
case _sconto :
{
int ndec = AUTO_DECIMALS ;
if ( nparms > 0 )
ndec = ( int ) stack . peek_real ( ) . integer ( ) ;
else
stack . push ( ZERO ) ;
real & val = stack . peek_real ( ) ;
if ( _row )
{
if ( _row - > is_sconto ( ) )
val = - _row - > importo ( FALSE , FALSE , ndec ) ;
else
val = _row - > importo ( FALSE , FALSE , ndec ) - _row - > importo ( TRUE , FALSE , ndec ) ;
}
else
val = ZERO ;
}
break ;
case _iva :
{
real r ;
if ( _row )
r = _row - > imposta ( ) ;
stack . push ( r ) ;
}
break ;
case _provv :
{
int ndec = AUTO_DECIMALS ;
if ( nparms > 0 )
ndec = ( int ) stack . peek_real ( ) . integer ( ) ;
else
stack . push ( ZERO ) ;
real & val = stack . peek_real ( ) ;
if ( _row )
val = _row - > provvigione ( ndec ) ;
else
val = ZERO ;
}
break ;
case _qtares :
{
int ndec = AUTO_DECIMALS ;
if ( nparms > 0 )
ndec = ( int ) stack . peek_real ( ) . integer ( ) ;
else
stack . push ( ZERO ) ;
real & val = stack . peek_real ( ) ;
if ( _row )
val = _row - > qtaresidua ( ) ;
else
val = ZERO ;
}
break ;
case _valdoc :
{
int ndec = AUTO_DECIMALS ;
bool totale = TRUE ; // Totale o residuo per documento
if ( nparms > 1 )
ndec = ( int ) stack . pop_real ( ) . integer ( ) ;
if ( nparms > 0 )
totale = ! stack . peek_real ( ) . is_zero ( ) ;
else
stack . push ( ZERO ) ;
real & r = stack . peek_real ( ) ;
if ( _doc )
r = _doc - > valore ( totale , ndec ) ;
else
r = ZERO ;
}
break ;
case _tipo :
{
TString s ;
if ( _row )
s < < _row - > tipo ( ) . tipo ( ) ;
stack . push ( s ) ;
}
break ;
case _imponibili :
{
int ndec = AUTO_DECIMALS ;
bool spese = FALSE ;
if ( nparms > 1 )
ndec = ( int ) stack . pop_real ( ) . integer ( ) ;
if ( nparms > 0 )
spese = ! stack . peek_real ( ) . is_zero ( ) ;
else
stack . push ( ZERO ) ;
real & val = stack . peek_real ( ) ;
val = _doc - > imponibile ( spese , ndec ) ;
}
break ;
case _imposte :
{
int ndec = AUTO_DECIMALS ;
bool spese = FALSE ;
if ( nparms > 1 )
ndec = ( int ) stack . pop_real ( ) . integer ( ) ;
if ( nparms > 0 )
spese = ! stack . peek_real ( ) . is_zero ( ) ;
else
stack . push ( ZERO ) ;
real & val = stack . peek_real ( ) ;
val = _doc - > imposta ( spese , ndec ) ;
}
break ;
case _totprovv :
{
int ndec = AUTO_DECIMALS ;
if ( nparms > 0 )
ndec = ( int ) stack . peek_real ( ) . integer ( ) ;
else
stack . push ( ZERO ) ;
real & val = stack . peek_real ( ) ;
val = _doc - > provvigione ( ndec ) ;
}
break ;
default :
TExpression : : evaluate_user_func ( index , nparms , stack , type ) ;
break ;
}
}
TObject * TExpr_documento : : dup ( ) const
{
TExpr_documento * o = new TExpr_documento ( * this ) ;
return o ;
}
///////////////////////////////////////////////////////////
// Formula documento
///////////////////////////////////////////////////////////
TFormula_documento : : TFormula_documento ( TTipo_formula tipo , const char * codice , const char * expr , bool numexpr )
: TRectype ( LF_TABCOM ) , _expr ( NULL )
{
_tab = tipo = = _documento ? " FRD " : " FRR " ;
settab ( _tab ) ;
_tab . insert ( " % " ) ;
if ( codice & & * codice )
read ( codice , expr , numexpr ) ;
}
TFormula_documento : : TFormula_documento ( const TRectype & rec )
: TRectype ( rec ) , _expr ( NULL )
{
_tab = " % " ;
_tab < < rec . get ( " COD " ) ;
_expr = new TExpr_documento ( expr_string ( ) , expr_type ( ) ) ;
}
TFormula_documento : : ~ TFormula_documento ( )
{
if ( _expr ) delete _expr ;
}
int TFormula_documento : : read ( const char * codice , const char * expr , bool numexpr )
{
if ( _expr ! = NULL )
{
delete _expr ;
_expr = NULL ;
}
put ( " CODTAB " , codice ) ;
int err = NOERR ;
if ( expr & & * expr )
{
put ( " S1 " , expr ) ;
put ( " B0 " , numexpr ? " X " : " " ) ;
}
else
{
TTable t ( _tab ) ;
err = TRectype : : read ( t ) ;
}
if ( err = = NOERR )
{
const TString & e = expr_string ( ) ;
_expr = new TExpr_documento ( e , expr_type ( ) ) ;
}
else
{
zero ( ) ;
put ( " CODTAB " , codice ) ;
}
return err ;
}
1997-06-03 15:56:27 +00:00
///////////////////////////////////////////////////////////
// Documento per vendite
///////////////////////////////////////////////////////////
1997-08-26 12:38:08 +00:00
long TDocumento : : _firm = - 1 ;
1997-06-03 15:56:27 +00:00
TAssoc_array TDocumento : : _tipi ;
1997-08-18 15:24:00 +00:00
TAssoc_array TDocumento : : _numerazioni ;
1997-08-21 16:47:14 +00:00
TString16 TDocumento : : _codiva_spese ;
TString16 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 ;
1997-06-03 15:56:27 +00:00
1998-11-04 18:04:26 +00:00
HIDDEN TStats_agg _st_agg ;
HIDDEN TAssoc_array _docs_to_agg ;
void TDocumento : : init ( )
{
1997-08-18 16:06:51 +00:00
add_file ( LF_RIGHEDOC , " NRIGA " ) ;
1998-11-04 18:04:26 +00:00
set_memo_fld ( " G1 " ) ;
1997-06-12 16:26:22 +00:00
_tipocf = new TRecfield ( * this , " TIPOCF " ) ;
_codcf = new TRecfield ( * this , " CODCF " ) ;
_cod_occas = new TRecfield ( * this , " OCFPI " ) ;
1997-10-13 15:22:11 +00:00
_provv_agente = new TProvvigioni_agente ;
1998-11-04 18:04:26 +00:00
_sconto = _esenzione = NULL ;
_stato_originale = ' ' ;
1997-08-18 16:06:51 +00:00
for ( int i = 3 ; i > = 0 ; i - - )
1997-09-26 15:22:39 +00:00
_liv_len [ i ] = 0 ;
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
1998-11-04 18:04:26 +00:00
TDocumento : : TDocumento ( )
: TMultiple_rectype ( LF_DOC )
{
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
if ( _provv_agente ! = NULL ) delete _provv_agente ;
1997-06-03 15:56:27 +00:00
if ( _sconto ! = NULL ) delete _sconto ;
if ( _esenzione ! = NULL ) delete _esenzione ;
}
1998-05-04 09:54:49 +00:00
inline const TString & TDocumento : : codiva_spese ( ) const
1997-10-23 10:55:09 +00:00
{ ( ( TDocumento * ) this ) - > test_firm ( ) ; return _codiva_spese ; }
1998-05-04 09:54:49 +00:00
inline 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 )
{
1998-08-25 18:07:30 +00:00
_has_mag = dongle ( ) . active ( MGAUT ) ;
_has_stat_ven = dongle ( ) . active ( SVAUT ) ;
_has_provv = dongle ( ) . active ( PRAUT ) ;
1997-09-26 15:22: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
}
1997-06-03 15:56:27 +00:00
real TDocumento : : spese_incasso ( real & imp , int ndec , TTipo_importo t ) const
{
real imp_spese ;
real percentuale = get_real ( " PERCSPINC " ) ;
static TArray spese_inc ;
if ( percentuale > ZERO )
{
1997-10-02 16:57:49 +00:00
if ( ndec = = AUTO_DECIMALS )
ndec = in_valuta ( ) ? 3 : 0 ;
1997-06-03 15:56:27 +00:00
if ( spese_inc . objptr ( _rim_dir ) = = NULL )
{
TConfig conf ( CONFIG_STUDIO ) ;
for ( TTipo_pag p = _rim_dir ; p < _nessun_pag ; p = ( TTipo_pag ) ( ( int ) p + 1 ) )
1997-05-23 14:26:19 +00:00
{
1997-06-03 15:56:27 +00:00
real r ( conf . get ( " IMPSPINC " , " ve " , p ) ) ;
spese_inc . add ( r , p ) ;
1997-05-23 14:26:19 +00:00
}
1997-06-03 15:56:27 +00:00
}
TPagamento & pag = ( ( TDocumento * ) this ) - > pagamento ( ) ;
const int nrate = pag . n_rate ( ) ;
for ( int i = 0 ; i < nrate ; i + + )
{
const TTipo_pag p = ( TTipo_pag ) pag . tipo_rata ( i ) ;
imp_spese + = ( real & ) spese_inc [ p ] ;
}
imp_spese * = percentuale / 100.0 ;
real cambio = get_real ( " CAMBIO " ) ;
if ( cambio = = ZERO )
cambio = 1.0 ;
1997-08-21 16:47:14 +00:00
real iva_spese ( iva ( imp_spese , TRiga_documento : : iva ( codiva_spese ( ) ) , ndec ) ) ;
1997-06-03 15:56:27 +00:00
if ( t = = _lordo )
imp_spese + = iva_spese ;
else
if ( t = = _imposta )
imp_spese = iva_spese ;
imp_spese / = cambio ;
imp_spese . round ( ndec ) ;
}
return imp_spese ;
}
real TDocumento : : bolli ( real & imp , int ndec , TTipo_importo t ) const
{
real tot_bolli ;
static TArray sca_bolli ;
static TArray imp_bolli ;
static int nscagl ;
TLocalisamfile clifo ( LF_CLIFO ) ;
1998-05-04 09:54:49 +00:00
short estero = 2 ;
1997-06-03 15:56:27 +00:00
if ( get_bool ( " ADDBOLLI " ) )
{
1997-10-02 16:57:49 +00:00
if ( ndec = = AUTO_DECIMALS )
ndec = in_valuta ( ) ? 3 : 0 ;
1997-06-03 15:56:27 +00:00
real cambio = get_real ( " CAMBIO " ) ;
if ( cambio = = ZERO )
cambio = 1.0 ;
real importo = imp * cambio ;
TPagamento & pag = ( ( TDocumento * ) this ) - > pagamento ( ) ;
const int nrate = pag . n_rate ( ) ;
real old_bolli = - 1.00 ;
real iva_bolli ;
real imp_orig = imposta ( ) ;
real sp_orig = spese ( ) ;
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 ;
const real imposte = imp_orig * cambio + iva_bolli ;
const real imp_spese = sp_orig * cambio + tot_bolli - iva_bolli ;
const real imponibile = importo - imposte - imp_spese ;
1997-05-23 14:26:19 +00:00
1997-06-03 15:56:27 +00:00
tot_bolli = ZERO ;
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
{
1997-06-03 15:56:27 +00:00
if ( sca_bolli . objptr ( 0 ) = = NULL )
1997-05-23 14:26:19 +00:00
{
1997-06-03 15:56:27 +00:00
TConfig conf ( CONFIG_STUDIO ) ;
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 ) ;
}
}
for ( int i = 0 ; i < nscagl - 1 ; i + + )
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 :
{
if ( estero = = 2 )
{
clifo . put ( " TIPOCF " , get ( " TIPOCF " ) ) ;
clifo . put ( " CODCF " , get ( " CODCF " ) ) ;
if ( clifo . read ( ) ! = NOERR )
clifo . zero ( ) ;
const TString16 stato ( clifo . get ( " STATOPAIV " ) ) ;
estero = stato . not_empty ( ) & & stato ! = " IT " ;
if ( ! estero )
estero = clifo . get ( " STATOCF " ) . not_empty ( ) | | clifo . get ( " COMCF " ) [ 0 ] = = ' Z ' ;
}
real r ( imp ) ;
r . ceil ( - 3 ) ;
if ( estero )
r * = 0.009 ;
else
r * = 0.012 ;
r . round ( - 2 ) ;
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
}
1997-08-21 16:47:14 +00:00
iva_bolli = iva ( tot_bolli , TRiga_documento : : iva ( codiva_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 ;
tot_bolli / = cambio ;
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
bool TDocumento : : modificabile ( ) const
{
const char stato_attuale = stato ( ) ;
if ( stato_attuale < = ' ' )
return TRUE ;
TString80 stati_modifica = tipo ( ) . stati_iniziali_modifica ( ) ;
return stati_modifica . trim ( ) . empty ( ) | | stati_modifica . find ( stato_attuale ) > = 0 ;
}
bool TDocumento : : cancellabile ( ) const
{
const char stato_attuale = stato ( ) ;
if ( stato_attuale < = ' ' )
return TRUE ;
TString80 stati_cancellazione = tipo ( ) . stati_iniziali_cancellazione ( ) ;
return stati_cancellazione . trim ( ) . empty ( ) | | stati_cancellazione . find ( stato_attuale ) > = 0 ;
}
bool TDocumento : : stampabile ( ) const
{
const char stato_attuale = stato ( ) ;
if ( stato_attuale < = ' ' )
return TRUE ;
TString80 stati_stampa = tipo ( ) . stati_iniziali_stampa ( ) ;
return stati_stampa . trim ( ) . empty ( ) | | stati_stampa . find ( stato_attuale ) > = 0 ;
}
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 ) ;
rec . put ( " PROVV " , provv ) ;
rec . put ( " ANNO " , anno ) ;
rec . put ( " CODNUM " , codnum ) ;
rec . put ( " NDOC " , numdoc ) ;
}
// Funzione statica utile a tutti gli utenti di LF_DOC e LF_RIGHEDOC
void TDocumento : : copy_data ( TRectype & dst , const TRectype & src )
{
// Memorizza tutti i campi chiave
const char provv = dst . get_char ( " PROVV " ) ;
const int anno = dst . get_int ( " ANNO " ) ;
const TString16 codnum = dst . get ( " CODNUM " ) ;
const long numdoc = dst . get_long ( " NDOC " ) ;
const int nriga = dst . num ( ) = = LF_RIGHEDOC ? dst . get_int ( " NRIGA " ) : 0 ;
// Copia tutto il record
dst = src ;
// Ripristina tutti i campi chiave
set_key ( dst , provv , anno , codnum , numdoc ) ;
if ( nriga > 0 )
1998-11-04 18:04:26 +00:00
{
1997-06-03 15:56:27 +00:00
dst . put ( " NRIGA " , nriga ) ;
1998-11-04 18:04:26 +00:00
dst . zero ( RDOC_MOVMAG ) ;
}
else
dst . zero ( DOC_MOVMAG ) ;
1997-06-03 15:56:27 +00:00
}
1997-05-23 14:26:19 +00:00
1997-06-03 15:56:27 +00:00
void TDocumento : : copy_contents ( const TDocumento & src )
{
copy_data ( head ( ) , src . head ( ) ) ;
destroy_rows ( ) ;
const int rows = src . physical_rows ( ) ;
1997-05-23 14:26:19 +00:00
1997-06-03 15:56:27 +00:00
for ( int i = 0 ; i < rows ; i + + )
1997-05-23 14:26:19 +00:00
{
1997-06-03 15:56:27 +00:00
const TRiga_documento & s = src [ i ] ;
TRiga_documento & r = new_row ( s . tipo ( ) . codice ( ) ) ;
copy_data ( r , s ) ;
}
}
TRiga_documento & TDocumento : : insert_row ( int row , const char * tipo )
{
1997-08-18 16:06:51 +00:00
TRiga_documento & r = ( TRiga_documento & ) TMultiple_rectype : : insert_row ( row ) ; // ok
1997-06-03 15:56:27 +00:00
if ( 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 )
{
1997-08-18 16:06:51 +00:00
TRiga_documento & r = ( TRiga_documento & ) TMultiple_rectype : : new_row ( ) ; // ok
1997-06-03 15:56:27 +00:00
if ( 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 )
1997-06-03 15:56:27 +00:00
{
1997-08-18 16:06:51 +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
if ( is_ordine ( ) )
{
TDate datacons ( get_date ( DOC_DATACONS ) ) ;
for ( int i = rows ( ) ; i > 0 ; i - - )
{
TRiga_documento & r = row ( i ) ;
TRecfield dcons ( r , RDOC_DATACONS ) ;
if ( datacons = = dcons )
dcons = " " ;
}
}
1997-10-02 16:57:49 +00:00
if ( err = = NOERR & & tipo ( ) . statistiche ( ) & & _has_stat_ven )
1997-09-26 15:22:39 +00:00
{
TString80 key ( get ( DOC_PROVV ) ) ; key < < get ( DOC_ANNO ) ; key < < get ( DOC_CODNUM ) ; key < < get ( DOC_NDOC ) ;
TObject * o = _docs_to_agg . objptr ( key ) ;
if ( lockop > = _lock & & o = = NULL )
{
_docs_to_agg . add ( key , key ) ;
for ( int i = physical_rows ( ) ; i > 0 ; i - - )
_st_agg . sub ( row ( i ) ) ;
}
else
if ( lockop = = _unlock & & o ! = NULL )
{
_docs_to_agg . remove ( key ) ;
for ( int i = physical_rows ( ) ; i > 0 ; i - - )
_st_agg . add ( row ( i ) ) ;
}
if ( _docs_to_agg . items ( ) = = 0 )
_st_agg . update ( ) ;
}
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 )
{
const char tn = tipo_numerazione ( ) ;
const int an = anno ( ) ;
const TString16 nu = numerazione ( ) ;
numdoc = get_next_key ( tn , an , nu ) ;
}
1997-08-18 16:06:51 +00:00
put ( DOC_NDOC , numdoc ) ; // Aggiorna testata
TMultiple_rectype : : renum_key ( ) ; // Aggiorna righe ok
1997-06-03 15:56:27 +00:00
return numdoc ;
}
void TDocumento : : set_riga_sconto ( )
{
const TString80 sconto ( get ( " SCONTOPERC " ) ) ;
if ( sconto . empty ( ) )
{
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 )
{
1998-08-25 18:07:30 +00:00
static TString16 _tipo_riga_sc ;
1997-06-03 15:56:27 +00:00
if ( _tipo_riga_sc . empty ( ) )
{
TConfig conf ( CONFIG_STUDIO ) ;
_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 ( ) )
{
TTable tri ( " %TRI " ) ;
for ( tri . first ( ) ; tri . good ( ) ; tri . next ( ) )
{
if ( tri . get ( " S7 " ) = = " C " )
{
_tipo_riga_sc = tri . get ( " CODTAB " ) ; // Prende il primo tipo SCONTO che trova...
break ;
}
}
if ( _tipo_riga_sc . not_empty ( ) )
{
conf . set ( " TRSCONTI " , _tipo_riga_sc , " ve " ) ;
warning_box ( " Il tipo riga sconti di testa non risultava impostato. \n L'applicazione usera' automaticamente il tipo %s " , ( const char * ) _tipo_riga_sc ) ;
}
else
error_box ( " Il tipo riga sconti di testa non risulta impostato. \n Impossibile reperire un tipo riga di default. \n Verificare la correttezza dei tipi riga. " ) ;
}
1997-06-03 15:56:27 +00:00
}
_sconto = new TRiga_documento ( this , _tipo_riga_sc ) ;
_sconto - > put ( " DESCR " , " Sconto " ) ;
}
_sconto - > put ( " SCONTO " , sconto ) ;
}
}
1997-05-23 14:26:19 +00:00
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 ( ) ;
const TIVA codes ( c . vendite ( ) . get ( CFV_ASSFIS ) ) ;
const TString16 v_esenzione ( c . vendite ( ) . get ( CFV_VSPROT ) ) ;
const TString16 v_data_esenzione ( c . vendite ( ) . get ( CFV_VSDATAREG ) ) ;
1997-06-03 15:56:27 +00:00
// const TString16 ufficio_IVA; ??
1997-06-12 16:26:22 +00:00
const TString16 n_registrazione ( c . vendite ( ) . get ( CFV_NSPROT ) ) ;
const TString16 n_data_registrazione ( c . vendite ( ) . get ( CFV_NSDATAREG ) ) ;
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
{
1997-06-03 15:56:27 +00:00
esente = FALSE ;
const TString16 codiva ( codes . codice ( ) ) ;
for ( int i = physical_rows ( ) ; ! esente & & i > 0 ; i - - )
esente = codiva = = row ( i ) . get ( " CODIVA " ) ;
}
1997-05-23 14:26:19 +00:00
1997-06-03 15:56:27 +00:00
if ( ! esente )
{
if ( _esenzione ! = NULL )
delete _esenzione ;
_esenzione = NULL ;
}
else
{
1998-08-25 18:07:30 +00:00
static TString16 _tipo_riga_es ;
1997-06-03 15:56:27 +00:00
static real _bollo_es ;
if ( _tipo_riga_es . empty ( ) )
{
1998-08-25 18:07:30 +00:00
TConfig conf ( CONFIG_STUDIO ) ;
1997-06-03 15:56:27 +00:00
_tipo_riga_es = conf . get ( " TRESENZ " , " ve " ) ;
_bollo_es = ( real ) conf . get ( " BOLLIES " , " ve " ) ;
1998-08-25 18:07:30 +00:00
CHECK ( _tipo_riga_es . not_empty ( ) , " Manca TRESENZ nel PRASSIS.INI " ) ;
1997-06-03 15:56:27 +00:00
}
if ( _esenzione = = NULL )
_esenzione = new TRiga_documento ( this , _tipo_riga_es ) ;
1998-08-25 18:07:30 +00:00
TString d ( 256 ) ; d . format ( " Fattura non imponibile come da vostra dichiarazione " ) ;
1997-06-03 15:56:27 +00:00
_esenzione - > put ( " DESCR " , d ) ;
/* rilasciata dall' ufficio IVA di %s*/
d . format ( " e n. %s del %s da noi annotata al n. %s il %s. Marca da bollo da Lit. %s sull' originale. " ,
( const char * ) v_esenzione , ( const char * ) v_data_esenzione ,
/*(const char *) ufficio_IVA, */ ( const char * ) n_registrazione ,
( const char * ) n_data_registrazione , _bollo_es . string ( " . " ) ) ;
_esenzione - > put ( " DESCLUNGA " , " X " ) ;
_esenzione - > put ( " DESCEST " , d ) ;
1997-05-23 14:26:19 +00:00
}
1997-06-03 15:56:27 +00:00
}
void TDocumento : : dirty_fields ( )
{
for ( TDocumento_variable_field * f = ( TDocumento_variable_field * ) first_variable_field ( ) ;
f ! = NULL ; f = ( TDocumento_variable_field * ) succ_variable_field ( ) )
1997-08-21 16:47:14 +00:00
f - > set_dirty ( ) ;
dirty_tabella_iva ( ) ;
1997-08-18 16:06:51 +00:00
for ( int i = loaded_rows ( ) ; i > 0 ; i - - )
1997-06-03 15:56:27 +00:00
{
1998-08-25 18:07:30 +00:00
TRiga_documento & r = ( TRiga_documento & ) row ( i ) ;
1997-06-03 15:56:27 +00:00
if ( r . doc_dependent ( ) )
r . dirty_fields ( FALSE ) ;
}
}
1997-06-12 16:26:22 +00:00
int TDocumento : : write_rewrite ( TBaseisamfile & f , bool re ) const
1997-08-18 16:06:51 +00:00
{
TDocumento & myself = * ( ( TDocumento * ) this ) ;
const bool new_doc = nuovo ( ) | | numero ( ) < = 0 ; // E' nuovo di zecca!
if ( new_doc )
{
char stato_finale = tipo ( ) . stato_finale_inserimento ( ) ;
if ( stato_finale > ' ' )
myself . stato ( stato_finale ) ;
}
else
1997-08-28 17:11:17 +00:00
{
1998-11-04 18:04:26 +00:00
// if (_stato_originale == stato())
// if (!modificabile() && !yesno_box("Documento non modificabile,\nSi desidera continuare ugualmente"))
// return NOERR;
1997-08-28 17:11:17 +00:00
myself . _stato_originale = stato ( ) ;
1997-08-18 16:06:51 +00:00
}
1998-08-25 18:07:30 +00:00
const bool check_movmag = dongle ( ) . active ( MGAUT ) & & tipo ( ) . mov_mag ( ) ;
1997-08-18 16:06:51 +00:00
const char stato_doc ( stato ( ) ) ;
1997-07-29 09:53:35 +00:00
const bool do_movmag = tipo ( ) . stato_with_mov_mag ( stato_doc ) ;
1997-06-27 09:21:13 +00:00
1997-08-01 09:20:02 +00:00
if ( tipo ( ) . spese_aut ( ) & & ! get_bool ( " SPESEUPD " ) )
{
TString16 name ( " CODSP0 " ) ;
TString_array spese ;
TRectype & ven_rec = clifor ( ) . vendite ( ) ;
for ( int i = 1 ; i < = 4 ; i + + )
{
name . rtrim ( 1 ) ; name < < i ;
const TString16 s ( ven_rec . get ( name ) ) ;
if ( s . not_empty ( ) )
spese . add ( s ) ;
}
1997-08-18 16:06:51 +00:00
myself . update_spese_aut ( spese ) ;
1997-08-01 09:20:02 +00:00
}
1997-08-04 13:52:55 +00:00
1997-06-03 15:56:27 +00:00
int err = NOERR ;
1997-06-27 09:21:13 +00:00
long num = get_long ( " MOVMAG " ) ;
const int rows = physical_rows ( ) ;
if ( check_movmag )
{
TMov_mag_doc mov ( this ) ;
TLocalisamfile m ( LF_MOVMAG ) ;
1998-11-04 18:04:26 +00:00
1997-06-27 09:21:13 +00:00
mov . zero ( ) ;
if ( num = = 0 & & do_movmag )
{
1997-08-18 16:06:51 +00:00
num = atol ( mov . get_next_key ( ) ) ;
mov . put ( MOVMAG_NUMREG , num ) ;
while ( mov . write ( m ) = = _isreinsert )
{
1997-06-27 09:21:13 +00:00
num + + ;
mov . put ( MOVMAG_NUMREG , num ) ;
1997-08-18 16:06:51 +00:00
}
myself . put ( " MOVMAG " , num ) ;
1997-06-27 09:21:13 +00:00
}
if ( num > 0 )
1998-08-25 18:07:30 +00:00
{
const bool scarica_residuo = tipo ( ) . scarica_residuo ( ) ;
1997-06-27 09:21:13 +00:00
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 " ) ;
if ( do_movmag )
{
TRecord_array & b = mov . body ( ) ;
const int mag_rows = mov . rows ( ) ;
for ( int i = mag_rows ; i > 0 ; i - - )
{
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 ) ;
}
}
b . pack ( ) ;
TDate d ( get ( " DATADOC " ) ) ;
mov . put ( MOVMAG_ANNOES , mov . codice_esercizio ( d ) ) ;
mov . put ( MOVMAG_DATAREG , d ) ;
mov . put ( MOVMAG_DATACOMP , d ) ;
mov . put ( MOVMAG_DOCPROVV , get ( " PROVV " ) ) ;
mov . put ( MOVMAG_ANNODOC , get ( " ANNO " ) ) ; ;
mov . put ( MOVMAG_CODNUM , get ( " CODNUM " ) ) ;
const long numdoc = get_long ( " NDOC " ) ;
1998-05-27 13:41:48 +00:00
mov . put ( MOVMAG_NUMDOC , numdoc ) ;
const long ex_numdoc = get_long ( " NUMDOCRIF " ) ;
if ( ex_numdoc = = 0 )
{
mov . put ( MOVMAG_EXNUMDOC , numdoc ) ;
mov . put ( MOVMAG_EXDATADOC , d ) ;
}
else
{
mov . put ( MOVMAG_EXNUMDOC , ex_numdoc ) ;
const TDate ex_d ( get ( " DATADOCRIF " ) ) ;
mov . put ( MOVMAG_EXDATADOC , ex_d ) ;
}
1997-06-27 09:21:13 +00:00
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 " ) ) ;
mov . put ( MOVMAG_TIPOCF , get ( " TIPOCF " ) ) ;
mov . put ( MOVMAG_CODCF , get ( " CODCF " ) ) ;
1998-05-04 09:54:49 +00:00
TString80 descr ;
descr . format ( " %s n.ro %ld del %s " , ( const char * ) tipo ( ) . get ( " S1 " ) , numdoc , ( const char * ) d . string ( ) ) ;
mov . put ( MOVMAG_DESCR , descr ) ;
1997-06-27 09:21:13 +00:00
int j = 1 ;
1998-11-04 18:04:26 +00:00
real cambio = ZERO ;
if ( get ( DOC_CODVAL ) . not_empty ( ) )
cambio = get_real ( DOC_CAMBIO ) ;
if ( cambio = = ZERO )
cambio = 1.0 ;
1997-06-27 09:21:13 +00:00
for ( i = 1 ; i < = rows ; i + + )
{
1997-08-18 16:06:51 +00:00
TRiga_documento & r = myself . row ( i ) ;
1997-06-27 09:21:13 +00:00
if ( r . is_articolo ( ) )
{
long r_num = r . get_long ( " MOVMAG " ) ;
if ( r_num = = 0 )
{
r_num = num ;
r . put ( " MOVMAG " , r_num ) ;
}
1998-08-25 18:07:30 +00:00
const real qta = scarica_residuo ? r . qtaresidua ( ) : r . quantita ( ) ;
if ( r_num = = num & & qta ! = ZERO )
1997-06-27 09:21:13 +00:00
{
TRectype & rm = mov . insert_row ( j + + ) ;
1998-11-04 18:04:26 +00:00
mov . add_magc ( r . get ( " CODMAGC " ) ) ;
1997-06-27 09:21:13 +00:00
rm . put ( RMOVMAG_CODMAG , r . get ( " CODMAG " ) ) ;
rm . put ( RMOVMAG_CODART , r . get ( " CODARTMAG " ) ) ;
rm . put ( RMOVMAG_LIVGIAC , r . get ( " LIVELLO " ) ) ;
rm . put ( RMOVMAG_UM , r . get ( " UMQTA " ) ) ;
1998-08-25 18:07:30 +00:00
rm . put ( RMOVMAG_QUANT , qta ) ;
1998-11-04 18:04:26 +00:00
real prezzo ( r . get ( " PREZZO " ) ) ;
prezzo * = cambio ;
rm . put ( RMOVMAG_PREZZO , prezzo ) ;
1997-06-27 09:21:13 +00:00
rm . put ( RMOVMAG_CODCAUS , r . get ( " CAUSMAG " ) ) ;
rm . put ( RMOVMAG_TIPORIGA , ( char ) riga_dadocumento ) ;
}
}
}
mov . rewrite ( m ) ;
}
else
{
mov . remove ( m ) ;
for ( int i = rows ; i > 0 ; i - - )
{
1997-08-18 16:06:51 +00:00
TRiga_documento & r = myself . row ( i ) ;
1997-06-27 09:21:13 +00:00
long r_num = r . get_long ( " MOVMAG " ) ;
if ( r_num = = num )
r . zero ( " MOVMAG " ) ;
}
( ( TDocumento * ) this ) - > zero ( " MOVMAG " ) ;
}
}
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 ) ;
1998-08-25 18:07:30 +00:00
bool docevaso = TRUE ;
TDate datacons ( get_date ( DOC_DATACONS ) ) ;
1997-06-27 09:21:13 +00:00
for ( int i = rows ; i > 0 ; i - - )
{
1997-08-18 16:06:51 +00:00
TRiga_documento & r = myself . row ( i ) ;
1997-08-27 13:28:15 +00:00
if ( ( r . is_merce ( ) | | r . is_omaggio ( ) ) & & ! r . is_checked ( ) )
1997-06-27 09:21:13 +00:00
{
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 ( ) ;
}
1998-08-25 18:07:30 +00:00
if ( is_ordine ( ) & & r . is_evadibile ( ) )
{
docevaso & = r . get_bool ( RDOC_RIGAEVASA ) ;
const TDate dcons = r . get ( RDOC_DATACONS ) ;
if ( ! dcons . ok ( ) )
r . put ( RDOC_DATACONS , datacons ) ;
}
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
1997-10-29 11:08:40 +00:00
if ( 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 ( ) )
1997-10-29 11:08:40 +00:00
myself . write_provvigioni ( ) ;
1997-09-26 15:22:39 +00:00
}
if ( tipo ( ) . statistiche ( ) & & _has_stat_ven )
{
TString80 key ( get ( DOC_PROVV ) ) ; key < < get ( DOC_ANNO ) ; key < < get ( DOC_CODNUM ) ; key < < get ( DOC_NDOC ) ;
TObject * o = _docs_to_agg . objptr ( key ) ;
if ( o ! = NULL )
_docs_to_agg . remove ( key ) ;
for ( int i = physical_rows ( ) ; i > 0 ; i - - )
_st_agg . add ( myself . row ( i ) ) ;
if ( _docs_to_agg . items ( ) = = 0 )
_st_agg . update ( ) ;
}
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
{
1997-08-18 16:06:51 +00:00
if ( ! cancellabile ( ) & & ! yesno_box ( " Documento non cancellabile, \n vuoi continuare ugualmente " ) )
return NOERR ;
1998-08-25 18:07:30 +00:00
const bool check_movmag = dongle ( ) . active ( MGAUT ) & & tipo ( ) . mov_mag ( ) ;
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 )
{
TMov_mag_doc mov ( this ) ;
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 " ) ;
mov . remove ( m ) ;
1997-08-04 13:52:55 +00:00
}
}
1997-09-26 15:22:39 +00:00
if ( tipo ( ) . statistiche ( ) & & _has_stat_ven )
{
TString80 key ( get ( DOC_PROVV ) ) ; key < < get ( DOC_ANNO ) ; key < < get ( DOC_CODNUM ) ; key < < get ( DOC_NDOC ) ;
TObject * o = _docs_to_agg . objptr ( key ) ;
if ( o ! = NULL )
_docs_to_agg . remove ( key ) ;
if ( _docs_to_agg . items ( ) = = 0 )
_st_agg . update ( ) ;
}
1998-01-23 09:57:34 +00:00
if ( _has_provv & & tipo ( ) . provvigioni ( ) )
{
TString agente ( get ( DOC_CODAG ) ) ;
const int anno = TDocumento : : anno ( ) ;
TString codnum ( numerazione ( ) ) ;
const long ndoc = numero ( ) ;
// Legge le provvigioni per questo documento
_provv_agente - > read ( agente , anno , codnum , ndoc ) ;
// Le rimuove
_provv_agente - > remove ( ) ;
}
1997-10-13 15:22:11 +00:00
return TMultiple_rectype : : remove ( f ) ;
}
1997-10-23 09:21:54 +00:00
TProvvigioni_agente & TDocumento : : calc_provvigioni ( const bool generata )
1997-10-13 15:22:11 +00:00
{
CHECK ( _provv_agente , " Bad TProvvigione_agente object " ) ;
TString agente ( get ( DOC_CODAG ) ) ;
const int anno = TDocumento : : anno ( ) ;
TString codnum ( numerazione ( ) ) ;
const long ndoc = numero ( ) ;
TDate datadoc ( data ( ) ) ;
1998-01-23 09:57:34 +00:00
while ( _provv_agente - > read ( agente , anno , codnum , ndoc ) = = _islocked ) // Legge le provvigioni per questo documento
if ( ! yesno_box ( " Dati agente %s in uso da un altro utente. Riprovo? " , ( const char * ) agente ) )
return * _provv_agente ;
1998-08-25 18:07:30 +00:00
const real perc = _provv_agente - > perc_fatt ( ) ;
real tot_doc ( totale_doc ( ) ) ;
real tot_netto ( totale_netto ( ) ) ;
real tot_provv = provvigione ( ) ;
1997-10-13 15:22:11 +00:00
real provv_fat = ( tot_provv / 100.0 ) * perc ; // Provvigione sul fatturato (rata 0)
provv_fat . round ( ) ;
real provv_pag = tot_provv - provv_fat ; // Provvigione sul pagato (da suddivere secondo il pagamento)
const real change ( cambio ( ) ) ;
// Calcolo rate per provvigioni e documento
TPagamento & pag1 = pagamento ( ) ; // Per rate documento
TPagamento * pag2 = new TPagamento ( pag1 . code ( ) , datadoc . string ( ) ) ; // Per rate documento
real totspese = spese ( ) ;
real totimposte = imposta ( ) ;
1998-08-25 18:07:30 +00:00
real totimponibili = tot_doc - totimposte - totspese ;
1997-10-13 15:22:11 +00:00
const bool valuta = in_valuta ( ) ;
1998-08-25 18:07:30 +00:00
const TString16 codcaus ( tipo ( ) . causale ( ) ) ;
if ( codcaus . not_empty ( ) )
{
TLocalisamfile caus ( LF_CAUSALI ) ;
TLocalisamfile rcaus ( LF_RCAUSALI ) ;
TCausale c ( codcaus , datadoc . year ( ) ) ;
const char sez = c . sezione_clifo ( ) ;
const bool swap = ( c . reg ( ) . iva ( ) = = iva_vendite ) ^ sez = = ' D ' ;
if ( swap )
{
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 ;
}
}
1997-10-13 15:22:11 +00:00
if ( valuta )
{
real val1 = totimponibili * change ;
real val2 = totimposte * change ;
real val3 = totspese * change ;
pag1 . set_total_valuta ( totimponibili , totimposte , totspese , change , val1 , val2 , val3 ) ;
pag2 - > set_total_valuta ( provv_pag , ZERO , ZERO , change , provv_pag * change , ZERO , ZERO ) ;
}
else
{
pag1 . set_total ( totimponibili , totimposte , totspese ) ;
pag2 - > set_total ( provv_pag , ZERO , ZERO ) ;
}
pag1 . set_rate_auto ( ) ;
pag2 - > set_rate_auto ( ) ;
// Crea le nuove rate provvigionali
const bool isnew = _provv_agente - > items ( ) = = 0 ; // Il documento non ha righe provvigionali
TRate_doc & rd = _provv_agente - > rate ( anno , codnum , ndoc , isnew ? TRUE : FALSE ) ;
// 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
const int nrate = pag1 . n_rate ( ) ;
1998-01-23 09:57:34 +00:00
for ( int i = 0 ; i < = nrate ; i + + )
1997-10-13 15:22:11 +00:00
{
1998-01-23 09:57:34 +00:00
TRata & rt = rd . row ( i , TRUE ) ; // Se non esiste la rata ne forza la creazione
1997-10-13 15:22:11 +00:00
rt . set_rata ( i ) ;
rt . set_datascad ( i = = 0 ? datadoc : pag1 . data_rata ( i - 1 ) ) ;
1997-10-23 09:21:54 +00:00
rt . set_tipopag ( i = = 0 ? 1 : pag1 . tipo_rata ( i - 1 ) ) ;
1997-10-13 15:22:11 +00:00
rt . set_imprata ( i = = 0 ? ZERO : pag1 . importo_rata ( i - 1 , valuta ? TRUE : FALSE ) ) ;
rt . set_impprovv ( i = = 0 ? provv_fat : pag2 - > importo_rata ( i - 1 , valuta ? TRUE : FALSE ) ) ;
1997-10-23 09:21:54 +00:00
if ( generata )
rt . set_generata ( ) ;
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
for ( i = nrate + 1 ; i < rd_items ; i + + )
1997-10-13 15:22:11 +00:00
rd . remove_rata ( i ) ;
delete pag2 ;
return * _provv_agente ;
1997-06-03 15:56:27 +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 ( ) ;
return ( val . not_empty ( ) & & val ! = " LIT " ) ;
}
1997-08-18 16:06:51 +00:00
TRiga_documento & TDocumento : : row ( int index )
{
TRecord_array & b = body ( ) ;
const int nrows = b . rows ( ) ;
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
{
1997-08-18 16:06:51 +00:00
r = & ( ( TRiga_documento & ) b . row ( index , FALSE ) ) ;
1997-08-18 15:24:00 +00:00
CHECKD ( r , " Riga documento non esistente " , index ) ;
}
1997-06-03 15:56:27 +00:00
else
{
CHECKD ( ( index = = nrows + 1 & & ( _sconto ! = NULL | | _esenzione ! = NULL ) ) | | ( index = = nrows + 2 & & _sconto ! = NULL & & _esenzione ! = NULL ) ,
" Riga documento non esistente " , index ) ;
if ( index = = nrows + 1 )
{
r = _sconto ! = NULL ? _sconto : _esenzione ;
}
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
{
TRecord_array & b = body ( ) ;
return ( TRiga_documento & ) b . row ( index , FALSE ) ;
}
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 char * tipodoc )
1997-06-03 15:56:27 +00:00
{
1997-08-04 14:15:45 +00:00
CHECK ( tipodoc & & * tipodoc , " Tipo documento nullo " ) ;
1997-06-03 15:56:27 +00:00
TTipo_documento * o = ( TTipo_documento * ) _tipi . objptr ( tipodoc ) ;
if ( o = = NULL )
{
o = new TTipo_documento ( tipodoc ) ;
_tipi . add ( tipodoc , o ) ;
}
return * o ;
}
1997-08-04 14:15:45 +00:00
const TTipo_documento & TDocumento : : tipo ( ) const
{
1997-08-04 14:21:03 +00:00
const TString16 tipodoc ( get ( " TIPODOC " ) ) ;
return tipo ( tipodoc ) ;
1997-08-04 14:15:45 +00:00
}
1997-08-18 15:24:00 +00:00
const TCodice_numerazione & TDocumento : : codice_numerazione ( ) const
{
const TString16 key ( numerazione ( ) ) ;
TCodice_numerazione * o = ( TCodice_numerazione * ) _numerazioni . objptr ( key ) ;
if ( o = = NULL )
{
o = new TCodice_numerazione ( key ) ;
_numerazioni . add ( key , o ) ;
}
return * o ;
}
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 ( ) )
{
campo = get ( c ) ;
ok & = campo = = doc . get ( c ) ;
}
}
return ok ;
}
void TDocumento : : set_fields ( TAuto_variable_rectype & rec )
{
if ( tipo_valido ( ) )
{
TTipo_documento & tipo_doc = ( TTipo_documento & ) tipo ( ) ;
const TString16 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
{
TExpr_documento * exp = f - > expr ( ) ;
1997-10-02 16:57:49 +00:00
1997-06-03 15:56:27 +00:00
if ( tot_doc = = f - > name ( ) )
{
1998-11-04 18:04:26 +00:00
TString16 work_tot_doc ( tot_doc ) ;
1997-05-23 14:26:19 +00:00
1997-06-03 15:56:27 +00:00
work_tot_doc . insert ( " _ " ) ;
1998-11-04 18:04:26 +00:00
TString80 netto_def ( exp - > string ( ) ) ;
1997-06-03 15:56:27 +00:00
if ( netto_def . find ( " IMPONIBILI " ) = = - 1 )
1997-05-23 14:26:19 +00:00
{
1997-06-03 15:56:27 +00:00
if ( netto_def . not_empty ( ) )
netto_def < < " + " ;
netto_def < < " IMPONIBILI() " ;
}
if ( netto_def . find ( " IMPOSTE " ) = = - 1 )
{
if ( netto_def . not_empty ( ) )
netto_def < < " + " ;
netto_def < < " IMPOSTE() " ;
1997-05-23 14:26:19 +00:00
}
1997-10-02 16:57:49 +00:00
TExpr_documento netto_exp ( netto_def , _numexpr , this ) ;
1997-06-03 15:56:27 +00:00
add_field ( new TDocumento_variable_field ( work_tot_doc , netto_exp ) ) ;
1998-05-04 09:54:49 +00:00
TString80 descr ;
descr . format ( " %s + _BOLLI(%s) " , ( const char * ) work_tot_doc , ( const char * ) work_tot_doc ) ;
TExpr_documento tot_exp ( descr , _numexpr , this ) ;
1997-06-03 15:56:27 +00:00
add_field ( new TDocumento_variable_field ( f - > name ( ) , tot_exp ) ) ;
1997-05-23 14:26:19 +00:00
}
1997-06-03 15:56:27 +00:00
else
1997-10-02 16:57:49 +00:00
if ( exp )
{
1998-11-04 18:04:26 +00:00
exp - > set_doc ( this ) ;
1997-10-02 16:57:49 +00:00
add_field ( new TDocumento_variable_field ( f - > name ( ) , * exp ) ) ;
}
1997-06-03 15:56:27 +00:00
}
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 ;
1997-08-18 15:24:00 +00:00
if ( ndec = = AUTO_DECIMALS )
1997-06-03 15:56:27 +00:00
ndec = in_valuta ( ) ? 3 : 0 ;
for ( int i = rows ( ) ; i > 0 ; i - - )
val + = ( ( TRiga_documento & ) ( ( TDocumento * ) this ) - > row ( i ) ) . imponibile ( ) ;
if ( spese )
{
real tot_doc = val + imposta ( FALSE , ndec ) ;
val + = spese_incasso ( tot_doc , ndec , _netto ) ;
tot_doc + = spese_incasso ( tot_doc , ndec ) ;
val + = bolli ( tot_doc , ndec , _netto ) ;
}
val . round ( ndec ) ;
return val ;
}
1997-08-21 16:47:14 +00:00
void TDocumento : : update_tabella_iva ( )
{
const int items = rows ( ) ;
TAssoc_array & table = _tabella_iva ;
if ( table . items ( ) > 0 | | items = = 0 )
{
if ( items = = 0 )
table . destroy ( ) ;
return ;
}
real tot_doc ;
real tot_sconti ;
1997-09-01 14:32:34 +00:00
real tot_sconti_perc ;
1997-08-21 16:47:14 +00:00
for ( int i = items ; i > 0 ; i - - )
{
const TRiga_documento & r = row ( i ) ;
const real imponibile = 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 ( ) )
{
const real imposta = r . imposta ( FALSE ) ;
// Aggiorna o aggiunge l'elemento se non esiste
const TIVA & iva = r . iva ( ) ;
const TString16 cod ( iva . codice ( ) ) ;
TRiepilogo_iva * aliquota = ( TRiepilogo_iva * ) table . objptr ( cod ) ;
if ( aliquota = = NULL )
{
aliquota = new TRiepilogo_iva ( iva ) ;
table . add ( cod , aliquota ) ;
}
aliquota - > imp ( ) + = imponibile ;
1998-04-30 14:04:19 +00:00
if ( r . is_spese ( ) & & iva . tipo ( ) . not_empty ( ) )
aliquota - > imp_spese_row ( ) + = imponibile ;
1997-08-21 16:47:14 +00:00
aliquota - > iva ( ) + = imposta ;
tot_doc + = imposta ;
}
}
if ( tot_sconti ! = ZERO )
{
1997-09-01 14:32:34 +00:00
const int ndec = in_valuta ( ) ? 3 : 0 ;
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
table . restart ( ) ;
for ( TRiepilogo_iva * ri = ( TRiepilogo_iva * ) table . get ( ) ; ri ! = NULL ;
ri = ( TRiepilogo_iva * ) table . get ( ) )
1998-04-30 14:04:19 +00:00
d . add ( ri - > imp ( ) - ri - > imp_spese_row ( ) ) ;
1997-08-21 16:47:14 +00:00
table . restart ( ) ;
for ( ri = ( TRiepilogo_iva * ) table . get ( ) ; ri ! = NULL ;
ri = ( TRiepilogo_iva * ) table . get ( ) )
{
const char * codiva = ri - > cod_iva ( ) . codice ( ) ;
const real i ( d . get ( ) ) ;
1997-08-28 17:11:17 +00:00
real & imponibile = ri - > imp ( ) ;
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 ) ;
ri - > sconto_imp ( ) = s . get ( ) ;
ri - > sconto_perc ( ) = s . get ( ) ;
real & iva = ri - > iva ( ) ;
const TIVA & ci = row ( 1 ) . iva ( codiva ) ;
const real imposta ( : : iva ( i , ci , ALL_DECIMALS ) ) ;
1997-08-21 16:47:14 +00:00
iva + = imposta ;
1997-09-01 14:32:34 +00:00
ri - > iva_sconto ( ) = : : iva ( i , ci , ndec ) ;
1997-08-21 16:47:14 +00:00
tot_doc + = imposta ;
}
}
1997-12-10 12:18:52 +00:00
1997-08-21 16:47:14 +00:00
real val = spese_incasso ( tot_doc , ALL_DECIMALS , _netto ) ;
1997-12-10 12:18:52 +00:00
TString16 codiva ( codiva_spese ( ) ) ;
TRiepilogo_iva * ri = ( TRiepilogo_iva * ) table . objptr ( codiva ) ;
if ( val ! = ZERO )
{
if ( ri = = NULL )
{
ri = new TRiepilogo_iva ( TIVA ( codiva ) ) ;
table . add ( codiva , ri ) ;
}
ri - > imp_spese ( ) + = val ;
tot_doc + = val ;
val = spese_incasso ( tot_doc , ALL_DECIMALS , _imposta ) ;
ri - > iva_spese ( ) + = val ;
tot_doc + = val ;
}
1997-08-21 16:47:14 +00:00
val = bolli ( tot_doc , ALL_DECIMALS , _netto ) ;
1997-12-10 12:18:52 +00:00
if ( val ! = ZERO )
{
codiva = codiva_bolli ( ) ;
ri = ( TRiepilogo_iva * ) table . objptr ( codiva ) ;
if ( ri = = NULL )
{
ri = new TRiepilogo_iva ( TIVA ( codiva ) ) ;
table . add ( codiva , ri ) ;
}
ri - > imp_spese ( ) + = val ;
tot_doc + = val ;
val = bolli ( tot_doc , ALL_DECIMALS , _imposta ) ;
ri - > iva_spese ( ) + = val ;
tot_doc + = val ;
}
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 )
{
TAssoc_array & table = ( ( TDocumento * ) this ) - > tabella_iva ( ) ;
if ( ndec = = AUTO_DECIMALS )
ndec = in_valuta ( ) ? 3 : 0 ;
for ( TRiepilogo_iva * ri = ( TRiepilogo_iva * ) table . get ( ) ; ri ! = NULL ;
ri = ( TRiepilogo_iva * ) table . get ( ) )
{
real iva = ri - > imposta ( spese ) ;
if ( iva < ZERO )
iva . floor ( ndec ) ;
else
iva . ceil ( ndec ) ;
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
{
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 ( ) ;
r + = spese_incasso ( r , in_valuta ( ) ? 3 : 0 ) ;
r + = bolli ( r , in_valuta ( ) ? 3 : 0 ) ;
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
{
1997-06-03 15:56:27 +00:00
const TString16 field ( tipo ( ) . totale_netto ( ) ) ;
if ( field . not_empty ( ) )
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
{
1997-06-03 15:56:27 +00:00
const TString16 field ( tipo ( ) . basesconto ( ) ) ;
if ( field . not_empty ( ) )
return get_real ( field ) ;
else
return ZERO ;
1997-05-23 14:26:19 +00:00
}
1997-06-03 15:56:27 +00:00
real TDocumento : : spese ( ) const
{
const TString16 field ( tipo ( ) . spese ( ) ) ;
1997-05-23 14:26:19 +00:00
1997-06-03 15:56:27 +00:00
if ( field . not_empty ( ) )
return get_real ( field ) ;
else
return ZERO ;
}
TPagamento & TDocumento : : pagamento ( )
{
const TString16 codpag ( get ( " CODPAG " ) ) ;
if ( codpag ! = _pag . code ( ) )
{
_pag . set_code ( codpag ) ;
_pag . read ( ) ;
}
return _pag ;
}
1997-10-02 16:57:49 +00:00
real TDocumento : : provvigione ( int ndec ) const
{
real val ;
if ( ndec = = AUTO_DECIMALS )
1997-10-29 11:08:40 +00:00
ndec = in_valuta ( ) ? 3 : 0 ;
TString16 field ( agente ( ) . campoprovv ( ) ) ;
if ( field . empty ( ) )
field = tipo ( ) . totprovv ( ) ;
1997-10-02 16:57:49 +00:00
if ( field . not_empty ( ) )
return get_real ( field ) ;
else
for ( int i = rows ( ) ; i > 0 ; i - - )
val + = ( ( TRiga_documento & ) ( ( TDocumento * ) this ) - > row ( i ) ) . provvigione ( ndec ) ;
return val ;
}
1998-08-25 18:07:30 +00:00
real TDocumento : : valore ( bool totale , int ndec ) const
{
real val ;
for ( int i = rows ( ) ; i > 0 ; i - - )
{
TRiga_documento & r = ( ( TRiga_documento & ) ( ( TDocumento * ) this ) - > row ( i ) ) ;
if ( r . is_merce ( ) | | r . is_spese ( ) | | r . is_prestazione ( ) )
val + = r . valore ( totale , ndec ) ;
}
return val ;
}
1997-06-03 15:56:27 +00:00
void TDocumento : : put_str ( const char * fieldname , const char * val )
{
1997-08-26 12:38:08 +00:00
if ( strcmp ( fieldname , " TIPODOC " ) = = 0 )
{
1998-11-04 18:04:26 +00:00
const TString16 v ( val ) ;
1997-08-26 12:38:08 +00:00
if ( TRectype : : get ( " TIPODOC " ) ! = v )
{
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
1997-08-26 12:38:08 +00:00
if ( strcmp ( fieldname , " CODCF " ) = = 0 )
{
1998-11-04 18:04:26 +00:00
const TString16 v ( val ) ;
1997-08-01 09:20:02 +00:00
put ( " SPESEUPD " , TRectype : : get ( " CODCF " ) = = v ) ;
1997-08-26 12:38:08 +00:00
TAuto_variable_rectype : : put_str ( fieldname , v ) ;
dirty_fields ( ) ;
}
else
{
TAuto_variable_rectype : : put_str ( fieldname , val ) ;
dirty_fields ( ) ;
if ( strcmp ( fieldname , " SCONTOPERC " ) = = 0 )
set_riga_sconto ( ) ;
}
1997-06-03 15:56:27 +00:00
}
void TDocumento : : zero ( const char * fieldname )
1997-05-23 14:26:19 +00:00
{
1997-06-03 15:56:27 +00:00
if ( strcmp ( fieldname , " TIPODOC " ) = = 0 )
reset_fields ( * this ) ;
1997-08-18 16:06:51 +00:00
TRectype : : zero ( fieldname ) ;
1997-06-03 15:56:27 +00:00
dirty_fields ( ) ;
1997-05-23 14:26:19 +00:00
}
1997-06-12 16:26:22 +00:00
TCli_for & TDocumento : : clifor ( ) const
{
const char tipo = tipocf ( ) ;
const long codice = codcf ( ) ;
if ( _cli_for . empty ( ) | | _cli_for . tipo ( ) ! = tipo | | _cli_for . codice ( ) ! = codice )
( ( TDocumento * ) this ) - > _cli_for . read ( tipo , codice ) ;
return ( TCli_for & ) _cli_for ;
}
TOccasionale & TDocumento : : occas ( ) const
{
const TString80 occ_code ( cod_occas ( ) ) ;
if ( _occas . empty ( ) | | strcmp ( _occas . codice ( ) , occ_code ) ! = 0 )
{
TLocalisamfile o ( LF_OCCAS ) ;
( ( TDocumento * ) this ) - > _occas . zero ( ) ;
( ( TDocumento * ) this ) - > _occas . put ( OCC_CFPI , occ_code ) ;
TRectype oc ( _occas ) ;
if ( ( ( TDocumento * ) this ) - > _occas . read ( o ) ! = NOERR )
( ( TDocumento * ) this ) - > _occas = oc ;
}
return ( TOccasionale & ) _occas ;
}
1997-10-29 11:08:40 +00:00
const TAgente & TDocumento : : agente ( ) const
{
return _agenti . agente ( get ( DOC_CODAG ) ) ;
}
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 ) ;
1997-10-02 16:57:49 +00:00
reset_fields ( * this ) ;
set_fields ( * this ) ;
1997-08-06 12:31:10 +00:00
for ( int i = physical_rows ( ) ; i > 0 ; i - - )
{
TRiga_documento & r = row ( i ) ;
r . set_doc ( this ) ;
}
for ( i = 0 ; i < 3 ; i + + )
_liv_len [ i ] = d . _liv_len [ i ] ;
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 ( ) ;
1998-08-25 18:07:30 +00:00
// set_condv(d._condv);
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
1997-06-03 15:56:27 +00:00
void TDocumento : : update_spese_aut ( TString_array & spese_aut , bool preserve_old , TSheet_field * sh )
1997-05-23 14:26:19 +00:00
1997-06-03 15:56:27 +00:00
{
1997-08-01 09:20:02 +00:00
const bool updated = get_bool ( " SPESEUPD " ) ;
if ( updated )
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 ( ) ;
for ( int i = nrows ; i > 0 ; i - - )
1997-06-03 15:56:27 +00:00
{
TRiga_documento & r = row ( i ) ;
1997-06-27 09:21:13 +00:00
if ( r . tipo ( ) . tipo ( ) = = RIGA_SPESEDOC & & r . is_generata ( ) )
1997-06-03 15:56:27 +00:00
{
if ( preserve_old )
return ;
destroy_row ( i , TRUE ) ;
if ( interactive )
sh - > destroy ( i - 1 ) ;
}
}
TString16 cod_iva_cli ;
const int nspese = spese_aut . items ( ) ;
if ( nspese > 0 )
{
TLocalisamfile cfven ( LF_CFVEN ) ;
1998-04-30 14:04:19 +00:00
TSpesa_prest sp ;
1997-06-03 15:56:27 +00:00
cfven . put ( " TIPOCF " , get ( " TIPOCF " ) ) ;
cfven . put ( " CODCF " , get ( " CODCF " ) ) ;
if ( cfven . read ( ) = = NOERR )
cod_iva_cli = cfven . get ( " ASSFIS " ) ;
for ( i = 0 ; i < nspese ; i + + )
{
const TString & s = spese_aut . row ( i ) ;
1998-04-30 14:04:19 +00:00
if ( sp . read ( s ) ! = NOERR )
message_box ( " Codice spesa %s assente " , ( const char * ) s ) ;
else
{
TString16 tipo ( sp . tipo_riga ( ) ) ;
TRiga_documento & riga = new_row ( tipo ) ;
riga . put ( " CODART " , s ) ;
riga . generata ( ) ;
riga . put ( " DESCR " , sp . descrizione ( ) ) ;
switch ( sp . tipo ( ) )
{
case ' Q ' :
{
real qta = sp . qta ( ) ;
if ( qta = = ZERO )
qta = 1.0 ;
riga . put ( " QTA " , qta ) ;
}
case ' V ' :
{
const real cambio = get_real ( " CAMBIO " ) ;
const TString16 valuta = get ( " CODVAL " ) ;
real prezzo = sp . prezzo ( ) ;
sppr_calc ( sp , valuta , cambio , prezzo ) ;
riga . put ( " PREZZO " , prezzo ) ;
riga . put ( " UMQTA " , sp . um ( ) ) ;
}
break ;
case ' P ' :
default :
break ;
}
if ( cod_iva_cli . empty ( ) )
riga . put ( " CODIVA " , sp . cod_iva ( ) ) ;
else
riga . put ( " CODIVA " , cod_iva_cli ) ;
if ( interactive )
{
const int nrow = sh - > insert ( - 1 , FALSE ) ;
riga . autoload ( * sh ) ;
sh - > check_row ( nrow ) ;
}
}
}
1997-06-03 15:56:27 +00:00
}
}
1997-08-01 09:20:02 +00:00
put ( " SPESEUPD " , TRUE ) ;
1997-06-03 15:56:27 +00:00
}
1998-08-25 18:07:30 +00:00
bool TDocumento : : is_evaso ( ) const
{
bool ok = is_ordine ( ) | | is_generic ( ) ;
for ( int r = 1 ; ok & & r < = physical_rows ( ) ; r + + )
{
const TRiga_documento & riga = physical_row ( r ) ;
if ( riga . is_evadibile ( ) )
ok = riga . get_bool ( RDOC_RIGAEVASA ) ;
}
return ok ;
}