Moduli e oggetti per il Motore Vendite.

git-svn-id: svn://10.65.10.50/trunk@2238 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
matteo 1995-12-05 09:22:10 +00:00
parent 407c8a6a87
commit 3469988609
6 changed files with 740 additions and 0 deletions

135
ve/dynarel.cpp Executable file
View File

@ -0,0 +1,135 @@
#ifndef __LFFILES_H
#include "lffiles.h"
#endif
#ifndef __DYNAREL_H
#include "dynarel.h"
#endif
TField_array::TField_array( const TRectype& rec )
{
int last = rec.items( );
for( int i = 0; i < last; i ++ )
{
add( rec.fieldname( i ), rec.get( rec.fieldname( i ) ) );
}
}
const TString& TField_array::get( const TString& nome_campo )
{
return ( TString& )(*this)[ nome_campo ];
}
int TField_array::get_int( const TString& nome_campo )
{
return atoi( get( nome_campo ) );
}
long TField_array::get_long( const TString& nome_campo )
{
return atoi( get( nome_campo ) );
}
bool TField_array::get_bool( const TString& nome_campo )
{
TString p( get( nome_campo ) );
char fc = toupper( p[ 0 ] );
return ( fc == 'T' || fc == 'Y' || fc == 'S' || fc == 'X' );
}
real TField_array::get_real( const TString& nome_campo )
{
real r( get( nome_campo ) );
return r;
}
TDyna_rel::TDyna_rel( const int main_file_index )
{
_main_file = main_file_index;
load_file( main_file_index );
};
bool TDyna_rel::file_added( const int file_index )
{
return ( &_rules[ file_index ] != NULL );
}
bool TDyna_rel::file_loaded( const int file_index )
{
return ( &_file_array[ file_index ] != NULL );
}
void TDyna_rel::load_file( const int file_index )
{
CHECK( file_loaded( file_index ), "Utilizzo di un file non aggiunto alla dyna_rel!" );
TToken_string rule( ( ( TString& ) _rules[ file_index ] ) );
// Il file principale è già caricato
TLocalisamfile to( file_index );
to.setkey( _keys[ file_index ] );
to.curr( ).zero( );
int last = rule.items( );
// Carico i valori per la ricerca
for( int i = 0; i < last; i += 3 )
to.curr( ).put( rule.get( i ), get( ( rule.get_int( i + 1 ) == 0 ? rule.get_int( i + 1 ) : _main_file ), rule.get( i + 2 ) ) );
to.read ( _isequal );
// Se il posizionamento riesce ...
if( !to.bad( ) )
{
// Carica tutti i campi
_file_array.add( new TField_array( to.curr( ) ), file_index );
}
}
void TDyna_rel::add_file( const int file_index, const TToken_string rule, const int key )
{
_rules[ file_index ] = rule;
_keys[ file_index ] = key;
};
const TString& TDyna_rel::get( const int file_index, const TString16 nome_campo )
{
CHECK( file_loaded( file_index ), "Tentativo di accesso ad un campo di un file non caricato!" );
return ( file( file_index ).get( nome_campo ) );
};
int TDyna_rel::get_int( const int file_index, const TString16 nome_campo )
{
CHECK( file_loaded( file_index ), "Tentativo di accesso ad un campo di un file non caricato!" );
return ( file( file_index ).get_int( nome_campo ) );
};
long TDyna_rel::get_long( const int file_index, const TString16 nome_campo )
{
CHECK( file_loaded( file_index ), "Tentativo di accesso ad un campo di un file non caricato!" );
return ( file( file_index ).get_long( nome_campo ) );
};
bool TDyna_rel::get_bool( const int file_index, const TString16 nome_campo )
{
CHECK( file_loaded( file_index ), "Tentativo di accesso ad un campo di un file non caricato!" );
return ( file( file_index ).get_bool( nome_campo ) );
};
real TDyna_rel::get_real( const int file_index, const TString16 nome_campo )
{
CHECK( file_loaded( file_index ), "Tentativo di accesso ad un campo di un file non caricato!" );
return ( file( file_index ).get_real( nome_campo ) );
};
class TCF : public TDyna_rel
{
public:
TCF( );
};
TCF::TCF( ) : TDyna_rel( LF_CLIFO )
{
add_file( LF_CFVEN, "", 1 );
}

63
ve/dynarel.h Executable file
View File

@ -0,0 +1,63 @@
#ifndef __DYNAREL_H
#define __DYNAREL_H
#ifndef __ISAM_H
#include <isam.h>
#endif
#ifndef __ASSOC_H
#include <assoc.h>
#endif
#ifndef __UTILITY_H
#include <utility.h>
#endif
#include <stdlib.h>
#define MAX_FILES 100
class TField_array : public TAssoc_array
{
public:
const TString& get( const TString& nome_campo );
int get_int( const TString& nome_campo );
long get_long( const TString& nome_campo );
bool get_bool( const TString& nome_campo );
real get_real( const TString& nome_campo );
TField_array( const TRectype& rec );
};
class TDyna_rel : public TObject
{
private:
int _main_file;
TArray _file_array;
TString_array _rules;
int _keys[ MAX_FILES ];
protected:
bool file_added( const int file_index );
bool file_loaded( const int file_index );
void load_file( const int file_index );
public:
TDyna_rel( const int main_file_index );
void add_file( const int file_index, const TToken_string rule, const int key );
TField_array& file( const int file_index ){ return ( TField_array& )_file_array[ file_index ]; };
const TString& get( const int file_index, const TString16 nome_campo );
int get_int( const int file_index, const TString16 nome_campo );
long get_long( const int file_index, const TString16 nome_campo );
bool get_bool( const int file_index, const TString16 nome_campo );
real get_real( const int file_index, const TString16 nome_campo );
};
#endif

359
ve/righedoc.cpp Executable file
View File

@ -0,0 +1,359 @@
#ifndef __RIGHEDOC_H
#include "righedoc.h"
#endif
#ifndef __VE0100_H
#include "ve0100.h"
#endif
#ifndef __VE0100C_H
#include "ve0100c.h"
#endif
#ifndef __VEUML2_H
#include "veuml2.h"
#endif
#ifndef __SCONTI_H
#include "sconti.h"
#endif
static void row_set_handler( TMask& m, const int field, const int index )
{
switch ( index )
{
case 1:
m.set_handler( field, dummy_hndl );
break;
default:
yesnofatal_box( FALSE, "Funzione di handler sulla riga non definita( %d ).", index );
}
}
static bool riga_des_handler( TMask_field& f, KEY key )
{
TMask& m = f.mask( );
// Se qualcuno cerca di modificare la maschera
if ( key == K_SPACE && m.is_running( ) )
{
TString val( f.get( ) );
if ( val.len( ) >= 49 )
{
TMask m1( "VE1000C" );
m1.set( 101, f.get( ) );
KEY k = m1.run( );
if ( k == K_SAVE )
f.set( m1.get( 101 ) );
}
}
return TRUE;
}
static bool riga_art_handler( TMask_field& f, KEY key )
{
TMask& m = f.mask( );
// Se qualcuno cerca di modificare la maschera
if ( key == K_TAB ) // && m.is_running( ) )
{
TSconto_riga r( app( ).clifo( ), &( app( ).edit_mask( ) ), &( f.mask( ) ) );
r.calcola( );
f.mask( ).set( FS_SCONTO, r.get( ) );
}
return TRUE;
}
void TRiga::load( TToken_string& row )
{
_data.put( "CODNUM", row.get( FS_CODNUM - 101 ) );
_data.put( "ANNO", row.get( FS_ANNO - 101 ) );
_data.put( "PROVV", row.get( FS_PROVV - 101 ) );
_data.put( "NDOC", row.get( FS_NDOC - 101 ) );
_data.put( "STATORIGA", row.get( FS_STATORIGA - 101 ) );
_data.put( "TIPORIGA", row.get( FS_TIPORIGA - 101 ) );
_data.put( "PROFRIGA", row.get( FS_PROFRIGA - 101 ) );
_data.put( "CODMAG", row.get( FS_CODMAG - 101 ) );
_data.put( "CODART", row.get( FS_CODART - 101 ) );
_data.put( "DESCR", row.get( FS_DESCR - 101 ) );
_data.put( "DESCLUNGA", row.get( FS_DESCLUNGA - 101 ) );
_data.put( "PREZZO", row.get( FS_PREZZO - 101 ) );
_data.put( "UMQTA", row.get( FS_UMQTA - 101 ) );
_data.put( "QTA", row.get( FS_QTA - 101 ) );
_data.put( "QTAEVASA", row.get( FS_QTAEVASA - 101 ) );
_data.put( "RIGAEVASA", row.get( FS_RIGAEVASA - 101 ) );
_data.put( "TARA", row.get( FS_TARA - 101 ) );
_data.put( "PNETTO", row.get( FS_PNETTO - 101 ) );
_data.put( "NCOLLI", row.get( FS_NCOLLI - 101 ) );
_data.put( "DAEVADERE", row.get( FS_DAEVADERE - 101 ) );
_data.put( "SCONTO", row.get( FS_SCONTO - 101 ) );
_data.put( "PERCPROV", row.get( FS_PERCPROV - 101 ) );
_data.put( "IMPFISSO", row.get( FS_IMPFISSO - 101 ) );
_data.put( "CODIVA", row.get( FS_CODIVA - 101 ) );
_data.put( "ADDIVA", row.get( FS_ADDIVA - 101 ) );
_data.put( "ASPBENI", row.get( FS_ASPBENI - 101 ) );
carica_profilo( );
_piede.destroy( );
somma( _piede );
}
void TRiga::save( TToken_string& row )
{
row.add( _data.get( "CODNUM" ), FS_CODNUM - 101 );
row.add( _data.get( "ANNO" ), FS_ANNO - 101 );
row.add( _data.get( "PROVV" ), FS_PROVV - 101 );
row.add( _data.get( "NDOC" ), FS_NDOC - 101 );
row.add( _data.get( "STATORIGA" ), FS_STATORIGA - 101 );
row.add( _data.get( "TIPORIGA" ), FS_TIPORIGA - 101 );
row.add( _data.get( "PROFRIGA" ), FS_PROFRIGA - 101 );
row.add( _data.get( "CODMAG" ), FS_CODMAG - 101 );
row.add( _data.get( "CODART" ), FS_CODART - 101 );
row.add( _data.get( "DESCR" ), FS_DESCR - 101 );
row.add( _data.get( "DESCLUNGA" ), FS_DESCLUNGA - 101 );
row.add( _data.get( "PREZZO" ), FS_PREZZO - 101 );
row.add( _data.get( "UMQTA" ), FS_UMQTA - 101 );
row.add( _data.get( "QTA" ), FS_QTA - 101 );
row.add( _data.get( "QTAEVASA" ), FS_QTAEVASA - 101 );
row.add( _data.get( "RIGAEVASA" ), FS_RIGAEVASA - 101 );
row.add( _data.get( "TARA" ), FS_TARA - 101 );
row.add( _data.get( "PNETTO" ), FS_PNETTO - 101 );
row.add( _data.get( "NCOLLI" ), FS_NCOLLI - 101 );
row.add( _data.get( "DAEVADERE" ), FS_DAEVADERE - 101 );
row.add( _data.get( "SCONTO" ), FS_SCONTO - 101 );
row.add( _data.get( "PERCPROV" ), FS_PERCPROV - 101 );
row.add( _data.get( "IMPFISSO" ), FS_IMPFISSO - 101 );
row.add( _data.get( "CODIVA" ), FS_CODIVA - 101 );
row.add( _data.get( "ADDIVA" ), FS_ADDIVA - 101 );
row.add( _data.get( "ASPBENI" ), FS_ASPBENI - 101 );
row.add( _piede.string( ), FS_G1 - 101 );
}
void TRiga::carica_maschera( )
{
_mask = new TMask( _pro->get( "MSK", "MAIN" ) );
int numhandler = _pro->get_int( "NHANDLER", "HANDLERS" );
for( int i = 1; i <= numhandler; i ++ )
{
TString chiave;
chiave.format( "%d", i );
TToken_string riga = _pro->get( chiave, "HANDLERS" );
row_set_handler( *_mask, riga.get_int( 0 ), riga.get_int( 1 ) );
}
_mask->set_handler( FS_CODART, riga_art_handler );
}
void TRiga::load( const TRectype& rec )
{
_data = rec;
carica_profilo( );
}
void TRiga::save( TRectype& rec )
{
rec = _data;
rec.put( "G1", _piede.string( ) );
}
void TRiga::carica_profilo( )
{
if( _pro )
delete _pro;
TFilename proname( _data.get( "PROFRIGA" ) );
proname.ext( "ini" );
_pro = new TConfig( proname );
}
void TRiga::configura_sheet( TSheet_field& f, int numriga )
{
int ncols = _pro->get_int( "NCOLS", "COLUMNS" );
// Disabilita tutte le colonne
f.disable_cell ( numriga, -1 );
// Abilita le colonne indicate nel profilo della riga
for( int i = 1; i <= ncols; i ++ )
{
TString16 chiave;
chiave.format( "%d", i );
int coltoenable = _pro->get_int( chiave, "COLUMNS" );
f.enable_cell ( numriga, coltoenable - 1 );
}
}
void TRiga::somma( TPiede_documento& piede )
{
// Metti solo i campi numerici poichè sono gli unici che si calcolano
//static const TString tabella_campi( "#STATORIGA#TIPORIGA#PROFRIGA#CODMAG#CODART#DESCR#DESCLUNGA#PREZZO#UMQTA#QTA#QTAEVASA#RIGAEVASA#TARA#PNETTO#NCOLLI#DAEVADERE#SCONTO#PERCPROV#IMPFISSO#IMPFISUN#CODIVA#ADDIVA#ASPBENI#" );
static const TString tabella_campi( "#PREZZO#QTA#QTAEVASA#TARA#PNETTO#NCOLLI#PERCPROV#" );
TToken_string s( _pro->get( "PROGPIEDE", "MAIN" ) );
TString16 progpiede( s.get( ) );
TTable ppd( "PPD" );
while( !progpiede.blank( ) )
{
TString formula = s.get( );
if( formula.blank( ) )
{
// Se non è indicata alcuna formula, la prendo dalla tabella piedi
ppd.zero( );
ppd.put( "CODTAB", progpiede );
if( ppd.read( ) == NOERR )
formula = ppd.get( "S0" );
else
yesnofatal_box( "Progressivo piede non definito( %s ).", ( const char * ) progpiede );
}
// Calcolo la espressione
TExpression espr( "" );
if ( espr.set( formula ) )
{
int last = espr.numvar( );
for( int i = 0; i < last; i ++ )
{
TString varname( espr.varname( i ) );
TString cerca;
cerca.format( "#%s#", ( const char *)varname );
if ( tabella_campi.find( cerca ) != -1 )
{
real value ( _data.get_real( varname ) );
espr.setvar( varname, value );
}
else
{
if ( varname[ 0 ] == 'F' || varname[ 0 ] == 'f' )
{
TString16 nfunz ( varname );
nfunz.rtrim( 1 );
espr.setvar( varname, atoi( nfunz ) );
}
else
{
yesnofatal_box( "Variabile non definita nella funzione di calcolo della riga ( %s ).", ( const char * ) varname );
break;
}
}
}
piede.somma( progpiede, espr );
}
else
yesnofatal_box( "Espressione non valida( %s )", ( const char * )formula );
progpiede = s.get( );
}
}
void TRiga::sottrai( TPiede_documento& piede )
{
TPiede_documento temp_piede;
somma( temp_piede );
piede.sottrai( temp_piede );
}
TMask& TRiga::getmask( )
{
if( !_mask)
carica_maschera( );
_mask->set_handler( FS_DESCR, riga_des_handler );
return *_mask;
}
void TRiga::edit_keys( const KEY key, TPiede_documento& nuovo )
{
static TPiede_documento vecchio;
switch( key )
{
// Inizio modifica
case K_SPACE:
vecchio.destroy( );
somma( vecchio );
break;
// Cancellazione
case K_DEL:
// Toglie i vecchi valori
nuovo.sottrai( vecchio );
break;
// Modifica
case K_ENTER:
// Toglie i vecchi valori
nuovo.sottrai( vecchio );
// Aggiunge i nuovi all
somma( nuovo );
break;
}
}
TRiga::~TRiga( )
{
if( _pro )
delete _pro;
if( _mask )
delete _mask;
}
void TPiede_documento::somma( TPiede_documento& tosum, bool add )
{
tosum.restart( );
THash_object* curr = tosum.get_hashobj( );
while( curr )
{
TString16 key( curr->key( ) );
if( add )
somma( key, ( real& )curr->obj( ) );
else
sottrai( key, ( real& )curr->obj( ) );
curr = tosum.get_hashobj( );
}
}
void TPiede_documento::somma( TString16& piede, const real& importo )
{
if( is_key( piede ) )
{
real& attuale = ( real& ) operator []( piede );
attuale += importo;
}
else
add( piede, importo );
}
TToken_string& TPiede_documento::string( )
{
TToken_string ret;
ret.separator( '~' );
restart( );
THash_object* curr = get_hashobj( );
while( curr )
{
ret.add( curr->key( ) );
ret.add( (( real& ) curr->obj( )).string( ) );
curr = get_hashobj( );
}
return ret;
}
void TPiede_documento::load( TToken_string& s )
{
s.separator( '~' );
for( int i = 0; i < s.items( ); i+=2 )
{
TString16 piede = s.get( i );
TString num = s.get( i + 1 );
real valore( num );
add( piede, valore );
}
}
real& TPiede_documento::get( TString16& piede )
{
static real zero( "0.0" );
if( is_key( piede ) )
{
return ( real& ) find( piede );
}
else
return zero;
}

107
ve/righedoc.h Executable file
View File

@ -0,0 +1,107 @@
#ifndef __RIGHEDOC_H
#define __RIGHEDOC_H
// Numero di colonne presenti sullo sheet totale
#define MAX_COLUMNS 27
#ifndef __ASSOC_H
#include "assoc.h"
#endif
#ifndef __REAL_H
#include "real.h"
#endif
#ifndef __ISAM_H
#include "isam.h"
#endif
#ifndef __EXPR_H
#include "expr.h"
#endif
#ifndef __TABUTIL_H
#include "tabutil.h"
#endif
#ifndef __CONFIG_H
#include "config.h"
#endif
#ifndef __MSKSHEET_H
#include "msksheet.h"
#endif
#ifndef __VEUML2_H
#include "veuml2.h"
#endif
class TPiede_documento : public TAssoc_array
{
public:
TToken_string& string( );
void load( TToken_string& s );
void somma( TPiede_documento& tosum, bool add = TRUE );
void sottrai( TPiede_documento& tosum ){ somma( tosum, FALSE ); };
void somma( TString16& piede, const real& importo );
void sottrai( TString16& piede, const real& importo ){ somma( piede, -importo ); };
real& get( TString16& piede );
};
class TRiga : public TObject
{
private:
// Record che contiene i dati sulla riga
TRectype _data;
// Profilo di riga
TConfig* _pro;
// Maschera per la riga
TMask* _mask;
TPiede_documento _piede;
protected:
// Carca il profilo di riga: da migliorare mettendo una cache o precaricando
// tutti i profili per un documento
void carica_profilo( );
public:
// Setta il numero della riga
void set_numero( int r ) { _data.put( "NRIGA", r ); }
int numero( ) { return _data.get_int( "NRIGA" ); }
const TString& profilo( ) { return _data.get( "PROFRIGA" ); }
// Carica la riga dalla riga dello sheet
void load( TToken_string& row );
// Registra la riga sullo sheet
void save( TToken_string& row );
// Legge la riga dal record
void load( const TRectype& rec );
// Scrive la riga sul record
void save( TRectype& rec );
// Disabilita le colonne dello sheet come da profilo riga
void configura_sheet( TSheet_field& f, int numriga );
// Somma la riga su di un piede documento
void somma( TPiede_documento& piede );
// Sottrae la riga da un piede documento
void sottrai( TPiede_documento& piede );
// Gestisce la modifica/cancellazione della riga sul piede
// documento indicato. Va chiamata negli handler degli sheet
void edit_keys( const KEY key, TPiede_documento& nuovo );
// Ritorna la maschera della riga per la editazione
TMask& getmask( );
void carica_maschera( );
// Costruttorino standard
TRiga( ) : _data( LF_RIGHEDOC ), _pro( NULL ), _mask( NULL ) { }
virtual ~TRiga( );
};
#endif

47
ve/tmaskven.cpp Executable file
View File

@ -0,0 +1,47 @@
#ifndef __TMASKVEN_H
#include "tmaskven.h"
#endif
const TString& TMask_vendite::get(short fld_id) const
{
if( !present( fld_id ) )
return "";
else
return TMask::get( fld_id );
}
void TMask_vendite::set_handler(short fld_id, CONTROL_HANDLER handler)
{
if( !present( fld_id ) )
return;
TMask::set_handler( fld_id, handler );
}
void TMask_vendite::set(short fld_id, const char* str, bool hit )
{
if( !present( fld_id ) )
return;
TMask::set( fld_id, str, hit );
}
void TMask_vendite::show(short fld_id, bool on )
{
if( !present( fld_id ) )
return;
TMask::show( fld_id, on );
}
void TMask_vendite::enable(short fld_id, bool on )
{
if( !present( fld_id ) )
return;
TMask::enable( fld_id, on );
}
void TMask_vendite::check_field( short fld_id )
{
if( !present( fld_id ) )
return;
field( fld_id ).on_hit( );
field( fld_id ).check( );
}

29
ve/tmaskven.h Executable file
View File

@ -0,0 +1,29 @@
#ifndef __TMASKVEN_H
#define __TMASKVEN_H
#ifndef __MASK_H
#include <mask.h>
#endif
class TMask_vendite : public TMask
{
friend TMask;
protected:
bool present( short fld_id ) const { return ( id2pos( fld_id ) >= 0 ); };
public:
void check_field( short fld_id );
TMask_vendite( const char* name ) : TMask( name ) { };
virtual void set(short fld_id, const char* str, bool hit=FALSE);
virtual const TString& get(short fld_id) const;
virtual void set_handler(short fld_id, CONTROL_HANDLER handler);
virtual void show(short fld_id = -1, bool on = TRUE);
virtual void enable(short fld_id, bool on = TRUE);
};
#endif