/// <summary> /// Create Difference Document. /// Creates one or two inventory lines /// </summary> /// <param name="move">movement</param> /// <param name="confirm">confirm line</param> /// <returns>true if created</returns> private Boolean CreateDifferenceDoc(MMovement move, MMovementLineConfirm confirm) { string query = ""; int result = 0; decimal currentQty = 0; MMovementLine mLine = confirm.GetLine(); // Difference - Create Inventory Difference for Source Location if (Env.ZERO.CompareTo(confirm.GetDifferenceQty()) != 0) { // Get Warehouse for Source MLocator loc = MLocator.Get(GetCtx(), mLine.GetM_Locator_ID()); if (_inventoryFrom != null && _inventoryFrom.GetM_Warehouse_ID() != loc.GetM_Warehouse_ID()) { _inventoryFrom = null; } if (_inventoryFrom == null) { MWarehouse wh = MWarehouse.Get(GetCtx(), loc.GetM_Warehouse_ID()); _inventoryFrom = new MInventory(wh); _inventoryFrom.SetDescription(Msg.Translate(GetCtx(), "M_MovementConfirm_ID") + " " + GetDocumentNo()); if (!_inventoryFrom.Save(Get_TrxName())) { _processMsg += "Inventory not created"; return(false); } // First Inventory if (GetM_Inventory_ID() == 0) { SetM_Inventory_ID(_inventoryFrom.GetM_Inventory_ID()); _inventoryInfo = _inventoryFrom.GetDocumentNo(); } else { _inventoryInfo += "," + _inventoryFrom.GetDocumentNo(); } } log.Info("createDifferenceDoc - Difference=" + confirm.GetDifferenceQty()); MInventoryLine line = new MInventoryLine(_inventoryFrom, mLine.GetM_Locator_ID(), mLine.GetM_Product_ID(), mLine.GetM_AttributeSetInstance_ID(), confirm.GetDifferenceQty(), Env.ZERO); //Added By amit 11-jun-2015 //Opening Stock , Qunatity Book => CurrentQty From Transaction of MovementDate //As On Date Count = Opening Stock - Diff Qty //Qty Count = Qty Book - Diff Qty query = "SELECT COUNT(*) FROM M_Transaction WHERE movementdate = " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID(); result = Util.GetValueOfInt(DB.ExecuteScalar(query)); if (result > 0) { query = @"SELECT currentqty FROM M_Transaction WHERE M_Transaction_ID = (SELECT MAX(M_Transaction_ID) FROM M_Transaction WHERE movementdate = (SELECT MAX(movementdate) FROM M_Transaction WHERE movementdate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @") AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @") AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID(); currentQty = Util.GetValueOfDecimal(DB.ExecuteScalar(query)); } else { query = "SELECT COUNT(*) FROM M_Transaction WHERE movementdate < " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID(); result = Util.GetValueOfInt(DB.ExecuteScalar(query)); if (result > 0) { query = @"SELECT currentqty FROM M_Transaction WHERE M_Transaction_ID = (SELECT MAX(M_Transaction_ID) FROM M_Transaction WHERE movementdate = (SELECT MAX(movementdate) FROM M_Transaction WHERE movementdate < " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @") AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @") AND M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID(); currentQty = Util.GetValueOfDecimal(DB.ExecuteScalar(query)); } } //End line.SetAdjustmentType("D"); line.SetDifferenceQty(Util.GetValueOfDecimal(confirm.GetDifferenceQty())); line.SetQtyBook(currentQty); line.SetOpeningStock(currentQty); line.SetAsOnDateCount(Decimal.Subtract(Util.GetValueOfDecimal(line.GetOpeningStock()), Util.GetValueOfDecimal(confirm.GetDifferenceQty()))); line.SetQtyCount(Decimal.Subtract(Util.GetValueOfDecimal(line.GetQtyBook()), Util.GetValueOfDecimal(confirm.GetDifferenceQty()))); line.SetDescription(Msg.Translate(GetCtx(), "DifferenceQty")); if (!line.Save(Get_TrxName())) { _processMsg += "Inventory Line not created"; return(false); } confirm.SetM_InventoryLine_ID(line.GetM_InventoryLine_ID()); } // Difference // Scrapped - Create Inventory Difference for TarGet Location if (Env.ZERO.CompareTo(confirm.GetScrappedQty()) != 0) { // Get Warehouse for TarGet MLocator loc = MLocator.Get(GetCtx(), mLine.GetM_LocatorTo_ID()); if (_inventoryTo != null && _inventoryTo.GetM_Warehouse_ID() != loc.GetM_Warehouse_ID()) { _inventoryTo = null; } if (_inventoryTo == null) { MWarehouse wh = MWarehouse.Get(GetCtx(), loc.GetM_Warehouse_ID()); _inventoryTo = new MInventory(wh); _inventoryTo.SetDescription(Msg.Translate(GetCtx(), "M_MovementConfirm_ID") + " " + GetDocumentNo()); if (!_inventoryTo.Save(Get_TrxName())) { _processMsg += "Inventory not created"; return(false); } // First Inventory if (GetM_Inventory_ID() == 0) { SetM_Inventory_ID(_inventoryTo.GetM_Inventory_ID()); _inventoryInfo = _inventoryTo.GetDocumentNo(); } else { _inventoryInfo += "," + _inventoryTo.GetDocumentNo(); } } log.Info("CreateDifferenceDoc - Scrapped=" + confirm.GetScrappedQty()); MInventoryLine line = new MInventoryLine(_inventoryTo, mLine.GetM_LocatorTo_ID(), mLine.GetM_Product_ID(), mLine.GetM_AttributeSetInstance_ID(), confirm.GetScrappedQty(), Env.ZERO); line.SetDescription(Msg.Translate(GetCtx(), "ScrappedQty")); if (!line.Save(Get_TrxName())) { _processMsg += "Inventory Line not created"; return(false); } confirm.SetM_InventoryLine_ID(line.GetM_InventoryLine_ID()); } // Scrapped return(true); }