Patch level : 4.0 874
Files correlati : ve0.exe ve6.exe Ricompilazione Demo : [ ] Commento : Contabilizzazione con il nuovo campo TIPODETR git-svn-id: svn://10.65.10.50/trunk@16077 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
0a72e7fbad
commit
27b55778b9
@ -384,88 +384,22 @@ bool TConti_array::remove_iva(bool det)
|
||||
}
|
||||
|
||||
real TMovimentoPN::indetraibile_al(const TString& codind, const TCausale& caus, int annodoc) const
|
||||
{
|
||||
real perc;
|
||||
{
|
||||
int tipodet;
|
||||
|
||||
if (caus.iva() == iva_acquisti) // Vendite sempre detraibili
|
||||
{
|
||||
// Se prorata = 100% e' indetraibile
|
||||
const bool prorata100 = caus.reg().prorata100(annodoc);
|
||||
if (prorata100)
|
||||
perc = CENTO;
|
||||
else
|
||||
{
|
||||
if (codind.full())
|
||||
{
|
||||
const TRectype& rec = cache().get("%DET", codind);
|
||||
if (rec.empty())
|
||||
{
|
||||
if (strchr("139", codind[0]) != NULL) // Clausola di salvaguardia
|
||||
perc = CENTO;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rec.get_int("I0") > 0)
|
||||
perc = rec.get_real("R0");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return perc;
|
||||
return ::indetraibile_al(codind, caus, annodoc, tipodet);
|
||||
}
|
||||
|
||||
int TMovimentoPN::analizza_riga_IVA(const real& imptot, const real& ivatot, const TCausale& caus,
|
||||
int annodoc, const TString& codiva, const TString& codind,
|
||||
real& imp_det, real& iva_det, real& imp_ind, real& iva_ind) const
|
||||
{
|
||||
int flag = 0;
|
||||
|
||||
const real perc_ind = indetraibile_al(codind, caus, annodoc);
|
||||
if (perc_ind <= ZERO)
|
||||
{
|
||||
flag = 1;
|
||||
imp_det = imptot;
|
||||
iva_det = ivatot;
|
||||
if (iva_det.is_zero() && caus.corrispettivi())
|
||||
{
|
||||
const TCodiceIVA iva(codiva);
|
||||
iva_det = iva.scorpora(imp_det);
|
||||
}
|
||||
imp_ind = iva_ind = ZERO;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (perc_ind >= CENTO)
|
||||
{
|
||||
flag = 2;
|
||||
imp_ind = imptot;
|
||||
iva_ind = ivatot;
|
||||
imp_det = iva_det = ZERO;
|
||||
}
|
||||
else
|
||||
{
|
||||
flag = 3;
|
||||
const int decimali = TCurrency::get_firm_dec();
|
||||
imp_ind = imptot * perc_ind / CENTO; imp_ind.round(decimali);
|
||||
imp_det = imptot - imp_ind;
|
||||
|
||||
const TCodiceIVA iva(codiva);
|
||||
iva_ind = iva.imposta(imp_ind, decimali);
|
||||
iva_det = ivatot - iva_ind;
|
||||
}
|
||||
if (!iva_ind.is_zero())
|
||||
{
|
||||
TBill billind; caus.bill(RIGA_IVA_NON_DETRAIBILE, billind);
|
||||
if (!billind.ok())
|
||||
{
|
||||
imp_ind += iva_ind;
|
||||
iva_ind = ZERO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
const bool corrispettivo = caus.corrispettivi();
|
||||
TBill billind; caus.bill(RIGA_IVA_NON_DETRAIBILE, billind);
|
||||
const bool iva_ind_al_costo = !billind.ok();
|
||||
return analizza_IVA(imptot, ivatot, perc_ind, corrispettivo, iva_ind_al_costo,
|
||||
codiva, imp_det, iva_det, imp_ind, iva_ind);
|
||||
}
|
||||
|
||||
// Aggiusta i row types se sono andati persi o non sono stati convertiti
|
||||
|
@ -5,6 +5,10 @@
|
||||
#include "cg2103.h"
|
||||
#endif
|
||||
|
||||
#ifndef __CGLIB03_H
|
||||
#include "cglib03.h"
|
||||
#endif
|
||||
|
||||
#ifndef __RECARRAY_H
|
||||
#include <recarray.h>
|
||||
#endif
|
||||
@ -25,6 +29,7 @@
|
||||
#include <rmoviva.h>
|
||||
#endif
|
||||
|
||||
|
||||
class TMovimentoPN : public TRelation
|
||||
{
|
||||
// class TMovimentoPN : public TRelation
|
||||
@ -41,10 +46,10 @@ protected:
|
||||
int registra(bool re, bool force);
|
||||
int read_mov_rows();
|
||||
|
||||
real indetraibile_al(const TString& codind, const TCausale& caus, int annodoc) const;
|
||||
// @END
|
||||
|
||||
public:
|
||||
real indetraibile_al(const TString& codind, const TCausale& caus, int annodoc) const;
|
||||
// @FPUB
|
||||
virtual int next(TReclock lockop = _nolock) { return (file().next(lockop) || read_mov_rows()); }
|
||||
virtual int prev(TReclock lockop = _nolock) { return (file().prev(lockop) || read_mov_rows()); }
|
||||
|
142
cg/cglib03.cpp
142
cg/cglib03.cpp
@ -1,10 +1,119 @@
|
||||
#include "cg2103.h"
|
||||
#include "cglib03.h"
|
||||
|
||||
#include <diction.h>
|
||||
#include <recarray.h>
|
||||
|
||||
#include <mov.h>
|
||||
#include <rmoviva.h>
|
||||
|
||||
static int codind2tipodet(const TString & codind, real& perc)
|
||||
{
|
||||
int tipodet = 0;
|
||||
perc = ZERO;
|
||||
if (codind.full())
|
||||
{
|
||||
const TRectype& rec = cache().get("%DET", codind);
|
||||
if (rec.empty())
|
||||
{
|
||||
if (strchr("139", codind[0]) != NULL) // Clausola di salvaguardia
|
||||
{
|
||||
tipodet = codind[0]-'0';
|
||||
perc = CENTO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tipodet = rec.get_int("I0");
|
||||
if (tipodet > 0)
|
||||
perc = rec.get_real("R0");
|
||||
}
|
||||
}
|
||||
return tipodet;
|
||||
}
|
||||
real indetraibile_al(const TString& codind, const TCausale& caus, int annodoc, int & tipodet)
|
||||
{
|
||||
real perc;
|
||||
tipodet = 0;
|
||||
|
||||
if (caus.iva() == iva_acquisti) // Vendite sempre detraibili
|
||||
{
|
||||
// Se prorata = 100% e' indetraibile
|
||||
const bool prorata100 = caus.reg().prorata100(annodoc);
|
||||
if (prorata100)
|
||||
{
|
||||
perc = CENTO;
|
||||
tipodet = 9;
|
||||
}
|
||||
else
|
||||
tipodet = codind2tipodet(codind, perc);
|
||||
}
|
||||
|
||||
return perc;
|
||||
}
|
||||
|
||||
int analizza_IVA(const real& imptot, const real& ivatot, const real perc_ind,
|
||||
const bool corrispettivo, const bool iva_ind_al_costo, const TString& codiva,
|
||||
real& imp_det, real& iva_det, real& imp_ind, real& iva_ind)
|
||||
|
||||
{
|
||||
int flag = 0;
|
||||
|
||||
if (perc_ind <= ZERO)
|
||||
{
|
||||
flag = 1;
|
||||
imp_det = imptot;
|
||||
iva_det = ivatot;
|
||||
if (iva_det.is_zero() && corrispettivo)
|
||||
{
|
||||
const TCodiceIVA iva(codiva);
|
||||
iva_det = iva.scorpora(imp_det);
|
||||
}
|
||||
imp_ind = iva_ind = ZERO;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (perc_ind >= CENTO)
|
||||
{
|
||||
flag = 2;
|
||||
imp_ind = imptot;
|
||||
iva_ind = ivatot;
|
||||
imp_det = iva_det = ZERO;
|
||||
}
|
||||
else
|
||||
{
|
||||
flag = 3;
|
||||
const int decimali = TCurrency::get_firm_dec();
|
||||
imp_ind = imptot * perc_ind / CENTO; imp_ind.round(decimali);
|
||||
imp_det = imptot - imp_ind;
|
||||
|
||||
const TCodiceIVA iva(codiva);
|
||||
iva_ind = iva.imposta(imp_ind, decimali);
|
||||
iva_det = ivatot - iva_ind;
|
||||
}
|
||||
if (!iva_ind.is_zero() && iva_ind_al_costo)
|
||||
{
|
||||
imp_ind += iva_ind;
|
||||
iva_ind = ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
// Anticamente TIPODET conteneva in tipo di indetraibilita,
|
||||
// ora invece trattasi di un codice di indetraibilita'
|
||||
// associato ad un motivo ed una percentuale di indetraibilita'
|
||||
int get_tipodet_from_rmi(const TRectype& rmi, const TRectype& mov,real& percind)
|
||||
{
|
||||
const TCausale c(mov.get(MOV_CODCAUS));
|
||||
const int annodoc = mov.get_date(MOV_DATAREG).year();
|
||||
int tipodet;
|
||||
|
||||
percind = indetraibile_al(rmi.get(RMI_TIPODET), c, annodoc, tipodet);
|
||||
return tipodet;
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
// classe TInteressi_IVA_table //
|
||||
// per la lettura versamenti e //
|
||||
@ -259,36 +368,3 @@ TIva_round::TIva_round()
|
||||
_decimals = _def_decimals;
|
||||
}
|
||||
|
||||
int codind2tipodet(const char codind, real& perc)
|
||||
{
|
||||
int tipodet = 0;
|
||||
perc = ZERO;
|
||||
if (isalnum(codind))
|
||||
{
|
||||
const char strind[2] = { codind, '\0' };
|
||||
const TRectype& rec = cache().get("%DET", strind);
|
||||
if (rec.empty())
|
||||
{
|
||||
if (strchr("139", codind) != NULL) // Clausola di salvaguardia
|
||||
{
|
||||
tipodet = codind-'0';
|
||||
perc = CENTO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tipodet = rec.get_int("I0");
|
||||
if (tipodet > 0)
|
||||
perc = rec.get_real("R0");
|
||||
}
|
||||
}
|
||||
return tipodet;
|
||||
}
|
||||
|
||||
// Anticamente TIPODET conteneva in tipo di indetraibilita,
|
||||
// ora invece trattasi di un codice di indetraibilita'
|
||||
// associato ad un motivo ed una percentuale di indetraibilita'
|
||||
int get_tipodet_from_rmi(const TRectype& rmi, real& percind)
|
||||
{
|
||||
return codind2tipodet(rmi.get_char(RMI_TIPODET), percind);
|
||||
}
|
||||
|
13
cg/cglib03.h
13
cg/cglib03.h
@ -3,6 +3,10 @@
|
||||
#ifndef __CGLIB03_H
|
||||
#define __CGLIB03_H
|
||||
|
||||
#ifndef __CG2103_H
|
||||
#include "cg2103.h"
|
||||
#endif
|
||||
|
||||
#ifndef __TABUTIL_H
|
||||
#include <tabutil.h>
|
||||
#endif
|
||||
@ -146,7 +150,12 @@ public: // High level functions (common usage)
|
||||
TIva_round();
|
||||
};
|
||||
|
||||
int codind2tipodet(char codind, real& percind);
|
||||
int get_tipodet_from_rmi(const TRectype& rmi, real& percind);
|
||||
real indetraibile_al(const TString& codind, const TCausale& caus, int annodoc,
|
||||
int& tipodet);
|
||||
int analizza_IVA(const real& imptot, const real& ivatot, const real perc_ind,
|
||||
const bool corrispettivo, const bool iva_ind_al_costo, const TString& codiva,
|
||||
real& imp_det, real& iva_det, real& imp_ind, real& iva_ind);
|
||||
int get_tipodet_from_rmi(const TRectype& rmi, const TRectype& mv, real& percind);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -426,8 +426,6 @@ public:
|
||||
const int decr_perc_prezzo() const { return _decrp;}
|
||||
|
||||
bool formfeed() const { return get_bool("B0"); }
|
||||
int detraibilita() const { return get_int("I0"); }
|
||||
real perc_indetraibilita() const { return get_real("R0"); }
|
||||
|
||||
TFormula_documento* first_formula() { return succ_formula(true); }
|
||||
TFormula_documento* succ_formula(bool restart = FALSE);
|
||||
@ -907,4 +905,4 @@ public:
|
||||
virtual ~TDocumento_mask();
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
@ -1,5 +1,6 @@
|
||||
#include <dongle.h>
|
||||
#include <modaut.h>
|
||||
#include <tabutil.h>
|
||||
#include <utility.h>
|
||||
|
||||
#include "../cg/cg2103.h"
|
||||
@ -1047,6 +1048,23 @@ int TDocumento::write_rewrite(TBaseisamfile & f, bool re) const
|
||||
rm.put(RMOVMAG_TIPORIGA, (char) riga_dadocumento);
|
||||
}
|
||||
}
|
||||
|
||||
const TString & indetr = r.get(RDOC_TIPODET);
|
||||
|
||||
if (indetr.full())
|
||||
{
|
||||
const TRectype & det = cache().get("%DET", indetr);
|
||||
|
||||
if (!det.empty() && !det.get_bool("FPC"))
|
||||
{
|
||||
TTable tab("%DET");
|
||||
|
||||
tab.curr() = det;
|
||||
tab.curr().put("FPC", "X");
|
||||
tab.rewrite();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
mov.rewrite(m);
|
||||
}
|
||||
@ -2656,4 +2674,4 @@ int TDocumento::tipo_riclassificato() const
|
||||
tipo_riclassificato = TTipo_documento::_fattura;
|
||||
}
|
||||
return tipo_riclassificato;
|
||||
}
|
||||
}
|
@ -136,16 +136,22 @@ int TLista_documenti::read(char provv, char tipocf, long clifo, int anno,
|
||||
{
|
||||
const TString4 tipodoc = head.get(DOC_TIPODOC);
|
||||
const TString4 statodoc = head.get(DOC_STATO);
|
||||
bool match = FALSE;
|
||||
bool match = false;
|
||||
|
||||
for (int i = tipidoc.items()-1; i>=0; i--)
|
||||
{
|
||||
if (tipodoc == tipidoc.get(i))
|
||||
if (statodoc == statidoc.get(i))
|
||||
const TString & tipo = tipidoc.get(i);
|
||||
|
||||
if (tipo.blank() || tipodoc == tipo)
|
||||
{
|
||||
const TString & stato = statidoc.get(i);
|
||||
|
||||
if (stato.blank() || statodoc == stato)
|
||||
{
|
||||
match = TRUE;
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (match)
|
||||
|
@ -493,8 +493,8 @@ class TContabilizzazione_analitica : public TElaborazione // velib04f
|
||||
bool _usepdcc;
|
||||
|
||||
protected:
|
||||
bool find_conti_iva_indetraibile(const TRiga_documento& riga, const TBill & bill, TString_array& conti);
|
||||
bool find_conti(const TRiga_documento& riga, TString_array& conti);
|
||||
bool find_conti_iva_indetraibile(const TRiga_documento& riga, const TBill & bill, TString_array& conti, int annoes);
|
||||
bool find_conti(const TRiga_documento& riga, TString_array& conti, int annoes);
|
||||
void init();
|
||||
|
||||
const TCausale& doc2caus(const TDocumento& doc);
|
||||
|
299
ve/velib04b.cpp
299
ve/velib04b.cpp
@ -62,20 +62,6 @@ TImporto TMovimentoPN_VE::real2imp(const real& r, char row_type)
|
||||
return importo;
|
||||
}
|
||||
|
||||
bool TMovimentoPN_VE::detraibile(TRectype& rec) const
|
||||
{
|
||||
CHECK(_caus,"Orgggssbb..._caus pointer is NULL!");
|
||||
if (_caus->iva() == iva_vendite)
|
||||
return true;
|
||||
|
||||
if (rec.get_int(RMI_TIPODET) != 0)
|
||||
return false;
|
||||
|
||||
const int annodoc = curr().get_date(MOV_DATADOC).year();
|
||||
const bool prorata100 = _caus->reg().prorata100(annodoc);
|
||||
return !prorata100; // Se prorata = 100% e' indetraibile
|
||||
}
|
||||
|
||||
int TMovimentoPN_VE::bill2pos(const TBill& conto, char tipo)
|
||||
{
|
||||
const int items = cg_items();
|
||||
@ -205,154 +191,121 @@ int TMovimentoPN_VE::insert_cg_rec(int n, const TImporto& imp, TBill& conto,
|
||||
return set_cg_rec(n, imp, conto, desc, tipo);
|
||||
}
|
||||
|
||||
void TMovimentoPN_VE::create_row(int i, const TString & descr_cr)
|
||||
{
|
||||
CHECK(_caus,"Orgggssbb..._caus pointer is NULL!");
|
||||
TRectype& cur = iva(i);
|
||||
real oldimp = cur.get_real(RMI_IMPONIBILE);
|
||||
real oldiva = cur.get_real(RMI_IMPOSTA);
|
||||
|
||||
if (oldiva.is_zero() && _caus->corrispettivi()) // In caso di corrispettivi ...
|
||||
{
|
||||
const TString4 zanicchi(cur.get(RMI_CODIVA)); // Codice IVA
|
||||
const TCodiceIVA i(zanicchi);
|
||||
oldiva = i.scorpora(oldimp); // ... scorpora imposta dall'imponibile
|
||||
}
|
||||
|
||||
const char tipod = detraibile(cur) ? 'D' : 'N';
|
||||
|
||||
if (type2pos(tipod) < 0 && !oldiva.is_zero())
|
||||
{
|
||||
const int ri = tipod == 'D' ? RIGA_IVA_DETRAIBILE : RIGA_IVA_NON_DETRAIBILE;
|
||||
TBill c; _caus->bill(ri, c);
|
||||
if (c.ok())
|
||||
{
|
||||
const TString80 d(_caus->desc_agg(ri));
|
||||
set_cg_rec(-1, real2imp(ZERO, 'I'), c, d, tipod);
|
||||
}
|
||||
else
|
||||
if (ri == RIGA_IVA_NON_DETRAIBILE) // Se non esiste il conto IVA indetraibile ...
|
||||
{ // ... somma imponibile e imposta
|
||||
oldimp += oldiva;
|
||||
oldiva = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
const TBill oldconto(cur);
|
||||
if (oldconto.ok())
|
||||
{
|
||||
if (bill2pos(oldconto, 'I') < 0)
|
||||
{
|
||||
const TString80 d(_caus->desc_agg(2));
|
||||
set_cg_rec(-1, real2imp(ZERO, 'I'), oldconto, d.empty() ? descr_cr: d, 'I');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TMovimentoPN_VE::enter_row(int i, const TString & descr_cr)
|
||||
{
|
||||
CHECK(_caus,"Orgggssbb..._caus pointer is NULL!");
|
||||
TRectype& cur = iva(i);
|
||||
real imponibile = cur.get_real(RMI_IMPONIBILE);
|
||||
real imposta = cur.get_real(RMI_IMPOSTA);
|
||||
|
||||
const int anno = lfile().curr().get_date(MOV_DATAREG).year();
|
||||
const TString4 tipodet = cur.get(RMI_TIPODET);
|
||||
const TString4 zanicchi(cur.get(RMI_CODIVA)); // Codice IVA
|
||||
|
||||
if (imposta.is_zero() && _caus->corrispettivi()) // In caso di corrispettivi ...
|
||||
{
|
||||
const TString4 zanicchi(cur.get(RMI_CODIVA));
|
||||
const TCodiceIVA i(zanicchi);
|
||||
imposta = i.scorpora(imponibile); // ... scorpora imposta dall'imponibile
|
||||
}
|
||||
|
||||
const TBill conto(cur);
|
||||
int newpos = bill2pos(conto, 'I'); // Riga in cui andra' l'imponibile
|
||||
|
||||
const bool detrarre = detraibile(cur); // Determina se IVA detraibile
|
||||
|
||||
// Calcola riga causale col conto opportuno
|
||||
const int ri = detrarre ? RIGA_IVA_DETRAIBILE : RIGA_IVA_NON_DETRAIBILE;
|
||||
TBill contoiva; _caus->bill(ri, contoiva);
|
||||
|
||||
if (ri == RIGA_IVA_NON_DETRAIBILE && !contoiva.ok()) // Se non c'e' il conto IVA indetraibile ...
|
||||
{ // ... somma imponibile e imposta
|
||||
imponibile += imposta;
|
||||
imposta = 0.0;
|
||||
}
|
||||
|
||||
real imp, impind, iva, ivaind;
|
||||
int flag = analizza_riga_IVA(imponibile, imposta, *_caus, anno, zanicchi, tipodet, imp, iva, impind, ivaind);
|
||||
const TBill conto(cur);
|
||||
TBill contoivaind;
|
||||
|
||||
_caus->bill(RIGA_IVA_NON_DETRAIBILE, contoivaind);
|
||||
imponibile = imp + impind;
|
||||
if (conto.ok() && !imponibile.is_zero()) // Se c'e' imponibile ...
|
||||
{ // crea una nuova riga contabile
|
||||
// Aggiorna conto sulla riga contabile
|
||||
if (newpos < 0) // conto non esistente: da inserire
|
||||
{
|
||||
const TImporto val(real2imp(imponibile, 'I'));
|
||||
if (conto.ok() && !val.is_zero()) // Se c'e' imponibile ...
|
||||
{ // crea una nuova riga contabile
|
||||
const TImporto val(real2imp(imponibile, 'I'));
|
||||
const int newpos = bill2pos(conto, 'I'); // Riga in cui andra' l'imponibile
|
||||
|
||||
if (newpos < 0) // conto non esistente: da inserire
|
||||
{
|
||||
const TString d(_caus->desc_agg(2));
|
||||
set_cg_rec(-1, val, conto, d.empty() ? descr_cr : d, 'I');
|
||||
}
|
||||
else
|
||||
add_cg_rec(newpos, val);
|
||||
cur.put(RMI_RIGAIMP, newpos+1); // Aggiorna riferimento alla riga contabile
|
||||
}
|
||||
else
|
||||
{
|
||||
TImporto val(real2imp(imponibile, 'I'));
|
||||
add_cg_rec(newpos, val);
|
||||
}
|
||||
cur.put(RMI_RIGAIMP, newpos+1); // Aggiorna riferimento alla riga contabile
|
||||
|
||||
// Aggiorna conto IVA sulla riga contabile
|
||||
|
||||
const char tipod = detrarre ? 'D' : 'N';
|
||||
int newposiva = type2pos(tipod);
|
||||
if (!iva.is_zero()) // Se c'e' imposta ...
|
||||
{
|
||||
int newposiva = type2pos('D');
|
||||
const TImporto val(real2imp(iva, 'I'));
|
||||
|
||||
if (newposiva < 0)
|
||||
{
|
||||
if (!imposta.is_zero()) // Se c'e' imposta ...
|
||||
{ // ... crea nuova riga per l'IVA
|
||||
const TImporto val(real2imp(imposta, 'I'));
|
||||
const TString80 d(_caus->desc_agg(ri));
|
||||
newposiva = set_cg_rec(-1, val, contoiva, d, tipod);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const TImporto val(real2imp(imposta, 'I'));
|
||||
add_cg_rec(newposiva, val);
|
||||
}
|
||||
if (newposiva < 0)
|
||||
{
|
||||
const TString80 d(_caus->desc_agg(RIGA_IVA_DETRAIBILE));
|
||||
TBill contoiva;
|
||||
|
||||
_caus->bill(RIGA_IVA_DETRAIBILE, contoiva);
|
||||
if (contoiva.ok())
|
||||
newposiva = set_cg_rec(-1, val, contoiva, d, 'D');
|
||||
}
|
||||
else
|
||||
add_cg_rec(newposiva, val);
|
||||
}
|
||||
|
||||
if (!ivaind.is_zero()) // Se c'e' imposta ...
|
||||
{
|
||||
int newposiva = type2pos('N');
|
||||
const TImporto val(real2imp(ivaind, 'I'));
|
||||
TBill contoivaind;
|
||||
|
||||
_caus->bill(RIGA_IVA_NON_DETRAIBILE, contoivaind);
|
||||
if (newposiva < 0)
|
||||
{
|
||||
const TString80 d(_caus->desc_agg(RIGA_IVA_NON_DETRAIBILE));
|
||||
|
||||
newposiva = set_cg_rec(-1, val, contoivaind, d, 'N');
|
||||
}
|
||||
else
|
||||
add_cg_rec(newposiva, val);
|
||||
}
|
||||
}
|
||||
|
||||
void TMovimentoPN_VE::add_row_re(int i)
|
||||
{
|
||||
TRectype& cur = iva(i);
|
||||
real oldimp = cur.get_real(RMI_IMPONIBILE);
|
||||
real oldiva = cur.get_real(RMI_IMPOSTA);
|
||||
|
||||
const char tipod = detraibile(cur) ? 'D' : 'N';
|
||||
real imponibile = cur.get_real(RMI_IMPONIBILE);
|
||||
real imposta = cur.get_real(RMI_IMPOSTA);
|
||||
const int anno = lfile().curr().get_date(MOV_DATAREG).year();
|
||||
const TString4 tipodet = cur.get(RMI_TIPODET);
|
||||
const TString4 zanicchi(cur.get(RMI_CODIVA)); // Codice IVA
|
||||
real imp, impind, iva, ivaind;
|
||||
|
||||
TBill c;
|
||||
if (tipod == 'N' && !oldiva.is_zero())
|
||||
analizza_riga_IVA(imponibile, imposta, *_caus, anno, zanicchi, tipodet, imp, iva, impind, ivaind);
|
||||
imponibile = imp + impind;
|
||||
if (!ivaind.is_zero())
|
||||
{
|
||||
_caus->bill(RIGA_IVA_NON_DETRAIBILE, c);
|
||||
if (c.ok())
|
||||
{
|
||||
int ivapos = bill2pos(c, 'I');
|
||||
if (ivapos < 0)
|
||||
ivapos= set_cg_rec(-1, real2imp(ZERO, 'I'), c, "", 'I');
|
||||
|
||||
const TImporto val(real2imp(oldiva, 'I'));
|
||||
add_cg_rec(ivapos, val);
|
||||
}
|
||||
TBill contoivaind;
|
||||
|
||||
_caus->bill(RIGA_IVA_NON_DETRAIBILE, contoivaind);
|
||||
const TImporto val(real2imp(ivaind, 'I'));
|
||||
int ivapos = bill2pos(contoivaind, 'I');
|
||||
|
||||
if (ivapos < 0)
|
||||
set_cg_rec(-1, val, contoivaind, "", 'I');
|
||||
else
|
||||
oldimp += oldiva;
|
||||
add_cg_rec(ivapos, val);
|
||||
}
|
||||
|
||||
const int gr = cur.get_int(RMI_GRUPPO);
|
||||
const int co = cur.get_int(RMI_CONTO);
|
||||
const long so = cur.get_long(RMI_SOTTOCONTO);
|
||||
c.set(gr,co,so);
|
||||
if (c.ok())
|
||||
const TBill conto(cur);
|
||||
int newpos = bill2pos(conto, ' '); // Riga in cui andra' l'imponibile
|
||||
|
||||
if (conto.ok() && !imponibile.is_zero())
|
||||
{
|
||||
int poscg = bill2pos(c, ' ');
|
||||
if (poscg < 0)
|
||||
poscg = set_cg_rec(-1, real2imp(ZERO, 'I'), c, _caus->desc_agg(2), ' ');
|
||||
|
||||
const TImporto val(real2imp(oldimp, 'I'));
|
||||
add_cg_rec(poscg, val);
|
||||
const TImporto val(real2imp(imponibile, 'I'));
|
||||
|
||||
if (newpos < 0)
|
||||
set_cg_rec(-1, val, conto, _caus->desc_agg(2), ' ');
|
||||
else
|
||||
add_cg_rec(newpos, val);
|
||||
}
|
||||
}
|
||||
|
||||
@ -481,10 +434,7 @@ int TMovimentoPN_VE::recalc_cg_rows(const TString & descr_cr, TCausale & caus)
|
||||
|
||||
set_caus(&caus);
|
||||
for (int i=0; i<righe; i++)
|
||||
{
|
||||
create_row(i, descr_cr);
|
||||
enter_row(i, descr_cr);
|
||||
}
|
||||
bool ok = true;
|
||||
if (_caus->intra() && _caus->iva() == iva_acquisti)
|
||||
{
|
||||
@ -633,7 +583,6 @@ error_type TIVA_array::add(const TRiga_documento& r, const TBill& conto, const i
|
||||
TBill c(conto);
|
||||
int ord = 0;
|
||||
int detr = 0;
|
||||
real pind = ZERO;
|
||||
real impon;
|
||||
const bool sconto_lordo = t.tipo() != RIGA_SCONTI && _contsclor && _sco_perc_bill.ok();
|
||||
const int firmdec = TCurrency::get_firm_dec();
|
||||
@ -723,18 +672,6 @@ error_type TIVA_array::add(const TRiga_documento& r, const TBill& conto, const i
|
||||
|
||||
real imposta = tiva.imposta(impon, ndec);
|
||||
|
||||
if (_caus->iva() == iva_acquisti || _caus->iva() == nessuna_iva)
|
||||
{
|
||||
detr = t.detraibilita();
|
||||
pind = t.perc_indetraibilita();
|
||||
}
|
||||
|
||||
real impres = (impon * pind) / CENTO;
|
||||
real ivares = (imposta * pind) / CENTO;
|
||||
|
||||
impres.round(firmdec); // was ndec
|
||||
ivares.round(firmdec); // was ndec
|
||||
|
||||
// Le righe di sconto ad importo o percentuale vanno saltate
|
||||
// Casistica sulle righe omaggio:
|
||||
// quelle che non hanno addebito IVA devono venire scartate, quelle che hanno
|
||||
@ -742,60 +679,32 @@ error_type TIVA_array::add(const TRiga_documento& r, const TBill& conto, const i
|
||||
// una riga IVA con lo stesso imponibile ma di segno opposto, con un cod. IVA
|
||||
// speciale per lo storno, proveniente da configurazione
|
||||
|
||||
if (pind < CENTO)
|
||||
{
|
||||
key.format("%d|%-4s|%c|%3d|%3d|%6ld|%d",
|
||||
ord,(const char*)cod,c.tipo(),c.gruppo(),c.conto(),c.sottoconto(), 0);
|
||||
TRectype * iva = (TRectype *) objptr(key);
|
||||
|
||||
if (iva == NULL)
|
||||
{
|
||||
iva = new TRectype(LF_RMOVIVA);
|
||||
iva->put(RMI_CODIVA,cod);
|
||||
iva->put(RMI_TIPOCR,c.tipo_cr());
|
||||
iva->put(RMI_INTRA, _caus->intra());
|
||||
iva->put(RMI_TIPOC, c.tipo());
|
||||
iva->put(RMI_GRUPPO, c.gruppo());
|
||||
iva->put(RMI_CONTO, c.conto());
|
||||
iva->put(RMI_SOTTOCONTO, c.sottoconto());
|
||||
TAssoc_array::add(key, iva, true);
|
||||
}
|
||||
real val = iva->get_real(RMI_IMPONIBILE);
|
||||
const TString4 tipodet(r.get(RDOC_TIPODET));
|
||||
|
||||
val += (impon - impres);
|
||||
iva->put(RMI_IMPONIBILE,val);
|
||||
val = iva->get_real(RMI_IMPOSTA);
|
||||
val += (imposta - ivares);
|
||||
iva->put(RMI_IMPOSTA, val);
|
||||
key.format("%d|%-4s|%c|%3d|%3d|%6ld|%s",
|
||||
ord,(const char*)cod,c.tipo(),c.gruppo(),c.conto(),c.sottoconto(), (const char *) tipodet);
|
||||
TRectype * iva = (TRectype *) objptr(key);
|
||||
|
||||
}
|
||||
if (pind > ZERO)
|
||||
if (iva == NULL)
|
||||
{
|
||||
key.format("%d|%-4s|%c|%3d|%3d|%6ld|%d",ord,
|
||||
(const char*)cod,c.tipo(),c.gruppo(),c.conto(),c.sottoconto(), detr);
|
||||
TRectype * iva = (TRectype *) objptr(key);
|
||||
|
||||
if (iva == NULL)
|
||||
{
|
||||
iva = new TRectype(LF_RMOVIVA);
|
||||
iva->put(RMI_CODIVA,cod);
|
||||
iva->put(RMI_TIPOCR,c.tipo_cr());
|
||||
iva->put(RMI_INTRA, _caus->intra());
|
||||
iva->put(RMI_TIPOC, c.tipo());
|
||||
iva->put(RMI_GRUPPO, c.gruppo());
|
||||
iva->put(RMI_CONTO, c.conto());
|
||||
iva->put(RMI_SOTTOCONTO, c.sottoconto());
|
||||
iva->put(RMI_TIPODET, detr);
|
||||
TAssoc_array::add(key, iva, true);
|
||||
}
|
||||
real val = iva->get_real(RMI_IMPONIBILE);
|
||||
|
||||
val += impres;
|
||||
iva->put(RMI_IMPONIBILE,val);
|
||||
val = iva->get_real(RMI_IMPOSTA);
|
||||
val += ivares;
|
||||
iva->put(RMI_IMPOSTA, val);
|
||||
iva = new TRectype(LF_RMOVIVA);
|
||||
iva->put(RMI_CODIVA,cod);
|
||||
iva->put(RMI_TIPOCR,c.tipo_cr());
|
||||
iva->put(RMI_INTRA, _caus->intra());
|
||||
iva->put(RMI_TIPOC, c.tipo());
|
||||
iva->put(RMI_GRUPPO, c.gruppo());
|
||||
iva->put(RMI_CONTO, c.conto());
|
||||
iva->put(RMI_SOTTOCONTO, c.sottoconto());
|
||||
TAssoc_array::add(key, iva, true);
|
||||
}
|
||||
real val = iva->get_real(RMI_IMPONIBILE);
|
||||
|
||||
val += impon;
|
||||
iva->put(RMI_IMPONIBILE, val);
|
||||
iva->put(RMI_TIPODET, tipodet);
|
||||
val = iva->get_real(RMI_IMPOSTA);
|
||||
val += imposta;
|
||||
iva->put(RMI_IMPOSTA, val);
|
||||
if (ord != 5)
|
||||
{
|
||||
if (sconto_lordo) // Se e' settato il flag di contabilizzare anche gli sconti merce
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "../ca/movana.h"
|
||||
#include "../ca/rmovana.h"
|
||||
#include "../ca/rrip.h"
|
||||
#include "../cg/cg2101.h"
|
||||
#include "../cg/cg2103.h"
|
||||
#include "../mg/anamag.h"
|
||||
|
||||
@ -59,16 +60,16 @@ const TCausale& TCache_causali::causale(const TDocumento& doc, const TString & f
|
||||
}
|
||||
if (codcaus.blank())
|
||||
{
|
||||
// Cerca il codice causale sul cliente
|
||||
const char* const fld = doc.is_nota_credito() ? CFV_CODCAUSNC : CFV_CODCAUS;
|
||||
// Cerca il codice causale sul cliente
|
||||
const char* const fld = doc.is_nota_credito() ? CFV_CODCAUSNC : CFV_CODCAUS;
|
||||
|
||||
key.format("%c|%ld", doc.get_char(DOC_TIPOCF), doc.get_long(DOC_CODCF));
|
||||
key.format("%c|%ld", doc.get_char(DOC_TIPOCF), doc.get_long(DOC_CODCF));
|
||||
codcaus = cache().get(LF_CFVEN, key, fld);
|
||||
if (codcaus.blank()) // Se non lo trova guarda sul tipo documento
|
||||
{
|
||||
const TTipo_documento& tipo = doc.tipo();
|
||||
codcaus = tipo.causale();
|
||||
}
|
||||
if (codcaus.blank()) // Se non lo trova guarda sul tipo documento
|
||||
{
|
||||
const TTipo_documento& tipo = doc.tipo();
|
||||
codcaus = tipo.causale();
|
||||
}
|
||||
}
|
||||
|
||||
//Assegna l'anno della causale
|
||||
@ -326,12 +327,12 @@ bool TContabilizzazione_analitica::search_costo_ricavo(const TRiga_documento& r,
|
||||
return conto.ok() && conto.find();
|
||||
}
|
||||
|
||||
bool TContabilizzazione_analitica::find_conti_iva_indetraibile(const TRiga_documento& riga, const TBill & bill, TString_array& conti)
|
||||
bool TContabilizzazione_analitica::find_conti_iva_indetraibile(const TRiga_documento& riga, const TBill & bill, TString_array& conti, int annoes)
|
||||
{
|
||||
const TString80 riga_cos = riga.codice_costo();
|
||||
const TString80 riga_cms = riga.codice_commessa();
|
||||
const TString16 riga_fsc = riga.fase_commessa();
|
||||
const int annoes = riga.get_int(RDOC_ANNO);
|
||||
// const int annoes = riga.get_int(RDOC_ANNO);
|
||||
const bool riga_any = riga_cos.full() || riga_cms.full() || riga_fsc.full();
|
||||
|
||||
TToken_string conto;
|
||||
@ -374,7 +375,7 @@ bool TContabilizzazione_analitica::find_conti_iva_indetraibile(const TRiga_docum
|
||||
return !conti.empty();
|
||||
}
|
||||
|
||||
bool TContabilizzazione_analitica::find_conti(const TRiga_documento& riga, TString_array& conti)
|
||||
bool TContabilizzazione_analitica::find_conti(const TRiga_documento& riga, TString_array& conti, int annoes)
|
||||
{
|
||||
bool bArcticleFound = false;
|
||||
|
||||
@ -431,7 +432,7 @@ bool TContabilizzazione_analitica::find_conti(const TRiga_documento& riga, TStri
|
||||
const TString80 riga_cos = riga.codice_costo();
|
||||
const TString80 riga_cms = riga.codice_commessa();
|
||||
const TString16 riga_fsc = riga.fase_commessa();
|
||||
const int annoes = riga.get_int(RDOC_ANNO);
|
||||
// const int annoes = riga.get_int(RDOC_ANNO);
|
||||
const bool riga_any = riga_cos.not_empty() || riga_cms.not_empty() || riga_fsc.not_empty();
|
||||
|
||||
if (contanal.blank()) // Non ho trovato il conto in anagrafica ...
|
||||
@ -591,15 +592,10 @@ bool TContabilizzazione_analitica::elabora(TDocumento& doc, long numreg_cg, TVis
|
||||
|
||||
if (tiva != iva_vendite && !riga.is_sconto())
|
||||
{
|
||||
real pind = ZERO;
|
||||
if (tiva != nessuna_iva)
|
||||
{
|
||||
const int annodoc = doc.get_date(DOC_DATADOC).year();
|
||||
if (caus.reg().prorata100(annodoc))
|
||||
pind = CENTO;
|
||||
}
|
||||
if (pind == ZERO)
|
||||
pind = riga.tipo().perc_indetraibilita();
|
||||
const TString4 tipodet = riga.get(RDOC_TIPODET);
|
||||
int td;
|
||||
const real pind = indetraibile_al(tipodet, caus, datareg.year(), td);
|
||||
|
||||
if (pind > ZERO)
|
||||
{
|
||||
const real ivaind = (riga.imposta(false) * pind) / CENTO;
|
||||
@ -608,7 +604,7 @@ bool TContabilizzazione_analitica::elabora(TDocumento& doc, long numreg_cg, TVis
|
||||
if (bill.is_analitico())
|
||||
{
|
||||
TString_array conti_ind;
|
||||
if (find_conti_iva_indetraibile(riga, bill, conti_ind)) //qui
|
||||
if (find_conti_iva_indetraibile(riga, bill, conti_ind,annoes)) //qui
|
||||
{
|
||||
TGeneric_distrib esso(ivaind, decimals);
|
||||
|
||||
@ -642,7 +638,7 @@ bool TContabilizzazione_analitica::elabora(TDocumento& doc, long numreg_cg, TVis
|
||||
continue;
|
||||
|
||||
TString_array conti;
|
||||
const bool ok = find_conti(riga, conti);
|
||||
const bool ok = find_conti(riga, conti, annoes);
|
||||
if (!ok)
|
||||
{
|
||||
if (viswin != NULL)
|
||||
|
Loading…
x
Reference in New Issue
Block a user