diff --git a/ve/righedoc.cpp b/ve/righedoc.cpp index 8b1508a90..8c1c7206a 100755 --- a/ve/righedoc.cpp +++ b/ve/righedoc.cpp @@ -18,437 +18,76 @@ #include "sconti.h" #endif -static void row_set_handler( TMask& m, const int field, const int index ) + +void TRiga_documento_motore::load(TSheet_field & f, TToken_string& row) { - switch ( index ) - { - case 1: - m.set_handler( field, dummy_hndl ); - break; - default: - yesnofatal_box( FALSE, "Funzione di handler sulla riga non definita( %d ).", index ); - } -} - -HIDDEN TString16 curr_um; -HIDDEN real curr_fc(1.0); - -HIDDEN bool codart_handler( TMask_field& f, KEY key ) -{ - // Se qualcuno cerca di modificare la maschera - if ( key == K_TAB && f.focusdirty()) - { - TMask& row_mask = f.mask(); - TMask & mask = app().edit_mask(); - TCond_vendita & condv = app().condv(); - - condv.set_testa(&mask); - condv.set_riga(&row_mask); - - TLocalisamfile & anamag = ((TEdit_field &) f).browse()->cursor()->file(); - TLocalisamfile & umart = ((TEdit_field &) row_mask.field(FR_UMQTA)).browse()->cursor()->file(); - - condv.set_anamag(anamag); - condv.set_umart(umart); - TString80 codart(f.get()); - anamag.setkey(1); - anamag.put("CODART", codart); - if (anamag.read() != NOERR) - { - TLocalisamfile codalt(LF_CODCORR); - - codalt.setkey(2); - codalt.put("CODARTALT", codart); - if (codalt.read() == NOERR) - { - codart = codalt.get("CODART"); - anamag.zero(); - anamag.put("CODART", codart); - if (anamag.read() == NOERR) - f.set(codart); - } - } - - if (anamag.good()) - { - const TString16 lingua = mask.get(F_CODLIN); - const TString codart(row_mask.get(FR_CODART)); - TString desc(anamag.get("DESCR")); - - if (lingua.not_empty()) - { - TLocalisamfile deslin(LF_DESLIN); - - deslin.setkey(2); - deslin.put("CODART", codart); - deslin.put("CODLIN", lingua); - if (deslin.read() == NOERR) - desc = deslin.get("DESCR"); - } - row_mask.set(FR_DESCR, desc); - - umart.setkey(1); - umart.zero(); - umart.put("CODART", codart); - if (umart.read(_isgteq) == NOERR && codart == umart.get("CODART")) - { - curr_um = umart.get("UM"); - curr_fc = umart.get_real("FC"); - } - else - { - curr_um.cut(0); - curr_fc = 1.0; - } - row_mask.set(FR_UMQTA, curr_um); - } - - condv.ricerca(); - } - return TRUE; -} - - -HIDDEN bool umart_handler( TMask_field& f, KEY key ) -{ - // Se qualcuno cerca di modificare la maschera - if ( key == K_TAB && f.focusdirty()) - { - TMask& row_mask = f.mask( ); - TMask & mask = app().edit_mask(); - TLocalisamfile & anamag = ((TEdit_field &) row_mask.field(FR_CODART)).browse()->cursor()->file(); - TLocalisamfile & umart = ((TEdit_field &) f).browse()->cursor()->file(); - TCond_vendita & condv = app().condv(); - - condv.set_testa(&mask); - condv.set_riga(&row_mask); - condv.set_anamag(anamag); - condv.set_umart(umart); - condv.ricerca(FALSE); - - const TString16 um(f.get()); - real fc(1.0); - - if (um.not_empty() && curr_um.not_empty() && um != curr_um) - { - umart.setkey(2); - umart.put("CODART", row_mask.get(FR_CODART)); - umart.put("UM", um); - if (umart.read() == NOERR) - { - real qta(row_mask.get_real(FR_QTA)); - qta *= curr_fc; - fc = umart.get_real("FC"); - qta /= fc; - row_mask.set(FR_QTA, qta); - } - - } - curr_um = um; - curr_fc = fc; - } - return TRUE; -} - -HIDDEN bool descr_handler( TMask_field& f, KEY key ) -{ - if (key == K_TAB && f.focusdirty()) - { - const TString s(f.get()); - if (s.find('\n') < 0) - { - TLocalisamfile & anamag = ((TEdit_field &) f).browse()->cursor()->file(); - - anamag.zero(); - anamag.setkey(2); - anamag.put("DESCR", ((TZoom_field &) f).get_first_line()); - if (anamag.read() == NOERR) - { - f.mask().set(FR_CODART, anamag.get("CODART")); - f.mask().field(FR_CODART).set_dirty(); - f.mask().check_field(FR_CODART); - } - } - } - return TRUE; -} - -HIDDEN bool qta_handler( TMask_field& f, KEY key ) -{ - // Se qualcuno cerca di modificare la maschera - if ( key == K_TAB && f.focusdirty()) - { - TMask& row_mask = f.mask( ); - TMask & mask = app().edit_mask(); - TLocalisamfile & anamag = ((TEdit_field &) row_mask.field(FR_CODART)).browse()->cursor()->file(); - TLocalisamfile & umart = ((TEdit_field &) row_mask.field(FR_UMQTA)).browse()->cursor()->file(); - TCond_vendita & condv = app().condv(); - - condv.set_testa(&mask); - condv.set_riga(&row_mask); - condv.set_anamag(anamag); - condv.set_umart(umart); - condv.ricerca(FALSE); - } - return TRUE; -} - - -void TRiga::load(TSheet_field & f, TToken_string& row, TRectype * r) -{ - if (r) - _data = *r; - _data.put( "STATORIGA", row.get( f.cid2index(FR_STATORIGA) ) ); - _data.put( "TIPORIGA", row.get( f.cid2index(FR_TIPORIGA )) ); + put( "STATORIGA", row.get( f.cid2index(FR_STATORIGA) ) ); + put( "TIPORIGA", row.get( f.cid2index(FR_TIPORIGA )) ); TString16 codmag(row.get(f.cid2index(FR_CODMAG))); codmag.left_just(3); codmag << row.get( f.cid2index(FR_CODDEP )); - _data.put( "CODMAG", codmag); - _data.put( "CODART", row.get( f.cid2index(FR_CODART )) ); + put( "CODMAG", codmag); + put( "CODART", row.get( f.cid2index(FR_CODART )) ); TString s(row.get(f.cid2index(FR_DESCR))); int split_pos = s.find('\n'); if (split_pos > 0) { - _data.put( "DESCR", s.left(split_pos)); - _data.put("DESCLUNGA", "X"); + put( "DESCR", s.left(split_pos)); + put("DESCLUNGA", "X"); s.ltrim(split_pos); - _data.put("DESCEST", s); + put("DESCEST", s); } else { - _data.put("DESCR", s); - _data.put("DESCLUNGA", ""); - _data.zero("DESCEST"); + put("DESCR", s); + put("DESCLUNGA", ""); + zero("DESCEST"); } - _data.put( "PREZZO", row.get( f.cid2index(FR_PREZZO )) ); - _data.put( "UMQTA", row.get( f.cid2index(FR_UMQTA )) ); - _data.put( "QTA", row.get( f.cid2index(FR_QTA )) ); - _data.put( "QTAEVASA", row.get( f.cid2index(FR_QTAEVASA )) ); - _data.put( "RIGAEVASA", row.get( f.cid2index(FR_RIGAEVASA )) ); - _data.put( "TARA", row.get( f.cid2index(FR_TARA )) ); - _data.put( "PNETTO", row.get( f.cid2index(FR_PNETTO )) ); - _data.put( "NCOLLI", row.get( f.cid2index(FR_NCOLLI )) ); - _data.put( "DAEVADERE", row.get( f.cid2index(FR_DAEVADERE )) ); - _data.put( "SCONTO", row.get( f.cid2index(FR_SCONTO )) ); - _data.put( "PERCPROV", row.get( f.cid2index(FR_PERCPROV )) ); - _data.put( "IMPFISSO", row.get( f.cid2index(FR_IMPFISSO )) ); - _data.put( "CODIVA", row.get( f.cid2index(FR_CODIVA )) ); - _data.put( "ADDIVA", row.get( f.cid2index(FR_ADDIVA )) ); - _data.put( "ASPBENI", row.get( f.cid2index(FR_ASPBENI )) ); - carica_profilo( ); - _piede.destroy( ); -// somma( _piede ); - _data.put( "G1", _piede.string( ) ); - if (r) - *r = _data; - + put( "PREZZO", row.get( f.cid2index(FR_PREZZO )) ); + put( "UMQTA", row.get( f.cid2index(FR_UMQTA )) ); + put( "QTA", row.get( f.cid2index(FR_QTA )) ); + put( "QTAEVASA", row.get( f.cid2index(FR_QTAEVASA )) ); + put( "RIGAEVASA", row.get( f.cid2index(FR_RIGAEVASA )) ); + put( "TARA", row.get( f.cid2index(FR_TARA )) ); + put( "PNETTO", row.get( f.cid2index(FR_PNETTO )) ); + put( "NCOLLI", row.get( f.cid2index(FR_NCOLLI )) ); + put( "DAEVADERE", row.get( f.cid2index(FR_DAEVADERE )) ); + put( "SCONTO", row.get( f.cid2index(FR_SCONTO )) ); + put( "PERCPROV", row.get( f.cid2index(FR_PERCPROV )) ); + put( "IMPFISSO", row.get( f.cid2index(FR_IMPFISSO )) ); + put( "CODIVA", row.get( f.cid2index(FR_CODIVA )) ); + put( "ADDIVA", row.get( f.cid2index(FR_ADDIVA )) ); + put( "ASPBENI", row.get( f.cid2index(FR_ASPBENI )) ); } -void TRiga::save(TSheet_field & f, TToken_string& row ) +void TRiga_documento_motore::save(TSheet_field & f, TToken_string& row ) { - row.add( _data.get( "STATORIGA" ), f.cid2index(FR_STATORIGA )); - row.add( _data.get( "TIPORIGA" ), f.cid2index(FR_TIPORIGA )); - const TString codmag(_data.get("CODMAG")); + row.add( get( "STATORIGA" ), f.cid2index(FR_STATORIGA )); + row.add( get( "TIPORIGA" ), f.cid2index(FR_TIPORIGA )); + const TString codmag(get("CODMAG")); row.add( codmag.left(3), f.cid2index(FR_CODMAG )); row.add( codmag.mid(3), f.cid2index(FR_CODDEP )); - row.add( _data.get( "CODART" ), f.cid2index(FR_CODART )); - TString s(_data.get("DESCR")); - if (_data.get_bool("DESCLUNGA")) - s << _data.get("DESCEST"); + row.add( get( "CODART" ), f.cid2index(FR_CODART )); + TString s(get("DESCR")); + if (get_bool("DESCLUNGA")) + s << get("DESCEST"); row.add(s, f.cid2index(FR_DESCR )); - row.add( _data.get( "UMQTA" ), f.cid2index(FR_UMQTA )); - row.add( _data.get( "PREZZO" ), f.cid2index(FR_PREZZO )); - row.add( _data.get( "QTA" ), f.cid2index(FR_QTA )); - row.add( _data.get( "QTAEVASA" ), f.cid2index(FR_QTAEVASA )); - row.add( _data.get( "RIGAEVASA" ), f.cid2index(FR_RIGAEVASA )); - row.add( _data.get( "TARA" ), f.cid2index(FR_TARA )); - row.add( _data.get( "PNETTO" ), f.cid2index(FR_PNETTO )); - row.add( _data.get( "NCOLLI" ), f.cid2index(FR_NCOLLI )); - row.add( _data.get( "DAEVADERE" ), f.cid2index(FR_DAEVADERE )); - row.add( _data.get( "SCONTO" ), f.cid2index(FR_SCONTO )); - row.add( _data.get( "PERCPROV" ), f.cid2index(FR_PERCPROV )); - row.add( _data.get( "IMPFISSO" ), f.cid2index(FR_IMPFISSO )); - row.add( _data.get( "CODIVA" ), f.cid2index(FR_CODIVA )); - row.add( _data.get( "ADDIVA" ), f.cid2index(FR_ADDIVA )); - row.add( _data.get( "ASPBENI" ), f.cid2index(FR_ASPBENI )); - // row.add( _piede.string( ), f.cid2index(FR_G1 )); + row.add( get( "UMQTA" ), f.cid2index(FR_UMQTA )); + row.add( get( "PREZZO" ), f.cid2index(FR_PREZZO )); + row.add( get( "QTA" ), f.cid2index(FR_QTA )); + row.add( get( "QTAEVASA" ), f.cid2index(FR_QTAEVASA )); + row.add( get( "RIGAEVASA" ), f.cid2index(FR_RIGAEVASA )); + row.add( get( "TARA" ), f.cid2index(FR_TARA )); + row.add( get( "PNETTO" ), f.cid2index(FR_PNETTO )); + row.add( get( "NCOLLI" ), f.cid2index(FR_NCOLLI )); + row.add( get( "DAEVADERE" ), f.cid2index(FR_DAEVADERE )); + row.add( get( "SCONTO" ), f.cid2index(FR_SCONTO )); + row.add( get( "PERCPROV" ), f.cid2index(FR_PERCPROV )); + row.add( get( "IMPFISSO" ), f.cid2index(FR_IMPFISSO )); + row.add( get( "CODIVA" ), f.cid2index(FR_CODIVA )); + row.add( get( "ADDIVA" ), f.cid2index(FR_ADDIVA )); + row.add( get( "ASPBENI" ), f.cid2index(FR_ASPBENI )); } -void TRiga::load( const TRectype& rec ) -{ - _data = rec; - carica_profilo( ); -} - -void TRiga::save( TRectype& rec ) -{ - rec = _data; -} - -void TRiga::carica_profilo( ) -{ - if( _pro ) - delete _pro; - TFilename proname("verig"); - proname << _data.get("TIPORIGA"); - proname.ext( "ini" ); - _pro = new TConfig( proname ); -} - -void TRiga::configura_sheet( TSheet_field& f, int numriga ) -{ - int ncols = _pro->get_int( "NCOLS", "COLUMNS" ); - // Disabilita tutte le colonne - f.disable_cell ( numriga, -1 ); - // Abilita le colonne indicate nel profilo della riga - for( int i = 1; i <= ncols; i ++ ) - { - TString16 chiave; - chiave.format( "%d", i ); - int coltoenable = _pro->get_int( chiave, "COLUMNS" ); - f.enable_cell ( numriga, coltoenable); - } -} - -TVariable_mask * TRiga::getmask( ) -{ - - TString16 msk("verig"); - msk << _data.get("TIPORIGA"); - TVariable_mask * mask = new TVariable_mask( msk ); - int numhandler = _pro->get_int( "NHANDLER", "HANDLERS" ); - for( int i = 1; i <= numhandler; i ++ ) - { - TString chiave; - chiave.format( "%d", i ); - TToken_string riga = _pro->get( chiave, "HANDLERS" ); - row_set_handler( *mask, riga.get_int( 0 ), riga.get_int( 1 ) ); - } - const TMask_field & f = mask->field(FR_CODART); - if (f.is_edit()) - { - TBrowse * browse = ((TEdit_field &) f).browse(); - - if (browse ) - { - TCursor * cur = browse->cursor(); - CHECK(cur, "Null cursor in CODART check"); - if (cur) - { - const int num = cur->file().num(); - if (num == LF_ANAMAG) - { - mask->set_handler( FR_CODART, codart_handler ); - mask->set_handler( FR_UMQTA, umart_handler ); - mask->set_handler( FR_DESCR, descr_handler ); - mask->set_handler( FR_QTA, qta_handler ); - } - } - } - } - return mask; -} - - -void TRiga::edit_keys( const KEY key, TPiede_documento& nuovo ) -{ - static TPiede_documento vecchio; - - switch( key ) - { - // Inizio modifica - case K_SPACE: - vecchio.destroy( ); -// somma( vecchio ); - break; - - // Cancellazione - case K_DEL: - // Toglie i vecchi valori - nuovo.sottrai( vecchio ); - break; - - // Modifica - case K_ENTER: - // Toglie i vecchi valori - nuovo.sottrai( vecchio ); - // Aggiunge i nuovi all -// somma( nuovo ); - break; - } -} - -TRiga::~TRiga( ) -{ - if( _pro ) - delete _pro; -} - - -void TPiede_documento::somma( TPiede_documento& tosum, bool add ) -{ - tosum.restart( ); - THash_object* curr = tosum.get_hashobj( ); - while( curr ) - { - TString16 key( curr->key( ) ); - if( add ) - somma( key, ( real& )curr->obj( ) ); - else - sottrai( key, ( real& )curr->obj( ) ); - curr = tosum.get_hashobj( ); - } -} - -void TPiede_documento::somma( TString16& piede, const real& importo ) -{ - if( is_key( piede ) ) - { - real& attuale = ( real& ) operator []( piede ); - attuale += importo; - } - else - add( piede, importo ); -} - -TToken_string& TPiede_documento::string( ) -{ - TToken_string ret; - - ret.separator( '~' ); - restart( ); - THash_object* curr = get_hashobj( ); - while( curr ) - { - ret.add( curr->key( ) ); - ret.add( (( real& ) curr->obj( )).string( ) ); - curr = get_hashobj( ); - } - return ret; -} - -void TPiede_documento::load( TToken_string& s ) -{ - s.separator( '~' ); - for( int i = 0; i < s.items( ); i+=2 ) - { - TString16 piede = s.get( i ); - TString num = s.get( i + 1 ); - real valore( num ); - add( piede, valore ); - } -} - -real& TPiede_documento::get( TString16& piede ) -{ - static real zero( "0.0" ); - - if( is_key( piede ) ) - { - return ( real& ) find( piede ); - } - else - return zero; -} \ No newline at end of file diff --git a/ve/righedoc.h b/ve/righedoc.h index 32d77b223..9afc5ddc3 100755 --- a/ve/righedoc.h +++ b/ve/righedoc.h @@ -25,72 +25,26 @@ #include "config.h" #endif -#ifndef __MSKSHEET_H -#include "msksheet.h" -#endif - #ifndef __VARMASK_H #include "varmask.h" #endif -class TPiede_documento : public TAssoc_array -{ - public: - - TToken_string& string( ); - void load( TToken_string& s ); - void somma( TPiede_documento& tosum, bool add = TRUE ); - void sottrai( TPiede_documento& tosum ){ somma( tosum, FALSE ); }; - void somma( TString16& piede, const real& importo ); - void sottrai( TString16& piede, const real& importo ){ somma( piede, -importo ); }; - real& get( TString16& piede ); -}; +#ifndef __VELIB01_H +#include "velib01.h" +#endif -class TRiga : public TObject +class TRiga_documento_motore : public TRiga_documento { - private: - - // Record che contiene i dati sulla riga - TRectype _data; - - // Profilo di riga - TConfig* _pro; - - // Maschera per la riga - - TPiede_documento _piede; - - protected: - - // Carca il profilo di riga: da migliorare mettendo una cache o precaricando - // tutti i profili per un documento - void carica_profilo( ); - public: - - // Setta il numero della riga - void set_numero( int r ) { _data.put( "NRIGA", r ); } - int numero( ) { return _data.get_int( "NRIGA" ); } - const TString & tipo( ) const { return _data.get( "TIPORIGA" ); } // Carica la riga dalla riga dello sheet - void load( TSheet_field& f, TToken_string& row , TRectype * r = NULL); + void load( TSheet_field& f, TToken_string& row); // Registra la riga sullo sheet void save( TSheet_field& f, TToken_string& row); - // Legge la riga dal record - void load( const TRectype& rec ); - // Scrive la riga sul record - void save( TRectype& rec ); - // Disabilita le colonne dello sheet come da profilo riga - void configura_sheet( TSheet_field& f, int numriga ); - // Somma la riga su di un piede documento - void edit_keys( const KEY key, TPiede_documento& nuovo ); - // Costruisce e Ritorna la maschera della riga per la editazione - TVariable_mask * getmask(); - // Costruttorino standard - TRiga( ) : _data( LF_RIGHEDOC ), _pro( NULL ) { } + TRiga_documento_motore(TDocumento* doc) : TRiga_documento(doc) { } + TRiga_documento_motore(const TRiga_documento& rec, TDocumento* doc) : TRiga_documento(rec, doc) { } - virtual ~TRiga( ); + virtual ~TRiga_documento_motore() {} }; #endif diff --git a/ve/sconti.cpp b/ve/sconti.cpp index 9e1074cbf..147f19439 100755 --- a/ve/sconti.cpp +++ b/ve/sconti.cpp @@ -26,8 +26,6 @@ #include #endif -// #define A_ANAMAG 0 - HIDDEN const real CENTO(100.0); bool TCond_vendita::set_sconto( const char * exp, bool signal ) @@ -58,7 +56,7 @@ bool TCond_vendita::set_sconto( const char * exp, bool signal ) { // Aggiunge il numero alla sequenza real newval( num ); - _molt_sconto *= ( CENTO + newval ) / CENTO; + _molt_sconto *= ( CENTO - newval ) / CENTO; goodexp << num; } // Inizia il nuovo numero @@ -106,7 +104,7 @@ bool TCond_vendita::set_sconto( const char * exp, bool signal ) { // Aggiunge l'ultimo numero preso real lastval( num ); - _molt_sconto *= ( CENTO + lastval ) / CENTO; + _molt_sconto *= ( CENTO - lastval ) / CENTO; goodexp << num; // Assegna la nuova espressione formattata bene } else @@ -118,7 +116,7 @@ bool TCond_vendita::set_sconto( const char * exp, bool signal ) } } _sconto = goodexp; - if (_riga && _riga->id2pos(FR_SCONTO) >= 0 && _riga->field(FR_SCONTO).active()) + if (_load_mask && _riga && _riga->id2pos(FR_SCONTO) >= 0 && _riga->field(FR_SCONTO).active()) _riga->set(FR_SCONTO, _sconto); return valid; } @@ -148,7 +146,7 @@ void TCond_vendita::set_prezzo(const real & prezzo, const char * val_rif) _prezzo.round(cambio == 1.0 ? 0 : 3); } } - if (_riga && _riga->id2pos(FR_PREZZO) >= 0 && _riga->field(FR_PREZZO).active()) + if (_load_mask && _riga && _riga->id2pos(FR_PREZZO) >= 0 && _riga->field(FR_PREZZO).active()) _riga->set(FR_PREZZO, _prezzo); } @@ -156,7 +154,7 @@ void TCond_vendita::set_provv(const real & provv) { _provv = provv; - if (_riga && _riga->id2pos(FR_PERCPROV) >= 0 && _riga->field(FR_PERCPROV).active()) + if (_load_mask && _riga && _riga->id2pos(FR_PERCPROV) >= 0 && _riga->field(FR_PERCPROV).active()) _riga->set(FR_PERCPROV, _provv); } @@ -164,7 +162,7 @@ void TCond_vendita::set_iva(const TString & codiva) { _codiva = codiva; - if (_riga && _riga->id2pos(FR_CODIVA) >= 0 && _riga->field(FR_CODIVA).active()) + if (_load_mask && _riga && _riga->id2pos(FR_CODIVA) >= 0 && _riga->field(FR_CODIVA).active()) _riga->set(FR_CODIVA, _codiva); } @@ -219,25 +217,25 @@ bool TCond_vendita::cerca( int tiporicerca ) } 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")); - _rcondv.put("COD", _condv.get("COD")); - if( _condv.get_bool( "GESTUM" ) ) - _rcondv.put( "UM", riga().get(FR_UMQTA)); +// _rcondv.setkey( 2 ); const bool gest_scagl = _condv.get_bool("GESTSCAGL"); const TString16 seqricrighe( _condv.get( "SEQRIC" ) ); bool found = FALSE; - if (gest_scagl) - _rcondv.put("NSCAGL", 1); for( int i = 0; !found && i < seqricrighe.len( ); i ++ ) { + _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")); + _rcondv.put("COD", _condv.get("COD")); + if( _condv.get_bool( "GESTUM" ) ) + _rcondv.put( "UM", riga().get(FR_UMQTA)); + if (gest_scagl) + _rcondv.put("NSCAGL", 1); char ricerca = seqricrighe[ i ]; _rcondv.put( "TIPORIGA", ricerca ); @@ -262,13 +260,13 @@ bool TCond_vendita::cerca( int tiporicerca ) _rcondv.put("CODRIGA", anamag().get( "RAGGFIS")); _rcondv.read(); break; - case 'C': + case 'S': { _rcondv.put( "CODRIGA", anamag().get("GRMERC")); _rcondv.read( ); } break; - case 'L': + case 'G': { _rcondv.put( "CODRIGA", anamag().get("GRMERC").left(3)); _rcondv.read( ); @@ -308,10 +306,11 @@ bool TCond_vendita::cerca( int tiporicerca ) } // Probabilmente dovrebbe lavorare sulla maschera, ma per ora la lasciamo cosl -void TCond_vendita::ricerca(bool full_load) +void TCond_vendita::ricerca(bool load_um_only, bool load_scagl_only) { TString codart = anamag().get( "CODART" ); - const TString codriga = riga().get( FR_CODART ); + const TString codriga = riga().get( FR_CODART ); + _load_mask = !load_um_only && !load_scagl_only; if(anamag().bad() || codriga != codart ) { @@ -319,13 +318,13 @@ void TCond_vendita::ricerca(bool full_load) anamag().put("CODART", codriga); if (anamag().read() != NOERR) { - if (full_load) - { +// if (full_load) +// { set_prezzo(ZERO); set_sconto(""); set_iva(""); set_provv(ZERO); - } +// } return; } } @@ -342,31 +341,39 @@ void TCond_vendita::ricerca(bool full_load) } const bool found_condv = cerca(A_CONTRATTI) || cerca(A_OFFERTE) || cerca(A_LISTINI); + const bool cv_scagl = _condv.get_bool("GESTSCAGL"); + const bool cv_um = _condv.get_bool("GESTUM"); if (found_condv) + { + _load_mask |= load_scagl_only && cv_scagl; + _load_mask |= load_um_only && cv_um; set_prezzo(_rcondv.get_real("PREZZO"), _condv.get("CODVAL")); + _load_mask = !load_um_only && !load_scagl_only; + } else - if (full_load) +// if (full_load) set_prezzo(umart().get_real("PREZZO")); - if (full_load) - { +// if (full_load) +// { if (_ivarid) set_iva(anamag().get("CODIVAR")); else set_iva(anamag().get("CODIVA")); - } +// } const char gestione = config_ditta().get_char( "GESSCORIGA", "ve" ); const bool sco_scagl = config_ditta().get_bool("GESCOSCA", "ve"); + const bool sco_um_gest = config_ditta().get_bool("GESSCORIGAUM", "ve"); - if (!full_load && gestione != 'A' && !sco_scagl) - { - if (gestione == 'L' && found_condv) - set_sconto(_rcondv.get("SCONTO")); - } - else +// if (!full_load && gestione != 'A' && !sco_scagl) +// { +// if (gestione == 'L' && found_condv) +// set_sconto(_rcondv.get("SCONTO")); +//} +// else { switch (gestione) { @@ -377,7 +384,12 @@ void TCond_vendita::ricerca(bool full_load) case 'L': // Percentuale su contratti/offerte/listini/anagrafica if (found_condv) + { + _load_mask |= load_scagl_only && cv_scagl; + _load_mask |= load_um_only && cv_um; set_sconto(_rcondv.get("SCONTO")); + _load_mask = !load_um_only && !load_scagl_only; + } else set_sconto(anamag().get("SCONTO")); break; @@ -390,7 +402,7 @@ void TCond_vendita::ricerca(bool full_load) _sconti.put("TIPO", "R"); if( config_ditta().get_bool("GESSCORIGACV", "ve")) _sconti.put("CODCAT", clifo().get(LF_CFVEN, "CATVEN")); - if( config_ditta().get_bool("GESSCORIGAUM", "ve")) + if (sco_um_gest) _sconti.put("UM", riga().get( FR_UMQTA)); _sconti.put("TIPORIGA", rigakey); @@ -448,7 +460,10 @@ void TCond_vendita::ricerca(bool full_load) } if (!found) _sconti.zero(); + _load_mask |= load_scagl_only && sco_scagl; + _load_mask |= load_scagl_only && sco_um_gest; set_sconto(_sconti.get("SCONTO")); + _load_mask = !load_um_only && !load_scagl_only; } break; case 'C': @@ -476,12 +491,12 @@ void TCond_vendita::ricerca(bool full_load) if (tipoprovv <= ' ') tipoprovv = config_ditta().get_char( "AGETIPOPERC", "ve" ); - if (!full_load) - { - if (tipoprovv == 'L' && found_condv) - set_provv(_rcondv.get_real("PERCPROVV")); - } - else +// if (!full_load) +// { +// if (tipoprovv == 'L' && found_condv) +// set_provv(_rcondv.get_real("PERCPROVV")); +// } +// else { switch (tipoprovv) { @@ -493,7 +508,11 @@ void TCond_vendita::ricerca(bool full_load) break; case 'L': if (found_condv) + { + _load_mask |= load_scagl_only && sco_scagl; + _load_mask |= load_scagl_only && sco_um_gest; set_provv(_rcondv.get_real("PERCPROVV")); + } else set_provv(anamag().get_real("PERCPROVV")); break; @@ -524,9 +543,9 @@ void TCond_vendita::ricerca(bool full_load) } } -TCond_vendita::TCond_vendita(TCliFor& clifo, TConfig * ditta, TMask * testa, TMask * riga, +TCond_vendita::TCond_vendita(TCliFor * clifo, TConfig * ditta, TMask * testa, TMask * riga, TLocalisamfile * anamag, TLocalisamfile * umart) - : _clifo(&clifo), _testa(testa), _riga(riga), + : _clifo(clifo), _testa(testa), _riga(riga), _condv( LF_CONDV ), _rcondv( LF_RCONDV ), _sconti( LF_SCONTI ), _anamag(anamag), _umart(umart), _config_ditta(ditta), _ivarid(FALSE) { diff --git a/ve/sconti.h b/ve/sconti.h index 29699ae71..929259704 100755 --- a/ve/sconti.h +++ b/ve/sconti.h @@ -33,7 +33,8 @@ class TCond_vendita : public TObject TLocalisamfile * _umart; TConfig * _config_ditta; TMask * _testa; - TMask * _riga; + TMask * _riga; + bool _load_mask; bool cerca(int tiporicerca); @@ -43,7 +44,7 @@ protected: void set_iva(const TString & codiva); TCliFor & clifo() const { CHECK(_clifo, "Cliente/fornitore non inizializzato"); return * _clifo; } - TConfig & config_ditta() const { CHECK(_clifo, "Configurazione ditta non inizializzata"); return * _config_ditta; } + TConfig & config_ditta() const { CHECK(_config_ditta, "Configurazione ditta non inizializzata"); return * _config_ditta; } TMask & testa() const { CHECK(_testa, "Maschera testata non inizializzata"); return * _testa; } TMask & riga() const { CHECK(_testa, "Maschera testata non inizializzata"); return * _riga; } TLocalisamfile & anamag() const { CHECK(_anamag, "Anagrafica di magazzino non inizializzata") ; return *_anamag; } @@ -62,10 +63,10 @@ public: void set_riga( TMask * riga ){ _riga = riga; } void set_anamag(TLocalisamfile & anamag) { _anamag = &anamag; } void set_umart(TLocalisamfile & umart) { _umart = &umart; } - void ricerca(bool full_load = TRUE); + void ricerca(bool load_um_only = FALSE, bool load_scagl_only = FALSE); bool gestum() const { return _condv.get_bool("GESTUM"); } - TCond_vendita(TCliFor & clifo, TConfig * _ditta = NULL, TMask * testa = NULL, TMask * riga = NULL, + TCond_vendita(TCliFor * clifo = NULL, TConfig * _ditta = NULL, TMask * testa = NULL, TMask * riga = NULL, TLocalisamfile * anamag = NULL, TLocalisamfile * umart = NULL); ~TCond_vendita() {} }; diff --git a/ve/tclifor.cpp b/ve/tclifor.cpp index 0cd0468bd..9c291cd89 100755 --- a/ve/tclifor.cpp +++ b/ve/tclifor.cpp @@ -143,9 +143,8 @@ void TCliForVendite::update_mask( TMask& m, bool onload ) 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" ); + set( m, F_SPESEINC, LF_CFVEN, "PERCSPINC" ); + set( m, F_ADDBOLLI, LF_CFVEN, "ADDBOLLI" ); set(m, F_CATVEN, LF_CFVEN, "CATVEN"); if (m.id2pos(F_CODLIST) >= 0 && m.field(F_CODLIST).active()) set(m, F_CODLIST, LF_CFVEN, "CODLIST"); diff --git a/ve/ve0100.cpp b/ve/ve0100.cpp index 348626c4d..6054da6e9 100755 --- a/ve/ve0100.cpp +++ b/ve/ve0100.cpp @@ -6,13 +6,22 @@ #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->tipo().codice(), TRUE); + + _msk->set( F_TIPODOC, _doc->get("TIPODOC"), TRUE); } void TMotore_application::init_insert_mode( TMask& m ) @@ -26,7 +35,7 @@ void TMotore_application::init_insert_mode( TMask& m ) const long numdoc = m.get_long(F_NDOC); _doc->read(provv, anno, codnum, numdoc); - _doc->head().put("TIPODOC", m.get(F_TIPODOC)); + _doc->set_tipo(m.get(F_TIPODOC)); m.field(F_CODNUM).set_focusdirty(TRUE); m.field(F_CODNUM).on_key(K_TAB); @@ -82,44 +91,11 @@ int TMotore_application::user_function( int index ) // 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 ) +TMask * TMotore_application::ss_getmask( int numriga, TMask& fullmask) { - static TRiga* r = NULL; - - if ( destroy ) - { - delete r; - r = NULL; - return( NULL ); - } - else - { - TSheet_field & ss = *fullmask.get_sheet( ); - TToken_string& riga = ss.row( numriga ); - const TString tipo(riga.get( ss.cid2index(FR_TIPORIGA))); - - if ( tipo.blank() ) return &fullmask; - if ( !r ) - r = new TRiga; - if(r->tipo() != tipo) - { - r->load(ss, riga); - } - TAssoc_array & row_masks = app()._row_masks; - TVariable_mask * row_mask = (TVariable_mask *) row_masks.objptr(tipo); - if (row_mask == NULL) - { - row_mask = r->getmask(); - row_mask->set_sheet( &ss ); - row_masks.add(tipo, row_mask); - } - return( row_mask ); - } -} - -void TMotore_application::azzera_piedi( ) -{ - _piede.destroy( ); + 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 ) @@ -143,50 +119,26 @@ void TMotore_application::user_set_handler( int fieldid, int index, TMask* m ) bool TMotore_application::ss_handler( TSheet_field& ss, int r, KEY key ) { - static TRiga * riga = NULL; - - if ( key == K_SPACE ) // Inizio modifica + if ( key == K_ENTER ) // Cancellazione { - 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; + TRiga_documento & riga = (*(app()._doc))[r + 1]; - riga->load(ss, ss.row( r )); - } - if ( key == K_INS ) // Inserimento - { - TMask & emask = app().edit_mask(); - TToken_string& tsr = ss.row( r ); - tsr.add(emask.get( F_LBTIPORIGA ), FR_TIPORIGA - 101 ); - tsr.add("", FR_STATORIGA - 101 ); - if ( riga ) - delete riga; - riga = new TRiga; - riga->load(ss, tsr); - return TRUE; - } - if (key == K_CTRL + K_INS) - { - ss.select(r); - 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; + 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; } @@ -209,7 +161,6 @@ bool TMotore_application::num_handler( TMask_field& f, KEY key ) // 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 h abilitata le numerazione provvisoria if ( tabnum.get_bool ( "B0" ) ) @@ -343,42 +294,6 @@ bool TMotore_application::clifo_handler( TMask_field& f, KEY key ) return TRUE; } - void TMotore_application::carica_piedi( ) -{ -/* - TToken_string s( pro( ).get( "PROGPIEDE", "MAIN" ) ); // prof - 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; @@ -440,40 +355,34 @@ TMask* TMotore_application::get_mask( int mode ) { const TString16 tipodoc(_msk->get(F_TIPODOC)); - _doc->head().put("TIPODOC", tipodoc); - - TVariable_mask * msk1 = (TVariable_mask *) _doc_masks.objptr(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 TVariable_mask(_doc->tipo().mask_name()); // prof + 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 - TTable tabtr( "%TRI" ); - TToken_string keys( "" ), descrs( "" ); + TToken_string keys, descrs; + TRiga_documento r(_doc); + 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" ) ); // pro - tabtr.put( "CODTAB", tiporiga ); - if ( tabtr.read( ) == NOERR ) - { - keys.add( tabtr.get( "CODTAB" ) ); - descrs.add( tabtr.get( "S0" ) ); - } - else - error_box( "Inserito un tipo di riga non valido ( %s )", ( const char * )tiporiga ); + { + 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 ); @@ -628,14 +537,10 @@ const char* TMotore_application::get_next_key( ) int TMotore_application::read( TMask& m ) { - azzera_piedi( ); - - TRectype & curr = _rel->lfile().curr(); - const int err = _doc->read(curr); + const int err = _doc->read(_doc->head()); if ( err == NOERR ) { - curr = _doc->head(); m.autoload(*_rel); const char tipocf = _doc->head().get("TIPOCF")[0]; const long codcf = _doc->head().get_long("CODCF"); @@ -649,17 +554,13 @@ int TMotore_application::read( TMask& m ) f.destroy( ); const int rows = _doc->rows(); for (int i = 1; i <= rows; i++) - { - TToken_string& srow = f.row( i - 1 ); - TRectype& rec = (*_doc)[i]; - - TRiga currentrow; + { + TToken_string & r = f.row(i -1); + TRiga_documento & rec = (*_doc)[i]; - currentrow.load( rec ); - currentrow.save(f, srow); + rec.autoload(f); f.post_insert(i - 1); } - carica_piedi( ); } return err; } @@ -676,22 +577,10 @@ int TMotore_application::write( const TMask& m ) // C 90 if ( err == NOERR ) { m.autosave(*_rel); - _doc->head() = _rel->lfile().curr(); - TSheet_field& f = ss( ); - _doc->destroy_rows(); - for ( int i = 0; i < f.items( ); i ++ ) - { - TToken_string& t = f.row( i ); - TRectype& rec = _doc->new_row(); - store_riga( f, i, rec ); - } err = _doc->write( ); } if (err == NOERR) - { - _rel->curr() = _doc->head(); _rel->read(); // per posizionare correttamente la relazione - } } return err; @@ -710,16 +599,6 @@ int TMotore_application::rewrite( const TMask& m ) // C 90 if ( err == NOERR ) { m.autosave(*_rel); - _doc->head() = _rel->lfile().curr(); - - TSheet_field& f = ss( ); - _doc->destroy_rows( ); - for ( int i = 0; i < f.items( ); i ++ ) - { - TToken_string& t = f.row( i ); - TRectype& rec = _doc->new_row(); - store_riga( f, i, rec ); - } err = _doc->rewrite( ); } } @@ -735,57 +614,6 @@ bool TMotore_application::remove( void ) // C 80 return _doc->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(f, rigastr, &r); - riga.save( r ); -} - void TMotore_application::open_files(int logicnum, ...) { va_list marker; @@ -805,7 +633,6 @@ void TMotore_application::on_firm_change() _config_ditta = new TConfig(CONFIG_DITTA); condv().set_config(_config_ditta); _doc_masks.destroy(); - _row_masks.destroy(); TApplication::on_firm_change(); } @@ -830,17 +657,19 @@ bool TMotore_application::user_create( ) _rel = new TRelation( LF_DOC ); open_files(LF_RIGHEDOC, LF_CONDV, LF_RCONDV, LF_ANAMAG, LF_SCONTI, LF_UMART, 0); _doc = new TDocumento; + _rel->lfile().set_curr(_doc); + _doc->set_relation(_rel); _clifor = new TCliForVendite( ); - _condv = new TCond_vendita(*_clifor, _config_ditta); + _condv = new TCond_vendita(_clifor, _config_ditta); + _doc->set_condv(_condv); - azzera_piedi( ); _msk = new TMask( "ve0100a" ); query_mask( ).set_handler( F_CODNUM, num_handler ); query_mask( ).set_handler( F_TIPODOC, tip_handler ); TConfig utente( CONFIG_USER ); - _doc->head().put("CODNUM", utente.get("CODNUM")); - _doc->head().put("TIPODOC", utente.get("TIPODOC")); + _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 @@ -852,7 +681,7 @@ 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->tipo().codice(), "ve" ); + utente.set( "TIPODOC", _doc->get("TIPODOC"), "ve" ); if (_config_ditta != NULL) delete _config_ditta; @@ -861,7 +690,6 @@ bool TMotore_application::user_destroy( ) delete _msk; // Distruggo la relazione - delete _doc; delete _rel; delete _condv; diff --git a/ve/ve0100.h b/ve/ve0100.h index adb006507..1d0bc9dcd 100755 --- a/ve/ve0100.h +++ b/ve/ve0100.h @@ -14,27 +14,8 @@ #define NO_CHANGE_STATUS -1 // #define NO_DOC_STATUS -2 -#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 occorre 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 @@ -48,10 +29,6 @@ #include #endif -#ifndef __BRWAPP_H -#include -#endif - #ifndef __RELAPP_H #include #endif @@ -126,12 +103,10 @@ // Definizione della classe dell'applicazione motore class TMotore_application : public TRelation_application -{ +{ TArray _file; // Tutti i fiels da usare - // Array di totalizzatori - TPiede_documento _piede; - + TDocumento * _doc; // Puntatore al profilo del documento caricato @@ -143,120 +118,111 @@ class TMotore_application : public TRelation_application // puntatore alla relazione TRelation * _rel; - + // Puntatore allo sheet delle righe documento TSheet_field * _sheet; - + // Oggetto cliente per il motore TCliForVendite * _clifor; - + TCond_vendita * _condv; - + // Indica se il documento ha come soggetto un liente o un ornitore char _tipocf; - + // TString16 _profilo; // TString16 _codnum; -// TString16 _tipodoc; +// TString16 _tipodoc; // int _anno; // TString16 _tiponum; // long _numdoc; // int _statodoc; - + // Array di maschere documento - + TAssoc_array _doc_masks; - // Array di maschere righe - - TAssoc_array _row_masks; - - // Ridefinizione dei metodi virtuali + // Ridefinizione dei metodi virtuali virtual bool user_create( ); - virtual bool user_destroy( ); + 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_query_mode(TMask& m); 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 ); - - void azzera_piedi( ); - void carica_piedi( ); - void somma_piedi( ); - void sottrai_piedi( ); - + // Esegue, se c'h, la procedura utente relativa ad una certa operazione int esegui_procedura( int operazione ); - + protected: - + void open_files(int logicnum, ...); void close_files() { _file.destroy(); } virtual void on_firm_change(); // Procedure e funzioni per la gestione della maschera e dei files - void read_rdoc( TMask& m ); + void read_rdoc( TMask& m ); void update_profile(); - - // 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 ); - + + // formato dipendente dallo sheet ( sono le varie colonne ) +// void load_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 ); - - // Procedure e funzioni per la gestione degli stati + + // 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 ); + 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 ); - + static TMask * ss_getmask( int numriga, TMask& fullmask); + // 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 elabora_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: - + + virtual TRelation* get_relation( ) const { return _rel;} + // Funzioni di accesso alle variabili private - + TConfig & pro() { CHECK( _pro, "Profilo del documento nullo!" ); return *_pro; } const TFilename & proname() { return _pro->name(); } TMask & query_mask() { CHECK( _msk, "Maschera di ricerca nulla!" ); return *_msk; } @@ -264,16 +230,16 @@ public: 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; } - TCond_vendita & condv() { return *_condv; } + TCond_vendita & condv() { return *_condv; } TConfig & config_ditta() {return *_config_ditta; } - + TDocumento & doc() {return *_doc; } + // 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; } @@ -281,5 +247,6 @@ public: }; -TMotore_application& app( ) { return ( TMotore_application& ) main_app( ); } +inline TMotore_application & app() { return (TMotore_application &) main_app(); } + #endif diff --git a/ve/ve0100c.cpp b/ve/ve0100c.cpp index b1d59c566..0be8db88e 100755 --- a/ve/ve0100c.cpp +++ b/ve/ve0100c.cpp @@ -21,11 +21,11 @@ #endif #ifndef __VEUML_H -#include "VeUML.h" +#include "veuml.h" #endif #ifndef __VEUML1_H -#include "VeUML1.h" +#include "veuml1.h" #endif #ifndef __VE0100_H @@ -104,3 +104,200 @@ bool condpag_hndl( TMask_field& field, KEY key ) return TRUE; } +// handler delle righe + +void row_set_handler( TMask& m, const int field, const int index ) +{ + switch ( index ) + { + case 1: + m.set_handler( field, dummy_hndl ); + break; + default: + yesnofatal_box( FALSE, "Funzione di handler sulla riga non definita( %d ).", index ); + } +} + +HIDDEN TString16 curr_um; +HIDDEN real curr_fc(1.0); + +bool codart_handler( TMask_field& f, KEY key ) +{ + // Se qualcuno cerca di modificare la maschera + if ( key == K_TAB && f.focusdirty()) + { + TMask& row_mask = f.mask(); +// TMask & mask = app().edit_mask(); + TMask & mask = row_mask.get_sheet()->mask(); + TCond_vendita & condv = app().condv(); + + condv.set_testa(&mask); + condv.set_riga(&row_mask); + + TLocalisamfile & anamag = ((TEdit_field &) f).browse()->cursor()->file(); + TLocalisamfile & umart = ((TEdit_field &) row_mask.field(FR_UMQTA)).browse()->cursor()->file(); + + condv.set_anamag(anamag); + condv.set_umart(umart); + TString80 codart(f.get()); + anamag.setkey(1); + anamag.put("CODART", codart); + if (anamag.read() != NOERR) + { + TLocalisamfile codalt(LF_CODCORR); + + codalt.setkey(2); + codalt.put("CODARTALT", codart); + if (codalt.read() == NOERR) + { + codart = codalt.get("CODART"); + anamag.zero(); + anamag.put("CODART", codart); + if (anamag.read() == NOERR) + f.set(codart); + } + } + + if (anamag.good()) + { + const TString16 lingua = mask.get(F_CODLIN); + const TString codart(row_mask.get(FR_CODART)); + TString desc(anamag.get("DESCR")); + + if (lingua.not_empty()) + { + TLocalisamfile deslin(LF_DESLIN); + + deslin.setkey(2); + deslin.put("CODART", codart); + deslin.put("CODLIN", lingua); + if (deslin.read() == NOERR) + desc = deslin.get("DESCR"); + } + row_mask.set(FR_DESCR, desc); + + umart.setkey(1); + umart.zero(); + umart.put("CODART", codart); + if (umart.read(_isgteq) == NOERR && codart == umart.get("CODART")) + { + curr_um = umart.get("UM"); + curr_fc = umart.get_real("FC"); + } + else + { + curr_um.cut(0); + curr_fc = 1.0; + } + row_mask.set(FR_UMQTA, curr_um); + } + + condv.ricerca(); + } + return TRUE; +} + +bool umart_handler( TMask_field& f, KEY key ) +{ + // Se qualcuno cerca di modificare la maschera + if ( key == K_TAB && f.focusdirty()) + { + TMask& row_mask = f.mask( ); +// TMask & mask = app().edit_mask(); + TMask & mask = row_mask.get_sheet()->mask(); + TLocalisamfile & anamag = ((TEdit_field &) row_mask.field(FR_CODART)).browse()->cursor()->file(); + TLocalisamfile & umart = ((TEdit_field &) f).browse()->cursor()->file(); + TCond_vendita & condv = app().condv(); + + condv.set_testa(&mask); + condv.set_riga(&row_mask); + condv.set_anamag(anamag); + condv.set_umart(umart); + condv.ricerca(FALSE); + + const TString16 um(f.get()); + real fc(1.0); + + if (um.not_empty() && curr_um.not_empty() && um != curr_um) + { + umart.setkey(2); + umart.put("CODART", row_mask.get(FR_CODART)); + umart.put("UM", um); + if (umart.read() == NOERR) + { + real qta(row_mask.get_real(FR_QTA)); + qta *= curr_fc; + fc = umart.get_real("FC"); + qta /= fc; + row_mask.set(FR_QTA, qta); + } + + } + curr_um = um; + curr_fc = fc; + } + return TRUE; +} + +bool descr_handler( TMask_field& f, KEY key ) +{ + if (key == K_TAB && f.focusdirty()) + { + const TString s(f.get()); + if (s.find('\n') < 0) + { + TLocalisamfile & anamag = ((TEdit_field &) f).browse()->cursor()->file(); + + anamag.zero(); + anamag.setkey(2); + anamag.put("DESCR", ((TZoom_field &) f).get_first_line()); + if (anamag.read() == NOERR) + { + f.mask().set(FR_CODART, anamag.get("CODART")); + f.mask().field(FR_CODART).set_dirty(); + f.mask().check_field(FR_CODART); + } + } + } + return TRUE; +} + +bool qta_handler( TMask_field& f, KEY key ) +{ + // Se qualcuno cerca di modificare la maschera + if ( key == K_TAB && f.focusdirty()) + { + TMask& row_mask = f.mask( ); +// TMask & mask = app().edit_mask(); + TMask & mask = row_mask.get_sheet()->mask(); + TLocalisamfile & anamag = ((TEdit_field &) row_mask.field(FR_CODART)).browse()->cursor()->file(); + TLocalisamfile & umart = ((TEdit_field &) row_mask.field(FR_UMQTA)).browse()->cursor()->file(); + TCond_vendita & condv = app().condv(); + + condv.set_testa(&mask); + condv.set_riga(&row_mask); + condv.set_anamag(anamag); + condv.set_umart(umart); + condv.ricerca(FALSE); + } + return TRUE; +} + +bool cod_handler( TMask_field& f, KEY key ) +{ + if ( key == K_TAB && f.focusdirty()) + { + TMask& row_mask = f.mask( ); + TMask & mask = row_mask.get_sheet()->mask(); + real cambio = mask.get(F_CAMBIO); + + if (cambio != 0.0) + { + real prezzo = row_mask.get(FR_PREZZO); + + prezzo /= mask.get_real(F_CAMBIO); + row_mask.set(FR_PREZZO, prezzo); + } + } + return TRUE; +} diff --git a/ve/ve0100c.h b/ve/ve0100c.h index b51d45a45..7d7b67e48 100755 --- a/ve/ve0100c.h +++ b/ve/ve0100c.h @@ -1,8 +1,14 @@ #define __VE0100C_H -// Handlers per i campi delle bolle +// Handlers per testata e righe -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 +bool ora_hndl(TMask_field& field, KEY key); +bool codcli_hndl(TMask_field& field, KEY key); +bool dummy_hndl(TMask_field& field, KEY key); +bool condpag_hndl(TMask_field& field, KEY key); +void row_set_handler(TMask& m, const int field, const int index); +bool codart_handler(TMask_field& f, KEY key); +bool umart_handler(TMask_field& f, KEY key); +bool descr_handler(TMask_field& f, KEY key); +bool qta_handler(TMask_field& f, KEY key); +bool cod_handler(TMask_field& f, KEY key); diff --git a/ve/ve0200f.uml b/ve/ve0200f.uml index 70cfcc1ae..917cc5b01 100755 --- a/ve/ve0200f.uml +++ b/ve/ve0200f.uml @@ -87,7 +87,7 @@ PAGE "Gestione spese bolli" 1 1 60 14 NUMBER F_SPBOSCA1 11 BEGIN PROMPT 2 2 "Scaglione " -FIELD SPBOBSCA[1] +FIELD SPBOSCA[1] PICTURE "." END diff --git a/ve/ve0300.cpp b/ve/ve0300.cpp index 0fc888f6e..93e729737 100755 --- a/ve/ve0300.cpp +++ b/ve/ve0300.cpp @@ -91,7 +91,7 @@ // Numero massimo di linee per pagina -#define MAX_LINES_PER_PAGE 18 +#define MAX_LINES_PER_PAGE 19 #define MASK_FIRST_LINE 6 #define GROUPKEY(x) format( "%5d", x ) @@ -120,7 +120,7 @@ public: void check( const int i ); // PAGE - void pagina( const int i, const TString& title = "Pagina " ){ _out << "PA \"" << title << " " << i << "\" 11 60 14\n"; }; + void pagina( const int i, const TString& title = "Pag." ){ _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"; }; @@ -148,7 +148,7 @@ public: // PICTURE void picture( const int p) { _out << "PI " << p << "\n"; }; - void picture( const TString & s) { _out << "PI " << s << "\n"; }; + void picture( const TString & s) { _out << "PI " << '\"' << s << "\"\n"; }; // FIELD void field( const TString& s ) { outline( s, "FI "); }; @@ -503,9 +503,8 @@ void TGruppo::add( TField * field ) TGruppo::TGruppo( int i ) { - TConfig pro( "ve0300c.ini" ); _id = i; - _height = pro.get_int( "HEIGHT", format( "%d", i ) ); + _height = 0; } TGruppo::TGruppo( int i, int height ) @@ -530,8 +529,16 @@ static void verifica_campo( const TObject& campo ) TGruppo & gruppo = cmp.grp(); cmp.stato(cmp.stato_reale()); - if (!gruppo.present() && cmp.stato() != S_NASCOSTO) - gruppo.present(TRUE); + if (cmp.stato() != S_NASCOSTO) + { + int h = cmp.y() + 1; + if (cmp.type() == T_CORNICE) + h += cmp.size()%100 - 1; + if (gruppo.height() < h) + gruppo.height(h); + if (!gruppo.present()) + gruppo.present(TRUE); + } } HIDDEN TProgind * _bar; @@ -896,8 +903,7 @@ void TMask_generator::carica_dati_campi( const TFilename& fn, TAssoc_array& a ) } TString16 taggruppo; taggruppo.format( "%d", campo->gruppo( ) ); - int hgruppo = _groupsini.get_int( "HEIGHT", taggruppo ); - gruppo = new TGruppo( campo->gruppo( ), hgruppo ); + gruppo = new TGruppo( campo->gruppo( )); gruppo->generatore( *this ); } gruppo->add( campo ); @@ -974,9 +980,8 @@ void TMask_generator::carica_dati_campi( const TFilename& fn, TAssoc_array& a ) a.add( curgruppo, gruppo ); } TString16 taggruppo; - taggruppo.format( "%d", campo->gruppo( ) ); - int hgruppo = _groupsini.get_int( "HEIGHT", taggruppo ); - gruppo = new TGruppo( campo->gruppo( ), hgruppo ); + taggruppo.format("%d", campo->gruppo()); + gruppo = new TGruppo(campo->gruppo()); gruppo->generatore( *this ); } gruppo->add( campo ); @@ -1184,7 +1189,7 @@ void TMask_generator::genera( const TString& profilo ) _m->begin( ); _m->prompt( 2, 1, "Cod. num. " ); _m->field("CODNUM"); - _m->use("NUM", 1); + _m->use("%NUM", 1); temp_s.format("CODTAB %d", F_CODNUM); _m->input(temp_s); _m->display("\"Codice\" CODTAB~\"Descrizione@50\" S0"); @@ -1332,7 +1337,6 @@ void TMask_generator::genera( const TString& profilo ) // Generazione - // carica_ordine_gruppi( ); // Scorro l'array dei gruppi, e ne creo una copia ordinata // con solo i gruppi visibili @@ -1381,29 +1385,38 @@ void TMask_generator::genera( const TString& profilo ) // Generazione pagina dei piedi { - TToken_string s(_pro->get("PROGPIEDE", "MAIN")); + TToken_string s(_pro->get("CAMPICALC", "MAIN")); if (s.not_empty()) { intestazione_pagina( ); - TTable ppd( "%PPD" ); + TTable frd( "%FRD" ); int nr = 1; int id = 0; for (const char * cp = s.get(0); cp && *cp; cp = s.get()) { const TString16 codpiede(cp); do_events(); - ppd.zero( ); - ppd.put( "CODTAB", codpiede ); - if ( ppd.read( ) == NOERR ) + frd.zero( ); + frd.put( "CODTAB", codpiede ); + if ( frd.read( ) == NOERR ) { - const TString80 picture(ppd.get( "S3")); + const TString80 picture(frd.get( "S3")); + const int len = picture.len() > 0 ? picture.len() : 18; + int dec = picture.find(','); + if (dec >= 0) + dec = len - dec - 1; + else + dec = 0; id++; - _m->control( T_NUMERO, BASE_PIEDE + id, 1805); + if (frd.get_bool("B0")) + _m->control( T_NUMERO, BASE_PIEDE + id, len * 100 + dec); + else + _m->control( T_STRINGA, BASE_PIEDE + id, len * 100); _m->begin( ); - TString80 header(ppd.get("S0")); header.left_just(40 - picture.len()); + TString80 header(frd.get("S0")); header.left_just(58 - len); _m->prompt( 2, 7 + nr, header ); _m->field(codpiede); @@ -1447,7 +1460,6 @@ protected: virtual bool create ( ); virtual bool destroy( ); - // virtual bool menu( MENU_TAG ); // Controlla il menu }; diff --git a/ve/veconf.h b/ve/veconf.h index 0b260d68f..5ea5d0587 100755 --- a/ve/veconf.h +++ b/ve/veconf.h @@ -57,16 +57,24 @@ // Campi per ve0200d.uml #define F_SPINCODIVA 101 #define F_SPINDESIVA 102 -#define F_SPINCODCON1 103 -#define F_SPINCODCON2 104 -#define F_SPINCODCON3 105 -#define F_SPINDESCON 106 -#define F_SPBRBCODIVA 107 -#define F_SPBRBDESIVA 108 -#define F_SPBRBCODCON1 109 -#define F_SPBRBCODCON2 110 -#define F_SPBRBCODCON3 111 -#define F_SPBRBDESCON 112 +#define F_SPINCODCON1V 103 +#define F_SPINCODCON2V 104 +#define F_SPINCODCON3V 105 +#define F_SPINDESCONV 106 +#define F_SPBOCODIVA 107 +#define F_SPBODESIVA 108 +#define F_SPBOCODCON1V 109 +#define F_SPBOCODCON2V 110 +#define F_SPBOCODCON3V 111 +#define F_SPBODESCONV 112 +#define F_SPBOCODCON1A 113 +#define F_SPBOCODCON2A 114 +#define F_SPBOCODCON3A 115 +#define F_SPBODESCONA 116 +#define F_SPINCODCON1A 117 +#define F_SPINCODCON2A 118 +#define F_SPINCODCON3A 119 +#define F_SPINDESCONA 120 // Campi per ve0200e.uml #define F_RICERCACR1 101 diff --git a/ve/veini.h b/ve/veini.h index d18bf7188..43fa68492 100755 --- a/ve/veini.h +++ b/ve/veini.h @@ -11,3 +11,11 @@ #define S_DISABILITATO 1 #define S_NORMALE 2 #define S_OBBLIGATORIO 3 + +// #define F_LBTIPORIGA 175 +// #define NPIEDI 40 + +#define F_SHEET 500 +// #define F_MEMORIGA 501 +#define BASE_PIEDE 600 + diff --git a/ve/velib01.cpp b/ve/velib01.cpp index 3f22abf95..2388e700a 100755 --- a/ve/velib01.cpp +++ b/ve/velib01.cpp @@ -2,13 +2,382 @@ #include +#ifndef __APPLICAT_H +#include +#endif + +#ifndef __EXPR_H +#include +#endif + +#ifndef __STACK_H +#include +#endif + +#ifndef __UTILITY_H +#include +#endif + #include "velib01.h" +#include "sconti.h" + +#ifndef __VE0100C_H +#include "ve0100c.h" +#endif + +#ifndef __VERIG_H +#include "verig.h" +#endif + +#ifndef __VEUML_H +#include "veuml.h" +#endif + +#ifndef __VEUML1_H +#include "veuml1.h" +#endif + +#ifndef __VEINI_H +#include "veini.h" +#endif + +#ifndef __PAGAMENT_H +#include "..\cg\pagament.h" +#endif + +#ifndef __SCONTI_H +#include "sconti.h" +#endif + +TSpesa_prest::TSpesa_prest(const char* codice, char tipo) + : TRectype(LF_TAB) +{ + settab(tipo == 'S' ? "SPP" : "PRS"); + if (codice && *codice) + read(codice); +} + +TSpesa_prest::TSpesa_prest(const TRectype& rec) + : TRectype(rec) +{ +} + +int TSpesa_prest::read(const char* codice) +{ + TTable t(get("COD")); + put("CODTAB", codice); + int err = TRectype::read(t); + if (err != NOERR) + yesnofatal_box("Tipo spesa assente : %s", codice); + return err; +} + +TIVA::TIVA(const char* codice) + : TRectype(LF_TABCOM) +{ + settab("IVA"); + if (codice && *codice) + read(codice); +} + +TIVA::TIVA(const TRectype& rec) + : TRectype(rec) +{ +} + +int TIVA::read(const char* codice) +{ + TTable t("%IVA"); + put("CODTAB", codice); + int err = TRectype::read(t); + if (err != NOERR) + yesnofatal_box("Codice IVA assente : %s", codice); + return err; +} + +bool ora_hndl( TMask_field& field, KEY key ) + +{ + 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 ); + } + } + const bool ok = ((isdigit(ora[0]))&&(isdigit(ora[1]))&&(isdigit(ora[3]))&&(isdigit(ora[4]))) && + ((atoi(&(ora[0]))<24)&&(atoi(&(ora[3]))<60)); + if (ok ) + field.set((ora)); + else + return error_box("Ora errata o formato non valido"); + } + } + 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 ( field.to_check(key)) + { + TDocumento_mask& m = (TDocumento_mask &) field.mask( ); + TString16 condpag( m.get( F_CODPAG ) ); + TString16 data( m.get( F_DATAINSC ) ); + if ( condpag.not_empty() && data.not_empty()) + { + TPagamento pag(condpag, data); + + pag.set_total( 100, 10, 10 ); + pag.set_rate_auto( ); + int numrate = pag.n_rate( ); + if (numrate > 5) + numrate = 5; + 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 delle righe + +HIDDEN void row_set_handler( TMask& m, const int field, const int index ) +{ + switch ( index ) + { + case 1: + m.set_handler( field, dummy_hndl ); + break; + default: + yesnofatal_box( FALSE, "Funzione di handler sulla riga non definita( %d ).", index ); + } +} + +HIDDEN TString16 curr_um; +HIDDEN real curr_fc(1.0); + +HIDDEN bool codart_handler( TMask_field& f, KEY key ) +{ + // Se qualcuno cerca di modificare la maschera + if ( key == K_TAB && f.focusdirty()) + { + TMask& row_mask = f.mask(); + TDocumento_mask & mask = (TDocumento_mask &) row_mask.get_sheet()->mask(); + TCond_vendita & condv = mask.condv(); + + condv.set_testa(&mask); + condv.set_riga(&row_mask); + + TLocalisamfile & anamag = ((TEdit_field &) f).browse()->cursor()->file(); + TLocalisamfile & umart = ((TEdit_field &) row_mask.field(FR_UMQTA)).browse()->cursor()->file(); + + condv.set_anamag(anamag); + condv.set_umart(umart); + TString80 codart(f.get()); + anamag.setkey(1); + anamag.put("CODART", codart); + if (anamag.read() != NOERR) + { + TLocalisamfile codalt(LF_CODCORR); + + codalt.setkey(2); + codalt.put("CODARTALT", codart); + if (codalt.read() == NOERR) + { + codart = codalt.get("CODART"); + anamag.zero(); + anamag.put("CODART", codart); + if (anamag.read() == NOERR) + f.set(codart); + } + } + + if (anamag.good()) + { + const TString16 lingua = mask.get(F_CODLIN); + const TString codart(row_mask.get(FR_CODART)); + TString desc(anamag.get("DESCR")); + + if (lingua.not_empty()) + { + TLocalisamfile deslin(LF_DESLIN); + + deslin.setkey(2); + deslin.put("CODART", codart); + deslin.put("CODLIN", lingua); + if (deslin.read() == NOERR) + desc = deslin.get("DESCR"); + } + row_mask.set(FR_DESCR, desc); + + umart.setkey(1); + umart.zero(); + umart.put("CODART", codart); + if (umart.read(_isgteq) == NOERR && codart == umart.get("CODART")) + { + curr_um = umart.get("UM"); + curr_fc = umart.get_real("FC"); + } + else + { + curr_um.cut(0); + curr_fc = 1.0; + } + row_mask.set(FR_UMQTA, curr_um); + } + + condv.ricerca(); + } + return TRUE; +} + +HIDDEN bool umart_handler( TMask_field& f, KEY key ) +{ + // Se qualcuno cerca di modificare la maschera + if ( key == K_TAB && f.focusdirty()) + { + TMask& row_mask = f.mask( ); + TDocumento_mask & mask = (TDocumento_mask &) row_mask.get_sheet()->mask(); + TLocalisamfile & anamag = ((TEdit_field &) row_mask.field(FR_CODART)).browse()->cursor()->file(); + TLocalisamfile & umart = ((TEdit_field &) f).browse()->cursor()->file(); + TCond_vendita & condv = mask.condv(); + + condv.set_testa(&mask); + condv.set_riga(&row_mask); + condv.set_anamag(anamag); + condv.set_umart(umart); + condv.ricerca(TRUE); + + const TString16 um(f.get()); + real fc(1.0); + + if (um.not_empty() && curr_um.not_empty() && um != curr_um) + { + umart.setkey(2); + umart.put("CODART", row_mask.get(FR_CODART)); + umart.put("UM", um); + if (umart.read() == NOERR) + { + real qta(row_mask.get_real(FR_QTA)); + qta *= curr_fc; + fc = umart.get_real("FC"); + qta /= fc; + row_mask.set(FR_QTA, qta); + } + + } + curr_um = um; + curr_fc = fc; + } + return TRUE; +} + +HIDDEN bool descr_handler( TMask_field& f, KEY key ) +{ + if (key == K_TAB && f.focusdirty()) + { + const TString s(f.get()); + if (s.find('\n') < 0) + { + TLocalisamfile & anamag = ((TEdit_field &) f).browse()->cursor()->file(); + + anamag.zero(); + anamag.setkey(2); + anamag.put("DESCR", ((TZoom_field &) f).get_first_line()); + if (anamag.read() == NOERR) + { + f.mask().set(FR_CODART, anamag.get("CODART")); + f.mask().field(FR_CODART).set_dirty(); + f.mask().check_field(FR_CODART); + } + } + } + return TRUE; +} + +HIDDEN bool qta_handler( TMask_field& f, KEY key ) +{ + // Se qualcuno cerca di modificare la maschera + if ( key == K_TAB && f.focusdirty()) + { + TMask& row_mask = f.mask( ); + TDocumento_mask & mask = (TDocumento_mask &) row_mask.get_sheet()->mask(); + TLocalisamfile & anamag = ((TEdit_field &) row_mask.field(FR_CODART)).browse()->cursor()->file(); + TLocalisamfile & umart = ((TEdit_field &) row_mask.field(FR_UMQTA)).browse()->cursor()->file(); + TCond_vendita & condv = mask.condv(); + + condv.set_testa(&mask); + condv.set_riga(&row_mask); + condv.set_anamag(anamag); + condv.set_umart(umart); + condv.ricerca(FALSE, TRUE); + } + return TRUE; +} + +HIDDEN bool sppr_handler( TMask_field& f, KEY key ) +{ + if (key == K_TAB && f.focusdirty()) + { + TMask& row_mask = f.mask( ); + const int pos = row_mask.id2pos(FR_PREZZO); + + if (pos >= 0) + { + TMask & mask = row_mask.get_sheet()->mask(); + TRectype & spprrec = ((TEdit_field &) row_mask.field(FR_CODART)).browse()->cursor()->file().curr(); + + if (spprrec.get("CODTAB") == row_mask.get(FR_CODART) && spprrec.get_char("S6") != 'P') + { + real cambio = mask.get(F_CAMBIO); + real prezzo = row_mask.get(FR_PREZZO); + const TString16 doc_valuta(mask.get(F_CODVAL)); + const TString16 sppr_valuta(spprrec.get("S4")); + + if (sppr_valuta != doc_valuta && cambio != 0.0) + { + TTable val("%VAL"); + + val.put("CODTAB", sppr_valuta); + if (val.read() == NOERR) + { + const real sppr_cambio = val.get_real("R10"); + if (sppr_cambio != ZERO) + prezzo *= sppr_cambio; + } + prezzo /= mask.get_real(F_CAMBIO); + } + row_mask.set(FR_PREZZO, prezzo); + } + } + } + return TRUE; +} /////////////////////////////////////////////////////////// // Funzioni per il calcolo dei prezzi netti/lordi /////////////////////////////////////////////////////////// -real lordo2netto(real& lordo, const TString& codiva, bool is_valuta) +real lordo2netto(real& lordo, const TString& codiva, int ndec) { TTable tabiva("%IVA"); real aliquota = 0.0; @@ -16,10 +385,10 @@ real lordo2netto(real& lordo, const TString& codiva, bool is_valuta) tabiva.put("CODTAB", codiva); if (tabiva.read() == NOERR) aliquota = tabiva.get_real("R0"); - return lordo2netto(lordo,aliquota,is_valuta); + return lordo2netto(lordo,aliquota, ndec); } -real netto2lordo(const real& netto, const TString& codiva, bool is_valuta) +real netto2lordo(const real& netto, const TString& codiva, int ndec) { TTable tabiva("%IVA"); real aliquota = 0.0; @@ -27,10 +396,10 @@ real netto2lordo(const real& netto, const TString& codiva, bool is_valuta) tabiva.put("CODTAB", codiva); if (tabiva.read() == NOERR) aliquota = tabiva.get_real("R0"); - return netto2lordo(netto,aliquota,is_valuta); + return netto2lordo(netto,aliquota, ndec); } -real lordo2netto(real& lordo, const real& iva, bool is_valuta) +real lordo2netto(real& lordo, const real& iva, int ndec) { real netto; real imposta = 0.0; @@ -38,33 +407,558 @@ real lordo2netto(real& lordo, const real& iva, bool is_valuta) if (!iva.is_zero()) { imposta = (lordo * iva) / (iva + 100.0); // Calcola l'imposta... - imposta.ceil(is_valuta ? 3 : 0); + imposta.ceil(ndec); } netto = lordo - imposta; // Questo e' l'importo netto imposta_rec = (netto * iva) / 100.0; // Ricalcola l'imposta con il nuovo imponibile - imposta_rec.ceil(is_valuta ? 3 : 0); + imposta_rec.ceil(ndec); if (imposta != imposta_rec) // In questo caso corregge l'importo lordo lordo = netto + imposta_rec; return netto; } -real netto2lordo(const real& netto, const real& iva, bool is_valuta) +real netto2lordo(const real& netto, const real& iva, int ndec) { real lordo; real imposta = 0.0; if (!iva.is_zero()) { imposta = (netto * iva) / 100.0; // Calcola l'imposta - imposta.ceil(is_valuta ? 3 : 0); + imposta.ceil(ndec); } lordo = imposta + netto; // prezzo lordo return lordo; } +real prezzo_scontato(const real& prezzo, const char * sconto) +{ + real scontato = prezzo; + + if (sconto && *sconto) + { + TCond_vendita cv; + + cv.set_sconto(sconto); + scontato = cv.sconto_val() * prezzo; + } + return scontato; +} + +enum TTipo_calcolo { _nessun_calcolo, _qtaprezzo, _valore, _percentuale, _scontoimp, _scontoperc}; + +real iva(real imponibile, const TIVA & iva,int ndec) +{ + real val = imponibile * iva.aliquota() / 100.0; + + val.ceil(ndec); + return val; +} + +real TDocumento::spese_incasso(real & imp, int ndec, bool netto) const +{ + real imp_spese; + real percentuale = get_real("PERCSPINC"); + static TArray spese_inc; + + if (percentuale > ZERO) + { + if (spese_inc.objptr(_rim_dir) == NULL) + { + TConfig conf(CONFIG_STUDIO); + + for (TTipo_pag p = _rim_dir; p < _nessun_pag; p = (TTipo_pag) ((int)p + 1)) + { + real r(conf.get("IMPSPIN", "ve", p)); + spese_inc.add(r, p); + } + } + TPagamento & pag = ((TDocumento *)this)->pagamento(); + const int nrate = pag.n_rate(); + + for (int i = 0; i < nrate; i++) + { + const TTipo_pag p = (TTipo_pag) pag.tipo_rata(i); + imp_spese += (real &) spese_inc[p]; + } + imp_spese *= percentuale / 100.0; + + real cambio = get_real("CAMBIO"); + + if (cambio == ZERO) + cambio = 1.0; + imp_spese /= cambio; + imp_spese.round(ndec); + if (netto == FALSE) + { + static TString16 codiva; + static long firm = -1; + long new_firm = main_app().get_firm(); + + if (firm != new_firm) + { + TConfig conf(CONFIG_DITTA); + + codiva = conf.get("SPINCODIVA", "ve"); + firm = new_firm; + } + imp_spese += iva(imp_spese, TRiga_documento::iva(codiva), ndec); + } + } + return imp_spese; +} + +real TDocumento::bolli(real & imp, int ndec, bool netto) const +{ + real tot_bolli; + static TArray sca_bolli; + static TArray imp_bolli; + static int nscagl; + TLocalisamfile clifo(LF_CLIFO); + bool estero = 2; + + if (get_bool("ADDBOLLI")) + { + real cambio = get_real("CAMBIO"); + + if (cambio == ZERO) + cambio = 1.0; + + real importo = imp*cambio; + TPagamento & pag = ((TDocumento*)this)->pagamento(); + const int nrate = pag.n_rate(); + real old_bolli = -1.00; + real iva_bolli; + + for (int j = 0; j < 5 && tot_bolli != old_bolli; j++) + { + old_bolli = tot_bolli; + const real imposte = imposta() * cambio + iva_bolli; + const real imp_spese = spese() * cambio + tot_bolli - iva_bolli; + const real imponibile = importo - imposte - imp_spese; + + tot_bolli = ZERO; + pag.set_total(imponibile, imposte, imp_spese); + pag.set_rate_auto(); + + for (int i = 0; i < nrate; i++) + { + const TTipo_pag p = (TTipo_pag) pag.tipo_rata(i); + real imp = pag.importo_rata(i); + + switch (p) + { + case _ric_ban: + { + if (sca_bolli.objptr(0) == NULL) + { + TConfig conf(CONFIG_STUDIO); + + for (nscagl = 0; nscagl < 7; nscagl++) + { + real s(conf.get("SPBOSCA", "ve", nscagl + 1)); + real i(conf.get("SPBOIMP", "ve", nscagl + 1)); + + if (s == ZERO && i == ZERO) + break; + sca_bolli.add(s, nscagl); + imp_bolli.add(i, nscagl); + } + } + for (int i = 0; i < nscagl - 1; i++) + if ((real &) sca_bolli[i] >= imp) + break; + tot_bolli += (real &) imp_bolli[i]; + } + break; + case _tratta: + case _tratta_acc: + { + if (estero == 2) + { + clifo.put("TIPOCF", get("TIPOCF")); + clifo.put("CODCF", get("CODCF")); + + if (clifo.read() != NOERR) + clifo.zero(); + + const TString16 stato(clifo.get("STATOPAIV")); + + estero = stato.not_empty() && stato != "IT"; + if (!estero) + estero = clifo.get("STATOCF").not_empty() || clifo.get("COMCF")[0] == 'Z'; + } + real r(imp); + + r.ceil(-3); + if (estero) + r *= 0.009; + else + r *= 0.012; + r.round(-2); + tot_bolli += r; + } + break; + case _cessione: + case _paghero: + case _let_cred: + case _rim_dir: + case _rid: + case _bonfico: + default: + break; + } + } + if (netto == FALSE) + { + static TString16 codiva; + static long firm = -1; + long new_firm = main_app().get_firm(); + + if (firm != new_firm) + { + TConfig conf(CONFIG_DITTA); + + codiva = conf.get("SPBOCODIVA", "ve"); + firm = new_firm; + } + iva_bolli = iva(tot_bolli, TRiga_documento::iva(codiva), ndec); + tot_bolli += iva_bolli; + } + importo += (tot_bolli - old_bolli); + } + tot_bolli /= cambio; + tot_bolli.round(ndec); + } + + return tot_bolli; +} + +/////////////////////////////////////////////////////////// +// Formula generica +/////////////////////////////////////////////////////////// + +HIDDEN enum _formula {_somma, _bolli, _bolli_int, _spinc, _prezzo, _importo, _sconto, _iva, _provv, _tipo}; + +TExpr_documento::TExpr_documento(const char* expression, TTypeexp type, + TDocumento * doc, TRiga_documento * row) + : TExpression(type), _doc(doc), _row(row) +{ + if (!set(expression, type)) + error_box("Wrong expression : %s", expression); +} + +int TExpr_documento::parse_user_func(const char * name, int nparms) const +{ + if (strcmp(name, "SOMMA") == 0) + return nparms > 0 || nparms < 3 ? _somma : -1; + else + if (strcmp(name, "BOLLI") == 0) + return nparms > 0 || nparms < 4 ? _bolli : -1; + else + if (strcmp(name, "_BOLLI") == 0) + return nparms > 0 || nparms < 3 ? _bolli_int : -1; + else + if (strcmp(name, "SPESEINC") == 0) + return nparms > 0 || nparms < 4 ? _spinc : -1; + else + if (strcmp(name, "PREZZO") == 0) + return nparms < 4 ? _prezzo : -1; + else + if (strcmp(name, "IMPORTO") == 0) + return nparms < 4 ? _importo : -1; + else + if (strcmp(name, "SCONTO") == 0) + return nparms < 2 ? _sconto : -1; + else + if (strcmp(name, "IVA") == 0) + return nparms < 2 ? _iva : -1; + else + if (strcmp(name, "PROVV") == 0) + return nparms < 2 ? _provv : -1; + else + if (strcmp(name, "TIPO") == 0) + return nparms == 0 ? _tipo : -1; + else + return -1; +} + +void TExpr_documento::evaluate_user_func(int index, int nparms, TEval_stack & stack, TTypeexp type) const +{ + switch (index) + { + case _somma: + { + const TString cond(nparms == 2 ? stack.pop_string() : "STR(1)"); + const TString & fieldname = stack.pop_string(); + real somma; + + if (_doc != NULL) + { + TExpr_documento cond_expr(cond, _strexpr, _doc); + const int nrows = _doc->rows(); + const int nvars = cond_expr.numvar(); + + for (int i = nrows; i > 0 ; i--) + { + TRiga_documento & riga = (TRiga_documento &) (*_doc)[i]; + + for (int j = nvars - 1; j >= 0; j--) + { + const char* s = cond_expr.varname(j); + TFieldref f(s,0); + cond_expr.setvar(j, f.read(riga)); + } + cond_expr.set_row(&riga); + if ((bool)cond_expr) + somma += riga.get_real(fieldname); + } + } + stack.push(somma); + } + break; + case _spinc: + { + int ndec = _doc && _doc->in_valuta() ? 3 : 0; + bool netto = FALSE; + + if (nparms > 2) + ndec = (int) stack.pop_real().integer(); + if (nparms > 1) + netto = !stack.pop_real().is_zero(); + + real & r = stack.peek_real(); + + if (_doc) + r = _doc->spese_incasso(r, ndec, netto); + else + r = ZERO; + } + break; + case _bolli: + { + int ndec = _doc && _doc->in_valuta() ? 3 : 0; + bool netto = FALSE; + + if (nparms > 2) + ndec = (int) stack.pop_real().integer(); + if (nparms > 1) + netto = !stack.pop_real().is_zero(); + + real & r = stack.peek_real(); + + if (_doc) + { + r += _doc->spese_incasso(r, ndec); + r = _doc->bolli(r, ndec, netto); + } + else + r = ZERO; + } + break; + case _bolli_int: + { + int ndec = _doc && _doc->in_valuta() ? 3 : 0; + + if (nparms > 2) + ndec = (int) stack.pop_real().integer(); + + real & r = stack.peek_real(); + + if (_doc) + { + real r1 = _doc->spese_incasso(r, ndec); + r += r1; + r1 += _doc->bolli(r, ndec); + r = r1; + } + else + r = ZERO; + } + break; + case _prezzo: + { + int ndec = _doc && _doc->in_valuta() ? 3 : 0; + bool lordo = FALSE; + bool scontato = FALSE; + + if (nparms > 2) + ndec = (int) stack.pop_real().integer(); + if (nparms > 1) + lordo = !stack.pop_real().is_zero(); + if (nparms > 0) + scontato = !stack.peek_real().is_zero(); + else + stack.push(ZERO); + + real & val = stack.peek_real(); + if (_row) + val = _row->prezzo(scontato, lordo, ndec); + else val = ZERO; + + } + break; + case _importo: + { + int ndec = _doc && _doc->in_valuta() ? 3 : 0; + bool lordo = FALSE; + bool scontato = FALSE; + + if (nparms > 2) + ndec = (int) stack.pop_real().integer(); + if (nparms > 1) + lordo = !stack.pop_real().is_zero(); + if (nparms > 0) + scontato = !stack.peek_real().is_zero(); + else + stack.push(ZERO); + + real & val = stack.peek_real(); + if (_row) + val = _row->importo(scontato, lordo, ndec); + else + val = ZERO; + } + break; + case _sconto: + { + int ndec = _doc && _doc->in_valuta() ? 3 : 0; + + if (nparms > 0) + ndec = (int) stack.peek_real().integer(); + else + stack.push(ZERO); + + real & val = stack.peek_real(); + if (_row) + { + if (_row->tipo().tipo() == 'C') + val = -_row->importo(FALSE, FALSE, ndec); + else + val = _row->importo(FALSE, FALSE, ndec) - _row->importo(TRUE, FALSE, ndec); + } + else + val = ZERO; + } + break; + case _iva: + { + int ndec = _doc && _doc->in_valuta() ? 3 : 0; + + if (nparms > 0) + ndec = (int) stack.peek_real().integer(); + else + stack.push(ZERO); + + real & val = stack.peek_real(); + + if (_row) + val = _row->iva(ndec); + else + val = ZERO; + } + break; + case _provv: + { + int ndec = _doc && _doc->in_valuta() ? 3 : 0; + + if (nparms > 0) + ndec = (int) stack.peek_real().integer(); + else + stack.push(ZERO); + + real & val = stack.peek_real(); + + if (_row) + { + val = _row->importo(TRUE, FALSE, ndec) * _row->get_real("PERCPROV") / 100.0; + val.round(ndec); + } + else + val = ZERO; + } + break; + case _tipo: + { + TString s; + if (_row) + s << _row->tipo().tipo(); + stack.push(s); + } + break; + default: + TExpression::evaluate_user_func(index, nparms, stack, type); + break; + } +} + +TObject* TExpr_documento::dup() const +{ + TExpr_documento* o = new TExpr_documento(*this); + return o; +} + +/////////////////////////////////////////////////////////// +// Formula generica +/////////////////////////////////////////////////////////// + +TFormula_documento::TFormula_documento(TTipo_formula tipo, const char* codice) + : TRectype(LF_TABCOM), _expr(NULL) +{ + _tab = tipo == _documento ? "FRD" : "FRR"; + settab(_tab); + _tab.insert("%"); + if (codice && *codice) + read(codice); +} + +TFormula_documento::TFormula_documento(const TRectype& rec) + : TRectype(rec), _expr(NULL) +{ + _tab = "%"; + _tab << rec.get("COD"); + _expr = new TExpr_documento(expr_string(), expr_type()); +} + +TFormula_documento::~TFormula_documento() +{ + if (_expr) delete _expr; +} + +int TFormula_documento::read(const char* codice) +{ + if (_expr != NULL) + { + delete _expr; + _expr = NULL; + } + + TTable t(_tab); + + put("CODTAB", codice); + + int err = TRectype::read(t); + + if (err == NOERR) + { + const TString e(expr_string()); + + _expr = new TExpr_documento(e, expr_type()); + } + else + { + zero(); + put("CODTAB", codice); + } + return err; +} + + /////////////////////////////////////////////////////////// // Tipo documento /////////////////////////////////////////////////////////// +TAssoc_array TTipo_documento::_formule_documento; + TTipo_documento::TTipo_documento(const char* tipodoc) : TRectype(LF_TABCOM) { @@ -75,7 +969,9 @@ TTipo_documento::TTipo_documento(const char* tipodoc) TTipo_documento::TTipo_documento(const TRectype& rec) : TRectype(rec) -{ } +{ + read_formule(); +} TTipo_documento::~TTipo_documento() { } @@ -85,49 +981,241 @@ int TTipo_documento::read(const char* tipodoc) TTable t("%TIP"); put("CODTAB", tipodoc); int err = TRectype::read(t); - if (err != NOERR) + _formule = ""; + if (err == NOERR) + read_formule(); + else yesnofatal_box("Tipo documento errato: %s", tipodoc); return err; } +void TTipo_documento::read_formule() + +{ + TFilename prof(profile_name()); + + prof.ext("ini"); + + TConfig profile(prof); + + _formule = profile.get("CAMPICALC", "MAIN"); + _formule.add(profile.get("CALCOLI", "MAIN")); + _imponibile = profile.get("IMPONIBILE", "MAIN"); + if (_imponibile.not_empty() && _formule.find(_imponibile) < 0) + { + error_box("Campo imponibile (%s) sconosciuto nel tipo documento %s", (const char *) _imponibile, (const char *) codice()); + _imponibile.cut(0); + } + _imposta = profile.get("IMPOSTA", "MAIN"); + if (_imposta.not_empty() && _formule.find(_imposta) < 0) + { + error_box("Campo imposta (%s) sconosciuto nel tipo documento %s", (const char *) _imposta, (const char *) codice()); + _imposta.cut(0); + } + _totale = profile.get("TOTALE", "MAIN"); + if (_totale.not_empty() && _formule.find(_totale) < 0) + { + error_box("Campo totale documento (%s) sconosciuto nel tipo documento %s", (const char *) _totale, (const char *) codice()); + _totale.cut(0); + } + _basesconto = profile.get("BASESCONTO", "MAIN"); + if (_basesconto.not_empty() && _formule.find(_basesconto) < 0) + { + error_box("Campo sconto documento (%s) sconosciuto nel tipo documento %s", (const char *) _basesconto, (const char *) codice()); + _basesconto.cut(0); + } + _spese = profile.get("SPESE", "MAIN"); + if (_spese.not_empty() && _formule.find(_spese) < 0) + { + error_box("Campo spese (%s) sconosciuto nel tipo documento %s", (const char *) _spese, (const char *) codice()); + _spese.cut(0); + } +} + +TFormula_documento * TTipo_documento::succ_formula(bool restart) +{ + if (restart) + _formule.restart(); + const TString16 formula(_formule.get()); + if (formula.not_empty()) + { + TFormula_documento * o = (TFormula_documento*)_formule_documento.objptr(formula); + if (o == NULL) + { + o = new TFormula_documento(_documento, formula); + _formule_documento.add(formula, o); + } + return o; + } + else + return NULL; +} + /////////////////////////////////////////////////////////// // Tipo riga di un documento /////////////////////////////////////////////////////////// +TAssoc_array TTipo_riga_documento::_formule_riga; + TTipo_riga_documento::TTipo_riga_documento(const char* tiporig) - : TRectype(LF_TABCOM) + : TRectype(LF_TABCOM), _mask(NULL) { settab("TRI"); + _name = "verig"; + _name << codice(); if (tiporig && *tiporig) read(tiporig); } TTipo_riga_documento::TTipo_riga_documento(const TRectype& rec) - : TRectype(rec) -{ } + : TRectype(rec), _mask(NULL) +{ + _name = "verig"; + _name << codice(); + read_formule(); +} TTipo_riga_documento::~TTipo_riga_documento() -{ } +{ + if (_mask) delete _mask; +} int TTipo_riga_documento::read(const char* tiporig) { TTable t("%TRI"); put("CODTAB", tiporig); int err = TRectype::read(t); - if (err != NOERR) + if (err == NOERR) + read_formule(); + else yesnofatal_box("Tipo riga documento errato: %s", tiporig); return err; } +void TTipo_riga_documento::read_formule() + +{ + TFilename prof(profile_name()); + + prof.ext("ini"); + + TConfig profile(prof); + + _formule = profile.get("CAMPICALC", "MAIN"); + _formule.add(profile.get("CALCOLI", "MAIN")); + _imponibile = profile.get("IMPONIBILE", "MAIN"); + if (_imponibile.not_empty() && _formule.find(_imponibile) < 0) + { + error_box("Campo imponibile (%s) sconosciuto nel tipo riga %s", (const char *) _imponibile, (const char *) codice()); + _imponibile.cut(0); + } + _imposta = profile.get("IMPOSTA", "MAIN"); + if (_imposta.not_empty() && _formule.find(_imposta) < 0) + { + error_box("Campo imposta (%s) sconosciuto nel tipo riga %s", (const char *) _imposta, (const char *) codice()); + _imposta.cut(0); + } +} + +TFormula_documento * TTipo_riga_documento::succ_formula(bool restart) +{ + if (restart) + _formule.restart(); + const TString16 formula(_formule.get()); + if (formula.not_empty()) + { + TFormula_documento * o = (TFormula_documento*)_formule_riga.objptr(formula); + if (o == NULL) + { + o = new TFormula_documento(_riga, formula); + _formule_riga.add(formula, o); + } + return o; + } + else + return NULL; +} + +TVariable_mask * TTipo_riga_documento::mask() +{ + if (mask_loaded()) + return _mask; + _mask = new TVariable_mask(mask_name()); + TFilename proname(profile_name()); + + proname.ext( "ini" ); + + TConfig pro( proname ); + int numhandler = pro.get_int( "NHANDLER", "HANDLERS" ); + + for( int i = 1; i <= numhandler; i ++ ) + { + TString chiave; + chiave.format( "%d", i ); + TToken_string riga = pro.get( chiave, "HANDLERS" ); + row_set_handler( *_mask, riga.get_int( 0 ), riga.get_int( 1 ) ); + } + + const int pos = _mask->id2pos(FR_CODART); + + if (pos >= 0) + { + const TMask_field & f = _mask->field(FR_CODART); + if (f.is_edit()) + { + TBrowse * browse = ((TEdit_field &) f).browse(); + const char tipo_r = tipo(); + + if (browse ) + { + const TCursor * cur = browse->cursor(); + if (cur) + { + const int num = cur->file().num(); + if (num == LF_ANAMAG) + { + _mask->set_handler( FR_CODART, codart_handler ); + _mask->set_handler( FR_UMQTA, umart_handler ); + _mask->set_handler( FR_DESCR, descr_handler ); + _mask->set_handler( FR_QTA, qta_handler ); + } + else + if (tipo_r == 'S' || tipo_r == 'P') + _mask->set_handler( FR_CODART, sppr_handler ); + } + } + } + } + return _mask; +} + /////////////////////////////////////////////////////////// // Riga documento per vendite /////////////////////////////////////////////////////////// TAssoc_array TRiga_documento::_tipi; +TAssoc_array TRiga_documento::_spese; +TAssoc_array TRiga_documento::_ive; +TRiga_documento::TRiga_documento(TDocumento* doc, const char * tipo) + : TAuto_variable_rectype(LF_RIGHEDOC), _doc(doc) +{ + if (tipo) + set_tipo(tipo); +} + +TRiga_documento::TRiga_documento(const TRiga_documento& rec, TDocumento* doc, + const char * tipo) + : TAuto_variable_rectype(rec), _doc(doc) +{ + if (tipo) + set_tipo(tipo); +} + const TTipo_riga_documento& TRiga_documento::tipo() const { const TString16 tiporig(get("TIPORIGA")); + CHECK(tiporig.not_empty(), "Tipo riga documento nullo"); TTipo_riga_documento* o = (TTipo_riga_documento*)_tipi.objptr(tiporig); if (o == NULL) { @@ -150,6 +1238,45 @@ const TTipo_riga_documento& TRiga_documento::tipo() const return *o; } +const TSpesa_prest & TRiga_documento::spesa() const +{ +#ifdef DBG + const char tipor = tipo().tipo(); + + CHECK(tipor == 'S' || tipor == 'P', "Tipo riga incompatibile con le spese"); +#endif + static long firm = -1; + long new_firm = main_app().get_firm(); + + if (firm != new_firm) + { + _spese.destroy(); + firm = new_firm; + } + + const TString16 codice(get("CODART")); + TString16 index; index << tipor << codice; + + TSpesa_prest * s = (TSpesa_prest *) _spese.objptr(index); + if (s == NULL) + { + s = new TSpesa_prest(codice, tipor); + _spese.add(index, s); + } + return *s; +} + +const TIVA & TRiga_documento::iva(const char *codice) +{ + TIVA * v = (TIVA *) _ive.objptr(codice); + if (v == NULL) + { + v = new TIVA(codice); + _ive.add(codice, v); + } + return *v; +} + bool TRiga_documento::sola_descrizione() const { char t = tipo().tipo(); @@ -178,7 +1305,21 @@ void TRiga_documento::forza_sola_descrizione() } } - +TRectype & TRiga_documento::operator =(const TRectype & r) +{ + TRectype::operator=(r); + reset_fields(*this); + set_fields(*this); + return *this; +} + +TRectype & TRiga_documento::operator =(const char * r) +{ + TRectype::operator=(r); + reset_fields(*this); + set_fields(*this); + return *this; +} // Ritorna TRUE se le due righe del documento possono essere sommate bool TRiga_documento::raggruppabile(const TRiga_documento& r, TToken_string& campi) const @@ -216,6 +1357,325 @@ TRiga_documento& TRiga_documento::operator +=(const TRiga_documento& r) return *this; } +void TRiga_documento::set_fields(TAuto_variable_rectype & rec) +{ + if (get("TIPORIGA").not_empty()) + { + TTipo_riga_documento & tipo_riga = (TTipo_riga_documento &) tipo(); + + for (const TFormula_documento * f = tipo_riga.first_formula(); f; f = tipo_riga.succ_formula()) + { + TExpr_documento * exp = f->expr(); + add_field(new TDocumento_variable_field(f->name(), exp)); + if (exp) + { + exp->set_doc(_doc); + exp->set_row(this); + } + } + } +} + +real TRiga_documento::prezzo(bool scontato, bool lordo, int ndec) const +{ + real prezzo = get_real("PREZZO"); + if (scontato) + prezzo = prezzo_scontato(prezzo, get("SCONTO")); + prezzo.round(ndec); + if (lordo) + prezzo = netto2lordo(prezzo, get("CODIVA"), ndec); + prezzo.round(ndec); + return prezzo; +} + +real TRiga_documento::importo(bool scontato, bool lordo, int ndec, bool iva_calc) const +{ + real importo; + + TTipo_calcolo c = _nessun_calcolo; + const char tipor = tipo().tipo(); + const real qta = get_real("QTA"); + TString16 field_perc; + TCond_vendita cv; + + switch (tipor) + { + case 'M': + c = _qtaprezzo; + break; + case 'P': + case 'S': + { + const TSpesa_prest & s = spesa(); + + switch (s.tipo()) + { + case 'Q': + c = _qtaprezzo; + break; + case 'V': + c = _valore; + break; + case 'P': + c = _percentuale; + field_perc = s.field_perc(); + break; + default: + break; + } + } + break; + case 'C': + cv.set_sconto(get("SCONTO")); + + if (cv.get_sconto().not_empty()) + c = _scontoperc; + else + c = _scontoimp; + break; + case 'O': + if (iva_calc) + c = _qtaprezzo; + default: + break; + } + switch (c) + { + case _qtaprezzo: + importo = prezzo(scontato, lordo, ndec) * qta; + break; + case _valore: + importo = prezzo(scontato, lordo, ndec); + break; + case _percentuale: + importo = doc().get_real(field_perc) * get_real("PSPESA") / 100; + break; + case _scontoimp: + importo = -prezzo(FALSE, lordo, ndec); + break; + case _scontoperc: + importo = doc().basesconto() * (cv.sconto_val() - 1.0); + break; + default: + break; + } + importo.round(ndec); + + return importo; +} + +real TRiga_documento::imponibile() const +{ + const TString16 field(tipo().imponibile()); + + if (field.not_empty()) + return get_real(field); + else + return importo(TRUE, FALSE, doc().in_valuta() ? 3 : 0); +} + +real TRiga_documento::imposta() const +{ + const TString16 field(tipo().imposta()); + + if (field.not_empty()) + return get_real(field); + else + return iva(doc().in_valuta() ? 3 : 0); +} + +void TRiga_documento::dirty_fields(bool dirty_document) +{ + for (TDocumento_variable_field * f = (TDocumento_variable_field *) first_variable_field(); + f != NULL; f = (TDocumento_variable_field *) succ_variable_field()) + f->set_dirty(); + if (dirty_document) + ((TDocumento &)doc()).dirty_fields(); +} + +bool TRiga_documento::doc_dependent() const + +{ + const char tipor = tipo().tipo(); + + if (tipor == 'S') + return spesa().tipo() == 'P'; + else + if (tipor == 'C') + return get("SCONTO").not_empty(); + + return FALSE; +} + +void TRiga_documento::put_str(const char* fieldname, const char* val) +{ + if (strcmp(fieldname, "TIPORIGA") == 0 && TRectype::get("TIPORIGA") != val) + { + TAuto_variable_rectype::put_str(fieldname, val); + reset_fields(*this); + set_fields(*this); + } + else + { + TAuto_variable_rectype::put_str(fieldname, val); + dirty_fields(); + } +} + +void TRiga_documento::zero(const char * fieldname) +{ + if (strcmp(fieldname, "TIPORIGA") == 0) + reset_fields(*this); + TAuto_variable_rectype::zero(fieldname); + dirty_fields(); +} + +void TRiga_documento::zero(char c) +{ + reset_fields(*this); + TAuto_variable_rectype::zero(c); +} + +void TRiga_documento::autosave(TSheet_field & f) +{ + const int num = numero() - 1; + + if (num >= 0 && num < f.items()) + { + TToken_string & row = f.row(num); + + put( "STATORIGA", row.get( f.cid2index(FR_STATORIGA) ) ); + put( "TIPORIGA", row.get( f.cid2index(FR_TIPORIGA )) ); + TString16 codmag(row.get(f.cid2index(FR_CODMAG))); + + codmag.left_just(3); + codmag << row.get( f.cid2index(FR_CODDEP )); + put( "CODMAG", codmag); + put( "CODART", row.get( f.cid2index(FR_CODART )) ); + TString s(row.get(f.cid2index(FR_DESCR))); + int split_pos = s.find('\n'); + if (split_pos > 0) + { + put( "DESCR", s.left(split_pos)); + put("DESCLUNGA", "X"); + s.ltrim(split_pos); + put("DESCEST", s); + } + else + { + put("DESCR", s); + put("DESCLUNGA", ""); + zero("DESCEST"); + } + + put( "PREZZO", row.get( f.cid2index(FR_PREZZO )) ); + put( "UMQTA", row.get( f.cid2index(FR_UMQTA )) ); + TMask * m = ((TTipo_riga_documento &)tipo()).mask(); + const int pos = m->id2pos(FR_QTA); + if (pos >= 0 && m->fld(pos).field()->name() == "PSPESA") + put( "PSPESA", row.get( f.cid2index(FR_QTA )) ); + else + put( "QTA", row.get( f.cid2index(FR_QTA )) ); + put( "QTAEVASA", row.get( f.cid2index(FR_QTAEVASA )) ); + put( "RIGAEVASA", row.get( f.cid2index(FR_RIGAEVASA )) ); + put( "TARA", row.get( f.cid2index(FR_TARA )) ); + put( "PNETTO", row.get( f.cid2index(FR_PNETTO )) ); + put( "NCOLLI", row.get( f.cid2index(FR_NCOLLI )) ); + put( "DAEVADERE", row.get( f.cid2index(FR_DAEVADERE )) ); + put( "SCONTO", row.get( f.cid2index(FR_SCONTO )) ); + put( "PERCPROV", row.get( f.cid2index(FR_PERCPROV )) ); + put( "IMPFISSO", row.get( f.cid2index(FR_IMPFISSO )) ); + put( "CODIVA", row.get( f.cid2index(FR_CODIVA )) ); + put( "ADDIVA", row.get( f.cid2index(FR_ADDIVA )) ); + put( "ASPBENI", row.get( f.cid2index(FR_ASPBENI )) ); + } +} + +void TRiga_documento::autoload(TSheet_field & f) +{ + const int num = numero() - 1; + + if (num >= 0 && num < f.items()) + { + TToken_string & row = f.row(num); + + row.add( get( "STATORIGA" ), f.cid2index(FR_STATORIGA )); + row.add( get( "TIPORIGA" ), f.cid2index(FR_TIPORIGA )); + const TString codmag(get("CODMAG")); + row.add( codmag.left(3), f.cid2index(FR_CODMAG )); + row.add( codmag.mid(3), f.cid2index(FR_CODDEP )); + row.add( get( "CODART" ), f.cid2index(FR_CODART )); + TString s(get("DESCR")); + if (get_bool("DESCLUNGA")) + s << get("DESCEST"); + row.add(s, f.cid2index(FR_DESCR )); + row.add( get( "UMQTA" ), f.cid2index(FR_UMQTA )); + row.add( get( "PREZZO" ), f.cid2index(FR_PREZZO )); + TMask * m = ((TTipo_riga_documento &)tipo()).mask(); + const int pos = m->id2pos(FR_QTA); + if (pos >= 0 && m->fld(pos).field()->name() == "PSPESA") + row.add( get( "PSPESA" ), f.cid2index(FR_QTA )); + else + row.add( get( "QTA" ), f.cid2index(FR_QTA )); + row.add( get( "QTAEVASA" ), f.cid2index(FR_QTAEVASA )); + row.add( get( "RIGAEVASA" ), f.cid2index(FR_RIGAEVASA )); + row.add( get( "TARA" ), f.cid2index(FR_TARA )); + row.add( get( "PNETTO" ), f.cid2index(FR_PNETTO )); + row.add( get( "NCOLLI" ), f.cid2index(FR_NCOLLI )); + row.add( get( "DAEVADERE" ), f.cid2index(FR_DAEVADERE )); + row.add( get( "SCONTO" ), f.cid2index(FR_SCONTO )); + row.add( get( "PERCPROV" ), f.cid2index(FR_PERCPROV )); + row.add( get( "IMPFISSO" ), f.cid2index(FR_IMPFISSO )); + row.add( get( "CODIVA" ), f.cid2index(FR_CODIVA )); + row.add( get( "ADDIVA" ), f.cid2index(FR_ADDIVA )); + row.add( get( "ASPBENI" ), f.cid2index(FR_ASPBENI )); + } +} + +TDocumento_mask::TDocumento_mask(const char* name, TDocumento * doc, int num, + int max) + : TVariable_mask(name, num, max), _progs_page(-1), _last_prog(-1), + _doc(doc) +{ + const int pos = id2pos(BASE_PIEDE + 1); + + if (pos >= 0) + { + _progs_page = find_parent_page(fld(pos)); + _last_prog = 0; + while (id2pos(BASE_PIEDE + _last_prog + 1) >= 0) + _last_prog++; + } +} + +void TDocumento_mask::next_page(int p) +{ + TMask::next_page(p); + if (curr_page() == _progs_page) + { + begin_wait(); + autosave(get_relation()); + for (int i = _last_prog; i > 0; i--) + { + const short id = BASE_PIEDE + i; + const TString16 name(field(id).field()->name()); + + set(id , doc().get(name)); + } + end_wait(); + } +} + +bool TDocumento_mask::on_key(KEY key) +{ + if (key == K_SHIFT + K_F12) + { + field(F_STATO).enable(!field(F_STATO).enabled()); + return TRUE; + } + return TVariable_mask::on_key(key); +} + /////////////////////////////////////////////////////////// // Documento per vendite /////////////////////////////////////////////////////////// @@ -223,13 +1683,18 @@ TRiga_documento& TRiga_documento::operator +=(const TRiga_documento& r) TAssoc_array TDocumento::_tipi; TDocumento::TDocumento() - : TRectype(LF_DOC), _rows(LF_RIGHEDOC, "NRIGA"), _nuovo(TRUE) -{ + : TAuto_variable_rectype(LF_DOC), _rows(LF_RIGHEDOC, "NRIGA"), _nuovo(TRUE), + _condv(NULL), _rel(NULL) +{ + set_memo_fld("G1"); } -TDocumento::TDocumento(char provv, int anno, const char* codnum, long numdoc) - : TRectype(LF_DOC), _rows(LF_RIGHEDOC, "NRIGA"), _nuovo(TRUE) +TDocumento::TDocumento(char provv, int anno, const char* codnum, long numdoc, + TCond_vendita * condv, TRelation * rel) + : TAuto_variable_rectype(LF_DOC), _rows(LF_RIGHEDOC, "NRIGA"), _nuovo(TRUE), + _condv(condv), _rel(rel) { + set_memo_fld("G1"); if (numdoc <= 0) { numdoc = 0; @@ -274,13 +1739,32 @@ void TDocumento::copy_data(TRectype& dst, const TRectype& src) dst.put("NRIGA", nriga); } - -TDocumento::TDocumento(const TRectype& rec) - : TRectype(LF_DOC), _rows(LF_RIGHEDOC, "NRIGA"), _nuovo(FALSE) +TDocumento::TDocumento(const TRectype& rec, TCond_vendita * condv, TRelation * rel) + : TAuto_variable_rectype(LF_DOC), _rows(LF_RIGHEDOC, "NRIGA"), _nuovo(FALSE), + _condv(condv), _rel(rel) { + set_memo_fld("G1"); read(rec); } +TRiga_documento& TDocumento::insert_row(int row, const char *tipo) +{ + TRiga_documento * r = new TRiga_documento((const TRiga_documento &) _rows.key(), this); + r->set_numero(row); + if (tipo) + r->set_tipo(tipo); + _rows.insert_row(r); + return *r; +} + +TRiga_documento& TDocumento::new_row(const char *tipo) +{ + TRiga_documento & r = (TRiga_documento&)_rows.row(-1, TRUE); + if (tipo) + r.set_tipo(tipo); + return r; +} + int TDocumento::read(const TRectype& rec) { head() = rec; @@ -302,7 +1786,7 @@ int TDocumento::read(const TRectype& rec) else { _nuovo = TRUE; - *this = rec; + head() = rec; destroy_rows(); _rows.set_key(key); } @@ -332,6 +1816,20 @@ long TDocumento::renum(long numdoc) return numdoc; } +void TDocumento::dirty_fields() +{ + for (TDocumento_variable_field * f = (TDocumento_variable_field *) first_variable_field(); + f != NULL; f = (TDocumento_variable_field *) succ_variable_field()) + f->set_dirty(); + for (int i = rows(); i > 0; i--) + { + TRiga_documento & r = (TRiga_documento &) _rows.row(i, FALSE); + + if (r.doc_dependent()) + r.dirty_fields(FALSE); + } +} + int TDocumento::write(bool re) const { const bool nuovo = _nuovo || numero() <= 0; // E' nuovo di zecca! @@ -387,7 +1885,7 @@ int TDocumento::remove() const return err; } -const bool TDocumento::in_valuta() +const bool TDocumento::in_valuta() const { const TString& val = valuta(); return (val.not_empty() && val != "LIT"); @@ -448,6 +1946,157 @@ bool TDocumento::raggruppabile(const TDocumento& doc, TToken_string& campi) cons return ok; } +void TDocumento::set_fields(TAuto_variable_rectype & rec) +{ + if (get("TIPODOC").not_empty()) + { + TTipo_documento & tipo_doc = (TTipo_documento &) tipo(); + const TString16 tot_doc(tipo_doc.totale_doc()); + + for (const TFormula_documento * f = tipo_doc.first_formula(); f; f = tipo_doc.succ_formula()) + { + TExpr_documento * exp = f->expr(); + if (tot_doc == f->name()) + { + TString work_tot_doc(tot_doc); + + work_tot_doc.insert("_"); + + add_field(new TDocumento_variable_field(work_tot_doc, exp)); + + TExpr_documento * new_exp = new TExpr_documento( + format("%s + _BOLLI(%s)", (const char *) work_tot_doc, + (const char *) work_tot_doc), _numexpr, this); + + add_field(new TDocumento_variable_field(f->name(), new_exp)); + } + else + add_field(new TDocumento_variable_field(f->name(), exp)); + if (exp) + exp->set_doc(this); + } + } +} + +real TDocumento::imponibile() const +{ + const TString16 field(tipo().imponibile()); + + if (field.not_empty()) + return get_real(field); + else + { + real val; + + for (int i = rows(); i > 0; i--) + val += ((TRiga_documento &) ((TDocumento *)this)->row(i)).imponibile(); + return val; + } +} + +real TDocumento::imposta() const +{ + const TString16 field(tipo().imposta()); + + if (field.not_empty()) + return get_real(field); + else + { + real val; + + for (int i = rows(); i > 0; i--) + val += ((TRiga_documento &) ((TDocumento *)this)->row(i)).imposta(); + return val; + } +} + +real TDocumento::totale_doc() const +{ + const TString16 field(tipo().totale_doc()); + + if (field.not_empty()) + return get_real(field); + else + return imponibile() + imposta(); +} + +real TDocumento::basesconto() const +{ + const TString16 field(tipo().basesconto()); + + if (field.not_empty()) + return get_real(field); + else + return ZERO; +} + +real TDocumento::spese() const +{ + const TString16 field(tipo().spese()); + + if (field.not_empty()) + return get_real(field); + else + return ZERO; +} + +TPagamento & TDocumento::pagamento() +{ + const TString16 codpag(get("CODPAG")); + + if (codpag != _pag.code()) + { + _pag.set_code(codpag); + _pag.read(); + } + return _pag; +} + +void TDocumento::put_str(const char* fieldname, const char* val) +{ + if (strcmp(fieldname, "TIPODOC") == 0 && TRectype::get("TIPODOC") != val) + { + TAuto_variable_rectype::put_str(fieldname, val); + reset_fields(*this); + set_fields(*this); + } + else + { + TAuto_variable_rectype::put_str(fieldname, val); + dirty_fields(); + } +} + +void TDocumento::zero(const char * fieldname) +{ + if (strcmp(fieldname, "TIPODOC") == 0) + reset_fields(*this); + TAuto_variable_rectype::zero(fieldname); + dirty_fields(); +} + +void TDocumento::zero(char c) +{ + reset_fields(*this); + TAuto_variable_rectype::zero(c); +} + +TRectype & TDocumento::operator =(const TRectype & r) +{ + TRectype::operator=(r); + reset_fields(*this); + set_fields(*this); + return *this; +} + +TRectype & TDocumento::operator =(const char * r) +{ + TRectype::operator=(r); + reset_fields(*this); + set_fields(*this); + return *this; +} + /////////////////////////////////////////////////////////// // Lista di documenti /////////////////////////////////////////////////////////// diff --git a/ve/velib01.h b/ve/velib01.h index 36f48c943..e67ff9c02 100755 --- a/ve/velib01.h +++ b/ve/velib01.h @@ -5,14 +5,176 @@ #include #endif -real lordo2netto(real& lordo, const TString& codiva, bool is_valuta = FALSE); -real netto2lordo(const real& netto, const TString& codiva, bool is_valuta = FALSE); -real lordo2netto(real& lordo, const real& iva, bool is_valuta = FALSE); -real netto2lordo(const real& netto, const real& iva, bool is_valuta = FALSE); +#ifndef __VARREC_H +#include +#endif + +#ifndef __VARMASK_H +#include +#endif + +#ifndef __PAGAMENT_H +#include "../cg/pagament.h" +#endif + +class TDocumento; +class TRiga_documento; +class TCond_vendita; +class TIVA; + +real lordo2netto(real& lordo, const TString& codiva, int ndec); +inline real lordo2netto(real& lordo, const TString& codiva, bool is_valuta = FALSE) { return lordo2netto(lordo, codiva, is_valuta ? 3 : 0);} +real netto2lordo(const real& netto, const TString& codiva, int ndec); +inline real netto2lordo(const real& netto, const TString& codiva, bool is_valuta = FALSE) { return netto2lordo(netto, codiva, is_valuta ? 3 : 0);} +real lordo2netto(real& lordo, const real& iva, int ndec); +inline real lordo2netto(real& lordo, const real& iva, bool is_valuta = FALSE) {return lordo2netto(lordo, iva, is_valuta ? 3 : 0); } +real netto2lordo(const real& netto, const real& iva, int ndec); +inline real netto2lordo(const real& netto, const real& iva, bool is_valuta = FALSE) { return netto2lordo(netto, iva, is_valuta ? 3 : 0); } +real prezzo_scontato(const real& prezzo, const char * sconto); +real iva(real imponibile, const TIVA & codiva,int ndec); + +bool ora_hndl(TMask_field& field, KEY key); +bool codcli_hndl(TMask_field& field, KEY key); +bool dummy_hndl(TMask_field& field, KEY key); +bool condpag_hndl(TMask_field& field, KEY key); + +class TDocumento_variable_field : public TVariable_field +{ + bool _dirty; + + public: +// @cmember segnala che il campo deve essere ricalcolato + virtual bool dirty() const { return _dirty;} +// @cmember assegna lo stato di campo da ricalcolare + virtual void set_dirty(bool on = TRUE) { _dirty = on;} + +// @ cmember Costruttore con una espressione di calcolo + TDocumento_variable_field(const char * name, const char * expr = "", TTypeexp type = _strexpr) + : TVariable_field(name, expr, type), _dirty(TRUE) {} +// @ cmember Costruttore con una funzione + TDocumento_variable_field(const char * name, VIRTUAL_GET_FUNCTION getfunc) + : TVariable_field(name, getfunc), _dirty(TRUE) {} +// @ cmember Costruttore con una espressione di calcolo + TDocumento_variable_field(const char * name, TExpression * expr, TTypeexp type = _strexpr) + : TVariable_field(name, expr, type), _dirty(TRUE) {} +// @ cmember Costruttore con un variable_field + TDocumento_variable_field(const TVariable_field & f) : TVariable_field(f), _dirty(TRUE) {} +// @ cmember Distruttore + ~TDocumento_variable_field() {} +}; + +class TSpesa_prest : public TRectype +{ + +protected: + int read(const char* codice); + +public: + TObject* dup() const { return new TSpesa_prest(codice()); } + +public: + const TString& codice() const { return get("CODTAB");} + const TString& descrizione() const { return get("S0"); } + const TString& field_perc() const { return get("S5"); } + char tipo() const { return get_char("S6"); } + char genere() const { return get("COD") == "SPP" ? 'S' : 'P'; } + + TSpesa_prest(const char* codice = NULL, char tipo = 'S'); + TSpesa_prest(const TRectype& rec); + virtual ~TSpesa_prest() {} +}; + +class TIVA : public TRectype +{ + +protected: + int read(const char* codice); + +public: + TObject* dup() const { return new TIVA(codice()); } + +public: + const TString& codice() const { return get("CODTAB");} + const TString& descrizione() const { return get("S0"); } + const real aliquota() const { return get_real("R0"); } + const TString& tipo() const { return get("S1"); } + + TIVA(const char* codice = NULL); + TIVA(const TRectype& rec); + virtual ~TIVA() {} +}; + +class TExpr_documento : public TExpression +{ + TDocumento * _doc; + TRiga_documento * _row; + +protected: + virtual void evaluate_user_func(int index, int nparms, TEval_stack & stack, TTypeexp type) const; + virtual int parse_user_func(const char * name, int nparms) const; + +public: + // @cmember Duplica l'espressione + virtual TObject* dup() const; + // @cmember Assegna il documento corrente + void set_doc(TDocumento * doc) { _doc = doc; } + // @cmember Assegna il documento corrente + void set_row(TRiga_documento * row) { _row = row; } + // @cmember Costruttore (assegna l'estressione e il suo tipo) + TExpr_documento(const char* expression, TTypeexp type = _numexpr, + TDocumento * doc = NULL, TRiga_documento * row = NULL); + // @cmember Costruttore (assegna il tipo dell'istruzione) + TExpr_documento(TTypeexp type = _numexpr, + TDocumento * doc = NULL, TRiga_documento * row = NULL) + : TExpression(type), _doc(doc), _row(row) {} + // @cmember Costruttore di copia + TExpr_documento(const TExpr_documento & expr) + : TExpression(expr), _doc(expr._doc), _row(expr._row) {} + // @cmember Distruttore + virtual ~TExpr_documento() {} +}; + +enum TTipo_formula { _documento, _riga }; + +class TFormula_documento : public TRectype +{ + TString16 _tab; + TExpr_documento * _expr; + +protected: + int read(const char* codice); + +public: + TObject* dup() const { return new TFormula_documento(_tab == "%FRD" ? _documento : _riga, codice()); } + +public: + const TString& codice() const { return get("CODTAB");} + const TString& name() const { return codice();} + TExpr_documento * expr() const { return _expr ? new TExpr_documento(*_expr) : NULL;} + + const TString& descrizione() const { return get("S0"); } + const TString& expr_string() const { return get("S1"); } + TTypeexp expr_type() const { return get_bool("B0") ? _numexpr : _strexpr;} + + TFormula_documento(TTipo_formula tipo = _documento, const char* codice = NULL); + TFormula_documento(const TRectype& rec); + virtual ~TFormula_documento(); +}; + class TTipo_documento : public TRectype -{ -protected: +{ + + static TAssoc_array _formule_documento; + TToken_string _formule; + TString16 _imponibile; + TString16 _imposta; + TString16 _totale; + TString16 _basesconto; + TString16 _spese; + +protected: + void read_formule(); int read(const char* tipodoc); public: @@ -26,6 +188,15 @@ public: const TString& descrizione() const { return get("S0"); } const TString& riferimento() const { return get("S1"); } + const TString& imponibile() const { return _imponibile;} + const TString& imposta() const { return _imposta;} + const TString& totale_doc() const { return _totale;} + const TString& basesconto() const { return _basesconto;} + const TString& spese() const { return _spese;} + + TFormula_documento * first_formula() { return succ_formula(TRUE); } + TFormula_documento * succ_formula(bool restart = FALSE); + const int ncopie() const { return get_int("I0"); } TTipo_documento(const char* tipodoc = NULL); @@ -35,17 +206,35 @@ public: class TTipo_riga_documento : public TRectype { + + static TAssoc_array _formule_riga; + TToken_string _formule; + TString16 _name; + TString16 _imponibile; + TString16 _imposta; + TVariable_mask * _mask; + protected: + void read_formule(); int read(const char* tiporig); public: TObject* dup() const { return new TTipo_riga_documento(codice()); } public: + const TString& profile_name() const { return _name;} + const TString& mask_name() const { return profile_name();} const TString& codice() const { return get("CODTAB");} - + bool mask_loaded() const { return _mask != NULL; } + TVariable_mask * mask(); + const TString& descrizione() const { return get("S0"); } char tipo() const { return get_char("S7"); } + const TString& imponibile() const { return _imponibile;} + const TString& imposta() const { return _imposta;} + + TFormula_documento * first_formula() { return succ_formula(TRUE); } + TFormula_documento * succ_formula(bool restart = FALSE); TTipo_riga_documento(const char* tiporig = NULL); TTipo_riga_documento(const TRectype& rec); @@ -53,60 +242,107 @@ public: }; -class TRiga_documento : public TRectype +class TRiga_documento : public TAuto_variable_rectype { - friend class TDocumento; - const TDocumento* _doc; - + TDocumento * _doc; static TAssoc_array _tipi; + static TAssoc_array _spese; + static TAssoc_array _ive; + protected: - void set_doc(const TDocumento* doc) { _doc = doc; } + // @cmember Setta il contenuto del campo

(non tipizzata) + virtual void put_str(const char* fieldname, const char* val); protected: TObject* dup() const { return new TRiga_documento(*this); } public: - const TDocumento& documento() const - { CHECK(_doc, "Riga documento orfana"); return *_doc; } + void dirty_fields(bool dirty_document = TRUE); + bool doc_dependent() const; + int numero() const { return get_int("NRIGA");} + void set_numero(int numero) { put("NRIGA", numero);} + // @cmember Assegna il documento corrente + void set_doc(TDocumento * doc) { _doc = doc; } + const TDocumento & doc() const { CHECK(_doc, "Documento nullo"); return *_doc;} + + virtual void zero(const char * fieldname); + virtual void zero(char c = '\0'); + // row -> sheet + void autoload( TSheet_field& f); + // sheet -> row + void autosave( TSheet_field& f); + + const TTipo_riga_documento & tipo() const; + const TSpesa_prest & spesa() const; + static const TIVA & iva(const char * codice); + const TIVA & iva() const {const TString16 cod(get("CODIVA")); return iva(cod);} - const TTipo_riga_documento& tipo() const; + void set_tipo(const char * tipo) { put("TIPORIGA", tipo);} bool sola_descrizione() const; void forza_sola_descrizione(); - TRiga_documento& operator =(const TRiga_documento& r) - { TRectype::operator=(r); _doc = r._doc; return *this; } + virtual TRectype & operator =(const TRectype & r); + virtual TRectype & operator =(const char * r); bool raggruppabile(const TRiga_documento& r, TToken_string& campi) const; TRiga_documento& operator +=(const TRiga_documento& r); - TRiga_documento(const TDocumento* doc) : TRectype(LF_RIGHEDOC), _doc(doc) { } - TRiga_documento(const TRiga_documento& rec) : TRectype(rec), _doc(rec._doc) { } - virtual ~TRiga_documento() { } + void reset_fields(TAuto_variable_rectype & rec) { rec.remove_field(); } + void set_fields(TAuto_variable_rectype & rec); + + real prezzo(bool scontato, bool lordo, int ndec) const ; + real importo(bool scontato, bool lordo, int ndec, bool iva_calc = FALSE) const ; +// real iva(int ndec) const {return ::iva(importo(TRUE, FALSE, ndec, TRUE), iva(), ndec);} + real iva(int ndec) const {return ::iva(imponibile(), iva(), ndec);} + real imponibile() const; + real imposta() const; + + TRiga_documento(TDocumento* doc, const char * tipo = NULL); + TRiga_documento(const TRiga_documento& rec, TDocumento* doc, + const char * tipo = NULL); + virtual ~TRiga_documento() {} }; -class TDocumento : public TRectype +class TDocumento : public TAuto_variable_rectype { static TAssoc_array _tipi; TRecord_array _rows; // Array di TRectype per le righe documenti di vendita. bool _nuovo; + TRelation * _rel; + TCond_vendita * _condv; + TPagamento _pag; + protected: - TRectype & row(int index) { return _rows.row(index, FALSE); } + TAuto_variable_rectype & row(int index) { return (TAuto_variable_rectype &) _rows.row(index, FALSE); } long get_next_key(char provv, int anno, const char* codnum) const; + virtual void put_str(const char* fieldname, const char* val); long renum(long numdoc = 0); public: - const TRectype& head() const { return *this; } // Ritorna la testata del documento - TRectype& head() { return *this; } // Ritorna la testata del documento - + void dirty_fields(); + const TAuto_variable_rectype& head() const { return *this; } // Ritorna la testata del documento + TAuto_variable_rectype& head() { return *this; } // Ritorna la testata del documento + + TCond_vendita & condv() const {CHECK(_condv, "Condizioni di vendita nulle"); return *_condv;} + TRelation & get_relation() const {CHECK(_rel, "Relazione nulla"); return *_rel;} + void set_condv(TCond_vendita * condv) { _condv = condv; } + void set_relation(TRelation * rel) { _rel = rel; } + + virtual TRectype & operator =(const TRectype & r); + virtual TRectype & operator =(const char * r); + virtual void zero(const char * fieldname); + virtual void zero(char c = '\0'); + int rows() const { return _rows.rows(); } const TRiga_documento& operator[](int index) const { return (const TRiga_documento&)_rows.row(index); } TRiga_documento& operator[](int index) { return (TRiga_documento&)_rows.row(index, FALSE); } - TRiga_documento& new_row() { return (TRiga_documento&)_rows.row(-1, TRUE); } - bool destroy_row(int n) { return _rows.destroy_row(n); } + TRiga_documento& insert_row(int row, const char *tipo = NULL); + TRiga_documento& new_row(const char *tipo = NULL); + bool destroy_row(int n, bool pack = FALSE) { return _rows.destroy_row(n, pack); } void destroy_rows() { _rows.destroy_rows(); } int read(char provv, int anno, const char* codnum, long numdoc); @@ -121,10 +357,11 @@ public: const TString& numerazione() { return get("CODNUM"); } long numero() const { return get_long("NDOC"); } TDate data() const { return get_date("DATADOC"); } - const bool in_valuta(); - const TString& valuta() { return get("CODVAL"); } + const bool in_valuta() const; + const TString& valuta() const { return get("CODVAL"); } const real cambio() { return get_real("CAMBIO"); } const TTipo_documento& tipo() const; + void set_tipo(const char * tipo) { head().put("TIPODOC", tipo);} char stato() const { return get_char("STATO"); } void stato(char s) { put("STATO", s); } @@ -134,13 +371,50 @@ public: static void set_key(TRectype& rec, char provv, int anno, const char* codnum, long numdoc); static void copy_data(TRectype& dst, const TRectype& src); + + void reset_fields(TAuto_variable_rectype & rec) { rec.remove_field(); } + void set_fields(TAuto_variable_rectype & rec); + + + real spese_incasso(real & imp, int ndec, bool netto = FALSE) const ; + real bolli(real & imp, int ndec, bool netto = FALSE) const ; + real descrizione() const; + real riferimento() const; + real imponibile() const; + real imposta() const; + real totale_doc() const; + real basesconto() const; + real spese() const; + + TPagamento & pagamento(); TDocumento (); - TDocumento(char provv, int anno, const char* codnum, long numdoc); - TDocumento(const TRectype& doc); + TDocumento(char provv, int anno, const char* codnum, long numdoc, + TCond_vendita * condv = NULL, TRelation * rel = NULL); + TDocumento(const TRectype& doc, TCond_vendita * condv = NULL, + TRelation * rel = NULL); virtual ~TDocumento() { } }; +class TDocumento_mask : public TVariable_mask +{ + int _progs_page; // pagina in cui cominciano i progressivi + int _last_prog; // numero dell'ultimo progressivo + TDocumento * _doc; // documento + +protected: + virtual void next_page(int p); + +public: + virtual bool on_key(KEY key); + TDocumento & doc() const {CHECK(_doc, "Documento nullo"); return *_doc;} + TCond_vendita & condv() const {CHECK(_doc, "Documento nullo"); return _doc->condv();} + TRelation & get_relation() const {CHECK(_doc, "Documento nullo"); return _doc->get_relation();} + + TDocumento_mask(const char* name, TDocumento * _doc, int num = 0, int max = MAX_PAGES); + virtual ~TDocumento_mask() { } +}; + class TLista_documenti : public TObject { TArray _documenti; diff --git a/ve/velib02.cpp b/ve/velib02.cpp index a083636be..cdb1a1ca3 100755 --- a/ve/velib02.cpp +++ b/ve/velib02.cpp @@ -77,12 +77,7 @@ void TDocumentoEsteso::compile_summary() if (_iva->read() != NOERR) continue; // Se non trova il codice salta questa riga aliquota = _iva->get_real("R0"); - if (_condv != NULL && sconto.not_empty()) // Se c'e' la condizione di vendita, calcola lo sconto... - { - _condv->set_sconto(sconto); - sc = 100.0 - _condv->sconto_val(); - price = (price * sc); - } + price = scontato(price, sconto); price.round(val ? _parm.pri_val : _parm.pri_lit); // prezzo scontato qta.round(val ? _parm.qta_val : _parm.qta_lit); imponibile = price * qta; @@ -299,30 +294,10 @@ const char* TDocumentoEsteso::get_head_info(const TString & what) return (const char*) rt; } -void TDocumentoEsteso::set_condv(TCliFor* cli) -{ - if (_condv != NULL) - delete _condv; - if (cli != NULL) - _condv = new TCond_vendita(*cli); -} - TDocumentoEsteso::TDocumentoEsteso(const TRectype& rec, TCliFor *cli) - : TDocumento(rec), _condv(NULL), _sum_filter(-1), _sum_selected(FALSE), _scadenze_current(-1) + : TDocumento(rec), _sum_filter(-1), _sum_selected(FALSE), _scadenze_current(-1) { _iva = new TTable("%IVA"); - if (cli != NULL) _condv = new TCond_vendita(*cli); - else - { - TCliFor cf; - TString16 tipocf,ocfpi; - long codcf; - tipocf = get("TIPOCF"); - codcf = get_long("CODCF"); - ocfpi = get("OCFPI"); - cf.load(tipocf[0],codcf,ocfpi); - _condv = new TCond_vendita(cf); - } // Inizializza i parametri di default _parm.pri_lit = 0; _parm.pri_val = 3; _parm.qta_lit = 3; _parm.qta_val = 3; @@ -330,26 +305,14 @@ TDocumentoEsteso::TDocumentoEsteso(const TRectype& rec, TCliFor *cli) } TDocumentoEsteso::TDocumentoEsteso(const TRectype& rec, dec_parm & parm, TCliFor *cli) - : TDocumento(rec), _condv(NULL), _sum_filter(-1), _sum_selected(FALSE), _scadenze_current(-1) + : TDocumento(rec), _sum_filter(-1), _sum_selected(FALSE), _scadenze_current(-1) { _parm = parm; _iva = new TTable("%IVA"); - if (cli != NULL) _condv = new TCond_vendita(*cli); - else - { - TCliFor cf; - TString16 tipocf,ocfpi; - long codcf; - tipocf = get("TIPOCF"); - codcf = get_long("CODCF"); - ocfpi = get("OCFPI"); - cf.load(tipocf[0],codcf,ocfpi); - _condv = new TCond_vendita(cf); - } } TDocumentoEsteso::TDocumentoEsteso() - : TDocumento(), _condv(NULL), _sum_filter(-1), _sum_selected(FALSE), _scadenze_current(-1) + : TDocumento(), _sum_filter(-1), _sum_selected(FALSE), _scadenze_current(-1) { _iva = new TTable("%IVA"); } @@ -357,7 +320,6 @@ TDocumentoEsteso::TDocumentoEsteso() TDocumentoEsteso::~TDocumentoEsteso() { if (_iva != NULL) delete _iva; - if (_condv != NULL) delete _condv; } diff --git a/ve/velib02.h b/ve/velib02.h index 4a59f50b9..42a1da67e 100755 --- a/ve/velib02.h +++ b/ve/velib02.h @@ -78,7 +78,6 @@ class TDocumentoEsteso : public TDocumento // Parametri del documento dec_parm _parm; // Parametri per gli arrotondamenti TTable * _iva; // Tabella codici IVA - TCond_vendita * _condv; // Condizioni di vendita per lo sconto // Totali del documento ricalcolati non appena la tabellina di riepilogo IVA e' completa real _importi_netti, _imposte;