campo-sirio/ve/ve0100.cpp
alex e4920136e8 Errore di abilitazione sconto
Errore nel cambio ditta


git-svn-id: svn://10.65.10.50/trunk@3711 c028cbd2-c16b-5b4b-a496-9718f37d4682
1996-10-04 16:45:43 +00:00

810 lines
22 KiB
C++
Executable File

#ifndef __VE0100_H
#include "ve0100.h"
#endif
#ifndef __VE0100O_H
#include "ve0100o.h"
#endif
#ifndef __VEINI_H
#include "veini.h"
#endif
#ifndef __UTILITY_H
#include "utility.h"
#endif
void TMotore_application::init_query_mode( TMask& m )
{
_msk->set( F_CODNUM, _doc->numerazione());
_msk->field(F_CODNUM).set_focusdirty(TRUE);
_msk->field(F_CODNUM).on_key(K_TAB);
_msk->field(F_CODNUM).set_dirty(FALSE);
_msk->set( F_TIPODOC, _doc->get("TIPODOC"), TRUE);
}
void TMotore_application::init_insert_mode( TMask& m )
{
TString tipocf( "A" );
tipocf[ 0 ] = app().tipocf();
const TString16 codnum(m.get(F_CODNUM));
const int anno = m.get_int(F_ANNO);
const char provv = m.get(F_PROVV)[0];
const long numdoc = m.get_long(F_NDOC);
_doc->read(provv, anno, codnum, numdoc);
_doc->set_tipo(m.get(F_TIPODOC));
m.field(F_CODNUM).set_focusdirty(TRUE);
m.field(F_CODNUM).on_key(K_TAB);
m.field(F_TIPODOC).set_focusdirty(TRUE);
m.field(F_TIPODOC).on_key(K_TAB);
m.set(F_STATO, _doc->head().get("STATO"));
const TString16 data_doc(m.get( F_DATADOC));
m.set(F_DATAINSC,data_doc);
m.set( F_DATACAMBIO, data_doc);
clifo( ).occas_mask( ).reset( );
const int ndefaults = pro( ).get_int( "NDEFAULTS", "DEFAULT" ); // prof
TMask & emask = edit_mask();
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 ) );
emask.set( campo, default_val, TRUE );
}
}
void TMotore_application::update_profile()
{
TFilename fn(_doc->tipo().profile_name());
fn.ext("ini");
if (_pro && _pro->name() != fn)
{
delete _pro;
_pro = NULL;
}
if (_pro == NULL)
_pro = new TConfig( fn );
}
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)
{
TRiga_documento & riga = (*(app()._doc))[numriga + 1];
return ((TTipo_riga_documento &)riga.tipo()).mask();
}
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 )
{
if ( key == K_ENTER ) // Cancellazione
{
TRiga_documento & riga = (*(app()._doc))[r + 1];
riga.autosave(ss);
}
else
if ( key == K_DEL ) // Cancellazione
app()._doc->destroy_row(r + 1, TRUE);
else
if ( key == K_INS ) // Inserimento
{
TMask & emask = app().edit_mask();
TRiga_documento & riga = app()._doc->insert_row(r + 1, emask.get( F_LBTIPORIGA ));
riga.autoload(ss);
}
else
if (key == K_CTRL + K_INS)
ss.select(r);
return TRUE;
}
bool TMotore_application::num_handler( TMask_field& f, KEY key )
{
// Ottengo la maschera
TMask& m = f.mask( );
if (key == K_TAB && f.focusdirty())
{
TTable & tabnum = ((TTable &) ((TEdit_field &)f).browse()->cursor()->file());
if ( tabnum.good())
{
// 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 ) );
// Propone il primo tipo di documento come default
m.set( F_TIPODOC, tipidocs.left( 4 ) );
m.send_key( K_TAB, F_TIPODOC );
// Se per questa numerazione h 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 );
}
}
else
{
m.set( F_DESNUM, "" );
m.set( F_TIPIDOCS, "" );
m.set( F_TIPODOC, "" );
}
}
return TRUE;
}
bool TMotore_application::elabora_handler( TMask_field& f, KEY key )
{
// Ottengo la maschera
// TMask& m = f.mask( );
// Registra il record corrente
// m.send_key( K_INS, 99 );
// TString commandline("ve4 ");
// commandline << m.get( F_CODNUM );
// commandline << " ";
// commandline << m.get( F_ANNO );
// commandline << " ";
// commandline << m.get( F_PROVV );
// commandline << " ";
// commandline << m.get( F_NDOC );
// TExternal_app interattivo( commandline );
// interattivo.run( );
// ricarica il documento dopo che l'interattivo lo ha modificato
// app( ).read( m );
return TRUE;
}
bool TMotore_application::occas_handler( TMask_field& f, KEY key )
{
TMask & m = f.mask();
if ( key == K_SPACE && m.is_running( ) )
{
TMask& om = app( ).clifo( ). occas_mask( );
if (om.run( ) != K_ESC)
app().clifo().update_mask(m);
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( ) && m.get(F_TIPODOC).not_empty())
{
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;
}
}
if ( key == K_ENTER && m.is_running( ) )
{ TString tipo( f.get( ) );
if ( tipo.blank( ) )
{
message_box( "Occorre un tipo documento per inserire un documento!" );
m.first_focus( F_TIPODOC );
return FALSE;
}
}
return TRUE;
}
bool TMotore_application::clifo_handler( TMask_field& f, KEY key )
{
if (key == K_ENTER)
return TRUE;
if (f.to_check(key, TRUE))
{
const char cf = app().tipocf();
TMask& m = f.mask();
TLocalisamfile& clifo = ((TEdit_field&)f).browse()->cursor()->file();
const long codcf = atol(f.get());
if ( clifo.get_bool("SOSPESO") )
return f.error_box( "Il codice '%ld' e' sospeso e non puo' essere utilizzato", codcf );
if (app().clifo().load( cf, codcf, ""))
{
app().clifo().update_mask(m, !m.is_running());
if( f.mask().id2pos(F_OCCASEDIT) > 0 && f.to_check(key))
{
if ( app().clifo().occasionale() && app().clifo().occas_mask().get(O_CODICE).empty() )
m.send_key( K_SPACE, F_OCCASEDIT ); // Lancia maschera occasionali
}
}
else
return FALSE;
}
return TRUE;
}
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 )
{
TBit_array to_delete(MAX_COLUMNS);
to_delete.set();
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 int field_id = sheet_col.get_int(0);
const int coltomove = sheet.cid2index(field_id);
to_delete.reset(coltomove);
const TString descr(sheet_col.get( 1 ));
if (descr.not_empty() )
sheet.set_column_header( field_id, descr);
const int size( sheet_col.get_int(2));
if (size != 0)
sheet.set_column_width( field_id, size);
}
to_delete.reset(0);
to_delete.reset(1);
const int sconto_col = sheet.cid2index(FR_SCONTO);
if (to_delete[sconto_col] == FALSE)
{
const bool del = (_config_ditta->get("GESSCORIGA") == "N");
to_delete.set(sconto_col, del);
}
for ( i = MAX_COLUMNS - 1; i >= 0; i-- )
if( to_delete[i] )
{
sheet.enable_column( i + FIRST_FIELD, FALSE);
sheet.delete_column( i + FIRST_FIELD);
}
}
TMask* TMotore_application::get_mask( int mode )
{
switch ( mode )
{
case MODE_INS:
case MODE_MOD:
{
const TString16 tipodoc(_msk->get(F_TIPODOC));
TDocumento_mask * msk1 = (TDocumento_mask *) _doc_masks.objptr(tipodoc);
_doc->set_tipo(tipodoc);
update_profile();
TString tipocf( app( ).pro( ).get( "TIPOCF", "MAIN" ) ); //prof
app( ).tipocf( tipocf[ 0 ] );
if (msk1 == NULL)
{
msk1 = new TDocumento_mask(_doc->tipo().mask_name(), _doc); // prof
_doc_masks.add(tipodoc, msk1);
_sheet = &( TSheet_field& )msk1->field( F_SHEET );
sheet( ).set_notify( ss_handler );
sheet().set_append(FALSE);
TList_field& listbox = ( TList_field& ) msk1->field( F_LBTIPORIGA );
const int numtr = app( ).pro( ).get_int( "NTIPIRIGA", "RIGHE" ); //prof
TToken_string keys, descrs;
TRiga_documento r(_doc);
for ( int i = 1; i <= numtr; i ++ )
{
TString16 var;
var.format("%d", i);
TString tiporiga(app().pro().get(var, "RIGHE")); // pro
r.set_tipo(tiporiga);
keys.add(r.tipo().codice());
descrs.add(r.tipo().descrizione());
}
listbox.replace_items( keys, descrs );
configura_sheet( *_sheet, *_pro );
((TVariable_sheet_field&)sheet()).set_getmask( ss_getmask );
if (msk1->id2pos( F_OCCASEDIT ) > 0 )
msk1->set_handler( F_OCCASEDIT, occas_handler );
msk1->set_handler( F_CODCF, clifo_handler );
msk1->set_handler( F_CODPAG, condpag_hndl );
msk1->set_handler( F_DATAINSC, condpag_hndl );
// _msk1->set_handler( 99, elabora_handler );
int numhandler = pro( ).get_int( "NHANDLER", "HANDLERS" ); // prof
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 ) );
}
// configurazione campi
const bool gesval = _config_ditta->get_bool("GESVAL");
const bool gescambi = _config_ditta->get_bool("GESVALAC");
if (gesval)
{
msk1->show(F_CODVAL, !gescambi);
msk1->show(F_DATACAMBIO, !gescambi);
msk1->show(F_NOMEVAL, !gescambi);
msk1->show(F_CODVAL1, gescambi);
msk1->show(F_DATACAMBIO1, gescambi);
msk1->show(F_NOMEVAL1, gescambi);
msk1->show(F_CAMBIO);
}
else
{
msk1->disable(F_CODVAL);
msk1->disable(F_DATACAMBIO);
msk1->disable(F_NOMEVAL);
msk1->hide(F_CODVAL1);
msk1->hide(F_DATACAMBIO1);
msk1->hide(F_NOMEVAL1);
msk1->disable(F_CAMBIO);
}
const bool geslin = _config_ditta->get_bool("GESLIN");
msk1->enable(F_CODLIN, geslin);
msk1->enable(F_DESLIN, geslin);
const bool geslis = _config_ditta->get_bool("GES", "ve", 1);
const bool gesliscatven = _config_ditta->get_bool("GESLISCV");
if (geslis)
{
msk1->show(F_CODLIST, !gesliscatven);
msk1->show(F_CODLIST1, gesliscatven);
}
else
{
msk1->disable(F_CODLIST);
msk1->hide(F_CODLIST1);
}
const bool gescontr = _config_ditta->get_bool("GES", "ve", 2);
const bool gescontrcli = _config_ditta->get_bool("GESCONCC");
if (gescontr)
{
msk1->show(F_CODCONT, !gescontrcli);
msk1->show(F_CODCONT1, gescontrcli);
}
else
{
msk1->disable(F_CODCONT);
msk1->hide(F_CODCONT1);
}
const bool gesoff = _config_ditta->get_bool("GES", "ve", 3);
msk1->enable(F_CODCAMP, gesoff);
const bool gessco = _config_ditta->get_char("GESSCO") != 'N';
msk1->enable(F_SCONTOPERC, gessco);
const bool gesage = _config_ditta->get_bool("GESAGE");
msk1->enable(F_CODAG, gesage);
msk1->enable(F_DESAG, gesage);
msk1->enable(F_CODAGVIS, gesage);
msk1->enable(F_DESAGVIS, gesage);
}
else
_sheet = &( TSheet_field& )edit_mask( ).field( F_SHEET );
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( );
const TString value = m.get( F_CODNUM );
if (value.not_empty())
{
TTable tabnum( "%NUM" );
tabnum.zero( );
tabnum.put( "CODTAB", value );
if ( tabnum.read( ) == NOERR && tabnum.get_bool ( "B1" ))
// Se per questa numerazione h abilitata le numerazione automatica
{
TLocalisamfile doc(LF_DOC);
doc.zero();
doc.put("CODNUM", value);
doc.put("ANNO", m.get(F_ANNO));
doc.put("PROVV", m.get(F_PROVV));
TRectype cmp_rec(doc.curr()); // record campione
doc.put( "NDOC", 9999999L );
if (doc.read(_isgreat) == NOERR)
doc.prev();
const long num = ((doc.curr() == cmp_rec) ? doc.get_long( "NDOC" ) : 0) + 1;
key.format( "%d|%d", F_NDOC, num);
}
}
return key;
}
int TMotore_application::read( TMask& m )
{
const int err = _doc->read(_doc->head());
if ( err == NOERR )
{
m.autoload(*_rel);
const char tipocf = _doc->head().get("TIPOCF")[0];
const long codcf = _doc->head().get_long("CODCF");
const TString occas_cod(_doc->head().get("OCFPI"));
clifo().load( tipocf, codcf, occas_cod);
clifo().update_mask( ( TVariable_mask& ) m, TRUE );
TSheet_field& f = ( TSheet_field& ) m.field( F_SHEET );
f.destroy( );
const int rows = _doc->rows();
for (int i = 1; i <= rows; i++)
{
TToken_string & r = f.row(i -1);
TRiga_documento & rec = (*_doc)[i];
rec.autoload(f);
f.post_insert(i - 1);
}
}
return err;
}
int TMotore_application::write( const TMask& m ) // C 90
{
int err = esegui_procedura(OP_NUOVO);
if (err == NOERR)
{
m.field(F_STATO).set( _pro->get( "STATOFINALE", "INSERIMENTO" ) );
if ( m.id2pos( F_OCCASEDIT) > 0 )
err = app().clifo().write_occas();
if ( err == NOERR )
{
m.autosave(*_rel);
err = _doc->write( );
}
if (err == NOERR)
_rel->read(); // per posizionare correttamente la relazione
}
return err;
}
int TMotore_application::rewrite( const TMask& m ) // C 90
{
if (!valida_operazione(OP_MODIFICA))
return NOERR; // Errore gia' segnalato
int err = esegui_procedura(OP_MODIFICA);
if (err == NOERR)
{
if ( m.id2pos( F_OCCASEDIT) > 0 )
err = app( ).clifo( ).write_occas( );
if ( err == NOERR )
{
m.autosave(*_rel);
err = _doc->rewrite( );
}
}
return err;
}
bool TMotore_application::remove( void ) // C 80
{
if ( ! valida_operazione( OP_CANCELLA ) )
return FALSE;
int err = esegui_procedura(OP_CANCELLA);
return _doc->remove() == NOERR;
}
void TMotore_application::open_files(int logicnum, ...)
{
va_list marker;
va_start(marker, logicnum);
while (logicnum > 0)
{
CHECKD(_file.objptr(logicnum) == NULL, "File gia' aperto: ", logicnum);
_file.add(new TLocalisamfile(logicnum), logicnum);
logicnum = va_arg(marker, int);
}
}
void TMotore_application::on_firm_change()
{
if (_config_ditta != NULL)
delete _config_ditta;
_config_ditta = new TConfig(CONFIG_DITTA);
condv().set_config(_config_ditta);
_doc_masks.destroy();
TApplication::on_firm_change();
}
bool TMotore_application::user_create( )
{
_config_ditta = new TConfig(CONFIG_DITTA);
// Controllo se sono cambiate le impostazioni delle vendite.
if (_config_ditta->get_bool( "CHANGED", "ve" ))
{ // Se sono cambiate, rigenero tutte le maschere
if (yesno_box( CHANGE_MESSAGE ) )
{
TExternal_app generazione( "ve0 -3 -all" );
generazione.run();
}
else
message_box("Attenzione i profili dei documenti potrebbero\n non essere aggiornati");
}
// Metto in relazione testata e righe
_rel = new TRelation( LF_DOC );
open_files(LF_RIGHEDOC, LF_CONDV, LF_RCONDV, LF_ANAMAG, LF_SCONTI, LF_UMART, LF_TAB, LF_TABCOM, 0);
_doc = new TDocumento;
_rel->lfile().set_curr(_doc);
_doc->set_relation(_rel);
_clifor = new TCliForVendite( );
_condv = new TCond_vendita(_clifor, _config_ditta);
_doc->set_condv(_condv);
_msk = new TMask( "ve0100a" );
query_mask( ).set_handler( F_CODNUM, num_handler );
query_mask( ).set_handler( F_TIPODOC, tip_handler );
TConfig utente( CONFIG_USER );
_msk->set(F_CODNUM, utente.get("CODNUM"));
_msk->set(F_TIPODOC, utente.get("TIPODOC"));
// La maschera di inserimento/modifica per ora non la so!
// Viene letta dal profilo non appena trovato il record
return TRUE;
}
bool TMotore_application::user_destroy( )
{
// Registro l'ultimo tipo documento e l'ultima numerazione
TConfig utente( CONFIG_USER );
utente.set( "CODNUM", _doc->numerazione(), "ve" );
utente.set( "TIPODOC", _doc->get("TIPODOC"), "ve" );
if (_config_ditta != NULL)
delete _config_ditta;
// Distruggo la maschera di modifica
if ( _msk != NULL )
delete _msk;
// Distruggo la relazione
delete _rel;
delete _condv;
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 ) // C 90
{
if (operazione != OP_NUOVO && !stato_valido( stato_corrente( ), operazione))
{
segnala_stato_non_valido( operazione );
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 );
}
int TMotore_application::stato_corrente( )
{
return _doc->head().get_int("STATO");
}
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;
}