diff --git a/ve/sconti.cpp b/ve/sconti.cpp index 1ef1e533f..b9b38cfd1 100755 --- a/ve/sconti.cpp +++ b/ve/sconti.cpp @@ -1,116 +1,319 @@ -#ifndef __SCONTI_H -#include "sconti.h" -#endif - -const real TSconto::cento( "100" ); - -void TSconto::set( const TString& exp, bool signal ) -{ - TString work( exp ); - TString goodexp; - TString num; - - // Elimina gli spazi molesti - work.strip_spaces( ); - // Per ora nessun errore - _errorpos = -1; - - int i = 0; - _part = 1.0; - const int wlen = work.len( ); - // Flag che indica se sono nella parte decimale di un numero - bool dec = FALSE; - // Flag che indica se si attende l'inizio di un numero - bool startnum = TRUE; - // Flag che indica se siamo all'inizio di un numero - while ( i < wlen && _errorpos < 0 ) - { - char c = work[ i++ ]; - switch( c ) - { - case '+': - case '-': - // Se ero in in numero ... - if( !startnum ) - { - // Aggiunge il numero alla sequenza - real newval( num ); - _part = _part * ( cento + newval ) / cento; - if( newval >= 0 ) - goodexp << '+'; - goodexp << num; - } - // Inizia il nuovo numero - num = ( c == '-' )?"-":""; - startnum = TRUE; - dec = FALSE; - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - num << c; - startnum = FALSE; - break; - case '.': - case ',': - // Se siamo già nella parte decimale ... - if( dec ) - { - // Segnala un errore - _errorpos = i; - break; - } - // Se occorrenva un numero ci metto lo 0 - if( startnum ) - num << '0'; - // Interpreto la virgola come punto - num << '.'; - dec = TRUE; - startnum = TRUE; - break; - default: - _errorpos = i; - break; - } - } - // Controlla la validità - _valid = ( _errorpos < 0 ); - // Se richiesto segnala l'errore - if( !_valid && signal ) - warning_box( "Espressione di sconto non valida. Errore sul carattere %d.", _errorpos + 1 ); - if( _valid ) - { - // Aggiunge l'ultimo numero preso - real lastval( num ); - _part = _part * ( cento + lastval ) / cento; - if( lastval >= 0 ) - goodexp << '+'; - goodexp << num; - // Assegna la nuova espressione formattata bene - _exp = goodexp; - } -else -{ - // Azzera la sequenza di percentuali - _part = 1.0; -} -} - -real TSconto::sconto( ) -{ - CHECK(is_valid( ),"Tentativo di usare uno sconto non valido!" ); - return ( ( _part * cento ) - cento ); -} - -void calcola_sconto_riga( TRectype riga ) -{ - - -} +#ifndef __SCONTI_H +#include "sconti.h" +#endif + +#ifndef __VEUML_H +#include "veuml.h" +#endif + +#ifndef __VEUML2_H +#include "veuml2.h" +#endif + +#ifndef __TCLIFOR_H +#include "tclifor.h" +#endif + +#ifndef __CONFIG_H +#include "config.h" +#endif + +#ifndef __VECONF_H +#include "veconf.h" +#endif + +#define A_ANAMAG 0 + +const real TSconto::cento( "100" ); + +void TSconto::set( const TString& exp, bool signal ) +{ + TString work( exp ); + TString goodexp; + TString num; + + // Elimina gli spazi molesti + work.strip_spaces( ); + // Per ora nessun errore + _errorpos = -1; + + int i = 0; + _part = 1.0; + const int wlen = work.len( ); + // Flag che indica se sono nella parte decimale di un numero + bool dec = FALSE; + // Flag che indica se si attende l'inizio di un numero + bool startnum = TRUE; + // Flag che indica se siamo all'inizio di un numero + while ( i < wlen && _errorpos < 0 ) + { + char c = work[ i++ ]; + switch( c ) + { + case '+': + case '-': + // Se ero in in numero ... + if( !startnum ) + { + // Aggiunge il numero alla sequenza + real newval( num ); + _part = _part * ( cento + newval ) / cento; + if( newval >= 0 ) + goodexp << '+'; + goodexp << num; + } + // Inizia il nuovo numero + num = ( c == '-' )?"-":""; + startnum = TRUE; + dec = FALSE; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + num << c; + startnum = FALSE; + break; + case '.': + case ',': + // Se siamo già nella parte decimale ... + if( dec ) + { + // Segnala un errore + _errorpos = i; + break; + } + // Se occorreva un numero ci metto lo 0 + if( startnum ) + num << '0'; + // Interpreto la virgola come punto + num << '.'; + dec = TRUE; + startnum = TRUE; + break; + default: + _errorpos = i; + break; + } + } + // Controlla la validità + _valid = ( _errorpos < 0 ); + // Se richiesto segnala l'errore + if( !_valid && signal ) + warning_box( "Espressione di sconto non valida. Errore sul carattere %d.", _errorpos + 1 ); + if( _valid ) + { + // Aggiunge l'ultimo numero preso + real lastval( num ); + _part = _part * ( cento + lastval ) / cento; + if( lastval >= 0 ) + goodexp << '+'; + goodexp << num; + // Assegna la nuova espressione formattata bene + _exp = goodexp; + } + else + { + // Azzera la sequenza di percentuali + _part = 1.0; + } +} + +real TSconto::sconto( ) +{ + CHECK(is_valid( ),"Tentativo di usare uno sconto non valido!" ); + return ( ( _part * cento ) - cento ); +} + + +TSconto_riga::TSconto_riga( TCliFor& clifo, TMask * testa, TMask * riga ) : _condv( LF_CONDV ), _rcondv( LF_RCONDV ), _anamag( LF_ANAGR ), _sconti( LF_SCONTI ), _ditta( CONFIG_DITTA ) +{ + _clifo = &clifo; + _testa = testa; + _riga = riga; +} + +bool TSconto_riga::cerca_condv( int tiporicerca ) +{ + TString s1 = _anamag.get( "CODART" ); + TString s2 = riga( ).get( FS_CODART ); + if( s1 != s2 ) + { + _anamag.setkey( 1 ); + _anamag.zero( ); + _anamag.put( "CODART", riga( ).get( FS_CODART ) ); + int ret = _anamag.read( ); + CHECK( ret == NOERR, "Articolo non trovato in anagrafica di magazzino!" ); + } + if( tiporicerca == A_ANAMAG ) + // Se ricercavo per anagrafica, ho già finito + return TRUE; + if( _ditta.get_bool( "GES", "ve", tiporicerca ) ) + { + // Se è attiva la gestione contratti ... + _condv.setkey( 1 ); + _condv.zero( ); + switch( tiporicerca ) + { + case A_CONTRATTI: + _condv.put( "TIPO", "C" ); + _condv.blank( "CATVEN" ); + if( _ditta.get_bool( "GESSCONCC", "ve" ) ) + { + // Se in ditta è abilitata la gestione del cliente in chiave + // al contratto, lo carico con gioia + _condv.put( "TIPOCF", clifo( ).tipocf( ) ); + _condv.put( "CODCF", clifo( ).codcf( ) ); + } + else + { + _condv.blank( "TIPOCF" ); + _condv.blank( "CODCF" ); + } + _condv.put( "COD", testa( ).get( F_CODCONT ) ); + break; + case A_LISTINI: + _condv.put( "TIPO", "L" ); + if( _ditta.get_bool( "GESLISCV", "ve" ) ) + { + // Se in ditta è abilitata la gestione del cliente in chiave + // al contratto, lo carico con gioia + _condv.put( "TIPOCF", clifo( ).tipocf( ) ); + _condv.put( "CODCF", clifo( ).codcf( ) ); + } + else + { + _condv.blank( "TIPOCF" ); + _condv.blank( "CODCF" ); + } + _condv.blank( "CATVEN" ); + _condv.put( "COD", testa( ).get( F_CODLIST ) ); + break; + case A_OFFERTE: + _condv.put( "TIPO", "O" ); + _condv.blank( "CATVEN" ); + _condv.blank( "TIPOCF" ); + _condv.blank( "CODCF" ); + _condv.put( "COD", testa( ).get( F_CODCAMP ) ); + break; + } + if( _condv.read( ) == NOERR ) + { + _rcondv.setkey( 2 ); + _rcondv.zero( ); + _rcondv.put( "TIPO", _condv.get( "TIPO" ) ); + _rcondv.put( "CATVEN", _condv.get( "CATVEN" ) ); + _rcondv.put( "TIPOCF", _condv.get( "TIPOCF" ) ); + _rcondv.put( "CODCF", _condv.get( "CODCF" ) ); + if( _condv.get_bool( "GESTUM" ) ) + { + _rcondv.put( "UM", riga( ).get( FS_UMQTA ) ); + } + else + { + _rcondv.blank( "UM" ); + } + if( _condv.get_bool( "GESTSCA" ) ) + { + _rcondv.put( "QLIM", riga( ).get( FS_QTA ) ); + } + else + { + _rcondv.blank( "QLIM" ); + } + const TString16 seqricrighe( _condv.get( "SEQRIC" ) ); + for( int i = 0; i < seqricrighe.len( ); i ++ ) + { + + char ricerca = seqricrighe[ i ]; + _rcondv.put( "TIPORIGA", ricerca ); + switch( ricerca ) + { + case 'A': + _rcondv.put( "CODRIGA", _anamag.get( "CODART" ) ); + if( _rcondv.read( ) == NOERR ) return TRUE; + break; + case 'R': + _rcondv.put( "CODRIGA", _anamag.get( "RAGGFIS" ) ); + if( _rcondv.read( ) == NOERR ) return TRUE; + break; + case 'G': + _rcondv.put( "CODRIGA", _anamag.get( "GRMERC1" ) ); + if( _rcondv.read( ) == NOERR ) return TRUE; + _rcondv.put( "CODRIGA", _anamag.get( "GRMERC2" ) ); + if( _rcondv.read( ) == NOERR ) return TRUE; + _rcondv.put( "CODRIGA", _anamag.get( "GRMERC3" ) ); + if( _rcondv.read( ) == NOERR ) return TRUE; + break; + default: + CHECK( FALSE, "Tipo di ricerca righe non valido!" ); + } + } + // Ricerca fallita + return FALSE; + } + else + // Ricerca fallita + return FALSE; + } + else + // La ricerca non è gestita, impossibile trovarlo ... + return FALSE; +} + +// Probabilmente dovrebbe lavorare sulla maschera, ma per ora la lasciamo così +void TSconto_riga::calcola( ) +{ + char gestione = _ditta.get_char( "GESSCORIGA", "ve" ); + bool trovato = TRUE; + switch( gestione ) + { + case 'N': + // Sconti di riga non gestiti + set( "" ); + break; + case 'L': + // Percentuale su contratti/offerte/listini/anagrafica + trovato = cerca_condv( A_CONTRATTI ); + if( !trovato ) trovato = cerca_condv( A_OFFERTE ); + if( !trovato ) trovato = cerca_condv( A_LISTINI ); + if( !trovato ) + set( _rcondv.get( "SCONTO" ) ); + else + { + if( cerca_condv( A_ANAMAG ) ) + set( _anamag.get( "SCONTO" ) ); + else + CHECK( FALSE, "Sconto non trovato!( 1 )" ); + } + break; + case 'A': + // Posiziono l'anagrafica + cerca_condv( A_ANAMAG ); + _sconti.setkey( 1 ); + _sconti.put( "TIPO", "R" ); + _sconti.put( "CODART", _anamag.get( "CODART" ) ); + if( _ditta.get_bool( "GESSCORIGACV", "ve" ) ) + { + _sconti.put( "CODCAT", clifo( ).get( LF_CFVEN, "SCONTO" ) ); + } + if( _ditta.get_bool( "GESSCORIGAUM", "ve" ) ) + { + _sconti.put( "UM", riga( ).get( FS_UMQTA ) ); + } + if( _sconti.read( ) == NOERR ) + // Bravo, hai vinto una bambolina + set( _sconti.get( "SCONTO" ) ); + else + CHECK( FALSE, "Sconto non trovato!( 2 )" ); + break; + case 'C': + set( clifo( ).get( LF_CFVEN, "SCONTO" ) ); + } +} diff --git a/ve/sconti.h b/ve/sconti.h index 4ad8e729f..4701db421 100755 --- a/ve/sconti.h +++ b/ve/sconti.h @@ -5,6 +5,19 @@ #include #endif +#ifndef __TCLIFOR_H +#include "tclifor.h" +#endif + +#ifndef __MASK_H +#include +#endif + +#ifndef __CONFIG_H +#include +#endif + + #define CHKVALID CHECK( _valid, "Tentativo di usare uno sconto non valido!" ) class TSconto : public TObject @@ -28,4 +41,35 @@ public: }; #undef CHKVALID + +class TSconto_riga : public TSconto +{ + private: + TCliFor* _clifo; + // TRelation _condv; + // Invece che la relazione uso i due files, poichè mi interessa sempre + // solo una delle righe + TLocalisamfile _condv; + TLocalisamfile _rcondv; + TLocalisamfile _anamag; + TLocalisamfile _sconti; + TConfig _ditta; + TMask* _testa; + TMask* _riga; + + protected: + + public: + + TSconto_riga( TCliFor& clifo, TMask * testa = NULL, TMask * riga = NULL ); + + TCliFor& clifo( ){ return *_clifo; } + void set_testa( TMask& testa ){ _testa = &testa; } + TMask& testa( ){ return *_testa; } + void set_riga( TMask& riga ){ _riga = &riga; } + TMask& riga( ){ return *_riga; } + bool cerca_condv( int tiporicerca ); + void calcola( ); +}; + #endif diff --git a/ve/tclifor.cpp b/ve/tclifor.cpp index 744898244..027f194e3 100755 --- a/ve/tclifor.cpp +++ b/ve/tclifor.cpp @@ -1,335 +1,384 @@ -#ifndef __TCLIFOR_H -#include "tclifor.h" -#endif - -#ifndef __CONFIG_H -#include "config.h" -#endif - -#ifndef __VEUML1_H -#include "veuml1.h" -#endif - -#ifndef __VE1000O_H -#include "ve1000o.h" -#endif - -const TString& TData_picker::get( const TString& table, const TString& codtab, const TString& field ) -{ - if( table != _tablename ) - { - delete _table; - _table = new TTable( table ); - _tablename = table; - } - if( codtab != _table->curr( ).get( "CODTAB" ) ) - { - _table->zero( ); - _table->put( "CODTAB", codtab ); - _table->read( ); - } - return _table->get( field ); -}; - -const TString& TData_picker::get( const int file, const TString& fieldname ) -{ - return lfile( file ).get( fieldname ); -} - -int TData_picker::get_int( const int file, const TString& fieldname ) -{ - return lfile( file ).get_int( fieldname ); -} - -long TData_picker::get_long( const int file, const TString& fieldname ) -{ - return lfile( file ).get_long( fieldname ); -} - -bool TData_picker::get_bool( const int file, const TString& fieldname ) -{ - return lfile( file ).get_bool( fieldname ); -} - -int TCliFor::write_occas( ) -{ - if( !occasionale( ) ) - return NOERR; - TRelation occas( LF_OCCAS ); - occas_mask( ).autosave( &occas ); - return occas.write( ); -} - -TCliFor::TCliFor( ) : TData_picker( LF_CLIFO ), _occas_mask( "ve1000o" ) -{ - _occas_mask.set_handler( O_CODICE, occas_code_handler ); - add( LF_CFVEN, "TIPOCF=TIPOCF|CODCF=CODCF" ); -} - -void TCliFor::load( const char tipocf, const long codcf, const TString& ocfpi ) -{ - _tipocf = tipocf; - _codcf = codcf; - zero( ); - curr( ).put( "TIPOCF", tipocf ); - curr( ).put( "CODCF", codcf ); - lfile( ).setkey( 1 ); - if( read( ) != NOERR ) - yesnofatal_box( "Il %s %d non è stato trovato!", tipocf == 'C'?"cliente":"fornitore", codcf ); - _occas = curr().get_bool( "OCCAS" ); - if ( occasionale( ) ) - { - TRelation occrel( LF_OCCAS ); - occrel.curr( ).zero( ); - occrel.curr( ).put( "CFPI", ocfpi ); - occrel.read( ); - occas_mask( ).autoload( &occrel ); - } -} - -void TCliForVendite::update_mask( TMask_vendite& m, bool onload ) -{ - TString16 stato; - - // Setta i campi che appartengono al file LF_CLIFO - bool occas = occasionale( ); - m.show( F_OCFPI, occas ); - m.show( F_OCCASEDIT, occas ); - // In forse per l'Occasionale, sicuri per il Normale - m.show( F_COFI, !occas ); - m.show( F_STATOPAIVA, !occas ); - m.show( F_PAIVA, !occas ); - set( m, F_RAGSOC, LF_CLIFO, "RAGSOC" ); - if( !onload ) - { - set( m, F_CODVAL, LF_CLIFO, "CODVAL" ); - set( m, F_CODLIN, LF_CLIFO, "CODLIN" ); - set( m, F_CODPAG, LF_CLIFO, "CODPAG" ); - set( m, F_CODABIA, LF_CLIFO, "CODABI" ); - set( m, F_CODCABA, LF_CLIFO, "CODCAB" ); - // Setta i campi che appartengono al file LF_CFVEN - set( m, F_CODABIP, LF_CFVEN, "CODABIPR" ); - set( m, F_CODCABP, LF_CFVEN, "CODCABPR" ); - set( m, F_RAGGR, LF_CFVEN, "RAGGDOC" ); - set( m, F_CODINDSP, LF_CFVEN, "CODINDSP" ); - set( m, F_CODAG, LF_CFVEN, "CODAG" ); - set( m, F_CODSPMEZZO, LF_CFVEN, "CODSPMEZZO" ); - set( m, F_CODPORTO, LF_CFVEN, "CODPORTO" ); - set( m, F_CODNOTESP1, LF_CFVEN, "CODNOTESP1" ); - set( m, F_CODNOTESP2, LF_CFVEN, "CODNOTESP2" ); - set( m, F_CODVETT1, LF_CFVEN, "CODVETT1" ); - set( m, F_CODVETT2, LF_CFVEN, "CODVETT2" ); - set( m, F_CODVETT3, LF_CFVEN, "CODVETT3" ); - set( m, F_SPESEINC, LF_CFVEN, "ADDSPINC" ); - set( m, F_ADDBRB, LF_CFVEN, "ADDBOLLIRB" ); - set( m, F_ADDBTR, LF_CFVEN, "ADDBOLLITR" ); - } - if ( occasionale ( ) ) - { - m.set( F_COFI, "" ); - m.set( F_PAIVA, "" ); - m.set( F_OCFPI, occas_mask( ).get( O_CODICE ) ); - m.set( F_RAGSOC, occas_mask( ).get( O_RAGSOC ) ); - m.set( F_INDCF, occas_mask( ).get( O_INDIRIZZO ) ); - m.set( F_CIVCF, occas_mask( ).get( O_NUMERO ) ); - m.set( F_CAPCF, occas_mask( ).get( O_CAP ) ); - m.set( F_COMCF, occas_mask( ).get( O_COMUNE ) ); - m.set( F_STATOCF, stato = occas_mask( ).get( O_STATO ) ); - } - else - { - set( m, F_COFI, LF_CLIFO, "COFI" ); - set( m, F_INDCF, LF_CLIFO, "INDCF" ); - set( m, F_CIVCF, LF_CLIFO, "CIVCF" ); - set( m, F_STATOPAIVA, LF_CLIFO, "STATOPAIV" ); - set( m, F_PAIVA, LF_CLIFO, "PAIV" ); - set( m, F_LOCALITACF, LF_CLIFO, "LOCALITACF" ); - set( m, F_CAPCF, LF_CLIFO, "CAPCF" ); - set( m, F_COMCF, LF_CLIFO, "COMCF" ); - stato = get( LF_CLIFO, "STATOCF" ); - m.set( F_STATOCF, stato ); - } - if ( !stato.blank( ) ) - m.set( F_DESSTATOCF, get( "%STA", stato, "S0" ) ); - TString16 tmpstr( m.get( F_CODPAG ) ); - if( !tmpstr.blank( ) ) - { - m.field( F_CODPAG ).on_hit( ); - m.field( F_CODPAG ).check( ); - } - tmpstr = m.get( F_CODLIN ); - if( !tmpstr.blank( ) ) - m.field( F_CODLIN ).check( ); - imposta_dati_comune( m ); - imposta_indirizzo_spedizione( m ); - imposta_sconto_testa( m ); -} - -void TCliFor::edita_occasionale( ) -{ - CHECK( occasionale( ), "Impossibile editare come occasionale un cliente non occasionale!" ); - _occas_mask.run( ); -}; - -bool TCliFor::occas_code_handler(TMask_field& f, KEY key) -{ - if (key == K_TAB) - { - const char* code = f.get(); - if (*code) - { - TRelation occas(LF_OCCAS); - occas.lfile().put("CFPI", code); - if (occas.read(_isequal) == NOERR) - { - f.mask().autoload(&occas); - f.mask().send_key(K_TAB, O_COMUNE); // Forza decodifica comuni - f.mask().send_key(K_TAB, O_COMUNENAS); - } - } - } - return TRUE; -} - -void TCliForVendite::imposta_dati_comune( TMask_vendite& m ) -{ - TLocalisamfile comuni(LF_COMUNI); - comuni.setkey( 1 ); - if( occasionale( ) ) - { - comuni.put( "COM", occas_mask( ).get( O_COMUNE )); - comuni.put( "STATO", occas_mask( ).get( O_STATO ) ); - } - else - { - comuni.put( "COM", get( LF_CLIFO, "COMCF" )); - comuni.put( "STATO", get( LF_CLIFO, "STATOCF" ) ); - } - comuni.read( ); - m.set( F_DENCOM, comuni.get( "DENCOM" ) ); - m.set( F_PROVCOM, comuni.get( "PROVCOM" ) ); -} - -void TCliForVendite::imposta_indirizzo_spedizione( TMask_vendite& m ) -{ - TString16 stato; - if( occasionale( ) ) - { - m.set( F_CODINDSP, "" ); - m.disable( F_CODINDSP ); - m.set( F_RAGSOCSP, occas_mask( ).get( O_RAGSOC ) ); - m.set( F_INDSP, occas_mask( ).get( O_INDIRIZZO ) ); - m.set( F_CIVSP, occas_mask( ).get( O_NUMERO ) ); - // Sugli occasionali non c'è la località - m.set( F_LOCALITASP, "" ); - m.set( F_CAPSP, occas_mask( ).get( O_CAP ) ); - m.set( F_COMSP, occas_mask( ).get( O_COMUNE ) ); - m.set( F_STATOSP, stato = occas_mask( ).get( O_STATO ) ); - } - else - { - TString16 codindsp( m.get( F_CODINDSP ) ); - if( codindsp.blank( ) ) - { - m.set( F_RAGSOCSP, "" ); - m.set( F_INDSP, "" ); - m.set( F_CIVSP, "" ); - m.set( F_LOCALITASP, "" ); - m.set( F_CAPSP, "" ); - m.set( F_COMSP, "" ); - m.set( F_STATOSP, "" ); - return; - } - else - { - TLocalisamfile indsped( LF_INDSP ); - indsped.setkey( 1 ); - indsped.put( "TIPOCF", _tipocf ); - indsped.put( "CODCF", _codcf ); - indsped.put( "CODIND", atoi( codindsp ) ); - if( indsped.read( ) != NOERR ) - yesnofatal_box( "Indirizzo di spedizione non trovato!" ); - m.set( F_RAGSOCSP, indsped.get( "RAGSOC" ) ); - m.set( F_INDSP, indsped.get( "INDIR" ) ); - m.set( F_CIVSP, indsped.get( "CIV" ) ); - m.set( F_LOCALITASP, indsped.get( "LOCALITA" ) ); - m.set( F_CAPSP, indsped.get( "CAP" ) ); - m.set( F_COMSP, indsped.get( "COM" ) ); - m.set( F_STATOSP, stato = indsped.get( "STATO" ) ); - } - } - if ( !stato.blank( ) ) - m.set( F_DESSTATOSP, get( "%STA", stato, "S0" ) ); - TLocalisamfile comuni(LF_COMUNI); - comuni.setkey( 1 ); - comuni.put( "COM", m.get( F_COMSP ) ); - comuni.put( "STATO", m.get( F_STATOSP ) ); - comuni.read( ); - m.set( F_DENCOMSP, comuni.get( "DENCOM" ) ); - m.set( F_PROVCOMSP, comuni.get( "PROVCOM" ) ); -} - -void TCliForVendite::imposta_sconto_testa( TMask_vendite& m ) -{ - TConfig ditta( CONFIG_DITTA ); - TString16 codsconto; - TString16 codart; - - char tipogestione = ditta.get( "GESSCO", "ve" )[ 0 ]; - switch( tipogestione ) - { - case 'N': // Sconti non gestiti: pussa via! - return; - break; - case 'P': // Percentuale su anagrafica cliente - m.set( F_SCONTOPERC, get( LF_CFVEN, "SCONTO" ) ); - return; - break; - case 'T': // Gestione tabella sconti - codsconto = get( LF_CFVEN, "CODSCC" ); - if( !codsconto.blank( ) ) - { - TLocalisamfile sconti( LF_SCONTI ); - sconti.setkey( 1 ); - sconti.zero( ); - sconti.put( "TIPO", "D" ); - sconti.put( "CODCAT", codsconto ); - if( sconti.read( ) == NOERR ) - m.set( F_SCONTOPERC, sconti.get( "SCONTO" ) ); - else - message_box( "Sconto non trovato nella tabella sconti!" ); - } - return; - break; - case 'A': // Gestione archivio sconti - TLocalisamfile sconti( LF_SCONTI ); - sconti.setkey( 1 ); - sconti.zero( ); - sconti.put( "TIPO", "I" ); - if( ditta.get_bool( "SCOKEY", "ve", 1 ) ) - { - sconti.put( "CODCAT", get( LF_CFVEN, "CATVEN" ) ); - if( ditta.get_bool( "SCOKEY", "ve", 2 ) ) - { - codart= get( LF_CFVEN, "CODSCC" ); - if( ditta.get_bool( "SCOKEY", "ve", 3 ) ) - { - codart << get( LF_CFVEN, "CODZONA" ); - if( ditta.get_bool( "SCOKEY", "ve", 4 ) ) - codart << get( LF_CLIFO, "CODPAG" ); - } - } - } - sconti.put( "CODART", codart ); - if( sconti.read( ) == NOERR ) - { - m.set( F_SCONTOPERC, sconti.get( "SCONTO" ) ); - } - else - { - message_box( "Sconto non trovato nell'archivio sconti!" ); - } - return; - break; - } -} +#ifndef __TCLIFOR_H +#include "tclifor.h" +#endif + +#ifndef __CONFIG_H +#include "config.h" +#endif + +#ifndef __VEUML1_H +#include "veuml1.h" +#endif + +#ifndef __VE1000O_H +#include "ve1000o.h" +#endif + +const TString& TData_picker::get( const TString& table, const TString& codtab, const TString& field ) +{ + if( table != _tablename ) + { + delete _table; + _table = new TTable( table ); + _tablename = table; + } + if( codtab != _table->curr( ).get( "CODTAB" ) ) + { + _table->zero( ); + _table->put( "CODTAB", codtab ); + _table->read( ); + } + return _table->get( field ); +}; + +const TString& TData_picker::get( const int file, const TString& fieldname ) +{ + return lfile( file ).get( fieldname ); +} + +int TData_picker::get_int( const int file, const TString& fieldname ) +{ + return lfile( file ).get_int( fieldname ); +} + +long TData_picker::get_long( const int file, const TString& fieldname ) +{ + return lfile( file ).get_long( fieldname ); +} + +bool TData_picker::get_bool( const int file, const TString& fieldname ) +{ + return lfile( file ).get_bool( fieldname ); +} + +int TCliFor::write_occas( ) +{ + if( !occasionale( ) ) + return NOERR; + TRelation occas( LF_OCCAS ); + occas_mask( ).autosave( &occas ); + return occas.write( ); +} + +TCliFor::TCliFor( ) : TData_picker( LF_CLIFO ), _occas_mask( "ve1000o" ) +{ + _occas_mask.set_handler( O_CODICE, occas_code_handler ); + add( LF_CFVEN, "TIPOCF=TIPOCF|CODCF=CODCF" ); +} + +void TCliFor::load( const char tipocf, const long codcf, const TString& ocfpi ) +{ + _tipocf = tipocf; + _codcf = codcf; + zero( ); + curr( ).put( "TIPOCF", tipocf ); + curr( ).put( "CODCF", codcf ); + lfile( ).setkey( 1 ); + if( read( ) != NOERR ) + yesnofatal_box( "Il %s %d non è stato trovato!", tipocf == 'C'?"cliente":"fornitore", codcf ); + _occas = curr().get_bool( "OCCAS" ); + if ( occasionale( ) ) + { + TRelation occrel( LF_OCCAS ); + occrel.curr( ).zero( ); + occrel.curr( ).put( "CFPI", ocfpi ); + occrel.read( ); + occas_mask( ).autoload( &occrel ); + } +} + +void TCliForVendite::update_mask( TMask_vendite& m, bool onload ) +{ + TString16 stato; + + // Setta i campi che appartengono al file LF_CLIFO + bool occas = occasionale( ); + m.show( F_OCFPI, occas ); + m.show( F_OCCASEDIT, occas ); + // In forse per l'Occasionale, sicuri per il Normale + m.show( F_COFI, !occas ); + m.show( F_STATOPAIVA, !occas ); + m.show( F_PAIVA, !occas ); + set( m, F_RAGSOC, LF_CLIFO, "RAGSOC" ); + if( !onload ) + { + set( m, F_CODVAL, LF_CLIFO, "CODVAL" ); + set( m, F_CODLIN, LF_CLIFO, "CODLIN" ); + set( m, F_CODPAG, LF_CLIFO, "CODPAG" ); + set( m, F_CODABIA, LF_CLIFO, "CODABI" ); + set( m, F_CODCABA, LF_CLIFO, "CODCAB" ); + // Setta i campi che appartengono al file LF_CFVEN + set( m, F_CODABIP, LF_CFVEN, "CODABIPR" ); + set( m, F_CODCABP, LF_CFVEN, "CODCABPR" ); + set( m, F_RAGGR, LF_CFVEN, "RAGGDOC" ); + set( m, F_CODINDSP, LF_CFVEN, "CODINDSP" ); + set( m, F_CODAG, LF_CFVEN, "CODAG" ); + set( m, F_CODSPMEZZO, LF_CFVEN, "CODSPMEZZO" ); + set( m, F_CODPORTO, LF_CFVEN, "CODPORTO" ); + set( m, F_CODNOTESP1, LF_CFVEN, "CODNOTESP1" ); + set( m, F_CODNOTESP2, LF_CFVEN, "CODNOTESP2" ); + set( m, F_CODVETT1, LF_CFVEN, "CODVETT1" ); + set( m, F_CODVETT2, LF_CFVEN, "CODVETT2" ); + set( m, F_CODVETT3, LF_CFVEN, "CODVETT3" ); + set( m, F_SPESEINC, LF_CFVEN, "ADDSPINC" ); + set( m, F_ADDBRB, LF_CFVEN, "ADDBOLLIRB" ); + set( m, F_ADDBTR, LF_CFVEN, "ADDBOLLITR" ); + } + if ( occasionale ( ) ) + { + m.set( F_COFI, "" ); + m.set( F_PAIVA, "" ); + m.set( F_OCFPI, occas_mask( ).get( O_CODICE ) ); + m.set( F_RAGSOC, occas_mask( ).get( O_RAGSOC ) ); + m.set( F_INDCF, occas_mask( ).get( O_INDIRIZZO ) ); + m.set( F_CIVCF, occas_mask( ).get( O_NUMERO ) ); + m.set( F_CAPCF, occas_mask( ).get( O_CAP ) ); + m.set( F_COMCF, occas_mask( ).get( O_COMUNE ) ); + m.set( F_STATOCF, stato = occas_mask( ).get( O_STATO ) ); + } + else + { + set( m, F_COFI, LF_CLIFO, "COFI" ); + set( m, F_INDCF, LF_CLIFO, "INDCF" ); + set( m, F_CIVCF, LF_CLIFO, "CIVCF" ); + set( m, F_STATOPAIVA, LF_CLIFO, "STATOPAIV" ); + set( m, F_PAIVA, LF_CLIFO, "PAIV" ); + set( m, F_LOCALITACF, LF_CLIFO, "LOCALITACF" ); + set( m, F_CAPCF, LF_CLIFO, "CAPCF" ); + set( m, F_COMCF, LF_CLIFO, "COMCF" ); + stato = get( LF_CLIFO, "STATOCF" ); + m.set( F_STATOCF, stato ); + } + if ( !stato.blank( ) ) + m.set( F_DESSTATOCF, get( "%STA", stato, "S0" ) ); + m.check_field( F_CODPAG ); + m.check_field( F_CODLIN ); + // m.check_field( F_CODABIA ); + m.check_field( F_CODCABA ); + // m.check_field( F_CODABIP ); + m.check_field( F_CODCABP ); + m.check_field( F_CODINDSP ); + m.check_field( F_CODAG ); + m.check_field( F_CODSPMEZZO ); + m.check_field( F_CODPORTO ); + m.check_field( F_CODNOTESP1 ); + m.check_field( F_CODNOTESP2 ); + m.check_field( F_CODVETT1 ); + m.check_field( F_CODVETT2 ); + m.check_field( F_CODVETT3 ); + imposta_dati_comune( m ); + imposta_indirizzo_spedizione( m ); + imposta_sconto_testa( m ); + imposta_valuta( m ); +} + +void TCliFor::edita_occasionale( ) +{ + CHECK( occasionale( ), "Impossibile editare come occasionale un cliente non occasionale!" ); + _occas_mask.run( ); +}; + +bool TCliFor::occas_code_handler(TMask_field& f, KEY key) +{ + if (key == K_TAB) + { + const char* code = f.get(); + if (*code) + { + TRelation occas(LF_OCCAS); + occas.lfile().put("CFPI", code); + if (occas.read(_isequal) == NOERR) + { + f.mask().autoload(&occas); + f.mask().send_key(K_TAB, O_COMUNE); // Forza decodifica comuni + f.mask().send_key(K_TAB, O_COMUNENAS); + } + } + } + return TRUE; +} + +void TCliForVendite::imposta_dati_comune( TMask_vendite& m ) +{ + TLocalisamfile comuni(LF_COMUNI); + comuni.setkey( 1 ); + if( occasionale( ) ) + { + comuni.put( "COM", occas_mask( ).get( O_COMUNE )); + comuni.put( "STATO", occas_mask( ).get( O_STATO ) ); + } + else + { + comuni.put( "COM", get( LF_CLIFO, "COMCF" )); + comuni.put( "STATO", get( LF_CLIFO, "STATOCF" ) ); + } + comuni.read( ); + m.set( F_DENCOM, comuni.get( "DENCOM" ) ); + m.set( F_PROVCOM, comuni.get( "PROVCOM" ) ); +} + +void TCliForVendite::imposta_indirizzo_spedizione( TMask_vendite& m ) +{ + TString16 stato; + if( occasionale( ) ) + { + m.set( F_CODINDSP, "" ); + m.disable( F_CODINDSP ); + m.set( F_RAGSOCSP, occas_mask( ).get( O_RAGSOC ) ); + m.set( F_INDSP, occas_mask( ).get( O_INDIRIZZO ) ); + m.set( F_CIVSP, occas_mask( ).get( O_NUMERO ) ); + // Sugli occasionali non c'è la località + m.set( F_LOCALITASP, "" ); + m.set( F_CAPSP, occas_mask( ).get( O_CAP ) ); + m.set( F_COMSP, occas_mask( ).get( O_COMUNE ) ); + m.set( F_STATOSP, stato = occas_mask( ).get( O_STATO ) ); + } + else + { + TString16 codindsp( m.get( F_CODINDSP ) ); + if( codindsp.blank( ) ) + { + m.set( F_RAGSOCSP, "" ); + m.set( F_INDSP, "" ); + m.set( F_CIVSP, "" ); + m.set( F_LOCALITASP, "" ); + m.set( F_CAPSP, "" ); + m.set( F_COMSP, "" ); + m.set( F_STATOSP, "" ); + return; + } + else + { + TLocalisamfile indsped( LF_INDSP ); + indsped.setkey( 1 ); + indsped.put( "TIPOCF", _tipocf ); + indsped.put( "CODCF", _codcf ); + indsped.put( "CODIND", atoi( codindsp ) ); + if( indsped.read( ) != NOERR ) + yesnofatal_box( "Indirizzo di spedizione non trovato!" ); + m.set( F_RAGSOCSP, indsped.get( "RAGSOC" ) ); + m.set( F_INDSP, indsped.get( "INDIR" ) ); + m.set( F_CIVSP, indsped.get( "CIV" ) ); + m.set( F_LOCALITASP, indsped.get( "LOCALITA" ) ); + m.set( F_CAPSP, indsped.get( "CAP" ) ); + m.set( F_COMSP, indsped.get( "COM" ) ); + m.set( F_STATOSP, stato = indsped.get( "STATO" ) ); + } + } + if ( !stato.blank( ) ) + m.set( F_DESSTATOSP, get( "%STA", stato, "S0" ) ); + TLocalisamfile comuni(LF_COMUNI); + comuni.setkey( 1 ); + comuni.put( "COM", m.get( F_COMSP ) ); + comuni.put( "STATO", m.get( F_STATOSP ) ); + comuni.read( ); + m.set( F_DENCOMSP, comuni.get( "DENCOM" ) ); + m.set( F_PROVCOMSP, comuni.get( "PROVCOM" ) ); +} + +void TCliForVendite::imposta_sconto_testa( TMask_vendite& m ) +{ + TConfig ditta( CONFIG_DITTA ); + TString16 codsconto; + TString16 codart; + + char tipogestione = ditta.get( "GESSCO", "ve" )[ 0 ]; + switch( tipogestione ) + { + case 'N': // Sconti non gestiti: pussa via! + return; + break; + case 'P': // Percentuale su anagrafica cliente + m.set( F_SCONTOPERC, get( LF_CFVEN, "SCONTO" ) ); + return; + break; + case 'T': // Gestione tabella sconti + codsconto = get( LF_CFVEN, "CODSCC" ); + if( !codsconto.blank( ) ) + { + // ARCHIVIO SVCONTI PER SCONTO CLIENTE + // TLocalisamfile sconti( LF_SCONTI ); + // sconti.setkey( 1 ); + // sconti.zero( ); + // sconti.put( "TIPO", "D" ); + // sconti.put( "CODCAT", codsconto ); + // if( sconti.read( ) == NOERR ) + // m.set( F_SCONTOPERC, sconti.get( "SCONTO" ) ); + // else + // message_box( "Sconto non trovato nella tabella sconti!" ); + TTable sconti( "%SCC" ); + sconti.setkey( 1 ); + sconti.zero( ); + // sconti.put( "TIPO", "D" ); + sconti.put( "CODTAB", codsconto ); + if( sconti.read( ) == NOERR ) + m.set( F_SCONTOPERC, sconti.get( "S1" ) ); + #ifdef DBG + else + message_box( "Sconto non trovato nella tabella sconti!" ); + #endif + } + return; + break; + case 'A': // Gestione archivio sconti + TLocalisamfile sconti( LF_SCONTI ); + sconti.setkey( 1 ); + sconti.zero( ); + sconti.put( "TIPO", "I" ); + if( ditta.get_bool( "SCOKEY", "ve", 1 ) ) + sconti.put( "CODCAT", get( LF_CFVEN, "CATVEN" ) ); + if( ditta.get_bool( "SCOKEY", "ve", 2 ) ) + codart << get( LF_CFVEN, "CODSCC" ); + else + codart << " "; + if( ditta.get_bool( "SCOKEY", "ve", 3 ) ) + codart << get( LF_CFVEN, "CODZONA" ); + else + codart << " "; + if( ditta.get_bool( "SCOKEY", "ve", 4 ) ) + codart << get( LF_CLIFO, "CODPAG" ); + sconti.put( "CODART", codart ); + if( sconti.read( ) == NOERR ) + m.set( F_SCONTOPERC, sconti.get( "SCONTO" ) ); + #ifdef DBG + else + message_box( FALSE, "Sconto non trovato nell'archivio sconti!" ); + #endif + return; + break; + } +} + +void TCliForVendite::imposta_valuta( TMask_vendite& m ) +{ + + TConfig ditta( CONFIG_DITTA ); + + if( ditta.get_bool( "GESVALAC", "ve" ) ) + { + TTable cambi( "%CAM" ); + cambi.zero( ); + TString16 val( m.get( F_CODVAL ) ); + TString16 codtab( ( const char * ) val ); + codtab << m.get( F_DATADOC ); + cambi.put( "CODTAB", codtab ); + const int result = cambi.read( _isgteq ); + if( result == _iseof ) + cambi.prev( ); + codtab = cambi.get( "CODTAB" ); + if ( codtab.sub( 0, 2 ) == val ) + { + m.set( F_CAMBIO, cambi.get( "R10" ) ); + m.set( F_DATACAMBIO, cambi.get( "D0" ) ); + return; + } + } + TTable valuta( "VAL" ); + valuta.zero( ); + valuta.put( "CODTAB", m.get( F_CODVAL ) ); + if( valuta.read( ) == NOERR ) + { + m.set( F_CAMBIO, valuta.get( "R10" ) ); + m.set( F_DATACAMBIO, valuta.get( "D0" ) ); + } +} diff --git a/ve/tclifor.h b/ve/tclifor.h index b23b191ce..19b42d969 100755 --- a/ve/tclifor.h +++ b/ve/tclifor.h @@ -1,73 +1,76 @@ -#ifndef __TCLIFOR_H -#define __TCLIFOR_H - -#ifndef __CHECKS_H -#include -#endif - -#ifndef __RELATION_H -#include -#endif - -#ifndef __TABUTIL_H -#include -#endif - - -#ifndef __TMASKVEN_H -#include "tmaskven.h" -#endif - -class TData_picker : public TRelation -{ -private: - - TTable* _table; - TString16 _tablename; - -public: - TData_picker( const int mainfile ) : TRelation ( mainfile ) { } - const TString& get( const TString& table, const TString& codtab, const TString& field ); - const TString& get( const int file, const TString& fieldname ); - int get_int( const int file, const TString& fieldname ); - long get_long( const int file, const TString& fieldname ); - bool get_bool( const int file, const TString& fieldname ); - void set( TMask_vendite& m, const int mskfield, const int file, const TString& filefield ){ m.set( mskfield, get( file, filefield ) ); }; -}; - -class TCliFor : public TData_picker -{ - private: - - bool _occas; - TMask _occas_mask; - - protected: - - char _tipocf; - long _codcf; - - public: - - TCliFor( ); - void load( const char tipocf, const long codcf, const TString& ocfpi ); - bool occasionale( ){ return get_bool( LF_CLIFO, "OCCAS" ); }; - TMask& occas_mask( ){ return _occas_mask; }; - static bool occas_code_handler(TMask_field& f, KEY key); - int write_occas( ); - void edita_occasionale( ); -}; - -class TCliForVendite : public TCliFor -{ - - public: - - void update_mask( TMask_vendite& m, bool onload = FALSE ); - void imposta_dati_comune( TMask_vendite& m ); - void imposta_indirizzo_spedizione( TMask_vendite& m ); - void imposta_sconto_testa( TMask_vendite& m ); - -}; - -#endif +#ifndef __TCLIFOR_H +#define __TCLIFOR_H + +#ifndef __CHECKS_H +#include +#endif + +#ifndef __RELATION_H +#include +#endif + +#ifndef __TABUTIL_H +#include +#endif + + +#ifndef __TMASKVEN_H +#include "tmaskven.h" +#endif + +class TData_picker : public TRelation +{ +private: + + TTable* _table; + TString16 _tablename; + +public: + TData_picker( const int mainfile ) : TRelation ( mainfile ) { } + const TString& get( const TString& table, const TString& codtab, const TString& field ); + const TString& get( const int file, const TString& fieldname ); + int get_int( const int file, const TString& fieldname ); + long get_long( const int file, const TString& fieldname ); + bool get_bool( const int file, const TString& fieldname ); + void set( TMask_vendite& m, const int mskfield, const int file, const TString& filefield ){ m.set( mskfield, get( file, filefield ) ); }; +}; + +class TCliFor : public TData_picker +{ +private: + + bool _occas; + TMask _occas_mask; + +protected: + + char _tipocf; + long _codcf; + +public: + + TCliFor( ); + void load( const char tipocf, const long codcf, const TString& ocfpi ); + bool occasionale( ){ return get_bool( LF_CLIFO, "OCCAS" ); }; + TMask& occas_mask( ){ return _occas_mask; }; + static bool occas_code_handler(TMask_field& f, KEY key); + int write_occas( ); + void edita_occasionale( ); + char tipocf( ){ return _tipocf; } + long codcf( ){ return _codcf; } +}; + +class TCliForVendite : public TCliFor +{ + +public: + + void update_mask( TMask_vendite& m, bool onload = FALSE ); + void imposta_dati_comune( TMask_vendite& m ); + void imposta_valuta( TMask_vendite& m ); + void imposta_indirizzo_spedizione( TMask_vendite& m ); + void imposta_sconto_testa( TMask_vendite& m ); + +}; + +#endif diff --git a/ve/totale.ini b/ve/totale.ini index 63d89d175..7e8eb42ee 100755 --- a/ve/totale.ini +++ b/ve/totale.ini @@ -1,243 +1,243 @@ -# Esempio di profilo documento : Profilo Bolla Vendita - -[MAIN] - -# Descrizione a caratteri del documento -TYPE=Bolla Base - -# Dove sono le risorse per il documento -MSKFILE=VEBOLLAC -FRMFILE=BOLLAC.FRM -PROGPIEDE=31|35 -# Procedure utente da chiamare per il documento ( preprocessarle? ) -NUOVO=1 -MODIFICA=5 -CANCELLA=12 -STAMPA=4 -RAGGRUPPA=3 -USER=2 - -# Indica se il documento è indirizzato ad un cliente o ad un fornitore -TIPOCF=C - -# Quali progressivi appaiono in stampa o visualizzazione del documento -ProgPiede=1,7,23,12 - -[INSERIMENTO] - -# Stati in cui è possibile effettuare la operazione -STATIVALIDI=1,2,3,4,5,6,7,8,9 - -# Stato finale del documento dopo la operazione -STATOFINALE=1 - -[MODIFICA] - -# Stati in cui è possibile effettuare la operazione -STATIVALIDI=1,2,3,4,5 - -# Stato finale del documento dopo la operazione -STATOFINALE=N - -[CANCELLAZIONE] -STATIVALIDI = 6,7 -STATOFINALE = 4 -REMOVE = 0 - -[STAMPA] - -# Stati in cui è possibile effettuare la operazione -STATIVALIDI=1,2,3,4,5 - -# Stato finale del documento dopo la operazione -STATOFINALE=6 - -[RAGGRUPPA] - -# Stati in cui è possibile effettuare la operazione -STATIVALIDI=6,7,8,9 - -# Stato finale del documento dopo la operazione -STATOFINALE=1 - -[SPECIALE] - -# Stati in cui è possibile effettuare la operazione -STATIVALIDI=1,2,3,4,5,6,7,8,9 - -# Stato finale del documento dopo la operazione -STATOFINALE=9 - -[PROFILO] -TIPOCF = 2 -CODCF = 3 -RAGSOC = 2 -OCCAS = 0 -OCFPI = 1 -COFI = 1 -STATOPAIV = 1 -PAIVA = 1 -INDCF = 1 -CIVCF = 1 -LOCALITACF = 1 -CAPCF = 1 -PROVCOM = 1 -COMCF = 1 -DENCOM = 1 -STATOCF = 1 -DESSTATOCF = 1 -CODVAL = 2 -NOME_VAL = 1 -CAMBIO = 3 -DATA_CAMBIO = 1 -CODLIN = 2 -DESLIN = 1 -CODPAG = 3 -DESCODPAG = 1 -DATAINSC = 2 -DATASCAD1 = 1 -DATASCAD2 = 1 -DATASCAD3 = 1 -DATASCAD4 = 1 -DATASCAD5 = 1 -CODABIA = 3 -CODCABA = 3 -DESBANAPP = 2 -CODABIP = 2 -CODCABP = 2 -DESBANPRE = 2 -CODLIST = 2 -CODCONT = 2 -CODCAMP = 2 -SCONTOPERC = 2 -CODINDSP = 2 -INDSP = 2 -CIVSP = 2 -LOCALITASP = 2 -CAPSP = 2 -COMSP = 2 -DENCOMSP = 2 -PROVCOMSP = 2 -STATOSP = 2 -DESSTATOSP = 2 -DATADOCRIF = 2 -NUMDOCRIF = 2 -CODAGVIS = 2 -CODAG = 2 -CODSPMEZZO = 2 -CODPORTO = 2 -PORTO = 2 -CODNOTESP1 = 2 -CODNOTESP2 = 2 -CAUSTRASP = 2 -DENCAUSTRASP = 2 -CODVETT1 = 2 -CODVETT2 = 2 -CODVETT3 = 2 -NOMEVETT1 = 2 -NOMEVETT2 = 2 -NOMEVETT3 = 2 -NCOPIE = 2 -DATAPART = 2 -ORAPART = 2 -IMPPAGATO = 2 -ACCSALDO = 2 -DOC1 = 2 -DOC2 = 2 -DOC3 = 2 -DATACONS = 2 -ASPBENI1 = 2 -DESCRBENI1 = 2 -ASPBENI2 = 2 -DESCRBENI2 = 2 -IMPNETTI = 2 -RAGGREFF = 2 -SPESEINC = 2 -ADDBRB = 2 -ADDBTR = 2 -ADDBDE = 2 -CODIVABRB = 2 -CODIVABTR = 2 -CODIVABTRE = 2 -CODIVABDE = 2 - -# fine modifiche - -CAUSMAG2 = 2 -TARA = 2 -PNETTO = 2 -UMTARA = 2 -RAGGR = 2 -CAUSMAG1 = 2 -NCOLLI = 2 -RAGSOCSP = 2 -CODIVAABRB = 3 -UMPNETTO = 2 -DESUMPNETTO = 2 -DESUMTARA = 2 -DESCRMAG1 = 2 -DESCRMAG2 = 2 -OCCASEDIT = 2 - -[SHEET] -NCOLS=4 -1=2 -2=5 -3=6||30 -4=9 -5=10 -6=13 -7=8 - -[RIGHE] -NTIPIRIGA=3 -1=01 -2=02 -3=03 - - - -[HANDLERS] -NHANDLER=0 -1 = 140|1 -2 = 108|2 -3 = 111|3 -3 = 113|3 -3 = 115|3 -3 = 117|3 -3 = 118|3 - -[PROFILOGRUPPO] - = -1000 = 0 -2000 = 0 -1400 = 0 -2400 = 0 -1800 = 0 -2800 = -1100 = 0 -2100 = 0 -1500 = 0 -2500 = 0 -1900 = 0 -2900 = -1200 = 0 -2200 = 0 -29 = -1600 = 0 -2600 = 0 -101 = 0 -100 = 2 -200 = 2 -300 = 2 -400 = 2 -500 = 2 -600 = 2 -1300 = 0 -700 = 2 -2300 = 0 -800 = 2 -900 = 2 -1700 = 0 -2700 = - +# Esempio di profilo documento : Profilo Bolla Vendita + +[MAIN] + +# Descrizione a caratteri del documento +TYPE=Bolla Base + +# Dove sono le risorse per il documento +MSKFILE=VEBOLLAC +FRMFILE=BOLLAC.FRM +PROGPIEDE=31|35 +# Procedure utente da chiamare per il documento ( preprocessarle? ) +NUOVO=1 +MODIFICA=5 +CANCELLA=12 +STAMPA=4 +RAGGRUPPA=3 +USER=2 + +# Indica se il documento è indirizzato ad un cliente o ad un fornitore +TIPOCF=C + +# Quali progressivi appaiono in stampa o visualizzazione del documento +ProgPiede=1,7,23,12 + +[INSERIMENTO] + +# Stati in cui è possibile effettuare la operazione +STATIVALIDI=1,2,3,4,5,6,7,8,9 + +# Stato finale del documento dopo la operazione +STATOFINALE=1 + +[MODIFICA] + +# Stati in cui è possibile effettuare la operazione +STATIVALIDI=1,2,3,4,5 + +# Stato finale del documento dopo la operazione +STATOFINALE=N + +[CANCELLAZIONE] +STATIVALIDI = 6,7 +STATOFINALE = 4 +REMOVE = 0 + +[STAMPA] + +# Stati in cui è possibile effettuare la operazione +STATIVALIDI=1,2,3,4,5 + +# Stato finale del documento dopo la operazione +STATOFINALE=6 + +[RAGGRUPPA] + +# Stati in cui è possibile effettuare la operazione +STATIVALIDI=6,7,8,9 + +# Stato finale del documento dopo la operazione +STATOFINALE=1 + +[SPECIALE] + +# Stati in cui è possibile effettuare la operazione +STATIVALIDI=1,2,3,4,5,6,7,8,9 + +# Stato finale del documento dopo la operazione +STATOFINALE=9 + +[PROFILO] +TIPOCF = 2 +CODCF = 3 +RAGSOC = 2 +OCCAS = 0 +OCFPI = 1 +COFI = 1 +STATOPAIV = 1 +PAIVA = 1 +INDCF = 1 +CIVCF = 1 +LOCALITACF = 1 +CAPCF = 1 +PROVCOM = 1 +COMCF = 1 +DENCOM = 1 +STATOCF = 1 +DESSTATOCF = 1 +CODVAL = 2 +NOME_VAL = 1 +CAMBIO = 3 +DATA_CAMBIO = 1 +CODLIN = 2 +DESLIN = 1 +CODPAG = 3 +DESCODPAG = 1 +DATAINSC = 2 +DATASCAD1 = 1 +DATASCAD2 = 1 +DATASCAD3 = 1 +DATASCAD4 = 1 +DATASCAD5 = 1 +CODABIA = 3 +CODCABA = 3 +DESBANAPP = 2 +CODABIP = 2 +CODCABP = 2 +DESBANPRE = 2 +CODLIST = 2 +CODCONT = 2 +CODCAMP = 2 +SCONTOPERC = 2 +CODINDSP = 2 +INDSP = 2 +CIVSP = 2 +LOCALITASP = 2 +CAPSP = 2 +COMSP = 2 +DENCOMSP = 2 +PROVCOMSP = 2 +STATOSP = 2 +DESSTATOSP = 2 +DATADOCRIF = 2 +NUMDOCRIF = 2 +CODAGVIS = 2 +CODAG = 2 +CODSPMEZZO = 2 +CODPORTO = 2 +PORTO = 2 +CODNOTESP1 = 2 +CODNOTESP2 = 2 +CAUSTRASP = 2 +DENCAUSTRASP = 2 +CODVETT1 = 2 +CODVETT2 = 2 +CODVETT3 = 2 +NOMEVETT1 = 2 +NOMEVETT2 = 2 +NOMEVETT3 = 2 +NCOPIE = 2 +DATAPART = 2 +ORAPART = 2 +IMPPAGATO = 2 +ACCSALDO = 2 +DOC1 = 2 +DOC2 = 2 +DOC3 = 2 +DATACONS = 2 +ASPBENI1 = 2 +DESCRBENI1 = 2 +ASPBENI2 = 2 +DESCRBENI2 = 2 +IMPNETTI = 2 +RAGGREFF = 2 +SPESEINC = 2 +ADDBRB = 2 +ADDBTR = 2 +ADDBDE = 2 +CODIVABRB = 2 +CODIVABTR = 2 +CODIVABTRE = 2 +CODIVABDE = 2 + +# fine modifiche + +CAUSMAG2 = 2 +TARA = 2 +PNETTO = 2 +UMTARA = 2 +RAGGR = 2 +CAUSMAG1 = 2 +NCOLLI = 2 +RAGSOCSP = 2 +CODIVAABRB = 3 +UMPNETTO = 2 +DESUMPNETTO = 2 +DESUMTARA = 2 +DESCRMAG1 = 2 +DESCRMAG2 = 2 +OCCASEDIT = 2 + +[SHEET] +NCOLS=4 +1=2 +2=5 +3=6||30 +4=9 +5=10 +6=13 +7=8 + +[RIGHE] +NTIPIRIGA=3 +1=01 +2=02 +3=03 + + + +[HANDLERS] +NHANDLER=0 +1 = 140|1 +2 = 108|2 +3 = 111|3 +3 = 113|3 +3 = 115|3 +3 = 117|3 +3 = 118|3 + +[PROFILOGRUPPO] + = +1000 = 0 +2000 = 0 +1400 = 0 +2400 = 0 +1800 = 0 +2800 = +1100 = 0 +2100 = 0 +1500 = 0 +2500 = 0 +1900 = 0 +2900 = +1200 = 0 +2200 = 0 +29 = +1600 = 0 +2600 = 0 +101 = 0 +100 = 2 +200 = 2 +300 = 2 +400 = 2 +500 = 2 +600 = 2 +1300 = 0 +700 = 2 +2300 = 0 +800 = 2 +900 = 2 +1700 = 0 +2700 = + diff --git a/ve/ve0100.cpp b/ve/ve0100.cpp index 8d72e9ace..35c694a84 100755 --- a/ve/ve0100.cpp +++ b/ve/ve0100.cpp @@ -1,1269 +1,1009 @@ -#include - -#ifndef __CHECKS_H -#include -#endif - -#ifndef __TABUTIL_H -#include -#endif - -#ifndef __BRWAPP_H -#include -#endif - -#ifndef __RELAPP_H -#include -#endif - -#ifndef __CONFIG_H -#include -#endif - -#ifndef __LFFILES_H -#include -#endif - -#ifndef __DEFMASK_H -#include "defmask.h" -#endif - -#ifndef __VEUML_H -#include "veuml.h" -#endif - -#ifndef __VEUML1_H -#include "veuml1.h" -#endif - -#ifndef __SHEET_H -#include -#endif - -#ifndef __REAL_H -#include -#endif - -#ifndef __MSKSHEET_H -#include -#endif - -#ifndef __VE0100_H -#include "ve0100.h" -#endif - -#ifndef __VE0100C_H -#include "ve0100c.h" -#endif - -#ifndef __VE0100D_H -#include "ve0100d.h" -#endif - -#ifndef __TCLIFOR_H -#include "tclifor.h" -#endif - -#ifndef __VE1000O_H -#include "ve1000o.h" -#endif - -#ifndef __TMASKVEN_H -#include "tmaskven.h" -#endif - -#ifndef __EXECP_H -#include "execp.h" -#endif - -#ifndef __SCONTI_H -#include "sconti.h" -#endif - - -#define CHANGE_MESSAGE "Sono state effettuate modifiche alla configurazione.\nPrima di eseguire la gestione documenti occorrerà rigenerare le maschere.\nDesideri farlo ora ?" - - - -// Numero di colonne presenti sullo sheet totale -#define MAX_COLUMNS 22 - -#define F_LBTIPORIGA 175 -#define NPIEDI 40 - -typedef real array_piede[ NPIEDI ]; - -// Definizione della classe dell'applicazione motore -class TMotore_application : public TRelation_application -{ - // Array di totalizzatori - array_piede _piedi; - array_piede _piedi_temp; - - // Record array per la gestione delle righe - TRecord_array* _righe_rec; - - // Puntatore al profilo del documento caricato - TConfig* _pro; - - // Puntatore al nome, per evitare di ricrearlo se è uguale - TFilename* _proname; - - // Puntatore alla maschera di ricerca - TMask* _msk; - - // Puntatore alla maschera di modifica/inserimento ( dipende dal profilo ) - TMask_vendite* _msk1; - - // puntatore alla relazione - TRelation* _rel; - - // Puntatore allo sheet delle righe documento - TSheet_field* _sheet; - - // Oggetto cliente per il motore - TCliForVendite* _clifor; - - // Indica se il documento ha come soggetto un liente o un ornitore - char _tipocf; - - // Ridefinizione dei metodi virtuali - virtual bool user_create( ); - virtual bool user_destroy( ); - virtual TMask* get_mask(int mode); - virtual bool changing_mask(int mode); - virtual TRelation* get_relation( ) const { return _rel;} - virtual void init_insert_mode( TMask& m ); - virtual int read( TMask& m ); - virtual bool remove( void ); - virtual int write(const TMask& m); - virtual int rewrite(const TMask& m); - - // Punti di ingresso per le funzioni utente - - // Funzioni da associare ad ogni procedura - int user_function( int index ); - - // Funzioni per il calcolo delle righe - real user_row_calculate( TRectype& row, int index ); - - void user_set_handler( int fieldid, int index, TMask* m = NULL ); - - long prossimo_numero( bool provv ); - int avanza_numero( bool provv ); - void get_edit_mask( void ); - void azzera_piedi( bool temp = FALSE ); - void carica_piedi( ); - void somma_piedi( ); - void sottrai_piedi( ); - - // Esegue, se c'è, la procedura utente relativa ad una certa operazione - int esegui_procedura( int operazione ); - -protected: - - // Procedure e funzioni per la gestione della maschera e dei files - void read_rdoc(TMask& m); - - // formato dipendente dallo sheet (sono le varie colonne) - void load_riga( TSheet_field& f, int numrig, TRectype& r ); - void store_riga( TSheet_field& f, int numrig, TRectype& r ); - - void save(TRelation* r) const; - void set_descr (int numrig, const char* descr); - void carica_righe_libere(int from = -1); - bool check_key( TLocalisamfile& rdoc, TString16 codnum, bool provv, TString16 _anno, TString16 _ndoc ); - - // Procedure e funzioni per la gestione degli stati - void setta_stato_corrente( int nuovostato ); - const char* nome_sezione( int op ); - int stato_corrente( ); - int stato_finale( int operazione ); - bool stato_valido( int stato, int operazione ); - void segnala_stato_non_valido( int operazione ); - TString& stati_validi( int operazione ){ return ( pro( ).get( "STATIVALIDI", nome_sezione( operazione ) ) );}; - - void calcola_riga( TRectype& rdoc, bool temp = FALSE ); - - // Handle che ritorna la maschera per le righe - static TMask * ss_getmask( int numriga, TMask& fullmask, bool destroy ); - - // Handler che gestisce la richiesta del tipo riga in inserimento - static bool ss_handler( TSheet_field& ss, int r, KEY key ); - - // Handler per la maschera di ricerca - static bool ndoc_handler(TMask_field& f, KEY key); - static bool num_handler(TMask_field& f, KEY key); - static bool tip_handler(TMask_field& f, KEY key); - - // Handler per la maschera di modifica - static bool clifo_handler(TMask_field& f, KEY key); - static bool occas_handler(TMask_field& f, KEY key); - - // Configurazione dello sheet dato il profilo - void configura_sheet( TSheet_field& sheet, TConfig& config ); - -public: - - // Funzioni di accesso alle variabili privste - - TRecord_array& righe_rec( ) { CHECK( _righe_rec, "Record array delle righe nullo!" ); return * _righe_rec; }; - TConfig& pro( ) { CHECK( _pro, "Profilo del documento nullo!" ); return *_pro; }; - TFilename& proname( ) { CHECK( _proname, "Nome del profilo nullo!" ); return *_proname; }; - TMask& query_mask( ) { CHECK( _msk, "Maschera di ricerca nulla!" ); return *_msk; }; - TMask& edit_mask( ) { CHECK( _msk1, "Maschera di modifica nulla!" ); return *_msk1; }; - TRelation& rel( ) { CHECK( _rel, "Relazione nulla!" ); return *_rel; }; - TSheet_field& sheet( ) { CHECK( _sheet, "Sheet nullo!" ); return *_sheet; }; - TCliForVendite& clifo( ) { CHECK( _clifor, "Oggetto cliente nullo!" ); return *_clifor; }; - - // Operazione - - const char tipocf( ){ return _tipocf; } - void tipocf( const char tcf ){ _tipocf = tcf; } - bool valida_operazione( int operazione ); - - TSheet_field& ss( ) const { return *_sheet; } - TMotore_application( ) { _pro = NULL; } - virtual ~TMotore_application( ) { if ( _pro ) delete _pro; } - virtual const char* get_next_key( ); - -}; - -HIDDEN TMotore_application& app( ) { return (TMotore_application&) main_app( ); } - -void TMotore_application::init_insert_mode( TMask& m ) -{ - m.set( F_DATAINSC, m.get( F_DATADOC ) ); - m.reset( ); - clifo( ).occas_mask( ).reset( ); -}; - -int TMotore_application::user_function( int index ) -{ - switch( index ) - { - case 1: - break; - default: - yesnofatal_box( "Chiamata ad una procedura utente non definita: %d", index ); - return NOERR; - break; - }; - return NOERR; -}; - -// Funzione che dato il profilo di riga ottiene la maschera -// Serve per ottenere una maschera diversa per ogni riga -// Da migliorare, mettendo una cache - -TMask *TMotore_application::ss_getmask( int numriga, TMask& fullmask, bool destroy ) -{ - static TMask* m; - - if ( destroy ) - { - delete m; - return( NULL ); - } - else - { - TFilename nome_proriga( fullmask.get( 103 ) ); - nome_proriga.ext( "ini" ); - TConfig proriga( nome_proriga ); - m = new TMask( proriga.get( "MSK", "MAIN" ) ); - int numhandler = proriga.get_int( "NHANDLER", "HANDLERS" ); - for( int i = 1; i <= numhandler; i ++ ) - { - TString chiave; - chiave.format( "%d", i ); - TToken_string riga = proriga.get( chiave, "HANDLERS" ); - app().user_set_handler( riga.get_int( 0 ), riga.get_int( 1 ), m ); - }; - return( m ); - } -} - -real TMotore_application::user_row_calculate( TRectype& r, int index ) -{ - switch( index ) - { - case 100: - return( f100( r ) ); - break; - case 200: - return( f200( r ) ); - break; - case 300: - return( f300( r ) ); - break; - case 400: - return( f400( r ) ); - break; - case 500: - return( f500( r ) ); - break; - case 600: - return( f600( r ) ); - break; - default: - CHECK( FALSE, "Tentativo di chiamare una funzione di calcolo riga inesistente!" ); - return 0.0; - } -}; - -void TMotore_application::user_set_handler( int fieldid, int index, TMask* m ) -{ - if( !m ) - m = &edit_mask( ); - switch( index ) - { - case 1: - m->set_handler( fieldid, ora_hndl ); - break; - case 2: - m->set_handler( fieldid, codcli_hndl ); - break; - case 3: - m->set_handler( fieldid, dummy_hndl ); - break; - default: - CHECK( FALSE, "Tentativo di installare un handler non definito" ); - break; - } -}; - -bool TMotore_application::ss_handler( TSheet_field& ss, int r, KEY key ) -{ - if ( key == K_SPACE ) // Inizio modifica - { - app().azzera_piedi( TRUE ); - TRelation rdoc( LF_RIGHEDOC ); - ss.sheet_mask( ).autosave( &rdoc ); - // Mi calcolo nei piedi temporanei la riga - app().calcola_riga( rdoc.curr( ), TRUE ); - } - if ( key == K_TAB ) // Mi posiziono su di una riga nello sheet - { - TRelation rdoc( LF_RIGHEDOC ); - TToken_string riga( ss.row( r ) ); - rdoc.curr( ).zero( ); - rdoc.curr( ).put( "CODNUM", app( ).edit_mask( ).get( F_CODNUM ) ); - rdoc.curr( ).put( "ANNO", app( ).edit_mask( ).get( F_ANNO ) ); - rdoc.curr( ).put( "PROVV", app( ).edit_mask( ).get( F_PROVV ) ); - rdoc.curr( ).put( "NDOC", app( ).edit_mask( ).get( F_NDOC ) ); - rdoc.curr( ).put( "NRIGA", riga.get( 1 ) ); - rdoc.read( ); - app( ).edit_mask( ).field( F_MEMORIGA ).autoload( &rdoc ); - } - if ( key == K_TAB ) // Lascio una riga nello sheet - { - TRelation rdoc( LF_RIGHEDOC ); - TToken_string riga( ss.row( r ) ); - rdoc.curr( ).zero( ); - rdoc.curr( ).put( "CODNUM", app( ).edit_mask( ).get( F_CODNUM ) ); - rdoc.curr( ).put( "ANNO", app( ).edit_mask( ).get( F_ANNO ) ); - rdoc.curr( ).put( "PROVV", app( ).edit_mask( ).get( F_PROVV ) ); - rdoc.curr( ).put( "NDOC", app( ).edit_mask( ).get( F_NDOC ) ); - rdoc.curr( ).put( "NRIGA", riga.get( 1 ) ); - rdoc.read( ); - app( ).edit_mask( ).field( F_MEMORIGA ).autosave( &rdoc ); - rdoc.write( ); - } - if ( key == K_INS ) // Inserimento - { - TMask& m = *app( )._msk1; - TTable tabtr( "%TRI" ); - tabtr.zero( ); - tabtr.put( "CODTAB", m.get( F_LBTIPORIGA ) ); - tabtr.read( ); - TToken_string& riga = ss.row( r ); - riga.add( 1, 0 ); - riga.add( m.get( F_LBTIPORIGA ), 1 ); - riga.add( tabtr.get( "S4" ), 2 ); - return TRUE; - } - if ( key == K_CTRL + K_INS ) // Dopo inserimento - { - TMask& m = *app( )._msk1; - TTable tabtr( "%TRI" ); - tabtr.zero( ); - tabtr.put( "CODTAB", m.get( F_LBTIPORIGA ) ); - tabtr.read( ); - TToken_string& riga = ss.row( r ); - TFilename nome_proriga( tabtr.get( "S4" ) ); - nome_proriga.ext( "ini" ); - TConfig pro( nome_proriga ); - int ncols = pro.get_int( "NCOLS", "COLUMNS" ); - // Disabilita tutte le colonne - for( int i = 1; i <= MAX_COLUMNS; i ++ ) - ss.disable_cell ( ss.items( ) - 1, i ); - // Abilita le colonne indicate nel profilo della riga - for( i = 1; i <= ncols; i ++ ) - { - TString16 chiave; - chiave.format( "%d", i ); - int coltoenable = pro.get_int( chiave, "COLUMNS" ); - ss.enable_cell ( ss.items( ) - 1, coltoenable - 1 ); - }; - ss.force_update( ); - app( ).curr_mask( ).send_key( K_ROWEDIT, F_SHEET ); - return TRUE; - } - if ( key == K_DEL ) // Cancellazione - { - // Sottraggo la riga appena cancellata ai totalizzatori - app().sottrai_piedi( ); - app().carica_piedi( ); - } - if ( key == K_ENTER ) // Modifica - { - app().sottrai_piedi( ); - TRelation rdoc( LF_RIGHEDOC ); - ss.sheet_mask( ).autosave( &rdoc ); - // Sommo la riga ai totalizzatori - app().calcola_riga( rdoc.curr( ) ); - app().sottrai_piedi( ); - } - return TRUE; -}; - -bool TMotore_application::num_handler( TMask_field& f, KEY key ) -{ - // Ottengo la maschera - TMask& m = f.mask( ); - - if (key == K_TAB && m.is_running( ) ) - { - // Se la numerazione non è specificata, - const TString16 value( m.get( F_CODNUM ) ); - if ( value.blank( ) ) - { - // Pulisce la descrizione - m.set(F_DESNUM, "" ); - // Pulisce i tipi di documento consentiti - m.set(F_TIPIDOCS, "" ); - // Pulisce il tipo di documento - m.set(F_TIPODOC, "" ); - return TRUE; - } - // Apro la tabella numerazioni - TTable tabnum( "NUM" ); - tabnum.zero( ); - tabnum.put( "CODTAB", value ); - if( tabnum.read( ) == NOERR ) - { - // Copio la descrizione della numerazione - m.set(F_DESNUM, tabnum.get("S0") ); - // Copio i tipi di documento validi per la numerazione - const TString tipidocs( tabnum.get("S2") ); - m.set(F_TIPIDOCS, tipidocs ); - TString16 curtipo( m.get( F_TIPODOC ) ); - if( curtipo.blank( ) ) - { - // Propone il primo tipo di documento come default - m.set(F_TIPODOC, tipidocs.left( 4 ) ); - // m.field( F_TIPODOC ).check( ); - m.send_key( K_TAB, F_TIPODOC ); - } - // Se per questa numerazione è abilitata le numerazione provvisoria - if ( tabnum.get_bool ( "B0" ) ) - { - // Setta di default la numerazione provvisoria - m.set( F_PROVV, "P" ); - // Abilita il campo per la selezione della numerazione - m.enable( F_PROVV ); - } - else // Altrimenti ... - { - // Setta la numerazione a definitiva - m.set( F_PROVV, "D" ); - // Disabilita il campo per la selezione della numerazione - m.disable( F_PROVV ); - }; - return TRUE; - } - message_box( "Numerazione non valida!" ); - return FALSE; - } - if (key == K_ENTER && m.is_running( ) ) - { // Se la numerazione non è specificata, - const TString16 value( m.get( F_CODNUM ) ); - if ( value.blank( ) ) - { - message_box( "Occorre una numerazione per inserire un documento!" ); - m.first_focus( F_NDOC ); - return FALSE; - } - } - return TRUE; -} - -bool TMotore_application::occas_handler(TMask_field& f, KEY key) -{ - if (key == K_SPACE && f.mask( ).is_running( ) ) - { - TMask& om = app( ).clifo( ). occas_mask( ); - om.run( ); - f.set_focus( ); - } - return TRUE; -} - - -bool TMotore_application::tip_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask( ); - if (key == K_TAB && m.is_running( ) ) - { - const TString16 value( m.get( F_TIPODOC ) ); - if ( value.blank( ) ) - { - // Pulisce il profilo - m.set(F_PROFILO, "" ); - return TRUE; - } - TString tipi_consentiti( m.get( F_TIPIDOCS ) ); - TString16 tipo( f.get( ) ); - tipo.trim( ); - bool tipo_valido = FALSE; - for ( int i = 0; i < 10; i ++ ) - { - TString16 curtipo( tipi_consentiti.mid( i * 4, 4 ) ); - curtipo.trim( ); - if( curtipo == tipo ) - { - tipo_valido = TRUE; - break; - } - } - if( ! tipo_valido ) - { - message_box( "Tipo non valido per la numerazione selezionata!" ); - f.set( "" ); - return FALSE; - } - TTable tabtip( "%TIP" ); - tabtip.zero( ); - tabtip.put( "CODTAB", tipo ); - tabtip.read( ); - m.set(F_DESTIPODOC, tabtip.get("S0") ); - m.set(F_PROFILO, tabtip.get("S4") ); - } - if (key == K_ENTER && m.is_running( ) ) - { TString tipo( f.get( ) ); - if ( ! tipo.blank( ) ) - { TTable tabtip( "%TIP" ); - tabtip.read( ); - m.set(F_PROFILO, tabtip.get("S4") ); - } - else - { message_box( "Occorre un tipo documento per inserire un documento!" ); - m.first_focus( F_TIPODOC ); - return FALSE; - } - } - return TRUE; -} - -bool TMotore_application::ndoc_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask( ); - if (key == K_TAB && m.is_running( ) ) - { TLocalisamfile& doc = app( ).rel( ).lfile( ); - doc.zero( ); - doc.put("CODNUM", m.get( F_CODNUM ) ); - doc.put("PROVV", m.get( F_PROVV ) ); - doc.put("ANNO", m.get( F_ANNO ) ); - doc.put("NDOC", f.get( ) ); - if ( doc.read( ) == NOERR ) - { m.set(F_TIPODOC, doc.get( "TIPODOC" ) ); - m.set(F_STATO, doc.get( "STATO" ) ); - TTable tabtip( "%TIP" ); - tabtip.put( "CODTAB", doc.get( "TIPODOC" ) ); - tabtip.read( ); - m.set(F_PROFILO, tabtip.get("S4") ); - m.stop_run( K_AUTO_ENTER ); - } - } - return TRUE; -} - -bool TMotore_application::clifo_handler(TMask_field& f, KEY key) -{ - if (key == K_TAB && f.active()) - { - TMask& m = f.mask(); - - const char cf = app().tipocf(); - TLocalisamfile& clifo = ((TEdit_field&)f).browse()->cursor()->file(); - - if (clifo.get_char("TIPOCF") != cf || clifo.get("CODCF") != f.get()) - { - clifo.setkey(1); - clifo.put("TIPOCF", cf); - clifo.put("CODCF", f.get()); - clifo.read(); - CHECK(clifo.good(), "Impossibile ritrovare il clifo" ); - } - CHECKD(f.is_edit(), "Can't check suspension of a non edit-field ", f.dlg()); - const TEdit_field& c = (const TEdit_field&)f; - const TBrowse* b = c.browse(); - CHECKD(b, "Can't check suspension of a edit-field without a USE ", f.dlg()); - const TLocalisamfile& i = b->cursor()->file(); - // Tabella File - const char* sf = i.tab() ? "B2" : "SOSPESO"; - const bool suspended = i.get_bool(sf); - if (suspended) - { - sf = f.get(); - return f.error_box("Il codice '%s' e' sospeso e non puo' essere utilizzato", sf); - } - /* - if (!m.is_running() || f.dirty()) - { - // Equichecazzociva? - - } - */ - // Disabilitazioni varie, ma le demando all'oggetto cliente - if (f.focusdirty()) - { - app().clifo( ).load( cf, atol( f.get( ) ), "" ); - app().clifo( ).update_mask( ( TMask_vendite& ) m ); - if ( app( ).clifo( ).occasionale( ) && app( ).clifo( ).occas_mask( ).get(O_CODICE).empty( ) ) - m.send_key(K_SPACE, F_OCCASEDIT); // Lancia maschera occasionali - } - } - return TRUE; -} - -void TMotore_application::azzera_piedi( bool temp ) -{ - for ( int i = 0; i < NPIEDI; i++ ) - if ( temp ) - _piedi_temp[ i ] = 0.0; - else - _piedi[ i ] = 0.0; -} - -void TMotore_application::carica_piedi( ) -{ - TToken_string s( pro( ).get( "PROGPIEDE", "MAIN" ) ); - int i = s.get_int( ); - int j = 0; - while( i != 0 ) - { - real strpiede( _piedi[ i ] ); - edit_mask( ).set( BASE_PIEDE + ( ++j ), strpiede.stringa( 15 ) ); - i = s.get_int( ); - } -} - -void TMotore_application::somma_piedi( ) -{ - for ( int i = 0; i < NPIEDI; i++ ) - _piedi[ i ] += _piedi_temp[ i ]; -} - -void TMotore_application::sottrai_piedi( ) -{ - for ( int i = 0; i < NPIEDI; i++ ) - _piedi[ i ] -= _piedi_temp[ i ]; -} - -bool TMotore_application::changing_mask(int mode) -{ - static int lastmode = NO_MODE; - - const bool change = ( mode != lastmode ); - lastmode = mode; - return change; - -} - -void TMotore_application::configura_sheet( TSheet_field& sheet, TConfig& config ) -{ - int ncols = config.get_int( "NCOLS", "SHEET" ); - for( int i = 1; i <= ncols; i ++ ) - { - TString col; - col.format( "%d", i ); - TToken_string sheet_col( config.get( col, "SHEET" ) ); - const TString descr( sheet_col.get( 1 ) ); - if ( ! descr.blank( ) ) - sheet.set_column_header( i, descr ); - TString size( sheet_col.get( 2 ) ); - if ( ! size.blank( ) ) - sheet.set_column_width( i, sheet_col.get_int( 2 ) ); - int coltomove = sheet_col.get_int( 0 ) - 1; - sheet.move_column( coltomove, i ); - }; - for ( int j = MAX_COLUMNS; j >= i - 1; j -- ) - sheet.delete_column( j ); -}; - -void TMotore_application::get_edit_mask( void ) -{ - TFilename fn; - - fn = query_mask( ).get( F_PROFILO ); - // query_mask( ).enable(DLG_NEWREC); - fn.ext( "ini" ); - fn.upper( ); - if ( _pro ) - { - if( (*_proname) == fn ) - return; - delete _pro; - }; - _pro = new TConfig( fn ); - _proname = new TFilename( fn ); - _proname->upper( ); - if ( _msk1 ) delete _msk1; - _msk1 = new TMask_vendite( pro( ).get( "MSKFILE", "MAIN" ) ); - // edit_mask( ).set( F_PROFILO, query_mask( ).get( F_PROFILO ) ); - edit_mask( ).set( F_DESNUM, query_mask( ).get( F_DESNUM ) ); - _sheet = &(TSheet_field &)edit_mask( ).field(F_SHEET); - sheet( ).set_notify( ss_handler ); - TString tipocf( app( ).pro( ).get( "TIPOCF", "MAIN" ) ); - app( ).tipocf( tipocf[ 0 ] ); - configura_sheet( *_sheet, *_pro ); - TList_field& listbox = ( TList_field& ) _msk1->field( F_LBTIPORIGA ); - const int numtr = app( ).pro( ).get_int( "NTIPIRIGA", "RIGHE" ); - TTable tabtr( "%TRI" ); - TToken_string keys( "" ), descrs( "" ); - for ( int i = 1; i <= numtr; i ++ ) - { - TString chiave; - TToken_string item; - chiave.format( "%d", i ); - tabtr.zero( ); - TString tiporiga( app( ).pro( ).get( chiave, "RIGHE" ) ); - tabtr.put( "CODTAB", tiporiga ); - if ( tabtr.read( ) == NOERR ) - { - keys.add( tabtr.get( "CODTAB" ) ); - descrs.add( tabtr.get( "S0" ) ); - } - else - { - yesnofatal_box( "Inserito un tipo di riga non valido (%s)", (const char *)tiporiga ); - } - } - listbox.replace_items( keys, descrs ); - sheet( ).set_getmask( ss_getmask ); - int numhandler = pro( ).get_int( "NHANDLER", "HANDLERS" ); - for( i = 1; i <= numhandler; i ++ ) - { - TString chiave; - chiave.format( "%d", i ); - TToken_string riga = pro( ).get( chiave, "HANDLERS" ); - user_set_handler( riga.get_int( 0 ), riga.get_int( 1 ) ); - }; - _msk1->set( F_MEMORIGA, "Riga1" ); -} - -TMask* TMotore_application::get_mask( int mode ) -{ - switch ( mode ) - { - case MODE_INS: - case MODE_MOD: - get_edit_mask( ); - edit_mask( ).enable( DLG_PRINT, ( mode == MODE_MOD ) ); - edit_mask( ).set_handler( F_OCCASEDIT, occas_handler ); - edit_mask( ).set_handler( F_CODCF, clifo_handler ); - edit_mask( ).set_handler( F_CODPAG, condpag_hndl ); - edit_mask( ).set_handler( F_DATAINSC, condpag_hndl ); - return ( _msk1 ); - break; - default: - return _msk; - break; - }; -} - -void TMotore_application::set_descr(int i, const char * dfi) -{ - TToken_string& r = ss( ).row(i); - r.add(dfi, 0); -} - -void TMotore_application::carica_righe_libere(int from) -{ - if (from < 0) from = ss( ).items( ); - for (int i = from; i < 20; i++) - set_descr( i, "" ); - ss( ).force_update( ); -} - -const char* TMotore_application::get_next_key( ) -{ - TToken_string key; - TMask& m = curr_mask( ); - - TString value = m.get( F_CODNUM ); - if ( value.blank( ) ) - return NULL; - TTable tabnum( "NUM" ); - tabnum.zero( ); - tabnum.put( "CODTAB", value ); - if( tabnum.read( ) == NOERR ) - { - // Se per questa numerazione è abilitata le numerazione automatica - if( tabnum.get_bool ( "B1" ) ) - { - TLocalisamfile doc( LF_DOC ); - doc.zero( ); - doc.put( "CODNUM", value ); - doc.put( "ANNO", m.get( F_ANNO ) ); - doc.put( "NDOC", 9999999L ); - // Se per questa numerazione è abilitata le numerazione provvisoria - if( tabnum.get_bool ( "B0" ) ) - { - doc.put( "PROVV", "P" ); - } - else // Altrimenti ... - { - doc.put( "PROVV", "D" ); - }; - if( doc.read( _isgteq ) == NOERR ) - { - doc.prev( ); - } - long num = ( value == doc.get( "CODNUM" ) ) ? doc.get_long( "NDOC" ) : 0; - key.format( "%d|%d", F_NDOC, num + 1 ); - return key; - } - }; - return NULL; -} - -int TMotore_application::read(TMask& m) -{ - azzera_piedi( ); - int err = TRelation_application::read( m ); - if ( err == NOERR ) - { - TString16 tipocf( m.get( F_TIPOCF ) ); - clifo( ).load( tipocf[ 0 ], m.get_int( F_CODCF ), rel( ).curr( ).get( "OCFPI" ) ); - clifo( ).update_mask( ( TMask_vendite& ) m, TRUE ); - TLocalisamfile& rdoc = rel( ).lfile(LF_RIGHEDOC); - TRectype r = rdoc.curr( ); - r.zero( ); - r.put( "CODNUM", m.get( F_CODNUM ) ); - r.put( "PROVV", m.get( F_PROVV ) ); - r.put( "ANNO", m.get( F_ANNO ) ); - r.put( "NDOC", m.get_long( F_NDOC ) ); - _righe_rec->read( r ); - TSheet_field& f = (TSheet_field&) m.field( F_SHEET ); - f.destroy( ); - int last = _righe_rec->last_row( ); - for( int i = 1; i <= last; i ++ ) - { - TRectype &rec = _righe_rec->row( i, TRUE ); - load_riga( f, i - 1, rec ); - calcola_riga( rec ); - }; - carica_piedi( ); - } - return err; -} - -bool TMotore_application::check_key( TLocalisamfile& rdoc, TString16 codnum, bool provv, TString16 anno, TString16 ndoc ) -{ - return ( ( rdoc.get("CODNUM") == codnum ) && - ( rdoc.get("NDOC") == ndoc ) && - ( rdoc.get("ANNO" ) == anno ) && - ( rdoc.get_bool( "PROVV" ) == provv ) ); -} - -int TMotore_application::write(const TMask& m) -{ - int err; - if ( esegui_procedura( OP_NUOVO ) != NOERR ) - return FALSE; - err = NOERR; // avanza_numero( m.get_bool( F_PROVV ) ); - if ( err == NOERR ) - { - err = app( ).clifo( ).write_occas( ); - } - if ( err == NOERR ) - { - err = TRelation_application::write( m ); - if ( err == NOERR ) - { - TSheet_field& f = ss( ); - _righe_rec->destroy_rows( ); - if ( m.insert_mode( ) ) - _righe_rec->renum_key( "NRIGA", 1 ); - for ( int i = 0; i < f.items( ); i ++ ) - { - TToken_string& t = f.row( i ); - TRectype& rec = _righe_rec->row(i + 1, TRUE); - store_riga( f, i, rec ); - } - err = _righe_rec->write( ); - } - } - return err; -}; - -int TMotore_application::rewrite(const TMask& m) -{ - if ( ! valida_operazione( OP_MODIFICA ) ) - return FALSE; - int err = TRelation_application::rewrite( m ); - if ( err == NOERR ) - { - TSheet_field& f = ss( ); - _righe_rec->destroy_rows( ); - if ( m.insert_mode( ) ) - _righe_rec->renum_key( "NRIGA", 1 ); - for ( int i = 0; i < f.items( ); i ++ ) - { - TToken_string& t = f.row( i ); - TRectype& rec = _righe_rec->row(i + 1, TRUE); - store_riga( f, i, rec ); - } - err = _righe_rec->rewrite( ); - } - return err; -}; - - -// La funzione si trova in ve0100b - -long TMotore_application::prossimo_numero( bool provv ) -{ - long ret; - TTable tabnum( "NUM" ); - - tabnum.read( ); - if ( provv ) - ret = tabnum.get_long( "I0" ) + 1; - else - ret = tabnum.get_long( "I1" ) + 1; - return ( ret ); -}; - -int TMotore_application::avanza_numero( bool provv ) -{ - TTable tabnum( "NUM" ); - - int err = tabnum.read( ); - if ( err == NOERR ) - { - if ( provv ) - tabnum.put( "I0", tabnum.get_long( "I0" ) + 1 ); - else - tabnum.put( "I1", tabnum.get_long( "I1" ) + 1 ); - err = tabnum.rewrite( ); - } - return err; -}; - -bool TMotore_application::remove( void ) -{ - if ( ! valida_operazione( OP_CANCELLA ) ) - return FALSE; - return TRelation_application::remove && ( _righe_rec->remove( ) == NOERR ); -} - -void TMotore_application::load_riga( TSheet_field& f, int numrig, TRectype& r ) -{ - TToken_string& riga = f.row(numrig); - riga = r.get( "STATORIGA" ); - riga.add( r.get( "TIPORIGA" ) ); - TFilename proname( r.get( "PROFRIGA" ) ); - riga.add( proname ); - riga.add( r.get( "CODMAG" ) ); - riga.add( r.get( "CODART" ) ); - riga.add( r.get( "DESCR" ) ); - riga.add( r.get( "DESCLUNGA" ) ); - riga.add( r.get( "PREZZO" ) ); - riga.add( r.get( "UMQTA" ) ); - riga.add( r.get_real( "QTA" ).string(11) ); - riga.add( r.get( "QTAEVASA" ) ); - riga.add( r.get( "RIGAEVASA" ) ); - riga.add( r.get( "TARA" ) ); - riga.add( r.get( "PNETTO" ) ); - riga.add( r.get( "NCOLLI" ) ); - riga.add( r.get( "DAEVADERE" ) ); - riga.add( r.get( "SCONTO" ) ); - riga.add( r.get( "PERCPROV" ) ); - riga.add( r.get( "IMPFISSO" ) ); - riga.add( r.get( "IMPFISUN" ) ); - riga.add( r.get( "CODIVA" ) ); - riga.add( r.get( "ADDIVA" ) ); - riga.add( r.get( "ASPBENI" ) ); - proname.ext( "ini" ); - TConfig pro( proname ); - int ncols = pro.get_int( "NCOLS", "COLUMNS" ); - // Disabilita tutte le colonne - for( int i = 1; i <= MAX_COLUMNS; i ++ ) - f.disable_cell ( f.items( ) - 1, i ); - // Abilita le colonne indicate nel profilo della riga - for( i = 1; i <= ncols; i ++ ) - { - TString16 chiave; - chiave.format( "%d", i ); - int coltoenable = pro.get_int( chiave, "COLUMNS" ); - f.enable_cell ( numrig - 1, coltoenable - 1 ); - } -} - -void TMotore_application::store_riga( TSheet_field& f, int numrig, TRectype& r ) -{ - TToken_string& riga = f.row(numrig); - - r.put( "CODNUM", edit_mask( ).get( F_CODNUM ) ); - r.put( "ANNO", edit_mask( ).get( F_ANNO ) ); - r.put( "PROVV", edit_mask( ).get( F_PROVV ) ); - r.put( "NDOC", edit_mask( ).get_long( F_NDOC ) ); - r.put( "STATORIGA", riga.get( 0 ) ); - r.put( "TIPORIGA", riga.get( 1 ) ); - r.put( "PROFRIGA", riga.get( 2 ) ); - r.put( "CODMAG", riga.get( 3 ) ); - r.put( "CODART", riga.get( 4 ) ); - r.put( "DESCR", riga.get( 5 ) ); - r.put( "DESCLUNGA", riga.get( 6 ) ); - r.put( "PREZZO", riga.get( 7 ) ); - r.put( "UMQTA", riga.get( 8 ) ); - r.put( "QTA", riga.get( 9 ) ); - r.put( "QTAEVASA", riga.get( 10 ) ); - r.put( "RIGAEVASA", riga.get( 11 ) ); - r.put( "TARA", riga.get( 12 ) ); -} - - -void TMotore_application::calcola_riga( TRectype& r, bool temp ) -{ - TFilename proriganame( r.get("PROFRIGA") ); - proriganame.ext( "INI" ); - TConfig proriga( proriganame ); - TToken_string s(proriga.get("PROGPIEDE", "MAIN")); - int func = s.get_int( ); - while( func ) - { - if ( temp ) - _piedi_temp[ s.get_int( ) ] += user_row_calculate( r, func ); - else - _piedi[ s.get_int( ) ] += user_row_calculate( r, func ); - func = s.get_int( ); - } -} - - -bool TMotore_application::user_create( ) -{ - TSconto s; - s.set( "12 - 23 + 12.2 +.5 ", TRUE ); - if( s.is_valid( ) ) - warning_box( "Sconto: %s( %s )", (const char *)s.get( ), (const char *)s.scontostr( ) ); - s.set( ".5-.5", TRUE ); - if( s.is_valid( ) ) - warning_box( "Sconto: %s( %s )", (const char *)s.get( ), (const char *)s.scontostr( ) ); - s.set( "12 - 2.3 + 12.2.1 +.5 ", TRUE ); - if( s.is_valid( ) ) - warning_box( "Sconto: %s( %s )", (const char *)s.get( ), (const char *)s.scontostr( ) ); - - TConfig ditta( CONFIG_DITTA ); - - // Controllo se sono cambiate le impostazioni delle vendite. - if( ditta.get_bool( "CHANGED", "ve" ) ) - { // Se sono cambiate, rigenero tutte le maschere - if ( !yesno_box( CHANGE_MESSAGE ) ) - return FALSE; - TExternal_app motore2( "VE0 -3 -all" ); - motore2.run( ); - ditta.set( "CHANGED", "", "ve" ); - } - _clifor = new TCliForVendite( ); - azzera_piedi( ); - _msk = new TMask("VE1000A"); - query_mask( ).set_handler( F_NDOC, ndoc_handler ); - query_mask( ).set_handler( F_CODNUM, num_handler ); - query_mask( ).set_handler( F_TIPODOC, tip_handler ); - TConfig utente( CONFIG_USER ); - TString16 codnum( utente.get( "CODNUM", "ve") ); - if (!codnum.blank( ) ) - { - query_mask( ).set( F_CODNUM, codnum ); - query_mask( ).set( F_DESNUM, utente.get( "DESNUM", "ve") ); - } - TString16 tipodoc( utente.get( "TIPODOC", "ve") ); - if (!tipodoc.blank( ) ) - { - query_mask( ).set( F_TIPODOC, tipodoc ); - query_mask( ).set( F_DESTIPODOC, utente.get( "DESTIPODOC", "ve") ); - } - // La maschera di inserimento/modifica per ora non la so! - // Viene letta dal profilo non appena trovato il record - _msk1 = NULL; - - // Metto in relazione testata e righe - _rel = new TRelation(LF_DOC); - rel( ).add( LF_RIGHEDOC,"CODNUM=CODNUM|ANNO=ANNO|PROVV=PROVV|NDOC=NDOC" ); - - // Inizializzo il Record_array - _righe_rec = new TRecord_array( LF_RIGHEDOC, "NRIGA", 1 ); - - return TRUE; -} - -bool TMotore_application::user_destroy( ) -{ - // Registro l'ultimo tipo documento e l'ultima numerazione - TConfig utente( CONFIG_USER ); - utente.set( "CODNUM", query_mask( ).get( F_CODNUM ), "ve" ); - utente.set( "TIPODOC", query_mask( ).get( F_TIPODOC ), "ve" ); - utente.set( "DESNUM", query_mask( ).get( F_DESNUM ), "ve" ); - utente.set( "DESTIPODOC", query_mask( ).get( F_DESTIPODOC), "ve" ); - // Se è ancora allocata, distruggo la maschera di modifica - if ( _msk1 ) delete _msk1; - - // Distruggo la maschera di modifica - delete _msk; - - // Distruggo la relazione - delete _rel; - - // Distruggo il Record_array - delete _righe_rec; - - return TRUE; -} - -int TMotore_application::esegui_procedura( int operazione ) -{ - // Accesso unico alla chiamata di procedure tramite operazione - int index = ( int )pro( ).get_long( nome_sezione( operazione ), "MAIN" ); - if ( index ) - return ( user_function( index ) ); - return ( NOERR ); -} - - -bool TMotore_application::valida_operazione( int operazione ) -{ - if ( operazione != OP_NUOVO ) - { - if ( !stato_valido( stato_corrente( ), operazione ) ) - { - segnala_stato_non_valido( operazione ); - return FALSE; - } - }; - if ( esegui_procedura( operazione ) == NOERR ) - return FALSE; - return TRUE; -} - -const char * TMotore_application::nome_sezione( int op ) -{ - switch( op ) - { - case OP_NUOVO: - return "INSERIMENTO"; - break; - case OP_MODIFICA: - return "MODIFICA"; - break; - case OP_CANCELLA: - return "CANCELLAZIONE"; - break; - case OP_STAMPA: - return "STAMPA"; - break; - case OP_RAGGRUPPA: - return "RAGGRUPPA"; - break; - case OP_USER: - return "SPECIALE"; - break; - default: - CHECK( FALSE, "tentativo di ottenere il nome di una operazione inesistente!" ); - // Per evitare la warning - return ""; - break; - } -} - -int TMotore_application::stato_finale( int operazione ) -{ - TString s( pro( ).get( "STATOFINALE", nome_sezione( operazione ) ) ); - if( strcmp( s, "N" ) == 0 ) return NO_CHANGE_STATUS; - return ( atoi( s ) ); -}; - -bool TMotore_application::stato_valido( int stato, int operazione ) -{ -#ifdef _DEBUG - warning_box( "Controllo stati validi!\nStato corrente %d.\nStati validi %s.", stato_corrente( ), ( const char * )stati_validi( operazione ) ); -#endif - char p[2] = "0"; - TToken_string ret ( stati_validi( operazione ), ',' ); - p[0] += (char)stato; - return ( ret.get_pos( p ) != -1 ); -}; - -void TMotore_application::setta_stato_corrente( int nuovostato ) -{ - // warning_box( "Settaggio stati validi!\nStato corrente %s.\nStati validi %s.\nStato finale %s.", stato_corrente( ), stati_validi( operazione ), stato_finale( operazione ) ); - TString p; - p.format( "%d", nuovostato ); - - TLocalisamfile& doc = rel( ).lfile(LF_DOC); - - p[0] += (char)nuovostato; - doc.put("STATO", p); - doc.rewrite( ); - query_mask( ).set( F_STATO, p ); - // warning_box( "Settaggio stati validi!\nStato corrente %s.\nStati validi %s.\nStato finale %s.", stato_corrente( ), stati_validi( operazione ), stato_finale( operazione ) ); -} - -int TMotore_application::stato_corrente( ) -{ - int i = query_mask( ).get_int( F_STATO ); - return ( i == 0 ? NO_DOC_STATUS : i ); -}; - -void TMotore_application::segnala_stato_non_valido( int operazione ) -{ - TString messaggio; - switch( operazione ) - { - case OP_NUOVO: - // Sempre valido - break; - case OP_MODIFICA: - messaggio = "Il documento non si trova in uno stato valido per poter essere modificato!"; - break; - case OP_CANCELLA: - messaggio = "Il documento non si trova in uno stato valido per poter essere cancellato!"; - break; - case OP_STAMPA: - messaggio = "Il documento non si trova in uno stato valido per poter essere stampato!"; - break; - case OP_RAGGRUPPA: - messaggio = "Il documento non si trova in uno stato valido per poter essere raggruppato!"; - break; - case OP_USER: - messaggio = "Il documento non si trova in uno stato valido per effettuare la operazione richiesta!"; - break; - default: - CHECK( FALSE, "Tentativo di segnalare stato non valido di una operazione non esistente!" ); - break; - }; - messaggio << "\nStato corrente :%d.\nStati validi :%s."; - warning_box( messaggio, stato_corrente( ), ( const char * )stati_validi( operazione ) ); -}; - -int ve0100(int argc, char** argv) -{ - TMotore_application a; - - a.run(argc, argv, "Gestione documenti"); - return 0; -} +#ifndef __VE0100_H +#include "ve0100.h" +#endif + +TMotore_application& app( ) { return ( TMotore_application& ) main_app( ); } + +void TMotore_application::init_insert_mode( TMask& m ) +{ + TString tipocf( "A" ); + tipocf[ 0 ] = app( ).tipocf( ); + // m.reset( ); + m.set( F_DATAINSC, m.get( F_DATADOC ) ); + m.set( F_TIPOCF, tipocf ); + clifo( ).occas_mask( ).reset( ); + int ndefaults = pro( ).get_int( "NDEFAULTS", "DEFAULT" ); + for( int i = 1; i <= ndefaults; i++ ) + { + TString16 chiave; + chiave.format( "%d", i ); + TToken_string valore( pro( ).get( chiave, "DEFAULT" ) ); + int campo( valore.get_int( 0 ) ); + TString default_val( valore.get( 1 ) ); + edit_mask( ).set( campo, default_val, TRUE ); + } +} + +int TMotore_application::user_function( int index ) +{ + switch( index ) + { + case 1: + break; + default: + yesnofatal_box( "Chiamata ad una procedura utente non definita: %d", index ); + return NOERR; + break; + } + return NOERR; +} + +// Funzione che dato il profilo di riga ottiene la maschera +// Serve per ottenere una maschera diversa per ogni riga +TMask *TMotore_application::ss_getmask( int numriga, TMask& fullmask, bool destroy ) +{ + static TRiga* r = NULL; + static TMask* m = NULL; + + if ( destroy ) + { + delete r; + r = NULL; + return( NULL ); + } + else + { + TSheet_field* ss = fullmask.get_sheet( ); + TToken_string& riga = ss->row( numriga ); + TString16 profilo( riga.get( FS_PROFRIGA - 101 ) ); + if ( profilo.blank( ) ) return &fullmask; + if( r && ( r->profilo( ) == profilo ) ) + { + return( m ); + } + if ( !r ) + r = new TRiga; + r->load( riga ); + m = &(r->getmask( )); + m->set_sheet( ss ); + return( m ); + } +} + +void TMotore_application::azzera_piedi( ) +{ + _piede.destroy( ); +} + +void TMotore_application::user_set_handler( int fieldid, int index, TMask* m ) +{ + if ( !m ) + m = &edit_mask( ); + switch( index ) + { + case 1: + m->set_handler( fieldid, ora_hndl ); + break; + case 3: + m->set_handler( fieldid, dummy_hndl ); + break; + default: + CHECK( FALSE, "Tentativo di installare un handler non definito" ); + break; + } +} + +bool TMotore_application::ss_handler( TSheet_field& ss, int r, KEY key ) +{ + static TRiga* riga; + + if ( key == K_SPACE ) // Inizio modifica + { + TPiede_documento& piede = app( ).piede( ); + riga->edit_keys( key, piede ); + } + if ( key == K_TAB ) // Mi posiziono su di una riga nello sheet + { + if ( riga ) + delete riga; + riga = new TRiga; + riga->load( ss.row( r ) ); + } + if ( key == K_CTRL + K_TAB ) // Lascio una riga nello sheet + { + // TRelation rdoc( LF_RIGHEDOC ); + // TToken_string riga( ss.row( r ) ); + // rdoc.curr( ).zero( ); + // rdoc.curr( ).put( "CODNUM", app( ).edit_mask( ).get( F_CODNUM ) ); + // rdoc.curr( ).put( "ANNO", app( ).edit_mask( ).get( F_ANNO ) ); + // rdoc.curr( ).put( "PROVV", app( ).edit_mask( ).get( F_PROVV ) ); + // rdoc.curr( ).put( "NDOC", app( ).edit_mask( ).get( F_NDOC ) ); + // rdoc.curr( ).put( "NRIGA", riga.get( 1 ) ); + // rdoc.read( ); + // app( ).edit_mask( ).field( F_MEMORIGA ).autosave( &rdoc ); + // rdoc.write( ); + } + if ( key == K_INS ) // Inserimento + { + TTable tabtr( "%TRI" ); + tabtr.zero( ); + tabtr.put( "CODTAB", app( ).edit_mask( ).get( F_LBTIPORIGA ) ); + tabtr.read( ); + TToken_string& tsr = ss.row( r ); + tsr.add( app( ).edit_mask( ).get( F_ANNO ), FS_ANNO - 101 ); + tsr.add( app( ).edit_mask( ).get( F_PROVV ), FS_PROVV - 101 ); + tsr.add( app( ).edit_mask( ).get( F_NDOC ), FS_NDOC - 101 ); + tsr.add( app( ).edit_mask( ).get( F_CODNUM ), FS_CODNUM - 101 ); + tsr.add( app( ).edit_mask( ).get( F_LBTIPORIGA ), FS_TIPORIGA - 101 ); + // tsr.add( app( ).edit_mask( ).get( F_PROFILO ), FS_PROFRIGA - 101 ); + tsr.add( tabtr.get( "S4" ), FS_PROFRIGA - 101 ); + if ( riga ) + delete riga; + riga = new TRiga; + riga->load( tsr ); + return TRUE; + } + if ( key == K_CTRL + K_INS ) // Dopo inserimento + { + riga->configura_sheet( ss, r ); + app( ).curr_mask( ).send_key( K_ROWEDIT, F_SHEET ); + return TRUE; + } + if ( key == K_DEL ) // Cancellazione + { + TPiede_documento& piede = app( ).piede( ); + riga->edit_keys( key, piede ); + return TRUE; + } + if ( key == K_ENTER ) // Modifica + { + TPiede_documento& piede = app( ).piede( ); + riga->edit_keys( key, piede ); + return TRUE; + } + return TRUE; +} + +bool TMotore_application::num_handler( TMask_field& f, KEY key ) +{ + // Ottengo la maschera + TMask& m = f.mask( ); + + if ( key == K_TAB && m.is_running( ) ) + { + // Se la numerazione non è specificata, + const TString16 value( m.get( F_CODNUM ) ); + if ( value.blank( ) ) + { + // Pulisce la descrizione + m.set( F_DESNUM, "" ); + // Pulisce i tipi di documento consentiti + m.set( F_TIPIDOCS, "" ); + // Pulisce il tipo di documento + m.set( F_TIPODOC, "" ); + return TRUE; + } + // Apro la tabella numerazioni + TTable tabnum( "NUM" ); + tabnum.zero( ); + tabnum.put( "CODTAB", value ); + if ( tabnum.read( ) == NOERR ) + { + // Copio la descrizione della numerazione + m.set( F_DESNUM, tabnum.get( "S0" ) ); + // Copio i tipi di documento validi per la numerazione + const TString tipidocs( tabnum.get( "S2" ) ); + m.set( F_TIPIDOCS, tipidocs ); + TString16 curtipo( m.get( F_TIPODOC ) ); + if ( curtipo.blank( ) ) + { + // Propone il primo tipo di documento come default + m.set( F_TIPODOC, tipidocs.left( 4 ) ); + // m.field( F_TIPODOC ).check( ); + m.send_key( K_TAB, F_TIPODOC ); + } + // Se per questa numerazione è abilitata le numerazione provvisoria + if ( tabnum.get_bool ( "B0" ) ) + { + // Setta di default la numerazione provvisoria + m.set( F_PROVV, "P" ); + // Abilita il campo per la selezione della numerazione + m.enable( F_PROVV ); + } + else // Altrimenti ... + { + // Setta la numerazione a definitiva + m.set( F_PROVV, "D" ); + // Disabilita il campo per la selezione della numerazione + m.disable( F_PROVV ); + } + return TRUE; + } + message_box( "Numerazione non valida!" ); + return FALSE; + } + if ( key == K_ENTER && m.is_running( ) ) + { // Se la numerazione non è specificata, + const TString16 value( m.get( F_CODNUM ) ); + if ( value.blank( ) ) + { + message_box( "Occorre una numerazione per inserire un documento!" ); + m.first_focus( F_NDOC ); + return FALSE; + } + } + return TRUE; +} + +bool TMotore_application::val_handler( TMask_field& f, KEY key ) +{ + // Ottengo la maschera + TMask& m = f.mask( ); + + // m.set( F_CAMBIO, "" ); + // m.set( F_DATACAMBIO, "" ); + app( ).clifo( ).imposta_valuta( ( TMask_vendite& ) m ); + return TRUE; +} + + +bool TMotore_application::occas_handler( TMask_field& f, KEY key ) +{ + if ( key == K_SPACE && f.mask( ).is_running( ) ) + { + TMask& om = app( ).clifo( ). occas_mask( ); + om.run( ); + f.set_focus( ); + } + return TRUE; +} + + +bool TMotore_application::tip_handler( TMask_field& f, KEY key ) +{ + TMask& m = f.mask( ); + if ( key == K_TAB && m.is_running( ) ) + { + const TString16 value( m.get( F_TIPODOC ) ); + if ( value.blank( ) ) + { + // Pulisce il profilo + m.set( F_PROFILO, "" ); + return TRUE; + } + TString tipi_consentiti( m.get( F_TIPIDOCS ) ); + TString16 tipo( f.get( ) ); + tipo.trim( ); + bool tipo_valido = FALSE; + for ( int i = 0; i < 10; i ++ ) + { + TString16 curtipo( tipi_consentiti.mid( i * 4, 4 ) ); + curtipo.trim( ); + if ( curtipo == tipo ) + { + tipo_valido = TRUE; + break; + } + } + if ( ! tipo_valido ) + { + message_box( "Tipo non valido per la numerazione selezionata!" ); + f.set( "" ); + return FALSE; + } + TTable tabtip( "%TIP" ); + tabtip.zero( ); + tabtip.put( "CODTAB", tipo ); + tabtip.read( ); + m.set( F_DESTIPODOC, tabtip.get( "S0" ) ); + m.set( F_PROFILO, tabtip.get( "S4" ) ); + } + if ( key == K_ENTER && m.is_running( ) ) + { TString tipo( f.get( ) ); + if ( ! tipo.blank( ) ) + { + TTable tabtip( "%TIP" ); + tabtip.read( ); + m.set( F_PROFILO, tabtip.get( "S4" ) ); + } + else + { + message_box( "Occorre un tipo documento per inserire un documento!" ); + m.first_focus( F_TIPODOC ); + return FALSE; + } + } + return TRUE; +} + +bool TMotore_application::ndoc_handler( TMask_field& f, KEY key ) +{ + TMask& m = f.mask( ); + if ( key == K_TAB && m.is_running( ) ) + { + TLocalisamfile& doc = app( ).rel( ).lfile( ); + doc.zero( ); + doc.put( "CODNUM", m.get( F_CODNUM ) ); + doc.put( "PROVV", m.get( F_PROVV ) ); + doc.put( "ANNO", m.get( F_ANNO ) ); + doc.put( "NDOC", f.get( ) ); + if ( doc.read( ) == NOERR ) + { + m.set( F_TIPODOC, doc.get( "TIPODOC" ) ); + m.set( F_STATO, doc.get( "STATO" ) ); + TTable tabtip( "%TIP" ); + tabtip.put( "CODTAB", doc.get( "TIPODOC" ) ); + tabtip.read( ); + m.set( F_PROFILO, tabtip.get( "S4" ) ); + m.stop_run( K_AUTO_ENTER ); + } + } + return TRUE; +} + +bool TMotore_application::clifo_handler( TMask_field& f, KEY key ) +{ + if ( key == K_TAB && f.active( ) ) + { + TMask& m = f.mask( ); + + const char cf = app( ).tipocf( ); + TLocalisamfile& clifo = ( ( TEdit_field& )f ).browse( )->cursor( )->file( ); + + if ( clifo.get_char( "TIPOCF" ) != cf || clifo.get( "CODCF" ) != f.get( ) ) + { + clifo.setkey( 1 ); + clifo.put( "TIPOCF", cf ); + clifo.put( "CODCF", f.get( ) ); + clifo.read( ); + CHECK( clifo.good( ), "Impossibile ritrovare il clifo" ); + } + CHECKD( f.is_edit( ), "Can't check suspension of a non edit-field ", f.dlg( ) ); + const TEdit_field& c = ( const TEdit_field& )f; + const TBrowse* b = c.browse( ); + CHECKD( b, "Can't check suspension of a edit-field without a USE ", f.dlg( ) ); + const TLocalisamfile& i = b->cursor( )->file( ); + // Tabella File + const char* sf = i.tab( ) ? "B2" : "SOSPESO"; + const bool suspended = i.get_bool( sf ); + if ( suspended ) + { + sf = f.get( ); + return f.error_box( "Il codice '%s' e' sospeso e non puo' essere utilizzato", sf ); + } + /* + if ( !m.is_running( ) || f.dirty( ) ) + { + // Equichecazzociva? + + } + */ + // Disabilitazioni varie, ma le demando all'oggetto cliente + if ( f.focusdirty( ) ) + { + app( ).clifo( ).load( cf, atol( f.get( ) ), "" ); + app( ).clifo( ).update_mask( ( TMask_vendite& ) m ); + if( f.mask( ).id2pos( F_OCCASEDIT ) > 0 ) + { + if ( app( ).clifo( ).occasionale( ) && app( ).clifo( ).occas_mask( ).get( O_CODICE ).empty( ) ) + m.send_key( K_SPACE, F_OCCASEDIT ); // Lancia maschera occasionali + } + } + } + return TRUE; +} + +void TMotore_application::carica_piedi( ) +{ + TToken_string s( pro( ).get( "PROGPIEDE", "MAIN" ) ); + TString s1 = s.get( ); + TTable ppd( "PPD" ); + while( !s1.blank( ) ) + { + ppd.zero( ); + ppd.put( "CODTAB", s1 ); + if( ppd.read( ) == NOERR ) + { + real valpiede( "0.0" ); + if ( _piede.is_key( s1 ) ) + valpiede = ( real & )( _piede[ s1 ] ); + edit_mask( ).set( BASE_PIEDE + ppd.get_int( "I0" ), valpiede.stringa( 15 ) ); + } + else + message_box( "Piede non trovato( %s )", ( const char * )s1 ); + s1 = s.get( ); + } +} + +void TMotore_application::somma_piedi( ) +{ + /*for ( int i = 0; i < NPIEDI; i++ ) + _piedi[ i ] += _piedi_temp[ i ];*/ +} + +void TMotore_application::sottrai_piedi( ) +{ + /*for ( int i = 0; i < NPIEDI; i++ ) + _piedi[ i ] -= _piedi_temp[ i ];*/ +} + +bool TMotore_application::changing_mask( int mode ) +{ + static int lastmode = NO_MODE; + + const bool change = ( mode != lastmode ); + lastmode = mode; + return change; +} + +void TMotore_application::configura_sheet( TSheet_field& sheet, TConfig& config ) +{ + int ncols = config.get_int( "NCOLS", "SHEET" ); + for ( int i = 1; i <= ncols; i ++ ) + { + TString col; + col.format( "%d", i ); + TToken_string sheet_col( config.get( col, "SHEET" ) ); + const TString descr( sheet_col.get( 1 ) ); + if ( ! descr.blank( ) ) + sheet.set_column_header( i, descr ); + TString size( sheet_col.get( 2 ) ); + if ( ! size.blank( ) ) + sheet.set_column_width( i, sheet_col.get_int( 2 ) ); + int coltomove = sheet_col.get_int( 0 ) - 1; + sheet.move_column( coltomove, i ); + } + for ( int j = MAX_COLUMNS; j >= i - 1; j -- ) + sheet.delete_column( j ); +} + +void TMotore_application::get_edit_mask( const char * profilo ) +{ + TFilename fn( profilo ); + + // query_mask( ).enable( DLG_NEWREC ); + fn.ext( "ini" ); + fn.upper( ); + if ( _pro ) + { + if ( ( *_proname ) == fn ) + return; + delete _pro; + } + _pro = new TConfig( fn ); + _proname = new TFilename( fn ); + _proname->upper( ); + if ( _msk1 ) delete _msk1; + _msk1 = new TMask_vendite( pro( ).get( "MSKFILE", "MAIN" ) ); + // edit_mask( ).set( F_PROFILO, query_mask( ).get( F_PROFILO ) ); + // edit_mask( ).set( F_DESNUM, query_mask( ).get( F_DESNUM ) ); + _sheet = &( TSheet_field& )edit_mask( ).field( F_SHEET ); + sheet( ).set_notify( ss_handler ); + TString tipocf( app( ).pro( ).get( "TIPOCF", "MAIN" ) ); + app( ).tipocf( tipocf[ 0 ] ); + configura_sheet( *_sheet, *_pro ); + TList_field& listbox = ( TList_field& ) _msk1->field( F_LBTIPORIGA ); + const int numtr = app( ).pro( ).get_int( "NTIPIRIGA", "RIGHE" ); + TTable tabtr( "%TRI" ); + TToken_string keys( "" ), descrs( "" ); + for ( int i = 1; i <= numtr; i ++ ) + { + TString chiave; + TToken_string item; + chiave.format( "%d", i ); + tabtr.zero( ); + TString tiporiga( app( ).pro( ).get( chiave, "RIGHE" ) ); + tabtr.put( "CODTAB", tiporiga ); + if ( tabtr.read( ) == NOERR ) + { + keys.add( tabtr.get( "CODTAB" ) ); + descrs.add( tabtr.get( "S0" ) ); + } + else + { + yesnofatal_box( "Inserito un tipo di riga non valido ( %s )", ( const char * )tiporiga ); + } + } + listbox.replace_items( keys, descrs ); + sheet( ).set_getmask( ss_getmask ); + int numhandler = pro( ).get_int( "NHANDLER", "HANDLERS" ); + for ( i = 1; i <= numhandler; i ++ ) + { + TString chiave; + chiave.format( "%d", i ); + TToken_string riga = pro( ).get( chiave, "HANDLERS" ); + user_set_handler( riga.get_int( 0 ), riga.get_int( 1 ) ); + } + // _msk1->set( F_MEMORIGA, "Riga1" ); +} + +TMask* TMotore_application::get_mask( int mode ) +{ + TString profilo( query_mask( ).get( F_PROFILO ) ); + switch ( mode ) + { + case MODE_INS: + case MODE_MOD: + if( !_msk ) + delete _msk; + get_edit_mask( profilo ); + if ( edit_mask( ).id2pos( F_OCCASEDIT ) > 0 ) + edit_mask( ).set_handler( F_OCCASEDIT, occas_handler ); + if ( edit_mask( ).id2pos( F_CODVAL ) > 0 ) + edit_mask( ).set_handler( F_CODVAL, val_handler ); + edit_mask( ).set_handler( F_CODCF, clifo_handler ); + edit_mask( ).set_handler( F_CODPAG, condpag_hndl ); + edit_mask( ).set_handler( F_DATAINSC, condpag_hndl ); + return( _msk1 ); + break; + default: + if( !_msk ) + { + _msk = new TMask( "ve1000a" ); + } + if( !_msk1 ) + { + delete _msk1; + } + return _msk; + break; + } +} + +void TMotore_application::set_descr( int i, const char * dfi ) +{ + TToken_string& r = ss( ).row( i ); + r.add( dfi, 0 ); +} + +void TMotore_application::carica_righe_libere( int from ) +{ + if ( from < 0 ) from = ss( ).items( ); + for ( int i = from; i < 20; i++ ) + set_descr( i, "" ); + ss( ).force_update( ); +} + +const char* TMotore_application::get_next_key( ) +{ + TToken_string key; + TMask& m = curr_mask( ); + + TString value = m.get( F_CODNUM ); + if ( value.blank( ) ) + return NULL; + TTable tabnum( "NUM" ); + tabnum.zero( ); + tabnum.put( "CODTAB", value ); + if ( tabnum.read( ) == NOERR ) + { + // Se per questa numerazione è abilitata le numerazione automatica + if ( tabnum.get_bool ( "B1" ) ) + { + TLocalisamfile doc( LF_DOC ); + doc.zero( ); + doc.put( "CODNUM", value ); + doc.put( "ANNO", m.get( F_ANNO ) ); + doc.put( "NDOC", 9999999L ); + // Se per questa numerazione è abilitata le numerazione provvisoria + if ( tabnum.get_bool ( "B0" ) ) + { + doc.put( "PROVV", "P" ); + } + else // Altrimenti ... + { + doc.put( "PROVV", "D" ); + } + if ( doc.read( _isgteq ) == NOERR ) + { + doc.prev( ); + } + long num = ( value == doc.get( "CODNUM" ) ) ? doc.get_long( "NDOC" ) : 0; + key.format( "%d|%d", F_NDOC, num + 1 ); + return key; + } + } + return NULL; +} + +int TMotore_application::read( TMask& m ) +{ + azzera_piedi( ); + int err = TRelation_application::read( m ); + if ( err == NOERR ) + { + edit_mask( ).set( F_DESNUM, query_mask( ).get( F_DESNUM ) ); + edit_mask( ).set( F_DESTIPODOC, query_mask( ).get( F_DESTIPODOC ) ); + const char tipocf = m.get( F_TIPOCF )[ 0 ]; + clifo( ).load( tipocf, m.get_int( F_CODCF ), rel( ).curr( ).get( "OCFPI" ) ); + clifo( ).update_mask( ( TMask_vendite& ) m, TRUE ); + TLocalisamfile& rdoc = rel( ).lfile( LF_RIGHEDOC ); + TRectype r = rdoc.curr( ); + TRectype& trec = get_relation( )->curr( ); + r.zero( ); + r.put( "CODNUM", trec.get( "CODNUM" ) ); + r.put( "PROVV", trec.get( "PROVV" ) ); + r.put( "ANNO", trec.get( "ANNO" ) ); + r.put( "NDOC", trec.get_long( "NDOC" ) ); + _righe_rec->read( r ); + TSheet_field& f = ( TSheet_field& ) m.field( F_SHEET ); + f.destroy( ); + int last = _righe_rec->last_row( ); + TRiga currentrow; + for ( int i = 1; i <= last; i ++ ) + { + TToken_string& srow = f.row( i - 1 ); + TRectype& rec = _righe_rec->row( i, FALSE ); + currentrow.load( rec ); + currentrow.save( srow ); + currentrow.configura_sheet( f, i - 1 ); + currentrow.somma( _piede ); + } + carica_piedi( ); + } + return err; +} + +bool TMotore_application::check_key( TLocalisamfile& rdoc, TString16 codnum, bool provv, TString16 anno, TString16 ndoc ) +{ + return ( ( rdoc.get( "CODNUM" ) == codnum ) && + ( rdoc.get( "NDOC" ) == ndoc ) && + ( rdoc.get( "ANNO" ) == anno ) && + ( rdoc.get_bool( "PROVV" ) == provv ) ); +} + +int TMotore_application::write( const TMask& m ) +{ + int err; + if ( esegui_procedura( OP_NUOVO ) != NOERR ) + return FALSE; + m.field( F_STATO ).set( _pro->get( "STATOFINALE", "INSERIMENTO" ) ); + err = NOERR; // avanza_numero( m.get_bool( F_PROVV ) ); + if ( err == NOERR ) + { + if ( m.id2pos( F_OCCASEDIT) > 0 ) + err = app( ).clifo( ).write_occas( ); + } + if ( err == NOERR ) + { + err = TRelation_application::write( m ); + if ( err == NOERR ) + { + TSheet_field& f = ss( ); + _righe_rec->destroy_rows( ); + if ( m.insert_mode( ) ) + _righe_rec->renum_key( "NRIGA", 1 ); + for ( int i = 0; i < f.items( ); i ++ ) + { + TToken_string& t = f.row( i ); + TRectype& rec = _righe_rec->row( i + 1, TRUE ); + store_riga( f, i, rec ); + } + err = _righe_rec->write( ); + } + } + return err; +} + +int TMotore_application::rewrite( const TMask& m ) +{ + int err = NOERR; + if ( ! valida_operazione( OP_MODIFICA ) ) + return FALSE; + if ( err == NOERR ) + { + err = app( ).clifo( ).write_occas( ); + } + if ( err == NOERR ) + { + err = TRelation_application::rewrite( m ); + if ( err == NOERR ) + { + TSheet_field& f = ss( ); + _righe_rec->destroy_rows( ); + if ( m.insert_mode( ) ) + _righe_rec->renum_key( "NRIGA", 1 ); + for ( int i = 0; i < f.items( ); i ++ ) + { + TToken_string& t = f.row( i ); + TRectype& rec = _righe_rec->row( i + 1, TRUE ); + store_riga( f, i, rec ); + } + err = _righe_rec->rewrite( ); + } + } + return err; +} + + +// La funzione si trova in ve0100b + +long TMotore_application::prossimo_numero( bool provv ) +{ + long ret; + TTable tabnum( "NUM" ); + + tabnum.read( ); + if ( provv ) + ret = tabnum.get_long( "I0" ) + 1; + else + ret = tabnum.get_long( "I1" ) + 1; + return ( ret ); +} + +int TMotore_application::avanza_numero( bool provv ) +{ + TTable tabnum( "NUM" ); + + int err = tabnum.read( ); + if ( err == NOERR ) + { + if ( provv ) + tabnum.put( "I0", tabnum.get_long( "I0" ) + 1 ); + else + tabnum.put( "I1", tabnum.get_long( "I1" ) + 1 ); + err = tabnum.rewrite( ); + } + return err; +} + +bool TMotore_application::remove( void ) +{ + if ( ! valida_operazione( OP_CANCELLA ) ) + return FALSE; + return TRelation_application::remove && ( _righe_rec->remove( ) == NOERR ); +} + +void TMotore_application::load_riga( TSheet_field& f, int numrig, TRectype& r ) +{ + TToken_string& riga = f.row( numrig ); + riga = r.get( "STATORIGA" ); + riga.add( r.get( "TIPORIGA" ) ); + TFilename proname( r.get( "PROFRIGA" ) ); + riga.add( proname ); + riga.add( r.get( "CODMAG" ) ); + riga.add( r.get( "CODART" ) ); + riga.add( r.get( "DESCR" ) ); + riga.add( r.get( "DESCLUNGA" ) ); + riga.add( r.get( "PREZZO" ) ); + riga.add( r.get( "UMQTA" ) ); + riga.add( r.get_real( "QTA" ).string( 11 ) ); + riga.add( r.get( "QTAEVASA" ) ); + riga.add( r.get( "RIGAEVASA" ) ); + riga.add( r.get( "TARA" ) ); + riga.add( r.get( "PNETTO" ) ); + riga.add( r.get( "NCOLLI" ) ); + riga.add( r.get( "DAEVADERE" ) ); + riga.add( r.get( "SCONTO" ) ); + riga.add( r.get( "PERCPROV" ) ); + riga.add( r.get( "IMPFISSO" ) ); + riga.add( r.get( "IMPFISUN" ) ); + riga.add( r.get( "CODIVA" ) ); + riga.add( r.get( "ADDIVA" ) ); + riga.add( r.get( "ASPBENI" ) ); + proname.ext( "ini" ); + TConfig pro( proname ); + int ncols = pro.get_int( "NCOLS", "COLUMNS" ); + // Disabilita tutte le colonne + for ( int i = 1; i <= MAX_COLUMNS; i ++ ) + f.disable_cell ( f.items( ) - 1, i ); + // Abilita le colonne indicate nel profilo della riga + for ( i = 1; i <= ncols; i ++ ) + { + TString16 chiave; + chiave.format( "%d", i ); + int coltoenable = pro.get_int( chiave, "COLUMNS" ); + f.enable_cell ( numrig - 1, coltoenable - 1 ); + } +} + +void TMotore_application::store_riga( TSheet_field& f, int numrig, TRectype& r ) +{ + TToken_string& rigastr = f.row( numrig ); + TRiga riga; + riga.load( rigastr ); + riga.set_numero( numrig + 1 ); + riga.save( r ); +} + +bool TMotore_application::user_create( ) +{ + TConfig ditta( CONFIG_DITTA ); + + // Controllo se sono cambiate le impostazioni delle vendite. + if ( ditta.get_bool( "CHANGED", "ve" ) ) + { // Se sono cambiate, rigenero tutte le maschere + if ( !yesno_box( CHANGE_MESSAGE ) ) + return FALSE; + TExternal_app motore2( "VE0 -3 -all" ); + motore2.run( ); + ditta.set( "CHANGED", "", "ve" ); + } + _clifor = new TCliForVendite( ); + azzera_piedi( ); + _msk = new TMask( "VE1000A" ); + query_mask( ).set_handler( F_NDOC, ndoc_handler ); + query_mask( ).set_handler( F_CODNUM, num_handler ); + query_mask( ).set_handler( F_TIPODOC, tip_handler ); + TConfig utente( CONFIG_USER ); + TString16 codnum( utente.get( "CODNUM", "ve" ) ); + if ( !codnum.blank( ) ) + { + query_mask( ).set( F_CODNUM, codnum ); + query_mask( ).set( F_DESNUM, utente.get( "DESNUM", "ve" ) ); + } + TString16 tipodoc( utente.get( "TIPODOC", "ve" ) ); + if ( !tipodoc.blank( ) ) + { + query_mask( ).set( F_TIPODOC, tipodoc ); + query_mask( ).set( F_DESTIPODOC, utente.get( "DESTIPODOC", "ve" ) ); + } + // La maschera di inserimento/modifica per ora non la so! + // Viene letta dal profilo non appena trovato il record + _msk1 = NULL; + + // Metto in relazione testata e righe + _rel = new TRelation( LF_DOC ); + rel( ).add( LF_RIGHEDOC,"CODNUM=CODNUM|ANNO=ANNO|PROVV=PROVV|NDOC=NDOC" ); + + // Inizializzo il Record_array + _righe_rec = new TRecord_array( LF_RIGHEDOC, "NRIGA", 1 ); + + return TRUE; +} + +bool TMotore_application::user_destroy( ) +{ + // Registro l'ultimo tipo documento e l'ultima numerazione + TConfig utente( CONFIG_USER ); + utente.set( "CODNUM", query_mask( ).get( F_CODNUM ), "ve" ); + utente.set( "TIPODOC", query_mask( ).get( F_TIPODOC ), "ve" ); + utente.set( "DESNUM", query_mask( ).get( F_DESNUM ), "ve" ); + utente.set( "DESTIPODOC", query_mask( ).get( F_DESTIPODOC ), "ve" ); + // Se è ancora allocata, distruggo la maschera di modifica + if ( _msk1 ) delete _msk1; + + // Distruggo la maschera di modifica + delete _msk; + + // Distruggo la relazione + delete _rel; + + // Distruggo il Record_array + delete _righe_rec; + + return TRUE; +} + +int TMotore_application::esegui_procedura( int operazione ) +{ + // Accesso unico alla chiamata di procedure tramite operazione + int index = ( int )pro( ).get_long( nome_sezione( operazione ), "MAIN" ); + if ( index ) + return ( user_function( index ) ); + return ( NOERR ); +} + +bool TMotore_application::valida_operazione( int operazione ) +{ + if ( operazione != OP_NUOVO ) + { + if ( !stato_valido( stato_corrente( ), operazione ) ) + { + segnala_stato_non_valido( operazione ); + return FALSE; + } + } + if ( esegui_procedura( operazione ) != NOERR ) + return FALSE; + return TRUE; +} + +const char * TMotore_application::nome_sezione( int op ) +{ + switch( op ) + { + case OP_NUOVO: + return "INSERIMENTO"; + break; + case OP_MODIFICA: + return "MODIFICA"; + break; + case OP_CANCELLA: + return "CANCELLAZIONE"; + break; + case OP_STAMPA: + return "STAMPA"; + break; + case OP_RAGGRUPPA: + return "RAGGRUPPA"; + break; + case OP_USER: + return "SPECIALE"; + break; + default: + CHECK( FALSE, "tentativo di ottenere il nome di una operazione inesistente!" ); + // Per evitare la warning + return ""; + break; + } +} + +int TMotore_application::stato_finale( int operazione ) +{ + TString s( pro( ).get( "STATOFINALE", nome_sezione( operazione ) ) ); + if ( strcmp( s, "N" ) == 0 ) return NO_CHANGE_STATUS; + return ( atoi( s ) ); +} + +bool TMotore_application::stato_valido( int stato, int operazione ) +{ +#ifdef _DEBUG + warning_box( "Controllo stati validi!\nStato corrente %d.\nStati validi %s.", stato_corrente( ), ( const char * )stati_validi( operazione ) ); +#endif + char p[2] = "0"; + TToken_string ret ( stati_validi( operazione ), ',' ); + p[0] += ( char )stato; + return ( ret.get_pos( p ) != -1 ); +} + +/*void TMotore_application::setta_stato_corrente( int nuovostato ) + { + // warning_box( "Settaggio stati validi!\nStato corrente %s.\nStati validi %s.\nStato finale %s.", stato_corrente( ), stati_validi( operazione ), stato_finale( operazione ) ); + TString p; + p.format( "%d", nuovostato ); + + TLocalisamfile& doc = rel( ).lfile( LF_DOC ); + + p[ 0 ] += ( char ) nuovostato; + doc.put( "STATO", p ); + doc.rewrite( ); + query_mask( ).set( F_STATO, p ); + // warning_box( "Settaggio stati validi!\nStato corrente %s.\nStati validi %s.\nStato finale %s.", stato_corrente( ), stati_validi( operazione ), stato_finale( operazione ) ); + } */ + +int TMotore_application::stato_corrente( ) +{ + int i = query_mask( ).get_int( F_STATO ); + return ( i == 0 ? NO_DOC_STATUS : i ); +} + +void TMotore_application::segnala_stato_non_valido( int operazione ) +{ + TString messaggio; + + switch( operazione ) + { + case OP_NUOVO: + // Sempre valido + break; + case OP_MODIFICA: + messaggio = "Il documento non si trova in uno stato valido per poter essere modificato!"; + break; + case OP_CANCELLA: + messaggio = "Il documento non si trova in uno stato valido per poter essere cancellato!"; + break; + case OP_STAMPA: + messaggio = "Il documento non si trova in uno stato valido per poter essere stampato!"; + break; + case OP_RAGGRUPPA: + messaggio = "Il documento non si trova in uno stato valido per poter essere raggruppato!"; + break; + case OP_USER: + messaggio = "Il documento non si trova in uno stato valido per effettuare la operazione richiesta!"; + break; + default: + CHECK( FALSE, "Tentativo di segnalare stato non valido di una operazione non esistente!" ); + break; + } + messaggio << "\nStato corrente :%d.\nStati validi :%s."; + warning_box( messaggio, stato_corrente( ), ( const char * )stati_validi( operazione ) ); +} + +int ve0100( int argc, char** argv ) +{ + TMotore_application a; + + a.run( argc, argv, "Gestione documenti" ); + return 0; +} diff --git a/ve/ve0100.h b/ve/ve0100.h index d3d16680a..748bbeeeb 100755 --- a/ve/ve0100.h +++ b/ve/ve0100.h @@ -1,4 +1,5 @@ -#define _VE0100_H +#ifndef __VE0100_H +#define __VE0100_H // Operazioni che può fare il motore su un documento #define OP_NUOVO 1 @@ -16,3 +17,252 @@ #define F_SHEET 500 #define F_MEMORIGA 501 #define BASE_PIEDE 600 + +#define CHANGE_MESSAGE "Sono state effettuate modifiche alla configurazione.\nPrima di eseguire la gestione documenti occorrerà rigenerare le maschere.\nDesideri farlo ora ?" + +// Modifiche pianificate per il dopo/cattolica: +// Rorganizzazione del codice come: +// Oggetto documento +// che contiene: +// Array di oggetti riga +// Oggetto Cliente +// Oggetto Cambio +// Oggetto Sconto testa + + +#define F_LBTIPORIGA 175 +#define NPIEDI 40 + + +#include + +#ifndef __CHECKS_H +#include +#endif + +#ifndef __EXPR_H +#include +#endif + +#ifndef __TABUTIL_H +#include +#endif + +#ifndef __BRWAPP_H +#include +#endif + +#ifndef __RELAPP_H +#include +#endif + +#ifndef __CONFIG_H +#include +#endif + +#ifndef __LFFILES_H +#include +#endif + +#ifndef __DEFMASK_H +#include "defmask.h" +#endif + +#ifndef __VEUML_H +#include "veuml.h" +#endif + +#ifndef __VEUML1_H +#include "veuml1.h" +#endif + +#ifndef __VEUML2_H +#include "veuml2.h" +#endif + +#ifndef __SHEET_H +#include +#endif + +#ifndef __REAL_H +#include +#endif + +#ifndef __MSKSHEET_H +#include +#endif + +#ifndef __VE0100C_H +#include "ve0100c.h" +#endif + +#ifndef __VE0100D_H +#include "ve0100d.h" +#endif + +#ifndef __TCLIFOR_H +#include "tclifor.h" +#endif + +#ifndef __RIGHEDOC_H +#include "righedoc.h" +#endif + +#ifndef __VE1000O_H +#include "ve1000o.h" +#endif + +#ifndef __TMASKVEN_H +#include "tmaskven.h" +#endif + +#ifndef __EXECP_H +#include "execp.h" +#endif + +#ifndef __SCONTI_H +#include "sconti.h" +#endif + +// Definizione della classe dell'applicazione motore +class TMotore_application : public TRelation_application +{ + // Array di totalizzatori + TPiede_documento _piede; + + // Record array per la gestione delle righe + TRecord_array* _righe_rec; + + // Puntatore al profilo del documento caricato + TConfig* _pro; + + // Puntatore al nome, per evitare di ricrearlo se è uguale + TFilename* _proname; + + // Puntatore alla maschera di ricerca + TMask* _msk; + + // Puntatore alla maschera di modifica/inserimento ( dipende dal profilo ) + TMask_vendite* _msk1; + + // puntatore alla relazione + TRelation* _rel; + + // Puntatore allo sheet delle righe documento + TSheet_field* _sheet; + + // Oggetto cliente per il motore + TCliForVendite* _clifor; + + // Indica se il documento ha come soggetto un liente o un ornitore + char _tipocf; + + // Ridefinizione dei metodi virtuali + virtual bool user_create( ); + virtual bool user_destroy( ); + virtual TMask* get_mask( int mode ); + virtual bool changing_mask( int mode ); + virtual TRelation* get_relation( ) const { return _rel;} + virtual void init_insert_mode( TMask& m ); + virtual int read( TMask& m ); + virtual bool remove( void ); + virtual int write( const TMask& m ); + virtual int rewrite( const TMask& m ); + + // Punti di ingresso per le funzioni utente + + // Funzioni da associare ad ogni procedura + int user_function( int index ); + + // Funzioni per il calcolo delle righe + real user_row_calculate( TRectype& row, int index ); + + void user_set_handler( int fieldid, int index, TMask* m = NULL ); + + long prossimo_numero( bool provv ); + int avanza_numero( bool provv ); + void get_edit_mask( const char * profilo ); + void azzera_piedi( ); + void carica_piedi( ); + void somma_piedi( ); + void sottrai_piedi( ); + + // Esegue, se c'è, la procedura utente relativa ad una certa operazione + int esegui_procedura( int operazione ); + +protected: + + // Procedure e funzioni per la gestione della maschera e dei files + void read_rdoc( TMask& m ); + + // formato dipendente dallo sheet ( sono le varie colonne ) + void load_riga( TSheet_field& f, int numrig, TRectype& r ); + void store_riga( TSheet_field& f, int numrig, TRectype& r ); + + void save( TRelation* r ) const; + void set_descr ( int numrig, const char* descr ); + void carica_righe_libere( int from = -1 ); + bool check_key( TLocalisamfile& rdoc, TString16 codnum, bool provv, TString16 _anno, TString16 _ndoc ); + + // Procedure e funzioni per la gestione degli stati + // void setta_stato_corrente( int nuovostato ); + const char* nome_sezione( int op ); + int stato_corrente( ); + int stato_finale( int operazione ); + bool stato_valido( int stato, int operazione ); + void segnala_stato_non_valido( int operazione ); + TString& stati_validi( int operazione ){ return ( pro( ).get( "STATIVALIDI", nome_sezione( operazione ) ) );} + + // Handle che ritorna la maschera per le righe + static TMask * ss_getmask( int numriga, TMask& fullmask, bool destroy ); + + // Handler che gestisce la richiesta del tipo riga in inserimento + static bool ss_handler( TSheet_field& ss, int r, KEY key ); + + // Handler per la maschera di ricerca + static bool ndoc_handler( TMask_field& f, KEY key ); + static bool num_handler( TMask_field& f, KEY key ); + static bool tip_handler( TMask_field& f, KEY key ); + + // Handler per la maschera di modifica + static bool clifo_handler( TMask_field& f, KEY key ); + static bool occas_handler( TMask_field& f, KEY key ); + static bool val_handler( TMask_field& f, KEY key ); + + // Configurazione dello sheet dato il profilo + void configura_sheet( TSheet_field& sheet, TConfig& config ); + + // Funzione per la sostituzione delle variabili nella decodifica + // delle espressioni di una riga + void carica_variabile( TExpression& e, const char * varname, TRectype r ); + +public: + + // Funzioni di accesso alle variabili private + + TRecord_array& righe_rec( ) { CHECK( _righe_rec, "Record array delle righe nullo!" ); return * _righe_rec; } + TConfig& pro( ) { CHECK( _pro, "Profilo del documento nullo!" ); return *_pro; } + TFilename& proname( ) { CHECK( _proname, "Nome del profilo nullo!" ); return *_proname; } + TMask& query_mask( ) { CHECK( _msk, "Maschera di ricerca nulla!" ); return *_msk; } + TMask& edit_mask( ) { CHECK( _msk1, "Maschera di modifica nulla!" ); return *_msk1; } + TRelation& rel( ) { CHECK( _rel, "Relazione nulla!" ); return *_rel; } + TSheet_field& sheet( ) { CHECK( _sheet, "Sheet nullo!" ); return *_sheet; } + TCliForVendite& clifo( ) { CHECK( _clifor, "Oggetto cliente nullo!" ); return *_clifor; } + TPiede_documento& piede( ){ return _piede; } + + // Operazione + + const char tipocf( ){ return _tipocf; } + void tipocf( const char tcf ){ _tipocf = tcf; } + bool valida_operazione( int operazione ); + + TSheet_field& ss( ) const { return *_sheet; } + TMotore_application( ) { _pro = NULL; } + virtual ~TMotore_application( ) { if ( _pro ) delete _pro; } + virtual const char* get_next_key( ); + +}; + +TMotore_application& app( ); + +#endif diff --git a/ve/ve0100c.cpp b/ve/ve0100c.cpp index 17862dcaf..74f7e7280 100755 --- a/ve/ve0100c.cpp +++ b/ve/ve0100c.cpp @@ -1,125 +1,128 @@ -// Handler di marco sui campi delle maschere -#ifndef __CHECKS_H -#include -#endif - -#ifndef __MASK_H -#include -#endif - -#ifndef __MASKFLD_H -#include -#endif - -#ifndef __KEYS_H -#include -#endif - -#ifndef __STRINGS_H -#include -#endif - -#ifndef __VEUML_H -#include "VeUML.h" -#endif - -#ifndef __VEUML1_H -#include "VeUML1.h" -#endif - -#ifndef __VE0100C_H -#include "ve0100c.h" -#endif - -#ifndef __PAGAMENT_H -#include "..\cg\pagament.h" -#endif - -bool ora_hndl(TMask_field& field, KEY key) -{ - if (key == K_TAB) - { - if (field.to_check(key)) - { - TFixed_string ora(field.get(),6); - ora.trim(); - if (ora.not_empty() || field.required()) - { - // bool changed = FALSE; - if (isdigit(ora[0])) - { - if (ora[2] != ':') - { - if (ora.len()>4) ora.overwrite(":",2); - else ora.insert(":", 2); - // changed = TRUE; - } - } - bool ok; - ok = ((isdigit(ora[0]))&&(isdigit(ora[1]))&&(isdigit(ora[3]))&&(isdigit(ora[4]))); - ok &= ((atoi(&(ora[0]))<24)&&(atoi(&(ora[3]))<60)); - if (!ok) - { - error_box("Ora errata o formato non valido"); - return FALSE; - } - else /* if (changed) */ - { - field.set((ora)); - // field.picture_data((ora),TRUE); - // field.picture_data((ora.strip(":")),FALSE); - } - } - } - } - return TRUE; -} - -bool codcli_hndl(TMask_field& field, KEY key) -{ - if (key == K_TAB) - { - if (field.to_check(key)) - { - field.send_key(K_TAB,F_CODVAL); - field.send_key(K_TAB,F_CODLIN); - field.send_key(K_TAB,F_CODPAG); - field.send_key(K_TAB,F_CODABIA); - field.send_key(K_TAB,F_CODCABA); - field.send_key(K_TAB,F_INDSP); - } - } - return TRUE; -} - -bool dummy_hndl(TMask_field& field, KEY key) -{ - warning_box("Al campo %d è arrivato un KEY %d",field.dlg(),key); - return TRUE; -} - -bool condpag_hndl(TMask_field& field, KEY key) -{ - - if (key == K_TAB) - { - if (field.to_check(key)) - { - TMask& m = field.mask( ); - TString16 condpag( m.get( F_CODPAG ) ); - TString16 data( m.get( F_DATAINSC ) ); - if ( condpag.blank( ) || data.blank( ) ) - return TRUE; - TPagamento pag( condpag, data ); - pag.set_total( 100, 10, 10 ); - pag.set_rate_auto( ); - int numrate = pag.n_rate( ); - for( int i = 0; i < numrate; i ++ ) - m.set( F_DATASCAD1 + i, pag.data_rata( i ).string( ) ); - for( ; i < 5; i ++ ) - m.hide( F_DATASCAD1 + i ); - } - } - return TRUE; -} - +// Handler di MarcoclaD sui campi delle maschere + +#ifndef __CHECKS_H +#include +#endif + +#ifndef __MASK_H +#include +#endif + +#ifndef __MASKFLD_H +#include +#endif + +#ifndef __KEYS_H +#include +#endif + +#ifndef __STRINGS_H +#include +#endif + +#ifndef __VEUML_H +#include "VeUML.h" +#endif + +#ifndef __VEUML1_H +#include "VeUML1.h" +#endif + +#ifndef __VE0100C_H +#include "ve0100c.h" +#endif + +#ifndef __PAGAMENT_H +#include "..\cg\pagament.h" +#endif + +#ifndef __SCONTI_H +#include "sconti.h" +#endif + +bool ora_hndl( TMask_field& field, KEY key ) +{ + if (key == K_TAB) + { + if (field.to_check(key)) + { + TFixed_string ora( field.get( ), 6 ); + ora.trim( ); + if (ora.not_empty( ) || field.required( ) ) + { + if ( isdigit( ora[ 0 ] ) ) + { + if ( ora[ 2 ] != ':') + { + if ( ora.len( ) > 4 ) + ora.overwrite( ":", 2 ); + else + ora.insert( ":", 2 ); + } + } + bool ok; + ok = ((isdigit(ora[0]))&&(isdigit(ora[1]))&&(isdigit(ora[3]))&&(isdigit(ora[4]))); + ok &= ((atoi(&(ora[0]))<24)&&(atoi(&(ora[3]))<60)); + if ( !ok ) + { + error_box("Ora errata o formato non valido"); + return FALSE; + } + else + { + field.set((ora)); + } + } + } + } + return TRUE; +} + +bool dummy_hndl( TMask_field& field, KEY key ) +{ + warning_box( "Al campo %d è arrivato un KEY %d", field.dlg( ), key ); + return TRUE; +} + +// Handler per il calcolo delle date di pagamento +bool condpag_hndl( TMask_field& field, KEY key ) +{ + if ( key == K_TAB ) + { + TMask& m = field.mask( ); + TString16 condpag( m.get( F_CODPAG ) ); + TString16 data( m.get( F_DATAINSC ) ); + if ( condpag.blank( ) || data.blank( ) ) + return TRUE; + TPagamento pag( condpag, data ); + pag.set_total( 100, 10, 10 ); + pag.set_rate_auto( ); + int numrate = pag.n_rate( ); + for( int i = 0; i < numrate; i ++ ) + m.set( F_DATASCAD1 + i, pag.data_rata( i ).string( ) ); + for( ; i < 5; i ++ ) + m.hide( F_DATASCAD1 + i ); + } + return TRUE; +} + +// handler per la validazione di una stringa/sconto +bool sconto_hndl( TMask_field& field, KEY key ) +{ + if ( field.to_check( key, TRUE ) ) + { + if (key == K_TAB) + { + TSconto s; + s.set( field.get( ), TRUE ); + if( s.is_valid( ) ) + { + field.set( s.get( ) ); + return TRUE; + } + else + return FALSE; + } + } + return TRUE; +} diff --git a/ve/ve0100c.h b/ve/ve0100c.h index 40a587441..b51d45a45 100755 --- a/ve/ve0100c.h +++ b/ve/ve0100c.h @@ -1,8 +1,8 @@ -#define __VE0100C_H - -// Handlers per i campi delle bolle - -extern bool ora_hndl(TMask_field& field, KEY key); -extern bool codcli_hndl(TMask_field& field, KEY key); -extern bool dummy_hndl(TMask_field& field, KEY key); +#define __VE0100C_H + +// Handlers per i campi delle bolle + +extern bool ora_hndl(TMask_field& field, KEY key); +extern bool codcli_hndl(TMask_field& field, KEY key); +extern bool dummy_hndl(TMask_field& field, KEY key); extern bool condpag_hndl(TMask_field& field, KEY key); \ No newline at end of file diff --git a/ve/ve0200.cpp b/ve/ve0200.cpp index e7ff9bef2..1056c9b9c 100755 --- a/ve/ve0200.cpp +++ b/ve/ve0200.cpp @@ -1,120 +1,120 @@ -#include - -#ifndef __CHECKS_H -#include -#endif - -#ifndef __CONFAPP_H -#include -#endif - -#ifndef __EXECP_H -#include -#endif - -#ifndef __TABUTIL_H -#include -#endif - -#define SINTASSI "Sintassi: VE0 -2 [a|b|c|d|e]" - -class TConf_vendite : public TConfig_application -{ - private: - - bool _changed; - - public: - - virtual bool preprocess_config (TMask& mask, TConfig& config); - virtual bool postprocess_config_changed (const char* par, const char* var, - const char* oldv, const char* newv); - virtual bool postprocess_config (TMask& mask, TConfig& config); - virtual bool user_create( ); - virtual bool user_destroy( ); - - TConf_vendite() : TConfig_application( CONFIG_DITTA ){ } - virtual ~TConf_vendite( ){ } -}; - -bool TConf_vendite::preprocess_config (TMask& mask, TConfig& config) -{ - disable_menu_item(M_FILE_NEW); - disable_menu_item(M_FILE_REVERT); - return TRUE; -} - -bool TConf_vendite::postprocess_config (TMask& mask, TConfig& config) -{ - enable_menu_item(M_FILE_NEW); - enable_menu_item(M_FILE_REVERT); - return TRUE; -} - - -bool TConf_vendite::postprocess_config_changed (const char* par, const char* var, - const char* oldv, const char* newv) -{ - // Notifica al motore che la configurazione è cambiata: occorre rigenerare le maschere - _changed = TRUE; - return TRUE; -} - -bool TConf_vendite::user_create( ) -{ - TString16 arg( argv(2) ); - _changed = FALSE; - // Il fottuto meno serve per evitare fottutamente che la fottuta confapp - // si fotta il fottuto parametro - if( arg[ 0 ] != '-' ) - fatal_box( SINTASSI ); - char msk = arg[1]; - // Devo usare un puntatore così deletandolo si registra - TConfig confditta( CONFIG_DITTA ); - // Prima usavo le lettere ma la fottuta confapp si fotte il fottuto -c per i suoi fottuti - // motivi, così uso i fottuti numeri - switch( msk ) - { - case '1': - confditta.set( "EdMask", "ve0200a", "ve" ); - break; - case '2': - confditta.set( "EdMask", "ve0200b", "ve" ); - break; - case '3': - confditta.set( "EdMask", "ve0200c", "ve" ); - break; - case '4': - confditta.set( "EdMask", "ve0200d", "ve" ); - break; - case '5': - confditta.set( "EdMask", "ve0200e", "ve" ); - break; - default: - fatal_box( SINTASSI ); - return FALSE; - break; - } - return TRUE; -} - -bool TConf_vendite::user_destroy( ) -{ - if( _changed ) - { - TConfig confditta( CONFIG_DITTA ); - confditta.set( "EdMask", "", "ve" ); - confditta.set( "CHANGED", "X", "ve" ); - } - return TRUE; -} - -int ve0200(int argc, char** argv) -{ - TConf_vendite appc; - - if( argc < 3 ) - fatal_box( SINTASSI ); - appc.run(argc, argv, "Parametri gestione vendite"); - return 0; -} +#include + +#ifndef __CHECKS_H +#include +#endif + +#ifndef __CONFAPP_H +#include +#endif + +#ifndef __EXECP_H +#include +#endif + +#ifndef __TABUTIL_H +#include +#endif + +#define SINTASSI "Sintassi: VE0 -2 -[1|2|3|4|5]" + +class TConf_vendite : public TConfig_application +{ +private: + + bool _changed; + +public: + + virtual bool preprocess_config (TMask& mask, TConfig& config); + virtual bool postprocess_config_changed (const char* par, const char* var, + const char* oldv, const char* newv); + virtual bool postprocess_config (TMask& mask, TConfig& config); + virtual bool user_create( ); + virtual bool user_destroy( ); + + TConf_vendite() : TConfig_application( CONFIG_DITTA ){ } + virtual ~TConf_vendite( ){ } +}; + +bool TConf_vendite::preprocess_config (TMask& mask, TConfig& config) +{ + disable_menu_item(M_FILE_NEW); + disable_menu_item(M_FILE_REVERT); + return TRUE; +} + +bool TConf_vendite::postprocess_config (TMask& mask, TConfig& config) +{ + enable_menu_item(M_FILE_NEW); + enable_menu_item(M_FILE_REVERT); + return TRUE; +} + + +bool TConf_vendite::postprocess_config_changed (const char* par, const char* var, + const char* oldv, const char* newv) +{ + // Notifica al motore che la configurazione è cambiata: occorre rigenerare le maschere + _changed = TRUE; + return TRUE; +} + +bool TConf_vendite::user_create( ) +{ + TString16 arg( argv(2) ); + _changed = FALSE; + // Il fottuto meno serve per evitare fottutamente che la fottuta confapp + // si fotta il fottuto parametro + if( arg[ 0 ] != '-' ) + fatal_box( SINTASSI ); + char msk = arg[1]; + // Devo usare un puntatore così deletandolo si registra + TConfig confditta( CONFIG_DITTA ); + // Prima usavo le lettere ma la fottuta confapp si fotte il fottuto -c per i suoi fottuti + // motivi, così uso i fottuti numeri + switch( msk ) + { + case '1': + confditta.set( "EdMask", "ve0200a", "ve" ); + break; + case '2': + confditta.set( "EdMask", "ve0200b", "ve" ); + break; + case '3': + confditta.set( "EdMask", "ve0200c", "ve" ); + break; + case '4': + confditta.set( "EdMask", "ve0200d", "ve" ); + break; + case '5': + confditta.set( "EdMask", "ve0200e", "ve" ); + break; + default: + fatal_box( SINTASSI ); + return FALSE; + break; + } + return TRUE; +} + +bool TConf_vendite::user_destroy( ) +{ + if( _changed ) + { + TConfig confditta( CONFIG_DITTA ); + confditta.set( "EdMask", "", "ve" ); + confditta.set( "CHANGED", "X", "ve" ); + } + return TRUE; +} + +int ve0200(int argc, char** argv) +{ + TConf_vendite appc; + + if( argc < 3 ) + fatal_box( SINTASSI ); + appc.run(argc, argv, "Parametri gestione vendite"); + return 0; +} diff --git a/ve/ve0200b.h b/ve/ve0200b.h index a86612125..2275553ed 100755 --- a/ve/ve0200b.h +++ b/ve/ve0200b.h @@ -1,12 +1,12 @@ -#define F_TIPOPERC 101 -#define F_GESARCHPROV 102 -#define F_ARCHPROV1 103 -#define F_ARCHPROV2 104 -#define F_ARCHPROV3 105 -#define F_ARCHPROV4 106 -#define F_TIPOLIQPROV 107 -#define F_GESVAL 108 -#define F_GESLIN 109 -#define F_GESSOSPIMP 110 -#define F_GESOCCAS 111 -#define F_GESOCCHK 112 +#define F_TIPOPERC 101 +#define F_GESARCHPROV 102 +#define F_ARCHPROV1 103 +#define F_ARCHPROV2 104 +#define F_ARCHPROV3 105 +#define F_ARCHPROV4 106 +#define F_TIPOLIQPROV 107 +#define F_GESVAL 108 +#define F_GESLIN 109 +#define F_GESSOSPIMP 110 +#define F_GESOCCAS 111 +#define F_GESOCCHK 112 diff --git a/ve/ve0300.cpp b/ve/ve0300.cpp index 0f37154a6..ba7c8cdb8 100755 --- a/ve/ve0300.cpp +++ b/ve/ve0300.cpp @@ -1,1254 +1,1408 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - - "Compilatore di profili" per la gestione vendite. - Considerando: - - Profilo documento - - Configurazione vendite per la ditta - - Condizioni atmosferiche - genera le maschere appropriate. - Accetta sulla riga di comando il nome del profilo documento per cui deve generare - la maschera. Il nome del file .MSK viene dedotto dal profilo documento stesso. - - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#ifndef __CHECKS_H -#include -#endif - -#ifndef __FSTREAM_H -#include -#endif - -#ifndef __SCANNER_H -#include -#endif - -#ifndef __CONFIG_H -#include -#endif - -#ifndef __APPLICATION_H -#include -#endif - -#ifndef __UTILITY_H -#include -#endif - -#ifndef __PROGIND_H -#include -#endif - -#ifndef __TABUTIL_H -#include -#endif - -#ifndef __DEFMASK_H -#include -#endif - -#ifndef __RELATION_H -#include -#endif - -#ifndef __VE0100_H -#include "ve0100.h" -#endif - -#ifndef __VEUML_H -#include "veuml.h" -#endif - -#ifndef __VEUML1_H -#include "veuml1.h" -#endif - -#ifndef __LFFILES_H -#include "lffiles.h" -#endif - -#ifndef __VEINI_H -#include "veini.h" -#endif - -// Significato delle colonne nella tabella _tab0300b -#define B_NOME 0 -#define B_MSKTYPE 1 -#define B_MSKSIZE 2 -#define B_DESCR 3 -#define B_WIDTH 4 - -// Significato dei campi nel profilo del documento -#define P_STATO 0 -#define P_PROMPT 1 -#define P_HELP 2 -#define P_WARNING 3 - - -// Numero massimo di linee per pagina - -#define MAX_LINES_PER_PAGE 16 -#define MASK_FIRST_LINE 6 - -class TMaschera : public TObject -{ - -private: - - // Linea corrente - int _curline; - - // Pagina corrente - int _curpage; - -public: - - void advance_line( ){ _curline ++; }; - - // Genera una serie di righe uguali per funzione ( DISPLAY, ecc. ) - void outline( const TString& s = "", const TString& prefix = "", const char sep = '~' ); - - // Crea un controllo del tipo specificato - void control( const int type, const int id = DLG_NULL, const int size = -1 ); - - // CHECKTYPE - void check( const int i ); - - // PAGE - void pagina( const int i ){ _out << "PA \"Pagina " << i << "\" 11 60 14\n"; }; - - // PROMPT - void prompt( const int x, const int y, const TString& s = "" ){ _out << "PR " << x << " " << y << " \"" << s << "\"\n"; }; - - // BEGIN - void begin( void ) { outline ( "BE" ); }; - - // END - void end( void ) { outline ( "EN" ); }; - - // ENDMASK - void endmask( void ) { outline ( "ENDMASK" ); }; - - // FLAG - void flag( const TString& s ) { _out << "FLAG \"" << s << "\"\n"; }; - - // HELP - void help( const TString& s ) { _out << "HE \"" << s << "\"\n"; }; - - // WARNING - void warning( const TString& s ) { _out << "WA \"" << s << "\"\n"; }; - - // GROUP - void group( const int g ) { _out << "GR " << g << "\n"; }; - - // FIELD - void field( const TString& s ) { outline( s, "FI "); }; - - // ITEM - void item( const TString& s ); - - // MESSAGE - void message( const TString& s ) { outline( s, "ME "); }; - - // USE - void use( const TString& s ){ outline( s, "US " ); }; - void use( const int file, const int key ){ _out << "US " << file << " KEY " << key << "\n"; }; - - // DISPLAY - void display( const TString& s ){ outline( s, "DI " ); }; - - // INPUT - void input( const TString& s ){ outline( s, "IN " ); }; - - // OUTPUT - void output( const TString& s ){ outline( s, "OU " ); }; - - // Funzioni per la lettura/scrittura di CURPAGE - int page( ) { return _curpage; }; - void page( const int i ){ _curpage = i; }; - - // Funzioni per la lettura/scrittura di CURLINE - int line( ) { return _curline; }; - void line( const int i ){ _curline = i; }; - - // Costruttore, vuole il nome del file .INI - TMaschera( const TFilename outfile ); - - // Vero se la pagina è aperta - bool _pageopen; - - // File .MSK di output - ofstream _out; - - -}; - - -TMaschera::TMaschera( const TFilename outfile ) : _out( outfile ) -{ - _curline = 1; - _curpage = 1; - _pageopen = FALSE; - bool _groupopen = FALSE; -} - -void TMaschera::outline( const TString& s, const TString& prefix, const char sep ) -{ - if ( s.left( 1 ) == "@" ) - _out << "CO " << prefix << s.mid( 1 ) << "\n"; - else - { TToken_string u( s, sep ); - for ( int i = 0; i < u.items(); i ++ ) - _out << prefix << u.get( i ) << "\n"; - } -} - -void TMaschera::check( const int i ) -{ - switch( i ) - { - case S_OBBLIGATORIO: - outline ( "CH REQUIRED" ); - break; - default: - outline ( "CH NORMAL" ); - break; - } -} - -void TMaschera::control( const int type, const int id, const int size ) -{ - switch ( type ) - { - case T_DATA: - _out << "DA"; - break; - case T_STRINGA: - _out << "ST"; - break; - case T_CHECKBOX: - _out << "BO"; - break; - case T_NUMERO: - _out << "NU"; - break; - case T_LISTA: - _out << "LI"; - break; - case T_MEMO: - _out << "ME"; - break; - case T_CORNICE: - _out << "GR"; - break; - case T_BOTTONE: - _out << "BU"; - break; - } - _out << " " << id; - if ( size > 0 ) - { - if ( size > 100 ) - _out << " " << ( int )( size / 100 ) << " " << ( size % 100 ); - else - _out << " " << size; - } - _out << "\n"; -} - -void TMaschera::item( const TString& str ) -{ - int i, j; - TToken_string u( str, '@' ); - TToken_string s; - - for( i = 0; i < u.items(); i ++ ) - { - _out << "IT \"" << s[ 0 ] << "\"\n"; - for( j = 1; j < s.items(); j ++ ) - _out << "ME " << s[ j ] << "\n"; - } -} - -class TGruppo : public TObject -{ -protected: - - int _id; - int _height; - bool _present; - -public: - - void id( int id ){ _id = id; } - int id( ){ return _id; } - void height( int h ){ _height = h; } - int height( ){ return _height; } - void present( bool p ){ _present = p; } - bool present( ){ return _present; } - - TGruppo ( int i ); - TGruppo ( int i, TConfig& pro ); -}; - -TGruppo::TGruppo( int i ) -{ - TConfig pro( "ve0300c.ini" ); - _id = i; - _height = pro.get_int( "HEIGHT", format( "%d", i ) ); -}; - -TGruppo::TGruppo( int i, TConfig& pro ) -{ - _id = i; - _height = pro.get_int( "HEIGHT", format( "%d", i ) ); -}; - -class TField : public TObject -{ -protected: - - TString _nome; - int _gruppo; - int _id; - int _type; - int _size; - int _stato; - int _x, _y; - TString _prompt, _flag, _help, _warning, _fieldname; - TToken_string _use, _input, _display, _output, _special, _items, _configs; - -public: - - TField( TString& campo, TConfig& pro ); - TField( ); - - void genera( TMaschera& _m ); - void configura( TConfig& pro ); - - void x( int x ){ _x = x; } - void y( int y ){ _y = y; } - void gruppo( int gruppo ){ _gruppo = gruppo; } - void id( int id ){ _id = id; } - void type( int type ){ _type = type; } - void size( int size ){ _size = size; } - void stato( int stato ){ _stato = stato; } - int x( ){ return _x; } - int y( ){ return _y; } - int gruppo( ){ return _gruppo; } - int id( ){ return _id; } - int type( ){ return _type; } - int size( ){ return _size; } - int stato( ){ return _stato; } - - - void nome( TString& nome ){ _nome = nome; } - void prompt( TString& prompt ){ _prompt = prompt; } - void flag( TString& flag ){ _flag = flag; } - void help( TString& help ){ _help = help; } - void warning( TString& warning ){ _warning = warning; } - void fieldname( TString& fieldname ){ _fieldname = fieldname; } - TString& nome( ){ return _nome; } - TString& prompt( ){ return _prompt; } - TString& flag( ){ return _flag; } - TString& help( ){ return _help; } - TString& warning( ){ return _warning; } - TString& fieldname( ){ return _fieldname; } - - void use( TToken_string& use ){ _use = use; } - void input( TToken_string& input ){ _input = input; } - void display( TToken_string& display ){ _display = display; } - void output( TToken_string& output ){ _output = output; } - void special( TToken_string& special ){ _special = special; } - void items( TToken_string& items ){ _items = items; } - void configs( TToken_string& configs ){ _configs = configs; } - TToken_string& use( ){ return _use; } - TToken_string& input( ){ return _input; } - TToken_string& display( ){ return _display; } - TToken_string& output( ){ return _output; } - TToken_string& special( ){ return _special; } - TToken_string& items( ){ return _items; } - TToken_string& configs( ){ return _configs; } - - - friend int sort_by_group(const TObject** o1, const TObject** o2 ); - // friend int TMask_generator::group( const TField& f1 ); -}; - -int sort_by_group(const TObject** o1, const TObject** o2 ) -{ - int g1 = ((TField * )( *o1 ))->_gruppo; - int g2 = ((TField * )( *o2 ))->_gruppo; - return ( g1 < g2 ) ? -1 : ( ( g1 = g2 ) ? 0 : 1 ); -}; - -TField::TField( TString& campo, TConfig& pro ) : _nome( campo ) -{ - _nome.trim( ); - _fieldname = pro.get( "FIELDNAME", campo ); - _x = _gruppo = pro.get_int( "X", campo ); - _y = _gruppo = pro.get_int( "Y", campo ); - _gruppo = pro.get_int( "GROUP", campo ); - CHECK( _gruppo != 0, "Gruppo uguale a 0" ); - _id = pro.get_int( "MSKID", campo ); - CHECK( _id != 0, "Campo con MSKID uguale a 0" ); - _type = pro.get_int( "TYPE", campo ); - _size = pro.get_int( "SIZE", campo ); - _prompt = pro.get( "PROMPT", campo ); - if( _prompt[ 0 ] == '\"' ) - { - _prompt.ltrim( 1 ); - _prompt.rtrim( 1 ); - }; - _flag = pro.get( "FLAG", campo ); - _help = pro.get( "FLAG", campo ); - _warning = pro.get( "FLAG", campo ); - _use = pro.get( "USE", campo ); - _use.separator( '~' ); - _input = pro.get( "INPUT", campo ); - _input.separator( '~' ); - _display = pro.get( "DISPLAY", campo ); - _display.separator( '~' ); - _output = pro.get( "OUTPUT", campo ); - _output.separator( '~' ); - _special = pro.get( "SPECIAL", campo ); - _special.separator( '~' ); - _configs = pro.get( "CONFIGS", campo ); - _configs.separator( '~' ); - _items = ""; - int last = pro.get_int( "NITEMS", campo ); - for( int i = 1; i <= last; i ++ ) - _items.add( pro.get( "ITEM", campo, i ) ); -}; - -TField::TField( ) -{ - _nome = ""; - _fieldname = ""; - _x = 0; - _y = 0; - _gruppo = 0; - _id = 0; - _type = 0; - _size = 0; - _prompt = ""; - _flag = ""; - _help = ""; - _warning = ""; - _use = ""; - _use.separator( '~' ); - _input = ""; - _input.separator( '~' ); - _display = ""; - _display.separator( '~' ); - _output = ""; - _output.separator( '~' ); - _special = ""; - _special.separator( '~' ); - _configs = ""; - _configs.separator( '~' ); - _items = ""; - _items.separator( '@' ); -} - -void TField::configura( TConfig& pro ) -{ - TToken_string riga_profilo( pro.get( _nome, "PROFILO" ) ); - TString newprompt( riga_profilo.get( P_PROMPT ) ) ; - TString newhelp( riga_profilo.get( P_HELP ) ) ; - TString newwarning( riga_profilo.get( P_WARNING ) ) ; - if ( ! newprompt.blank( ) ) - _prompt = newprompt; - if ( ! newhelp.blank( ) ) - _help = newhelp; - if ( ! newwarning.blank( ) ) - _warning = newwarning; -} - -void TField::genera( TMaschera& m ) -{ - TString s; - - if ( _stato == S_NASCOSTO ) - return; - if ( _size != 0 ) - m.control( _type, _id, _size ); - else - m.control( _type, _id ); - m.begin(); - switch( _stato ) - { - case S_DISABILITATO : - m.prompt( _x, _y + m.line( ), _prompt ); - s = "D"; - s << _flag; - m.flag( s ) ; - break; - case S_NORMALE : - case S_OBBLIGATORIO : - m.prompt( _x, _y + m.line( ), _prompt ); - m.flag( _flag ); - break; - } - m.check( _stato ); - if ( !_fieldname.blank( ) ) m.field( _fieldname ); - if ( !_items.blank( ) ) m.item( _items ); - if ( !_use.blank( ) ) m.use( _use ); - if ( !_input.blank( ) ) m.input( _input ); - if ( !_display.blank( ) ) m.display( _display ); - if ( !_output.blank( ) ) m.output( _output ); - if ( !_help.blank( ) ) m.help( _help ); - if ( !_warning.blank( ) ) m.warning( _warning ); - if ( !_special.blank( ) ) m.outline( _special ); - m.end(); - if ( ( m.line() > MAX_LINES_PER_PAGE ) && ( m._pageopen == TRUE)) - { - m.end(); - m._pageopen = FALSE; - m.line( MASK_FIRST_LINE ); - } -} - - -class TMask_generator -{ - -private: - - // Identificatore corrente per lo sheet - int _curid; - - // vero se il gruppo è aperto - bool _groupopen; - - // nome del file di .INI di input - TFilename _proname; - - // File .INI di riferimento per i campi - TConfig _fieldsini; - - // File .INI di riferimento per i gruppi - TConfig _groupsini; - - // File .INI di input - TConfig* _pro; - - TConfig _ditta; - - // Tabelle per la generazione - - // Campi dei documenti - TString_array _fields; - - // Campi dello sheet - TString_array _tab0300b; - - TArray _campi; - -protected: - - // Carica un file di tabella in un TString array - void carica_tabella( const TFilename& fn, TString_array& tabella ); - - // Scrive sul file di output una serie di righe uguali per funzione ( DISPLAY, ecc. ) - void outline( const TString& s = "", const TString& prefix = "", const char sep = '~' ); - - - // Crea un controllo del tipo specificato - void control( const int type, const int id = DLG_NULL, const int size = -1 ); - - // Ritorna vero se una componente della maschera è presente - int present( const int i, TToken_string line ){ const TString s = line.get( i ); return !(s.blank( )); }; - - // Carica dati dei campi - void carica_dati_campi( const TFilename& fn, TArray& a ); - - // Funzioni di accesso alle variabili private - // ------------------------------------------ - - // Funzioni per la lettura/scrittura di ID. Si incrementa da solo. - int id ( ) { return( _curid++ ); }; - void id( const int i ){ _curid = i; }; - - - // Funzioni di generazione ad alto livello - // --------------------------------------- - - // Genera un campo a partire da una linea del file VE0300A.DAT - void genera_campo( TToken_string _line ); - - // Genera un campo dello sheet a partire da una linea del file VE0300B.DAT - void genera_campo_sheet( TToken_string _line ); - - - // Genera la colonna dello sheet a partire da una linea del file VE0300B.DAT - void genera_item_sheet( TToken_string _line ); - - // Genera l'intestazione di una pagina ( non la prima ) - void intestazione_pagina( ); - - // Ritorna lo stato che dovrà avere il campo sulla maschera da generare - int stato_del_campo( TString campo ); - -public: - - TMaschera * _m; - - // Costruttore, vuole il nome del file .INI - TMask_generator( const TString& profilo ); - - // Attiva la generazione della maschera - void genera( const TString& ); - - // Distruttore - virtual ~TMask_generator( ); - -}; - -// Definizione dei metodi di TMask_generator -// ----------------------------------------- - -TMask_generator::TMask_generator( const TString& profilo ) : _fieldsini( "ve0300a.ini" ), _groupsini( "ve0300c.ini" ), _ditta( CONFIG_DITTA ) -{ - CHECK( fexist( "ve0300a.ini" ), "Il file ve0300a.ini non esiste!" ); - _fieldsini.list_paragraphs( _fields ); - CHECK( fexist( "ve0300b.dat" ), "Il file ve0300b.dat non esiste!" ); - carica_tabella( "ve0300b.dat", _tab0300b ); - carica_dati_campi( "ve0300a.ini", _campi ); - TString16 param( profilo ); - param.lower( ); - if( param == "-all" ) - { - TRelation rel("TIP"); - TCursor t( &rel ); - long count = t.items(); - TProgind bar( count, "Generazione delle maschere", FALSE, TRUE); - t = 0; - while( t.ok() ) - { - genera( t.curr().get( "S4" ) ); - ++t; - bar.addstatus(1); - } - } - else genera( profilo ); -} - -TMask_generator::~TMask_generator( ) -{ - -}; - - -void TMask_generator::carica_dati_campi( const TFilename& fn, TArray& a ) -{ - TScanner infile( fn ); - TString line; - TField *campo = NULL; - - while ( infile.ok( ) ) - { - line = infile.line( ); - line.trim( ); - while ( ( line.empty() || line[ 0 ] == '#' || line.left( 2 ) == "//" ) && infile.ok( ) ) - { - line = infile.line( ); - line.trim(); - } - if( infile.ok( ) ) - { - if ( line[ 0 ] == '[' ) // Carica un un campo - { - line.strip( "[]" ); - if ( campo ) - a.add( campo ); - campo = new TField(); - campo->nome( line ); - } - else - { - int pos; - if( ( pos = line.find( '=' ) ) == 0 ) - yesnofatal_box( "Linea errata nel file.INI: %s", (const char *) line ); - else - { - TString key = line.sub( 0, pos ); - key.trim(); - TString value = line.mid( pos + 1 ); - value.trim(); - if( key == "X" ) - campo->x( atoi( value ) ); - else if( key == "Y" ) - campo->y( atoi( value ) ); - else if( key == "GROUP" ) - campo->gruppo( atoi( value ) ); - else if( key == "FIELDNAME" ) - campo->fieldname( value ); - else if( key == "MSKID" ) - campo->id( atoi( value ) ); - else if( key == "TYPE" ) - campo->type( atoi( value ) ); - else if( key == "SIZE" ) - campo->size( atoi( value ) ); - else if( key == "PROMPT" ) - { - if( value[ 0 ] == '"' ) - { - value.rtrim( 1 ); - value.ltrim( 1 ); - }; - campo->prompt( value ); - } - else if( key == "FLAG" ) - campo->flag( value ); - else if( key == "USE" ) - campo->use( (TToken_string & ) value ); - else if( key == "INPUT" ) - campo->input( (TToken_string & )value ); - else if( key == "DISPLAY" ) - campo->display( (TToken_string & )value ); - else if( key == "OUTPUT" ) - campo->output( (TToken_string & )value ); - else if( key == "WARNING" ) - campo->warning( value ); - else if( key == "HELP" ) - campo->help( value ); - else if( key == "SPECIAL" ) - campo->special( (TToken_string & )value ); - else if( key == "ITEMS" ) - campo->items( (TToken_string & )value ); - else if( key == "CONFIGS" ) - campo->configs( (TToken_string & )value ); - else yesnofatal_box( "Chiave non trovata(%s)", (const char *) key ); - } - } - } - } - if ( campo ) - a.add( campo ); -} - -void TMask_generator::carica_tabella( const TFilename& fn, TString_array& tabella ) -{ TScanner in( fn ); - TToken_string line = in.line(); - while( line.not_empty( ) ) - { // Attacca tutte le righe che finiscono con § - while ( line.right( 1 ) == "§" ) - { line.rtrim( 1 ); - line << in.line( ); - }; - tabella.add( line ); - line = in.line(); - } -}; - -int TMask_generator::stato_del_campo( TString campo ) -{ - // Strategia al 28/08/95 - // Se il campo, nel file .INI di definizione dei campi, è legato a qualche voce in - // configurazione, legge il suo stato, altrimenti assume il massimo. - // Va poi a verificare nel .INI da compilare, e verifica li' la impostazione. - // Controlla poi la impostazione per il gruppo, come impostato nel file .INI - // e nella sezione CONFIGS nel .INI di defiunizione dei gruppi. - // Utilizza poi la minore delle due. - TToken_string config( _fieldsini.get( "CONFIGS", campo ) ); - int items = config.items( ); - int stato = S_OBBLIGATORIO; - for ( int i = 0; i < items; i += 3 ) - { TString chiave = config[ i ]; - TString valore = config[ i + 1 ]; - TString reale = _ditta.get( chiave, "VE" ); - if ( reale == valore ) - stato = atoi( ( char * ) config[ i + 2 ] ); - }; - TToken_string riga_profilo( _pro->get( campo, "PROFILO" ) ); - int stato_profilo = riga_profilo.get_int( P_STATO ); - stato = ( stato < stato_profilo )? stato : stato_profilo; - TString gruppo ( _fieldsini.get( "GROUP", campo ) ); - gruppo.trim( ); - config = ( _groupsini.get( "CONFIGS", gruppo ) ); - int stato_gruppo = S_OBBLIGATORIO; - for ( i = 0; i < items; i += 3 ) - { TString chiave = config[ i ]; - TString valore = config[ i + 1 ]; - TString reale = _ditta.get( chiave, "VE" ); - if ( reale == valore ) - stato_gruppo = atoi( ( char * ) config[ i + 2 ] ); - }; - stato = ( stato < stato_gruppo )? stato : stato_gruppo; - int stato_gruppo_profilo = _pro->get_int( gruppo, "PROFILOGRUPPO" ); - stato = ( stato < stato_gruppo_profilo )? stato : stato_gruppo_profilo; - return stato; - -} - -void TMask_generator::genera_campo_sheet( TToken_string _line ) -{ - const int type( _line.get_int( B_MSKTYPE ) ); - _m->control( type, id( ), _line.get_int( B_MSKSIZE ) ); - _m->begin( ); - _m->prompt( 2, 2 ); - _m->field( _line.get( B_NOME ) ); - _m->end( ); -} - -void TMask_generator::genera_item_sheet( TToken_string _line ) -{ - _m->_out << "IT \"" << _line.get( B_DESCR ); - _m->_out << "@" << _line.get_int( B_WIDTH ) << "\"\n"; -} - -void TMask_generator::intestazione_pagina( ) -{ - _m->page( _m->page( ) + 1 ); - _m->pagina( _m->page( ) ); - - _m->control( T_CORNICE, DLG_NULL, 7806 ); - _m->begin( ); - _m->prompt( 1, 0, "" ); - _m->end( ); - - _m->control( T_STRINGA, DLG_NULL, 4 ); - _m->begin(); - _m->prompt( 2, 1, "Cod. num. " ); - _m->group( 2 ); - _m->flag( "DUZ" ); - _m->end(); - - _m->control( T_STRINGA, DLG_NULL, 50 ); - _m->begin(); - _m->prompt( 24, 1 ); - _m->flag( "DU" ); - _m->group( 3 ); - _m->end(); - - _m->control( T_STRINGA, DLG_NULL, 4 ); - _m->begin(); - _m->prompt( 2, 2, "Tipo doc. " ); - _m->flag( "DU" ); - _m->group( 4 ); - _m->end(); - - _m->control( T_STRINGA, DLG_NULL, 50 ); - _m->begin(); - _m->prompt( 24, 2 ); - _m->flag( "DU" ); - _m->group( 5 ); - _m->end(); - - _m->control( T_NUMERO, DLG_NULL, 6 ); - _m->begin(); - _m->prompt( 2, 3, "Doc.: nr. " ); - _m->group( 6 ); - _m->flag( "D" ); - _m->end(); - - _m->control( T_DATA ); - _m->begin(); - _m->prompt( 24, 3, "Data " ); - _m->group( 7 ); - _m->flag( "D" ); - _m->end(); - - _m->control( T_NUMERO, DLG_NULL, 1 ); - _m->begin(); - _m->prompt( 50, 3, "Stato " ); - _m->group( 8 ); - _m->flag( "D" ); - _m->end(); - - _m->control( T_STRINGA, DLG_NULL, 4 ); - _m->begin(); - _m->prompt( 66, 3, "Es. " ); - _m->flag( "D" ); - _m->group( 9 ); - _m->end(); - - _m->control( T_STRINGA, DLG_NULL, 6 ); - _m->begin(); - if ( _pro->get( "TIPOCF", "MAIN" ) == "C" ) - _m->prompt( 2, 4, "Cliente " ); - else - _m->prompt( 2, 4, "Fornitore " ); - _m->flag( "D" ); - _m->group( 10 ); - _m->end(); - - _m->control( T_STRINGA, DLG_NULL, 50 ); - _m->begin(); - _m->prompt( 24, 4, "" ); - _m->flag( "D" ); - _m->group( 11 ); - _m->end(); - -} - -void TMask_generator::genera( const TString& profilo ) -{ - int i; - TString temp_s; - TFilename proname( profilo ), - // All'inizio il gruppo è 'chiuso' - _groupopen = FALSE; - - // Forza l'estensione al profilo - proname.ext( "ini" ); - - // Se il file di profilo non esiste, esci con un errore fatale - if ( !fexist( proname ) ) - fatal_box( "Il file %s non esiste!", ( const char * )proname ); - - _pro = new TConfig( proname ); - - TFilename _mskname( _pro->get( "MSKFILE", "MAIN") ); - _mskname.ext( "msk" ); - - - _m = new TMaschera( _mskname ); - - // Definizione della toolbar - _m->outline( "TOOLBAR \"\" 0 20 0 2" ); - - _m->control( T_BOTTONE, 18, 802 ); - _m->begin(); - _m->prompt( -15, -1, "~Registra" ); - _m->message( "EXIT,20082" ); - _m->end(); - - _m->control( T_BOTTONE, 17, 802 ); - _m->begin(); - _m->prompt( -25, -1, "~Elimina" ); - _m->message( "EXIT,127" ); - _m->end(); - - _m->control( T_BOTTONE, 99, 802 ); - _m->begin(); - _m->prompt( -35, -1, "E~labora" ); - _m->message( "EXIT,345" ); - _m->end(); - - _m->control( T_BOTTONE, 24, 802 ); - _m->begin(); - _m->prompt( -45, -1 ); - _m->message( "EXIT,346" ); - _m->end(); - - _m->control( T_BOTTONE, 2, 802 ); - _m->begin(); - _m->prompt( -55, -1 ); - _m->message( "EXIT,27" ); - _m->end(); - - // End della toolbar - _m->end(); - - - // Header della prima pagina - - _m->outline( "PA \"Pagina \" 11 60 14" ); - - _m->control( T_CORNICE, DLG_NULL, 7806 ); - _m->begin( ); - _m->prompt( 1, 0, "" ); - _m->end( ); - - _m->control( T_STRINGA, F_CODNUM, 4 ); - _m->begin(); - _m->prompt( 2, 1, "Cod. num. " ); - _m->field( "CODNUM" ); - _m->flag( "GDUZ" ); - _m->message( "CO,2@" ); - _m->end(); - - _m->control( T_STRINGA, F_DESNUM, 50 ); - _m->begin(); - _m->prompt( 24, 1 ); - _m->flag( "GDU" ); - _m->message( "CO,3@" ); - _m->end(); - - _m->control( T_STRINGA, F_TIPODOC, 4 ); - _m->begin(); - _m->prompt( 2, 2, "Tipo doc. " ); - _m->flag( "GDU" ); - _m->message( "CO,4@" ); - _m->end(); - - _m->control( T_STRINGA, F_TIPOCF, 1 ); - _m->begin(); - _m->prompt( 2, 2, "Tipo CF " ); - _m->field( "TIPOCF" ); - _m->flag( "H" ); - _m->end(); - - _m->control( T_STRINGA, F_PROVV, 1 ); - _m->begin(); - _m->prompt( 2, 2, "

" ); - _m->field( "PROVV" ); - _m->flag( "H" ); - _m->end(); - - - _m->control( T_STRINGA, F_DESTIPODOC, 50 ); - _m->begin(); - _m->prompt( 24, 2 ); - _m->flag( "GDU" ); - _m->message( "CO,5@" ); - _m->end(); - - _m->control( T_NUMERO, F_NDOC, 6 ); - _m->begin(); - _m->prompt( 2, 3, "Doc.: nr. " ); - _m->field( "NDOC" ); - _m->message( "CO,6@" ); - _m->flag( "GDR" ); - _m->end(); - - _m->control( T_DATA, F_DATADOC ); - _m->begin(); - _m->prompt( 24, 3, "Data " ); - _m->field( "DATADOC" ); - _m->message( "CO,7@" ); - _m->flag( "A" ); - _m->end(); - - _m->control( T_NUMERO, F_STATO, 1 ); - _m->begin(); - _m->prompt( 50, 3, "Stato " ); - _m->field( "STATO" ); - _m->message( "CO,8@" ); - _m->flag( "D" ); - _m->end(); - - _m->control( T_STRINGA, F_ANNO, 4 ); - _m->begin(); - _m->prompt( 66, 3, "Es. " ); - _m->field( "ANNO" ); - _m->flag( "GD" ); - _m->message( "CO,9@" ); - _m->end(); - - _m->control( T_STRINGA, F_CODCF, 6 ); - _m->begin(); - if ( _pro->get( "TIPOCF", "MAIN" ) == "C" ) - { - _m->prompt( 2, 4, "Cliente " ); - _m->warning( "Cliente assente" ); - _m->help( "Codice del cliente del documento" ); - - } - else - { - _m->prompt( 2, 4, "Fornitore " ); - _m->warning( "Fornitore assente" ); - _m->help( "Codice del fornitore del documento" ); - } - _m->flag( "R" ); - _m->field( "CODCF" ); - _m->group( 1 ); - _m->use( LF_CLIFO, 1 ); - temp_s.format( "TIPOCF \"C\"~CODCF %d", F_CODCF); - _m->input( temp_s ); - _m->display( "\"Codice\" CODCF~\"Ragione Sociale@50\" RAGSOC~\"Partita IVA@12\" PAIV~\"Sospeso\" SOSPESO" ); - temp_s.format( "%d CODCF~%d RAGSOC", F_CODCF, F_RAGSOC ); - _m->output( temp_s ); - _m->check( S_OBBLIGATORIO ); - _m->outline( "ADD RU cg0 -1 C" ); - _m->message( "CO,10@" ); - _m->end(); - - _m->control( T_STRINGA, F_RAGSOC, 50 ); - _m->begin( ); - if ( _pro->get( "TIPOCF", "MAIN" ) == "C" ) - { - _m->warning( "Cliente assente" ); - _m->help( "Ragione sociale del cliente del documento" ); - - } - else - { - _m->warning( "Fornitore assente" ); - _m->help( "Ragione sociale del fornitore del documento" ); - } - _m->prompt( 24, 4, "" ); - _m->group( 1 ); - _m->use( LF_CLIFO, 2 ); - temp_s.format( "TIPOCF \"C\"~RAGSOC %d", F_RAGSOC ); - _m->input( temp_s ); - _m->display( "\"Ragione Sociale@50\" RAGSOC~\"Partita IVA@12\" PAIV~\"Codice\" CODCF" ); - temp_s.format( "%d CODCF~%d RAGSOC", F_CODCF, F_RAGSOC ); - _m->output( temp_s ); - _m->check( S_OBBLIGATORIO ); - _m->outline( "ADD RU cg0 -1 C" ); - _m->message( "CO,11@" ); - _m->end(); - _m->line( MASK_FIRST_LINE ); - - // Generazione - - // Scorro l'array dei campi, per vedere gli stati ed i gruppi - - TAssoc_array gruppi; - - int last = _campi.items( ); - for( i = 0; i < last; i ++ ) - { - TString nome = (( TField & )_campi[ i ]).nome( ); - int stato = stato_del_campo( nome ); - if( stato != S_NASCOSTO ) - { - const int addgruppo = (( TField & )_campi[ i ]).gruppo( ); - TString16 chiave; - chiave.format( "%5d", addgruppo ); - if ( !gruppi.is_key( chiave ) ) - gruppi.add( chiave, new TGruppo( addgruppo, _groupsini ) ); - } - (( TField & )_campi[ i ]).stato( stato ); - }; - // Si ordinano a mano nel .INI per velocizzare il processo di generazione - // campi.sort( sort_by_group ); - - // Generazione vera e propria - _m->_pageopen = TRUE; - last = _campi.items( ); - int curgruppo = 0; - for( i = 0; i < last; i ++ ) - { - if ( _m->_pageopen == FALSE) - { - intestazione_pagina( ); - _m->_pageopen = TRUE; - } - TField& campo = ( TField& ) _campi[ i ]; - if ( campo.gruppo( ) != curgruppo ) - { - TString16 chiave; - chiave.format( "%5d", campo.gruppo( ) ); - if ( gruppi.is_key( chiave ) ) - { - TGruppo& gruppo = ( TGruppo& ) gruppi[ chiave ]; - if ( _m->line( ) + gruppo.height( ) > MAX_LINES_PER_PAGE ) - { - _m->end( ); - intestazione_pagina( ); - _m->line( MASK_FIRST_LINE ); - } - else - { - TString16 vecchiachiave; - vecchiachiave.format( "%5d", curgruppo ); - if ( gruppi.is_key( vecchiachiave ) ) - { - _m->line( _m->line( ) + ( ( TGruppo& ) gruppi[ vecchiachiave ]).height( ) ); - } - } - } - curgruppo = campo.gruppo( ); - } - campo.configura( *_pro ); - campo.genera( *_m ); - } - if ( _m->_pageopen == TRUE ) _m->end( ); - intestazione_pagina( ); - - // Generazione del listbox per i tipi di riga da aggiungere nello sheet - _m->control ( T_LISTA, F_LBTIPORIGA, 30 ); - _m->begin( ); - _m->prompt( 2, 7, "Tipo riga da aggiungere " ); - _m->end( ); - - // Generazione dello sheet : vedi il profilo - TScanner sheet_in( "ve0300b.dat" ); - _m->_out << "SPREADSHEET " << F_SHEET << " 76 6 \n"; - _m->begin( ); - _m->prompt( 2, 8 ); - for( i = 0; i < _tab0300b.items( ); i ++ ) - genera_item_sheet( _tab0300b.row( i ) ); - _m->end(); - - _m->control( T_MEMO, F_MEMORIGA, 7604 ); - _m->begin( ); - _m->prompt( 2, 15, " " ); - _m->field( "34->DESCEST" ); - _m->end( ); - - - _m->end( ); - - // Generazione pagina dei piedi - TToken_string s(_pro->get( "PROGPIEDE", "MAIN" ) ); - if ( s.not_empty() ) - { - intestazione_pagina( ); - int cp = 1; - int piede = s.get_int();; - while ( piede != 0 ) - { - _m->control( T_NUMERO, BASE_PIEDE + cp, 1805 ); - _m->begin(); - TString header = _ditta.get( "PIEDE", "ve", piede ); - while( header.len() < 40 ) header << " "; - _m->prompt( 2, 7 + cp, header ); - _m->flag( "D" ); - _m->end(); - cp ++; - piede = s.get_int(); - } - _m->end(); - }; - _m->endmask( ); - - // Stategia al 30/06/95 - // Creo una maschera con tutte le colonne, poi, a RUNTIME, - // dal motore, nascondo e adatto le colonne. - - // Generazione maschera dello sheet - _m->_out << "PA \"Pagina 1\" 8 5 64 13\n"; - - id( 101 ); - for( i = 0; i < _tab0300b.items( ); i ++ ) - genera_campo_sheet( _tab0300b.row( i ) ); - _m->end( ); - _m->end( ); - _m->endmask( ); - delete _m; - delete _pro; -} - - -// Applicazione guscio - -class TGenMask_application : public TApplication -{ - -protected: - - virtual bool create( ); - virtual bool menu( MENU_TAG _m ); - -}; - - -bool TGenMask_application::menu(MENU_TAG _m) -{ - TMask_generator a( argv( 2 ) ); - return( TRUE ); -}; - -bool TGenMask_application::create( ) -{ - TApplication::create(); - menu( 0 ); - return FALSE; -}; - -int ve0300( int argc, char** argv ) -{ - - if ( argc < 3 ) - fatal_box( "Sintassi: VE0 -3 " ); - - TGenMask_application a; - a.run ( argc, argv, "Generazione in corso ..." ); - return 0; -} +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + + "Compilatore di profili" per la gestione vendite. + Considerando: + - Profilo documento + - Configurazione vendite per la ditta + - Condizioni atmosferiche + genera le maschere appropriate. + Accetta sulla riga di comando il nome del profilo documento per cui deve generare + la maschera. Il nome del file .MSK viene dedotto dal profilo documento stesso. + + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef __CHECKS_H +#include +#endif + +#ifndef __URLDEFID_H +#include +#endif + +#ifndef __FSTREAM_H +#include +#endif + +#ifndef __SCANNER_H +#include +#endif + +#ifndef __CONFIG_H +#include +#endif + +#ifndef __APPLICATION_H +#include +#endif + +#ifndef __UTILITY_H +#include +#endif + +#ifndef __PROGIND_H +#include +#endif + +#ifndef __TABUTIL_H +#include +#endif + +#ifndef __DEFMASK_H +#include +#endif + +#ifndef __RELATION_H +#include +#endif + +#ifndef __VEUML_H +#include "veuml.h" +#endif + +#ifndef __VEUML1_H +#include "veuml1.h" +#endif + +#ifndef __LFFILES_H +#include "lffiles.h" +#endif + +#ifndef __VEINI_H +#include "veini.h" +#endif + +#ifndef __VE0100_H +#include "ve0100.h" +#endif + + +// Significato delle colonne nella tabella _tab0300b +#define B_NOME 0 +#define B_MSKTYPE 1 +#define B_MSKSIZE 2 +#define B_DESCR 3 +#define B_WIDTH 4 + +// Significato dei campi nel profilo del documento +#define P_STATO 0 +#define P_PROMPT 1 +#define P_HELP 2 +#define P_WARNING 3 + + +// Numero massimo di linee per pagina +#define MAX_LINES_PER_PAGE 18 +#define MASK_FIRST_LINE 5 + +#define GROUPKEY(x) format( "%5d", x ) + +class TMaschera : public TObject +{ +private: + + // Linea corrente + int _curline; + + // Pagina corrente + int _curpage; + +public: + + void advance_line( ){ _curline ++; }; + + // Genera una serie di righe uguali per funzione ( DISPLAY, ecc. ) + void outline( const TString& s = "", const TString& prefix = "", const char sep = '~' ); + + // Crea un controllo del tipo specificato + void control( const int type, const int id = DLG_NULL, const int size = -1 ); + + // CHECKTYPE + void check( const int i ); + + // PAGE + void pagina( const int i, const TString& title = "Pagina " ){ _out << "PA \"" << title << " " << i << "\" 11 60 14\n"; }; + + // PROMPT + void prompt( const int x, const int y, const TString& s = "" ){ _out << "PR " << x << " " << y << " \"" << s << "\"\n"; }; + + // BEGIN + void begin( void ) { outline ( "BE" ); }; + + // END + void end( void ) { outline ( "EN" ); }; + + // ENDMASK + void endmask( void ) { outline ( "ENDMASK" ); }; + + // FLAG + void flag( const TString& s ) { _out << "FLAG \"" << s << "\"\n"; }; + + // HELP + void help( const TString& s ) { _out << "HE \"" << s << "\"\n"; }; + + // WARNING + void warning( const TString& s ) { _out << "WA \"" << s << "\"\n"; }; + + // GROUP + void group( const int g ) { _out << "GR " << g << "\n"; }; + + // FIELD + void field( const TString& s ) { outline( s, "FI "); }; + + // ITEM + void item( const TString& s ); + + // MESSAGE + void message( const TString& s ) { outline( s, "ME "); }; + + // USE + void use( const TString& s ){ outline( s, "US " ); }; + void use( const int file, const int key ){ _out << "US " << file << " KEY " << key << "\n"; }; + + // DISPLAY + void display( const TString& s ){ outline( s, "DI " ); }; + + // INPUT + void input( const TString& s ){ outline( s, "IN " ); }; + + // OUTPUT + void output( const TString& s ){ outline( s, "OU " ); }; + + // Funzioni per la lettura/scrittura di CURPAGE + int page( ) { return _curpage; }; + void page( const int i ){ _curpage = i; }; + + // Funzioni per la lettura/scrittura di CURLINE + int line( ) { return _curline; }; + void line( const int i ){ _curline = i; }; + + // Costruttore, vuole il nome del file .INI + TMaschera( const TFilename outfile ); + + // Vero se la pagina è aperta + bool _pageopen; + + // File .MSK di output + ofstream _out; + +}; + + + +class TMask_generator +{ + +private: + + // Identificatore corrente per lo sheet + int _curid; + + // vero se il gruppo è aperto + bool _groupopen; + + // nome del file di .INI di input + TFilename _proname; + + // File .INI di riferimento per i campi + TConfig _fieldsini; + + // File .INI di riferimento per i gruppi + TConfig _groupsini; + + // File .INI di input + TConfig* _pro; + + TConfig _ditta; + + // Tabelle per la generazione + + // Campi dei documenti + TString_array _fields; + + // Campi dello sheet + TString_array _tab0300b; + + TAssoc_array _gruppi; + + TMaschera *_m; + +protected: + + // Carica un file di tabella in un TString array + void carica_tabella( const TFilename& fn, TString_array& tabella ); + + // Scrive sul file di output una serie di righe uguali per funzione ( DISPLAY, ecc. ) + void outline( const TString& s = "", const TString& prefix = "", const char sep = '~' ); + + + // Crea un controllo del tipo specificato + void control( const int type, const int id = DLG_NULL, const int size = -1 ); + + // Ritorna vero se una componente della maschera è presente + int present( const int i, TToken_string line ){ const TString s = line.get( i ); return !(s.blank( )); }; + + // Carica dati dei campi + void carica_dati_campi( const TFilename& fn, TAssoc_array& a ); + + // Funzioni di accesso alle variabili private + // ------------------------------------------ + + // Funzioni per la lettura/scrittura di ID. Si incrementa da solo. + int id ( ) { return( _curid++ ); }; + void id( const int i ){ _curid = i; }; + + + // Funzioni di generazione ad alto livello + // --------------------------------------- + + // Genera un campo a partire da una linea del file VE0300A.DAT + void genera_campo( TToken_string _line ); + + // Genera un campo dello sheet a partire da una linea del file VE0300B.DAT + void genera_campo_sheet( TToken_string _line ); + + + // Genera la colonna dello sheet a partire da una linea del file VE0300B.DAT + void genera_item_sheet( TToken_string _line ); + +public: + + + TMaschera& maschera( ){ return *_m; } + + // Costruttore, vuole il nome del file .INI + TMask_generator( const TString& profilo ); + + // Attiva la generazione della maschera + void genera( const TString& ); + + // Genera l'intestazione di una pagina ( non la prima ) + void intestazione_pagina( ); + + TConfig& profilo( ){ return *_pro; } + TConfig& ditta( ){ return _ditta; } + TConfig& groupsini( ){ return _groupsini; } + TConfig& fieldsini( ){ return _fieldsini; } + + // Distruttore + virtual ~TMask_generator( ); + +}; + + +TMaschera::TMaschera( const TFilename outfile ) : _out( outfile ) +{ + _curline = 1; + _curpage = 1; + _pageopen = FALSE; + bool _groupopen = FALSE; +} + +void TMaschera::outline( const TString& s, const TString& prefix, const char sep ) +{ + if ( s.left( 1 ) == "@" ) + _out << "CO " << prefix << s.mid( 1 ) << "\n"; + else + { + TToken_string u( s, sep ); + for ( int i = 0; i < u.items( ); i ++ ) + _out << prefix << u.get( i ) << "\n"; + } +} + +void TMaschera::check( const int i ) +{ + switch( i ) + { + case S_OBBLIGATORIO: + outline ( "CH REQUIRED" ); + break; + default: + outline ( "CH NORMAL" ); + break; + } +} + +void TMaschera::control( const int type, const int id, const int size ) +{ + switch ( type ) + { + case T_DATA: + _out << "DA"; + break; + case T_STRINGA: + _out << "ST"; + break; + case T_CHECKBOX: + _out << "BO"; + break; + case T_NUMERO: + _out << "NU"; + break; + case T_LISTA: + _out << "LI"; + break; + case T_MEMO: + _out << "ME"; + break; + case T_CORNICE: + _out << "GR"; + break; + case T_BOTTONE: + _out << "BU"; + break; + } + _out << " " << id; + if ( size > 0 ) + { + if ( size > 100 ) + _out << " " << ( int )( size / 100 ) << " " << ( size % 100 ); + else + _out << " " << size; + } + _out << "\n"; +} + +void TMaschera::item( const TString& str ) +{ + int i, j; + TToken_string u( str, '@' ); + TToken_string s; + + for( i = 0; i < u.items( ); i ++ ) + { + _out << "IT \"" << s[ 0 ] << "\"\n"; + for( j = 1; j < s.items( ); j ++ ) + _out << "ME " << s[ j ] << "\n"; + } +} + +class TField; + +class TGruppo : public TObject +{ +protected: + + int _id; + int _height; + bool _present; + TArray _fields; + TMask_generator * _mg; + +public: + + TMaschera& maschera( ){ return generatore( ).maschera( ); } + TMask_generator& generatore( ){ CHECK( _mg, "Generatore nullo!" ); return *_mg; } + void generatore( TMask_generator& mg ){ _mg = &mg; } + void id( int id ){ _id = id; } + int id( ){ return _id; } + void height( int h ){ _height = h; } + int height( ){ return _height; } + void present( bool p ){ _present = p; } + bool present( ){ return _present; } + TArray& campi( ){ return _fields; } + + TGruppo ( int i ); + TGruppo ( int i, int height ); + void genera( ); + void add( TField * field ); + +}; + +class TField : public TObject +{ +protected: + + TString _nome; + // Gruppo di appartenenza + TGruppo *_grp; + + int _gruppo; + int _id; + int _type; + int _size; + int _stato; + int _x, _y; + TString _prompt, _flag, _help, _warning, _fieldname; + TToken_string _use, _input, _display, _output, _special, _items, _configs; + +public: + + TField( TString& campo, TConfig& pro ); + TField( ); + + void genera( ); + void configura( TConfig& pro ); + + void x( int x ){ _x = x; } + void y( int y ){ _y = y; } + void gruppo( int gruppo ){ _gruppo = gruppo; } + void grp( TGruppo& grp ){ _grp = &grp; } + void id( int id ){ _id = id; } + void type( int type ){ _type = type; } + void size( int size ){ _size = size; } + void stato( int stato ){ _stato = stato; } + int x( ){ return _x; } + int y( ){ return _y; } + int gruppo( ){ return _gruppo; } + TGruppo& grp( ) const { return *_grp; } + int id( ){ return _id; } + int type( ){ return _type; } + int size( ){ return _size; } + int stato( ){ return _stato; } + int stato_reale( ); + + + void nome( TString& nome ){ _nome = nome; } + void prompt( TString& prompt ){ _prompt = prompt; } + void flag( TString& flag ){ _flag = flag; } + void help( TString& help ){ _help = help; } + void warning( TString& warning ){ _warning = warning; } + void fieldname( TString& fieldname ){ _fieldname = fieldname; } + TString& nome( ){ return _nome; } + TString& prompt( ){ return _prompt; } + TString& flag( ){ return _flag; } + TString& help( ){ return _help; } + TString& warning( ){ return _warning; } + TString& fieldname( ){ return _fieldname; } + + void use( TToken_string& use ){ _use = use; } + void input( TToken_string& input ){ _input = input; } + void display( TToken_string& display ){ _display = display; } + void output( TToken_string& output ){ _output = output; } + void special( TToken_string& special ){ _special = special; } + void items( TToken_string& items ){ _items = items; } + void configs( TToken_string& configs ){ _configs = configs; } + TToken_string& use( ){ return _use; } + TToken_string& input( ){ return _input; } + TToken_string& display( ){ return _display; } + TToken_string& output( ){ return _output; } + TToken_string& special( ){ return _special; } + TToken_string& items( ){ return _items; } + TToken_string& configs( ){ return _configs; } + + TConfig& profilo( ) { return grp( ).generatore( ).profilo( ); } + TConfig& ditta( ) { return grp( ).generatore( ).ditta( ); } + TConfig& groupsini( ) { return grp( ).generatore( ).groupsini( ); } + TConfig& fieldsini( ) { return grp( ).generatore( ).fieldsini( ); } + +}; + +void TGruppo::add( TField * field ) +{ + _fields.add( field ); + field->grp( *this ); +} + +TGruppo::TGruppo( int i ) +{ + TConfig pro( "ve0300c.ini" ); + _id = i; + _height = pro.get_int( "HEIGHT", format( "%d", i ) ); +} + +TGruppo::TGruppo( int i, int height ) +{ + _id = i; + _height = height; +} + +static void genera_campo( const TObject& campo ) +{ + // Per evitare 3000 casts ... + TField& cmp = ( TField& )campo; + + cmp.configura( cmp.grp( ).generatore( ).profilo( ) ); + cmp.genera( ); +} + +static void verifica_campo( const TObject& campo ) +{ + // Per evitare 3000 casts ... + TField& cmp = ( TField& )campo; + + int stato = cmp.stato_reale( ); + cmp.stato( stato ); + if( cmp.stato( ) != S_NASCOSTO ) + cmp.grp( ).present( TRUE ); +} + +static void genera_gruppo( const TObject& gruppo ) +{ + // Per evitare 3000 casts ... + TGruppo& grp = ( TGruppo& )gruppo; + + grp.present( FALSE ); + grp.campi( ).for_each( verifica_campo ); + if( grp.present( ) ) + grp.genera( ); +} + +void TGruppo::genera( ) +{ + // Se il gruppo non sta sulla pagina ... + int oldlinea = maschera( ).line( ); + if ( oldlinea + _height > MAX_LINES_PER_PAGE ) + { + // Passa alla pagina successiva + maschera( ).end( ); + generatore( ).intestazione_pagina( ); + maschera( ).line( MASK_FIRST_LINE ); + oldlinea = MASK_FIRST_LINE; + } + _fields.for_each( genera_campo ); + maschera( ).line( oldlinea + _height ); +} + +TField::TField( TString& campo, TConfig& pro ) : _nome( campo ) +{ + _nome.trim( ); + _fieldname = pro.get( "FIELDNAME", campo ); + _x = _gruppo = pro.get_int( "X", campo ); + _y = _gruppo = pro.get_int( "Y", campo ); + _gruppo = pro.get_int( "GROUP", campo ); + CHECK( _gruppo != 0, "Gruppo uguale a 0" ); + _id = pro.get_int( "MSKID", campo ); + CHECK( _id != 0, "Campo con MSKID uguale a 0" ); + _type = pro.get_int( "TYPE", campo ); + _size = pro.get_int( "SIZE", campo ); + _prompt = pro.get( "PROMPT", campo ); + if( _prompt[ 0 ] == '\"' ) + { + _prompt.ltrim( 1 ); + _prompt.rtrim( 1 ); + }; + _flag = pro.get( "FLAG", campo ); + _help = pro.get( "FLAG", campo ); + _warning = pro.get( "FLAG", campo ); + _use = pro.get( "USE", campo ); + _use.separator( '~' ); + _input = pro.get( "INPUT", campo ); + _input.separator( '~' ); + _display = pro.get( "DISPLAY", campo ); + _display.separator( '~' ); + _output = pro.get( "OUTPUT", campo ); + _output.separator( '~' ); + _special = pro.get( "SPECIAL", campo ); + _special.separator( '~' ); + _configs = pro.get( "CONFIGS", campo ); + _configs.separator( '~' ); + _items = ""; + int last = pro.get_int( "NITEMS", campo ); + for( int i = 1; i <= last; i ++ ) + _items.add( pro.get( "ITEM", campo, i ) ); +}; + +TField::TField( ) +{ + _nome = ""; + _fieldname = ""; + _x = 0; + _y = 0; + _gruppo = 0; + _id = 0; + _type = 0; + _size = 0; + _prompt = ""; + _flag = ""; + _help = ""; + _warning = ""; + _use = ""; + _use.separator( '~' ); + _input = ""; + _input.separator( '~' ); + _display = ""; + _display.separator( '~' ); + _output = ""; + _output.separator( '~' ); + _special = ""; + _special.separator( '~' ); + _configs = ""; + _configs.separator( '~' ); + _items = ""; + _items.separator( '@' ); +} + +int TField::stato_reale( ) +{ + // Strategia al 28/08/95 + // Se il campo, nel file .INI di definizione dei campi, è legato a qualche voce in + // configurazione, legge il suo stato, altrimenti assume il massimo. + // Va poi a verificare nel .INI da compilare, e verifica li' la impostazione. + // Controlla poi la impostazione per il gruppo, come impostato nel file .INI + // e nella sezione CONFIGS nel .INI di definizione dei gruppi. + // Utilizza poi la minore delle due. + TToken_string config( fieldsini( ).get( "CONFIGS", _nome ) ); + TString reale; + int items = config.items( ); + int stato = S_OBBLIGATORIO; + for ( int i = 0; i < items; i += 3 ) + { TString chiave = config.get( i ); + TString valore = config.get( i + 1 ); + TString reale = ditta( ).get( chiave, "ve" ); + int pos = chiave.find( '[' ); + if ( pos >= 0 ) + { + TString index = chiave.sub( pos + 1, chiave.find( ']' ) ); + chiave = chiave.sub( 0, pos ); + reale = ditta( ).get( chiave, "ve", atoi( index ) ); + } + else + reale = ditta( ).get( chiave, "ve" ); + if ( reale == valore ) + stato = atoi( ( char * ) config.get( i + 2 ) ); + }; + TToken_string riga_profilo( grp( ).generatore( ).profilo( ).get( _nome, "PROFILO" ) ); + int stato_profilo = riga_profilo.get_int( P_STATO ); + stato = ( stato < stato_profilo )? stato : stato_profilo; + TString gruppo ( fieldsini( ).get( "GROUP", _nome ) ); + gruppo.trim( ); + config = ( groupsini( ).get( "CONFIGS", gruppo ) ); + items = config.items( ); + int stato_gruppo = S_OBBLIGATORIO; + for ( i = 0; i < items; i += 3 ) + { TString chiave = config.get( i ); + TString valore = config.get( i + 1 ); + reale = ditta( ).get( chiave, "ve" ); + if ( reale == valore ) + stato_gruppo = atoi( ( char * ) config.get( i + 2 ) ); + }; + stato = ( stato < stato_gruppo )? stato : stato_gruppo; + int stato_gruppo_profilo = grp( ).generatore( ).profilo( ).get_int( gruppo, "PROFILOGRUPPO" ); + stato = ( stato < stato_gruppo_profilo )? stato : stato_gruppo_profilo; + return stato; +} + +void TField::configura( TConfig& pro ) +{ + TToken_string riga_profilo( pro.get( _nome, "PROFILO" ) ); + TString newprompt( riga_profilo.get( P_PROMPT ) ) ; + TString newhelp( riga_profilo.get( P_HELP ) ) ; + TString newwarning( riga_profilo.get( P_WARNING ) ) ; + if ( ! newprompt.blank( ) ) + _prompt = newprompt; + if ( ! newhelp.blank( ) ) + _help = newhelp; + if ( ! newwarning.blank( ) ) + _warning = newwarning; +} + +void TField::genera( ) +{ + TMaschera& m = grp( ).maschera( ); + TString s; + + if ( _stato == S_NASCOSTO ) + return; + if ( _size != 0 ) + m.control( _type, _id, _size ); + else + m.control( _type, _id ); + m.begin( ); + switch( _stato ) + { + case S_DISABILITATO : + m.prompt( _x, _y + m.line( ), _prompt ); + s = "D"; + s << _flag; + m.flag( s ) ; + break; + case S_NORMALE : + case S_OBBLIGATORIO : + m.prompt( _x, _y + m.line( ), _prompt ); + m.flag( _flag ); + break; + } + m.check( _stato ); + if ( !_fieldname.blank( ) ) m.field( _fieldname ); + if ( !_items.blank( ) ) m.item( _items ); + if ( !_use.blank( ) ) m.use( _use ); + if ( !_input.blank( ) ) m.input( _input ); + if ( !_display.blank( ) ) m.display( _display ); + if ( !_output.blank( ) ) m.output( _output ); + if ( !_help.blank( ) ) m.help( _help ); + if ( !_warning.blank( ) ) m.warning( _warning ); + if ( !_special.blank( ) ) m.outline( _special ); + m.end( ); + if ( ( m.line( ) > MAX_LINES_PER_PAGE ) && ( m._pageopen == TRUE)) + { + m.end( ); + m._pageopen = FALSE; + m.line( MASK_FIRST_LINE ); + } +} + +// Definizione dei metodi di_generator +// ----------------------------------------- + +TMask_generator::TMask_generator( const TString& profilo ) : _fieldsini( "ve0300a.ini" ), _groupsini( "ve0300c.ini" ), _ditta( CONFIG_DITTA ) +{ + CHECK( fexist( "ve0300a.ini" ), "Il file ve0300a.ini non esiste!" ); + _fieldsini.list_paragraphs( _fields ); + CHECK( fexist( "ve0300b.dat" ), "Il file ve0300b.dat non esiste!" ); + carica_tabella( "ve0300b.dat", _tab0300b ); + carica_dati_campi( "ve0300a.ini", _gruppi ); + TString16 param( profilo ); + param.lower( ); + if( param == "-all" ) + { + TRelation rel("%TIP"); + TCursor t( &rel ); + long count = t.items( ); + TProgind bar( count, "Generazione delle maschere", FALSE, TRUE); + for( t = 0; t.pos( ) < count; ++t ) + { + genera( t.curr( ).get( "S4" ) ); + bar.addstatus(1); + } + } + else genera( profilo ); +} + +TMask_generator::~TMask_generator( ) +{ + +}; + +/* + + void TMask_generator::carica_ordine_gruppi( ) + { + int last, i; + last = _gruppi.items( ); + for( i = 1; i <= last; i ++ ) + { + TString16 chiavepro, chiavegruppi; + chiavepro.format( "%d", i ); + const int gruppo( _pro->get_int( chiavepro, "ORDINEGRUPPI" ) ); + chiavegruppo.format( "%5d", gruppo ); + ( ( TGruppo& )_gruppi[ chiavegruppo ] ).ordine( i ); + } + last = _pro->get( "NGRUPPI", "ORDINEGRUPPI" ); + for( i = 1; i <= last; i ++ ) + { + TString16 chiavepro, chiavegruppi; + chiavepro.format( "%d", i ); + const int gruppo( _pro->get_int( chiavepro, "ORDINEGRUPPI" ) ); + chiavegruppo.format( "%5d", gruppo ); + ( ( TGruppo& )_gruppi[ chiavegruppo ] ).ordine( i ); + } + } + */ + +void TMask_generator::carica_dati_campi( const TFilename& fn, TAssoc_array& a ) +{ + TScanner infile( fn ); + TString line; + TField *campo = NULL; + TGruppo *gruppo = NULL; + TString16 curgruppo( "" ); + + while ( infile.ok( ) ) + { + line = infile.line( ); + line.trim( ); + while ( ( line.empty( ) || line[ 0 ] == '#' || line.left( 2 ) == "//" ) && infile.ok( ) ) + { + line = infile.line( ); + line.trim( ); + } + if( infile.ok( ) ) + { + if ( line[ 0 ] == '[' ) // Carica un un campo + { + line.strip( "[]" ); + if ( campo ) + { + TString16 fieldkey = GROUPKEY( campo->gruppo( ) ); + if ( fieldkey != curgruppo ) + { + if ( gruppo ) + { + a.add( curgruppo, gruppo ); + } + TString16 taggruppo; + taggruppo.format( "%d", campo->gruppo( ) ); + int hgruppo = _groupsini.get_int( "HEIGHT", taggruppo ); + gruppo = new TGruppo( campo->gruppo( ), hgruppo ); + gruppo->generatore( *this ); + } + gruppo->add( campo ); + curgruppo = GROUPKEY( campo->gruppo( ) ); + } + campo = new TField( ); + campo->nome( line ); + } + else + { + int pos; + if( ( pos = line.find( '=' ) ) == 0 ) + yesnofatal_box( "Linea errata nel file.INI: %s", (const char *) line ); + else + { + TString key = line.sub( 0, pos ); + key.trim( ); + TString value = line.mid( pos + 1 ); + value.trim( ); + if( key == "X" ) + campo->x( atoi( value ) ); + else if( key == "Y" ) + campo->y( atoi( value ) ); + else if( key == "GROUP" ) + campo->gruppo( atoi( value ) ); + else if( key == "FIELDNAME" ) + campo->fieldname( value ); + else if( key == "MSKID" ) + campo->id( atoi( value ) ); + else if( key == "TYPE" ) + campo->type( atoi( value ) ); + else if( key == "SIZE" ) + campo->size( atoi( value ) ); + else if( key == "PROMPT" ) + { + if( value[ 0 ] == '"' ) + { + value.rtrim( 1 ); + value.ltrim( 1 ); + }; + campo->prompt( value ); + } + else if( key == "FLAG" ) + campo->flag( value ); + else if( key == "USE" ) + campo->use( (TToken_string & ) value ); + else if( key == "INPUT" ) + campo->input( (TToken_string & )value ); + else if( key == "DISPLAY" ) + campo->display( (TToken_string & )value ); + else if( key == "OUTPUT" ) + campo->output( (TToken_string & )value ); + else if( key == "WARNING" ) + campo->warning( value ); + else if( key == "HELP" ) + campo->help( value ); + else if( key == "SPECIAL" ) + campo->special( (TToken_string & )value ); + else if( key == "ITEMS" ) + campo->items( (TToken_string & )value ); + else if( key == "CONFIGS" ) + campo->configs( (TToken_string & )value ); + else yesnofatal_box( "Chiave non trovata(%s)", (const char *) key ); + } + } + } + } + if ( campo ) + { + if( format( "%5d", campo->gruppo( ) ) != curgruppo ) + { + if( gruppo ) + { + a.add( curgruppo, gruppo ); + } + TString16 taggruppo; + taggruppo.format( "%d", campo->gruppo( ) ); + int hgruppo = _groupsini.get_int( "HEIGHT", taggruppo ); + gruppo = new TGruppo( campo->gruppo( ), hgruppo ); + gruppo->generatore( *this ); + } + gruppo->add( campo ); + curgruppo = GROUPKEY( campo->gruppo( ) ); + a.add( curgruppo, gruppo ); + } +} + +void TMask_generator::carica_tabella( const TFilename& fn, TString_array& tabella ) +{ + TScanner in( fn ); + TToken_string line = in.line( ); + while( line.not_empty( ) ) + { // Attacca tutte le righe che finiscono con § + while ( line.right( 1 ) == "§" ) + { line.rtrim( 1 ); + line << in.line( ); + }; + tabella.add( line ); + line = in.line( ); + } +} + +void TMask_generator::genera_campo_sheet( TToken_string _line ) +{ + const int type( _line.get_int( B_MSKTYPE ) ); + _m->control( type, id( ), _line.get_int( B_MSKSIZE ) ); + _m->begin( ); + _m->prompt( 2, 2 ); + _m->field( _line.get( B_NOME ) ); + _m->end( ); +} + +void TMask_generator::genera_item_sheet( TToken_string _line ) +{ + _m->_out << "IT \"" << _line.get( B_DESCR ); + _m->_out << "@" << _line.get_int( B_WIDTH ) << "\"\n"; +} + +void TMask_generator::intestazione_pagina( ) +{ + _m->page( _m->page( ) + 1 ); + _m->pagina( _m->page( ), _pro->get( "TYPE", "MAIN" ) ); + + _m->control( T_CORNICE, DLG_NULL, 7805 ); + _m->begin( ); + _m->prompt( 1, 0, "" ); + _m->end( ); + + _m->control( T_STRINGA, DLG_NULL, 50 ); + _m->begin( ); + _m->prompt( 2, 1, "Tipo doc. " ); + _m->flag( "DU" ); + _m->group( 5 ); + _m->end( ); + + _m->control( T_NUMERO, DLG_NULL, 6 ); + _m->begin( ); + _m->prompt( 2, 2, "Doc.: nr. " ); + _m->group( 6 ); + _m->flag( "D" ); + _m->end( ); + + _m->control( T_DATA ); + _m->begin( ); + _m->prompt( 24, 2 ); + _m->group( 7 ); + _m->flag( "D" ); + _m->end( ); + + _m->control( T_STRINGA, DLG_NULL, 50 ); + _m->begin( ); + if ( _pro->get( "TIPOCF", "MAIN" ) == "C" ) + _m->prompt( 2, 3, "Cliente " ); + else + _m->prompt( 2, 3, "Fornitore " ); + _m->flag( "D" ); + _m->group( 11 ); + _m->end( ); + +} + +void TMask_generator::genera( const TString& profilo ) +{ + int i, last; + TString temp_s; + TFilename proname( profilo ), + // All'inizio il gruppo è 'chiuso' + _groupopen = FALSE; + + // Forza l'estensione al profilo + proname.ext( "ini" ); + + // Se il file di profilo non esiste, esci con un errore fatale + if ( !fexist( proname ) ) + fatal_box( "Il file %s non esiste!", ( const char * )proname ); + + _pro = new TConfig( proname ); + + TFilename _mskname( _pro->get( "MSKFILE", "MAIN") ); + _mskname.ext( "msk" ); + + // Mi serve per ordinare i gruppi a seconda del documento + TAssoc_array grouporder; + + _m = new TMaschera( _mskname ); + + // Definizione della toolbar + _m->outline( "TOOLBAR \"\" 0 20 0 2" ); + + _m->control( T_BOTTONE, 18, 802 ); + _m->begin( ); + _m->prompt( -15, -1, "~Registra" ); + _m->message( "EXIT,20082" ); + _m->end( ); + + _m->control( T_BOTTONE, 17, 802 ); + _m->begin( ); + _m->prompt( -25, -1, "~Elimina" ); + _m->message( "EXIT,127" ); + _m->end( ); + + _m->control( T_BOTTONE, 99, 802 ); + _m->begin( ); + _m->prompt( -35, -1, "E~labora" ); + _m->message( "EXIT,345" ); + _m->end( ); + + _m->control( T_BOTTONE, 24, 802 ); + _m->begin( ); + _m->prompt( -45, -1 ); + _m->message( "EXIT,346" ); + _m->end( ); + + _m->control( T_BOTTONE, 2, 802 ); + _m->begin( ); + _m->prompt( -55, -1 ); + _m->message( "EXIT,27" ); + _m->end( ); + + // End della toolbar + _m->end( ); + + + // Header della prima pagina + + _m->pagina( _m->page( ), _pro->get( "TYPE", "MAIN" ) ); + + _m->control( T_CORNICE, DLG_NULL, 7806 ); + _m->begin( ); + _m->prompt( 1, 0, "" ); + _m->end( ); + + _m->control( T_STRINGA, F_CODNUM, 4 ); + _m->begin( ); + _m->prompt( 2, 1, "Cod. num. " ); + _m->field( "CODNUM" ); + _m->flag( "GDUZ" ); + _m->message( "CO,2@" ); + _m->end( ); + + _m->control( T_STRINGA, F_DESNUM, 50 ); + _m->begin( ); + _m->prompt( 24, 1 ); + _m->flag( "GDU" ); + _m->message( "CO,3@" ); + _m->end( ); + + _m->control( T_STRINGA, F_TIPODOC, 4 ); + _m->begin( ); + _m->field( "TIPODOC" ); + _m->prompt( 2, 2, "Tipo doc. " ); + _m->flag( "GDU" ); + _m->message( "CO,4@" ); + _m->end( ); + + _m->control( T_STRINGA, F_TIPOCF, 1 ); + _m->begin( ); + _m->prompt( 2, 2, "Tipo CF " ); + _m->field( "TIPOCF" ); + _m->flag( "H" ); + _m->end( ); + + _m->control( T_STRINGA, F_PROVV, 1 ); + _m->begin( ); + _m->prompt( 2, 2, "

" ); + _m->field( "PROVV" ); + _m->flag( "H" ); + _m->end( ); + + _m->control( T_STRINGA, F_DESTIPODOC, 50 ); + _m->begin( ); + _m->prompt( 24, 2 ); + _m->flag( "GDU" ); + _m->message( "CO,5@" ); + _m->end( ); + + _m->control( T_NUMERO, F_NDOC, 6 ); + _m->begin( ); + _m->prompt( 2, 3, "Doc.: nr. " ); + _m->field( "NDOC" ); + _m->message( "CO,6@" ); + _m->flag( "GDR" ); + _m->end( ); + + _m->control( T_DATA, F_DATADOC ); + _m->begin( ); + _m->prompt( 24, 3, "Data " ); + _m->field( "DATADOC" ); + _m->message( "CO,7@" ); + _m->flag( "A" ); + _m->end( ); + + _m->control( T_NUMERO, F_STATO, 1 ); + _m->begin( ); + _m->prompt( 50, 3, "Stato " ); + _m->field( "STATO" ); + _m->message( "CO,8@" ); + _m->flag( "D" ); + _m->end( ); + + _m->control( T_STRINGA, F_ANNO, 4 ); + _m->begin( ); + _m->prompt( 66, 3, "Es. " ); + _m->field( "ANNO" ); + _m->flag( "GD" ); + _m->message( "CO,9@" ); + _m->end( ); + + _m->control( T_STRINGA, F_CODCF, 6 ); + _m->begin( ); + if ( _pro->get( "TIPOCF", "MAIN" ) == "C" ) + { + _m->prompt( 2, 4, "Cliente " ); + _m->warning( "Cliente assente" ); + _m->help( "Codice del cliente del documento" ); + } + else + { + _m->prompt( 2, 4, "Fornitore " ); + _m->warning( "Fornitore assente" ); + _m->help( "Codice del fornitore del documento" ); + } + _m->flag( "R" ); + _m->field( "CODCF" ); + _m->group( 1 ); + _m->use( LF_CLIFO, 1 ); + temp_s.format( "TIPOCF \"C\"~CODCF %d", F_CODCF); + _m->input( temp_s ); + _m->display( "\"Codice\" CODCF~\"Ragione Sociale@50\" RAGSOC~\"Partita IVA@12\" PAIV~\"Sospeso\" SOSPESO" ); + temp_s.format( "%d CODCF~%d RAGSOC", F_CODCF, F_RAGSOC ); + _m->output( temp_s ); + _m->check( S_OBBLIGATORIO ); + _m->outline( "ADD RU cg0 -1 C" ); + _m->message( "CO,10@" ); + _m->end( ); + + _m->control( T_STRINGA, F_RAGSOC, 50 ); + _m->begin( ); + if ( _pro->get( "TIPOCF", "MAIN" ) == "C" ) + { + _m->warning( "Cliente assente" ); + _m->help( "Ragione sociale del cliente del documento" ); + } + else + { + _m->warning( "Fornitore assente" ); + _m->help( "Ragione sociale del fornitore del documento" ); + } + _m->prompt( 24, 4, "" ); + _m->group( 1 ); + _m->use( LF_CLIFO, 2 ); + temp_s.format( "TIPOCF \"C\"~RAGSOC %d", F_RAGSOC ); + _m->input( temp_s ); + _m->display( "\"Ragione Sociale@50\" RAGSOC~\"Partita IVA@12\" PAIV~\"Codice\" CODCF" ); + temp_s.format( "%d CODCF~%d RAGSOC", F_CODCF, F_RAGSOC ); + _m->output( temp_s ); + _m->check( S_OBBLIGATORIO ); + _m->outline( "ADD RU cg0 -1 C" ); + _m->message( "CO,11@" ); + _m->end( ); + _m->line( MASK_FIRST_LINE + 1 ); + + _m->_pageopen = TRUE; + + // Generazione + + // carica_ordine_gruppi( ); + // Scorro l'array dei gruppi, e ne creo una copia ordinata + // con solo i gruppi visibili + + TArray sortedgroups; + TString16 chiave, chiavegruppo; + last = _pro->get_int( "NGROUPS", "ORDINEGRUPPI" ); + for( i = 1; i <= last; i ++ ) + { + chiave.format( "%d", i ); + chiavegruppo.GROUPKEY( _pro->get_int( chiave, "ORDINEGRUPPI" ) ); + if( _gruppi.is_key( chiavegruppo ) ) + sortedgroups.add( &_gruppi[ (chiavegruppo) ] ); + } + sortedgroups.for_each( genera_gruppo ); + if ( _m->_pageopen == TRUE ) + { + _m->end( ); + intestazione_pagina( ); + } + + /* + + last = _campi.items( ); + for( i = 0; i < last; i ++ ) + { + TString nome = (( TField & )_campi[ i ]).nome( ); + int stato = stato_del_campo( nome ); + if( stato != S_NASCOSTO ) + { + const int addgruppo = (( TField & )_campi[ i ]).gruppo( ); + const int ordine = 0; //ordine_del_gruppo( addgruppo ); + if( ordine ) + { + TString16 chiave; + chiave.format( "%5d", addgruppo ); + if ( !gruppi.is_key( chiave ) ) + gruppi.add( chiave, new TGruppo( addgruppo, _groupsini ) ); + } + else + { + // Se il gruppo non compare nell'elenco dei gruppi, + stato = S_NASCOSTO; + } + } + (( TField & )_campi[ i ]).stato( stato ); + // (( TField & )_campi[ i ]).ordine( ordine ); + }; + + _campi.sort( ); + // Generazione vera e propria + _m->_pageopen = TRUE; + last = _campi.items( ); + int curgruppo = 0; + for( i = 0; i < last; i ++ ) + { + if ( _m->_pageopen == FALSE) + { + intestazione_pagina( ); + _m->_pageopen = TRUE; + } + TField& campo = ( TField& ) _campi[ i ]; + if ( campo.gruppo( ) != curgruppo ) + { + TString16 chiave; + chiave.format( "%5d", campo.gruppo( ) ); + if ( gruppi.is_key( chiave ) ) + { + TGruppo& gruppo = ( TGruppo& ) gruppi[ chiave ]; + if ( _m->line( ) + gruppo.height( ) > MAX_LINES_PER_PAGE ) + { + _m->end( ); + intestazione_pagina( ); + _m->line( MASK_FIRST_LINE ); + } + else + { + TString16 vecchiachiave; + vecchiachiave.format( "%5d", curgruppo ); + if ( gruppi.is_key( vecchiachiave ) ) + { + _m->line( _m->line( ) + ( ( TGruppo& ) gruppi[ vecchiachiave ]).height( ) ); + } + } + } + curgruppo = campo.gruppo( ); + } + campo.configura( *_pro ); + campo.genera( *_m ); + } + if ( _m->_pageopen == TRUE ) _m->end( ); + intestazione_pagina( ); + + */ + + // Generazione del listbox per i tipi di riga da aggiungere nello sheet + _m->control ( T_LISTA, F_LBTIPORIGA, 30 ); + _m->begin( ); + _m->prompt( 2, 6, "Tipo riga da aggiungere " ); + _m->end( ); + + // Generazione dello sheet : vedi il profilo + TScanner sheet_in( "ve0300b.dat" ); + _m->_out << "SPREADSHEET " << F_SHEET << " 76 6 \n"; + // _m->_out << "SPREADSHEET " << F_SHEET << " 76 10 \n"; + _m->begin( ); + _m->prompt( 2, 7 ); + for( i = 0; i < _tab0300b.items( ); i ++ ) + genera_item_sheet( _tab0300b.row( i ) ); + _m->end( ); + + // Campo memo per mostrare le righe + _m->control( T_MEMO, F_MEMORIGA, 7604 ); + _m->begin( ); + _m->prompt( 2, 14, " " ); + _m->field( "34->DESCEST" ); + _m->flag( "D" ); + _m->end( ); + + _m->end( ); + + // Generazione pagina dei piedi + TToken_string s(_pro->get( "PROGPIEDE", "MAIN" ) ); + TTable tab( "PPD" ); + if ( s.not_empty( ) ) + { + intestazione_pagina( ); + TString16 codpiede( s.get( ) ); + int cp = 1; + while ( !codpiede.empty( ) ) + { + tab.zero( ); + tab.put( "CODTAB", codpiede ); + if ( tab.read( ) == NOERR ) + { + TString picture( tab.get( "S3" ) ); + _m->control( T_NUMERO, BASE_PIEDE + tab.get_int( "I0" ), 1805 ); + _m->begin( ); + TString header = tab.get( "S1" ); + header.trim( ); + while( header.len( ) < 40 - picture.len( ) ) + header << " "; + _m->prompt( 2, 7 + cp, header ); + _m->flag( "D" ); + _m->end( ); + cp ++; + if( cp + MASK_FIRST_LINE > MAX_LINES_PER_PAGE ) + { + _m->end( ); + intestazione_pagina( ); + _m->line( MASK_FIRST_LINE ); + cp = 1; + } + } + codpiede = s.get( ); + } + _m->end( ); + }; + _m->endmask( ); + + // Stategia al 30/06/95 + // Creo una maschera con tutte le colonne, poi, a RUNTIME, + // dal motore, nascondo e adatto le colonne. + + // Generazione maschera dello sheet + _m->_out << "PA \"Pagina 1\" 8 5 64 13\n"; + + id( 101 ); + for( i = 0; i < _tab0300b.items( ); i ++ ) + genera_campo_sheet( _tab0300b.row( i ) ); + _m->end( ); + _m->end( ); + _m->endmask( ); + delete _m; + delete _pro; +} + + +// Applicazione guscio + +class TGenMask_application : public TApplication +{ + +protected: + + virtual bool create ( ); + virtual bool destroy( ); + // virtual bool menu( MENU_TAG ); // Controlla il menu + +}; + + +bool TGenMask_application::create( ) + +{ + TApplication::create( ); + TMask_generator a( argv( 2 ) ); + return FALSE; +} + +bool TGenMask_application::destroy( ) +{ + return TApplication::destroy() ; +} + +int ve0300( int argc, char** argv ) +{ + + if ( argc < 3 ) + fatal_box( "Sintassi: VE0 -3 " ); + + TGenMask_application a; + a.run ( argc, argv, "Generazione in corso ..." ); + return 0; +} diff --git a/ve/ve2100d.h b/ve/ve2100d.h index 6a5125fb2..cab4a7785 100755 --- a/ve/ve2100d.h +++ b/ve/ve2100d.h @@ -1,5 +1,4 @@ -#define F_D_TIPO 111 -#define F_D_CODCAT 112 -#define F_D_SCONTO 113 -#define F_D_DESCR 114 - \ No newline at end of file +#define F_D_TIPO 111 +#define F_D_CODCAT 112 +#define F_D_SCONTO 113 +#define F_D_DESCR 114 diff --git a/ve/ve2100r.h b/ve/ve2100r.h index e60c8fb56..1cf593f12 100755 --- a/ve/ve2100r.h +++ b/ve/ve2100r.h @@ -1,9 +1,8 @@ -#define F_R_RICERCA 121 -#define F_R_TIPO 122 -#define F_R_CODCAT 123 -#define F_R_CODART 124 -#define F_R_UM 125 -#define F_R_DESART 126 -#define F_R_SCONTO 127 -#define F_R_DESCAT 128 - \ No newline at end of file +#define F_R_RICERCA 121 +#define F_R_TIPO 122 +#define F_R_CODCAT 123 +#define F_R_CODART 124 +#define F_R_UM 125 +#define F_R_DESART 126 +#define F_R_SCONTO 127 +#define F_R_DESCAT 128 diff --git a/ve/ve2200.cpp b/ve/ve2200.cpp index 877f33847..b420fbf73 100755 --- a/ve/ve2200.cpp +++ b/ve/ve2200.cpp @@ -100,8 +100,8 @@ bool TCondizioni_vendita::user_create() { DESTROY(F_L_DESSUCC); _codcon_codcf= prassid.get_bool("GESCONCC"); // setta il booleano di abilitazione di TIPOCF e CODCF if (!_codcon_codcf) { // disabilita i campi di gestione clienti/fornitori in base al flag. di config. - KILL(F_R_C_TIPOCF); - KILL(F_R_C_CODCF); + KILL(F_C_TIPOCF); + KILL(F_C_CODCF); } set_search_field(F_C_COD); // impostazione del campo di ricerca _gest_um= prassid.get_bool("GESUM", NULL, A_CONTRATTI); // setta il booleano di abilitazione delle unità di misura diff --git a/ve/vefields.wri b/ve/vefields.wri index 08102a0b3..f381443c7 100755 Binary files a/ve/vefields.wri and b/ve/vefields.wri differ diff --git a/ve/veuml1.h b/ve/veuml1.h index 9a51c5858..ce904b04e 100755 --- a/ve/veuml1.h +++ b/ve/veuml1.h @@ -1,65 +1,64 @@ -#ifndef __VEUML1_H -#define __VEUML1_H - -#ifndef __VEUML_H -#include "VEUML.H" -#endif - -// gruppo dei vettori - -#define GR_VETTORI 15 - -// campi della maschera totale - -#define F_RAGSOC 301 -#define F_INDCF 302 -#define F_CIVCF 303 -#define F_NOME_VAL 304 -#define F_DESCODPAG 305 -// I prossimi 5 campi devono essere consecutivi come numerazione -// perchè faccio un ciclo per settarli -#define F_DATASCAD1 306 -#define F_DATASCAD2 307 -#define F_DATASCAD3 308 -#define F_DATASCAD4 309 -#define F_DATASCAD5 310 -#define F_BANCA_APP 311 -#define F_BANCA_PRE 312 -#define F_INDSP 313 -#define F_CIVSP 314 -#define F_CAPSP 315 -#define F_LOCALITASP 316 -#define F_PORTO 317 -#define F_DENCAUSTRASP 318 -#define F_NOMEVETT1 319 -#define F_NOMEVETT2 320 -#define F_NOMEVETT3 321 -#define F_DESCRBENI1 322 -#define F_DESCRBENI2 323 -#define F_DESUMTARA 324 -#define F_DESUMPNETTO 325 -#define F_DESCRMAG1 326 -#define F_DESCRMAG2 327 -#define F_COFI 328 -#define F_STATOPAIVA 329 -#define F_LOCALITACF 330 -#define F_CAPCF 331 -#define F_COMCF 332 -#define F_PROVCOM 333 -#define F_STATOCF 334 -#define F_DATACAMBIO 335 -#define F_DESBANAPP 336 -#define F_DESLIN 337 -#define F_DESBANPRE 338 -#define F_NOMEVAL 339 -#define F_PAIVA 340 -#define F_DENCOM 341 -#define F_DESSTATOCF 342 -#define F_COMSP 343 -#define F_DENCOMSP 344 -#define F_PROVCOMSP 345 -#define F_STATOSP 346 -#define F_DESSTATOSP 347 -#define F_DESLIST 348 -#define F_RAGSOCSP 349 -#endif // __VEUML1_H +#ifndef __VEUML1_H +#define __VEUML1_H + +#ifndef __VEUML_H +#include "VEUML.H" +#endif + +// gruppo dei vettori + +#define GR_VETTORI 15 + +// campi della maschera totale + +#define F_RAGSOC 301 +#define F_INDCF 302 +#define F_CIVCF 303 +#define F_RAGSOCSP 304 +#define F_DESCODPAG 305 +// I prossimi 5 campi devono essere consecutivi come numerazione +// perchè faccio un ciclo per settarli +#define F_DATASCAD1 306 +#define F_DATASCAD2 307 +#define F_DATASCAD3 308 +#define F_DATASCAD4 309 +#define F_DATASCAD5 310 +#define F_BANCA_APP 311 +#define F_BANCA_PRE 312 +#define F_INDSP 313 +#define F_CIVSP 314 +#define F_CAPSP 315 +#define F_LOCALITASP 316 +#define F_PORTO 317 +#define F_DENCAUSTRASP 318 +#define F_NOMEVETT1 319 +#define F_NOMEVETT2 320 +#define F_NOMEVETT3 321 +#define F_DESCRBENI1 322 +#define F_DESCRBENI2 323 +#define F_DESUMTARA 324 +#define F_DESUMPNETTO 325 +#define F_DESCRMAG1 326 +#define F_DESCRMAG2 327 +#define F_COFI 328 +#define F_STATOPAIVA 329 +#define F_LOCALITACF 330 +#define F_CAPCF 331 +#define F_COMCF 332 +#define F_PROVCOM 333 +#define F_STATOCF 334 +#define F_DATACAMBIO 335 +#define F_DESBANAPP 336 +#define F_DESLIN 337 +#define F_DESBANPRE 338 +#define F_NOMEVAL 339 +#define F_PAIVA 340 +#define F_DENCOM 341 +#define F_DESSTATOCF 342 +#define F_COMSP 343 +#define F_DENCOMSP 344 +#define F_PROVCOMSP 345 +#define F_STATOSP 346 +#define F_DESSTATOSP 347 +#define F_DESLIST 348 +#endif // __VEUML1_H diff --git a/ve/veuml2.h b/ve/veuml2.h index 727a1fa79..e3f625919 100755 --- a/ve/veuml2.h +++ b/ve/veuml2.h @@ -1,28 +1,34 @@ #ifndef __SHEET_FIELDS #define __SHEET_FIELDS -#define FS_STATORIGA 101 -#define FS_TIPORIGA 102 -#define FS_PROFRIGA 103 -#define FS_CODMAG 104 -#define FS_CODART 105 -#define FS_DESCR 106 -#define FS_DESCLUNGA 107 -#define FS_PREZZO 108 -#define FS_UMQTA 109 -#define FS_QTA 110 -#define FS_QTAEVASA 111 -#define FS_RIGAEVASA 112 -#define FS_TARA 113 -#define FS_PNETTO 114 -#define FS_NCOLLI 115 -#define FS_DAEVADERE 116 -#define FS_SCONTO 117 -#define FS_PERCPROV 118 -#define FS_IMPFISSO 119 -#define FS_IMPFISUN 120 -#define FS_CODIVA 121 -#define FS_ADDIVA 122 -#define FS_ASPBENI 123 - +#define FS_CODNUM 101 +#define FS_ANNO 102 +#define FS_PROVV 103 +#define FS_NDOC 104 +#define FS_STATORIGA 105 +#define FS_TIPORIGA 106 +#define FS_PROFRIGA 107 +#define FS_CODMAG 108 +#define FS_CODDEP 109 +#define FS_CODART 110 +#define FS_DESCR 111 +#define FS_DESCLUNGA 112 +#define FS_PREZZO 113 +#define FS_UMQTA 114 +#define FS_QTA 115 +#define FS_QTAEVASA 116 +#define FS_RIGAEVASA 117 +#define FS_TARA 118 +#define FS_PNETTO 119 +#define FS_NCOLLI 120 +#define FS_DAEVADERE 121 +#define FS_SCONTO 122 +#define FS_PERCPROV 123 +#define FS_IMPFISSO 124 +#define FS_IMPFISUN 125 +#define FS_CODIVA 126 +#define FS_ADDIVA 127 +#define FS_ASPBENI 128 +#define FS_G1 129 + #endif // __SHEET_FIELDS