Skip to content

Commit

Permalink
- Se corrige error con NPE en export de BANAVIH con empleados sin
Browse files Browse the repository at this point in the history
apellido registrado
- Se corrige error con NPE en el cálculo de IVA desde el POS
  • Loading branch information
yamelsenih committed Oct 13, 2022
1 parent 3db2af2 commit 45b79a8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.HashMap;
Expand All @@ -32,6 +33,7 @@

import org.compiere.model.MBPartner;
import org.compiere.model.MOrgInfo;
import org.compiere.model.Query;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Util;
Expand Down Expand Up @@ -153,7 +155,7 @@ private void writeLine() throws IOException {
if(currentProcessDetail == null)
return;
// Process Business Partner
Map<Integer,String> bpInfo = processBPartner(currentProcessDetail.getC_BPartner_ID(), currentProcessDetail.get_TrxName());
Map<Integer,String> bpInfo = processBPartner(currentProcessDetail.getC_BPartner_ID(), currentProcessDetail.getDateAcct(), currentProcessDetail.get_TrxName());
// Line
if(bpInfo == null)
return;
Expand Down Expand Up @@ -202,24 +204,26 @@ private void writeLine() throws IOException {

/**
* Process Business Partner
* @author <a href="mailto:yamelsenih@gmail.com">Yamel Senih</a> 16/08/2014, 12:27:09
* @param p_C_BPartner_ID
* @param p_TrxName
* @param businessPartnerId
* @param dateAcct
* @param transactionName
* @return String []
*/
private Map<Integer,String> processBPartner(int p_C_BPartner_ID, String p_TrxName) {
private Map<Integer,String> processBPartner(int businessPartnerId, Timestamp dateAcct, String transactionName) {
Map<Integer,String> bpInfo = new HashMap<Integer, String>();

// Get Business Partner
MBPartner bpartner = MBPartner.get(Env.getCtx(), p_C_BPartner_ID);
MBPartner bpartner = MBPartner.get(Env.getCtx(), businessPartnerId);
// Get Name
String name = bpartner.getName();
String name2 = bpartner.getName2();
// Valid Null
if(name.isEmpty())
if(Util.isEmpty(name)) {
name = "";
if(name2.isEmpty())
}
if(Util.isEmpty(name2)) {
name2 = "";
}

List <String> nameList = Arrays.asList(name.split(" "));
// Extract First Name 1
Expand Down Expand Up @@ -278,8 +282,7 @@ else if(lastName2.length() == 0)
lastName2 = "";

// Get Active Employee
MHREmployee employee = MHREmployee.getActiveEmployee(Env.getCtx(),
bpartner.getC_BPartner_ID(), p_TrxName);
MHREmployee employee = getByPartnerIdAndStartDate(bpartner.getC_BPartner_ID(), dateAcct, transactionName);
// Valid Employee
if(employee == null)
return null;
Expand All @@ -306,6 +309,25 @@ else if(lastName2.length() == 0)
return bpInfo;
}

/**
* Get Employee by Partner Id and Date Start
* @param ctx
* @param partnerId
* @param dateStart
* @param trxName
* @return
*/
private MHREmployee getByPartnerIdAndStartDate(int partnerId , Timestamp dateStart, String trxName) {
StringBuilder whereClause = new StringBuilder();
whereClause.append(MHREmployee.COLUMNNAME_C_BPartner_ID).append("=? AND ");
whereClause.append(MHREmployee.COLUMNNAME_StartDate).append(" <= ?");
return new Query(Env.getCtx(), MHREmployee.Table_Name , whereClause.toString(),trxName)
.setClient_ID()
.setParameters(partnerId , dateStart)
.setOrderBy(MHREmployee.COLUMNNAME_StartDate + " DESC, " + MHREmployee.COLUMNNAME_EndDate + " DESC")
.first();
}

public String processValue(String value) {
if(Util.isEmpty(value)) {
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ public String run() {
MTable posPaymentType = MTable.get(getContext(), "C_POSPaymentTypeAllocation");
if(posPaymentType != null) {
PO paymentTypeAllocation = getDefaultPaymentMethodAllocated();
if(paymentTypeAllocation == null) {
return null;
}
if(Util.isEmpty(paymentTypeAllocation.get_ValueAsString("Name"))) {
MCPaymentMethod paymentMethod = MCPaymentMethod.getById(getContext(), paymentTypeAllocation.get_ValueAsInt("C_PaymentMethod_ID"), getTransactionName());
if(!Util.isEmpty(paymentMethod.getDescription())) {
Expand Down Expand Up @@ -266,6 +269,9 @@ protected void savePaymentReference(boolean createIfNotExists) {
// Add backward compatibility
MTable paymentReferenceDefinition = MTable.get(getContext(), "C_POSPaymentReference");
if(paymentReferenceDefinition != null) {
if(getDefaultPaymentMethodAllocated() == null) {
return;
}
PO paymentReferenceToCreate = new Query(getContext(), "C_POSPaymentReference",
"C_Order_ID = ? "
+ "AND TenderType = ? "
Expand Down Expand Up @@ -319,6 +325,9 @@ protected void savePaymentReference(boolean createIfNotExists) {
private void deleteReference() {
MTable paymentReferenceDefinition = MTable.get(getContext(), "C_POSPaymentReference");
if(paymentReferenceDefinition != null) {
if(getDefaultPaymentMethodAllocated() == null) {
return;
}
PO paymentReferenceToDelete = new Query(getContext(), "C_POSPaymentReference",
"C_Order_ID = ? "
+ "AND TenderType = ? "
Expand Down

0 comments on commit 45b79a8

Please sign in to comment.