private void btnRelocatePallet_Click(object sender, EventArgs e)
        {
            //Get the chosen pallet Location
            BLL.PalletLocation palletLocation = new BLL.PalletLocation();
            palletLocation.LoadByPrimaryKey(Convert.ToInt16(lkAvailablePalletLocation.EditValue));

            //Get the chosen misplaced receivepallet entry
            DataRow dr = grdViewMisplacedItems.GetFocusedDataRow();
            int     receivePalletID = Convert.ToInt32(dr["ID"]);

            BLL.ReceivePallet rp = new BLL.ReceivePallet();
            rp.LoadByPrimaryKey(receivePalletID);
            if (palletLocation.IsColumnNull("PalletID"))
            {
                palletLocation.PalletID = rp.PalletID;
                palletLocation.Save();
            }
            else
            {
                rp.PalletID = palletLocation.PalletID;
                rp.Save();
            }

            int storeID = Convert.ToInt16(lkStoreLocation.EditValue);

            LoadMisplacedItems(storeID);

            XtraMessageBox.Show("Placed!!");
        }
        public static void ReserveQty(decimal pack, int receivePalletId, bool isOriginalReceive = true)
        {
            var receivepallet = new ReceivePallet();

            receivepallet.LoadByPrimaryKey(receivePalletId);
            receivepallet.IsOriginalReceive = isOriginalReceive;
            receivepallet.ReservedStock     = receivepallet.ReservedStock + pack;
            if (receivepallet.Balance >= receivepallet.ReservedStock)
            {
                receivepallet.Save();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Undo pick list that has been printed
        /// </summary>
        /// <param name="orderID">The order ID.</param>
        public void CancelOrderWithPickList(int orderID)
        {
            // Create a pick list entry
            Order          ord            = new Order();
            PickList       pl             = new PickList();
            PickListDetail pld            = new PickListDetail();
            ReceivePallet  rp             = new ReceivePallet();
            ReceiveDoc     rd             = new ReceiveDoc();
            PickFace       pf             = new PickFace();
            PalletLocation palletLocation = new PalletLocation();


            ord.LoadByPrimaryKey(orderID);
            pl.LoadByOrderID(orderID);

            pld.LoadByPickListID(pl.ID);

            while (!pld.EOF)
            {
                rp.LoadByPrimaryKey(pld.ReceivePalletID);
                rp.ReservedStock -= Convert.ToInt32(pld.QuantityInBU);
                if (rp.ReservedStock < 0)
                {
                    rp.ReservedStock = 0; //If there has been no reservation, allow to cancel the picklist too.  No need for it to be blocked by the constraint.
                }
                rp.Save();
                palletLocation.LoadByPrimaryKey(pld.PalletLocationID);
                if (palletLocation.StorageTypeID.ToString() == StorageType.PickFace)
                {
                    pf.LoadByPalletLocation(pld.PalletLocationID);
                    pf.Balance += Convert.ToInt32(pld.QuantityInBU);
                    pf.Save();
                }

                //Delete from picklistDetail and add to pickListDetailDeleted
                PickListDetailDeleted.AddNewLog(pld, BLL.CurrentContext.UserId);
                pld.MarkAsDeleted();
                pld.MoveNext();
            }
            pld.Save();
            ord.ChangeStatus(OrderStatus.Constant.CANCELED, CurrentContext.UserId);

            pl.MarkAsDeleted();
            pl.Save();
        }
        //,bool pricedItems)
        /// <summary>
        /// Gets picked order detail for item (Used by the IssueLog)
        /// </summary>
        /// <param name="ordID"></param>
        /// <param name="storeid"></param>
        /// <param name="pricedItems">True - For Priced Items Only, False - For Delivery Notes Only</param>
        /// <returns></returns>
        public DataView GetPickedOrderDetailForOrder(int stvLogID, bool includeDeleted)
        {
            string query;

            // remove this line ...
            // check if this has changed the dn to stv conversion
            // (pld.DeliveryNote is null or pld.DeliveryNote = 0 or (pld.DeliveryNote=1 and pld.UnitPrice<>0)) and
            query = HCMIS.Repository.Queries.PickList.SelectGetPickedOrderDetailForOrder(stvLogID);
            if (includeDeleted)
            {
                query = HCMIS.Repository.Queries.PickList.SelectGetPickedOrderDetailForOrderIncludeDeleted(stvLogID);
            }

            this.LoadFromRawSql(query);
            // Add important columns
            this.DataTable.Columns.Add("SKUTOPICK", typeof(int));
            this.DataTable.Columns.Add("SKUPICKED", typeof(int));
            this.DataTable.Columns.Add("BUPICKED", typeof(int));
            this.DataTable.Columns.Add("BoxSizeDisplay");
            this.DataTable.Columns.Add("SKUBU", typeof(int));
            this.DataTable.Columns.Add("IsManufacturerLocal", typeof(bool));
            this.DataTable.Columns.Add("PrintedSTVNumber", typeof(string));
            this.DataTable.Columns.Add("PhysicalStoreName", typeof(string));
            this.DataTable.Columns.Add("PhysicalStoreTypeID", typeof(int));
            this.DataTable.Columns.Add("PhysicalStoreTypeName", typeof(string));

            ItemManufacturer im = new ItemManufacturer();
            int i = 1;
            while (!this.EOF)
            {
                int packs = Convert.ToInt32(this.GetColumn("Packs"));
                int manufacturer = Convert.ToInt32(this.GetColumn("ManufacturerID"));
                Manufacturer m = new Manufacturer();
                m.LoadByPrimaryKey(manufacturer);
                if (!m.IsColumnNull("CountryOfOrigin") && m.CountryOfOrigin == "Ethiopia")
                    this.SetColumn("IsManufacturerLocal", true);
                else
                    this.SetColumn("IsManufacturerLocal", false);

                int recPalletID = Convert.ToInt32(this.GetColumn("ReceivePalletID"));
                ReceivePallet rp = new ReceivePallet();
                rp.LoadByPrimaryKey(recPalletID);
                try
                {
                    this.SetColumn("PhysicalStoreName", rp.GetPhysicalStoreName());
                    int physicalStoreTypeID = rp.GetPhysicalStoreTypeID();
                    this.SetColumn("PhysicalStoreTypeID", physicalStoreTypeID);
                    Warehouse phyStoreType = new Warehouse();
                    phyStoreType.LoadByPrimaryKey(physicalStoreTypeID);
                    this.SetColumn("PhysicalStoreTypeName", phyStoreType.Name);
                }
                catch
                {
                }

                int itemId = Convert.ToInt32(this.GetColumn("ItemID"));
                int boxLevel = Convert.ToInt32(this.GetColumn("BoxLevel"));
                int qtyPerPack = this.Getint("QtyPerPack");
                //im.LoadIMbyLevel(itemId, manufacturer, boxLevel);
                this.SetColumn("SKUTOPICK", (packs));
                this.SetColumn("SKUPICKED", this.GetColumn("SKUTOPICK"));
                // TODO:show the box size here for Program store
                this.SetColumn("BoxSizeDisplay", "");
                this.SetColumn("SKUBU", qtyPerPack);
                this.SetColumn("BUPICKED", qtyPerPack * Convert.ToInt32(this.GetColumn("SKUPICKED")));
                this.SetColumn("LineNum", i++);
                this.MoveNext();

            }
            return this.DefaultView;
        }
        /// <summary>
        /// Undo pick list that has been printed
        /// </summary>
        /// <param name="orderID">The order ID.</param>
        public void CancelOrderWithPickList(int orderID)
        {
            // Create a pick list entry
            Order ord = new Order();
            PickList pl = new PickList();
            PickListDetail pld = new PickListDetail();
            ReceivePallet rp = new ReceivePallet();
            ReceiveDoc rd = new ReceiveDoc();
            PickFace pf = new PickFace();
            PalletLocation palletLocation = new PalletLocation();

            ord.LoadByPrimaryKey(orderID);
            pl.LoadByOrderID(orderID);

            pld.LoadByPickListID(pl.ID);

            while (!pld.EOF)
            {
                rp.LoadByPrimaryKey(pld.ReceivePalletID);
                rp.ReservedStock -= Convert.ToInt32(pld.QuantityInBU);
                if (rp.ReservedStock < 0)
                    rp.ReservedStock = 0; //If there has been no reservation, allow to cancel the picklist too.  No need for it to be blocked by the constraint.
                rp.Save();
                palletLocation.LoadByPrimaryKey(pld.PalletLocationID);
                if (palletLocation.StorageTypeID.ToString() == StorageType.PickFace)
                {
                    pf.LoadByPalletLocation(pld.PalletLocationID);
                    pf.Balance += Convert.ToInt32(pld.QuantityInBU);
                    pf.Save();
                }

                //Delete from picklistDetail and add to pickListDetailDeleted
                PickListDetailDeleted.AddNewLog(pld, BLL.CurrentContext.UserId);
                pld.MarkAsDeleted();
                pld.MoveNext();
            }
            pld.Save();
            ord.ChangeStatus(OrderStatus.Constant.CANCELED,CurrentContext.UserId);

            pl.MarkAsDeleted();
            pl.Save();
        }
        private void btnMove_Click(object sender, EventArgs e)
        {
            // Validation
            foreach (DataRowView drv in _rpl.DefaultView)
            {
                int Balance = Convert.ToInt32(drv["Balance"]);
                int splited = Convert.ToInt32(drv["BalanceToMove"]);
                if (Balance < splited)
                {
                    XtraMessageBox.Show("Couldn't split to the numbers you specified. Please specify number less than the balance.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            // validate the selected pallet location
            if (lkFreePalletLocations.EditValue == null)
            {
                XtraMessageBox.Show("Please select a valid destination pallet location.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //

            PalletLocation destinationPalletLocatin = new PalletLocation();
            destinationPalletLocatin.LoadByPrimaryKey(Convert.ToInt32(lkFreePalletLocations.EditValue));
            if (destinationPalletLocatin.IsColumnNull("PalletID"))//The Pallet Location is empty
            {
                Pallet pallet = new Pallet();
                pallet.AddNew();
                pallet.Save();
                destinationPalletLocatin.PalletID = pallet.ID;
                destinationPalletLocatin.Save();
            }
            // THIS HAS BEEN REMOVED AS PER RUTH'S SUGGESTION THAT: THE SYSTEM SHOULD NOT BLOCK IF THE WAREHOUSE MANAGER WANTES TO USE
            //else if (destinationPalletLocatin.StorageTypeID.ToString() != BLL.StorageType.Free) //If the pallet location is not empty and it is not free storage, you can't put more on it.
            //{
            //    // the thingy has not been moved
            //    XtraMessageBox.Show("The selected Pallet location is not Empty. Please select another location.", "Error splitting");
            //    return;
            //}

            foreach (DataRowView drv in _rpl.DefaultView)
            {
                int balanceToMove = Convert.ToInt32(drv["BalanceToMove"]);
                int qtyPerPack = Convert.ToInt32(drv["QtyPerPack"]);
                balanceToMove *= qtyPerPack;
                if (balanceToMove > 0)
                {
                    ReceivePallet rpSource = new ReceivePallet();
                    ReceivePallet rpDestination = new ReceivePallet();

                    rpSource.LoadByPrimaryKey(Convert.ToInt32(drv["ID"]));

                    rpDestination.AddNew();

                    //rpDestination.Balance = balanceToMove;//
                    if (!rpSource.IsColumnNull("BoxSize"))
                    {
                        rpDestination.BoxSize = rpSource.BoxSize;
                    }
                    else
                    {
                        rpDestination.BoxSize = 1;
                    }
                    rpDestination.ReceivedQuantity = balanceToMove;
                    rpDestination.PalletID = destinationPalletLocatin.PalletID;//pallet.ID;
                    rpDestination.PalletLocationID = destinationPalletLocatin.ID;
                    rpDestination.ReceiveID = rpSource.ReceiveID;
                    if (!rpSource.IsColumnNull("ReceivedQuantity"))
                        rpSource.ReceivedQuantity -= balanceToMove;
                    //rpSource.Balance -= balanceToMove;//

                    rpDestination.ReservedStock = 0;
                    rpDestination.IsOriginalReceive = false;
                    BLL.ReceivePallet.MoveBalance(rpSource, rpDestination, balanceToMove);
                    //rpSource.Save();
                    //rpDestination.Save();
                }
            }
            XtraMessageBox.Show("The pallet was split.", "Success");
            this.Close();
        }
        private void OnReplenishClicked(object sender, EventArgs e)
        {
            PalletLocation pl = new PalletLocation();
            PickFace pf = new PickFace();
            DataRow dr = gridPickFaceStockLevelView.GetFocusedDataRow();
            DataRow dr2 = gridReplenishmentChoiceView.GetFocusedDataRow();
            if (dr2 != null)
            {
                // check if the replenishment is from allowed location.
                //
                if (!Convert.ToBoolean(dr2["CanReplenish"]))
                {
                    XtraMessageBox.Show("Please choose replenishment from the first to expire items", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                pl.LoadByPrimaryKey(_palletLocationID);
                pf.LoadByPrimaryKey(_pickFaceID);
                if (pf.IsColumnNull("Balance"))
                {
                    pf.Balance = 0;
                }

                if (pl.IsColumnNull("PalletID"))
                {
                    Pallet pallet = new Pallet();
                    pallet.AddNew();
                    pallet.StorageTypeID = Convert.ToInt32(StorageType.PickFace);
                    pallet.Save();
                    pl.PalletID = pallet.ID;
                    pl.Save();
                }

                ReceivePallet rp = new ReceivePallet();
                ReceivePallet rp2 = new ReceivePallet();
                ReceiveDoc rd = new ReceiveDoc();
                rp.LoadByPrimaryKey(Convert.ToInt32(dr2["ReceivePalletID"]));
                rp2.AddNew();
                rp2.IsOriginalReceive = false;
                rp2.PalletID = pl.PalletID;
                rp2.ReceiveID = rp.ReceiveID;
                rp2.BoxSize = rp.BoxSize;

                // calculate the new balance
                BLL.ItemManufacturer im = new BLL.ItemManufacturer();
                im.LoadIMbyLevel(_designatedItemID, Convert.ToInt32(dr2["ManufacturerID"]),Convert.ToInt32(dr2["BoxSize"]));
                if (rp.IsColumnNull("ReservedStock"))
                {
                    rp.ReservedStock = 0;
                }
                //if (rp.Balance - rp.ReservedStock < im.QuantityInBasicUnit )
                //{
                //    XtraMessageBox.Show("You cannot replenish the pick face from this location because the items are reserved for Issue. Please replenish from another receive.","Warning",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                //    return;
                //}
                BLL.ItemManufacturer imff = new BLL.ItemManufacturer();
                imff.LoadOuterBoxForItemManufacturer(im.ItemID,im.ManufacturerID);
                if (imff.PackageLevel > im.PackageLevel && rp.Balance < imff.QuantityInBasicUnit)
                {
                    rp2.Balance = rp.Balance;
                }
                else if (rp.Balance - rp.ReservedStock > im.QuantityInBasicUnit)
                {
                    rp2.ReceivedQuantity = rp2.Balance = im.QuantityInBasicUnit;
                }
                else
                {
                    rp2.Balance = rp.Balance;
                }
                rp2.ReservedStock = 0;
                rp.Balance -= rp2.Balance;
                if (rp.IsColumnNull("ReceivedQuantity"))
                {
                    rp.ReceivedQuantity = rp.Balance + rp2.Balance;
                }
                rp.ReceivedQuantity -= rp2.Balance;
                rp.Save();
                rp2.Save();
                pl.Confirmed = false;
                pl.Save();
                pf.Balance += Convert.ToInt32(rp2.Balance);
                pf.Save();
                PalletLocation pl2 = new PalletLocation();
                pl2.LoadLocationForPallet(rp.PalletID);
                rd.LoadByPrimaryKey(rp2.ReceiveID);
                // Now update the screen accordingly.
                dr["Balance"] = pf.Balance;// Convert.ToInt32(dr["Balance"]) + rp2.Balance;

                InternalTransfer it = new InternalTransfer();

                it.AddNew();
                it.ItemID = _designatedItemID;
                it.BoxLevel = im.PackageLevel;
                it.ExpireDate = rd.ExpDate;
                it.BatchNumber = rd.BatchNo;
                it.ManufacturerID = im.ManufacturerID;
                it.FromPalletLocationID = pl2.ID;
                it.ToPalletLocationID = _palletLocationID;
                it.IssuedDate = DateTimeHelper.ServerDateTime;
                it.QtyPerPack = im.QuantityInBasicUnit;
                it.Packs = 1;
                it.ReceiveDocID = rp.ReceiveID;
                it.QuantityInBU = it.Packs * it.QtyPerPack;
                it.Type = "PickFace";
                it.Status = 0;
                it.Save();

                BindPickFaceDetailAndReplenismehmnent();
                XtraMessageBox.Show("Your Pick Face is updated, please print the replenishment list and confirm the stock movement", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Gets picked order detail for item (Used by the IssueLog)
        /// </summary>
        /// <param name="ordID"></param>
        /// <param name="storeid"></param>
        /// <param name="pricedItems">True - For Priced Items Only, False - For Delivery Notes Only</param>
        /// <returns></returns>
        public DataView GetPickedOrderDetailForOrder(int stvLogID, bool includeDeleted)//,bool pricedItems)
        {
            string query;

            // remove this line ...
            // check if this has changed the dn to stv conversion
            // (pld.DeliveryNote is null or pld.DeliveryNote = 0 or (pld.DeliveryNote=1 and pld.UnitPrice<>0)) and
            query = HCMIS.Repository.Queries.PickList.SelectGetPickedOrderDetailForOrder(stvLogID);
            if (includeDeleted)
            {
                query = HCMIS.Repository.Queries.PickList.SelectGetPickedOrderDetailForOrderIncludeDeleted(stvLogID);
            }



            this.LoadFromRawSql(query);
            // Add important columns
            this.DataTable.Columns.Add("SKUTOPICK", typeof(int));
            this.DataTable.Columns.Add("SKUPICKED", typeof(int));
            this.DataTable.Columns.Add("BUPICKED", typeof(int));
            this.DataTable.Columns.Add("BoxSizeDisplay");
            this.DataTable.Columns.Add("SKUBU", typeof(int));
            this.DataTable.Columns.Add("IsManufacturerLocal", typeof(bool));
            this.DataTable.Columns.Add("PrintedSTVNumber", typeof(string));
            this.DataTable.Columns.Add("PhysicalStoreName", typeof(string));
            this.DataTable.Columns.Add("PhysicalStoreTypeID", typeof(int));
            this.DataTable.Columns.Add("PhysicalStoreTypeName", typeof(string));

            ItemManufacturer im = new ItemManufacturer();
            int i = 1;

            while (!this.EOF)
            {
                int          packs        = Convert.ToInt32(this.GetColumn("Packs"));
                int          manufacturer = Convert.ToInt32(this.GetColumn("ManufacturerID"));
                Manufacturer m            = new Manufacturer();
                m.LoadByPrimaryKey(manufacturer);
                if (!m.IsColumnNull("CountryOfOrigin") && m.CountryOfOrigin == "Ethiopia")
                {
                    this.SetColumn("IsManufacturerLocal", true);
                }
                else
                {
                    this.SetColumn("IsManufacturerLocal", false);
                }

                int           recPalletID = Convert.ToInt32(this.GetColumn("ReceivePalletID"));
                ReceivePallet rp          = new ReceivePallet();
                rp.LoadByPrimaryKey(recPalletID);
                try
                {
                    this.SetColumn("PhysicalStoreName", rp.GetPhysicalStoreName());
                    int physicalStoreTypeID = rp.GetPhysicalStoreTypeID();
                    this.SetColumn("PhysicalStoreTypeID", physicalStoreTypeID);
                    Warehouse phyStoreType = new Warehouse();
                    phyStoreType.LoadByPrimaryKey(physicalStoreTypeID);
                    this.SetColumn("PhysicalStoreTypeName", phyStoreType.Name);
                }
                catch
                {
                }

                int itemId     = Convert.ToInt32(this.GetColumn("ItemID"));
                int boxLevel   = Convert.ToInt32(this.GetColumn("BoxLevel"));
                int qtyPerPack = this.Getint("QtyPerPack");
                //im.LoadIMbyLevel(itemId, manufacturer, boxLevel);
                this.SetColumn("SKUTOPICK", (packs));
                this.SetColumn("SKUPICKED", this.GetColumn("SKUTOPICK"));
                // TODO:show the box size here for Program store
                this.SetColumn("BoxSizeDisplay", "");
                this.SetColumn("SKUBU", qtyPerPack);
                this.SetColumn("BUPICKED", qtyPerPack * Convert.ToInt32(this.GetColumn("SKUPICKED")));
                this.SetColumn("LineNum", i++);
                this.MoveNext();
            }
            return(this.DefaultView);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Saves issue order details
        /// </summary>
        /// <param name="orderID"></param>
        /// <param name="dvPickListMakeup"></param>
        public void SavePickList(int orderID, DataView dvPickListMakeup, int userID)
        {
            //~ Check if This Order has a previous Printed Picklist with detail: Note a header only doesnt affect us! //
            var pickList = new PickList();

            pickList.LoadByOrderID(orderID);
            if (pickList.RowCount > 0)
            {
                var pldetail = new PickListDetail();
                pldetail.LoadByPickListID(pickList.ID);
                if (pldetail.RowCount > 0)
                {
                    RemoveFakePartialCommitPickListDetails(orderID);
                    var pickL = new PickList();
                    pickL.LoadByOrderID(orderID);
                    if (pickL.RowCount > 0)
                    {
                        throw new Exception("Picklist has already been printed for this Order ");
                        // This error has been apprearing for the last one year so funny! I hope it won't come again! day: 10/21/2014 @yido  //
                    }
                }
            }
            // Create a pick list entry
            Order ord = new Order();

            ord.LoadByPrimaryKey(orderID);
            PickList       pl        = new PickList();
            PalletLocation plocation = new PalletLocation();

            plocation.LoadByPrimaryKey(Convert.ToInt32(dvPickListMakeup[0]["PalletLocationID"]));
            pl.AddNew();
            pl.OrderID  = orderID;
            pl.PickType = "Pick";
            pl.PickedBy = userID;

            pl.IsConfirmed          = false;
            pl.IssuedDate           = DateTimeHelper.ServerDateTime;
            pl.SavedDate            = DateTimeHelper.ServerDateTime;
            pl.PickedDate           = DateTimeHelper.ServerDateTime;
            pl.IsWarehouseConfirmed = 0;
            pl.WarehouseID          = plocation.WarehouseID;
            pl.Save();
            PickListDetail pld = new PickListDetail();
            ReceivePallet  rp  = new ReceivePallet();
            ReceiveDoc     rd  = new ReceiveDoc();

            PickFace pf = new PickFace();

            foreach (DataRowView drv in dvPickListMakeup)
            {
                pld.AddNew();
                pld.PickListID    = pl.ID;
                pld.OrderDetailID = Convert.ToInt32(drv["OrderDetailID"]);

                pld.ItemID      = Convert.ToInt32(drv["ItemID"]);
                pld.BatchNumber = (drv["BatchNo"].ToString());
                if (drv["ExpDate"] != DBNull.Value)
                {
                    pld.ExpireDate = Convert.ToDateTime(drv["ExpDate"]);
                }
                pld.ManufacturerID   = Convert.ToInt32(drv["ManufacturerID"]);
                pld.BoxLevel         = Convert.ToInt32(drv["BoxLevel"]);
                pld.QtyPerPack       = Convert.ToInt32(drv["QtyPerPack"]);
                pld.Packs            = Convert.ToDecimal(drv["Pack"]);
                pld.PalletLocationID = Convert.ToInt32(drv["PalletLocationID"]);
                pld.QuantityInBU     = Convert.ToDecimal(drv["QtyInBU"]);
                pld.ReceiveDocID     = Convert.ToInt32(drv["ReceiveDocID"]);
                pld.ReceivePalletID  = Convert.ToInt32(drv["ReceivePalletID"]);
                if (drv["CalculatedCost"] != DBNull.Value)
                {
                    pld.Cost = Convert.ToDouble(drv["CalculatedCost"]);
                }
                if (drv["UnitPrice"] != DBNull.Value)
                {
                    pld.UnitPrice = Convert.ToDouble(drv["UnitPrice"]);
                }
                int ReceivePalletID = Convert.ToInt32(drv["ReceivePalletID"]);
                rp.LoadByPrimaryKey(ReceivePalletID);
                pld.StoreID = Convert.ToInt32(drv["StoreID"]);

                if (drv["DeliveryNote"] != null)
                {
                    pld.DeliveryNote = Convert.ToBoolean(drv["DeliveryNote"]);
                }
                else
                {
                    pld.DeliveryNote = false;
                }


                if (rp.IsColumnNull("ReservedStock"))
                {
                    rp.ReservedStock = Convert.ToDecimal(pld.QuantityInBU);
                }
                else
                {
                    rp.ReservedStock += Convert.ToDecimal(pld.QuantityInBU);
                }
                if (drv["UnitID"] != DBNull.Value)
                {
                    pld.UnitID = Convert.ToInt32(drv["UnitID"]);
                }
                plocation.LoadByPrimaryKey(Convert.ToInt32(drv["PalletLocationID"]));
                pld.PhysicalStoreID = plocation.PhysicalStoreID;

                rp.Save();

                if (drv["StorageTypeID"].ToString() == StorageType.PickFace)
                {
                    pf.LoadByPalletLocation(Convert.ToInt32(drv["PalletLocationID"]));
                    //pf.Balance -= Convert.ToDecimal(pld.QuantityInBU);
                    pf.Save();
                }
            }

            pld.Save();
            ord.ChangeStatus(OrderStatus.Constant.PICK_LIST_GENERATED, CurrentContext.UserId);
            ord.Save();
        }
        /// <summary>
        /// Releases the reservation.
        /// </summary>
        public void ReleaseReservation()
        {
            PickList pickList = new PickList();
            pickList.LoadByOrderID(this.ID);
            if (pickList.RowCount == 0) //If there is no picklist, there is nothing to release.
                return;
            PickListDetail pld = new PickListDetail();
            pld.LoadByPickListID(pickList.ID);
            pld.Rewind();
            while (!pld.EOF)
            {
                ReceivePallet receivePallet = new ReceivePallet();
                receivePallet.LoadByPrimaryKey(pld.ReceivePalletID);
                ReceiveDoc rdoc = new ReceiveDoc();
                rdoc.LoadByPrimaryKey(pld.ReceiveDocID);

                receivePallet.ReservedStock = receivePallet.ReservedStock - Convert.ToInt32(pld.QuantityInBU);
                if (receivePallet.ReservedStock < 0)
                    receivePallet.ReservedStock = 0;
                receivePallet.Save();
                //Delete from picklistDetail and add to pickListDetailDeleted
                PickListDetailDeleted.AddNewLog(pld, BLL.CurrentContext.UserId);
                pld.MarkAsDeleted();
                pld.MoveNext();

                //Delete issues if the order has any
                    var iss = new Issue();
                    iss.GetIssueByOrderID(this.ID);
                iss.Rewind();
                if (iss.RowCount > 0)
                {
                    while (!iss.EOF)
                    {
                        iss.MarkAsDeleted();
                        iss.MoveNext();
                    }
                    iss.Save();
                }

            }
            pld.Save();
            pickList.MarkAsDeleted();
            pickList.Save();
        }
        private void btnMoveToQuaranteen_Click(object sender, EventArgs e)
        {
            if (ValidateMoveToQuaranteen())
            {
                if (DialogResult.Yes == XtraMessageBox.Show("Are you sure you want to move the items to Quarantine", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    InternalItemMovements ims = new InternalItemMovements();
                    PalletLocation pl = new PalletLocation();
                    int printNubmer = InternalTransfer.GetNewPrintNumber() + 1 ;
                    for (int i = 0; i < gridView3.RowCount; i++)
                    {
                        DataRow dr = gridView3.GetDataRow(i);
                        if (dr["Loss"] != DBNull.Value)
                        {
                            int amount = Convert.ToInt32(dr["Loss"]);
                            int palletLocationID = Convert.ToInt32(dr["PalletLocationID"]);

                            ReceivePallet rp = new ReceivePallet();
                            ReceiveDoc rdoc = new ReceiveDoc();

                            rp.LoadByPrimaryKey(Convert.ToInt32(dr["ReceivePalletID"]));
                            rdoc.LoadByPrimaryKey(rp.ReceiveID);
                            amount *= rdoc.QtyPerPack;

                            if (rp.Balance - amount < rp.ReservedStock)
                            {
                                //Item has been reserved for a facility.  This needs to be handled.
                                DataTable dtble = rp.GetFacilitiesItemsReservedFor();
                                string facilities = "";
                                foreach(DataRow dRow in dtble.Rows)
                                {
                                    if (dr != null)
                                        facilities += dRow["Name"].ToString() + System.Environment.NewLine;
                                }
                                XtraMessageBox.Show("You cannot fill in a loss because the item in this location has been reserved to the following facilities:" + System.Environment.NewLine + facilities, "Exisiting reservations must be cancelled", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return;
                            }

                            var receiveDocID = Convert.ToInt32(dr["ID"]);
                            var rec = new ReceiveDoc();
                            rec.LoadByPrimaryKey(receiveDocID);

                            int qPalletLocationID = PalletLocation.GetQuaranteenPalletLocation(rec.PhysicalStoreID);
                            pl.LoadByPrimaryKey(qPalletLocationID);
                            if (pl.IsColumnNull("PalletID"))
                            {
                                Pallet p = new Pallet();
                                p.AddNew();
                                p.StorageTypeID = Convert.ToInt32( StorageType.Quaranteen);
                                p.Save();
                                pl.PalletID = p.ID;
                                pl.Save();
                            }

                            ReceivePallet rp2 = new ReceivePallet();
                            ReceiveDoc rd = new ReceiveDoc();

                            rd.LoadByPrimaryKey(rp.ReceiveID);
                            rp2.AddNew();

                            rp2.PalletID = pl.PalletID;
                            rp2.ReceiveID = rp.ReceiveID;
                            rp2.PalletLocationID = pl.ID;

                            // calculate the new balance
                            BLL.ItemManufacturer im = new BLL.ItemManufacturer();
                            //im.LoadDefaultReceiving(rd.ItemID, Convert.ToInt32(dr["ManufacturerID"]));
                            if (dr["BoxLevel"] == DBNull.Value)
                            {
                                dr["BoxLevel"] = 0;
                            }
                            im.LoadIMbyLevel(rd.ItemID, Convert.ToInt32(dr["ManufacturerID"]), Convert.ToInt32(dr["BoxLevel"]));
                            int packqty = (amount / im.QuantityInBasicUnit);
                            rp2.ReservedStock = 0;

                            BLL.ReceivePallet.MoveBalance(rp, rp2, amount);
                            //rp2.Balance = amount;
                            //rp.Balance -= rp2.Balance;

                            //rp.Save();
                            //rp2.Save();

                            pl.Confirmed = false;
                            pl.Save();
                            if (rp.Balance == 0 )
                            {
                                PalletLocation.GarbageCollection();
                            }

                            InternalTransfer it = new InternalTransfer();
                            it.AddNew();
                            it.ItemID = rd.ItemID;
                            it.BoxLevel = im.PackageLevel;
                            if (!rd.IsColumnNull("ExpDate"))
                            {
                                it.ExpireDate = rd.ExpDate;
                            }
                            it.BatchNumber = rd.BatchNo;
                            it.ManufacturerID = im.ManufacturerID;
                            it.FromPalletLocationID = palletLocationID;
                            it.ToPalletLocationID = qPalletLocationID;
                            it.QtyPerPack = im.QuantityInBasicUnit;
                            it.Packs = packqty;
                            it.ReceiveDocID = rp.ReceiveID;
                            it.QuantityInBU = rp2.Balance; //it.Packs * it.QtyPerPack;
                            it.Type = "ToQuaranteen";
                            it.IssuedDate = DateTime.Today;
                            it.Status = 0;
                            it.PrintNumber = printNubmer;
                            it.Save();
                        }
                    }

                    gridConfirmationControl.DataSource = InternalTransfer.GetAllTransfers("ToQuaranteen");

                    PopulateItemDetails();
                    XtraMessageBox.Show("Your items are marked for movement to Quarantine, please go to Internal Movements page to confirm!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        private void btnCommit_Click(object sender, EventArgs e)
        {
            if (ValidateQuarantine())
            {

                MyGeneration.dOOdads.TransactionMgr transaction = MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();
                transaction.BeginTransaction();
                if (DialogResult.Yes == XtraMessageBox.Show("Are you sure you want to commit the Loss and Adjustment on this screen?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    // do the actual commit here.
                    int printNubmer = InternalTransfer.GetNewPrintNumber() + 1;
                    PalletLocation pl = new PalletLocation();
                    Pallet p = new Pallet();
                    ReceiveDoc rdoc = new ReceiveDoc();
                    ReceivePallet rp = new ReceivePallet();
                    for (int i = 0; i < gridView1.RowCount; i++)
                    {
                        DataRow dr = gridView1.GetDataRow(i);
                        Double writeoff = 0;
                        Double reLocate = 0;
                        try
                        {
                            if (dr["WriteOff"] != DBNull.Value)
                            {
                                writeoff = Double.Parse(dr["WriteOff"].ToString());
                            }
                            if (dr["ReLocate"] != DBNull.Value)
                            {
                                reLocate = Double.Parse(dr["ReLocate"].ToString());
                            }
                        }
                        catch (Exception exc)
                        {
                        }

                        if(dr["WriteOff"] != DBNull.Value & writeoff>0)
                        {
                            if (Double.Parse(dr["WriteOff"].ToString()) > Double.Parse(dr["Balance"].ToString()))
                            {
                                XtraMessageBox.Show("Couldn't commit to the numbers you specified. Please specify number less than the balance.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                            int writeoffAmout = Convert.ToInt32(dr["WriteOff"]);
                            int qtyPerPack = Convert.ToInt32(dr["QtyPerPack"]);
                            writeoffAmout *= qtyPerPack;
                            rp.LoadByPrimaryKey(Convert.ToInt32(dr["ReceivePalletID"]));
                            rdoc.LoadByPrimaryKey(rp.ReceiveID);
                            string x = dr["NewPalletLocation"].ToString();
                            rp.Balance -= writeoffAmout;
                            try
                            {
                              //  rp.ReceivedQuantity -= writeoffAmout;
                            }
                            catch { }
                            rdoc.QuantityLeft -= writeoffAmout;

                             ReceivePallet nrp =new ReceivePallet();
                             nrp.AddNew();
                             nrp.ReceiveID = rp.ReceiveID;
                             nrp.PalletID = pl.GetpalletidbyPalletLocationOrgetnew(int.Parse(dr["NewPalletLocation"].ToString()));
                            //nrp.ReceivedQuantity = rp.ReceivedQuantity;
                            nrp.Balance = writeoffAmout;
                            nrp.ReservedStock = 0;
                            //nrp.ReserveOrderID = rp.ReserveOrderID;
                            nrp.BoxSize = rp.BoxSize;
                            nrp.PalletLocationID = int.Parse(dr["NewPalletLocation"].ToString());
                            nrp.IsOriginalReceive = rp.IsOriginalReceive;

                            BLL.LossAndAdjustment d = new BLL.LossAndAdjustment();
                            d.AddNew();
                            d.GenerateRefNo();
                            d.ItemID = Convert.ToInt32(dr["ItemID"]);
                            d.ReasonId = Convert.ToInt32(dr["Reason"]);
                            d.RecID = rdoc.ID;
                            d.Quantity = writeoffAmout;
                            d.BatchNo = rdoc.BatchNo;

                            CalendarLib.DateTimePickerEx edate = new CalendarLib.DateTimePickerEx();
                            edate.Value = DateTime.Today;
                            //TODO: fix to an ethiopian date here
                            edate.CustomFormat = "MM/dd/yyyy";

                            d.Date = ConvertDate.DateConverter(edate.Text);

                            d.EurDate = DateTime.Today;
                             d.Cost = rdoc.IsColumnNull("Cost")? 0: Math.Abs(rdoc.Cost * writeoffAmout);
                            d.StoreId = rdoc.StoreID;
                            d.Losses = true;
                            //todo:
                            d.ApprovedBy = CurrentContext.UserId.ToString();
                            //d.Remarks

                             InternalTransfer it =new  InternalTransfer();
                             it.AddNew();
                            it.ItemID = d.ItemID;
                            it.FromPalletLocationID = pl.GetPalletLocationIDByPalletID(int.Parse(dr["PalletID"].ToString()));
                            it.ToPalletLocationID = nrp.PalletLocationID;
                            it.BatchNumber = d.BatchNo;
                            if (!rdoc.IsColumnNull("ExpDate"))
                            {
                                it.ExpireDate = rdoc.ExpDate;
                            }
                            it.ReceiveDocID = rdoc.ID;
                            it.ManufacturerID = rdoc.ManufacturerId;
                            it.QtyPerPack = Convert.ToInt32(dr["QtyPerPack"]);
                            it.Packs = rdoc.NoOfPack;
                            it.QuantityInBU = nrp.Balance;

                            LossAndAdjustmentReason r = new LossAndAdjustmentReason();
                            it.Type = r.GetReasonByID(d.ReasonId);

                           // d.Save();
                            rdoc.Save();
                            rp.Save();

                            rdoc.QuantityLeft += writeoffAmout;
                             rdoc.Save();
                             nrp.Save();
                             it.Save();
                            int xs = it.ID;
                        }
                        else if (dr["ReLocate"] != DBNull.Value & reLocate > 0)
                         {

                             if (dr["ReLocate"] != DBNull.Value)
                             {
                                 int amount = Convert.ToInt32(dr["ReLocate"]);
                                 int qtyPerPack = Convert.ToInt32(dr["QtyPerPack"]);
                                 amount *= qtyPerPack;
                                 rp.LoadByPrimaryKey(Convert.ToInt32(dr["ReceivePalletID"]));
                                 rdoc.LoadByPrimaryKey(rp.ReceiveID);
                                 int palletLocationID = Convert.ToInt32(dr["PalletLocationID"]);

                                 int qPalletLocationID =
                                     PalletLocation.GetQuaranteenPalletLocationByPalletLocationID(palletLocationID);//PalletLocation.GetQuaranteenPalletLocation(Convert.ToInt32(dr["ID"]));
                                 pl.LoadByPrimaryKey(qPalletLocationID);

                                 ReceivePallet rp2 = new ReceivePallet();
                                 ReceiveDoc rd = new ReceiveDoc();
                                 Pallet pallet = new Pallet();
                                 rp.LoadByPrimaryKey(Convert.ToInt32(dr["ReceivePalletID"]));
                                 rd.LoadByPrimaryKey(rp.ReceiveID);
                                 pallet.AddNew();
                                 Item item = new Item();
                                 item.LoadByPrimaryKey(rdoc.ItemID);
                                 if (item.StorageTypeID.ToString() == StorageType.BulkStore)
                                 {
                                     pallet.PalletNo = Pallet.GetLastPanelNumber();

                                 }
                                 pallet.Save();
                                 rp2.AddNew();
                                 rp2.PalletID = pl.GetpalletidbyPalletLocationOrgetnew(int.Parse(dr["NewPalletLocation"].ToString()));//pallet.ID;
                                 rp2.ReceiveID = rp.ReceiveID;
                                 rp2.IsOriginalReceive = rp.IsOriginalReceive;
                                 // calculate the new balance
                                 BLL.ItemManufacturer im = new BLL.ItemManufacturer();
                                 //im.LoadDefaultReceiving(rd.ItemID, Convert.ToInt32(dr["ManufacturerID"]));
                                 //im.LoadIMbyLevel(rd.ItemID, Convert.ToInt32(dr["ManufacturerID"]), Convert.ToInt32(dr["BoxLevel"]));
                                 //int packqty = (amount / im.QuantityInBasicUnit);
                                 rd.QuantityLeft -= amount;
                                 rp.Balance -= amount;
                                rd.Save();
                                rp.Save();

                                 rd.QuantityLeft += amount;
                                 rp2.Balance = amount;//packqty * im.QuantityInBasicUnit;
                                 rd.Save();

                                 rp2.BoxSize = rp.BoxSize;
                                 rp2.ReservedStock = 0;
                                 rp2.PalletLocationID= int.Parse(dr["NewPalletLocation"].ToString());
                                 rp2.Save();

                                 pl.Confirmed = false;
                                 pl.Save();

                                 // select the new pallet location here.
                              /*   XtraForm xdb = new XtraForm();
                                 xdb.Controls.Add(panelControl2);
                                 Item itms= new Item();
                                 itms.GetItemByPrimaryKey(Convert.ToInt32(dr["ItemID"]));
                                 lblItemName.Text = itms.FullItemName;
                                 panelControl2.Visible = true;
                                 panelControl2.Dock = DockStyle.Fill;
                                 xdb.Text = "Select Location for relocated Item";
                                 lkLocation.Properties.DataSource = PalletLocation.GetAllFreeFor(Convert.ToInt32(dr["ItemID"]));
                                 xdb.ShowDialog();

                                 PalletLocation pl2 = new PalletLocation();
                                 pl2.LoadByPrimaryKey(Convert.ToInt32(lkLocation.EditValue));
                                 pl2.PalletID = pallet.ID;
                                 pl2.Confirmed = false;
                                 pl2.Save();
                                 */
                                 InternalTransfer it = new InternalTransfer();

                                 it.AddNew();
                                 it.ItemID = rd.ItemID;
                                 it.BoxLevel = 0;// im.PackageLevel;
                                 //it.ExpireDate = rd.ExpDate;
                                 if (!rd.IsColumnNull("ExpDate"))
                                 {
                                     it.ExpireDate = rd.ExpDate;
                                 }
                                 it.BatchNumber = rd.BatchNo;
                                 it.ManufacturerID = Convert.ToInt32(dr["ManufacturerID"]);//im.ManufacturerID;
                                 it.FromPalletLocationID = qPalletLocationID;
                                 it.ToPalletLocationID = int.Parse(dr["NewPalletLocation"].ToString()); //pl2.ID;
                                 it.QtyPerPack = 1;
                                //it.Packs = pack qty;
                                 it.ReceiveDocID = rp.ReceiveID;
                                 it.QuantityInBU = amount;// it.QtyPerPack;
                                 it.Type = "ReLocation";
                                 it.IssuedDate = DateTime.Today;
                                 it.Status = 0;
                                 it.PrintNumber = printNubmer;
                                 it.Save();
                             }
                         }
                    }
                    transaction.CommitTransaction();
                    BindQuarantine();
                    XtraMessageBox.Show("Quarantine Write off/Adjustment was commitd.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        private void SaveOrder()
        {
            var order = GenerateOrder();
            var picklist = PickList.GeneratePickList(order.ID);

            int lineNo = 0;

            // This is a kind of initializing the data table.
            OrderDetail ord = new OrderDetail();
            PickListDetail pkDetail = new PickListDetail();
            DataView dv = orderGrid.DataSource as DataView;

            foreach (DataRowView r in dv)
            {
                if (r["ApprovedPacks"] != null && r["ApprovedPacks"] != DBNull.Value && r["ApprovedPacks"].ToString()!= "")
                    if (Convert.ToInt32(r["ApprovedPacks"]) != 0)
                    {
                        lineNo = lineNo + 1;
                        int itemID = Convert.ToInt32(r["ItemID"]);
                        int unitID = Convert.ToInt32(r["UnitID"]);
                        ord.AddNew();
                        ord.OrderID = order.ID;
                        ord.ItemID = itemID;
                        if (r["ApprovedPacks"] != DBNull.Value)
                        {
                            ord.Pack = Convert.ToInt32(r["ApprovedPacks"]);
                        }
                        if (r["QtyPerPack"] != DBNull.Value)
                        {
                            ord.QtyPerPack = Convert.ToInt32(r["QtyPerPack"]);
                        }
                        ord.Quantity = Convert.ToInt32(r["ApprovedPacks"]) * Convert.ToInt32(r["QtyPerPack"]);
                        ord.ApprovedQuantity = Convert.ToInt32(r["ApprovedPacks"]) * Convert.ToInt32(r["QtyPerPack"]);
                        ord.UnitID = unitID;
                        ord.StoreID = Convert.ToInt32(lkAccountType.EditValue);

                        ord.Save();
                        pkDetail.AddNew();
                        pkDetail.PickListID = picklist.ID;
                        pkDetail.ItemID = itemID;
                        pkDetail.PalletLocationID = Convert.ToInt32(r["LocationID"]);
                        pkDetail.BatchNumber = r["BatchNo"].ToString();
                        if (r["ExpDate"] != DBNull.Value)
                            pkDetail.ExpireDate = DateTime.Parse(r["ExpDate"].ToString());

                        pkDetail.StoreID = Convert.ToInt32(r["StoreID"]);
                        pkDetail.UnitID = unitID;
                        pkDetail.ReceiveDocID = Convert.ToInt32(r["ReceiveDocID"]);
                        if (r["UnitPrice"] != DBNull.Value)
                        {
                            pkDetail.Cost = Convert.ToInt32(r["ApprovedPacks"]) * Convert.ToDouble(r["UnitPrice"]);
                            pkDetail.UnitPrice = Convert.ToDouble(r["UnitPrice"]);
                        }
                        pkDetail.Packs = Convert.ToInt32(r["ApprovedPacks"]);
                        pkDetail.QtyPerPack = Convert.ToInt32(r["QtyPerPack"]);
                        pkDetail.QuantityInBU = Convert.ToInt32(r["ApprovedPacks"]) * Convert.ToInt32(r["QtyPerPack"]);
                        pkDetail.StoreID = Convert.ToInt32(r["StoreID"]);
                        pkDetail.ReceivePalletID = Convert.ToInt32(r["ReceivingLocationID"]);
                        pkDetail.ManufacturerID = Convert.ToInt32(r["ManufacturerID"]);
                        pkDetail.BoxLevel = 0;
                        pkDetail.DeliveryNote = true;
                        pkDetail.Save();
                        //To Print The Picklist
                      //Then reserve Items
                        ReceivePallet receivepallet = new ReceivePallet();
                        receivepallet.LoadByPrimaryKey(Convert.ToInt32(r["ReceivingLocationID"]));
                        receivepallet.ReservedStock = receivepallet.ReservedStock + Convert.ToInt32(r["ApprovedPacks"]);
                        receivepallet.Save();

                        DataRow drvpl = dvPickList.NewRow();
                        drvpl["FullItemName"] = r["FullItemName"];
                        drvpl["StockCode"] = r["StockCode"];
                        drvpl["BatchNo"] = r["BatchNo"];
                        if (r["ExpDate"] != DBNull.Value)
                            drvpl["ExpDate"] = Convert.ToDateTime(r["ExpDate"]).ToString("MMM/yyyy");
                        else
                            drvpl["ExpDate"] = DBNull.Value;
                        drvpl["LineNum"] = lineNo + 1;
                        drvpl["ManufacturerName"] = r["Manufacturer"];
                        drvpl["Pack"] = r["ApprovedPacks"];
                        drvpl["UnitPrice"] = r["UnitPrice"];

                        drvpl["Unit"] = r["Unit"];
                        drvpl["PalletLocation"] = r["Location"];
                        drvpl["QtyInSKU"] = Convert.ToInt32(r["ApprovedPacks"]);
                        if (r["UnitPrice"] != DBNull.Value)
                        drvpl["CalculatedCost"] = Convert.ToInt32(r["ApprovedPacks"]) * Convert.ToDouble(r["UnitPrice"]);

                        PalletLocation palletLocation = new PalletLocation();
                        palletLocation.LoadByPrimaryKey(pkDetail.PalletLocationID);
                        drvpl["WarehouseName"] = palletLocation.WarehouseName;
                        drvpl["PhysicalStoreName"] = palletLocation.PhysicalStoreName;
                        var activity = new Activity();
                        activity.LoadByPrimaryKey(pkDetail.StoreID);
                        drvpl["ActivityConcat"] = activity.FullActivityName;
                        drvpl["AccountName"] = activity.AccountName;
                        dvPickList.Rows.Add(drvpl);

                    }

            }
            if (lineNo == 0)
                throw new System.ArgumentException("Please review your list,you haven't approved any Quantity");

            var plr = HCMIS.Desktop.Reports.WorkflowReportFactory.CreatePicklistReport(order, lkForHub.Text,
                                                                                       dvPickList.DefaultView);

            plr.PrintDialog();

            if (!BLL.Settings.IsCenter)
            {
                if (TransferTypeID == 3)
                {

                    XtraMessageBox.Show("Your Store To Store Transfer will be Printed now", "Store To Store Transfer");
                    Transfer.Move(picklist.ID);
                    HCMIS.Desktop.Reports.StoreTransferPrintOut STM =
                        new HCMIS.Desktop.Reports.StoreTransferPrintOut();
                    STM.LoadByPickListID(picklist.ID);
                    STM.PrintDialog();

                }
                else if (TransferTypeID == 2)
                {
                    XtraMessageBox.Show(ReceiveDoc.ReceiveFromAccountTransfer(picklist.ID,
                                                                              Convert.ToInt32(lkForHub.EditValue),
                                                                              CurrentContext.LoggedInUserName,
                                                                              CurrentContext.UserId));
                }
            }
            else
            {
                XtraMessageBox.Show("Picklist Prepared!", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// Moves the specified pick list ID.
        /// </summary>
        /// <param name="PickListID">The pick list ID.</param>
        public static void Move(int PickListID)
        {
            DataView       dv = GetTransferReportForStore();
            PalletLocation pl = new PalletLocation();

            foreach (DataRowView dr in dv)
            {
                int amount           = Convert.ToInt32(dr["packs"]);
                int palletLocationID = Convert.ToInt32(dr["PalletLocationID"]);

                ReceivePallet rp   = new ReceivePallet();
                ReceiveDoc    rdoc = new ReceiveDoc();

                rp.LoadByPrimaryKey(Convert.ToInt32(dr["ReceivePalletID"]));
                rdoc.LoadByPrimaryKey(rp.ReceiveID);
                amount *= rdoc.QtyPerPack;

                int qPalletLocationID = PalletLocation.GetTransferPalletLocation(Convert.ToInt32(dr["PhysicalStoreID"]));
                pl.LoadByPrimaryKey(qPalletLocationID);
                if (pl.IsColumnNull("PalletID"))
                {
                    Pallet p = new Pallet();
                    p.AddNew();
                    p.StorageTypeID = Convert.ToInt32(StorageType.Quaranteen);
                    p.Save();
                    pl.PalletID = p.ID;
                    pl.Save();
                }


                ReceivePallet rp2 = new ReceivePallet();
                ReceiveDoc    rd  = new ReceiveDoc();


                rd.LoadByPrimaryKey(rp.ReceiveID);
                rp2.AddNew();

                rp2.PalletID  = pl.PalletID;
                rp2.ReceiveID = rp.ReceiveID;


                // calculate the new balance
                BLL.ItemManufacturer im = new BLL.ItemManufacturer();
                //im.LoadDefaultReceiving(rd.ItemID, Convert.ToInt32(dr["ManufacturerID"]));
                if (dr["BoxLevel"] == DBNull.Value)
                {
                    dr["BoxLevel"] = 0;
                }
                im.LoadIMbyLevel(rd.ItemID, Convert.ToInt32(dr["ManufacturerID"]), Convert.ToInt32(dr["BoxLevel"]));
                int packqty = (amount / im.QuantityInBasicUnit);
                rp2.ReservedStock = 0;
                rp.ReservedStock -= amount;
                BLL.ReceivePallet.MoveBalance(rp, rp2, amount);
                //rp2.Balance = amount;
                //rp.Balance -= rp2.Balance;

                //rp.Save();
                //rp2.Save();

                pl.Confirmed = false;
                pl.Save();
                if (rp.Balance == 0)
                {
                    PalletLocation.GarbageCollection();
                }
            }
        }
        /// <summary>
        /// Gets the pick list details for order.
        /// </summary>
        /// <param name="ordID">The ord ID.</param>
        /// <param name="Preparedby">The preparedby.</param>
        /// <returns></returns>
        public DataView GetPickListDetailsForOrder(int ordID, string Preparedby)
        {
            this.LoadByOrderID(ordID);
            var query = HCMIS.Repository.Queries.PickList.SelectGetPickListDetailsForOrder(this.ID);
            this.LoadFromRawSql(query);
            // Add important columns
            this.DataTable.Columns.Add("SKUTOPICK", typeof(decimal));
            this.DataTable.Columns.Add("SKUPICKED", typeof(decimal));
            this.DataTable.Columns.Add("BUPICKED", typeof(decimal));
            this.DataTable.Columns.Add("BoxSizeDisplay");
            this.DataTable.Columns.Add("SKUBU", typeof(decimal));
            this.DataTable.Columns.Add("IsManufacturerLocal", typeof(bool));
            this.DataTable.Columns.Add("PrintedSTVNumber", typeof(string));
            this.DataTable.Columns.Add("PhysicalStoreName", typeof(string));
            this.DataTable.Columns.Add("PhysicalStoreTypeID", typeof(int));
            this.DataTable.Columns.Add("PhysicalStoreTypeName", typeof(string));
            this.DataTable.Columns.Add("PreparedBy", typeof(string));
            int i = 1;
            while (!this.EOF)
            {
                decimal packs = Convert.ToDecimal(this.GetColumn("Packs"));

                int manufacturer = Convert.ToInt32(this.GetColumn("ManufacturerID"));
                Manufacturer m = new Manufacturer();
                m.LoadByPrimaryKey(manufacturer);
                if (!m.IsColumnNull("CountryOfOrigin") && m.CountryOfOrigin.Contains("Ethiopia"))
                    this.SetColumn("IsManufacturerLocal", true);
                else
                    this.SetColumn("IsManufacturerLocal", false);

                int recPalletID = Convert.ToInt32(this.GetColumn("ReceivePalletID"));
                ReceivePallet rp = new ReceivePallet();
                rp.LoadByPrimaryKey(recPalletID);
                try
                {
                    ReceiveDoc receiveDoc = new ReceiveDoc();
                    Receipt receipt = new Receipt();
                    receiveDoc.LoadByPrimaryKey(rp.ReceiveID);
                    receipt.LoadByPrimaryKey(receiveDoc.ReceiptID);
                    this.SetColumn("PhysicalStoreName", rp.GetPhysicalStoreName());
                    int physicalStoreTypeID = rp.GetPhysicalStoreTypeID();
                    this.SetColumn("PhysicalStoreTypeID", physicalStoreTypeID);
                    Warehouse phyStoreType = new Warehouse();
                    phyStoreType.LoadByPrimaryKey(physicalStoreTypeID);
                    this.SetColumn("PhysicalStoreTypeName", phyStoreType.Name);
                    if (BLL.Settings.PrintUserNameOnInvoice)
                    {
                        this.SetColumn("PreparedBy", Preparedby);
                    }

                }
                catch
                {

                }

                int itemId = Convert.ToInt32(this.GetColumn("ItemID"));
                int boxLevel = Convert.ToInt32(this.GetColumn("BoxLevel"));
                decimal qtyPerPack = this.Getint("QtyPerPack");
                //im.LoadIMbyLevel(itemId, manufacturer, boxLevel);
                this.SetColumn("SKUTOPICK", (packs));
                this.SetColumn("SKUPICKED", this.GetColumn("SKUTOPICK"));
                // TODO:show the box size here for Program store
                this.SetColumn("BoxSizeDisplay", "");
                this.SetColumn("SKUBU", qtyPerPack);
                this.SetColumn("BUPICKED", qtyPerPack * Convert.ToDecimal(this.GetColumn("SKUPICKED")));
                this.SetColumn("LineNum", i++);
                if (this.IsColumnNull("DeliveryNote"))
                {
                    this.SetColumn("DeliveryNote", false);
                }
                this.MoveNext();
            }
            return this.DefaultView;
        }
        /// <summary>
        /// Saves issue order details
        /// </summary>
        /// <param name="orderID"></param>
        /// <param name="dvPickListMakeup"></param>
        public void SavePickList(int orderID, DataView dvPickListMakeup, int userID)
        {
            //~ Check if This Order has a previous Printed Picklist with detail: Note a header only doesnt affect us! //
            var pickList = new PickList();
            pickList.LoadByOrderID(orderID);
            if(pickList.RowCount>0)
            {
                var pldetail = new PickListDetail();
                pldetail.LoadByPickListID(pickList.ID);
                if (pldetail.RowCount > 0)
                {
                    RemoveFakePartialCommitPickListDetails(orderID);
                      var pickL = new PickList();
                    pickL.LoadByOrderID(orderID);
                    if (pickL.RowCount > 0)
                    {
                        throw new Exception("Picklist has already been printed for this Order ");
                        // This error has been apprearing for the last one year so funny! I hope it won't come again! day: 10/21/2014 @yido  //
                    }
                }
            }
            // Create a pick list entry
            Order ord = new Order();
            ord.LoadByPrimaryKey(orderID);
            PickList pl = new PickList();
            PalletLocation plocation = new PalletLocation();
            plocation.LoadByPrimaryKey(Convert.ToInt32(dvPickListMakeup[0]["PalletLocationID"]));
            pl.AddNew();
            pl.OrderID = orderID;
            pl.PickType = "Pick";
            pl.PickedBy = userID;

            pl.IsConfirmed = false;
            pl.IssuedDate = DateTimeHelper.ServerDateTime;
            pl.SavedDate = DateTimeHelper.ServerDateTime;
            pl.PickedDate = DateTimeHelper.ServerDateTime;
            pl.IsWarehouseConfirmed = 0;
            pl.WarehouseID = plocation.WarehouseID;
            pl.Save();
            PickListDetail pld = new PickListDetail();
            ReceivePallet rp = new ReceivePallet();
            ReceiveDoc rd = new ReceiveDoc();

            PickFace pf = new PickFace();

            foreach (DataRowView drv in dvPickListMakeup)
            {
                pld.AddNew();
                pld.PickListID = pl.ID;
                pld.OrderDetailID = Convert.ToInt32(drv["OrderDetailID"]);

                pld.ItemID = Convert.ToInt32(drv["ItemID"]);
                pld.BatchNumber = (drv["BatchNo"].ToString());
                if (drv["ExpDate"] != DBNull.Value)
                {
                    pld.ExpireDate = Convert.ToDateTime(drv["ExpDate"]);
                }
                pld.ManufacturerID = Convert.ToInt32(drv["ManufacturerID"]);
                pld.BoxLevel = Convert.ToInt32(drv["BoxLevel"]);
                pld.QtyPerPack = Convert.ToInt32(drv["QtyPerPack"]);
                pld.Packs = Convert.ToDecimal(drv["Pack"]);
                pld.PalletLocationID = Convert.ToInt32(drv["PalletLocationID"]);
                pld.QuantityInBU = Convert.ToDecimal(drv["QtyInBU"]);
                pld.ReceiveDocID = Convert.ToInt32(drv["ReceiveDocID"]);
                pld.ReceivePalletID = Convert.ToInt32(drv["ReceivePalletID"]);
                if (drv["CalculatedCost"] != DBNull.Value)
                    pld.Cost = Convert.ToDouble(drv["CalculatedCost"]);
                if (drv["UnitPrice"] != DBNull.Value)
                    pld.UnitPrice = Convert.ToDouble(drv["UnitPrice"]);
                int ReceivePalletID = Convert.ToInt32(drv["ReceivePalletID"]);
                rp.LoadByPrimaryKey(ReceivePalletID);
                pld.StoreID = Convert.ToInt32(drv["StoreID"]);

                if (drv["DeliveryNote"] != null)
                    pld.DeliveryNote = Convert.ToBoolean(drv["DeliveryNote"]);
                else
                    pld.DeliveryNote = false;

                if (rp.IsColumnNull("ReservedStock"))
                {
                    rp.ReservedStock = Convert.ToDecimal(pld.QuantityInBU);
                }
                else
                {
                    rp.ReservedStock += Convert.ToDecimal(pld.QuantityInBU);
                }
                if (drv["UnitID"] != DBNull.Value)
                {
                    pld.UnitID = Convert.ToInt32(drv["UnitID"]);
                }
                plocation.LoadByPrimaryKey(Convert.ToInt32(drv["PalletLocationID"]));
                pld.PhysicalStoreID = plocation.PhysicalStoreID;

                rp.Save();

                if (drv["StorageTypeID"].ToString() == StorageType.PickFace)
                {
                    pf.LoadByPalletLocation(Convert.ToInt32(drv["PalletLocationID"]));
                    //pf.Balance -= Convert.ToDecimal(pld.QuantityInBU);
                    pf.Save();
                }
            }

            pld.Save();
            ord.ChangeStatus(OrderStatus.Constant.PICK_LIST_GENERATED,CurrentContext.UserId);
            ord.Save();
        }
        private void btnAdjustments_Click(object sender, EventArgs e)
        {
            if (ValidateMoveToAdjustments())
            {
                if (DialogResult.Yes == XtraMessageBox.Show("Are you sure you would like to commit this adjustment?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {

                    PalletLocation pl = new PalletLocation();
                    Pallet p = new Pallet();
                    ReceiveDoc rdoc = new ReceiveDoc();
                    ReceivePallet rp = new ReceivePallet();
                    int printNubmer = InternalTransfer.GetNewPrintNumber() + 1 ;
                    for (int i = 0; i < gridView3.RowCount; i++)
                    {
                         DataRow dr = gridView3.GetDataRow(i);
                         if (dr["Adjust"] != DBNull.Value)
                         {

                             int amount = Convert.ToInt32(dr["Adjust"]);
                             rp.LoadByPrimaryKey(Convert.ToInt32(dr["ReceivePalletID"]));
                             rdoc.LoadByPrimaryKey(rp.ReceiveID);

                             rdoc.NoOfPack += amount;
                             amount *= rdoc.QtyPerPack;
                             rp.Balance += amount;
                             if (rp.IsColumnNull("ReceivedQuantity"))
                             {
                                 rp.ReceivedQuantity = 0;
                             }
                             rp.ReceivedQuantity += amount;

                             rdoc.QuantityLeft += amount;
                             rdoc.Quantity += amount;

                             BLL.LossAndAdjustment d = new BLL.LossAndAdjustment();
                             d.AddNew();
                             d.GenerateRefNo();
                             d.ItemID = Convert.ToInt32(dr["ItemID"]);
                             d.ReasonId = Convert.ToInt32(dr["Reason"]);
                             d.RecID = rdoc.ID;
                             d.Quantity = amount;
                             d.BatchNo = rdoc.BatchNo;

                             CalendarLib.DateTimePickerEx edate = new CalendarLib.DateTimePickerEx();
                             edate.Value = DateTime.Today;

                             edate.CustomFormat = "MM/dd/yyyy";
                             d.Date = ConvertDate.DateConverter(edate.Text);

                             d.EurDate = DateTime.Today;
                             if (!rdoc.IsColumnNull("Cost"))
                             {
                                 d.Cost = Math.Abs(rdoc.Cost*amount);
                             }
                             d.StoreId = rdoc.StoreID;
                             d.Losses = false;
                             d.ApprovedBy = CurrentContext.UserId.ToString();
                             d.Save();
                             rdoc.Save();
                             rp.Save();

                         }
                    }
                    PopulateItemDetails();
                    XtraMessageBox.Show("Items adjusted successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
        public static void DeleteIssueDoc(int issueID)
        {
            MyGeneration.dOOdads.TransactionMgr tranMgr =
                MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

            try
            {
                tranMgr.BeginTransaction();

                var pld = new PickListDetail();
                var rdoc = new ReceiveDoc();
                var rp = new ReceivePallet();
                var idoc = new IssueDoc();

                idoc.LoadByPrimaryKey(issueID);
                pld.LoadByPrimaryKey(idoc.PLDetailID);
                rdoc.LoadByPrimaryKey(idoc.RecievDocID);

                rp.LoadByPrimaryKey(pld.ReceivePalletID);
                var pl = new PalletLocation();
                pl.loadByPalletID(rp.PalletID);

                if (pl.RowCount == 0)
                {
                    pl.LoadByPrimaryKey(pld.PalletLocationID);
                    if (pl.IsColumnNull("PalletID"))
                    {
                        pl.PalletID = rp.PalletID;
                        pl.Save();
                    }
                }

                if (rp.RowCount == 0)
                {
                    XtraMessageBox.Show("You cannot delete this item, please contact the administrator", "Error");
                    return;
                }
                if (rp.RowCount > 0)
                {
                    // in error cases this could lead to a number greater than the received quantity
                    // instead of being an error, it should just delete the respective issue and
                    // adjust the remaining quantity to the received quantity.
                    if (rdoc.QuantityLeft + idoc.Quantity > rdoc.Quantity)
                    {
                        rdoc.QuantityLeft = rp.Balance = rdoc.Quantity;
                    }
                    else
                    {
                        rdoc.QuantityLeft += idoc.Quantity;
                        rp.Balance += idoc.Quantity;
                    }

                    //Delete from picklistDetail and add to pickListDetailDeleted
                    PickListDetailDeleted.AddNewLog(pld, BLL.CurrentContext.UserId);
                    pld.MarkAsDeleted();

                    // are we adding it the pick face?
                    // if so add it to the balance of the pick face also
                    pl.loadByPalletID(rp.PalletID);

                    if (pl.RowCount == 0)
                    {
                        var plocation = new PutawayLocation(rdoc.ItemID);

                        // we don't have a location for this yet,
                        // select a new location
                        //PutawayLocataion pl = new PutawayLocataion();
                        if (plocation.ShowDialog() == DialogResult.OK)
                        {
                            pl.LoadByPrimaryKey(plocation.PalletLocationID);
                            if (pl.RowCount > 0)
                            {
                                pl.PalletID = rp.PalletID;
                                pl.Save();
                            }
                        }
                    }

                    if (pl.RowCount > 0)
                    {
                        var pf = new PickFace();
                        pf.LoadByPalletLocation(pl.ID);
                        if (pf.RowCount > 0)
                        {
                            pf.Balance += Convert.ToInt32(idoc.Quantity);
                            pf.Save();
                        }

                        IssueDocDeleted.AddNewLog(idoc, CurrentContext.UserId);
                        idoc.MarkAsDeleted();
                        rdoc.Save();
                        rp.Save();
                        idoc.Save();
                        pld.Save();

                        // now refresh the window
                        XtraMessageBox.Show("Issue Deleted!", "Confirmation", MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        tranMgr.CommitTransaction();

                    }
                }
                else
                {
                    XtraMessageBox.Show(
                        "This delete is not successfull because a free pick face location was not selected. please select a free location and try again.",
                        "Error Deleteing issue transaction", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    tranMgr.RollbackTransaction();
                }
            }
            catch
            {
                XtraMessageBox.Show("This delete is not successfull", "Warning ...", MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                tranMgr.RollbackTransaction();
            }
        }
        private void tpDelete_Click(object sender, EventArgs e)
        {
            DataRow dr = gridViewBinCard.GetFocusedDataRow();
             if (Convert.ToInt32(dr["Precedance"]) != 3)
             {
             XtraMessageBox.Show("You cannot delete this");
             return;
             }
             if (CurrentContext.LoggedInUser.UserType == UserType.Constants.DISTRIBUTION_MANAGER_WITH_DELETE)
             {

             if (
                 XtraMessageBox.Show(
                     "Are you sure you want to delete this transaction? You will not be able to undo this.",
                     "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
             {
                 MyGeneration.dOOdads.TransactionMgr tranMgr =
                     MyGeneration.dOOdads.TransactionMgr.ThreadTransactionMgr();

                 try
                 {
                     tranMgr.BeginTransaction();

                     ReceiveDoc rdoc = new ReceiveDoc();
                     ReceivePallet rp = new ReceivePallet();
                     IssueDoc idoc = new IssueDoc();

                     PickListDetail pld = new PickListDetail();
                     int issueID = Convert.ToInt32(dr["ID"]);
                     //pld.LoadByOrderAndItem(Convert.ToInt32(dr["OrderID"]), Convert.ToInt32(dr["ItemID"]),
                     //                       Convert.ToInt32(dr["Quantity"]));
                     idoc.LoadByPrimaryKey(issueID);
                     pld.LoadByPrimaryKey(idoc.PLDetailID);

                     string RefNo = idoc.RefNo;

                     rdoc.LoadByPrimaryKey(idoc.RecievDocID);

                     //if (pld.RowCount == 0)
                     //{
                     //    pld.LoadByOrderAndItem(Convert.ToInt32(dr["OrderID"]), Convert.ToInt32(dr["ItemID"]));
                     //}

                     rp.LoadByPrimaryKey(pld.ReceivePalletID);
                     PalletLocation pl = new PalletLocation();
                     pl.loadByPalletID(rp.PalletID);

                     if (pl.RowCount == 0)
                     {
                         pl.LoadByPrimaryKey(pld.PalletLocationID);
                         if (pl.IsColumnNull("PalletID"))
                         {
                             pl.PalletID = rp.PalletID;
                             pl.Save();
                         }
                         //rp.LoadNonZeroRPByReceiveID(rdoc.ID);
                     }

                     if (rp.RowCount == 0)
                     {
                         XtraMessageBox.Show("You cannot delete this item, please contact the administrator", "Error");
                         return;
                     }
                     if (rp.RowCount > 0)
                     {
                         rdoc.QuantityLeft += idoc.Quantity;
                         rp.Balance += idoc.Quantity;
                         pld.QuantityInBU = 0;

                         // are we adding it the pick face?
                         // if so add it to the balance of the pick face also
                         pl.loadByPalletID(rp.PalletID);

                         if (pl.RowCount == 0)
                         {
                             PutawayLocation plocation = new PutawayLocation(rdoc.ItemID);

                             // we don't have a location for this yet,
                             // select a new location
                             //PutawayLocataion pl = new PutawayLocataion();
                             if (plocation.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                             {
                                 pl.LoadByPrimaryKey(plocation.PalletLocationID);
                                 if (pl.RowCount > 0)
                                 {
                                     pl.PalletID = rp.PalletID;
                                     pl.Save();
                                 }
                             }
                         }

                         if (pl.RowCount > 0)
                         {

                             PickFace pf = new PickFace();
                             pf.LoadByPalletLocation(pl.ID);
                             if (pf.RowCount > 0)
                             {
                                 pf.Balance += Convert.ToInt32(idoc.Quantity);
                                 pf.Save();
                             }

                             IssueDocDeleted.AddNewLog(idoc, CurrentContext.UserId);
                             idoc.MarkAsDeleted();
                             rdoc.Save();
                             rp.Save();
                             idoc.Save();

                             // now refresh the window
                             XtraMessageBox.Show("Issue Deleted!", "Confirmation", MessageBoxButtons.OK,
                                                 MessageBoxIcon.Information);
                             tranMgr.CommitTransaction();
                             //TODO: refresh the list
                             // gridViewReferences_FocusedRowChanged(null, null);
                         }

                     }
                     else
                     {
                         XtraMessageBox.Show(
                             "This delete is not successfull because a free pick face location was not selected. please select a free location and try again.",
                             "Error Deleteing issue transaction", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         tranMgr.RollbackTransaction();
                     }
                 }
                 catch
                 {
                     XtraMessageBox.Show("This delete is not successfull", "Warning ...", MessageBoxButtons.OK,
                                         MessageBoxIcon.Warning);
                     tranMgr.RollbackTransaction();
                 }
             }
             }
             else
             {
             XtraMessageBox.Show(
                 "You cannot delete this transaction because you don't have previlage. Please contact the administrator if you thing this is an error.",
                 "Delete is not allowed");
             }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Gets the pick list details for order.
        /// </summary>
        /// <param name="ordID">The ord ID.</param>
        /// <param name="Preparedby">The preparedby.</param>
        /// <returns></returns>
        public DataView GetPickListDetailsForOrder(int ordID, string Preparedby)
        {
            this.LoadByOrderID(ordID);
            var query = HCMIS.Repository.Queries.PickList.SelectGetPickListDetailsForOrder(this.ID);

            this.LoadFromRawSql(query);
            // Add important columns
            this.DataTable.Columns.Add("SKUTOPICK", typeof(decimal));
            this.DataTable.Columns.Add("SKUPICKED", typeof(decimal));
            this.DataTable.Columns.Add("BUPICKED", typeof(decimal));
            this.DataTable.Columns.Add("BoxSizeDisplay");
            this.DataTable.Columns.Add("SKUBU", typeof(decimal));
            this.DataTable.Columns.Add("IsManufacturerLocal", typeof(bool));
            this.DataTable.Columns.Add("PrintedSTVNumber", typeof(string));
            this.DataTable.Columns.Add("PhysicalStoreName", typeof(string));
            this.DataTable.Columns.Add("PhysicalStoreTypeID", typeof(int));
            this.DataTable.Columns.Add("PhysicalStoreTypeName", typeof(string));
            this.DataTable.Columns.Add("PreparedBy", typeof(string));
            int i = 1;

            while (!this.EOF)
            {
                decimal packs = Convert.ToDecimal(this.GetColumn("Packs"));


                int          manufacturer = Convert.ToInt32(this.GetColumn("ManufacturerID"));
                Manufacturer m            = new Manufacturer();
                m.LoadByPrimaryKey(manufacturer);
                if (!m.IsColumnNull("CountryOfOrigin") && m.CountryOfOrigin.Contains("Ethiopia"))
                {
                    this.SetColumn("IsManufacturerLocal", true);
                }
                else
                {
                    this.SetColumn("IsManufacturerLocal", false);
                }

                int           recPalletID = Convert.ToInt32(this.GetColumn("ReceivePalletID"));
                ReceivePallet rp          = new ReceivePallet();
                rp.LoadByPrimaryKey(recPalletID);
                try
                {
                    ReceiveDoc receiveDoc = new ReceiveDoc();
                    Receipt    receipt    = new Receipt();
                    receiveDoc.LoadByPrimaryKey(rp.ReceiveID);
                    receipt.LoadByPrimaryKey(receiveDoc.ReceiptID);
                    this.SetColumn("PhysicalStoreName", rp.GetPhysicalStoreName());
                    int physicalStoreTypeID = rp.GetPhysicalStoreTypeID();
                    this.SetColumn("PhysicalStoreTypeID", physicalStoreTypeID);
                    Warehouse phyStoreType = new Warehouse();
                    phyStoreType.LoadByPrimaryKey(physicalStoreTypeID);
                    this.SetColumn("PhysicalStoreTypeName", phyStoreType.Name);
                    if (BLL.Settings.PrintUserNameOnInvoice)
                    {
                        this.SetColumn("PreparedBy", Preparedby);
                    }
                }
                catch
                {
                }

                int     itemId     = Convert.ToInt32(this.GetColumn("ItemID"));
                int     boxLevel   = Convert.ToInt32(this.GetColumn("BoxLevel"));
                decimal qtyPerPack = this.Getint("QtyPerPack");
                //im.LoadIMbyLevel(itemId, manufacturer, boxLevel);
                this.SetColumn("SKUTOPICK", (packs));
                this.SetColumn("SKUPICKED", this.GetColumn("SKUTOPICK"));
                // TODO:show the box size here for Program store
                this.SetColumn("BoxSizeDisplay", "");
                this.SetColumn("SKUBU", qtyPerPack);
                this.SetColumn("BUPICKED", qtyPerPack * Convert.ToDecimal(this.GetColumn("SKUPICKED")));
                this.SetColumn("LineNum", i++);
                if (this.IsColumnNull("DeliveryNote"))
                {
                    this.SetColumn("DeliveryNote", false);
                }
                this.MoveNext();
            }
            return(this.DefaultView);
        }
        /// <summary>
        /// Moves the specified pick list ID.
        /// </summary>
        /// <param name="PickListID">The pick list ID.</param>
        public static void Move(int PickListID)
        {
            DataView dv = GetTransferReportForStore();
            PalletLocation pl = new PalletLocation();
            foreach (DataRowView dr in dv)
            {

                int amount = Convert.ToInt32(dr["packs"]);
                int palletLocationID = Convert.ToInt32(dr["PalletLocationID"]);

                ReceivePallet rp = new ReceivePallet();
                ReceiveDoc rdoc = new ReceiveDoc();

                rp.LoadByPrimaryKey(Convert.ToInt32(dr["ReceivePalletID"]));
                rdoc.LoadByPrimaryKey(rp.ReceiveID);
                amount *= rdoc.QtyPerPack;

                int qPalletLocationID = PalletLocation.GetTransferPalletLocation(Convert.ToInt32(dr["PhysicalStoreID"]));
                pl.LoadByPrimaryKey(qPalletLocationID);
                if (pl.IsColumnNull("PalletID"))
                {
                    Pallet p = new Pallet();
                    p.AddNew();
                    p.StorageTypeID = Convert.ToInt32(StorageType.Quaranteen);
                    p.Save();
                    pl.PalletID = p.ID;
                    pl.Save();
                }

                ReceivePallet rp2 = new ReceivePallet();
                ReceiveDoc rd = new ReceiveDoc();

                rd.LoadByPrimaryKey(rp.ReceiveID);
                rp2.AddNew();

                rp2.PalletID = pl.PalletID;
                rp2.ReceiveID = rp.ReceiveID;

                // calculate the new balance
                BLL.ItemManufacturer im = new BLL.ItemManufacturer();
                //im.LoadDefaultReceiving(rd.ItemID, Convert.ToInt32(dr["ManufacturerID"]));
                if (dr["BoxLevel"] == DBNull.Value)
                {
                    dr["BoxLevel"] = 0;
                }
                im.LoadIMbyLevel(rd.ItemID, Convert.ToInt32(dr["ManufacturerID"]), Convert.ToInt32(dr["BoxLevel"]));
                int packqty = (amount / im.QuantityInBasicUnit);
                rp2.ReservedStock = 0;
                rp.ReservedStock -= amount;
                BLL.ReceivePallet.MoveBalance(rp, rp2, amount);
                //rp2.Balance = amount;
                //rp.Balance -= rp2.Balance;

                //rp.Save();
                //rp2.Save();

                pl.Confirmed = false;
                pl.Save();
                if (rp.Balance == 0)
                {
                    PalletLocation.GarbageCollection();
                }

            }
        }
 public static void ReserveQty(decimal pack, int receivePalletId, bool isOriginalReceive = true)
 {
     var receivepallet = new ReceivePallet();
     receivepallet.LoadByPrimaryKey(receivePalletId);
     receivepallet.IsOriginalReceive = isOriginalReceive;
     receivepallet.ReservedStock = receivepallet.ReservedStock + pack;
     if (receivepallet.Balance >= receivepallet.ReservedStock)
         receivepallet.Save();
 }
        private void btnRelocatePallet_Click(object sender, EventArgs e)
        {
            //Get the chosen pallet Location
            BLL.PalletLocation palletLocation = new BLL.PalletLocation();
            palletLocation.LoadByPrimaryKey(Convert.ToInt16(lkAvailablePalletLocation.EditValue));

            //Get the chosen misplaced receivepallet entry
            DataRow dr = grdViewMisplacedItems.GetFocusedDataRow();
            int receivePalletID = Convert.ToInt32(dr["ID"]);

            BLL.ReceivePallet rp = new BLL.ReceivePallet();
            rp.LoadByPrimaryKey(receivePalletID);
            if (palletLocation.IsColumnNull("PalletID"))
            {
                palletLocation.PalletID = rp.PalletID;
                palletLocation.Save();
            }
            else
            {
                rp.PalletID = palletLocation.PalletID;
                rp.Save();
            }

            int storeID = Convert.ToInt16(lkStoreLocation.EditValue);
            LoadMisplacedItems(storeID);

            XtraMessageBox.Show("Placed!!");
        }
        private void returnToBulkStoreToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataRow dr = gridPickFaceDetailView.GetFocusedDataRow();
            if (dr != null)
            {
                int ReceivePalletID = Convert.ToInt32(dr["ID"]);
                ReceivePallet rp = new ReceivePallet();
                rp.LoadByPrimaryKey(ReceivePalletID);

                ReceiveDoc rd = new ReceiveDoc();
                rd.LoadByPrimaryKey(rp.ReceiveID);

                BLL.ItemManufacturer imf = new BLL.ItemManufacturer();
                imf.LoadIMbyLevel(rd.ItemID, rd.ManufacturerId, rp.BoxSize);

                int QuantityToReturn = Convert.ToInt32(((rp.Balance - rp.ReservedStock) / imf.QuantityInBasicUnit) * imf.QuantityInBasicUnit);
                InternalTransfer itfr = new InternalTransfer();

            }
        }
        /// <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);
        }