if(remainingQty==amount){ if(backlog>0.0) { remainingQty= taskQtyInBucket(task, currentBucket, thePG); backlog=backlog-remainingQty; } else { remainingQty=0.0; } } else { remainingQty = remainingQty-amount; } }
      public void addPhase(double amount, int currentBucket){       if(amount < 0.0) {         if(logger.isInfoEnabled()) {           String itemId = getTaskUtils().getTaskItemName(task);           TypeIdentificationPG typeIdPG = thePG.getResource().getTypeIdentificationPG();           String nomenclature = null;           String orgId = thePG.getOrg().getItemIdentificationPG().getItemIdentification();           if (typeIdPG == null) {             logger.warn("No typeIdentificationPG for asset");           } else {             nomenclature = typeIdPG.getNomenclature();           }           if (nomenclature == null) {             nomenclature = itemId;           }           logger.info(" Adding a phase of a negative amount==" + amount + " at bucket " + getTimeUtils().dateString(thePG.convertBucketToTime(currentBucket)) + "for task: " + task.getUID() + " org is " + inventoryPlugin.getOrgName() + " and the item is : "  + nomenclature);         }         amount = 0.0;       }      if (amount == 0.0) {        if(task.getVerb().equals(Constants.Verb.WITHDRAW)) {          return;        }      }				             if (task.getVerb().equals(Constants.Verb.PROJECTWITHDRAW) &&              lastPhase !=null &&              currentBucket==lastPhase.endBucket &&              amount==lastPhase.amount ) {        // same as last phase so just extend last phase        lastPhase.endBucket=currentBucket+1;      } else {        // find existing phase for bucket if exists        Iterator phases = allocated.iterator();        AllocPhase aPhase=null, thePhase=null;        while (phases.hasNext()) {          aPhase = (AllocPhase)phases.next();          if ((aPhase.startBucket <= currentBucket) &&              (aPhase.endBucket > currentBucket)) {            thePhase = aPhase;            break;          }        }        if (thePhase == null) {//          if ((inventoryPlugin.getClusterId().toString().indexOf("2-NLOS-BTY") >= 0) &&//              (task.getDirectObject().getTypeIdentificationPG().getTypeIdentification().indexOf("155mm-DPICM") >= 0)) {//            System.out.println("Adding new last phase to fill deficit... task " + task.getUID() + " bucket " +//                               new Date (thePG.convertBucketToTime(currentBucket)) + " amount " + amount);//          }          // add new phase          lastPhase = new AllocPhase(currentBucket, amount);          allocated.add(lastPhase);        } else {          thePhase.amount += amount;        }      }      if(remainingQty==amount){        if(backlog>0.0) {          remainingQty= taskQtyInBucket(task, currentBucket, thePG);          backlog=backlog-remainingQty;        } else {          remainingQty=0.0;        }      } else {        remainingQty = remainingQty-amount;      }    }