1998-11-04 18:04:26 +00:00
//////////////////////////////////////////////////////////////
// Stampa documenti
//////////////////////////////////////////////////////////////
1995-08-07 08:41:34 +00:00
# include <applicat.h>
2006-04-13 17:56:02 +00:00
# include <config.h>
1999-04-06 15:34:39 +00:00
# include <defmask.h>
2003-11-17 10:20:13 +00:00
# include <postman.h>
1996-08-13 15:35:33 +00:00
# include <printer.h>
1996-09-04 07:30:33 +00:00
# include <progind.h>
1998-11-04 18:04:26 +00:00
# include <sheet.h>
1995-12-04 17:35:52 +00:00
2006-02-07 12:17:10 +00:00
# include "velib05.h"
1997-06-10 16:25:07 +00:00
# include "sconti.h"
1997-08-02 08:47:57 +00:00
# include "ve1100.h"
2003-11-17 10:20:13 +00:00
# include <comuni.h>
1996-10-12 11:53:11 +00:00
1998-04-30 14:04:19 +00:00
# define LISTADOC "listadoc"
# define FAKETOTFLD 9999
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
{
2006-01-31 15:33:00 +00:00
TDocumentoEsteso * _doc ;
1999-04-06 15:34:39 +00:00
1996-10-12 11:53:11 +00:00
public :
1997-01-02 09:01:59 +00:00
virtual TRectype & curr ( ) const { return ( TRectype & ) * _doc ; }
2006-01-31 15:33:00 +00:00
TDocisamfile ( TDocumentoEsteso * doc ) : TLocalisamfile ( LF_DOC ) , _doc ( doc )
{ CHECK ( _doc , " Invalid document " ) ; }
2006-12-13 16:22:33 +00:00
virtual int readat ( TRecnotype nrec , word lockop ) ;
1997-01-02 09:01:59 +00:00
virtual ~ TDocisamfile ( ) { } ;
1996-10-12 11:53:11 +00:00
} ;
2006-12-13 16:22:33 +00:00
int TDocisamfile : : readat ( TRecnotype nrec , word lockop )
{
int err = TBaseisamfile : : readat ( nrec , _nolock ) ;
if ( err = = NOERR )
{
err = _doc - > read ( curr ( ) ) ;
if ( err = = NOERR )
{
_doc - > summary_reset ( true ) ; // forza il ricalcolo perche' trattasi di documento diverso
_doc - > summary_filter ( 1 ) ;
}
}
return err ;
}
1997-01-02 09:01:59 +00:00
class TRDocisamfile : public TLocalisamfile
{
TDocumento * _doc ;
int _row ;
2006-01-31 15:33:00 +00:00
bool _normal_next ;
1999-04-06 15:34:39 +00:00
1997-01-02 09:01:59 +00:00
protected :
TDocumento & doc ( ) const { return * _doc ; }
1999-04-06 15:34:39 +00:00
1997-01-02 09:01:59 +00:00
public :
2006-01-31 15:33:00 +00:00
void set_normal_next ( bool b = true ) { _normal_next = b ; }
2006-12-13 16:22:33 +00:00
1999-04-06 15:34:39 +00:00
virtual int next ( word lockop = _nolock ) { return _normal_next ? TLocalisamfile : : next ( lockop ) : NOERR ; }
virtual TRectype & curr ( ) const ;
1997-01-02 09:01:59 +00:00
void set_row ( int r ) { _row = r ; }
2006-01-31 15:33:00 +00:00
TRDocisamfile ( TDocumento * doc ) : TLocalisamfile ( LF_RIGHEDOC ) , _doc ( doc ) , _row ( 1 ) , _normal_next ( false ) { }
2006-12-13 16:22:33 +00:00
1997-01-02 09:01:59 +00:00
virtual ~ TRDocisamfile ( ) { } ;
} ;
1996-10-12 11:53:11 +00:00
1999-04-06 15:34:39 +00:00
TRectype & TRDocisamfile : : curr ( ) const
{
TRectype & rr = ( ( _row > 0 & & _row < = _doc - > rows ( ) ) ? ( TRectype & ) doc ( ) [ _row ] : TLocalisamfile : : curr ( ) ) ;
return rr ;
}
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
////////////////////////////////////////////////////////////////////////////
1999-04-06 15:34:39 +00:00
1997-01-02 09:01:59 +00:00
class TDocumento_form : public TForm
{
static TDocumento_form * _form ;
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
1998-08-25 18:07:30 +00:00
2004-03-22 11:59:28 +00:00
TString_array _exclude_array ; // array di tipi riga e articoli da escludere dalla stampa
1999-04-06 15:34:39 +00:00
TAssoc_array _doc_totals ; // Assocarray per codice numerazione contenente i totali nel caso di stampa 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
2004-04-28 21:14:03 +00:00
TSorted_cursor * _sorted_cur ; // Valido solo per i form di lista documenti
TDocisamfile * _docfile ;
TRDocisamfile * _rdocfile ;
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
1996-08-13 15:35:33 +00:00
// 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
2006-12-13 16:22:33 +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
1997-01-02 09:01:59 +00:00
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 ) ;
2002-02-26 16:20:19 +00:00
void output_values ( const TRectype & rec , const char * output , TForm_item & cf ) ;
1997-01-02 09:01:59 +00:00
1995-08-07 08:41:34 +00:00
public :
1999-04-06 15:34:39 +00:00
void edit_picture ( TForm_item & f , const int dec ) ;
void modify_pictures ( ) ;
1998-11-04 18:04:26 +00:00
virtual TCursor * cursor ( ) const { return _sorted_cur ? _sorted_cur : TForm : : cursor ( ) ; }
1998-04-30 14:04:19 +00:00
void hide_sections ( ) ;
bool is_faketotfld ( ) ;
1997-01-02 09:01:59 +00:00
void print_documento ( ) ;
2003-07-22 13:22:11 +00:00
bool valid ( ) const { return _valid ; }
1997-01-02 09:01:59 +00:00
bool doc_arrange ( ) ;
2003-02-25 14:39:02 +00:00
int ncopie ( ) const { return _doc - > tipo ( ) . ncopie ( ) ; }
const TString & get_module_code ( ) const { return _module ; } // ritorna il codice del modulo di carta
2004-03-22 11:59:28 +00:00
TString_array & exclude_list ( ) { return _exclude_array ; }
2003-06-24 12:55:12 +00:00
1997-01-02 09:01:59 +00:00
TDocumentoEsteso & doc ( ) { return * _doc ; }
2003-06-24 12:55:12 +00:00
void set_doc_ext ( TRectype * doc ) ;
2003-02-25 14:39:02 +00:00
TDocumento_form ( TRectype & doc , TRelation & rel , bool definitiva , bool interattivo , bool aggiuntivo ) ;
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
2003-06-24 12:55:12 +00:00
void TDocumento_form : : set_doc_ext ( TRectype * doc )
{
CHECK ( _doc = = NULL , " Doppio documeto esteso " ) ;
if ( doc ! = NULL )
_doc = new TDocumentoEsteso ( * doc ) ;
else
_doc = new TDocumentoEsteso ;
_docfile = new TDocisamfile ( _doc ) ;
_rdocfile = new TRDocisamfile ( _doc ) ;
_rdocfile - > set_normal_next ( ) ;
relation ( ) - > replace ( _docfile , 0 ) ;
relation ( ) - > replace ( _rdocfile , 1 ) ;
if ( _doc - > physical_rows ( ) > 0 )
relation ( ) - > update ( ) ;
}
2004-11-30 22:02:59 +00:00
static TTipi_documento_cache __tipi ;
2003-02-25 14:39:02 +00:00
TDocumento_form : : TDocumento_form ( TRectype & doc , TRelation & rel , bool definitiva , bool interattivo , bool aggiuntivo )
2005-11-15 12:04:34 +00:00
: _firmrel ( rel ) , _sorted_cur ( NULL ) , _docfile ( NULL ) , _rdocfile ( NULL ) , _doc ( NULL ) , _valid ( false )
1997-01-02 09:01:59 +00:00
{
_form = this ;
2004-11-30 22:02:59 +00:00
2003-11-10 15:18:25 +00:00
const TString4 tipodoc ( doc . get ( DOC_TIPODOC ) ) ;
2005-11-15 12:04:34 +00:00
bool found = false ;
TFilename nomeform ;
2006-07-11 13:12:41 +00:00
const TTipo_documento & tipo = __tipi . tipo ( tipodoc ) ;
if ( tipo . empty ( ) )
{
error_box ( FR ( " Tipo di documento non valido: '%s' " ) , ( const char * ) tipodoc ) ;
2005-11-15 12:04:34 +00:00
return ;
1997-01-02 09:01:59 +00:00
}
2006-07-11 13:12:41 +00:00
if ( tipo . printable ( ) )
{ // se non ci sono errori procede con la stampa
2006-07-11 16:22:58 +00:00
if ( aggiuntivo )
tipo . additional_print_profile ( nomeform ) ;
else
tipo . main_print_profile ( nomeform ) ; // legge il nome del form di stampa
2006-07-11 13:12:41 +00:00
nomeform . trim ( ) ;
TFilename test ( nomeform ) ; test . ext ( " frm " ) ;
if ( ! test . custom_path ( ) )
{
error_box ( FR ( " Nome form di stampa '%s' non valido per il tipo documento %s " ) , ( const char * ) nomeform , ( const char * ) tipodoc ) ;
return ;
}
}
else
return ;
1995-08-07 08:41:34 +00:00
2006-12-13 16:22:33 +00:00
_valid = true ;
1997-01-02 09:01:59 +00:00
read ( nomeform ) ;
2006-12-13 16:22:33 +00:00
_cli_loaded = false ;
2003-06-24 12:55:12 +00:00
set_doc_ext ( & doc ) ; // istanzia TDocumentoEsteso
1996-08-13 15:35:33 +00:00
modify_pictures ( ) ;
2004-11-30 22:02:59 +00:00
1996-08-13 15:35:33 +00:00
dec_parm p ;
const int items = _group_decimals . items ( ) ;
2004-11-30 22:02:59 +00:00
1996-08-13 15:35:33 +00:00
for ( int i = 0 ; i < items ; i + + )
{
TToken_string & t = _group_decimals . row ( i ) ;
int gruppo = t . get_int ( 0 ) ;
switch ( gruppo )
{
2000-05-05 15:25:49 +00:00
case GROUP_QTA : p . qta_lit = t . get_int ( 1 ) ; p . qta_val = t . get_int ( 2 ) ;
break ;
1996-08-13 15:35:33 +00:00
// add other groups here
default :
2000-05-05 15:25:49 +00:00
break ;
1996-08-13 15:35:33 +00:00
}
}
1997-11-14 09:36:04 +00:00
_doc - > set_decimals ( p ) ;
// Inizializza lo sfondo delle pagine normali
2006-12-13 16:22:33 +00:00
set_background ( 3 , true ) ;
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)
2003-06-24 12:55:12 +00:00
TDocumento_form : : TDocumento_form ( const char * form , TRelation & rel )
2006-12-13 16:22:33 +00:00
: TForm ( form ) , _firmrel ( rel ) , _docfile ( NULL ) , _rdocfile ( NULL ) , _doc ( NULL ) , _valid ( false )
1997-03-10 14:51:08 +00:00
{
2006-12-13 16:22:33 +00:00
_cli_loaded = false ;
1999-04-06 15:34:39 +00:00
_sorted_cur = new TSorted_cursor ( relation ( ) , " PROVV|ANNO|CODNUM|STATO|DATADOC|NDOC " ) ;
1997-03-10 14:51:08 +00:00
}
1997-01-02 09:01:59 +00:00
TDocumento_form : : ~ TDocumento_form ( )
{
1998-11-04 18:04:26 +00:00
// Membri di cui NON va fatta la delete:
// _docfile : perche' viene fatta dal distruttore di TRelation
// _rdocfile : perche' viene fatta dal distruttore di TRelation
1999-06-18 15:35:05 +00:00
if ( _doc ) delete _doc ;
1998-11-04 18:04:26 +00:00
if ( _sorted_cur ) delete _sorted_cur ;
1997-01-02 09:01:59 +00:00
}
1998-04-30 14:04:19 +00:00
void TDocumento_form : : hide_sections ( )
{
// Scorre tutte le sezioni e nasconde gli items
const char s [ 3 ] = { ' B ' , ' G ' , ' H ' } ;
for ( int sn = 0 ; sn < 3 ; sn + + )
{
const char sc = s [ sn ] ;
for ( pagetype pt = odd_page ; pt < = last_page ; pt = pagetype ( pt + 1 ) )
{
TPrint_section * sec = exist ( sc , pt ) ;
if ( sec = = NULL )
continue ;
TForm_item * f ;
for ( word i = 0 ; i < sec - > fields ( ) ; i + + )
{
f = & ( sec - > field ( i ) ) ;
f - > hide ( ) ;
}
}
}
}
bool TDocumento_form : : is_faketotfld ( )
{
TPrint_section * fl = exist ( ' F ' , last_page ) ;
if ( fl ! = NULL )
{
TForm_item * f ;
for ( word i = 0 ; i < fl - > fields ( ) ; i + + )
{
f = & ( fl - > field ( i ) ) ;
if ( f - > id ( ) = = FAKETOTFLD )
2006-12-13 16:22:33 +00:00
return true ;
1998-04-30 14:04:19 +00:00
}
}
2006-12-13 16:22:33 +00:00
return false ;
1998-04-30 14:04:19 +00:00
}
1997-01-02 09:01:59 +00:00
bool TDocumento_form : : doc_arrange ( )
{
TPrinter & pr = printer ( ) ;
if ( char_to_pos ( ) ! = ' \0 ' | | ( ipx ( ) + ipy ( ) + fpx ( ) ) ! = 0 )
{
if ( offset_x ( ) ! = 0 | | offset_y ( ) ! = 0 )
{
2003-06-19 14:35:45 +00:00
error_box ( FR ( " Non e' possibile settare contemporaneamente gli offset "
" e i parametri di posizionamento del modulo %s. " ) , ( const char * ) name ( ) ) ;
2006-12-13 16:22:33 +00:00
return false ;
1997-01-02 09:01:59 +00:00
}
else
if ( pr . printtype ( ) = = winprinter )
_form - > arrange_form ( ) ;
}
else
1999-06-18 15:35:05 +00:00
pr . set_offset ( _form - > offset_y ( ) , _form - > offset_x ( ) ) ;
2006-12-13 16:22:33 +00:00
return true ;
1995-12-04 17:35:52 +00:00
}
2004-03-23 15:38:19 +00:00
1997-01-02 09:01:59 +00:00
void TDocumento_form : : print_documento ( )
{
2000-05-05 15:25:49 +00:00
TPrinter & pr = printer ( ) ;
1997-01-02 09:01:59 +00:00
// stampa tutte le righe
TPrint_section & body = section ( ' B ' ) ;
2004-04-28 21:14:03 +00:00
// TPrint_section& foot = section('F'); // qui verificare
2000-05-05 15:25:49 +00:00
TPrint_section * sect = exist ( ' B ' , last_page ) ;
TString last_section ;
1997-01-11 10:41:52 +00:00
1997-01-02 09:01:59 +00:00
const int righe = _doc - > rows ( ) ;
2006-12-13 16:22:33 +00:00
bool one_row_printed = false ;
2004-03-23 15:38:19 +00:00
const bool update_relation = relation ( ) - > has_children ( 1 ) ;
1997-01-02 09:01:59 +00:00
2006-12-13 16:22:33 +00:00
set_last_page ( false ) ; // E' importante settare questo flag, per evitare "Falli di Piede" eheh :-)
1997-01-02 09:01:59 +00:00
for ( int r = 1 ; r < = righe ; r + + )
{
_rdocfile - > set_row ( r ) ;
2004-03-23 15:38:19 +00:00
if ( update_relation )
relation ( ) - > update ( 1 ) ;
2003-10-17 13:48:47 +00:00
2003-02-25 14:39:02 +00:00
if ( ! print_on_body ( r ) )
continue ;
2000-05-05 15:25:49 +00:00
if ( sect )
{
sect - > update ( ) ;
const TString & curr_section = sect - > field ( 0 ) . get ( ) ;
if ( r = = 1 | | curr_section ! = last_section )
{
last_section = curr_section ;
const word h = sect - > height ( ) ;
for ( word j = 0 ; j < h ; j + + )
pr . print ( sect - > row ( j ) ) ;
}
}
1997-01-02 09:01:59 +00:00
const word h = body . height ( ) ;
for ( word j = 0 ; j < h ; j + + )
pr . print ( body . row ( j ) ) ;
1999-10-22 10:00:18 +00:00
if ( ! one_row_printed )
2006-12-13 16:22:33 +00:00
one_row_printed = true ;
2000-05-05 15:25:49 +00:00
if ( ( * _doc ) [ r ] . tipo ( ) . formfeed ( ) )
pr . formfeed ( ) ;
1999-10-22 10:00:18 +00:00
}
if ( ! one_row_printed )
{
// Riga fasulla... per stampare l'intestazione obbligatoriamente,
// anche in caso che non vi siano righe nel documento o che siano tutte escluse
TPrintrow r ;
pr . print ( r ) ;
1997-01-02 09:01:59 +00:00
}
1999-04-06 15:34:39 +00:00
if ( _doc - > tipo ( ) . add_conai ( ) & & _doc - > clifor ( ) . vendite ( ) . get_bool ( " CONAIASS " ) )
{
TRiga_documento last_row ( _doc ) ;
TConfig c ( CONFIG_DITTA ) ;
last_row = _rdocfile - > curr ( ) ;
_rdocfile - > zero ( ) ;
TString80 desc ( c . get ( " DESCCONAIASS " ) ) ;
if ( desc . empty ( ) )
desc = " Contributo CONAI assolto " ;
_rdocfile - > put ( RDOC_DESCR , desc ) ;
body . update ( ) ;
const word h = body . height ( ) ;
if ( pr . rows_left ( ) < = h + 1 ) // salto pagina
pr . formfeed ( ) ;
for ( word j = 0 ; j < h ; j + + )
pr . print ( body . row ( j ) ) ;
_rdocfile - > curr ( ) = last_row ;
}
2006-12-13 16:22:33 +00:00
TPrint_section * last_foot = exist ( ' F ' , last_page , false ) ;
1999-04-06 15:34:39 +00:00
if ( last_foot ! = NULL )
{
const word lfh = last_foot - > height ( ) ;
const word left = pr . rows_left ( ) + pr . footersize ( ) ;
if ( lfh > left ) // Se l'ultimo footer e' troppo grande ...
pr . formfeed ( ) ; // Stampa il footer normale
pr . footerlen ( lfh ) ; // Fondamentale!
}
2006-12-13 16:22:33 +00:00
set_last_page ( true ) ;
1999-04-06 15:34:39 +00:00
pr . formfeed ( ) ; // Stampa l'ultimo footer
1997-01-02 09:01:59 +00:00
// Rimette ad 1 il numero della pagina
pr . setcurrentpage ( 1 ) ;
}
void TDocumento_form : : print_header ( TPrinter & pr )
{
TPrint_section & head = section ( ' H ' ) ;
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 ( ) ;
1998-11-04 18:04:26 +00:00
word r = foot . height ( ) ;
for ( word j = 0 ; j < r ; j + + )
1997-01-02 09:01:59 +00:00
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
{
2000-05-05 15:25:49 +00:00
const TString old_picture = fi . picture ( ) ;
1997-12-10 12:12:46 +00:00
TString new_picture ( 20 ) ;
1998-11-04 18:04:26 +00:00
const int comma_pos = old_picture . find ( ' , ' ) ;
const int stop_pos = old_picture . find ( ' . ' ) ;
char migliaia_char = ' . ' ;
if ( comma_pos > 0 & & stop_pos > 0 )
{
if ( stop_pos > comma_pos )
migliaia_char = ' , ' ;
}
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
1998-11-04 18:04:26 +00:00
if ( dec > 0 ) new_picture < < dec ; // in valuta
1996-08-13 15:35:33 +00:00
}
else
{
if ( dec = = 0 ) return ; // 0 non cambia la picture
1998-11-04 18:04:26 +00:00
1996-08-13 15:35:33 +00:00
new_picture = old_picture ;
1998-11-04 18:04:26 +00:00
// Resetta la picture: toglie eventuali decimali gia' presenti...
const int pos = new_picture . rfind ( migliaia_char = = ' . ' ? ' , ' : ' . ' ) ;
if ( pos > = 0 )
new_picture . cut ( pos ) ;
// Se si decide di metterne... altrimenti ndec -1 lascia la picture senza decimali
if ( dec > 0 )
{
TString16 dec_to_add ;
for ( int i = 0 ; i < dec ; i + + )
dec_to_add < < " @ " ; // aggiunge tanti "@" quanti sono i decimali voluti
if ( migliaia_char = = ' , ' )
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
}
1996-08-13 15:35:33 +00:00
}
2001-06-25 10:41:20 +00:00
const int w = old_picture . len ( ) ; // se la picture eccede la dimensione della picture, toglie i caratteri piu' a sx
1996-08-13 15:35:33 +00:00
int exceed = w - new_picture . len ( ) ;
if ( exceed < 0 & & w > 0 )
{
exceed = : : abs ( exceed ) ;
new_picture = new_picture . mid ( exceed , new_picture . len ( ) - exceed ) ;
1997-12-10 12:12:46 +00:00
if ( new_picture [ 0 ] = = migliaia_char )
new_picture . ltrim ( 1 ) ;
1996-08-13 15:35:33 +00:00
}
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 ( ) ;
2000-05-05 15:25:49 +00:00
const char sechar [ 4 ] = { ' B ' , ' F ' , ' G ' , ' H ' } ;
1996-08-13 15:35:33 +00:00
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 ) ;
2000-05-05 15:25:49 +00:00
if ( fi . in_group ( GROUP_PRICES ) )
2006-12-13 16:22:33 +00:00
edit_picture ( fi , _doc - > decimals ( true ) ) ;
2000-05-05 15:25:49 +00:00
else
if ( fi . in_group ( GROUP_IMPORTI ) )
edit_picture ( fi , _doc - > decimals ( ) ) ;
else
1996-08-13 15:35:33 +00:00
{
2000-05-05 15:25:49 +00:00
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-08-13 15:35:33 +00:00
}
}
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 ) ;
2006-12-13 16:22:33 +00:00
bool ok = true ;
2004-03-22 11:59:28 +00:00
FOR_EACH_ARRAY_ROW ( _exclude_array , i , row )
{
if ( row - > starts_with ( tiporiga ) )
{
const int pos = row - > find ( ' , ' ) ;
if ( pos < = 0 )
2006-12-13 16:22:33 +00:00
ok = false ;
2004-03-22 11:59:28 +00:00
else
{
const TString & codart = riga . get ( RDOC_CODART ) ;
const TString art_to_exclude ( row - > mid ( pos + 1 ) ) ;
ok = art_to_exclude . not_empty ( ) & & ( art_to_exclude . find ( codart ) < 0 ) ;
}
if ( ! ok )
break ;
}
}
if ( ok )
1997-01-02 09:01:59 +00:00
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...
2003-02-25 14:39:02 +00:00
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)
2000-05-05 15:25:49 +00:00
// if (scanner.key() == "PR")
// {
// TToken_string t;
// t.add(GROUP_PRICES);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 ;
2000-05-05 15:25:49 +00:00
t . add ( GROUP_QTA ) ; t . add ( scanner . integer ( ) ) ; t . add ( scanner . integer ( ) ) ;
1996-08-13 15:35:33 +00:00
_group_decimals . add ( t ) ;
}
1996-08-05 13:45:27 +00:00
// Stessa cosa per gli importi in genere
2000-05-05 15:25:49 +00:00
// if (scanner.key() == "IM")
// {
// TToken_string t;
// t.add(GROUP_IMPORTI);t.add(scanner.integer());t.add(scanner.integer());
// _group_decimals.add(t);
// }
1996-08-13 15:35:33 +00:00
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 ( ) , ' , ' ) ;
2004-03-22 11:59:28 +00:00
_exclude_array . add ( s ) ;
1996-08-13 15:35:33 +00:00
}
1995-10-09 15:47:28 +00:00
}
2002-02-26 16:20:19 +00:00
void TDocumento_form : : output_values ( const TRectype & rec , const char * output , TForm_item & cf )
{
TToken_string out ( output , ' ! ' ) ;
TString curr ;
for ( const char * str = out . get ( 0 ) ; str ; str = out . get ( ) )
{ // scansione sugli elementi dell'output
curr = str ;
int poseq = curr . find ( ' = ' ) ; // divide la stringa corrente in lvalue e rvalue
if ( poseq < 0 )
cf . set ( rec . get ( curr ) ) ;
else
{
int posrv = poseq + 1 ;
if ( poseq > = 0 & & curr [ posrv ] = = ' = ' )
posrv + + ;
TString16 fld ( curr . left ( poseq ) ) ; // preleva il nome del campo del form alla sinistra dell'uguale
const TString dat ( rec . get ( curr . mid ( posrv ) ) ) ; // preleva il nome del campo del file alla destra dell'uguale e lo legge dal record
if ( fld [ 0 ] = = ' # ' ) fld . ltrim ( 1 ) ;
if ( fld . right ( 1 ) = = " @ " )
{ // se c'<27> la a-commerciale <20> un gruppo
char sec = cf . section ( ) . section_type ( ) ;
pagetype pt = cf . section ( ) . page_type ( ) ;
int group = atoi ( fld ) ;
if ( fld . find ( " -> " ) > = 0 )
{ // se nel gruppo c'<27> la freccia si riferisce ad un'altra sezione
sec = fld [ 0 ] ;
pt = ( fld [ 1 ] ! = ' - ' ) ? char2page ( fld [ 1 ] ) : even_page ;
}
TPrint_section & fs = section ( sec , pt ) ;
word itms = fs . fields ( ) ;
for ( word j = 0 ; j < itms ; j + + )
{
TForm_item & fi = fs . field ( j ) ;
if ( fi . in_group ( group ) )
fi . set ( dat ) ;
}
}
else
{
TForm_item & fi = cf . find_field ( fld ) ;
fi . set ( dat ) ;
}
}
}
}
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 ) ) ;
2006-12-13 16:22:33 +00:00
return true ;
1997-08-29 16:42:42 +00:00
}
else
{
1995-09-28 15:26:35 +00:00
in . ltrim ( 1 ) ;
2005-02-17 18:13:12 +00:00
const 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 " ) ) ;
2006-12-13 16:22:33 +00:00
return true ;
1997-08-29 16:42:42 +00:00
}
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 " ) ) ;
2006-12-13 16:22:33 +00:00
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 " ) ) ;
2006-12-13 16:22:33 +00:00
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 " ) ) ;
2006-12-13 16:22:33 +00:00
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 " ) ) ;
2006-12-13 16:22:33 +00:00
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 " ) ) ;
2006-12-13 16:22:33 +00:00
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 " ) ) ;
2006-12-13 16:22:33 +00:00
return true ;
1997-08-29 16:42:42 +00:00
}
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 " ) ) ;
2006-12-13 16:22:33 +00:00
return true ;
1997-08-29 16:42:42 +00:00
}
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 ) ;
2006-12-13 16:22:33 +00:00
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 ) ;
2006-12-13 16:22:33 +00:00
return true ;
1995-09-28 15:26:35 +00:00
}
1997-08-29 16:42:42 +00:00
if ( in = = " REGSOC " )
{
1999-10-22 10:00:18 +00:00
valore = _firmrel [ LF_UNLOC ] . get ( " REGIMP " ) ;
valore . insert ( " " , 2 ) ; valore . insert ( " " , 6 ) ;
valore . insert ( " " , 11 ) ; valore . insert ( " " , 21 ) ;
valore . insert ( " Reg.Imp. " , 0 ) ;
1997-08-29 16:42:42 +00:00
cf . set ( valore ) ;
2006-12-13 16:22:33 +00:00
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 ( ) )
2000-05-05 15:25:49 +00:00
valore < < " del " < < data ;
cf . set ( valore ) ;
2006-12-13 16:22:33 +00:00
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
1998-11-04 18:04:26 +00:00
// !CAP Codice Avviamento Postale (viene implementato un messaggio perche' sugli occasionali ha un nome campo diverso!!)
1995-12-04 17:35:52 +00:00
// !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
1998-11-04 18:04:26 +00:00
TCli_for & cli_for = _doc - > clifor ( ) ;
TOccasionale & cli_occ = _doc - > occas ( ) ;
const bool occasionale = cli_for . occasionale ( ) ;
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 ] ! = ' ! ' )
1998-11-04 18:04:26 +00:00
{
// Controlla l'esistenza dei campi...
if ( occasionale & & cli_occ . exist ( in ) )
valore = cli_occ . get ( in ) ;
if ( ! occasionale & & cli_for . exist ( in ) )
valore = cli_for . get ( in ) ;
cf . set ( valore ) ;
2006-12-13 16:22:33 +00:00
return true ;
1997-08-29 16:42:42 +00:00
}
in . ltrim ( 1 ) ;
if ( in = = " INDNUM " )
{
1998-11-04 18:04:26 +00:00
valore = occasionale ? cli_occ . get ( OCC_INDIR ) : cli_for . get ( CLI_INDCF ) ;
valore < < " " ;
valore < < ( occasionale ? cli_occ . get ( OCC_CIV ) : cli_for . get ( CLI_CIVCF ) ) ;
1997-08-29 16:42:42 +00:00
cf . set ( valore ) ;
2006-12-13 16:22:33 +00:00
return true ;
1997-08-29 16:42:42 +00:00
}
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
{
2003-11-17 10:20:13 +00:00
com . put ( COM_STATO , occasionale ? cli_occ . get ( OCC_STATONASC ) : cli_for . get ( CLI_STATONASC ) ) ;
com . put ( COM_COM , occasionale ? cli_occ . get ( OCC_COMNASC ) : cli_for . get ( CLI_COMNASC ) ) ;
1997-08-29 16:42:42 +00:00
}
1997-06-12 16:26:22 +00:00
else
1997-08-29 16:42:42 +00:00
{
2003-11-17 10:20:13 +00:00
com . put ( COM_STATO , occasionale ? cli_occ . get ( OCC_STATO ) : cli_for . get ( CLI_STATOCF ) ) ;
com . put ( COM_COM , occasionale ? cli_occ . get ( OCC_COM ) : cli_for . get ( CLI_COMCF ) ) ;
1997-08-29 16:42:42 +00:00
}
if ( com . read ( ) = = NOERR )
cf . set ( com . get ( in ) ) ;
2006-12-13 16:22:33 +00:00
return true ;
1997-08-29 16:42:42 +00:00
}
1998-11-04 18:04:26 +00:00
if ( in . find ( " CAP " ) = = 0 )
{
valore = occasionale ? cli_occ . get ( OCC_CAP ) : cli_for . get ( CLI_CAPCF ) ;
cf . set ( valore ) ;
2006-12-13 16:22:33 +00:00
return true ;
1998-11-04 18:04:26 +00:00
}
1997-08-29 16:42:42 +00:00
if ( in . find ( " TEL " ) = = 0 )
{
1998-11-04 18:04:26 +00:00
if ( ! occasionale )
{
if ( in . len ( ) = = 3 )
in < < " 1 " ;
const TString num ( cli_for . get ( in ) ) ;
in . insert ( " P " ) ;
valore = cli_for . get ( in ) ;
valore < < " / " < < num ;
}
1997-08-29 16:42:42 +00:00
cf . set ( valore ) ;
2006-12-13 16:22:33 +00:00
return true ;
1997-08-29 16:42:42 +00:00
}
if ( in = = " FAX " )
{
1998-11-04 18:04:26 +00:00
if ( ! occasionale )
{
valore = cli_for . get ( " PFAX " ) ;
valore < < " / " < < cli_for . get ( " FAX " ) ;
}
1997-08-29 16:42:42 +00:00
cf . set ( valore ) ;
2006-12-13 16:22:33 +00:00
return true ;
1997-08-29 16:42:42 +00:00
}
if ( in = = " RAGSOC " )
{
1998-11-04 18:04:26 +00:00
valore = occasionale ? cli_occ . get ( in ) : cli_for . get ( in ) ;
2005-10-05 18:02:25 +00:00
valore . strip_double_spaces ( ) ;
1997-08-29 16:42:42 +00:00
cf . set ( valore ) ;
2006-12-13 16:22:33 +00:00
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
2003-12-15 14:25:45 +00:00
const TRectype & rdoc = cursor ( ) - > curr ( LF_RIGHEDOC ) ;
TString descrizione = rdoc . get ( RDOC_DESCR ) ;
const bool desclunga = rdoc . get_bool ( RDOC_DESCLUNGA ) ;
1997-06-03 10:29:42 +00:00
if ( desclunga )
{
2003-12-15 14:25:45 +00:00
const TString & dest = rdoc . get ( RDOC_DESCEST ) ;
if ( ! dest . blank ( ) )
descrizione < < dest ;
1999-04-06 15:34:39 +00:00
}
int nfields = s . items ( ) ;
for ( int j = 1 ; j < nfields ; j + + )
{
const TString & fld = s . get ( j ) ;
TForm_item & f = cf . find_field ( fld ) ;
const TString & val = f . get ( ) ;
2003-12-15 14:25:45 +00:00
if ( ! val . blank ( ) )
descrizione < < ' ' < < val ;
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 ( ) ;
2004-04-28 21:14:03 +00:00
int i ;
for ( i = 0 ; p . get ( ) ! = NULL & & i < h ; i + + ) ;
1997-08-29 16:42:42 +00:00
// cf.put_paragraph(descrizione);
1997-01-02 09:01:59 +00:00
// Setta l'altezza effettiva del body, per evitare sprechi di righe
1998-11-04 18:04:26 +00:00
cf . section ( ) . set_height ( p . empty ( ) ? 1 : i ) ;
2006-12-13 16:22:33 +00:00
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 )
{
2006-01-31 15:33:00 +00:00
byte selector = byte ( s . get_int ( ) ) ; // il primo parametro e' il selettore del tipo di codice
1996-08-13 15:35:33 +00:00
if ( selector ! = 0 )
{
_doc - > summary_filter ( selector ) ;
2006-01-31 15:33:00 +00:00
const TString4 what = s . get ( ) ; // cosa deve stampare ?
const TString value ( _doc - > summary_get ( what ) ) ; // Piglia il valore dalla riga selezionata sulla tabellina
1996-08-13 15:35:33 +00:00
2006-01-31 15:33:00 +00:00
if ( s . get_int ( ) = = 1 ) // deve cambiare elemento ?
_doc - > summary_set_next ( ) ;
1996-08-13 15:35:33 +00:00
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 " ) ;
2006-12-13 16:22:33 +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
2006-01-31 15:33:00 +00:00
const byte sel = ( byte ) s . get_int ( ) ;
const real x = sel = = 0 ? _doc - > imponibile ( true ) : _doc - > tot_imponibili ( sel ) ;
1997-01-02 09:01:59 +00:00
2006-12-13 16:22:33 +00:00
1997-08-29 16:42:42 +00:00
cf . set ( x . string ( ) ) ;
2006-12-13 16:22:33 +00:00
return true ;
1997-01-02 09:01:59 +00:00
} // 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 )
2002-02-26 16:20:19 +00:00
{
1997-01-02 09:01:59 +00:00
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
}
2006-12-13 16:22:33 +00:00
return true ;
1996-08-05 13:45:27 +00:00
}
1998-04-30 14:04:19 +00:00
1998-11-04 18:04:26 +00:00
if ( code = = " _EDITPICTURE " )
{
const int flds2set = s . items ( ) - 1 ;
2000-05-05 15:25:49 +00:00
// TString16 val(cursor()->file(LF_DOC).get(DOC_CODVAL));
// const bool valuta = val.not_empty() && val != "LIT";
const int ndec = _doc - > decimals ( ) ;
1998-11-04 18:04:26 +00:00
for ( int i = 1 ; i < = flds2set ; i + + )
{
const short fld = s . get_int ( i ) ;
2000-05-05 15:25:49 +00:00
edit_picture ( cf . section ( ) . find_field ( fld ) , ndec ) ;
1998-11-04 18:04:26 +00:00
}
2006-12-13 16:22:33 +00:00
return true ;
1998-11-04 18:04:26 +00:00
}
1999-04-06 15:34:39 +00:00
if ( code = = " _SEPARATOR " ) // Riempitore
{
TString sep ;
sep . fill ( ' - ' , s . get_int ( 1 ) ) ;
cf . set ( sep ) ;
2006-12-13 16:22:33 +00:00
return true ;
1999-04-06 15:34:39 +00:00
}
2000-05-05 15:25:49 +00:00
if ( code = = " _WEEK " | | code = = " _YEAR " )
{
const TString16 which ( s . get ( ) ) ;
TString16 data ;
2003-10-06 10:19:37 +00:00
if ( which = = RDOC_DATACONS )
2000-05-05 15:25:49 +00:00
{
2003-10-06 10:19:37 +00:00
const TRectype & rdoc = cursor ( ) - > curr ( LF_RIGHEDOC ) ;
2000-05-05 15:25:49 +00:00
data = rdoc . get ( which ) ;
}
if ( data . empty ( ) )
data = _doc - > get ( which ) ;
TDate d ( data ) ;
const char * c = s . get ( ) ;
bool complete = c ! = NULL & & * c ! = ' \0 ' ;
int week ;
int year ;
d . get_week_year ( week , year , complete ) ;
if ( code = = " _WEEK " )
cf . set ( data . format ( " %d " , week ) ) ;
else
cf . set ( data . format ( " %d " , year ) ) ;
2006-12-13 16:22:33 +00:00
return true ;
2000-05-05 15:25:49 +00:00
}
2002-02-26 16:20:19 +00:00
if ( code = = " _PARENTDOC " )
{
2003-10-06 10:19:37 +00:00
const TRectype * rdoc = & cursor ( ) - > curr ( LF_RIGHEDOC ) ;
2003-12-16 14:37:26 +00:00
// Se il campo corrente non appartiene al body allora cerco la prima riga documento buona!
if ( cf . section ( ) . section_type ( ) ! = ' B ' )
{
const TDocumento & doc = ( const TDocumento & ) cursor ( ) - > curr ( ) ;
2004-02-06 13:51:56 +00:00
const TRiga_documento * first_merc = NULL ;
const TRiga_documento * first_desc = NULL ;
2004-02-23 15:08:07 +00:00
for ( int r = 1 ; r < = doc . physical_rows ( ) ; r + + )
2003-12-16 14:37:26 +00:00
{
const TRiga_documento & row = doc [ r ] ;
if ( row . get ( RDOC_DANDOC ) . not_empty ( ) )
{
2004-02-06 13:51:56 +00:00
if ( row . is_descrizione ( ) )
{
if ( first_desc = = NULL )
first_desc = & row ; // Non e' una riga buona, ma nemmeno da buttare!
}
else
{
first_merc = & row ;
break ; // Ho trovato la riga buona!
}
2003-12-16 14:37:26 +00:00
}
}
2004-02-06 13:51:56 +00:00
if ( first_merc ! = NULL )
rdoc = first_merc ;
else
{
if ( first_desc ! = NULL )
rdoc = first_desc ;
}
2003-12-16 14:37:26 +00:00
}
int level = s . get_int ( 1 ) ;
2002-02-26 16:20:19 +00:00
for ( ; rdoc ! = NULL & & level > 0 ; level - - )
2003-10-06 10:19:37 +00:00
rdoc = ( ( const TRiga_documento * ) rdoc ) - > find_original_rdoc ( ) ;
2002-02-26 16:20:19 +00:00
if ( rdoc ! = NULL & & rdoc - > get ( RDOC_PROVV ) . not_empty ( ) )
{
2003-10-06 10:19:37 +00:00
const char provv = rdoc - > get_char ( RDOC_PROVV ) ;
const int anno = rdoc - > get_int ( RDOC_ANNO ) ;
2003-12-16 14:37:26 +00:00
const TString4 codnum = rdoc - > get ( RDOC_CODNUM ) ;
2003-10-06 10:19:37 +00:00
const long ndoc = rdoc - > get_long ( RDOC_NDOC ) ;
2002-02-26 16:20:19 +00:00
if ( s . get ( 3 ) ! = NULL ) // "FULL"
{
2003-10-06 10:19:37 +00:00
TDocumento doc ( provv , anno , codnum , ndoc ) ;
2002-02-26 16:20:19 +00:00
output_values ( doc , s . get ( 2 ) , cf ) ;
}
else
{
TToken_string key ;
key . add ( provv ) ;
key . add ( anno ) ;
key . add ( codnum ) ;
key . add ( ndoc ) ;
const TRectype & doc = cache ( ) . get ( LF_DOC , key ) ;
output_values ( doc , s . get ( 2 ) , cf ) ;
}
}
2006-12-13 16:22:33 +00:00
return true ;
2002-02-26 16:20:19 +00:00
}
if ( code = = " _PARENTROW " )
{
const TRectype * rdoc = & cursor ( ) - > file ( LF_RIGHEDOC ) . curr ( ) ;
int level = s . get_int ( 1 ) ;
for ( ; rdoc ! = NULL & & level > 0 ; level - - )
rdoc = ( ( const TRiga_documento * ) rdoc ) - > find_original_rdoc ( ) ;
if ( rdoc ! = NULL & & rdoc - > get ( RDOC_PROVV ) . not_empty ( ) )
{
if ( s . get ( 3 ) ! = NULL ) // "FULL"
{
2003-10-06 10:19:37 +00:00
const char provv = rdoc - > get_char ( RDOC_PROVV ) ;
const int anno = rdoc - > get_int ( RDOC_ANNO ) ;
2003-12-16 14:37:26 +00:00
const TString4 codnum = rdoc - > get ( RDOC_CODNUM ) ;
2003-10-06 10:19:37 +00:00
const long ndoc = rdoc - > get_long ( RDOC_NDOC ) ;
2002-02-26 16:20:19 +00:00
TDocumento doc ( provv , anno , codnum , ndoc ) ;
output_values ( doc [ rdoc - > get_int ( RDOC_NRIGA ) ] , s . get ( 2 ) , cf ) ;
}
else
output_values ( * rdoc , s . get ( 2 ) , cf ) ;
}
2006-12-13 16:22:33 +00:00
return true ;
2002-02-26 16:20:19 +00:00
}
1999-04-06 15:34:39 +00:00
if ( code = = " _LISTADOC " ) // Messaggio per riepilogo lista documenti
{
const TString16 what ( s . get ( 1 ) ) ;
TString16 which ( s . get ( 2 ) ) ;
if ( what = = " STORE " )
{
if ( which [ 0 ] = = ' # ' )
which . ltrim ( 1 ) ; // Toglie il #
const TString16 codnum ( cf . section ( ) . find_field ( atoi ( which ) ) . get ( ) ) ;
const real r ( cf . get ( ) ) ;
1999-05-24 13:34:11 +00:00
real * v = ( real * ) _doc_totals . objptr ( codnum ) ;
if ( v = = NULL )
{
v = new real ( ZERO ) ;
_doc_totals . add ( codnum , v ) ;
}
if ( _doc - > is_nota_credito ( ) )
* v - = r ;
else
1999-04-06 15:34:39 +00:00
* v + = r ;
1999-06-18 15:35:05 +00:00
} else
if ( what = = " ADDTOT " )
{
const real r = cf . get ( ) ;
if ( ! r . is_zero ( ) )
{
TForm_item & tot = cf . find_field ( which ) ;
real v = tot . get ( ) ;
if ( _doc - > is_nota_credito ( ) )
v - = r ;
else
v + = r ;
tot . set ( v . string ( ) ) ;
}
1999-04-06 15:34:39 +00:00
}
else
{
TString_array k ;
_doc_totals . get_keys ( k ) ;
const int index = atoi ( which ) - 1 ;
if ( index < k . items ( ) )
{
TString16 codnum ( k . row ( index ) ) ;
if ( what = = " CODICE " )
cf . set ( codnum ) ;
else
if ( what = = " TOTALE " )
{
real & r = ( real & ) _doc_totals [ codnum ] ;
cf . set ( r . string ( ) ) ;
}
}
}
2006-12-13 16:22:33 +00:00
return true ;
1999-04-06 15:34:39 +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
1999-04-06 15:34:39 +00:00
class TStampaDoc_application : public TSkeleton_application
1997-01-02 09:01:59 +00:00
{
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
1998-08-25 18:07:30 +00:00
TMask * _selection_mask ;
2002-02-26 16:20:19 +00:00
TRelation * _clifo_rel ;
TCursor * _clifo_cur ;
TCursor_sheet * _clifo_sheet ; // Array sheet per la selezione cli/fo
1998-11-04 18:04:26 +00:00
TAssoc_array _clifo_sel ; // Assoc array con solo i cli/fo selezionati. Facilita il filtro...
1997-07-28 14:16:44 +00:00
1997-01-02 09:01:59 +00:00
protected :
virtual bool create ( ) ;
virtual bool destroy ( ) ;
1999-04-06 15:34:39 +00:00
virtual void main_loop ( ) ;
1997-01-02 09:01:59 +00:00
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
2003-02-25 14:39:02 +00:00
void set_filter ( TDocumento_form & frm ) ;
1997-01-02 09:01:59 +00:00
static bool date2num_handler ( TMask_field & f , KEY key ) ;
static bool range_handler ( TMask_field & f , KEY key ) ;
1998-11-04 18:04:26 +00:00
static bool tipocf_handler ( TMask_field & f , KEY k ) ;
static bool fr_cod_handler ( TMask_field & f , KEY k ) ;
static bool to_cod_handler ( TMask_field & f , KEY k ) ;
static bool select_button ( TMask_field & f , KEY k ) ;
static bool reset_button ( TMask_field & f , KEY k ) ;
2002-12-20 16:15:03 +00:00
static bool tipodoc_handler ( TMask_field & f , KEY k ) ;
1998-11-04 18:04:26 +00:00
static bool filter_clifo ( const TRelation * r ) ;
2003-11-17 10:20:13 +00:00
long select_cod_range ( long from , long to ) ;
void reset_choices ( TMask & m ) ;
void set_choice_limits ( TMask & m ) ;
void build_clifo_list ( const char c = ' C ' ) ;
int numerazione_definitiva ( TDocumento & doc ) const ;
1998-11-04 18:04:26 +00:00
1997-01-02 09:01:59 +00:00
public :
2003-02-25 14:39:02 +00:00
void print_documento ( TDocumento_form & frm ) ;
1997-01-02 09:01:59 +00:00
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 ( ) { } ;
} ;
1998-11-04 18:04:26 +00:00
inline TStampaDoc_application & app ( ) { return ( TStampaDoc_application & ) main_app ( ) ; }
1997-01-02 09:01:59 +00:00
2003-11-17 10:20:13 +00:00
int TStampaDoc_application : : numerazione_definitiva ( TDocumento & doc ) const
{
int err = NOERR ;
if ( doc . get_char ( DOC_PROVV ) = = ' D ' ) // Se e' una numerazione definitiva
{
if ( doc . stampabile ( ) ) // Controlla se non e' gia' nello stato si stampato in definitiva
{
2006-12-13 16:22:33 +00:00
const char sfs = doc . tipo ( ) . stato_finale_stampa ( ) ;
doc . stato ( sfs ) ; // Se e' gia' in definitiva aggiorna solo lo stato
2003-11-17 10:20:13 +00:00
err = doc . rewrite ( ) ;
2006-12-13 16:22:33 +00:00
2003-11-17 10:20:13 +00:00
// Invia la transazione di cambio stato se necessario
if ( : : can_dispatch_transaction ( doc ) )
{
TFilename tmpname ; tmpname . temp ( ) ;
{ // Parentesi strategiche
TConfig ini ( tmpname , " Transaction " ) ;
ini . set ( " Action " , " MODIFY " ) ;
ini . set ( " Firm " , prefix ( ) . get_codditta ( ) ) ;
ini . set ( " Mode " , " A " ) ;
TString8 paradoc ; paradoc . format ( " %d " , LF_DOC ) ;
ini . set_paragraph ( paradoc ) ;
ini . set ( DOC_PROVV , doc . get ( DOC_PROVV ) ) ;
ini . set ( DOC_ANNO , doc . get ( DOC_ANNO ) ) ;
ini . set ( DOC_CODNUM , doc . get ( DOC_CODNUM ) ) ;
ini . set ( DOC_NDOC , doc . get ( DOC_NDOC ) ) ;
ini . set ( DOC_STATO , doc . stato ( ) ) ;
}
: : dispatch_transaction ( doc , tmpname ) ;
: : remove ( tmpname ) ;
}
}
}
else // Se e' una numerazione provvisoria
{
// Scrive il nuovo documento con lo stato, numero e flag di definitiva
TDocumento bak_doc ;
bak_doc = doc ; // Setta il flag di nuovo documento
bak_doc . put ( DOC_STATO , doc . tipo ( ) . stato_finale_stampa ( ) ) ;
bak_doc . put ( DOC_PROVV , " D " ) ;
bak_doc . put ( DOC_NDOC , - 1L ) ;
const int pr = bak_doc . physical_rows ( ) ;
for ( int i = 1 ; i < = pr ; i + + )
bak_doc [ i ] . put ( DOC_PROVV , " D " ) ;
err = bak_doc . write ( ) ; // Esegue automagicamente rinumerazione di testata e righe nel caso di reinsert
if ( err = = NOERR ) // Cancella il vecchio documento
doc . remove ( ) ;
}
return err ;
}
1997-01-02 09:01:59 +00:00
void TStampaDoc_application : : print_selected ( )
{
TRelation rel ( LF_DOC ) ;
rel . add ( LF_RIGHEDOC , " CODNUM==CODNUM|ANNO==ANNO|PROVV==PROVV|NDOC==NDOC " ) ;
TCursor cur ( & rel ) ;
cur . setkey ( _key ) ;
1998-11-04 18:04:26 +00:00
TLocalisamfile & doc = cur . file ( ) ;
1997-01-02 09:01:59 +00:00
TRectype darec ( LF_DOC ) , arec ( LF_DOC ) ; // Estremi filtro
TString modulo_prec ;
const bool order_by_num = _key = = BY_NUM_KEY ;
1998-11-04 18:04:26 +00:00
if ( ! _is_lista )
1998-08-25 18:07:30 +00:00
{
1998-11-04 18:04:26 +00:00
doc . put ( DOC_CODNUM , _codnum ) ; // compone la chiave per il record di inizio cursore
doc . put ( DOC_ANNO , _anno ) ;
doc . put ( DOC_PROVV , _provv ) ;
arec = doc . curr ( ) ;
if ( order_by_num )
doc . put ( DOC_NDOC , _dalnum ) ;
else
doc . put ( DOC_DATADOC , _dadata ) ;
//doc.setkey(_key);
doc . read ( ) ; // trova il record iniziale
darec = doc . curr ( ) ;
doc . curr ( ) = arec ;
if ( order_by_num )
{
doc . put ( DOC_NDOC , _alnum ) ;
if ( doc . read ( ) = = _iskeynotfound ) // trova il record finale
doc . prev ( ) ;
}
else
{
doc . put ( DOC_DATADOC , _adata ) ; // trova il record finale
doc . put ( DOC_NDOC , 999999L ) ;
int err = doc . read ( _isgteq ) ;
if ( err = = NOERR )
err = doc . prev ( ) ;
}
arec = doc . curr ( ) ;
if ( arec < darec )
{
error_box ( " Non vi sono documenti da stampare nell'intervallo indicato " ) ;
return ;
}
_definitiva = query_final_print ( ) ; // legge il flag di stampa definitiva
1998-08-25 18:07:30 +00:00
}
1997-01-02 09:01:59 +00:00
TPrinter & pr = printer ( ) ;
pr . open ( ) ;
TProgind * pi = pr . printtype ( ) ! = screenvis ?
2006-12-13 16:22:33 +00:00
new TProgind ( cur . items ( ) , TR ( " Stampa documenti in corso... " ) , false , true ) :
1997-01-02 09:01:59 +00:00
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 ) ;
2000-10-03 13:45:12 +00:00
if ( ! order_by_num )
{
TString80 filter ;
filter . format ( " (CODNUM== \" %s \" )&&(PROVV== \" %c \" ) " , ( const char * ) _codnum , _provv ) ;
cur . setfilter ( filter ) ;
}
1997-03-10 14:51:08 +00:00
const long items = cur . items ( ) ;
behaviour whattodo = go ;
2006-12-13 16:22:33 +00:00
bool first_inst = true ;
1998-04-30 14:04:19 +00:00
real totdocumenti = ZERO ;
1997-03-10 14:51:08 +00:00
//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
2003-02-25 14:39:02 +00:00
// Istanzia il form principale
2006-12-13 16:22:33 +00:00
TDocumento_form * mainform = new TDocumento_form ( cur . curr ( ) , * _firmrel , _definitiva , _interattivo , false ) ;
2004-11-30 22:02:59 +00:00
if ( ! mainform - > valid ( ) )
break ; // interrompe la stampa se il doc corrente non e' tra i tipi validi
2003-02-25 14:39:02 +00:00
2004-11-30 22:02:59 +00:00
const TString & modulo = mainform - > 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
2006-12-13 16:22:33 +00:00
first_inst = false ;
2004-11-30 22:02:59 +00:00
const bool module_changed = modulo ! = modulo_prec ;
if ( first_inst | | module_changed )
2003-02-25 14:39:02 +00:00
if ( ! mainform - > doc_arrange ( ) ) // Setta l'offset o posiziona manualmente
1997-03-10 14:51:08 +00:00
break ; // Se vi sono errori interrompe la stampa
2004-11-30 22:02:59 +00:00
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
2003-02-25 14:39:02 +00:00
int ncopie = _ncopie < = 0 ? mainform - > ncopie ( ) : _ncopie ; // Numero di copie da stampare per questo documento
1999-04-06 15:34:39 +00:00
if ( ncopie < = 0 ) ncopie = 1 ;
1997-03-10 14:51:08 +00:00
for ( int n = 0 ; n < ncopie ; n + + )
{
2003-02-25 14:39:02 +00:00
TDocumentoEsteso & extdoc = mainform - > doc ( ) ;
2004-11-30 22:02:59 +00:00
print_documento ( * mainform ) ;
2003-02-25 14:39:02 +00:00
extdoc . summary_reset ( ) ;
extdoc . scadenze_reset ( ) ;
// Stampa eventuali documenti allegati
2006-07-11 16:22:58 +00:00
TFilename formagg ;
extdoc . tipo ( ) . additional_print_profile ( formagg ) ;
2006-07-11 13:12:41 +00:00
const int ncopie2 = extdoc . tipo ( ) . get_int ( " I2 " ) ;
2005-11-15 12:04:34 +00:00
2006-07-11 13:12:41 +00:00
if ( ! formagg . blank ( ) & & ncopie2 > 0 ) // Se esiste un tipo documento da accodare
{
2006-12-13 16:22:33 +00:00
TDocumento_form * secform = new TDocumento_form ( cur . curr ( ) , * _firmrel , _definitiva , _interattivo , true ) ;
2006-07-11 13:12:41 +00:00
if ( secform - > valid ( ) )
{
for ( int i = 0 ; i < ncopie2 ; i + + )
{
print_documento ( * secform ) ;
extdoc . summary_reset ( ) ;
extdoc . scadenze_reset ( ) ;
}
}
delete secform ;
2003-02-25 14:39:02 +00:00
}
1997-03-10 14:51:08 +00:00
}
1998-04-30 14:04:19 +00:00
2000-05-05 15:25:49 +00:00
// se la stampa <20> definitiva viene lanciata la procedura di rinumerazione
if ( _definitiva & & _interattivo )
{
2003-02-25 14:39:02 +00:00
if ( numerazione_definitiva ( mainform - > doc ( ) ) ! = NOERR )
2000-05-05 15:25:49 +00:00
{
2003-06-19 14:35:45 +00:00
error_box ( FR ( " Non <20> possibile completare la procedura di numerazione definitiva dei documenti. Errore %d " ) , doc . status ( ) ) ;
2000-05-05 15:25:49 +00:00
break ;
}
1997-03-10 14:51:08 +00:00
}
2000-05-05 15:25:49 +00:00
1998-04-30 14:04:19 +00:00
// Totalizza gli importi per eventuale stampa su FAKETOTFLD
2003-02-25 14:39:02 +00:00
totdocumenti + = mainform - > doc ( ) . totale_doc ( ) ;
if ( i = = items - 1 & & mainform - > is_faketotfld ( ) )
1998-04-30 14:04:19 +00:00
{
2003-02-25 14:39:02 +00:00
mainform - > hide_sections ( ) ;
TForm_item & fk = mainform - > find_field ( ' F ' , last_page , FAKETOTFLD ) ;
1998-04-30 14:04:19 +00:00
fk . show ( ) ;
fk . set ( totdocumenti . string ( ) ) ;
2003-02-25 14:39:02 +00:00
print_documento ( * mainform ) ;
1998-04-30 14:04:19 +00:00
}
2000-05-05 15:25:49 +00:00
2003-02-25 14:39:02 +00:00
delete mainform ;
1997-01-02 09:01:59 +00:00
}
1997-03-10 14:51:08 +00:00
}
else // Lista documenti
{
2003-02-25 14:39:02 +00:00
TDocumento_form * mainform = new TDocumento_form ( LISTADOC , * _firmrel ) ;
2003-06-24 12:55:12 +00:00
TCursor & cur = * mainform - > cursor ( ) ;
cur . setkey ( _key ) ;
1998-11-04 18:04:26 +00:00
darec . put ( DOC_DATADOC , _dadata ) ;
darec . put ( DOC_PROVV , _provv ) ;
darec . put ( DOC_ANNO , _anno ) ;
arec = darec ;
arec . put ( DOC_DATADOC , _adata ) ;
2003-06-24 12:55:12 +00:00
cur . setregion ( darec , arec ) ;
1999-04-06 15:34:39 +00:00
const bool dettaglio = _selection_mask - > get_bool ( F_DETTAGLIO ) ;
2003-02-25 14:39:02 +00:00
mainform - > find_field ( ' B ' , odd_page , " H_RIGHE " ) . enable ( dettaglio ) ; // Visualizza i dettagli righe se richiesto
mainform - > find_field ( ' B ' , odd_page , " RIGHE " ) . enable ( dettaglio ) ;
1999-04-06 15:34:39 +00:00
2003-02-25 14:39:02 +00:00
set_filter ( * mainform ) ;
2003-06-24 12:55:12 +00:00
const TRecnotype items = cur . items ( ) ;
if ( items > 0 )
{
cur . freeze ( ) ;
mainform - > set_doc_ext ( NULL ) ; // Setta il documento esteso DOPO aver fatto il filtro
2003-02-25 14:39:02 +00:00
mainform - > print ( ) ;
2003-06-24 12:55:12 +00:00
}
2003-02-25 14:39:02 +00:00
delete mainform ;
1997-01-02 09:01:59 +00:00
}
if ( pi ! = NULL ) delete pi ;
printer ( ) . close ( ) ;
}
2003-02-25 14:39:02 +00:00
void TStampaDoc_application : : print_documento ( TDocumento_form & f )
1997-01-02 09:01:59 +00:00
{
2003-10-23 10:33:56 +00:00
const TRectype & doc = f . cursor ( ) - > curr ( ) ;
1997-01-02 09:01:59 +00:00
const bool is_vis = printer ( ) . printtype ( ) = = screenvis ;
if ( ! is_vis )
{
2003-10-23 10:33:56 +00:00
TString80 status ( TR ( " Documento: " ) ) ;
1997-01-02 09:01:59 +00:00
status < < doc . get ( DOC_CODNUM ) ;
status < < ' \\ ' < < doc . get ( DOC_NDOC ) ;
2005-10-05 18:02:25 +00:00
xvtil_statbar_set ( status ) ;
1997-01-02 09:01:59 +00:00
}
f . print_documento ( ) ;
if ( ! is_vis )
2005-10-05 18:02:25 +00:00
xvtil_statbar_set ( NULL ) ;
1997-01-02 09:01:59 +00:00
}
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
2003-06-19 14:35:45 +00:00
int risp = yesnocancel_box ( FR ( " Il modulo di carta <20> cambiato: inserire il modulo '%s' e premere 'Si' per continuare, "
" 'No' per saltare il documento o 'Annulla' per interrompere la stampa " ) , ( const char * ) modulo ) ;
1997-01-02 09:01:59 +00:00
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 :
2004-04-28 21:14:03 +00:00
default :
1997-01-02 09:01:59 +00:00
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
2006-12-13 16:22:33 +00:00
if ( yesno_box ( TR ( " E' una stampa definitiva? " ) ) ) return true ;
else return false ;
1997-01-02 09:01:59 +00:00
} else return _definitiva ; // altrimenti ritorna il valore letto dalla linea di comando
}
2003-02-25 14:39:02 +00:00
void TStampaDoc_application : : set_filter ( TDocumento_form & frm )
1998-11-04 18:04:26 +00:00
{
2003-02-25 14:39:02 +00:00
TCursor * cur = frm . cursor ( ) ;
1998-11-04 18:04:26 +00:00
TString filtro , e1 , e2 , sw ;
// Compone la lista dei clienti/forntitori selezionati
_clifo_sel . destroy ( ) ;
TString16 key ;
const long items = _clifo_sheet - > items ( ) ;
for ( long i = 0L ; i < items ; i + + )
if ( _clifo_sheet - > checked ( i ) )
{
key . format ( " %06ld " , _clifo_sheet - > row ( i ) . get_long ( 1 ) ) ; // Formatta il codice
_clifo_sel . add ( key , NULL ) ;
}
// NB: se _clifo_sel non contiene nulla, non viene effettuato alcun filtro su CLI/FO (non setta la funzione!!)
filtro . format ( " TIPOCF== \" %c \" " , _selection_mask - > get ( F_TIPOCF ) [ 0 ] ) ;
1999-04-06 15:34:39 +00:00
const int selval = _selection_mask - > get_int ( F_SELVAL ) ;
const TString16 val = _selection_mask - > get ( F_VALUTA ) ;
2000-05-05 15:25:49 +00:00
const int ndec = TCurrency : : get_firm_dec ( ) ;
2003-02-25 14:39:02 +00:00
frm . edit_picture ( frm . find_field ( ' F ' , last_page , 6 ) , ndec ) ; // pictures per totali finali
frm . edit_picture ( frm . find_field ( ' F ' , last_page , 8 ) , ndec ) ;
frm . edit_picture ( frm . find_field ( ' F ' , last_page , 10 ) , ndec ) ;
frm . edit_picture ( frm . find_field ( ' F ' , last_page , 12 ) , ndec ) ;
frm . edit_picture ( frm . find_field ( ' F ' , last_page , 16 ) , ndec ) ;
frm . edit_picture ( frm . find_field ( ' F ' , last_page , 17 ) , ndec ) ;
1999-04-06 15:34:39 +00:00
if ( selval = = 1 ) //In Lire
{
2000-05-05 15:25:49 +00:00
const TString16 firm_val ( TCurrency : : get_firm_val ( ) ) ;
const bool not_empty = firm_val . not_empty ( ) ;
filtro < < " && " ;
if ( not_empty )
filtro < < " ((CODVAL== \" " < < firm_val < < " \" )|| " ;
filtro < < " (CODVAL== \" \" ) " ;
if ( not_empty )
filtro < < " ) " ;
1999-04-06 15:34:39 +00:00
}
else
if ( selval = = 2 ) // nella valuta specificata
2000-05-05 15:25:49 +00:00
filtro < < " &&(CODVAL== \" " < < val < < " \" ) " ;
1999-04-06 15:34:39 +00:00
else
2003-02-25 14:39:02 +00:00
frm . find_field ( ' B ' , odd_page , 35 ) . set ( " 1 " ) ; // Cosi' effettua i totali generali in lire ?????
1999-04-06 15:34:39 +00:00
1998-11-04 18:04:26 +00:00
// Compone l'espressione filtro...
// prende tutte le righe dello spreasheet che non sono totalmente vuote:
// (CODNUM=="xxx"&&(STATO=="x"||STATO=="y"||STATO=="z"...)) ---> questo per una singola riga...
// se vi sono piu' righe, lo si ripete aggiungendo prima un bellissimo "||"
2006-12-13 16:22:33 +00:00
bool put_parentheses = false ;
1998-11-04 18:04:26 +00:00
TSheet_field & sf = ( TSheet_field & ) _selection_mask - > field ( F_SHEETNUMS ) ;
const int rows = sf . items ( ) ;
for ( int j = 0 ; j < rows ; j + + )
{
TToken_string & riga = sf . row ( j ) ;
sw = riga . get ( 0 ) ; sw . trim ( ) ;
if ( riga . empty_items ( ) | | sw . empty ( ) )
break ; // Interrompe alla prima riga vuota...
2002-12-20 16:15:03 +00:00
e1 . format ( " ((CODNUM== \" %s \" ) " , ( const char * ) sw ) ;
TString4 td = riga . get ( 1 ) ; td . trim ( ) ;
if ( td . not_empty ( ) )
{
e1 < < " &&(TIPODOC== \" " < < td < < " \" ) " ;
}
1998-11-04 18:04:26 +00:00
e2 = " " ;
2002-12-20 16:15:03 +00:00
for ( int k = 2 ; k < = 7 ; k + + ) // Famme vede' li stati generali... Aho' A BURINO! Che e' la Rivoluzione Francese?
1998-11-04 18:04:26 +00:00
{
const char c = riga . get ( k ) [ 0 ] ;
if ( c = = ' \0 ' | | c = = ' ' )
break ; // Interrompe al primo blank...
e2 . format ( " (STATO== \" %c \" ) " , c ) ;
2002-12-20 16:15:03 +00:00
// Se k vale 3 o piu' significa ke gli stati prec erano != "" no!?
if ( k = = 2 )
1998-11-04 18:04:26 +00:00
e1 < < " &&( " ;
else
e1 < < " || " ;
e1 < < e2 ;
}
if ( e2 . not_empty ( ) )
e1 < < " ) " ;
e1 < < " ) " ; // Piazza la parentesi finale
1999-04-06 15:34:39 +00:00
2006-12-13 16:22:33 +00:00
put_parentheses = true ;
1998-11-04 18:04:26 +00:00
if ( j = = 0 )
filtro < < " &&( " ;
else
filtro < < " || " ;
filtro < < e1 ;
}
1999-04-06 15:34:39 +00:00
if ( put_parentheses )
1998-11-04 18:04:26 +00:00
filtro < < " ) " ; // Parentesi finale
cur - > setfilter ( filtro ) ;
cur - > set_filterfunction ( _clifo_sheet - > checked ( ) > 0 ? filter_clifo : NULL ) ;
}
////////////////////////////////////////////////////////////////
// Handlers della maschera
////////////////////////////////////////////////////////////////
long TStampaDoc_application : : select_cod_range ( long from , long to )
2002-02-26 16:20:19 +00:00
{
TWait_cursor hourglass ;
if ( to < = 0l ) to = 999999L ;
1998-11-04 18:04:26 +00:00
for ( int i = 0 ; i < _clifo_sheet - > items ( ) ; i + + )
{
TToken_string & c = _clifo_sheet - > row ( i ) ;
const long cod = c . get_long ( 1 ) ;
if ( cod > = from & & cod < = to )
_clifo_sheet - > check ( i ) ;
else
_clifo_sheet - > uncheck ( i ) ;
}
return _clifo_sheet - > checked ( ) ;
}
void TStampaDoc_application : : build_clifo_list ( const char c )
2002-02-26 16:20:19 +00:00
{
// Semplice ed efficace
TRectype rec ( LF_CLIFO ) ;
rec . put ( CLI_TIPOCF , c ) ;
_clifo_cur - > setregion ( rec , rec ) ;
1998-11-04 18:04:26 +00:00
}
bool TStampaDoc_application : : tipocf_handler ( TMask_field & f , KEY key )
{
if ( f . to_check ( key ) & & key = = K_TAB )
{
2002-07-30 14:11:47 +00:00
TWait_cursor hourglass ;
1998-11-04 18:04:26 +00:00
app ( ) . reset_choices ( f . mask ( ) ) ;
app ( ) . build_clifo_list ( f . get ( ) [ 0 ] ) ;
}
2006-12-13 16:22:33 +00:00
return true ;
1998-11-04 18:04:26 +00:00
}
bool TStampaDoc_application : : fr_cod_handler ( TMask_field & f , KEY key )
{
TMask & m = f . mask ( ) ;
if ( key = = K_F9 )
{
TMask & m = f . mask ( ) ;
2002-02-26 16:20:19 +00:00
TCursor_sheet * sh = app ( ) . _clifo_sheet ;
1998-11-04 18:04:26 +00:00
sh - > disable_check ( ) ;
sh - > disable ( DLG_USER ) ;
if ( sh - > run ( ) = = K_ENTER )
{
app ( ) . select_cod_range ( sh - > row ( sh - > selected ( ) ) . get_long ( 1 ) , m . get_long ( F_CODTO ) ) ;
app ( ) . set_choice_limits ( m ) ;
}
sh - > enable ( DLG_USER ) ;
}
else if ( key = = K_TAB & & f . focusdirty ( ) )
{
const long l = app ( ) . select_cod_range ( m . get_long ( F_CODFR ) , m . get_long ( F_CODTO ) ) ;
app ( ) . set_choice_limits ( m ) ;
m . set ( F_SELECTED , l ) ;
}
2006-12-13 16:22:33 +00:00
return true ;
1998-11-04 18:04:26 +00:00
}
bool TStampaDoc_application : : to_cod_handler ( TMask_field & f , KEY key )
{
TMask & m = f . mask ( ) ;
if ( key = = K_F9 )
{
2002-02-26 16:20:19 +00:00
TCursor_sheet * sh = app ( ) . _clifo_sheet ;
1998-11-04 18:04:26 +00:00
TMask & m = f . mask ( ) ;
sh - > disable_check ( ) ;
sh - > disable ( DLG_USER ) ;
if ( sh - > run ( ) = = K_ENTER )
{
app ( ) . select_cod_range ( m . get_long ( F_CODFR ) , sh - > row ( sh - > selected ( ) ) . get_long ( 1 ) ) ;
app ( ) . set_choice_limits ( m ) ;
}
sh - > enable ( DLG_USER ) ;
}
if ( key = = K_TAB & & f . focusdirty ( ) )
{
const long l = app ( ) . select_cod_range ( m . get_long ( F_CODFR ) ,
m . get_long ( F_CODTO ) ) ;
app ( ) . set_choice_limits ( m ) ;
m . set ( F_SELECTED , l ) ;
}
2006-12-13 16:22:33 +00:00
return true ;
1998-11-04 18:04:26 +00:00
}
bool TStampaDoc_application : : select_button ( TMask_field & f , KEY key )
{
if ( key = = K_SPACE )
{
app ( ) . _clifo_sheet - > enable_check ( ) ;
if ( app ( ) . _clifo_sheet - > run ( ) = = K_ENTER )
app ( ) . set_choice_limits ( f . mask ( ) ) ;
}
2006-12-13 16:22:33 +00:00
return true ;
1998-11-04 18:04:26 +00:00
}
void TStampaDoc_application : : reset_choices ( TMask & m )
{
2004-06-08 13:13:27 +00:00
m . reset ( F_SELECTED ) ;
m . reset ( F_CODFR ) ;
m . reset ( F_CODTO ) ;
2006-12-13 16:22:33 +00:00
_clifo_sheet - > check ( - 1 , false ) ;
1998-11-04 18:04:26 +00:00
}
bool TStampaDoc_application : : reset_button ( TMask_field & f , KEY key )
{
if ( key = = K_SPACE )
app ( ) . reset_choices ( f . mask ( ) ) ;
2006-12-13 16:22:33 +00:00
return true ;
1998-11-04 18:04:26 +00:00
}
void TStampaDoc_application : : set_choice_limits ( TMask & m )
2002-02-26 16:20:19 +00:00
{
TWait_cursor hourglass ;
1998-11-04 18:04:26 +00:00
long first = - 1l , last = - 1l ;
for ( int i = 0 ; i < _clifo_sheet - > items ( ) ; i + + )
{
if ( _clifo_sheet - > checked ( i ) )
{
const long cf = _clifo_sheet - > row ( i ) . get_long ( 1 ) ;
if ( first = = - 1l )
first = cf ;
if ( last < cf )
last = cf ;
}
}
if ( first ! = - 1 )
m . set ( F_CODFR , first ) ;
if ( last ! = - 1 )
m . set ( F_CODTO , last ) ;
m . set ( F_SELECTED , _clifo_sheet - > checked ( ) ) ;
}
1997-01-02 09:01:59 +00:00
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 ) ;
}
}
}
2006-12-13 16:22:33 +00:00
return true ;
1996-06-27 09:37:32 +00:00
}
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
{
2006-12-13 16:22:33 +00:00
bool rt = true ;
2004-04-28 21:14:03 +00:00
1996-08-05 13:45:27 +00:00
if ( key = = K_TAB & & f . focusdirty ( ) )
{
const long lim_sup = atol ( f . get ( ) ) ;
1998-05-04 09:54:49 +00:00
const long lim_inf = f . mask ( ) . get_long ( F_DA_NDOC ) ;
1996-08-05 13:45:27 +00:00
if ( lim_sup < lim_inf )
2003-06-19 14:35:45 +00:00
rt = f . error_box ( TR ( " Il limite superiore deve essere maggiore del limite inferiore " ) ) ;
1996-08-05 13:45:27 +00:00
}
return rt ;
}
2002-12-20 16:15:03 +00:00
bool TStampaDoc_application : : tipodoc_handler ( TMask_field & f , KEY key )
{
TMask & m = f . mask ( ) ;
switch ( key )
{
case K_F9 : //caso del bottone di selezione
{
2003-06-19 14:35:45 +00:00
TArray_sheet as ( - 1 , - 1 , 70 , 20 , TR ( " Tipi documento " ) , " Codice|Descrizione@50 " ) ; //costruisce uno sheet di selezione dei tipi doc
2002-12-20 16:15:03 +00:00
const TRectype & recnum = cache ( ) . get ( " %NUM " , m . get ( 101 ) ) ; //cache sulla tabella numerazione documento con il numero doc immesso nella maschera
const TString80 s2 = recnum . get ( " S2 " ) ; //prende tutto il contenuto del campo S2 della tabella %NUM (numerazione docs)
for ( int i = 0 ; i < s2 . len ( ) ; i + = 4 )
{
const TString4 tipodoc = s2 . mid ( i , 4 ) ; //si va di 4 in 4, x' cosi' sono ordinati i tipidoc nel campo S2
if ( ! tipodoc . blank ( ) ) //ovviamente si procede solo se il tipodoc esiste
{
TToken_string row ; //classica token_string con codice e descrizione del tipodoc: questa viene scelta nella tabella
row . add ( tipodoc ) ; //dei tipi docs %TIP
row . add ( cache ( ) . get ( " %TIP " , tipodoc , " S0 " ) ) ;
as . add ( row ) ; //..e viene aggiunta allo sheet di selezione
}
}
if ( as . run ( ) ! = K_ESC )
{
TToken_string & riga = as . row ( - 1 ) ; //setta sul campo a maschera il codice della riga selezionata di as
f . set ( riga . get ( 0 ) ) ;
}
}
break ;
case K_ENTER : //caso del bottone invio; + o - come sopra; deve xo' verificare che l'eventuale codice di tipodoc digitato
if ( ! f . empty ( ) ) //sia valido (esista nel campo S2 della tabella NUM)
{
const TRectype & recnum = cache ( ) . get ( " %NUM " , m . get ( 101 ) ) ;
const TString80 s2 = recnum . get ( " S2 " ) ;
for ( int i = 0 ; i < s2 . len ( ) ; i + = 4 )
{
TString4 tipodoc = s2 . mid ( i , 4 ) ;
tipodoc . trim ( ) ;
if ( tipodoc = = f . get ( ) )
2006-12-13 16:22:33 +00:00
return true ;
2002-12-20 16:15:03 +00:00
}
2003-06-19 14:35:45 +00:00
return f . error_box ( FR ( " Tipo documento non valido per la numerazione %s " ) , ( const char * ) m . get ( 101 ) ) ;
2002-12-20 16:15:03 +00:00
}
break ;
default :
break ;
}
2006-12-13 16:22:33 +00:00
return true ;
2002-12-20 16:15:03 +00:00
}
1998-11-04 18:04:26 +00:00
////////////////////////////////////////////////////////////////
// Filtro per cli/fo sul cursore della lista documenti
////////////////////////////////////////////////////////////////
bool TStampaDoc_application : : filter_clifo ( const TRelation * r )
{
const long codcf = r - > lfile ( ) . get_long ( CLI_CODCF ) ;
TString16 key ;
key . format ( " %06ld " , codcf ) ;
return app ( ) . _clifo_sel . is_key ( key ) ;
}
////////////////////////////////////////////////////////////////
// Funzioni rimanenti
////////////////////////////////////////////////////////////////
1997-08-22 15:39:50 +00:00
1997-01-02 09:01:59 +00:00
bool TStampaDoc_application : : create ( )
1999-04-06 15:34:39 +00:00
{
1995-08-07 08:41:34 +00:00
_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
2005-03-17 18:21:37 +00:00
_firmrel - > add ( LF_COMUNI , " STATO=STATORES|COM=COMRES " , 1 , LF_ANAG , 100 + LF_COMUNI ) ;
_firmrel - > add ( LF_COMUNI , " STATO=STATORES|COM=COMRF " , 1 , LF_ANAG , 200 + LF_COMUNI ) ;
1999-10-22 10:00:18 +00:00
open_files ( LF_TABCOM , LF_TAB , LF_OCCAS , LF_CLIFO , LF_INDSP , LF_CFVEN , LF_MOVMAG , LF_RMOVMAG , LF_CONDV , LF_ANAMAG , LF_SVRIEP , LF_AGENTI , LF_PERCPROV , LF_CAUSALI , 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 ' ;
1998-08-25 18:07:30 +00:00
on_firm_change ( ) ;
1998-11-04 18:04:26 +00:00
_selection_mask = new TMask ( _is_lista ? " ve1100b " : " ve1100a " ) ;
2002-12-20 16:15:03 +00:00
1998-11-04 18:04:26 +00:00
if ( ! _is_lista )
{
2002-02-26 16:20:19 +00:00
_clifo_sheet = NULL ;
1998-11-04 18:04:26 +00:00
_selection_mask - > set_handler ( F_DA_DATADOC , date2num_handler ) ;
_selection_mask - > set_handler ( F_A_DATADOC , date2num_handler ) ;
_selection_mask - > set_handler ( F_A_NDOC , range_handler ) ;
}
else
2002-02-26 16:20:19 +00:00
{
_clifo_rel = new TRelation ( LF_CLIFO ) ;
_clifo_cur = new TCursor ( _clifo_rel ) ;
2003-06-19 14:35:45 +00:00
_clifo_sheet = new TCursor_sheet ( _clifo_cur , " |CODCF|RAGSOC " , TR ( " Selezione Clienti/Fornitori " ) ,
2002-02-26 16:20:19 +00:00
" @1|Codice@6R|Descrizione@50 " , 0 , 1 ) ;
build_clifo_list ( ) ; // Costruisce l'array sheet dei clienti (si parte!!)
1998-11-04 18:04:26 +00:00
_selection_mask - > set_handler ( F_TIPOCF , tipocf_handler ) ;
_selection_mask - > set_handler ( F_CODFR , fr_cod_handler ) ;
_selection_mask - > set_handler ( F_CODTO , to_cod_handler ) ;
_selection_mask - > set_handler ( BUT_SEL , select_button ) ;
_selection_mask - > set_handler ( BUT_ANN , reset_button ) ;
2002-12-20 16:15:03 +00:00
_selection_mask - > sfield ( F_SHEETNUMS ) . sheet_mask ( ) . set_handler ( 102 , tipodoc_handler ) ;
1998-08-25 18:07:30 +00:00
}
1998-11-04 18:04:26 +00:00
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 ;
2006-12-13 16:22:33 +00:00
_definitiva = false ;
1997-02-03 15:28:53 +00:00
_ncopie = 1 ;
2006-12-13 16:22:33 +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 ) ) ;
}
2006-12-13 16:22:33 +00:00
else
_interattivo = true ;
1997-02-03 15:28:53 +00:00
}
2006-12-13 16:22:33 +00:00
1997-02-03 15:28:53 +00:00
print_selected ( ) ;
2006-12-13 16:22:33 +00:00
return false ;
1997-01-02 09:01:59 +00:00
}
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
2006-12-13 16:22:33 +00:00
_interattivo = true ;
1999-04-06 15:34:39 +00:00
TSkeleton_application : : create ( ) ;
1997-02-03 15:28:53 +00:00
}
2000-05-05 15:25:49 +00:00
else
return error_box ( " Usage: ve1 -0 {[codnum anno {D|P} dalnum alnum {D|P} [ncopie]] | [L]} " ) ;
1997-03-10 14:51:08 +00:00
}
2006-12-13 16:22:33 +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
1998-08-25 18:07:30 +00:00
delete _selection_mask ;
2002-02-26 16:20:19 +00:00
if ( _clifo_sheet ! = NULL )
{
delete _clifo_sheet ;
delete _clifo_cur ;
delete _clifo_rel ;
}
1995-08-07 08:41:34 +00:00
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 ( )
{
2006-01-31 15:33:00 +00:00
TMask & m = * _selection_mask ;
2003-07-22 13:22:11 +00:00
1998-08-25 18:07:30 +00:00
m . reset ( ) ;
1998-11-04 18:04:26 +00:00
if ( _is_lista )
reset_choices ( m ) ;
2003-07-22 13:22:11 +00:00
const bool ok = m . run ( ) = = K_ENTER ;
if ( ok )
1997-01-02 09:01:59 +00:00
{
1998-11-04 18:04:26 +00:00
if ( ! _is_lista )
{
_codnum = m . get ( F_CODNUM ) ; // lettura dei dati dalla maschera
_dalnum = m . get_long ( F_DA_NDOC ) ;
_alnum = m . get_long ( F_A_NDOC ) ;
_ncopie = m . get_int ( F_NCOPIE ) ;
2006-01-31 15:33:00 +00:00
if ( _alnum < = 0 )
1998-11-04 18:04:26 +00:00
_alnum = 9999999L ;
2003-10-23 10:33:56 +00:00
/* Per ora disabilitamo questa feature, che forse deve essere studiata meglio
1999-04-06 15:34:39 +00:00
TString16 config ; config < < " NUM " < < _codnum ;
printer ( ) . read_configuration ( config ) ;
2003-10-23 10:33:56 +00:00
*/
1998-11-04 18:04:26 +00:00
}
1995-08-07 08:41:34 +00:00
_anno = m . get_int ( F_ANNO ) ;
1997-01-02 09:01:59 +00:00
_provv = m . get ( F_PROVV ) [ 0 ] ;
1998-08-25 18:07:30 +00:00
_dadata = m . get_date ( F_DA_DATADOC ) ;
if ( ! _dadata . ok ( ) )
1998-11-04 18:04:26 +00:00
_dadata = TDate ( 1 , 1 , _anno ) ;
1998-08-25 18:07:30 +00:00
_adata = m . get_date ( F_A_DATADOC ) ;
if ( ! _adata . ok ( ) )
1998-11-04 18:04:26 +00:00
_adata = TDate ( 31 , 12 , _anno ) ;
if ( _is_lista | | m . get ( F_DATA_O_NUM ) = = " D " )
1998-08-25 18:07:30 +00:00
_key = BY_DATE_KEY ;
1998-11-04 18:04:26 +00:00
else
_key = BY_NUM_KEY ;
}
2003-10-23 10:33:56 +00:00
return ok ;
1995-08-07 08:41:34 +00:00
}
1999-04-06 15:34:39 +00:00
void TStampaDoc_application : : main_loop ( )
1997-01-02 09:01:59 +00:00
{
1999-04-06 15:34:39 +00:00
while ( select ( ) )
print_selected ( ) ;
1995-08-07 08:41:34 +00:00
}
1997-01-02 09:01:59 +00:00
// Do all the work!
1999-04-06 15:34:39 +00:00
int ve1100 ( int argc , char * argv [ ] )
2003-07-22 13:22:11 +00:00
{
1997-01-02 09:01:59 +00:00
TStampaDoc_application a ;
2003-06-24 12:55:12 +00:00
const bool riep = argc = = 4 & & argv [ 2 ] [ 0 ] = = ' L ' ; // Lista documenti
a . run ( argc , argv , riep ? TR ( " Lista documenti " ) : TR ( " Stampa documenti " ) ) ;
return 0 ;
2006-04-13 17:56:02 +00:00
}