diff --git a/ce/ce3200.cpp b/ce/ce3200.cpp index 7c2f7a9cc..5305b5267 100755 --- a/ce/ce3200.cpp +++ b/ce/ce3200.cpp @@ -9,8 +9,10 @@ #include "ce3200a.h" #include "ce3200.h" #include "celib.h" +#include "ammce.h" #include "cespi.h" #include "movce.h" +#include "salce.h" //-----FORM--------------------------------------------------------------------------------------// @@ -90,6 +92,7 @@ class TStampa_storico : public TSkeleton_application { TStampastorico_mask * _mask; TForm_schedacesp * _form; + TEsercizi_contabili _esc; bool _ammvenduti; protected: @@ -97,10 +100,14 @@ protected: virtual bool destroy(); virtual void main_loop(); - void print_header( const int tipo ); + void print_header(const int tipo); void print_footer(); - void print_percespite( const int tipo ); - void stampa_rigauno( bool errore ); + void print_percespite(const int tipo); + + const TRectype& cespite() const { return _form->cursor()->curr(LF_CESPI);} + bool stampa_primo_saldo(const int tipo); + bool stampa_ammortamenti(const int tipo, const int esc_ini, const int esc_fin); + bool stampa_rigatre(const TRectype& recammce); public: TStampa_storico() {} @@ -157,21 +164,33 @@ void TStampa_storico::print_footer() } -void TStampa_storico::stampa_rigauno( bool errore) +bool TStampa_storico::stampa_primo_saldo(const int tipo) { - const TRectype& recsalce = _form->cursor()->curr(LF_SALCE); - TDate datasaldo = _form->cursor()->curr(-102).get_date("D0"); - int numele = recsalce.get_int("NUMELE"); + TLocalisamfile salce(LF_SALCE); + const TString16 id = cespite().get(CESPI_IDCESPITE); + salce.put(SALCE_IDCESPITE, id); + int err = salce.read(_isgteq); + //se non lo trova + if (err != NOERR || salce.get(SALCE_IDCESPITE) != id) + return false; + + //gli serve il saldo primordiale di tipo 1 del cespite;e' il primo che trova,quindi non ci va.. + //..nient'altro + const TRectype& recsalce = salce.curr(); + const int esercizio = recsalce.get_int(SALCE_CODES); + const TDate& dataini = _esc[esercizio].inizio(); + const int numele = recsalce.get_int("NUMELE"); TPrint_section& section1 = _form->get_rigauno(); //preparazione stampa riga dettaglio 1 - TDate dtcomp = _form->cursor()->curr(LF_CESPI).get_date("DTCOMP"); + const TDate dtcomp = cespite().get_date("DTCOMP"); section1.reset(); - - if ((datasaldo >= dtcomp && numele > 0) || (datasaldo == dtcomp && numele == 0)) //datasaldo >= data acquisto + bool devo_stampare = false; + + if ((dataini >= dtcomp && numele > 0) || (dataini == dtcomp && numele == 0)) //datasaldo >= data acquisto { - section1.find_field(FF_DATAUNO).set(datasaldo); + section1.find_field(FF_DATAUNO).set(dataini); section1.find_field(FF_DESCRUNO).set(TR("Ripresa saldi")); - section1.find_field(FF_NUMELEUNO).set(_form->cursor()->curr(LF_SALCE).get("NUMELE")); + section1.find_field(FF_NUMELEUNO).set(recsalce.get(SALCE_NUMELE)); real sum = recsalce.get_real("CSTO"); sum -= recsalce.get_real("VNONAMM"); sum += recsalce.get_real("RIV75"); @@ -180,45 +199,171 @@ void TStampa_storico::stampa_rigauno( bool errore) sum += recsalce.get_real("RIV91"); sum += recsalce.get_real("RIVGF"); section1.find_field(FF_VALOREUNO).set(sum.string()); - sum = 0; - TRectype& recammce = _form->cursor()->curr(LF_AMMCE); + devo_stampare = sum != ZERO; + + TLocalisamfile ammce(LF_AMMCE); + ammce.put(AMMCE_IDCESPITE, id); + ammce.put(AMMCE_CODES, esercizio); + ammce.put(AMMCE_TPSALDO, 1); + ammce.put(AMMCE_TPAMM, tipo); + if (ammce.read() != NOERR) + ammce.zero(); + const TRectype& recammce = ammce.curr(); sum = recammce.get_real("QNOR"); sum += recammce.get_real("QANT"); sum += recammce.get_real("QACC"); section1.find_field(FF_FONDIUNO).set(sum.string()); + devo_stampare |= sum != ZERO; } - else // se datasaldo < data acquisto sono sbagliate le date + else // se dataini < data acquisto sono sbagliate le date { section1.find_field(FF_DESCRUNO).set(TR("Data acquisto incongruente")); - errore = TRUE; + devo_stampare = true; } - - section1.update(); - for (word i = 0; i < section1.height(); i++) // stampa le righe tipo 1 (solo nel caso che dtmov != dtcomp) - printer().print(section1.row(i)); // in caso contrario passa semplicemente alle righe tipo 2 + + if (devo_stampare) + { + section1.update(); + for (word i = 0; i < section1.height(); i++) // stampa le righe tipo 1 (solo nel caso che dtmov != dtcomp) + printer().print(section1.row(i)); // in caso contrario passa semplicemente alle righe tipo 2 + } + return devo_stampare; } -void TStampa_storico::print_percespite( const int tipo) +bool TStampa_storico::stampa_rigatre(const TRectype& recammce) +{ + const TDate dataelim = cespite().get_date(CESPI_DTALIEN); + + const int esercizio = recammce.get_int(AMMCE_CODES); + const TDate& datafinees = _esc[esercizio].fine(); + + bool scrivo_unarigatre = false; + + if (dataelim.empty() || dataelim > datafinees) // qui ci va l'if con la condizione di scrittura riga3 + { + real aliqnort = recammce.get_real("PNOR"); + real aliqantt = recammce.get_real("PANT"); + real aliqacct = recammce.get_real("PACC"); + + real qnort = recammce.get_real("QNOR"); + real qantt = recammce.get_real("QANT"); + real qacct = recammce.get_real("QACC"); + + TPrint_section& section3 = _form->get_rigatre(); + section3.find_field(FF_TPNOR).set(aliqnort.string()); + section3.find_field(FF_TPANT).set(aliqantt.string()); + section3.find_field(FF_TPACC).set(aliqacct.string()); + section3.find_field(FF_TQNOR).set(qnort.string()); + section3.find_field(FF_TQANT).set(qantt.string()); + section3.find_field(FF_TQACC).set(qacct.string()); + //controllo sulla scrittura di piú righe causa diverse aliquote + int r = 1; + if (aliqnort != ZERO || qnort != ZERO) + { + section3.find_field(FF_TPNOR).show(); + section3.find_field(FF_TPNOR).y() = r; + section3.find_field(FF_TALINOR).show(); + section3.find_field(FF_TALINOR).y() = r; + section3.find_field(FF_TQNOR).show(); + section3.find_field(FF_TQNOR).y() = r; + r++; + scrivo_unarigatre = true; + } + else + { + section3.find_field(FF_TPNOR).hide(); + section3.find_field(FF_TALINOR).hide(); + section3.find_field(FF_TQNOR).hide(); + } + if (aliqantt != ZERO || qantt != ZERO) + { + section3.find_field(FF_TPANT).show(); + section3.find_field(FF_TPANT).y() = r; + section3.find_field(FF_TALIANT).show(); + section3.find_field(FF_TALIANT).y() = r; + section3.find_field(FF_TQANT).show(); + section3.find_field(FF_TQANT).y() = r; + r++; + scrivo_unarigatre = true; + } + else + { + section3.find_field(FF_TPANT).hide(); + section3.find_field(FF_TALIANT).hide(); + section3.find_field(FF_TQANT).hide(); + } + if (aliqacct != ZERO || qacct != ZERO) + { + section3.find_field(FF_TPACC).show(); + section3.find_field(FF_TPACC).y() = r; + section3.find_field(FF_TALIACC).show(); + section3.find_field(FF_TALIACC).y() = r; + section3.find_field(FF_TQACC).show(); + section3.find_field(FF_TQACC).y() = r; + r++; + scrivo_unarigatre = true; + } + else + { + section3.find_field(FF_TPACC).hide(); + section3.find_field(FF_TALIACC).hide(); + section3.find_field(FF_TQACC).hide(); + } + + if (scrivo_unarigatre) //stampa la riga3 solo se ha trovato almeno una cosa da stampare + { + _form->find_field('B', last_page, FF_DATASIT).set(datafinees.string()); + + section3.update(); + for (int i = 0; i < r ; i++) // stampa riga tipo 3 + printer().print(section3.row(i)); + } + } + + return scrivo_unarigatre; +} + + +bool TStampa_storico::stampa_ammortamenti(const int tipo, int esc_ini, int esc_fin) +{ + bool ho_stampato_qualcosa = false; + if (esc_ini <= 0) + esc_ini = _esc.first(); + if (esc_fin <=0) + esc_fin = _esc.last(); + + TLocalisamfile ammce(LF_AMMCE); + TRectype& recammce = ammce.curr(); + //attenzione!NON va preso l'ultimo esercizio x' servono ammortamenti finali + for (int e = esc_ini; e != esc_fin; e = _esc.next(e)) + { + recammce.put(AMMCE_IDCESPITE, cespite().get(CESPI_IDCESPITE)); + recammce.put(AMMCE_CODES, e); + recammce.put(AMMCE_TPSALDO, 2); + recammce.put(AMMCE_TPAMM, tipo); + if (ammce.read() == NOERR) + ho_stampato_qualcosa |= stampa_rigatre(recammce); + } + return ho_stampato_qualcosa; +} + + +//parte principale del programma +void TStampa_storico::print_percespite(const int tipo) { bool ho_stampato_qualcosa = FALSE; print_header(tipo); // stampa l'intestazione;tipo si riferisce al tipo di situazione da stampare print_footer(); //stampa data e pagenumber - const int esercizio = _mask->get_int(F_ESERCIZIO); - + const int esercizio_finale = _mask->get_int(F_ESERCIZIO); const long pos = _form->cursor()->pos(); //memorizza posizione cursore - - TRectype& recammce = _form->cursor()->curr(LF_AMMCE); //scelta dei tipi ammort. su AMMCE - bool continua = _form->cursor()->is_first_match(LF_AMMCE); - while (recammce.get_int("TPAMM") != tipo && continua) - continua = _form->cursor()->next_match(LF_AMMCE); TRectype& recammmv = _form->cursor()->curr(LF_AMMMV); //scelta dei tipi ammort. su AMMMV - continua = _form->cursor()->is_first_match(LF_AMMMV); + bool continua = _form->cursor()->is_first_match(LF_AMMMV); while (recammmv.get_int("TPAMM") != tipo && continua) - continua = _form->cursor()->next_match(LF_AMMMV); + continua = _form->cursor()->next_match(LF_AMMMV); TPrint_section& sectot = _form->get_rigatot(); //resetta il totale elementi,valore,fondo amm. @@ -229,25 +374,34 @@ void TStampa_storico::print_percespite( const int tipo) TRectype& recmovce = _form->cursor()->curr(LF_MOVCE); // riga dettaglio 2 TRelation& rel = *_form->relation(); - - if (rel.is_first_match(LF_MOVCE)) - { - bool errore = FALSE; //variabile che indica se le date del cespite sono congruenti per essere stampate - - TDate dtmov = _form->cursor()->curr(-105).get_date("DTMOV"); - TDate dtcomp = _form->cursor()->curr(LF_CESPI).get_date("DTCOMP"); - - TEsercizi_contabili esc; - const TDate& inies = esc[esercizio].inizio(); - + //per prima cosa stampa il saldo iniziale primordiale + ho_stampato_qualcosa = stampa_primo_saldo(tipo); - if (!errore) do //se non c'é incongruenza di date procede alla stampa righe 2 - { - - TDate datamov = rel.curr(LF_MOVCE).get_date("DTMOV"); - if (datamov >= inies) break; + TEsercizi_contabili esc; + int esercizio_stampato = 0; + + //poi stampa le righe dei movimenti (stampa riga 2) + if (rel.is_first_match(LF_MOVCE)) + { + const TDate& inies = esc[esercizio_finale].inizio(); + do + { + const TDate datamov = rel.curr(LF_MOVCE).get_date("DTMOV"); + if (datamov >= inies) + break; - bool ammven = FALSE; + const int esc_mov = esc.date2esc(datamov); + //se e' cambiato l'esercizio nelle datemov (i mov sono ordinati per data dalla relazione.. + //..sul form) -> deve stampare gli ammortamenti (righe tre) prima di procedere con i.. + //..movimenti del nuovo esercizio!!!! + if (esc_mov != esercizio_stampato) + { + ho_stampato_qualcosa |= stampa_ammortamenti(tipo, esercizio_stampato, esc_mov); + esercizio_stampato = esc_mov; + } + + + bool ammven = false; if (_ammvenduti) // caso in cui la ditta ha "ammort. su venduti" = SI { // controlla su %tmc se il movimento é una vendita TString16 tipomov = recmovce.get("CODMOV"); @@ -393,123 +547,26 @@ void TStampa_storico::print_percespite( const int tipo) section2.update(); for (int i = 0; i < r; i++) // stampa le righe con tutti i movimenti (righe tipo 2) printer().print(section2.row(i)); - ho_stampato_qualcosa = TRUE; + ho_stampato_qualcosa = true; } } while (rel.next_match(LF_MOVCE)); - - if (!errore) - { - TDate dataelim = _form->cursor()->curr(LF_CESPI).get_date("DTALIEN"); - TDate datafinees = _form->cursor()->curr(-102).get_date("D1"); - if (dataelim.empty() || dataelim > datafinees) // qui ci va l'if con la condizione di scrittura riga3 - { - TRectype& recsalce = _form->cursor()->curr(LF_SALCE); - bool continua = _form->cursor()->is_first_match(LF_SALCE);; - while (recsalce.get_int("TPSALDO") != 2 && continua) - continua = _form->cursor()->next_match(LF_SALCE); - - real aliqnort = recammce.get_real("PNOR"); - real aliqantt = recammce.get_real("PANT"); - real aliqacct = recammce.get_real("PACC"); - - real qnort = recammce.get_real("QNOR"); - real qantt = recammce.get_real("QANT"); - real qacct = recammce.get_real("QACC"); - - bool scrivo_unarigatre = FALSE; - - TPrint_section& section3 = _form->get_rigatre(); - //controllo sulla scrittura di piú righe causa diverse aliquote - int r = 1; - if (aliqnort != ZERO || qnort != ZERO) - { - section3.find_field(FF_TPNOR).show(); - section3.find_field(FF_TPNOR).y() = r; - section3.find_field(FF_TALINOR).show(); - section3.find_field(FF_TALINOR).y() = r; - section3.find_field(FF_TQNOR).show(); - section3.find_field(FF_TQNOR).y() = r; - r++; - scrivo_unarigatre = TRUE; - } - else - { - section3.find_field(FF_TPNOR).hide(); - section3.find_field(FF_TALINOR).hide(); - section3.find_field(FF_TQNOR).hide(); - } - if (aliqantt != ZERO || qantt != ZERO) - { - section3.find_field(FF_TPANT).show(); - section3.find_field(FF_TPANT).y() = r; - section3.find_field(FF_TALIANT).show(); - section3.find_field(FF_TALIANT).y() = r; - section3.find_field(FF_TQANT).show(); - section3.find_field(FF_TQANT).y() = r; - r++; - scrivo_unarigatre = TRUE; - } - else - { - section3.find_field(FF_TPANT).hide(); - section3.find_field(FF_TALIANT).hide(); - section3.find_field(FF_TQANT).hide(); - } - if (aliqacct != ZERO || qacct != ZERO) - { - section3.find_field(FF_TPACC).show(); - section3.find_field(FF_TPACC).y() = r; - section3.find_field(FF_TALIACC).show(); - section3.find_field(FF_TALIACC).y() = r; - section3.find_field(FF_TQACC).show(); - section3.find_field(FF_TQACC).y() = r; - r++; - scrivo_unarigatre = TRUE; - } - else - { - section3.find_field(FF_TPACC).hide(); - section3.find_field(FF_TALIACC).hide(); - section3.find_field(FF_TQACC).hide(); - } - - if (scrivo_unarigatre) //stampa la riga3 solo se ha trovato almeno una cosa da stampare - { - TDate inies(_mask->get(F_INIZIO_ES)); - --inies; - _form->find_field('B', last_page, FF_DATASIT).set(inies.string()); - - section3.update(); - for (int i = 0; i < r ; i++) // stampa riga tipo 3 - printer().print(section3.row(i)); - ho_stampato_qualcosa = TRUE; - } - - } - - if (ho_stampato_qualcosa) //controlla se ha stampato qualcosa (riga1, righe2, riga3).. - { - sectot.update(); - for (word i = 0; i < sectot.height(); i++) //..e in caso affermativo stampa riga totale - printer().print(sectot.row(i)); - } - - } + } - - } - else //é l'else di if(rel.is_first_match(LF_MOVCE)): - { //serve nel caso il cespite non abbia movimenti ma solo saldi - bool errore = FALSE; - stampa_rigauno( errore ); - ho_stampato_qualcosa = TRUE; - } - + //ammortamenti conclusivi (da stampare anche in assenza di movimenti) + ho_stampato_qualcosa |= stampa_ammortamenti(tipo, esercizio_stampato, esercizio_finale); + + //controlla se ha stampato qualcosa (riga1, righe2, riga3).. if (ho_stampato_qualcosa) - printer().formfeed(); //salta una pagina alla fine della scheda + { + sectot.update(); + for (word i = 0; i < sectot.height(); i++) //..e in caso affermativo stampa riga totale + printer().print(sectot.row(i)); + printer().formfeed(); //salta una pagina alla fine della scheda + } + *_form->cursor() = pos; //riposiziona il cursore } @@ -578,6 +635,6 @@ void TStampa_storico::main_loop() int ce3200(int argc, char* argv[]) { TStampa_storico a; - a.run(argc,argv,TR("Stampa schede cespiti")); + a.run(argc,argv,TR("Scheda storica cespite")); return 0; } \ No newline at end of file diff --git a/ce/ce3200a.frm b/ce/ce3200a.frm index 4e0821b8a..5fe2e3af5 100755 --- a/ce/ce3200a.frm +++ b/ce/ce3200a.frm @@ -4,16 +4,13 @@ USE LF_CESPI -JOIN LF_SALCE INTO IDCESPITE==IDCESPITE -JOIN LF_MOVCE KEY 2 ALIAS 105 INTO IDCESPITE==IDCESPITE +SORT LF_MOVCE BY IDCESPITE DTMOV IDMOV + JOIN TO LF_CESPI ALIAS 105 INTO IDCESPITE==IDCESPITE JOIN LF_MOVAM TO LF_MOVCE INTO IDCESPITE==IDCESPITE IDMOV==IDMOV JOIN LF_AMMMV TO LF_MOVCE ALIAS 107 INTO IDCESPITE==IDCESPITE IDMOV==IDMOV -JOIN LF_AMMCE TO LF_SALCE INTO IDCESPITE==IDCESPITE CODES==CODES TPSALDO==TPSALDO - JOIN %CAC ALIAS 101 INTO CODTAB[1,2]==CODCGRA|CODTAB[3,6]==CODSPA|CODTAB[7,8]==CODCAT -JOIN ESC TO LF_SALCE ALIAS 102 INTO CODTAB==CODES JOIN %TMC TO LF_MOVCE ALIAS 103 INTO CODTAB==CODMOV END @@ -599,7 +596,6 @@ VALUTA FF_TQNOR 15 BEGIN KEY "fondo ammortamento normale" PROMPT 66 1 "" - FIELD LF_AMMCE->QNOR MESSAGE ADD,F0->FF_TOTAMMO END @@ -607,7 +603,6 @@ VALUTA FF_TQANT 15 BEGIN KEY "fondo ammortamento anticipato" PROMPT 66 2 "" - FIELD LF_AMMCE->QANT MESSAGE ADD,F0->FF_TOTAMMO END @@ -615,7 +610,6 @@ VALUTA FF_TQACC 15 BEGIN KEY "fondo ammortamento accelerato" PROMPT 66 3 "" - FIELD LF_AMMCE->QACC MESSAGE ADD,F0->FF_TOTAMMO END @@ -624,8 +618,6 @@ BEGIN KEY "aliquota normale" PROMPT 82 1 "" PICTURE "##@,@@@" - FIELD LF_AMMCE->PNOR - END NUMERO FF_TPANT 7 @@ -633,7 +625,6 @@ BEGIN KEY "aliquota anticipata" PROMPT 82 2 "" PICTURE "##@,@@@" - FIELD LF_AMMCE->PANT END NUMERO FF_TPACC 7 @@ -641,7 +632,6 @@ BEGIN KEY "aliquota accelerata" PROMPT 82 3 "" PICTURE "##@,@@@" - FIELD LF_AMMCE->PACC END STRINGA FF_TALINOR