Skip to content

Commit

Permalink
Se agrega soporte para asignación de retenciones generadas desde el
Browse files Browse the repository at this point in the history
Punto de Ventas y con carga de comprobante desde el Punto de Ventas
  • Loading branch information
yamelsenih committed Sep 3, 2022
1 parent 509e18f commit 7600c15
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Properties;

import org.compiere.model.I_C_Invoice;
import org.compiere.model.I_C_Order;
import org.compiere.model.I_C_OrderLine;
import org.compiere.model.I_C_POS;
Expand Down Expand Up @@ -106,6 +107,10 @@ private void setupWithholding() {
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;
}
// After process withholding document
if(createSettingWithEvent(withHolgingType.getWH_Type_ID(),org.erpya.lve.util.POSWihholdingIVAProcess.class.getName(), MWHSetting.EVENTMODELVALIDATOR_DocumentBeforeComplete, I_C_Invoice.Table_ID, "IVA-Comprobante-Procesar", "Retención I.V.A Antes de Procesar Comprobante de Retención", maxSequence)) {
maxSequence += 10;
}
// Payment Method
createPaymentMethod(withHolgingType.getWH_Type_ID());
}
Expand All @@ -121,35 +126,72 @@ private void createPaymentMethod(int withholdingTypeId) {
if(paymentMethod == null
|| paymentMethod.get_ID() <= 0) {
paymentMethod = MTable.get(context, "C_PaymentMethod").getPO(0, getTrx_Name());
paymentMethod.setAD_Org_ID(0);
paymentMethod.set_ValueOfColumn("TenderType", MPayment.TENDERTYPE_CreditMemo);
paymentMethod.set_ValueOfColumn("Value", "Retencion-IVA");
paymentMethod.set_ValueOfColumn("Name", "Retencion de I.V.A.");
paymentMethod.set_ValueOfColumn("Description", "I.V.A. sobre");
paymentMethod.set_ValueOfColumn("WH_Type_ID", withholdingTypeId);
paymentMethod.saveEx();
}
PO payPaymentMethod = new Query(getCtx(), "C_PaymentMethod", "TenderType = 'M' "
+ "AND Value = ?", getTrx_Name())
.setParameters("Pago-IVA")
.first();
if(payPaymentMethod == null
|| payPaymentMethod.get_ID() <= 0) {
payPaymentMethod.setAD_Org_ID(0);
payPaymentMethod = MTable.get(context, "C_PaymentMethod").getPO(0, getTrx_Name());
payPaymentMethod.set_ValueOfColumn("TenderType", MPayment.TENDERTYPE_CreditMemo);
payPaymentMethod.set_ValueOfColumn("Value", "Pago-IVA");
payPaymentMethod.set_ValueOfColumn("Name", "Pago de I.V.A.");
payPaymentMethod.set_ValueOfColumn("Description", "Pago de I.V.A.");
payPaymentMethod.set_ValueOfColumn("WH_Type_ID", withholdingTypeId);
payPaymentMethod.set_ValueOfColumn("IsWithholdingExempt", true);
payPaymentMethod.saveEx();
}
//
if(MTable.getTable_ID("C_POSPaymentTypeAllocation") <= 0) {
return;
}
int paymentMethodId = paymentMethod.get_ID();
int payPaymentMethodId = payPaymentMethod.get_ID();
// Add for All POS
new Query(getCtx(), I_C_POS.Table_Name, "NOT EXISTS(SELECT 1 FROM C_POSPaymentTypeAllocation pm "
+ "WHERE pm.C_POS_ID = C_POS.C_POS_ID AND pm.C_PaymentMethod_ID = ?)", getTrx_Name())
.setParameters(paymentMethodId)
new Query(getCtx(), I_C_POS.Table_Name, null, getTrx_Name())
.setOnlyActiveRecords(true)
.setClient_ID()
.getIDsAsList()
.forEach(posId -> {
MPOS pos = MPOS.get(getCtx(), posId);
PO allocatedPaymentMethod = MTable.get(getCtx(), "C_POSPaymentTypeAllocation").getPO(0, getTrx_Name());
allocatedPaymentMethod.setAD_Org_ID(pos.getAD_Org_ID());
allocatedPaymentMethod.set_ValueOfColumn("C_POS_ID", posId);
allocatedPaymentMethod.set_ValueOfColumn("C_PaymentMethod_ID", paymentMethodId);
allocatedPaymentMethod.set_ValueOfColumn("IsPaymentReference", true);
allocatedPaymentMethod.set_ValueOfColumn("IsDisplayedFromCollection", false);
allocatedPaymentMethod.set_ValueOfColumn("SeqNo", 999);
allocatedPaymentMethod.saveEx();
PO allocatedPaymentMethod = new Query(getCtx(), "C_POSPaymentTypeAllocation", "C_POS_ID = ? AND C_PaymentMethod_ID = ?" ,getTrx_Name())
.setParameters(posId, paymentMethodId)
.first();
if(allocatedPaymentMethod == null
|| allocatedPaymentMethod.get_ID() <= 0) {
allocatedPaymentMethod.setAD_Org_ID(pos.getAD_Org_ID());
allocatedPaymentMethod.set_ValueOfColumn("C_POS_ID", posId);
allocatedPaymentMethod.set_ValueOfColumn("C_PaymentMethod_ID", paymentMethodId);
allocatedPaymentMethod.set_ValueOfColumn("IsPaymentReference", true);
allocatedPaymentMethod.set_ValueOfColumn("IsDisplayedFromCollection", false);
allocatedPaymentMethod.set_ValueOfColumn("SeqNo", 999);
allocatedPaymentMethod.saveEx();
}
// For payment
PO allocatedPayPaymentMethod = new Query(getCtx(), "C_POSPaymentTypeAllocation", "C_POS_ID = ? AND C_PaymentMethod_ID = ?" ,getTrx_Name())
.setParameters(posId, payPaymentMethodId)
.first();
if(allocatedPayPaymentMethod == null
|| allocatedPayPaymentMethod.get_ID() <= 0) {
allocatedPayPaymentMethod = MTable.get(getCtx(), "C_POSPaymentTypeAllocation").getPO(0, getTrx_Name());
allocatedPayPaymentMethod.setAD_Org_ID(pos.getAD_Org_ID());
allocatedPayPaymentMethod.set_ValueOfColumn("C_POS_ID", posId);
allocatedPayPaymentMethod.set_ValueOfColumn("Name", "Comprobante de I.V.A.");
allocatedPayPaymentMethod.set_ValueOfColumn("C_PaymentMethod_ID", payPaymentMethodId);
allocatedPayPaymentMethod.set_ValueOfColumn("IsPaymentReference", false);
allocatedPayPaymentMethod.set_ValueOfColumn("IsDisplayedFromCollection", true);
allocatedPayPaymentMethod.set_ValueOfColumn("SeqNo", 999);
allocatedPayPaymentMethod.saveEx();
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public PO getDefaultPaymentMethodAllocated() {
}
defaultPaymentMethodallocated = new Query(getContext(), "C_POSPaymentTypeAllocation",
"C_POS_ID = ? "
+ "AND IsPaymentReference = 'Y' "
+ "AND EXISTS(SELECT 1 FROM C_PaymentMethod pm "
+ "WHERE pm.C_PaymentMethod_ID = C_POSPaymentTypeAllocation.C_PaymentMethod_ID "
+ "AND pm.TenderType = ? "
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*************************************************************************************
* 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 <https://www.gnu.org/licenses/>. *
************************************************************************************/
package org.erpya.lve.util;

import java.util.Arrays;

import org.compiere.model.I_C_Invoice;
import org.compiere.model.I_C_Order;
import org.compiere.model.MInvoice;
import org.compiere.model.Query;
import org.compiere.util.Util;
import org.spin.model.MWHDefinition;
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 un comprobante de IVA asociado a un
* 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 POSWihholdingIVAProcess extends AbstractWithholdingSetting {

/** Current Invoice */
private MInvoice withholdingDocument;
/** Wihholding document */
private MWHWithholding withholding;
/** Event */
private String event;

public MInvoice getWithholdingDocument() {
return withholdingDocument;
}

public POSWihholdingIVAProcess(MWHSetting setting) {
super(setting);
}

public String getEvent() {
return event;
}

@Override
public boolean isValid() {
if(getDocument().get_Table_ID() != I_C_Invoice.Table_ID) {
return false;
}
if(getDocument().get_ValueAsInt(I_C_Order.COLUMNNAME_C_POS_ID) <= 0) {
return false;
}
event = getSetting().getEventModelValidator();
if(Util.isEmpty(event)) {
return false;
}
withholdingDocument = (MInvoice) getDocument();
if(getWithholding() == null) {
return false;
}
// Default
return true;
}

@Override
public String run() {
if(getWithholding() != null) {
withholding.setC_Invoice_ID(getWithholdingDocument().getC_Invoice_ID());
withholding.saveEx();
// Set values from withholding
int documentTypeId = withholding.getWHDocType();
if(documentTypeId > 0) {
withholdingDocument.setC_DocTypeTarget_ID(documentTypeId);
withholdingDocument.saveEx();
}
MWHDefinition whDefinition = (MWHDefinition) withholding.getWH_Definition();
MWHSetting whSetting = (MWHSetting) withholding.getWH_Setting();
Arrays.asList(withholdingDocument.getLines(true)).stream().findFirst().ifPresent(withholdingDocumentLine -> {
if (whSetting.getC_Charge_ID() > 0) {
withholdingDocumentLine.setC_Charge_ID(whSetting.getC_Charge_ID());
} else if (whDefinition.getC_Charge_ID() > 0) {
withholdingDocumentLine.setC_Charge_ID(whDefinition.getC_Charge_ID());
}
withholdingDocumentLine.saveEx();
});
}
return null;
}

/**
* Get Withholding from POS
* @return
*/
private MWHWithholding getWithholding() {
if(withholding != null) {
return withholding;
}
if (withholdingDocument != null) {
withholding = new Query(getContext(), MWHWithholding.Table_Name, "SourceInvoice_ID IS NOT NULL "
+ "AND SourceOrder_ID = ? "
+ "AND WH_Definition_ID = ? "
+ "AND Processed = 'Y' "
+ "AND IsSimulation='N' "
+ "AND C_Invoice_ID IS NULL "
+ "AND DocStatus IN (?,?)" , getTransactionName())
.setParameters(withholdingDocument.getC_Order_ID(), getDefinition().getWH_Definition_ID(), MWHWithholding.DOCSTATUS_Completed, MWHWithholding.DOCSTATUS_Closed)
.first();
}
return withholding;
}
}


0 comments on commit 7600c15

Please sign in to comment.