| Attached Files |   LE_32241_mobilecore.diff [^] (5,914 bytes) 2016-02-15 19:55 [Show Content] [Hide Content]diff -r 5bb60b75d022 web/org.openbravo.mobile.core/source/data/ob-dal.js
--- a/web/org.openbravo.mobile.core/source/data/ob-dal.js	Mon Feb 15 18:10:33 2016 +0100
+++ b/web/org.openbravo.mobile.core/source/data/ob-dal.js	Mon Feb 15 19:55:06 2016 +0100
@@ -603,6 +603,8 @@
           firstParam = true,
           uuid, propertyName, filterVal, processError;
 
+      var updateToBeChecked = false;
+
       processError = function (txError, e) {
         executeSqlErrorHandler('error', "OB.Dal.save: table", tableName, txError, e, callerInfo);
         if (_.isFunction(error)) {
@@ -649,6 +651,9 @@
           params.push(model.get(primaryKeyProperty));
         } else {
           // UPDATE
+          if (tableName === 'c_order') {
+            updateToBeChecked = true;
+          }
           sql = 'UPDATE ' + tableName + ' SET ';
 
           _.each(_.keys(modelProto.properties), function (attr) {
@@ -751,20 +756,95 @@
           // OB.error(e);
         }
       }
+
       if (currentTransaction) {
-        try {
-          currentTransaction.executeSql(sql, params, silentFunction(success), processError);
-        } catch (e) {
-          executeSqlErrorHandler('error', "OB.Dal.save: table", tableName, null, e, callerInfo);
-        }
-      } else {
-        OB.Data.localDB.transaction(function (tx) {
+        if (updateToBeChecked) {
+          OB.Dal.getInTransaction(currentTransaction, modelDefinition, model.get('id'), function (result) {
+            if (result) {
+              if (result.get('hasbeenpaid') === 'Y') {
+                OB.error('[checkBlocked][transaction][hasbeenpaid_is_yes] Wrong write in c_order avoided [' + result.get('id') + '][' + result.get('documentNo') + '] - Caller: ' + caller + ' - callerInfo: ' + callerInfo);
+                if (success) {
+                  success();
+                }
+              } else {
+                try {
+                  currentTransaction.executeSql(sql, params, silentFunction(success), processError);
+                } catch (e) {
+                  executeSqlErrorHandler('error', "OB.Dal.save: table", tableName, null, e, callerInfo);
+                }
+              }
+            } else {
+              //no results
+              OB.warn('[checkBlocked][transaction] No result after getInTransaction for [' + model.get('id') + '][' + model.get('documentNo') + ']. This update doesnt make sense - Caller: ' + caller + ' - callerInfo: ' + callerInfo);
+              if (success) {
+                success();
+              }
+            }
+          }, function () {
+            OB.error('[checkBlocked][transaction] Error for [' + model.get('id') + '][' + model.get('documentNo') + '] - Caller: ' + caller + ' - callerInfo: ' + callerInfo);
+            if (error) {
+              error();
+            }
+          }, function () {
+            //no results
+            OB.warn('[checkBlocked][transaction] No result after getInTransaction for [' + model.get('id') + '][' + model.get('documentNo') + ']. This update doesnt make sense - Caller: ' + caller + ' - callerInfo: ' + callerInfo);
+            if (success) {
+              success();
+            }
+          });
+        } else {
           try {
-            tx.executeSql(sql, params, silentFunction(success), processError);
+            currentTransaction.executeSql(sql, params, silentFunction(success), processError);
           } catch (e) {
             executeSqlErrorHandler('error', "OB.Dal.save: table", tableName, null, e, callerInfo);
           }
-        });
+        }
+      } else {
+        if (updateToBeChecked) {
+          OB.Data.localDB.transaction(function (tx) {
+            OB.Dal.getInTransaction(tx, modelDefinition, model.get('id'), function (result) {
+              if (result) {
+                if (result.get('hasbeenpaid') === 'Y') {
+                  OB.error('[checkBlocked][no-transaction][hasbeenpaid_is_yes] Wrong write in c_order avoided [' + result.get('id') + '][' + result.get('documentNo') + '] - Caller: ' + caller + ' - callerInfo: ' + callerInfo);
+                  if (success) {
+                    success();
+                  }
+                } else {
+                  try {
+                    tx.executeSql(sql, params, silentFunction(success), processError);
+                  } catch (e) {
+                    executeSqlErrorHandler('error', "OB.Dal.save: table", tableName, null, e, callerInfo);
+                  }
+                }
+              } else {
+                //no results
+                OB.warn('[checkBlocked][no-transaction] No result after getInTransaction for [' + model.get('id') + '][' + model.get('documentNo') + ']. This update doesnt make sense - Caller: ' + caller + ' - callerInfo: ' + callerInfo);
+                if (success) {
+                  success();
+                }
+              }
+            }, function () {
+              OB.error('[checkBlocked][no-transaction] Error for [' + model.get('id') + '][' + model.get('documentNo') + ']');
+              if (error) {
+                error();
+              }
+            }, function () {
+              //no results
+              OB.warn('[checkBlocked][no-transaction] No result after getInTransaction for [' + model.get('id') + '][' + model.get('documentNo') + ']. This update doesnt make sense - Caller: ' + caller + ' - callerInfo: ' + callerInfo);
+              if (success) {
+                success();
+              }
+            });
+          });
+        } else {
+          OB.Data.localDB.transaction(function (tx) {
+            try {
+              tx.executeSql(sql, params, silentFunction(success), processError);
+            } catch (e) {
+              executeSqlErrorHandler('error', "OB.Dal.save: table", tableName, null, e, callerInfo);
+            }
+          });
+        }
       }
     } else {
       this.missingLocalStorageLogic();
 
  LE_32241_posterminal.diff [^] (8,727 bytes) 2016-02-15 19:55 [Show Content] [Hide Content]diff -r 4d0f648f3236 web/org.openbravo.retail.posterminal/js/data/dataordersave.js
--- a/web/org.openbravo.retail.posterminal/js/data/dataordersave.js	Mon Feb 15 16:21:51 2016 +0100
+++ b/web/org.openbravo.retail.posterminal/js/data/dataordersave.js	Mon Feb 15 19:54:15 2016 +0100
@@ -64,16 +64,13 @@
     // finished receipt verifications
     this.receipt.on('closed', function (eventParams) {
       this.receipt = model.get('order');
-      
+      OB.info('Ticket closed: ', this.receipt.getOrderDescription() + ' with localstorageid: ' + window.localStorage.idCacheDevice);
       var me = this,
           docno = this.receipt.get('documentNo'),
           isLayaway = (this.receipt.get('orderType') === 2 || this.receipt.get('isLayaway')),
           json = this.receipt.serializeToJSON(),
           receiptId = this.receipt.get('id');
 
-      	  OB.info('Ticket closed' +  docno + ' with localstorageid: '+window.localStorage.idCacheDevice);
-
-      
       if (this.receipt.get('isbeingprocessed') === 'Y') {
         //The receipt has already been sent, it should not be sent again
         return;
@@ -88,8 +85,8 @@
       } catch (e) {
         OB.error("Ticket closed: the 'creationDate' was not a valid date ('" + this.receipt.get('creationDate') + "')");
       }
-      OB.info("Ticket closed: 'creationDate' set to '" + creationDate.toISOString() + "' (was '" + this.receipt.get('creationDate') + "')");
 
+      this.receipt.set('hasbeenpaid', 'Y');
 
       OB.trace('Executing pre order save hook.');
 
@@ -105,6 +102,7 @@
           return true;
         }
         var receipt = args.context.receipt,
+            auxReceipt = new OB.Model.Order(),
             currentDocNo = receipt.get('documentNo') || docno;
 
         OB.trace('Execution of pre order save hook OK.');
@@ -127,7 +125,17 @@
           }
         });
 
-        receipt.set('obposAppCashup', OB.MobileApp.model.get('terminal').cashUpId);
+        if (OB.MobileApp.model.get('terminal').cashUpId) {
+          receipt.set('obposAppCashup', OB.MobileApp.model.get('terminal').cashUpId);
+        } else {
+          args.context.receipt.set('isbeingprocessed', 'N');
+          args.context.receipt.set('hasbeenpaid', 'N');
+          args.context.receipt.trigger('paymentCancel');
+          OB.UTIL.showConfirmation.display("CashupID not found", "Please reload the application after complete the ticket");
+          return true;
+        }
+
+
         // convert returns
         if (receipt.getGross() < 0) {
           _.forEach(receipt.get('payments').models, function (item) {
@@ -136,35 +144,27 @@
             item.set('paid', -item.get('paid'));
           });
         }
-        
-        receipt.set('hasbeenpaid', 'Y');
-
         receipt.set('json', JSON.stringify(receipt.serializeToJSON()));
 
         OB.trace('Calculationg cashup information.');
-        
-        var auxReceipt = new OB.Model.Order();
+
         auxReceipt.clearWith(receipt);
-        var auxReceipt2 = new OB.Model.Order();
-        auxReceipt2.clearWith(receipt);
-        var auxReceipt3 = new OB.Model.Order();
-        auxReceipt3.clearWith(receipt);
-
         OB.Dal.transaction(function (tx) {
           OB.UTIL.cashUpReport(auxReceipt, function () {
             OB.UTIL.calculateCurrentCash(null, tx);
-            OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(auxReceipt2.get('documentnoSuffix'), auxReceipt2.get('quotationnoSuffix'), function () {
-              var docno = auxReceipt2.get('documentNo');
-              var creationDate = auxReceipt2.get('creationDate');
-              var tzo = auxReceipt2.get('timezoneOffset');
+            OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(receipt.get('documentnoSuffix'), receipt.get('quotationnoSuffix'), function () {
+              var docno = receipt.get('documentNo');
+              var creationDate = receipt.get('creationDate');
+              var tzo = receipt.get('timezoneOffset');
               var message = "[transaction.saveorder] receipt '" + docno + "'; creationDate '" + creationDate + "'; timezoneOffset: '" + tzo + "'";
-              OB.Dal.saveInTransaction(tx, auxReceipt2, function () {
+              OB.Dal.saveInTransaction(tx, receipt, function () {
+                OB.info(message);
               });
             }, tx);
           }, tx);
-        }, function () {
-        }, function () {
+        }, null, function () {
           // success transaction...
+          OB.trace('Executing of post order save hook.');
 
           var successCallback = function (model) {
               OB.trace('Sync process success.');
@@ -172,8 +172,10 @@
               //In case the processed document is a quotation, we remove its id so it can be reactivated
               if (model && !_.isNull(model)) {
                 if (model.get('order') && model.get('order').get('isQuotation')) {
-                  model.get('order').set('oldId', model.get('order').get('id'));
-                  model.get('order').set('id', null);
+                  if (!(model.get('order').get('oldId') && model.get('order').get('oldId').length > 0)) {
+                    model.get('order').set('oldId', model.get('order').get('id'));
+                    model.get('order').set('id', null);
+                  }
                   model.get('order').set('isbeingprocessed', 'N');
                   OB.UTIL.showSuccess(OB.I18N.getLabel('OBPOS_QuotationSaved', [currentDocNo]));
                 } else {
@@ -195,7 +197,7 @@
 
             OB.MobileApp.model.runSyncProcess(function () {
               OB.UTIL.HookManager.executeHooks('OBPOS_PostSyncReceipt', {
-                receipt: auxReceipt3
+                receipt: auxReceipt
               }, function (args) {
                 successCallback();
                 if (eventParams && eventParams.callback) {
@@ -204,7 +206,7 @@
               });
             }, function () {
               OB.UTIL.HookManager.executeHooks('OBPOS_PostSyncReceipt', {
-                receipt: auxReceipt3
+                receipt: auxReceipt
               }, function (args) {
                 if (eventParams && eventParams.callback) {
                   eventParams.callback();
@@ -216,13 +218,12 @@
             OB.trace('Execution Sync process.');
 
             //If there are no elements in the hook, we can execute the callback asynchronusly with the synchronization process
-            successCallback(model);
+            OB.MobileApp.model.runSyncProcess(function () {
+              successCallback(model);
+            });
             if (eventParams && eventParams.callback) {
               eventParams.callback();
             }
-            OB.MobileApp.model.runSyncProcess(function () {
-              OB.debug("Ticket closed: runSyncProcess executed");
-            });
           }
         });
       });
@@ -272,23 +273,21 @@
         receipt: this.receipt
       }, function (args) {
 
-        var receipt = args.context.receipt,
-        trxName;
-
         OB.trace('Execution of pre order save hook OK.');
         if (args && args.cancellation && args.cancellation === true) {
-          receipt.set('isbeingprocessed', 'N');
+          args.context.receipt.set('isbeingprocessed', 'N');
           return true;
         }
 
-        OB.MobileApp.model.updateDocumentSequenceWhenOrderSaved(receipt.get('documentnoSuffix'), receipt.get('quotationnoSuffix'), function () {
-          OB.trace('Saving receipt.');
-          trxName = 'closeTicketTrx' + receipt.get('id');
-          OB.Dal.saveInTransaction(trxName, me.receipt, function () {
+        OB.trace('Saving receipt.');
+
+        OB.Dal.save(me.receipt, function () {
+          OB.Dal.get(OB.Model.Order, receiptId, function (receipt) {
             var successCallback, errorCallback;
             successCallback = function () {
 
               OB.trace('Sync process success.');
+              OB.UTIL.showLoading(false);
               if (me.hasInvLayaways) {
                 OB.UTIL.showWarning(OB.I18N.getLabel('OBPOS_noInvoiceIfLayaway'));
                 me.hasInvLayaways = false;
@@ -315,12 +314,12 @@
               me.ordersToSend = OB.DEC.Zero;
             }
 
-          }, function () {
-            //We do nothing: we don't need to alert the user, as the order is still present in the database, so it will be resent as soon as the user logs in again
-          });
-        }, trxName);
+          }, null);
+        }, function () {
+          //We do nothing: we don't need to alert the user, as the order is still present in the database, so it will be resent as soon as the user logs in again
+        });
       });
 
     }, this);
   };
-}());
+}());
\ No newline at end of file
 |