# HG changeset patch
# User Ranjith S R <ranjith@qualiantech.com>
# Date 1537169471 -19800
#      Mon Sep 17 13:01:11 2018 +0530
# Node ID 617d7da2d6b5531e98e4d7a83b0be6bfb2735576
# Parent  076124488f655a634a4a432a648d58fcd6155e92
Fixed issue 39281 : Added modulescript for deleting tills when upgrading to 18Q3

* Tills without cashup id and not closed will be deleted when upgrading from any version to !8Q3

diff -r 076124488f65 -r 617d7da2d6b5 build/classes/org/openbravo/retail/sessions/modulescript/FixDataIssue39281.class
Binary file build/classes/org/openbravo/retail/sessions/modulescript/FixDataIssue39281.class has changed
diff -r 076124488f65 -r 617d7da2d6b5 src-util/modulescript/src/org/openbravo/retail/sessions/modulescript/FixDataIssue39281.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src-util/modulescript/src/org/openbravo/retail/sessions/modulescript/FixDataIssue39281.java	Mon Sep 17 13:01:11 2018 +0530
@@ -0,0 +1,53 @@
+/*
+ ************************************************************************************
+ * Copyright (C) 2018 Openbravo S.L.U.
+ * Licensed under the Openbravo Commercial License version 1.0
+ * You may obtain a copy of the License at http://www.openbravo.com/legal/obcl.html
+ * or in the legal folder of this module distribution.
+ ************************************************************************************
+ */
+package org.openbravo.retail.sessions.modulescript;
+
+import java.sql.PreparedStatement;
+
+import org.apache.log4j.Logger;
+import org.openbravo.database.ConnectionProvider;
+import org.openbravo.modulescript.ModuleScript;
+import org.openbravo.modulescript.ModuleScriptExecutionLimits;
+import org.openbravo.modulescript.OpenbravoVersion;
+
+public class FixDataIssue39281 extends ModuleScript {
+
+  private static final Logger log4j = Logger.getLogger(FixDataIssue39281.class);
+  private static final String RETAIL_PACK_MODULE_ID = "03FAB282A7BF47D3B1B242AC67F7845B";
+
+  public void execute() {
+    try {
+      ConnectionProvider cp = getConnectionProvider();
+      PreparedStatement ps1 = cp.getPreparedStatement("delete from poss_termsessions_approval "
+          + "where poss_terminalsessions_id in (select poss_terminalsessions_id from poss_terminalsessions "
+          + "where obpos_app_cashup_id is null and closed is null)");
+      ps1.executeUpdate();
+      ps1.close();
+      
+      PreparedStatement ps2 = cp.getPreparedStatement("delete from poss_terminalsessions "
+          + "where obpos_app_cashup_id is null and closed is null");
+      ps2.executeUpdate();
+      ps2.close();
+    } catch (Exception e) {
+      log4j.error("Errors when deleting the wrong tills", e);
+      handleError(e);
+    }
+  }
+
+  @Override
+  protected ModuleScriptExecutionLimits getModuleScriptExecutionLimits() {
+    return new ModuleScriptExecutionLimits(RETAIL_PACK_MODULE_ID, null, 
+        new OpenbravoVersion(1, 8, 3702));
+  }
+
+  @Override
+  protected boolean executeOnInstall() {
+    return false;
+  }
+}
\ No newline at end of file
