Esempio n. 1
0
        private void btnConsolidate_Click(object sender, EventArgs e)
        {
            DataRow dr = gridView4.GetFocusedDataRow();

            if (dr != null)
            {
                if (DialogResult.Yes == XtraMessageBox.Show("Are you sure you want to consolidate the two pallets? you will not be able to undo this change.", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    DataRow        dr2 = gridView3.GetFocusedDataRow();
                    PalletLocation pl  = new PalletLocation();
                    pl.LoadByPrimaryKey(Convert.ToInt32(dr2["ID"]));

                    int sourcePalletID = pl.PalletID;
                    pl.LoadByPrimaryKey(Convert.ToInt32(dr["ID"]));
                    int destinationPalletID = pl.PalletID;

                    ReceivePallet rp = new ReceivePallet();
                    rp.Consolidate(sourcePalletID, destinationPalletID);
                    pl.LoadByPrimaryKey(Convert.ToInt32(dr2["ID"]));
                    pl.SetColumnNull("PalletID");
                    pl.Save();
                    XtraMessageBox.Show("Items Consolidated.", "Items Consolidated");

                    gridView5_RowClick(null, null);
                }
            }
        }
        public void CreateDetailTransactionsForErrorCorrection(Order order, BLL.PickList picklist,
                                        Issue stvLog, int receiptPalletId, int receiptID, User user, DateTime convertedEthDate
                                        , int newItemId, int newUnitId, int newManufacturerId, decimal pickedPack
                                        , decimal Convertedpack, int confirmationStatusId, bool changeExpiryDate
                                        , DateTime? ExpiryDate, bool changeBatchNo, string batchNo)
        {
            //Load the ReceivePallet First From that we Get the Information that We need
            ReceivePallet receivePalletOriginal = new ReceivePallet();
            receivePalletOriginal.LoadByPrimaryKey(receiptPalletId);

            ReceiveDoc receiveDocOriginal = new ReceiveDoc();
            receiveDocOriginal.LoadByPrimaryKey(receivePalletOriginal.ReceiveID);

            //Load ItemUnit Detail for For ItemUnit Change;
            ItemUnit newItemUnit = new ItemUnit();
            newItemUnit.LoadByPrimaryKey(newUnitId);

              // Generate PicklistDetail With OrderDetail information
            PickListService pickListService = new PickListService();
            PickListDetail pickListDetail = pickListService.CreatePicklistDetailWithOrder(receiveDocOriginal, receivePalletOriginal, order, picklist,
                                                          pickedPack);
            // Generate IssueDoc from picklistDetail and substract the quantity from receiveDoc
            IssueService issueService = new IssueService();
            issueService.CreateIssueFromPicklist(pickListDetail, order, convertedEthDate, stvLog, user);

            if (Convertedpack > 0)
            {
                //duplicate The ReceiveDoc and ReceiptPallet
                ReceiveService receiveService = new ReceiveService();
                receiveService.CloneReceiveForErrorCorrection(confirmationStatusId, receivePalletOriginal, receiveDocOriginal
                                                                , Convertedpack, user, newItemId
                                                                , receiveDocOriginal.StoreID, receiptID
                                                                , newManufacturerId, newItemUnit, convertedEthDate,changeExpiryDate,ExpiryDate,changeBatchNo,batchNo);
            }
        }
        /// <summary>
        /// This generates picklist for everything in the receivepallet entry.
        /// </summary>
        /// <param name="receiveDoc"></param>
        /// <param name="receivePallet"></param>
        /// <param name="order"></param>
        /// <param name="picklist"></param>
        /// <returns></returns>
        public PickListDetail CreatePicklistDetailWithOrder(ReceiveDoc receiveDoc, ReceivePallet receivePallet, Order order, PickList picklist)
        {
            double?      cost         = null;
            decimal      pack         = receivePallet.Balance / receiveDoc.QtyPerPack;
            OrderService orderService = new OrderService();

            orderService.CreateOrderDetail(receiveDoc, order, pack);
            if (!receiveDoc.IsColumnNull("Cost"))
            {
                cost = receiveDoc.Cost;
            }
            PickListDetail pickListDetail = PickListDetail.GeneratePickListDetail(pack, cost, receiveDoc.ID,
                                                                                  receiveDoc.ManufacturerId,
                                                                                  receivePallet.ID,
                                                                                  receiveDoc.QtyPerPack,
                                                                                  receiveDoc.StoreID, receiveDoc.UnitID,
                                                                                  receiveDoc.ItemID, picklist.ID,
                                                                                  receivePallet.PalletID,
                                                                                  receiveDoc.ExpDate.ToString(),
                                                                                  receiveDoc.BatchNo);

            ReceivePallet.ReserveQty(pack, receivePallet.ID);

            return(pickListDetail);
        }
        public PickListDetail CreatePicklistDetailWithOrder(ReceiveDoc receiveDoc, ReceivePallet receivePallet, Order order, PickList picklist, decimal pack)
        {
            double? cost = null;
            OrderService orderService = new OrderService();
            orderService.CreateOrderDetail(receiveDoc, order, pack);
            if (!receiveDoc.IsColumnNull("Cost"))
                cost = receiveDoc.Cost;
            PickListDetail pickListDetail = PickListDetail.GeneratePickListDetail(pack, cost, receiveDoc.ID, receiveDoc.ManufacturerId, receivePallet.ID,
                receiveDoc.QtyPerPack, receiveDoc.StoreID, receiveDoc.UnitID, receiveDoc.ItemID, picklist.ID, receivePallet.PalletID, receiveDoc.IsColumnNull("ExpDate")?"":receiveDoc.ExpDate.ToString(),  receiveDoc.IsColumnNull("BatchNo")?"":receiveDoc.BatchNo);
            ReceivePallet.ReserveQty(pack, receivePallet.ID);

            return pickListDetail;
        }
        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);
        }
Esempio n. 6
0
        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();
            }
        }
Esempio n. 7
0
        public void CreateDetailTransactionsForErrorCorrection(Order order, BLL.PickList picklist,
                                                               Issue stvLog, int receiptPalletId, int receiptID, User user, DateTime convertedEthDate
                                                               , int newItemId, int newUnitId, int newManufacturerId, decimal pickedPack
                                                               , decimal Convertedpack, int confirmationStatusId, bool changeExpiryDate
                                                               , DateTime?ExpiryDate, bool changeBatchNo, string batchNo)
        {
            //Load the ReceivePallet First From that we Get the Information that We need
            ReceivePallet receivePalletOriginal = new ReceivePallet();

            receivePalletOriginal.LoadByPrimaryKey(receiptPalletId);

            ReceiveDoc receiveDocOriginal = new ReceiveDoc();

            receiveDocOriginal.LoadByPrimaryKey(receivePalletOriginal.ReceiveID);

            //Load ItemUnit Detail for For ItemUnit Change;
            ItemUnit newItemUnit = new ItemUnit();

            newItemUnit.LoadByPrimaryKey(newUnitId);

            // Generate PicklistDetail With OrderDetail information
            PickListService pickListService = new PickListService();
            PickListDetail  pickListDetail  = pickListService.CreatePicklistDetailWithOrder(receiveDocOriginal, receivePalletOriginal, order, picklist,
                                                                                            pickedPack);
            // Generate IssueDoc from picklistDetail and substract the quantity from receiveDoc
            IssueService issueService = new IssueService();

            issueService.CreateIssueFromPicklist(pickListDetail, order, convertedEthDate, stvLog, user);

            if (Convertedpack > 0)
            {
                //duplicate The ReceiveDoc and ReceiptPallet
                ReceiveService receiveService = new ReceiveService();
                receiveService.CloneReceiveForErrorCorrection(confirmationStatusId, receivePalletOriginal, receiveDocOriginal
                                                              , Convertedpack, user, newItemId
                                                              , receiveDocOriginal.StoreID, receiptID
                                                              , newManufacturerId, newItemUnit, convertedEthDate, changeExpiryDate, ExpiryDate, changeBatchNo, batchNo);
            }
        }
        private void btnDispose_Click(object sender, EventArgs e)
        {
            if (!dxValidationProvider1.Validate())
            {
                return;
            }

            TransferService transferService = new TransferService();
            IssueService    issueService    = new IssueService();

            if (XtraMessageBox.Show("Please Confirm that you want to dispose the selected items", "Warning", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
            {
                int activityID = Convert.ToInt32(glkActivity.EditValue);
                var dt         = (DataView)grdSelectedExpiredItemsView.DataSource;

                Order    order    = OrderForDisposal(activityID);
                PickList picklist = PickList.GeneratePickList(order.ID);

                BLL.Issue stvLog = issueService.CreateSTVLog(null, false, picklist, order, null, activityID, false, CurrentContext.UserId);

                foreach (DataRow row in dt.Table.Rows)
                {
                    ReceiveDoc    rd = new ReceiveDoc();
                    ReceivePallet rp = new ReceivePallet();

                    rd.LoadByPrimaryKey((int)row["ReceiveDocID"]);
                    rp.LoadByReceiveDocID((int)row["ReceiveDocID"]);

                    var picklistDetail = transferService.GeneratePickListDetail(rd, rp, order, picklist);
                    issueService.CreateIssueFromPicklist(picklistDetail, order, DateTime.Now, stvLog, CurrentContext.LoggedInUser);
                }

                HCMIS.Reports.Workflow.Activities.Disposal disposalPrintout = new HCMIS.Reports.Workflow.Activities.Disposal(glkActivity.Text, txtLicenseNo.Text, DateTime.Now, ((DataView)grdSelectedExpiredItemsView.DataSource).Table);
                disposalPrintout.PrintDialog();

                RefreshSelection();
                txtLicenseNo.ResetText();
            }
        }
        private int SaveOrder()
        {
            int      warehouseID;
            var      order      = GenerateOrder();
            PickList pickList   = PickList.GeneratePickList(order.ID);
            int      picklistId = pickList.ID;

            if (TransferTypeID != Transfer.Constants.HUB_TO_HUB)
            {
                warehouseID = GenerateTransfer(order.ID);
            }

            // Log
            this.LogActivity("Transfer", order.ID);


            int LineNo = 0;

            // This is a kind of initializing the data table.


            DataView dv = orderGrid.DataSource as DataView;

            foreach (DataRowView r in dv)
            {
                if (r["ApprovedPacks"] != null && r["ApprovedPacks"] != DBNull.Value && r["ApprovedPacks"].ToString() != "")
                {
                    if (Convert.ToDecimal(r["ApprovedPacks"]) != 0)
                    {
                        LineNo = LineNo + 1;
                        int     itemId           = Convert.ToInt32(r["ItemID"]);
                        int     unitId           = Convert.ToInt32(r["UnitID"]);
                        decimal pack             = Convert.ToDecimal(r["ApprovedPacks"]);
                        int     qtyPerPack       = Convert.ToInt32(r["QtyPerPack"]);
                        int     activityId       = Convert.ToInt32(lkFromActivity.EditValue);
                        int     manufacturerId   = Convert.ToInt32(Convert.ToInt32(r["ManufacturerID"]));
                        int     receivePalletId  = Convert.ToInt32(r["ReceivingLocationID"]);
                        int     palletLocationId = Convert.ToInt32(r["LocationID"]);
                        double? unitPrice;
                        string  batchNumber  = r["BatchNo"].ToString();
                        string  expireDate   = "";
                        int     receiveDocId = Convert.ToInt32(r["ReceiveDocID"]);
                        if ((r["UnitPrice"] != DBNull.Value))
                        {
                            unitPrice = Convert.ToDouble(r["UnitPrice"]);
                        }
                        else
                        {
                            unitPrice = null;
                        }

                        if (r["ExpDate"] != DBNull.Value)
                        {
                            expireDate = r["ExpDate"].ToString();
                        }

                        OrderDetail    ord            = OrderDetail.GenerateOrderDetail(unitId, activityId, pack, order.ID, qtyPerPack, itemId);
                        PalletLocation palletLocation = new PalletLocation();
                        palletLocation.LoadByPrimaryKey(palletLocationId);
                        int            palletID = palletLocation.PalletID;
                        PickListDetail pkDetail = PickListDetail.GeneratePickListDetail(pack, unitPrice, receiveDocId, manufacturerId, receivePalletId, qtyPerPack, activityId, unitId, itemId, picklistId, palletID, expireDate, batchNumber);
                        ReceivePallet.ReserveQty(pack, receivePalletId);
                        //To Print The Picklist
                        //Then reserve Items


                        Item item = new Item();
                        item.LoadByPrimaryKey(itemId);
                        DataRow drvpl = dvPickList.NewRow();
                        drvpl["FullItemName"] = item.FullItemName;
                        drvpl["StockCode"]    = item.StockCode;
                        drvpl["BatchNo"]      = batchNumber;
                        if (expireDate != "")
                        {
                            drvpl["ExpDate"] = Convert.ToDateTime(expireDate).ToString("MMM/yyyy");
                        }
                        else
                        {
                            drvpl["ExpDate"] = DBNull.Value;
                        }
                        drvpl["LineNum"] = LineNo + 1;
                        var manufacturer = new Manufacturer();
                        manufacturer.LoadByPrimaryKey(manufacturerId);
                        drvpl["ManufacturerName"] = manufacturer.Name;

                        drvpl["Pack"]      = pack;
                        drvpl["UnitPrice"] = unitPrice;
                        var unit = new ItemUnit();
                        unit.LoadByPrimaryKey(unitId);

                        drvpl["Unit"] = unit.Text;

                        drvpl["QtyInSKU"] = pack;
                        if (unitPrice != null)
                        {
                            drvpl["CalculatedCost"] = pack * Convert.ToDecimal(unitPrice);
                        }


                        palletLocation.LoadByPrimaryKey(pkDetail.PalletLocationID);
                        drvpl["PalletLocation"]    = palletLocation.Label;
                        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");
            }
            string   receivingUnit;
            Transfer transfer = new Transfer();

            transfer.LoadByOrderID(order.ID);
            if (TransferTypeID == Transfer.Constants.ACCOUNT_TO_ACCOUNT)
            {
                var fromActivity = new Activity();
                fromActivity.LoadByPrimaryKey(transfer.FromStoreID);
                var toActivity = new Activity();
                toActivity.LoadByPrimaryKey(transfer.ToStoreID);

                receivingUnit = String.Format("Account to Account from {0} to {1}", fromActivity.FullActivityName,
                                              toActivity.FullActivityName);
            }
            else if (TransferTypeID == Transfer.Constants.STORE_TO_STORE)
            {
                var toStore = new PhysicalStore();

                toStore.LoadByPrimaryKey(transfer.ToPhysicalStoreID);
                receivingUnit = string.Format("Store to Store transfer to: {0}", toStore.WarehouseName);
            }
            else
            {
                receivingUnit = lkForHub.Text;
            }
            var plr = HCMIS.Desktop.Reports.WorkflowReportFactory.CreatePicklistReport(order, receivingUnit,
                                                                                       dvPickList.DefaultView);

            plr.PrintDialog();

            XtraMessageBox.Show("Picklist Prepared!", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return(order.ID);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="inventory"></param>
        /// <param name="palletLocation">Please note that the pallet location passed here is going to be used for the sound qty.  A quarantine location in the physical store that the pallet location exists is chosen for the damaged location.  For now, we're using the same pallet location for the expired quantity as well. (Only if the location type is free)</param>
        /// <param name="confirmationStatusID"></param>
        /// <param name="receipt"></param>
        /// <param name="user"></param>
        /// <param name="convertedEthDate"></param>
        /// <param name="remark"></param>
        internal void CreateReceiveEntriesForInventory(Inventory inventory, PalletLocation palletLocation, int confirmationStatusID, Receipt receipt, User user, DateTime convertedEthDate, string remark)
        {
            //Now Save the receive doc entry
            decimal soundQty = inventory.IsColumnNull("InventorySoundQuantity") ? 0 : inventory.InventorySoundQuantity;
            decimal damagedQty = inventory.IsColumnNull("InventoryDamagedQuantity") ? 0 : inventory.InventoryDamagedQuantity;
            decimal expQty = inventory.IsColumnNull("InventoryExpiredQuantity") ? 0 : inventory.InventoryExpiredQuantity;

            //As per the design of the Inventory object, expired and sound cannot be passed using a single object: Why? There's a data memeber for Expiry Date which can only hold one value.
            decimal soundOrExpiredQty = soundQty + expQty;
            decimal totalFoundQty = soundOrExpiredQty + damagedQty;

            ReceiveDoc newReceiveDoc = CreateReceiveDocForInventory(inventory, confirmationStatusID, totalFoundQty,
                                                                    receipt.ID, convertedEthDate, user, remark);

            ReceivePallet newReceivePallet = new ReceivePallet();
            BLL.ItemUnit iu = new ItemUnit();
            iu.LoadByPrimaryKey(inventory.UnitID);

            if (soundOrExpiredQty > 0)
            {
                newReceivePallet.AddNew();
                newReceivePallet.ReceiveID = newReceiveDoc.ID;
                newReceivePallet.ReceivedQuantity = newReceivePallet.Balance = soundOrExpiredQty*iu.QtyPerUnit;
                newReceivePallet.ReservedStock = 0;
                newReceivePallet.PalletID = palletLocation.PalletID;
                newReceivePallet.PalletLocationID = palletLocation.ID;
            }

            if(damagedQty>0)
            {
                newReceivePallet.AddNew();
                newReceivePallet.ReceiveID = newReceiveDoc.ID;
                newReceivePallet.ReceivedQuantity = newReceivePallet.Balance = damagedQty*iu.QtyPerUnit;
                newReceivePallet.ReservedStock = 0;

                if(palletLocation.StorageTypeID==Convert.ToInt32(BLL.StorageType.Quaranteen)) //Was the original pallet stored in a quarantine location?
                {
                    newReceivePallet.PalletID = palletLocation.PalletID;
                    newReceivePallet.PalletLocationID = palletLocation.ID;
                }
                else //The original pallet was not marked as a quarantine or suspension location.  Meaning we need to choose a quarantine location in the same physical store as the original pallet location.
                {
                    BLL.PalletLocation plQuarantine = new PalletLocation();
                    plQuarantine.LoadFirstOrDefault(palletLocation.PhysicalStoreID,
                                                    Convert.ToInt32((StorageType.Quaranteen)));
                    if(plQuarantine.RowCount>0) //There is already quarantine location.
                    {
                        //Pick the first quarantine location.
                        if(plQuarantine.IsColumnNull("PalletID"))
                        {
                            //TODO: Create a Pallet.
                        }

                        newReceivePallet.PalletID = plQuarantine.PalletID;
                        newReceivePallet.PalletLocationID = plQuarantine.ID;
                    }
                    else
                    {
                        //There is no quarantine locaiton in the physical store: This is basically bad news.  We let them know that this is unacceptable.
                        throw new Exception("Please create a quarantine storage location for this store");
                    }
                }
            }
            newReceivePallet.IsOriginalReceive = true;
            newReceivePallet.Save();
        }
        public ReceiveDoc CreateInventoryReceive(Inventory inventory,int receiptID,Inventory.QuantityType quantityType,DateTime ethiopianDate,User user)
        {
            ItemUnit itemUnit = new ItemUnit();
            itemUnit.LoadByPrimaryKey(inventory.UnitID);

            ReceiveDoc receiveDoc = new ReceiveDoc();
            receiveDoc.AddNew();
            receiveDoc.ItemID = inventory.ItemID;
            receiveDoc.UnitID = inventory.UnitID;
            receiveDoc.ManufacturerId = inventory.ManufacturerID;

            receiveDoc.StoreID = inventory.ActivityID;
            receiveDoc.Date = ethiopianDate;
            receiveDoc.EurDate = DateTimeHelper.ServerDateTime;
            receiveDoc.PhysicalStoreID = inventory.PhysicalStoreID;
            receiveDoc.SetColumn("BatchNo", inventory.GetColumn("BatchNo"));
            decimal quantity = quantityType == Inventory.QuantityType.Sound
                                   ? inventory.InventorySoundQuantity
                                   : quantityType == Inventory.QuantityType.Damaged
                                    ? inventory.InventoryDamagedQuantity :inventory.InventoryExpiredQuantity;

            if(quantityType == Inventory.QuantityType.Damaged) receiveDoc.ShortageReasonID = ShortageReasons.Constants.DAMAGED;
            receiveDoc.Quantity = receiveDoc.QuantityLeft = quantity * itemUnit.QtyPerUnit;
            receiveDoc.NoOfPack = receiveDoc.InvoicedNoOfPack = quantity;
            receiveDoc.QtyPerPack = itemUnit.QtyPerUnit;
            receiveDoc.SetColumn("ExpDate", inventory.GetColumn("ExpiryDate"));

            receiveDoc.Out = false;

            receiveDoc.ReceivedBy = user.UserName;

            receiveDoc.StoreID = inventory.ActivityID;
            receiveDoc.RefNo = "BeginningBalance";
            decimal cost = 0;
            decimal margin = 0;

            if (!inventory.IsColumnNull("Cost"))
            {
                cost = inventory.Cost;
            }

            if(!inventory.IsColumnNull("Margin"))
            {
                margin = inventory.Margin;
            }

            receiveDoc.Cost = Convert.ToDouble(cost);
            receiveDoc.PricePerPack = Convert.ToDouble(cost);
            receiveDoc.UnitCost = cost;
            receiveDoc.Margin = Convert.ToDouble(margin);
            receiveDoc.SellingPrice = Convert.ToDouble(BLL.Settings.IsCenter ? cost : cost * (1 + margin));
            receiveDoc.SupplierID = 2; //TODO: HARDCODE WARNING WARNING WARNING
            receiveDoc.DeliveryNote = false;
            receiveDoc.Confirmed = true;
            receiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime;
            receiveDoc.ReturnedStock = false;
            receiveDoc.ReceiptID = receiptID;
            receiveDoc.RefNo = "BeginningBalance";
            receiveDoc.InventoryPeriodID = inventory.InventoryPeriodID;
            receiveDoc.IsDamaged = (quantityType == Inventory.QuantityType.Damaged ||
                                   quantityType == Inventory.QuantityType.Expired);
            receiveDoc.Save();

            //Now Save the ReceiveDocConfirmation

            ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation();
            rdConf.AddNew();
            rdConf.ReceiveDocID = receiveDoc.ID;
            rdConf.ReceivedByUserID = user.ID;
            rdConf.ReceiptConfirmationStatusID = ReceiptConfirmationStatus.Constants.RECEIVE_QUANTITY_CONFIRMED;
            rdConf.Save();

            //TODO: Create Receive Pallet Here
            PalletLocation palletLocation = new PalletLocation();

            palletLocation.LoadByPrimaryKey(quantityType != Inventory.QuantityType.Damaged
                                                ? inventory.PalletLocationID
                                                : inventory.DamagedPalletLocationID);

            ReceivePallet receivePallet = new ReceivePallet();
            receivePallet.AddNew();
            receivePallet.Balance = quantity * itemUnit.QtyPerUnit;
            receivePallet.ReceivedQuantity = quantity * itemUnit.QtyPerUnit;
            receivePallet.ReservedStock = 0;
            receivePallet.ReceiveID = receiveDoc.ID;

            if(palletLocation.IsColumnNull("PalletID"))
            {
                Pallet pallet = new Pallet();
                pallet.AddNew();
                pallet.Save();
                palletLocation.PalletID = pallet.ID;
                palletLocation.Save();
            }

            receivePallet.PalletID = palletLocation.PalletID;
            receivePallet.PalletLocationID =palletLocation.ID;
            receivePallet.BoxSize = 0;
            receivePallet.IsOriginalReceive = true;
            receivePallet.Save();

            return receiveDoc;
        }
        public IssueDoc CreateIssueFromPicklist(PickListDetail picklistDetail,Order order,DateTime convertedEthDate,Issue stvLog,User user)
        {
            ReceivePallet receivePallet = new ReceivePallet();
            receivePallet.LoadByPrimaryKey(picklistDetail.ReceivePalletID);

            ReceiveDoc receiveDoc = new ReceiveDoc();
            receiveDoc.LoadByPrimaryKey(receivePallet.ReceiveID);

            IssueDoc issueDoc = new IssueDoc();
            issueDoc.AddNew();
            issueDoc.BatchNo = picklistDetail.BatchNumber;
            if(!picklistDetail.IsColumnNull("Cost"))
            issueDoc.Cost = picklistDetail.Cost;
            issueDoc.Date = convertedEthDate;
            issueDoc.EurDate = DateTimeHelper.ServerDateTime;
            issueDoc.StoreId = picklistDetail.StoreID;
            issueDoc.STVID = stvLog.ID;
            issueDoc.IsTransfer = true;
            issueDoc.IssuedBy = user.FullName;
            issueDoc.ItemID = picklistDetail.ItemID;
            issueDoc.NoOfPack = picklistDetail.Packs;
            issueDoc.QtyPerPack = picklistDetail.QtyPerPack;
            issueDoc.Quantity = picklistDetail.QuantityInBU;
            issueDoc.OrderID = order.ID;
            issueDoc.UnitID = receiveDoc.UnitID;
            issueDoc.ManufacturerID = receiveDoc.ManufacturerId;
            issueDoc.SetColumn("UnitCost" ,receiveDoc.GetColumn("Cost"));
            issueDoc.SetColumn("SellingPrice"  ,receiveDoc.GetColumn("SellingPrice"));
            issueDoc.SetColumn("Margin", receiveDoc.GetColumn("Margin"));
            issueDoc.SetColumn("PhysicalStoreID", receiveDoc.GetColumn("PhysicalStoreID"));
            issueDoc.PLDetailID = picklistDetail.ID;
            issueDoc.RecievDocID = picklistDetail.ReceiveDocID;
            issueDoc.SetColumn("InventoryPeriodID", receiveDoc.GetColumn("InventoryPeriodID"));
            // This is a deprecated field
            issueDoc.RecomendedQty = 0;// picklistDetail.Packs;
            issueDoc.RefNo = stvLog.IDPrinted.ToString();
            issueDoc.DispatchConfirmed = false;
            issueDoc.Save();

            //substract from QuantityLeft
            receiveDoc.QuantityLeft -= picklistDetail.QuantityInBU;
            if(receiveDoc.QuantityLeft < 0)
            {
                receiveDoc.QuantityLeft = 0;
            }
            receiveDoc.Save();

            receivePallet.Balance -= picklistDetail.QuantityInBU;
            if(receivePallet.Balance < 0)
            {
                receivePallet.Balance=0;
            }

            receivePallet.ReservedStock -= picklistDetail.Packs;
            if(receivePallet.ReservedStock < 0)
            {
                receivePallet.ReservedStock = 0;
            }
            receivePallet.Save();

            return issueDoc;
        }
 public PickListDetail GeneratePickListDetail(ReceiveDoc rd, ReceivePallet rp, Order o, PickList pl)
 {
     PickListService pickListService = new PickListService ();
     return pickListService.CreatePicklistDetailWithOrder(rd, rp, o, pl);
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            LogReceiptChange change = new LogReceiptChange(rDoc);

            if (txtBatchNo.EditValue != null)
            {
                rDoc.BatchNo = txtBatchNo.Text;
            }
            if (dtExpiry.EditValue != null)
            {
                rDoc.ExpDate = dtExpiry.DateTime;
            }
            else
            {
                rDoc.SetColumnNull("ExpDate");
            }
            if (txtPrice.EditValue != null)
            {
                rDoc.Cost = Convert.ToDouble(txtPrice.EditValue);
            }

            if (lkAccount.EditValue != null)
            {
                rDoc.StoreID = Convert.ToInt32(lkAccount.EditValue);
                //TODO:Edit other tables as well.
            }

            if (lkUnit.EditValue != null)
            {
                int unitID = Convert.ToInt32(lkUnit.EditValue);
                if (rDoc.UnitID != unitID)
                {
                    rDoc.UnitID = Convert.ToInt32(lkUnit.EditValue);
                    BLL.ItemUnit itemUnit = new ItemUnit();
                    itemUnit.LoadByPrimaryKey(rDoc.UnitID);
                    rDoc.QtyPerPack   = itemUnit.QtyPerUnit;
                    rDoc.Quantity     = rDoc.NoOfPack * rDoc.QtyPerPack;
                    rDoc.QuantityLeft = rDoc.Quantity;

                    BLL.ReceivePallet rp = new ReceivePallet();
                    rp.LoadByReceiveDocID(rDoc.ID);
                    rp.Balance          = rDoc.QuantityLeft;
                    rp.ReceivedQuantity = rDoc.Quantity;

                    rDoc.Save();
                    rp.Save();
                }
            }


            // decide to save the quantity or not
            //Lord have mercy, this is not a proper way to do it,
            decimal quantity = Convert.ToDecimal(txtQuanitity.EditValue.ToString().Replace(",", ""));



            if (txtQuanitity.Enabled && !rDoc.HasTransactions() && rDoc.Quantity != rDoc.QtyPerPack * quantity)
            {
                // now find the receive pallets
                ReceivePallet receivePallet = new ReceivePallet();
                receivePallet.LoadNonZeroRPByReceiveID(rDoc.ID);
                if (receivePallet.RowCount > 1)
                {
                    //
                    XtraMessageBox.Show(
                        "This Item is stored in more than one location and chaning the quanitity is not implemented. try to consolidate it and try again");
                }
                else
                {
                    rDoc.NoOfPack         = quantity;
                    receivePallet.Balance = receivePallet.ReceivedQuantity = rDoc.QuantityLeft = rDoc.Quantity = quantity * rDoc.QtyPerPack;
                    rDoc.Save();
                    receivePallet.Save();
                }
            }
            else if (rDoc.Quantity != quantity * rDoc.QtyPerPack)
            {
                XtraMessageBox.Show("The Quantity was not edited because there was an issue transaction on it.");
            }

            rDoc.RefNo = txtGrvNo.EditValue.ToString();
            //rDoc.SupplierID = Convert.ToInt32(lkSupplier.EditValue);
            if (lkManufacturer.EditValue != null)
            {
                rDoc.ManufacturerId = Convert.ToInt32(lkManufacturer.EditValue);
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            rDoc.Save();
            change.SaveChangeLog(rDoc, CurrentContext.UserId);
            this.LogActivity("Save-Receipt-Change", rDoc.ID);
            this.Close();
        }
Esempio n. 15
0
        public void CloneReceiveForErrorCorrection(int confirmationStatusID, ReceivePallet receivePallet, ReceiveDoc receiveDoc, decimal pack, User user, int itemId, int storeId, int receiptId, int manufacturerId, ItemUnit itemUnit, DateTime convertedEthDate, bool changeExpiryDate = false, DateTime?ExpiryDate = null, bool changeBatchNo = false, string batchNo = null)
        {
            var newReceiveDoc = receiveDoc.Clone();

            newReceiveDoc.ItemID = itemId;

            if (changeBatchNo)
            {
                newReceiveDoc.BatchNo = batchNo;
            }

            if (changeExpiryDate)
            {
                if (ExpiryDate.HasValue)
                {
                    newReceiveDoc.ExpDate = ExpiryDate.Value;
                }
                else
                {
                    newReceiveDoc.SetColumnNull("ExpDate");
                }
            }

            newReceiveDoc.ManufacturerId = manufacturerId;
            newReceiveDoc.SetColumn("UnitID", itemUnit.ID);
            newReceiveDoc.Quantity          = pack * itemUnit.QtyPerUnit;
            newReceiveDoc.QuantityLeft      = pack * itemUnit.QtyPerUnit;
            newReceiveDoc.NoOfPack          = pack;
            newReceiveDoc.InvoicedNoOfPack  = pack;
            newReceiveDoc.QtyPerPack        = itemUnit.QtyPerUnit;
            newReceiveDoc.Date              = convertedEthDate;
            newReceiveDoc.ReceivedBy        = user.UserName;
            newReceiveDoc.StoreID           = storeId;
            newReceiveDoc.RefNo             = receiptId.ToString();
            newReceiveDoc.EurDate           = DateTimeHelper.ServerDateTime;
            newReceiveDoc.Confirmed         = true;
            newReceiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime;
            newReceiveDoc.ReturnedStock     = false;
            newReceiveDoc.ReceiptID         = receiptId;

            newReceiveDoc.Save();

            //Now Save the ReceiveDocConfirmation

            ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation();

            rdConf.AddNew();
            rdConf.ReceiveDocID                = newReceiveDoc.ID;
            rdConf.ReceivedByUserID            = user.ID;
            rdConf.ReceiptConfirmationStatusID = confirmationStatusID;
            rdConf.Save();

            ReceivePallet newReceivePallet = new ReceivePallet();

            newReceivePallet.AddNew();
            newReceivePallet.ReceiveID         = newReceiveDoc.ID;
            newReceivePallet.ReceivedQuantity  = pack * itemUnit.QtyPerUnit;
            newReceivePallet.Balance           = pack * itemUnit.QtyPerUnit;
            newReceivePallet.ReservedStock     = 0;
            newReceivePallet.BoxSize           = 0;
            newReceivePallet.PalletID          = receivePallet.PalletID;
            newReceivePallet.IsOriginalReceive = true;
            if (!receivePallet.IsColumnNull("PalletLocationID"))
            {
                newReceivePallet.PalletLocationID = receivePallet.PalletLocationID;
            }
            newReceivePallet.Save();
        }
Esempio n. 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inventory"></param>
        /// <param name="palletLocation">Please note that the pallet location passed here is going to be used for the sound qty.  A quarantine location in the physical store that the pallet location exists is chosen for the damaged location.  For now, we're using the same pallet location for the expired quantity as well. (Only if the location type is free)</param>
        /// <param name="confirmationStatusID"></param>
        /// <param name="receipt"></param>
        /// <param name="user"></param>
        /// <param name="convertedEthDate"></param>
        /// <param name="remark"></param>
        internal void CreateReceiveEntriesForInventory(Inventory inventory, PalletLocation palletLocation, int confirmationStatusID, Receipt receipt, User user, DateTime convertedEthDate, string remark)
        {
            //Now Save the receive doc entry
            decimal soundQty   = inventory.IsColumnNull("InventorySoundQuantity") ? 0 : inventory.InventorySoundQuantity;
            decimal damagedQty = inventory.IsColumnNull("InventoryDamagedQuantity") ? 0 : inventory.InventoryDamagedQuantity;
            decimal expQty     = inventory.IsColumnNull("InventoryExpiredQuantity") ? 0 : inventory.InventoryExpiredQuantity;

            //As per the design of the Inventory object, expired and sound cannot be passed using a single object: Why? There's a data memeber for Expiry Date which can only hold one value.
            decimal soundOrExpiredQty = soundQty + expQty;
            decimal totalFoundQty     = soundOrExpiredQty + damagedQty;


            ReceiveDoc newReceiveDoc = CreateReceiveDocForInventory(inventory, confirmationStatusID, totalFoundQty,
                                                                    receipt.ID, convertedEthDate, user, remark);

            ReceivePallet newReceivePallet = new ReceivePallet();

            BLL.ItemUnit iu = new ItemUnit();
            iu.LoadByPrimaryKey(inventory.UnitID);


            if (soundOrExpiredQty > 0)
            {
                newReceivePallet.AddNew();
                newReceivePallet.ReceiveID        = newReceiveDoc.ID;
                newReceivePallet.ReceivedQuantity = newReceivePallet.Balance = soundOrExpiredQty * iu.QtyPerUnit;
                newReceivePallet.ReservedStock    = 0;
                newReceivePallet.PalletID         = palletLocation.PalletID;
                newReceivePallet.PalletLocationID = palletLocation.ID;
            }

            if (damagedQty > 0)
            {
                newReceivePallet.AddNew();
                newReceivePallet.ReceiveID        = newReceiveDoc.ID;
                newReceivePallet.ReceivedQuantity = newReceivePallet.Balance = damagedQty * iu.QtyPerUnit;
                newReceivePallet.ReservedStock    = 0;

                if (palletLocation.StorageTypeID == Convert.ToInt32(BLL.StorageType.Quaranteen)) //Was the original pallet stored in a quarantine location?
                {
                    newReceivePallet.PalletID         = palletLocation.PalletID;
                    newReceivePallet.PalletLocationID = palletLocation.ID;
                }
                else //The original pallet was not marked as a quarantine or suspension location.  Meaning we need to choose a quarantine location in the same physical store as the original pallet location.
                {
                    BLL.PalletLocation plQuarantine = new PalletLocation();
                    plQuarantine.LoadFirstOrDefault(palletLocation.PhysicalStoreID,
                                                    Convert.ToInt32((StorageType.Quaranteen)));
                    if (plQuarantine.RowCount > 0) //There is already quarantine location.
                    {
                        //Pick the first quarantine location.
                        if (plQuarantine.IsColumnNull("PalletID"))
                        {
                            //TODO: Create a Pallet.
                        }

                        newReceivePallet.PalletID         = plQuarantine.PalletID;
                        newReceivePallet.PalletLocationID = plQuarantine.ID;
                    }
                    else
                    {
                        //There is no quarantine locaiton in the physical store: This is basically bad news.  We let them know that this is unacceptable.
                        throw new Exception("Please create a quarantine storage location for this store");
                    }
                }
            }
            newReceivePallet.IsOriginalReceive = true;
            newReceivePallet.Save();
        }
        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);
            }
        }
Esempio n. 18
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            int warehouseID = Convert.ToInt32(lkWarehouse.EditValue);

            receiveDoc.Rewind();
            var po             = new BLL.PO();
            var receiptInvoice = new BLL.ReceiptInvoice();

            while (!receiveDoc.EOF)
            {
                //Handle the PO.
                //int receiptID;
                if (po.RowCount == 0 || po.StoreID != receiveDoc.StoreID)
                {
                    Supplier supplier = new Supplier();
                    po = BLL.PO.CreatePOforStandard(OrderType.CONSTANTS.STANDARD_ORDER, receiveDoc.StoreID,
                                                    supplier.GetHubHomeOfficeSupplierID(), "", CurrentContext.LoggedInUser.ID);
                    //Should we receive it as hub to hub transfer? We're now using Standard order.
                    receipt = BLL.ReceiptInvoice.CreateAutomaticReceiptInvoiceForSTVTransfer(po.ID, warehouseID, STVNo,
                                                                                             CurrentContext.UserId);
                }

                receiveDoc.Quantity  = receiveDoc.QtyPerPack * receiveDoc.NoOfPack;
                receiveDoc.ReceiptID = receipt.ID;
                receiveDoc.MoveNext();
            }
            receiveDoc.Save();

            //Save the location
            receiveDoc.Rewind();

            BLL.ReceivePallet receivePallet = new ReceivePallet();
            while (!receiveDoc.EOF)
            {
                //Save Location Information
                BLL.PalletLocation palletLocation = new PalletLocation();

                receivePallet.AddNew();

                int palletLocationID = Convert.ToInt32(receiveDoc.GetColumn("PalletLocationID"));
                receivePallet.PalletLocationID = palletLocationID;

                palletLocation.LoadByPrimaryKey(palletLocationID);

                receivePallet.PalletID         = palletLocation.PalletID;
                receivePallet.ReceivedQuantity = receiveDoc.Quantity;
                receivePallet.Balance          = receiveDoc.Quantity;
                receivePallet.ReceiveID        = receiveDoc.ID;
                receivePallet.ReservedStock    = 0;


                //Save Discrepancy information if there is any
                receiveDocShortage.Rewind();
                while (receiveDocShortage.FindNextByGUID(receiveDoc.GetColumn("GUID").ToString()))
                {
                    receiveDocShortage.ReceiveDocID = receiveDoc.ID;

                    if (receiveDocShortage.ShortageReasonID == ShortageReasons.Constants.DAMAGED)
                    {
                        receiveDoc.NoOfPack += receiveDocShortage.NoOfPacks;
                        receiveDoc.Quantity += receiveDocShortage.NoOfPacks * receiveDoc.QtyPerPack;

                        palletLocationID = Convert.ToInt32(receiveDocShortage.GetColumn("PalletLocationID"));
                        receivePallet.AddNew();
                        receivePallet.PalletLocationID = palletLocationID;
                        palletLocation.LoadByPrimaryKey(palletLocationID);

                        receivePallet.PalletID         = palletLocation.PalletID;
                        receivePallet.ReceivedQuantity = receiveDocShortage.NoOfPacks * receiveDoc.QtyPerPack;
                        receivePallet.Balance          = receiveDocShortage.NoOfPacks * receiveDoc.QtyPerPack;
                        receivePallet.ReceiveID        = receiveDoc.ID;
                        receivePallet.ReservedStock    = 0;
                    }
                }

                receiveDoc.MoveNext();
            }
            receivePallet.IsOriginalReceive = true;
            receivePallet.Save();
        }
Esempio n. 19
0
        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);
                }
            }
        }
Esempio n. 20
0
        public ReceiveDoc CreateInventoryReceive(Inventory inventory, int receiptID, Inventory.QuantityType quantityType, DateTime ethiopianDate, User user)
        {
            ItemUnit itemUnit = new ItemUnit();

            itemUnit.LoadByPrimaryKey(inventory.UnitID);

            ReceiveDoc receiveDoc = new ReceiveDoc();

            receiveDoc.AddNew();
            receiveDoc.ItemID         = inventory.ItemID;
            receiveDoc.UnitID         = inventory.UnitID;
            receiveDoc.ManufacturerId = inventory.ManufacturerID;

            receiveDoc.StoreID         = inventory.ActivityID;
            receiveDoc.Date            = ethiopianDate;
            receiveDoc.EurDate         = DateTimeHelper.ServerDateTime;
            receiveDoc.PhysicalStoreID = inventory.PhysicalStoreID;
            receiveDoc.SetColumn("BatchNo", inventory.GetColumn("BatchNo"));
            decimal quantity = quantityType == Inventory.QuantityType.Sound
                                   ? inventory.InventorySoundQuantity
                                   : quantityType == Inventory.QuantityType.Damaged
                                    ? inventory.InventoryDamagedQuantity :inventory.InventoryExpiredQuantity;

            if (quantityType == Inventory.QuantityType.Damaged)
            {
                receiveDoc.ShortageReasonID = ShortageReasons.Constants.DAMAGED;
            }
            receiveDoc.Quantity   = receiveDoc.QuantityLeft = quantity * itemUnit.QtyPerUnit;
            receiveDoc.NoOfPack   = receiveDoc.InvoicedNoOfPack = quantity;
            receiveDoc.QtyPerPack = itemUnit.QtyPerUnit;
            receiveDoc.SetColumn("ExpDate", inventory.GetColumn("ExpiryDate"));

            receiveDoc.Out = false;

            receiveDoc.ReceivedBy = user.UserName;

            receiveDoc.StoreID = inventory.ActivityID;
            receiveDoc.RefNo   = "BeginningBalance";
            decimal cost   = 0;
            decimal margin = 0;

            if (!inventory.IsColumnNull("Cost"))
            {
                cost = inventory.Cost;
            }

            if (!inventory.IsColumnNull("Margin"))
            {
                margin = inventory.Margin;
            }

            receiveDoc.Cost              = Convert.ToDouble(cost);
            receiveDoc.PricePerPack      = Convert.ToDouble(cost);
            receiveDoc.UnitCost          = cost;
            receiveDoc.Margin            = Convert.ToDouble(margin);
            receiveDoc.SellingPrice      = Convert.ToDouble(BLL.Settings.IsCenter ? cost : cost * (1 + margin));
            receiveDoc.SupplierID        = 2; //TODO: HARDCODE WARNING WARNING WARNING
            receiveDoc.DeliveryNote      = false;
            receiveDoc.Confirmed         = true;
            receiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime;
            receiveDoc.ReturnedStock     = false;
            receiveDoc.ReceiptID         = receiptID;
            receiveDoc.RefNo             = "BeginningBalance";
            receiveDoc.InventoryPeriodID = inventory.InventoryPeriodID;
            receiveDoc.IsDamaged         = (quantityType == Inventory.QuantityType.Damaged ||
                                            quantityType == Inventory.QuantityType.Expired);
            receiveDoc.Save();

            //Now Save the ReceiveDocConfirmation

            ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation();

            rdConf.AddNew();
            rdConf.ReceiveDocID                = receiveDoc.ID;
            rdConf.ReceivedByUserID            = user.ID;
            rdConf.ReceiptConfirmationStatusID = ReceiptConfirmationStatus.Constants.RECEIVE_QUANTITY_CONFIRMED;
            rdConf.Save();

            //TODO: Create Receive Pallet Here
            PalletLocation palletLocation = new PalletLocation();

            palletLocation.LoadByPrimaryKey(quantityType != Inventory.QuantityType.Damaged
                                                ? inventory.PalletLocationID
                                                : inventory.DamagedPalletLocationID);


            ReceivePallet receivePallet = new ReceivePallet();

            receivePallet.AddNew();
            receivePallet.Balance          = quantity * itemUnit.QtyPerUnit;
            receivePallet.ReceivedQuantity = quantity * itemUnit.QtyPerUnit;
            receivePallet.ReservedStock    = 0;
            receivePallet.ReceiveID        = receiveDoc.ID;

            if (palletLocation.IsColumnNull("PalletID"))
            {
                Pallet pallet = new Pallet();
                pallet.AddNew();
                pallet.Save();
                palletLocation.PalletID = pallet.ID;
                palletLocation.Save();
            }

            receivePallet.PalletID          = palletLocation.PalletID;
            receivePallet.PalletLocationID  = palletLocation.ID;
            receivePallet.BoxSize           = 0;
            receivePallet.IsOriginalReceive = true;
            receivePallet.Save();

            return(receiveDoc);
        }
Esempio n. 21
0
        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");
            }
        }
        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);
                }
            }
        }
Esempio n. 23
0
        public PickListDetail GeneratePickListDetail(ReceiveDoc rd, ReceivePallet rp, Order o, PickList pl)
        {
            PickListService pickListService = new PickListService();

            return(pickListService.CreatePicklistDetailWithOrder(rd, rp, o, pl));
        }
Esempio n. 24
0
        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);
            }
        }
        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);
                }
            }
        }
        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);
                }
            }
        }
        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();
            }
        }
        /// <summary>
        /// Saves the whole transaction for
        /// </summary>
        /// <param name="orderID">The order ID.</param>
        /// <param name="dvOutstandingPickList">The dv outstanding pick list.</param>
        /// <param name="remark">The remark.</param>
        /// <param name="issuedBy">The issued by.</param>
        /// <param name="etCurrentDate">The et current date.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception"></exception>
        public static Order SaveIssueTransaction(int orderID, ref DataView dvOutstandingPickList, string remark, string issuedBy, DateTime etCurrentDate)
        {
            // Add the IssueDocID field
            dvOutstandingPickList.Table.Columns.Add("IssueDocID");
            PickList plst = new PickList();
            IssueDoc issDoc = new IssueDoc();
            ReceiveDoc recDoc = new ReceiveDoc();
            BLL.Order ord = new BLL.Order();
            ord.LoadByPrimaryKey(orderID);
            plst.LoadByOrderID(ord.ID);

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

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

                }

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

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

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

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

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

                //long prevQuantityLeft = recDoc.QuantityLeft;

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

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

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

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

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

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

                rp.ReservedStock -= totReservedQty;
                if (rp.ReservedStock < 0) //If there has been a quantity problem somewhere
                    rp.ReservedStock = 0;
                rp.Save();
            }
            plst.IsConfirmed = true;
            ord.ChangeStatus(OrderStatus.Constant.ISSUED, CurrentContext.UserId);
            plst.Save();
            ord.Save();
            return ord;
        }
        public void CloneReceiveForErrorCorrection(int confirmationStatusID, ReceivePallet receivePallet, ReceiveDoc receiveDoc, decimal pack, User user, int itemId, int storeId, int receiptId, int manufacturerId, ItemUnit itemUnit, DateTime convertedEthDate, bool changeExpiryDate = false, DateTime? ExpiryDate = null, bool changeBatchNo = false, string batchNo = null)
        {
            var newReceiveDoc = receiveDoc.Clone();

            newReceiveDoc.ItemID = itemId;

            if (changeBatchNo)
            {
                newReceiveDoc.BatchNo = batchNo;
            }

            if (changeExpiryDate)
            {
                if (ExpiryDate.HasValue)
                {
                    newReceiveDoc.ExpDate = ExpiryDate.Value;
                }
                else
                {
                    newReceiveDoc.SetColumnNull("ExpDate");
                }
            }

            newReceiveDoc.ManufacturerId = manufacturerId;
            newReceiveDoc.SetColumn("UnitID", itemUnit.ID);
            newReceiveDoc.Quantity = pack * itemUnit.QtyPerUnit;
            newReceiveDoc.QuantityLeft = pack * itemUnit.QtyPerUnit;
            newReceiveDoc.NoOfPack = pack;
            newReceiveDoc.InvoicedNoOfPack = pack;
            newReceiveDoc.QtyPerPack = itemUnit.QtyPerUnit;
            newReceiveDoc.Date = convertedEthDate;
            newReceiveDoc.ReceivedBy = user.UserName;
            newReceiveDoc.StoreID = storeId;
            newReceiveDoc.RefNo = receiptId.ToString();
            newReceiveDoc.EurDate = DateTimeHelper.ServerDateTime;
            newReceiveDoc.Confirmed = true;
            newReceiveDoc.ConfirmedDateTime = DateTimeHelper.ServerDateTime;
            newReceiveDoc.ReturnedStock = false;
            newReceiveDoc.ReceiptID = receiptId;

            newReceiveDoc.Save();

            //Now Save the ReceiveDocConfirmation

            ReceiveDocConfirmation rdConf = new ReceiveDocConfirmation();
            rdConf.AddNew();
            rdConf.ReceiveDocID = newReceiveDoc.ID;
            rdConf.ReceivedByUserID = user.ID;
            rdConf.ReceiptConfirmationStatusID = confirmationStatusID;
            rdConf.Save();

            ReceivePallet newReceivePallet = new ReceivePallet();
            newReceivePallet.AddNew();
            newReceivePallet.ReceiveID = newReceiveDoc.ID;
            newReceivePallet.ReceivedQuantity = pack * itemUnit.QtyPerUnit;
            newReceivePallet.Balance = pack * itemUnit.QtyPerUnit;
            newReceivePallet.ReservedStock = 0;
            newReceivePallet.BoxSize = 0;
            newReceivePallet.PalletID = receivePallet.PalletID;
            newReceivePallet.IsOriginalReceive = true;
            if (!receivePallet.IsColumnNull("PalletLocationID"))
            {
                newReceivePallet.PalletLocationID = receivePallet.PalletLocationID;
            }
            newReceivePallet.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();
        }
        public IssueDoc CreateIssueFromPicklist(PickListDetail picklistDetail, Order order, DateTime convertedEthDate, Issue stvLog, User user)
        {
            ReceivePallet receivePallet = new ReceivePallet();

            receivePallet.LoadByPrimaryKey(picklistDetail.ReceivePalletID);

            ReceiveDoc receiveDoc = new ReceiveDoc();

            receiveDoc.LoadByPrimaryKey(receivePallet.ReceiveID);

            IssueDoc issueDoc = new IssueDoc();

            issueDoc.AddNew();
            issueDoc.BatchNo = picklistDetail.BatchNumber;
            if (!picklistDetail.IsColumnNull("Cost"))
            {
                issueDoc.Cost = picklistDetail.Cost;
            }
            issueDoc.Date           = convertedEthDate;
            issueDoc.EurDate        = DateTimeHelper.ServerDateTime;
            issueDoc.StoreId        = picklistDetail.StoreID;
            issueDoc.STVID          = stvLog.ID;
            issueDoc.IsTransfer     = true;
            issueDoc.IssuedBy       = user.FullName;
            issueDoc.ItemID         = picklistDetail.ItemID;
            issueDoc.NoOfPack       = picklistDetail.Packs;
            issueDoc.QtyPerPack     = picklistDetail.QtyPerPack;
            issueDoc.Quantity       = picklistDetail.QuantityInBU;
            issueDoc.OrderID        = order.ID;
            issueDoc.UnitID         = receiveDoc.UnitID;
            issueDoc.ManufacturerID = receiveDoc.ManufacturerId;
            issueDoc.SetColumn("UnitCost", receiveDoc.GetColumn("Cost"));
            issueDoc.SetColumn("SellingPrice", receiveDoc.GetColumn("SellingPrice"));
            issueDoc.SetColumn("Margin", receiveDoc.GetColumn("Margin"));
            issueDoc.SetColumn("PhysicalStoreID", receiveDoc.GetColumn("PhysicalStoreID"));
            issueDoc.PLDetailID  = picklistDetail.ID;
            issueDoc.RecievDocID = picklistDetail.ReceiveDocID;
            issueDoc.SetColumn("InventoryPeriodID", receiveDoc.GetColumn("InventoryPeriodID"));
            // This is a deprecated field
            issueDoc.RecomendedQty     = 0;// picklistDetail.Packs;
            issueDoc.RefNo             = stvLog.IDPrinted.ToString();
            issueDoc.DispatchConfirmed = false;
            issueDoc.Save();



            //substract from QuantityLeft
            receiveDoc.QuantityLeft -= picklistDetail.QuantityInBU;
            if (receiveDoc.QuantityLeft < 0)
            {
                receiveDoc.QuantityLeft = 0;
            }
            receiveDoc.Save();

            receivePallet.Balance -= picklistDetail.QuantityInBU;
            if (receivePallet.Balance < 0)
            {
                receivePallet.Balance = 0;
            }

            receivePallet.ReservedStock -= picklistDetail.Packs;
            if (receivePallet.ReservedStock < 0)
            {
                receivePallet.ReservedStock = 0;
            }
            receivePallet.Save();

            return(issueDoc);
        }