493 lines
13 KiB
C++
Executable File
493 lines
13 KiB
C++
Executable File
#include <mask.h>
|
|
#include <printapp.h>
|
|
#include <scanner.h>
|
|
#include <relation.h>
|
|
#include <tabutil.h>
|
|
#include <utility.h>
|
|
#include <prefix.h>
|
|
#include <lffiles.h>
|
|
#include <sort.h>
|
|
#include <assoc.h>
|
|
#include <progind.h>
|
|
|
|
#include <nditte.h>
|
|
|
|
#include "ba3.h"
|
|
#include "ba3600.h"
|
|
|
|
#define ALIAS 50
|
|
|
|
extern char __tmp [MAXSTR];
|
|
static TFixed_string tmp(__tmp, MAXSTR);
|
|
|
|
const int TABLBU = (int)TTable::name2log("%LBU");
|
|
const int TABINL = (int)TTable::name2log("%INL");
|
|
|
|
class BA3600_application : public TPrintapp
|
|
{
|
|
struct ind_lib
|
|
{
|
|
char mese[3];
|
|
char anno[5];
|
|
char nini_plib[6];
|
|
long num_riga;
|
|
long nfin_plib;
|
|
long codditta;
|
|
char cod_reg[4];
|
|
long nini_put;
|
|
long nfin_put;
|
|
char cod_vid[4];
|
|
bool stamp_bol;
|
|
bool pag_ann;
|
|
};
|
|
|
|
TMask* _msk;
|
|
TTable* _tab_inl;
|
|
TTable* _tab_lbu;
|
|
TTable* _tab_reg;
|
|
TLocalisamfile* _nditte;
|
|
TSort* _sort;
|
|
TProgind* _prog;
|
|
ind_lib* _lib;
|
|
const char* _buff;
|
|
|
|
TDate _datastampa;
|
|
int _tipo_stampa, _meseda, _mesea;
|
|
long _anno, _numini_paglib, _numfin_paglib, _numini_pagut, _numfin_pagut;
|
|
long _codditta, _pag_fin, _num_riga, _nfin_plib_prec;
|
|
TString _cod_lib, _rag_soc, _cod_reg, _descrizione, _cod_vidimaz;
|
|
TString _cod_lib_stampa, _stamp_bollato_str;
|
|
bool _stamp_bollato, _pag_ann, _pag_fuori_sequenza;
|
|
|
|
public:
|
|
|
|
bool menu (MENU_TAG m) { return TPrintapp::menu(m) ; }
|
|
void user_create() ;
|
|
void user_destroy();
|
|
bool set_print(int);
|
|
|
|
virtual bool preprocess_page (int,int);
|
|
virtual print_action postprocess_page (int,int);
|
|
|
|
virtual void preprocess_header();
|
|
virtual void set_page(int,int);
|
|
|
|
void init_sort();
|
|
void crea_sort();
|
|
bool preprocess_prova(int);
|
|
bool preprocess_bollato();
|
|
void crea_intestazione();
|
|
const char* ragsoc_ditta(long);
|
|
const char* descrizione_codreg(TString&);
|
|
void setta_righe_prova();
|
|
void setta_righe_bollato();
|
|
|
|
BA3600_application() {}
|
|
};
|
|
|
|
void BA3600_application::init_sort()
|
|
{
|
|
_lib = new ind_lib;
|
|
_sort = new TSort (sizeof(ind_lib));
|
|
|
|
_sort -> addsortkey((char*)&(_lib->mese) - (char*)&(_lib->mese),2);
|
|
_sort -> addsortkey((char*)&(_lib->anno) - (char*)&(_lib->anno),4);
|
|
_sort -> addsortkey((char*)&(_lib->nini_plib) - (char*)&(_lib->nini_plib),5);
|
|
_sort->init();
|
|
}
|
|
|
|
//Crea sort ordina i record della tabella %INL per mese registrazione, anno
|
|
//registrazione e numero iniziale pagine registro libro unico
|
|
|
|
void BA3600_application::crea_sort()
|
|
{
|
|
long anno,numini_paglib,numfin_paglib,codditta,numini_pagut,numfin_pagut;
|
|
TString cod_reg,cod_vidimaz,dep,app;
|
|
long mese, ultimo_mese;
|
|
bool stamp_bollato = FALSE;
|
|
bool pagine_ann = FALSE;
|
|
bool stampato = FALSE;
|
|
mese = 0;
|
|
ultimo_mese = 0;
|
|
|
|
init_sort();
|
|
|
|
_tab_lbu->zero();
|
|
// TString dep (format ("%4d%-3s", _anno, (const char*) _cod_lib));
|
|
// sprintf(__tmp, "%4d", _anno);
|
|
// strcat (__tmp, _cod_lib);
|
|
dep = format ("%4d", _anno);
|
|
dep << format ("%-3s", (const char*) _cod_lib);
|
|
_tab_lbu->put("CODTAB", (const char*) dep);
|
|
|
|
if (_tab_lbu->read(_isequal) == NOERR)
|
|
{
|
|
_tab_inl->zero();
|
|
app = format("%4d" , _anno);
|
|
app << format("%-3s", (const char*) _cod_lib);
|
|
_tab_inl->put("CODTAB", (const char*) app);
|
|
|
|
TRectype rec (_tab_inl->curr());
|
|
|
|
for (_tab_inl->read(); !_tab_inl->eof(); _tab_inl->next())
|
|
{
|
|
if (_tab_inl->curr() > rec) break;
|
|
|
|
mese = _tab_inl->get_int("I1");
|
|
|
|
if (((_tipo_stampa == 1) && (mese >= _meseda) && (mese <= _mesea)) ||
|
|
((_tipo_stampa == 2) && (mese == _mesea)))
|
|
{
|
|
TRecfield num_riga (_tab_inl->curr(),"CODTAB",7,12);
|
|
anno = _tab_inl->get_long("I0");
|
|
numini_paglib = _tab_inl->get_long("I2");
|
|
numfin_paglib = _tab_inl->get_long("I3");
|
|
codditta = _tab_inl->get_long("I4");
|
|
cod_reg = _tab_inl->get("S0");
|
|
cod_vidimaz = _tab_inl->get("S1");
|
|
numini_pagut = _tab_inl->get_long("I5");
|
|
numfin_pagut = _tab_inl->get_long("I6");
|
|
stamp_bollato = _tab_inl->get_bool("B0");
|
|
pagine_ann = _tab_inl->get_bool("B1");
|
|
|
|
//Se tipo_stampa = 1 (stampa di prova) stampo ugualmente. Se tipo_stampa = 2
|
|
// (stampa su bollato), stampo solamente se il flag di stampa su bollato e'
|
|
// FALSE.
|
|
|
|
if ((_tipo_stampa == 1) || ((_tipo_stampa == 2) && (!stamp_bollato)))
|
|
{
|
|
ultimo_mese = mese;
|
|
stampato = TRUE;
|
|
sprintf (_lib->mese, "%2d", mese);
|
|
sprintf (_lib->anno, "%4d", anno);
|
|
sprintf (_lib->nini_plib, "%5d", numini_paglib);
|
|
_lib->num_riga = long(num_riga);
|
|
_lib->nfin_plib = numfin_paglib;
|
|
_lib->codditta = codditta;
|
|
sprintf (_lib->cod_reg, "%3s", (const char*) cod_reg);
|
|
_lib->nini_put = numini_pagut;
|
|
_lib->nfin_put = numfin_pagut;
|
|
sprintf (_lib->cod_vid, "%3s", (const char*) cod_vidimaz);
|
|
_lib->stamp_bol = stamp_bollato;
|
|
_lib->pag_ann = pagine_ann;
|
|
_sort->sort ((const char*) _lib);
|
|
|
|
//Se si tratta di una stampa su bollato e il flag "stampa su bollato" indica
|
|
//che non e' mai stato stampato su bollato (flag = FALSE), allora devo stampare
|
|
//il record della tabella %INL, e contemporaneamente aggiornare il flag, per
|
|
//evitare di ristampare successivamente su bollato
|
|
|
|
if (_tipo_stampa == 2)
|
|
{
|
|
_tab_inl->put("B0", "X");
|
|
_tab_inl->rewrite();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
_sort->endsort();
|
|
}
|
|
|
|
// Se si tratta di una stampa su libro bollato, aggiorno sulla tabella %LBU // l' ultimo mese stampato, l' ultima pagina stampata e il flag che indica se
|
|
// quel record e' stato stampato su bollato
|
|
|
|
if ((_tipo_stampa == 2) && (stampato)) // stampato e' il flag che mi dice
|
|
{ //se almeno un record, nella stampa
|
|
_tab_lbu->put("I0", ultimo_mese); //su bollato, va in stampa. In caso
|
|
_tab_lbu->put("I1", numfin_paglib); //contrario non avrebbe senso
|
|
_tab_lbu->rewrite(); //aggiornare %LBU. ES:tutti i record
|
|
} //di quel mese sono gia stati stampati
|
|
} //su bollato (flag = TRUE).
|
|
|
|
bool BA3600_application::set_print(int)
|
|
{
|
|
KEY tasto;
|
|
|
|
tasto = _msk->run();
|
|
|
|
if (tasto == K_ENTER)
|
|
{
|
|
_tipo_stampa = _msk->get_int(F_TIPO_STAMPA);
|
|
|
|
if (_tipo_stampa == 1)
|
|
{
|
|
_cod_lib = _msk->get(F_LIBRO_UNICO1);
|
|
_datastampa = (_msk->get(F_DATA_STAMPA));
|
|
_meseda = _msk->get_int(F_MESEDA);
|
|
_mesea = _msk->get_int(F_MESEA);
|
|
_anno = _msk->get_long(F_ANNOA);
|
|
}
|
|
else if (_tipo_stampa == 2)
|
|
{
|
|
_cod_lib = _msk->get(F_LIBRO_UNICO2);
|
|
_mesea = _msk->get_int(F_STAMPA_MESE);
|
|
_anno = _msk->get_long(F_STAMPA_ANNO);
|
|
_cod_lib_stampa = _msk->get(F_CODLIB_STAMPA);
|
|
_pag_fin = _msk->get_long(F_PAGFINALE);
|
|
}
|
|
|
|
_pag_fuori_sequenza = FALSE;
|
|
|
|
crea_sort();
|
|
|
|
crea_intestazione();
|
|
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
/*********
|
|
bool BA3600_application::preprocess_page(int file, int counter)
|
|
{
|
|
if (_tipo_stampa == 1)
|
|
{
|
|
if (preprocess_prova(counter))
|
|
return TRUE;
|
|
else
|
|
return FALSE;
|
|
}
|
|
else if (_tipo_stampa == 2)
|
|
{
|
|
if (preprocess_bollato())
|
|
return TRUE;
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
***********/
|
|
|
|
bool BA3600_application::preprocess_page(int file, int counter)
|
|
{
|
|
struct ind_lib* lib = (struct ind_lib*) _buff;
|
|
long nini_plib;
|
|
|
|
reset_print();
|
|
|
|
_buff = _sort->retrieve();
|
|
|
|
if (_buff != NULL)
|
|
{
|
|
lib = (struct ind_lib*) _buff;
|
|
|
|
_numini_paglib = atoi(lib->nini_plib);
|
|
_numfin_paglib = lib->nfin_plib;
|
|
_codditta = lib->codditta;
|
|
_rag_soc = ragsoc_ditta(_codditta);
|
|
_cod_reg = lib->cod_reg;
|
|
_descrizione = descrizione_codreg(_cod_reg);
|
|
_cod_vidimaz = lib->cod_vid;
|
|
_numini_pagut = lib->nini_put;
|
|
_numfin_pagut = lib->nfin_put;
|
|
_num_riga = lib->num_riga;
|
|
_stamp_bollato = lib->stamp_bol;
|
|
_pag_ann = lib->pag_ann;
|
|
// _stamp_bollato_str = _stamp_bollato.string();
|
|
|
|
//Il controllo di pagine fuori sequenza viene sempre effettuato, tranne che per
|
|
//il primo record.
|
|
|
|
if (counter)
|
|
{
|
|
nini_plib = _numini_paglib - 1;
|
|
if (_nfin_plib_prec != nini_plib)
|
|
_pag_fuori_sequenza = TRUE;
|
|
else
|
|
_pag_fuori_sequenza = FALSE;
|
|
}
|
|
|
|
_nfin_plib_prec = _numfin_paglib;
|
|
|
|
return TRUE;
|
|
}
|
|
else
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
/*******
|
|
bool BA3600_application::preprocess_bollato()
|
|
{
|
|
|
|
}
|
|
******/
|
|
|
|
void BA3600_application::set_page(int file, int counter)
|
|
{
|
|
if (_tipo_stampa == 1)
|
|
setta_righe_prova();
|
|
else if (_tipo_stampa == 2)
|
|
setta_righe_bollato();
|
|
}
|
|
|
|
void BA3600_application::setta_righe_prova()
|
|
{
|
|
int i;
|
|
|
|
i = 1;
|
|
|
|
if (_pag_fuori_sequenza)
|
|
set_row (i++,"@10gPAGINE FUORI SEQUENZA");
|
|
|
|
set_row (i,"@1g#t", &_cod_lib);
|
|
set_row (i,"@6g#5d", &_numini_paglib);
|
|
set_row (i,"@13g#5d", &_numfin_paglib);
|
|
set_row (i,"@21g#5d", &_codditta);
|
|
set_row (i,"@27g#.41t", &_rag_soc);
|
|
set_row (i,"@69g#t", &_cod_reg);
|
|
set_row (i,"@73g#.31t", &_descrizione);
|
|
set_row (i,"@105g#t", &_cod_vidimaz);
|
|
set_row (i,"@111g#5d", &_numini_pagut);
|
|
set_row (i,"@117g#5d", &_numfin_pagut);
|
|
set_row (i,"@124g#5d", &_num_riga);
|
|
set_row (i,"@130g#t", &_stamp_bollato_str);
|
|
}
|
|
|
|
void BA3600_application::setta_righe_bollato()
|
|
{
|
|
int i;
|
|
|
|
i = 1;
|
|
|
|
if (_pag_fuori_sequenza)
|
|
set_row (i++,"@10gPAGINE FUORI SEQUENZA");
|
|
|
|
set_row (i,"@1g#t", &_cod_lib);
|
|
set_row (i,"@6g#5d", &_numini_paglib);
|
|
set_row (i,"@13g#5d", &_numfin_paglib);
|
|
if ((_pag_ann) && (_codditta == 0))
|
|
set_row (i,"@27gPAGINE ANNULLATE");
|
|
else
|
|
{
|
|
set_row (i,"@21g#5d", &_codditta);
|
|
set_row (i,"@27g#.41t", &_rag_soc);
|
|
}
|
|
if ((_pag_ann) && (_cod_reg == ""))
|
|
set_row (i,"@73gPAGINE ANNULLATE");
|
|
else
|
|
{
|
|
set_row (i,"@69g#t", &_cod_reg);
|
|
set_row (i,"@73g#.31t", &_descrizione);
|
|
}
|
|
set_row (i,"@105g#t", &_cod_vidimaz);
|
|
set_row (i,"@111g#5d", &_numini_pagut);
|
|
set_row (i,"@117g#5d", &_numfin_pagut);
|
|
set_row (i,"@124g#5d", &_num_riga);
|
|
set_row (i,"@130g#t", &_stamp_bollato_str);
|
|
}
|
|
|
|
print_action BA3600_application::postprocess_page(int file, int counter)
|
|
{
|
|
if (_buff == NULL)
|
|
return NEXT_PAGE;
|
|
|
|
return REPEAT_PAGE;
|
|
}
|
|
|
|
const char* BA3600_application::ragsoc_ditta(long codditta)
|
|
{
|
|
TLocalisamfile nditte(LF_NDITTE);
|
|
|
|
nditte.zero();
|
|
nditte.put(NDT_CODDITTA, codditta);
|
|
nditte.read();
|
|
if (nditte.bad())
|
|
nditte.zero();
|
|
tmp = nditte.get(NDT_RAGSOC);
|
|
return (__tmp);
|
|
}
|
|
|
|
const char* BA3600_application::descrizione_codreg(TString& codreg)
|
|
{
|
|
TString dep;
|
|
|
|
_tab_reg->zero();
|
|
dep = format("%4d", _anno);
|
|
dep << format("%-3s", (const char*) codreg);
|
|
_tab_reg->put("CODTAB", dep);
|
|
_tab_reg->read();
|
|
if (_tab_reg->bad())
|
|
_tab_reg->zero();
|
|
tmp = _tab_reg->get("S0");
|
|
return (__tmp);
|
|
}
|
|
|
|
void BA3600_application::preprocess_header()
|
|
{
|
|
}
|
|
|
|
void BA3600_application::crea_intestazione()
|
|
{
|
|
TString datastampastr;
|
|
TString sep(132);
|
|
|
|
reset_header();
|
|
|
|
set_header (1,"Studio");
|
|
|
|
sep << "Pag. @#";
|
|
sep.right_just(132);
|
|
set_header (2,(const char*) sep);
|
|
|
|
datastampastr = _datastampa.string();
|
|
|
|
set_header (2,"@0gPartita iva");
|
|
set_header (2,"@30gCodice fiscale");
|
|
if (_tipo_stampa == 1)
|
|
{
|
|
set_header (2,"@75gLIBRO UNICO DI PROVA");
|
|
set_header (2,"@105gData@110g%s",(const char*) datastampastr);
|
|
}
|
|
else
|
|
if (_tipo_stampa == 2)
|
|
{
|
|
TString mese = itom(_mesea);
|
|
set_header (2,"@75gmese di ", (const char*) mese);
|
|
set_header (2,"@92g%4d", _anno);
|
|
}
|
|
|
|
set_header (3,"@0gLibro unico :");
|
|
sep.fill('-'); //Stampa 132 - (sep(132))
|
|
set_header (4, (const char *) sep);
|
|
set_header (5,"@0gCod.@6gNumero@13gpagine@21gCodice@69gCod.@104gCodice@111gN.pag.@118gutente@126gNum.@131gF");
|
|
set_header (6,"@0gLibro@8gda@16ga@21gditta@28gDenominazione@69greg.@74gDescrizione@104gvidim.@112gutilizzate@126greg.@131g8");
|
|
set_header (7, (const char *) sep);
|
|
}
|
|
|
|
void BA3600_application::user_create()
|
|
{
|
|
_nditte = new TLocalisamfile (LF_NDITTE);
|
|
|
|
_tab_inl = new TTable (TAB_INL);
|
|
_tab_lbu = new TTable (TAB_LBU);
|
|
_tab_reg = new TTable (TAB_REG);
|
|
|
|
_msk = new TMask("ba3600a");
|
|
}
|
|
|
|
void BA3600_application::user_destroy()
|
|
{
|
|
delete _msk;
|
|
|
|
delete _tab_inl;
|
|
delete _tab_lbu;
|
|
delete _tab_reg;
|
|
delete _nditte;
|
|
}
|
|
|
|
int ba3600 (int argc, char* argv[])
|
|
{
|
|
|
|
BA3600_application a;
|
|
|
|
a.run(argc, argv, "Stampa indici registro libro unico");
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|