2002-09-09 14:10:14 +00:00
# include <applicat.h>
# include <automask.h>
# include <form.h>
# include <printer.h>
# include <recarray.h>
# include "cm0.h"
# include "cm0200a.h"
# include "cm0200.h"
2002-10-23 14:14:55 +00:00
# include "causali.h"
2002-09-09 14:10:14 +00:00
# include "mov.h"
# include "rmov.h"
# include "pconti.h"
class TForm_schedacdc : public TForm
{
2005-05-16 23:44:23 +00:00
static TForm_schedacdc * _cur_form ;
static void conti_header_handler ( TPrinter & p ) ;
2002-09-09 14:10:14 +00:00
public :
virtual bool validate ( TForm_item & cf , TToken_string & s ) ;
2005-05-16 23:44:23 +00:00
void set_testata ( ) ;
2002-09-09 14:10:14 +00:00
TPrint_section & get_body ( ) { return section ( ' B ' , odd_page ) ; }
TPrint_section & get_section ( char s , pagetype pos ) { return section ( s , pos ) ; }
2005-05-16 23:44:23 +00:00
2002-09-09 14:10:14 +00:00
TForm_schedacdc ( ) ;
virtual ~ TForm_schedacdc ( ) ;
} ;
TForm_schedacdc : : TForm_schedacdc ( ) : TForm ( " cm0200a " ) //costruttore
{
}
TForm_schedacdc : : ~ TForm_schedacdc ( ) //distruttore
{
}
2005-05-16 23:44:23 +00:00
//pazzesco (ma forse unico) modo di stampare i numeri pagina progressivi senza poter usare la
//print() standard dei TForm; e' stata reimplementata la header_handler() come conti_header_handler()
TForm_schedacdc * TForm_schedacdc : : _cur_form = NULL ;
void TForm_schedacdc : : conti_header_handler ( TPrinter & p )
{
TForm_schedacdc & f = * _cur_form ;
if ( f . firstpage_is_lastpage ( ) )
{
f . set_background ( 1 , TRUE ) ;
f . set_header ( 1 , TRUE ) ;
f . set_footer ( 0 , FALSE ) ;
}
else
{
const word page = f . page ( p ) ;
f . set_background ( page , TRUE ) ;
f . set_header ( 1 , TRUE ) ;
f . set_footer ( page , FALSE ) ;
}
}
void TForm_schedacdc : : set_testata ( )
{
set_header ( 1 , false ) ; set_header ( 1 , true ) ;
_cur_form = this ;
printer ( ) . setheaderhandler ( conti_header_handler ) ; // Setta handlers
}
2002-09-09 14:10:14 +00:00
bool TForm_schedacdc : : validate ( TForm_item & cf , TToken_string & s )
{
2002-10-23 14:14:55 +00:00
const TString code ( s . get ( 0 ) ) ; // prende il primo parametro, il codice del messaggio
TString valore ;
if ( code = = " _DITTA " )
{
// lettura dei dati della ditta
// sintassi: _DITTA,{<campo relazione>|<macro>}
// 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)
// <macro> <20> uno delle macro seguenti:
// !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)
// !PROV provincia (fiscale se c'<27> , oppure di residenza)
// !IVA partita iva
// !CF codice fiscale
// !TEL numero di telefono (con prefisso)
// !FAX numero di fax (con prefisso)
// !REGSOC numero di registrazione presso il Tribunale
// !CCIAA numero di registrazione presso la camera di commercio
2003-05-14 10:26:51 +00:00
2002-10-23 14:14:55 +00:00
TString in ( s . get ( ) ) ;
if ( in [ 0 ] ! = ' ! ' )
{
2003-05-14 10:26:51 +00:00
const TRectype & firm = cache ( ) . get ( LF_NDITTE , main_app ( ) . get_firm ( ) ) ;
cf . set ( firm . get ( in ) ) ;
2002-10-23 14:14:55 +00:00
return TRUE ;
}
else
return TForm : : validate ( cf , s ) ; // se il codice del messaggio non <20> identificato viene passato alla funzione standard
} // fine _DITTA
return TForm : : validate ( cf , s ) ; // se il codice del messaggio non <20> identificato viene passato alla funzione standard
2002-09-09 14:10:14 +00:00
}
class TSchedacdc_mask : public TAutomask
{
TRelation * _rel ;
TCursor * _cur ;
protected :
bool on_field_event ( TOperable_field & o , TField_event e , long jolly ) ;
public :
TSchedacdc_mask ( ) ;
virtual ~ TSchedacdc_mask ( ) { } ;
} ;
TSchedacdc_mask : : TSchedacdc_mask ( ) : TAutomask ( " cm0200a " )
{
}
bool TSchedacdc_mask : : on_field_event ( TOperable_field & o , TField_event e , long jolly )
{
switch ( o . dlg ( ) )
{
case F_DACDC :
case F_ACDC :
if ( e = = fe_modify )
{
const bool on = ! ( field ( F_DACDC ) . empty ( ) & & field ( F_ACDC ) . empty ( ) ) ;
if ( ! on )
{
reset ( F_DAFSC ) ;
reset ( F_AFSC ) ;
}
enable ( F_DAFSC , on ) ;
enable ( F_AFSC , on ) ;
}
break ;
2002-10-23 14:14:55 +00:00
case F_DATAINI :
if ( e = = fe_modify | | e = = fe_close )
{
TDate dataini ( field ( F_DATAINI ) . get ( ) ) ;
if ( dataini . ok ( ) )
{
TDate datainies = cache ( ) . get ( " ESC " , field ( F_ANNO ) . get ( ) , " D0 " ) ;
if ( dataini < datainies & & datainies . ok ( ) )
2003-05-14 10:26:51 +00:00
return error_box ( FR ( " La data iniziale non pu<70> essere precedente alla data inizio esercizio %s " ) , ( const char * ) datainies . string ( ) ) ;
2002-10-23 14:14:55 +00:00
}
}
2005-05-16 23:44:23 +00:00
if ( e = = fe_close )
{
const int annoes = get_int ( F_ANNO ) ;
const TDate dataini = get ( F_DATAINI ) ;
if ( annoes = = 0 & & ! dataini . ok ( ) )
return error_box ( TR ( " Data iniziale obbligatoria se anno esercizio non specificato " ) ) ;
}
2002-10-23 14:14:55 +00:00
break ;
case F_DATAFIN :
if ( e = = fe_modify | | fe_close )
{
TDate datafin ( field ( F_DATAFIN ) . get ( ) ) ;
if ( datafin . ok ( ) )
{
TDate datafines = cache ( ) . get ( " ESC " , field ( F_ANNO ) . get ( ) , " D1 " ) ;
if ( datafin > datafines & & datafines . ok ( ) )
2003-05-14 10:26:51 +00:00
return error_box ( FR ( " La data finale non pu<70> essere successiva alla data fine esercizio %s " ) , ( const char * ) datafines . string ( ) ) ;
2002-10-23 14:14:55 +00:00
TDate dataini ( field ( F_DATAINI ) . get ( ) ) ;
if ( dataini > datafin )
2003-05-14 10:26:51 +00:00
return error_box ( TR ( " La data iniziale non pu<70> essere successiva alla data finale " ) ) ;
2002-10-23 14:14:55 +00:00
}
}
2005-05-16 23:44:23 +00:00
if ( e = = fe_close )
{
const int annoes = get_int ( F_ANNO ) ;
const TDate datafin = get ( F_DATAFIN ) ;
if ( annoes = = 0 & & ! datafin . ok ( ) )
return error_box ( TR ( " Data finale obbligatoria se anno esercizio non specificato " ) ) ;
}
2002-10-23 14:14:55 +00:00
break ;
2002-09-09 14:10:14 +00:00
default : break ;
}
return TRUE ;
}
struct TTotalis : public TObject
{
2002-10-23 14:14:55 +00:00
TImporto _tot_perprec , _tot_periodo , _tot_generale ;
2002-09-09 14:10:14 +00:00
void azzera ( ) ;
TTotalis & operator + = ( const TTotalis & t ) ;
} ;
void TTotalis : : azzera ( )
{
2002-10-23 14:14:55 +00:00
_tot_perprec = 0 ;
_tot_periodo = 0 ;
_tot_generale = 0 ;
2002-09-09 14:10:14 +00:00
}
TTotalis & TTotalis : : operator + = ( const TTotalis & t )
{
2002-10-23 14:14:55 +00:00
_tot_perprec + = t . _tot_perprec ;
2002-09-09 14:10:14 +00:00
_tot_periodo + = t . _tot_periodo ;
_tot_generale + = t . _tot_generale ;
return * this ; //ritorna se stesso, quindi i valori dei totali
}
class TSchedacdc : public TSkeleton_application
{
2002-10-23 14:14:55 +00:00
TSchedacdc_mask * _mask ;
TForm_schedacdc * _form ;
2002-09-09 14:10:14 +00:00
int _codes ;
TDate _dataini , _datafin ;
2002-10-23 14:14:55 +00:00
TTotalis _t_sottoc , _t_fsc , _t_cms ;
TString _currcms , _currfsc , _oldcms , _oldfsc ;
2004-02-17 11:59:51 +00:00
bool _saltopagina , _print_tot_sottoc , _headercms , _headerfsc , _headersottoc ;
2002-09-09 14:10:14 +00:00
int _currgruppo , _currconto , _oldgruppo , _oldconto ;
long _currsottoc , _oldsottoc ;
protected :
virtual bool create ( ) ;
virtual bool destroy ( ) ;
virtual void main_loop ( ) ;
void print_movimento ( TSorted_cursor & cur ) ;
2002-10-23 14:14:55 +00:00
void print_header_mov ( ) { print_specialsection ( ' H ' , even_page ) ; } ;
void print_header_sottoc ( ) ;
2004-02-17 11:59:51 +00:00
void print_footer_sottoc ( ) ;
2002-10-23 14:14:55 +00:00
void print_footer_cms ( ) ;
void print_header_cms ( ) ;
void print_footer_fsc ( ) ;
void print_header_fsc ( ) ;
2002-09-09 14:10:14 +00:00
void set_intestazione ( ) ;
void print_body ( ) ; //stampa effettivamente il body
void set_field ( int id , const real & val ) ; //mette in un campo del body odd un valore numerico
void set_field ( int id , const char * val ) ; //mette in un campo del body odd una stringa
2002-10-23 14:14:55 +00:00
void print_specialsection ( char s , pagetype pos ) ; // stampa una sezione qualunque
2002-09-09 14:10:14 +00:00
void aggiorna_totali ( const TImporto importo , const TDate data ) ;
public :
TSchedacdc ( ) { }
} ;
bool TSchedacdc : : create ( )
{
open_files ( LF_RMOV , 0 ) ;
_mask = new TSchedacdc_mask ;
_form = new TForm_schedacdc ;
return TSkeleton_application : : create ( ) ;
}
bool TSchedacdc : : destroy ( )
{
delete _mask ;
delete _form ;
return TSkeleton_application : : destroy ( ) ;
}
2002-10-23 14:14:55 +00:00
void TSchedacdc : : aggiorna_totali ( const TImporto importo , const TDate data )
{
if ( data < _dataini )
{
_t_cms . _tot_perprec + = importo ;
_t_fsc . _tot_perprec + = importo ;
_t_sottoc . _tot_perprec + = importo ;
}
else if ( data < = _datafin )
{
_t_cms . _tot_periodo + = importo ;
_t_fsc . _tot_periodo + = importo ;
_t_sottoc . _tot_periodo + = importo ;
}
_t_cms . _tot_generale + = importo ;
_t_fsc . _tot_generale + = importo ;
_t_sottoc . _tot_generale + = importo ;
2002-09-09 14:10:14 +00:00
}
void TSchedacdc : : print_movimento ( TSorted_cursor & cur )
{
2002-10-23 14:14:55 +00:00
if ( _headercms )
{
print_header_cms ( ) ;
if ( ! _headerfsc )
print_header_mov ( ) ;
_headercms = FALSE ;
}
if ( _headerfsc )
{
print_header_fsc ( ) ;
print_header_mov ( ) ;
_headerfsc = FALSE ;
}
if ( _headersottoc )
{
print_header_sottoc ( ) ;
_headersottoc = FALSE ;
}
TRectype rec = cur . curr ( ) ;
TString16 key ;
2002-09-09 14:10:14 +00:00
set_field ( FR_DATAREG , cur . curr ( ) . get ( RMV_DATAREG ) ) ;
set_field ( FR_NUMREG , cur . curr ( ) . get ( RMV_NUMREG ) ) ;
set_field ( FR_DESCRMOV , cur . curr ( LF_MOV ) . get ( MOV_DESCR ) ) ;
2004-07-19 17:05:47 +00:00
set_field ( FR_PROTIVA , cur . curr ( LF_MOV ) . get ( MOV_PROTIVA ) ) ;
2002-10-23 14:14:55 +00:00
set_field ( FR_NUMDOC , cur . curr ( LF_MOV ) . get ( MOV_NUMDOC ) ) ;
set_field ( FR_DATADOC , cur . curr ( LF_MOV ) . get ( MOV_DATADOC ) ) ;
set_field ( FR_CAUSALE , cur . curr ( LF_MOV ) . get ( MOV_CODCAUS ) ) ;
TString tmp = cache ( ) . get ( LF_CAUSALI , cur . curr ( LF_MOV ) . get ( MOV_CODCAUS ) , CAU_DESCR ) ;
set_field ( FR_D_CAUSALE , tmp ) ;
2002-09-09 14:10:14 +00:00
const char sezione = cur . curr ( ) . get_char ( RMV_SEZIONE ) ;
const real importo = cur . curr ( ) . get_real ( RMV_IMPORTO ) ;
set_field ( FR_DARE , " " ) ;
set_field ( FR_AVERE , " " ) ;
if ( sezione = = ' D ' )
set_field ( FR_DARE , importo . string ( ) ) ;
else
set_field ( FR_AVERE , importo . string ( ) ) ;
print_body ( ) ;
}
2004-02-17 11:59:51 +00:00
void TSchedacdc : : print_footer_sottoc ( )
{
if ( _print_tot_sottoc )
{
TString tmp ;
tmp . format ( FR ( " CONTO %d %d %ld " ) , _oldgruppo , _oldconto , _oldsottoc ) ;
_form - > find_field ( ' F ' , first_page , FR_CODICE ) . set ( tmp ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_DARE ) . set ( " " ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_AVERE ) . set ( " " ) ;
char sezione = _t_sottoc . _tot_periodo . sezione ( ) ;
real valore = _t_sottoc . _tot_periodo . valore ( ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SALDO ) . set ( valore . string ( ) ) ;
if ( sezione = = ' D ' )
{
_form - > find_field ( ' F ' , first_page , FR_TOTALE_DARE ) . set ( valore . string ( ) ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SEGNO ) . set ( " D " ) ;
}
else
{
_form - > find_field ( ' F ' , first_page , FR_TOTALE_AVERE ) . set ( valore . string ( ) ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SEGNO ) . set ( " A " ) ;
}
print_specialsection ( ' F ' , first_page ) ;
}
}
2002-10-23 14:14:55 +00:00
void TSchedacdc : : print_footer_cms ( )
{
if ( ! _t_cms . _tot_periodo . is_zero ( ) )
{
TString tmp ;
2003-05-14 10:26:51 +00:00
tmp . format ( FR ( " PERIODO COMMESSA %s " ) , ( const char * ) _oldcms ) ;
2002-10-23 14:14:55 +00:00
_form - > find_field ( ' F ' , first_page , FR_CODICE ) . set ( tmp ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_DARE ) . set ( " " ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_AVERE ) . set ( " " ) ;
char sezione = _t_cms . _tot_periodo . sezione ( ) ;
real valore = _t_cms . _tot_periodo . valore ( ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SALDO ) . set ( valore . string ( ) ) ;
if ( sezione = = ' D ' )
{
_form - > find_field ( ' F ' , first_page , FR_TOTALE_DARE ) . set ( valore . string ( ) ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SEGNO ) . set ( " D " ) ;
}
else
{
_form - > find_field ( ' F ' , first_page , FR_TOTALE_AVERE ) . set ( valore . string ( ) ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SEGNO ) . set ( " A " ) ;
}
print_specialsection ( ' F ' , first_page ) ;
2003-05-14 10:26:51 +00:00
tmp . format ( FR ( " GENERALE COMMESSA %s " ) , ( const char * ) _oldcms ) ;
2002-10-23 14:14:55 +00:00
_form - > find_field ( ' F ' , first_page , FR_CODICE ) . set ( tmp ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_DARE ) . set ( " " ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_AVERE ) . set ( " " ) ;
sezione = _t_cms . _tot_generale . sezione ( ) ;
valore = _t_cms . _tot_generale . valore ( ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SALDO ) . set ( valore . string ( ) ) ;
if ( sezione = = ' D ' )
{
_form - > find_field ( ' F ' , first_page , FR_TOTALE_DARE ) . set ( valore . string ( ) ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SEGNO ) . set ( " D " ) ;
}
else
{
_form - > find_field ( ' F ' , first_page , FR_TOTALE_AVERE ) . set ( valore . string ( ) ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SEGNO ) . set ( " A " ) ;
}
print_specialsection ( ' F ' , first_page ) ;
if ( _saltopagina )
printer ( ) . formfeed ( ) ;
}
_t_cms . azzera ( ) ;
_oldcms = _currcms ;
_headercms = TRUE ;
2002-09-09 14:10:14 +00:00
}
2002-10-23 14:14:55 +00:00
void TSchedacdc : : print_footer_fsc ( )
2002-09-09 14:10:14 +00:00
{
2002-10-23 14:14:55 +00:00
if ( ! _t_fsc . _tot_periodo . is_zero ( ) )
{
TString tmp ;
2003-05-14 10:26:51 +00:00
tmp . format ( FR ( " PERIODO FASE %s " ) , ( const char * ) _oldfsc ) ;
2002-10-23 14:14:55 +00:00
_form - > find_field ( ' F ' , first_page , FR_CODICE ) . set ( tmp ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_DARE ) . set ( " " ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_AVERE ) . set ( " " ) ;
char sezione = _t_fsc . _tot_periodo . sezione ( ) ;
real valore = _t_fsc . _tot_periodo . valore ( ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SALDO ) . set ( valore . string ( ) ) ;
if ( sezione = = ' D ' )
{
_form - > find_field ( ' F ' , first_page , FR_TOTALE_DARE ) . set ( valore . string ( ) ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SEGNO ) . set ( " D " ) ;
}
else
{
_form - > find_field ( ' F ' , first_page , FR_TOTALE_AVERE ) . set ( valore . string ( ) ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SEGNO ) . set ( " A " ) ;
}
print_specialsection ( ' F ' , first_page ) ;
2003-05-14 10:26:51 +00:00
tmp . format ( FR ( " GENERALE FASE %s " ) , ( const char * ) _oldfsc ) ;
2002-10-23 14:14:55 +00:00
_form - > find_field ( ' F ' , first_page , FR_CODICE ) . set ( tmp ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_DARE ) . set ( " " ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_AVERE ) . set ( " " ) ;
sezione = _t_fsc . _tot_generale . sezione ( ) ;
valore = _t_fsc . _tot_generale . valore ( ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SALDO ) . set ( valore . string ( ) ) ;
if ( sezione = = ' D ' )
{
_form - > find_field ( ' F ' , first_page , FR_TOTALE_DARE ) . set ( valore . string ( ) ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SEGNO ) . set ( " D " ) ;
}
else
{
_form - > find_field ( ' F ' , first_page , FR_TOTALE_AVERE ) . set ( valore . string ( ) ) ;
_form - > find_field ( ' F ' , first_page , FR_TOTALE_SEGNO ) . set ( " A " ) ;
}
print_specialsection ( ' F ' , first_page ) ;
}
_oldfsc = _currfsc ;
_t_fsc . azzera ( ) ;
_headerfsc = TRUE ;
2002-09-09 14:10:14 +00:00
}
2002-10-23 14:14:55 +00:00
void TSchedacdc : : print_header_sottoc ( )
{
TString16 key ;
key . format ( " %d|%d|%ld " , _oldgruppo , _oldconto , _oldsottoc ) ;
const TRectype & pcon = cache ( ) . get ( LF_PCON , key ) ;
key . format ( " %d " , _oldgruppo ) ;
_form - > find_field ( ' B ' , first_page , FR_GRUPPO ) . set ( key ) ;
key . format ( " %d " , _oldconto ) ;
_form - > find_field ( ' B ' , first_page , FR_CONTO ) . set ( key ) ;
key . format ( " %ld " , _oldsottoc ) ;
_form - > find_field ( ' B ' , first_page , FR_SOTTOC ) . set ( key ) ;
_form - > find_field ( ' B ' , first_page , FR_D_SOTTOC ) . set ( pcon . get ( PCN_DESCR ) ) ;
2002-09-09 14:10:14 +00:00
TString tmp ;
2002-10-23 14:14:55 +00:00
_form - > find_field ( ' B ' , first_page , FR_S_DARE ) . set ( " " ) ;
_form - > find_field ( ' B ' , first_page , FR_S_AVERE ) . set ( " " ) ;
char sezione = _t_sottoc . _tot_perprec . sezione ( ) ;
real valore = _t_sottoc . _tot_perprec . valore ( ) ;
if ( sezione = = ' D ' )
_form - > find_field ( ' B ' , first_page , FR_S_DARE ) . set ( valore . string ( ) ) ;
else
_form - > find_field ( ' B ' , first_page , FR_S_AVERE ) . set ( valore . string ( ) ) ;
print_specialsection ( ' B ' , first_page ) ;
}
2002-09-09 14:10:14 +00:00
2002-10-23 14:14:55 +00:00
void TSchedacdc : : print_header_cms ( )
2002-09-09 14:10:14 +00:00
{
2002-10-23 14:14:55 +00:00
_form - > find_field ( ' H ' , odd_page , FR_CMS ) . set ( _oldcms ) ;
_form - > find_field ( ' H ' , odd_page , FR_D_CMS ) . set ( cache ( ) . get ( " CMS " , _oldcms ) . get ( " S0 " ) ) ;
2002-09-09 14:10:14 +00:00
print_specialsection ( ' H ' , odd_page ) ;
}
2002-10-23 14:14:55 +00:00
void TSchedacdc : : print_header_fsc ( )
2002-09-09 14:10:14 +00:00
{
2002-10-23 14:14:55 +00:00
_form - > find_field ( ' H ' , last_page , FR_FSC ) . set ( _oldfsc ) ;
_form - > find_field ( ' H ' , last_page , FR_D_FSC ) . set ( cache ( ) . get ( " FSC " , _oldfsc ) . get ( " S0 " ) ) ;
2002-09-09 14:10:14 +00:00
print_specialsection ( ' H ' , last_page ) ;
}
void TSchedacdc : : set_intestazione ( )
{
// scrive l'header first, contenente i dati della ditta e dell'esercizio e le selezioni di stampa
_form - > find_field ( ' H ' , first_page , FR_ESERCIZIO ) . set ( _mask - > get ( F_ANNO ) ) ;
_form - > find_field ( ' H ' , first_page , FR_DATAINI ) . set ( _mask - > get ( F_DATAINI ) ) ;
_form - > find_field ( ' H ' , first_page , FR_DATAFIN ) . set ( _mask - > get ( F_DATAFIN ) ) ;
_form - > find_field ( ' H ' , first_page , FR_DACDC ) . set ( _mask - > get ( F_DACDC ) ) ;
_form - > find_field ( ' H ' , first_page , FR_DAFSC ) . set ( _mask - > get ( F_DAFSC ) ) ;
_form - > find_field ( ' H ' , first_page , FR_ACDC ) . set ( _mask - > get ( F_ACDC ) ) ;
_form - > find_field ( ' H ' , first_page , FR_AFSC ) . set ( _mask - > get ( F_AFSC ) ) ;
_form - > set_testata ( ) ;
}
void TSchedacdc : : print_body ( )
{
TPrint_section & body = _form - > get_body ( ) ;
body . update ( ) ;
if ( body . height ( ) > printer ( ) . rows_left ( ) )
printer ( ) . formfeed ( ) ;
for ( word i = 0 ; i < body . height ( ) ; i + + ) // stampa le righe del body
printer ( ) . print ( body . row ( i ) ) ;
}
void TSchedacdc : : print_specialsection ( char s , pagetype pos )
{
TPrint_section & sec = _form - > get_section ( s , pos ) ;
sec . update ( ) ;
if ( sec . height ( ) > printer ( ) . rows_left ( ) )
printer ( ) . formfeed ( ) ;
for ( word i = 0 ; i < sec . height ( ) ; i + + ) // stampa le righe del body
printer ( ) . print ( sec . row ( i ) ) ;
}
void TSchedacdc : : set_field ( int id , const real & val )
{
_form - > find_field ( ' B ' , odd_page , id ) . set ( val . string ( ) ) ;
}
void TSchedacdc : : set_field ( int id , const char * val )
{
_form - > find_field ( ' B ' , odd_page , id ) . set ( val ) ;
}
void TSchedacdc : : main_loop ( )
{
while ( _mask - > run ( ) = = K_ENTER )
{
_saltopagina = _mask - > get_bool ( F_SALTOPAGINA ) ; // salto pagina a fine commessa
2004-02-17 11:59:51 +00:00
_print_tot_sottoc = _mask - > get_bool ( F_TOT_GCS ) ; //stampa totali sottoconti
2002-09-09 14:10:14 +00:00
_codes = _mask - > get_int ( F_ANNO ) ; // esercizio
_dataini = _mask - > get_date ( F_DATAINI ) ; // data iniziale
_datafin = _mask - > get_date ( F_DATAFIN ) ; // data finale
2002-10-23 14:14:55 +00:00
if ( _dataini . empty ( ) )
_dataini = cache ( ) . get ( " ESC " , _mask - > get ( F_ANNO ) ) . get_date ( " D0 " ) ;
if ( _datafin . empty ( ) )
_datafin = cache ( ) . get ( " ESC " , _mask - > get ( F_ANNO ) ) . get_date ( " D1 " ) ;
2002-09-09 14:10:14 +00:00
TString80 dacdc = _mask - > get ( F_DACDC ) ; // cdc/commessa iniziale
TString80 dafsc = _mask - > get ( F_DAFSC ) ; // fase iniziale
TString80 acdc = _mask - > get ( F_ACDC ) ; // cdc/commessa finale
TString80 afsc = _mask - > get ( F_AFSC ) ; // fase finale
// relazione su rmov
TRelation relrmov ( LF_RMOV ) ;
relrmov . add ( LF_MOV , " NUMREG==NUMREG " ) ;
// filtro
TString filtro = " " ;
2004-11-30 22:02:59 +00:00
if ( _codes > 0 )
2002-09-09 14:10:14 +00:00
filtro . format ( " ANNOES==%d " , _codes ) ;
if ( dacdc . not_empty ( ) )
{
if ( filtro . not_empty ( ) )
filtro < < " && " ;
filtro < < " (CODCMS>= \" " < < dacdc < < " \" ) " ;
}
if ( dafsc . not_empty ( ) )
{
if ( filtro . not_empty ( ) )
filtro < < " && " ;
filtro < < " (FASCMS>= \" " < < dafsc < < " \" ) " ;
}
if ( acdc . not_empty ( ) )
{
if ( filtro . not_empty ( ) )
filtro < < " && " ;
filtro < < " (CODCMS<= \" " < < acdc < < " \" ) " ;
}
if ( afsc . not_empty ( ) )
{
if ( filtro . not_empty ( ) )
filtro < < " && " ;
filtro < < " (FASCMS<= \" " < < afsc < < " \" ) " ;
}
if ( filtro . empty ( ) )
filtro . format ( " (CODCMS!= \" \" ) " ) ;
else
if ( dacdc . empty ( ) & & acdc . empty ( ) )
filtro < < " && " < < " (CODCMS!= \" \" ) " ;
TRectype darec ( LF_RMOV ) , arec ( LF_RMOV ) ;
// servono per gruppo-conto-sottoconto
darec . zero ( ) ;
arec . zero ( ) ;
darec . put ( RMV_GRUPPO , _mask - > get_int ( F_GRUPPOINI ) ) ;
darec . put ( RMV_CONTO , _mask - > get_int ( F_CONTOINI ) ) ;
darec . put ( RMV_SOTTOCONTO , _mask - > get_long ( F_SOTTOCINI ) ) ;
arec . put ( RMV_GRUPPO , _mask - > get_int ( F_GRUPPOFIN ) ) ;
arec . put ( RMV_CONTO , _mask - > get_int ( F_CONTOFIN ) ) ;
arec . put ( RMV_SOTTOCONTO , _mask - > get_long ( F_SOTTOCFIN ) ) ;
2002-10-23 14:14:55 +00:00
TString ordin = " GRUPPO|CONTO|SOTTOCONTO|DATAREG|NUMREG|NUMRIG " ;
bool ctrlfsc = TRUE ;
if ( dafsc . empty ( ) & & afsc . empty ( ) )
{
ctrlfsc = FALSE ;
ordin . insert ( " CODCMS| " ) ;
}
else
ordin . insert ( " CODCMS|FASCMS| " ) ;
2005-05-16 23:44:23 +00:00
2002-09-09 14:10:14 +00:00
TSorted_cursor sortcur ( & relrmov , ordin , filtro , 2 , & darec , & arec ) ;
sortcur . setregion ( darec , arec ) ;
sortcur . setfilter ( filtro , TRUE ) ;
long num = sortcur . items ( ) ;
sortcur . freeze ( ) ;
printer ( ) . open ( ) ;
set_intestazione ( ) ;
TRectype currrec ( LF_RMOV ) ;
_oldcms = " @@ " ;
2002-10-23 14:14:55 +00:00
_oldfsc = ( ctrlfsc ) ? " @@ " : " " ;
2002-09-09 14:10:14 +00:00
_oldgruppo = - 1 ;
_oldconto = - 1 ;
2002-10-23 14:14:55 +00:00
_oldsottoc = - 1 ;
2002-09-09 14:10:14 +00:00
_t_cms . azzera ( ) ;
_t_fsc . azzera ( ) ;
2002-10-23 14:14:55 +00:00
_t_sottoc . azzera ( ) ;
_headercms = TRUE ;
_headerfsc = ( ctrlfsc ) ? TRUE : FALSE ;
_headersottoc = TRUE ;
2005-05-16 23:44:23 +00:00
2002-09-09 14:10:14 +00:00
for ( sortcur = 0 ; sortcur . pos ( ) < num ; + + sortcur ) //scansione su tutte le righe di movimento
{
const TRectype rmovrec = sortcur . curr ( ) ;
2005-05-17 16:39:01 +00:00
_currcms = rmovrec . get ( " CODCMS " ) ;
_currfsc = ( ctrlfsc ) ? rmovrec . get ( " FASCMS " ) : " " ;
2002-09-09 14:10:14 +00:00
_currsottoc = rmovrec . get_long ( RMV_SOTTOCONTO ) ;
_currgruppo = rmovrec . get_int ( RMV_GRUPPO ) ;
_currconto = rmovrec . get_int ( RMV_CONTO ) ;
2005-05-16 23:44:23 +00:00
TImporto importo ( rmovrec . get_char ( RMV_SEZIONE ) , rmovrec . get_real ( RMV_IMPORTO ) ) ;
2002-10-23 14:14:55 +00:00
if ( ( _oldcms ! = _currcms ) | | ( _oldfsc ! = _currfsc ) | | ( _oldgruppo ! = _currgruppo ) | | ( _oldconto ! = _currconto ) | | ( _oldsottoc ! = _currsottoc ) )
2002-09-09 14:10:14 +00:00
{
2004-02-17 11:59:51 +00:00
if ( _oldgruppo > 0 )
print_footer_sottoc ( ) ;
2002-09-09 14:10:14 +00:00
_oldgruppo = _currgruppo ;
_oldconto = _currconto ;
_oldsottoc = _currsottoc ;
2002-10-23 14:14:55 +00:00
_headersottoc = TRUE ;
_t_sottoc . azzera ( ) ;
if ( ( _oldcms ! = _currcms ) | | ( _oldfsc ! = _currfsc ) )
{
if ( ctrlfsc )
print_footer_fsc ( ) ;
if ( _oldcms ! = _currcms )
print_footer_cms ( ) ;
}
2005-05-16 23:44:23 +00:00
}
TDate data ;
if ( _codes > 0 )
data = relrmov . curr ( LF_MOV ) . get_date ( MOV_DATACOMP ) ;
else
data = rmovrec . get_date ( RMV_DATAREG ) ;
aggiorna_totali ( importo , data ) ;
2004-11-30 22:02:59 +00:00
2005-05-16 23:44:23 +00:00
bool da_stampare = ! _dataini . ok ( ) | | data > = _dataini ;
2004-11-30 22:02:59 +00:00
if ( da_stampare )
2005-05-16 23:44:23 +00:00
da_stampare = ! _datafin . ok ( ) | | data < = _datafin ;
2004-11-30 22:02:59 +00:00
if ( da_stampare )
2002-10-23 14:14:55 +00:00
print_movimento ( sortcur ) ;
2002-09-09 14:10:14 +00:00
}
if ( num > 0 )
{
2004-02-17 11:59:51 +00:00
print_footer_sottoc ( ) ;
2002-10-23 14:14:55 +00:00
if ( ctrlfsc )
print_footer_fsc ( ) ;
print_footer_cms ( ) ;
2002-09-09 14:10:14 +00:00
printer ( ) . formfeed ( ) ;
}
printer ( ) . close ( ) ;
}
}
int cm0200 ( int argc , char * argv [ ] )
{
TSchedacdc a ;
2003-05-14 10:26:51 +00:00
a . run ( argc , argv , TR ( " Stampa scheda per CDC/Commessa " ) ) ;
2002-09-09 14:10:14 +00:00
return 0 ;
}