diff --git a/m770/772.cpp b/m770/772.cpp index a9e215afe..67f012651 100755 --- a/m770/772.cpp +++ b/m770/772.cpp @@ -1,29 +1,29 @@ -#include -#include -#include "770.h" -#include "772.h" - -#define usage "Error - usage : %s -{0|1|2|3}" - -int main(int argc,char** argv) -{ - int n = (argc > 1) ? atoi(argv[1]+1) : -1; - - switch (n) - { - case 0: - m72100(argc,argv); break; - case 1: - m72200(argc,argv); break; - case 2: - m72300(argc,argv); break; - case 3: - m72400(argc,argv); break; - case 4: - stampa_quadro(argc,argv); break; - default: - error_box(usage, argv[0]) ; - } - return 0; -} - +#include +#include +#include "770.h" +#include "772.h" + +#define usage "Error - usage : %s -{0|1|2|3}" + +int main(int argc,char** argv) +{ + const int n = (argc > 1) ? atoi(argv[1]+1) : -1; + + switch (n) + { + case 0: + m72100(argc,argv); break; + case 1: + m72200(argc,argv); break; + case 2: + m72300(argc,argv); break; + case 3: + m72400(argc,argv); break; + case 4: + stampa_quadro(argc,argv); break; + default: + error_box(usage, argv[0]) ; + } + return 0; +} + diff --git a/m770/77qa.frm b/m770/77qa.frm new file mode 100755 index 000000000..f745f8295 --- /dev/null +++ b/m770/77qa.frm @@ -0,0 +1,407 @@ +USE 62 +JOIN %CA7 ALIAS 14 INTO CODTAB=CODCAUS +JOIN 9 INTO CODDITTA=CODDITTA +JOIN 6 TO 9 ALIAS 116 INTO TIPOA=TIPOA CODANAGR=CODANAGR +JOIN 8 TO 116@ ALIAS 118 INTO CODANAGR=CODANAGR +JOIN 13 TO 118@ ALIAS 113 INTO COM=COMNASC +JOIN 13 TO 116@ ALIAS 213 INTO COM=COMRF(COMRES) +JOIN 6 ALIAS 216 INTO TIPOA=TIPOA CODANAGR=CODANAGR +JOIN 8 TO 216@ ALIAS 218 INTO CODANAGR=CODANAGR +JOIN 13 TO 216@ ALIAS 313 INTO COM=COMNASC +JOIN 13 TO 218@ ALIAS 413 INTO COM=COMRF(COMRES) +JOIN %STA TO 216@ ALIAS 24 INTO CODTAB=STATORES + +END +DESCRIPTION +BEGIN + 62->* "Quadro D 770" + 14@->* "CA7" + 9->* "Ditte" + 116@->* "Anagrafica persone fisiche e giuridiche (ditta)" + 118@->* "Anagrafica persone fisiche (ditta)" + 113@->* "Comuni DITTA (nascita)" + 213@->* "Comuni DITTA (res. fisc)" + 216@->* "Anagrafica persone fisiche e giuridiche (percip.)" + 218@->* "Anagrafica persone fisiche (percipiente)" + 313@->* "Comuni PERCIPIENTE (nascita)" + 413@->* "Comuni PERCIPIENTE (resid. fisc)" + 24@->* "Tabella stati" +END + +GENERAL +BEGIN + OFFSET 0 0 + FONT "Courier 17cpi" + SIZE 10 + CARATTERE "X" + INIZIO_POS 3 2 + FINE_POS 131 + GRID "+++++++++-|" +END + +SECTION HEADER FIRST 28 + +STRINGA 1 +BEGIN + KEY "CODICE FISCALE" + PROMPT 4 9 "" + FIELD 116@->COFI +END + +STRINGA 2 +BEGIN + KEY "RAGIONE SOCIALE" + PROMPT 39 9 "" + GROUP 2 + FIELD 116@->RAGSOC +END + +STRINGA 3 +BEGIN + KEY "COGNOME" + PROMPT 39 9 "" + GROUP 1 + FIELD 116@->RAGSOC[1,30] +END + +STRINGA 4 +BEGIN + KEY "NOME" + PROMPT 17 11 "" + GROUP 1 + FIELD 116@->RAGSOC[31,50] +END + +STRINGA 5 +BEGIN + KEY "SESSO" + PROMPT 58 11 "" + GROUP 1 + FIELD 118@->SESSO +END + +STRINGA 6 +BEGIN + KEY "DATA DI NASCITA" + PROMPT 66 11 "" + GROUP 1 + FIELD 118@->DATANASC +END + +STRINGA 7 +BEGIN + KEY "COMUNE DI NASCITA" + PROMPT 84 11 "" + GROUP 1 + FIELD 113@->DENCOM +END + +STRINGA 8 +BEGIN + KEY "PROV. DI NASCITA" + PROMPT 126 11 "" + GROUP 1 + FIELD 113@->PROVCOM +END + +LISTA 9 +BEGIN + KEY "Tipo anagrafica" + FIELD 116@->TIPOA +END + +STRINGA 10 +BEGIN + KEY "COMUNE DI RES.FISCALE" + PROMPT 17 13 "" + FIELD 213@->DENCOM +END + +STRINGA 11 +BEGIN + KEY "PROV DI RES.FISCALE" + PROMPT 59 13 "" + FIELD 213@->PROVCOM +END + +STRINGA 12 +BEGIN + KEY "VIA di RES." + PROMPT 66 13 "" + FIELD 116@->INDRF +END + +STRINGA 13 +BEGIN + KEY "NUM. CIVICO di RES." + PROMPT 102 13 "" + FIELD 116@->CIVRF +END + +STRINGA 14 +BEGIN + KEY "CAP" + PROMPT 120 13 "" + FIELD 116@->CAPRF +END + +STRINGA 15 +BEGIN + KEY "CODICE FISCALE DICHIARANTE" + PROMPT 118 16 "" +END + +NUMERO 16 +BEGIN + KEY "NUM. FOGLIO" + PROMPT 123 20 "" +END + +END + +SECTION BODY ODD 8 + +LISTA 100 +BEGIN + KEY "Tipo anagrafica" + FIELD 216@->TIPOA +END + +STRINGA 1 +BEGIN + KEY "COD.FIS" + PROMPT 2 12 "" + FIELD 216@->COFI +END + +STRINGA 2 +BEGIN + KEY "COGNOME" + PROMPT 23 12 "" + GROUP 1 + FIELD 216@->RAGSOC[1,30] +END + +STRINGA 3 +BEGIN + KEY "NOME" + PROMPT 10 14 "" + GROUP 1 + FIELD 216@->RAGSOC[31,50] +END + +STRINGA 102 +BEGIN + KEY "RAGSOC GIURIDICHE" + PROMPT 23 12 "" + GROUP 2 + FIELD 216@->RAGSOC +END + +DATA 4 +BEGIN + KEY "DATA NASCITA" + PROMPT 39 14 "" + FIELD 118@->DATANASC +END + +STRINGA 5 +BEGIN + KEY "SESSO" + PROMPT 34 14 "" + FIELD 118@->SESSO +END + +STRINGA 6 +BEGIN + KEY "COMUNE DI NASCITA" + PROMPT 49 14 "" + GROUP 1 + FIELD 313@->DENCOM +END + +STRINGA 101 +BEGIN + KEY "COMUNE DI RESIDENZA GIURIDICHE" + PROMPT 10 16 "" + GROUP 2 + FIELD 413@->DENCOM +END + +STRINGA 7 +BEGIN + KEY "PROV DI NASCITA" + PROMPT 73 14 "" + GROUP 1 + FIELD 313@->PROVCOM +END + +STRINGA 8 +BEGIN + KEY "COMUNE DI RESIDENZA" + PROMPT 10 16 "" + GROUP 1 + FIELD 413@->DENCOM +END + +STRINGA 9 +BEGIN + KEY "PROV. RESIDENZA" + PROMPT 34 16 "" + FIELD 413@->PROVCOM +END + +STRINGA 106 +BEGIN + KEY "PROV. RESIDENZA GIURIDICHE" + PROMPT 34 16 "" + GROUP 2 + FIELD 413@->PROVCOM +END + +STRINGA 10 +BEGIN + KEY "VIA RES." + PROMPT 94 4 "" + FLAGS "H" + MESSAGE COPY,12|COPY,107 + FIELD 216@->INDRES[1,18] +END + +STRINGA 11 +BEGIN + KEY "NUM.CIV" + PROMPT 93 4 "" + FLAGS "H" + MESSAGE APPEND,12|APPEND,107 + FIELD 216@->CIVRES +END + +STRINGA 12 +BEGIN + KEY "VIA RES. + numcivres" + PROMPT 39 16 "" + GROUP 1 +END + +STRINGA 13 +BEGIN + KEY "Codice fiscale percipiente" + PROMPT 6 23 "" + FIELD 216@->COFI +END + +STRINGA 14 +BEGIN + KEY "Cognome percipiente" + PROMPT 25 23 "" + FIELD 216@->RAGSOC[1,30] +END + +STRINGA 15 +BEGIN + KEY "Nome percipiente" + PROMPT 45 23 "" + FIELD 216@->RAGSOC[31,50] +END + +DATA 16 +BEGIN + KEY "Data nascita percipiente" + PROMPT 67 23 "" +END + +STRINGA 17 +BEGIN + KEY "Sesso percipiente" + PROMPT 75 23 "" + FIELD 218@->SESSO +END + +STRINGA 18 +BEGIN + KEY "Comune nascita percipiente" + PROMPT 6 24 "" + FIELD 313@->DENCOM +END + +STRINGA 19 +BEGIN + KEY "Provincia nascita percipiente" + PROMPT 28 24 "" + FIELD 313@->PROVCOM +END + +STRINGA 20 +BEGIN + KEY "Comune residenza percipiente" + PROMPT 31 24 "" + FIELD 413@->DENCOM +END + +STRINGA 21 +BEGIN + KEY "Provincia residenza percipiente" + PROMPT 52 24 "" + FIELD 413@->PROVCOM +END + +STRINGA 22 +BEGIN + KEY "dummy (via perc)" + FLAGS "H" + MESSAGE COPY, 24 + FIELD 216@->INDRES[1,18] +END + +STRINGA 23 +BEGIN + KEY "dummy (civ. percip.)" + FLAGS "H" + MESSAGE APPEND,24 + FIELD 216@->CIVRES +END + +STRINGA 24 23 +BEGIN + KEY "Indirizzo + n. civ. percipiente" + PROMPT 55 24 "" +END + +END + +SECTION BODY EVEN 2 + +NUMERO 1 +BEGIN + KEY "TOTALE TOTALE" + PROMPT 36 1 "" +END + +NUMERO 2 +BEGIN + KEY "TOTALE SOMME NON SOGGETTE" + PROMPT 55 1 "" +END + +NUMERO 3 +BEGIN + KEY "TOTALE IMPONIBILE" + PROMPT 75 1 "" +END + +NUMERO 4 +BEGIN + KEY "TOTALE IMPORTO" + PROMPT 101 1 "" +END + +NUMERO 5 +BEGIN + KEY "TOTALE NETTO" + PROMPT 120 1 "" +END + +END + +END diff --git a/m770/77stq.cpp b/m770/77stq.cpp index 615549efa..1fb020aea 100755 --- a/m770/77stq.cpp +++ b/m770/77stq.cpp @@ -1,3407 +1,3517 @@ -// Stampa quadro -#include -#include -#include -#include -#include -#include -#include -#include -#include "base.h" -#include - -#include -#include -#include "quadrod.h" -#include "quadrod1.h" -#include "quadrogd.h" -#include "quadrif.h" -#include "77stqd.h" -#include "77lib.h" - -// -// Lista modifiche -// -// 3.4.96 Nella stampa per Modulaser, aggiunto all'inizio un comando per settare -// il font della stampante a 17cpi (v.riga 176) -// - - -// Chincaglieria che serve per posiziona() -typedef long HWND; -HWND hInst; -HIDDEN const int MAX_LEN = 300; -extern "C" { - BOOLEAN PrintLineNow( char *pData, word cbBytes, HWND hInst ); -}; - - -HIDDEN TString16 __dep16; -HIDDEN TString80 __dep80; -HIDDEN const char* form(TString& quadro); - -// Vega-Key di Modulaser -HIDDEN const char* VK_STARTDOC = "&MA795&0&1"; -HIDDEN const char* VK_ENDDOC = "!0"; -HIDDEN const char* VK_STARTPAGE[] = { "*9*1", "*9*2", "*9*3", "*9*4" }; -typedef enum { STARTDOC, STARTDITTA, STARTPAGE, ENDDOC } ModulaserKey; - -// Campi form -#define TOT_TOTALE 1 -#define TOT_SNSRIT 2 -#define TOT_IMPON 3 -#define TOT_IMPOR 4 -#define TOT_NETTO 5 -#define H_COFI_DIC 13 -#define H_NUM_FOGLIO 14 - -// Quadro D -HIDDEN const int QD_FORMLEN_PRIMA = 70; // 72 - 3 (3 e' la posizione della X di posiz.) -HIDDEN const int QD_FORMLEN = 72; -HIDDEN const int POS_DITTA = 91; // Colonna del codice ditta a pie' di modulo -HIDDEN const int QD_PAGINE = 4; -HIDDEN const int QD_RIGHE_PRIMA = 5; -HIDDEN const int QD_RIGHE_SECONDA = 7; -HIDDEN const int QD_RIGHE_TERZA = 6; -HIDDEN const int QD_RIGHE_QUARTA = 6; -HIDDEN const int HEADER_SECONDA = 7; -HIDDEN const int HEADER_TERZA = 8; // Sarebbero 9 col righello... -HIDDEN const int HEADER_QUARTA = 14; // 15 col righello... - -typedef enum { PRIMA=1, SECONDA, TERZA, QUARTA } PagineQD; -typedef enum { fisiche, nofisiche } TipoPagina; - -/////////////////////////////////////////////////////////////////////////////////////////// -// -// Quadro D -// -/////////////////////////////////////////////////////////////////////////////////////////// - -class TDicForm : public TForm -{ - private: - real _f_tot_totale, _f_tot_snsrit, _f_tot_impon, _f_tot_impor, _f_tot_netto; - real _nf_tot_totale, _nf_tot_snsrit, _nf_tot_impon, _nf_tot_impor, _nf_tot_netto; - void aggiorna_totali_C(const char tipo); - void aggiorna_totali_D(const char tipo); - void aggiorna_totali_D1(const char tipo); - void aggiorna_totali_E(const char tipo); - void aggiorna_totali_E1(const char tipo); - - TRelation* _rel; - TCursor* _cur; - TSorted_cursor* _sorted_cur; - - protected: - long _Items; // numero di record che hanno passato il filtro - PagineQD _PaginaCorrente; - void set_curr_page(PagineQD pagina) { _PaginaCorrente = pagina; } - virtual void inc_curr_page(); - virtual void next_page(TPrinter& pr); - bool _modulaser; // se stampa per modulaser - bool _posiziona; // se deve fare posizionamento - TipoDitta _tipo_ditta; // tipo ditta: normale, estinto, dichiarante - int _num_foglio; // numero foglio - TString _cofi_dic; // cod.fis. dichiarante - bool _can_print_tot_fis, _can_print_tot_nofis; - bool _finite_fis, _finite_nofis, _LastDitta, _EndPrintDitta; - bool _GiaStampatiFis, _GiaStampatiNoFis, _PaginaPosizionamento; - bool _GiaPosizionato, _GiaMessoStartDoc, _GiaMessoStartPage[QD_PAGINE]; // flag per modulaser - int _CtrNoFisStampati, _CtrFisStampati; // contatori p.f. e p.g. stampate - long _codditta; // ditta in stampa - int _RigaCorr; // contatore riga corrente - TString16 _quadro; // codice quadro in stampa - virtual TCursor* cursor() const { return _cur; } - virtual TRelation* relation() const { return _rel; } - void stampa_testata(TPrinter& pr); - virtual void stampa_totali(TPrinter& pr); - virtual void aggiorna_totali(const char tipo); - virtual void set_body(TPrinter& pr, const char tipo, const bool UsaProgind); - void StampaPagina(PagineQD PaginaCorrente, const bool StampaTotali, const long Fis, const long NoFis); - void posiziona(); - void fill_page(TPrinter& pr, const int righe); - void put_modulaser(TPrintrow& row, ModulaserKey key, int page=0); - void ClearFlagModulaser(); - bool PaginaPosizionamento() const; - virtual bool InitPrint(const long codditta); - bool _UsaProgind; // usa la progind solo se non e' stampa a video - - public: - - const long filtra(const long codditta); - virtual bool UsaSortedCursor() { return TRUE; } - - TProgind* _prog; // progind usata in print() - - void set_progind(TProgind* prog, bool usaprogind) { _prog = prog; _UsaProgind = usaprogind; } - long codditta() const { return _codditta; } - void set_codditta(const long ditta) { _codditta = ditta; } - void set_posiziona(const bool posiz) { _posiziona = posiz; _GiaPosizionato = FALSE; } - void can_print_tot_fis(const bool canpr) { _can_print_tot_fis = canpr; } - void can_print_tot_nofis(const bool canpr) { _can_print_tot_nofis = canpr; } - void set_last_ditta(const bool last) { _LastDitta = last; } - bool last_ditta() const { return _LastDitta; } - bool EndJob() const { return _LastDitta && _EndPrintDitta; } - bool ultima_fis(); - bool ultima_nofis(); - TString& cofi_dic() { return _cofi_dic; } - void set_cofi_dic(const char* cofi) { _cofi_dic = cofi; } - TipoDitta tipo_ditta() const { return _tipo_ditta; } - void set_tipo_ditta(TipoDitta tipo) { _tipo_ditta = tipo; } - bool modulaser() const { return _modulaser; } - void set_modulaser(const bool modul) { _modulaser = modul; } - void set_num_foglio(const int foglio) { _num_foglio = foglio; } - int num_foglio() const { return _num_foglio; } - void azzera_totali(); - PagineQD curr_page() const { return _PaginaCorrente; } - TCursor& cur(); - TProgind* progind() { return _prog; } - bool usaprogind() const { return _UsaProgind; } - virtual void set_cur_rel(TRelation* rel, TCursor* cur); - virtual void close_print(); - virtual bool print(const long codditta, const long NumFis, const long NumNoFis); - - TDicForm(const char* form, const char* quadro); - virtual ~TDicForm() {} -}; - -TCursor& TDicForm::cur() -{ - if (UsaSortedCursor()) - return *_sorted_cur; - else - return *_cur; -} - -void TDicForm::set_cur_rel(TRelation* rel, TCursor* cur) -{ - _rel = rel; - if (UsaSortedCursor()) - _sorted_cur = (TSorted_cursor*) cur; - else - _cur = cur; -} - -TDicForm::TDicForm(const char* form, const char* quadro) : _quadro(quadro), TForm(form) -{ - _can_print_tot_fis = _can_print_tot_nofis = FALSE; - _GiaStampatiFis = _GiaStampatiNoFis = _GiaMessoStartDoc = FALSE; - _GiaPosizionato = _posiziona = _modulaser = FALSE; - _LastDitta = _EndPrintDitta = _PaginaPosizionamento = FALSE; - ClearFlagModulaser(); -} - -const long TDicForm::filtra(const long codditta) -{ - long items=0L; - TString filtr(20); - - filtr.format("CODDITTA=%ld", codditta); - if (UsaSortedCursor()) - { - _sorted_cur->setfilter(filtr, TRUE); - items = _sorted_cur->items(); - } - else - { - _cur->setfilter(filtr, TRUE); - items = _cur->items(); - } - - return items; -} - - -bool TDicForm::InitPrint(const long codditta) -{ - _codditta = codditta; - _RigaCorr = 0; - - TPrinter& pr = printer(); - pr.set_offset(offset_y(), offset_x()); - pr.set_char_size(fontsize()); // Set font name and size - pr.set_fontname(fontname()); // according to current form - - if (_posiziona && !_GiaPosizionato && pr.printtype() != screenvis && - pr.printtype() != fileprinter) -// arrange_form(); - posiziona(); - -#ifdef DBG - if (pr.printtype() != screenvis) - if (!yesno_box("Proseguo con la stampa ?")) - return FALSE; -#endif - - const bool was_open = pr.isopen(); - - set_last_page(FALSE); - set_background(1, TRUE); - set_curr_page(PRIMA); - - if (!was_open && !pr.open()) - return FALSE; - do_events(); - - _Items = filtra(codditta); - - if (_Items == 0L) // Se non ci sono record non stampa - return FALSE; - - _prog = NULL; - _UsaProgind = pr.printtype() != screenvis; - if (_UsaProgind) - { - TString msg(60); - msg.format("Elaborazione in corso ditta %ld", codditta); - _prog = new TProgind(_Items, msg, FALSE,TRUE); - } - return TRUE; -} - -void TDicForm::close_print() -{ - if (_UsaProgind) - delete _prog; -} - -bool TDicForm::print(const long codditta, const long NumFis, const long NumNoFis) -{ - TCursor* cur = UsaSortedCursor() ? _sorted_cur : _cur; - - bool StabilitaInesistenzaNoFis = FALSE; - bool StabilitaInesistenzaFis = FALSE; - long CtrFis = NumFis; - long CtrNoFis = NumNoFis; - long PtrFis = -1L, PtrNoFis=-1L; - TPrinter& pr = printer(); - - _CtrFisStampati = _CtrNoFisStampati = 0; - _finite_fis = _finite_nofis = FALSE; - _GiaStampatiFis = _GiaStampatiNoFis = FALSE; - _EndPrintDitta = FALSE; // Vero se stampato l'ultimo record - bool LastRecord = FALSE; // Vero se letto l'ultimo record - - _PaginaCorrente = PRIMA; - _UsaProgind = FALSE; - - if (!InitPrint(codditta)) - return FALSE; - - while (!_EndPrintDitta) - { - for (int pagina=1; pagina <= QD_PAGINE; pagina++, next_page(pr)) - { - pr.formlen(QD_FORMLEN); - - if (_PaginaCorrente == PRIMA) - { - if (_modulaser) ClearFlagModulaser(); - - for (int righe=0; righe < QD_RIGHE_PRIMA; righe++) - { -// Stampa intestazione, solo sul primo foglio. - if (!righe) - { - (*cur) = PtrFis >= 0L ? PtrFis : 0L; - stampa_testata(pr); - } - - if (_finite_fis || StabilitaInesistenzaFis) - break; - -// La prima volta si deve posizionare sul primo record di p.f. - if (PtrFis<0L && !StabilitaInesistenzaFis) - { - bool Trovato = FALSE; - - while (!Trovato) - { - const long ditta = cur->curr().get_long(QUD_CODDITTA); - if (ditta != codditta) - break; - const char tipo = cur->curr().get(QUD_TIPOA)[0]; - if (tipo != 'G') - { - PtrFis = cur->pos(); - Trovato = TRUE; - break; - } - else - ++(*cur); - } - StabilitaInesistenzaFis = !Trovato; - } - - if (StabilitaInesistenzaFis) - break; - - (*cur) = PtrFis; - const char tipo = cur->curr().get(QUD_TIPOA)[0]; - - if (tipo != 'F') - break; - else - { - CtrFis--; - if (CtrFis == 0L) _finite_fis = TRUE; - set_body(pr, 'F', _UsaProgind); -// La stampa e' finita se ho STAMPATO l'ultimo record - LastRecord = cur->pos() >= _Items-1; - _EndPrintDitta = LastRecord; - if (!LastRecord) - { - ++(*cur); - PtrFis = cur->pos(); - LastRecord = cur->pos() >= _Items-1; - } - } - } // for righe.. - PtrFis = cur->pos(); - } - - if (_PaginaCorrente == SECONDA) - { -// Reset del flag di pagina con posiz. - if (_posiziona && _PaginaPosizionamento) _PaginaPosizionamento = FALSE; - for (int righe=0; righe < QD_RIGHE_SECONDA; righe++) - { - if (!righe) - fill_page(pr, HEADER_SECONDA); - - if (_finite_fis || StabilitaInesistenzaFis) - break; - - (*cur) = PtrFis; - const char tipo = cur->curr().get(QUD_TIPOA)[0]; - - if (tipo != 'F') - break; - else - { - CtrFis--; - if (CtrFis == 0L) _finite_fis = TRUE; - set_body(pr, 'F', _UsaProgind); - LastRecord = cur->pos() >= _Items-1; - _EndPrintDitta = LastRecord; - if (!LastRecord) - { - ++(*cur); - PtrFis = cur->pos(); - LastRecord = cur->pos() >= _Items-1; - } - } - } - PtrFis = cur->pos(); - } - - if (_PaginaCorrente == TERZA) - { - for (int righe=0; righe < QD_RIGHE_TERZA; righe++) - { - if (!righe) - { - fill_page(pr, HEADER_TERZA); - _CtrFisStampati = 0; // conta quelli che stampo sulla terza - } - - if (_finite_fis || StabilitaInesistenzaFis) - break; - - (*cur) = PtrFis; - const char tipo = cur->curr().get(QUD_TIPOA)[0]; - - if (tipo != 'F') - break; - else - { - CtrFis--; - if (CtrFis == 0L) _finite_fis = TRUE; - set_body(pr, 'F', _UsaProgind); - LastRecord = cur->pos() >= _Items-1; - _EndPrintDitta = LastRecord; - _CtrFisStampati++; - if (!LastRecord) - { - ++(*cur); - PtrFis = cur->pos(); - LastRecord = cur->pos() >= _Items-1; - } - } - } - PtrFis = cur->pos(); - } - - if (_PaginaCorrente == QUARTA) - { - for (int righe=0; righe < QD_RIGHE_QUARTA; righe++) - { - if (!righe) - _CtrNoFisStampati = 0; - -// All'inizio salta le righe in alto - if (!righe) - fill_page(pr, HEADER_QUARTA); - - if (_finite_nofis || StabilitaInesistenzaNoFis) - break; - -// La prima volta si deve posizionare sul primo record di p.g. - if (PtrNoFis<0L && !StabilitaInesistenzaNoFis) - { - bool Trovato = FALSE; - bool eof = FALSE; - (*cur) = PtrFis-1 > 0L ? PtrFis-1 : 0L; // parti dall'inizio - while (!Trovato && !eof) - { - eof = cur->pos() >= _Items-1; - const long ditta = cur->curr().get_long(QUD_CODDITTA); - if (ditta != codditta) - break; - const char tipo = cur->curr().get(QUD_TIPOA)[0]; - if (tipo != 'F') - { - PtrNoFis = cur->pos(); - Trovato = TRUE; - break; - } - else - ++(*cur); - } - StabilitaInesistenzaNoFis = !Trovato; - } - - if (StabilitaInesistenzaNoFis) - break; - - (*cur) = PtrNoFis; - const char tipo = cur->curr().get(QUD_TIPOA)[0]; - - if (tipo != 'G') - break; - else - { - CtrNoFis--; - if (CtrNoFis == 0L) _finite_nofis = TRUE; - set_body(pr, 'G', _UsaProgind); - LastRecord = cur->pos() >= _Items-1; - _EndPrintDitta = LastRecord; - _CtrNoFisStampati++; - if (!LastRecord) - { - ++(*cur); - PtrNoFis = cur->pos(); - LastRecord = cur->pos() >= _Items-1; - } - } - } - PtrNoFis = cur->pos(); - } - } // for pagina.. - } // while !_EndPrintDitta - close_print(); - return TRUE; -} - - -void TDicForm::ClearFlagModulaser() -{ - for (int i=0; i<=QD_PAGINE; i++) - _GiaMessoStartPage[i] = FALSE; -} - -bool TDicForm::ultima_fis() -{ - return _can_print_tot_fis && _finite_fis && !_GiaStampatiFis; -} - -bool TDicForm::ultima_nofis() -{ - return _can_print_tot_nofis && _finite_nofis && !_GiaStampatiNoFis; -} - -void TDicForm::inc_curr_page() -{ - if (_PaginaCorrente == PRIMA) - _PaginaCorrente = SECONDA; - else - if (_PaginaCorrente == SECONDA) - _PaginaCorrente = TERZA; - else - if (_PaginaCorrente == TERZA) - _PaginaCorrente = QUARTA; - else - if (_PaginaCorrente == QUARTA) - _PaginaCorrente = PRIMA; -} - -void TDicForm::put_modulaser(TPrintrow& row, ModulaserKey Cmd, int page) -{ - TString riga(80); - - switch (Cmd) - { - case STARTDOC: - if (!_GiaMessoStartDoc) - { -// riga = VK_STARTDOC; - riga = "\xf"; // Printer escape: font 17cpi - riga << VK_STARTDOC; - _GiaMessoStartDoc = TRUE; - } - break; - case STARTDITTA: - { - TString cofi(16); - const char* tmp = _cur->file(-116).get(ANA_COFI); - cofi.format("%-16s", tmp); - TString ragsoc(50); - ragsoc = _cur->file(LF_NDITTE).get(NDT_RAGSOC); - riga = "$"; - riga << cofi; - riga << "$0$"; - riga << ragsoc; - } - break; - case STARTPAGE: - riga = "*9*"; - riga << page; - _GiaMessoStartPage[page] = TRUE; - break; - case ENDDOC: - riga = VK_ENDDOC; - break; - default: - break; - } - riga.rtrim(); - riga << '\r'; - row.put(riga); -} - - -bool TDicForm::PaginaPosizionamento() const -{ - return curr_page() == PRIMA && _PaginaPosizionamento; -} - -// Stampa "righe" righe vuote. Se righe e' -1 fa un formfeed mettendo -// il codice ditta sull'ultima riga -void TDicForm::fill_page(TPrinter& pr, const int righe) -{ - TPrintrow row; - PagineQD pagina = curr_page(); - -// form feed - if (righe < 0) - { - const bool PrimaPagina = curr_page() == PRIMA; - int stop = PaginaPosizionamento() ? QD_FORMLEN_PRIMA : QD_FORMLEN; - for (int i = _RigaCorr; i < stop; i++) - { - if (i == 0) - if (_modulaser) - { - if (!_GiaMessoStartPage[pagina]) - put_modulaser(row, STARTPAGE, pagina); - } -// Sull'ultima riga metto il codice ditta - if (i == stop-1) - { - if (_modulaser && EndJob() && curr_page() == QUARTA) - put_modulaser(row, ENDDOC); - - TString16 ditta; ditta << _codditta; - row.put(ditta, POS_DITTA); - } - pr.print(row); - } - _RigaCorr = 0; - return; - } - else // righe > 0 - for (int i=0; i0) - fill_page(pr,gap); - } - - if (stampa_tot_nofis) - if (PagCorr == QUARTA) // Scrive totali p.non fisiche - { - stampa=TRUE; - TString ftot(_nf_tot_totale.string(pic)); - TString fsnsrit(_nf_tot_snsrit.string(pic)); - TString fimpon(_nf_tot_impon.string(pic)); - TString fimpor(_nf_tot_impor.string(pic)); - TString fnetto(_nf_tot_netto.string(pic)); -// Toglie le migliaia - ftot.cut(ftot.len() - 3); - fsnsrit.cut(fsnsrit.len()-3); - fimpon.cut(fimpon.len()-3); - fimpor.cut(fimpor.len()-3); - fnetto.cut(fnetto.len()-3); - if (ftot.empty()) ftot = "0"; - if (fsnsrit.empty()) fsnsrit = "0"; - if (fimpon.empty()) fimpon = "0"; - if (fimpor.empty()) fimpor = "0"; - if (fnetto.empty()) fnetto = "0"; -// Setta i campi - ttotale.set(ftot); - tsnsrit.set(fsnsrit); - timpon.set(fimpon); - timpor.set(fimpor); - tnetto.set(fnetto); - _GiaStampatiNoFis = TRUE; -const int NUMPER_QUARTA = 6; -const int NUM_RIGHE = 8; - const int gap = ((NUMPER_QUARTA - _CtrNoFisStampati) * NUM_RIGHE)+1; - - if (gap > 0) - fill_page(pr,gap); - } - if (stampa) - { - foot.update(); - for (word j = 0; j < foot.height(); j++) - { - pr.print(foot.row(j)); - _RigaCorr++; - } - foot.reset(); // non stampare piu' questi totali! - } -} - -void TDicForm::stampa_testata(TPrinter& pr) -{ - TPrint_section& head = section('H', 1); - const word r = head.height()-1; - TPrintrow& head_row = head.row(r-1); - -// Setta il numero di pagina e poi lo incrementa - TForm_item& nf = head.find_field(H_NUM_FOGLIO); - TString fstr(10); fstr << _num_foglio; - nf.set(fstr); - _num_foglio++; - -// Setta il cod.fis. del dichiarante se necessario - if (tipo_ditta() == estinto) - { - TForm_item& cfd = head.find_field(H_COFI_DIC); - cfd.set(_cofi_dic); - } -// Righe da saltare nelle prime pag. dei moduli successivi al primo (che' son -// senza le righe del posizionamento...) - int HEADER_PRIMA_NOPOS = 3; - head.update(); - for (word j = 0; j <= r; j++) - { - if (j==0) - { - if (_modulaser) - { - TPrintrow& r = head.row(j); - if (!_GiaMessoStartDoc) - put_modulaser(r, STARTDOC); - put_modulaser(r, STARTDITTA); - put_modulaser(r, STARTPAGE, 1); - pr.print(r); - _RigaCorr++; - r.reset(); - HEADER_PRIMA_NOPOS--; - } - if (!PaginaPosizionamento()) - fill_page(pr, HEADER_PRIMA_NOPOS); - } - else - { - pr.print(head.row(j)); - _RigaCorr++; - } - } -} - -void TDicForm::next_page(TPrinter& pr) -{ - PagineQD PagCorr = curr_page(); - if (PagCorr >= TERZA) - stampa_totali(pr); - fill_page(pr, -1); // formfeed "adattato" - inc_curr_page(); -} - -void TDicForm::azzera_totali() -{ - _f_tot_netto = _f_tot_totale = _f_tot_impor = _f_tot_impon = _f_tot_snsrit = ZERO; - _nf_tot_netto = _nf_tot_totale = _nf_tot_impor = _nf_tot_impon = _nf_tot_snsrit = ZERO; -} - -void TDicForm::aggiorna_totali_E(const char tipo) -{ -} - -void TDicForm::aggiorna_totali_E1(const char tipo) -{ -} - -void TDicForm::aggiorna_totali_D(const char tipo) -{ - real totale, netto, impon, nsrit, impor; - TCursor* cur = UsaSortedCursor() ? _sorted_cur : _cur; - TRectype& crr = cur->curr(); - - totale = crr.get_real(QUD_TOTALE); - netto = crr.get_real(QUD_NETTO); - impon = crr.get_real(QUD_IMPONIBILE); - impor = crr.get_real(QUD_IMPORTO); - nsrit = crr.get_real(QUD_SOMME); - - if (tipo == 'F') - { - _f_tot_totale += totale; - _f_tot_netto += netto; - _f_tot_impon += impon; - _f_tot_snsrit += nsrit; - _f_tot_impor += impor; - } - else - { - _nf_tot_totale += totale; - _nf_tot_netto += netto; - _nf_tot_impon += impon; - _nf_tot_snsrit += nsrit; - _nf_tot_impor += impor; - } -} - -void TDicForm::aggiorna_totali_D1(const char tipo) -{ - real totale, netto, impon, QuotaProv, SpeseAnt, impor; - TCursor* cur = UsaSortedCursor() ? _sorted_cur : _cur; - TRectype& crr = cur->curr(); - - totale = crr.get_real(QD1_TOTALE); - netto = crr.get_real(QD1_NETTO); - impon = crr.get_real(QD1_IMPONIBILE); - impor = crr.get_real(QD1_IMPORTO); - QuotaProv = crr.get_real(QD1_QUOTAPRO); - SpeseAnt = crr.get_real(QD1_SPESEANT); - - if (tipo == 'F') - { - _f_tot_totale += totale; - _f_tot_netto += netto; - _f_tot_impon += impon; - _f_tot_snsrit += QuotaProv; - _f_tot_impor += impor; - } - else - { - _nf_tot_totale += totale; - _nf_tot_netto += netto; - _nf_tot_impon += impon; - _nf_tot_snsrit += QuotaProv; - _nf_tot_impor += impor; - } -} - -void TDicForm::aggiorna_totali_C(const char tipo) -{ - real totale, netto, impon, nsrit, impor; - TCursor* cur = UsaSortedCursor() ? _sorted_cur : _cur; - TRectype& crr = cur->curr(); - - totale = crr.get_real(QUD_TOTALE); - netto = crr.get_real(QUD_NETTO); - impon = crr.get_real(QUD_IMPONIBILE); - impor = crr.get_real(QUD_IMPORTO); - nsrit = crr.get_real(QUD_SOMME); - - if (tipo == 'F') - { - _f_tot_totale += totale; - _f_tot_netto += netto; - _f_tot_impon += impon; - _f_tot_snsrit += nsrit; - _f_tot_impor += impor; - } - else - { - _nf_tot_totale += totale; - _nf_tot_netto += netto; - _nf_tot_impon += impon; - _nf_tot_snsrit += nsrit; - _nf_tot_impor += impor; - } -} - - -void TDicForm::aggiorna_totali(const char tipo) -{ - if (_quadro == "C") - aggiorna_totali_C(tipo); - - if (_quadro == "D") - aggiorna_totali_D(tipo); - - if (_quadro == "D1") - aggiorna_totali_D1(tipo); - - if (_quadro == "E") - aggiorna_totali_E(tipo); - - if (_quadro == "E1") - aggiorna_totali_E1(tipo); -} - -void TDicForm::set_body(TPrinter& pr, const char tipo, const bool progind) -{ - TPrint_section& body = section('B', odd_page); - body.reset(); - body.update(); - aggiorna_totali(tipo); - const int body_righe = body.height(); - for (int i=0; i < body_righe; i++) - { - pr.print(body.row(i)); - _RigaCorr++; - } - if (progind) - _prog->addstatus(1); -} - - -void TDicForm::posiziona() -{ - _GiaPosizionato = TRUE; - _PaginaPosizionamento = TRUE; - - arrange_form(); -/**************************** - char str_pos[MAX_LEN]; - int i; - const int xip = ipx(); - const int yip = ipy(); - const int xfp = fpx(); //131; - - for (i=0; i < MAX_LEN; i++) str_pos[i] = ' '; - str_pos[0] = '\r'; - str_pos[0] = '\r'; - str_pos[xip] = str_pos[xfp] = char_to_pos(); - str_pos[xfp+1] = '\r'; - str_pos[xfp+1] = '\0'; - - bool parti = yesno_box("Conferma stampa riga di posizionamento ?"); - if (!parti) return; - - _GiaPosizionato = TRUE; - _PaginaPosizionamento = TRUE; - - do - { - if (!PrintLineNow(str_pos, xfp+1, hInst)) - message_box("PrintLineNow fallita!"); - } - while (!yesno_box("Posizione corretta ?")); -**************/ -} - -/////////////////////////////////////////////////////////////////////////////////////////// -// -// Quadro G -// -/////////////////////////////////////////////////////////////////////////////////////////// - -HIDDEN const int QG_FORMLEN = 72; -HIDDEN const int QG_PAGINE = 2; -HIDDEN const int HEADER_SECONDA_G = 7; - -class TQuadroG : public TDicForm -{ - private: - long _items_g, _items_gd; - void stampa_prospetti1_2(TPrinter& pr, const bool UsaProgind); - void stampa_prospetti3_4(TPrinter& pr, const bool UsaProgind); - - protected: - virtual void inc_curr_page(); - virtual void next_page(TPrinter& pr); - virtual void stampa_totali(TPrinter& pr) {} - virtual void aggiorna_totali(const char tipo) {} - virtual void set_body(TPrinter& pr, const char tipo, const bool UsaProgind) {} - - public: - virtual bool UsaSortedCursor() { return FALSE; } - virtual bool print(const long codditta, const long NumFis, const long NumNoFis); - void set_items_gd(const long itg, const long itgd) { _items_g = itg; _items_gd = itgd; } - - TQuadroG(const char* form, const char* quadro) : TDicForm(form, quadro), - _items_g(0L), _items_gd(0L) {} - virtual ~TQuadroG() {} -}; - - -void TQuadroG::inc_curr_page() -{ - if (_PaginaCorrente == PRIMA) - _PaginaCorrente = SECONDA; - else - if (_PaginaCorrente == SECONDA) - _PaginaCorrente = PRIMA; -} - - -void TQuadroG::next_page(TPrinter& pr) -{ - PagineQD PagCorr = curr_page(); - fill_page(pr, -1); - inc_curr_page(); -} - - -void TQuadroG::stampa_prospetti1_2(TPrinter& pr, const bool UsaProgind) -{ - TPrint_section& head = section('H', 1); - const word rr = head.height()-1; - TPrintrow& head_row = head.row(rr-1); - -// Setta il numero di pagina e poi lo incrementa - TForm_item& nf = head.find_field(H_NUM_FOGLIO); - TString fstr(10); fstr << _num_foglio; - nf.set(fstr); - _num_foglio++; - -// Setta il cod.fis. del dichiarante se necessario - if (tipo_ditta() == estinto) - { - TForm_item& cfd = head.find_field(H_COFI_DIC); - cfd.set(_cofi_dic); - } - - TCursor* cur = cursor(); - -// Prospetto n. 2 - TRectype& r = cur->curr(); - TToken_string p22(r.get("P22")); - TToken_string p23(r.get("P23")); - TToken_string p24(r.get("P24")); - TToken_string p25(r.get("P25")); - TToken_string p26(r.get("P26")); - - const int START_P2 = 56; - const int RIGHE_P2 = 5; - const int COL_P2 = 5; - int cols = 0; - for (int i = 0; i < RIGHE_P2; i++) - { - const int fc2 = START_P2 + cols; - TForm_item& c2 = head.find_field(fc2); - c2.set(p22.get(i)); - - const int fc3 = fc2 + 1; - TForm_item& c3 = head.find_field(fc3); - c3.set(p23.get(i)); - - const int fc4 = fc3 + 1; - TForm_item& c4 = head.find_field(fc4); - c4.set(p24.get(i)); - - const int fc5 = fc4 + 1; - TForm_item& c5 = head.find_field(fc5); - c5.set(p25.get(i)); - - const int fc6 = fc5 + 1; - TForm_item& c6 = head.find_field(fc6); - c6.set(p26.get(i)); - - cols += COL_P2; - } - -// Righe da saltare nelle prime pag. dei moduli successivi al primo (che' son -// senza le righe del posizionamento...) - int HEADER_PRIMA_NOPOS = 3; - head.update(); - for (word j = 0; j <= rr; j++) - { - if (j==0) - { - if (_modulaser) - { - TPrintrow& r = head.row(j); - if (!_GiaMessoStartDoc) - put_modulaser(r, STARTDOC); - put_modulaser(r, STARTDITTA); - put_modulaser(r, STARTPAGE, 1); - pr.print(r); - _RigaCorr++; - r.reset(); - HEADER_PRIMA_NOPOS--; - } - if (!PaginaPosizionamento()) - fill_page(pr, HEADER_PRIMA_NOPOS); - } - else - { - pr.print(head.row(j)); - _RigaCorr++; - } - } -} - -void TQuadroG::stampa_prospetti3_4(TPrinter& pr, const bool UsaProgind) -{ - TPrint_section& sez = section('B'); - const word rr = sez.height()-1; - sez.reset(); - TPrintrow& head_row = sez.row(rr-1); - -// Prospetto n. 3 - TCursor* cur = cursor(); - TRectype& r = cur->curr(); - TToken_string p33a(r.get("P33A")); - TToken_string p33b(r.get("P33B")); - TToken_string p35a(r.get("P35A")); - TToken_string p35b(r.get("P35B")); - TToken_string p36a(r.get("P36A")); - TToken_string p36b(r.get("P36B")); - -// colonna 2 e 7 - for (int i=1; i<=5; i++) - { - TForm_item& c2 = sez.find_field(i); - TForm_item& c7 = sez.find_field(i+65); - int src=0; // determina quale posizione va letta dalla token-string per il campo corrente - switch (i) - { - case 1: - src = 0; - break; - case 2: - src = 7; - break; - case 3: - src = 10; - break; - case 4: - src = 12; - break; - case 5: - src = 14; - break; - } - - c2.set(p33a.get(src)); - c7.set(p36b.get(src)); - } - - const int RIGHE_P3 = 20; - -// Colonna 3 - const int START_P3_COL3 = 6; - int c3=0; - for (i = 0; i < RIGHE_P3; i++) - { - c3 = START_P3_COL3 + i; - TForm_item& c5a = sez.find_field(c3); - c5a.set(p33b.get(i)); - } - -// Colonna 5 - const int START_P3_COL5 = c3 + 1; - int c5=0; - for (i = 0; i < RIGHE_P3; i++) - { - c5 = START_P3_COL5 + i; - TForm_item& c6a = sez.find_field(c5); - c6a.set(p35b.get(i)); - } - -// Colonna 6 - const int START_P3_COL6 = c5 + 1; - int c6=0; - for (i = 0; i < RIGHE_P3; i++) - { - c6 = START_P3_COL6 + i; - TForm_item& c6a = sez.find_field(c6); - c6a.set(p36a.get(i)); - } - - sez.update(); - const int sez_righe = sez.height(); - for (i=0; i < sez_righe; i++) - { - pr.print(sez.row(i)); - _RigaCorr++; - } - if (UsaProgind) - _prog->addstatus(1); -} - - -bool TQuadroG::print(const long codditta, const long NumFis, const long NumNoFis) -{ - TCursor* cur = cursor(); - - bool StabilitaInesistenzaNoFis = FALSE; - bool StabilitaInesistenzaFis = FALSE; - long CtrFis = NumFis; - long CtrNoFis = NumNoFis; - long PtrFis = -1L, PtrNoFis=-1L; - TPrinter& pr = printer(); - - _CtrFisStampati = _CtrNoFisStampati = 0; - _finite_fis = _finite_nofis = FALSE; - _GiaStampatiFis = _GiaStampatiNoFis = FALSE; - _EndPrintDitta = FALSE; // Vero se stampato l'ultimo record - bool LastRecord = FALSE; // Vero se letto l'ultimo record - - _PaginaCorrente = PRIMA; - _UsaProgind = FALSE; - - if (!InitPrint(codditta)) - return FALSE; - - for (int pagina=1; pagina <= QG_PAGINE; pagina++, next_page(pr)) - { - pr.formlen(QG_FORMLEN); - - if (_PaginaCorrente == PRIMA) - { - if (_modulaser) ClearFlagModulaser(); - - (*cur) = PtrFis >= 0L ? PtrFis : 0L; - stampa_prospetti1_2(pr, _UsaProgind); - } - - if (_PaginaCorrente == SECONDA) - { -// Reset del flag di pagina con posiz. - if (_posiziona && _PaginaPosizionamento) _PaginaPosizionamento = FALSE; - - fill_page(pr, HEADER_SECONDA_G); - stampa_prospetti3_4(pr, _UsaProgind); - } - } // for pagina.. - - return TRUE; -} - - -/////////////////////////////////////////////////////////////////////////////////////////// -// -// Distinta G -// -/////////////////////////////////////////////////////////////////////////////////////////// - -HIDDEN const int QGD_FORMLEN = 72; -HIDDEN const int QGD_PAGINE = 2; -HIDDEN const int HEADER_SECONDA_GD = 7; -HIDDEN const int QGD_RIGHE_PRIMA = 8; - -class TDistintaG : public TQuadroG -{ - private: - real _f_tot_utspet, _f_tot_utpag, _f_tot_rope, _f_tot_ropespet; - real _nf_tot_utspet, _nf_tot_utpag, _nf_tot_rope, _nf_tot_ropespet; - void aggiorna_totali(const char tipo); - void stampa_totali(TPrinter& pr); - void stampa_testata(TPrinter& pr); - virtual void next_page(TPrinter& pr); - virtual void set_body(TPrinter& pr, const char tipo, const bool UsaProgind); - - public: - virtual bool UsaSortedCursor() { return FALSE; } - virtual bool print(const long codditta, const long NumFis, const long NumNoFis); - - TDistintaG(const char* form, const char* quadro) : TQuadroG(form,quadro) {} - virtual ~TDistintaG() {} -}; - -void TDistintaG::next_page(TPrinter& pr) -{ - PagineQD PagCorr = curr_page(); -// if (PagCorr == SECONDA) - stampa_totali(pr); - fill_page(pr, -1); // formfeed "adattato" - inc_curr_page(); -} - -void TDistintaG::aggiorna_totali(const char tipo) -{ - real utspet, utpag, rope, ropespet; - TCursor* cur = cursor(); - TRectype& crr = cur->curr(); - - utspet = crr.get_real(QGD_UTSPETT); - utpag = crr.get_real(QGD_UTPAG); - rope = crr.get_real(QGD_ROPE); - ropespet = crr.get_real(QGD_ROPESPET); - - if (tipo == 'F') - { - _f_tot_utspet += utspet; - _f_tot_utpag += utpag; - _f_tot_rope += rope; - _f_tot_ropespet += ropespet; - } - else - { - _nf_tot_utspet += utspet; - _nf_tot_utpag += utpag; - _nf_tot_rope += rope; - _nf_tot_ropespet += ropespet; - } -} - - -void TDistintaG::stampa_totali(TPrinter& pr) -{ - PagineQD PagCorr = curr_page(); - TPrint_section& foot = section('B', even_page); - const word righe = foot.height(); - const char* pic = "############"; - bool stampa = FALSE; - - TForm_item& ttotale = foot.find_field(TOT_TOTALE); - TForm_item& tsnsrit = foot.find_field(TOT_SNSRIT); - TForm_item& timpon = foot.find_field(TOT_IMPON); - TForm_item& timpor = foot.find_field(TOT_IMPOR); - - const bool stampa_tot_fis = ultima_fis(); - const bool stampa_tot_nofis = ultima_nofis(); - - if (stampa_tot_fis) - if (PagCorr == PRIMA) // Scrive totali p.fisiche - { - stampa=TRUE; - TString ftot(_f_tot_utspet.string(pic)); - TString fsnsrit(_f_tot_utpag.string(pic)); - TString fimpon(_f_tot_rope.string(pic)); - TString fimpor(_f_tot_ropespet.string(pic)); - -// Toglie le migliaia - ftot.cut(ftot.len() - 3); - fsnsrit.cut(fsnsrit.len()-3); - fimpon.cut(fimpon.len()-3); - fimpor.cut(fimpor.len()-3); - if (ftot.empty()) ftot = "0"; - if (fsnsrit.empty()) fsnsrit = "0"; - if (fimpon.empty()) fimpon = "0"; - if (fimpor.empty()) fimpor = "0"; - -// Setta i campi - ttotale.set(ftot); - tsnsrit.set(fsnsrit); - timpon.set(fimpon); - timpor.set(fimpor); - - _GiaStampatiFis = TRUE; -const int NUMPER_TERZA = 6; -const int NUM_RIGHE = 8; - const int gap = ((NUMPER_TERZA - _CtrFisStampati) * NUM_RIGHE)+1; - if (gap>0) - fill_page(pr,gap); - } - - if (stampa_tot_nofis) - if (PagCorr == SECONDA) // Scrive totali p.non fisiche - { - stampa=TRUE; - TString ftot (_nf_tot_utspet.string(pic)); - TString fsnsrit(_nf_tot_utpag.string(pic)); - TString fimpon (_nf_tot_rope.string(pic)); - TString fimpor (_nf_tot_ropespet.string(pic)); - -// Toglie le migliaia - ftot.cut(ftot.len() - 3); - fsnsrit.cut(fsnsrit.len()-3); - fimpon.cut(fimpon.len()-3); - fimpor.cut(fimpor.len()-3); - - if (ftot.empty()) ftot = "0"; - if (fsnsrit.empty()) fsnsrit = "0"; - if (fimpon.empty()) fimpon = "0"; - if (fimpor.empty()) fimpor = "0"; - -// Setta i campi - ttotale.set(ftot); - tsnsrit.set(fsnsrit); - timpon.set(fimpon); - timpor.set(fimpor); - - _GiaStampatiNoFis = TRUE; -const int NUMPER_QUARTA = 6; -const int NUM_RIGHE = 8; - const int gap = ((NUMPER_QUARTA - _CtrNoFisStampati) * NUM_RIGHE)+1; - - if (gap > 0) - fill_page(pr,gap); - } - if (stampa) - { - foot.update(); - for (word j = 0; j < righe; j++) - { - pr.print(foot.row(j)); - _RigaCorr++; - } - foot.reset(); // non stampare piu' questi totali! - } -} - -void TDistintaG::stampa_testata(TPrinter& pr) -{ - TPrint_section& head = section('H', 1); - const word r = head.height()-1; - TPrintrow& head_row = head.row(r-1); - -// Setta il numero di pagina e poi lo incrementa - TForm_item& nf = head.find_field(H_NUM_FOGLIO); - TString fstr(10); fstr << _num_foglio; - nf.set(fstr); - _num_foglio++; -} - -void TDistintaG::set_body(TPrinter& pr, const char tipo, const bool progind) -{ - TPrint_section& body = section('B', odd_page); - body.reset(); - body.update(); - aggiorna_totali(tipo); - const int body_righe = body.height(); - for (int i=0; i < body_righe; i++) - { - pr.print(body.row(i)); - _RigaCorr++; - } - if (progind) - _prog->addstatus(1); -} - - -bool TDistintaG::print(const long codditta, const long NumFis, const long NumNoFis) -{ - TCursor* cur = cursor(); - - bool StabilitaInesistenzaNoFis = FALSE; - bool StabilitaInesistenzaFis = FALSE; - long CtrFis = NumFis; - long CtrNoFis = NumNoFis; - long PtrFis = -1L, PtrNoFis=-1L; - TPrinter& pr = printer(); - - _CtrFisStampati = _CtrNoFisStampati = 0; - _finite_fis = _finite_nofis = FALSE; - _GiaStampatiFis = _GiaStampatiNoFis = FALSE; - _EndPrintDitta = FALSE; // Vero se stampato l'ultimo record - bool LastRecord = FALSE; // Vero se letto l'ultimo record - _PaginaCorrente = PRIMA; - - _codditta = codditta; - _RigaCorr = 0; - - const long items = filtra(codditta); - - while (!_EndPrintDitta) - { - for (int pagina=1; pagina <= QGD_PAGINE; pagina++, next_page(pr)) - { - pr.formlen(QGD_FORMLEN); - - if (_PaginaCorrente == PRIMA) - { - if (_modulaser) ClearFlagModulaser(); - - for (int righe=0; righe < QGD_RIGHE_PRIMA; righe++) - { -// Stampa intestazione, solo sul primo foglio. - if (!righe) - { - (*cur) = PtrFis >= 0L ? PtrFis : 0L; - stampa_testata(pr); - } - - if (_finite_fis || StabilitaInesistenzaFis) - break; - -// La prima volta si deve posizionare sul primo record di p.f. - if (PtrFis<0L && !StabilitaInesistenzaFis) - { - bool Trovato = FALSE; - - while (!Trovato) - { - const long ditta = cur->curr().get_long(QGD_CODDITTA); - if (ditta != codditta) - break; - const char tipo = cur->curr().get(QGD_TIPOA)[0]; - if (tipo != 'G') - { - PtrFis = cur->pos(); - Trovato = TRUE; - break; - } - else - ++(*cur); - } - StabilitaInesistenzaFis = !Trovato; - } - - if (StabilitaInesistenzaFis) - break; - - (*cur) = PtrFis; - const char tipo = cur->curr().get(QGD_TIPOA)[0]; - - if (tipo != 'F') - break; - else - { - CtrFis--; - if (CtrFis == 0L) _finite_fis = TRUE; - set_body(pr, 'F', _UsaProgind); -// La stampa e' finita se ho STAMPATO l'ultimo record - LastRecord = cur->pos() >= items-1; - _EndPrintDitta = LastRecord; - if (!LastRecord) - { - ++(*cur); - PtrFis = cur->pos(); - LastRecord = cur->pos() >= items-1; - } - } - } // for righe.. - PtrFis = cur->pos(); - } - - if (_PaginaCorrente == SECONDA) - { -// Reset del flag di pagina con posiz. - if (_posiziona && _PaginaPosizionamento) _PaginaPosizionamento = FALSE; - for (int righe=0; righe < QD_RIGHE_SECONDA; righe++) - { - if (!righe) - _CtrNoFisStampati = 0; - -// All'inizio salta le righe in alto - if (!righe) - fill_page(pr, HEADER_SECONDA_GD); - - if (_finite_nofis || StabilitaInesistenzaNoFis) - break; - -// La prima volta si deve posizionare sul primo record di p.g. - if (PtrNoFis<0L && !StabilitaInesistenzaNoFis) - { - bool Trovato = FALSE; - bool eof = FALSE; - (*cur) = PtrFis-1 > 0L ? PtrFis-1 : 0L; // parti dall'inizio - while (!Trovato && !eof) - { - eof = cur->pos() >= items-1; - const long ditta = cur->curr().get_long(QGD_CODDITTA); - if (ditta != codditta) - break; - const char tipo = cur->curr().get(QGD_TIPOA)[0]; - if (tipo != 'F') - { - PtrNoFis = cur->pos(); - Trovato = TRUE; - break; - } - else - ++(*cur); - } - StabilitaInesistenzaNoFis = !Trovato; - } - - if (StabilitaInesistenzaNoFis) - break; - - (*cur) = PtrNoFis; - const char tipo = cur->curr().get(QGD_TIPOA)[0]; - - if (tipo != 'G') - break; - else - { - CtrNoFis--; - if (CtrNoFis == 0L) _finite_nofis = TRUE; - set_body(pr, 'G', _UsaProgind); - LastRecord = cur->pos() >= items-1; - _EndPrintDitta = LastRecord; - _CtrNoFisStampati++; - if (!LastRecord) - { - ++(*cur); - PtrNoFis = cur->pos(); - LastRecord = cur->pos() >= items-1; - } - } - } - PtrNoFis = cur->pos(); - } - } // for pagina.. - } // while !EndPrintDitta - if (_UsaProgind) delete _prog; - return TRUE; -} - - -/////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////// - - - -//////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////// -// -// TStDicArray -// -// Array delle ditte da stampare. Contiene una riga per ogni ditta che si vuole stampare -// Il formato della riga e': -// codditta|estinti|numfis|numnofis|ultimafis|ultimanofis -// -///////////////////////////////////////////////////////////////////////////////////////////// - -class TStDicArray : public TObject -{ - private: - TArray _store; - public: - TToken_string& operator[](int i); - int curr_index() const { return _store.last(); } - void set(const int index, const TipoDitta tipo=normale, const int num_fis=0, const int num_nofis=0, - bool ultima_con_fis=FALSE, bool ultima_con_nofis=FALSE, const char* cofidic=NULL); - void set_tipo(const int index, const TipoDitta tipo); - void set_ultima_con_fis(const int index, const bool ultima_fis); - void set_ultima_con_nofis(const int index, const bool ultima_nofis); - void set_flag_tipi(const int index, const bool ultima_fis, const bool ultima_nofis); - void set_ctr_tipi(const int index, const int num_fis, const int num_nofis); - void add(const long codditta, const TipoDitta tipo=normale, const int num_fis=0, const int num_nofis=0, - bool ultima_con_fis=FALSE, bool ultima_con_nofis=FALSE, const char* cofidic=NULL); - int items() const { return _store.items(); } - void destroy() { _store.destroy(); } -}; - - -TToken_string& TStDicArray::operator[](int i) -{ - __dep80 = (TToken_string&)_store[i]; - return (TToken_string&)__dep80; -} - -void TStDicArray::set_ultima_con_fis(const int index, const bool ultima_fis) -{ - TToken_string riga((TString&)_store[index]); - riga.add(ultima_fis, 4); - _store.add(riga,index); -} - -void TStDicArray::set_ultima_con_nofis(const int index, const bool ultima_nofis) -{ - TToken_string riga((TString&)_store[index]); - riga.add(ultima_nofis, 5); - _store.add(riga,index); -} - -void TStDicArray::set_flag_tipi(const int index, const bool ultima_fis, const bool ultima_nofis) -{ - TToken_string riga((TString&)_store[index]); - riga.add(ultima_fis,4); - riga.add(ultima_nofis,5); - _store[index] = riga; -} - -void TStDicArray::set_ctr_tipi(const int index, const int num_fis, const int num_nofis) -{ - TToken_string riga((TString&)_store[index]); - riga.add(num_fis,2); - riga.add(num_nofis,3); - _store[index] = riga; -} - -void TStDicArray::set(const int index, const TipoDitta tipo, const int num_fis, const int num_nofis, - bool ultima_con_fis, bool ultima_con_nofis, const char* cofi_dic) -{ - TToken_string riga((TString&)_store[index]); - riga.add(tipo,1); - riga.add(num_fis,2); - riga.add(num_nofis,3); - riga.add(ultima_con_fis,4); - riga.add(ultima_con_nofis,5); - TString codfis(20); codfis = cofi_dic ? cofi_dic : ""; - riga.add((const char*)codfis,6); - _store[index] = riga; -} - -void TStDicArray::add(const long codditta, const TipoDitta tipo, const int num_fis, const int num_nofis, - bool ultima_con_fis, bool ultima_con_nofis, const char* cfdic) -{ - TString key(40); -// Il formato della riga e': codditta|estinti|numfis|numnofis|ultimafis|ultimanofis - key.format("%ld|%d|%d|%d|%d|%d|%s", codditta, tipo, num_fis, num_nofis, ultima_con_fis, ultima_con_nofis, cfdic ? cfdic : ""); - _store.add(key); -} - - - -///////////////////////////////////////////////////////////////////////////////////////////// -// -// STAMPA QUADRO D -// -///////////////////////////////////////////////////////////////////////////////////////////// -class TStampaQuadro : public TApplication -{ - private: - TDicForm* _form; - - protected: - TMask* _m; - TRelation* _rel; - TCursor* _cur; - TSorted_cursor* _sorted_cur; - TString16 _quadro; - TString80 _title; - char _livello; // "S" studio, "D" singola ditta - long _codditta; - TStDicArray _ditte; - TConfig* _cnf; - TString16 _section; - bool _singola_ditta; - int _anno_dic; - - virtual TDicForm* build_form(); - virtual TCursor* build_cursor(); - virtual TDicForm* get_form() const { return _form; } - virtual TRelation* get_relation() const { return _rel; } - virtual TCursor* get_cursor() const { return _cur; } - virtual TSorted_cursor* get_sorted_cursor() const { return _sorted_cur; } - - virtual void on_config_change(); - virtual void fill_estinti(const long CodDic); - virtual void print(); - virtual bool create(); - virtual bool destroy(); - virtual bool menu(MENU_TAG); - virtual const char* mask(const char* quadro); - virtual bool print_quadro(TString& quadro, const int OffsetDitta=-1); - virtual bool UsaSortedCursor() const { return TRUE; } - virtual bool ContaTipiPer() const { return TRUE; } - - public: - virtual TSorted_cursor* sorted_cur() const { return _sorted_cur; } - - const char* taitol() { return _title; } - TStampaQuadro(const char* quadro, const char livel); -}; - -void TStampaQuadro::on_config_change() -{ - TConfig conf(_singola_ditta ? CONFIG_STUDIO : CONFIG_USER); - _anno_dic = (int)conf.get_long(ANNO_SEL, _section); -} - -TStampaQuadro::TStampaQuadro(const char* quadro, const char liv) -{ - _quadro = quadro; - _livello = liv; - _singola_ditta = _livello == 'D'; - _title = "Stampa quadro "; - _title << _quadro; -} - -const char* form(TString& quadro) -{ - __dep16 = "77Q"; - __dep16 << quadro; - return __dep16; -} - -// La maschera e' uguale per tutti i quadri -const char* TStampaQuadro::mask(const char* quadro) -{ - return "77STQD"; -} - -TCursor* TStampaQuadro::build_cursor() -{ - if (_quadro == "C") - { - _rel = new TRelation(LF_QUAC); - _rel->add("%ca7", "CODTAB=CODCAUS", 1, LF_QUAC, 14); - _rel->add(LF_NDITTE, "CODDITTA=CODDITTA"); - _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); - _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); - _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); - _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); - _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_QUAC, 216); - _rel->add("%STA", "CODTAB=STATORES", 1, -216, 24); - _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, -216, 218); - _rel->add(LF_COMUNI, "COM=COMNASC", 1, -218, 313); - _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, -216, 413); - _sorted_cur = new TSorted_cursor(_rel, "CODDITTA|TIPOA|216@->RAGSOC|CODANAGR|CODCAUS|PERC"); - } - - if (_quadro == "D") - { - _rel = new TRelation(LF_QUAD); - _rel->add("%ca7", "CODTAB=CODCAUS", 1, LF_QUAD, 14); - _rel->add(LF_NDITTE, "CODDITTA=CODDITTA"); - _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); - _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); - _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); - _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); - _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_QUAD, 216); - _rel->add("%STA", "CODTAB=STATORES", 1, -216, 24); - _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, -216, 218); - _rel->add(LF_COMUNI, "COM=COMNASC", 1, -218, 313); - _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, -216, 413); - _sorted_cur = new TSorted_cursor(_rel, "CODDITTA|TIPOA|216@->RAGSOC|CODANAGR|CODCAUS|PERC"); - } - - if (_quadro == "D1") - { - _rel = new TRelation(LF_QUAD1); - _rel->add("%ca7", "CODTAB=CODCAUS", 1, LF_QUAD1, 14); - _rel->add(LF_NDITTE, "CODDITTA=CODDITTA"); - _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); - _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); - _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); - _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); - _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_QUAD1, 216); - _rel->add("%STA", "CODTAB=STATORES", 1, -216, 24); - _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, -216, 218); - _rel->add(LF_COMUNI, "COM=COMNASC", 1, -218, 313); - _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, -216, 413); - _sorted_cur = new TSorted_cursor(_rel, "CODDITTA|TIPOA|216@->RAGSOC|CODANAGR|CODCAUS|PERC"); - } - - if (_quadro == "E") - { - _rel = new TRelation(LF_QUAE); - _rel->add("%ca7", "CODTAB=CODCAUS", 1, LF_QUAE, 14); - _rel->add(LF_NDITTE, "CODDITTA=CODDITTA"); - _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); - _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); - _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); - _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); - _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_QUAE, 216); - _rel->add("%STA", "CODTAB=STATORES", 1, -216, 24); - _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, -216, 218); - _rel->add(LF_COMUNI, "COM=COMNASC", 1, -218, 313); - _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, -216, 413); - _sorted_cur = new TSorted_cursor(_rel, "CODDITTA|TIPOA|216@->RAGSOC|CODANAGR|CODCAUS|PERC"); - } - - if (_quadro == "E1") - { - _rel = new TRelation(LF_QUAE1); - _rel->add("%ca7", "CODTAB=CODCAUS", 1, LF_QUAE1, 14); - _rel->add(LF_NDITTE, "CODDITTA=CODDITTA"); - _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); - _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); - _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); - _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); - _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_QUAE1, 216); - _rel->add("%STA", "CODTAB=STATORES", 1, -216, 24); - _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, -216, 218); - _rel->add(LF_COMUNI, "COM=COMNASC", 1, -218, 313); - _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, -216, 413); - _sorted_cur = new TSorted_cursor(_rel, "CODDITTA|TIPOA|216@->RAGSOC|CODANAGR|CODCAUS|PERC"); - } - return _sorted_cur; -} - -TDicForm* TStampaQuadro::build_form() -{ - _form = new TDicForm(form(_quadro), _quadro); - return _form; -} - -bool TStampaQuadro::create() -{ - TApplication::create(); - - hInst = (HWND)xvt_vobj_get_attr(TASK_WIN, ATTR_NATIVE_WINDOW); // Usato in posiziona() - - _form = build_form(); - - _section = name(); - _section.cut(2); - _cnf = new TConfig(CONFIG_USER, _section); - - _m = new TMask(mask(_quadro)); - _m->set_caption(taitol()); - - if (_singola_ditta) - { - _codditta = get_firm_770(); - _m->set(F_CODDITTA, _codditta); - } - else - { - _m->hide(F_RAGDITTA); - _m->set(F_TEXT, "Ditte selezionate"); - _m->show(F_TEXT); - } - - if (UsaSortedCursor()) - _sorted_cur = (TSorted_cursor*)build_cursor(); - else - _cur = build_cursor(); - - dispatch_e_menu(BAR_ITEM(1)); - return TRUE; -} - -bool TStampaQuadro::destroy() -{ - delete _m; - delete _rel; - if (UsaSortedCursor()) - delete _sorted_cur; - else - delete _cur; - delete _cnf; - delete _form; - return TApplication::destroy(); -} - -bool TStampaQuadro::menu(MENU_TAG) -{ - KEY k; - _m->set(F_ANNO, _anno_dic); - while ((k = _m->run()) == K_ENTER) - print(); - return FALSE; -} - -// _ditte e' fatto di righe siffatte: -// codditta, flag 2 dichiarante, 1 normale, 0 estinto, num_fis, num_nofis, ultima_con_fis, ultima_con_nofis -bool TStampaQuadro::print_quadro(TString& quadro, const int OffsetDitta) -{ - TDicForm* ff = get_form(); - int start=0, last=0; -// Setta formlen prima di printer.open per avere la lunghezza giusta nel caso di -// stampa a video - printer().formlen(QD_FORMLEN); - bool ok = printer().open(); - bool modulaser = _m->get_bool(F_MODULASER); - - if (UsaSortedCursor()) - ff->set_cur_rel(get_relation(), get_sorted_cursor()); - else - ff->set_cur_rel(get_relation(), get_cursor()); - - ff->azzera_totali(); - ff->set_modulaser(modulaser); - -// Dice se deve eseguire il posizionamento del foglio. -// Se stampa piu' ditte va eseguito solo sulla prima -// Occhio a non spostarlo nel ciclo. - ff->set_posiziona(TRUE); - - if (OffsetDitta >= 0) - { - start = OffsetDitta; - last = OffsetDitta; - } - else - last = _ditte.items() - 1; - - for (int i = start; i <= last; i++) - { - TString CoFiDic(20); - TToken_string riga(_ditte[i]); - riga.separator('|'); - const long codditta = atol(riga.get(0)); - const TipoDitta tipo = (TipoDitta)riga.get_int(1); - const long fis = riga.get_long(2); - const long nofis = riga.get_long(3); - const bool LastFis = (bool)riga.get_int(4); - const bool LastNoFis = (bool)riga.get_int(5); - -// I gruppi dich-estinti hanno totali comuni -// Si presume che nell'array vengano messi nell'ordine dich-estinti - if (tipo == normale || tipo == dichiarante) - ff->azzera_totali(); - - if (tipo == estinto) - CoFiDic = riga.get(6); - - if (ContaTipiPer()) - { -// Se e' un dichiarante i totali vanno sull'estinto in cui finiscono o le F o le G - const bool StampaTotaliFis = tipo == normale || - (tipo == estinto && LastFis); - - const bool StampaTotaliNoFis = tipo == normale || - (tipo == estinto && LastNoFis); - -// Dice al form se e' questa ditta e' l'ultima con f. o g. - ff->can_print_tot_fis(StampaTotaliFis); - ff->can_print_tot_nofis(StampaTotaliNoFis); - } - -// Dice al form che tipo di ditta si stampa - ff->set_tipo_ditta(tipo); - -// Numera i fogli a partire da 1 per ogni ditta normale e da 1 e di seguito negli estinti -// per i sogg. dichiaranti - if (tipo == normale || tipo == dichiarante) - ff->set_num_foglio(1); - -// Se la ditta e' estinta dice al form il cod.fis. del dichiarante - if (tipo == estinto) - ff->set_cofi_dic(CoFiDic); - -// Dice al form che e' l'ultima ditta - if (i == last) - ff->set_last_ditta(TRUE); - - ff->print(codditta, fis, nofis); - } - - printer().close(); - return ok; -} - -void TStampaQuadro::fill_estinti(const long CodDic) -{ - int NumFisiche=0, NumNoFisiche=0; - TString CodFiDic(20); - -// Salva il cod.fis. del dichiarante - CodFiDic = cod_fis(CodDic); - - if (ContaTipiPer()) - { - conta_tipiper(CodDic, _quadro, &NumFisiche, &NumNoFisiche); - _ditte.add(CodDic, dichiarante, NumFisiche, NumNoFisiche); - } - else - _ditte.add(CodDic, dichiarante); - - const int index_dich = _ditte.curr_index(); - bool gia_trovata_ultima_fis = FALSE; - bool gia_trovata_ultima_nofis = FALSE; - int index = index_dich; - -// Leggo gli estinti - TLocalisamfile base(LF_BASE); - base.setkey(2); - base.zero(); - base.put(BSE_CODDIC, (long)CodDic); - TRectype dep(base.curr()); - - for (base.read(); !base.eof(); base.next()) - { - if (base.curr() > dep) - break; - -// Scarta il record del quadro I "globale" del dichiarante - const char tipoqua = base.get(BSE_TIPOQUA)[0]; - if (tipoqua == COD_QUA_I_DIC) - continue; - - const long DittaEstinta = base.get_long(BSE_CODDITTA); - - if (ContaTipiPer()) - { - conta_tipiper(DittaEstinta, _quadro, &NumFisiche, &NumNoFisiche); - _ditte.add(DittaEstinta, estinto, NumFisiche, NumNoFisiche, FALSE, FALSE, CodFiDic); - } - else - _ditte.add(DittaEstinta, estinto, 0L, 0L, FALSE, FALSE, CodFiDic); - - if (ContaTipiPer()) - { - // Determina se con questa ditta finiscono le persone f. o g. - if (NumFisiche == 0 && !gia_trovata_ultima_fis) - { - _ditte.set_ultima_con_fis(index, TRUE); - gia_trovata_ultima_fis = TRUE; - } - - if (NumNoFisiche == 0 && !gia_trovata_ultima_nofis) - { - _ditte.set_ultima_con_nofis(index, TRUE); - gia_trovata_ultima_nofis = TRUE; - } - } - index++; - } - - if (ContaTipiPer()) - { -// Finiti gli estinti. L'ultima ditta deve avere i totali se non gia' trovati - if (!gia_trovata_ultima_fis) - _ditte.set_ultima_con_fis(index, TRUE); - - if (!gia_trovata_ultima_nofis) - _ditte.set_ultima_con_nofis(index, TRUE); - } -} - -void TStampaQuadro::print() -{ - int NumFisiche=0, NumNoFisiche=0; - - _ditte.destroy(); // Pulisce l'array delle ditte - - if (_singola_ditta) - { - if (sogg_estinto(_codditta)) - { - warning_box("La ditta %ld e' un soggetto estinto", _codditta); - return; - } - -// Se e' un dichiarante va a prendere tutti i suoi estinti. - bool dich = sogg_dic(_codditta); - if (dich) - fill_estinti(_codditta); - else - { - if (ContaTipiPer()) - { - conta_tipiper(_codditta, _quadro, &NumFisiche, &NumNoFisiche); - _ditte.add(_codditta, normale, NumFisiche, NumNoFisiche); - } - else - _ditte.add(_codditta, normale); - } - } - else // stampa ditte selezionate - { -// Costruisco un'array delle ditte da stampare. -// Tolgo i sogg. estinti, e dopo un dichiarante metto tutti i suoi estinti. - long codditta_prec = get_firm_770(); - long codditta = 0L; - int i=0; - while ((codditta = _cnf->get_long(DITTE_SEL, _section, i++)) != 0L) - { - if (sogg_estinto(codditta)) - continue; - -// Se e' un dichiarante va a prendere tutti i suoi estinti. - bool dich = sogg_dic(codditta); - if (dich) - fill_estinti(codditta); - else - { - if (ContaTipiPer()) - { - conta_tipiper(codditta, _quadro, &NumFisiche, &NumNoFisiche); - _ditte.add(codditta, normale, NumFisiche, NumNoFisiche); - } - else - _ditte.add(codditta, normale); - } - } - set_firm_770(codditta_prec); - } - print_quadro(_quadro, -1); -} - - -///////////////////////////////////////////////////////////////////////////////////////////// -// -// STAMPA QUADRO G -// -///////////////////////////////////////////////////////////////////////////////////////////// -class TStampaQuadroG : public TStampaQuadro -{ - private: - TQuadroG* _form_g; - TDistintaG* _form_gd; - TRelation* _rel_g, * _rel_gd; - TCursor* _cur_g, * _cur_gd; - - protected: - virtual TCursor* build_cursor(); - virtual TDicForm* build_form(); - virtual TDicForm* get_form() const { return _form_g; } - virtual bool destroy(); - bool print_quadro(TString& quadro, const int OffsetDitta=-1); - - public: - TStampaQuadroG(const char* quadro, const char livel) : TStampaQuadro(quadro,livel) {} -}; - -TDicForm* TStampaQuadroG::build_form() -{ - _form_g = new TQuadroG("77QG", _quadro); - _form_gd = new TDistintaG("77QGD", _quadro); - return _form_g; -} - -TCursor* TStampaQuadroG::build_cursor() -{ - _rel_g = new TRelation(LF_QUAG); - _rel_g->add(LF_NDITTE, "CODDITTA=CODDITTA"); - _rel_g->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); - _rel_g->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); - _rel_g->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); - _rel_g->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); - _cur_g = new TCursor(_rel_g); - - _rel_gd = new TRelation(LF_QUAGD); - _rel_gd->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_QUAGD, 216); - _rel_gd->add("%STA", "CODTAB=STATORES", 1, -216, 24); - _rel_gd->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, -216, 218); - _rel_gd->add(LF_COMUNI, "COM=COMNASC", 1, -218, 313); - _rel_gd->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, -216, 413); - _cur_gd = new TSorted_cursor(_rel_gd, "CODDITTA|TIPOA|216@->RAGSOC|CODANAGR"); - - return _cur_g; -} - -bool TStampaQuadroG::destroy() -{ - delete _m; - delete _rel_g; - delete _rel_gd; - delete _cur_gd; - delete _cur_g; - delete _cnf; - delete _form_g; - delete _form_gd; - return TApplication::destroy(); -} - -// _ditte e' fatto di righe siffatte: -// codditta, flag 2 dichiarante, 1 normale, 0 estinto, num_fis, num_nofis, ultima_con_fis, ultima_con_nofis -bool TStampaQuadroG::print_quadro(TString& quadro, const int OffsetDitta) -{ - int start=0, last=0; - long items_g, items_gd; - - items_g = items_gd = 0L; -// Setta formlen prima di printer.open per avere la lunghezza giusta nel caso di -// stampa a video - printer().formlen(QG_FORMLEN); - bool ok = printer().open(); - bool modulaser = _m->get_bool(F_MODULASER); - - _form_g->set_cur_rel(_rel_g, _cur_g); - _form_gd->set_cur_rel(_rel_gd, _cur_gd); - - _form_g->set_modulaser(modulaser); - _form_gd->set_modulaser(modulaser); - - _form_gd->azzera_totali(); - -// Dice se deve eseguire il posizionamento del foglio. -// Se stampa piu' ditte va eseguito solo sulla prima -// Occhio a non spostarlo nel ciclo. - _form_g->set_posiziona(TRUE); - - if (OffsetDitta >= 0) - { - start = OffsetDitta; - last = OffsetDitta; - } - else - last = _ditte.items() - 1; - - for (int i = start; i <= last; i++) - { - TString CoFiDic(20); - TToken_string riga(_ditte[i]); - riga.separator('|'); - const long codditta = atol(riga.get(0)); - const TipoDitta tipo = (TipoDitta)riga.get_int(1); - const long fis = riga.get_long(2); - const long nofis = riga.get_long(3); - const bool LastFis = (bool)riga.get_int(4); - const bool LastNoFis = (bool)riga.get_int(5); - -// I gruppi dich-estinti hanno totali comuni -// Si presume che nell'array vengano messi nell'ordine dich-estinti - if (tipo == normale || tipo == dichiarante) - _form_g->azzera_totali(); - - if (tipo == estinto) - CoFiDic = riga.get(6); - -// Se e' un dichiarante i totali vanno sull'estinto in cui finiscono o le F o le G - const bool StampaTotaliFis = tipo == normale || - (tipo == estinto && LastFis); - - const bool StampaTotaliNoFis = tipo == normale || - (tipo == estinto && LastNoFis); - -// Dice al form se e' questa ditta e' l'ultima con f. o g. - _form_gd->can_print_tot_fis(StampaTotaliFis); - _form_gd->can_print_tot_nofis(StampaTotaliNoFis); - -// Dice al form che tipo di ditta si stampa - _form_g->set_tipo_ditta(tipo); - -// Numera i fogli a partire da 1 per ogni ditta normale e da 1 e di seguito negli estinti -// per i sogg. dichiaranti - if (tipo == normale || tipo == dichiarante) - _form_g->set_num_foglio(1); - -// Se la ditta e' estinta dice al form il cod.fis. del dichiarante - if (tipo == estinto) - _form_g->set_cofi_dic(CoFiDic); - -// Dice al form che e' l'ultima ditta - if (i == last) - _form_gd->set_last_ditta(TRUE); - - items_g = _form_g->filtra(codditta); - items_gd = _form_gd->filtra(codditta); - -// Dice al form quanto e' lunga la progress-bar - _form_g->set_items_gd(items_g, items_gd); - - _form_g->print(codditta, fis, nofis); -// La progind deve essere la stessa tra G e distinta... - _form_gd->set_progind(_form_g->progind(), _form_g->usaprogind()); - _form_gd->print(codditta, fis, nofis); - } - - printer().close(); - return ok; -} - -/////////////////////////////////////////////////////////////////////////////////////////// -// -// Quadro G-1 -// -/////////////////////////////////////////////////////////////////////////////////////////// - -HIDDEN const int QG1_FORMLEN = 72; -HIDDEN const int QG1_PAGINE = 1; - -class TQuadroG1 : public TDicForm -{ - private: - long _items; - void stampa_prospetto(TPrinter& pr, const bool UsaProgind); - - public: - virtual bool UsaSortedCursor() { return FALSE; } - virtual bool print(const long codditta, const long NumFis=0L, const long NumNoFis=0L); - //virtual bool print(const long codditta); - - TQuadroG1(const char* form, const char* quadro) : TDicForm(form, quadro) {} - virtual ~TQuadroG1() {} -}; - -bool TQuadroG1::print(const long codditta, const long NumFis, const long NumNoFis) -{ - TCursor* cur = cursor(); - TPrinter& pr = printer(); - _UsaProgind = FALSE; - - if (!InitPrint(codditta)) - return FALSE; - - pr.formlen(QG1_FORMLEN); - - if (_modulaser) ClearFlagModulaser(); - - (*cur) = 0L; - stampa_prospetto(pr, _UsaProgind); - - return TRUE; -} - -void TQuadroG1::stampa_prospetto(TPrinter& pr, const bool UsaProgind) -{ - TPrint_section& head = section('H', 1); - const word rr = head.height()-1; - TPrintrow& head_row = head.row(rr-1); - -// Setta il cod.fis. del dichiarante se necessario - if (tipo_ditta() == estinto) - { - TForm_item& cfd = head.find_field(H_COFI_DIC); - cfd.set(_cofi_dic); - } - - TCursor* cur = cursor(); -// Prospetto - TRectype& r = cur->curr(); - TToken_string p12(r.get("P12")); - TToken_string p13(r.get("P13")); - TToken_string p14(r.get("P14")); - TToken_string p15(r.get("P15")); - TToken_string p16(r.get("P16")); - TToken_string p17(r.get("P17")); - - const int START_PROSP = 56; - const int RIGHE_COL356 = 12; - const int RIGHE_COL27 = 5; - const int COL_PROSP = 5; - -// Colonne 2 e 7 - for (int i = 0; i < RIGHE_COL27; i++) - { - const int fc2 = START_PROSP + i; - TForm_item& c2 = head.find_field(fc2); - c2.set(p12.get(i)); - - const int fc7 = fc2 + RIGHE_COL27 + 1; - TForm_item& c7 = head.find_field(fc7); - c7.set(p17.get(i)); - } - - const int START_COL3 = 68; -// Colonne 3 5 e 6 - for (i = 0; i < RIGHE_COL356; i++) - { - const int fc3 = START_COL3 + i; - TForm_item& c3 = head.find_field(fc3); - c3.set(p13.get(i)); - - const int fc5 = fc3 + RIGHE_COL356 + 1; - TForm_item& c5 = head.find_field(fc5); - c5.set(p15.get(i)); - - const int fc6 = fc5 + RIGHE_COL356 + 1; - TForm_item& c6 = head.find_field(fc6); - c6.set(p16.get(i)); - } - -// Righe da saltare nelle prime pag. dei moduli successivi al primo (che' son -// senza le righe del posizionamento...) - int HEADER_PRIMA_NOPOS = 3; - head.update(); - for (word j = 0; j <= rr; j++) - { - if (j==0) - { - if (_modulaser) - { - TPrintrow& r = head.row(j); - if (!_GiaMessoStartDoc) - put_modulaser(r, STARTDOC); - put_modulaser(r, STARTDITTA); - put_modulaser(r, STARTPAGE, 1); - pr.print(r); - _RigaCorr++; - r.reset(); - HEADER_PRIMA_NOPOS--; - } - if (!PaginaPosizionamento()) - fill_page(pr, HEADER_PRIMA_NOPOS); - } - else - { - pr.print(head.row(j)); - _RigaCorr++; - } - } -} - -///////////////////////////////////////////////////////////////////////////////////////////// -// -// STAMPA QUADRO G-1 -// -///////////////////////////////////////////////////////////////////////////////////////////// -class TStampaQuadroG1 : public TStampaQuadro -{ - private: - TQuadroG1* _form; - TRelation* _rel; - TCursor* _cur; - - protected: - virtual TCursor* get_cursor() const { return _cur; } - virtual TRelation* get_relation() const { return _rel; } - virtual bool ContaTipiPer() const { return FALSE; } - virtual bool UsaSortedCursor() const { return FALSE; } - virtual TDicForm* get_form() const { return _form; } - virtual TDicForm* build_form(); - virtual TCursor* build_cursor(); -// virtual void fill_estinti(const long CodDic); - virtual bool destroy(); -// bool print_quadro(TString& quadro, const int OffsetDitta=-1); -// virtual void print(); - public: - TStampaQuadroG1(const char* quadro, const char livel) : TStampaQuadro(quadro,livel) {} -}; - -TDicForm* TStampaQuadroG1::build_form() -{ - _form = new TQuadroG1("77QG1", _quadro); - return _form; -} - -TCursor* TStampaQuadroG1::build_cursor() -{ - _rel = new TRelation(LF_QUAG1); - _rel->add(LF_NDITTE, "CODDITTA=CODDITTA"); - _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); - _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); - _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); - _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); - _cur = new TCursor(_rel); - return _cur; -} - -bool TStampaQuadroG1::destroy() -{ - delete _m; - delete _rel; - delete _cur; - delete _cnf; - delete _form; - - return TApplication::destroy(); -} - -/* -// _ditte e' fatto di righe siffatte: -// codditta, flag 2 dichiarante, 1 normale, 0 estinto, num_fis, num_nofis, ultima_con_fis, ultima_con_nofis -bool TStampaQuadroG1::print_quadro(TString& quadro, const int OffsetDitta) -{ - int start=0, last=0; - -// Setta formlen prima di printer.open per avere la lunghezza giusta nel caso di -// stampa a video - printer().formlen(QG_FORMLEN); - bool ok = printer().open(); - bool modulaser = _m->get_bool(F_MODULASER); - - _form->set_cur_rel(_rel, _cur); - - _form->set_modulaser(modulaser); - -// Dice se deve eseguire il posizionamento del foglio. -// Se stampa piu' ditte va eseguito solo sulla prima -// Occhio a non spostarlo nel ciclo. - _form->set_posiziona(TRUE); - - if (OffsetDitta >= 0) - { - start = OffsetDitta; - last = OffsetDitta; - } - else - last = _ditte.items() - 1; - - for (int i = start; i <= last; i++) - { - TString CoFiDic(20); - TToken_string riga(_ditte[i]); - riga.separator('|'); - const long codditta = atol(riga.get(0)); - const TipoDitta tipo = (TipoDitta)riga.get_int(1); - -// I gruppi dich-estinti hanno totali comuni -// Si presume che nell'array vengano messi nell'ordine dich-estinti - if (tipo == normale || tipo == dichiarante) - _form->azzera_totali(); - - if (tipo == estinto) - CoFiDic = riga.get(6); - -// Dice al form che tipo di ditta si stampa - _form->set_tipo_ditta(tipo); - -// Numera i fogli a partire da 1 per ogni ditta normale e da 1 e di seguito negli estinti -// per i sogg. dichiaranti - if (tipo == normale || tipo == dichiarante) - _form->set_num_foglio(1); - -// Se la ditta e' estinta dice al form il cod.fis. del dichiarante - if (tipo == estinto) - _form->set_cofi_dic(CoFiDic); - -// Dice al form che e' l'ultima ditta - if (i == last) - _form->set_last_ditta(TRUE); - - _form->print(codditta); - } - printer().close(); - return ok; -} -*/ -/* -void TStampaQuadroG1::fill_estinti(const long CodDic) -{ - int NumFisiche=0, NumNoFisiche=0; - TString CodFiDic(20); - -// Salva il cod.fis. del dichiarante - CodFiDic = cod_fis(CodDic); - - _ditte.add(CodDic, dichiarante); - const int index_dich = _ditte.curr_index(); - int index = index_dich; - -// Leggo gli estinti - TLocalisamfile base(LF_BASE); - base.setkey(2); - base.zero(); - base.put(BSE_CODDIC, (long)CodDic); - TRectype dep(base.curr()); - - for (base.read(); !base.eof(); base.next()) - { - if (base.curr() > dep) - break; - -// Scarta il record del quadro I "globale" del dichiarante - const char tipoqua = base.get(BSE_TIPOQUA)[0]; - if (tipoqua == COD_QUA_I_DIC) - continue; - - const long DittaEstinta = base.get_long(BSE_CODDITTA); - - _ditte.add(DittaEstinta, estinto, 0L, 0L, FALSE, FALSE, CodFiDic); - - index++; - } -} -*/ -/* -void TStampaQuadroG1::print() -{ - int NumFisiche=0, NumNoFisiche=0; - - _ditte.destroy(); // Pulisce l'array delle ditte - - if (_singola_ditta) - { - if (sogg_estinto(_codditta)) - { - warning_box("La ditta %ld e' un soggetto estinto", _codditta); - return; - } - -// Se e' un dichiarante va a prendere tutti i suoi estinti. - bool dich = sogg_dic(_codditta); - if (dich) - fill_estinti(_codditta); - else - _ditte.add(_codditta, normale); - } - else // stampa ditte selezionate - { -// Costruisco un'array delle ditte da stampare. -// Tolgo i sogg. estinti, e dopo un dichiarante metto tutti i suoi estinti. - long codditta_prec = get_firm_770(); - long codditta = 0L; - int i=0; - while ((codditta = _cnf->get_long(DITTE_SEL, _section, i++)) != 0L) - { - if (sogg_estinto(codditta)) - continue; - -// Se e' un dichiarante va a prendere tutti i suoi estinti. - bool dich = sogg_dic(codditta); - if (dich) - fill_estinti(codditta); - else - _ditte.add(codditta, normale); - - } - set_firm_770(codditta_prec); - } - print_quadro(_quadro, -1); -} -*/ - - -/////////////////////////////////////////////////////////////////////////////////////////// -// -// Quadro F -// -/////////////////////////////////////////////////////////////////////////////////////////// - -HIDDEN const int QF_FORMLEN = 72; -HIDDEN const int QF_PAGINE = 2; -HIDDEN const int HEADER_SECONDA_F = 7; - -class TQuadroF : public TDicForm -{ - private: - real pa3t, pa4t, pa5t, pa6t, pa7t; // totali prosp. A - real pb3t, pb4t, pc3t, pc4t, pd3t, pd4t; // totali prosp, B, C e D - int _ptrA, _ptrB, _ptrC, _ptrD; // puntatori alle righe dei prospetti - long _items; - int stampa_prospetto_A(TPrinter& pr, const bool UsaProgind); - int stampa_prospetto_B(TPrinter& pr, const bool UsaProgind); - int stampa_prospetto_C(TPrinter& pr, const bool UsaProgind); - int stampa_prospetto_D(TPrinter& pr, const bool UsaProgind); - TRecord_array* _prosp_a, *_prosp_b, *_prosp_c, *_prosp_d; - void azzera_contatori(); - void aggiorna_totali(char tipoprosp, TRectype& r); - void stampa_totali(char tipoprosp, TPrinter& pr, const bool UsaProgind); - - public: - virtual bool UsaSortedCursor() { return FALSE; } - virtual bool print(const long codditta, const long numfis=0L, const long numnofis=0L); - virtual void inc_curr_page(); - virtual void next_page(TPrinter& pr); - - TQuadroF(const char* form, const char* quadro) : TDicForm(form, quadro) {} - virtual ~TQuadroF() {} -}; - -void TQuadroF::azzera_contatori() -{ - pa3t = pa4t = pa5t = pa6t = pa7t = ZERO; - pb3t=pb4t=pc3t=pc4t=pd3t=pd4t = ZERO; // totali prosp, B, C e D - _ptrA = _ptrB = _ptrC = _ptrD = 1; -} - - -void TQuadroF::stampa_totali(char tipoprosp, TPrinter& pr, const bool UsaProgind) -{ - const int PA3_TOT = 104; - const int PB3_TOT = 54; - TPrint_section& sez = tipoprosp == 'A' ? section('H', 1) : section('B', 1); - const int rr = sez.height()-1; - int i = PA3_TOT, riga_tot=0; - - switch (tipoprosp) - { - case 'A': - { - riga_tot = 46; - TForm_item& c = sez.find_field(i++); - TString c3(pa3t.string()); - c.set(c3); - c = sez.find_field(i++); - TString c4(pa4t.string()); - c.set(c4); - c = sez.find_field(i++); - TString c5(pa5t.string()); - c.set(c5); - c = sez.find_field(i++); - TString c6(pa6t.string()); - c.set(c6); - c = sez.find_field(i++); - TString c7(pa7t.string()); - c.set(c7); - break; - } - case 'B': - { - i = PB3_TOT; - riga_tot = 14; - TForm_item& c = sez.find_field(i++); - TString c3(pb3t.string()); - c.set(c3); - c = sez.find_field(i); - TString c4(pb4t.string()); - c.set(c4); - break; - } - case 'C': - { - i = PB3_TOT+2; - riga_tot = 20; - TForm_item& c = sez.find_field(i++); - TString c3(pc3t.string()); - c.set(c3); - c = sez.find_field(i); - TString c4(pc4t.string()); - c.set(c4); - break; - } - case 'D': - { - i = PB3_TOT+4; - riga_tot = 26; - TForm_item& c = sez.find_field(i++); - TString d3(pd3t.string()); - c.set(d3); - c = sez.find_field(i); - TString d4(pd4t.string()); - c.set(d4); - break; - } - default: - break; - } - - sez.update(); - pr.print(sez.row(riga_tot)); - _RigaCorr++; - - if (UsaProgind) - _prog->addstatus(1); -} - -void TQuadroF::aggiorna_totali(char tipoprosp, TRectype& r) -{ - real sogg,rope,acc,ecc,sal; - - switch (tipoprosp) - { - case 'A': - sogg = r.get_real(QUF_SOGRIT); - rope = r.get_real(QUF_ROPE); - acc = r.get_real(QUF_ACCONTI); - ecc = r.get_real(QUF_VERSECC); - sal = r.get_real(QUF_VERSALDO); - pa3t += sogg; - pa4t += rope; - pa5t += acc; - pa6t += ecc; - pa7t += sal; - break; - case 'B': - sogg = r.get_real(QUF_SOGRIT); - rope = r.get_real(QUF_ROPE); - pb3t += sogg; - pb4t += rope; - break; - case 'C': - sogg = r.get_real(QUF_SOGRIT); - rope = r.get_real(QUF_ROPE); - pc3t += sogg; - pc4t += rope; - break; - case 'D': - sogg = r.get_real(QUF_SOGRIT); - rope = r.get_real(QUF_ROPE); - pd3t += sogg; - pd4t += rope; - break; - default: - break; - } -} - -void TQuadroF::next_page(TPrinter& pr) -{ - PagineQD PagCorr = curr_page(); -// if (PagCorr = SECONDA) stampa_totali(pr); - fill_page(pr, -1); // formfeed "adattato" - inc_curr_page(); -} - -void TQuadroF::inc_curr_page() -{ - if (_PaginaCorrente == PRIMA) - _PaginaCorrente = SECONDA; - else - if (_PaginaCorrente == SECONDA) - _PaginaCorrente = PRIMA; -} - - -bool TQuadroF::print(const long codditta, const long numfis, const long numnofis) -{ - bool EndPrint=FALSE, End_A=FALSE, End_B=FALSE, End_C=FALSE, End_D=FALSE; - int residui_A=0, residui_B=0, residui_C=0, residui_D=0; - TCursor* cur = cursor(); - TPrinter& pr = printer(); - _UsaProgind = FALSE; - - if (!InitPrint(codditta)) - return FALSE; - - azzera_contatori(); - - TLocalisamfile& rf = cur->file(LF_RIGHEF); - TRectype dep(rf.curr()); - dep.zero(); - dep.put("CODDITTA", _codditta); - dep.put("TIPOPRO", "A"); - _prosp_a = new TRecord_array(dep, "NPROG"); - dep.put("TIPOPRO", "B"); - _prosp_b = new TRecord_array(dep, "NPROG"); - dep.put("TIPOPRO", "C"); - _prosp_c = new TRecord_array(dep, "NPROG"); - dep.put("TIPOPRO", "D"); - _prosp_d = new TRecord_array(dep, "NPROG"); - - pr.formlen(QG1_FORMLEN); - - while (!EndPrint) - { - for (int pagina=1; pagina <= QF_PAGINE; pagina++, next_page(pr)) - { - if (_PaginaCorrente == PRIMA) - { - if (_modulaser) ClearFlagModulaser(); - - if (End_A) - break; - - (*cur) = 0L; - - residui_A = stampa_prospetto_A(pr, _UsaProgind); - - End_A = (residui_A == 0); - if (End_A) stampa_totali('A', pr, _UsaProgind); - EndPrint = End_A && End_B && End_C && End_D; - } - - if (_PaginaCorrente == SECONDA) - { -// Reset del flag di pagina con posiz. - if (_posiziona && _PaginaPosizionamento) _PaginaPosizionamento = FALSE; - - if (End_B && End_C && End_D) - break; - - fill_page(pr, HEADER_SECONDA_F); - - residui_B = stampa_prospetto_B(pr, _UsaProgind); - End_B = (residui_B == 0); - if (End_B) stampa_totali('B', pr, _UsaProgind); - - residui_C = stampa_prospetto_C(pr, _UsaProgind); - End_C = (residui_C == 0); - if (End_C) stampa_totali('C', pr, _UsaProgind); - - residui_D = stampa_prospetto_D(pr, _UsaProgind); - End_D = (residui_D == 0); - if (End_D) stampa_totali('D', pr, _UsaProgind); - - EndPrint = End_A && End_B && End_C && End_D; - } - } // for pagina.. - } // EndPrint() - close_print(); - return TRUE; -} - -const int F_DESC_CAUS = 50; -const int RIGHE_PROSP = 3; - -int TQuadroF::stampa_prospetto_C(TPrinter& pr, const bool UsaProgind) -{ - TPrint_section& sez = section('B', 1); - const int rr = sez.height()-1; - - const int START_C = 16; - const int last_c = _prosp_c->last_row(); - for (int i=0; i < RIGHE_PROSP; _ptrC++, i++) - { - if (_ptrC > last_c) - break; - - TRectype& r = _prosp_c->row(_ptrC, TRUE); - aggiorna_totali('C', r); - TString16 codcau(r.get(QUF_CODCAUS)); - TString descr_cau(get_desc_cau(codcau)); - TString16 aliq (r.get(QUF_ALIQUOTA)); - TString sogg (r.get(QUF_SOGRIT)); - TString rope (r.get(QUF_ROPE)); - - const int fc0 = START_C + _ptrC - 1; - TString16 nord; nord << _ptrC; - TForm_item& c0 = sez.find_field(fc0); - c0.set(nord); - - const int fc1 = fc0 + RIGHE_PROSP; - TForm_item& c1 = sez.find_field(fc1); - c1.set(descr_cau); - - const int fc2 = fc1 + RIGHE_PROSP; - TForm_item& c2 = sez.find_field(fc2); - c2.set(aliq); - - const int fc3 = fc2 + RIGHE_PROSP; - TForm_item& c3 = sez.find_field(fc3); - c3.set(sogg); - - const int fc4 = fc3 + RIGHE_PROSP; - TForm_item& c4 = sez.find_field(fc4); - c4.set(rope); - } - const int res_C = last_c - _ptrC; - return res_C < 0 ? 0 : res_C; -} - -int TQuadroF::stampa_prospetto_D(TPrinter& pr, const bool UsaProgind) -{ - TPrint_section& sez = section('B', 1); - const int rr = sez.height()-1; - - const int START_D = 31; - const int last_d = _prosp_d->last_row(); - for (int i=0; i < RIGHE_PROSP; _ptrD++, i++) - { - if (_ptrD > last_d) - break; - - TRectype& r = _prosp_d->row(_ptrD, TRUE); - aggiorna_totali('D', r); - TString16 codcau(r.get(QUF_CODCAUS)); - TString descr_cau(get_desc_cau(codcau)); - TString16 aliq (r.get(QUF_ALIQUOTA)); - TString sogg (r.get(QUF_SOGRIT)); - TString rope (r.get(QUF_ROPE)); - - const int fc0 = START_D + _ptrD - 1; - TString16 nord; nord << _ptrD; - TForm_item& c0 = sez.find_field(fc0); - c0.set(nord); - - const int fc1 = fc0 + RIGHE_PROSP; - TForm_item& c1 = sez.find_field(fc1); - c1.set(descr_cau); - - const int fc2 = fc1 + RIGHE_PROSP; - TForm_item& c2 = sez.find_field(fc2); - c2.set(aliq); - - const int fc3 = fc2 + RIGHE_PROSP; - TForm_item& c3 = sez.find_field(fc3); - c3.set(sogg); - - const int fc4 = fc3 + RIGHE_PROSP; - TForm_item& c4 = sez.find_field(fc4); - c4.set(rope); - } - - sez.update(); - for (i=0; i < rr; i++) - { - pr.print(sez.row(i)); - _RigaCorr++; - } - - if (UsaProgind) - _prog->addstatus(1); - - const int res_D = last_d - _ptrD; - return res_D < 0 ? 0 : res_D; -} - -int TQuadroF::stampa_prospetto_B(TPrinter& pr, const bool UsaProgind) -{ - TPrint_section& sez = section('B', 1); - const int rr = sez.height()-1; - - const int START_B = 1; - - const int last_b = _prosp_b->last_row(); - for (int i=0; i < RIGHE_PROSP; _ptrB++, i++) - { - if (_ptrB > last_b) - break; - - TRectype& r = _prosp_b->row(_ptrB, TRUE); - aggiorna_totali('B', r); - TString dep(50); - dep = r.get(QUF_CODCAUS); - TString descr_cau(get_desc_cau(dep)); - TString16 aliq (r.get(QUF_ALIQUOTA)); - TString sogg (r.get(QUF_SOGRIT)); - TString rope (r.get(QUF_ROPE)); - - const int fc0 = START_B + _ptrB - 1; - TString16 nord; nord << _ptrB; - TForm_item& c0 = sez.find_field(fc0); - c0.set(nord); - - const int fc1 = fc0 + RIGHE_PROSP; - TForm_item& c1 = sez.find_field(fc1); - c1.set(descr_cau); - - const int fc2 = fc1 + RIGHE_PROSP; - TForm_item& c2 = sez.find_field(fc2); - c2.set(aliq); - - const int fc3 = fc2 + RIGHE_PROSP; - TForm_item& c3 = sez.find_field(fc3); - c3.set(sogg); - - const int fc4 = fc3 + RIGHE_PROSP; - TForm_item& c4 = sez.find_field(fc4); - c4.set(rope); - } - -// TBI setta totali e descr.causale F - TString16 fcau(cursor()->curr(LF_QUAF).get(QUF_FCAUS)); - TString descr_cau(get_desc_cau(fcau)); - TForm_item& fd = sez.find_field(F_DESC_CAUS); - fd.set(descr_cau); - - const int res_B = last_b - _ptrB; - return res_B < 0 ? 0 : res_B; -} - -int TQuadroF::stampa_prospetto_A(TPrinter& pr, const bool UsaProgind) -{ - TPrint_section& head = section('H', 1); - const word rr = head.height()-1; - TPrintrow& head_row = head.row(rr-1); - -// Setta il cod.fis. del dichiarante se necessario - if (tipo_ditta() == estinto) - { - TForm_item& cfd = head.find_field(H_COFI_DIC); - cfd.set(_cofi_dic); - } - - TCursor* cur = cursor(); - - const int START_PROSP = 56; - const int RIGHE_PROSP = 6; - const int COL_PROSP = 8; - const int last_a = _prosp_a->last_row(); - - for (int i=0; i < RIGHE_PROSP ; _ptrA++, i++) - { - if (_ptrA > last_a) - break; - TRectype& r = _prosp_a->row(_ptrA, TRUE); - aggiorna_totali('A', r); - TString16 codcau(r.get(QUF_CODCAUS)); - TString descr_cau(get_desc_cau(codcau)); - TString16 aliq (r.get(QUF_ALIQUOTA)); - TString sogg (r.get(QUF_SOGRIT)); - TString rope (r.get(QUF_ROPE)); - TString acc(r.get(QUF_ACCONTI)); - TString ecc(r.get(QUF_VERSECC)); - TString sal(r.get(QUF_VERSALDO)); - - const int fc0 = START_PROSP + _ptrA - 1; - TString16 nord; nord << _ptrA; - TForm_item& c0 = head.find_field(fc0); - c0.set(nord); - - const int fc1 = fc0 + RIGHE_PROSP; - TForm_item& c1 = head.find_field(fc1); - c1.set(descr_cau); - - const int fc2 = fc1 + RIGHE_PROSP; - TForm_item& c2 = head.find_field(fc2); - c2.set(aliq); - - const int fc3 = fc2 + RIGHE_PROSP; - TForm_item& c3 = head.find_field(fc3); - c3.set(sogg); - - const int fc4 = fc3 + RIGHE_PROSP; - TForm_item& c4 = head.find_field(fc4); - c4.set(rope); - - const int fc5 = fc4 + RIGHE_PROSP; - TForm_item& c5 = head.find_field(fc5); - c5.set(acc); - - const int fc6 = fc5 + RIGHE_PROSP; - TForm_item& c6 = head.find_field(fc6); - c6.set(ecc); - - const int fc7 = fc6 + RIGHE_PROSP; - TForm_item& c7 = head.find_field(fc7); - c7.set(sal); - } - -// Righe da saltare nelle prime pag. dei moduli successivi al primo (che' son -// senza le righe del posizionamento...) - int HEADER_PRIMA_NOPOS = 3; - head.update(); - for (word j = 0; j <= rr; j++) - { - if (j==0) - { - if (_modulaser) - { - TPrintrow& r = head.row(j); - if (!_GiaMessoStartDoc) - put_modulaser(r, STARTDOC); - put_modulaser(r, STARTDITTA); - put_modulaser(r, STARTPAGE, 1); - pr.print(r); - _RigaCorr++; - r.reset(); - HEADER_PRIMA_NOPOS--; - } - if (!PaginaPosizionamento()) - fill_page(pr, HEADER_PRIMA_NOPOS); - } - else - { - pr.print(head.row(j)); - _RigaCorr++; - } - } - const int res = last_a - _ptrA; - return res < 0 ? 0 : res; -} - -///////////////////////////////////////////////////////////////////////////////////////////// -// -// STAMPA QUADRO F -// -///////////////////////////////////////////////////////////////////////////////////////////// -class TStampaQuadroF : public TStampaQuadro -{ - private: - TQuadroF* _form; - TRelation* _rel; - TCursor* _cur; - - protected: - virtual bool ContaTipiPer() const { return FALSE; } - virtual bool UsaSortedCursor() const { return FALSE; } - virtual TDicForm* get_form() const { return _form; } - virtual TDicForm* build_form(); - virtual TCursor* build_cursor(); - virtual TCursor* get_cursor() const { return _cur; } - virtual TRelation* get_relation() const { return _rel; } - virtual bool destroy(); -// virtual void print(); - - public: - TStampaQuadroF(const char* quadro, const char livel) : TStampaQuadro(quadro,livel) {} -}; - -TDicForm* TStampaQuadroF::build_form() -{ - _form = new TQuadroF("77QF", _quadro); - return _form; -} - -TCursor* TStampaQuadroF::build_cursor() -{ - _rel = new TRelation(LF_QUAF); - _rel->add(LF_RIGHEF, "CODDITTA=CODDITTA"); - _rel->add(LF_NDITTE, "CODDITTA=CODDITTA", 1, LF_QUAF); - _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); - _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); - _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); - _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); - _cur = new TCursor(_rel); - return _cur; -} - -bool TStampaQuadroF::destroy() -{ - delete _m; - delete _rel; - delete _cur; - delete _cnf; - delete _form; - - return TApplication::destroy(); -} - -/////////////////////////////////////////////////////////////////////////////////////////// -// -// Quadro H -// -/////////////////////////////////////////////////////////////////////////////////////////// - -HIDDEN const int QH_FORMLEN = 72; -HIDDEN const int QH_PAGINE = 2; -HIDDEN const int HEADER_SECONDA_H = 7; - -class TQuadroH : public TDicForm -{ - private: - real _rC2t, _rC3t; // totali colonna 2 e 3 - long _items; - void azzera_contatori(); -// void aggiorna_totali(char tipoprosp, TRectype& r); -// void stampa_totali(char tipoprosp, TPrinter& pr, const bool UsaProgind); - - public: - virtual bool UsaSortedCursor() { return FALSE; } - virtual bool print(const long codditta, const long numfis=0L, const long numnofis=0L); - virtual void inc_curr_page(); - virtual void next_page(TPrinter& pr); - - TQuadroH(const char* form, const char* quadro) : TDicForm(form, quadro) {} - virtual ~TQuadroH() {} -}; - - -void TQuadroH::azzera_contatori() -{ - _rC2t = _rC3t = ZERO; -} - -//--------------------------------------------------------------------------------------- -// Quadro 770/A -// almeno credo -// ------------------------------------------------------------------------------------- - -class TQuadroA : public TDicForm -{ - private: - - public: - virtual bool UsaSortedCursor() { return FALSE; } -// virtual bool print(const long codditta, const long numfis=0L, const long numnofis=0L); -// virtual void inc_curr_page(); -// virtual void next_page(TPrinter& pr); - - TQuadroA(const char* form, const char* quadro) : TDicForm(form, quadro) {} - virtual ~TQuadroA() {} -}; - -class TStampaQuadroA : public TStampaQuadro -{ - private: - TQuadroA* _form; - TRelation* _rel; - TCursor* _cur; - - protected: - virtual bool ContaTipiPer() const { return FALSE; } - virtual bool UsaSortedCursor() const { return FALSE; } - virtual TDicForm* get_form() const { return _form; } - virtual TDicForm* build_form(); - virtual TCursor* build_cursor(); - virtual TCursor* get_cursor() const { return _cur; } - virtual TRelation* get_relation() const { return _rel; } - virtual bool destroy(); -// virtual void print(); - - public: - TStampaQuadroA(const char* quadro, const char livel) : TStampaQuadro(quadro,livel) {} -}; - -TDicForm* TStampaQuadroA::build_form() -{ - _form = new TQuadroA("77QA", _quadro); - return _form; -} - -TCursor* TStampaQuadroA::build_cursor() -{ - _rel = new TRelation(LF_QUAF); - _rel->add(LF_RIGHEF, "CODDITTA=CODDITTA"); - _rel->add(LF_NDITTE, "CODDITTA=CODDITTA", 1, LF_QUAF); - _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); - _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); - _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); - _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); - _cur = new TCursor(_rel); - return _cur; -} - -bool TStampaQuadroA::destroy() -{ - delete _m; - delete _rel; - delete _cur; - delete _cnf; - delete _form; - - return TApplication::destroy(); -} - -///////////////////////////////////////////////////////////////////////////////// -// -// MAIN -// -// Uso: -// 772mod -4 [QUADRO] [ LIVELLO {S|D} ] -// -///////////////////////////////////////////////////////////////////////////////// - -int stampa_quadro(int argc, char* argv[]) -{ - if (argc >= 4) - { - TString quadro(argv[2]); - const char livello = *argv[3]; - - if ( quadro == "C" || quadro == "D" || quadro == "D1" || quadro == "E" || - quadro == "E1" ) - { - TStampaQuadro app(quadro, livello); - app.run(argc, argv, app.taitol()); - } - else if (quadro == "A") - { - TStampaQuadroA app(quadro, livello); - app.run(argc, argv, app.taitol()); - } - else if (quadro == "F") - { - TStampaQuadroF app(quadro, livello); - app.run(argc, argv, app.taitol()); - } - else if (quadro == "G") - { - TStampaQuadroG app(quadro, livello); - app.run(argc, argv, app.taitol()); - } - else if (quadro == "G1") - { - TStampaQuadroG1 app(quadro, livello); - app.run(argc, argv, app.taitol()); - } -/* - else if (quadro == "H") - { - TStampaQuadroH app(quadro, livello); - app.run(argc, argv, app.taitol()); - } -*/ - } - return 0; -} - - +// Stampa quadro +#include + +#include +#include +#include +#include +#include +#include +#include +#include "base.h" +#include + +#include +#include +#include "quadrod.h" +#include "quadrod1.h" +#include "quadrogd.h" +#include "quadrif.h" +#include "77stqd.h" +#include "77lib.h" + +// +// Lista modifiche +// +// 3.4.96 Nella stampa per Modulaser, aggiunto all'inizio un comando per settare +// il font della stampante a 17cpi (v.riga 176) +// + + +// Chincaglieria che serve per posiziona() +typedef long HWND; +HIDDEN const int MAX_LEN = 300; +extern "C" { + BOOLEAN PrintLineNow( char *pData, word cbBytes, HWND hInst ); +}; + + +HIDDEN TString16 __dep16; +HIDDEN TString80 __dep80; + +// Vega-Key di Modulaser +HIDDEN const char* VK_STARTDOC = "&MA795&0&1"; +HIDDEN const char* VK_ENDDOC = "!0"; +HIDDEN const char* VK_STARTPAGE[] = { "*9*1", "*9*2", "*9*3", "*9*4" }; +typedef enum { STARTDOC, STARTDITTA, STARTPAGE, ENDDOC } ModulaserKey; + +// Campi form +#define TOT_TOTALE 1 +#define TOT_SNSRIT 2 +#define TOT_IMPON 3 +#define TOT_IMPOR 4 +#define TOT_NETTO 5 +#define H_COFI_DIC 13 +#define H_NUM_FOGLIO 14 + +// Quadro D +HIDDEN const int QD_FORMLEN_PRIMA = 70; // 72 - 3 (3 e' la posizione della X di posiz.) +HIDDEN const int QD_FORMLEN = 72; +HIDDEN const int POS_DITTA = 91; // Colonna del codice ditta a pie' di modulo +HIDDEN const int QD_PAGINE = 4; +HIDDEN const int QD_RIGHE_PRIMA = 5; +HIDDEN const int QD_RIGHE_SECONDA = 7; +HIDDEN const int QD_RIGHE_TERZA = 6; +HIDDEN const int QD_RIGHE_QUARTA = 6; +HIDDEN const int HEADER_SECONDA = 7; +HIDDEN const int HEADER_TERZA = 8; // Sarebbero 9 col righello... +HIDDEN const int HEADER_QUARTA = 14; // 15 col righello... + +typedef enum { PRIMA=1, SECONDA, TERZA, QUARTA } PagineQD; +typedef enum { fisiche, nofisiche } TipoPagina; + +/////////////////////////////////////////////////////////////////////////////////////////// +// +// Quadro D +// +/////////////////////////////////////////////////////////////////////////////////////////// + +class TDicForm : public TForm +{ + private: + real _f_tot_totale, _f_tot_snsrit, _f_tot_impon, _f_tot_impor, _f_tot_netto; + real _nf_tot_totale, _nf_tot_snsrit, _nf_tot_impon, _nf_tot_impor, _nf_tot_netto; + void aggiorna_totali_C(const char tipo); + void aggiorna_totali_D(const char tipo); + void aggiorna_totali_D1(const char tipo); + void aggiorna_totali_E(const char tipo); + void aggiorna_totali_E1(const char tipo); + + TCursor* _cur; + + protected: + long _Items; // numero di record che hanno passato il filtro + PagineQD _PaginaCorrente; + + void set_curr_page(PagineQD pagina) { _PaginaCorrente = pagina; } + virtual void inc_curr_page(); + virtual void next_page(TPrinter& pr); + bool _modulaser; // se stampa per modulaser + bool _posiziona; // se deve fare posizionamento + TipoDitta _tipo_ditta; // tipo ditta: normale, estinto, dichiarante + int _num_foglio; // numero foglio + TString _cofi_dic; // cod.fis. dichiarante + bool _can_print_tot_fis, _can_print_tot_nofis; + bool _finite_fis, _finite_nofis, _LastDitta, _EndPrintDitta; + bool _GiaStampatiFis, _GiaStampatiNoFis, _PaginaPosizionamento; + bool _GiaPosizionato, _GiaMessoStartDoc, _GiaMessoStartPage[QD_PAGINE]; // flag per modulaser + int _CtrNoFisStampati, _CtrFisStampati; // contatori p.f. e p.g. stampate + long _codditta; // ditta in stampa + int _RigaCorr; // contatore riga corrente + TString16 _quadro; // codice quadro in stampa + + virtual TCursor* cursor() const { return _cur; } + virtual TRelation* relation() const { return _cur->relation(); } + + void stampa_testata(TPrinter& pr); + virtual void stampa_totali(TPrinter& pr); + virtual void aggiorna_totali(const char tipo); + virtual void set_body(TPrinter& pr, const char tipo); + void StampaPagina(PagineQD PaginaCorrente, const bool StampaTotali, const long Fis, const long NoFis); + void posiziona(); + void fill_page(TPrinter& pr, const int righe); + void jump_to_line(TPrinter& pr, const int riga); + void put_modulaser(TPrintrow& row, ModulaserKey key, int page=0); + void ClearFlagModulaser(); + bool PaginaPosizionamento() const; + virtual bool InitPrint(const long codditta); + + public: + + const long filtra(const long codditta); + + TProgind* _prog; // progind usata in print() + + long codditta() const { return _codditta; } + void set_codditta(const long ditta) { _codditta = ditta; } + void set_posiziona(const bool posiz) { _posiziona = posiz; _GiaPosizionato = FALSE; } + void can_print_tot_fis(const bool canpr) { _can_print_tot_fis = canpr; } + void can_print_tot_nofis(const bool canpr) { _can_print_tot_nofis = canpr; } + void set_last_ditta(const bool last) { _LastDitta = last; } + bool last_ditta() const { return _LastDitta; } + bool EndJob() const { return _LastDitta && _EndPrintDitta; } + bool ultima_fis(); + bool ultima_nofis(); + TString& cofi_dic() { return _cofi_dic; } + void set_cofi_dic(const char* cofi) { _cofi_dic = cofi; } + TipoDitta tipo_ditta() const { return _tipo_ditta; } + void set_tipo_ditta(TipoDitta tipo) { _tipo_ditta = tipo; } + bool modulaser() const { return _modulaser; } + void set_modulaser(const bool modul) { _modulaser = modul; } + void set_num_foglio(const int foglio) { _num_foglio = foglio; } + int num_foglio() const { return _num_foglio; } + virtual void azzera_totali(); + PagineQD curr_page() const { return _PaginaCorrente; } + TCursor& cur(); + + void set_progind(TProgind* prog) { _prog = prog; } + TProgind* progind() { return _prog; } + bool usa_progind() const { return _prog != NULL; } + + virtual void set_cursor(TCursor* cur); + virtual void close_print(); + virtual bool print(const long codditta, const long NumFis, const long NumNoFis); + + TDicForm(const char* form, const char* quadro); + virtual ~TDicForm() {} +}; + +TCursor& TDicForm::cur() +{ + return *_cur; +} + +void TDicForm::set_cursor(TCursor* cur) +{ + _cur = cur; +} + +TDicForm::TDicForm(const char* form, const char* quadro) + : TForm(form), _quadro(quadro), _prog(NULL) +{ + _can_print_tot_fis = _can_print_tot_nofis = FALSE; + _GiaStampatiFis = _GiaStampatiNoFis = _GiaMessoStartDoc = FALSE; + _GiaPosizionato = _posiziona = _modulaser = FALSE; + _LastDitta = _EndPrintDitta = _PaginaPosizionamento = FALSE; + ClearFlagModulaser(); +} + +const long TDicForm::filtra(const long codditta) +{ + TString filtr(24); + filtr.format("CODDITTA=%ld", codditta); + + _cur->setfilter(filtr, TRUE); + const long items = _cur->items(); + + return items; +} + + +bool TDicForm::InitPrint(const long codditta) +{ + _codditta = codditta; + _RigaCorr = 0; + + TPrinter& pr = printer(); + pr.set_offset(offset_y(), offset_x()); + pr.set_char_size(fontsize()); // Set font name and size + pr.set_fontname(fontname()); // according to current form + + if (_posiziona && !_GiaPosizionato && pr.printtype() != screenvis && + pr.printtype() != fileprinter) +// arrange_form(); + posiziona(); + +#ifdef DBG + if (pr.printtype() != screenvis) + if (!yesno_box("Proseguo con la stampa ?")) + return FALSE; +#endif + + const bool was_open = pr.isopen(); + + set_last_page(FALSE); + set_background(1, TRUE); + set_curr_page(PRIMA); + + if (!was_open && !pr.open()) + return FALSE; + do_events(); + + _Items = filtra(codditta); + + if (_Items == 0L) // Se non ci sono record non stampa + return FALSE; + + if (_prog) + { + delete _prog; + _prog = NULL; + } + if (pr.printtype() != screenvis) + { + TString msg(60); + msg.format("Elaborazione in corso ditta %ld", codditta); + _prog = new TProgind(_Items, msg, FALSE,TRUE); + } + return TRUE; +} + +void TDicForm::close_print() +{ + if (_prog) + { + delete _prog; + _prog = NULL; + } +} + +bool TDicForm::print(const long codditta, const long NumFis, const long NumNoFis) +{ + bool StabilitaInesistenzaNoFis = FALSE; + bool StabilitaInesistenzaFis = FALSE; + long CtrFis = NumFis; + long CtrNoFis = NumNoFis; + long PtrFis = -1L, PtrNoFis=-1L; + TPrinter& pr = printer(); + + _CtrFisStampati = _CtrNoFisStampati = 0; + _finite_fis = _finite_nofis = FALSE; + _GiaStampatiFis = _GiaStampatiNoFis = FALSE; + _EndPrintDitta = FALSE; // Vero se stampato l'ultimo record + bool LastRecord = FALSE; // Vero se letto l'ultimo record + + _PaginaCorrente = PRIMA; + + if (!InitPrint(codditta)) + return FALSE; + + TCursor* cur = cursor(); + + while (!_EndPrintDitta) + { + for (int pagina=1; pagina <= QD_PAGINE; pagina++, next_page(pr)) + { + pr.formlen(QD_FORMLEN); + + if (_PaginaCorrente == PRIMA) + { + if (_modulaser) ClearFlagModulaser(); + + for (int righe=0; righe < QD_RIGHE_PRIMA; righe++) + { +// Stampa intestazione, solo sul primo foglio. + if (!righe) + { + (*cur) = PtrFis >= 0L ? PtrFis : 0L; + stampa_testata(pr); + } + + if (_finite_fis || StabilitaInesistenzaFis) + break; + +// La prima volta si deve posizionare sul primo record di p.f. + if (PtrFis<0L && !StabilitaInesistenzaFis) + { + bool Trovato = FALSE; + + while (!Trovato) + { + const long ditta = cur->curr().get_long(QUD_CODDITTA); + if (ditta != codditta) + break; + const char tipo = cur->curr().get(QUD_TIPOA)[0]; + if (tipo != 'G') + { + PtrFis = cur->pos(); + Trovato = TRUE; + break; + } + else + ++(*cur); + } + StabilitaInesistenzaFis = !Trovato; + } + + if (StabilitaInesistenzaFis) + break; + + (*cur) = PtrFis; + const char tipo = cur->curr().get(QUD_TIPOA)[0]; + + if (tipo != 'F') + break; + else + { + CtrFis--; + if (CtrFis == 0L) _finite_fis = TRUE; + set_body(pr, 'F'); +// La stampa e' finita se ho STAMPATO l'ultimo record + LastRecord = cur->pos() >= _Items-1; + _EndPrintDitta = LastRecord; + if (!LastRecord) + { + ++(*cur); + PtrFis = cur->pos(); + LastRecord = cur->pos() >= _Items-1; + } + } + } // for righe.. + PtrFis = cur->pos(); + } + + if (_PaginaCorrente == SECONDA) + { +// Reset del flag di pagina con posiz. + if (_posiziona && _PaginaPosizionamento) _PaginaPosizionamento = FALSE; + for (int righe=0; righe < QD_RIGHE_SECONDA; righe++) + { + if (!righe) + fill_page(pr, HEADER_SECONDA); + + if (_finite_fis || StabilitaInesistenzaFis) + break; + + (*cur) = PtrFis; + const char tipo = cur->curr().get(QUD_TIPOA)[0]; + + if (tipo != 'F') + break; + else + { + CtrFis--; + if (CtrFis == 0L) _finite_fis = TRUE; + set_body(pr, 'F'); + LastRecord = cur->pos() >= _Items-1; + _EndPrintDitta = LastRecord; + if (!LastRecord) + { + ++(*cur); + PtrFis = cur->pos(); + LastRecord = cur->pos() >= _Items-1; + } + } + } + PtrFis = cur->pos(); + } + + if (_PaginaCorrente == TERZA) + { + for (int righe=0; righe < QD_RIGHE_TERZA; righe++) + { + if (!righe) + { + fill_page(pr, HEADER_TERZA); + _CtrFisStampati = 0; // conta quelli che stampo sulla terza + } + + if (_finite_fis || StabilitaInesistenzaFis) + break; + + (*cur) = PtrFis; + const char tipo = cur->curr().get(QUD_TIPOA)[0]; + + if (tipo != 'F') + break; + else + { + CtrFis--; + if (CtrFis == 0L) _finite_fis = TRUE; + set_body(pr, 'F'); + LastRecord = cur->pos() >= _Items-1; + _EndPrintDitta = LastRecord; + _CtrFisStampati++; + if (!LastRecord) + { + ++(*cur); + PtrFis = cur->pos(); + LastRecord = cur->pos() >= _Items-1; + } + } + } + PtrFis = cur->pos(); + } + + if (_PaginaCorrente == QUARTA) + { + for (int righe=0; righe < QD_RIGHE_QUARTA; righe++) + { + if (!righe) + _CtrNoFisStampati = 0; + +// All'inizio salta le righe in alto + if (!righe) + fill_page(pr, HEADER_QUARTA); + + if (_finite_nofis || StabilitaInesistenzaNoFis) + break; + +// La prima volta si deve posizionare sul primo record di p.g. + if (PtrNoFis<0L && !StabilitaInesistenzaNoFis) + { + bool Trovato = FALSE; + bool eof = FALSE; + (*cur) = PtrFis-1 > 0L ? PtrFis-1 : 0L; // parti dall'inizio + while (!Trovato && !eof) + { + eof = cur->pos() >= _Items-1; + const long ditta = cur->curr().get_long(QUD_CODDITTA); + if (ditta != codditta) + break; + const char tipo = cur->curr().get(QUD_TIPOA)[0]; + if (tipo != 'F') + { + PtrNoFis = cur->pos(); + Trovato = TRUE; + break; + } + else + ++(*cur); + } + StabilitaInesistenzaNoFis = !Trovato; + } + + if (StabilitaInesistenzaNoFis) + break; + + (*cur) = PtrNoFis; + const char tipo = cur->curr().get(QUD_TIPOA)[0]; + + if (tipo != 'G') + break; + else + { + CtrNoFis--; + if (CtrNoFis == 0L) _finite_nofis = TRUE; + set_body(pr, 'G'); + LastRecord = cur->pos() >= _Items-1; + _EndPrintDitta = LastRecord; + _CtrNoFisStampati++; + if (!LastRecord) + { + ++(*cur); + PtrNoFis = cur->pos(); + LastRecord = cur->pos() >= _Items-1; + } + } + } + PtrNoFis = cur->pos(); + } + } // for pagina.. + } // while !_EndPrintDitta + close_print(); + return TRUE; +} + + +void TDicForm::ClearFlagModulaser() +{ + for (int i=0; i<=QD_PAGINE; i++) + _GiaMessoStartPage[i] = FALSE; +} + +bool TDicForm::ultima_fis() +{ + return _can_print_tot_fis && _finite_fis && !_GiaStampatiFis; +} + +bool TDicForm::ultima_nofis() +{ + return _can_print_tot_nofis && _finite_nofis && !_GiaStampatiNoFis; +} + +void TDicForm::inc_curr_page() +{ + if (_PaginaCorrente == PRIMA) + _PaginaCorrente = SECONDA; + else + if (_PaginaCorrente == SECONDA) + _PaginaCorrente = TERZA; + else + if (_PaginaCorrente == TERZA) + _PaginaCorrente = QUARTA; + else + if (_PaginaCorrente == QUARTA) + _PaginaCorrente = PRIMA; +} + +void TDicForm::put_modulaser(TPrintrow& row, ModulaserKey Cmd, int page) +{ + TString riga(80); + + switch (Cmd) + { + case STARTDOC: + if (!_GiaMessoStartDoc) + { +// riga = VK_STARTDOC; + riga = "\xf"; // Printer escape: font 17cpi + riga << VK_STARTDOC; + _GiaMessoStartDoc = TRUE; + } + break; + case STARTDITTA: + { + TString cofi(16); + const char* tmp = _cur->file(-116).get(ANA_COFI); + cofi.format("%-16s", tmp); + TString ragsoc(50); + ragsoc = _cur->file(LF_NDITTE).get(NDT_RAGSOC); + riga = "$"; + riga << cofi; + riga << "$0$"; + riga << ragsoc; + } + break; + case STARTPAGE: + riga = "*9*"; + riga << page; + _GiaMessoStartPage[page] = TRUE; + break; + case ENDDOC: + riga = VK_ENDDOC; + break; + default: + break; + } + riga.rtrim(); + riga << '\r'; + row.put(riga); +} + + +bool TDicForm::PaginaPosizionamento() const +{ + return _PaginaPosizionamento && curr_page() == PRIMA; +} + +// Stampa "righe" righe vuote. Se righe e' -1 fa un formfeed mettendo +// il codice ditta sull'ultima riga +void TDicForm::fill_page(TPrinter& pr, const int righe) +{ + TPrintrow row; + PagineQD pagina = curr_page(); + +// form feed + if (righe < 0) + { + const bool PrimaPagina = curr_page() == PRIMA; + int stop = PaginaPosizionamento() ? QD_FORMLEN_PRIMA : QD_FORMLEN; + for (int i = _RigaCorr; i < stop; i++) + { + if (i == 0) + if (_modulaser) + { + if (!_GiaMessoStartPage[pagina]) + put_modulaser(row, STARTPAGE, pagina); + } +// Sull'ultima riga metto il codice ditta + if (i == stop-1) + { + if (_modulaser && EndJob() && curr_page() == QUARTA) + put_modulaser(row, ENDDOC); + + TString16 ditta; ditta << _codditta; + row.put(ditta, POS_DITTA); + } + pr.print(row); + } + _RigaCorr = 0; + return; + } + else // righe > 0 + for (int i=0; i < righe; i++) + { + if (i == 0 && _modulaser && !_GiaMessoStartPage[pagina]) + put_modulaser(row, STARTPAGE, pagina); + else + row.reset(); + pr.print(row); + _RigaCorr++; + } +} + +void TDicForm::jump_to_line(TPrinter& pr, const int lin) +{ + if (_RigaCorr > lin) + fill_page(pr, -1); + fill_page(pr, lin - _RigaCorr); +} + +void TDicForm::stampa_totali(TPrinter& pr) +{ + PagineQD PagCorr = curr_page(); + TPrint_section& foot = section('B', even_page); + const char* pic = "############"; + bool stampa = FALSE; + + TForm_item& ttotale = foot.find_field(TOT_TOTALE); + TForm_item& tsnsrit = foot.find_field(TOT_SNSRIT); + TForm_item& timpon = foot.find_field(TOT_IMPON); + TForm_item& timpor = foot.find_field(TOT_IMPOR); + TForm_item& tnetto = foot.find_field(TOT_NETTO); + + const bool stampa_tot_fis = ultima_fis(); + const bool stampa_tot_nofis = ultima_nofis(); + + if (stampa_tot_fis) + if (PagCorr == TERZA) // Scrive totali p.fisiche + { + stampa=TRUE; + TString ftot(_f_tot_totale.string(pic)); + TString fsnsrit(_f_tot_snsrit.string(pic)); + TString fimpon(_f_tot_impon.string(pic)); + TString fimpor(_f_tot_impor.string(pic)); + TString fnetto(_f_tot_netto.string(pic)); +// Toglie le migliaia + ftot.cut(ftot.len() - 3); + fsnsrit.cut(fsnsrit.len()-3); + fimpon.cut(fimpon.len()-3); + fimpor.cut(fimpor.len()-3); + fnetto.cut(fnetto.len()-3); + if (ftot.empty()) ftot = "0"; + if (fsnsrit.empty()) fsnsrit = "0"; + if (fimpon.empty()) fimpon = "0"; + if (fimpor.empty()) fimpor = "0"; + if (fnetto.empty()) fnetto = "0"; +// Setta i campi + ttotale.set(ftot); + tsnsrit.set(fsnsrit); + timpon.set(fimpon); + timpor.set(fimpor); + tnetto.set(fnetto); + _GiaStampatiFis = TRUE; +const int NUMPER_TERZA = 6; +const int NUM_RIGHE = 8; + const int gap = ((NUMPER_TERZA - _CtrFisStampati) * NUM_RIGHE)+1; + if (gap>0) + fill_page(pr,gap); + } + + if (stampa_tot_nofis) + if (PagCorr == QUARTA) // Scrive totali p.non fisiche + { + stampa=TRUE; + TString ftot(_nf_tot_totale.string(pic)); + TString fsnsrit(_nf_tot_snsrit.string(pic)); + TString fimpon(_nf_tot_impon.string(pic)); + TString fimpor(_nf_tot_impor.string(pic)); + TString fnetto(_nf_tot_netto.string(pic)); +// Toglie le migliaia + ftot.cut(ftot.len() - 3); + fsnsrit.cut(fsnsrit.len()-3); + fimpon.cut(fimpon.len()-3); + fimpor.cut(fimpor.len()-3); + fnetto.cut(fnetto.len()-3); + if (ftot.empty()) ftot = "0"; + if (fsnsrit.empty()) fsnsrit = "0"; + if (fimpon.empty()) fimpon = "0"; + if (fimpor.empty()) fimpor = "0"; + if (fnetto.empty()) fnetto = "0"; +// Setta i campi + ttotale.set(ftot); + tsnsrit.set(fsnsrit); + timpon.set(fimpon); + timpor.set(fimpor); + tnetto.set(fnetto); + _GiaStampatiNoFis = TRUE; +const int NUMPER_QUARTA = 6; +const int NUM_RIGHE = 8; + const int gap = ((NUMPER_QUARTA - _CtrNoFisStampati) * NUM_RIGHE)+1; + + if (gap > 0) + fill_page(pr,gap); + } + if (stampa) + { + foot.update(); + for (word j = 0; j < foot.height(); j++) + { + pr.print(foot.row(j)); + _RigaCorr++; + } + foot.reset(); // non stampare piu' questi totali! + } +} + +void TDicForm::stampa_testata(TPrinter& pr) +{ + TPrint_section& head = section('H', 1); + const word r = head.height()-1; + TPrintrow& head_row = head.row(r-1); + +// Setta il numero di pagina e poi lo incrementa + TForm_item& nf = head.find_field(H_NUM_FOGLIO); + TString fstr(10); fstr << _num_foglio; + nf.set(fstr); + _num_foglio++; + +// Setta il cod.fis. del dichiarante se necessario + if (tipo_ditta() == estinto) + { + TForm_item& cfd = head.find_field(H_COFI_DIC); + cfd.set(_cofi_dic); + } +// Righe da saltare nelle prime pag. dei moduli successivi al primo (che' son +// senza le righe del posizionamento...) + int HEADER_PRIMA_NOPOS = 3; + head.update(); + for (word j = 0; j <= r; j++) + { + if (j==0) + { + if (_modulaser) + { + TPrintrow& r = head.row(j); + if (!_GiaMessoStartDoc) + put_modulaser(r, STARTDOC); + put_modulaser(r, STARTDITTA); + put_modulaser(r, STARTPAGE, 1); + pr.print(r); + _RigaCorr++; + r.reset(); + HEADER_PRIMA_NOPOS--; + } + if (!PaginaPosizionamento()) + fill_page(pr, HEADER_PRIMA_NOPOS); + } + else + { + pr.print(head.row(j)); + _RigaCorr++; + } + } +} + +void TDicForm::next_page(TPrinter& pr) +{ + PagineQD PagCorr = curr_page(); + if (PagCorr >= TERZA) + stampa_totali(pr); + fill_page(pr, -1); // formfeed "adattato" + inc_curr_page(); +} + +void TDicForm::azzera_totali() +{ + _f_tot_netto = _f_tot_totale = _f_tot_impor = _f_tot_impon = _f_tot_snsrit = ZERO; + _nf_tot_netto = _nf_tot_totale = _nf_tot_impor = _nf_tot_impon = _nf_tot_snsrit = ZERO; +} + +void TDicForm::aggiorna_totali_E(const char tipo) +{ +} + +void TDicForm::aggiorna_totali_E1(const char tipo) +{ +} + +void TDicForm::aggiorna_totali_D(const char tipo) +{ + real totale, netto, impon, nsrit, impor; + TCursor* cur = cursor(); + TRectype& crr = cur->curr(); + + totale = crr.get_real(QUD_TOTALE); + netto = crr.get_real(QUD_NETTO); + impon = crr.get_real(QUD_IMPONIBILE); + impor = crr.get_real(QUD_IMPORTO); + nsrit = crr.get_real(QUD_SOMME); + + if (tipo == 'F') + { + _f_tot_totale += totale; + _f_tot_netto += netto; + _f_tot_impon += impon; + _f_tot_snsrit += nsrit; + _f_tot_impor += impor; + } + else + { + _nf_tot_totale += totale; + _nf_tot_netto += netto; + _nf_tot_impon += impon; + _nf_tot_snsrit += nsrit; + _nf_tot_impor += impor; + } +} + +void TDicForm::aggiorna_totali_D1(const char tipo) +{ + real totale, netto, impon, QuotaProv, SpeseAnt, impor; + TCursor* cur = cursor(); + TRectype& crr = cur->curr(); + + totale = crr.get_real(QD1_TOTALE); + netto = crr.get_real(QD1_NETTO); + impon = crr.get_real(QD1_IMPONIBILE); + impor = crr.get_real(QD1_IMPORTO); + QuotaProv = crr.get_real(QD1_QUOTAPRO); + SpeseAnt = crr.get_real(QD1_SPESEANT); + + if (tipo == 'F') + { + _f_tot_totale += totale; + _f_tot_netto += netto; + _f_tot_impon += impon; + _f_tot_snsrit += QuotaProv; + _f_tot_impor += impor; + } + else + { + _nf_tot_totale += totale; + _nf_tot_netto += netto; + _nf_tot_impon += impon; + _nf_tot_snsrit += QuotaProv; + _nf_tot_impor += impor; + } +} + +void TDicForm::aggiorna_totali_C(const char tipo) +{ + real totale, netto, impon, nsrit, impor; + TCursor* cur = cursor(); + TRectype& crr = cur->curr(); + + totale = crr.get_real(QUD_TOTALE); + netto = crr.get_real(QUD_NETTO); + impon = crr.get_real(QUD_IMPONIBILE); + impor = crr.get_real(QUD_IMPORTO); + nsrit = crr.get_real(QUD_SOMME); + + if (tipo == 'F') + { + _f_tot_totale += totale; + _f_tot_netto += netto; + _f_tot_impon += impon; + _f_tot_snsrit += nsrit; + _f_tot_impor += impor; + } + else + { + _nf_tot_totale += totale; + _nf_tot_netto += netto; + _nf_tot_impon += impon; + _nf_tot_snsrit += nsrit; + _nf_tot_impor += impor; + } +} + + +void TDicForm::aggiorna_totali(const char tipo) +{ + if (_quadro == "C") + aggiorna_totali_C(tipo); + + if (_quadro == "D") + aggiorna_totali_D(tipo); + + if (_quadro == "D1") + aggiorna_totali_D1(tipo); + + if (_quadro == "E") + aggiorna_totali_E(tipo); + + if (_quadro == "E1") + aggiorna_totali_E1(tipo); +} + +void TDicForm::set_body(TPrinter& pr, const char tipo) +{ + TPrint_section& body = section('B', odd_page); + body.reset(); + body.update(); + aggiorna_totali(tipo); + const int body_righe = body.height(); + for (int i=0; i < body_righe; i++) + { + pr.print(body.row(i)); + _RigaCorr++; + } + if (usa_progind()) + progind()->addstatus(1); +} + + +void TDicForm::posiziona() +{ + _GiaPosizionato = TRUE; + _PaginaPosizionamento = TRUE; + + arrange_form(); +/**************************** + char str_pos[MAX_LEN]; + int i; + const int xip = ipx(); + const int yip = ipy(); + const int xfp = fpx(); //131; + + for (i=0; i < MAX_LEN; i++) str_pos[i] = ' '; + str_pos[0] = '\r'; + str_pos[0] = '\r'; + str_pos[xip] = str_pos[xfp] = char_to_pos(); + str_pos[xfp+1] = '\r'; + str_pos[xfp+1] = '\0'; + + bool parti = yesno_box("Conferma stampa riga di posizionamento ?"); + if (!parti) return; + + _GiaPosizionato = TRUE; + _PaginaPosizionamento = TRUE; + + do + { + if (!PrintLineNow(str_pos, xfp+1, hInst)) + message_box("PrintLineNow fallita!"); + } + while (!yesno_box("Posizione corretta ?")); +**************/ +} + +/////////////////////////////////////////////////////////////////////////////////////////// +// +// Quadro G +// +/////////////////////////////////////////////////////////////////////////////////////////// + +HIDDEN const int QG_FORMLEN = 72; +HIDDEN const int QG_PAGINE = 2; +HIDDEN const int HEADER_SECONDA_G = 7; + +class TQuadroG : public TDicForm +{ + private: + long _items_g, _items_gd; + void stampa_prospetti1_2(TPrinter& pr); + void stampa_prospetti3_4(TPrinter& pr); + + protected: + virtual void inc_curr_page(); + virtual void next_page(TPrinter& pr); + virtual void stampa_totali(TPrinter& pr) {} + virtual void aggiorna_totali(const char tipo) {} + virtual void set_body(TPrinter& pr, const char tipo) {} + + public: + virtual bool print(const long codditta, const long NumFis, const long NumNoFis); + void set_items_gd(const long itg, const long itgd) { _items_g = itg; _items_gd = itgd; } + + TQuadroG(const char* form, const char* quadro) : TDicForm(form, quadro), + _items_g(0L), _items_gd(0L) {} + virtual ~TQuadroG() {} +}; + + +void TQuadroG::inc_curr_page() +{ + if (_PaginaCorrente == PRIMA) + _PaginaCorrente = SECONDA; + else + if (_PaginaCorrente == SECONDA) + _PaginaCorrente = PRIMA; +} + + +void TQuadroG::next_page(TPrinter& pr) +{ + PagineQD PagCorr = curr_page(); + fill_page(pr, -1); + inc_curr_page(); +} + + +void TQuadroG::stampa_prospetti1_2(TPrinter& pr) +{ + TPrint_section& head = section('H', 1); + const word rr = head.height()-1; + TPrintrow& head_row = head.row(rr-1); + +// Setta il numero di pagina e poi lo incrementa + TForm_item& nf = head.find_field(H_NUM_FOGLIO); + TString fstr(10); fstr << _num_foglio; + nf.set(fstr); + _num_foglio++; + +// Setta il cod.fis. del dichiarante se necessario + if (tipo_ditta() == estinto) + { + TForm_item& cfd = head.find_field(H_COFI_DIC); + cfd.set(_cofi_dic); + } + + TCursor* cur = cursor(); + +// Prospetto n. 2 + TRectype& r = cur->curr(); + TToken_string p22(r.get("P22")); + TToken_string p23(r.get("P23")); + TToken_string p24(r.get("P24")); + TToken_string p25(r.get("P25")); + TToken_string p26(r.get("P26")); + + const int START_P2 = 56; + const int RIGHE_P2 = 5; + const int COL_P2 = 5; + int cols = 0; + for (int i = 0; i < RIGHE_P2; i++) + { + const int fc2 = START_P2 + cols; + TForm_item& c2 = head.find_field(fc2); + c2.set(p22.get(i)); + + const int fc3 = fc2 + 1; + TForm_item& c3 = head.find_field(fc3); + c3.set(p23.get(i)); + + const int fc4 = fc3 + 1; + TForm_item& c4 = head.find_field(fc4); + c4.set(p24.get(i)); + + const int fc5 = fc4 + 1; + TForm_item& c5 = head.find_field(fc5); + c5.set(p25.get(i)); + + const int fc6 = fc5 + 1; + TForm_item& c6 = head.find_field(fc6); + c6.set(p26.get(i)); + + cols += COL_P2; + } + +// Righe da saltare nelle prime pag. dei moduli successivi al primo (che' son +// senza le righe del posizionamento...) + int HEADER_PRIMA_NOPOS = 3; + head.update(); + for (word j = 0; j <= rr; j++) + { + if (j==0) + { + if (_modulaser) + { + TPrintrow& r = head.row(j); + if (!_GiaMessoStartDoc) + put_modulaser(r, STARTDOC); + put_modulaser(r, STARTDITTA); + put_modulaser(r, STARTPAGE, 1); + pr.print(r); + _RigaCorr++; + r.reset(); + HEADER_PRIMA_NOPOS--; + } + if (!PaginaPosizionamento()) + fill_page(pr, HEADER_PRIMA_NOPOS); + } + else + { + pr.print(head.row(j)); + _RigaCorr++; + } + } +} + +void TQuadroG::stampa_prospetti3_4(TPrinter& pr) +{ + TPrint_section& sez = section('B'); + const word rr = sez.height()-1; + sez.reset(); + TPrintrow& head_row = sez.row(rr-1); + +// Prospetto n. 3 + TCursor* cur = cursor(); + TRectype& r = cur->curr(); + TToken_string p33a(r.get("P33A")); + TToken_string p33b(r.get("P33B")); + TToken_string p35a(r.get("P35A")); + TToken_string p35b(r.get("P35B")); + TToken_string p36a(r.get("P36A")); + TToken_string p36b(r.get("P36B")); + +// colonna 2 e 7 + for (int i=1; i<=5; i++) + { + TForm_item& c2 = sez.find_field(i); + TForm_item& c7 = sez.find_field(i+65); + int src=0; // determina quale posizione va letta dalla token-string per il campo corrente + switch (i) + { + case 1: + src = 0; + break; + case 2: + src = 7; + break; + case 3: + src = 10; + break; + case 4: + src = 12; + break; + case 5: + src = 14; + break; + } + + c2.set(p33a.get(src)); + c7.set(p36b.get(src)); + } + + const int RIGHE_P3 = 20; + +// Colonna 3 + const int START_P3_COL3 = 6; + int c3=0; + for (i = 0; i < RIGHE_P3; i++) + { + c3 = START_P3_COL3 + i; + TForm_item& c5a = sez.find_field(c3); + c5a.set(p33b.get(i)); + } + +// Colonna 5 + const int START_P3_COL5 = c3 + 1; + int c5=0; + for (i = 0; i < RIGHE_P3; i++) + { + c5 = START_P3_COL5 + i; + TForm_item& c6a = sez.find_field(c5); + c6a.set(p35b.get(i)); + } + +// Colonna 6 + const int START_P3_COL6 = c5 + 1; + int c6=0; + for (i = 0; i < RIGHE_P3; i++) + { + c6 = START_P3_COL6 + i; + TForm_item& c6a = sez.find_field(c6); + c6a.set(p36a.get(i)); + } + + sez.update(); + const int sez_righe = sez.height(); + for (i=0; i < sez_righe; i++) + { + pr.print(sez.row(i)); + _RigaCorr++; + } + if (usa_progind()) + progind()->addstatus(1); +} + + +bool TQuadroG::print(const long codditta, const long NumFis, const long NumNoFis) +{ + TCursor* cur = cursor(); + + bool StabilitaInesistenzaNoFis = FALSE; + bool StabilitaInesistenzaFis = FALSE; + long CtrFis = NumFis; + long CtrNoFis = NumNoFis; + long PtrFis = -1L, PtrNoFis=-1L; + TPrinter& pr = printer(); + + _CtrFisStampati = _CtrNoFisStampati = 0; + _finite_fis = _finite_nofis = FALSE; + _GiaStampatiFis = _GiaStampatiNoFis = FALSE; + _EndPrintDitta = FALSE; // Vero se stampato l'ultimo record + bool LastRecord = FALSE; // Vero se letto l'ultimo record + + _PaginaCorrente = PRIMA; + + if (!InitPrint(codditta)) + return FALSE; + + for (int pagina=1; pagina <= QG_PAGINE; pagina++, next_page(pr)) + { + pr.formlen(QG_FORMLEN); + + if (_PaginaCorrente == PRIMA) + { + if (_modulaser) ClearFlagModulaser(); + + (*cur) = PtrFis >= 0L ? PtrFis : 0L; + stampa_prospetti1_2(pr); + } + + if (_PaginaCorrente == SECONDA) + { +// Reset del flag di pagina con posiz. + if (_posiziona && _PaginaPosizionamento) _PaginaPosizionamento = FALSE; + + fill_page(pr, HEADER_SECONDA_G); + stampa_prospetti3_4(pr); + } + } // for pagina.. + + return TRUE; +} + + +/////////////////////////////////////////////////////////////////////////////////////////// +// +// Distinta G +// +/////////////////////////////////////////////////////////////////////////////////////////// + +HIDDEN const int QGD_FORMLEN = 72; +HIDDEN const int QGD_PAGINE = 2; +HIDDEN const int HEADER_SECONDA_GD = 7; +HIDDEN const int QGD_RIGHE_PRIMA = 8; + +class TDistintaG : public TQuadroG +{ + private: + real _f_tot_utspet, _f_tot_utpag, _f_tot_rope, _f_tot_ropespet; + real _nf_tot_utspet, _nf_tot_utpag, _nf_tot_rope, _nf_tot_ropespet; + void aggiorna_totali(const char tipo); + void stampa_totali(TPrinter& pr); + void stampa_testata(TPrinter& pr); + virtual void next_page(TPrinter& pr); + virtual void set_body(TPrinter& pr, const char tipo); + + public: + virtual bool print(const long codditta, const long NumFis, const long NumNoFis); + + TDistintaG(const char* form, const char* quadro) : TQuadroG(form,quadro) {} + virtual ~TDistintaG() {} +}; + +void TDistintaG::next_page(TPrinter& pr) +{ + PagineQD PagCorr = curr_page(); +// if (PagCorr == SECONDA) + stampa_totali(pr); + fill_page(pr, -1); // formfeed "adattato" + inc_curr_page(); +} + +void TDistintaG::aggiorna_totali(const char tipo) +{ + real utspet, utpag, rope, ropespet; + TCursor* cur = cursor(); + TRectype& crr = cur->curr(); + + utspet = crr.get_real(QGD_UTSPETT); + utpag = crr.get_real(QGD_UTPAG); + rope = crr.get_real(QGD_ROPE); + ropespet = crr.get_real(QGD_ROPESPET); + + if (tipo == 'F') + { + _f_tot_utspet += utspet; + _f_tot_utpag += utpag; + _f_tot_rope += rope; + _f_tot_ropespet += ropespet; + } + else + { + _nf_tot_utspet += utspet; + _nf_tot_utpag += utpag; + _nf_tot_rope += rope; + _nf_tot_ropespet += ropespet; + } +} + + +void TDistintaG::stampa_totali(TPrinter& pr) +{ + PagineQD PagCorr = curr_page(); + TPrint_section& foot = section('B', even_page); + const word righe = foot.height(); + const char* pic = "############"; + bool stampa = FALSE; + + TForm_item& ttotale = foot.find_field(TOT_TOTALE); + TForm_item& tsnsrit = foot.find_field(TOT_SNSRIT); + TForm_item& timpon = foot.find_field(TOT_IMPON); + TForm_item& timpor = foot.find_field(TOT_IMPOR); + + const bool stampa_tot_fis = ultima_fis(); + const bool stampa_tot_nofis = ultima_nofis(); + + if (stampa_tot_fis) + if (PagCorr == PRIMA) // Scrive totali p.fisiche + { + stampa=TRUE; + TString ftot(_f_tot_utspet.string(pic)); + TString fsnsrit(_f_tot_utpag.string(pic)); + TString fimpon(_f_tot_rope.string(pic)); + TString fimpor(_f_tot_ropespet.string(pic)); + +// Toglie le migliaia + ftot.cut(ftot.len() - 3); + fsnsrit.cut(fsnsrit.len()-3); + fimpon.cut(fimpon.len()-3); + fimpor.cut(fimpor.len()-3); + if (ftot.empty()) ftot = "0"; + if (fsnsrit.empty()) fsnsrit = "0"; + if (fimpon.empty()) fimpon = "0"; + if (fimpor.empty()) fimpor = "0"; + +// Setta i campi + ttotale.set(ftot); + tsnsrit.set(fsnsrit); + timpon.set(fimpon); + timpor.set(fimpor); + + _GiaStampatiFis = TRUE; +const int NUMPER_TERZA = 6; +const int NUM_RIGHE = 8; + const int gap = ((NUMPER_TERZA - _CtrFisStampati) * NUM_RIGHE)+1; + if (gap>0) + fill_page(pr,gap); + } + + if (stampa_tot_nofis) + if (PagCorr == SECONDA) // Scrive totali p.non fisiche + { + stampa=TRUE; + TString ftot (_nf_tot_utspet.string(pic)); + TString fsnsrit(_nf_tot_utpag.string(pic)); + TString fimpon (_nf_tot_rope.string(pic)); + TString fimpor (_nf_tot_ropespet.string(pic)); + +// Toglie le migliaia + ftot.cut(ftot.len() - 3); + fsnsrit.cut(fsnsrit.len()-3); + fimpon.cut(fimpon.len()-3); + fimpor.cut(fimpor.len()-3); + + if (ftot.empty()) ftot = "0"; + if (fsnsrit.empty()) fsnsrit = "0"; + if (fimpon.empty()) fimpon = "0"; + if (fimpor.empty()) fimpor = "0"; + +// Setta i campi + ttotale.set(ftot); + tsnsrit.set(fsnsrit); + timpon.set(fimpon); + timpor.set(fimpor); + + _GiaStampatiNoFis = TRUE; + const int NUMPER_QUARTA = 6; + const int NUM_RIGHE = 8; + const int gap = ((NUMPER_QUARTA - _CtrNoFisStampati) * NUM_RIGHE)+1; + + if (gap > 0) + fill_page(pr,gap); + } + if (stampa) + { + foot.update(); + for (word j = 0; j < righe; j++) + { + pr.print(foot.row(j)); + _RigaCorr++; + } + foot.reset(); // non stampare piu' questi totali! + } +} + +void TDistintaG::stampa_testata(TPrinter& pr) +{ + TPrint_section& head = section('H', 1); + const word r = head.height()-1; + TPrintrow& head_row = head.row(r-1); + +// Setta il numero di pagina e poi lo incrementa + TForm_item& nf = head.find_field(H_NUM_FOGLIO); + TString fstr(10); fstr << _num_foglio; + nf.set(fstr); + _num_foglio++; +} + +void TDistintaG::set_body(TPrinter& pr, const char tipo) +{ + TPrint_section& body = section('B', odd_page); + body.reset(); + body.update(); + aggiorna_totali(tipo); + const int body_righe = body.height(); + for (int i=0; i < body_righe; i++) + { + pr.print(body.row(i)); + _RigaCorr++; + } + if (usa_progind()) + progind()->addstatus(1); +} + + +bool TDistintaG::print(const long codditta, const long NumFis, const long NumNoFis) +{ + TCursor* cur = cursor(); + + bool StabilitaInesistenzaNoFis = FALSE; + bool StabilitaInesistenzaFis = FALSE; + long CtrFis = NumFis; + long CtrNoFis = NumNoFis; + long PtrFis = -1L, PtrNoFis=-1L; + TPrinter& pr = printer(); + + _CtrFisStampati = _CtrNoFisStampati = 0; + _finite_fis = _finite_nofis = FALSE; + _GiaStampatiFis = _GiaStampatiNoFis = FALSE; + _EndPrintDitta = FALSE; // Vero se stampato l'ultimo record + bool LastRecord = FALSE; // Vero se letto l'ultimo record + _PaginaCorrente = PRIMA; + + _codditta = codditta; + _RigaCorr = 0; + + const long items = filtra(codditta); + + while (!_EndPrintDitta) + { + for (int pagina=1; pagina <= QGD_PAGINE; pagina++, next_page(pr)) + { + pr.formlen(QGD_FORMLEN); + + if (_PaginaCorrente == PRIMA) + { + if (_modulaser) ClearFlagModulaser(); + + for (int righe=0; righe < QGD_RIGHE_PRIMA; righe++) + { +// Stampa intestazione, solo sul primo foglio. + if (!righe) + { + (*cur) = PtrFis >= 0L ? PtrFis : 0L; + stampa_testata(pr); + } + + if (_finite_fis || StabilitaInesistenzaFis) + break; + +// La prima volta si deve posizionare sul primo record di p.f. + if (PtrFis<0L && !StabilitaInesistenzaFis) + { + bool Trovato = FALSE; + + while (!Trovato) + { + const long ditta = cur->curr().get_long(QGD_CODDITTA); + if (ditta != codditta) + break; + const char tipo = cur->curr().get(QGD_TIPOA)[0]; + if (tipo != 'G') + { + PtrFis = cur->pos(); + Trovato = TRUE; + break; + } + else + ++(*cur); + } + StabilitaInesistenzaFis = !Trovato; + } + + if (StabilitaInesistenzaFis) + break; + + (*cur) = PtrFis; + const char tipo = cur->curr().get(QGD_TIPOA)[0]; + + if (tipo != 'F') + break; + else + { + CtrFis--; + if (CtrFis == 0L) _finite_fis = TRUE; + set_body(pr, 'F'); +// La stampa e' finita se ho STAMPATO l'ultimo record + LastRecord = cur->pos() >= items-1; + _EndPrintDitta = LastRecord; + if (!LastRecord) + { + ++(*cur); + PtrFis = cur->pos(); + LastRecord = cur->pos() >= items-1; + } + } + } // for righe.. + PtrFis = cur->pos(); + } + + if (_PaginaCorrente == SECONDA) + { +// Reset del flag di pagina con posiz. + if (_posiziona && _PaginaPosizionamento) _PaginaPosizionamento = FALSE; + for (int righe=0; righe < QD_RIGHE_SECONDA; righe++) + { + if (!righe) + _CtrNoFisStampati = 0; + +// All'inizio salta le righe in alto + if (!righe) + fill_page(pr, HEADER_SECONDA_GD); + + if (_finite_nofis || StabilitaInesistenzaNoFis) + break; + +// La prima volta si deve posizionare sul primo record di p.g. + if (PtrNoFis<0L && !StabilitaInesistenzaNoFis) + { + bool Trovato = FALSE; + bool eof = FALSE; + (*cur) = PtrFis-1 > 0L ? PtrFis-1 : 0L; // parti dall'inizio + while (!Trovato && !eof) + { + eof = cur->pos() >= items-1; + const long ditta = cur->curr().get_long(QGD_CODDITTA); + if (ditta != codditta) + break; + const char tipo = cur->curr().get(QGD_TIPOA)[0]; + if (tipo != 'F') + { + PtrNoFis = cur->pos(); + Trovato = TRUE; + break; + } + else + ++(*cur); + } + StabilitaInesistenzaNoFis = !Trovato; + } + + if (StabilitaInesistenzaNoFis) + break; + + (*cur) = PtrNoFis; + const char tipo = cur->curr().get(QGD_TIPOA)[0]; + + if (tipo != 'G') + break; + else + { + CtrNoFis--; + if (CtrNoFis == 0L) _finite_nofis = TRUE; + set_body(pr, 'G'); + LastRecord = cur->pos() >= items-1; + _EndPrintDitta = LastRecord; + _CtrNoFisStampati++; + if (!LastRecord) + { + ++(*cur); + PtrNoFis = cur->pos(); + LastRecord = cur->pos() >= items-1; + } + } + } + PtrNoFis = cur->pos(); + } + } // for pagina.. + } // while !EndPrintDitta + + if (usa_progind()) + { + delete _prog; + _prog = NULL; + } + + return TRUE; +} + + +/////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////////// + + + +//////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////// +// +// TStDicArray +// +// Array delle ditte da stampare. Contiene una riga per ogni ditta che si vuole stampare +// Il formato della riga e': +// codditta|estinti|numfis|numnofis|ultimafis|ultimanofis +// +///////////////////////////////////////////////////////////////////////////////////////////// + +class TStDicArray : public TObject +{ + private: + TString_array _store; + + public: + TToken_string& operator[](int i) const; + int curr_index() const { return _store.last(); } + void set(const int index, const TipoDitta tipo=normale, const int num_fis=0, const int num_nofis=0, + bool ultima_con_fis=FALSE, bool ultima_con_nofis=FALSE, const char* cofidic=NULL); + void set_tipo(const int index, const TipoDitta tipo); + void set_ultima_con_fis(const int index, const bool ultima_fis); + void set_ultima_con_nofis(const int index, const bool ultima_nofis); + void set_flag_tipi(const int index, const bool ultima_fis, const bool ultima_nofis); + void set_ctr_tipi(const int index, const int num_fis, const int num_nofis); + void add(const long codditta, const TipoDitta tipo=normale, const int num_fis=0, const int num_nofis=0, + bool ultima_con_fis=FALSE, bool ultima_con_nofis=FALSE, const char* cofidic=NULL); + int items() const { return _store.items(); } + void destroy() { _store.destroy(); } +}; + + +TToken_string& TStDicArray::operator[](int i) const +{ + return ((TString_array&)_store).row(i); +} + +void TStDicArray::set_ultima_con_fis(const int index, const bool ultima_fis) +{ + TToken_string riga((TString&)_store[index]); + riga.add(ultima_fis, 4); + _store.add(riga,index); +} + +void TStDicArray::set_ultima_con_nofis(const int index, const bool ultima_nofis) +{ + TToken_string riga((TString&)_store[index]); + riga.add(ultima_nofis, 5); + _store.add(riga,index); +} + +void TStDicArray::set_flag_tipi(const int index, const bool ultima_fis, const bool ultima_nofis) +{ + TToken_string riga((TString&)_store[index]); + riga.add(ultima_fis,4); + riga.add(ultima_nofis,5); + _store[index] = riga; +} + +void TStDicArray::set_ctr_tipi(const int index, const int num_fis, const int num_nofis) +{ + TToken_string riga((TString&)_store[index]); + riga.add(num_fis,2); + riga.add(num_nofis,3); + _store[index] = riga; +} + +void TStDicArray::set(const int index, const TipoDitta tipo, const int num_fis, const int num_nofis, + bool ultima_con_fis, bool ultima_con_nofis, const char* cofi_dic) +{ + TToken_string riga((TString&)_store[index]); + riga.add(tipo,1); + riga.add(num_fis,2); + riga.add(num_nofis,3); + riga.add(ultima_con_fis,4); + riga.add(ultima_con_nofis,5); + TString codfis(20); codfis = cofi_dic ? cofi_dic : ""; + riga.add((const char*)codfis,6); + _store[index] = riga; +} + +void TStDicArray::add(const long codditta, const TipoDitta tipo, const int num_fis, const int num_nofis, + bool ultima_con_fis, bool ultima_con_nofis, const char* cfdic) +{ + TString key(40); +// Il formato della riga e': codditta|estinti|numfis|numnofis|ultimafis|ultimanofis + key.format("%ld|%d|%d|%d|%d|%d|%s", codditta, tipo, num_fis, num_nofis, ultima_con_fis, ultima_con_nofis, cfdic ? cfdic : ""); + _store.add(key); +} + + +///////////////////////////////////////////////////////////////////////////////////////////// +// +// STAMPA QUADRO +// +///////////////////////////////////////////////////////////////////////////////////////////// + +class TStampaQuadro : public TApplication +{ + TMask* _m; // Maschera di stampa + + TConfig* _cnf; // Configurazione + TString16 _section; // Paragrafo del config + long _codditta; + int _anno_dic; + + TString _quadro; + char _livello; // "S" studio, "D" singola ditta + TString _title; + + TStDicArray _ditte; + +protected: // TApplication + virtual bool menu(MENU_TAG); + virtual void on_config_change(); + + virtual bool create(); + virtual bool destroy(); + +protected: + virtual bool user_create() pure; + virtual bool user_destroy() pure; + + virtual TDicForm* get_form() const pure; + virtual TCursor* get_cursor() const pure; + + virtual const char* mask_name() const; + virtual const char* form_name() const; + + virtual bool conta_tipi_per() const { return TRUE; } + void fill_estinti(const long CodDic); + const TStDicArray& ditte() const { return _ditte; } + + virtual bool print_quadro(const int OffsetDitta, const bool modulaser); + virtual void print(const bool modulaser); + + bool singola_ditta() const { return _livello == 'D'; } + const TString& quadro() const { return _quadro; } + + TStampaQuadro(const char* quad, char liv); + virtual ~TStampaQuadro() { } + +public: + const TString& taitol() const { return _title; } +}; + +TStampaQuadro::TStampaQuadro(const char* quad, char liv) + : _quadro(quad), _livello(liv) +{ + _title = "Stampa Quadro "; _title << _quadro; +} + +// La maschera e' uguale per tutti i quadri +const char* TStampaQuadro::mask_name() const +{ + return "77STQD"; +} + +const char* TStampaQuadro::form_name() const +{ + __dep16 = "77Q"; + __dep16 << _quadro; + return __dep16; +} + +bool TStampaQuadro::create() +{ + TApplication::create(); + + _section = name(); + _section.cut(2); + _cnf = new TConfig(CONFIG_USER, _section); + + _m = new TMask(mask_name()); + _m->set_caption(taitol()); + + if (singola_ditta()) + { + _codditta = get_firm_770(); + _m->set(F_CODDITTA, _codditta); + } + else + { + _m->hide(F_RAGDITTA); + _m->set(F_TEXT, "Ditte selezionate"); + _m->show(F_TEXT); + } + + user_create(); + + dispatch_e_menu(BAR_ITEM(1)); + return TRUE; +} + +bool TStampaQuadro::destroy() +{ + user_destroy(); + + delete _m; + delete _cnf; + return TApplication::destroy(); +} + +void TStampaQuadro::on_config_change() +{ + TConfig conf(singola_ditta() ? CONFIG_STUDIO : CONFIG_USER); + _anno_dic = (int)conf.get_long(ANNO_SEL, _section); +} + +bool TStampaQuadro::menu(MENU_TAG) +{ + KEY k; + _m->set(F_ANNO, _anno_dic); + while ((k = _m->run()) == K_ENTER) + { + const bool modulaser = _m->get_bool(F_MODULASER); + print(modulaser); + } + return FALSE; +} + +void TStampaQuadro::fill_estinti(const long CodDic) +{ + int NumFisiche=0, NumNoFisiche=0; + TString CodFiDic(20); + +// Salva il cod.fis. del dichiarante + CodFiDic = cod_fis(CodDic); + + if (conta_tipi_per()) + { + conta_tipiper(CodDic, _quadro, &NumFisiche, &NumNoFisiche); + _ditte.add(CodDic, dichiarante, NumFisiche, NumNoFisiche); + } + else + _ditte.add(CodDic, dichiarante); + + const int index_dich = _ditte.curr_index(); + bool gia_trovata_ultima_fis = FALSE; + bool gia_trovata_ultima_nofis = FALSE; + int index = index_dich; + +// Leggo gli estinti + TLocalisamfile base(LF_BASE); + base.setkey(2); + base.zero(); + base.put(BSE_CODDIC, (long)CodDic); + TRectype dep(base.curr()); + + for (base.read(); !base.eof(); base.next()) + { + if (base.curr() > dep) + break; + +// Scarta il record del quadro I "globale" del dichiarante + const char tipoqua = base.get(BSE_TIPOQUA)[0]; + if (tipoqua == COD_QUA_I_DIC) + continue; + + const long DittaEstinta = base.get_long(BSE_CODDITTA); + + if (conta_tipi_per()) + { + conta_tipiper(DittaEstinta, _quadro, &NumFisiche, &NumNoFisiche); + _ditte.add(DittaEstinta, estinto, NumFisiche, NumNoFisiche, FALSE, FALSE, CodFiDic); + } + else + _ditte.add(DittaEstinta, estinto, 0L, 0L, FALSE, FALSE, CodFiDic); + + if (conta_tipi_per()) + { + // Determina se con questa ditta finiscono le persone f. o g. + if (NumFisiche == 0 && !gia_trovata_ultima_fis) + { + _ditte.set_ultima_con_fis(index, TRUE); + gia_trovata_ultima_fis = TRUE; + } + + if (NumNoFisiche == 0 && !gia_trovata_ultima_nofis) + { + _ditte.set_ultima_con_nofis(index, TRUE); + gia_trovata_ultima_nofis = TRUE; + } + } + index++; + } + + if (conta_tipi_per()) + { +// Finiti gli estinti. L'ultima ditta deve avere i totali se non gia' trovati + if (!gia_trovata_ultima_fis) + _ditte.set_ultima_con_fis(index, TRUE); + + if (!gia_trovata_ultima_nofis) + _ditte.set_ultima_con_nofis(index, TRUE); + } +} + +// _ditte e' fatto di righe siffatte: +// codditta, flag 2 dichiarante, 1 normale, 0 estinto, num_fis, num_nofis, ultima_con_fis, ultima_con_nofis + +bool TStampaQuadro::print_quadro(const int OffsetDitta, const bool modulaser) +{ + TDicForm* ff = get_form(); + int start=0, last=0; +// Setta formlen prima di printer.open per avere la lunghezza giusta nel caso di +// stampa a video + printer().formlen(QD_FORMLEN); + bool ok = printer().open(); + + ff->set_cursor(get_cursor()); + ff->azzera_totali(); + ff->set_modulaser(modulaser); + +// Dice se deve eseguire il posizionamento del foglio. +// Se stampa piu' ditte va eseguito solo sulla prima +// Occhio a non spostarlo nel ciclo. + ff->set_posiziona(TRUE); + + if (OffsetDitta >= 0) + { + start = OffsetDitta; + last = OffsetDitta; + } + else + last = _ditte.items() - 1; + + for (int i = start; i <= last; i++) + { + TString CoFiDic(20); + TToken_string riga(ditte()[i]); + const long codditta = atol(riga.get(0)); + const TipoDitta tipo = (TipoDitta)riga.get_int(1); + const long fis = riga.get_long(2); + const long nofis = riga.get_long(3); + const bool LastFis = (bool)riga.get_int(4); + const bool LastNoFis = (bool)riga.get_int(5); + +// I gruppi dich-estinti hanno totali comuni +// Si presume che nell'array vengano messi nell'ordine dich-estinti + if (tipo == normale || tipo == dichiarante) + ff->azzera_totali(); + + if (tipo == estinto) + CoFiDic = riga.get(6); + + if (conta_tipi_per()) + { +// Se e' un dichiarante i totali vanno sull'estinto in cui finiscono o le F o le G + const bool StampaTotaliFis = tipo == normale || + (tipo == estinto && LastFis); + + const bool StampaTotaliNoFis = tipo == normale || + (tipo == estinto && LastNoFis); + +// Dice al form se e' questa ditta e' l'ultima con f. o g. + ff->can_print_tot_fis(StampaTotaliFis); + ff->can_print_tot_nofis(StampaTotaliNoFis); + } + +// Dice al form che tipo di ditta si stampa + ff->set_tipo_ditta(tipo); + +// Numera i fogli a partire da 1 per ogni ditta normale e da 1 e di seguito negli estinti +// per i sogg. dichiaranti + if (tipo == normale || tipo == dichiarante) + ff->set_num_foglio(1); + +// Se la ditta e' estinta dice al form il cod.fis. del dichiarante + if (tipo == estinto) + ff->set_cofi_dic(CoFiDic); + +// Dice al form che e' l'ultima ditta + if (i == last) + ff->set_last_ditta(TRUE); + + ff->print(codditta, fis, nofis); + } + + printer().close(); + return ok; +} + +void TStampaQuadro::print(const bool modulaser) +{ + int NumFisiche=0, NumNoFisiche=0; + + _ditte.destroy(); // Pulisce l'array delle ditte + + if (singola_ditta()) + { + if (sogg_estinto(_codditta)) + { + warning_box("La ditta %ld e' un soggetto estinto", _codditta); + return; + } + +// Se e' un dichiarante va a prendere tutti i suoi estinti. + bool dich = sogg_dic(_codditta); + if (dich) + fill_estinti(_codditta); + else + { + if (conta_tipi_per()) + { + conta_tipiper(_codditta, _quadro, &NumFisiche, &NumNoFisiche); + _ditte.add(_codditta, normale, NumFisiche, NumNoFisiche); + } + else + _ditte.add(_codditta, normale); + } + } + else // stampa ditte selezionate + { +// Costruisco un'array delle ditte da stampare. +// Tolgo i sogg. estinti, e dopo un dichiarante metto tutti i suoi estinti. + long codditta_prec = get_firm_770(); + long codditta = 0L; + int i=0; + while ((codditta = _cnf->get_long(DITTE_SEL, _section, i++)) != 0L) + { + if (sogg_estinto(codditta)) + continue; + +// Se e' un dichiarante va a prendere tutti i suoi estinti. + bool dich = sogg_dic(codditta); + if (dich) + fill_estinti(codditta); + else + { + if (conta_tipi_per()) + { + conta_tipiper(codditta, _quadro, &NumFisiche, &NumNoFisiche); + _ditte.add(codditta, normale, NumFisiche, NumNoFisiche); + } + else + _ditte.add(codditta, normale); + } + } + set_firm_770(codditta_prec); + } + + print_quadro(-1, modulaser); +} + + +///////////////////////////////////////////////////////////////////////////////////////////// +// +// STAMPA QUADRO D +// +///////////////////////////////////////////////////////////////////////////////////////////// +class TStampaQuadroD : public TStampaQuadro +{ + TDicForm* _form; + TRelation* _rel; + TCursor* _cur; + +protected: + virtual bool user_create(); + virtual bool user_destroy(); + + virtual TDicForm* get_form() const { return _form; } + virtual TCursor* get_cursor() const { return _cur; } + + public: + TStampaQuadroD(const char* quadro, char livel); + virtual ~TStampaQuadroD() { } +}; + +TStampaQuadroD::TStampaQuadroD(const char* quadro, char liv) + : TStampaQuadro(quadro, liv) +{ +} + +bool TStampaQuadroD::user_create() +{ + if (quadro() == "C") + { + _rel = new TRelation(LF_QUAC); + _rel->add("%CA7", "CODTAB=CODCAUS", 1, LF_QUAC, 14); + _rel->add(LF_NDITTE, "CODDITTA=CODDITTA"); + _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); + _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); + _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); + _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); + _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_QUAC, 216); + _rel->add("%STA", "CODTAB=STATORES", 1, -216, 24); + _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, -216, 218); + _rel->add(LF_COMUNI, "COM=COMNASC", 1, -218, 313); + _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, -216, 413); + _cur = new TSorted_cursor(_rel, "CODDITTA|TIPOA|216@->RAGSOC|CODANAGR|CODCAUS|PERC"); + } + + if (quadro() == "D") + { + _rel = new TRelation(LF_QUAD); + _rel->add("%CA7", "CODTAB=CODCAUS", 1, LF_QUAD, 14); + _rel->add(LF_NDITTE, "CODDITTA=CODDITTA"); + _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); + _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); + _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); + _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); + _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_QUAD, 216); + _rel->add("%STA", "CODTAB=STATORES", 1, -216, 24); + _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, -216, 218); + _rel->add(LF_COMUNI, "COM=COMNASC", 1, -218, 313); + _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, -216, 413); + _cur = new TSorted_cursor(_rel, "CODDITTA|TIPOA|216@->RAGSOC|CODANAGR|CODCAUS|PERC"); + } + + if (quadro() == "D1") + { + _rel = new TRelation(LF_QUAD1); + _rel->add("%CA7", "CODTAB=CODCAUS", 1, LF_QUAD1, 14); + _rel->add(LF_NDITTE, "CODDITTA=CODDITTA"); + _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); + _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); + _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); + _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); + _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_QUAD1, 216); + _rel->add("%STA", "CODTAB=STATORES", 1, -216, 24); + _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, -216, 218); + _rel->add(LF_COMUNI, "COM=COMNASC", 1, -218, 313); + _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, -216, 413); + _cur = new TSorted_cursor(_rel, "CODDITTA|TIPOA|216@->RAGSOC|CODANAGR|CODCAUS|PERC"); + } + + if (quadro() == "E") + { + _rel = new TRelation(LF_QUAE); + _rel->add("%CA7", "CODTAB=CODCAUS", 1, LF_QUAE, 14); + _rel->add(LF_NDITTE, "CODDITTA=CODDITTA"); + _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); + _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); + _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); + _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); + _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_QUAE, 216); + _rel->add("%STA", "CODTAB=STATORES", 1, -216, 24); + _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, -216, 218); + _rel->add(LF_COMUNI, "COM=COMNASC", 1, -218, 313); + _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, -216, 413); + _cur = new TSorted_cursor(_rel, "CODDITTA|TIPOA|216@->RAGSOC|CODANAGR|CODCAUS|PERC"); + } + + if (quadro() == "E1") + { + _rel = new TRelation(LF_QUAE1); + _rel->add("%CA7", "CODTAB=CODCAUS", 1, LF_QUAE1, 14); + _rel->add(LF_NDITTE, "CODDITTA=CODDITTA"); + _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); + _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); + _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); + _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); + _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_QUAE1, 216); + _rel->add("%STA", "CODTAB=STATORES", 1, -216, 24); + _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, -216, 218); + _rel->add(LF_COMUNI, "COM=COMNASC", 1, -218, 313); + _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, -216, 413); + _cur = new TSorted_cursor(_rel, "CODDITTA|TIPOA|216@->RAGSOC|CODANAGR|CODCAUS|PERC"); + } + + _form = new TDicForm(form_name(), quadro()); + + return TRUE; +} + +bool TStampaQuadroD::user_destroy() +{ + delete _form; + delete _cur; + delete _rel; + return TRUE; +} + +///////////////////////////////////////////////////////////////////////////////////////////// +// +// STAMPA QUADRO G +// +///////////////////////////////////////////////////////////////////////////////////////////// +class TStampaQuadroG : public TStampaQuadro +{ +private: + TQuadroG* _form_g; + TDistintaG* _form_gd; + TRelation* _rel_g, * _rel_gd; + TCursor* _cur_g, * _cur_gd; + +protected: + virtual bool user_create(); + virtual bool user_destroy(); + + virtual TDicForm* get_form() const { return _form_g; } + virtual TCursor* get_cursor() const { return _cur_g; } + + virtual bool print_quadro(const int OffsetDitta, const bool modulaser); + +public: + TStampaQuadroG(char livel) : TStampaQuadro("G", livel) { } +}; + +bool TStampaQuadroG::user_create() +{ + _rel_g = new TRelation(LF_QUAG); + _rel_g->add(LF_NDITTE, "CODDITTA=CODDITTA"); + _rel_g->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); + _rel_g->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); + _rel_g->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); + _rel_g->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); + _cur_g = new TCursor(_rel_g); + + _rel_gd = new TRelation(LF_QUAGD); + _rel_gd->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_QUAGD, 216); + _rel_gd->add("%STA", "CODTAB=STATORES", 1, -216, 24); + _rel_gd->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, -216, 218); + _rel_gd->add(LF_COMUNI, "COM=COMNASC", 1, -218, 313); + _rel_gd->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, -216, 413); + _cur_gd = new TSorted_cursor(_rel_gd, "CODDITTA|TIPOA|216@->RAGSOC|CODANAGR"); + + _form_g = new TQuadroG("77QG", quadro()); + _form_gd = new TDistintaG("77QGD", quadro()); + + return TRUE; +} + +bool TStampaQuadroG::user_destroy() +{ + delete _form_gd; + delete _form_g; + + delete _rel_gd; + delete _cur_gd; + + delete _rel_g; + delete _cur_g; + + return TRUE; +} + +// _ditte e' fatto di righe siffatte: +// codditta, flag 2 dichiarante, 1 normale, 0 estinto, num_fis, num_nofis, ultima_con_fis, ultima_con_nofis +bool TStampaQuadroG::print_quadro(const int OffsetDitta, const bool modulaser) +{ + int start=0, last=0; + long items_g, items_gd; + + items_g = items_gd = 0L; +// Setta formlen prima di printer.open per avere la lunghezza giusta nel caso di +// stampa a video + printer().formlen(QG_FORMLEN); + bool ok = printer().open(); + + _form_g->set_cursor(_cur_g); + _form_gd->set_cursor(_cur_gd); + + _form_g->set_modulaser(modulaser); + _form_gd->set_modulaser(modulaser); + + _form_gd->azzera_totali(); + +// Dice se deve eseguire il posizionamento del foglio. +// Se stampa piu' ditte va eseguito solo sulla prima +// Occhio a non spostarlo nel ciclo. + _form_g->set_posiziona(TRUE); + + if (OffsetDitta >= 0) + { + start = OffsetDitta; + last = OffsetDitta; + } + else + last = ditte().items() - 1; + + for (int i = start; i <= last; i++) + { + TString CoFiDic(20); + TToken_string riga(ditte()[i]); + const long codditta = atol(riga.get(0)); + const TipoDitta tipo = (TipoDitta)riga.get_int(1); + const long fis = riga.get_long(2); + const long nofis = riga.get_long(3); + const bool LastFis = (bool)riga.get_int(4); + const bool LastNoFis = (bool)riga.get_int(5); + +// I gruppi dich-estinti hanno totali comuni +// Si presume che nell'array vengano messi nell'ordine dich-estinti + if (tipo == normale || tipo == dichiarante) + _form_g->azzera_totali(); + + if (tipo == estinto) + CoFiDic = riga.get(6); + +// Se e' un dichiarante i totali vanno sull'estinto in cui finiscono o le F o le G + const bool StampaTotaliFis = tipo == normale || + (tipo == estinto && LastFis); + + const bool StampaTotaliNoFis = tipo == normale || + (tipo == estinto && LastNoFis); + +// Dice al form se e' questa ditta e' l'ultima con f. o g. + _form_gd->can_print_tot_fis(StampaTotaliFis); + _form_gd->can_print_tot_nofis(StampaTotaliNoFis); + +// Dice al form che tipo di ditta si stampa + _form_g->set_tipo_ditta(tipo); + +// Numera i fogli a partire da 1 per ogni ditta normale e da 1 e di seguito negli estinti +// per i sogg. dichiaranti + if (tipo == normale || tipo == dichiarante) + _form_g->set_num_foglio(1); + +// Se la ditta e' estinta dice al form il cod.fis. del dichiarante + if (tipo == estinto) + _form_g->set_cofi_dic(CoFiDic); + +// Dice al form che e' l'ultima ditta + if (i == last) + _form_gd->set_last_ditta(TRUE); + + items_g = _form_g->filtra(codditta); + items_gd = _form_gd->filtra(codditta); + +// Dice al form quanto e' lunga la progress-bar + _form_g->set_items_gd(items_g, items_gd); + + _form_g->print(codditta, fis, nofis); +// La progind deve essere la stessa tra G e distinta... + + _form_gd->set_progind(_form_g->progind()); // Passa la progind al form gd ... + _form_g->set_progind(NULL); // ... e la toglie dal form g + + _form_gd->print(codditta, fis, nofis); + } + + printer().close(); + return ok; +} + +/////////////////////////////////////////////////////////////////////////////////////////// +// +// Quadro G-1 +// +/////////////////////////////////////////////////////////////////////////////////////////// + +HIDDEN const int QG1_FORMLEN = 72; +HIDDEN const int QG1_PAGINE = 1; + +class TQuadroG1 : public TDicForm +{ + private: + long _items; + void stampa_prospetto(TPrinter& pr); + + public: + virtual bool print(const long codditta, const long NumFis=0L, const long NumNoFis=0L); + //virtual bool print(const long codditta); + + TQuadroG1(const char* form, const char* quadro) : TDicForm(form, quadro) {} + virtual ~TQuadroG1() {} +}; + +bool TQuadroG1::print(const long codditta, const long NumFis, const long NumNoFis) +{ + TCursor* cur = cursor(); + TPrinter& pr = printer(); + + if (!InitPrint(codditta)) + return FALSE; + + pr.formlen(QG1_FORMLEN); + + if (_modulaser) ClearFlagModulaser(); + + (*cur) = 0L; + stampa_prospetto(pr); + + return TRUE; +} + +void TQuadroG1::stampa_prospetto(TPrinter& pr) +{ + TPrint_section& head = section('H', 1); + const word rr = head.height()-1; + TPrintrow& head_row = head.row(rr-1); + +// Setta il cod.fis. del dichiarante se necessario + if (tipo_ditta() == estinto) + { + TForm_item& cfd = head.find_field(H_COFI_DIC); + cfd.set(_cofi_dic); + } + + TCursor* cur = cursor(); +// Prospetto + TRectype& r = cur->curr(); + TToken_string p12(r.get("P12")); + TToken_string p13(r.get("P13")); + TToken_string p14(r.get("P14")); + TToken_string p15(r.get("P15")); + TToken_string p16(r.get("P16")); + TToken_string p17(r.get("P17")); + + const int START_PROSP = 56; + const int RIGHE_COL356 = 12; + const int RIGHE_COL27 = 5; + const int COL_PROSP = 5; + +// Colonne 2 e 7 + for (int i = 0; i < RIGHE_COL27; i++) + { + const int fc2 = START_PROSP + i; + TForm_item& c2 = head.find_field(fc2); + c2.set(p12.get(i)); + + const int fc7 = fc2 + RIGHE_COL27 + 1; + TForm_item& c7 = head.find_field(fc7); + c7.set(p17.get(i)); + } + + const int START_COL3 = 68; +// Colonne 3 5 e 6 + for (i = 0; i < RIGHE_COL356; i++) + { + const int fc3 = START_COL3 + i; + TForm_item& c3 = head.find_field(fc3); + c3.set(p13.get(i)); + + const int fc5 = fc3 + RIGHE_COL356 + 1; + TForm_item& c5 = head.find_field(fc5); + c5.set(p15.get(i)); + + const int fc6 = fc5 + RIGHE_COL356 + 1; + TForm_item& c6 = head.find_field(fc6); + c6.set(p16.get(i)); + } + +// Righe da saltare nelle prime pag. dei moduli successivi al primo (che' son +// senza le righe del posizionamento...) + int HEADER_PRIMA_NOPOS = 3; + head.update(); + for (word j = 0; j <= rr; j++) + { + if (j==0) + { + if (_modulaser) + { + TPrintrow& r = head.row(j); + if (!_GiaMessoStartDoc) + put_modulaser(r, STARTDOC); + put_modulaser(r, STARTDITTA); + put_modulaser(r, STARTPAGE, 1); + pr.print(r); + _RigaCorr++; + r.reset(); + HEADER_PRIMA_NOPOS--; + } + if (!PaginaPosizionamento()) + fill_page(pr, HEADER_PRIMA_NOPOS); + } + else + { + pr.print(head.row(j)); + _RigaCorr++; + } + } +} + +///////////////////////////////////////////////////////////////////////////////////////////// +// +// STAMPA QUADRO G-1 +// +///////////////////////////////////////////////////////////////////////////////////////////// +class TStampaQuadroG1 : public TStampaQuadroD +{ + private: + TQuadroG1* _form; + TRelation* _rel; + TCursor* _cur; + + protected: + virtual bool user_create(); + virtual bool user_destroy(); + + virtual TDicForm* get_form() const { return _form; } + virtual TCursor* get_cursor() const { return _cur; } + virtual bool conta_tipi_per() const { return FALSE; } + + public: + TStampaQuadroG1(char livel) : TStampaQuadroD("G1", livel) {} +}; + +bool TStampaQuadroG1::user_create() +{ + _form = new TQuadroG1("77QG1", quadro()); + + _rel = new TRelation(LF_QUAG1); + _rel->add(LF_NDITTE, "CODDITTA=CODDITTA"); + _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); + _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); + _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); + _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); + _cur = new TCursor(_rel); + + return TRUE; +} + +bool TStampaQuadroG1::user_destroy() +{ + delete _cur; + delete _rel; + delete _form; + + return TRUE; +} + +/* +// _ditte e' fatto di righe siffatte: +// codditta, flag 2 dichiarante, 1 normale, 0 estinto, num_fis, num_nofis, ultima_con_fis, ultima_con_nofis +bool TStampaQuadroG1::print_quadro(TString& quadro, const int OffsetDitta) +{ + int start=0, last=0; + +// Setta formlen prima di printer.open per avere la lunghezza giusta nel caso di +// stampa a video + printer().formlen(QG_FORMLEN); + bool ok = printer().open(); + bool modulaser = _m->get_bool(F_MODULASER); + + _form->set_cursor(_rel, _cur); + + _form->set_modulaser(modulaser); + +// Dice se deve eseguire il posizionamento del foglio. +// Se stampa piu' ditte va eseguito solo sulla prima +// Occhio a non spostarlo nel ciclo. + _form->set_posiziona(TRUE); + + if (OffsetDitta >= 0) + { + start = OffsetDitta; + last = OffsetDitta; + } + else + last = _ditte.items() - 1; + + for (int i = start; i <= last; i++) + { + TString CoFiDic(20); + TToken_string riga(_ditte[i]); + riga.separator('|'); + const long codditta = atol(riga.get(0)); + const TipoDitta tipo = (TipoDitta)riga.get_int(1); + +// I gruppi dich-estinti hanno totali comuni +// Si presume che nell'array vengano messi nell'ordine dich-estinti + if (tipo == normale || tipo == dichiarante) + _form->azzera_totali(); + + if (tipo == estinto) + CoFiDic = riga.get(6); + +// Dice al form che tipo di ditta si stampa + _form->set_tipo_ditta(tipo); + +// Numera i fogli a partire da 1 per ogni ditta normale e da 1 e di seguito negli estinti +// per i sogg. dichiaranti + if (tipo == normale || tipo == dichiarante) + _form->set_num_foglio(1); + +// Se la ditta e' estinta dice al form il cod.fis. del dichiarante + if (tipo == estinto) + _form->set_cofi_dic(CoFiDic); + +// Dice al form che e' l'ultima ditta + if (i == last) + _form->set_last_ditta(TRUE); + + _form->print(codditta); + } + printer().close(); + return ok; +} +*/ +/* +void TStampaQuadroG1::fill_estinti(const long CodDic) +{ + int NumFisiche=0, NumNoFisiche=0; + TString CodFiDic(20); + +// Salva il cod.fis. del dichiarante + CodFiDic = cod_fis(CodDic); + + _ditte.add(CodDic, dichiarante); + const int index_dich = _ditte.curr_index(); + int index = index_dich; + +// Leggo gli estinti + TLocalisamfile base(LF_BASE); + base.setkey(2); + base.zero(); + base.put(BSE_CODDIC, (long)CodDic); + TRectype dep(base.curr()); + + for (base.read(); !base.eof(); base.next()) + { + if (base.curr() > dep) + break; + +// Scarta il record del quadro I "globale" del dichiarante + const char tipoqua = base.get(BSE_TIPOQUA)[0]; + if (tipoqua == COD_QUA_I_DIC) + continue; + + const long DittaEstinta = base.get_long(BSE_CODDITTA); + + _ditte.add(DittaEstinta, estinto, 0L, 0L, FALSE, FALSE, CodFiDic); + + index++; + } +} +*/ +/* +void TStampaQuadroG1::print() +{ + int NumFisiche=0, NumNoFisiche=0; + + _ditte.destroy(); // Pulisce l'array delle ditte + + if (_singola_ditta) + { + if (sogg_estinto(_codditta)) + { + warning_box("La ditta %ld e' un soggetto estinto", _codditta); + return; + } + +// Se e' un dichiarante va a prendere tutti i suoi estinti. + bool dich = sogg_dic(_codditta); + if (dich) + fill_estinti(_codditta); + else + _ditte.add(_codditta, normale); + } + else // stampa ditte selezionate + { +// Costruisco un'array delle ditte da stampare. +// Tolgo i sogg. estinti, e dopo un dichiarante metto tutti i suoi estinti. + long codditta_prec = get_firm_770(); + long codditta = 0L; + int i=0; + while ((codditta = _cnf->get_long(DITTE_SEL, _section, i++)) != 0L) + { + if (sogg_estinto(codditta)) + continue; + +// Se e' un dichiarante va a prendere tutti i suoi estinti. + bool dich = sogg_dic(codditta); + if (dich) + fill_estinti(codditta); + else + _ditte.add(codditta, normale); + + } + set_firm_770(codditta_prec); + } + print_quadro(_quadro, -1); +} +*/ + + +/////////////////////////////////////////////////////////////////////////////////////////// +// +// Quadro F +// +/////////////////////////////////////////////////////////////////////////////////////////// + +HIDDEN const int QF_FORMLEN = 72; +HIDDEN const int QF_PAGINE = 2; +HIDDEN const int HEADER_SECONDA_F = 7; + +class TQuadroF : public TDicForm +{ + private: + real pa3t, pa4t, pa5t, pa6t, pa7t; // totali prosp. A + real pb3t, pb4t, pc3t, pc4t, pd3t, pd4t; // totali prosp, B, C e D + int _ptrA, _ptrB, _ptrC, _ptrD; // puntatori alle righe dei prospetti + long _items; + int stampa_prospetto_A(TPrinter& pr); + int stampa_prospetto_B(TPrinter& pr); + int stampa_prospetto_C(TPrinter& pr); + int stampa_prospetto_D(TPrinter& pr); + TRecord_array* _prosp_a, *_prosp_b, *_prosp_c, *_prosp_d; + void azzera_contatori(); + void aggiorna_totali(char tipoprosp, TRectype& r); + void stampa_totali(char tipoprosp, TPrinter& pr); + + public: + virtual bool print(const long codditta, const long numfis=0L, const long numnofis=0L); + virtual void inc_curr_page(); + virtual void next_page(TPrinter& pr); + + TQuadroF(const char* form, const char* quadro) : TDicForm(form, quadro) {} + virtual ~TQuadroF() {} +}; + +void TQuadroF::azzera_contatori() +{ + pa3t = pa4t = pa5t = pa6t = pa7t = ZERO; + pb3t=pb4t=pc3t=pc4t=pd3t=pd4t = ZERO; // totali prosp, B, C e D + _ptrA = _ptrB = _ptrC = _ptrD = 1; +} + + +void TQuadroF::stampa_totali(char tipoprosp, TPrinter& pr) +{ + const int PA3_TOT = 104; + const int PB3_TOT = 54; + TPrint_section& sez = tipoprosp == 'A' ? section('H', 1) : section('B', 1); + const int rr = sez.height()-1; + int i = PA3_TOT, riga_tot=0; + + switch (tipoprosp) + { + case 'A': + { + riga_tot = 46; + TForm_item& c = sez.find_field(i++); + TString c3(pa3t.string()); + c.set(c3); + c = sez.find_field(i++); + TString c4(pa4t.string()); + c.set(c4); + c = sez.find_field(i++); + TString c5(pa5t.string()); + c.set(c5); + c = sez.find_field(i++); + TString c6(pa6t.string()); + c.set(c6); + c = sez.find_field(i++); + TString c7(pa7t.string()); + c.set(c7); + break; + } + case 'B': + { + i = PB3_TOT; + riga_tot = 14; + TForm_item& c = sez.find_field(i++); + TString c3(pb3t.string()); + c.set(c3); + c = sez.find_field(i); + TString c4(pb4t.string()); + c.set(c4); + break; + } + case 'C': + { + i = PB3_TOT+2; + riga_tot = 20; + TForm_item& c = sez.find_field(i++); + TString c3(pc3t.string()); + c.set(c3); + c = sez.find_field(i); + TString c4(pc4t.string()); + c.set(c4); + break; + } + case 'D': + { + i = PB3_TOT+4; + riga_tot = 26; + TForm_item& c = sez.find_field(i++); + TString d3(pd3t.string()); + c.set(d3); + c = sez.find_field(i); + TString d4(pd4t.string()); + c.set(d4); + break; + } + default: + break; + } + + sez.update(); + pr.print(sez.row(riga_tot)); + _RigaCorr++; + + if (usa_progind()) + progind()->addstatus(1); +} + +void TQuadroF::aggiorna_totali(char tipoprosp, TRectype& r) +{ + real sogg,rope,acc,ecc,sal; + + switch (tipoprosp) + { + case 'A': + sogg = r.get_real(QUF_SOGRIT); + rope = r.get_real(QUF_ROPE); + acc = r.get_real(QUF_ACCONTI); + ecc = r.get_real(QUF_VERSECC); + sal = r.get_real(QUF_VERSALDO); + pa3t += sogg; + pa4t += rope; + pa5t += acc; + pa6t += ecc; + pa7t += sal; + break; + case 'B': + sogg = r.get_real(QUF_SOGRIT); + rope = r.get_real(QUF_ROPE); + pb3t += sogg; + pb4t += rope; + break; + case 'C': + sogg = r.get_real(QUF_SOGRIT); + rope = r.get_real(QUF_ROPE); + pc3t += sogg; + pc4t += rope; + break; + case 'D': + sogg = r.get_real(QUF_SOGRIT); + rope = r.get_real(QUF_ROPE); + pd3t += sogg; + pd4t += rope; + break; + default: + break; + } +} + +void TQuadroF::next_page(TPrinter& pr) +{ + PagineQD PagCorr = curr_page(); +// if (PagCorr = SECONDA) stampa_totali(pr); + fill_page(pr, -1); // formfeed "adattato" + inc_curr_page(); +} + +void TQuadroF::inc_curr_page() +{ + if (_PaginaCorrente == PRIMA) + _PaginaCorrente = SECONDA; + else + if (_PaginaCorrente == SECONDA) + _PaginaCorrente = PRIMA; +} + + +bool TQuadroF::print(const long codditta, const long numfis, const long numnofis) +{ + bool EndPrint=FALSE, End_A=FALSE, End_B=FALSE, End_C=FALSE, End_D=FALSE; + int residui_A=0, residui_B=0, residui_C=0, residui_D=0; + TCursor* cur = cursor(); + TPrinter& pr = printer(); + + if (!InitPrint(codditta)) + return FALSE; + + azzera_contatori(); + + TLocalisamfile& rf = cur->file(LF_RIGHEF); + TRectype dep(rf.curr()); + dep.zero(); + dep.put("CODDITTA", _codditta); + dep.put("TIPOPRO", "A"); + _prosp_a = new TRecord_array(dep, "NPROG"); + dep.put("TIPOPRO", "B"); + _prosp_b = new TRecord_array(dep, "NPROG"); + dep.put("TIPOPRO", "C"); + _prosp_c = new TRecord_array(dep, "NPROG"); + dep.put("TIPOPRO", "D"); + _prosp_d = new TRecord_array(dep, "NPROG"); + + pr.formlen(QG1_FORMLEN); + + while (!EndPrint) + { + for (int pagina=1; pagina <= QF_PAGINE; pagina++, next_page(pr)) + { + if (_PaginaCorrente == PRIMA) + { + if (_modulaser) ClearFlagModulaser(); + + if (End_A) + break; + + (*cur) = 0L; + + residui_A = stampa_prospetto_A(pr); + + End_A = (residui_A == 0); + if (End_A) stampa_totali('A', pr); + EndPrint = End_A && End_B && End_C && End_D; + } + + if (_PaginaCorrente == SECONDA) + { +// Reset del flag di pagina con posiz. + if (_posiziona && _PaginaPosizionamento) _PaginaPosizionamento = FALSE; + + if (End_B && End_C && End_D) + break; + + fill_page(pr, HEADER_SECONDA_F); + + residui_B = stampa_prospetto_B(pr); + End_B = (residui_B == 0); + if (End_B) stampa_totali('B', pr); + + residui_C = stampa_prospetto_C(pr); + End_C = (residui_C == 0); + if (End_C) stampa_totali('C', pr); + + residui_D = stampa_prospetto_D(pr); + End_D = (residui_D == 0); + if (End_D) stampa_totali('D', pr); + + EndPrint = End_A && End_B && End_C && End_D; + } + } // for pagina.. + } // EndPrint() + close_print(); + return TRUE; +} + +const int F_DESC_CAUS = 50; +const int RIGHE_PROSP = 3; + +int TQuadroF::stampa_prospetto_C(TPrinter& pr) +{ + TPrint_section& sez = section('B', 1); + const int rr = sez.height()-1; + + const int START_C = 16; + const int last_c = _prosp_c->last_row(); + for (int i=0; i < RIGHE_PROSP; _ptrC++, i++) + { + if (_ptrC > last_c) + break; + + TRectype& r = _prosp_c->row(_ptrC, TRUE); + aggiorna_totali('C', r); + TString16 codcau(r.get(QUF_CODCAUS)); + TString descr_cau(get_desc_cau(codcau)); + TString16 aliq (r.get(QUF_ALIQUOTA)); + TString sogg (r.get(QUF_SOGRIT)); + TString rope (r.get(QUF_ROPE)); + + const int fc0 = START_C + _ptrC - 1; + TString16 nord; nord << _ptrC; + TForm_item& c0 = sez.find_field(fc0); + c0.set(nord); + + const int fc1 = fc0 + RIGHE_PROSP; + TForm_item& c1 = sez.find_field(fc1); + c1.set(descr_cau); + + const int fc2 = fc1 + RIGHE_PROSP; + TForm_item& c2 = sez.find_field(fc2); + c2.set(aliq); + + const int fc3 = fc2 + RIGHE_PROSP; + TForm_item& c3 = sez.find_field(fc3); + c3.set(sogg); + + const int fc4 = fc3 + RIGHE_PROSP; + TForm_item& c4 = sez.find_field(fc4); + c4.set(rope); + } + const int res_C = last_c - _ptrC; + return res_C < 0 ? 0 : res_C; +} + +int TQuadroF::stampa_prospetto_D(TPrinter& pr) +{ + TPrint_section& sez = section('B', 1); + const int rr = sez.height()-1; + + const int START_D = 31; + const int last_d = _prosp_d->last_row(); + for (int i=0; i < RIGHE_PROSP; _ptrD++, i++) + { + if (_ptrD > last_d) + break; + + TRectype& r = _prosp_d->row(_ptrD, TRUE); + aggiorna_totali('D', r); + TString16 codcau(r.get(QUF_CODCAUS)); + TString descr_cau(get_desc_cau(codcau)); + TString16 aliq (r.get(QUF_ALIQUOTA)); + TString sogg (r.get(QUF_SOGRIT)); + TString rope (r.get(QUF_ROPE)); + + const int fc0 = START_D + _ptrD - 1; + TString16 nord; nord << _ptrD; + TForm_item& c0 = sez.find_field(fc0); + c0.set(nord); + + const int fc1 = fc0 + RIGHE_PROSP; + TForm_item& c1 = sez.find_field(fc1); + c1.set(descr_cau); + + const int fc2 = fc1 + RIGHE_PROSP; + TForm_item& c2 = sez.find_field(fc2); + c2.set(aliq); + + const int fc3 = fc2 + RIGHE_PROSP; + TForm_item& c3 = sez.find_field(fc3); + c3.set(sogg); + + const int fc4 = fc3 + RIGHE_PROSP; + TForm_item& c4 = sez.find_field(fc4); + c4.set(rope); + } + + sez.update(); + for (i=0; i < rr; i++) + { + pr.print(sez.row(i)); + _RigaCorr++; + } + + if (usa_progind()) + progind()->addstatus(1); + + const int res_D = last_d - _ptrD; + return res_D < 0 ? 0 : res_D; +} + +int TQuadroF::stampa_prospetto_B(TPrinter& pr) +{ + TPrint_section& sez = section('B', 1); + const int rr = sez.height()-1; + + const int START_B = 1; + + const int last_b = _prosp_b->last_row(); + for (int i=0; i < RIGHE_PROSP; _ptrB++, i++) + { + if (_ptrB > last_b) + break; + + TRectype& r = _prosp_b->row(_ptrB, TRUE); + aggiorna_totali('B', r); + TString dep(50); + dep = r.get(QUF_CODCAUS); + TString descr_cau(get_desc_cau(dep)); + TString16 aliq (r.get(QUF_ALIQUOTA)); + TString sogg (r.get(QUF_SOGRIT)); + TString rope (r.get(QUF_ROPE)); + + const int fc0 = START_B + _ptrB - 1; + TString16 nord; nord << _ptrB; + TForm_item& c0 = sez.find_field(fc0); + c0.set(nord); + + const int fc1 = fc0 + RIGHE_PROSP; + TForm_item& c1 = sez.find_field(fc1); + c1.set(descr_cau); + + const int fc2 = fc1 + RIGHE_PROSP; + TForm_item& c2 = sez.find_field(fc2); + c2.set(aliq); + + const int fc3 = fc2 + RIGHE_PROSP; + TForm_item& c3 = sez.find_field(fc3); + c3.set(sogg); + + const int fc4 = fc3 + RIGHE_PROSP; + TForm_item& c4 = sez.find_field(fc4); + c4.set(rope); + } + +// TBI setta totali e descr.causale F + TString16 fcau(cursor()->curr(LF_QUAF).get(QUF_FCAUS)); + TString descr_cau(get_desc_cau(fcau)); + TForm_item& fd = sez.find_field(F_DESC_CAUS); + fd.set(descr_cau); + + const int res_B = last_b - _ptrB; + return res_B < 0 ? 0 : res_B; +} + +int TQuadroF::stampa_prospetto_A(TPrinter& pr) +{ + TPrint_section& head = section('H', 1); + const word rr = head.height()-1; + TPrintrow& head_row = head.row(rr-1); + +// Setta il cod.fis. del dichiarante se necessario + if (tipo_ditta() == estinto) + { + TForm_item& cfd = head.find_field(H_COFI_DIC); + cfd.set(_cofi_dic); + } + + TCursor* cur = cursor(); + + const int START_PROSP = 56; + const int RIGHE_PROSP = 6; + const int COL_PROSP = 8; + const int last_a = _prosp_a->last_row(); + + for (int i=0; i < RIGHE_PROSP ; _ptrA++, i++) + { + if (_ptrA > last_a) + break; + TRectype& r = _prosp_a->row(_ptrA, TRUE); + aggiorna_totali('A', r); + TString16 codcau(r.get(QUF_CODCAUS)); + TString descr_cau(get_desc_cau(codcau)); + TString16 aliq (r.get(QUF_ALIQUOTA)); + TString sogg (r.get(QUF_SOGRIT)); + TString rope (r.get(QUF_ROPE)); + TString acc(r.get(QUF_ACCONTI)); + TString ecc(r.get(QUF_VERSECC)); + TString sal(r.get(QUF_VERSALDO)); + + const int fc0 = START_PROSP + _ptrA - 1; + TString16 nord; nord << _ptrA; + TForm_item& c0 = head.find_field(fc0); + c0.set(nord); + + const int fc1 = fc0 + RIGHE_PROSP; + TForm_item& c1 = head.find_field(fc1); + c1.set(descr_cau); + + const int fc2 = fc1 + RIGHE_PROSP; + TForm_item& c2 = head.find_field(fc2); + c2.set(aliq); + + const int fc3 = fc2 + RIGHE_PROSP; + TForm_item& c3 = head.find_field(fc3); + c3.set(sogg); + + const int fc4 = fc3 + RIGHE_PROSP; + TForm_item& c4 = head.find_field(fc4); + c4.set(rope); + + const int fc5 = fc4 + RIGHE_PROSP; + TForm_item& c5 = head.find_field(fc5); + c5.set(acc); + + const int fc6 = fc5 + RIGHE_PROSP; + TForm_item& c6 = head.find_field(fc6); + c6.set(ecc); + + const int fc7 = fc6 + RIGHE_PROSP; + TForm_item& c7 = head.find_field(fc7); + c7.set(sal); + } + +// Righe da saltare nelle prime pag. dei moduli successivi al primo (che' son +// senza le righe del posizionamento...) + int HEADER_PRIMA_NOPOS = 3; + head.update(); + for (word j = 0; j <= rr; j++) + { + if (j==0) + { + if (_modulaser) + { + TPrintrow& r = head.row(j); + if (!_GiaMessoStartDoc) + put_modulaser(r, STARTDOC); + put_modulaser(r, STARTDITTA); + put_modulaser(r, STARTPAGE, 1); + pr.print(r); + _RigaCorr++; + r.reset(); + HEADER_PRIMA_NOPOS--; + } + if (!PaginaPosizionamento()) + fill_page(pr, HEADER_PRIMA_NOPOS); + } + else + { + pr.print(head.row(j)); + _RigaCorr++; + } + } + const int res = last_a - _ptrA; + return res < 0 ? 0 : res; +} + +///////////////////////////////////////////////////////////////////////////////////////////// +// +// STAMPA QUADRO F +// +///////////////////////////////////////////////////////////////////////////////////////////// + +class TStampaQuadroF : public TStampaQuadro +{ + private: + TQuadroF* _form; + TRelation* _rel; + TCursor* _cur; + + protected: + virtual bool conta_tipi_per() const { return FALSE; } + virtual TDicForm* get_form() const { return _form; } + + virtual TCursor* get_cursor() const { return _cur; } + + virtual bool user_create(); + virtual bool user_destroy(); + + public: + TStampaQuadroF(char livel) : TStampaQuadro("F", livel) { } +}; + +bool TStampaQuadroF::user_create() +{ + _form = new TQuadroF("77QF", quadro()); + + _rel = new TRelation(LF_QUAF); + _rel->add(LF_RIGHEF, "CODDITTA=CODDITTA"); + _rel->add(LF_NDITTE, "CODDITTA=CODDITTA", 1, LF_QUAF); + _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 116); + _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 118); + _rel->add(LF_COMUNI, "COM=COMNASC", 1, LF_ANAGFIS, 113); + _rel->add(LF_COMUNI, "COM=COMRF(COMRES)", 1, LF_ANAG, 213); + _cur = new TCursor(_rel); + + return TRUE; +} + +bool TStampaQuadroF::user_destroy() +{ + delete _cur; + delete _rel; + delete _form; + return TRUE; +} + +/////////////////////////////////////////////////////////////////////////////////////////// +// +// Quadro H +// +/////////////////////////////////////////////////////////////////////////////////////////// + +HIDDEN const int QH_FORMLEN = 72; +HIDDEN const int QH_PAGINE = 2; +HIDDEN const int HEADER_SECONDA_H = 7; + +class TQuadroH : public TDicForm +{ + private: + real _rC2t, _rC3t; // totali colonna 2 e 3 + long _items; + void azzera_contatori(); +// void aggiorna_totali(char tipoprosp, TRectype& r); +// void stampa_totali(char tipoprosp, TPrinter& pr); + + public: + virtual bool print(const long codditta, const long numfis=0L, const long numnofis=0L); + virtual void inc_curr_page(); + virtual void next_page(TPrinter& pr); + + TQuadroH(const char* form, const char* quadro) : TDicForm(form, quadro) {} + virtual ~TQuadroH() {} +}; + + +void TQuadroH::azzera_contatori() +{ + _rC2t = _rC3t = ZERO; +} + +/////////////////////////////////////////////////////////// +// Quadro 770/A +/////////////////////////////////////////////////////////// + +class TQuadroA : public TDicForm +{ + enum { QA_PAGINE = 4, QA_FORMLEN = 72 }; + +protected: + virtual void next_page(TPrinter& pr); + virtual bool print(const long codditta, const long NumFis, const long NumNoFis); + + virtual void azzera_totali(); + virtual void aggiorna_totali(const char) { } + + void stampa_totali(TPrinter& pr); + +public: + + TQuadroA(const char* form, const char* quadro) : TDicForm(form, quadro) {} + virtual ~TQuadroA() {} +}; + +void TQuadroA::azzera_totali() +{ + TPrint_section& totali = section('F', odd_page); + totali.reset(); +} + +void TQuadroA::stampa_totali(TPrinter& pr) +{ + TPrint_section& totali = section('F', odd_page); + totali.update(); + for (int i = 0; i < totali.items(); i++) + { + pr.print(totali.row(i)); + _RigaCorr++; + } +} + +void TQuadroA::next_page(TPrinter& pr) +{ + fill_page(pr, -1); // formfeed "adattato" + inc_curr_page(); +} + +bool TQuadroA::print(const long codditta, const long NumFis, const long NumNoFis) +{ + TCursor& cur = *cursor(); + TPrinter& pr = printer(); + + if (!InitPrint(codditta)) + return FALSE; + + pr.formlen(QA_FORMLEN); + + int percipienti = 0; // Numero di percipienti stampati in questa pagina + bool stampato_ultimo = FALSE; + bool stampati_totali = FALSE; + + for (cur = 0; stampati_totali == FALSE; stampato_ultimo ? 0 : ++cur) + { + const bool stampero_ultimo = stampato_ultimo == FALSE && cur.pos() == cur.items()-1; + + switch(_PaginaCorrente) + { + case PRIMA: + if (_modulaser) + ClearFlagModulaser(); + + if (!stampato_ultimo) + { + if (cur.pos() == 0) + stampa_testata(pr); + jump_to_line(pr, 45); + set_body(pr, 'F'); + stampato_ultimo = stampero_ultimo; + } + + next_page(pr); + percipienti = 0; + break; + case SECONDA: + case TERZA: + if (!stampato_ultimo) + { + if (percipienti == 0) + jump_to_line(pr, 4); + set_body(pr, 'F'); + stampato_ultimo = stampero_ultimo; + } + percipienti++; + if (percipienti == 3) + { + next_page(pr); + percipienti = 0; + } + break; + case QUARTA: + if (!stampato_ultimo) + { + if (percipienti == 0) + jump_to_line(pr, 4); + + set_body(pr, 'F'); + stampato_ultimo = stampero_ultimo; + } + + percipienti++; + + if (percipienti == 2) + { + if (stampato_ultimo) + { + jump_to_line(pr, 39); + stampa_totali(pr); + stampati_totali = TRUE; + } + next_page(pr); + percipienti = 0; + } + break; + default: + CHECK(0, "Invalid Quadro A page"); + break; + } + } + + return TRUE; +} + + +class TStampaQuadroA : public TStampaQuadro +{ +private: + TQuadroA* _form; + TRelation* _rel; + TSorted_cursor* _cur; + +protected: + virtual bool user_create(); + virtual bool user_destroy(); + + virtual bool conta_tipi_per() const { return FALSE; } + virtual TDicForm* get_form() const { return _form; } + virtual TCursor* get_cursor() const { return _cur; } + +public: + TStampaQuadroA(char livel) : TStampaQuadro("A", livel) { } +}; + +bool TStampaQuadroA::user_create() +{ + _form = new TQuadroA("77QA", quadro()); + + _rel = new TRelation(LF_QUAA); + _rel->add(LF_NDITTE, "CODDITTA=CODDITTA", 1, LF_QUAA); + _rel->add(LF_ANAG, "TIPOA=TIPOA|CODANAGR=CODANAGR", 1, LF_NDITTE, 106); + _rel->add(LF_ANAGFIS, "CODANAGR=CODANAGR", 1, LF_ANAG, 108); + _rel->add(LF_COMUNI, "COM==COMNASC", 1, LF_ANAGFIS, 113); + _rel->add(LF_COMUNI, "COM==COMRF(COMRES)", 1, LF_ANAG, 213); + _rel->add(LF_DIPEND, "CODDITTA=CODDITTA|CODDIP=CODDIP"); + _rel->add(LF_COMUNI, "COM==COMNASC", 1, LF_DIPEND, 313); + _rel->add(LF_COMUNI, "COM==COMRES", 1, LF_DIPEND, 413); + _rel->add("%CAF", "CODTAB=CODCAAF", 1, LF_QUAA, 104); + + TString sortkey(80); + sortkey.format("CODDITTA|%d->COGNOME|%d->NOME|CODDIP", LF_DIPEND, LF_DIPEND); + _cur = new TSorted_cursor(_rel, sortkey); + + return TRUE; +} + +bool TStampaQuadroA::user_destroy() +{ + delete _cur; + delete _rel; + delete _form; + + return TRUE; +} + +///////////////////////////////////////////////////////////////////////////////// +// +// MAIN +// +// Uso: +// 772mod -4 [QUADRO] [ LIVELLO {S|D} ] +// +///////////////////////////////////////////////////////////////////////////////// + +int stampa_quadro(int argc, char* argv[]) +{ + if (argc >= 4) + { + const TFixed_string quadro(argv[2]); + const char livello = *argv[3]; + + TStampaQuadro* app = NULL; + + if ( quadro == "C" || quadro == "D" || quadro == "D1" || quadro == "E" || quadro == "E1" ) + { + app = new TStampaQuadroD(quadro, livello); + } + else if (quadro == "A") + { + app = new TStampaQuadroA(livello); + } + else if (quadro == "F") + { + app = new TStampaQuadroF(livello); + } + else if (quadro == "G") + { + app = new TStampaQuadroG(livello); + } + else if (quadro == "G1") + { + app = new TStampaQuadroG1(livello); + } +/* + else if (quadro == "H") + { + app = new TStampaQuadroH app(quadro, livello); + } +*/ + if (app != NULL) + app->run(argc, argv, app->taitol()); + } + return 0; +} + +