1995-08-07 08:41:34 +00:00
# include <applicat.h>
# include <config.h>
# include <form.h>
# include <mask.h>
# include <relation.h>
# include <expr.h>
# include <tabutil.h>
1996-08-13 15:35:33 +00:00
# include <printer.h>
1995-08-07 08:41:34 +00:00
# include <utility.h>
1996-08-13 15:35:33 +00:00
# include <urldefid.h>
1996-09-04 07:30:33 +00:00
# include <progind.h>
1995-12-04 17:35:52 +00:00
1997-01-02 09:01:59 +00:00
# include <doc.h>
# include <rdoc.h>
1995-08-07 08:41:34 +00:00
1997-06-09 13:10:38 +00:00
# include "velib.h"
1997-06-10 16:25:07 +00:00
# include "sconti.h"
1997-08-02 08:47:57 +00:00
# include "ve1100.h"
# include "ve0100b.h"
1996-10-12 11:53:11 +00:00
1997-03-10 14:51:08 +00:00
# define LISTADOC "listadoc"
# define Usage "Usage: ve1 -0 {[codnum anno {D|P} dalnum alnum {D|P} [ncopie]] | [L]}"
1996-10-12 11:53:11 +00:00
1997-01-02 09:01:59 +00:00
// Queste classi (TDocisamfile e TRDocisamfile) servono nel costruttore di TDocumento_form
// in modo da sostituire i file della relazione, ovvero LF_DOC e LF_RIGHEDOC.
// Facendo in questo modo ogni get() del record, viene reindirizzata alla get() dei
// TVariable_recfield, in modo da utilizzare nel form le istruzioni FIELD anche per i campi
// virtuali.
1996-10-12 11:53:11 +00:00
1997-01-02 09:01:59 +00:00
class TDocisamfile : public TLocalisamfile
{
1997-03-10 14:51:08 +00:00
TDocumentoEsteso * _doc ;
1996-10-12 11:53:11 +00:00
public :
1997-01-02 09:01:59 +00:00
virtual TRectype & curr ( ) const { return ( TRectype & ) * _doc ; }
1997-03-10 14:51:08 +00:00
virtual int readat ( TRecnotype nrec , word lockop = _nolock ) ;
TDocisamfile ( TDocumentoEsteso * doc ) : TLocalisamfile ( LF_DOC ) { _doc = doc ; }
1997-01-02 09:01:59 +00:00
virtual ~ TDocisamfile ( ) { } ;
1996-10-12 11:53:11 +00:00
} ;
1997-03-10 14:51:08 +00:00
int TDocisamfile : : readat ( TRecnotype nrec , word lockop )
{
int err = TBaseisamfile : : readat ( nrec , _nolock ) ;
if ( err = = NOERR )
if ( ( err = _doc - > read ( curr ( ) ) ) = = NOERR )
{
1997-03-15 11:05:12 +00:00
_doc - > summary_reset ( TRUE ) ; // forza il ricalcolo perche' trattasi di documento diverso
1997-03-10 14:51:08 +00:00
_doc - > summary_filter ( 1 ) ;
}
return err ;
1997-08-27 13:28:15 +00:00
}
1997-01-02 09:01:59 +00:00
class TRDocisamfile : public TLocalisamfile
{
TDocumento * _doc ;
int _row ;
protected :
TDocumento & doc ( ) const { return * _doc ; }
public :
virtual TRectype & curr ( ) const { return ( TRectype & ) doc ( ) [ _row > 0 ? _row : 1 ] ; }
void set_row ( int r ) { _row = r ; }
TRDocisamfile ( TDocumento * doc ) : TLocalisamfile ( LF_RIGHEDOC ) { _doc = doc ; _row = 1 ; }
virtual ~ TRDocisamfile ( ) { } ;
} ;
1996-10-12 11:53:11 +00:00
1995-08-07 08:41:34 +00:00
////////////////////////////////////////////////////////////////////////////
1997-01-02 09:01:59 +00:00
// classe TDocumento_form customizzata dalla Form per i documenti
1995-08-07 08:41:34 +00:00
////////////////////////////////////////////////////////////////////////////
1997-01-02 09:01:59 +00:00
class TDocumento_form : public TForm
{
static TDocumento_form * _form ;
TDocisamfile * _docfile ;
TRDocisamfile * _rdocfile ;
TLocalisamfile * _tab ;
TTable * _tip ;
1995-08-07 08:41:34 +00:00
TRelation & _firmrel ; // relazione di gestione dei dati della ditta corrente
1996-03-20 16:15:18 +00:00
TString _module ; // codice del modulo di carta associato a questo al form
1997-06-12 16:26:22 +00:00
TCond_vendita * _condv ;
1997-08-27 13:28:15 +00:00
TString_array _exclude_array_t ; // array di tipi riga da escludere dalla stampa
TString_array _exclude_array_a ; // array di articoli da escludere dalla stampa
1997-01-02 09:01:59 +00:00
TDocumentoEsteso * _doc ; // Documento da stampare
bool _valid , _cli_loaded ; // flag che indica se il form e' valido | se l'oggetto cliente <20> gi<67> stato caricato
1997-03-10 14:51:08 +00:00
bool _is_lista ; // flag che indica se il form e' usato per la stampa della lista documenti
1996-08-13 15:35:33 +00:00
TString_array _group_decimals ; // Array di TToken_string per ogni gruppo definito in GENERAL.
// Il primo elelemento della token_string conterra' il numero del gruppo
// il secondo il n.ro di decimali per importi in lire ed il terzo il n.ro
// di decimali per gli importi in valuta
// I gruppi sono cosi' predefiniti:
// PRI_DECIMALS corrisponde al gruppo 29
// QTA_DECIMALS corrisponde al gruppo 30
// IMP_DECIMALS corrisponde al gruppo 31
// Altri gruppi definiti dall'utente saranno cosi' sintatticamente impostati:
// NEW_GROUP <n> <lit_dec> <val_dec>
// Dove <n> e' il numero del gruppo
// <lit_dec> e' il numero di decimali per i documenti in lire
// <val_dec> e' il numero di decimali per i documenti in valuta
// ATTENZIONE: e' importante che i nomi dei gruppi utilizzati per modificare le pictures non siano usati per
// per altri messaggi. Inoltre un TForm_item che appartiene ad un gruppo di modifica picture
// non puo' appartenere ad un altro gruppo dello stesso tipo, ad esempio i gruppi 29 e 30 contemporaneamente.
// Puo' pero' appartenere anche ad altri gruppi che non siano utilizzati per lo scopo qui definito
1995-08-07 08:41:34 +00:00
protected :
1996-03-20 16:15:18 +00:00
virtual void extended_parse_general ( TScanner & ) ; // gestione dei parametri estesi nella sezione general
1995-10-09 15:47:28 +00:00
virtual bool validate ( TForm_item & , TToken_string & ) ; // gestione dei messaggi estesi nei campi
1996-08-13 15:35:33 +00:00
void edit_picture ( TForm_item & f , const int dec ) ;
void modify_pictures ( ) ;
1997-01-02 09:01:59 +00:00
bool print_on_body ( int r ) ; // Trascrive la riga 'r' del documento sul body. Ritorna TRUE se va stampata, FALSE se va saltata
void print_header ( TPrinter & p ) ; // Stampa la testata
void print_footer ( TPrinter & p ) ; // Stampa la pedata
static void doc_header_handler ( TPrinter & p ) ;
static void doc_footer_handler ( TPrinter & p ) ;
1995-08-07 08:41:34 +00:00
public :
1997-01-02 09:01:59 +00:00
void print_documento ( ) ;
bool valid ( ) { return _valid ; }
bool doc_arrange ( ) ;
int ncopie ( ) { return _doc - > tipo ( ) . ncopie ( ) ; }
1996-03-20 16:15:18 +00:00
const TString & get_module_code ( ) { return _module ; } // ritorna il codice del modulo di carta
1997-08-27 13:28:15 +00:00
TString_array & exclude_list_t ( ) { return _exclude_array_t ; }
TString_array & exclude_list_a ( ) { return _exclude_array_a ; }
1997-01-02 09:01:59 +00:00
TDocumentoEsteso & doc ( ) { return * _doc ; }
1997-01-11 10:41:52 +00:00
TDocumento_form ( TRectype & /*TDocumentoEsteso **/ doc , TRelation & rel , const bool definitiva , const bool interattivo ) ;
1997-03-10 14:51:08 +00:00
TDocumento_form ( const char * form , TRelation & rel ) ;
1997-01-02 09:01:59 +00:00
virtual ~ TDocumento_form ( ) ;
1995-08-07 08:41:34 +00:00
} ;
1997-01-02 09:01:59 +00:00
TDocumento_form * TDocumento_form : : _form = NULL ;
1995-08-07 08:41:34 +00:00
1997-01-11 10:41:52 +00:00
TDocumento_form : : TDocumento_form ( TRectype & /*TDocumentoEsteso**/ doc , TRelation & rel , const bool definitiva , const bool interattivo ) : TForm ( ) , _firmrel ( rel ) , _valid ( FALSE )
1997-01-02 09:01:59 +00:00
{
_form = this ;
1997-01-11 10:41:52 +00:00
//_doc = doc;
1997-01-02 09:01:59 +00:00
_tip = new TTable ( " %TIP " ) ;
_tab = new TLocalisamfile ( LF_TAB ) ;
TString nomeform ;
1997-08-27 13:28:15 +00:00
// TFilename profilo;
1997-01-11 10:41:52 +00:00
TString codnum ( doc . get ( DOC_CODNUM ) ) ;
TString numdoc ( doc . get ( DOC_NDOC ) ) ;
1997-08-27 13:28:15 +00:00
// modificare ??
1997-01-11 10:41:52 +00:00
_tip - > put ( " CODTAB " , doc . get ( DOC_TIPODOC ) ) ; // posiziona la tabella dei tipi di documento
1997-01-02 09:01:59 +00:00
int err = _tip - > read ( ) ; // legge la tabella
if ( err = = NOERR )
{ // se non ci sono errori procede con la stampa
nomeform = _tip - > get ( " S5 " ) ; // legge il nome del form di stampa
1997-08-27 13:28:15 +00:00
TFilename test ( nomeform ) ; test . ext ( " frm " ) ;
// profilo= _tip->get("S4"); // legge il nome del profilo di configurazione
// profilo.ext("ini"); // aggiunge l'estensione al nome del file del profilo
if ( /* profilo.empty() || */ fexist ( nomeform ) )
1997-01-02 09:01:59 +00:00
{
1997-08-27 13:28:15 +00:00
error_box ( " Nome form di stampa (%s) non valido per il tipo documento %s " , ( const char * ) nomeform , ( const char * ) ( ( TDocumento & ) doc ) . tipo ( ) . codice ( ) ) ;
1997-01-02 09:01:59 +00:00
return ;
}
}
else
{
error_box ( " Il documento %s %s non <20> stato trovato nella tabella dei tipi di documento (errore %d) " ,
( const char * ) codnum , ( const char * ) numdoc , err ) ;
return ;
}
_valid = TRUE ;
1995-08-07 08:41:34 +00:00
1997-01-02 09:01:59 +00:00
read ( nomeform ) ;
1996-06-27 09:37:32 +00:00
_cli_loaded = FALSE ;
1997-03-10 14:51:08 +00:00
_is_lista = FALSE ;
1997-06-12 16:26:22 +00:00
_condv = new TCond_vendita ( NULL ) ;
_doc = new TDocumentoEsteso ( doc , _condv ) ; // istanzia TDocumentoEsteso
_condv - > set_clifo ( & _doc - > clifor ( ) ) ;
1997-01-02 09:01:59 +00:00
_docfile = new TDocisamfile ( _doc ) ;
_rdocfile = new TRDocisamfile ( _doc ) ;
relation ( ) - > replace ( _docfile , 0 ) ;
relation ( ) - > replace ( _rdocfile , 1 ) ;
1997-07-02 17:34:51 +00:00
relation ( ) - > update ( ) ;
1996-08-13 15:35:33 +00:00
modify_pictures ( ) ;
dec_parm p ;
const int items = _group_decimals . items ( ) ;
for ( int i = 0 ; i < items ; i + + )
{
TToken_string & t = _group_decimals . row ( i ) ;
int gruppo = t . get_int ( 0 ) ;
switch ( gruppo )
{
case 29 : p . pri_lit = t . get_int ( 1 ) ; p . pri_val = t . get_int ( 2 ) ;
break ;
case 30 : p . qta_lit = t . get_int ( 1 ) ; p . qta_val = t . get_int ( 2 ) ;
break ;
case 31 : p . imp_lit = t . get_int ( 1 ) ; p . imp_val = t . get_int ( 2 ) ;
break ;
// add other groups here
default :
break ;
}
}
_doc - > set_decimals ( p ) ;
1997-01-02 09:01:59 +00:00
TPrinter & pr = printer ( ) ;
pr . setheaderhandler ( doc_header_handler ) ;
TPrint_section & head = section ( ' H ' ) ;
pr . headerlen ( head . height ( ) ) ;
pr . setfooterhandler ( doc_footer_handler ) ;
const TPrint_section & foot = section ( ' F ' ) ;
pr . footerlen ( foot . height ( ) ) ;
1995-12-04 17:35:52 +00:00
}
1997-03-10 14:51:08 +00:00
// costruttore per stampa lista documenti (uso convenzionale dei forms)
TDocumento_form : : TDocumento_form ( const char * form , TRelation & rel ) : TForm ( form ) , _firmrel ( rel ) , _valid ( FALSE )
{
_is_lista = TRUE ;
_rdocfile = NULL ;
_tip = new TTable ( " %TIP " ) ;
_tab = new TLocalisamfile ( LF_TAB ) ;
_cli_loaded = FALSE ;
_doc = new TDocumentoEsteso ;
_docfile = new TDocisamfile ( _doc ) ;
relation ( ) - > replace ( _docfile , 0 ) ;
}
1997-01-02 09:01:59 +00:00
TDocumento_form : : ~ TDocumento_form ( )
{
1997-01-11 10:41:52 +00:00
//if (_doc) delete _doc;
1997-01-02 09:01:59 +00:00
if ( _tip ) delete _tip ;
if ( _tab ) delete _tab ;
if ( _docfile ) delete _docfile ;
if ( _rdocfile ) delete _rdocfile ;
}
bool TDocumento_form : : doc_arrange ( )
{
TPrinter & pr = printer ( ) ;
if ( char_to_pos ( ) ! = ' \0 ' | | ( ipx ( ) + ipy ( ) + fpx ( ) ) ! = 0 )
{
if ( offset_x ( ) ! = 0 | | offset_y ( ) ! = 0 )
{
error_box ( " Non e' possibile settare contemporaneamente gli offset "
" e i parametri di posizionamento del modulo %s. " , ( const char * ) name ( ) ) ;
return FALSE ;
}
else
if ( pr . printtype ( ) = = winprinter )
_form - > arrange_form ( ) ;
}
else
pr . set_offset ( _form - > offset_x ( ) , _form - > offset_y ( ) ) ;
return TRUE ;
1995-12-04 17:35:52 +00:00
}
1997-01-02 09:01:59 +00:00
void TDocumento_form : : print_documento ( )
{
// stampa tutte le righe
TPrint_section & body = section ( ' B ' ) ;
TPrint_section & foot = section ( ' F ' ) ;
TPrinter & pr = printer ( ) ;
1997-01-11 10:41:52 +00:00
1997-01-02 09:01:59 +00:00
const int righe = _doc - > rows ( ) ;
set_last_page ( FALSE ) ; // E' importante settare questo flag, per evitare "Falli di Piede" eheh :-)
for ( int r = 1 ; r < = righe ; r + + )
{
_rdocfile - > set_row ( r ) ;
if ( pr . rows_left ( ) < = ( body . height ( ) + 1 ) ) // salto pagina
pr . formfeed ( ) ;
if ( ! print_on_body ( r ) ) continue ;
const word h = body . height ( ) ;
for ( word j = 0 ; j < h ; j + + )
pr . print ( body . row ( j ) ) ;
}
set_last_page ( TRUE ) ; // Cosi' stampera' l'ultima pagina del footer
pr . formfeed ( ) ;
// Rimette ad 1 il numero della pagina
pr . setcurrentpage ( 1 ) ;
}
void TDocumento_form : : print_header ( TPrinter & pr )
{
TPrint_section & head = section ( ' H ' ) ;
1997-01-11 10:41:52 +00:00
1997-01-02 09:01:59 +00:00
head . update ( ) ;
const word r = head . height ( ) - 1 ;
for ( word j = 0 ; j < = r ; j + + )
pr . setheaderline ( j , head . row ( j ) ) ;
}
void TDocumento_form : : print_footer ( TPrinter & pr )
{
const bool p = _form - > page ( pr ) > 0 ;
TPrint_section & foot = section ( ' F ' , p ? odd_page : last_page ) ;
foot . update ( ) ;
const word r = foot . height ( ) - 1 ;
for ( word j = 0 ; j < = r ; j + + )
pr . setfooterline ( j , foot . row ( j ) ) ;
}
void TDocumento_form : : doc_header_handler ( TPrinter & pr )
{
pr . resetheader ( ) ;
_form - > print_header ( pr ) ;
}
void TDocumento_form : : doc_footer_handler ( TPrinter & pr )
{
pr . resetfooter ( ) ;
_form - > print_footer ( pr ) ;
}
void TDocumento_form : : edit_picture ( TForm_item & fi , const int dec )
1996-08-13 15:35:33 +00:00
{
TString old_picture ( 20 ) ;
old_picture = fi . picture ( ) ;
TString new_picture ( 20 ) ;
1996-08-05 13:45:27 +00:00
1996-08-13 15:35:33 +00:00
if ( old_picture . empty ( ) ) // picture di default
{
new_picture = " . " ; // in lire
if ( dec ! = 0 ) new_picture < < dec ; // in valuta
}
else
{
if ( dec = = 0 ) return ; // 0 non cambia la picture
TString16 dec_to_add ;
for ( int i = 0 ; i < dec ; i + + ) dec_to_add < < " @ " ; // aggiunge tanti "@" quanti sono i decimali voluti
new_picture = old_picture ;
if ( old_picture . find ( ' , ' ) > 0 )
new_picture < < " . " ; // se ha trovato la virgola come separatore di migliaia significa che deve aggiungere il punto decimale
else
new_picture < < " , " ; // altrimenti aggiunge la solita virgola
new_picture < < dec_to_add ; // infine aggiunge i decimali richiesti
}
const int w = fi . width ( ) ; // se la picture eccede la dimensione, toglie i caratteri piu' a sx
int exceed = w - new_picture . len ( ) ;
if ( exceed < 0 & & w > 0 )
{
exceed = : : abs ( exceed ) ;
new_picture = new_picture . mid ( exceed , new_picture . len ( ) - exceed ) ;
}
fi . set_picture ( new_picture ) ; // setta la nuova picture
}
1997-01-02 09:01:59 +00:00
void TDocumento_form : : modify_pictures ( )
1996-08-13 15:35:33 +00:00
{
const bool valuta = _doc - > in_valuta ( ) ;
const char sechar [ 4 ] = { ' B ' , ' F ' , ' G ' , ' H ' } ;
for ( int sn = 0 ; sn < 4 ; sn + + )
{
const char sc = sechar [ sn ] ;
for ( pagetype pt = odd_page ; pt < = last_page ; pt = pagetype ( pt + 1 ) )
{
TPrint_section * sec = exist ( sc , pt ) ;
if ( sec ! = NULL )
for ( word i = 0 ; i < sec - > fields ( ) ; i + + )
{
TForm_item & fi = sec - > field ( i ) ;
const int items = _group_decimals . items ( ) ; // numero di gruppi definiti
for ( int j = 0 ; j < items ; j + + )
{
TToken_string & r = _group_decimals . row ( j ) ;
const int group = r . get_int ( 0 ) ;
if ( fi . in_group ( group ) ) // trova se appartiene al gruppo, modifica la picture
{
edit_picture ( fi , valuta ? r . get_int ( 2 ) : r . get_int ( 1 ) ) ;
break ; // considera solo il primo gruppo trovato
}
}
}
}
1996-03-20 16:15:18 +00:00
}
1996-08-13 15:35:33 +00:00
}
1997-01-02 09:01:59 +00:00
bool TDocumento_form : : print_on_body ( int r )
{
TPrint_section & body = section ( ' B ' ) ;
1997-01-11 10:41:52 +00:00
TRiga_documento & riga = doc ( ) [ r ] ;
1997-08-27 13:28:15 +00:00
const TString & tiporiga = riga . get ( RDOC_TIPORIGA ) ;
bool ok = _exclude_array_t . find ( tiporiga ) < 0 ;
1997-01-02 09:01:59 +00:00
1997-08-27 13:28:15 +00:00
if ( ok )
1997-01-02 09:01:59 +00:00
{
1997-08-27 13:28:15 +00:00
const TString & codart = riga . get ( RDOC_CODART ) ;
ok = _exclude_array_a . find ( codart ) < 0 ;
}
1997-01-02 09:01:59 +00:00
if ( ok )
body . update ( ) ; // Crea la vera riga di stampa, eventuali allineamenti avverranno nella validate(), come al solito.
return ok ;
1995-12-04 17:35:52 +00:00
}
1995-08-07 08:41:34 +00:00
1997-01-02 09:01:59 +00:00
void TDocumento_form : : extended_parse_general ( TScanner & scanner )
{
1996-08-13 15:35:33 +00:00
// se viene riconosciuto il token per l'impostazione del modulo legge il codice...
if ( scanner . key ( ) = = " MO " ) _module = scanner . string ( ) ;
1996-08-05 13:45:27 +00:00
// Legge i decimali necessari per gli arrotondamenti (il primo per gli importi in lire, l'altro per quelli in valuta)
1997-01-02 09:01:59 +00:00
if ( scanner . key ( ) = = " PR " )
{
1996-08-13 15:35:33 +00:00
TToken_string t ;
t . add ( 29 ) ; t . add ( scanner . integer ( ) ) ; t . add ( scanner . integer ( ) ) ;
_group_decimals . add ( t ) ;
}
1996-08-05 13:45:27 +00:00
// Stessa cosa per le quantita'
1996-08-13 15:35:33 +00:00
if ( scanner . key ( ) = = " QT " )
{
TToken_string t ;
t . add ( 30 ) ; t . add ( scanner . integer ( ) ) ; t . add ( scanner . integer ( ) ) ;
_group_decimals . add ( t ) ;
}
1996-08-05 13:45:27 +00:00
// Stessa cosa per gli importi in genere
1997-01-02 09:01:59 +00:00
if ( scanner . key ( ) = = " IM " )
{
1996-08-13 15:35:33 +00:00
TToken_string t ;
t . add ( 31 ) ; t . add ( scanner . integer ( ) ) ; t . add ( scanner . integer ( ) ) ;
_group_decimals . add ( t ) ;
}
1997-01-02 09:01:59 +00:00
if ( scanner . key ( ) = = " NE " )
{
1996-08-13 15:35:33 +00:00
TToken_string t ;
t . add ( scanner . integer ( ) ) ; t . add ( scanner . integer ( ) ) ; t . add ( scanner . integer ( ) ) ;
_group_decimals . add ( t ) ;
}
// Esclude certi tipi riga e codici articolo
1997-01-02 09:01:59 +00:00
if ( scanner . key ( ) = = " EX " )
{
1996-08-13 15:35:33 +00:00
TToken_string s ( scanner . string ( ) , ' , ' ) ;
1997-08-27 13:28:15 +00:00
const char * i = s . get ( ) ;
if ( i )
{
if ( * i )
_exclude_array_t . add ( i ) ;
i = s . get ( ) ;
if ( i & & * i )
_exclude_array_a . add ( i ) ;
}
1996-08-13 15:35:33 +00:00
}
1995-10-09 15:47:28 +00:00
}
1997-08-29 16:42:42 +00:00
bool TDocumento_form : : validate ( TForm_item & cf , TToken_string & s )
{
1995-10-02 10:49:35 +00:00
const TString code ( s . get ( 0 ) ) ; // prende il primo parametro, il codice del messaggio
1996-08-05 13:45:27 +00:00
TString valore ;
1995-08-07 08:41:34 +00:00
1997-08-29 16:42:42 +00:00
if ( code = = " _DITTA " )
{
1995-08-07 08:41:34 +00:00
// lettura dei dati della ditta
1995-10-09 15:47:28 +00:00
// sintassi: _DITTA,{<campo relazione>|<macro>}
1995-08-07 08:41:34 +00:00
// dove: <campo relazione> <20> un riferimento alla relazione di gestione dei dati della ditta (es. 113@->DENCOM <20> la denominazione del comune di residenza della ditta)
1995-09-28 15:26:35 +00:00
// <macro> <20> uno delle macro seguenti:
1995-10-09 15:47:28 +00:00
// !RAGSOC ragione sociale
// !IND indirizzo (fiscale se c'<27> , oppure di residenza)
// !NUM numero civico (fiscale se c'<27> , oppure di residenza)
// !CAP CAP (fiscale se c'<27> , oppure di residenza)
// !COM comune (fiscale se c'<27> , oppure di residenza)
1995-12-04 17:35:52 +00:00
// !PROV provincia (fiscale se c'<27> , oppure di residenza)
1995-10-09 15:47:28 +00:00
// !IVA partita iva
// !CF codice fiscale
// !TEL numero di telefono (con prefisso)
// !FAX numero di fax (con prefisso)
1996-08-05 13:45:27 +00:00
// !REGSOC numero di registrazione presso il Tribunale
// !CCIAA numero di registrazione presso la camera di commercio
1995-12-04 17:35:52 +00:00
// nota: la relazione della ditta <20> cos<6F> strutturata:
1995-08-07 08:41:34 +00:00
// %NDITTE (9) Dati ditte
// + %ANAGR (6) Anagrafica generale (indirizzo, ecc.)
// + %COMUNI (113@) Comune di residenza
// + %COMUNI (213@) Comune di residenza fiscale
1995-09-28 15:26:35 +00:00
TString in ( s . get ( ) ) ;
1997-08-29 16:42:42 +00:00
if ( in [ 0 ] ! = ' ! ' )
{
cf . set ( _firmrel . curr ( ) . get ( in ) ) ;
return TRUE ;
}
else
{
1995-09-28 15:26:35 +00:00
in . ltrim ( 1 ) ;
bool _fisc = _firmrel . lfile ( 6 ) . get ( " INDRF " ) . not_empty ( ) ;
1997-08-29 16:42:42 +00:00
if ( in = = " RAGSOC " )
{
cf . set ( _firmrel . lfile ( ) . get ( " RAGSOC " ) ) ;
return TRUE ;
}
if ( in = = " IND " )
{
1997-01-02 09:01:59 +00:00
if ( _fisc )
1997-08-29 16:42:42 +00:00
cf . set ( _firmrel . lfile ( 6 ) . get ( " INDRF " ) ) ;
1997-01-02 09:01:59 +00:00
else
1997-08-29 16:42:42 +00:00
cf . set ( _firmrel . lfile ( 6 ) . get ( " INDRES " ) ) ;
return TRUE ;
1995-09-28 15:26:35 +00:00
}
1997-08-29 16:42:42 +00:00
if ( in = = " NUM " )
{
1997-01-02 09:01:59 +00:00
if ( _fisc )
1997-08-29 16:42:42 +00:00
cf . set ( _firmrel . lfile ( 6 ) . get ( " CIVRF " ) ) ;
1997-01-02 09:01:59 +00:00
else
1997-08-29 16:42:42 +00:00
cf . set ( _firmrel . lfile ( 6 ) . get ( " CIVRES " ) ) ;
return TRUE ;
1995-09-28 15:26:35 +00:00
}
1997-08-29 16:42:42 +00:00
if ( in = = " CAP " )
{
1997-01-02 09:01:59 +00:00
if ( _fisc )
1997-08-29 16:42:42 +00:00
cf . set ( _firmrel . lfile ( 6 ) . get ( " CAPRF " ) ) ;
1997-01-02 09:01:59 +00:00
else
1997-08-29 16:42:42 +00:00
cf . set ( _firmrel . lfile ( 6 ) . get ( " CAPRES " ) ) ;
return TRUE ;
1995-09-28 15:26:35 +00:00
}
1997-08-29 16:42:42 +00:00
if ( in = = " COM " )
{
1997-01-02 09:01:59 +00:00
if ( _fisc )
1997-08-29 16:42:42 +00:00
cf . set ( _firmrel . lfile ( - 213 ) . get ( " DENCOM " ) ) ;
1997-01-02 09:01:59 +00:00
else
1997-08-29 16:42:42 +00:00
cf . set ( _firmrel . lfile ( - 113 ) . get ( " DENCOM " ) ) ;
return TRUE ;
1995-09-28 15:26:35 +00:00
}
1997-08-29 16:42:42 +00:00
if ( in = = " PROV " )
{
1997-01-02 09:01:59 +00:00
if ( _fisc )
1997-08-29 16:42:42 +00:00
cf . set ( _firmrel . lfile ( - 213 ) . get ( " PROVCOM " ) ) ;
1997-01-02 09:01:59 +00:00
else
1997-08-29 16:42:42 +00:00
cf . set ( _firmrel . lfile ( - 113 ) . get ( " PROVCOM " ) ) ;
return TRUE ;
1995-12-04 17:35:52 +00:00
}
1997-01-02 09:01:59 +00:00
if ( in = = " IVA " )
1997-08-29 16:42:42 +00:00
{
cf . set ( _firmrel . lfile ( 6 ) . get ( " PAIV " ) ) ;
return TRUE ;
}
1997-01-02 09:01:59 +00:00
if ( in = = " CF " )
1997-08-29 16:42:42 +00:00
{
cf . set ( _firmrel . lfile ( 6 ) . get ( " COFI " ) ) ;
return TRUE ;
}
if ( in = = " TEL " )
{
1997-01-02 09:01:59 +00:00
valore = _firmrel . lfile ( ) . get ( " PTEL " ) ;
valore < < " / " < < _firmrel . lfile ( ) . get ( " TEL " ) ;
1997-08-29 16:42:42 +00:00
cf . set ( valore ) ;
return TRUE ;
1995-09-28 15:26:35 +00:00
}
1997-08-29 16:42:42 +00:00
if ( in = = " FAX " )
{
1997-01-02 09:01:59 +00:00
valore = _firmrel . lfile ( ) . get ( " PFAX " ) ;
valore < < " / " < < _firmrel . lfile ( ) . get ( " FAX " ) ;
1997-08-29 16:42:42 +00:00
cf . set ( valore ) ;
return TRUE ;
1995-09-28 15:26:35 +00:00
}
1997-08-29 16:42:42 +00:00
if ( in = = " REGSOC " )
{
1997-01-02 09:01:59 +00:00
valore = _firmrel [ LF_UNLOC ] . get ( " REGTRIB " ) ;
1997-08-29 16:42:42 +00:00
const TString & vol = _firmrel [ LF_UNLOC ] . get ( " VOLTRIB " ) ;
if ( vol . not_empty ( ) )
valore < < " Vol. " < < vol ;
const TString & fasc = _firmrel [ LF_UNLOC ] . get ( " FASCTRIB " ) ;
if ( fasc . not_empty ( ) )
valore < < " Fasc. " < < fasc ;
cf . set ( valore ) ;
return TRUE ;
1996-08-05 13:45:27 +00:00
}
1997-08-29 16:42:42 +00:00
if ( in = = " CCIAA " )
{
valore = _firmrel [ LF_UNLOC ] . get ( " NUMCCIAA " ) ;
const TString & data = _firmrel [ LF_UNLOC ] . get ( " DATAICCIAA " ) ;
if ( data . not_empty ( ) )
valore < < " del " < < data ;
return TRUE ;
1996-08-05 13:45:27 +00:00
}
1995-09-28 15:26:35 +00:00
}
1995-08-07 08:41:34 +00:00
} // fine _DITTA
1995-09-28 15:26:35 +00:00
1997-06-12 16:26:22 +00:00
if ( code = = " _CLIENTE " )
{
1995-12-04 17:35:52 +00:00
// lettura dei dati del cliente
// sintassi: _CLIENTE,{<campo relazione>|<macro>}
// dove: <campo relazione> <20> un riferimento alla relazione di gestione dei dati del cliente
// <macro> <20> uno delle macro seguenti:
// !RAGSOC ragione sociale
// !IND indirizzo
// !NUM numero civico
1996-08-05 13:45:27 +00:00
// !INDNUM indirizzo + numero civico
1995-12-04 17:35:52 +00:00
// !COM comune
// !PROV provincia
// !TEL primo numero di telefono (con prefisso)
// !TEL2 secondo numero di telefono (con prefisso)
// !TEL3 terzo numero di telefono (con prefisso)
// !FAX numero di fax (con prefisso)
1997-06-28 11:29:43 +00:00
// !COM-><FIELD> accede ai campi del comune di residenza cliente
// !COMN-><FIELD> accede ai campi del comune di nascita del cliente
1997-06-12 16:26:22 +00:00
TCli_for & cli_for = _doc - > clifor ( ) ;
1995-12-04 17:35:52 +00:00
TString in ( s . get ( ) ) ; // prende la macro o il fieldref
1997-06-12 16:26:22 +00:00
if ( in [ 0 ] ! = ' ! ' )
{
1997-08-29 16:42:42 +00:00
cf . set ( cli_for . get ( in ) ) ;
return TRUE ;
}
in . ltrim ( 1 ) ;
if ( in = = " INDNUM " )
{
valore = cli_for . get ( CLI_INDCF ) ;
valore < < " " < < cli_for . get ( CLI_CIVCF ) ;
cf . set ( valore ) ;
return TRUE ;
}
if ( in . find ( " COM " ) = = 0 )
{
const bool nascita = in [ 3 ] = = ' N ' ;
const int p = in . find ( " -> " ) ;
if ( p > 0 )
in . ltrim ( p + 2 ) ;
TLocalisamfile com ( LF_COMUNI ) ;
if ( nascita )
1997-03-10 14:51:08 +00:00
{
1997-08-29 16:42:42 +00:00
com . put ( " STATO " , cli_for . get ( CLI_STATONASC ) ) ;
com . put ( " COM " , cli_for . get ( CLI_COMNASC ) ) ;
}
1997-06-12 16:26:22 +00:00
else
1997-08-29 16:42:42 +00:00
{
com . put ( " STATO " , cli_for . get ( CLI_STATOCF ) ) ;
com . put ( " COM " , cli_for . get ( CLI_COMCF ) ) ;
}
if ( com . read ( ) = = NOERR )
cf . set ( com . get ( in ) ) ;
return TRUE ;
}
if ( in . find ( " TEL " ) = = 0 )
{
if ( in . len ( ) = = 3 )
in < < " 1 " ;
const TString num ( cli_for . get ( in ) ) ;
in . insert ( " P " ) ;
valore = cli_for . get ( in ) ;
valore < < " / " < < num ;
cf . set ( valore ) ;
return TRUE ;
}
if ( in = = " FAX " )
{
valore = cli_for . get ( " PFAX " ) ;
valore < < " / " < < cli_for . get ( " FAX " ) ;
cf . set ( valore ) ;
return TRUE ;
}
if ( in = = " RAGSOC " )
{
valore = cli_for . get ( in ) ;
valore . strip_d_spaces ( ) ;
cf . set ( valore ) ;
return TRUE ;
1995-12-04 17:35:52 +00:00
}
} // fine _CLIENTE
1996-08-13 15:35:33 +00:00
1997-08-27 13:28:15 +00:00
if ( code = = " _DESCRIGA " )
{
1997-01-02 09:01:59 +00:00
// Messaggio per reperire la descrizione estesa sulle righe del documento
TLocalisamfile & rdoc = ( cursor ( ) ) - > file ( LF_RIGHEDOC ) ;
TString descrizione = rdoc . get ( " DESCR " ) ;
const bool desclunga = rdoc . get_bool ( " DESCLUNGA " ) ;
1997-06-03 10:29:42 +00:00
if ( desclunga )
{
const TString & s = rdoc . get ( " DESCEST " ) ;
descrizione < < s ;
1996-08-13 15:35:33 +00:00
}
1997-08-29 16:42:42 +00:00
cf . set ( descrizione ) ;
TParagraph_string p ( descrizione , cf . width ( ) ) ;
const int h = cf . height ( ) ;
for ( int i = 0 ; p . get ( ) ! = NULL & & i < h ; i + + ) ;
// cf.put_paragraph(descrizione);
1997-01-02 09:01:59 +00:00
// Setta l'altezza effettiva del body, per evitare sprechi di righe
1997-08-29 16:42:42 +00:00
cf . section ( ) . set_height ( i ) ;
return TRUE ;
1996-08-13 15:35:33 +00:00
}
1997-01-02 09:01:59 +00:00
1997-08-27 13:28:15 +00:00
if ( code = = " _RIEPILOGOIVA " )
{
1996-03-20 16:15:18 +00:00
// tabella riepilogo aliquote iva e relative imposte
1996-08-13 15:35:33 +00:00
// sintassi: _RIEPILOGOIVA,<selettore>,<macro>,<cambio codice>
// dove: <selettore> <20> uno dei seguenti:
// 1 = codici IVA a regime normale
// 2 = codici IVA da ventilare
// 4 = codici IVA esenti
// 8 = codici IVA non imponibili
// 16 = codici IVA non soggetti
// oppure la combinazione di uno o piu' di essi:
// 12 = 4+8, 19 = 1+2+16, 29 = 1+4+8+16 ecc...
1996-03-20 16:15:18 +00:00
// dove: <macro> <20> uno dei seguenti:
1996-08-13 15:35:33 +00:00
// COD colonna dei codici
// IMP colonna degli imponibili
// IVA colonna delle imposte
// ALI colonna delle aliquote
// DES colonna delle descrizioni (stampata solo se il regime IVA non e' normale)
// dove: <cambio codice> <20> uno dei seguenti:
// 0 indica di non leggere il successivo codice IVA nella tabella riepilogativa
// 1 indica di leggere il successivo codice IVA nella tabella riepilogativa
if ( s . items ( ) = = 4 )
{
byte selector = byte ( atoi ( s . get ( ) ) ) ; // il primo parametro e' il selettore del tipo di codice
if ( selector ! = 0 )
{
_doc - > summary_filter ( selector ) ;
TString what ( s . get ( ) ) ; // cosa deve stampare ?
TString value ( _doc - > summary_get ( what ) ) ; // Piglia il valore dalla riga selezionata sullatabellina
what = s . get ( ) ;
const bool next = what = = " 1 " ; // deve cambiare elemento ?
if ( next ) _doc - > summary_set_next ( ) ;
1997-08-29 16:42:42 +00:00
cf . set ( value ) ;
1996-03-20 16:15:18 +00:00
}
}
1996-08-13 15:35:33 +00:00
else
error_box ( " Numero di parametri non corretto in _RIEPILOGOIVA " ) ;
1997-08-29 16:42:42 +00:00
return TRUE ;
1995-12-04 17:35:52 +00:00
} // fine _RIEPILOGOIVA
1997-01-02 09:01:59 +00:00
if ( code = = " _TOTIMPONIBILI " )
{
// sintassi: _TOTIMPONIBILI,<selettore>
// dove: <selettore> funge da filtro per la somma degli imponibili
1997-05-14 10:35:52 +00:00
// se selettore vale 0 restituisce il tot. imponibili con le spese
1997-01-02 09:01:59 +00:00
// vedi _RIEPILOGOIVA per la spiegazione dei filtri selettivi
byte sel = atoi ( s . get ( ) ) ;
1997-05-14 10:35:52 +00:00
real x = sel = = 0 ? _doc - > imponibile ( TRUE ) : _doc - > tot_imponibili ( sel ) ;
1997-01-02 09:01:59 +00:00
1997-08-29 16:42:42 +00:00
cf . set ( x . string ( ) ) ;
1997-01-02 09:01:59 +00:00
return ( TRUE ) ;
} // fine _TOTIMPONIBILI
1997-08-27 13:28:15 +00:00
if ( code = = " _SCADENZE " )
{
1997-01-02 09:01:59 +00:00
// messaggio per stampare le scadenze
// sintassi: _SCADENZE,<macro>,<cambio codice>
// dove <macro> e' uno dei seguenti:
// DATA : stampa la data di scadenza
// IMPORTO : stampa l'importo in scadenza
// dove <cambio codice> vale 0 o 1 se indica di rendere corrente la prossima scadenza
if ( s . items ( ) = = 3 )
{
TString what ( s . get ( ) ) ;
TString value ( _doc - > scadenze_get ( what ) ) ;
what = s . get ( ) ;
const bool next = what = = " 1 " ;
if ( next ) _doc - > scadenze_set_next ( ) ;
1997-08-29 16:42:42 +00:00
cf . set ( value ) ;
1997-01-02 09:01:59 +00:00
}
1997-08-29 16:42:42 +00:00
return TRUE ;
1996-08-05 13:45:27 +00:00
}
1997-01-02 09:01:59 +00:00
1995-08-07 08:41:34 +00:00
return TForm : : validate ( cf , s ) ; // se il codice del messaggio non <20> identificato viene passato alla funzione standard
}
//////////////////////////////////////////////////////////////////////////////////////////////
1997-01-02 09:01:59 +00:00
// classe TStampaDoc_application customizzata dalla TApplication per l'applicazione principale
1995-08-07 08:41:34 +00:00
//////////////////////////////////////////////////////////////////////////////////////////////
1997-01-02 09:01:59 +00:00
enum behaviour
{
skip ,
go ,
cancel
} ;
// Chiavi di ordinamento LF_DOC:
// Chiave 1: ordinamento per Provvisorio + Anno + Codice numerazione + Numero documento
// Chiave 3: ordinamento per Data documento + Provvisorio + Anno + Codice numerazione + Numero documento
# define BY_NUM_KEY 1
# define BY_DATE_KEY 3
class TStampaDoc_application : public TApplication
{
TString _codnum ; // codice di numerazione
char _provv ; // stampa documenti provvisiori o definitivi (D o P)
int _anno ; // anno della documentazione
int _key ; // chiave per scorrere i documenti (1 o 3, vedi sopra)
int _ncopie ; // numero di copie per ogni documento
long _dalnum , _alnum ; // estremi di numerazione dei documenti
TDate _dadata , _adata ; // estremi di data dei documenti
bool _interattivo ; // flag che indica se il prog. funziona in interattivo o in batch
1997-03-10 14:51:08 +00:00
bool _is_lista ; // flga che indica se e' stata selezionata la lista documenti
1997-01-02 09:01:59 +00:00
bool _definitiva ; // flag che indica se la stampa <20> definitiva o no
TRelation * _firmrel ; // puntatore alla relazione che gestisce i dati della ditta corrente
TDocumento_form * _form ; // puntatore al form di stampa
1997-08-22 15:39:50 +00:00
TArray _file ;
1997-07-28 14:16:44 +00:00
1997-01-02 09:01:59 +00:00
protected :
1997-08-22 15:39:50 +00:00
void open_files ( int logicnum , . . . ) ;
1997-01-02 09:01:59 +00:00
virtual bool create ( ) ;
virtual bool destroy ( ) ;
virtual bool menu ( MENU_TAG ) ;
bool select ( void ) ;
virtual void on_firm_change ( void ) ;
virtual behaviour on_module_change ( const TString & , TString & ) ; // funzione chiamata ad ogni cambio modulo durante la stampa
virtual bool query_final_print ( void ) ; // funzione chiamata all'inizializzazione per sapere se la stampa <20> definitiva
static bool date2num_handler ( TMask_field & f , KEY key ) ;
static bool range_handler ( TMask_field & f , KEY key ) ;
public :
TDocumento_form & form ( ) { return * _form ; }
void print_documento ( ) ;
void print_selected ( ) ;
1997-02-03 15:28:53 +00:00
TStampaDoc_application ( ) : _key ( BY_NUM_KEY ) { } ;
1997-01-02 09:01:59 +00:00
virtual ~ TStampaDoc_application ( ) { } ;
} ;
void TStampaDoc_application : : print_selected ( )
{
TRelation rel ( LF_DOC ) ;
rel . add ( LF_RIGHEDOC , " CODNUM==CODNUM|ANNO==ANNO|PROVV==PROVV|NDOC==NDOC " ) ;
TCursor cur ( & rel ) ;
TLocalisamfile & doc = cur . file ( ) ;
cur . setkey ( _key ) ;
TRectype darec ( LF_DOC ) , arec ( LF_DOC ) ; // Estremi filtro
TString modulo_prec ;
const bool order_by_num = _key = = BY_NUM_KEY ;
doc . put ( DOC_CODNUM , _codnum ) ; // compone la chiave per il record di inizio cursore
doc . put ( DOC_ANNO , _anno ) ;
doc . put ( DOC_PROVV , _provv ) ;
doc . put ( DOC_NDOC , _dalnum ) ;
if ( ! order_by_num ) doc . put ( DOC_DATADOC , _dadata ) ;
doc . setkey ( _key ) ;
doc . read ( ) ; // trova il record iniziale
darec = doc . curr ( ) ;
doc . put ( DOC_NDOC , _alnum ) ;
if ( ! order_by_num ) doc . put ( DOC_DATADOC , _adata ) ;
int err = doc . read ( ) ; // trova il record finale
if ( err = = _iseof ) doc . last ( ) ;
else if ( err = = _iskeynotfound ) doc . prev ( ) ;
arec = doc . curr ( ) ;
if ( arec < darec )
{
error_box ( " Non vi sono documenti da stampare nell'intervallo indicato " ) ;
return ;
}
1997-03-10 14:51:08 +00:00
if ( ! _is_lista ) _definitiva = query_final_print ( ) ; // legge il flag di stampa definitiva
1997-01-02 09:01:59 +00:00
TPrinter & pr = printer ( ) ;
pr . open ( ) ;
TProgind * pi = pr . printtype ( ) ! = screenvis ?
new TProgind ( cur . items ( ) , " Stampa documenti in corso... " , FALSE , TRUE , 10 ) :
NULL ;
1997-03-10 14:51:08 +00:00
if ( ! _is_lista )
1997-01-02 09:01:59 +00:00
{
1997-03-10 14:51:08 +00:00
cur . setregion ( darec , arec ) ;
const long items = cur . items ( ) ;
behaviour whattodo = go ;
bool first_inst = TRUE ;
//TDocumentoEsteso *documento = new TDocumentoEsteso;
//cur.file().set_curr(documento);
for ( long i = 0 ; i < items ; i + + )
1997-01-02 09:01:59 +00:00
{
1997-03-10 14:51:08 +00:00
cur = i ; // Posiziona il documento
1997-08-22 15:39:50 +00:00
if ( _definitiva & & ! ( ( TDocumento & ) cur . curr ( ) ) . stampabile ( ) )
continue ;
1997-03-10 14:51:08 +00:00
_form = new TDocumento_form ( cur . curr ( ) /*documento*/ , * _firmrel , _definitiva , _interattivo ) ; // Istanzia il form
if ( ! _form - > valid ( ) ) break ; // interrompe la stampa se il doc corrente non e' tra i tipi validi
const TString & modulo = _form - > get_module_code ( ) ; // legge dal form il codice del modulo di carta per la stampa
if ( modulo_prec . empty ( ) ) modulo_prec = modulo ; // se siamo al primo passaggio la variabile di modulo precedente viene riempita
else first_inst = FALSE ;
const bool module_changed = modulo ! = modulo_prec ;
if ( first_inst | | module_changed )
if ( ! _form - > doc_arrange ( ) ) // Setta l'offset o posiziona manualmente
break ; // Se vi sono errori interrompe la stampa
if ( module_changed ) whattodo = on_module_change ( modulo , modulo_prec ) ; // se il modulo <20> cambiato dalla stampa precedente interroga la funzione per sapere che comportamento tenere
if ( whattodo = = cancel ) break ; // se non si pu<70> procedere la stampa viene interrotta
1997-08-22 15:39:50 +00:00
if ( whattodo = = skip )
continue ; // Salta il documento corrente
1997-03-10 14:51:08 +00:00
// altrimenti prosegue
// Carica il numero di copie da stampare per questo form
int ncopie = _ncopie = = 0 ? _form - > ncopie ( ) : _ncopie ; // Numero di copie da stampare per questo documento
if ( ncopie = = 0 ) ncopie = 1 ;
for ( int n = 0 ; n < ncopie ; n + + )
{
print_documento ( ) ;
_form - > doc ( ) . summary_reset ( ) ;
_form - > doc ( ) . scadenze_reset ( ) ;
}
1997-08-22 15:39:50 +00:00
if ( _definitiva & & ( numerazione_definitiva ( _form - > doc ( ) ) ! = NOERR ) )
1997-03-10 14:51:08 +00:00
{ // se la stampa <20> definitiva viene lanciata la procedura di rinumerazione
1997-07-07 08:32:35 +00:00
if ( _interattivo ) error_box ( " Non <20> possibile completare la procedura di numerazione definitiva dei documenti. Errore %d " , doc . status ( ) ) ;
1997-03-10 14:51:08 +00:00
break ;
}
1997-06-10 16:25:07 +00:00
delete _form ;
1997-01-02 09:01:59 +00:00
}
1997-03-10 14:51:08 +00:00
// Non viene fatta la delete documento perche' gia' presente nella distruzione del cursore, avendo fatto una set_curr()
}
else // Lista documenti
{
_form = new TDocumento_form ( LISTADOC , * _firmrel ) ;
_form - > cursor ( ) - > setregion ( darec , arec ) ;
_form - > print ( ) ;
1997-01-02 09:01:59 +00:00
delete _form ;
}
if ( pi ! = NULL ) delete pi ;
printer ( ) . close ( ) ;
}
void TStampaDoc_application : : print_documento ( )
{
CHECK ( _form , " Nessun form istanziato! " ) ;
TDocumento_form & f = form ( ) ;
TLocalisamfile & doc = f . cursor ( ) - > file ( ) ;
const bool is_vis = printer ( ) . printtype ( ) = = screenvis ;
if ( ! is_vis )
{
TString status ( " Documento: " ) ;
status < < doc . get ( DOC_CODNUM ) ;
status < < ' \\ ' < < doc . get ( DOC_NDOC ) ;
xvt_statbar_set ( status ) ;
}
f . print_documento ( ) ;
if ( ! is_vis )
xvt_statbar_set ( NULL ) ;
}
behaviour TStampaDoc_application : : on_module_change ( const TString & modulo , TString & modulo_prec )
{
if ( ! _interattivo ) return skip ; // se siamo in interattivo il documento viene saltato...
else
{ // ...altrimenti viene chiesto all'utente il da farsi
int risp = yesnocancel_box ( " Il modulo di carta <20> cambiato: inserisci il modulo '%s' e premi 'S<> ' per continuare, 'No' per saltare il documento o 'Cancel' per interrompere la stampa " , modulo ) ;
behaviour ret ;
switch ( risp )
{
case K_YES :
modulo_prec = modulo ; // aggiorna l'inseguitore dei moduli
ret = go ; // la stampa pu<70> continuare
break ;
case K_NO :
ret = skip ; // il documento viene saltato
break ;
case K_ESC :
ret = cancel ; // la stampa viene interrotta
break ;
}
return ret ;
}
}
bool TStampaDoc_application : : query_final_print ( )
{
if ( _interattivo )
{ // se siamo in interattivo viene richiesto all'utente se la stampa <20> definitiva o meno
if ( yesno_box ( " E' una stampa definitiva? " ) ) return TRUE ;
else return FALSE ;
} else return _definitiva ; // altrimenti ritorna il valore letto dalla linea di comando
}
bool TStampaDoc_application : : date2num_handler ( TMask_field & f , KEY key )
1996-06-27 09:37:32 +00:00
{
TMask & m = f . mask ( ) ;
if ( key = = K_TAB & & f . focusdirty ( ) )
{
short dlg = f . dlg ( ) ;
TLocalisamfile doc ( LF_DOC ) ;
doc . setkey ( 3 ) ;
TString codnum1 ( m . get ( F_CODNUM ) ) , codnum2 ;
TString anno1 ( m . get ( F_ANNO ) ) , anno2 ;
TString provv1 ( m . get ( F_PROVV ) ) , provv2 ;
TDate data1 ( m . get_date ( dlg ) ) , data2 ;
long numdoc ;
doc . zero ( ) ;
doc . put ( " CODNUM " , codnum1 ) ;
doc . put ( " ANNO " , anno1 ) ;
doc . put ( " PROVV " , provv1 ) ;
doc . put ( " DATADOC " , data1 ) ;
if ( doc . read ( _isgteq ) = = NOERR )
{
codnum2 = doc . get ( " CODNUM " ) ;
anno2 = doc . get ( " ANNO " ) ;
provv2 = doc . get ( " PROVV " ) ;
data2 = doc . get_date ( " DATADOC " ) ;
if ( codnum1 = = codnum2 & & anno1 = = anno2 & & provv1 = = provv2 & & data1 = = data2 )
{
numdoc = doc . get_long ( " NDOC " ) ;
m . set ( dlg = = F_DA_DATADOC ? F_DA_NDOC : F_A_NDOC , numdoc ) ;
}
}
}
return TRUE ;
}
1995-08-07 08:41:34 +00:00
1997-01-02 09:01:59 +00:00
bool TStampaDoc_application : : range_handler ( TMask_field & f , KEY key )
1996-08-05 13:45:27 +00:00
{
int rt = TRUE ;
TMask & m = f . mask ( ) ;
if ( key = = K_TAB & & f . focusdirty ( ) )
{
const long lim_sup = atol ( f . get ( ) ) ;
const long lim_inf = m . get_long ( F_DA_NDOC ) ;
if ( lim_sup < lim_inf )
{
f . error_box ( " Il limite superiore deve essere maggiore del limite inferiore " ) ;
rt = FALSE ;
}
}
return rt ;
}
1997-08-22 15:39:50 +00:00
void TStampaDoc_application : : open_files ( int logicnum , . . . )
{
va_list marker ;
va_start ( marker , logicnum ) ;
while ( logicnum > 0 )
{
CHECKD ( _file . objptr ( logicnum ) = = NULL , " File gia' aperto: " , logicnum ) ;
_file . add ( new TLocalisamfile ( logicnum ) , logicnum ) ;
logicnum = va_arg ( marker , int ) ;
}
}
1997-01-02 09:01:59 +00:00
bool TStampaDoc_application : : create ( )
1996-08-13 15:35:33 +00:00
{
1995-08-07 08:41:34 +00:00
TApplication : : create ( ) ;
_firmrel = new TRelation ( LF_NDITTE ) ; // istanziamento e impostazione della relazione di gestione della ditta corrente
_firmrel - > add ( LF_ANAG , " TIPOA=TIPOA|CODANAGR=CODANAGR " ) ;
1996-08-13 15:35:33 +00:00
_firmrel - > add ( LF_UNLOC , " CODDITTA=CODDITTA " ) ; // si posiziona sulla prima unita' locale della ditta
1995-12-04 17:35:52 +00:00
_firmrel - > add ( LF_COMUNI , " COM=STATORES+COMRES " , 1 , LF_ANAG , 100 + LF_COMUNI ) ;
_firmrel - > add ( LF_COMUNI , " COM=STATORES+COMRF " , 1 , LF_ANAG , 200 + LF_COMUNI ) ;
1997-08-22 15:39:50 +00:00
open_files ( LF_TABCOM , LF_TAB , LF_OCCAS , LF_CLIFO , LF_CFVEN , LF_MOVMAG , LF_RMOVMAG , 0 ) ;
1997-02-03 15:28:53 +00:00
const int argc = TApplication : : argc ( ) ;
1997-06-10 15:26:29 +00:00
_is_lista = argc = = 3 & & argv ( 2 ) [ 0 ] = = ' L ' ;
1997-03-10 14:51:08 +00:00
if ( argc > 3 )
1997-01-02 09:01:59 +00:00
{ // lettura dei parametri iniziali dalla linea di comando
1995-08-07 08:41:34 +00:00
_codnum = argv ( 2 ) ; // il primo parametro <20> il codice di numerazione
_anno = atoi ( argv ( 3 ) ) ; // il secondo <20> l'anno
1997-01-02 09:01:59 +00:00
_provv = argv ( 4 ) [ 0 ] ; // il terzo <20> il flag di numerazione provvisoria
1995-08-07 08:41:34 +00:00
_dalnum = atol ( argv ( 5 ) ) ; // il quarto <20> il numero di documento di partenza
1997-02-03 15:28:53 +00:00
_alnum = _dalnum ;
_definitiva = FALSE ;
_ncopie = 1 ;
1995-08-07 08:41:34 +00:00
_interattivo = FALSE ;
1997-02-03 15:28:53 +00:00
if ( argc > 6 )
{
_alnum = atol ( argv ( 6 ) ) ; // il quinto <20> il numero di documento di fine
if ( argc > 7 )
{
_definitiva = ( strcmp ( argv ( 7 ) , " D " ) = = 0 ) ; // il sesto <20> se la stampa <20> definitiva (rinumerazione dei documenti)
if ( argc > 8 )
_ncopie = atoi ( argv ( 8 ) ) ;
}
else _interattivo = TRUE ;
}
print_selected ( ) ;
1997-01-02 09:01:59 +00:00
return FALSE ;
}
1997-02-03 15:28:53 +00:00
else
1997-03-10 14:51:08 +00:00
{
if ( argc = = 2 | | _is_lista )
1997-02-03 15:28:53 +00:00
{ // oppure lancio della maschera
_interattivo = TRUE ;
dispatch_e_menu ( BAR_ITEM ( 1 ) ) ;
}
else
return error_box ( Usage ) ;
1997-03-10 14:51:08 +00:00
}
1995-09-28 15:26:35 +00:00
return TRUE ;
1995-08-07 08:41:34 +00:00
}
1997-01-02 09:01:59 +00:00
bool TStampaDoc_application : : destroy ( )
{
1995-08-07 08:41:34 +00:00
delete _firmrel ; // distruzione della relazione di gestione della ditta corrente
return TApplication : : destroy ( ) ;
}
1997-01-02 09:01:59 +00:00
void TStampaDoc_application : : on_firm_change ( )
{
1995-08-07 08:41:34 +00:00
TLocalisamfile & firmfile = _firmrel - > lfile ( ) ;
firmfile . put ( " CODDITTA " , get_firm ( ) ) ;
_firmrel - > read ( ) ;
}
1997-01-02 09:01:59 +00:00
bool TStampaDoc_application : : select ( )
{
1995-08-07 08:41:34 +00:00
TMask m ( " ve1100a " ) ;
1997-03-10 14:51:08 +00:00
1997-04-04 10:09:40 +00:00
if ( _is_lista )
{
m . hide ( F_NCOPIE ) ;
m . set_caption ( " Lista Documenti " ) ;
}
1996-06-27 09:37:32 +00:00
TString wdate ;
m . set_handler ( F_DA_DATADOC , date2num_handler ) ;
m . set_handler ( F_A_DATADOC , date2num_handler ) ;
1996-08-05 13:45:27 +00:00
m . set_handler ( F_A_NDOC , range_handler ) ;
1997-01-02 09:01:59 +00:00
if ( m . run ( ) = = K_ENTER )
{
1995-08-07 08:41:34 +00:00
_codnum = m . get ( F_CODNUM ) ; // lettura dei dati dalla maschera
_anno = m . get_int ( F_ANNO ) ;
1997-01-02 09:01:59 +00:00
_provv = m . get ( F_PROVV ) [ 0 ] ;
1995-08-07 08:41:34 +00:00
_dalnum = m . get_long ( F_DA_NDOC ) ;
_alnum = m . get_long ( F_A_NDOC ) ;
1996-09-04 07:30:33 +00:00
_ncopie = m . get_int ( F_NCOPIE ) ;
1996-06-27 09:37:32 +00:00
if ( _alnum = = 0 ) _alnum = 9999999L ;
wdate = m . get ( F_DA_DATADOC ) ;
if ( wdate . not_empty ( ) ) _dadata = wdate ;
else _dadata = botime ;
wdate = m . get ( F_A_DATADOC ) ;
if ( wdate . not_empty ( ) ) _adata = wdate ;
else _adata = eotime ;
1997-01-02 09:01:59 +00:00
_key = BY_NUM_KEY ;
if ( m . get ( F_DATA_O_NUM ) ! = " N " ) _key = BY_DATE_KEY ;
return TRUE ;
} else return FALSE ;
1995-08-07 08:41:34 +00:00
}
1997-01-02 09:01:59 +00:00
bool TStampaDoc_application : : menu ( MENU_TAG )
{
while ( select ( ) ) print_selected ( ) ;
1995-09-28 15:26:35 +00:00
return FALSE ;
1995-08-07 08:41:34 +00:00
}
1997-01-02 09:01:59 +00:00
// Do all the work!
1997-03-10 14:51:08 +00:00
int ve1100 ( int argc , char * * argv )
1997-01-02 09:01:59 +00:00
{
1997-03-10 14:51:08 +00:00
1997-01-02 09:01:59 +00:00
TStampaDoc_application a ;
1997-03-10 14:51:08 +00:00
const bool cond = argc = = 4 & & argv [ 2 ] [ 0 ] = = ' L ' ; // List documenti
a . run ( argc , argv , cond ? " Lista documenti " : " Stampa documenti di vendita " ) ;
1995-10-09 15:47:28 +00:00
return ( 0 ) ;
}
1996-08-13 15:35:33 +00:00