From 509e18f8d8d613d63bc45a2432ac6d93d03e1c11 Mon Sep 17 00:00:00 2001 From: Yamel Senih Date: Fri, 2 Sep 2022 17:45:54 -0400 Subject: [PATCH] =?UTF-8?q?-=20Se=20corrige=20problema=20al=20generar=20re?= =?UTF-8?q?tenci=C3=B3n=20de=20manera=20autom=C3=A1tica=20desde=20el=20ter?= =?UTF-8?q?minal=20de=20punto=20de=20ventas=20-=20Se=20agrega=20evento=20p?= =?UTF-8?q?ara=20procesar=20orden=20de=20venta=20y=20generar=20retenci?= =?UTF-8?q?=C3=B3n=20de=20manera=20autom=C3=A1tica?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- .../lve/setup/WithholdingPOSIVASetup.java | 4 + .../erpya/lve/util/POSOrderIVAProcess.java | 134 ++++++++++++++++++ 3 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 withholding/src/main/java/base/org/erpya/lve/util/POSOrderIVAProcess.java diff --git a/build.gradle b/build.gradle index bcf167e..b2f06de 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ if (JavaVersion.current().isJava8Compatible()) { } dependencies { - api 'io.github.adempiere:withholding-engine:1.2.6' + api 'io.github.adempiere:withholding-engine:1.2.8' compileOnly fileTree(dir: 'dependences', include: ['*.jar']) compileOnly fileTree(dir: 'lib', include: ['*.jar']) } diff --git a/withholding/src/main/java/base/org/erpya/lve/setup/WithholdingPOSIVASetup.java b/withholding/src/main/java/base/org/erpya/lve/setup/WithholdingPOSIVASetup.java index c7da32c..7993126 100644 --- a/withholding/src/main/java/base/org/erpya/lve/setup/WithholdingPOSIVASetup.java +++ b/withholding/src/main/java/base/org/erpya/lve/setup/WithholdingPOSIVASetup.java @@ -102,6 +102,10 @@ private void setupWithholding() { if(createSettingWithEvent(withHolgingType.getWH_Type_ID(), org.erpya.lve.util.POSOrderIVAChange.class.getName(), MWHSetting.EVENTMODELVALIDATOR_TableBeforeChange, I_C_Order.Table_ID, "IVA-Orden-Modificar", "Retención I.V.A Antes de odificar Orden de Venta", maxSequence)) { maxSequence += 10; } + // Order Process + if(createSettingWithEvent(withHolgingType.getWH_Type_ID(),org.erpya.lve.util.POSOrderIVAProcess.class.getName(), MWHSetting.EVENTMODELVALIDATOR_DocumentAfterComplete, I_C_Order.Table_ID, "IVA-Orden-Procesar", "Retención I.V.A Después de Procesar Orden de Venta", maxSequence)) { + maxSequence += 10; + } // Payment Method createPaymentMethod(withHolgingType.getWH_Type_ID()); } diff --git a/withholding/src/main/java/base/org/erpya/lve/util/POSOrderIVAProcess.java b/withholding/src/main/java/base/org/erpya/lve/util/POSOrderIVAProcess.java new file mode 100644 index 0000000..3857ff5 --- /dev/null +++ b/withholding/src/main/java/base/org/erpya/lve/util/POSOrderIVAProcess.java @@ -0,0 +1,134 @@ +/************************************************************************************* + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 2012-2018 E.R.P. Consultores y Asociados, C.A. * + * Contributor(s): Yamel Senih ysenih@erpya.com * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + ************************************************************************************/ +package org.erpya.lve.util; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +import org.compiere.model.I_C_Order; +import org.compiere.model.MOrder; +import org.compiere.model.MPayment; +import org.compiere.model.MTable; +import org.compiere.model.PO; +import org.compiere.model.Query; +import org.compiere.util.Util; +import org.spin.model.I_WH_Withholding; +import org.spin.model.MWHSetting; +import org.spin.model.MWHWithholding; +import org.spin.util.AbstractWithholdingSetting; + +/** + * Implementación de retención de I.V.A. para la localización de Venezuela + * Esto aplica para cuando se completa una orden de ventas + * generada desde un Punto de Ventas y que posee pagos y referencias de IVA + * @author Yamel Senih, ysenih@erpya.com, ERPCyA http://www.erpya.com + * @contributor Carlos Parada, cparada@erpya.com, ERPCyA http://www.erpya.com + */ +public class POSOrderIVAProcess extends AbstractWithholdingSetting { + + /** References */ + private List paymentReferences = new ArrayList(); + /** Current order */ + private MOrder order; + /** Event */ + private String event; + + public MOrder getOrder() { + return order; + } + + public POSOrderIVAProcess(MWHSetting setting) { + super(setting); + } + + public String getEvent() { + return event; + } + + public List getPaymentReferences() { + return paymentReferences; + } + + @Override + public boolean isValid() { + if(getDocument().get_ValueAsInt(I_C_Order.COLUMNNAME_C_POS_ID) <= 0) { + return false; + } + event = getSetting().getEventModelValidator(); + if(Util.isEmpty(event)) { + return false; + } + // Validate Document + if(getDocument().get_Table_ID() != I_C_Order.Table_ID) { + return false; + } + order = (MOrder) getDocument(); + MTable paymentReferenceDefinition = MTable.get(getContext(), "C_POSPaymentReference"); + if(paymentReferenceDefinition == null) { + return false; + } + fillReferences(); + if(paymentReferences.size() <= 0) { + return false; + } + // Default + return true; + } + + /** + * Fill References from order + */ + private void fillReferences() { + paymentReferences = new Query(getContext(), "C_POSPaymentReference", + "C_Order_ID = ? AND TenderType = ? " + + "AND EXISTS(SELECT 1 FROM C_PaymentMethod pm " + + "WHERE pm.C_PaymentMethod_ID = C_POSPaymentReference.C_PaymentMethod_ID " + + "AND pm.IsWithholdingExempt = 'N' " + + "AND pm.WH_Type_ID = ?)", getTransactionName()) + .setParameters(order.getC_Order_ID(), MPayment.TENDERTYPE_CreditMemo, getSetting().getWH_Type_ID()) + .getIDsAsList(); + } + + @Override + public String run() { + MTable paymentReferenceDefinition = MTable.get(getContext(), "C_POSPaymentReference"); + if(paymentReferenceDefinition != null) { + int invoiceId = order.getC_Invoice_ID(); + paymentReferences.forEach(paymentReferenceId -> { + PO paymentReference = paymentReferenceDefinition.getPO(paymentReferenceId, getTransactionName()); + setWithholdingRate((BigDecimal) paymentReference.get_Value("Rate")); + addBaseAmount((BigDecimal) paymentReference.get_Value("Base")); + addWithholdingAmount((BigDecimal) paymentReference.get_Value("Amount")); + setReturnValue(I_WH_Withholding.COLUMNNAME_C_Currency_ID, paymentReference.get_ValueAsInt("C_Currency_ID")); + setReturnValue(I_WH_Withholding.COLUMNNAME_C_ConversionType_ID, paymentReference.get_ValueAsInt("C_ConversionType_ID")); + addDescription(paymentReference.get_ValueAsString("Description")); + setReturnValue(MWHWithholding.COLUMNNAME_IsManual, true); + setReturnValue(I_WH_Withholding.COLUMNNAME_DateAcct, paymentReference.get_Value("PayDate")); + if(invoiceId > 0) { + setReturnValue(I_WH_Withholding.COLUMNNAME_SourceInvoice_ID, invoiceId); + } + saveResult(); + paymentReferenceDefinition.set_ValueOfColumn("IsPaid", true); + paymentReferenceDefinition.set_ValueOfColumn("Processed", true); + paymentReferenceDefinition.saveEx(); + }); + } + return null; + } +} + +