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");
             }
        }
        /// <summary>
        /// Fix For Delivery Note When Converting Do not use under any other situation
        /// </summary>
        /// <param name="issueDocID"></param>
        /// <param name="picklistID"></param>
        /// <returns></returns>
        public PickListDetail FixDeliveryNoteCostReceiveDoc(int issueDocID, int picklistID)
        {
            IssueDoc issueDoc = new IssueDoc();
            issueDoc.LoadByPrimaryKey(issueDocID);
            PickListDetail pickList = new PickListDetail();
            pickList.LoadByPrimaryKey(picklistID);
            //safety first
            if (issueDoc.RecievDocID != pickList.ReceiveDocID)
            {
                Item item = new Item();
                item.LoadByPrimaryKey(picklistID);
                throw new Exception(String.Format("PicklistDetail vs IssueDoc Inconsistancy for Item {0}", item.FullItemName));

            }
            // now we are sure we have one ReceiveDocID
            ReceiveDoc receiveDoc = new ReceiveDoc();
            receiveDoc.LoadByPrimaryKey(pickList.ReceiveDocID);
            ReceiveDocConfirmation receiveDocConfirmation = new ReceiveDocConfirmation();
            receiveDocConfirmation.LoadByReceiveDocID(receiveDoc.ID);
            //Check if it has been Printed and that Selling Price and Cost is set
            if (receiveDocConfirmation.ReceiptConfirmationStatusID == ReceiptConfirmationStatus.Constants.GRV_PRINTED)
            {
                double unitPrice, unitCost, margin;
                if (Settings.IsCenter == true && !receiveDoc.IsColumnNull("Cost") && receiveDoc.Cost != 0)
                {
                    unitPrice = Math.Round(receiveDoc.Cost, 2);
                    unitCost = Math.Round(receiveDoc.Cost, 2);
                    margin = !receiveDoc.IsColumnNull("Margin") ? receiveDoc.Margin : 0;

                }
                else if (!receiveDoc.IsColumnNull("SellingPrice") && receiveDoc.SellingPrice != 0)
                {
                    unitPrice = Math.Round(receiveDoc.SellingPrice, 2);
                    unitCost = Math.Round(receiveDoc.SellingPrice, 2);
                    margin = !receiveDoc.IsColumnNull("Margin") ? receiveDoc.Margin : 0;

                }
                else
                {
                    var item = new Item();
                    item.LoadByPrimaryKey(pickList.ItemID);
                    throw new Exception(String.Format("Price Not set For item: {0}", item.FullItemName));
                }
                pickList.UnitPrice = unitPrice;
                pickList.Cost = Convert.ToDouble(pickList.Packs) * unitPrice;
                issueDoc.SellingPrice = Convert.ToDecimal(unitPrice);
                issueDoc.Cost = Convert.ToDouble(issueDoc.NoOfPack) * unitPrice;
                issueDoc.UnitCost = Convert.ToDecimal(unitCost);
                issueDoc.Margin = Convert.ToDecimal(margin);
                pickList.Save();
                issueDoc.Save();
            }
            else
            {
                var item = new Item();
                item.LoadByPrimaryKey(pickList.ItemID);
                throw new Exception(String.Format("GRV/IGRV Not Printed For Item: {0}", item.FullItemName));
            }
            return pickList;
        }
        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 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();
            }
        }
Example #5
0
        /// <summary>
        /// Fix For Delivery Note When Converting Do not use under any other situation
        /// </summary>
        /// <param name="issueDocID"></param>
        /// <param name="picklistID"></param>
        /// <returns></returns>
        public PickListDetail FixDeliveryNoteCostReceiveDoc(int issueDocID, int picklistID)
        {
            IssueDoc issueDoc = new IssueDoc();

            issueDoc.LoadByPrimaryKey(issueDocID);
            PickListDetail pickList = new PickListDetail();

            pickList.LoadByPrimaryKey(picklistID);
            //safety first
            if (issueDoc.RecievDocID != pickList.ReceiveDocID)
            {
                Item item = new Item();
                item.LoadByPrimaryKey(picklistID);
                throw new Exception(String.Format("PicklistDetail vs IssueDoc Inconsistancy for Item {0}", item.FullItemName));
            }
            // now we are sure we have one ReceiveDocID
            ReceiveDoc receiveDoc = new ReceiveDoc();

            receiveDoc.LoadByPrimaryKey(pickList.ReceiveDocID);
            ReceiveDocConfirmation receiveDocConfirmation = new ReceiveDocConfirmation();

            receiveDocConfirmation.LoadByReceiveDocID(receiveDoc.ID);
            //Check if it has been Printed and that Selling Price and Cost is set
            if (receiveDocConfirmation.ReceiptConfirmationStatusID == ReceiptConfirmationStatus.Constants.GRV_PRINTED)
            {
                double unitPrice, unitCost, margin;
                if (Settings.IsCenter == true && !receiveDoc.IsColumnNull("Cost") && receiveDoc.Cost != 0)
                {
                    unitPrice = Math.Round(receiveDoc.Cost, 2);
                    unitCost  = Math.Round(receiveDoc.Cost, 2);
                    margin    = !receiveDoc.IsColumnNull("Margin") ? receiveDoc.Margin : 0;
                }
                else if (!receiveDoc.IsColumnNull("SellingPrice") && receiveDoc.SellingPrice != 0)
                {
                    unitPrice = Math.Round(receiveDoc.SellingPrice, 2);
                    unitCost  = Math.Round(receiveDoc.SellingPrice, 2);
                    margin    = !receiveDoc.IsColumnNull("Margin") ? receiveDoc.Margin : 0;
                }
                else
                {
                    var item = new Item();
                    item.LoadByPrimaryKey(pickList.ItemID);
                    throw new Exception(String.Format("Price Not set For item: {0}", item.FullItemName));
                }
                pickList.UnitPrice    = unitPrice;
                pickList.Cost         = Convert.ToDouble(pickList.Packs) * unitPrice;
                issueDoc.SellingPrice = Convert.ToDecimal(unitPrice);
                issueDoc.Cost         = Convert.ToDouble(issueDoc.NoOfPack) * unitPrice;
                issueDoc.UnitCost     = Convert.ToDecimal(unitCost);
                issueDoc.Margin       = Convert.ToDecimal(margin);
                pickList.Save();
                issueDoc.Save();
            }
            else
            {
                var item = new Item();
                item.LoadByPrimaryKey(pickList.ItemID);
                throw new Exception(String.Format("GRV/IGRV Not Printed For Item: {0}", item.FullItemName));
            }
            return(pickList);
        }