275 lines
9.6 KiB
Java
275 lines
9.6 KiB
Java
package it.acxent.contab.iva;
|
|
|
|
import it.acxent.anag.Iva;
|
|
import it.acxent.anag.IvaInterface;
|
|
import it.acxent.contab.RigaDocumentoInterface;
|
|
import it.acxent.util.DoubleOperator;
|
|
import java.util.Enumeration;
|
|
import java.util.Hashtable;
|
|
|
|
public class RigheRegistroIva implements Cloneable {
|
|
private Hashtable<String, RigaRegistroIvaItem> ri;
|
|
|
|
private DoubleOperator totImponibileDO;
|
|
|
|
private double importoRM;
|
|
|
|
private Hashtable<String, RigaRegistroIvaItem> riFatt;
|
|
|
|
public void addRigaDocumento(Iva l_iva, double imponibile) {
|
|
DoubleOperator dop = new DoubleOperator(imponibile);
|
|
dop.setScale(4, 5);
|
|
dop.multiply(l_iva.getAliquota());
|
|
dop.divide(100.0F);
|
|
dop.setScale(2, 5);
|
|
addRigaDocumento(l_iva, imponibile, dop.getResult(), false, false);
|
|
}
|
|
|
|
public void addRigaDocumento(RigaDocumentoInterface rigaDocumento) {
|
|
RigaRegistroIvaItem rii;
|
|
if (!rigaDocumento.getIva().isRegimeMargine()) {
|
|
String str = String.valueOf(rigaDocumento.getIva().getId_iva());
|
|
if (getRi().containsKey(str)) {
|
|
rii = getRi().get(str);
|
|
} else {
|
|
rii = new RigaRegistroIvaItem(rigaDocumento.getIva());
|
|
}
|
|
rii.addImporto(rigaDocumento.getRDITotImponibile(), rigaDocumento.getRDITotImposta());
|
|
getTotImponibileDO().add(rigaDocumento.getRDITotImponibile());
|
|
rii.setFEEsigibilitaIva(rigaDocumento.getFEEsigibilitaIva());
|
|
getRi().put(str, rii);
|
|
} else {
|
|
RigaRegistroIvaItem rigaRegistroIvaItem;
|
|
Iva ivaStdVend = rigaDocumento.getIva().getIvaStdRM();
|
|
RegimeMargine rm = new RegimeMargine(ivaStdVend, rigaDocumento.getRDITotImponibile(), rigaDocumento.getRDITotCosto());
|
|
String theKeyStdVend = String.valueOf(ivaStdVend.getId_iva());
|
|
if (getRi().containsKey(theKeyStdVend)) {
|
|
rigaRegistroIvaItem = getRi().get(theKeyStdVend);
|
|
} else {
|
|
rigaRegistroIvaItem = new RigaRegistroIvaItem(ivaStdVend);
|
|
}
|
|
rigaRegistroIvaItem.setFEEsigibilitaIva(rigaDocumento.getFEEsigibilitaIva());
|
|
rigaRegistroIvaItem.addImporto(rm.getImponibileMargine(), rm.getImpostaMargine());
|
|
rigaRegistroIvaItem.setRegimeDelMargine(true);
|
|
getRi().put(theKeyStdVend, rigaRegistroIvaItem);
|
|
getTotImponibileDO().add(rm.getImponibileMargine());
|
|
String rm_theKey = String.valueOf(rigaDocumento.getIva().getId_iva());
|
|
if (getRi().containsKey(rm_theKey)) {
|
|
rigaRegistroIvaItem = getRi().get(rm_theKey);
|
|
} else {
|
|
rigaRegistroIvaItem = new RigaRegistroIvaItem(rigaDocumento.getIva());
|
|
}
|
|
rigaRegistroIvaItem.setFEEsigibilitaIva(rigaDocumento.getFEEsigibilitaIva());
|
|
rigaRegistroIvaItem.addImporto(rigaDocumento.getRDITotCosto(), 0.0D);
|
|
rigaRegistroIvaItem.setRegimeDelMargine(true);
|
|
getTotImponibileDO().add(rigaDocumento.getRDITotCosto());
|
|
getRi().put(rm_theKey, rigaRegistroIvaItem);
|
|
}
|
|
String theKey = String.valueOf(rigaDocumento.getIva().getId_iva());
|
|
if (getRiFatt().containsKey(theKey)) {
|
|
rii = getRiFatt().get(theKey);
|
|
} else {
|
|
rii = new RigaRegistroIvaItem(rigaDocumento.getIva());
|
|
}
|
|
rii.addImporto(rigaDocumento.getRDITotImponibile(), rigaDocumento.getRDITotImposta());
|
|
getRiFatt().put(theKey, rii);
|
|
}
|
|
|
|
public Enumeration<RigaRegistroIvaItem> elements() {
|
|
return getRi().elements();
|
|
}
|
|
|
|
public Enumeration elementsNoType() {
|
|
return getRi().elements();
|
|
}
|
|
|
|
public Enumeration<RigaRegistroIvaItem> elementsFatt() {
|
|
return getRiFatt().elements();
|
|
}
|
|
|
|
public Enumeration elementsFattNoType() {
|
|
return getRiFatt().elements();
|
|
}
|
|
|
|
private Hashtable<String, RigaRegistroIvaItem> getRi() {
|
|
if (this.ri == null)
|
|
this.ri = new Hashtable<>();
|
|
return this.ri;
|
|
}
|
|
|
|
public double getImportoRM() {
|
|
return this.importoRM;
|
|
}
|
|
|
|
public void setImportoRM(double importoRM) {
|
|
this.importoRM = importoRM;
|
|
}
|
|
|
|
private void addRigaDocumentoRM(Iva l_iva, double imponibile, double imposta, double costo) {
|
|
String theKey = String.valueOf(l_iva.getId_iva());
|
|
if (!l_iva.getFlgTipo().equals("R")) {
|
|
RigaRegistroIvaItem rii;
|
|
if (getRi().containsKey(theKey)) {
|
|
rii = getRi().get(theKey);
|
|
} else {
|
|
rii = new RigaRegistroIvaItem(l_iva);
|
|
}
|
|
rii.addImporto(imponibile, imposta);
|
|
getTotImponibileDO().add(imponibile);
|
|
getRi().put(theKey, rii);
|
|
} else {
|
|
synchronized (this) {
|
|
RigaRegistroIvaItem rii;
|
|
DoubleOperator dop = new DoubleOperator(this.importoRM);
|
|
dop.add(imponibile);
|
|
this.importoRM = dop.getResult();
|
|
double l_imponibile = 0.0D;
|
|
if (getRi().containsKey(theKey)) {
|
|
rii = getRi().get(theKey);
|
|
} else {
|
|
rii = new RigaRegistroIvaItem(l_iva);
|
|
}
|
|
DoubleOperator impo = new DoubleOperator(imponibile);
|
|
DoubleOperator temp2 = new DoubleOperator((float)-l_iva.getAliquota());
|
|
temp2.divide(100.0F);
|
|
temp2.add(1);
|
|
impo.subtract(costo);
|
|
DoubleOperator l_imposta = new DoubleOperator(impo.getResult());
|
|
impo.setScale(4, 5);
|
|
impo.multiply(temp2);
|
|
l_imponibile = impo.getResult();
|
|
l_imposta.subtract(l_imponibile);
|
|
rii.addImporto(l_imponibile, l_imposta.getResult());
|
|
getTotImponibileDO().add(l_imponibile);
|
|
getRi().put(theKey, rii);
|
|
long l_id_ivaEs = l_iva.getParm("CODICE_IVA_REGIME_MARGINE").getNumeroLong();
|
|
if (l_id_ivaEs == 0L)
|
|
l_id_ivaEs = l_iva.getId_iva();
|
|
String es_theKey = String.valueOf(l_id_ivaEs);
|
|
if (getRi().containsKey(es_theKey)) {
|
|
rii = getRi().get(es_theKey);
|
|
} else {
|
|
Iva ivaEs = new Iva(l_iva.getApFull());
|
|
ivaEs.findByPrimaryKey(l_id_ivaEs);
|
|
rii = new RigaRegistroIvaItem(ivaEs);
|
|
}
|
|
rii.addImporto(costo, 0.0D);
|
|
getRi().put(es_theKey, rii);
|
|
}
|
|
}
|
|
}
|
|
|
|
private DoubleOperator getTotImponibileDO() {
|
|
if (this.totImponibileDO == null) {
|
|
this.totImponibileDO = new DoubleOperator();
|
|
this.totImponibileDO.setScale(4, 5);
|
|
}
|
|
return this.totImponibileDO;
|
|
}
|
|
|
|
public double getTotale() {
|
|
DoubleOperator dop = new DoubleOperator(getTotImponibile());
|
|
dop.add(getTotIva());
|
|
return dop.getResult();
|
|
}
|
|
|
|
public double getTotIva() {
|
|
Enumeration<RigaRegistroIvaItem> enu = getRi().elements();
|
|
DoubleOperator dIva = new DoubleOperator();
|
|
dIva.setScale(4, 5);
|
|
while (enu.hasMoreElements()) {
|
|
RigaRegistroIvaItem row = enu.nextElement();
|
|
dIva.add(row.getImportoIva());
|
|
}
|
|
dIva.setScale(2, 5);
|
|
return dIva.getResult();
|
|
}
|
|
|
|
public double getTotImponibile() {
|
|
return getTotImponibileDO().getResult();
|
|
}
|
|
|
|
public void addRigaDocumento(IvaInterface l_iva, double imponibile, double imposta, boolean isNotaDiCredito, boolean isPartitaIva) {
|
|
RigaRegistroIvaItem rii;
|
|
String theKey = String.valueOf(l_iva.getId_iva());
|
|
if (getRi().containsKey(theKey)) {
|
|
rii = getRi().get(theKey);
|
|
} else {
|
|
rii = new RigaRegistroIvaItem(l_iva);
|
|
}
|
|
rii.addImporto(imponibile, imposta);
|
|
getTotImponibileDO().add(imponibile);
|
|
getRi().put(theKey, rii);
|
|
if (getRiFatt().containsKey(theKey)) {
|
|
rii = getRiFatt().get(theKey);
|
|
} else {
|
|
rii = new RigaRegistroIvaItem(l_iva);
|
|
}
|
|
rii.addImporto(imponibile, imposta);
|
|
getRiFatt().put(theKey, rii);
|
|
}
|
|
|
|
protected Object clone() throws CloneNotSupportedException {
|
|
return super.clone();
|
|
}
|
|
|
|
private void addRigaDocumentoRMOLD(Iva l_iva, double imponibile, double imposta, double costo) {
|
|
String theKey = String.valueOf(l_iva.getId_iva());
|
|
if (!l_iva.getFlgTipo().equals("R")) {
|
|
RigaRegistroIvaItem rii;
|
|
if (getRi().containsKey(theKey)) {
|
|
rii = getRi().get(theKey);
|
|
} else {
|
|
rii = new RigaRegistroIvaItem(l_iva);
|
|
}
|
|
rii.addImporto(imponibile, imposta);
|
|
getTotImponibileDO().add(imponibile);
|
|
getRi().put(theKey, rii);
|
|
} else {
|
|
synchronized (this) {
|
|
RigaRegistroIvaItem rii;
|
|
DoubleOperator dop = new DoubleOperator(this.importoRM);
|
|
dop.add(imponibile);
|
|
this.importoRM = dop.getResult();
|
|
double l_imponibile = 0.0D;
|
|
if (getRi().containsKey(theKey)) {
|
|
rii = getRi().get(theKey);
|
|
} else {
|
|
rii = new RigaRegistroIvaItem(l_iva);
|
|
}
|
|
DoubleOperator impo = new DoubleOperator(imponibile);
|
|
DoubleOperator temp2 = new DoubleOperator((float)-l_iva.getAliquota());
|
|
temp2.divide(100.0F);
|
|
temp2.add(1);
|
|
impo.subtract(costo);
|
|
DoubleOperator l_imposta = new DoubleOperator(impo.getResult());
|
|
impo.setScale(4, 5);
|
|
impo.multiply(temp2);
|
|
l_imponibile = impo.getResult();
|
|
l_imposta.subtract(l_imponibile);
|
|
rii.addImporto(l_imponibile, l_imposta.getResult());
|
|
getTotImponibileDO().add(l_imponibile);
|
|
getRi().put(theKey, rii);
|
|
long l_id_ivaEs = l_iva.getParm("CODICE_IVA_REGIME_MARGINE").getNumeroLong();
|
|
if (l_id_ivaEs == 0L)
|
|
l_id_ivaEs = l_iva.getId_iva();
|
|
String es_theKey = String.valueOf(l_id_ivaEs);
|
|
if (getRi().containsKey(es_theKey)) {
|
|
rii = getRi().get(es_theKey);
|
|
} else {
|
|
Iva ivaEs = new Iva(l_iva.getApFull());
|
|
ivaEs.findByPrimaryKey(l_id_ivaEs);
|
|
rii = new RigaRegistroIvaItem(ivaEs);
|
|
}
|
|
rii.addImporto(costo, 0.0D);
|
|
getRi().put(es_theKey, rii);
|
|
}
|
|
}
|
|
}
|
|
|
|
private Hashtable<String, RigaRegistroIvaItem> getRiFatt() {
|
|
if (this.riFatt == null)
|
|
this.riFatt = new Hashtable<>();
|
|
return this.riFatt;
|
|
}
|
|
}
|