Beispiel #1
0
        internal static PickListDetail GeneratePickListDetail(ReceivePallet receivePallet, int pickListId, decimal qtyInBU)
        {
            ReceiveDoc receiveDoc = new ReceiveDoc();

            receiveDoc.LoadByPrimaryKey(receivePallet.ReceiveID);
            decimal pack = qtyInBU / Convert.ToDecimal(receiveDoc.QtyPerPack);

            PickListDetail pkDetail = new PickListDetail();

            pkDetail.AddNew();
            pkDetail.PickListID = pickListId;
            pkDetail.ItemID     = receiveDoc.ItemID;
            PalletLocation palletLocation = new PalletLocation();

            palletLocation.loadByPalletID(receivePallet.PalletID);
            int palletLocationId;

            try
            {
                palletLocationId = palletLocation.ID;
            }
            catch (Exception exp)
            {
                palletLocationId = receivePallet.PalletLocationID;
                palletLocation.LoadByPrimaryKey(palletLocationId);
            }
            pkDetail.PalletLocationID = palletLocationId;
            if (!receiveDoc.IsColumnNull("BatchNo"))
            {
                pkDetail.BatchNumber = receiveDoc.BatchNo;
            }

            if (!receiveDoc.IsColumnNull("ExpDate"))
            {
                pkDetail.ExpireDate = receiveDoc.ExpDate;
            }

            pkDetail.StoreID      = receiveDoc.StoreID;
            pkDetail.UnitID       = receiveDoc.UnitID;
            pkDetail.ReceiveDocID = receiveDoc.ID;
            if (!receiveDoc.IsColumnNull("Cost"))
            {
                pkDetail.Cost      = Convert.ToDouble(pack) * Math.Round(receiveDoc.Cost, BLL.Settings.NoOfDigitsAfterTheDecimalPoint);
                pkDetail.UnitPrice = Math.Round(receiveDoc.Cost, BLL.Settings.NoOfDigitsAfterTheDecimalPoint);
            }
            pkDetail.Packs           = pack;
            pkDetail.QtyPerPack      = receiveDoc.QtyPerPack;
            pkDetail.QuantityInBU    = qtyInBU;
            pkDetail.StoreID         = receiveDoc.StoreID;
            pkDetail.ReceivePalletID = receivePallet.ID;
            pkDetail.ManufacturerID  = receiveDoc.ManufacturerId;
            pkDetail.BoxLevel        = 0;
            pkDetail.DeliveryNote    = true;

            pkDetail.PhysicalStoreID = palletLocation.PhysicalStoreID;
            pkDetail.Save();

            return(pkDetail);
        }
        public void LoadPalletLocation(int palletId,int shlefId=0)
        {
            _pl = new BLL.PalletLocation();
            _pl.loadByPalletID(palletId);

            txtPalletLocation.Text = _pl.FullName;
            lblStorageType.Text = _pl.FullName;

            _rpl = new BLL.ReceivePallet();
            gridMovement.DataSource = _rpl.GetPalletLocationReadyForMovement( palletId );

            _itm = new BLL.Item();
            _itm.LoadByPrimaryKey(Convert.ToInt32(_rpl.GetColumn("ItemID")));
            txtItemName.Text = _itm.FullItemName;
            lblItemName.Text = _itm.FullItemName;

            lkFreePalletLocations.Properties.DataSource = BLL.PalletLocation.GetAllFreeFor(_itm.ID, shlefId);
        }
Beispiel #3
0
        public static PickListDetail GeneratePickListDetail(decimal pack, double?unitPrice, int receiveDocId, int manufacturerId,
                                                            int receivePalletId, int qtyPerPack, int activityId, int unitId,
                                                            int itemId, int picklistId, int palletId, string expireDate,
                                                            string batchNumber)
        {
            PalletLocation plocation = new PalletLocation();
            PickListDetail pkDetail  = new PickListDetail();

            pkDetail.AddNew();
            pkDetail.PickListID = picklistId;
            pkDetail.ItemID     = itemId;
            PalletLocation palletLocation = new PalletLocation();

            palletLocation.loadByPalletID(palletId);
            pkDetail.PalletLocationID = palletLocation.ID;
            pkDetail.BatchNumber      = batchNumber;
            if (expireDate != "")
            {
                pkDetail.ExpireDate = DateTime.Parse(expireDate);
            }

            pkDetail.StoreID      = activityId;
            pkDetail.UnitID       = unitId;
            pkDetail.ReceiveDocID = receiveDocId;
            if (unitPrice != null)
            {
                pkDetail.Cost      = Convert.ToDouble(pack) * Math.Round(unitPrice.Value, BLL.Settings.NoOfDigitsAfterTheDecimalPoint);
                pkDetail.UnitPrice = Math.Round(unitPrice.Value, BLL.Settings.NoOfDigitsAfterTheDecimalPoint);
            }
            pkDetail.Packs           = pack;
            pkDetail.QtyPerPack      = qtyPerPack;
            pkDetail.QuantityInBU    = pack * qtyPerPack;
            pkDetail.StoreID         = activityId;
            pkDetail.ReceivePalletID = receivePalletId;
            pkDetail.ManufacturerID  = manufacturerId;
            pkDetail.BoxLevel        = 0;
            pkDetail.DeliveryNote    = true;

            plocation.LoadByPrimaryKey(pkDetail.PalletLocationID);
            pkDetail.PhysicalStoreID = plocation.PhysicalStoreID;
            pkDetail.Save();
            return(pkDetail);
        }
        public static PickListDetail GeneratePickListDetail(decimal pack, double? unitPrice, int receiveDocId, int manufacturerId,
                                                             int receivePalletId, int qtyPerPack, int activityId, int unitId,
                                                             int itemId, int picklistId, int palletId, string expireDate,
                                                             string batchNumber)
        {
            PalletLocation plocation = new PalletLocation();
            PickListDetail pkDetail = new PickListDetail();
            pkDetail.AddNew();
            pkDetail.PickListID = picklistId;
            pkDetail.ItemID = itemId;
            PalletLocation palletLocation = new PalletLocation();
            palletLocation.loadByPalletID(palletId);
            pkDetail.PalletLocationID = palletLocation.ID;
            pkDetail.BatchNumber = batchNumber;
            if (expireDate != "")
                pkDetail.ExpireDate = DateTime.Parse(expireDate);

            pkDetail.StoreID = activityId;
            pkDetail.UnitID = unitId;
            pkDetail.ReceiveDocID = receiveDocId;
            if (unitPrice != null)
            {
                pkDetail.Cost = Convert.ToDouble(pack) * Math.Round(unitPrice.Value, BLL.Settings.NoOfDigitsAfterTheDecimalPoint);
                pkDetail.UnitPrice = Math.Round(unitPrice.Value, BLL.Settings.NoOfDigitsAfterTheDecimalPoint);
            }
            pkDetail.Packs = pack;
            pkDetail.QtyPerPack = qtyPerPack;
            pkDetail.QuantityInBU = pack * qtyPerPack;
            pkDetail.StoreID = activityId;
            pkDetail.ReceivePalletID = receivePalletId;
            pkDetail.ManufacturerID = manufacturerId;
            pkDetail.BoxLevel = 0;
            pkDetail.DeliveryNote = true;

            plocation.LoadByPrimaryKey(pkDetail.PalletLocationID);
            pkDetail.PhysicalStoreID = plocation.PhysicalStoreID;
            pkDetail.Save();
            return pkDetail;
        }
        /// <summary>
        /// Adds to pick list for an order detail.
        /// </summary>
        /// <param name="orderDetailID">The order detail ID.</param>
        /// <param name="itemId">The item id.</param>
        /// <param name="unitID">The unit ID.</param>
        /// <param name="initalApprovedQuantity">The inital approved quantity.</param>
        /// <param name="storeID">The store ID.</param>
        /// <param name="preferedManufacturer">The prefered manufacturer.</param>
        /// <param name="preferredPhysicalStore">The preferred physical store.</param>
        /// <param name="isDeliveryNote">if set to <c>true</c> [is delivery note].</param>
        /// <param name="preferredExpiry">The preferred expiry.</param>
        /// <exception cref="System.Exception"></exception>
        private void AddToPickListFor(int userID, int orderDetailID, int itemId, int? unitID, decimal initalApprovedQuantity, int storeID, int preferedManufacturer, int preferredPhysicalStore, bool isDeliveryNote, DateTime? preferredExpiry)
        {
            bool deliveryNoteWarning = false;

            if (isDeliveryNote && !BLL.Settings.HandleDeliveryNotes)
            {
                //If the request is for delivery notes but the delivery notes haven't been enabled, then let's change the delivery note bit but also set a warning bit so that we can report it to the user if there are no priced items available. (i.e. In case the picklist comes out empty, we report an error)
                deliveryNoteWarning = true;
                isDeliveryNote = false;
            }

            decimal approvedQuantity = initalApprovedQuantity;

            bool belowBoxPickedFromRack = false;
            //if (preferedManufacturer == -1)
            //{
            var rp = new ReceivePallet();
            var palletLoc = new PalletLocation();
            var im = new ItemManufacturer();

            var pf = new PickFace();
            int buinsku = 0;

            // no manufacturer is preferred so just do the pick list
            // select items that have balance, with sales price and that do have
            rp.LoadNonPickFaceAllItemsReadyToDispatch(userID, itemId, unitID, storeID, preferedManufacturer,
                                                      preferredPhysicalStore, isDeliveryNote, preferredExpiry);

            //If the delivery note warning bit has been set and there are no priced items in the databasee,
            //let's throw an error to the users so that they know the cause of the problem.
            //The solution is to either not choose delivery notes or on the approval stage or enable delivery notes in the settings.
            if (rp.RowCount == 0 && deliveryNoteWarning)
            {
                throw new Exception("Delivery Notes Preference has been set but delivery notes are not enabled for this database.");
            }

            // get how much of it is on the pick face
            //TOFIX: this doesn't have to rely on the quantity on the pick face
            pf.LoadPickFaceFor(itemId, storeID);

            // Just to be safe
            rp.Rewind();
            if (rp.RowCount == 0)
            {
                // this means there is no item to issue other than on the pick face
                // try issuing from the pick face
                LoadFromPickFace(itemId, unitID, approvedQuantity, storeID, isDeliveryNote);
                return;
            }
            while (!rp.EOF)
            {
                // get the current manufacturer
                int manufId = Convert.ToInt32(rp.GetColumn("ManufacturerID"));
                // what is the dispatch able quantity in the current record?
                decimal dispatchableQuantity = Convert.ToDecimal(rp.GetColumn("DispatchableStock"));
                palletLoc.loadByPalletID(rp.PalletID);

                // check if the item is from the rack or the low quantity storage place.
                // if it is from the rack, make sure the packs column counts in cartons
                // if it is not, count in number of packs/SKU or Level 0 only
                if (palletLoc.RowCount > 0 && palletLoc.StorageTypeID.ToString() == StorageType.StackedStorage)
                {
                    im.LoadIMbyLevel(itemId, manufId, 0);
                }
                else if ((palletLoc.RowCount > 0 && palletLoc.StorageTypeID.ToString() != StorageType.BulkStore) ||
                         (pf.RowCount == 0 && palletLoc.StorageTypeID.ToString() == StorageType.BulkStore))
                {
                    im.LoadIMbyLevel(itemId, manufId, 0);
                }
                else
                {
                    im.LoadIMbyLevel(itemId, manufId, Convert.ToInt32(rp.GetColumn("BoxLevel")));
                }
                // just incase there are open cartons on the rack, handle them here.
                if (im.RowCount > 0 && (im.QuantityInBasicUnit > dispatchableQuantity && im.PackageLevel > 0))
                {
                    im.LoadIMbyLevel(itemId, manufId, 0);
                }
                // hold what level we are about to issue,
                // which level of carton and the basic unit in that carton.

                int bUsinBoxLevel;
                buinsku = Convert.ToInt32(rp.GetColumn("QtyPerPack"));// imff.LoadSKUUnit(im.ItemID, im.ManufacturerID);
                if (unitID != null)
                {
                    ItemUnit iu = new ItemUnit();
                    iu.LoadByPrimaryKey(unitID.Value);
                    bUsinBoxLevel = iu.QtyPerUnit;

                    if (buinsku != bUsinBoxLevel)
                    {
                        // This defintely is an error,
                        //TODO: do something about it ;)
                        buinsku = bUsinBoxLevel;
                    }
                }
                else
                {
                    bUsinBoxLevel = im.QuantityInBasicUnit;
                }

                // get the maximum amount of item that can be fulfilled under the current box level
                decimal dispatch = (approvedQuantity / bUsinBoxLevel) * bUsinBoxLevel;
                if (dispatch > dispatchableQuantity)
                {
                    // if the dispatch able quantity is less than what is requested,
                    // only give what we have.
                    dispatch = dispatchableQuantity;
                }
                else if (dispatch == 0)
                {
                    break;
                }

                if (dispatchableQuantity > approvedQuantity)
                {
                    // check if the dispatch is possible with existing pick face items

                    decimal remaining = approvedQuantity - dispatch;
                    // TODO: Explain WTF all this condition is
                    // I assume at this point that it is checking if the remaining amount should be fulfilled from the pick face or not
                    //
                    if (((pf.RowCount == 0 || pf.IsColumnNull("Balance")) && remaining == 0) ||
                        ((pf.RowCount > 0 && !pf.IsColumnNull("Balance") && pf.Balance >= remaining)))
                    {
                        // do this if we should go to the pick face for any reason.
                        if (dispatch > 0)
                        {
                            // do the pick list entries here
                            _pickList.ImportRow(rp.CurrentDataRow);
                            // pick the currently inserted entry and adjust all the numbers in it.
                            DataRow dr = _pickList.Rows[_pickList.Rows.Count - 1];
                            dr["OrderDetailID"] = orderDetailID;
                            // only Adjust the entries that matter to the pick list
                            SetPriceAndQuantity(dr, dispatch, buinsku, rp, itemId, isDeliveryNote);
                            approvedQuantity -= dispatch;
                            // add the items from the pick face
                        }
                        //TODO: implement the pick face logic here.
                        LoadFromPickFace(itemId, unitID, approvedQuantity, storeID, isDeliveryNote);
                        return;
                    }
                    else
                    {
                        // do the bulk pick list and  entries here
                        if (dispatch > 0)
                        {
                            _pickList.ImportRow(rp.CurrentDataRow);
                            // pick the currently inserted entry and adjust all the numbers in it.
                            DataRow dr = _pickList.Rows[_pickList.Rows.Count - 1];
                            dr["OrderDetailID"] = orderDetailID;

                            // only Adjust the entries that matter to the pick list
                            SetPriceAndQuantity(dr, dispatch, buinsku, rp, itemId, isDeliveryNote);
                            approvedQuantity -= dispatch;
                            // the order couldn't be done at this time because the pickface has to be reprenished,
                            // Mark the ReplenishmentList and continue with the other pick list items.
                            // return this message to the user and continue to the next level
                            // do the pick list entries here
                        }
                    }
                }
                else
                // if we are here, it means that the dispatch able quantity is equal to  what we have or greater than the request
                {
                    // dispatch the existing quantity and continue with the other entries in the receive pallet
                    _pickList.ImportRow(rp.CurrentDataRow);
                    // pick the currently inserted entry and adjust all the numbers in it.
                    DataRow dr = _pickList.Rows[_pickList.Rows.Count - 1];
                    dr["OrderDetailID"] = orderDetailID;
                    // only Adjust the entries that matter to the pick list
                    SetPriceAndQuantity(dr, dispatch, buinsku, rp, itemId, isDeliveryNote);
                    approvedQuantity -= dispatch;
                    belowBoxPickedFromRack = true;
                }
                rp.MoveNext();
            }

            if (!belowBoxPickedFromRack && approvedQuantity > 0)
            {
                LoadFromPickFace(itemId, unitID, approvedQuantity, storeID, isDeliveryNote);
            }

            if (approvedQuantity > buinsku && approvedQuantity > 0 &&
                ((pf.RowCount == 0 || pf.IsColumnNull("Balance")) || (approvedQuantity > pf.Balance)))
            {
                //TODO: if this was the last entry in the rp pallet, then it means that the pick face needs to be replenished,\
                // Implement that logic here.

                // this means the pick face has been setup.
                DataRowView drv = _replenishmentList.DefaultView.AddNew();
                drv["ItemID"] = itemId;
                drv["StoreID"] = storeID;
                drv.EndEdit();
            }
        }
        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");
             }
        }
        internal static PickListDetail GeneratePickListDetail(ReceivePallet receivePallet, int pickListId,decimal qtyInBU)
        {
            ReceiveDoc receiveDoc = new ReceiveDoc();
            receiveDoc.LoadByPrimaryKey(receivePallet.ReceiveID);
            decimal pack = qtyInBU / Convert.ToDecimal(receiveDoc.QtyPerPack);

            PickListDetail pkDetail = new PickListDetail();

            pkDetail.AddNew();
            pkDetail.PickListID = pickListId;
            pkDetail.ItemID = receiveDoc.ItemID;
            PalletLocation palletLocation = new PalletLocation();
            palletLocation.loadByPalletID(receivePallet.PalletID);
            int palletLocationId;
            try
            {
                palletLocationId = palletLocation.ID;
            }
            catch (Exception exp)
            {

                palletLocationId = receivePallet.PalletLocationID;
                palletLocation.LoadByPrimaryKey(palletLocationId);

            }
            pkDetail.PalletLocationID = palletLocationId;
            if (!receiveDoc.IsColumnNull("BatchNo"))
                pkDetail.BatchNumber = receiveDoc.BatchNo;

            if (!receiveDoc.IsColumnNull("ExpDate"))
                pkDetail.ExpireDate = receiveDoc.ExpDate;

            pkDetail.StoreID = receiveDoc.StoreID;
            pkDetail.UnitID = receiveDoc.UnitID;
            pkDetail.ReceiveDocID = receiveDoc.ID;
            if (!receiveDoc.IsColumnNull("Cost"))
            {
                pkDetail.Cost = Convert.ToDouble(pack) * Math.Round(receiveDoc.Cost, BLL.Settings.NoOfDigitsAfterTheDecimalPoint);
                pkDetail.UnitPrice = Math.Round(receiveDoc.Cost, BLL.Settings.NoOfDigitsAfterTheDecimalPoint);
            }
            pkDetail.Packs = pack;
            pkDetail.QtyPerPack = receiveDoc.QtyPerPack;
            pkDetail.QuantityInBU = qtyInBU;
            pkDetail.StoreID = receiveDoc.StoreID;
            pkDetail.ReceivePalletID = receivePallet.ID;
            pkDetail.ManufacturerID = receiveDoc.ManufacturerId;
            pkDetail.BoxLevel = 0;
            pkDetail.DeliveryNote = true;

            pkDetail.PhysicalStoreID = palletLocation.PhysicalStoreID;
            pkDetail.Save();

            return pkDetail;
        }
        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();
            }
        }
        public void DeleteAnIssue(int issueDociD)
        {
            ReceiveDoc rdoc = new ReceiveDoc();
            ReceivePallet rp = new ReceivePallet();
            IssueDoc idoc = new IssueDoc();
            idoc.LoadByPrimaryKey(issueDociD);

            if (idoc.IsThereSRM)
            {
                throw new Exception("There is an SRM for this issue.  You can't void it.");
            }

            PickListDetail pld = new PickListDetail();
            //pld.LoadByOrderAndItem(idoc.OrderID, idoc.ItemID, idoc.NoOfPack);
            pld.LoadByPrimaryKey(idoc.PLDetailID);

            string RefNo = idoc.RefNo;

            rdoc.LoadByPrimaryKey(idoc.RecievDocID);

            //if (pld.RowCount == 0)
            //{
            //    pld.LoadByOrderAndItem(idoc.OrderID, idoc.ItemID);
            //}

            rp.LoadByReceiveDocID(idoc.RecievDocID);
            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();
                }

            }

            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;

                //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)
                {
                    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();
                    pld.Save();
                }
                else
                {
                    XtraMessageBox.Show(
                        "This delete is not successful 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);

                }
            }
        }
 public int GetPalletLocationIDByPalletID(int palletID)
 {
     BLL.PalletLocation pl = new PalletLocation();
     pl.loadByPalletID(palletID);
     return pl.ID;
 }