2017-07-10 14:16:23 +00:00
/* Gestione maschera */
# include "tf0100b.h"
/////////////////////////////////////////////////////////////////////////////////////
// TTrFa_mask
/////////////////////////////////////////////////////////////////////////////////////
TTrFa_mask : : ~ TTrFa_mask ( )
{
TSheet_field & sheet = sfield ( F_RIGHE ) ;
if ( ! sheet . empty ( ) )
sheet . destroy ( ) ;
}
void TTrFa_mask : : next_page ( int p )
{
TAutomask : : next_page ( p ) ;
if ( _filter_changed )
{
TSheet_field & sf = sfield ( F_RIGHE ) ;
if ( curr_win ( ) = = sf . parent ( ) )
{
load_sheet ( ) ;
sf . force_update ( ) ;
_filter_changed = false ;
}
}
}
bool TTrFa_mask : : on_field_event ( TOperable_field & o , TField_event e , long jolly )
{
switch ( o . dlg ( ) )
{
case F_DATAFIN :
if ( e = = fe_init )
o . set ( TDate ( TODAY ) ) ;
break ;
case DLG_ALL :
if ( e = = fe_button )
{
TSheet_field & docs = sfield ( F_RIGHE ) ;
TString_array & sht = docs . rows_array ( ) ;
const int items = sht . items ( ) ;
if ( items > 0 )
{
const TString4 select = * ( sht . row ( 0 ) . get ( 0 ) ) = = ' X ' ? " " : " X " ;
for ( int i = 0 ; i < items ; i + + )
sht . row ( i ) . add ( select , 0 ) ;
docs . force_update ( ) ;
}
}
break ;
case F_RIGHE :
if ( e = = se_notify_add )
{
TSheet_field & s = ( TSheet_field & ) o ;
TToken_string & row = s . row ( jolly ) ;
row . add ( nuovo_progr ( ) , s . cid2index ( A_NUMERO ) ) ;
2017-07-18 15:27:20 +00:00
row . add ( get ( F_TIPOCF ) , s . cid2index ( A_TIPOCF ) ) ;
2017-07-10 14:16:23 +00:00
} else
if ( e = = se_query_del )
{
TSheet_field & s = ( TSheet_field & ) o ;
TToken_string & row = s . row ( jolly ) ;
const TRecnotype progr = row . get_long ( 0 ) ;
return progr > = MOV_CUSTOM ;
} else
if ( e = = se_enter )
{
//primaNota(o,e);
}
break ;
case A_DATAREG :
{
// Mi interessa solo fe_edit
if ( e ! = fe_modify ) break ;
// Controllo che la data sia < della data documento e l'esercizio sia quello richiesto
TDate datareg = o . get ( ) , datadoc = o . mask ( ) . get ( A_DATADOC ) ;
if ( datareg > = get_date ( F_DATAINI ) & & datareg < = get_date ( F_DATAFIN ) )
{
// Controllo la data del documento
if ( datadoc . ok ( ) )
{
if ( datadoc > datareg )
{
error_box ( " La data del documento <20> antecedente a quella di registrazione " ) ;
o . set ( " " ) ;
}
}
}
else
{
error_box ( " La data di registrazione non appartiene al periodo corrente " ) ;
o . set ( " " ) ;
}
}
break ;
case A_DATADOC :
{
// Mi interessa solo fe_edit
if ( e ! = fe_modify ) break ;
TDate datareg = o . mask ( ) . get ( A_DATAREG ) , datadoc = o . get ( ) ;
// Controllo la data di registrazione
if ( datareg . ok ( ) )
{
if ( datadoc > datareg )
{
error_box ( " La data del documento <20> antecedente a quella di registrazione " ) ;
o . set ( " " ) ;
}
}
}
break ;
case A_ALIQUOTA :
if ( e = = fe_modify )
{
// Calcolo la natura
o . mask ( ) . set ( A_NATURA , natura ( o . get ( ) ) ) ;
// Se esiste un imponibile calcolo l'imposta
real imponibile = o . mask ( ) . get ( A_IMPONIBILE ) , imposta = ZERO ;
if ( imponibile > 0 )
{
imposta = imponibile * real ( cache ( ) . get ( " %IVA " , o . get ( ) , " R0 " ) ) / 100 ;
2017-07-26 14:58:22 +00:00
if ( imposta ! = o . mask ( ) . get_real ( A_IMPOSTA ) & & yesno_box ( " Aggiornare l'imposta? " ) )
o . mask ( ) . set ( A_IMPOSTA , imposta . round ( 2 ) . string ( ) ) ;
2017-07-10 14:16:23 +00:00
}
}
break ;
case A_IMPONIBILE :
if ( e = = fe_modify )
{
// Se esiste l'iva calcolo l'imposta
real imponibile = o . get ( ) , imposta = ZERO ;
TString codiva = o . mask ( ) . get ( A_ALIQUOTA ) ;
if ( codiva ! = " " )
{
imposta = imponibile * real ( cache ( ) . get ( " %IVA " , codiva , " R0 " ) ) / 100 ;
2017-07-26 14:58:22 +00:00
if ( imposta ! = o . mask ( ) . get_real ( A_IMPOSTA ) & & yesno_box ( " Aggiornare l'imposta? " ) )
o . mask ( ) . set ( A_IMPOSTA , imposta . round ( 2 ) . string ( ) ) ;
2017-07-10 14:16:23 +00:00
}
}
break ;
case A_IMPOSTA :
if ( e = = fe_modify )
{
// Controllo dell'esistenza sia di codiva che dell'imponibile e verifico che l'importo immesso sia corretto
real imponibile = o . mask ( ) . get ( A_IMPONIBILE ) , imposta = ZERO ;
TString codiva = o . mask ( ) . get ( A_ALIQUOTA ) ;
if ( codiva ! = " " & & imponibile > ZERO )
{
imposta = imponibile * real ( cache ( ) . get ( " %IVA " , codiva , " R0 " ) ) / 100 ; imposta = imposta . round ( 2 ) ;
// Controllo che l'aliquota calcolata sia == a quella che ho qua
real impostaInserita = o . get ( ) ;
if ( impostaInserita ! = imposta )
{
TString msg ;
msg < < " Attenzione!! Il valore immesso " < < impostaInserita . string ( ) < < " <EFBFBD> non <20> corretto!\n " ;
msg < < " Valore corretto: " < < imposta . string ( ) < < " <EFBFBD> \n Vuoi proseguire? " ;
if ( ! yesno_box ( msg ) )
{
o . set ( imposta . string ( ) ) ;
}
}
}
}
2017-07-13 12:27:06 +00:00
break ;
2017-07-10 14:16:23 +00:00
case A_TIPOCF :
case A_CODCF :
case A_OCFPI :
{
if ( e ! = fe_modify ) break ;
2017-07-13 12:27:06 +00:00
// Leggo dal clifo
TString tipocf , codcf , ocfpi ;
tipocf = o . mask ( ) . get ( A_TIPOCF ) ;
codcf = o . mask ( ) . get ( A_CODCF ) ;
ocfpi = o . mask ( ) . get ( A_OCFPI ) ;
TRectype app = getCli ( tipocf , codcf , ocfpi ) ;
2017-07-10 14:16:23 +00:00
o . mask ( ) . set ( A_RAGSOC , app . get ( " RAGSOC " ) ) ;
o . mask ( ) . set ( A_RFSO , app . get ( " CODRFSO " ) ) ;
o . mask ( ) . set ( A_RAGSOCRFSO , getRFSO ( app . get ( " CODRFSO " ) ) ) ;
o . mask ( ) . set ( A_PAIV , app . get ( " PAIV " ) ) ;
o . mask ( ) . set ( A_COFI , app . get ( " COFI " ) ) ;
2017-07-13 12:27:06 +00:00
// Abilito se il cliente <20> occasionale
o . mask ( ) . enable ( A_OCFPI , app . get_bool ( " OCCAS " ) ) ;
2017-07-10 14:16:23 +00:00
// Controllo autofattura
TString key ; key < < prefix ( ) . firm ( ) . get ( " TIPOA " ) < < " | " < < prefix ( ) . firm ( ) . get ( " CODANAGR " ) ;
TString piva = cache ( ) . get ( LF_ANAG , key , " PAIV " ) ;
if ( piva = = app . get ( " PAIV " ) )
{
// Autofattura!
o . mask ( ) . set ( A_AUTOFATT , " X " ) ;
}
}
2017-07-13 12:27:06 +00:00
break ;
2017-07-18 09:49:17 +00:00
case A_TIPODOC :
// Controllo che il tipo di documento rientri in quelli del filtro
if ( e = = fe_modify & & ! get_bool ( getTipoDoc ( o . get ( ) ) ) )
{
error_box ( " Attenzione! il tipo di documento scelto non fa parte dei filtri correnti! " ) ;
o . set ( " " ) ;
}
break ;
2017-07-10 14:16:23 +00:00
case DLG_SAVEREC :
if ( e = = fe_button )
saveAll ( ) ;
break ;
case DLG_ARCHIVE :
if ( e = = fe_button )
checkAll ( ) ;
break ;
case DLG_EDIT :
if ( e = = fe_button )
{
TSheet_field & sheet = sfield ( F_RIGHE ) ;
if ( sheet . items ( ) > 0 )
{
sheet . esporta ( ) ;
}
else
{
warning_box ( " Impossibile esportare una griglia vuota " ) ;
}
}
break ;
case DLG_RECALC :
if ( e = = fe_button )
next_page ( 1 ) ;
break ;
case DLG_USER :
if ( e = = fe_button | | e = = fe_init )
{
const long numreg = o . mask ( ) . get_long ( A_NUMERO ) ;
const bool enab = ( numreg > 0 ) & & ( numreg < MOV_CUSTOM ) ;
if ( e = = fe_button & & enab )
{
o . disable ( ) ; // Tecnica anti doppio click!
TRectype mov ( LF_MOV ) ;
mov . put ( " NUMREG " , numreg ) ;
mov . edit ( ) ;
o . enable ( ) ;
}
else
o . enable ( enab ) ;
}
break ;
case DLG_DELREC :
if ( e = = fe_button & & o . active ( ) )
{
const long progr = o . mask ( ) . get_long ( A_NUMERO ) ;
TString codalq = o . mask ( ) . get ( A_ALIQUOTA ) ;
TString key ; key < < progr < < " | " < < codalq ;
2017-07-26 14:58:22 +00:00
if ( cache ( ) . get ( LF_TRASFATT , key ) . full ( ) )
{
TLocalisamfile trasfat ( LF_TRASFATT ) ;
trasfat . put ( " NUMREG " , progr ) ;
trasfat . put ( " CODIVA " , codalq ) ;
const int err = trasfat . remove ( ) ;
if ( err ! = NOERR )
return error_box ( FR ( " Errore di cancellazione: %d " ) , err ) ;
}
else
2017-07-10 14:16:23 +00:00
return error_box ( TR ( " Riga non cancellabile " ) ) ;
2017-07-26 14:58:22 +00:00
// Elimino la riga
TSheet_field & sheet = sfield ( F_RIGHE ) ;
// Vado a cercare la riga
FOR_EACH_SHEET_ROW ( sheet , r , strarr )
{
long thisProg ;
TString thisAlq ;
strarr - > get ( _numero , thisProg ) ;
strarr - > get ( _aliquota , thisAlq ) ;
if ( thisProg = = progr & & thisAlq = = codalq ) break ;
}
sheet . destroy ( r ) ; // Aggiorna in automatico
// Se ha cancellato un movimento custom che deriva dalla prima nota propongo di andarlo a ripescare
if ( progr < MOV_CUSTOM & & yesno_box ( " Hai cancellato una riga custom di un movimento in prima nota, vuoi ricaricare la tabella? \n (Tutti i record verranno salvati per non perdere le modifiche!) " ) )
{
saveAll ( ) ;
load_sheet ( ) ;
return true ;
}
2017-07-10 14:16:23 +00:00
}
break ;
2017-07-13 12:27:06 +00:00
case DLG_EMAIL :
if ( e = = fe_button )
openJava ( ) ;
break ;
2017-07-10 14:16:23 +00:00
default :
break ;
}
const short id = o . dlg ( ) ;
if ( e = = fe_modify & & jolly = = 1 )
{
if ( id > = START_SHEET & & id < END_SHEET & & id ! = A_FORZATA )
{
// Se ho modificato l'impostazione dell'invio non va segnata la modifica MA devo togliere o mettere il flag a tutti quelli con movimento uguale
if ( id ! = A_INVIO )
o . mask ( ) . set ( A_FORZATA , true ) ;
else
{
changeInvio ( o . mask ( ) . get ( A_TIPOCF ) , o . mask ( ) . get ( A_CODCF ) , o . mask ( ) . get ( A_NUMDOC ) , o . mask ( ) . get ( A_INVIO ) ) ;
}
}
}
if ( e = = fe_modify & & jolly = = 0 )
{
if ( id > = START_MASK & & id < = END_MASK )
{
setFilterChanged ( ) ;
}
if ( id > = START_BOOLEAN & & id < = END_BOOLEAN )
saveConfig ( ) ;
}
return true ;
}
2017-07-13 12:27:06 +00:00
void TTrFa_mask : : openJava ( )
{
TFilename tmp ;
tmp = SPESOMETROBASE " \\ ModuliSirio.jar " ;
tmp . make_absolute_path ( ) ;
DIRECTORY old_dir ; xvt_fsys_get_dir ( & old_dir ) ;
DIRECTORY new_dir ; xvt_fsys_convert_str_to_dir ( tmp . path ( ) , & new_dir ) ;
xvt_fsys_set_dir ( & new_dir ) ;
2017-07-14 10:49:00 +00:00
2017-07-13 12:27:06 +00:00
const bool good = goto_url ( tmp ) ;
if ( good )
{
xvt_sys_sleep ( 3000 ) ;
}
else
{
error_box ( FR ( " Impossibile eseguire Java -jar %s " ) , ( const char * ) tmp ) ;
}
2017-07-14 10:49:00 +00:00
xvt_fsys_set_dir ( & old_dir ) ;
2017-07-13 12:27:06 +00:00
}
2017-07-10 14:16:23 +00:00
void TTrFa_mask : : loadConfig ( )
{
// Rilevo i tipi scelti
TToken_string tipidoc ( ini_get_string ( CONFIG_DITTA , " tf " , " TIPIDOC " ) ) ;
// Potrei fare un for su TToken_string ma non darebbe la possibilit<69> di flaggare tutto in caso di prima installazione
for ( int pos = 0 ; pos < tipidoc . items ( ) ; pos + + )
{
int field = getTipoDoc ( tipidoc . get ( pos ) ) ;
if ( field ! = - 1 )
set ( field , " X " ) ;
}
}
void TTrFa_mask : : saveConfig ( )
{
TToken_string tipidoc ;
for ( int id = START_BOOLEAN ; id < = END_BOOLEAN ; id + + )
{
if ( get_bool ( id ) )
{
tipidoc . add ( getTipoDoc ( id ) ) ;
}
}
ini_set_string ( CONFIG_DITTA , " tf " , " TIPIDOC " , tipidoc ) ;
}
/* salvo tutti i record modificati */
bool TTrFa_mask : : saveAll ( )
{
TSheet_field & sheet = sfield ( F_RIGHE ) ;
//TString_array& strarr = sheet.rows_array();
TString mod = " " ;
2017-07-13 12:27:06 +00:00
TLocalisamfile mov ( LF_MOV ) ;
2017-07-10 14:16:23 +00:00
FOR_EACH_SHEET_ROW ( sheet , r , strarr )
{
strarr - > get ( _forzata , mod ) ;
if ( mod = = " X " )
{
bool ok , retry = false ;
do
{
ok = saveRec ( * strarr ) ;
if ( ! ok )
{
TString msg = " Errore durante il salvataggio del movimento " ;
msg < < " alla riga " < < r < < " \n Ritentare? " ;
retry = yesno_box ( msg ) ;
}
} while ( retry & & ! ok ) ;
if ( ! ok )
return false ;
}
2017-07-13 12:27:06 +00:00
// Salvo il valore di invio se <20> stato modificato
else if ( strcmp ( strarr - > get ( _invio ) , " X " ) ! = 0 )
{
TRectype rmov = cache ( ) . get ( LF_MOV , strarr - > get ( _numero ) ) ;
mov . rewrite ( rmov ) ;
}
2017-07-10 14:16:23 +00:00
}
2017-07-17 08:15:41 +00:00
message_box ( " Salvataggio effettuato! " ) ;
2017-07-10 14:16:23 +00:00
return true ;
}
bool TTrFa_mask : : checkAll ( )
{
// Controllo di avere uno sheet pieno
if ( ! checkNotEmpty ( ) ) return true ;
if ( yesno_box ( " Controllare tutti i C.F. P.IVA? " ) )
{
TExternal_app servizio ( " cg1 -2 L " ) ;
servizio . run ( ) ;
}
// Sistemo i flag
theFinalCheckDown ( ) ;
static TPrinter stampa ;
stampa . reset ( ) ;
stampa . open ( ) ;
TPrintrow riga ;
riga . put ( TR ( " ------------------ Controllo Errori TF ------------------- " ) , 30 ) ;
stampa . setheaderline ( 1 , riga ) ;
riga . reset ( ) ;
riga . put ( " N.Registrazione " , 0 ) ;
riga . put ( " N.Documento " , 20 ) ;
riga . put ( " Tipo errore " , 40 ) ;
stampa . setheaderline ( 3 , riga ) ;
riga . reset ( ) ;
riga . put ( TR ( " Tutti i record qui elencati sono stati segnati con il codice \" Errore \" e non verranno inviati " ) , 0 ) ;
stampa . setheaderline ( 2 , riga ) ;
riga . reset ( ) ;
stampa . setheaderline ( 4 , riga ) ;
stampa . print ( riga ) ;
TSheet_field & sheet = sfield ( F_RIGHE ) ;
FOR_EACH_SHEET_ROW ( sheet , r , strarr )
{
2017-07-18 09:49:17 +00:00
checkRec ( & stampa , strarr ) ;
2017-07-10 14:16:23 +00:00
}
riga . reset ( ) ;
riga . put ( TR ( " ------------------ Fine controllo! ------------------ " ) , 30 ) ;
stampa . print ( riga ) ;
stampa . close ( ) ;
return true ;
}
inline void printError ( TPrinter * stampa , TString movimento , TString documento , TString msgerr )
{
TPrintrow riga ;
riga . put ( movimento , 0 ) ;
riga . put ( documento , 20 ) ;
riga . put ( msgerr , 40 ) ;
stampa - > print ( riga ) ;
}
2017-07-18 09:49:17 +00:00
bool TTrFa_mask : : checkRec ( TPrinter * stampa , TToken_string * rec )
2017-07-10 14:16:23 +00:00
{
bool ok = true ;
2017-07-18 09:49:17 +00:00
TString numMov = rec - > get ( _numero ) , numDoc = rec - > get ( _numdoc ) ;
2017-07-10 14:16:23 +00:00
TString msgerr ;
TString coderr ;
// Controllo date ***********************************************************************************
2017-07-18 09:49:17 +00:00
TDate reg = rec - > get ( _datareg ) , doc = rec - > get ( _datadoc ) ;
2017-07-10 14:16:23 +00:00
if ( reg < doc )
{
ok = false ;
msgerr . cut ( 0 ) < < " Data registrazione precedente alla data del documento " ;
printError ( stampa , numMov , numDoc , msgerr ) ;
coderr < < " 1; " ;
}
// Controllo aliquota, imponibile e imposta *********************************************************
2017-07-18 09:49:17 +00:00
TCodiceIVA codiva ( rec - > get ( _aliquota ) ) ;
TString nat = rec - > get ( _natura ) , realNat ( natura ( rec - > get ( _aliquota ) ) ) ;
2017-07-10 14:16:23 +00:00
nat . ltrim ( ) ; // Se vuoto arriva con uno spazio
2017-07-18 09:49:17 +00:00
real imponibile = rec - > get ( _imponibile ) , imposta = rec - > get ( _importoIVA ) ;
2017-07-10 14:16:23 +00:00
if ( nat ! = realNat )
{
msgerr . cut ( 0 ) < < " Natura del movimento errata, valore dichiarato: " < < nat < < " valore corretto: " < < realNat ;
printError ( stampa , numMov , numDoc , msgerr ) ;
coderr < < " 2; " ;
}
real realImp = imponibile * codiva . percentuale ( ) / CENTO ;
realImp . round ( 2 ) ;
if ( imposta > realImp + TOLLARANZA | | imposta < realImp - TOLLARANZA )
{
msgerr . cut ( 0 ) < < " Imposta errata, valore dichiarato: " < < imposta . string ( ) < < " valore \" potenzialmente \" corretto: " < < realImp . string ( ) ;
printError ( stampa , numMov , numDoc , msgerr ) ;
coderr < < " 3; " ;
}
2017-07-28 08:20:30 +00:00
if ( decodTipo ( rec ) = = " ERR0 " )
2017-07-20 14:39:52 +00:00
{
ok = false ;
msgerr . cut ( 0 ) < < " Non riesco a determinare il tipo di documento corretto per l'agenzia delle entrate! " ;
printError ( stampa , numMov , numDoc , msgerr ) ;
coderr < < " 4; " ;
}
2017-07-10 14:16:23 +00:00
// Flaggo il record con i messaggi di errore
2017-07-18 09:49:17 +00:00
rec - > add ( coderr , _coderr ) ; // Sempre potrebbero esserci errori non bloccanti
2017-07-10 14:16:23 +00:00
return ok ;
}
bool TTrFa_mask : : checkNotEmpty ( )
{
TSheet_field & sheet = sfield ( F_RIGHE ) ;
TString msg ;
if ( sheet . empty ( ) )
msg = " La tabella dei movimenti <20> vuota, vuoi caricarla con i filtri selezionati? " ;
else if ( _filter_changed )
msg = " I filtri sono stati cambiati, vuoi ricaricare la tabella con i nuovi filtri selezionati? " ;
if ( msg . full ( ) & & yesno_box ( msg ) )
{
_filter_changed = false ;
load_sheet ( ) ;
}
return sheet . full ( ) ;
}
2017-07-20 14:39:52 +00:00
void TTrFa_mask : : theFinalCheckDown ( ) // IT'S THE FINAL CHECKDOOOOOOOWN! WE'RE CHECKING TOGEEEETHEEEEER!!!!
2017-07-10 14:16:23 +00:00
{
TSheet_field & sheet = sfield ( F_RIGHE ) ;
TAssoc_array cliDocs ;
FOR_EACH_SHEET_ROW ( sheet , r , strarr )
{
// Chiave: TIPOCF + CODCF + NUMDOC + CODIVA
TString key ; key < < strarr - > get_char ( _tipocf ) < < " | " < < strarr - > get_int ( _codcf ) < < " | " < < strarr - > get ( _numdoc ) < < " | " < < strarr - > get ( _aliquota ) ;
TToken_string newNumero ; newNumero . add ( r , 0 ) ; newNumero . add ( strarr - > get_char ( _invio ) , 1 ) ;
if ( cliDocs . is_key ( key ) )
{
TToken_string oldnumero = * ( TToken_string * ) cliDocs . objptr ( key ) ;
TString oldflag ; oldnumero . get ( 1 , oldflag ) ;
if ( oldflag = = FLAG_FORZATO )
flagRow ( r , FLAG_NINVIO ) ;
else
{
int oldr ; oldnumero . get ( 0 , oldr ) ;
flagRow ( oldr , FLAG_NINVIO ) ;
}
cliDocs . add ( key , newNumero ) ;
}
else
{
cliDocs . add ( key , newNumero ) ;
}
}
2017-07-13 12:27:06 +00:00
// Forzo l'aggiornamento dello sheet
sfield ( F_RIGHE ) . force_update ( ) ;
2017-07-10 14:16:23 +00:00
}
void TTrFa_mask : : flagRow ( int nrow , TString flag )
{
TSheet_field & sheet = sfield ( F_RIGHE ) ;
TToken_string & row = sheet . row ( nrow ) ;
row . add ( flag , _invio ) ;
}
TRecnotype TTrFa_mask : : nuovo_progr ( ) const
{
static TRectype app ( LF_TRASFATT ) ;
app . last ( TLocalisamfile ( LF_TRASFATT ) ) ;
// Lo inizializzo solo la prima volta poi incremento
static TRecnotype numreg = app . get_long ( " NUMREG " ) > MOV_CUSTOM ? app . get_long ( " NUMREG " ) : MOV_CUSTOM ;
numreg + + ;
return numreg ;
}
// Dato un cliente e il suo numero documento imposto il nuovo flag di invio su tutti i campi
void TTrFa_mask : : changeInvio ( TString tipocf , TString codcf , TString numdoc , TString invio ) const
{
TSheet_field & sheet = sfield ( F_RIGHE ) ;
TString rtipo , rcod , rnum ;
FOR_EACH_SHEET_ROW ( sheet , r , strarr )
{
// Ricevo i parametri della riga
rtipo . cut ( 0 ) ; rtipo < < strarr - > get_char ( _tipocf ) ;
rcod . cut ( 0 ) ; rcod < < strarr - > get_int ( _codcf ) ;
rnum . cut ( 0 ) ; rnum < < strarr - > get ( _numdoc ) ;
if ( tipocf = = rtipo & & codcf = = rcod & & rnum = = numdoc )
{
strarr - > add ( invio , _invio ) ;
}
}
}
void TTrFa_mask : : load_sheet ( )
{
const char tipo = get ( F_TIPOCF ) [ 0 ] ;
const long codice = get_long ( F_CODCF ) ;
TDate dal = get_date ( F_DATAINI ) , al = get_date ( F_DATAFIN ) ;
2017-07-24 09:50:05 +00:00
// Importanti! Evito errori dopo premendo il bottone invia
if ( ! dal . ok ( ) )
{
dal = TDate ( 01 , 01 , 2017 ) ; // Data inizio validit<69> questo spesometro
set ( F_DATAINI , dal ) ;
}
if ( ! al . ok ( ) )
{
al = TDate ( TODAY ) ;
set ( F_DATAFIN , al ) ;
}
2017-07-10 14:16:23 +00:00
//TString key; key << "TIPOA=" << prefix().firm().get("TIPOA")<< ",CODANAGR=" << prefix().firm().get("CODANAGR");
TString key ; key < < prefix ( ) . firm ( ) . get ( " TIPOA " ) < < " | " < < prefix ( ) . firm ( ) . get ( " CODANAGR " ) ;
2017-07-28 08:20:30 +00:00
static const TString pivaDitta = cache ( ) . get ( LF_ANAG , key , " PAIV " ) ;
static const TString cofiDitta = cache ( ) . get ( LF_ANAG , key , " COFI " ) ;
2017-07-10 14:16:23 +00:00
TTrFa_cursors c ;
TSheet_field & sheet = sfield ( F_RIGHE ) ;
sheet . hide ( ) ; // Nascondo lo sheet per guadagnare un 20% di velocit<69> di caricamento, le ottimizzazioni da PRO!
if ( ! sheet . empty ( ) )
sheet . destroy ( ) ;
TAssoc_array recimposte ;
int items = c . updateFilters ( tipo , codice , dal , al , get_int ( F_FATTSEL ) ) ;
for ( bool ok = true ; items > 0 & & ok ; )
{
2017-07-13 12:27:06 +00:00
TString tipocf , codcf , ocfpi ;
int err = c . next ( recimposte , ok , tipocf , codcf , ocfpi ) ;
2017-07-18 15:27:20 +00:00
2017-07-10 14:16:23 +00:00
// Carico i clienti
2017-07-13 12:27:06 +00:00
TRectype cli = getCli ( tipocf , codcf , ocfpi ) ;
2017-07-10 14:16:23 +00:00
FOR_EACH_ASSOC_OBJECT ( recimposte , h , iva , rec )
{
TRectype movimento = * ( TRectype * ) rec ;
// Controllo che sia un tipo documento da leggere
if ( ! get_bool ( getTipoDoc ( movimento . get ( " TIPODOC " ) ) ) ) continue ;
2017-07-18 09:49:17 +00:00
// A volte mi pesca movimenti con invio sbagliato
if ( ! checkInvio ( movimento . get ( " TFINVIO " ) ) ) continue ;
2017-07-10 14:16:23 +00:00
2017-07-17 08:15:41 +00:00
// Creo una nuova riga nello sheet
TToken_string & row = sheet . row ( - 1 ) ;
2017-07-10 14:16:23 +00:00
/* Siccome mi cambiano l'ordine ogni volta e non ho voglia di cambiare tutto ovunque
* basta settare i valori negli enum e lo sheet
*/
TRectype isCust = getTrasFatt ( movimento . get ( " NUMREG " ) , iva ) ;
2017-07-13 12:27:06 +00:00
2017-07-18 09:49:17 +00:00
row . add ( movimento . get ( " TFINVIO " ) = = " I " ? " X " : " " , _spedita ) ; // Spedita
2017-07-13 12:27:06 +00:00
row . add ( " X " ) ; // Da spedire, sempre!
row . add ( isCust . full ( ) ? " X " : " " , _forzata ) ; // Modificato
row . add ( movimento . get_long ( " NUMREG " ) , _numero ) ; // Numero registrazione
row . add ( movimento . get_date ( " DATAREG " ) , _datareg ) ; // Data Registrazione
row . add ( movimento . get ( " TIPO " ) , _tipocf ) ; // Tipo Cli/For
row . add ( movimento . get ( " CODCF " ) , _codcf ) ; // Codice Cli/For
row . add ( movimento . get ( " OCCAS " ) , _occas ) ; // Codice Occasionale
row . add ( cli . get ( " RAGSOC " ) , _ragsoc ) ; // Ragione sociale
row . add ( cli . get ( " CODRFSO " ) , _rfso ) ; // Codice RF/SO
row . add ( getRFSO ( cli . get ( " CODRFSO " ) ) , _ragsocrfso ) ; // Ragione Sociale RF/SO
row . add ( movimento . get ( " TIPODOC " ) , _codnum ) ; // Tipo documento
row . add ( movimento . get ( " NUMDOC " ) , _numdoc ) ; // Numero documento
row . add ( movimento . get_date ( " DATADOC " ) , _datadoc ) ; // Data documento
row . add ( natura ( iva ) , _natura ) ; // NATURA!
row . add ( iva , _aliquota ) ; // Codice aliquota!
row . add ( findDetraib ( movimento . get ( " TIPODET " ) ) , _detraibile ) ; // Detraibilit<69>
row . add ( movimento . get_real ( " IMPONIBILE " ) , _imponibile ) ; // Imponibile
row . add ( movimento . get_real ( " IMPOSTA " ) , _importoIVA ) ; // Imposta
row . add ( revCharge ( movimento . get ( " NUMREG " ) ) , _reverse ) ; // Rev.Charge
2017-07-10 14:16:23 +00:00
/*
* Possono esistere movimenti custom dove il cliente ha una partita IVA propria
* ma <EFBFBD> stato flaggato l ' autofattura , quindi in trasfat <EFBFBD> presente il codice cliente con PIVA e CODFIS della ditta .
* Controllo sia il movimento che il cliente
*/
if ( movimento . get ( " AUTOFATT " ) = = " X " | | pivaDitta = = cli . get ( " PAIV " ) ) // Se <20> un autofattura
{
2017-07-13 12:27:06 +00:00
row . add ( " X " , _autofatt ) ; // AutoFatt
row . add ( pivaDitta , _paiv ) ; // P.IVA
row . add ( cofiDitta , _codfis ) ; // Codice Fiscale
2017-07-10 14:16:23 +00:00
}
else
{
2017-07-13 12:27:06 +00:00
row . add ( " " , _autofatt ) ; // AutoFatt
row . add ( cli . get ( " PAIV " ) , _paiv ) ; // P.IVA
row . add ( cli . get ( " COFI " ) , _codfis ) ; // Codice Fiscale
2017-07-10 14:16:23 +00:00
}
2017-07-13 12:27:06 +00:00
sheet . enable_cell ( sheet . items ( ) - 1 , _occas , movimento . get ( " OCCAS " ) . full ( ) ) ;
2017-07-10 14:16:23 +00:00
}
recimposte . destroy ( ) ;
}
sheet . force_update ( ) ;
sheet . show ( ) ;
}
2017-07-18 09:49:17 +00:00
bool TTrFa_mask : : checkInvio ( const TString & invio )
{
bool ok ;
switch ( get_int ( F_FATTSEL ) )
{
case 0 :
2017-07-24 09:50:05 +00:00
ok = invio = = " " | | invio = = FLAG_INVIO | | invio = = FLAG_FORZATO | | invio = = FLAG_ERRORE ;
2017-07-18 09:49:17 +00:00
break ;
case 1 :
ok = invio = = FLAG_INVIATO ;
break ;
case 2 :
default :
ok = invio = = FLAG_NINVIO ;
break ;
}
return ok ;
}
2017-07-10 14:16:23 +00:00
TTrFa_mask : : TTrFa_mask ( TString msk )
: TAutomask ( msk ) , _filter_changed ( true )
{
loadConfig ( ) ;
}