Fixes bug 28896: Purchase Invoices Supplier reference is shown in add payment.
authorUnai Martirena <unai.martirena@openbravo.com>
Wed, 11 Feb 2015 19:01:27 +0100
changeset 25902 f0e8afa3c9fa
parent 25901 8e9266e71595
child 25903 da4a7752b467
Fixes bug 28896: Purchase Invoices Supplier reference is shown in add payment.

A case has been added in AddPaymentOrderInvoicesTransformer to display the Supplier Reference instead of Invoice Number when is configured like that in Organization Info tab, only for Purchase Invoices
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java	Wed Feb 11 18:25:54 2015 +0100
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/hqlinjections/AddPaymentOrderInvoicesTransformer.java	Wed Feb 11 19:01:27 2015 +0100
@@ -35,6 +35,8 @@
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.model.ad.datamodel.Column;
 import org.openbravo.model.ad.datamodel.Table;
+import org.openbravo.model.common.enterprise.OrganizationInformation;
+import org.openbravo.model.common.invoice.Invoice;
 import org.openbravo.service.datasource.HQLDataSourceService;
 import org.openbravo.service.datasource.hql.HqlQueryTransformer;
 import org.openbravo.service.db.DalConnectionProvider;
@@ -119,7 +121,11 @@
     selectClause.append(getAggregatorFunction("psd.id") + " as paymentScheduleDetail, ");
     if ("I".equals(transactionType)) {
       selectClause.append(getAggregatorFunction("ord.documentNo") + " as salesOrderNo, ");
-      selectClause.append(" inv.documentNo as invoiceNo, ");
+      selectClause.append(" case when (inv." + Invoice.PROPERTY_SALESTRANSACTION
+          + " = false and oinfo is not null and oinfo."
+          + OrganizationInformation.PROPERTY_APRMPAYMENTDESCRIPTION
+          + " like 'Supplier Reference') then inv." + Invoice.PROPERTY_ORDERREFERENCE
+          + " else inv." + Invoice.PROPERTY_DOCUMENTNO + " end as invoiceNo, ");
       selectClause
           .append(" COALESCE(ips.finPaymentmethod.id, ops.finPaymentmethod.id) as paymentMethod, ");
       selectClause.append(" COALESCE(ipsfp.name, opsfp.name) as paymentMethodName, ");
@@ -130,7 +136,12 @@
       selectClause.append(" max(COALESCE(inv.grandTotalAmount, 0)) as invoicedAmount, ");
     } else if ("O".equals(transactionType)) {
       selectClause.append(" ord.documentNo as salesOrderNo, ");
-      selectClause.append(getAggregatorFunction("inv.documentNo") + " as invoiceNo, ");
+      selectClause.append(getAggregatorFunction(" case when (inv."
+          + Invoice.PROPERTY_SALESTRANSACTION + " = false and oinfo is not null and oinfo."
+          + OrganizationInformation.PROPERTY_APRMPAYMENTDESCRIPTION
+          + " like 'Supplier Reference') then inv." + Invoice.PROPERTY_ORDERREFERENCE
+          + " else inv." + Invoice.PROPERTY_DOCUMENTNO + " end")
+          + " as invoiceNo, ");
       selectClause
           .append(" COALESCE(ops.finPaymentmethod.id, ips.finPaymentmethod.id) as paymentMethod, ");
       selectClause.append(" COALESCE(opsfp.name, ipsfp.name) as paymentMethodName, ");
@@ -141,7 +152,11 @@
       selectClause.append(" sum(COALESCE(inv.grandTotalAmount, 0)) as invoicedAmount, ");
     } else {
       selectClause.append(" ord.documentNo as salesOrderNo, ");
-      selectClause.append(" inv.documentNo as invoiceNo, ");
+      selectClause.append(" case when (inv." + Invoice.PROPERTY_SALESTRANSACTION
+          + " = false and oinfo is not null and oinfo."
+          + OrganizationInformation.PROPERTY_APRMPAYMENTDESCRIPTION
+          + " like 'Supplier Reference') then inv." + Invoice.PROPERTY_ORDERREFERENCE
+          + " else inv." + Invoice.PROPERTY_DOCUMENTNO + " end as invoiceNo, ");
       selectClause
           .append(" COALESCE(ips.finPaymentmethod.id, ops.finPaymentmethod.id) as paymentMethod, ");
       selectClause.append(" COALESCE(ipsfp.name, opsfp.name) as paymentMethodName, ");
@@ -277,6 +292,9 @@
       groupByClause.append(" COALESCE(ipsfp.name, opsfp.name), ");
       groupByClause.append(" COALESCE(ips.expectedDate, ops.expectedDate), ");
       groupByClause.append(" COALESCE(ipriority.priority, opriority.priority), ");
+      groupByClause.append(" inv.salesTransaction, ");
+      groupByClause.append(" oinfo.organization, ");
+      groupByClause.append(" inv.orderReference, ");
     } else if ("O".equals(transactionType)) {
       groupByClause.append(" ord.documentNo, ");
       groupByClause.append(" COALESCE(ops.finPaymentmethod.id, ips.finPaymentmethod.id), ");
@@ -290,6 +308,9 @@
       groupByClause.append(" COALESCE(ipsfp.name, opsfp.name), ");
       groupByClause.append(" COALESCE(ips.expectedDate, ops.expectedDate), ");
       groupByClause.append(" COALESCE(ipriority.priority, opriority.priority), ");
+      groupByClause.append(" inv.salesTransaction, ");
+      groupByClause.append(" oinfo.organization, ");
+      groupByClause.append(" inv.orderReference, ");
     }
     groupByClause.append(" COALESCE(invbp.id, ordbp.id), ");
     groupByClause.append(" COALESCE(invbp.name, ordbp.name) ");