[aprm-windows] validations in grids
authorSandra Huguet <sandra.huguet@openbravo.com>
Fri, 30 May 2014 14:14:37 +0200
changeset 23669 bf2f4c45ce2a
parent 23668 8d2daeeab3ca
child 23670 145e2860b111
[aprm-windows] validations in grids
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_FIELD.xml
modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MESSAGE.xml
modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_FIELD.xml	Fri May 30 11:04:14 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_FIELD.xml	Fri May 30 14:14:37 2014 +0200
@@ -1255,6 +1255,7 @@
 <!--1279D50CA56A45EDAD05193ED24832EA-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
 <!--1279D50CA56A45EDAD05193ED24832EA-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
 <!--1279D50CA56A45EDAD05193ED24832EA-->  <ONCHANGEFUNCTION><![CDATA[OB.APRM.AddPayment.updateCreditTotal]]></ONCHANGEFUNCTION>
+<!--1279D50CA56A45EDAD05193ED24832EA-->  <EM_OBUIAPP_VALIDATOR><![CDATA[OB.APRM.AddPayment.creditValidation]]></EM_OBUIAPP_VALIDATOR>
 <!--1279D50CA56A45EDAD05193ED24832EA-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--1279D50CA56A45EDAD05193ED24832EA--></AD_FIELD>
 
@@ -3231,6 +3232,7 @@
 <!--35DD8B0180354F51810C33CD9364AADE-->  <STARTNEWLINE><![CDATA[N]]></STARTNEWLINE>
 <!--35DD8B0180354F51810C33CD9364AADE-->  <ISSHOWNINSTATUSBAR><![CDATA[N]]></ISSHOWNINSTATUSBAR>
 <!--35DD8B0180354F51810C33CD9364AADE-->  <ONCHANGEFUNCTION><![CDATA[OB.APRM.AddPayment.orderInvoiceAmountOnChange]]></ONCHANGEFUNCTION>
+<!--35DD8B0180354F51810C33CD9364AADE-->  <EM_OBUIAPP_VALIDATOR><![CDATA[OB.APRM.AddPayment.orderInvoiceGridValidation]]></EM_OBUIAPP_VALIDATOR>
 <!--35DD8B0180354F51810C33CD9364AADE-->  <EM_OBUIAPP_SHOWSUMMARY><![CDATA[N]]></EM_OBUIAPP_SHOWSUMMARY>
 <!--35DD8B0180354F51810C33CD9364AADE--></AD_FIELD>
 
--- a/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MESSAGE.xml	Fri May 30 11:04:14 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/src-db/database/sourcedata/AD_MESSAGE.xml	Fri May 30 14:14:37 2014 +0200
@@ -685,6 +685,18 @@
 <!--8FC3C9524EE54E518B679D58F709119D-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
 <!--8FC3C9524EE54E518B679D58F709119D--></AD_MESSAGE>
 
+<!--9124E0172DAA4B07B4C4F035BDDA2424--><AD_MESSAGE>
+<!--9124E0172DAA4B07B4C4F035BDDA2424-->  <AD_MESSAGE_ID><![CDATA[9124E0172DAA4B07B4C4F035BDDA2424]]></AD_MESSAGE_ID>
+<!--9124E0172DAA4B07B4C4F035BDDA2424-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--9124E0172DAA4B07B4C4F035BDDA2424-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--9124E0172DAA4B07B4C4F035BDDA2424-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--9124E0172DAA4B07B4C4F035BDDA2424-->  <VALUE><![CDATA[aprm_biggerthanzero]]></VALUE>
+<!--9124E0172DAA4B07B4C4F035BDDA2424-->  <MSGTEXT><![CDATA[You must set one amount bigger than zero.]]></MSGTEXT>
+<!--9124E0172DAA4B07B4C4F035BDDA2424-->  <MSGTYPE><![CDATA[E]]></MSGTYPE>
+<!--9124E0172DAA4B07B4C4F035BDDA2424-->  <AD_MODULE_ID><![CDATA[A918E3331C404B889D69AA9BFAFB23AC]]></AD_MODULE_ID>
+<!--9124E0172DAA4B07B4C4F035BDDA2424-->  <ISINCLUDEINI18N><![CDATA[N]]></ISINCLUDEINI18N>
+<!--9124E0172DAA4B07B4C4F035BDDA2424--></AD_MESSAGE>
+
 <!--91CCBCC8F7D940AA8F5EE2DD301C9291--><AD_MESSAGE>
 <!--91CCBCC8F7D940AA8F5EE2DD301C9291-->  <AD_MESSAGE_ID><![CDATA[91CCBCC8F7D940AA8F5EE2DD301C9291]]></AD_MESSAGE_ID>
 <!--91CCBCC8F7D940AA8F5EE2DD301C9291-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Fri May 30 11:04:14 2014 +0200
+++ b/modules/org.openbravo.advpaymentmngt/web/org.openbravo.advpaymentmngt/js/ob-aprm-addPayment.js	Fri May 30 14:14:37 2014 +0200
@@ -102,10 +102,9 @@
   OB.APRM.AddPayment.actualPaymentOnLoad(view);
   orderInvoiceGrid.selectionChanged = OB.APRM.AddPayment.selectionChanged;
   orderInvoiceGrid.dataProperties.transformData = OB.APRM.AddPayment.ordInvTransformData;
-  // glitemGrid.selectionChanged = OB.APRM.AddPayment.selectionChangedGlitem;
   glitemGrid.removeRecordClick = OB.APRM.AddPayment.removeRecordClick;
   creditUseGrid.selectionChanged = OB.APRM.AddPayment.selectionChangedCredit;
-  orderInvoiceGrid.dataArrived = OB.APRM.AddPayment.ordInvDataArrived;
+  orderInvoiceGrid.dataArrived = OB.APRM.AddPayment.ordInvDataArrived;
 
 };
 
@@ -208,6 +207,7 @@
 };
 
 OB.APRM.AddPayment.orderInvoiceAmountOnChange = function (item, view, form, grid) {
+  //OB.APRM.AddPayment.orderInvoiceGridValidation(item, view, form, grid);
   OB.APRM.AddPayment.updateInvOrderTotal(form, grid);
   return true;
 };
@@ -228,11 +228,11 @@
       orderInvoice = form.getItem('order_invoice').canvas.viewGrid,
       scheduledPaymentDetailId, outstandingAmount, j, i, total, chk, credit, glitem;
 
-  //amounts de gl items
+  // glitems amount
   glitem = new BigDecimal(String(form.getItem('amount_gl_items').getValue() || 0));
   amount = amount.add(glitem);
 
-  //amount de credito
+  // credit amount
   credit = new BigDecimal(String(form.getItem('used_credit').getValue() || 0));
   amount = amount.add(credit);
 
@@ -325,11 +325,11 @@
   selectedIds = orderInvoice.selectedIds;
   outstandingAmount = new BigDecimal(String(record.outstandingAmount));
   amount = amount.subtract(distributedAmount);
-  //amounts de gl items
+  // glitems amount
   glitem = new BigDecimal(String(view.theForm.getItem('amount_gl_items').getValue() || 0));
   amount = amount.add(glitem);
 
-  //amount de credito
+  // credit amount
   credit = new BigDecimal(String(view.theForm.getItem('used_credit').getValue() || 0));
   amount = amount.add(credit);
   var issotrx = view.theForm.getItem('issotrx').getValue();
@@ -348,12 +348,12 @@
         orderInvoice.setEditValue(orderInvoice.getRecordIndex(record), 'amount', '');
 
       } else {
-        orderInvoice.setEditValue(orderInvoice.getRecordIndex(record), 'amount', outstandingAmount.toString());
+        orderInvoice.setEditValue(orderInvoice.getRecordIndex(record), 'amount', Number(outstandingAmount.toString()));
 
       }
     }
   } else {
-    orderInvoice.setEditValue(orderInvoice.getRecordIndex(record), 'amount', outstandingAmount.toString());
+    orderInvoice.setEditValue(orderInvoice.getRecordIndex(record), 'amount', Number(outstandingAmount.toString()));
     actualPaymentAmount = new BigDecimal(String(view.theForm.getItem('actual_payment').getValue() || 0));
     actualPayment = view.theForm.getItem('actual_payment');
     actualPayment.setValue((actualPaymentAmount.add(outstandingAmount)).toString());
@@ -441,20 +441,7 @@
   OB.APRM.AddPayment.updateTotal(form);
   return true;
 };
-//OB.APRM.AddPayment.selectionChangedGlitem = function (record, state) {
-//  var glitem = this.view.theForm.getItem('glitem').canvas.viewGrid;
-//  if (!glitem.preventDistributingOnSelectionChanged) {
-//    this.fireOnPause('updateButtonState', function () {
-//      OB.APRM.AddPayment.doSelectionChangedGLitem(record, state, this.view);
-//    }, 500);
-//    this.Super('selectionChangedGlitem', record, state);
-//  }
-//
-//};
-//
-//OB.APRM.AddPayment.doSelectionChangedGLitem = function (record, state, view) {
-//  OB.APRM.AddPayment.updateGLItemsTotal(view.theForm);
-//};
+
 OB.APRM.AddPayment.selectionChangedCredit = function (record, state) {
 
   var credit = this.view.theForm.getItem('credit_to_use').canvas.viewGrid;
@@ -466,6 +453,30 @@
   }
 
 };
+
+
+OB.APRM.AddPayment.orderInvoiceGridValidation = function (item, validator, value, record) {
+  if (!isc.isA.Number(record.amount)) {
+    isc.warn(OB.I18N.getLabel('APRM_NotValidNumber'));
+    return false;
+  }
+  var i, row, allRows = item.grid.data.allRows,
+      outstanding = new BigDecimal(String(record.outstandingAmount)),
+      paidamount = new BigDecimal(String(record.amount));
+
+  if (outstanding.abs().compareTo(paidamount.abs()) < 0) {
+    isc.warn(OB.I18N.getLabel('APRM_MoreAmountThanOutstanding'));
+    return false;
+  }
+  
+  if ((paidamount.signum() === 0)&& (record.writeoff===false) ){
+	  isc.warn(OB.I18N.getLabel('APRM_JSZEROUNDERPAYMENT'));
+	    return false; 
+  }
+
+};
+
+
 OB.APRM.AddPayment.doSelectionChangedCredit = function (record, state, view) {
   OB.APRM.AddPayment.updateCreditTotal(view.theForm);
 };