1995-09-27 15:28:09 +00:00
// cg4305: liquidazione IVA
1995-09-18 10:45:10 +00:00
// funzionalita' accessorie (calcolo acconto, estrazione deleghe)
2001-05-01 08:17:07 +00:00
# include <currency.h>
1995-09-18 10:45:10 +00:00
# include <defmask.h>
2003-03-20 12:25:48 +00:00
# include <recarray.h>
1995-09-18 10:45:10 +00:00
# include <progind.h>
# include <prefix.h>
# include <sheet.h>
# include <utility.h>
# include <config.h>
2007-09-17 15:33:04 +00:00
# include <righef24.h>
# include <modaut.h>
1995-09-18 10:45:10 +00:00
# include "cg4300.h"
# include "cg4300b.h"
1995-09-27 15:28:09 +00:00
# include "cg4300c.h"
# include "cg4800b.h"
1995-09-18 10:45:10 +00:00
// -------------------------------------------------- estrazione deleghe
bool TLiquidazione_app : : set_deleghe ( )
{
TMask m ( " cg4300b.msk " ) ;
1995-11-30 09:39:32 +00:00
m . field ( FLD_CGB_YEAR ) . set_handler ( ch_year_handler ) ;
m . field ( FLD_CGB_YEAR ) . set ( _year ) ;
1995-09-18 10:45:10 +00:00
m . field ( CHK_CGB_PRINT ) . set ( _isprint ? " X " : " " ) ;
int k = 0 ;
long j ;
_calcall = FALSE ;
for ( ; ; )
{
if ( k = = K_ESC | | k = = K_ENTER )
break ;
k = m . run ( ) ;
_isprint = m . get_bool ( CHK_CGB_PRINT ) ;
switch ( k )
{
case DLG_SELECT :
1996-07-02 16:57:57 +00:00
1995-09-18 10:45:10 +00:00
_ditte - > run ( ) ;
for ( j = 0l ; j < _ditte - > items ( ) ; j + + )
if ( _ditte - > checked ( j ) ) _selected . set ( j ) ;
break ;
case BUT_CGB_ALL :
_ditte - > check ( - 1 ) ;
for ( j = 0l ; j < _ditte - > items ( ) ; j + + )
1996-05-20 13:58:29 +00:00
if ( _ditte - > checked ( j ) & & ! _ditte - > row_disabled ( j ) )
1995-09-18 10:45:10 +00:00
_selected . set ( j ) ;
_calcall = TRUE ;
k = K_ENTER ;
break ;
}
}
if ( k = = K_ENTER )
{
1995-09-27 15:28:09 +00:00
_year = m . get ( FLD_CGB_YEAR ) ;
_month = atoi ( m . get ( FLD_CGB_MONTH ) ) ;
1995-09-18 10:45:10 +00:00
}
return k = = K_ENTER ;
}
bool TLiquidazione_app : : extract_deleghe ( )
1996-04-24 16:54:45 +00:00
{
1996-04-26 16:27:56 +00:00
TString buf ( 256 ) ; TArray desc ;
1995-09-18 10:45:10 +00:00
_prind = new TProgind ( _calcall ? _n_ditte : _selected . ones ( ) ,
2003-03-20 12:25:48 +00:00
TR ( " Estrazione deleghe \n "
" preparazione archivi \n "
" \n " ) ,
TRUE , TRUE ) ;
1995-09-18 10:45:10 +00:00
1996-04-24 16:54:45 +00:00
if ( _ver - > read ( atoi ( _year ) , ( _month > 12 ) ? 12 : _month ) ! = NOERR )
2003-03-20 12:25:48 +00:00
warning_box ( FR ( " Errore %d in lettura tabella versamenti ed interessi. " ) , _ver - > status ( ) ) ;
1995-09-18 10:45:10 +00:00
for ( int l = 0 ; l < _ditte - > items ( ) ; l + + )
{
if ( _prind - > iscancelled ( ) )
break ;
1996-05-20 13:58:29 +00:00
if ( ! ( _calcall | | _selected [ l ] ) | | _ditte - > row_disabled ( l ) )
1995-09-18 10:45:10 +00:00
continue ;
2002-02-26 16:20:19 +00:00
const long ditta = _ditte - > row ( l ) . get_long ( 1 ) ;
TApplication : : set_firm ( ditta ) ;
TIva_round ir ; ir . set_default_iva_mode ( atoi ( _year ) , _month > 12 , ditta ) ;
1995-09-18 10:45:10 +00:00
_nditte - > curr ( ) . zero ( ) ;
2002-02-26 16:20:19 +00:00
_nditte - > curr ( ) . put ( " CODDITTA " , ditta ) ;
1995-09-18 10:45:10 +00:00
_nditte - > read ( ) ;
// must succeed
look_lia ( ) ;
1995-09-27 15:28:09 +00:00
_freqviva = _lia - > get ( " S7 " ) ;
1995-09-18 10:45:10 +00:00
2003-03-20 12:25:48 +00:00
buf . format ( FR ( " Estrazione deleghe (%d): \n ditta %s \n " ) ,
2000-05-05 15:25:49 +00:00
_month , ( const char * ) _nditte_r - > get ( " RAGSOC " ) ) ;
1995-09-18 10:45:10 +00:00
_prind - > set_text ( buf ) ;
if ( is_month_ok_strict ( _month ) | | _month = = 13 )
{
2001-05-01 08:17:07 +00:00
const bool mens = _freqviva = = " M " ;
1995-10-24 10:34:55 +00:00
_isbenzinaro = _nditte - > curr ( LF_ATTIV ) . get_bool ( " ART74_4 " ) ;
1995-09-18 10:45:10 +00:00
_isriepilogo = _month = = 13 ;
_isendliq = _isannual | | _isriepilogo ;
1996-05-20 13:58:29 +00:00
if ( mens | | _isbenzinaro | | _month ! = 12 )
extract_delega ( _month , desc ) ;
1995-09-18 10:45:10 +00:00
}
_prind - > addstatus ( 1 ) ;
}
TApplication : : set_firm ( __firm ) ;
delete _prind ;
if ( _isprint )
{
_DescrItem * ddeb = NULL ;
_DescrItem * dcrd = NULL ;
// scorri desc e prepara descritems
for ( int i = 0 ; i < desc . items ( ) ; i + + )
{
TToken_string & tt = ( TToken_string & ) desc [ i ] ;
real tp ( tt . get ( 3 ) ) ;
if ( tp . sign ( ) > 0 )
{
if ( ddeb = = NULL )
{
ddeb = new _DescrItem ( DELDEB ) ;
ddeb - > _f0 = _month ;
}
ddeb - > _arr . add ( tt ) ;
}
else
{
if ( dcrd = = NULL )
{
dcrd = new _DescrItem ( DELCRED ) ;
dcrd - > _f0 = _month ;
}
dcrd - > _arr . add ( tt ) ;
}
}
if ( dcrd ! = NULL ) _descr_arr . add ( dcrd ) ;
if ( ddeb ! = NULL ) _descr_arr . add ( ddeb ) ;
}
return TRUE ;
}
bool TLiquidazione_app : : extract_delega ( int month , TArray & desc )
{
2007-09-17 15:33:04 +00:00
const bool has_f24 = main_app ( ) . has_module ( GVAUT ) ;
1995-09-18 10:45:10 +00:00
TToken_string * tt = NULL ;
1995-09-27 15:28:09 +00:00
bool versare = FALSE ;
1996-09-13 07:38:30 +00:00
bool skip_print = FALSE ;
1995-09-27 15:28:09 +00:00
1995-09-18 10:45:10 +00:00
if ( look_lim ( month ) )
{
1995-09-27 15:28:09 +00:00
real topay = result_liq ( month ) ; // TBC non si puo' fa' accussi'!!!!! pena il casino!
if ( month = = 12 )
1996-04-24 16:54:45 +00:00
{
if ( topay > _ver - > get ( I_ANNUALE ) )
1995-09-27 15:28:09 +00:00
versare = TRUE ;
}
1996-04-24 16:54:45 +00:00
else if ( topay > _ver - > get ( I_PERIODICO ) )
1995-09-27 15:28:09 +00:00
versare = TRUE ;
1995-09-18 10:45:10 +00:00
real intr = _lim - > get_real ( " R14 " ) ;
topay + = intr ; // lo vogliono registrato con interessi
real nrnd = topay ;
2002-02-26 16:20:19 +00:00
round_imposta ( topay ) ; // importo totale del versamento arrotondato
1995-09-27 15:28:09 +00:00
bool wasdel = look_del ( month , 1 ) ;
1995-11-08 16:18:13 +00:00
//la stampa deve essere fatta sia se a credito che a debito
1995-09-18 10:45:10 +00:00
if ( ! topay . is_zero ( ) )
{
tt = new TToken_string ( 80 ) ;
tt - > add ( _nditte - > curr ( ) . get ( " CODDITTA " ) ) ;
tt - > add ( _nditte - > curr ( ) . get ( " RAGSOC " ) ) ;
tt - > add ( _freqviva ) ;
tt - > add ( topay . string ( ) ) ;
tt - > add ( " " ) ;
}
1995-09-27 15:28:09 +00:00
if ( versare )
1995-09-18 10:45:10 +00:00
{
1995-11-08 16:18:13 +00:00
look_del ( month , 1 , TRUE ) ; //ci mette abi, cab o con
//che legge dall'anagrafica!!!
1995-09-27 15:28:09 +00:00
bool stampato = _del - > get_bool ( " B0 " ) ;
if ( stampato ) //se esiste e stampato si richiede conferma aggiornamento
{
if ( topay ! = _del - > get_real ( " R0 " ) )
1996-09-13 07:38:30 +00:00
skip_print = ! video_conferma ( topay , intr , nrnd ) ; // se non conferma o annulla, salta il tabulato
else
2007-09-17 15:33:04 +00:00
skip_print = true ; // Se l'importo e' lo stesso e la delega era gia' stampata, salta il tabulato
1995-09-27 15:28:09 +00:00
}
else //aggiorna importo versamento
{
2007-09-17 15:33:04 +00:00
_del - > put ( " R0 " , topay ) ;
_del - > put ( " R1 " , intr ) ;
_del - > put ( " R2 " , nrnd ) ; // non arrotondato, per calcolo risultato a debito/cr
_del - > rewrite ( ) ;
1995-09-27 15:28:09 +00:00
}
2007-09-17 15:33:04 +00:00
if ( has_f24 )
{
TLocalisamfile f24 ( LF_RIGHEF24 ) ;
TTable trib ( " %TRB " ) ;
long progr = 0L ;
TString descr ( " IVA annuale " ) ;
const bool mensile = _freqviva = = " M " ;
const int codtrib = mensile ? 6000 + month : 6031 + ( month / 3 ) ;
TDate scad ( 16 , ( mensile ? month : ( ( month + 2 ) / 3 ) * 3 ) , atoi ( _year ) ) ;
const long codditta = _nditte - > lfile ( ) . get_long ( " CODDITTA " ) ;
if ( month < 13 )
scad . addmonth ( mensile ? 1 : 2 ) ;
while ( scad . wday ( ) > 5 )
+ + scad ;
if ( month < 13 )
{
if ( mensile )
descr . format ( " IVA mese di %s %s " , itom ( month ) , ( const char * ) _year ) ;
else
descr . format ( " IVA %s Trimestre %s " , itor ( month / 3 + 1 ) , ( const char * ) _year ) ;
}
trib . put ( " CODTAB " , codtrib ) ;
if ( trib . read ( ) ! = NOERR )
{
int g = 0 , c = 0 ;
long s = 0 ;
trib . put ( " CODTAB " , 6001 ) ;
if ( trib . read ( _isgteq ) = = NOERR )
{
const int cod = trib . get_int ( " CODTAB " ) ;
if ( cod > 6000 & & cod < 6036 )
{
g = trib . get_int ( " I0 " ) ;
c = trib . get_int ( " I1 " ) ;
s = trib . get_long ( " I2 " ) ;
}
}
trib . zero ( ) ;
trib . put ( " CODTAB " , codtrib ) ;
TString d ( descr ) ;
trib . put ( " S0 " , d . rtrim ( 5 ) ) ;
trib . put ( " S6 " , " E " ) ;
trib . put ( " I0 " , g ) ;
trib . put ( " I1 " , c ) ;
trib . put ( " I2 " , s ) ;
trib . write ( ) ;
}
f24 . setkey ( 4 ) ;
f24 . put ( F24_TIPOINTEST , " D " ) ;
f24 . put ( F24_INTEST , codditta ) ;
f24 . put ( F24_ANNO , _year ) ;
f24 . put ( F24_TRIBUTO , codtrib ) ;
if ( f24 . read ( ) = = NOERR )
{
if ( f24 . get ( F24_DATAVERS ) . blank ( ) | | skip_print )
{
f24 . put ( F24_IMPORTODEB , topay ) ;
f24 . put ( F24_INTIVATRIM , intr ) ;
f24 . put ( F24_DATASCAD , scad ) ;
const int err = f24 . rewrite ( ) ;
if ( err ! = NOERR )
error_box ( FR ( " Ditta %ld \n %s \n errore %d " ) , codditta , ( const char * ) descr , err ) ;
}
}
else
{
f24 . setkey ( 1 ) ;
if ( f24 . last ( ) = = NOERR )
progr = f24 . get_long ( F24_PROGR ) ;
progr + + ;
f24 . zero ( ) ;
f24 . put ( F24_PROGR , progr ) ;
f24 . put ( F24_TRIBUTO , codtrib ) ;
f24 . put ( F24_TIPOINTEST , " D " ) ;
f24 . put ( F24_INTEST , codditta ) ;
f24 . put ( F24_DESCR , descr ) ;
f24 . put ( F24_DATASCAD , scad ) ;
f24 . put ( F24_ANNO , _year ) ;
f24 . put ( F24_IMPORTODEB , topay ) ;
f24 . put ( F24_INTIVATRIM , intr ) ;
const int err = f24 . write ( ) ;
if ( err ! = NOERR )
error_box ( FR ( " Ditta %ld \n %s \n errore %d " ) , codditta , ( const char * ) descr , err ) ;
}
}
1995-09-18 10:45:10 +00:00
tt - > add ( _del - > get ( " S7 " ) ) ;
tt - > add ( _del - > get ( " S8 " ) ) ;
tt - > add ( _del - > get ( " S9 " ) ) ;
tt - > add ( _nditte - > curr ( ) . get ( " PTEL " ) ) ;
1995-09-27 15:28:09 +00:00
tt - > add ( _nditte - > curr ( ) . get ( " TEL " ) ) ;
1995-11-08 16:18:13 +00:00
TString desc ;
if ( _del - > get ( " S9 " ) . not_empty ( ) )
{
2003-03-20 12:25:48 +00:00
const TRectype & ucc = cache ( ) . get ( " %UCC " , _del - > get ( " S9 " ) ) ;
if ( ! ucc . empty ( ) )
desc = ucc . get ( " S0 " ) ;
1998-04-30 15:59:34 +00:00
}
if ( _del - > get ( " S7 " ) . not_empty ( ) )
1995-11-08 16:18:13 +00:00
{
TString16 cod ;
cod = _del - > get ( " S7 " ) ;
if ( _del - > get ( " S8 " ) . not_empty ( ) ) cod < < _del - > get ( " S8 " ) ;
2003-03-20 12:25:48 +00:00
const TRectype & ban = cache ( ) . get ( " %BAN " , cod ) ;
if ( ! ban . empty ( ) )
1995-11-08 16:18:13 +00:00
desc = ban . get ( " S0 " ) ;
}
tt - > add ( desc ) ;
}
1995-09-27 15:28:09 +00:00
else if ( wasdel ) //se esiste e no versare
1996-09-26 07:27:04 +00:00
{
bool stampato = _del - > get_bool ( " B0 " ) ;
TString buf ;
2003-03-20 12:25:48 +00:00
buf . format ( FR ( " Il versamento relativo alla ditta %ld e' gia' stato stampato. Si desidera eliminare il flag di stampa definitiva? " ) , _nditte - > lfile ( ) . get_long ( " CODDITTA " ) ) ;
1996-09-26 07:27:04 +00:00
if ( stampato & & yesno_box ( buf ) )
{ // Se la delega e' gia' stampata in definitva, chiede se deve eliminare il flag di stampa
_del - > put ( " B0 " , FALSE ) ;
_del - > rewrite ( ) ;
}
// Se non e' stampata invece visualizza la delega presente su file e l'importo a credito che ha calcolato
// chiedendo cosa fare: Registra elimina fisicamente la delega dal file, Annulla lo fa proseguire
1998-04-30 15:59:34 +00:00
if ( ! stampato )
video_conferma ( topay , intr , nrnd , TRUE ) ;
1996-09-26 07:27:04 +00:00
}
1995-09-18 10:45:10 +00:00
}
1996-09-13 07:38:30 +00:00
if ( tt ! = NULL & & ! skip_print ) // Se il tabulato deve essere stampato per questa delega...
1995-09-18 10:45:10 +00:00
desc . add ( tt ) ;
2007-09-17 15:33:04 +00:00
return true ;
1995-09-18 10:45:10 +00:00
}
1995-09-27 15:28:09 +00:00
bool TLiquidazione_app : : video_conferma ( const real & newimp , const real & intr ,
1996-09-26 07:27:04 +00:00
const real & narr , bool to_del )
1995-09-27 15:28:09 +00:00
{
TMask m ( " cg4800b " ) ;
1996-09-13 07:38:30 +00:00
2003-03-20 12:25:48 +00:00
m . set_caption ( to_del ? TR ( " Conferma eliminazione " ) : TR ( " Estrazione versamenti " ) ) ; // Modifica il titolo...
1995-09-27 15:28:09 +00:00
m . field ( F_CODDITTA ) . set ( _nditte - > lfile ( ) . get ( " CODDITTA " ) ) ;
m . field ( F_RAGSOC ) . set ( _nditte - > lfile ( ) . get ( " RAGSOC " ) ) ;
m . field ( F_DATAVER ) . set ( _del - > get_date ( " D0 " ) ) ;
m . field ( F_ABI ) . set ( _del - > get ( " S7 " ) ) ;
m . field ( F_CAB ) . set ( _del - > get ( " S8 " ) ) ;
m . field ( F_CON ) . set ( _del - > get ( " S9 " ) ) ;
m . field ( F_IMPVER ) . set ( _del - > get ( " R0 " ) ) ;
1996-09-26 07:27:04 +00:00
if ( to_del )
{
real xr = abs ( newimp ) ;
m . hide ( F_NEWIMP ) ;
m . show ( F_NEWIMPCRED ) ; m . disable ( F_NEWIMPCRED ) ;
m . field ( F_NEWIMPCRED ) . set ( xr . string ( ) ) ;
}
else
m . field ( F_NEWIMP ) . set ( newimp . string ( ) ) ;
1995-09-27 15:28:09 +00:00
1996-09-13 07:38:30 +00:00
KEY k ;
1995-09-27 15:28:09 +00:00
for ( bool stop = FALSE ; ! stop ; )
{
1996-09-13 07:38:30 +00:00
k = m . run ( ) ;
1995-09-27 15:28:09 +00:00
switch ( k )
{
1996-09-13 07:38:30 +00:00
case K_SAVE :
1995-09-27 15:28:09 +00:00
{
1996-09-26 07:27:04 +00:00
k = yesnocancel_box ( to_del ?
2003-03-20 12:25:48 +00:00
TR ( " Si desidera veramente confermare l'eliminazione? " )
1996-09-26 07:27:04 +00:00
:
2003-03-20 12:25:48 +00:00
TR ( " Delega gia' stampata. Si desidera ugualmente confermare l'aggiornamento? " ) ) ;
1996-09-13 07:38:30 +00:00
if ( k = = K_YES )
{
1996-09-26 07:27:04 +00:00
if ( to_del )
_del - > remove ( ) ;
else
{
_del - > put ( " B0 " , " " ) ;
_del - > put ( " R0 " , newimp ) ;
_del - > put ( " R1 " , intr ) ;
_del - > put ( " R2 " , narr ) ;
_del - > rewrite ( ) ;
}
1996-09-13 07:38:30 +00:00
}
if ( k = = K_YES | | k = = K_NO )
stop = TRUE ;
}
break ;
case K_ESC :
//case K_QUIT:
stop = TRUE ;
break ;
}
1995-09-27 15:28:09 +00:00
}
1996-09-13 07:38:30 +00:00
return k = = K_YES ;
1995-09-27 15:28:09 +00:00
}
1995-09-18 10:45:10 +00:00
// -------------------------------------------- calcolo acconto dicembre
bool TLiquidazione_app : : set_acconto ( real & inf , real & ina )
{
1996-06-20 16:01:52 +00:00
TMask m ( " cg4300c " ) ;
1995-11-30 09:39:32 +00:00
1995-09-18 10:45:10 +00:00
m . set ( CHK_CGC_PRINT , " X " ) ;
m . field ( FLD_CGC_YEAR ) . set_handler ( ch_year_handler ) ;
1995-11-30 09:39:32 +00:00
m . field ( FLD_CGC_YEAR ) . set ( _year ) ;
1995-09-18 10:45:10 +00:00
int k = 0 ; long j ;
_calcall = FALSE ;
for ( ; ; )
{
2009-02-03 16:03:01 +00:00
if ( k = = K_ESC | | k = = K_ENTER | | k = = K_QUIT )
1995-09-18 10:45:10 +00:00
break ;
k = m . run ( ) ;
_year = m . get ( FLD_CGC_YEAR ) ;
_isprint = m . get_bool ( CHK_CGC_PRINT ) ;
_isbase = m . get_bool ( CHK_CGC_BASE ) ;
_basecalc = ( tbc ) m . get_long ( RDB_CGC_BASE ) ;
inf = ina = ZERO ;
switch ( k )
{
case DLG_SELECT :
// scegli ditte
_ditte - > run ( ) ;
for ( j = 0l ; j < _ditte - > items ( ) ; j + + )
if ( _ditte - > checked ( j ) ) _selected . set ( j ) ;
break ;
case BUT_CGC_ALL :
_ditte - > check ( - 1 ) ;
for ( j = 0l ; j < _ditte - > items ( ) ; j + + )
1996-05-20 13:58:29 +00:00
if ( _ditte - > checked ( j ) & & ! _ditte - > row_disabled ( j ) )
1995-09-18 10:45:10 +00:00
_selected . set ( j ) ;
_calcall = TRUE ;
k = K_ENTER ;
break ;
}
}
return k = = K_ENTER ;
}
bool TLiquidazione_app : : recalc_acconti ( real & inf , real & ina )
{
1996-04-26 16:27:56 +00:00
TString buf ( 256 ) ;
1995-09-18 10:45:10 +00:00
bool onemade = FALSE ;
2002-02-26 16:20:19 +00:00
const long firm = TApplication : : get_firm ( ) ;
1995-09-18 10:45:10 +00:00
_prind = new TProgind ( _n_ditte ,
2003-03-20 12:25:48 +00:00
TR ( " Calcolo acconto "
" \n Preparazione archivi "
" \n " ) ,
TRUE , TRUE ) ;
1995-09-18 10:45:10 +00:00
1996-04-24 16:54:45 +00:00
if ( _ver - > read ( atoi ( _year ) , ( _month > 12 ) ? 12 : _month ) ! = NOERR )
2003-03-20 12:25:48 +00:00
warning_box ( FR ( " Errore %d in lettura tabella versamenti ed interessi. " ) , _ver - > status ( ) ) ;
1995-09-18 10:45:10 +00:00
for ( int l = 0 ; l < _ditte - > items ( ) ; l + + )
{
if ( _prind - > iscancelled ( ) )
break ;
1996-05-20 13:58:29 +00:00
if ( ( _calcall | | _selected [ l ] ) & & ! _ditte - > row_disabled ( l ) )
1995-09-18 10:45:10 +00:00
{
if ( onemade = = FALSE & & _isprint )
{
_DescrItem * d = new _DescrItem ( ACCHEAD ) ;
d - > _f0 = _basecalc = = incorso ;
d - > _f1 = _isbase ;
_descr_arr . add ( d ) ;
}
_nditte - > curr ( ) . zero ( ) ;
_nditte - > curr ( ) . put ( " CODDITTA " , _ditte - > row ( l ) . get ( 1 ) ) ;
_nditte - > read ( ) ;
2002-02-26 16:20:19 +00:00
const long ditta = _nditte - > curr ( ) . get_long ( " CODDITTA " ) ;
TApplication : : set_firm ( ditta ) ;
TIva_round ir ;
ir . set_default_iva_mode ( atoi ( _year ) , _month > 12 , ditta ) ;
1995-09-27 15:28:09 +00:00
1995-10-24 10:34:55 +00:00
_isbenzinaro = _nditte - > curr ( LF_ATTIV ) . get_bool ( " ART74_4 " ) ;
1995-09-27 15:28:09 +00:00
look_lia ( ) ;
_freqviva = _lia - > get ( " S7 " ) ;
inf = _lia - > get_real ( " R13 " ) ;
ina = _lia - > get_real ( " R14 " ) ;
2003-03-20 12:25:48 +00:00
buf . format ( FR ( " Calcolo acconto: \n ditta %s " ) ,
1995-09-18 10:45:10 +00:00
( const char * ) _nditte_r - > get ( " RAGSOC " ) ) ;
_prind - > set_text ( buf ) ;
recalc_acconto ( inf , ina ) ;
onemade = TRUE ;
}
_prind - > addstatus ( 1 ) ;
}
TApplication : : set_firm ( firm ) ;
delete _prind ;
return TRUE ;
}
bool TLiquidazione_app : : recalc_acconto ( real & inf , real & ina )
{
1995-09-27 15:28:09 +00:00
real bc = 0.0 ;
real acc = 0.0 ;
real cre = 0.0 ;
real deb = 0.0 ;
real iva_ven = 0.0 ;
real iva_acq = 0.0 ;
real iva_ret = 0.0 ;
real iva_rim = 0.0 ;
real ult_det = 0.0 ;
real iva_pro = 0.0 ;
real cre_pre = 0.0 ;
real acq_intr = 0.0 ;
2001-05-01 08:17:07 +00:00
const bool isdifferita = is_differita ( ) ; // MI3262...
2002-05-31 10:35:40 +00:00
int error = FALSE ;
2001-05-01 08:17:07 +00:00
1995-09-27 15:28:09 +00:00
TString16 tipo_acc ;
1995-09-18 10:45:10 +00:00
// TBI rewrite from scratch
// this is absolutely fundamental
if ( _basecalc = = precedente )
{
// determina casistica
enum { mm , tt , mt , tm , boh } history = boh ;
1997-05-14 10:46:05 +00:00
real divide_by_three = 1.0 ;
1995-09-18 10:45:10 +00:00
char thh = * _freqviva ;
2001-05-01 08:17:07 +00:00
const TString16 thyear = _year ;
1998-05-04 09:34:04 +00:00
_year . format ( " %d " , atoi ( _year ) - 1 ) ;
1995-09-18 10:45:10 +00:00
if ( ! look_lia ( ) )
error = 3 ;
else
{
char ohh = _lia - > get_char ( " S7 " ) ;
if ( ohh = = ' M ' ) history = thh = = ' M ' ? mm : mt ;
if ( ohh = = ' T ' ) history = thh = = ' M ' ? tm : tt ;
1996-09-26 07:27:04 +00:00
if ( history = = boh )
{
_year = thyear ;
return FALSE ;
}
1995-09-18 10:45:10 +00:00
// casino benzinari
TString attprev = _nditte - > curr ( ) . get ( " CODATTPREV " ) ;
long codd = _nditte - > curr ( ) . get_long ( " CODDITTA " ) ;
2003-03-20 12:25:48 +00:00
TString16 key ;
key . format ( " %ld|%s " , codd , ( const char * ) attprev ) ;
const TRectype & atts = cache ( ) . get ( LF_ATTIV , key ) ;
1995-10-24 10:34:55 +00:00
if ( atts . get_bool ( " ART74_4 " ) ) // e' proprio un gran benzinaro
2002-02-26 16:20:19 +00:00
history = _lia - > get_bool ( " B4 " ) ? mm : tt ; // Was CNF_DITTA->GesT74
1995-09-18 10:45:10 +00:00
switch ( history )
{
case mm :
// base calcolo: 12a anno preced, Rideterminare a seconda dell'acconto
// versato; ris = 88% del debito (0 se credito)
if ( ! look_lim ( 12 ) ) error = 2 ;
else
{
bc + = _lim - > get_real ( " R0 " ) ;
real av = _lim - > get_real ( " R11 " ) ;
bc + = av ;
}
break ;
case tt :
case tm :
// base calcolo: 13a anno precedente. Rideterm. per eventuale acconto
1995-10-18 14:44:50 +00:00
if ( ! look_lim ( 13 ) ) error = 2 ; // TBC sara' 13a davvero? Secondo me e' 12
1995-09-18 10:45:10 +00:00
else
{
bc + = _lim - > get_real ( " R0 " ) ;
real av = _lim - > get_real ( " R11 " ) ;
bc + = av ;
}
1997-05-14 10:46:05 +00:00
if ( history = = tm )
1995-09-18 10:45:10 +00:00
// tm come tt ma si divide per 3 la base di calcolo prima di calcolare l'88%
1997-05-14 10:46:05 +00:00
divide_by_three = 3.0 ;
1995-09-18 10:45:10 +00:00
break ;
case mt :
// basecalcolo: 10, 11, 12 anno prec., 10 e 11 se a debito, 12 vedi acconto;
// sommare e prendi 88% se a debito
if ( ! look_lim ( 10 ) ) error = 2 ;
else
{
real app = _lim - > get_real ( " R0 " ) ;
if ( app . sign ( ) > 0 ) //a debito
bc + = app ;
}
if ( ! look_lim ( 11 ) ) error = 2 ;
else
{
real app = _lim - > get_real ( " R0 " ) ;
if ( app . sign ( ) > 0 ) //a debito
bc + = app ;
}
if ( ! look_lim ( 12 ) ) error = 2 ;
else
{
bc + = _lim - > get_real ( " R0 " ) ;
real av = _lim - > get_real ( " R11 " ) ;
bc + = av ;
}
break ;
}
2002-02-26 16:20:19 +00:00
round_imposta ( bc ) ;
1995-09-18 10:45:10 +00:00
if ( bc . sign ( ) > 0 ) //debito
{
1997-05-14 10:46:05 +00:00
acc = ( ( bc / divide_by_three ) * _ver - > get ( isdifferita ? B_LIQ_DIFF : B_LIQ_NORM ) ) / CENTO ;
2001-05-01 08:17:07 +00:00
acc . round ( TCurrency : : get_firm_dec ( ) ) ;
1995-09-27 15:28:09 +00:00
}
tipo_acc = " S " ;
1995-09-18 10:45:10 +00:00
}
_year = thyear ;
}
1997-05-14 10:46:05 +00:00
else
if ( _basecalc = = incorso )
{
// that's pazzesc but as it turns out there's no better way
_comp_acconto = TRUE ;
// force recalc of current month
_recalc = one ;
int need_refresh = FALSE ;
for ( int mese = 1 ; mese < _month ; mese + + )
if ( is_month_ok_strict ( mese ) & & ( ! look_lim ( mese ) | | ! _lim - > get_bool ( " B0 " ) ) )
{
need_refresh = TRUE ;
break ;
}
2003-03-20 12:25:48 +00:00
if ( need_refresh & & yesno_box ( FR ( " Alcuni mesi precedenti non risultano ricalcolati: \n "
" <EFBFBD> consigliabile il ricalcolo. Si desidera eseguirlo?" ) ) )
1997-05-14 10:46:05 +00:00
_recalc = ever ;
for ( int m = 1 ; m < = _month ; m + + )
if ( is_month_plain ( m ) | | _recalc = = ever )
{
2001-05-01 08:17:07 +00:00
if ( _prind - > iscancelled ( ) )
break ;
1997-05-14 10:46:05 +00:00
update_firm ( m ) ;
}
1995-10-10 10:10:29 +00:00
1997-05-14 10:46:05 +00:00
// calcola l'acconto
if ( look_lim ( 12 ) ) //posiziona anche la tabella lam
{
cre = _lim - > get_real ( " R12 " ) ;
2001-05-01 08:17:07 +00:00
cre - = _lim - > get_real ( " R19 " ) ;
1997-05-14 10:46:05 +00:00
deb = _lim - > get_real ( " R13 " ) + inf + ina ;
2001-05-01 08:17:07 +00:00
deb - = _lim - > get_real ( " R18 " ) + _lim - > get_real ( " R1 " ) ; // CM600446
if ( _lim - > get_real ( " R17 " ) > ZERO )
deb - = _lim - > get_real ( " R17 " ) ;
else
cre + = _lim - > get_real ( " R17 " ) ;
1997-05-14 10:46:05 +00:00
bc = deb - cre ;
if ( bc . sign ( ) > 0 ) acc = bc ;
1995-10-12 15:13:21 +00:00
1997-05-14 10:46:05 +00:00
iva_ven = _lam - > get_real ( " R0 " ) ; //iva sulle vendite annotate fino al 20/12
iva_acq = _lam - > get_real ( " R1 " ) ; //iva sugli acquisti annotati fino al 20/12
cre_pre = _lam - > get_real ( " R2 " ) ; //credito precedente
iva_ret = _lim - > get_real ( " R5 " ) ; //rettifica
iva_rim = _lim - > get_real ( " R1 " ) ; //iva chiesta a rimborso
ult_det = _lim - > get_real ( " R6 " ) ; //ulteriori detrazioni
//iva_pro: //iva relativa alla percentuale di prorata
TTable plm ( " PLM " ) ;
plm . zero ( ) ;
plm . put ( " CODTAB " , _year ) ;
TRectype rec ( plm . curr ( ) ) ;
plm . read ( _isgteq ) ;
for ( ; ! plm . eof ( ) ; plm . next ( ) )
{
if ( plm . curr ( ) ! = rec ) break ;
iva_pro + = plm . get_real ( " R2 " ) ;
}
//acq_intr
TTable pom ( " POM " ) ;
pom . zero ( ) ;
pom . put ( " CODTAB " , _year ) ;
rec = pom . curr ( ) ;
pom . read ( _isgteq ) ;
for ( ; ! pom . eof ( ) ; pom . next ( ) )
{
if ( pom . curr ( ) ! = rec ) break ;
acq_intr + = pom . get_real ( " R0 " ) ;
}
tipo_acc = " A " ; //flag per dire che si e' utilizzato il metodo analitico
//stop
}
else error = 1 ;
// pulisci il water
_comp_acconto = FALSE ;
_isprint = FALSE ;
for ( int i = 1 ; i < = _month ; i + + )
if ( is_month_plain ( i ) )
update_firm ( i ) ;
1995-10-18 14:44:50 +00:00
1997-05-14 10:46:05 +00:00
_lim - > put ( " B0 " , " " ) ;
_lim - > rewrite ( ) ;
if ( look_lim ( 13 ) )
{
2001-05-01 08:17:07 +00:00
_lim - > put ( " B0 " , " " ) ;
_lim - > rewrite ( ) ;
1997-05-14 10:46:05 +00:00
}
//fine
_isprint = TRUE ;
}
1995-09-18 10:45:10 +00:00
1997-05-14 10:46:05 +00:00
// sbatti l'acconto (e non solo!) in LIA
if ( look_lia ( ) )
1995-10-18 14:44:50 +00:00
{
1997-05-14 10:46:05 +00:00
if ( isdifferita & & _basecalc = = incorso )
{
acc * = real ( 2.0 ) ;
acc / = real ( 3.0 ) ;
}
_lia - > put ( " R4 " , acc ) ;
_lia - > put ( " R7 " , iva_ven ) ;
_lia - > put ( " R8 " , iva_acq ) ;
_lia - > put ( " R9 " , iva_ret ) ;
_lia - > put ( " R10 " , iva_rim ) ;
_lia - > put ( " R11 " , ult_det ) ;
_lia - > put ( " R12 " , iva_pro ) ;
TToken_string rr ( " " , ' ! ' ) ;
rr . add ( cre_pre . string ( ) , 0 ) ;
rr . add ( acq_intr . string ( ) , 1 ) ;
_lia - > put ( " S1 " , rr ) ;
_lia - > put ( " S8 " , tipo_acc ) ;
_lia - > rewrite ( ) ;
1995-10-18 14:44:50 +00:00
}
1995-09-18 10:45:10 +00:00
1995-09-27 15:28:09 +00:00
// per questa volta lasciamo perdere la describe_acconto
1997-05-14 10:46:05 +00:00
if ( _isprint )
{
1995-09-18 10:45:10 +00:00
// segnalazioni di errore da gesticolare:
// error = 0: no error
// error = 1: manca tabella risultati liquidazione per l'anno indicato
// error = 2: manca tabella risultati liquidazione per l'anno precedente
// error = 3: manca tabella dichiarazione annuale per l'anno precedente
1997-05-14 10:46:05 +00:00
_DescrItem * d = new _DescrItem ( ACCONTO ) ;
d - > _r0 = bc ;
d - > _r1 = acc ;
d - > _r2 = cre ;
d - > _r3 = deb ;
d - > _f0 = _basecalc = = incorso ;
d - > _f1 = _isbase ;
d - > _f2 = error ;
d - > _f3 = isdifferita ;
d - > _s0 = _nditte - > curr ( ) . get ( " CODDITTA " ) ;
d - > _s1 = _nditte - > curr ( ) . get ( " RAGSOC " ) ;
2001-05-01 08:17:07 +00:00
1997-05-14 10:46:05 +00:00
_descr_arr . add ( d ) ;
}
return TRUE ;
1995-09-18 10:45:10 +00:00
}
1995-09-27 15:28:09 +00:00