示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ordID"></param>
        /// <param name="returnToApproval">When false, the order is cancelled completely</param>
        /// <returns></returns>
        public static bool ReleaseReservation(int ordID, bool returnToApproval)
        {
            BLL.Order ord = new BLL.Order();
            ord.LoadByPrimaryKey(ordID);
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            try
            {
                transaction.BeginTransaction();
                if (ord.RowCount > 0 && (ord.OrderStatusID == OrderStatus.Constant.PICK_LIST_GENERATED || ord.OrderStatusID == OrderStatus.Constant.PICK_LIST_CONFIRMED))
                {
                    ord.ReleaseReservation();
                    if (returnToApproval)
                    {
                        ord.ChangeStatus(OrderStatus.Constant.ORDER_FILLED, CurrentContext.UserId);
                    }
                    else
                    {
                        ord.ChangeStatus(OrderStatus.Constant.CANCELED, CurrentContext.UserId);
                    }
                    ord.Save();
                }

                transaction.CommitTransaction();
                return(true);
            }
            catch (Exception exp)
            {
                transaction.RollbackTransaction();
                throw (exp);
            }
        }
        /// <summary>
        /// Saves the whole transaction for
        /// </summary>
        /// <param name="orderID">The order ID.</param>
        /// <param name="dvOutstandingPickList">The dv outstanding pick list.</param>
        /// <param name="remark">The remark.</param>
        /// <param name="issuedBy">The issued by.</param>
        /// <param name="etCurrentDate">The et current date.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception"></exception>
        public static Order SaveIssueTransaction(int orderID, ref DataView dvOutstandingPickList, string remark, string issuedBy, DateTime etCurrentDate)
        {
            // Add the IssueDocID field
            dvOutstandingPickList.Table.Columns.Add("IssueDocID");
            PickList plst = new PickList();
            IssueDoc issDoc = new IssueDoc();
            ReceiveDoc recDoc = new ReceiveDoc();
            BLL.Order ord = new BLL.Order();
            ord.LoadByPrimaryKey(orderID);
            plst.LoadByOrderID(ord.ID);

            foreach (DataRowView drv in dvOutstandingPickList)
            {
                // Pseudo:
                // for each row in the picklist
                // undate the issue document
                // subtract the issued quantity from the receive doc
                // subtract the issued quantity from recieve pallet
                // subtract the issued the reserved quantity irregardless of the quantity issued.

                //Saving the new Issue issue
                if (Convert.ToDecimal(drv["BUPICKED"]) == 0)
                {
                    continue;

                }

                if (Convert.ToDecimal(drv["SKUPicked"]) != Convert.ToDecimal(drv["SKUTOPICK"]))
                {
                    drv["Cost"] = Convert.ToDecimal(drv["SKUPicked"]) * Convert.ToDecimal(drv["UnitPrice"]);
                }

                // Select the receive doc that is associated with this issue.
                recDoc.LoadByPrimaryKey(Convert.ToInt32(drv["ReceiveDocID"]));

                issDoc.AddNew();
                issDoc.StoreId = Convert.ToInt32(drv["StoreID"]);
                issDoc.RefNo = ord.RefNo;
                if (!ord.IsColumnNull("RequestedBy"))
                    issDoc.ReceivingUnitID = ord.RequestedBy;
                // TOFIX:
                // TODO:
                // Lord have mercy kind of hack to avoid the feb date problem
                // this needs to be fixed for pagume also
                issDoc.Date = etCurrentDate;
                issDoc.EurDate = DateTimeHelper.ServerDateTime;
                issDoc.RecievDocID = Convert.ToInt32(drv["ReceiveDocID"]);
                issDoc.IsApproved = true;
                issDoc.IsTransfer = false;
                issDoc.Remark = remark;
                issDoc.ItemID = Convert.ToInt32(drv["ItemID"]);
                issDoc.Quantity = Convert.ToDecimal(drv["BUPICKED"]);
                issDoc.NoOfPack = Convert.ToDecimal(drv["SKUPICKED"]);
                issDoc.QtyPerPack = Convert.ToInt32(drv["SKUBU"]);
                issDoc.BatchNo = drv["BatchNumber"].ToString();
                issDoc.UnitID = recDoc.UnitID;
                issDoc.ManufacturerID = recDoc.ManufacturerId;
                if (drv["Cost"] != DBNull.Value)
                {
                    issDoc.Cost = Convert.ToDouble(drv["Cost"]);

                    issDoc.SellingPrice = Convert.ToDecimal(drv["UnitPrice"]);
                    if (!recDoc.IsColumnNull("Cost"))
                    {
                        issDoc.UnitCost = Convert.ToDecimal(recDoc.Cost);
                    }
                }
                issDoc.OrderID = orderID;
                issDoc.IssuedBy = issuedBy;
                // TODO: is this the right place where we need to pick the physical store ID from?
                // check it against the receipt pallet physical store.
                if (!recDoc.IsColumnNull("PhysicalStoreID"))
                {
                    issDoc.PhysicalStoreID = recDoc.PhysicalStoreID;
                }
                if (!recDoc.IsColumnNull("InventoryPeriodID"))
                {
                    //Todo: Remove for Inventory
                    issDoc.InventoryPeriodID = recDoc.InventoryPeriodID;
                }
                if (!recDoc.IsColumnNull("Margin"))
                {
                    issDoc.Margin = (decimal)recDoc.Margin;
                }
                //Replaced by
                issDoc.PLDetailID = Convert.ToInt32(drv["PLDetailID"]);
                BLL.Balance bal = new Balance();
                BLL.ReceiveDoc rd = new ReceiveDoc();
                rd.LoadByPrimaryKey(issDoc.RecievDocID);
                decimal currentBalance = bal.GetSoh(issDoc.ItemID, rd.UnitID, issDoc.StoreId, issDoc.Date.Month, issDoc.Date.Year);
                if (currentBalance < issDoc.NoOfPack)
                {
                    throw new Exception(string.Format("The item {0} is not available in {1} Qty.", drv["FullItemName"].ToString(), issDoc.NoOfPack));
                }

                // This is a field that is not applicable on the hub edition
                // It is about the dispensing unit quantity and there is no such thing as Dispensing unit
                // in the hub edition
                issDoc.DUSOH = 0;
                issDoc.RecomendedQty = 0;// ((recQty > 0) ? Convert.ToInt64(recQty) : 0);
                // End DU
                issDoc.DispatchConfirmed = false;
                issDoc.Save();
                drv["IssueDocID"] = issDoc.ID;
                // updating the receiving doc

                //long prevQuantityLeft = recDoc.QuantityLeft;

                recDoc.QuantityLeft = recDoc.QuantityLeft - issDoc.Quantity;

                if (recDoc.QuantityLeft < 0)
                {
                    //Possibly the wrong ReceiveDoc Entry chosen
                    BLL.Item itm = new Item();
                    itm.LoadByPrimaryKey(recDoc.ItemID);
                    throw new Exception(string.Format("Quantity problem detected for the item {0}", itm.FullItemName));
                }
                //long
                recDoc.Out = (recDoc.QuantityLeft == 0) ? true : false;
                recDoc.Save();

                ReceivePallet rp = new ReceivePallet();
                int id = Convert.ToInt32(drv["ReceivePalletID"]);
                rp.LoadByPrimaryKey(id);
                if (rp.IsColumnNull("Balance"))
                {
                    rp.Balance = rp.ReceivedQuantity;
                }
                rp.Balance -= issDoc.Quantity;

                if (rp.Balance < 0)
                {
                    BLL.Item itm = new Item();
                    itm.LoadByPrimaryKey(recDoc.ItemID);
                    throw new Exception(string.Format("Quantity problem detected for the item {0}", itm.FullItemName));
                }

                decimal totReservedQty = Convert.ToDecimal(drv["QuantityInBU"]);

                if (rp.IsColumnNull("ReservedStock"))
                    rp.ReservedStock = 0;

                rp.ReservedStock -= totReservedQty;
                if (rp.ReservedStock < 0) //If there has been a quantity problem somewhere
                    rp.ReservedStock = 0;
                rp.Save();
            }
            plst.IsConfirmed = true;
            ord.ChangeStatus(OrderStatus.Constant.ISSUED, CurrentContext.UserId);
            plst.Save();
            ord.Save();
            return ord;
        }
        public static int SavePLITSApprovedOrderToDatabase(int Status, int userID, int? plitsOrderID, int facilityID, int paymentType,
                                              int modeID, string remarks, string letterNumber, string contactPerson,
                                              BLL.OrderDetail _PLITSOrderDetail)
        {
            int hcmisorderid;
            MyGeneration.dOOdads.TransactionMgr mgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            try
            {
                mgr.BeginTransaction();
                BLL.Order or = new BLL.Order();

                or.AddNew();
                or.RefNo = Order.GetNextOrderReference();
                or.OrderTypeID = OrderType.CONSTANTS.PLITS;
                or.HCTSReferenceID = plitsOrderID.Value;

                or.OrderStatusID = Status;

                or.RequisitionTypeID = RequisitionType.CONSTANTS.DEMAND;
                or.Remark = remarks;

                or.EurDate = or.Date = DateTimeHelper.ServerDateTime; //Both fields are assigned dates.
                var institution = new Institution();
                institution.LoadBySN(facilityID);
                or.RequestedBy = institution.ID;
                or.FilledBy = userID;
                or.LetterNo = letterNumber;
                or.PaymentTypeID = paymentType;
                or.ContactPerson = contactPerson;
                or.FromStore = modeID;
                or.FiscalYearID = FiscalYear.Current.ID;
                or.Save();
                or.LogRequisitionStatus(or.ID,null,Status, CurrentContext.UserId); //Log OrderStatus change

                _PLITSOrderDetail.Rewind();
                while (!_PLITSOrderDetail.EOF)
                {
                    _PLITSOrderDetail.OrderID = or.ID;

                    _PLITSOrderDetail.MoveNext();
                }
                _PLITSOrderDetail.Save();

                hcmisorderid = or.ID;
                //this.LogActivity("Save-Requisition", ord.ID);
                mgr.CommitTransaction();

            }
            catch (Exception exp)
            {
                mgr.RollbackTransaction();
                return 0;
                throw (exp);
            }
            //ResetOrder();
            return hcmisorderid;
        }
        public static Order SaveOrderToDB(int Status, int userID, int? orderID, int facilityID, int paymentType,
                                       int modeID, string remarks, string letterNumber, string contactPerson,
                                       DataView _dvOrderTable)
        {
            MyGeneration.dOOdads.TransactionMgr mgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            try
            {
                mgr.BeginTransaction();
                BLL.Order or = new BLL.Order();
                if (orderID == null)
                {
                    or.AddNew();
                    or.RefNo = Order.GetNextOrderReference();
                    or.OrderTypeID = OrderType.CONSTANTS.STANDARD_ORDER;
                    or.FiscalYearID = FiscalYear.Current.ID;
                }
                else
                {
                    or.LoadByPrimaryKey(orderID.Value);
                }

                var oldOrderStatus = or.IsColumnNull("OrderStatusID") ? (int?)null : or.OrderStatusID;
                or.OrderStatusID = Status;
                or.RequisitionTypeID = RequisitionType.CONSTANTS.DEMAND;
                or.Remark = remarks;

                or.EurDate = or.Date = DateTimeHelper.ServerDateTime; //Both fields are assigned dates.
                or.RequestedBy = facilityID;
                or.FilledBy = userID;
                or.LetterNo = letterNumber;
                or.PaymentTypeID = paymentType;
                or.ContactPerson = contactPerson;
                or.FromStore = modeID;

                or.Save();
                or.LogRequisitionStatus(or.ID, oldOrderStatus, Status, CurrentContext.UserId); //Log OrderStatus Change

                // this is a kind of initializing the data table.
                OrderDetail ord = new OrderDetail();
                foreach (DataRowView r in _dvOrderTable)
                {
                    int itemID = Convert.ToInt32(r["ItemID"]);
                    int unitID = Convert.ToInt32(r["UnitID"]);

                    ord.LoadByItemUnit(or.ID, itemID, unitID);
                    if (ord.RowCount == 0)
                    {
                        ord.AddNew();
                    }
                    ord.OrderID = or.ID;
                    ord.ItemID = itemID;
                    if (r["Pack"] != DBNull.Value)
                    {
                        ord.Pack = Convert.ToDecimal(r["Pack"]);
                    }
                    if (r["QtyPerPack"] != DBNull.Value)
                    {
                        ord.QtyPerPack = Convert.ToInt32(r["QtyPerPack"]);
                    }

                    if (r["StockOnHand"] != DBNull.Value)
                    {
                        ord.StockOnHand = Convert.ToDecimal(r["StockOnHand"]);
                    }

                    //if (r["ExpiredStock"] != DBNull.Value)
                    //{
                    //    ord.ExpiredStock = Convert.ToDecimal(r["ExpiredStock"]);
                    //}

                    //if (r["DamagedStock"] != DBNull.Value)
                    //{
                    //    ord.DamagedStock = Convert.ToDecimal(r["DamagedStock"]);
                    //}
                    ord.Quantity = Convert.ToDecimal(r["Quantity"]);
                    ord.UnitID = unitID;
                    //ord.StoreID = or.FromStore;
                    ord.Save();
                }
                //this.LogActivity("Save-Requisition", ord.ID);
                mgr.CommitTransaction();

                return or;
            }
            catch (Exception exp)
            {
                mgr.RollbackTransaction();
                throw;
            }
            //ResetOrder();
        }
        //~ This Method is Obsoleted ~//
        public static bool SaveBackOrderToDatabase(BLL.Order _order)
        {
            var _orderDetail = new OrderDetail();
            _orderDetail.LoadAllByOrderID(_order.ID);

            MyGeneration.dOOdads.TransactionMgr mgr = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            try
            {
                mgr.BeginTransaction();
                var or = new BLL.Order();

                or.AddNew();
                or.RefNo = Order.GetNextOrderReference();
                or.SetColumn("OrderTypeID", _order.GetColumn("OrderTypeID"));
                or.SetColumn("HCTSReferenceID", _order.GetColumn("HCTSReferenceID"));

                or.OrderStatusID = OrderStatus.Constant.DRAFT_WISHLIST;
                or.RequisitionTypeID = RequisitionType.CONSTANTS.DEMAND;
                or.Remark = _order.ID.ToString(); //Store the Original ID here for the backorder.  We need to have a standard way of marking backorders.

                or.EurDate = or.Date = DateTimeHelper.ServerDateTime; //Both fields are assigned dates.
                or.RequestedBy = _order.RequestedBy;
                or.FilledBy = _order.FilledBy;
                or.LetterNo = _order.LetterNo;
                or.PaymentTypeID = _order.PaymentTypeID;
                or.ContactPerson = _order.ContactPerson;
                or.FromStore = _order.FromStore;
                or.FiscalYearID = FiscalYear.Current.ID;
                or.OrderTypeID = _order.OrderTypeID == OrderType.CONSTANTS.PLITS
                                     ? _order.OrderTypeID
                                     : OrderType.CONSTANTS.BACK_ORDER;

                or.Save();
                or.LogRequisitionStatus(or.ID,null,OrderStatus.Constant.DRAFT_WISHLIST,CurrentContext.UserId);
                _orderDetail.Rewind();
                var orderDetail = new OrderDetail();

                while (!_orderDetail.EOF)
                {
                    if (_orderDetail.ApprovedQuantity >= _orderDetail.Quantity)
                    {
                        _orderDetail.MoveNext();
                        continue; //Backorder is only for those with approved quantity less than the requested quantity.
                    }
                    orderDetail.AddNew();
                    orderDetail.ItemID = _orderDetail.ItemID;
                    orderDetail.OrderID = or.ID;
                    orderDetail.Pack = (_orderDetail.Quantity - _orderDetail.ApprovedQuantity) /
                                       _orderDetail.QtyPerPack;
                    orderDetail.QtyPerPack = _orderDetail.QtyPerPack;
                    orderDetail.Quantity = orderDetail.Pack * orderDetail.QtyPerPack;
                    orderDetail.SetColumn("HACTOrderDetailID", _orderDetail.GetColumn("HACTOrderDetailID"));
                    orderDetail.UnitID = _orderDetail.UnitID;

                    _orderDetail.MoveNext();
                }

                orderDetail.Save();
                mgr.CommitTransaction();
                return true;
            }
            catch (Exception exp)
            {
                mgr.RollbackTransaction();
                return false;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ordID"></param>
        /// <param name="returnToApproval">When false, the order is cancelled completely</param>
        /// <returns></returns>
        public static bool ReleaseReservation(int ordID, bool returnToApproval)
        {
            BLL.Order ord = new BLL.Order();
            ord.LoadByPrimaryKey(ordID);
            MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
            try
            {
                transaction.BeginTransaction();
                if (ord.RowCount > 0 && (ord.OrderStatusID == OrderStatus.Constant.PICK_LIST_GENERATED || ord.OrderStatusID == OrderStatus.Constant.PICK_LIST_CONFIRMED))
                {
                    ord.ReleaseReservation();
                    if (returnToApproval)
                    {
                        ord.ChangeStatus(OrderStatus.Constant.ORDER_FILLED,CurrentContext.UserId);
                    }
                    else
                    {
                        ord.ChangeStatus(OrderStatus.Constant.CANCELED,CurrentContext.UserId);
                    }
                    ord.Save();
                }

                transaction.CommitTransaction();
                return true;
            }
            catch (Exception exp)
            {
                transaction.RollbackTransaction();
                throw (exp);
            }
        }
        /// <summary>
        /// Saves the whole transaction for
        /// </summary>
        /// <param name="orderID">The order ID.</param>
        /// <param name="dvOutstandingPickList">The dv outstanding pick list.</param>
        /// <param name="remark">The remark.</param>
        /// <param name="issuedBy">The issued by.</param>
        /// <param name="etCurrentDate">The et current date.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception"></exception>
        public static Order SaveIssueTransaction(int orderID, ref DataView dvOutstandingPickList, string remark, string issuedBy, DateTime etCurrentDate)
        {
            // Add the IssueDocID field
            dvOutstandingPickList.Table.Columns.Add("IssueDocID");
            PickList   plst   = new PickList();
            IssueDoc   issDoc = new IssueDoc();
            ReceiveDoc recDoc = new ReceiveDoc();

            BLL.Order ord = new BLL.Order();
            ord.LoadByPrimaryKey(orderID);
            plst.LoadByOrderID(ord.ID);

            foreach (DataRowView drv in dvOutstandingPickList)
            {
                // Pseudo:
                // for each row in the picklist
                // undate the issue document
                // subtract the issued quantity from the receive doc
                // subtract the issued quantity from recieve pallet
                // subtract the issued the reserved quantity irregardless of the quantity issued.


                //Saving the new Issue issue
                if (Convert.ToDecimal(drv["BUPICKED"]) == 0)
                {
                    continue;
                }

                if (Convert.ToDecimal(drv["SKUPicked"]) != Convert.ToDecimal(drv["SKUTOPICK"]))
                {
                    drv["Cost"] = Convert.ToDecimal(drv["SKUPicked"]) * Convert.ToDecimal(drv["UnitPrice"]);
                }

                // Select the receive doc that is associated with this issue.
                recDoc.LoadByPrimaryKey(Convert.ToInt32(drv["ReceiveDocID"]));


                issDoc.AddNew();
                issDoc.StoreId = Convert.ToInt32(drv["StoreID"]);
                issDoc.RefNo   = ord.RefNo;
                if (!ord.IsColumnNull("RequestedBy"))
                {
                    issDoc.ReceivingUnitID = ord.RequestedBy;
                }
                // TOFIX:
                // TODO:
                // Lord have mercy kind of hack to avoid the feb date problem
                // this needs to be fixed for pagume also
                issDoc.Date           = etCurrentDate;
                issDoc.EurDate        = DateTimeHelper.ServerDateTime;
                issDoc.RecievDocID    = Convert.ToInt32(drv["ReceiveDocID"]);
                issDoc.IsApproved     = true;
                issDoc.IsTransfer     = false;
                issDoc.Remark         = remark;
                issDoc.ItemID         = Convert.ToInt32(drv["ItemID"]);
                issDoc.Quantity       = Convert.ToDecimal(drv["BUPICKED"]);
                issDoc.NoOfPack       = Convert.ToDecimal(drv["SKUPICKED"]);
                issDoc.QtyPerPack     = Convert.ToInt32(drv["SKUBU"]);
                issDoc.BatchNo        = drv["BatchNumber"].ToString();
                issDoc.UnitID         = recDoc.UnitID;
                issDoc.ManufacturerID = recDoc.ManufacturerId;
                if (drv["Cost"] != DBNull.Value)
                {
                    issDoc.Cost = Convert.ToDouble(drv["Cost"]);

                    issDoc.SellingPrice = Convert.ToDecimal(drv["UnitPrice"]);
                    if (!recDoc.IsColumnNull("Cost"))
                    {
                        issDoc.UnitCost = Convert.ToDecimal(recDoc.Cost);
                    }
                }
                issDoc.OrderID  = orderID;
                issDoc.IssuedBy = issuedBy;
                // TODO: is this the right place where we need to pick the physical store ID from?
                // check it against the receipt pallet physical store.
                if (!recDoc.IsColumnNull("PhysicalStoreID"))
                {
                    issDoc.PhysicalStoreID = recDoc.PhysicalStoreID;
                }
                if (!recDoc.IsColumnNull("InventoryPeriodID"))
                {
                    //Todo: Remove for Inventory
                    issDoc.InventoryPeriodID = recDoc.InventoryPeriodID;
                }
                if (!recDoc.IsColumnNull("Margin"))
                {
                    issDoc.Margin = (decimal)recDoc.Margin;
                }
                //Replaced by
                issDoc.PLDetailID = Convert.ToInt32(drv["PLDetailID"]);
                BLL.Balance    bal = new Balance();
                BLL.ReceiveDoc rd  = new ReceiveDoc();
                rd.LoadByPrimaryKey(issDoc.RecievDocID);
                decimal currentBalance = bal.GetSoh(issDoc.ItemID, rd.UnitID, issDoc.StoreId, issDoc.Date.Month, issDoc.Date.Year);
                if (currentBalance < issDoc.NoOfPack)
                {
                    throw new Exception(string.Format("The item {0} is not available in {1} Qty.", drv["FullItemName"].ToString(), issDoc.NoOfPack));
                }

                // This is a field that is not applicable on the hub edition
                // It is about the dispensing unit quantity and there is no such thing as Dispensing unit
                // in the hub edition
                issDoc.DUSOH         = 0;
                issDoc.RecomendedQty = 0;// ((recQty > 0) ? Convert.ToInt64(recQty) : 0);
                // End DU
                issDoc.DispatchConfirmed = false;
                issDoc.Save();
                drv["IssueDocID"] = issDoc.ID;
                // updating the receiving doc

                //long prevQuantityLeft = recDoc.QuantityLeft;

                recDoc.QuantityLeft = recDoc.QuantityLeft - issDoc.Quantity;

                if (recDoc.QuantityLeft < 0)
                {
                    //Possibly the wrong ReceiveDoc Entry chosen
                    BLL.Item itm = new Item();
                    itm.LoadByPrimaryKey(recDoc.ItemID);
                    throw new Exception(string.Format("Quantity problem detected for the item {0}", itm.FullItemName));
                }
                //long
                recDoc.Out = (recDoc.QuantityLeft == 0) ? true : false;
                recDoc.Save();

                ReceivePallet rp = new ReceivePallet();
                int           id = Convert.ToInt32(drv["ReceivePalletID"]);
                rp.LoadByPrimaryKey(id);
                if (rp.IsColumnNull("Balance"))
                {
                    rp.Balance = rp.ReceivedQuantity;
                }
                rp.Balance -= issDoc.Quantity;

                if (rp.Balance < 0)
                {
                    BLL.Item itm = new Item();
                    itm.LoadByPrimaryKey(recDoc.ItemID);
                    throw new Exception(string.Format("Quantity problem detected for the item {0}", itm.FullItemName));
                }

                decimal totReservedQty = Convert.ToDecimal(drv["QuantityInBU"]);

                if (rp.IsColumnNull("ReservedStock"))
                {
                    rp.ReservedStock = 0;
                }

                rp.ReservedStock -= totReservedQty;
                if (rp.ReservedStock < 0) //If there has been a quantity problem somewhere
                {
                    rp.ReservedStock = 0;
                }
                rp.Save();
            }
            plst.IsConfirmed = true;
            ord.ChangeStatus(OrderStatus.Constant.ISSUED, CurrentContext.UserId);
            plst.Save();
            ord.Save();
            return(ord);
        }