diff --git a/cg/cg2100.cpp b/cg/cg2100.cpp index b7098a317..c63f37f6a 100755 --- a/cg/cg2100.cpp +++ b/cg/cg2100.cpp @@ -564,7 +564,7 @@ void TPrimanota_application::mask2rel(const TMask& m) const long numreg = m.get_long(F_NUMREG); const TDate datareg(m.get(F_DATAREG)); - const int annoes = (int) m.get_long(F_ANNOES); + const int annoes = m.get_int(F_ANNOES); _saldi.set_movprovv(m.get_bool(F_PROVVISORIO)); _saldi.set_movap(_causale.apertura()); @@ -686,24 +686,6 @@ void TPrimanota_application::mask2rel(const TMask& m) cur++; } - - // Resetta il flag di calcolato sulla liquidazione IVA del mese di registrazione - // TBI: occorre resettarlo anche su PLM (B0), attivita' per attivita' - // Chiave di PLM: Anno (1-4), Cod. Att. (5-9), Mese (10-11) - // - const TDate d(m.get(F_DATAREG)); - TString16 chiave; chiave << d.year() << d.month(); - TTable lim("LIM"); - lim.put("CODTAB", chiave); - if (lim.read() == NOERR) - { - const bool calcolato = lim.get_bool("B0"); - if (calcolato) - { - lim.put("B0", FALSE); - lim.rewrite(); - } - } } diff --git a/cg/cg2100b.uml b/cg/cg2100b.uml index 39c3f5979..fda152f86 100755 --- a/cg/cg2100b.uml +++ b/cg/cg2100b.uml @@ -136,36 +136,6 @@ BEGIN COPY OUTPUT F_CODCAUS END -STRING F_VALUTA 3 -BEGIN - PROMPT 1 9 "Valuta " - FIELD CODVAL - FLAGS "U" - GROUP 3 - USE %VAL - INPUT CODTAB F_VALUTA - DISPLAY "Codice" CODTAB - DISPLAY "Nome@50" S0 - DISPLAY "Cambio corrente" R0 - OUTPUT F_VALUTA CODTAB - OUTPUT F_CAMBIO R0 -END - -NUMBER F_CAMBIO 10 -BEGIN - PROMPT 16 9 "Cambio " - FIELD CAMBIO - FLAGS "RU" - GROUP 3 - PICTURE ".3" -END - -BOOLEAN F_VISVAL -BEGIN - PROMPT 42 9 "Visualizza importi in valuta" - GROUP 3 -END - SPREADSHEET F_SHEETCG BEGIN PROMPT 0 9 "" diff --git a/cg/cg2100c.uml b/cg/cg2100c.uml index c24c65e97..e19839cef 100755 --- a/cg/cg2100c.uml +++ b/cg/cg2100c.uml @@ -349,6 +349,7 @@ BEGIN ITEM "LU|Lussemburgo" ITEM "NL|Olanda" ITEM "PT|Portogallo" + GROUP 1 END BUTTON F_OCCASEDIT 18 @@ -368,12 +369,14 @@ STRING F_CODPAG 4 BEGIN PROMPT 60 11 "Pagamento " FIELD CODPAG + FLAGS "U" USE %CPG INPUT CODTAB F_CODPAG DISPLAY "Codice" CODTAB DISPLAY "Descrizione@50" S0 OUTPUT F_CODPAG CODTAB CHECKTYPE NORMAL + WARNING "Codice pagamento assente" END NUMBER F_TOTALE 15 diff --git a/cg/cg2101.cpp b/cg/cg2101.cpp index 6d91164e4..4482a3299 100755 --- a/cg/cg2101.cpp +++ b/cg/cg2101.cpp @@ -167,6 +167,45 @@ int TMovimentoPN::registra(bool re, bool force) cancella(ri, i+1, _oldiva); _oldiva = iva_items(); + // Resetta il flag di calcolato sulla liquidazione IVA del mese di registrazione + // Chiave di LIM: Anno (1-4), Mese (5-6) + + const TDate d(m.get("DATAREG")); + TString16 chiave; chiave << d.year() << d.month(); + TTable lim("LIM"); + lim.put("CODTAB", chiave); + if (lim.read() == NOERR) + { + const bool calcolato = lim.get_bool("B0"); + if (calcolato) + { + lim.put("B0", FALSE); + lim.rewrite(); + } + } + + const TString16 cod(m.get("REG")); + const int anno = m.get_int("ANNOIVA"); + TRegistro reg(cod, anno); + const int att = reg.attivita_mista() ? 2 : 1; + + // Chiave di PLM: Anno (1-4), Cod. Att. (5-9), Tipo att. (10-10), Mese (11-12) + TTable plm("PLM"); + for (int a = 1; a <= att; a++) + { + chiave.cut(0); + chiave << d.year() << reg.attivita() << a << d.month(); + plm.put("CODTAB", chiave); + if (plm.read() == NOERR) + { + const bool calcolato = plm.get_bool("B0"); + if (calcolato) + { + plm.put("B0", FALSE); + plm.rewrite(); + } + } + } return err; } diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index 066bdfd0a..0c02a18ed 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -21,7 +21,7 @@ inline TPrimanota_application& app() // Certified 100% TipoIVA TPrimanota_application::cau2IVA(const char* causale, int annoiva) { - TipoIVA i = iva_errata; + TipoIVA i = nessuna_iva; if (*causale > ' ') { @@ -29,8 +29,11 @@ TipoIVA TPrimanota_application::cau2IVA(const char* causale, int annoiva) if (c.read(causale, annoiva)) i = c.iva(); else + { error_box("Causale errata: '%s'", causale); - } else i = nessuna_iva; + i = iva_errata; + } + } return i; } @@ -338,6 +341,15 @@ void TPrimanota_application::disable_cgs_cells(int n, char tipo) } +void TPrimanota_application::reset_cgs_row(int n) +{ + TSheet_field& cg = cgs(); + cg.row(cg.items()); // Append a new line + cg.destroy(n); // Remove line n +} + + + int TPrimanota_application::set_cgs_row(int n, const TImporto& imp, TBill& conto, const char* desc, char tipo) @@ -535,7 +547,7 @@ bool TPrimanota_application::descr_handler(TMask_field& f, KEY k) if (k == K_ENTER && f.get().empty()) { if (f.mask().get(F_CODCAUS).empty()) - return error_box("Descrizione documento necessaria in mancanza della causale"); + return f.error_box("La descrizione del documento e' necessaria in mancanza della causale"); } return TRUE; } @@ -695,12 +707,12 @@ bool TPrimanota_application::iva_notify(int r, KEY k) const char tipod = detraibile(row) ? 'D' : 'N'; oldposiva = type2pos(tipod); - TString80 d; + if (oldposiva < 0 && oldiva != ZERO) { const int r = tipod == 'D' ? 3 : 4; TBill c; cau.bill(r, c); - d = cau.desc_agg(r); + const TString80 d(cau.desc_agg(r)); oldposiva = app().set_cgs_row(-1, app().real2imp(ZERO, 'I'), c, d, tipod); } @@ -708,7 +720,7 @@ bool TPrimanota_application::iva_notify(int r, KEY k) oldpos = bill2pos(oldconto, 'I'); if (oldpos < 0 && oldconto.ok()) { - d = cau.desc_agg(2); + const TString80 d(cau.desc_agg(2)); oldpos = app().set_cgs_row(-1, app().real2imp(ZERO, 'I'), oldconto, d, 'I'); } } @@ -720,13 +732,16 @@ bool TPrimanota_application::iva_notify(int r, KEY k) } if (k == K_ENTER) { + int delimp = -1, deliva = -1; if (oldpos >= 0) // Il conto esisteva anche prima { const TImporto& imp = app().sub_cgs_imp(oldpos, oldimp); + if (imp.valore().is_zero) delimp = oldpos; } if (oldposiva >= 0) // Il conto IVA esisteva anche prima { const TImporto& imp = app().sub_cgs_imp(oldposiva, oldiva); + if (imp.valore().is_zero) deliva = oldposiva; } // Aggiorna conto sulla riga contabile @@ -745,6 +760,8 @@ bool TPrimanota_application::iva_notify(int r, KEY k) if (newpos < 0) { + if (delimp >= 0) app().reset_cgs_row(delimp); + const TImporto val(app().real2imp(imp, 'I')); if (val.valore() != ZERO) { @@ -758,7 +775,7 @@ bool TPrimanota_application::iva_notify(int r, KEY k) val = app().add_cgs_imp(newpos, val); if (val.valore().is_zero()) { - app().cgs().destroy(newpos); + app().reset_cgs_row(newpos); newpos = -1; } } @@ -788,7 +805,7 @@ bool TPrimanota_application::iva_notify(int r, KEY k) val = app().add_cgs_imp(newposiva, val); if (val.valore().is_zero()) { - app().cgs().destroy(newposiva); + app().reset_cgs_row(newposiva); newposiva = -1; } } @@ -907,8 +924,8 @@ bool TPrimanota_application::caus_modify_handler(TMask_field& f, KEY key) if (!ok) return FALSE; const int ann = f.mask().get_int(F_ANNOIVA); - const char* cau = f.get(); - TCausale c(cau, ann); + const TString16 cau(f.get()); + const TCausale c(cau, ann); if (!c.ok()) return FALSE; @@ -959,9 +976,9 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) "ultima stampa del libro giornale dell'esercizio %d", gio.last_reg().string(), ae); if (dr < gio.last_reg()) - warning_box("La data dell'operazione e' antecedente al %s,\n" - "ultima registrazione sul libro giornale dell'esercizio %d", - gio.last_reg().string(), ae); + f.warning_box("La data dell'operazione e' antecedente al %s,\n" + "ultima registrazione sul libro giornale dell'esercizio %d", + gio.last_reg().string(), ae); if (m.query_mode()) { @@ -980,7 +997,6 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) const TString16 codreg(reg.name()); if (codreg.not_empty()) { - if (reg.year() != dr.year()) { const bool ok = reg.read(codreg, dr.year()); @@ -988,13 +1004,13 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) } if (dr < reg.last_print()) - return error_box("La data dell'operazione e' antecedente al %s,\n" - "ultima stampa del registro '%s' dell'anno %d", - reg.last_print().string(), (const char*)codreg, dr.year()); + return f.error_box("La data dell'operazione e' antecedente al %s,\n" + "ultima stampa del registro '%s' dell'anno %d", + reg.last_print().string(), (const char*)codreg, dr.year()); if (dr < reg.last_reg()) - warning_box("La data dell'operazione e' antecedente al %s,\n" - "ultima registrazione sul registro '%s' dell'anno %d", - reg.last_reg().string(), (const char*)codreg, dr.year()); + f.warning_box("La data dell'operazione e' antecedente al %s,\n" + "ultima registrazione sul registro '%s' dell'anno %d", + reg.last_reg().string(), (const char*)codreg, dr.year()); } } } @@ -1089,15 +1105,7 @@ bool TPrimanota_application::occas_code_handler(TMask_field& f, KEY key) f.mask().send_key(K_TAB, O_COMUNENAS); } } - } else - if (key == K_ENTER) - { - const TFixed_string codice(f.get()); - if (codice.not_empty()) - app().mask().set(app().iva() == iva_vendite ? F_PIVACLIENTE : F_PIVAFORNITORE, codice); - else - return f.error_box("Il codice e' obbligatorio"); - } + } return TRUE; } @@ -1123,16 +1131,19 @@ void TPrimanota_application::add_cgs_tot(TMask& m) long codice = m.get_long(tipo == 'C' ? F_CLIENTE : F_FORNITORE); // Se l'utente non ha ancora specificato un conto lo prendo dalla prima riga della causale + TBill bill; _causale.bill(1, bill); if (conto == 0) { - TBill bill; _causale.bill(1, bill); gruppo = bill.gruppo(); m.set(F_GRUPPOCLIFO, gruppo); conto = bill.conto(); m.set(F_CONTOCLIFO, conto); codice = bill.sottoconto(); } if (tipo == 'C' && causale().corrispettivi()) + { + codice = bill.sottoconto(); tipo = ' '; + } TBill c(gruppo, conto, codice, tipo); real tot(m.get(F_TOTALE)); @@ -1320,6 +1331,7 @@ bool TPrimanota_application::solaiva_handler(TMask_field& f, KEY key) } app().fill_sheet(m); app().cgs().force_update(); + m.set_focus(); } } return TRUE; diff --git a/cg/cg2102.h b/cg/cg2102.h index c57770df8..a524a1c2e 100755 --- a/cg/cg2102.h +++ b/cg/cg2102.h @@ -154,6 +154,7 @@ protected: void set_ivas_row(int n, const char* codiva, TBill& tc, const char* desc); int set_cgs_row(int n, const TImporto& importo, TBill& conto, const char* desc, char tipo); + void reset_cgs_row(int n); void disable_cgs_cells(int n, char tipo); void add_cgs_tot(TMask& m); void add_cgs_rit(bool fisc); diff --git a/cg/cg2103.cpp b/cg/cg2103.cpp index d732b826f..0b0c415b4 100755 --- a/cg/cg2103.cpp +++ b/cg/cg2103.cpp @@ -75,6 +75,16 @@ int TRegistro::year() const } +static TString16 n; +const TString& TRegistro::name() const +{ + if (ok()) n = _rec.get("CODTAB").mid(4); + else n = ""; + return n; +} + + + TRegistro& TRegistro::operator =(const TRegistro& r) { diff --git a/cg/cg2103.h b/cg/cg2103.h index c562f9aac..f20fde0a6 100755 --- a/cg/cg2103.h +++ b/cg/cg2103.h @@ -37,7 +37,7 @@ public: int tipo() const; TipoIVA iva() const; bool corrispettivi() const; - const TString& name() const { return _rec.get("CODTAB").mid(4); } + const TString& name() const; int year() const; TDate last_reg() const { return _rec.get_date("D2"); } TDate last_print() const { return _rec.get_date("D3"); } diff --git a/cg/cg4301.cpp b/cg/cg4301.cpp index 33f6ab2a0..25021a8df 100755 --- a/cg/cg4301.cpp +++ b/cg/cg4301.cpp @@ -1,840 +1,840 @@ -// ------------------------------------------------------------ -// Calcolo liquidazioni -// Part 2: calcolo -// fv 21-1-94 -// ------------------------------------------------------------ - -#include "cg4300.h" - -char buf[256]; - -// -------------------- QUI comincia l'avventura -------------------------- - -bool CG4300_App::recalc_all() -{ - long l; - - long firm = TApplication::get_firm(); - - _prind = new TProgind(_selected.ones()*2, - " Calcolo liquidazioni... " - "\n Preparazione archivi ", - TRUE,TRUE,45); - - for (l = 0l, _nditte->first(); !_nditte->eof(); l++, _nditte->next()) - { - if (_prind->iscancelled()) - break; - - if (_selected[l]) - { - TApplication::set_firm(_nditte->curr().get_long("CODDITTA")); - _prind->addstatus(1); - if (_recalc == ever) - { - for (int m = 1; m < _month; m++) - if (is_month_ok(m)) - update_firm(m); - } - update_firm(_month); - } - } - if (!_prind->iscancelled()) _prind->addstatus(1); - TApplication::set_firm(firm); - delete _prind; - - return TRUE; -} - -bool CG4300_App::update_firm(int month, bool recalc) -{ - // Se recalc e' TRUE considera la necessita' di ricalcolare e le - // opzioni utente. Se FALSE se ne impipa dell'utente e ricalcola - // se necessario (serve nelle chiamate ricorsive) - // Ritorna FALSE soltanto se il ricalcolo era necessario e non e' - // stato effettuato per scelta dello stronzo commercialista. - - look_lim(month, TRUE); - - // gia' ricalcolata definitivamente? - bool ok = _lim->get_bool("B1"); - if (ok && !_comp_acconto) return TRUE; - - // ricalcolo normale - ok = _lim->get_bool("B0"); - if (ok && !recalc) return TRUE; - bool calc = (_recalc == ever || (_recalc == one && month == _month)); - if (!calc && _recalc != never) calc = !ok; - bool gheravergot = FALSE; - - TToken_string atts; - TToken_string cattivs; - - _nditte->save_status(); - if (_nditte->is_first_match(LF_ATTIV)) - { - do - { - TString codatt = _nditte->curr(LF_ATTIV).get("CODATT"); - TString desatt = _nditte->curr(LF_ATTIV).get("DESCR"); - - // attivita' mista: ce ne sono in realta' due - _mixed = _nditte->curr().get_bool("FLIVA11Q"); - - sprintf (buf,"Calcolo liquidazioni (%d)...\n%s: %s", - month, - (const char*)_nditte_r->get("RAGSOC"), - (const char*)desatt); - _prind->set_text(buf); - _vend_arr.destroy(); - - cattivs = ""; - - for (int tipoatt = 1; tipoatt <= (_mixed ? 2 : 1); tipoatt++) - { - TString cattiv(codatt); - - cattiv << tipoatt; - look_pla(cattiv, TRUE); - - _p8 = _pla->get_real("R5"); - _p8b = _pla->get_real("R6"); - _p9 = _pla->get_real("R7"); - _prorata = _pla->get_real("R8"); - _isplafond = !(_p8.is_zero() && _p8b.is_zero() && - _p9.is_zero()); - _isviaggio = _nditte->curr(LF_ATTIV).get_bool("REG74TER"); - _isagricolo = _nditte->curr(LF_ATTIV).get_bool("REGAGR"); - _isbenzinaro = _nditte->curr(LF_ATTIV).get_bool("ART74/4"); - _isservizio = _nditte->curr(LF_ATTIV).get("TIPOATT") == "S"; - _freqviva = look_lia() ? _lia->get("S7") : _nditte->curr().get("FREQVIVA"); - bool mens = _freqviva == "M"; - _isannual = (_month == 12 && !mens && !_isbenzinaro) || - (_month == 13 && (mens || _isbenzinaro)); - _isriepilogo = _month == 13; - _isvent = _pla->get_bool("B0"); - - if ((month != 13 || _isannual) && (calc || !recalc)) - if (!update_att(month, cattiv)) - describe_error("Attivita' non ricalcolate: possibili errori", - codatt); - - - // vediamo se c'e' qualcosa da raccontare - gheravergot = _isannual || _isriepilogo; - if (!gheravergot) - { - look_plm(month,cattiv); - gheravergot = !_plm->get_real("R0").is_zero() || - !_plm->get_real("R1").is_zero(); - } - - if (month == _month && gheravergot) - describe_att(month,cattiv); - atts.add(cattiv); - cattivs.add(cattiv); - } // for tipoatt - - // se attivita' mista stampa riepilogo (solo se - // la seconda attivita'aveva movimenti) - - if (_mixed && month == _month && gheravergot) - describe_att(month,cattivs); - } - while (_nditte->next_match(LF_ATTIV)); - - // occorre poterla chiamare altre volte con mesi diversi - _nditte->restore_status(); - - // aggiorna le liquidazioni mensili - if ((_month != 13 || _isannual) && (calc || !recalc)) - write_liq (month, atts); - - // rimborso infraannuale - _DescrItem* rimb_d = NULL; - if (month == _month && is_trim(month)) - { - // unica nel suo genere, recalc_rimborso ritorna - // un bel descritem (NULL se non si rimborsa un cas) - // da passare a describe_liq - rimb_d = recalc_rimborso(month,atts); - } - - if (month == _month) - { - describe_firm(month); - describe_liq(_month, atts, rimb_d); - } - } - return ok || calc; -} - -bool CG4300_App::update_att(int month, const char* codatt, bool recalc) - // viene passato un codice attivita' con codatt+tipoatt - // vedi update_firm per il burdel dei calc e recalc - - // occhecasino. Se _comp_acconto e' TRUE, i movimenti considerati - // saranno solo quelli di dicembre per data <= 20/12; - // il ricalcolo e' FORZATO da _recalc messo a one -{ - look_plm(month, codatt, TRUE); - bool ok = _plm->get_bool("B0"); - if (ok && !recalc) return TRUE; - bool calc = _recalc == ever || (_recalc == one && month == _month) ; - - if (!calc && _recalc != never) calc = !ok; - if (_isannual && month == 13) month = 12; - - if (calc || !recalc) - { - zero_att(month,codatt); - recalc_att(month,codatt); - recalc_ventilation(month, codatt); - recalc_corrispettivi(month, codatt); - if (month == 12) recalc_annual(codatt); - } - return ok || calc; -} - -void CG4300_App::zero_att(int month, const char* codatt) -{ - for (_pim->first(); !_pim->eof(); _pim->next()) - { - int m = atoi(*_pim_mese); - TString att = (const char*)*_pim_codatt; - if (m == month && att == codatt) - { - _pim->put("R0",""); - _pim->put("R1",""); - _pim->put("R2",""); - _pim->rewrite(); - } - } - if (_isplafond) - zero_plafond(month,codatt); -} - -void CG4300_App::recalc_att(int month, const char* codatt) - // il codatt passato e' codice att + tipo att ( IN {1|2} ) -{ - real totintra = 0.0; - real nond19_imp = 0.0; - real nond19_iva = 0.0; - real ammort = 0.0; - real ammort_iva = 0.0; - real ammort_6 = 0.0; - real ammort_6_iva = 0.0; - real acq_riv = 0.0; - real acq_riv_iva = 0.0; - real leasing = 0.0; - real leasing_iva = 0.0; - real cess_amm = 0.0; - real cess_amm_iva = 0.0; - real acquisti = 0.0; - real acquisti_iva = 0.0; - real vendite = 0.0; - real vendite_iva = 0.0; - real esenti_b1 = 0.0; - real esenti_b2 = 0.0; - real esenti_b3 = 0.0; - real esenti_b14 = 0.0; - real corr_CEE = 0.0; - real corr_noCEE = 0.0; - real acq_CEE = 0.0; - real acq_noCEE = 0.0; - real corr_misCEE = 0.0; - real acq_misCEE = 0.0; - real acq_misnoCEE = 0.0; - real agr_ven = 0.0; - real agr_acq = 0.0; - real agr_conf = 0.0; - real agr_acc = 0.0; - real cred_cost = 0.0; - real for_rimb = 0.0; - - *_cur = 0; - long items = _cur->items(); - TString trueatt(codatt); - int tipatt = atoi(trueatt.sub(5)); - trueatt = trueatt.left(5); - - for (; _cur->pos() < items; ++(*_cur)) - { - TDate date(_mov_r->get("DATAREG")); - TString reg = _mov_r->get("REG"); - bool isreg = look_reg(_mov_r->get("REG")); - - /* - * check register present, rmoviva present and date OK - */ -#ifndef DBG - - if (!is_date_ok(date, month) || - !isreg || - _reg_r->get("S8") != trueatt || - !_cur->is_first_match(LF_RMOVIVA)) - continue; -#else - - bool dok = !is_date_ok(date, month); - bool sreg = !isreg; - bool rs8 = _reg_r->get("S8") != trueatt; - bool cmt = !_cur->is_first_match(LF_RMOVIVA); - - if (dok || sreg || rs8 || cmt) continue; - -#endif - - /* - * check date se si calcola l'acconto - */ - if (_month == 12 && _comp_acconto) - if (date.month() != 12 && date.day() > 20) - continue; - - bool corrisp = _reg_r->get_bool("B0"); - tiporeg tipomov = (tiporeg)_reg_r->get_long("I0"); - - do - { - look_iva(_rmoviva->get("CODIVA")); - - // TBI settare _isrimborso - - TString codiva = _iva->get("CODTAB"); - TString tipoiva = _iva->get("S1"); - int tipoes_v = (int)_iva->get_long("I3"); - int tipoes_a = (int)_iva->get_long("I4"); - int tipoagr = atoi(_iva->get("S4")); - int tipoag = atoi(_iva->get("S5")); - int tipopla = atoi(_iva->get("S3")); - int tipodet = atoi(_rmoviva->get("TIPODET")); - bool ivarimb = _iva->get_bool("B3"); - TString tipocr_s = _rmoviva->get("TIPOCR"); - int tipocr = atoi(tipocr_s); - real imponibile = _rmoviva->get_real("IMPONIBILE"); - real imposta = _rmoviva->get_real("IMPOSTA"); - bool intra = _rmoviva->get_bool("INTRA"); - int tipoatt = _rmoviva->get_int("TIPOATT"); - - if ( tipoatt != tipatt ) continue; - - // ***************************************** - // casi particolari - // ***************************************** - - // imposta acquisti intracomunitari - if (tipomov == acquisto && intra) - totintra += imposta; - - // acquisti non detraibili art. 19 - if (tipodet == 9) - { - nond19_imp += imponibile; - nond19_iva += imposta; - continue; - } - - // Altre cose di cui tener conto - if (tipomov == acquisto && (tipocr == 1 || tipocr == 5)) - // Acquisto beni per rivendita - { - acq_riv += imponibile; - acq_riv_iva += imposta; - } - else if (tipomov == acquisto && tipocr == 2) - // Acquisto beni ammortizzabili - { - ammort += imponibile; - ammort_iva += imposta; - } - else if (tipomov == acquisto && tipocr == 3) - // Acquisto beni ammortizzabili detr. 6% - { - ammort_6 += imponibile; - ammort_6_iva += imposta; - } - else if (tipomov == vendita && tipocr == 4) - // Vendite strum. art 17 (cess. amm.???) - { - cess_amm += imponibile; - cess_amm_iva += imposta; - } - else if (tipomov == acquisto && tipocr == 8) - // Acquisto beni strum. in leasing - { - leasing += imponibile; - leasing_iva += imposta; - } - - // operazioni per calcolo rimborso infracazzuale - if ((tipoiva == "ES" || tipoiva == "NI") && ivarimb) - { - for_rimb += imponibile; - } - - // operazioni esenti - if (tipoiva == "ES") - { - if (tipomov == vendita) - { - switch(tipoes_v) - { - case 1: esenti_b1 += imponibile; break; - case 2: esenti_b2 += imponibile; break; - case 3: esenti_b3 += imponibile; break; - } - } - else if (tipoes_a == 14) - esenti_b14 += imponibile; - } - - // plafond - if (_isplafond && tipomov == acquisto && - tipoiva == "NI" && tipopla != 0) - add_plafond(month, codatt, tipopla, imponibile, intra); - - // agenzie viaggio (CHECK imponibili etc.) - if (_isviaggio) - switch (tipoag) - { - case 1: - if (tipomov == acquisto) acq_CEE += imponibile; - else corr_CEE += imponibile; - break; - case 2: - if (tipomov == acquisto) acq_noCEE += imponibile; - else corr_noCEE += imponibile; - break; - case 3: corr_misCEE += imponibile; break; - case 4: acq_misCEE += imponibile; break; - case 5: acq_misnoCEE += imponibile; break; - } - - if (_isagricolo) - switch(tipoagr) - { - case 1: - if (tipomov == acquisto) agr_acq += imposta; - else agr_ven += imposta; - break; - case 2: if (tipomov == vendita) agr_conf += imposta; break; - case 3: if (tipomov == vendita) agr_acc += imposta; break; - } - - if (tipodet == 3 || // passaggi interni (solo ventilaz.) - tipodet == 1) // esenti art. 10 - continue; - - // ***************************************** - // Fine casi particolari - // Non che i casi normali siano tanto meglio - // ***************************************** - - if (tipomov == vendita) - { - // totale vendite - vendite += imponibile; - vendite_iva += imposta; - } - else - { - // totale acquisti - acquisti += imponibile; - acquisti_iva += imposta; - } - - /* - * Calcolo e aggiornamento - * cerca o crea progressivo IVA - */ - look_pim(month, codatt, reg, tipocr_s, codiva, TRUE); - - real imp = _pim_r->get_real("R0"); // imponibile - real ivp = _pim_r->get_real("R1"); // IVA su imp. - real lor = _pim_r->get_real("R2"); // lordo - - /* - * se corrispettivi da ventilare considera il lordo - */ - if (corrisp && tipoiva == "VE") - { - lor += imponibile; - _pim_r->put("I0",LORDO); - add_vendite(month, reg, imponibile); - } - else - if (corrisp) - { - lor += imponibile; - lor += imposta; - _pim_r->put("I0",LORDO); - add_corrisp(month, reg, imponibile); - } - else - { - // netti e imposta separata - imp += imponibile; - ivp += imposta; - _pim_r->put("I0",NETTO); - } - - _pim_r->put("R0",imp); - _pim_r->put("R1",ivp); - _pim_r->put("R2",lor); - _pim->rewrite(); - } - while (_cur->next_match(LF_RMOVIVA)); - } - - // calcolati tutti i movimenti e aggiornati i pim - // salviamo i totali antes que seja tarde - - real dd6 = ammort_6 * real(DETRAZIONE_6PERCENTO); - // calcola il lercio prorata - real prorata; - if (!_prorata.is_zero()) - prorata = acquisti_iva * (_prorata / 100.0); - - look_plm(month, codatt, TRUE); - - // ACHTUNG: l'iva sulle vendite e' calcolata sommando anche i - // corrispettivi; non tiene conto quindi delle imposte calcolate - // con la ventilazione (che vanno sottratte) ne' di quelle - // calcolate per le agenzie di viaggio (che sembra non vadano - // sottratte per il calcolo del volume di affari) - - _plm->put("R2", prorata); - - if (_isviaggio) - { - _plm->put("R5", corr_CEE); - _plm->put("R6", corr_noCEE); - _plm->put("R7", acq_CEE); - _plm->put("R8", acq_noCEE); - _plm->put("R9", corr_misCEE); - _plm->put("R10",acq_misCEE); - _plm->put("R11",acq_misnoCEE); - // calcola base da base e credito di costo - // indi abilmente trova il codiva e calcola l'iva del caso - real rip = acq_misCEE / (acq_misCEE + acq_misnoCEE); - real corr_imp = corr_misCEE * rip; corr_imp.round(ROUND_LIRA); - corr_imp += corr_CEE; - real cost_detr = acq_misCEE * acq_CEE; - real base_imp = corr_imp - (cost_detr - + credito_costo_prec(month, codatt)); - - real debito = 0.0; - - if (base_imp.sign() < 0) - { - // credito di costo - cred_cost = abs(base_imp); - // vendite_iva e' corretto cosi' visto che i corrispettivi - // sono registrati al lordo e l'imposta e' 0 - } - else - { - debito = base_imp * aliquota_agvia(); - vendite_iva += debito; - vendite_iva.round(ROUND_LIRA); - } - - // tutte ste minchie le mettiamo in lim anche se sarebbe - // assai piu' migliore metterle in plm - look_lim(month,TRUE); - _lim->put("R2", cred_cost); - _lim->put("R3", debito); - _lim->put("R4", rip); - _lim->rewrite(); - } - else if (_isagricolo) - { - _plm->put("R5", agr_ven); - _plm->put("R6", agr_conf); - _plm->put("R7", agr_acc); - _plm->put("R8", agr_acq); - // Il porco agricoltore spende poco e paga meno - acquisti_iva -= (agr_acq + leasing_iva + ammort_iva + ammort_6_iva); - vendite_iva -= (agr_ven + agr_conf + agr_acc); - } - _plm->put("R0", vendite_iva); - _plm->put("R1", acquisti_iva); - _plm->put("R3", dd6); - _plm->put("R12", _prorata); // per comodita' in stampa - _plm->put("B0", "X"); // calcolato (deve essere invalidato dalla - // primanota) - _plm->put("S1", for_rimb.string()); - _plm->rewrite(); - - // salva gli altri totali para no ponernos locos despues - look_ptm(month, codatt, TRUE); - _ptm->put("R0", totintra); - _ptm->put("R1", nond19_imp); - _ptm->put("R2", nond19_iva); - _ptm->put("R3", ammort); - _ptm->put("R4", ammort_iva); - _ptm->put("R5", ammort_6); - _ptm->put("R6", acq_riv); - _ptm->put("R7", acq_riv_iva); - _ptm->put("R8", leasing); - _ptm->put("R9", leasing_iva); - _ptm->put("R10", cess_amm); - _ptm->put("R11", cess_amm_iva); - _ptm->put("R12", ammort_6_iva); - _ptm->put("R13", esenti_b1); - _ptm->put("R14", esenti_b2); - _ptm->put("S0", esenti_b3.string()); - _ptm->put("S1", esenti_b14.string()); - _ptm->put("S2", acquisti.string()); - _ptm->put("S3", vendite.string()); - _ptm->rewrite(); -} - -void CG4300_App::write_liq(int month, const char* codatts) - // Calcolo liq. mensili e progr. liq. annuali -{ - TToken_string atts(codatts); - const char* tmpatt; - - real risultato = 0.0; - real vol_aff = 0.0; - real debito_prec = 0.0; - - while ((tmpatt = atts.get()) != NULL) - { - TString att(tmpatt); - { - look_plm(month, att); look_ptm(month,att); - // a debito: IVA vendite, debito precedente, Prorata - // a credito: IVA acquisti, ulteriori detrazioni 1 e 2 - risultato += (_plm->get_real("R0") - _plm->get_real("R1") + - _plm->get_real("R2") - _plm->get_real("R3") - - _plm->get_real("R4")); - - if (month == 12) - { - look_pla(att); - vol_aff += _pla->get_real("R0"); - // a credito anche il conguaglio prorata - risultato -= _pla->get_real("R10"); - } - } - } - // toglie credito precedente decrementato di ev. rimborsi chiesti - // e acconto versato e rettifiche a debito - risultato -= credito_prec(month); - - // vedi se c'era un debito precedente - if (!is_first_month(month)) - { - if (look_lim(previous_month(month))) - { - real r = _lim->get_real("R0"); - if (_lim->get_real("R5").sign() > 0) - r += _plm->get_real("R5"); - // non considera il rimborso in quanto se e' a debito - // non c'e' rimborso, e se e' rettificato pure - if (r.sign() > 0 && r < IVA_DA_RIPORTARE) - debito_prec += r; - } - } - risultato += debito_prec; - - look_lim(month,TRUE); - - _lim->put("R0",risultato); - _lim->put("B0","X"); - - if (_isfinal) - _lim->put("B1","X"); - _lim->rewrite(); - - if (month == 12) - { - if (!look_lia(TRUE)) - _lia->put("S7", (const char *) _freqviva); - _lia->put("R1", vol_aff); - _lia->rewrite(); - } -} - - -void CG4300_App::recalc_annual(const char* att) -{ - // TBI calcolo nuovo plafond - - // calcolo volume d'affari e altro - real es_b1 = 0.0; - real es_b2 = 0.0; - real es_b3 = 0.0; - real cess_amm = 0.0; - real vendite = 0.0; - real pro_pag = 0.0; - real acq_iva = 0.0; // per conguaglio prorata - real acq = 0.0; - real ivlac = 0.0; - real ivven = 0.0; - real ven_lrd = 0.0; - - TString aaa(att); - - for (int i = 1; i <= 12; i++) - { - if (is_month_ok(i)) - { - // ricalcola se necessario - if (i != 12 && !update_att(i,aaa,FALSE)) - describe_error("Attivita' non ricalcolata: " - "possibili errori",att); - look_ptm(i,aaa); look_plm(i,aaa); - real vend = _ptm->get("S3"); - ven_lrd += vend; // lordo vendite - // non entra l'IVA per calcolo volume affari - vendite += (vend - _plm->get_real("R0")); - real eb3 = _ptm->get("S0"); - es_b1 += _ptm->get_real("R13"); - es_b2 += _ptm->get_real("R14"); - es_b3 += eb3; - acq_iva += _plm->get_real("R1"); - cess_amm += _ptm->get_real("R10"); - pro_pag += _plm->get_real("R2"); - real aax = _ptm->get("S2"); - acq += aax - // rilevanti per aliquota media - _ptm->get_real("R3") - // toglie ammortizz. etc - _ptm->get_real("R5") - // non detraibili non ci sono - _ptm->get_real("R8"); - ivlac += _plm->get_real("R1") - // idem per IVE - _ptm->get_real("R4") - - _ptm->get_real("R9") - - _ptm->get_real("R12"); - ivven += _plm->get_real("R0"); - } - } - // calcolo prorata - real prorata = (es_b1/(vendite - cess_amm - es_b3)) * 100.0; - real conguaglio = 0.0; - prorata.round(ROUND_LIRA); - if (prorata != _prorata) - { - // calcolo conguaglio -- se positivo e' a debito - real topay = acq_iva * (prorata / 100.0); - conguaglio = topay - pro_pag; - } - // vediamo se la porca aliquota media acquisti e' superiore alla - // porca aliquota media vendite - - look_pla(aaa); - _pla->put("R0", vendite); - _pla->put("R1", es_b1); - _pla->put("R2", es_b2); - _pla->put("R3", es_b3); - _pla->put("R4", cess_amm); - _pla->put("R9", prorata); - _pla->put("R10", conguaglio); - _pla->put("R11", ivven); - _pla->put("R12", ivlac); - _pla->put("R13", ven_lrd); - _pla->put("R14", acq); - _pla->rewrite(); -} - -_DescrItem* CG4300_App::recalc_rimborso(int month, const char* codatts) -{ - bool rimborsami = FALSE; - _DescrItem* d = NULL; - TToken_string atts(codatts); - const char* tmpatt; - TString att; - - real iva_v, iva_a, imp_a, es_ni, vol_aff; - - while ((tmpatt = atts.get()) != NULL) - { - att = tmpatt; - look_plm(month,att); look_ptm(month,att); - - real tvol = _ptm->get("S3"); - vol_aff += tvol; - real esni = _plm->get("S1"); - es_ni += esni; - iva_a += _plm->get_real("R1"); - iva_v += _plm->get_real("R0"); - real aax = _ptm->get("S2"); - imp_a += aax - // rilevanti per aliquota media - _ptm->get_real("R3") - // toglie ammortizz. etc - _ptm->get_real("R5") - // non detraibili non ci sono - _ptm->get_real("R8"); - - if (_freqviva == "M") // sommiamo i due mesi precedenti - { - for (int m = month - 2; m < month; m++) - { - bool ok = look_plm(m,att); - if (!ok) - if (!update_att(m, att)) - describe_error("Attivita' non ricalcolate: possibili errori", - att); - - look_ptm(m,att); - - real tvol = _ptm->get("S3"); - vol_aff += tvol; - real esni = _plm->get("S1"); - es_ni += esni; - iva_a += _plm->get_real("R1"); - iva_v += _plm->get_real("R0"); - real aax = _ptm->get("S2"); - imp_a += aax - // rilevanti per aliquota media - _ptm->get_real("R3") - // toglie ammortizz. etc - _ptm->get_real("R5") - // non detraibili non ci sono - _ptm->get_real("R8"); - } - } - } - - // condizione 1 - if (!vol_aff.is_zero() && (es_ni/vol_aff) > MIN_PARTE_ESENTE) - { - rimborsami = TRUE; - d = new _DescrItem(RIMBORSO); - d->_f0 = TRUE; - d->_r0 = es_ni; - d->_r1 = vol_aff; - } - - real alv = vol_aff.is_zero() ? real(0.0) : (iva_v / vol_aff); - real ala = imp_a.is_zero() ? real(0.0) : (iva_a / imp_a); - - // condizione 2 - if (ala > alv) - { - rimborsami = TRUE; - if (d == NULL) d = new _DescrItem(RIMBORSO); - d->_f1 = TRUE; - d->_r2 = vol_aff; - d->_r3 = imp_a; - d->_r4 = iva_v; - d->_r5 = iva_a; - d->_r6 = alv * real(100.0); - d->_r7 = ala * real(100.0); - } - - if (rimborsami) - { - // il rimborso viene chiesto automaticamente - look_lim(month); - real cred = _lim->get_real("R0"); - if (cred.sign() < 0) - { - _lim->put("R1",abs(cred)); - _lim->rewrite(); - } - } - - return d; -} - - - - +// ------------------------------------------------------------ +// Calcolo liquidazioni +// Part 2: calcolo +// fv 21-1-94 +// ------------------------------------------------------------ + +#include "cg4300.h" + +char buf[256]; + +// -------------------- QUI comincia l'avventura -------------------------- + +bool CG4300_App::recalc_all() +{ + long l; + + long firm = TApplication::get_firm(); + + _prind = new TProgind(_selected.ones()*2, + " Calcolo liquidazioni... " + "\n Preparazione archivi ", + TRUE,TRUE,45); + + for (l = 0l, _nditte->first(); !_nditte->eof(); l++, _nditte->next()) + { + if (_prind->iscancelled()) + break; + + if (_selected[l]) + { + TApplication::set_firm(_nditte->curr().get_long("CODDITTA")); + _prind->addstatus(1); + if (_recalc == ever) + { + for (int m = 1; m < _month; m++) + if (is_month_ok(m)) + update_firm(m); + } + update_firm(_month); + } + } + if (!_prind->iscancelled()) _prind->addstatus(1); + TApplication::set_firm(firm); + delete _prind; + + return TRUE; +} + +bool CG4300_App::update_firm(int month, bool recalc) +{ + // Se recalc e' TRUE considera la necessita' di ricalcolare e le + // opzioni utente. Se FALSE se ne impipa dell'utente e ricalcola + // se necessario (serve nelle chiamate ricorsive) + // Ritorna FALSE soltanto se il ricalcolo era necessario e non e' + // stato effettuato per scelta dello stronzo commercialista. + + look_lim(month, TRUE); + + // gia' ricalcolata definitivamente? + bool ok = _lim->get_bool("B1"); + if (ok && !_comp_acconto) return TRUE; + + // ricalcolo normale + ok = _lim->get_bool("B0"); + if (ok && !recalc) return TRUE; + bool calc = (_recalc == ever || (_recalc == one && month == _month)); + if (!calc && _recalc != never) calc = !ok; + bool gheravergot = FALSE; + + TToken_string atts; + TToken_string cattivs; + + _nditte->save_status(); + if (_nditte->is_first_match(LF_ATTIV)) + { + do + { + TString codatt = _nditte->curr(LF_ATTIV).get("CODATT"); + TString desatt = _nditte->curr(LF_ATTIV).get("DESCR"); + + // attivita' mista: ce ne sono in realta' due + _mixed = _nditte->curr().get_bool("FLIVA11Q"); + + sprintf (buf,"Calcolo liquidazioni (%d)...\n%s: %s", + month, + (const char*)_nditte_r->get("RAGSOC"), + (const char*)desatt); + _prind->set_text(buf); + _vend_arr.destroy(); + + cattivs = ""; + + for (int tipoatt = 1; tipoatt <= (_mixed ? 2 : 1); tipoatt++) + { + TString cattiv(codatt); + + cattiv << tipoatt; + look_pla(cattiv, TRUE); + + _p8 = _pla->get_real("R5"); + _p8b = _pla->get_real("R6"); + _p9 = _pla->get_real("R7"); + _prorata = _pla->get_real("R8"); + _isplafond = !(_p8.is_zero() && _p8b.is_zero() && + _p9.is_zero()); + _isviaggio = _nditte->curr(LF_ATTIV).get_bool("REG74TER"); + _isagricolo = _nditte->curr(LF_ATTIV).get_bool("REGAGR"); + _isbenzinaro = _nditte->curr(LF_ATTIV).get_bool("ART74/4"); + _isservizio = _nditte->curr(LF_ATTIV).get("TIPOATT") == "S"; + _freqviva = look_lia() ? _lia->get("S7") : _nditte->curr().get("FREQVIVA"); + bool mens = _freqviva == "M"; + _isannual = (_month == 12 && !mens && !_isbenzinaro) || + (_month == 13 && (mens || _isbenzinaro)); + _isriepilogo = _month == 13; + _isvent = _pla->get_bool("B0"); + + if ((month != 13 || _isannual) && (calc || !recalc)) + if (!update_att(month, cattiv)) + describe_error("Attivita' non ricalcolate: possibili errori", + codatt); + + + // vediamo se c'e' qualcosa da raccontare + gheravergot = _isannual || _isriepilogo; + if (!gheravergot) + { + look_plm(month,cattiv); + gheravergot = !_plm->get_real("R0").is_zero() || + !_plm->get_real("R1").is_zero(); + } + + if (month == _month && gheravergot) + describe_att(month,cattiv); + atts.add(cattiv); + cattivs.add(cattiv); + } // for tipoatt + + // se attivita' mista stampa riepilogo (solo se + // la seconda attivita'aveva movimenti) + + if (_mixed && month == _month && gheravergot) + describe_att(month,cattivs); + } + while (_nditte->next_match(LF_ATTIV)); + + // occorre poterla chiamare altre volte con mesi diversi + _nditte->restore_status(); + + // aggiorna le liquidazioni mensili + if ((_month != 13 || _isannual) && (calc || !recalc)) + write_liq (month, atts); + + // rimborso infraannuale + _DescrItem* rimb_d = NULL; + if (month == _month && is_trim(month)) + { + // unica nel suo genere, recalc_rimborso ritorna + // un bel descritem (NULL se non si rimborsa un cas) + // da passare a describe_liq + rimb_d = recalc_rimborso(month,atts); + } + + if (month == _month) + { + describe_firm(month); + describe_liq(_month, atts, rimb_d); + } + } + return ok || calc; +} + +bool CG4300_App::update_att(int month, const char* codatt, bool recalc) + // viene passato un codice attivita' con codatt+tipoatt + // vedi update_firm per il burdel dei calc e recalc + + // occhecasino. Se _comp_acconto e' TRUE, i movimenti considerati + // saranno solo quelli di dicembre per data <= 20/12; + // il ricalcolo e' FORZATO da _recalc messo a one +{ + look_plm(month, codatt, TRUE); + bool ok = _plm->get_bool("B0"); + if (ok && !recalc) return TRUE; + bool calc = _recalc == ever || (_recalc == one && month == _month) ; + + if (!calc && _recalc != never) calc = !ok; + if (_isannual && month == 13) month = 12; + + if (calc || !recalc) + { + zero_att(month,codatt); + recalc_att(month,codatt); + recalc_ventilation(month, codatt); + recalc_corrispettivi(month, codatt); + if (month == 12) recalc_annual(codatt); + } + return ok || calc; +} + +void CG4300_App::zero_att(int month, const char* codatt) +{ + for (_pim->first(); !_pim->eof(); _pim->next()) + { + int m = atoi(*_pim_mese); + TString att = (const char*)*_pim_codatt; + if (m == month && att == codatt) + { + _pim->put("R0",""); + _pim->put("R1",""); + _pim->put("R2",""); + _pim->rewrite(); + } + } + if (_isplafond) + zero_plafond(month,codatt); +} + +void CG4300_App::recalc_att(int month, const char* codatt) + // il codatt passato e' codice att + tipo att ( IN {1|2} ) +{ + real totintra = 0.0; + real nond19_imp = 0.0; + real nond19_iva = 0.0; + real ammort = 0.0; + real ammort_iva = 0.0; + real ammort_6 = 0.0; + real ammort_6_iva = 0.0; + real acq_riv = 0.0; + real acq_riv_iva = 0.0; + real leasing = 0.0; + real leasing_iva = 0.0; + real cess_amm = 0.0; + real cess_amm_iva = 0.0; + real acquisti = 0.0; + real acquisti_iva = 0.0; + real vendite = 0.0; + real vendite_iva = 0.0; + real esenti_b1 = 0.0; + real esenti_b2 = 0.0; + real esenti_b3 = 0.0; + real esenti_b14 = 0.0; + real corr_CEE = 0.0; + real corr_noCEE = 0.0; + real acq_CEE = 0.0; + real acq_noCEE = 0.0; + real corr_misCEE = 0.0; + real acq_misCEE = 0.0; + real acq_misnoCEE = 0.0; + real agr_ven = 0.0; + real agr_acq = 0.0; + real agr_conf = 0.0; + real agr_acc = 0.0; + real cred_cost = 0.0; + real for_rimb = 0.0; + + *_cur = 0; + long items = _cur->items(); + TString trueatt(codatt); + int tipatt = atoi(trueatt.sub(5)); + trueatt = trueatt.left(5); + + for (; _cur->pos() < items; ++(*_cur)) + { + TDate date(_mov_r->get("DATAREG")); + TString reg = _mov_r->get("REG"); + bool isreg = look_reg(_mov_r->get("REG")); + + /* + * check register present, rmoviva present and date OK + */ +#ifndef DBG + + if (!is_date_ok(date, month) || + !isreg || + _reg_r->get("S8") != trueatt || + !_cur->is_first_match(LF_RMOVIVA)) + continue; +#else + + bool dok = !is_date_ok(date, month); + bool sreg = !isreg; + bool rs8 = _reg_r->get("S8") != trueatt; + bool cmt = !_cur->is_first_match(LF_RMOVIVA); + + if (dok || sreg || rs8 || cmt) continue; + +#endif + + /* + * check date se si calcola l'acconto + */ + if (_month == 12 && _comp_acconto) + if (date.month() != 12 && date.day() > 20) + continue; + + bool corrisp = _reg_r->get_bool("B0"); + tiporeg tipomov = (tiporeg)_reg_r->get_long("I0"); + + do + { + look_iva(_rmoviva->get("CODIVA")); + + // TBI settare _isrimborso + + TString codiva = _iva->get("CODTAB"); + TString tipoiva = _iva->get("S1"); + int tipoes_v = (int)_iva->get_long("I3"); + int tipoes_a = (int)_iva->get_long("I4"); + int tipoagr = atoi(_iva->get("S4")); + int tipoag = atoi(_iva->get("S5")); + int tipopla = atoi(_iva->get("S3")); + int tipodet = atoi(_rmoviva->get("TIPODET")); + bool ivarimb = _iva->get_bool("B3"); + TString tipocr_s = _rmoviva->get("TIPOCR"); + int tipocr = atoi(tipocr_s); + real imponibile = _rmoviva->get_real("IMPONIBILE"); + real imposta = _rmoviva->get_real("IMPOSTA"); + bool intra = _rmoviva->get_bool("INTRA"); + int tipoatt = _rmoviva->get_int("TIPOATT"); + + if ( tipoatt != tipatt ) continue; + + // ***************************************** + // casi particolari + // ***************************************** + + // imposta acquisti intracomunitari + if (tipomov == acquisto && intra) + totintra += imposta; + + // acquisti non detraibili art. 19 + if (tipodet == 9) + { + nond19_imp += imponibile; + nond19_iva += imposta; + continue; + } + + // Altre cose di cui tener conto + if (tipomov == acquisto && (tipocr == 1 || tipocr == 5)) + // Acquisto beni per rivendita + { + acq_riv += imponibile; + acq_riv_iva += imposta; + } + else if (tipomov == acquisto && tipocr == 2) + // Acquisto beni ammortizzabili + { + ammort += imponibile; + ammort_iva += imposta; + } + else if (tipomov == acquisto && tipocr == 3) + // Acquisto beni ammortizzabili detr. 6% + { + ammort_6 += imponibile; + ammort_6_iva += imposta; + } + else if (tipomov == vendita && tipocr == 4) + // Vendite strum. art 17 (cess. amm.???) + { + cess_amm += imponibile; + cess_amm_iva += imposta; + } + else if (tipomov == acquisto && tipocr == 8) + // Acquisto beni strum. in leasing + { + leasing += imponibile; + leasing_iva += imposta; + } + + // operazioni per calcolo rimborso infracazzuale + if ((tipoiva == "ES" || tipoiva == "NI") && ivarimb) + { + for_rimb += imponibile; + } + + // operazioni esenti + if (tipoiva == "ES") + { + if (tipomov == vendita) + { + switch(tipoes_v) + { + case 1: esenti_b1 += imponibile; break; + case 2: esenti_b2 += imponibile; break; + case 3: esenti_b3 += imponibile; break; + } + } + else if (tipoes_a == 14) + esenti_b14 += imponibile; + } + + // plafond + if (_isplafond && tipomov == acquisto && + tipoiva == "NI" && tipopla != 0) + add_plafond(month, codatt, tipopla, imponibile, intra); + + // agenzie viaggio (CHECK imponibili etc.) + if (_isviaggio) + switch (tipoag) + { + case 1: + if (tipomov == acquisto) acq_CEE += imponibile; + else corr_CEE += imponibile; + break; + case 2: + if (tipomov == acquisto) acq_noCEE += imponibile; + else corr_noCEE += imponibile; + break; + case 3: corr_misCEE += imponibile; break; + case 4: acq_misCEE += imponibile; break; + case 5: acq_misnoCEE += imponibile; break; + } + + if (_isagricolo) + switch(tipoagr) + { + case 1: + if (tipomov == acquisto) agr_acq += imposta; + else agr_ven += imposta; + break; + case 2: if (tipomov == vendita) agr_conf += imposta; break; + case 3: if (tipomov == vendita) agr_acc += imposta; break; + } + + if (tipodet == 3 || // passaggi interni (solo ventilaz.) + tipodet == 1) // esenti art. 10 + continue; + + // ***************************************** + // Fine casi particolari + // Non che i casi normali siano tanto meglio + // ***************************************** + + if (tipomov == vendita) + { + // totale vendite + vendite += imponibile; + vendite_iva += imposta; + } + else + { + // totale acquisti + acquisti += imponibile; + acquisti_iva += imposta; + } + + /* + * Calcolo e aggiornamento + * cerca o crea progressivo IVA + */ + look_pim(month, codatt, reg, tipocr_s, codiva, TRUE); + + real imp = _pim_r->get_real("R0"); // imponibile + real ivp = _pim_r->get_real("R1"); // IVA su imp. + real lor = _pim_r->get_real("R2"); // lordo + + /* + * se corrispettivi da ventilare considera il lordo + */ + if (corrisp && tipoiva == "VE") + { + lor += imponibile; + _pim_r->put("I0",LORDO); + add_vendite(month, reg, imponibile); + } + else + if (corrisp) + { + lor += imponibile; + lor += imposta; + _pim_r->put("I0",LORDO); + add_corrisp(month, reg, imponibile); + } + else + { + // netti e imposta separata + imp += imponibile; + ivp += imposta; + _pim_r->put("I0",NETTO); + } + + _pim_r->put("R0",imp); + _pim_r->put("R1",ivp); + _pim_r->put("R2",lor); + _pim->rewrite(); + } + while (_cur->next_match(LF_RMOVIVA)); + } + + // calcolati tutti i movimenti e aggiornati i pim + // salviamo i totali antes que seja tarde + + real dd6 = ammort_6 * real(DETRAZIONE_6PERCENTO); + // calcola il lercio prorata + real prorata; + if (!_prorata.is_zero()) + prorata = acquisti_iva * (_prorata / 100.0); + + look_plm(month, codatt, TRUE); + + // ACHTUNG: l'iva sulle vendite e' calcolata sommando anche i + // corrispettivi; non tiene conto quindi delle imposte calcolate + // con la ventilazione (che vanno sottratte) ne' di quelle + // calcolate per le agenzie di viaggio (che sembra non vadano + // sottratte per il calcolo del volume di affari) + + _plm->put("R2", prorata); + + if (_isviaggio) + { + _plm->put("R5", corr_CEE); + _plm->put("R6", corr_noCEE); + _plm->put("R7", acq_CEE); + _plm->put("R8", acq_noCEE); + _plm->put("R9", corr_misCEE); + _plm->put("R10",acq_misCEE); + _plm->put("R11",acq_misnoCEE); + // calcola base da base e credito di costo + // indi abilmente trova il codiva e calcola l'iva del caso + real rip = acq_misCEE / (acq_misCEE + acq_misnoCEE); + real corr_imp = corr_misCEE * rip; corr_imp.round(ROUND_LIRA); + corr_imp += corr_CEE; + real cost_detr = acq_misCEE * acq_CEE; + real base_imp = corr_imp - (cost_detr + + credito_costo_prec(month, codatt)); + + real debito = 0.0; + + if (base_imp.sign() < 0) + { + // credito di costo + cred_cost = abs(base_imp); + // vendite_iva e' corretto cosi' visto che i corrispettivi + // sono registrati al lordo e l'imposta e' 0 + } + else + { + debito = base_imp * aliquota_agvia(); + vendite_iva += debito; + vendite_iva.round(ROUND_LIRA); + } + + // tutte ste minchie le mettiamo in lim anche se sarebbe + // assai piu' migliore metterle in plm + look_lim(month,TRUE); + _lim->put("R2", cred_cost); + _lim->put("R3", debito); + _lim->put("R4", rip); + _lim->rewrite(); + } + else if (_isagricolo) + { + _plm->put("R5", agr_ven); + _plm->put("R6", agr_conf); + _plm->put("R7", agr_acc); + _plm->put("R8", agr_acq); + // Il porco agricoltore spende poco e paga meno + acquisti_iva -= (agr_acq + leasing_iva + ammort_iva + ammort_6_iva); + vendite_iva -= (agr_ven + agr_conf + agr_acc); + } + _plm->put("R0", vendite_iva); + _plm->put("R1", acquisti_iva); + _plm->put("R3", dd6); + _plm->put("R12", _prorata); // per comodita' in stampa + _plm->put("B0", "X"); // calcolato (deve essere invalidato dalla + // primanota) + _plm->put("S1", for_rimb.string()); + _plm->rewrite(); + + // salva gli altri totali para no ponernos locos despues + look_ptm(month, codatt, TRUE); + _ptm->put("R0", totintra); + _ptm->put("R1", nond19_imp); + _ptm->put("R2", nond19_iva); + _ptm->put("R3", ammort); + _ptm->put("R4", ammort_iva); + _ptm->put("R5", ammort_6); + _ptm->put("R6", acq_riv); + _ptm->put("R7", acq_riv_iva); + _ptm->put("R8", leasing); + _ptm->put("R9", leasing_iva); + _ptm->put("R10", cess_amm); + _ptm->put("R11", cess_amm_iva); + _ptm->put("R12", ammort_6_iva); + _ptm->put("R13", esenti_b1); + _ptm->put("R14", esenti_b2); + _ptm->put("S0", esenti_b3.string()); + _ptm->put("S1", esenti_b14.string()); + _ptm->put("S2", acquisti.string()); + _ptm->put("S3", vendite.string()); + _ptm->rewrite(); +} + +void CG4300_App::write_liq(int month, const char* codatts) + // Calcolo liq. mensili e progr. liq. annuali +{ + TToken_string atts(codatts); + const char* tmpatt; + + real risultato = 0.0; + real vol_aff = 0.0; + real debito_prec = 0.0; + + while ((tmpatt = atts.get()) != NULL) + { + TString att(tmpatt); + { + look_plm(month, att); look_ptm(month,att); + // a debito: IVA vendite, debito precedente, Prorata + // a credito: IVA acquisti, ulteriori detrazioni 1 e 2 + risultato += (_plm->get_real("R0") - _plm->get_real("R1") + + _plm->get_real("R2") - _plm->get_real("R3") - + _plm->get_real("R4")); + + if (month == 12) + { + look_pla(att); + vol_aff += _pla->get_real("R0"); + // a credito anche il conguaglio prorata + risultato -= _pla->get_real("R10"); + } + } + } + // toglie credito precedente decrementato di ev. rimborsi chiesti + // e acconto versato e rettifiche a debito + risultato -= credito_prec(month); + + // vedi se c'era un debito precedente + if (!is_first_month(month)) + { + if (look_lim(previous_month(month))) + { + real r = _lim->get_real("R0"); + if (_lim->get_real("R5").sign() > 0) + r += _plm->get_real("R5"); + // non considera il rimborso in quanto se e' a debito + // non c'e' rimborso, e se e' rettificato pure + if (r.sign() > 0 && r < IVA_DA_RIPORTARE) + debito_prec += r; + } + } + risultato += debito_prec; + + look_lim(month,TRUE); + + _lim->put("R0",risultato); + _lim->put("B0","X"); + + if (_isfinal) + _lim->put("B1","X"); + _lim->rewrite(); + + if (month == 12) + { + if (!look_lia(TRUE)) + _lia->put("S7", (const char *) _freqviva); + _lia->put("R1", vol_aff); + _lia->rewrite(); + } +} + + +void CG4300_App::recalc_annual(const char* att) +{ + // TBI calcolo nuovo plafond + + // calcolo volume d'affari e altro + real es_b1 = 0.0; + real es_b2 = 0.0; + real es_b3 = 0.0; + real cess_amm = 0.0; + real vendite = 0.0; + real pro_pag = 0.0; + real acq_iva = 0.0; // per conguaglio prorata + real acq = 0.0; + real ivlac = 0.0; + real ivven = 0.0; + real ven_lrd = 0.0; + + TString aaa(att); + + for (int i = 1; i <= 12; i++) + { + if (is_month_ok(i)) + { + // ricalcola se necessario + if (i != 12 && !update_att(i,aaa,FALSE)) + describe_error("Attivita' non ricalcolata: " + "possibili errori",att); + look_ptm(i,aaa); look_plm(i,aaa); + real vend = _ptm->get("S3"); + ven_lrd += vend; // lordo vendite + // non entra l'IVA per calcolo volume affari + vendite += (vend - _plm->get_real("R0")); + real eb3 = _ptm->get("S0"); + es_b1 += _ptm->get_real("R13"); + es_b2 += _ptm->get_real("R14"); + es_b3 += eb3; + acq_iva += _plm->get_real("R1"); + cess_amm += _ptm->get_real("R10"); + pro_pag += _plm->get_real("R2"); + real aax = _ptm->get("S2"); + acq += aax - // rilevanti per aliquota media + _ptm->get_real("R3") - // toglie ammortizz. etc + _ptm->get_real("R5") - // non detraibili non ci sono + _ptm->get_real("R8"); + ivlac += _plm->get_real("R1") - // idem per IVE + _ptm->get_real("R4") - + _ptm->get_real("R9") - + _ptm->get_real("R12"); + ivven += _plm->get_real("R0"); + } + } + // calcolo prorata + real prorata = (es_b1/(vendite - cess_amm - es_b3)) * 100.0; + real conguaglio = 0.0; + prorata.round(ROUND_LIRA); + if (prorata != _prorata) + { + // calcolo conguaglio -- se positivo e' a debito + real topay = acq_iva * (prorata / 100.0); + conguaglio = topay - pro_pag; + } + // vediamo se la porca aliquota media acquisti e' superiore alla + // porca aliquota media vendite + + look_pla(aaa); + _pla->put("R0", vendite); + _pla->put("R1", es_b1); + _pla->put("R2", es_b2); + _pla->put("R3", es_b3); + _pla->put("R4", cess_amm); + _pla->put("R9", prorata); + _pla->put("R10", conguaglio); + _pla->put("R11", ivven); + _pla->put("R12", ivlac); + _pla->put("R13", ven_lrd); + _pla->put("R14", acq); + _pla->rewrite(); +} + +_DescrItem* CG4300_App::recalc_rimborso(int month, const char* codatts) +{ + bool rimborsami = FALSE; + _DescrItem* d = NULL; + TToken_string atts(codatts); + const char* tmpatt; + TString att; + + real iva_v, iva_a, imp_a, es_ni, vol_aff; + + while ((tmpatt = atts.get()) != NULL) + { + att = tmpatt; + look_plm(month,att); look_ptm(month,att); + + real tvol = _ptm->get("S3"); + vol_aff += tvol; + real esni = _plm->get("S1"); + es_ni += esni; + iva_a += _plm->get_real("R1"); + iva_v += _plm->get_real("R0"); + real aax = _ptm->get("S2"); + imp_a += aax - // rilevanti per aliquota media + _ptm->get_real("R3") - // toglie ammortizz. etc + _ptm->get_real("R5") - // non detraibili non ci sono + _ptm->get_real("R8"); + + if (_freqviva == "M") // sommiamo i due mesi precedenti + { + for (int m = month - 2; m < month; m++) + { + bool ok = look_plm(m,att); + if (!ok) + if (!update_att(m, att)) + describe_error("Attivita' non ricalcolate: possibili errori", + att); + + look_ptm(m,att); + + real tvol = _ptm->get("S3"); + vol_aff += tvol; + real esni = _plm->get("S1"); + es_ni += esni; + iva_a += _plm->get_real("R1"); + iva_v += _plm->get_real("R0"); + real aax = _ptm->get("S2"); + imp_a += aax - // rilevanti per aliquota media + _ptm->get_real("R3") - // toglie ammortizz. etc + _ptm->get_real("R5") - // non detraibili non ci sono + _ptm->get_real("R8"); + } + } + } + + // condizione 1 + if (!vol_aff.is_zero() && (es_ni/vol_aff) > MIN_PARTE_ESENTE) + { + rimborsami = TRUE; + d = new _DescrItem(RIMBORSO); + d->_f0 = TRUE; + d->_r0 = es_ni; + d->_r1 = vol_aff; + } + + real alv = vol_aff.is_zero() ? real(0.0) : (iva_v / vol_aff); + real ala = imp_a.is_zero() ? real(0.0) : (iva_a / imp_a); + + // condizione 2 + if (ala > alv) + { + rimborsami = TRUE; + if (d == NULL) d = new _DescrItem(RIMBORSO); + d->_f1 = TRUE; + d->_r2 = vol_aff; + d->_r3 = imp_a; + d->_r4 = iva_v; + d->_r5 = iva_a; + d->_r6 = alv * real(100.0); + d->_r7 = ala * real(100.0); + } + + if (rimborsami) + { + // il rimborso viene chiesto automaticamente + look_lim(month); + real cred = _lim->get_real("R0"); + if (cred.sign() < 0) + { + _lim->put("R1",abs(cred)); + _lim->rewrite(); + } + } + + return d; +} + + + + diff --git a/cg/cg5.cpp b/cg/cg5.cpp index e27bc074f..aada3e43e 100755 --- a/cg/cg5.cpp +++ b/cg/cg5.cpp @@ -1,20 +1,20 @@ -#include -#include - -#include "cg5.h" - -#define usage "Error - usage : %s -{0,1,3}" - -int main(int argc,char** argv) -{ - int n = (argc > 1) ? atoi(argv[1]+1) : -1; - - switch (n) - { - case 0: cg5000(argc,argv) ; break; - case 1: cg5100(argc,argv) ; break; - case 3: cg5300(argc,argv) ; break; - default: fatal_box(usage, argv[0]) ; - } - return 0; -} +#include +#include + +#include "cg5.h" + +#define usage "Error - usage : %s -{0,1,3}" + +int main(int argc,char** argv) +{ + int n = (argc > 1) ? atoi(argv[1]+1) : -1; + + switch (n) + { + case 0: cg5000(argc,argv) ; break; + case 1: cg5100(argc,argv) ; break; + case 3: cg5300(argc,argv) ; break; + default: fatal_box(usage, argv[0]) ; + } + return 0; +} diff --git a/cg/cg5.h b/cg/cg5.h index cd805ce5d..74d81f2ec 100755 --- a/cg/cg5.h +++ b/cg/cg5.h @@ -1,3 +1,3 @@ -extern int cg5000 (int argc, char* argv[]); -extern int cg5100 (int argc, char* argv[]); -extern int cg5300 (int argc, char* argv[]); +extern int cg5000 (int argc, char* argv[]); +extern int cg5100 (int argc, char* argv[]); +extern int cg5300 (int argc, char* argv[]);