/// <summary> /// This happes when there is plenty of transaction at the same time /// and will result a partial commit. /// This fake rows should be deleted from DB. /// </summary> /// <param name="orderID"></param> private void RemoveFakePartialCommitPickListDetails(int orderID) { var order = new Order(); order.LoadByPrimaryKey(orderID); if (order.OrderStatusID == OrderStatus.Constant.ORDER_APPROVED) { var pickList = new PickList(); pickList.LoadByOrderID(order.ID); if (pickList.RowCount == 0) //~ If there is no picklist, there is nothing to delete. ~// { return; } var picklistDetail = new PickListDetail(); picklistDetail.LoadByPickListID(pickList.ID); picklistDetail.Rewind(); while (!picklistDetail.EOF) { PickListDetailDeleted.AddNewLog(picklistDetail, CurrentContext.UserId); picklistDetail.MarkAsDeleted(); picklistDetail.MoveNext(); } picklistDetail.Save(); pickList.MarkAsDeleted(); pickList.Save(); } }
/// <summary> /// Undo pick list that has been printed /// </summary> /// <param name="orderID">The order ID.</param> public void CancelOrderWithPickList(int orderID) { // Create a pick list entry Order ord = new Order(); PickList pl = new PickList(); PickListDetail pld = new PickListDetail(); ReceivePallet rp = new ReceivePallet(); ReceiveDoc rd = new ReceiveDoc(); PickFace pf = new PickFace(); PalletLocation palletLocation = new PalletLocation(); ord.LoadByPrimaryKey(orderID); pl.LoadByOrderID(orderID); pld.LoadByPickListID(pl.ID); while (!pld.EOF) { rp.LoadByPrimaryKey(pld.ReceivePalletID); rp.ReservedStock -= Convert.ToInt32(pld.QuantityInBU); if (rp.ReservedStock < 0) { rp.ReservedStock = 0; //If there has been no reservation, allow to cancel the picklist too. No need for it to be blocked by the constraint. } rp.Save(); palletLocation.LoadByPrimaryKey(pld.PalletLocationID); if (palletLocation.StorageTypeID.ToString() == StorageType.PickFace) { pf.LoadByPalletLocation(pld.PalletLocationID); pf.Balance += Convert.ToInt32(pld.QuantityInBU); pf.Save(); } //Delete from picklistDetail and add to pickListDetailDeleted PickListDetailDeleted.AddNewLog(pld, BLL.CurrentContext.UserId); pld.MarkAsDeleted(); pld.MoveNext(); } pld.Save(); ord.ChangeStatus(OrderStatus.Constant.CANCELED, CurrentContext.UserId); pl.MarkAsDeleted(); pl.Save(); }
/// <summary> /// Saves issue order details /// </summary> /// <param name="orderID"></param> /// <param name="dvPickListMakeup"></param> public void SavePickList(int orderID, DataView dvPickListMakeup, int userID) { //~ Check if This Order has a previous Printed Picklist with detail: Note a header only doesnt affect us! // var pickList = new PickList(); pickList.LoadByOrderID(orderID); if (pickList.RowCount > 0) { var pldetail = new PickListDetail(); pldetail.LoadByPickListID(pickList.ID); if (pldetail.RowCount > 0) { RemoveFakePartialCommitPickListDetails(orderID); var pickL = new PickList(); pickL.LoadByOrderID(orderID); if (pickL.RowCount > 0) { throw new Exception("Picklist has already been printed for this Order "); // This error has been apprearing for the last one year so funny! I hope it won't come again! day: 10/21/2014 @yido // } } } // Create a pick list entry Order ord = new Order(); ord.LoadByPrimaryKey(orderID); PickList pl = new PickList(); PalletLocation plocation = new PalletLocation(); plocation.LoadByPrimaryKey(Convert.ToInt32(dvPickListMakeup[0]["PalletLocationID"])); pl.AddNew(); pl.OrderID = orderID; pl.PickType = "Pick"; pl.PickedBy = userID; pl.IsConfirmed = false; pl.IssuedDate = DateTimeHelper.ServerDateTime; pl.SavedDate = DateTimeHelper.ServerDateTime; pl.PickedDate = DateTimeHelper.ServerDateTime; pl.IsWarehouseConfirmed = 0; pl.WarehouseID = plocation.WarehouseID; pl.Save(); PickListDetail pld = new PickListDetail(); ReceivePallet rp = new ReceivePallet(); ReceiveDoc rd = new ReceiveDoc(); PickFace pf = new PickFace(); foreach (DataRowView drv in dvPickListMakeup) { pld.AddNew(); pld.PickListID = pl.ID; pld.OrderDetailID = Convert.ToInt32(drv["OrderDetailID"]); pld.ItemID = Convert.ToInt32(drv["ItemID"]); pld.BatchNumber = (drv["BatchNo"].ToString()); if (drv["ExpDate"] != DBNull.Value) { pld.ExpireDate = Convert.ToDateTime(drv["ExpDate"]); } pld.ManufacturerID = Convert.ToInt32(drv["ManufacturerID"]); pld.BoxLevel = Convert.ToInt32(drv["BoxLevel"]); pld.QtyPerPack = Convert.ToInt32(drv["QtyPerPack"]); pld.Packs = Convert.ToDecimal(drv["Pack"]); pld.PalletLocationID = Convert.ToInt32(drv["PalletLocationID"]); pld.QuantityInBU = Convert.ToDecimal(drv["QtyInBU"]); pld.ReceiveDocID = Convert.ToInt32(drv["ReceiveDocID"]); pld.ReceivePalletID = Convert.ToInt32(drv["ReceivePalletID"]); if (drv["CalculatedCost"] != DBNull.Value) { pld.Cost = Convert.ToDouble(drv["CalculatedCost"]); } if (drv["UnitPrice"] != DBNull.Value) { pld.UnitPrice = Convert.ToDouble(drv["UnitPrice"]); } int ReceivePalletID = Convert.ToInt32(drv["ReceivePalletID"]); rp.LoadByPrimaryKey(ReceivePalletID); pld.StoreID = Convert.ToInt32(drv["StoreID"]); if (drv["DeliveryNote"] != null) { pld.DeliveryNote = Convert.ToBoolean(drv["DeliveryNote"]); } else { pld.DeliveryNote = false; } if (rp.IsColumnNull("ReservedStock")) { rp.ReservedStock = Convert.ToDecimal(pld.QuantityInBU); } else { rp.ReservedStock += Convert.ToDecimal(pld.QuantityInBU); } if (drv["UnitID"] != DBNull.Value) { pld.UnitID = Convert.ToInt32(drv["UnitID"]); } plocation.LoadByPrimaryKey(Convert.ToInt32(drv["PalletLocationID"])); pld.PhysicalStoreID = plocation.PhysicalStoreID; rp.Save(); if (drv["StorageTypeID"].ToString() == StorageType.PickFace) { pf.LoadByPalletLocation(Convert.ToInt32(drv["PalletLocationID"])); //pf.Balance -= Convert.ToDecimal(pld.QuantityInBU); pf.Save(); } } pld.Save(); ord.ChangeStatus(OrderStatus.Constant.PICK_LIST_GENERATED, CurrentContext.UserId); ord.Save(); }
/// <summary> /// Releases the reservation. /// </summary> public void ReleaseReservation() { PickList pickList = new PickList(); pickList.LoadByOrderID(this.ID); if (pickList.RowCount == 0) //If there is no picklist, there is nothing to release. return; PickListDetail pld = new PickListDetail(); pld.LoadByPickListID(pickList.ID); pld.Rewind(); while (!pld.EOF) { ReceivePallet receivePallet = new ReceivePallet(); receivePallet.LoadByPrimaryKey(pld.ReceivePalletID); ReceiveDoc rdoc = new ReceiveDoc(); rdoc.LoadByPrimaryKey(pld.ReceiveDocID); receivePallet.ReservedStock = receivePallet.ReservedStock - Convert.ToInt32(pld.QuantityInBU); if (receivePallet.ReservedStock < 0) receivePallet.ReservedStock = 0; receivePallet.Save(); //Delete from picklistDetail and add to pickListDetailDeleted PickListDetailDeleted.AddNewLog(pld, BLL.CurrentContext.UserId); pld.MarkAsDeleted(); pld.MoveNext(); //Delete issues if the order has any var iss = new Issue(); iss.GetIssueByOrderID(this.ID); iss.Rewind(); if (iss.RowCount > 0) { while (!iss.EOF) { iss.MarkAsDeleted(); iss.MoveNext(); } iss.Save(); } } pld.Save(); pickList.MarkAsDeleted(); pickList.Save(); }
/// <summary> /// This happes when there is plenty of transaction at the same time /// and will result a partial commit. /// This fake rows should be deleted from DB. /// </summary> /// <param name="orderID"></param> private void RemoveFakePartialCommitPickListDetails(int orderID) { var order = new Order(); order.LoadByPrimaryKey(orderID); if (order.OrderStatusID == OrderStatus.Constant.ORDER_APPROVED) { var pickList = new PickList(); pickList.LoadByOrderID(order.ID); if (pickList.RowCount == 0) //~ If there is no picklist, there is nothing to delete. ~// return; var picklistDetail = new PickListDetail(); picklistDetail.LoadByPickListID(pickList.ID); picklistDetail.Rewind(); while (!picklistDetail.EOF) { PickListDetailDeleted.AddNewLog(picklistDetail, CurrentContext.UserId); picklistDetail.MarkAsDeleted(); picklistDetail.MoveNext(); } picklistDetail.Save(); pickList.MarkAsDeleted(); pickList.Save(); } }
/// <summary> /// Saves issue order details /// </summary> /// <param name="orderID"></param> /// <param name="dvPickListMakeup"></param> public void SavePickList(int orderID, DataView dvPickListMakeup, int userID) { //~ Check if This Order has a previous Printed Picklist with detail: Note a header only doesnt affect us! // var pickList = new PickList(); pickList.LoadByOrderID(orderID); if(pickList.RowCount>0) { var pldetail = new PickListDetail(); pldetail.LoadByPickListID(pickList.ID); if (pldetail.RowCount > 0) { RemoveFakePartialCommitPickListDetails(orderID); var pickL = new PickList(); pickL.LoadByOrderID(orderID); if (pickL.RowCount > 0) { throw new Exception("Picklist has already been printed for this Order "); // This error has been apprearing for the last one year so funny! I hope it won't come again! day: 10/21/2014 @yido // } } } // Create a pick list entry Order ord = new Order(); ord.LoadByPrimaryKey(orderID); PickList pl = new PickList(); PalletLocation plocation = new PalletLocation(); plocation.LoadByPrimaryKey(Convert.ToInt32(dvPickListMakeup[0]["PalletLocationID"])); pl.AddNew(); pl.OrderID = orderID; pl.PickType = "Pick"; pl.PickedBy = userID; pl.IsConfirmed = false; pl.IssuedDate = DateTimeHelper.ServerDateTime; pl.SavedDate = DateTimeHelper.ServerDateTime; pl.PickedDate = DateTimeHelper.ServerDateTime; pl.IsWarehouseConfirmed = 0; pl.WarehouseID = plocation.WarehouseID; pl.Save(); PickListDetail pld = new PickListDetail(); ReceivePallet rp = new ReceivePallet(); ReceiveDoc rd = new ReceiveDoc(); PickFace pf = new PickFace(); foreach (DataRowView drv in dvPickListMakeup) { pld.AddNew(); pld.PickListID = pl.ID; pld.OrderDetailID = Convert.ToInt32(drv["OrderDetailID"]); pld.ItemID = Convert.ToInt32(drv["ItemID"]); pld.BatchNumber = (drv["BatchNo"].ToString()); if (drv["ExpDate"] != DBNull.Value) { pld.ExpireDate = Convert.ToDateTime(drv["ExpDate"]); } pld.ManufacturerID = Convert.ToInt32(drv["ManufacturerID"]); pld.BoxLevel = Convert.ToInt32(drv["BoxLevel"]); pld.QtyPerPack = Convert.ToInt32(drv["QtyPerPack"]); pld.Packs = Convert.ToDecimal(drv["Pack"]); pld.PalletLocationID = Convert.ToInt32(drv["PalletLocationID"]); pld.QuantityInBU = Convert.ToDecimal(drv["QtyInBU"]); pld.ReceiveDocID = Convert.ToInt32(drv["ReceiveDocID"]); pld.ReceivePalletID = Convert.ToInt32(drv["ReceivePalletID"]); if (drv["CalculatedCost"] != DBNull.Value) pld.Cost = Convert.ToDouble(drv["CalculatedCost"]); if (drv["UnitPrice"] != DBNull.Value) pld.UnitPrice = Convert.ToDouble(drv["UnitPrice"]); int ReceivePalletID = Convert.ToInt32(drv["ReceivePalletID"]); rp.LoadByPrimaryKey(ReceivePalletID); pld.StoreID = Convert.ToInt32(drv["StoreID"]); if (drv["DeliveryNote"] != null) pld.DeliveryNote = Convert.ToBoolean(drv["DeliveryNote"]); else pld.DeliveryNote = false; if (rp.IsColumnNull("ReservedStock")) { rp.ReservedStock = Convert.ToDecimal(pld.QuantityInBU); } else { rp.ReservedStock += Convert.ToDecimal(pld.QuantityInBU); } if (drv["UnitID"] != DBNull.Value) { pld.UnitID = Convert.ToInt32(drv["UnitID"]); } plocation.LoadByPrimaryKey(Convert.ToInt32(drv["PalletLocationID"])); pld.PhysicalStoreID = plocation.PhysicalStoreID; rp.Save(); if (drv["StorageTypeID"].ToString() == StorageType.PickFace) { pf.LoadByPalletLocation(Convert.ToInt32(drv["PalletLocationID"])); //pf.Balance -= Convert.ToDecimal(pld.QuantityInBU); pf.Save(); } } pld.Save(); ord.ChangeStatus(OrderStatus.Constant.PICK_LIST_GENERATED,CurrentContext.UserId); ord.Save(); }
/// <summary> /// Undo pick list that has been printed /// </summary> /// <param name="orderID">The order ID.</param> public void CancelOrderWithPickList(int orderID) { // Create a pick list entry Order ord = new Order(); PickList pl = new PickList(); PickListDetail pld = new PickListDetail(); ReceivePallet rp = new ReceivePallet(); ReceiveDoc rd = new ReceiveDoc(); PickFace pf = new PickFace(); PalletLocation palletLocation = new PalletLocation(); ord.LoadByPrimaryKey(orderID); pl.LoadByOrderID(orderID); pld.LoadByPickListID(pl.ID); while (!pld.EOF) { rp.LoadByPrimaryKey(pld.ReceivePalletID); rp.ReservedStock -= Convert.ToInt32(pld.QuantityInBU); if (rp.ReservedStock < 0) rp.ReservedStock = 0; //If there has been no reservation, allow to cancel the picklist too. No need for it to be blocked by the constraint. rp.Save(); palletLocation.LoadByPrimaryKey(pld.PalletLocationID); if (palletLocation.StorageTypeID.ToString() == StorageType.PickFace) { pf.LoadByPalletLocation(pld.PalletLocationID); pf.Balance += Convert.ToInt32(pld.QuantityInBU); pf.Save(); } //Delete from picklistDetail and add to pickListDetailDeleted PickListDetailDeleted.AddNewLog(pld, BLL.CurrentContext.UserId); pld.MarkAsDeleted(); pld.MoveNext(); } pld.Save(); ord.ChangeStatus(OrderStatus.Constant.CANCELED,CurrentContext.UserId); pl.MarkAsDeleted(); pl.Save(); }
/// <summary> /// Receives from account transfer. /// </summary> /// <param name="PicklistID">The picklist ID.</param> /// <param name="StoreID">The store ID.</param> /// <param name="User">The user.</param> /// <param name="UserID">The user ID.</param> /// <returns></returns> public static String ReceiveFromAccountTransfer(int PicklistID, int StoreID, string User, int UserID) { PickListDetail pickListDetail = new PickListDetail(); pickListDetail.LoadByPickListID(PicklistID); DataView dv = pickListDetail.DefaultView; ReceiveDoc NewReceiveDoc = new ReceiveDoc(); String ReferenceID = ReceiveDoc.GetNextRefForTransfer(); foreach (DataRowView dvr in dv) { //Get ReceiveDoc information. int receiveDocID = Convert.ToInt32(dvr["ReceiveDocID"]); ReceiveDoc receiveDocFromPicklist = new ReceiveDoc(); receiveDocFromPicklist.LoadByPrimaryKey(receiveDocID); //We have all the Receivedoc information that we want NewReceiveDoc.AddNew(); if (receiveDocFromPicklist.s_BatchNo == null) NewReceiveDoc.BatchNo = receiveDocFromPicklist.BatchNo; NewReceiveDoc.ItemID = receiveDocFromPicklist.ItemID; NewReceiveDoc.SupplierID = receiveDocFromPicklist.SupplierID; if (receiveDocFromPicklist.s_ExpDate == null) NewReceiveDoc.ExpDate = receiveDocFromPicklist.ExpDate; NewReceiveDoc.StoreID = StoreID; NewReceiveDoc.ReceivedBy = User; NewReceiveDoc.Remark = receiveDocFromPicklist.Remark; NewReceiveDoc.RefNo = "TA" + receiveDocFromPicklist.RefNo; if (!receiveDocFromPicklist.IsColumnNull("Cost")) NewReceiveDoc.Cost = receiveDocFromPicklist.Cost; NewReceiveDoc.ManufacturerId = receiveDocFromPicklist.ManufacturerId; NewReceiveDoc.Quantity = Convert.ToInt32(dvr["Packs"]) * Convert.ToInt32(dvr["QtyPerPack"]); NewReceiveDoc.NoOfPack = Convert.ToInt32(dvr["Packs"]); NewReceiveDoc.QtyPerPack = Convert.ToInt32(dvr["QtyPerPack"]); if (!receiveDocFromPicklist.IsColumnNull("PricePerPack")) NewReceiveDoc.PricePerPack = receiveDocFromPicklist.PricePerPack; if (!receiveDocFromPicklist.IsColumnNull("SellingPrice")) NewReceiveDoc.SellingPrice = receiveDocFromPicklist.SellingPrice; NewReceiveDoc.UnitID = receiveDocFromPicklist.UnitID; NewReceiveDoc.DeliveryNote = receiveDocFromPicklist.DeliveryNote; //NewReceiveDoc.PricePerPack = receiveDocFromPicklist.PricePerPack; NewReceiveDoc.QuantityLeft = Convert.ToInt32(dvr["Packs"]) * Convert.ToInt32(dvr["QtyPerPack"]); NewReceiveDoc.EurDate = DateTimeHelper.ServerDateTime; NewReceiveDoc.Date = EthiopianDate.EthiopianDate.Now.ToGregorianDate(); NewReceiveDoc.IsDamaged = receiveDocFromPicklist.IsDamaged; NewReceiveDoc.Save(); NewReceiveDoc.SetStatusAsReceived(UserID); PalletizeTransfer(NewReceiveDoc); } return ReferenceID; }