Fixes issue 21802: Shows and filters Supplier's document number
authorDavid Miguelez <david.miguelez@openbravo.com>
Mon, 01 Oct 2012 12:51:18 +0200
changeset 18134 1d2b86422c02
parent 18133 8b5d149fdbdb
child 18135 30b3bd0350b0
Fixes issue 21802: Shows and filters Supplier's document number
when the Organization Info is set to do so.
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java	Thu Oct 04 16:37:09 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/dao/AdvPaymentMngtDao.java	Mon Oct 01 12:51:18 2012 +0200
@@ -55,6 +55,7 @@
 import org.openbravo.model.common.currency.Currency;
 import org.openbravo.model.common.enterprise.DocumentType;
 import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.model.common.enterprise.OrganizationInformation;
 import org.openbravo.model.common.invoice.Invoice;
 import org.openbravo.model.common.order.Order;
 import org.openbravo.model.common.plm.Product;
@@ -214,6 +215,8 @@
       whereClause.append(" left outer join psd.invoicePaymentSchedule as ips ");
       whereClause.append(" left outer join ips.invoice as inv");
       whereClause.append(" left outer join ips.fINPaymentPriority as ipriority");
+      whereClause.append(" left outer join psd.organization as org");
+      whereClause.append(" left outer join org.organizationInformationList as oinfo");
       whereClause.append(" where psd.");
       whereClause.append(FIN_PaymentScheduleDetail.PROPERTY_PAYMENTDETAILS);
       whereClause.append(" is null");
@@ -223,6 +226,7 @@
       whereClause.append(Utility.getInStrSet(OBContext.getOBContext()
           .getOrganizationStructureProvider().getNaturalTree(organization.getId())));
       whereClause.append(")");
+      whereClause.append(" and (oinfo is null or oinfo.active = true)");
 
       // remove selected payments
       if (selectedScheduledPaymentDetails != null && selectedScheduledPaymentDetails.size() > 0) {
@@ -292,13 +296,33 @@
         whereClause.append(Invoice.PROPERTY_SALESTRANSACTION);
         whereClause.append(" = ");
         whereClause.append(isReceipt);
+
+        // Invoice Document No. filter
         if (!StringUtils.isEmpty(strDocumentNo)) {
-          whereClause.append(" and inv.");
+          whereClause.append(" and (case when");
+          whereClause.append(" (inv.");
+          whereClause.append(Invoice.PROPERTY_SALESTRANSACTION);
+          whereClause.append(" = false");
+          whereClause.append(" and oinfo is not null");
+          whereClause.append(" and oinfo.");
+          whereClause.append(OrganizationInformation.PROPERTY_APRMPAYMENTDESCRIPTION);
+          whereClause.append(" like 'Supplier Reference')");
+          whereClause.append(" then ");
+          // When the Organization of the Invoice sets that the Invoice Document No. is the
+          // supplier's
+          whereClause.append(" inv.");
+          whereClause.append(Invoice.PROPERTY_ORDERREFERENCE);
+          whereClause.append(" else ");
+          // When the Organization of the Invoice sets that the Invoice Document No. is the default
+          // Invoice Number
+          whereClause.append(" inv.");
           whereClause.append(Invoice.PROPERTY_DOCUMENTNO);
+          whereClause.append(" end) ");
           whereClause.append(" like '%");
           whereClause.append(strDocumentNo);
           whereClause.append("%' ");
         }
+
         whereClause.append(" and inv.");
         whereClause.append(Invoice.PROPERTY_CURRENCY);
         whereClause.append(".id = '");
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java	Thu Oct 04 16:37:09 2012 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_AddPayment.java	Mon Oct 01 12:51:18 2012 +0200
@@ -46,6 +46,7 @@
 import org.openbravo.dal.core.OBContext;
 import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
+import org.openbravo.dal.service.OBDao;
 import org.openbravo.data.FieldProvider;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.FieldProviderFactory;
@@ -55,6 +56,7 @@
 import org.openbravo.model.common.currency.Currency;
 import org.openbravo.model.common.enterprise.DocumentType;
 import org.openbravo.model.common.enterprise.Organization;
+import org.openbravo.model.common.enterprise.OrganizationInformation;
 import org.openbravo.model.common.invoice.Invoice;
 import org.openbravo.model.common.plm.Product;
 import org.openbravo.model.financialmgmt.gl.GLItem;
@@ -730,10 +732,28 @@
           FieldProviderFactory.setField(data[i], "orderPaymentScheduleId", "");
         }
         if (FIN_PaymentScheduleDetails[i].getInvoicePaymentSchedule() != null) {
-          FieldProviderFactory.setField(data[i], "invoiceNr", FIN_PaymentScheduleDetails[i]
-              .getInvoicePaymentSchedule().getInvoice().getDocumentNo());
-          FieldProviderFactory.setField(data[i], "invoiceNrTrunc", FIN_PaymentScheduleDetails[i]
-              .getInvoicePaymentSchedule().getInvoice().getDocumentNo());
+          FIN_PaymentSchedule psd = FIN_PaymentScheduleDetails[i].getInvoicePaymentSchedule();
+          OrganizationInformation orgInfo = OBDao.getActiveOBObjectList(psd.getOrganization(),
+              Organization.PROPERTY_ORGANIZATIONINFORMATIONLIST) != null ? (OrganizationInformation) OBDao
+              .getActiveOBObjectList(psd.getOrganization(),
+                  Organization.PROPERTY_ORGANIZATIONINFORMATIONLIST).get(0) : null;
+          if (!psd.getInvoice().isSalesTransaction() && orgInfo != null
+              && orgInfo.getAPRMPaymentDescription().equals("Supplier Reference")) {
+            // When the Organization of the Invoice sets that the Invoice Document No. is the
+            // supplier's
+            FieldProviderFactory.setField(data[i], "invoiceNr", FIN_PaymentScheduleDetails[i]
+                .getInvoicePaymentSchedule().getInvoice().getOrderReference());
+            FieldProviderFactory.setField(data[i], "invoiceNrTrunc", FIN_PaymentScheduleDetails[i]
+                .getInvoicePaymentSchedule().getInvoice().getOrderReference());
+          } else {
+            // When the Organization of the Invoice sets that the Invoice Document No. is the
+            // default
+            // Invoice Number
+            FieldProviderFactory.setField(data[i], "invoiceNr", FIN_PaymentScheduleDetails[i]
+                .getInvoicePaymentSchedule().getInvoice().getDocumentNo());
+            FieldProviderFactory.setField(data[i], "invoiceNrTrunc", FIN_PaymentScheduleDetails[i]
+                .getInvoicePaymentSchedule().getInvoice().getDocumentNo());
+          }
           FieldProviderFactory.setField(data[i], "invoicePaymentScheduleId",
               FIN_PaymentScheduleDetails[i].getInvoicePaymentSchedule().getId());
         } else {