2010-10-11 14:40:52 +00:00
# include <applicat.h>
# include <automask.h>
# include <progind.h>
# include <reputils.h>
2011-02-02 15:04:06 +00:00
# include "../cg/cg2101.h"
# include "../cg/cg2103.h"
# include "../cg/cgsaldac.h"
2011-01-26 16:56:02 +00:00
# include "../mg/movmag.h"
# include "../mg/rmovmag.h"
2010-10-11 14:40:52 +00:00
2011-01-26 16:56:02 +00:00
# include "halib.h"
2010-10-11 14:40:52 +00:00
# include "ha1300a.h"
2011-02-01 17:01:21 +00:00
# include "ha1301a.h"
2010-10-11 14:40:52 +00:00
# define UPLOAD_FILE "upload.d"
2010-10-26 15:46:30 +00:00
//funzione di ordinamento del file di upload una volta caricato in memoria
2011-02-02 15:04:06 +00:00
static TToken_string tipi_record ( " SU|VC|TF|RF|SI|BR|RC " ) ;
2010-10-26 15:46:30 +00:00
int ordina_upload ( const TObject * * o1 , const TObject * * o2 )
{
const TString & s1 = * ( TString * ) * o1 ;
const TString & s2 = * ( TString * ) * o2 ;
2011-02-02 15:04:06 +00:00
//ordinatore dei record Testata e Riga fattura
if ( s1 [ 1 ] = = ' F ' & & s2 [ 1 ] = = ' F ' )
2011-02-01 11:40:26 +00:00
{
2011-02-02 15:04:06 +00:00
TToken_string k [ 2 ] ;
for ( int i = 0 ; i < 2 ; i + + )
2010-10-26 15:46:30 +00:00
{
2011-02-02 15:04:06 +00:00
const TString & rec = i = = 0 ? s1 : s2 ;
TToken_string & key = k [ i ] ;
if ( rec [ 0 ] = = ' T ' )
2010-10-26 15:46:30 +00:00
{
2011-02-02 15:04:06 +00:00
key . add ( rec . mid ( 14 , 2 ) ) ; //anno
key . add ( rec . mid ( 16 , 1 ) ) ; //tipodoc
key . add ( rec . mid ( 5 , 5 ) ) ; //numdoc
}
else
{
key . add ( rec . mid ( 14 , 2 ) ) ; //anno
key . add ( rec . mid ( 28 , 1 ) ) ; //tipodoc
key . add ( rec . mid ( 5 , 5 ) ) ; //numdoc
key . add ( rec . mid ( 29 , 5 ) ) ; //codart
2010-10-26 15:46:30 +00:00
}
}
2011-02-02 15:04:06 +00:00
return k [ 0 ] . compare ( k [ 1 ] ) ;
2010-10-26 15:46:30 +00:00
}
2011-02-02 15:04:06 +00:00
const int pos1 = tipi_record . get_pos ( s1 . left ( 2 ) ) ;
const int pos2 = tipi_record . get_pos ( s2 . left ( 2 ) ) ;
if ( pos1 ! = pos2 )
return pos1 - pos2 ;
2010-10-26 15:46:30 +00:00
return s1 . compare ( s2 ) ;
}
//------------------------------------------------------------
// Hardy_upload_recordset: serve per l'INPUT
//------------------------------------------------------------
class THardy_upload_recordset : public THardy_recordset
{
protected :
virtual TRecnotype new_rec ( const char * trc ) ;
public :
THardy_upload_recordset ( const TFilename & filename ) ;
} ;
/////////////////////////////////////////////////////////////
// Recordset specifici per i dati da trasferire INPUT
/////////////////////////////////////////////////////////////
TRecnotype THardy_upload_recordset : : new_rec ( const char * trc )
{
if ( trc & & * trc > ' ' )
{
TString rec ; rec < < trc < < " \r \n " ;
return TText_recordset : : new_rec ( rec ) ;
}
return - 1 ;
}
//questo invece <20> il metodo magico che vale per il caricamento da file esterno
THardy_upload_recordset : : THardy_upload_recordset ( const TFilename & filename )
: THardy_recordset ( 256 )
{
TFilename cazzone ;
//as400 con lunghezza 256 e chiave lunga 2 (a partire dall'inizio): <20> il tipo record
parse_query ( " AS400(256,2) " , cazzone ) ;
//Tipo record SU
//--------------
add_trc_field ( " SU " , " TipoRecord " , T_X , 1 , 2 ) ; //x
add_trc_field ( " SU " , " CodiceTerminale " , T_N , 3 , 3 ) ; //x
2011-02-02 15:04:06 +00:00
add_trc_field ( " SU " , " CodiceAgente " , T_N , 6 , 3 ) ; //x
2010-10-26 15:46:30 +00:00
add_trc_field ( " SU " , " NonUsato " , T_X , 9 , 6 ) ;
add_trc_field ( " SU " , " Targa " , T_X , 15 , 8 ) ;
add_trc_field ( " SU " , " nDDT " , T_N , 23 , 5 ) ;
add_trc_field ( " SU " , " nFATT " , T_N , 28 , 5 ) ;
add_trc_field ( " SU " , " nBOLLA " , T_N , 33 , 5 ) ;
2011-02-02 15:04:06 +00:00
add_trc_field ( " SU " , " NomeAgente " , T_X , 38 , 30 ) ; //x
2010-10-26 15:46:30 +00:00
//Tipo record TF
//--------------
add_trc_field ( " TF " , " TipoRecord " , T_X , 1 , 2 ) ; //x
add_trc_field ( " TF " , " CodiceTerminale " , T_N , 3 , 3 ) ; //x
add_trc_field ( " TF " , DOC_NDOC , T_N , 6 , 5 ) ; //x
add_trc_field ( " TF " , DOC_DATADOC , T_X , 11 , 6 ) ; //x
add_trc_field ( " TF " , DOC_TIPODOC , T_X , 17 , 1 ) ; //x
add_trc_field ( " TF " , DOC_CODCF , T_X , 18 , 6 ) ; //x
add_trc_field ( " TF " , DOC_CODCFFATT , T_X , 24 , 6 ) ; //x
add_trc_field ( " TF " , " ImponibileLordo " , T_Nv2N , 30 , 8 ) ; // campi seguenti da righe doc
add_trc_field ( " TF " , " ScontoFattura " , T_2Nv2N , 38 , 4 ) ;
add_trc_field ( " TF " , " ImponibileDoc " , T_Nv2N , 42 , 8 ) ;
add_trc_field ( " TF " , " TotaleDoc " , T_Nv2N , 50 , 8 ) ;
add_trc_field ( " TF " , " ScontoTotale " , T_Nv2N , 58 , 8 ) ;
add_trc_field ( " TF " , " ImponibileOmaggi " , T_Nv2N , 66 , 8 ) ;
add_trc_field ( " TF " , " ImponibileSost " , T_Nv2N , 74 , 8 ) ;
add_trc_field ( " TF " , " Incasso " , T_Nv2N , 82 , 8 ) ; //forse IMPPAGATO ?
add_trc_field ( " TF " , DOC_CODPAG , T_X , 90 , 2 ) ; //x
add_trc_field ( " TF " , DOC_DATAPART , T_X , 92 , 6 ) ; //x
add_trc_field ( " TF " , " Iva1 " , T_N , 98 , 2 ) ; //anche questi da righe doc
add_trc_field ( " TF " , " Imponibile1 " , T_Nv2N , 100 , 8 ) ;
add_trc_field ( " TF " , " Imposta1 " , T_Nv2N , 108 , 7 ) ;
add_trc_field ( " TF " , " Iva2 " , T_N , 115 , 2 ) ;
add_trc_field ( " TF " , " Imponibile2 " , T_Nv2N , 117 , 8 ) ;
add_trc_field ( " TF " , " Imposta2 " , T_Nv2N , 125 , 7 ) ;
add_trc_field ( " TF " , " Iva3 " , T_N , 132 , 2 ) ;
add_trc_field ( " TF " , " Imponibile3 " , T_Nv2N , 134 , 8 ) ;
add_trc_field ( " TF " , " Imposta3 " , T_Nv2N , 142 , 7 ) ;
add_trc_field ( " TF " , " Iva4 " , T_N , 149 , 2 ) ;
add_trc_field ( " TF " , " Imponibile4 " , T_Nv2N , 151 , 8 ) ;
add_trc_field ( " TF " , " Imposta4 " , T_Nv2N , 159 , 7 ) ;
add_trc_field ( " TF " , " CodcliGiro3 " , T_X , 166 , 6 ) ;
add_trc_field ( " TF " , " IvaOmag1 " , T_N , 172 , 2 ) ;
add_trc_field ( " TF " , " ImponibileOmag1 " , T_Nv2N , 174 , 6 ) ;
add_trc_field ( " TF " , " ImpostaOmag1 " , T_Nv2N , 180 , 5 ) ;
add_trc_field ( " TF " , " IvaOmag2 " , T_N , 185 , 2 ) ;
add_trc_field ( " TF " , " ImponibileOmag2 " , T_Nv2N , 187 , 6 ) ;
add_trc_field ( " TF " , " ImpostaOmag2 " , T_Nv2N , 193 , 5 ) ;
add_trc_field ( " TF " , " DataEmissione " , T_X , 198 , 6 ) ;
add_trc_field ( " TF " , " PagamentoCarta " , T_X , 204 , 1 ) ;
//Tipo record RF
//--------------
add_trc_field ( " RF " , " TipoRecord " , T_X , 1 , 2 ) ; //x
add_trc_field ( " RF " , " CodiceTerminale " , T_N , 3 , 3 ) ; //x
add_trc_field ( " RF " , RDOC_NDOC , T_N , 6 , 5 ) ; //x
add_trc_field ( " RF " , DOC_DATADOC , T_X , 11 , 6 ) ; //x testata
add_trc_field ( " RF " , DOC_CODCF , T_X , 17 , 6 ) ; //x testata
add_trc_field ( " RF " , DOC_CODCFFATT , T_X , 23 , 6 ) ; //x testata
add_trc_field ( " RF " , DOC_TIPODOC , T_X , 29 , 1 ) ; //x testata
add_trc_field ( " RF " , RDOC_CODART , T_X , 30 , 5 ) ; //x
add_trc_field ( " RF " , " TipoCessione " , T_X , 35 , 1 ) ;
add_trc_field ( " RF " , " Qta[int] " , T_N , 36 , 5 ) ; //x
add_trc_field ( " RF " , " Qta[dec] " , T_N , 41 , 2 ) ; //x
add_trc_field ( " RF " , " Sconto1 " , T_2Nv2N , 43 , 4 ) ;
add_trc_field ( " RF " , " Sconto2 " , T_2Nv2N , 47 , 4 ) ;
add_trc_field ( " RF " , " Sconto3 " , T_2Nv2N , 51 , 4 ) ;
add_trc_field ( " RF " , " ScontoLibero " , T_2Nv2N , 55 , 4 ) ;
add_trc_field ( " RF " , RDOC_PREZZO , T_Nv3N , 59 , 7 ) ; //x forse PREZZOL ?
add_trc_field ( " RF " , " TotaleRiga " , T_Nv3N , 66 , 8 ) ;
add_trc_field ( " RF " , " TotaleSconto " , T_Nv3N , 74 , 8 ) ;
add_trc_field ( " RF " , " AliquotaIva " , T_N , 82 , 2 ) ; //noi abbiamo il codice
add_trc_field ( " RF " , RDOC_UMQTA , T_X , 84 , 2 ) ; //x
add_trc_field ( " RF " , " PrezzoScontato " , T_Nv3N , 86 , 7 ) ;
add_trc_field ( " RF " , " Fascia " , T_X , 93 , 1 ) ;
add_trc_field ( " RF " , " ScontoFascia " , T_2N , 94 , 2 ) ;
add_trc_field ( " RF " , " NonUsato " , T_N , 96 , 2 ) ;
add_trc_field ( " RF " , " CodcliGiro3 " , T_X , 98 , 6 ) ;
add_trc_field ( " RF " , " CodiceLotto " , T_X , 104 , 10 ) ; //noi lo leghiamo all'articolo
//Tipo record SI
//--------------
add_trc_field ( " SI " , " TipoRecord " , T_X , 1 , 2 ) ; //x
add_trc_field ( " SI " , " CodiceTerminale " , T_N , 3 , 3 ) ; //x
add_trc_field ( " SI " , " CodiceCliente " , T_X , 6 , 6 ) ;
add_trc_field ( " SI " , " NumeroFattura " , T_X , 12 , 12 ) ;
add_trc_field ( " SI " , " DataFattura " , T_X , 24 , 6 ) ;
add_trc_field ( " SI " , " NonUsato " , T_N , 30 , 9 ) ;
add_trc_field ( " SI " , " ImportoIncassato " , T_Nv2N , 39 , 9 ) ;
add_trc_field ( " SI " , " DataIncasso " , T_X , 48 , 6 ) ;
add_trc_field ( " SI " , " Partita " , T_X , 54 , 15 ) ;
add_trc_field ( " SI " , " TipoDocumento " , T_X , 69 , 1 ) ;
add_trc_field ( " SI " , " DataEmissione " , T_X , 70 , 6 ) ;
add_trc_field ( " SI " , " PagamentoCarta " , T_X , 76 , 1 ) ;
//Tipo record BR
//--------------
add_trc_field ( " BR " , " TipoRecord " , T_X , 1 , 2 ) ; //x
add_trc_field ( " BR " , " CodiceTerminale " , T_N , 3 , 3 ) ; //x
add_trc_field ( " BR " , " NumeroRiga " , T_N , 6 , 3 ) ;
add_trc_field ( " BR " , " NumeroDoc " , T_N , 9 , 5 ) ;
add_trc_field ( " BR " , " DataMov " , T_X , 14 , 6 ) ;
add_trc_field ( " BR " , " CodiceArticolo " , T_X , 20 , 5 ) ;
add_trc_field ( " BR " , " Qta[int] " , T_N , 25 , 5 ) ;
add_trc_field ( " BR " , " Qta[dec] " , T_N , 30 , 2 ) ;
add_trc_field ( " BR " , " Mittente " , T_N , 32 , 3 ) ;
add_trc_field ( " BR " , " Destinatario " , T_N , 35 , 3 ) ;
add_trc_field ( " BR " , " CausaleMov " , T_N , 38 , 2 ) ;
add_trc_field ( " BR " , " CodiceLotto " , T_X , 40 , 10 ) ;
//Tipo record VC
//--------------
add_trc_field ( " VC " , " TipoRecord " , T_X , 1 , 2 ) ; //x
add_trc_field ( " VC " , " CodiceTerminale " , T_N , 3 , 3 ) ; //x
2011-02-01 11:40:26 +00:00
add_trc_field ( " VC " , " CodiceCliente " , T_X , 6 , 6 ) ; //x
add_trc_field ( " VC " , " RagioneSociale " , T_X , 12 , 34 ) ; //x
add_trc_field ( " VC " , " Indirizzo " , T_X , 46 , 34 ) ; //x
2010-10-26 15:46:30 +00:00
add_trc_field ( " VC " , " Localita " , T_X , 80 , 20 ) ; //x attenzione che potrebbe essere il com_dencom
2011-02-01 11:40:26 +00:00
add_trc_field ( " VC " , " CAP " , T_X , 100 , 5 ) ; //x
2010-10-26 15:46:30 +00:00
add_trc_field ( " VC " , " Provincia " , T_X , 105 , 2 ) ; //x da questo e da dencom ricaviamo il codcom
2011-02-01 11:40:26 +00:00
add_trc_field ( " VC " , " PartitaIVA " , T_X , 107 , 16 ) ; //x
add_trc_field ( " VC " , " CodicePagamento " , T_X , 123 , 2 ) ; //x
add_trc_field ( " VC " , " CodiceListino " , T_X , 125 , 3 ) ;
add_trc_field ( " VC " , " TipoDocumento " , T_X , 128 , 1 ) ;
add_trc_field ( " VC " , " CodiceFiscale " , T_X , 129 , 16 ) ; //x
2010-10-26 15:46:30 +00:00
2011-01-27 15:16:23 +00:00
//Tipo record RC
//--------------
add_trc_field ( " RC " , " TipoRecord " , T_X , 1 , 2 ) ; //x
add_trc_field ( " RC " , " CodiceTerminale " , T_N , 3 , 3 ) ; //x
add_trc_field ( " RC " , " CodiceArticolo " , T_X , 6 , 5 ) ; //x
add_trc_field ( " RC " , " Quantita " , T_Nv2N , 11 , 7 ) ; //x
add_trc_field ( " RC " , " DataCarico " , T_X , 18 , 6 ) ; //x
2010-10-26 15:46:30 +00:00
TText_recordset : : load_file ( filename ) ;
}
2010-10-11 14:40:52 +00:00
///////////////////////////////////////////////////////////
2011-02-01 17:01:21 +00:00
// TAutomask : maschera principale
2010-10-11 14:40:52 +00:00
///////////////////////////////////////////////////////////
class TUpload2Campo_mask : public TAutomask
{
protected :
virtual bool on_field_event ( TOperable_field & o , TField_event e , long jolly ) ;
public :
TUpload2Campo_mask ( ) ;
} ;
bool TUpload2Campo_mask : : on_field_event ( TOperable_field & o , TField_event e , long jolly )
{
return true ;
}
TUpload2Campo_mask : : TUpload2Campo_mask ( ) : TAutomask ( " ha1300a " )
{
TConfig config ( CONFIG_DITTA , " ha " ) ;
const TString & path = config . get ( " InputPath " ) ;
set ( F_PATH , path ) ;
}
2011-02-01 17:01:21 +00:00
///////////////////////////////////////////////////////////
// TAutomask : maschera secondaria per inserimento nuovo cliente
///////////////////////////////////////////////////////////
class TUpload2Campo_newcli_mask : public TAutomask
{
protected :
virtual bool on_field_event ( TOperable_field & o , TField_event e , long jolly ) ;
public :
TUpload2Campo_newcli_mask ( ) ;
} ;
bool TUpload2Campo_newcli_mask : : on_field_event ( TOperable_field & o , TField_event e , long jolly )
{
return true ;
}
TUpload2Campo_newcli_mask : : TUpload2Campo_newcli_mask ( ) : TAutomask ( " ha1301a " )
{
}
2010-10-11 14:40:52 +00:00
///////////////////////////////////////
// TSkeleton_application
///////////////////////////////////////
class TUpload2Campo : public TSkeleton_application
{
TFilename _intput_dir ;
2010-10-26 15:46:30 +00:00
bool _can_write ;
2011-02-01 11:40:26 +00:00
TAssoc_array _nuovi_clienti ;
2010-10-11 14:40:52 +00:00
protected :
2011-01-26 16:56:02 +00:00
//metodi di basso livello
const TString & check_agente ( TString & codice_terminale , TLog_report & log ) ;
const TString & check_articolo ( TString & codart , TLog_report & log ) ;
2011-02-02 15:04:06 +00:00
long check_cliente ( const TString & str_codcf , TLog_report & log ) ;
2011-01-27 15:16:23 +00:00
void check_magazzino ( const TString & codmag_age , TLog_report & log ) ;
void check_causale ( TString & codcaus , TLog_report & log ) ;
2011-02-03 16:55:44 +00:00
bool genera_incasso ( TPartita & game , int nriga , int nrata , const TMovimentoPN & mov , TLog_report & log ) const ;
2011-01-26 16:56:02 +00:00
2011-02-02 15:04:06 +00:00
//metodi di alto livello
2010-10-11 14:40:52 +00:00
void elabora_SU ( THardy_upload_recordset & recset , TLog_report & log ) ;
2010-10-14 13:15:43 +00:00
void elabora_BR ( THardy_upload_recordset & recset , TLog_report & log ) ;
void elabora_VC ( THardy_upload_recordset & recset , TLog_report & log ) ;
2010-10-26 15:46:30 +00:00
void elabora_TF ( THardy_upload_recordset & recset , TLog_report & log ) ;
2010-10-27 10:53:47 +00:00
void elabora_SI ( THardy_upload_recordset & recset , TLog_report & log ) ;
2011-01-27 15:16:23 +00:00
void elabora_RC ( THardy_upload_recordset & recset , TLog_report & log ) ;
2010-10-11 14:40:52 +00:00
void elabora ( const TMask & mask ) ;
public :
virtual void main_loop ( ) ;
virtual bool create ( ) ;
} ;
2011-02-02 15:04:06 +00:00
/////////////////////////////////////////////////////////////////////////////////////////////////
// Metodi di basso livello
/////////////////////////////////////////////////////////////////////////////////////////////////
//controlla se il terminale corrisponde ad un agente registrato e restituisce l'agente
2011-01-26 16:56:02 +00:00
const TString & TUpload2Campo : : check_agente ( TString & codice_terminale , TLog_report & log )
{
codice_terminale . right_just ( 3 , ' 0 ' ) ;
TString8 codice_agente = codice_terminale ;
codice_agente . right_just ( 5 , ' 0 ' ) ;
const TRectype & rec_age = cache ( ) . get ( LF_AGENTI , codice_agente ) ;
const TString & codage_campo = rec_age . get ( AGE_CODAGE ) ;
if ( codage_campo ! = codice_agente )
{
_can_write = false ;
TString msg ;
msg < < " Codice agente " < < codice_agente < < " da terminale: sconosciuto " ;
log . log ( 2 , msg ) ;
}
return codage_campo ;
}
2011-02-02 15:04:06 +00:00
//controlla che l'articolo esista su Campo
2011-01-26 16:56:02 +00:00
const TString & TUpload2Campo : : check_articolo ( TString & codart , TLog_report & log )
{
codart . trim ( ) ;
const TRectype & rec_anamag = cache ( ) . get ( LF_ANAMAG , codart ) ;
const TString & articolo_campo = rec_anamag . get ( ANAMAG_CODART ) ;
if ( articolo_campo ! = codart )
{
_can_write = false ;
TString msg ;
msg < < " Codice articolo " < < codart < < " sconosciuto su Campo " ;
log . log ( 2 , msg ) ;
}
return rec_anamag . get ( ANAMAG_DESCR ) ;
}
2010-10-11 14:40:52 +00:00
2011-02-02 15:04:06 +00:00
//controlla l'esistenza del magazzino su Campo
2011-01-27 15:16:23 +00:00
void TUpload2Campo : : check_magazzino ( const TString & codmag_age , TLog_report & log )
{
const TString & codmag_campo = cache ( ) . get ( " MAG " , codmag_age , " CODTAB " ) ;
if ( codmag_campo ! = codmag_age )
{
_can_write = false ;
TString msg ;
msg < < " Codice magazzino " < < codmag_age < < " sconosciuto su Campo " ;
log . log ( 2 , msg ) ;
}
}
2011-02-02 15:04:06 +00:00
//controlla il cliente;se nuovo controlla che sia gi<67> stato importato nella lista dei nuovi clienti,se..
//esistente controlla che ci sia negli archivi Campo
long TUpload2Campo : : check_cliente ( const TString & str_codcf , TLog_report & log )
{
long codcf = 0L ;
const bool new_cliente = str_codcf . find ( ' * ' ) > = 0 ;
if ( new_cliente )
{
const real * ptr = ( const real * ) _nuovi_clienti . objptr ( str_codcf ) ;
codcf = ptr ? ptr - > integer ( ) : 0L ;
}
else
{
TToken_string key_clifo ;
key_clifo . add ( " C " ) ;
key_clifo . add ( str_codcf ) ;
codcf = atol ( cache ( ) . get ( LF_CLIFO , key_clifo , CLI_CODCF ) ) ;
}
//controllo effettuabile solo se il cliente <20> gi<67> presente (vecchio o nuovo aggiunto con la importa_VC se era _can_write)
if ( codcf < = 0 )
{
_can_write = false ;
TString msg ;
msg < < " Codice cliente " < < str_codcf < < " sconosciuto " ;
log . log ( 2 , msg ) ;
}
return codcf ;
}
2011-02-03 16:55:44 +00:00
//aggiorna una partita con una nuova riga che riguarda l'incasso
bool TUpload2Campo : : genera_incasso ( TPartita & game , int nriga , int nrata ,
const TMovimentoPN & mov , TLog_report & log ) const
{
TString msg ;
msg . format ( FR ( " %d della riga %d della partita %d/%s " ) ,
nrata , nriga , game . anno ( ) , ( const char * ) game . numero ( ) ) ;
if ( ! game . esiste ( nriga , nrata ) ) // Non si sa mai col saldaconto!
{
msg . insert ( TR ( " Non esiste la rata " ) ) ;
log . log ( 1 , msg ) ;
//return false;
nriga = nrata = game . UNASSIGNED ;
}
const TRectype & head = mov . curr ( ) ;
// Creo una riga di partita di tipo pagamento e ci copio i dati della testata del movimento
TRiga_partite & riga = game . new_row ( ) ;
const int nrigp = riga . get_int ( PART_NRIGA ) ;
riga . put ( PART_TIPOMOV , tm_pagamento ) ;
riga . put ( PART_SEZ , game . conto ( ) . tipo ( ) = = ' F ' ? ' D ' : ' A ' ) ;
riga . put ( PART_NREG , head . get ( MOV_NUMREG ) ) ;
riga . put ( PART_NUMRIG , 1 ) ;
riga . put ( PART_DATAREG , head . get ( MOV_DATAREG ) ) ;
riga . put ( PART_DATAPAG , head . get ( MOV_DATACOMP ) ) ;
riga . put ( PART_CODCAUS , head . get ( MOV_CODCAUS ) ) ;
riga . put ( PART_NUMDOC , head . get ( MOV_NUMDOC ) ) ;
riga . put ( PART_DATADOC , head . get ( MOV_DATADOC ) ) ;
riga . put ( PART_DESCR , head . get ( MOV_DESCR ) ) ;
// Creo una nuova riga di pagamento assegnado il flag di saldo
TRectype new_pag ( LF_PAGSCA ) ;
if ( nriga > 0 & & nriga < game . UNASSIGNED )
{
TRiga_scadenze & scad = game . rata ( nriga , nrata ) ;
new_pag = scad . new_row ( nrigp ) ; // Creo nuova riga e la duplico
}
else //se la partita non esiste si inventa il pagamento
new_pag = game . pagamento ( nriga , nrata , nrigp ) ;
new_pag . put ( PAGSCA_ACCSAL , ' A ' ) ;
new_pag . put ( PART_IMPORTO , head . get_real ( MOV_TOTDOC ) ) ;
const TValuta valuta ( head ) ;
game . modifica_pagamento ( new_pag , valuta , true ) ;
return true ;
}
2011-02-02 15:04:06 +00:00
/////////////////////////////////////////////////////////////////////////////////////////////////
// Metodi di alto livello
/////////////////////////////////////////////////////////////////////////////////////////////////
2011-02-01 13:51:55 +00:00
//SU non <20> un tipo record di qualche utilit<69>
2010-10-11 14:40:52 +00:00
void TUpload2Campo : : elabora_SU ( THardy_upload_recordset & recset , TLog_report & log )
{
2010-10-14 13:15:43 +00:00
}
2011-02-01 13:51:55 +00:00
//elabora clienti e loro variazioni; viene comunque eseguita per prima perch<63> i record VC vengono messi all'inizio
2010-10-14 13:15:43 +00:00
void TUpload2Campo : : elabora_VC ( THardy_upload_recordset & recset , TLog_report & log )
{
2011-02-01 11:40:26 +00:00
//dati dal recordset di upload
TString4 codice_terminale = recset . get ( " CodiceTerminale " ) . as_string ( ) ;
2011-02-02 15:04:06 +00:00
const TString8 codice_agente = check_agente ( codice_terminale , log ) ;
2011-02-01 11:40:26 +00:00
long codcf = recset . get ( " CodiceCliente " ) . as_int ( ) ;
TLocalisamfile file_clifo ( LF_CLIFO ) ;
//se il codice contiene un '*' -> il cliente <20> nuovo e va aggiunto alla lista di Campo
//se invece il cliente ha un codice normale -> <20> un aggiornamento dei suoi dati -> controlla che esista davvero
if ( codcf < = 0 )
{
2011-02-01 17:01:21 +00:00
//questa <20> un surrogato della get_next_cli considerando che vanno riempiti i clienti della serie 200000..
//..prima di intaccare eventuali clienti della serie 300000
2011-02-01 11:40:26 +00:00
file_clifo . zero ( ) ;
file_clifo . put ( CLI_TIPOCF , ' C ' ) ;
2011-02-01 17:01:21 +00:00
file_clifo . put ( CLI_CODCF , 300000 ) ;
int err = file_clifo . read ( _isgteq ) ;
codcf = 1 ;
if ( err = = NOERR )
{
file_clifo . prev ( ) ;
2011-02-01 11:40:26 +00:00
codcf + = file_clifo . get_long ( CLI_CODCF ) ;
2011-02-01 17:01:21 +00:00
}
//La finestra propositiva per ora non viene usata!
//finestra propositiva del nuovo codcf; viene proposto il codcf calcolato come ultimo + 1, ma l'utonto potrebbe..
//..decidere di andare a riempire un qualche 'buco' precedentemente alla cazzo creato!!
/* TUpload2Campo_newcli_mask newcli_mask;
newcli_mask . set ( F_CODCF , codcf ) ;
FOR_EACH_MASK_FIELD ( newcli_mask , f , fld )
{
const TFieldref * fr = fld - > field ( ) ;
if ( fr ! = NULL )
fld - > set ( recset . get ( fr - > name ( ) ) . as_string ( ) ) ;
}
if ( newcli_mask . run ( ) = = K_ENTER )
{ */
2011-02-01 11:40:26 +00:00
2011-02-01 17:01:21 +00:00
//aggiunge il cliente nuovo ricodificato all'array dei nuovi clienti in modo da ricordarsi chi era..
//..quando loritrover<65> nei record di tipo TF,RF,SI; lo in ogni modo perch<63> serve anche in caso di simulazione!
const TString & str_new_codcf = recset . get ( " CodiceCliente " ) . as_string ( ) ;
_nuovi_clienti . add ( str_new_codcf , real ( codcf ) ) ;
2011-02-01 11:40:26 +00:00
file_clifo . zero ( ) ;
file_clifo . put ( CLI_TIPOCF , ' C ' ) ;
file_clifo . put ( CLI_CODCF , codcf ) ;
2011-02-01 13:51:55 +00:00
2011-02-01 17:01:21 +00:00
//ATTENZIONE!! In caso di simulazione ci si ferma qui perch<63> non si potrebbe inserire alcun dato, visto che..
//_can_write <20> comunque falso!
if ( _can_write )
file_clifo . write ( ) ;
else
{
TString msg ;
msg < < " Nuovo cliente con codice provvisorio: " < < str_new_codcf < < " da registrare in Campo con il codice: " < < codcf ;
log . log ( 0 , msg ) ;
return ;
}
/*}
else
{
_can_write = false ;
TString msg ;
msg < < " Annullata importazione cliente " < < codcf ;
log . log ( 2 , msg ) ;
codcf = 0L ;
} */
2011-02-03 16:55:44 +00:00
} //if(codcf<=0)...
2011-02-01 11:40:26 +00:00
2011-02-01 17:01:21 +00:00
2011-02-01 11:40:26 +00:00
//il cliente, se non nuovo, deve esistere!
file_clifo . put ( CLI_TIPOCF , ' C ' ) ;
file_clifo . put ( CLI_CODCF , codcf ) ;
int err = file_clifo . read ( ) ;
//se non esiste non scrive ma continua
if ( err ! = NOERR )
{
_can_write = false ;
TString msg ;
msg < < " Impossibile aggiornare il cliente " < < codcf < < " . File clifo. " ;
log . log ( 2 , msg ) ;
}
//campi clifo
const TString & ragsoc = recset . get ( " RagioneSociale " ) . as_string ( ) ;
file_clifo . put ( CLI_RAGSOC , ragsoc ) ;
const TString & indcf = recset . get ( " Indirizzo " ) . as_string ( ) ;
file_clifo . put ( CLI_INDCF , indcf ) ;
const TString & localita = recset . get ( " Localita " ) . as_string ( ) ;
file_clifo . put ( CLI_LOCCF , localita ) ;
const TString & cap = recset . get ( " CAP " ) . as_string ( ) ;
file_clifo . put ( CLI_CAPCF , cap ) ;
2011-02-01 17:01:21 +00:00
//modo semi-intelligente per cercare il comune dato il cap e la localit<69>
const TString & codcom = cap2comune ( cap , localita ) ;
file_clifo . put ( CLI_COMCF , codcom ) ;
2011-02-01 11:40:26 +00:00
//la provincia non serve perch<63> si passa dal codice del comune
//const TString& provincia = recset.get("Provincia").as_string();
const TString & piva = recset . get ( " PartitaIVA " ) . as_string ( ) ;
file_clifo . put ( CLI_PAIV , piva ) ;
const TString & codpag = recset . get ( " CodicePagamento " ) . as_string ( ) ;
file_clifo . put ( CLI_CODPAG , codpag ) ;
const TString & cofi = recset . get ( " CodiceFiscale " ) . as_string ( ) ;
file_clifo . put ( CLI_COFI , cofi ) ;
//campi cfven
2011-02-01 17:01:21 +00:00
//prima cerca se il record di questo c+codcf esiste gi<67> sul cfven
2011-02-01 11:40:26 +00:00
TLocalisamfile file_cfven ( LF_CFVEN ) ;
file_cfven . put ( CFV_TIPOCF , ' C ' ) ;
file_cfven . put ( CFV_CODCF , codcf ) ;
err = file_cfven . read ( ) ;
2011-02-01 17:01:21 +00:00
//se non c'<27> lo crea!
if ( err ! = NOERR )
{
file_cfven . zero ( ) ;
file_cfven . put ( CFV_TIPOCF , ' C ' ) ;
file_cfven . put ( CFV_CODCF , codcf ) ;
2011-02-03 12:12:50 +00:00
if ( _can_write )
err = file_cfven . write ( ) ;
else
err = NOERR ;
2011-02-01 17:01:21 +00:00
}
//se la creazione non va a buon fine avverte
2011-02-01 11:40:26 +00:00
if ( err ! = NOERR )
{
_can_write = false ;
TString msg ;
msg < < " Impossibile aggiornare il cliente " < < ragsoc < < " . File cfven. " ;
log . log ( 2 , msg ) ;
}
file_cfven . put ( CFV_CODAG , codice_agente ) ;
const TString & codlist = recset . get ( " CodiceListino " ) . as_string ( ) ;
file_cfven . put ( CFV_CODLIST , codlist ) ;
2011-02-03 12:12:50 +00:00
//incredibilmente arriva in fondo
2010-10-14 13:15:43 +00:00
TString msg ;
2011-02-01 11:40:26 +00:00
msg < < " Cliente: " < < codcf < < " Terminale: " < < codice_terminale ;
//se pu<70> scrivere...
if ( _can_write )
{
//alla fine della fiera salva il cliente e il cfven
2011-02-03 12:12:50 +00:00
err = file_clifo . rewrite ( ) ;
if ( err = = NOERR )
err = file_cfven . rewrite ( ) ;
2011-02-01 11:40:26 +00:00
if ( err = = NOERR )
{
msg . insert ( " Registrato cliente: " , 0 ) ;
log . log ( 0 , msg ) ;
}
else
{
msg . insert ( " Impossibile registrare cliente: " , 0 ) ;
log . log ( 2 , msg ) ;
}
}
2011-02-03 16:55:44 +00:00
log . log ( 0 , " " ) ;
2010-10-11 14:40:52 +00:00
}
2011-02-02 15:04:06 +00:00
//movimenti di incasso
2010-10-27 10:53:47 +00:00
void TUpload2Campo : : elabora_SI ( THardy_upload_recordset & recset , TLog_report & log )
{
2011-02-02 15:04:06 +00:00
//dati dal recordset di upload (con i relativi controlli)
TString4 codice_terminale = recset . get ( " CodiceTerminale " ) . as_string ( ) ;
2011-02-03 12:12:50 +00:00
const TString8 codice_agente = check_agente ( codice_terminale , log ) ;
2011-02-02 15:04:06 +00:00
const TString & str_codcf = recset . get ( " CodiceCliente " ) . as_string ( ) ;
long codcf = check_cliente ( str_codcf , log ) ;
//crea un movimento contabile pescando i dati dal recordset (e inventandosene qualcuno!)
//testata
2011-02-03 16:55:44 +00:00
const TString & str_dataincasso = recset . get ( " DataIncasso " ) . as_string ( ) ;
const TDate data_incasso = upload_format_date6 ( str_dataincasso ) ;
2011-02-02 15:04:06 +00:00
const TDate datareg = data_incasso ;
const TDate datacomp = data_incasso ;
TEsercizi_contabili esc ;
const int annoes = esc . date2esc ( data_incasso ) ;
2011-02-03 12:12:50 +00:00
const int anno = datareg . year ( ) ;
2011-02-02 15:04:06 +00:00
const long numdoc = recset . get ( " NumeroFattura " ) . as_int ( ) ;
2011-02-03 16:55:44 +00:00
const TString & str_datadoc = recset . get ( " DataFattura " ) . as_string ( ) ;
const TDate datadoc = upload_format_date6 ( str_datadoc ) ;
2011-02-02 15:04:06 +00:00
const TString4 tipodoc = recset . get ( " TipoDocumento " ) . as_string ( ) ;
const real incasso = recset . get ( " ImportoIncassato " ) . as_real ( ) / CENTO ;
2011-02-03 16:55:44 +00:00
//il codice partita su Campo <20> lungo 7 mentre i terminalini lo possono inviare lungo 15 (cazzi loro..)
const TString8 numpart = recset . get ( " Partita " ) . as_string ( ) . left ( 7 ) ;
2011-02-02 15:04:06 +00:00
TConfig config ( CONFIG_DITTA , " ha " ) ;
const TString & codcaus = config . get ( " InpCausale " ) ;
2011-02-03 12:12:50 +00:00
const TCausale caus ( codcaus , anno ) ;
2011-02-02 15:04:06 +00:00
TMovimentoPN mov ;
TRectype & head = mov . curr ( ) ;
head . put ( MOV_CODCAUS , codcaus ) ;
head . put ( MOV_DATAREG , datareg ) ;
head . put ( MOV_DATACOMP , datacomp ) ;
TString descr ;
descr < < " Incasso. Cliente: " < < codcf < < " - Agente: " < < codice_agente ;
head . put ( MOV_DESCR , descr ) ;
head . put ( MOV_ANNOES , annoes ) ;
head . put ( MOV_DATADOC , datadoc ) ;
head . put ( MOV_NUMDOC , numdoc ) ;
head . put ( MOV_TIPODOC , tipodoc ) ;
2011-02-03 12:12:50 +00:00
head . put ( MOV_TIPOMOV , caus . tipomov ( ) ) ;
head . put ( MOV_ANNOIVA , anno ) ;
head . put ( MOV_TOTDOC , incasso ) ;
long numreg = 999999L ;
2011-02-02 15:04:06 +00:00
2011-02-03 16:55:44 +00:00
TString msg ;
msg < < " movimento di incasso. Cliente: " < < codcf < < " - Agente: " < < codice_agente < < " - Data: " < < data_incasso ;
2011-02-02 15:04:06 +00:00
if ( _can_write )
{
2011-02-03 12:12:50 +00:00
if ( mov . write ( ) ! = NOERR )
{
_can_write = false ;
msg . insert ( " Impossibile registrare " ) ;
log . log ( 2 , msg ) ;
}
else
{
msg . insert ( " Registrato " ) ;
log . log ( 0 , msg ) ;
numreg = head . get_long ( MOV_NUMREG ) ;
}
2011-02-02 15:04:06 +00:00
}
2011-02-03 16:55:44 +00:00
else
{
msg . insert ( " Controllato " ) ;
log . log ( 0 , msg ) ;
}
2011-02-02 15:04:06 +00:00
2011-02-03 12:12:50 +00:00
2011-02-02 15:04:06 +00:00
//righe
2011-02-03 12:12:50 +00:00
//panegirico sui conti
//conto cliente
TToken_string key_clifo ;
key_clifo . add ( ' C ' ) ;
key_clifo . add ( codcf ) ;
const TRectype & rec_codcf = cache ( ) . get ( LF_CLIFO , key_clifo ) ;
int gr_cli = rec_codcf . get_int ( CLI_GRUPPO ) ;
int co_cli = rec_codcf . get_int ( CLI_CONTO ) ;
TBill zio_clifo ( gr_cli , co_cli , codcf , ' C ' ) ;
//se il cliente non ha un suo conto, prova con il primo della causale incassi in configurazione
if ( zio_clifo . conto ( ) < = 0 )
{
2011-02-03 16:55:44 +00:00
caus . bill ( 1 , zio_clifo ) ;
2011-02-03 12:12:50 +00:00
gr_cli = zio_clifo . gruppo ( ) ;
co_cli = zio_clifo . conto ( ) ;
zio_clifo . set ( gr_cli , co_cli , codcf , ' C ' ) ;
}
//conto agente
const TRectype & rec_agente = cache ( ) . get ( LF_AGENTI , codice_agente ) ;
int gr_age = rec_agente . get_int ( AGE_GRUPPO ) ;
int co_age = rec_agente . get_int ( AGE_CONTO ) ;
long sott_age = rec_agente . get_long ( AGE_SOTTOCONTO ) ;
TBill zio_agente ( gr_age , co_age , sott_age ) ;
//se l'agente non ha un suo conto, prova con il secondo della causale incassi in configurazione
if ( zio_agente . conto ( ) < = 0 )
{
2011-02-03 16:55:44 +00:00
caus . bill ( 2 , zio_agente ) ;
2011-02-03 12:12:50 +00:00
gr_age = zio_agente . gruppo ( ) ;
co_age = zio_agente . conto ( ) ;
sott_age = zio_agente . sottoconto ( ) ;
zio_agente . set ( gr_age , co_age , sott_age ) ;
}
2011-02-02 15:04:06 +00:00
2011-02-03 12:12:50 +00:00
//creazione vera e propria delle righe
//riga 1: conto cliente
TRectype & new_rmov_cli = mov . cg ( - 1 ) ;
new_rmov_cli . put ( RMV_ROWTYPE , ' K ' ) ;
2011-02-03 16:55:44 +00:00
new_rmov_cli . put ( RMV_ANNOES , annoes ) ;
new_rmov_cli . put ( RMV_DATAREG , datareg ) ;
2011-02-03 12:12:50 +00:00
zio_clifo . put ( new_rmov_cli ) ;
2011-02-03 16:55:44 +00:00
const char sezione_cli = caus . sezione ( 1 ) ;
2011-02-03 12:12:50 +00:00
new_rmov_cli . put ( RMV_SEZIONE , sezione_cli ) ;
TString descr_rmv_cli ;
descr_rmv_cli < < " Incasso cliente " < < codcf ;
new_rmov_cli . put ( RMV_DESCR , descr_rmv_cli ) ;
zio_agente . put ( new_rmov_cli , true ) ; //conto di contropartita = conto agente
new_rmov_cli . put ( RMV_IMPORTO , incasso ) ;
//riga 2: conto agente
TRectype & new_rmov_age = mov . cg ( - 1 ) ;
new_rmov_age . put ( RMV_ROWTYPE , ' I ' ) ;
2011-02-03 16:55:44 +00:00
new_rmov_age . put ( RMV_ANNOES , annoes ) ;
new_rmov_age . put ( RMV_DATAREG , datareg ) ;
2011-02-03 12:12:50 +00:00
zio_agente . put ( new_rmov_age ) ;
2011-02-03 16:55:44 +00:00
const char sezione_age = caus . sezione ( 2 ) ;
2011-02-03 12:12:50 +00:00
new_rmov_age . put ( RMV_SEZIONE , sezione_age ) ;
TString descr_rmv_age ;
descr_rmv_age < < " Incasso agente " < < codice_agente ;
new_rmov_age . put ( RMV_DESCR , descr_rmv_age ) ;
zio_clifo . put ( new_rmov_age , true ) ; //conto di contropartita = conto cliente
new_rmov_age . put ( RMV_IMPORTO , incasso ) ;
//crea i pagamenti aggiornando anche la partita (qui si parr<72> la tua nobilitate!)
2011-02-03 16:55:44 +00:00
TPartita game ( zio_clifo , anno , numpart ) ;
const int nriga = game . prima_fattura ( ) ;
const int nrata = 1 ;
//metodo magicissimo per l'aggiornamento della partita con l'incasso
genera_incasso ( game , nriga , nrata , mov , log ) ;
2011-02-03 12:12:50 +00:00
2011-02-03 16:55:44 +00:00
//alla fine della fiera scrive (se pu<70> ) movimento e pagamento su partita
if ( _can_write )
{
int err = mov . rewrite ( ) ;
TString mov_msg ;
mov_msg < < " movimento di incasso n.reg.: " < < numreg ;
if ( err = = NOERR )
{
mov_msg . insert ( " Completato " ) ;
log . log ( 0 , mov_msg ) ;
game . write ( true ) ;
}
else
{
_can_write = false ;
mov_msg . insert ( " Impossibile completare " ) ;
log . log ( 2 , mov_msg ) ;
}
} //if(_can_write)...
log . log ( 0 , " " ) ;
2010-10-27 10:53:47 +00:00
}
2011-01-26 16:56:02 +00:00
void TUpload2Campo : : elabora_BR ( THardy_upload_recordset & recset , TLog_report & log )
2010-10-26 15:46:30 +00:00
{
2011-01-26 16:56:02 +00:00
//dati dal recordset di upload
2011-01-24 15:39:37 +00:00
TString4 codice_terminale = recset . get ( " CodiceTerminale " ) . as_string ( ) ;
2011-01-26 16:56:02 +00:00
const TString & codice_agente = check_agente ( codice_terminale , log ) ;
const TString8 cod_magazzino = cache ( ) . get ( LF_AGENTI , codice_agente , AGE_CODMAG ) ;
2011-01-27 15:16:23 +00:00
check_magazzino ( cod_magazzino , log ) ;
2011-01-26 16:56:02 +00:00
const long curr_movmag = recset . get ( " NumeroDoc " ) . as_int ( ) ;
const TString & str_data_mov = recset . get ( " DataMov " ) . as_string ( ) ;
const TDate data_mov = upload_format_date6 ( str_data_mov ) ;
const int anno = data_mov . year ( ) ;
TString descr ;
descr < < " Agente: " < < codice_terminale ;
//1) crea la testata
//movimento di magazzino da riempire
TMov_mag movmag ;
//const long numreg = atol(movmag.get_next_key());
//movmag.put(MOVMAG_NUMREG, numreg);
movmag . put ( MOVMAG_ANNOES , anno ) ;
movmag . put ( MOVMAG_DATAREG , data_mov ) ;
movmag . put ( MOVMAG_DATACOMP , data_mov ) ;
movmag . put ( MOVMAG_EXNUMDOC , curr_movmag ) ;
movmag . put ( MOVMAG_EXDATADOC , data_mov ) ;
movmag . put ( MOVMAG_DESCR , descr ) ;
2011-01-27 15:16:23 +00:00
//la causale va trascodificata con l'apposita tabella &CAU
const TString & caus_term = recset . get ( " CausaleMov " ) . as_string ( ) ;
const TString & codcaus = cache ( ) . get ( " &CAU " , caus_term , " S7 " ) ;
if ( codcaus . empty ( ) )
{
_can_write = false ;
TString msg ;
msg < < " Causale movimento " < < caus_term < < " non codificata " ;
log . log ( 2 , msg ) ;
}
movmag . put ( MOVMAG_CODCAUS , codcaus ) ;
2011-01-26 16:56:02 +00:00
bool go_on = true ;
// righe movimento di magazzino
//scansione delle righe documento su record BR
while ( go_on )
{
//2) crea le righe (legge tutti i record di tipo BR successivi finch<63> hanno lo stesso numero documento!)
2011-01-26 13:31:15 +00:00
2011-01-26 16:56:02 +00:00
//agginunge una nuova riga (solo merce, per quanto ne sappiamo)
TRectype & rmovmag = movmag . new_row ( ) ;
rmovmag . put ( RMOVMAG_CODMAG , cod_magazzino ) ;
TString8 codart = recset . get ( " CodiceArticolo " ) . as_string ( ) ;
check_articolo ( codart , log ) ;
rmovmag . put ( RMOVMAG_CODART , codart ) ;
TToken_string key_umart ;
key_umart . add ( codart ) ;
key_umart . add ( 1 ) ;
const TString & um = cache ( ) . get ( LF_UMART , key_umart , UMART_UM ) ;
rmovmag . put ( RMOVMAG_UM , um ) ;
const TString & lotto = recset . get ( " CodiceLotto " ) . as_string ( ) ;
rmovmag . put ( RMOVMAG_LIVGIAC , lotto ) ;
real qta = recset . get ( " Qta[int] " ) . as_real ( ) ;
qta + = recset . get ( " Qta[dec] " ) . as_real ( ) / CENTO ;
rmovmag . put ( RMOVMAG_QUANT , qta ) ;
//quando non trova un BR con lo stesso numero di movimento significa che le righe sono finite!
go_on = recset . move_next ( ) ;
2011-01-26 13:31:15 +00:00
2011-01-26 16:56:02 +00:00
if ( go_on & & ( recset . get ( " TipoRecord " ) . as_string ( ) ! = " BR " | | curr_movmag ! = recset . get ( " NumeroDoc " ) . as_int ( ) ) )
{
recset . move_prev ( ) ; //allora torna indietro di un record per riposizionarsi sull'ultimo non letto
go_on = false ;
}
2011-01-27 15:16:23 +00:00
} //while(go_on)...
2011-01-26 16:56:02 +00:00
//incredibilmente arriva in fondo
TString msg ;
msg < < " Doc.: " < < curr_movmag < < " Terminale: " < < codice_terminale ;
//se pu<70> scrivere...
if ( _can_write )
2010-10-26 15:46:30 +00:00
{
2011-01-26 16:56:02 +00:00
//alla fine della fiera salva il maggico movimento di magazzino
TLocalisamfile file_movmag ( LF_MOVMAG ) ;
int err = movmag . write ( file_movmag ) ;
if ( err = = NOERR )
{
msg . insert ( " Registrato mov. magazzino: " , 0 ) ;
log . log ( 0 , msg ) ;
}
else
{
msg . insert ( " Impossibile registrare mov. magazzino: " , 0 ) ;
log . log ( 2 , msg ) ;
}
2010-10-26 15:46:30 +00:00
}
2011-01-26 16:56:02 +00:00
else //..senn<6E> avverte e basta
{
msg . insert ( " Controllato mov. magazzino: " , 0 ) ;
log . log ( 0 , msg ) ;
}
log . log ( 0 , " " ) ;
}
2010-10-26 15:46:30 +00:00
2011-01-26 16:56:02 +00:00
void TUpload2Campo : : elabora_TF ( THardy_upload_recordset & recset , TLog_report & log )
{
2011-02-02 15:04:06 +00:00
char rec_tipodoc = recset . get ( DOC_TIPODOC ) . as_string ( ) [ 0 ] ;
//i documenti di vendita annullati vanno ignorati
2011-02-03 12:12:50 +00:00
if ( rec_tipodoc = = ' A ' | | rec_tipodoc = = ' N ' | | rec_tipodoc < = ' ' )
2011-02-02 15:04:06 +00:00
return ;
2011-01-26 16:56:02 +00:00
//1) codice terminale (lungo 3) e codice agente (lungo 5)
TString4 codice_terminale = recset . get ( " CodiceTerminale " ) . as_string ( ) ;
const TString & codice_agente = check_agente ( codice_terminale , log ) ;
const TString8 codmag = cache ( ) . get ( LF_AGENTI , codice_agente , AGE_CODMAG ) ;
2011-01-27 15:16:23 +00:00
check_magazzino ( codmag , log ) ;
2011-01-26 16:56:02 +00:00
2010-10-26 15:46:30 +00:00
//2) Testata documento
//genera una simpatico documento di cui raccatta la chiave
2010-10-27 10:53:47 +00:00
const TString & str_datadoc = recset . get ( DOC_DATADOC ) . as_string ( ) ;
2011-01-26 16:56:02 +00:00
const TDate datadoc = upload_format_date6 ( str_datadoc ) ;
2010-10-27 10:53:47 +00:00
2011-02-02 15:04:06 +00:00
2010-10-26 15:46:30 +00:00
//2a) tipo documento
TString4 tipodoc ;
TConfig hardy ( CONFIG_DITTA , " ha " ) ;
switch ( rec_tipodoc )
{
2011-01-26 13:31:15 +00:00
case ' F ' : tipodoc = hardy . get ( " InpFatTip " ) ; break ; //Fatture
case ' B ' : tipodoc = hardy . get ( " InpBolTip " ) ; break ; //Bolle
case ' V ' : tipodoc = hardy . get ( " InpValTip " ) ; break ; //bolle Valorizzate: attenzione!! devono essere trasformate in 'B'olle alla creazione della numerazione di Campo
case ' O ' : tipodoc = hardy . get ( " InpOrdTip " ) ; break ; //Ordini
2010-10-26 15:46:30 +00:00
default :
{
_can_write = false ;
TString msg ;
msg < < " Tipo documento in input " < < rec_tipodoc < < " sconosciuto " ;
log . log ( 2 , msg ) ;
}
break ;
}
//2b) numerazione documento
//il codnum dipende dal tipo documento del terminale (F,B,O...) e dal codice del terminale
2011-01-26 16:56:02 +00:00
//se tipo 'V' va cambiato in tipo 'B' in quanto le bolle valorizzate sono normali bolle in Campo
2010-10-26 15:46:30 +00:00
TString4 codnum ;
2011-01-26 13:31:15 +00:00
if ( rec_tipodoc = = ' V ' )
rec_tipodoc = ' B ' ;
2010-10-26 15:46:30 +00:00
codnum < < rec_tipodoc < < codice_terminale ;
const TString & numerazione = cache ( ) . get ( " %NUM " , codnum , " CODTAB " ) ;
if ( numerazione ! = codnum )
{
_can_write = false ;
TString msg ;
msg < < " Codice numerazione " < < codnum < < " sconosciuto " ;
log . log ( 2 , msg ) ;
}
const long ndoc = recset . get ( DOC_NDOC ) . as_int ( ) ;
2011-01-26 16:56:02 +00:00
TDocumento doc ( ' D ' , datadoc . year ( ) , codnum , ndoc ) ;
2010-10-26 15:46:30 +00:00
2011-01-26 13:31:15 +00:00
//2c) tipo documento e data documento
2010-10-26 15:46:30 +00:00
doc . put ( DOC_TIPODOC , tipodoc ) ;
2011-01-26 13:31:15 +00:00
TTipo_documento td ( tipodoc ) ;
const TString & caus_movmag = td . caus_mov ( ) ;
doc . put ( DOC_CAUSMAG , caus_movmag ) ;
2010-10-27 10:53:47 +00:00
doc . put ( DOC_DATADOC , datadoc ) ;
2011-01-26 13:31:15 +00:00
//2d) cliente e campi collegati via cli2doc()
2010-10-26 15:46:30 +00:00
doc . put ( DOC_TIPOCF , " C " ) ;
2011-02-01 13:51:55 +00:00
2011-02-02 15:04:06 +00:00
//dato il codice cliente sul recordset (stringa di 6) risale al codice di Campo (long di 6) stabilendo..
//..eventuali relazioni con i clienti nuovi (con '*') importati nei record VC all'inizio della procedura
2011-02-01 13:51:55 +00:00
const TString & str_codcf = recset . get ( DOC_CODCF ) . as_string ( ) ;
2011-02-02 15:04:06 +00:00
long codcf = check_cliente ( str_codcf , log ) ;
2011-01-26 13:31:15 +00:00
2010-10-26 15:46:30 +00:00
doc . put ( DOC_CODCF , codcf ) ;
doc . put ( DOC_CODCFFATT , recset . get ( DOC_CODCFFATT ) . as_int ( ) ) ;
//sconto in fattura, sconto totale, incasso ecc.... che cazzo sono?
//TString8 scontone = recset.get();
doc . put ( DOC_CODPAG , recset . get ( DOC_CODPAG ) . as_string ( ) ) ;
//data spedizione...datapart o datacons? (solo per ordini)
2011-01-26 13:31:15 +00:00
//usa la cli2doc per riempire tutti i campi legati al cliente
TCli_for clifor ( ' C ' , codcf ) ;
clifor . cli2doc ( doc ) ;
2010-10-26 15:46:30 +00:00
//al simpatico documento appiccia tutte le righe RF che seguono il record TF..
//..dopo il magico ordinamento iniziale del recordset
//intanto azzera le righe eventualmente gi<67> presenti (riscrittura)
doc . destroy_rows ( ) ;
//3) righe documento
//scansione delle righe documento su record RF
while ( recset . move_next ( ) )
{
if ( recset . get ( " TipoRecord " ) . as_string ( ) ! = " RF " ) //quando non trova un RF significa che le righe della testata sono finite!
{
recset . move_prev ( ) ; //allora torna indietro di un record per riposizionarsi sull'ultimo non letto
break ;
}
//agginunge una nuova riga (solo merce, per quanto ne sappiamo)
TRiga_documento & rigadoc = doc . new_row ( " 01 " ) ;
//serie delle put sulla riga documento; ricordiamo che la chiave della riga viene riempita dalla new_row
//3a) articolo
2010-10-27 10:53:47 +00:00
TString8 codart = recset . get ( RDOC_CODART ) . as_string ( ) ;
2011-01-26 16:56:02 +00:00
const TString & descr = check_articolo ( codart , log ) ;
2010-10-26 15:46:30 +00:00
rigadoc . put ( RDOC_CODART , codart ) ;
rigadoc . put ( RDOC_CODARTMAG , codart ) ;
rigadoc . put ( RDOC_CHECKED , " X " ) ;
2011-01-26 16:56:02 +00:00
rigadoc . put ( RDOC_DESCR , descr ) ;
2010-10-27 10:53:47 +00:00
2011-01-27 15:16:23 +00:00
//3b) umart e qta
2010-10-26 15:46:30 +00:00
const TString & umqta = recset . get ( RDOC_UMQTA ) . as_string ( ) ;
2010-10-27 10:53:47 +00:00
TLocalisamfile file_umart ( LF_UMART ) ;
file_umart . setkey ( 2 ) ;
file_umart . put ( UMART_CODART , codart ) ;
file_umart . put ( UMART_UM , umqta ) ;
const int err_umart = file_umart . read ( ) ;
if ( err_umart ! = NOERR )
2010-10-26 15:46:30 +00:00
{
_can_write = false ;
TString msg ;
msg < < " U.m. " < < umqta < < " dell'articolo " < < codart < < " sconosciuta " ;
log . log ( 2 , msg ) ;
}
rigadoc . put ( RDOC_UMQTA , umqta ) ;
real qta = recset . get ( " Qta[int] " ) . as_real ( ) ;
qta + = recset . get ( " Qta[dec] " ) . as_real ( ) / CENTO ;
rigadoc . put ( RDOC_QTA , qta ) ;
//panegirico sugli sconti
TString str_sconto ;
real sconto [ 4 ] ;
sconto [ 0 ] = recset . get ( " Sconto1 " ) . as_real ( ) ;
2010-10-27 10:53:47 +00:00
sconto [ 1 ] = recset . get ( " Sconto2 " ) . as_real ( ) ;
sconto [ 2 ] = recset . get ( " Sconto3 " ) . as_real ( ) ;
sconto [ 3 ] = recset . get ( " ScontoLibero " ) . as_real ( ) ;
2010-10-26 15:46:30 +00:00
for ( int s = 0 ; s < 4 ; s + + )
{
if ( ! sconto [ s ] . is_zero ( ) )
str_sconto < < ( sconto [ s ] / CENTO ) < < ' + ' ;
}
str_sconto . rtrim ( 1 ) ;
rigadoc . put ( RDOC_SCONTO , str_sconto ) ;
2011-01-27 15:16:23 +00:00
//prezzi
2010-10-26 15:46:30 +00:00
real prezzo_lordo = recset . get ( RDOC_PREZZO ) . as_real ( ) ;
prezzo_lordo / = 1000 ;
2010-10-27 10:53:47 +00:00
rigadoc . put ( RDOC_PREZZO , prezzo_lordo ) ;
2010-10-26 15:46:30 +00:00
//3x) iva
const int aliquota_iva = recset . get ( " AliquotaIva " ) . as_int ( ) ;
2010-11-23 15:28:56 +00:00
TString4 codiva ;
//il codice lo si trova nella configurazione del modulo Ha (c'<27> un magico sheet apposito)
TConfig config ( CONFIG_DITTA , " ha " ) ;
TString curr_name ;
for ( int j = 0 ; ; j + + )
{
const real curr_aliq_iva = config . get ( " IVAaliquota " , NULL , j ) ;
if ( curr_aliq_iva = = ZERO )
break ;
if ( curr_aliq_iva . integer ( ) = = aliquota_iva )
{
codiva = config . get ( " IVAcodice " , NULL , j ) ;
break ;
}
}
rigadoc . put ( RDOC_CODIVA , codiva ) ;
2010-10-26 15:46:30 +00:00
rigadoc . put ( RDOC_LIVELLO , recset . get ( " CodiceLotto " ) . as_string ( ) ) ;
2011-01-26 13:31:15 +00:00
rigadoc . put ( RDOC_CODMAG , codmag ) ; //questo viene dall'agente ed <20> stato preso all'inizio del metodo
2010-10-26 15:46:30 +00:00
}
//incredibilmente arriva in fondo
TString msg ;
2011-01-26 16:56:02 +00:00
msg < < datadoc . year ( ) < < " - " < < codnum < < " - " < < ndoc < < " Terminale: " < < codice_terminale < < " Cliente: " < < codcf ;
2010-10-26 15:46:30 +00:00
//se pu<70> scrivere...
if ( _can_write )
{
int err = doc . write ( ) ;
if ( err = = NOERR )
{
msg . insert ( " Registrato documento: " , 0 ) ;
log . log ( 0 , msg ) ;
}
else
{
msg . insert ( " Impossibile registrare documento: " , 0 ) ;
log . log ( 2 , msg ) ;
}
}
else //..senn<6E> avverte e basta
{
msg . insert ( " Controllato documento: " , 0 ) ;
log . log ( 0 , msg ) ;
}
2010-10-27 10:53:47 +00:00
log . log ( 0 , " " ) ;
2010-10-26 15:46:30 +00:00
}
2011-01-27 15:16:23 +00:00
void TUpload2Campo : : elabora_RC ( THardy_upload_recordset & recset , TLog_report & log )
{
//1) codice terminale (lungo 3) e codice agente (lungo 5)
TString4 codice_terminale = recset . get ( " CodiceTerminale " ) . as_string ( ) ;
const TString & codice_agente = check_agente ( codice_terminale , log ) ;
const TRectype & rec_agente = cache ( ) . get ( LF_AGENTI , codice_agente ) ;
const TString8 codmag = rec_agente . get ( AGE_CODMAG ) ;
const long codcf = rec_agente . get_long ( AGE_CODFORN ) ; //cliente (legato all'agente)
//2) Testata documento
const TString & str_datadoc = recset . get ( " DataCarico " ) . as_string ( ) ;
const TDate datadoc = upload_format_date6 ( str_datadoc ) ;
const int anno = datadoc . year ( ) ;
//2a) numerazione e tipo documento
TConfig hardy ( CONFIG_DITTA , " ha " ) ;
const TString4 codnum = hardy . get ( " CarDocNum " ) ;
2011-02-02 15:04:06 +00:00
const TString4 tipodoc = hardy . get ( " CarDocTip " ) ;
2011-01-27 15:16:23 +00:00
const TString4 stato = hardy . get ( " CarDocSta " ) ;
//2b) documento vero e proprio (stessi campi del caso tipo record = TF)
TDocumento doc ;
doc . put ( DOC_CODNUM , codnum ) ;
doc . put ( DOC_ANNO , anno ) ;
doc . put ( DOC_PROVV , " D " ) ;
doc . put ( DOC_TIPODOC , tipodoc ) ;
doc . put ( DOC_STATO , stato ) ;
doc . put ( DOC_DATADOC , datadoc ) ;
doc . put ( DOC_TIPOCF , " C " ) ;
doc . put ( DOC_CODCF , codcf ) ;
TTipo_documento td ( tipodoc ) ;
const TString & caus_movmag = td . caus_mov ( ) ;
doc . put ( DOC_CAUSMAG , caus_movmag ) ;
TCli_for clifor ( ' C ' , codcf ) ;
clifor . cli2doc ( doc ) ;
doc . destroy_rows ( ) ;
// righe documento di carico
bool go_on = true ;
//scansione delle righe documento su record RC
while ( go_on )
{
//3) crea le righe (legge tutti i record di tipo RC successivi)
TRiga_documento & rigadoc = doc . new_row ( " 01 " ) ;
//serie delle put sulla riga documento; ricordiamo che la chiave della riga viene riempita dalla new_row
//3a) articolo
TString8 codart = recset . get ( " CodiceArticolo " ) . as_string ( ) ;
const TString & descr = check_articolo ( codart , log ) ;
rigadoc . put ( RDOC_CODART , codart ) ;
rigadoc . put ( RDOC_CODARTMAG , codart ) ;
rigadoc . put ( RDOC_CHECKED , " X " ) ;
rigadoc . put ( RDOC_DESCR , descr ) ;
TToken_string key_umart ;
key_umart . add ( codart ) ;
key_umart . add ( 1 ) ;
const TString & um = cache ( ) . get ( LF_UMART , key_umart , UMART_UM ) ;
rigadoc . put ( RDOC_UMQTA , um ) ;
const real qta = recset . get ( " Quantita " ) . as_real ( ) / CENTO ;
rigadoc . put ( RDOC_QTA , qta ) ;
rigadoc . put ( RDOC_CODMAG , codmag ) ;
//quando non trova un RC significa che le righe sono finite!
go_on = recset . move_next ( ) ;
if ( go_on & & ( recset . get ( " TipoRecord " ) . as_string ( ) ! = " RC " ) )
{
recset . move_prev ( ) ; //allora torna indietro di un record per riposizionarsi sull'ultimo non letto
go_on = false ;
}
}
//incredibilmente arriva in fondo
TString msg ;
msg < < anno < < " - " < < codnum < < " Terminale: " < < codice_terminale < < " Cliente: " < < codcf ;
//se pu<70> scrivere...
if ( _can_write )
{
int err = doc . write ( ) ;
if ( err = = NOERR )
{
msg . insert ( " Registrato documento di carico: " , 0 ) ;
log . log ( 0 , msg ) ;
}
else
{
msg . insert ( " Impossibile registrare documento di carico: " , 0 ) ;
log . log ( 2 , msg ) ;
}
}
else //..senn<6E> avverte e basta
{
msg . insert ( " Controllato documento di carico: " , 0 ) ;
log . log ( 0 , msg ) ;
}
log . log ( 0 , " " ) ;
}
2011-02-01 11:40:26 +00:00
2010-10-11 14:40:52 +00:00
void TUpload2Campo : : elabora ( const TMask & mask )
{
//creazione del filename del file da importare
TFilename src_file = mask . get ( F_PATH ) ;
src_file . add ( UPLOAD_FILE ) ;
THardy_upload_recordset recset ( src_file ) ;
const long items = recset . items ( ) ;
2010-10-26 15:46:30 +00:00
//ordinamento del file in memoria; sotto ogni TF (testata) mette le sue righe (RF)...MAGIA!!!
recset . sort ( ordina_upload ) ;
# ifdef DBG
2011-01-26 16:56:02 +00:00
recset . save_as ( " D:/dati/hardy/cazzone.txt " ) ;
2010-10-26 15:46:30 +00:00
# endif
2010-10-11 14:40:52 +00:00
//creazione progind e log
TProgind pi ( items , TR ( " Acquisizione dati in corso... " ) , true , true ) ;
TLog_report log ( " Segnalazioni su acquisizione " ) ;
2010-10-26 15:46:30 +00:00
log . kill_duplicates ( ) ;
2010-10-27 10:53:47 +00:00
log . log ( 0 , " " ) ;
2010-10-26 15:46:30 +00:00
//parametro di controllo; solo se resta true fino alla fine il documento viene writato
//solo in caso di elaborazione definitiva pu<70> diventare true
_can_write = false ;
if ( mask . get_bool ( F_DEFINITIVO ) )
_can_write = true ;
2010-10-11 14:40:52 +00:00
//giro su tutti i record del terribile recordset per l'acquisizione dei dati
for ( bool ok = recset . move_first ( ) ; ok ; ok = recset . move_next ( ) )
{
if ( ! pi . addstatus ( 1 ) )
break ;
//acquisizione tipo record da riga corrente del file di input
2010-10-26 15:46:30 +00:00
TString4 tipo_record = recset . rec_type ( ) ;
tipo_record . trim ( ) ;
2010-10-11 14:40:52 +00:00
2011-02-03 16:55:44 +00:00
//Sequenza di ordinamento dei record "SU|VC|TF|RF|SI|BR|RC": NON ATTENTATEVI A CAMBIARLA O NON FUNZIONA PIU' UN CAZZO!!
2010-10-11 14:40:52 +00:00
const int pos = tipi_record . get_pos ( tipo_record ) ;
//trattazione dei vari tracciati record
switch ( pos )
{
case 0 : //tipo record: SU (SetUp...ovvero agente)
2010-10-27 10:53:47 +00:00
//elabora_SU(recset, log); //non serve a una cippa!
2010-10-11 14:40:52 +00:00
break ;
2011-02-03 12:12:50 +00:00
case 1 : //tipo record: VC (nuovi clienti e Variazioni Cliente)
elabora_VC ( recset , log ) ;
break ;
case 2 : //tipo record: TF (Testata Fattura)
2010-10-26 15:46:30 +00:00
elabora_TF ( recset , log ) ;
2010-10-11 14:40:52 +00:00
break ;
2011-02-03 12:12:50 +00:00
case 3 : //tipo record: RF (Riga Fattura)
2010-10-27 10:53:47 +00:00
//elabora_RF(recset, log); //non serve! lo fa l'elaborazione di testata
2010-10-11 14:40:52 +00:00
break ;
2011-02-03 12:12:50 +00:00
case 4 : //tipo record: SI (incasso documenti)
2011-02-03 16:55:44 +00:00
elabora_SI ( recset , log ) ;
2010-10-11 14:40:52 +00:00
break ;
2011-02-03 12:12:50 +00:00
case 5 : //tipo record: BR (righe movimenti magazzino)
2011-01-26 16:56:02 +00:00
elabora_BR ( recset , log ) ;
2010-10-11 14:40:52 +00:00
break ;
2011-01-27 15:16:23 +00:00
case 6 : //tipo record: RC (Richiesta Carico)
elabora_RC ( recset , log ) ;
break ;
2010-10-11 14:40:52 +00:00
default : //se il tipo record non esiste nella lista dei tipi record si incazza e lo scrive!
{
TString msg ;
2010-10-26 15:46:30 +00:00
msg < < " Tipo record non riconosciuto ' " < < tipo_record < < " ' alla riga " < < ( recset . current_row ( ) + 1 ) ;
log . log ( 2 , msg ) ;
2010-10-11 14:40:52 +00:00
}
break ;
2010-10-14 13:15:43 +00:00
} //switch(pos)..
2010-10-11 14:40:52 +00:00
} //for (bool ok...
2010-10-26 15:46:30 +00:00
log . preview ( ) ;
2010-10-11 14:40:52 +00:00
}
void TUpload2Campo : : main_loop ( )
{
TUpload2Campo_mask mask ;
_intput_dir = mask . get ( F_PATH ) ;
while ( mask . run ( ) = = K_ENTER )
{
elabora ( mask ) ;
}
}
bool TUpload2Campo : : create ( )
{
return TSkeleton_application : : create ( ) ;
}
int ha1300 ( int argc , char * argv [ ] )
{
TUpload2Campo a ;
a . run ( argc , argv , " Importazione dati da file " ) ;
return 0 ;
}