# HG changeset patch
# User Prakash M <prakash@qualiantech.com>
# Date 1496059727 -19800
#      Mon May 29 17:38:47 2017 +0530
# Node ID 533e1ac08400c32da5101da91ae9a4b7ff74eff8
# Parent  e1b877d628621bc9a44e73573b91e5da58584fea
imported patch issue_2862.diff

diff --git a/src/org/openbravo/retail/giftcards/process/ExpirationDateProcess.java b/src/org/openbravo/retail/giftcards/process/ExpirationDateProcess.java
--- a/src/org/openbravo/retail/giftcards/process/ExpirationDateProcess.java
+++ b/src/org/openbravo/retail/giftcards/process/ExpirationDateProcess.java
@@ -50,6 +50,7 @@
 
   private void closeGiftCards(String clientId, int iter) throws Exception {
     List<String> openGiftCards = getOpenGiftCards(clientId);
+    int closedGC = 0;
     if (openGiftCards.size() > 0 && !killProcess) {
       if (killProcess) {
         return;
@@ -57,9 +58,10 @@
       long init = System.currentTimeMillis();
       for (String giftcard : openGiftCards) {
         GiftCardGLItemUtils.close((String) giftcard, "E");
-        if (iter % 50 == 0 && iter % 1000 != 0 && iter != 0) {
+        closedGC++;
+        if (closedGC == openGiftCards.size() || closedGC % 50 == 0) {
           logger.logln(OBMessageUtils.getI18NMessage("GCNV_GiftCardsClosed",
-              new String[] { String.valueOf(iter) }));
+              new String[] { String.valueOf(iter + closedGC) }));
           OBDal.getInstance().getConnection(true).commit();
           OBDal.getInstance().getSession().clear();
           logger.logln(OBMessageUtils.getI18NMessage("GCNV_TimeConsumedGiftCards",
@@ -73,8 +75,8 @@
             return;
           }
         }
-        counter = iter + 1;
       }
+      counter = iter + closedGC;
       closeGiftCards(clientId, counter);
     }
   }
