public IHttpActionResult DeleteReceiveOrder(int id) { ReceiveOrder receiveOrder = new ReceiveOrder(); var status = false; receiveOrder = db.ReceiveOrders.Where(x => x.IsActive == true && x.Id == id).FirstOrDefault(); if (receiveOrder.IsFinalize == true) { status = false; } else { receiveOrder.IsActive = false; receiveOrder.ReceiptOrderItems = db.ReceiptOrderItems.Where(x => x.IsActive == true && x.ReceiptOrderId == id).ToList(); foreach (var a in receiveOrder.ReceiptOrderItems) { a.IsActive = false; var data = db.StockWarehouseTransactions.Where(x => x.IsActive == true && x.TransactionReferenceID == 1).FirstOrDefault(); data.StockTransactionTypeId = 3; db.SaveChanges(); } } return(Ok(status)); }
public IHttpActionResult PutReceiveOrder(int Id, ReceiveOrder receiveOrder) { var receipt = db.ReceiveOrders.Where(x => x.IsActive == true && x.Id == Id).FirstOrDefault(); receipt.IsActive = true; receiveOrder.ReceiptOrderItems = receiveOrder.ReceiptOrderItems; return(Ok(true)); }
public void ReceivePurchaseOrder(int orderNumber, List <ViewPurchaseOrderItems> orderDetails, bool orderCompleted) { using (var context = new eToolsContext()) { PurchaseOrder purchaseOrder = context.PurchaseOrders.Find(orderNumber); purchaseOrder.Closed = orderCompleted; context.Entry(purchaseOrder).Property("Closed").IsModified = true; ReceiveOrder receiveOrder = new ReceiveOrder(); receiveOrder.PurchaseOrderID = orderNumber; receiveOrder.ReceiveDate = DateTime.Now; context.ReceiveOrders.Add(receiveOrder); StockItem stockItem = null; PurchaseOrderDetail purchaseOrderDetail = null; ReceiveOrderDetail receiveOrderDetail = null; ReturnedOrderDetail returnedOrderDetail = null; foreach (ViewPurchaseOrderItems item in orderDetails) { purchaseOrderDetail = purchaseOrder.PurchaseOrderDetails.Where(order => order.StockItemID == item.ItemID).SingleOrDefault(); if (item.Received > 0) { receiveOrderDetail = new ReceiveOrderDetail(); receiveOrderDetail.ReceiveOrderID = receiveOrder.ReceiveOrderID; receiveOrderDetail.PurchaseOrderDetailID = purchaseOrderDetail.PurchaseOrderDetailID; receiveOrderDetail.QuantityReceived = item.Received; context.ReceiveOrderDetails.Add(receiveOrderDetail); stockItem = context.StockItems.Find(item.ItemID); stockItem.QuantityOnHand += item.Received; context.Entry(stockItem).Property("QuantityOnHand").IsModified = true; if (item.Received > stockItem.QuantityOnOrder) { stockItem.QuantityOnOrder = 0; } else { stockItem.QuantityOnOrder -= item.Received; } context.Entry(stockItem).Property("QuantityOnOrder").IsModified = true; } if (item.Returned > 0) { returnedOrderDetail = new ReturnedOrderDetail(); returnedOrderDetail.ReceiveOrderID = receiveOrder.ReceiveOrderID; returnedOrderDetail.PurchaseOrderDetailID = purchaseOrderDetail.PurchaseOrderDetailID; returnedOrderDetail.ItemDescription = stockItem.Description; returnedOrderDetail.Quantity = item.Returned; returnedOrderDetail.Reason = item.Reason; context.ReturnedOrderDetails.Add(returnedOrderDetail); } } context.SaveChanges(); } }
private void GetOrderInfo() { ReceiveOrder orderInfo = Core.Container.Instance.Resolve <IServiceReceiveOrder>().GetEntity(OrderID); lblAmount.Text = orderInfo.OrderAmount.ToString(); lblCount.Text = orderInfo.OrderNumber.ToString(); lblOrderNo.Text = orderInfo.OrderNO; lblOrderDate.Text = orderInfo.OrderDate.ToString(); lblUser.Text = orderInfo.UserName; ddlWH.SelectedValue = orderInfo.WareHouseID.ToString(); //绑定商品明细 BindGrid(orderInfo.OrderNO); }
private void GetOrderInfo() { ReceiveOrder order = Core.Container.Instance.Resolve <IServiceReceiveOrder>().GetEntity(OrderID); OrderNO = order.OrderNO; //初始化页面数据 dpStartDate.Text = order.OrderDate.ToString("yyyy-MM-dd HH:mm:ss"); txtRemark.Text = order.Remark; lblOrderNo.Text = OrderNO; ddlSuplier.SelectedValue = order.UserID.ToString(); ddlWH.SelectedValue = order.WareHouseID.ToString(); }
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e) { int ID = GetSelectedDataKeyID(Grid1); //获取当前选中记录信息 ReceiveOrder orderInfo = Core.Container.Instance.Resolve <IServiceReceiveOrder>().GetEntity(ID); if (e.CommandName == "Delete") { if (orderInfo != null) { if (orderInfo.IsTemp == 1) { //删除临时订单商品信息 IList <ICriterion> qryList = new List <ICriterion>(); qryList.Add(Expression.Eq("OrderNO", orderInfo.OrderNO)); IList <ReceiveOrderDetail> goodsList = Core.Container.Instance.Resolve <IServiceReceiveOrderDetail>().GetAllByKeys(qryList); foreach (ReceiveOrderDetail goods in goodsList) { Core.Container.Instance.Resolve <IServiceReceiveOrderDetail>().Delete(goods); } //删除临时订单信息 Core.Container.Instance.Resolve <IServiceReceiveOrder>().Delete(orderInfo); BindGrid(); } else { Alert.Show("正式订单不能删除!"); } } } if (e.CommandName == "editField") { if (orderInfo != null) { if (orderInfo.IsTemp == 1) { PageContext.Redirect(string.Format("~/Inventory/ReceiveOrderEdit.aspx?id={0}", ID)); } else { Alert.Show("正式订单不能修改!"); } } } if (e.CommandName == "viewField") { PageContext.Redirect(string.Format("~/Inventory/ReceiveOrderView.aspx?id={0}", ID)); } }
private void BindOrderInfo() { IList <ICriterion> qryList = new List <ICriterion>(); qryList.Add(Expression.Eq("OrderNO", OrderNO)); ReceiveOrder orderInfo = Core.Container.Instance.Resolve <IServiceReceiveOrder>().GetEntityByFields(qryList); OrderID = orderInfo != null ? orderInfo.ID : 0; WHID = orderInfo != null ? orderInfo.WareHouseID : 0; lblTitle.Text = string.Format("领用单号:{0}", OrderNO); //获取出库库房信息 WareHouse houseInfo = Core.Container.Instance.Resolve <IServiceWareHouse>().GetEntity(WHID); lblWHInfo.Text = string.Format("出库库房:{0}", houseInfo != null ? houseInfo.WHName : ""); }
public IHttpActionResult PostReceiveOrder(ReceiveOrder receiveOrder) { ReceiveOrder model = new ReceiveOrder(); model.PurchaseOrderId = receiveOrder.PurchaseOrderId; model.ReceiptNumber = receiveOrder.ReceiptNumber; DateTime dNow = DateTime.Now; model.ReceiptDate = dNow; model.LogId = 2; model.TotalQuantity = 0; model.TotalCost = 0; model.TotalVAT = 0; model.IsActive = true; db.ReceiveOrders.Add(model); db.SaveChanges(); return(Ok(true)); }
/// <summary> /// 接收订单并生成任务 /// </summary> /// <param name="pid"></param> /// <param name="num"></param> /// <returns></returns> public bool AddOrder(int pid, int num, dynamic user) { using (ShopEntities db = new ShopEntities()) { bool flag = false; using (var transaction = db.Database.BeginTransaction()) { try { ReceiveOrder ro = new ReceiveOrder(); ro.Pid = pid; ro.Num = num; ro.UserID = user.ID; ro.Url = "www.xxx.com"; ro.Shape = 1; db.ReceiveOrder.Add(ro); db.SaveChanges(); var res = db.Product.SingleOrDefault(o => o.ID == pid); Tasks t = new Tasks(); t.ProductID = pid; t.BuyerUserID = user.ID; t.Status = 0;//接单任务改为待确认 t.Price = res.Price; t.Time = DateTime.Now; t.OrderCode = Guid.NewGuid().ToString("N"); db.Tasks.Add(t); db.SaveChanges(); var p = db.Product.SingleOrDefault(o => o.ID == pid); if (p.ProductNumber > 0) { p.SalesVolume = p.SalesVolume + num; } db.SaveChanges(); transaction.Commit(); flag = true; } catch (Exception ex) { transaction.Rollback(); } return(flag); } } }
private void CreateOrderInfo() { ReceiveOrder order = new ReceiveOrder(); order.OrderAmount = 0; order.OrderDate = DateTime.Now; order.OrderNO = string.Format("LY{0}", DateTime.Now.ToString("yyyyMMddHHmmss")); order.OrderNumber = 0; order.Remark = ""; order.UserID = 0; order.WareHouseID = int.Parse(ddlWH.SelectedValue); order.Operator = User.Identity.Name; Core.Container.Instance.Resolve <IServiceReceiveOrder>().Create(order); OrderNO = order.OrderNO; //初始化页面数据 lblOrderNo.Text = OrderNO; dpStartDate.Text = DateTime.Now.ToString("yyyy-MM-dd"); }
public void Create_ReceiveOrder(int purchaseorderid, List <RecevingOrderList> quanreceList) { using (var context = new eToolsContext()) { ReceiveOrder newReceiveOrder = new ReceiveOrder(); newReceiveOrder.PurchaseOrderID = purchaseorderid; newReceiveOrder.ReceiveDate = DateTime.Now; context.ReceiveOrders.Add(newReceiveOrder); context.SaveChanges(); var get_lastReceiveOrder = (from x in context.ReceiveOrders select x).ToList(); ReceiveOrder lastRece = get_lastReceiveOrder.LastOrDefault(); Create_ReturnedOrderDetails(lastRece.ReceiveOrderID, quanreceList); Create_ReceiveOrderDetail(lastRece.ReceiveOrderID, quanreceList); } }// part-three, Insert button.
public void btnReturn_Click(object sender, EventArgs e) { IList <ICriterion> qryList = new List <ICriterion>(); qryList.Add(Expression.Eq("OrderNO", OrderNO)); //获取当前订单信息 ReceiveOrder orderInfo = Core.Container.Instance.Resolve <IServiceReceiveOrder>().GetEntityByFields(qryList); //删除临时订单商品信息 if (orderInfo != null && orderInfo.IsTemp == 1) { IList <ReceiveOrderDetail> goodsList = Core.Container.Instance.Resolve <IServiceReceiveOrderDetail>().GetAllByKeys(qryList); foreach (ReceiveOrderDetail goods in goodsList) { Core.Container.Instance.Resolve <IServiceReceiveOrderDetail>().Delete(goods); } //删除临时订单信息 Core.Container.Instance.Resolve <IServiceReceiveOrder>().Delete(orderInfo); } //返回订单管理页面 PageContext.Redirect("~/Inventory/ReceiveOrderManager.aspx"); }
public NukeStrikeDialog(ReceiveOrder receiveOrder) { this.receiveOrder = receiveOrder; InitializeComponent(); }
} //eom public void Add_ReceivedOrders(int purchaseOrderId, int poNumber, List <ReceiveNewOrders> newOrders) { using (var context = new eBikesContext()) { int idValue = 0; ReceiveOrder receiveNewOrder = null; ReceiveOrderDetail receiveNewOrderDetail = null; ReturnedOrderDetail returnedOrder = null; //Add new received order receiveNewOrder = new ReceiveOrder(); receiveNewOrder.PurchaseOrderID = purchaseOrderId; receiveNewOrder.ReceiveDate = DateTime.Now; receiveNewOrder = context.ReceiveOrders.Add(receiveNewOrder); idValue = receiveNewOrder.ReceiveOrderDetails.Count() + 1; //Loop through the details of order foreach (ReceiveNewOrders item in newOrders) { if (item.QtyReceived != 0) { if (item.QtyReceived <= item.Outstanding) { receiveNewOrderDetail = new ReceiveOrderDetail(); receiveNewOrderDetail.PurchaseOrderDetailID = item.PurchaseOrderDetailId; receiveNewOrderDetail.ReceiveOrderID = idValue; receiveNewOrderDetail.QuantityReceived = item.QtyReceived; receiveNewOrder.ReceiveOrderDetails.Add(receiveNewOrderDetail); //Update quantities in parts table var partExists = context.Parts.Where(p => p.PartID == item.PartId).SingleOrDefault(); if (partExists != null) { if (partExists.QuantityOnOrder >= item.Outstanding) { context.Parts.Attach(partExists); partExists.QuantityOnHand += item.QtyReceived; partExists.QuantityOnOrder -= item.QtyReceived; context.Entry(partExists).State = EntityState.Modified; } else { throw new Exception("There is an issue with Part Number " + partExists.PartID + " - " + partExists.Description + " the quanity on order (" + partExists.QuantityOnOrder + ") is less than that outsanding."); } } else { throw new Exception("Part does not exist in database or there is no quantity on order"); } } else { throw new Exception("Receive Quantity can not be more than Outstanding quantity"); } } //Process returned items if (!string.IsNullOrEmpty(item.QtyReturned.ToString()) && !string.IsNullOrEmpty(item.Notes)) { returnedOrder = new ReturnedOrderDetail(); returnedOrder.ReceiveOrderID = idValue; returnedOrder.PurchaseOrderDetailID = item.PurchaseOrderDetailId; returnedOrder.ItemDescription = item.PartDescription; returnedOrder.Quantity = item.QtyReturned; returnedOrder.Reason = item.Notes; returnedOrder.VendorPartNumber = item.PartId.ToString(); receiveNewOrder.ReturnedOrderDetails.Add(returnedOrder); } } //Process items in unorder cart var unordered = context.UnorderedPurchaseItemCarts.Where(up => up.PurchaseOrderNumber == 0); if (unordered.Count() > 0) { foreach (var unorderedItem in unordered) { ReturnedOrderDetail unorderedReturn = new ReturnedOrderDetail(); unorderedReturn.ReceiveOrderID = idValue; unorderedReturn.Quantity = unorderedItem.Quantity; unorderedReturn.Reason = unorderedItem.Description; unorderedReturn.VendorPartNumber = unorderedItem.VendorPartNumber; receiveNewOrder.ReturnedOrderDetails.Add(unorderedReturn); context.UnorderedPurchaseItemCarts.Remove(unorderedItem); } } //Get count of outstanding items int outstandingSum = newOrders.Sum(item => item.Outstanding); int receivedSum = newOrders.Sum(rs => rs.QtyReceived); if ((outstandingSum - receivedSum) == 0) { PurchaseOrder po = context.PurchaseOrders.Find(purchaseOrderId); if (po != null) { context.PurchaseOrders.Attach(po); po.Closed = true; context.Entry(po).State = EntityState.Modified; } } context.SaveChanges(); } }
public PROcountDialog(ReceiveOrder receiveOrder) { this.receiveOrder = receiveOrder; InitializeComponent(); }
/*--------------Function Area------------------*/ /* * Check wheather the receiving record of the respective sypply order * Number existed or not. * Author:Shahriar * Date:19-7-07 */ //private bool IsEmptyRecord(string supplyOrder) //{ // sql = "select count(*) as count from receiveorders where supplyorderid='" + supplyOrder + "'"; // DataTable dtSupplyOrders = dbHandler.GetDataTable(sql); // string count=dtSupplyOrders.Rows[0]["count"].ToString(); // if(count.Equals("0")) // return true; // else // return false; //} /* * Function for update Receive Details * Author:Shahriar * Date:19-7-07 */ //private bool UpdateReceiveDetails(string supplyOrder) //{ // int index=1; // Double orderedQty=0.00; // Double receivedQty = 0.00; // int num_orders = (grdReceive.Rows.Count*3) + 2; // NpgsqlCommand[] commands = new NpgsqlCommand[num_orders]; // sql = "update receiveorders set receivedate=:receivedate,received_by=:received_by,remarks=:remarks where receiveid=:receiveid and supplyorderid=:supplyorderid"; // commands[0] = new NpgsqlCommand(sql); // commands[0].Parameters.Add("receiveid", lblReceiveNoValue.Text); // commands[0].Parameters.Add("supplyorderid", lblSupplyOrderValue.Text); // commands[0].Parameters.Add("receivedate", System.DateTime.Parse(txtReceiveDt.Text).ToString("yyyy-MM-dd")); // commands[0].Parameters.Add("received_by", txtReceiveBy.Text); // commands[0].Parameters.Add("remarks", txtRemarks.Text); // foreach (GridViewRow row in grdReceive.Rows) // { // Label lblArticleCode = (Label)row.Cells[0].FindControl("lblArticleCode"); // Label lblPrevRecvQty = (Label)row.Cells[0].FindControl("lblPrevRecvQty"); // Label lblOrderQty = (Label)row.Cells[0].FindControl("lblOrderQty"); // DecimalControl intCtrPurchasePrice = (DecimalControl)row.Cells[0].FindControl("intCtrPurchasePrice"); // IntegerControl intCtrRecvQty = (IntegerControl)row.Cells[0].FindControl("intCtrRecvQty"); // sql = "update receiveordersline set purchaseprice=:purchaseprice,receiveqty=:receiveqty where receiveid=:receiveid and articlecode=:articlecode"; // commands[index] = new NpgsqlCommand(sql); // commands[index].Parameters.Add("receiveid", lblReceiveNoValue.Text); // commands[index].Parameters.Add("articlecode", lblArticleCode.Text); // commands[index].Parameters.Add("purchaseprice", intCtrPurchasePrice.Text.Replace(',', '.')); // commands[index].Parameters.Add("receiveqty", intCtrRecvQty.Text); // index++; // //calculate total received quantity // Double recvQty = Double.Parse(lblPrevRecvQty.Text) + Double.Parse(intCtrRecvQty.Text); // receivedQty+=recvQty; // //calculate wheather received qty fulfil ordered qty // orderedQty+= Double.Parse(lblOrderQty.Text); // sql = "update supplyordersline set receiveqty=:receiveqty where supplyorderid=:supplyorderid and articlecode=:articlecode"; // commands[index] = new NpgsqlCommand(sql); // commands[index].Parameters.Add("receiveqty", recvQty); // commands[index].Parameters.Add("supplyorderid", lblSupplyOrderValue.Text); // commands[index].Parameters.Add("articlecode", lblArticleCode.Text); // index++; // sql = "update article set quantity=(quantity+:quantity) where articlecode=:articlecode"; // commands[index] = new NpgsqlCommand(sql); // commands[index].Parameters.Add("quantity", intCtrRecvQty.Text); // commands[index].Parameters.Add("articlecode",lblArticleCode.Text); // index++; // } // string rcvStatus = ""; // if (receivedQty == 0) // rcvStatus = "N"; // else if (receivedQty > 0 && receivedQty < orderedQty) // rcvStatus = "P"; // else if (receivedQty >= orderedQty) // rcvStatus = "F"; // sql = "update supplyorders set receivingstatus=:receivingstatus where supplyorderid=:supplyorderid"; // commands[index] = new NpgsqlCommand(sql); // commands[index].Parameters.Add("receivingstatus", rcvStatus); // commands[index].Parameters.Add("supplyorderid", supplyOrder); // string errorMsg = ""; // bool b = dbHandler.ExecuteTransaction(commands, ref errorMsg); // if (b == false) // lblErrorMsg.Text = errorMsg; // return b; //} /* * Function for saving Receive Details * Author:Shahriar * Date:19-7-07 *//// It doesn't work properly, by-Arif. private bool SaveReceiveDetails(string supplyOrder) { DataTable dtReceive = new Facade().GetRceiveDeatilsFromSupplyordersbySupplyOrderId(supplyOrder); string shipCost = dtReceive.Rows[0]["shipcost"].ToString(); int counter = 0; foreach (GridViewRow row in grdReceive.Rows) { TextBox intCtrRecvQty = (TextBox)row.Cells[0].FindControl("intCtrRecvQty"); double qty = Double.Parse(intCtrRecvQty.Text.ToString()); if (qty != 0) //if no quantity received then don't insert into DB { counter++; } } int num_orders = (counter) * 3 + 2; ReceiveOrder objReceiveOrder = new ReceiveOrder(); objReceiveOrder.Receiveid = Int32.Parse(lblReceiveNoValue.Text); objReceiveOrder.Supplyorderid = Int32.Parse(lblSupplyOrderValue.Text); System.Globalization.CultureInfo enUS = new System.Globalization.CultureInfo("en-US", true); System.Globalization.DateTimeFormatInfo dtfi = new System.Globalization.DateTimeFormatInfo(); dtfi.ShortDatePattern = "dd-MM-yyyy"; dtfi.DateSeparator = "-"; DateTime dtIn = Convert.ToDateTime(txtReceiveDt.Text.Trim(), dtfi); objReceiveOrder.Receivedate = Convert.ToDateTime(txtReceiveDt.Text.Trim(), dtfi); objReceiveOrder.Shippingcost = double.Parse(shipCost.Replace(',', '.')); objReceiveOrder.Remarks = txtRemarks.Text; objReceiveOrder.Received_by = txtReceiveBy.Text; List <ReceiveOrderLine> objReceiveOrderLines = new List <ReceiveOrderLine>(); ArrayList PrevRecvQty = new ArrayList(); ArrayList OrderQty = new ArrayList(); foreach (GridViewRow row in grdReceive.Rows) { ReceiveOrderLine objReceiveOrderLine = new ReceiveOrderLine(); Label lblArticleCode = (Label)row.Cells[0].FindControl("lblArticleCode"); Label lblPrevRecvQty = (Label)row.Cells[0].FindControl("lblPrevRecvQty"); PrevRecvQty.Add(lblPrevRecvQty.Text); Label lblOrderQty = (Label)row.Cells[0].FindControl("lblOrderQty"); OrderQty.Add(lblOrderQty.Text); TextBox intCtrPurchasePrice = (TextBox)row.Cells[0].FindControl("intCtrPurchasePrice"); TextBox intCtrRecvQty = (TextBox)row.Cells[0].FindControl("intCtrRecvQty"); double qty = Double.Parse(intCtrRecvQty.Text.ToString()); Double recvQty = 0.0; if (qty != 0) //if no quantity received then don't insert into DB { objReceiveOrderLine.Receiveid = Int32.Parse(lblReceiveNoValue.Text); objReceiveOrderLine.Articlecode = lblArticleCode.Text; objReceiveOrderLine.Purchaseprice = double.Parse(intCtrPurchasePrice.Text.Replace(',', '.')); objReceiveOrderLine.Receiveqty = Int32.Parse(intCtrRecvQty.Text); objReceiveOrderLines.Add(objReceiveOrderLine); } } string errorMsg = ""; bool b = new Facade().SaveReceiveOrder(objReceiveOrder, objReceiveOrderLines, PrevRecvQty, OrderQty, supplyOrder, num_orders, ref errorMsg); if (b == false) { lblErrorMsg.Text = errorMsg; } return(b); }
/// <summary> /// Transactional process of an outstanding order: /// <para>>> Updates the order details</para> /// <para>>> Updates stock item quantity fields for the receive order detail rows</para> /// <para>>> Creates a receive order record</para> /// <para>>> Creates receive order details and/or returned order details record(s)</para> /// <para>>> Updates the outstanding order as closed if fully received</para> /// </summary> /// <param name="_poID"></param> /// <param name="_OODs"></param> /// <param name="_UPICs"></param> public bool OpenOrder_Receive(int _poID, List <OpenOrderDetail> _OODs, List <int> _UPICs) { using (var context = new eToolsContext()) { // Transaction process: // A) Create a ReceiveOrder record when at least one item is received, returned, or unordered // B) Create a new ReceiveOrderDetail record for each item that is received // C) Increase stock item QuantityOnHand by the received quantity // D) Decrease stock item QuantityOnOrder by the received quantity // E) Create a new ReturnedOrderDetail record for each item that is returned // F) Check if the PurchaseOrder can be closed // G) Create a new ReturnedOrderDetail record for each item that is unordered // H) Save all changes // All the records that can be created or updated in the transaction processs List <ReceiveOrderDetail> ReceiveOrderDetails = new List <ReceiveOrderDetail>(); List <ReturnedOrderDetail> ReturnedOrderDetails = new List <ReturnedOrderDetail>(); List <StockItem> StockItems = new List <StockItem>(); PurchaseOrder purchaseOrder = null; // A >> ReceiveOrder receiveOrder = new ReceiveOrder(); // Note: ReceiveOrderID is an identity created when ReceiveOrder inserted receiveOrder.PurchaseOrderID = _poID; receiveOrder.ReceiveDate = DateTime.Now; // Nullable // Continue if order details exist if (_OODs.Count > 0) { bool isOpen = false; // Reverse logic check where order has to be proven to be open (upon iteration through each order detail row) // Process each open order detail foreach (OpenOrderDetail ood in _OODs) { StockItem stockItem = null; int qtyOutstanding = ood.QtyOutstanding; int qtyReceived = (int)ood.QtyReceived; // Check if item was received if (ood.QtyReceived != null && ood.QtyReceived > 0) { // Ensure received qty is not greather than the outstanding qty if (qtyReceived > qtyOutstanding) { throw new Exception("Each received qty must be less than the outstanding qty"); } else { // Monitor order state if (qtyReceived < qtyOutstanding) { isOpen = true; } // B >> ReceiveOrderDetail receiveOrderDetail = new ReceiveOrderDetail(); // Note: ReceiveOrderID is an identity created when ReceiveOrder inserted receiveOrderDetail.PurchaseOrderDetailID = ood.PODetailID; receiveOrderDetail.QuantityReceived = qtyReceived; // Pull stock item from database int stockItemID = ood.StockItemID; stockItem = ( from x in context.StockItems where x.StockItemID == stockItemID select x) .FirstOrDefault(); // C >> stockItem.QuantityOnHand += qtyReceived; // D >> stockItem.QuantityOnOrder -= qtyReceived; // Hold created and updated records ReceiveOrderDetails.Add(receiveOrderDetail); StockItems.Add(stockItem); } } else // Item not received { // Monitor order state if (qtyOutstanding > 0) { isOpen = true; } } // Check if item was returned if (ood.QtyReturned != null && ood.QtyReturned > 0) { // Ensure a reason was entered by the user if (string.IsNullOrEmpty(ood.ReturnReason)) { throw new Exception("Returned quantities require a reason entry"); } else { // Pull stock item from database (if it has not yet been retrieved) if (stockItem == null) { int stockItemID = ood.StockItemID; stockItem = ( from x in context.StockItems where x.StockItemID == stockItemID select x) .FirstOrDefault(); } // E >> ReturnedOrderDetail returnedOrderDetail = new ReturnedOrderDetail(); // Note: ReceiveOrderID is an identity created when ReceiveOrder inserted returnedOrderDetail.PurchaseOrderDetailID = ood.PODetailID; // Nullable returnedOrderDetail.ItemDescription = stockItem.Description; // Nullable returnedOrderDetail.Quantity = (int)ood.QtyReturned; returnedOrderDetail.Reason = string.IsNullOrEmpty(ood.ReturnReason) ? null : ood.ReturnReason; returnedOrderDetail.VendorStockNumber = null; // Nullable // Hold created record ReturnedOrderDetails.Add(returnedOrderDetail); } } } // F >> if (isOpen == false) { // Pull purchase order from database purchaseOrder = ( from x in context.PurchaseOrders where x.PurchaseOrderID == _poID select x) .FirstOrDefault(); // Close order purchaseOrder.Closed = true; } } // Process each unordered purchase item cart (Note: This can happen even if there are no order details for the order) if (_UPICs.Count > 0) { foreach (int cart in _UPICs) { // Pull upic from database int cartID = cart; var upic = ( from x in context.UnorderedPurchaseItemCart where x.CartID == cartID select x) .FirstOrDefault(); // G >> ReturnedOrderDetail returnedOrderDetail = new ReturnedOrderDetail(); // Note: ReceiveOrderID is an identity created when ReceiveOrder inserted returnedOrderDetail.PurchaseOrderDetailID = null; // Nullable returnedOrderDetail.ItemDescription = upic.Description; // Nullable returnedOrderDetail.Quantity = upic.Quantity; returnedOrderDetail.Reason = null; // Nullable returnedOrderDetail.VendorStockNumber = string.IsNullOrEmpty(upic.VendorStockNumber) ? null : upic.VendorStockNumber; // Hold created record ReturnedOrderDetails.Add(returnedOrderDetail); } } // H >> context.ReceiveOrders.Add(receiveOrder); // Creates identity ID used by detail records foreach (ReceiveOrderDetail rod in ReceiveOrderDetails) { // Set detail records receive order ID rod.ReceiveOrderID = receiveOrder.ReceiveOrderID; // Stage detail record context.ReceiveOrderDetails.Add(rod); } foreach (ReturnedOrderDetail rod in ReturnedOrderDetails) { // Set detail record receive order ID rod.ReceiveOrderID = receiveOrder.ReceiveOrderID; // Stage detail record context.ReturnedOrderDetails.Add(rod); } foreach (StockItem si in StockItems) { context.Entry(si).Property(y => y.QuantityOnHand).IsModified = true; context.Entry(si).Property(y => y.QuantityOnOrder).IsModified = true; } bool closed = false; if (purchaseOrder != null) // Purchase order can be closed { context.Entry(purchaseOrder).Property(y => y.Closed).IsModified = true; closed = true; } // Commit transaction context.SaveChanges(); // Return order state return(closed); } }
public void ReceiveOrder(int purchaseOrderID, List <OpenPurchaseOrderDetails> openPODetails) { //openpodetails and unordereditems collected in code-behind from controls on page using (var context = new eToolsContext()) { UnorderedPurchaseItemCartController unorderedItemsController = new UnorderedPurchaseItemCartController(); List <UnorderedPurchaseItemCart> unorderedItems = unorderedItemsController.Get_ListUnorderedPurchaseItemCart(); //transaction //create a receiveorder for the purchaseorderid ReceiveOrder receiveOrder = new ReceiveOrder(); receiveOrder.PurchaseOrderID = purchaseOrderID; receiveOrder.ReceiveDate = DateTime.Now; context.ReceiveOrders.Add(receiveOrder); //create receiveorderdetails for each openPODetails if there is anything entered in receivedquantity foreach (OpenPurchaseOrderDetails openPO in openPODetails) { //make a receiveorderdetail if quantityreceived > 0 and update stockitems, make a returnorderdetail if quantityreturned > 0 if (openPO.ReceivedQuantity > 0) { ReceiveOrderDetail rOD = new ReceiveOrderDetail(); rOD.ReceiveOrderID = receiveOrder.ReceiveOrderID; rOD.PurchaseOrderDetailID = openPO.PurchaseOrderDetailID; rOD.QuantityReceived = openPO.ReceivedQuantity; openPO.QuantityOutstanding -= openPO.ReceivedQuantity; context.ReceiveOrderDetails.Add(rOD); //adjust stockitem QoH (+ReceivedQuantity) and QoO (-ReceivedQuantity) with same stockitemid StockItem stockItem = context.StockItems.Find(openPO.StockItemID); stockItem.QuantityOnHand += openPO.ReceivedQuantity; stockItem.QuantityOnOrder -= openPO.ReceivedQuantity; context.Entry(stockItem).State = System.Data.Entity.EntityState.Modified; } if (openPO.ReturnedQuantity > 0) { ReturnedOrderDetail reOD = new ReturnedOrderDetail(); reOD.ReceiveOrderID = receiveOrder.ReceiveOrderID; reOD.PurchaseOrderDetailID = openPO.PurchaseOrderDetailID; reOD.ItemDescription = openPO.StockItemDescription; reOD.Quantity = openPO.ReturnedQuantity; reOD.Reason = openPO.ReturnReason; reOD.VendorStockNumber = openPO.VendorStockNumber; context.ReturnedOrderDetails.Add(reOD); } } //create returnorderdetail for each unorderedItems and delete them from database UnorderedPurchaseItemCartController unOsysmgr = new UnorderedPurchaseItemCartController(); foreach (UnorderedPurchaseItemCart item in unorderedItems) { ReturnedOrderDetail reOD = new ReturnedOrderDetail(); reOD.ReceiveOrderID = receiveOrder.ReceiveOrderID; reOD.ItemDescription = item.Description; reOD.Quantity = item.Quantity; reOD.VendorStockNumber = item.VendorStockNumber; context.ReturnedOrderDetails.Add(reOD); unOsysmgr.Delete_UnorderedPurchaseItemCart(item.CartID); } //if no purchaseorderdetails have > 0 QOS, close the order if (!(openPODetails.Any(x => x.QuantityOutstanding > 0))) { PurchaseOrder pOrder = context.PurchaseOrders.Find(purchaseOrderID); pOrder.Closed = true; context.Entry(pOrder).State = System.Data.Entity.EntityState.Modified; } context.SaveChanges(); } }
public void ReceiveShimpmentOrder(ReceivedOrderDetails order) { /* command modify Products, ReceiveOrders, ReceiveOrderItems and ReturnOrderItems */ List <Exception> errors = new List <Exception>(); using (var context = new eRaceContext()) { var existing = context.Orders.Find(order.OrderID); if (order == null) { errors.Add(new ArgumentNullException(nameof(order), $"No {nameof(order)} was supplied for ")); } else { if (existing.Closed == true) { errors.Add(new BusinessRuleException <bool>("The order you are accessing is already closed.", nameof(existing.Closed), existing.Closed)); } if (order.OrderID == 0) { errors.Add(new BusinessRuleException <int>("The OrderID is required.", nameof(order.OrderID), order.OrderID)); } if (order.ReceivedOrder.OrderID == 0) { errors.Add(new BusinessRuleException <int>("The OrderID is required.", nameof(order.ReceivedOrder.OrderID), order.ReceivedOrder.OrderID)); } if (order.ReceivedOrder.EmployeeID == 0) { errors.Add(new BusinessRuleException <int>("The Employee ID is required.", nameof(order.ReceivedOrder.EmployeeID), order.ReceivedOrder.EmployeeID)); } foreach (var item in order.ReceiveOrderItems) { var existingOrderDetail = context.OrderDetails.Find(item.OrderDetailID); var itemsize = context.OrderDetails.Find(item.OrderDetailID).OrderUnitSize; if (existingOrderDetail == null) { errors.Add(new ArgumentNullException(nameof(item.OrderDetailID), $"There is no Order Detail with the ID given.")); } if (item.ItemQuantity < 1) { errors.Add(new BusinessRuleException <int>("The item quantity must be greater than 0", nameof(item.ItemQuantity), item.ItemQuantity)); } if (item.ItemQuantity / itemsize >= context.OrderDetails.Find(item.OrderDetailID).Quantity + 1) { errors.Add(new BusinessRuleException <int>("The total amount received cannot exceed the amount ordered by 1 package.", nameof(item.ItemQuantity), item.ItemQuantity)); } } foreach (var item in order.Products) { if (item.QuantityReceived < 1) { errors.Add(new BusinessRuleException <int>("The number of received items must be postive. ", nameof(item.QuantityReceived), item.QuantityReceived)); } } foreach (var item in order.ReturnOrderItems) { if (item.ItemQuantity < 1) { errors.Add(new BusinessRuleException <int>("The number of returned items is required.", nameof(item.ItemQuantity), item.ItemQuantity)); } } } if (errors.Any()) { throw new BusinessRuleCollectionException("Unable to receive shipment.", errors); } // ReceiveOrder var newReceiveOrder = new ReceiveOrder { OrderID = order.ReceivedOrder.OrderID, ReceiveDate = order.ReceivedOrder.ReceiveDate, EmployeeID = order.ReceivedOrder.EmployeeID }; context.ReceiveOrders.Add(newReceiveOrder); int id = newReceiveOrder.ReceiveOrderID; // ReceiveOrderItems foreach (var item in order.ReceiveOrderItems) { var newReceiveOrderItem = new ReceiveOrderItem { ReceiveOrderID = id, OrderDetailID = item.OrderDetailID, ItemQuantity = item.ItemQuantity }; context.ReceiveOrderItems.Add(newReceiveOrderItem); } // ReturnOrderItems foreach (var item in order.ReturnOrderItems) { var newReturnOrderItem = new ReturnOrderItem { ReceiveOrderID = id, OrderDetailID = item.OrderDetailID, ItemQuantity = item.ItemQuantity, Comment = item.Comment, UnOrderedItem = item.UnOrderedItem, VendorProductID = item.VendorProductID }; context.ReturnOrderItems.Add(newReturnOrderItem); } // Products foreach (var item in order.Products) { var given = context.Products.Find(context.OrderDetails.Find(item.ProductID).ProductID); if (given == null) { throw new ArgumentException($"The given product id of {item.ProductID} does not exist in the database.", nameof(item.ProductID)); } given.QuantityOnHand = given.QuantityOnHand + item.QuantityReceived; given.QuantityOnOrder = given.QuantityOnOrder - item.QuantityReceived; if (given.QuantityOnOrder < 0) { given.QuantityOnOrder = 0; } var existingProduct = context.Entry(given); existingProduct.Property(nameof(given.QuantityOnHand)).IsModified = true; existingProduct.Property(nameof(given.QuantityOnOrder)).IsModified = true; } // Check if the order has been filled var outstanding = context.Orders.Find(order.OrderID).OrderDetails; var num = 0; foreach (var item in outstanding) { if (context.OrderDetails.Find(item.OrderDetailID).Quantity *context.OrderDetails.Find(item.OrderDetailID).OrderUnitSize - (context.OrderDetails.Find(item.OrderDetailID).ReceiveOrderItems.Select(x => x.ItemQuantity)).FirstOrDefault() == 0) { num++; } } if (num == outstanding.Count) { var givenOrder = context.Orders.Find(order.OrderID); givenOrder.Closed = true; givenOrder.Comment = "Order Complete"; var existingOrder = context.Entry(givenOrder); existingOrder.Property(nameof(givenOrder.Comment)).IsModified = true; existingOrder.Property(nameof(givenOrder.Closed)).IsModified = true; } context.SaveChanges(); } }
public WarDialog(ReceiveOrder receiveOrder) { this.receiveOrder = receiveOrder; InitializeComponent(); }
public void ReceiveShipment(int orderid, List <TransactionItemPOCO> received, List <RejectedItemPOCO> rejected) { List <string> errors = new List <string>(); using (var context = new RaceContext()) { var closed = (from x in context.Orders where x.OrderID == orderid select x.Closed).FirstOrDefault(); if (closed) { errors.Add("You cannot receive a closed order"); } else if (received.Any(x => x.ItemQuantity < 0)) { errors.Add("You cannot have a negative received amount"); } else { int newrecieveorderid = context.ReceiveOrders.Select(x => x.ReceiveOrderID).Max(); newrecieveorderid++; var recieveorderlist = new List <ReceiveOrderItem>(); var returnorderlist = new List <ReturnOrderItem>(); foreach (var item in received) { int newrecieveorderitemid = context.ReceiveOrderItems.Select(x => x.ReceiveOrderItemID).Max(); newrecieveorderid++; int orderDetailID = (from x in context.Products from y in x.OrderDetails where x.ItemName == item.ItemName && y.OrderID == orderid select y.OrderDetailID).FirstOrDefault(); recieveorderlist.Add(new ReceiveOrderItem() { ReceiveOrderItemID = newrecieveorderitemid, ReceiveOrderID = newrecieveorderid, OrderDetailID = orderDetailID, ItemQuantity = item.ItemQuantity, OrderDetail = (from x in context.OrderDetails where x.OrderDetailID == orderDetailID select x).FirstOrDefault(), ReceiveOrder = (from x in context.ReceiveOrders where x.ReceiveOrderID == newrecieveorderid select x).FirstOrDefault() }); } if (rejected.Count() > 0) { foreach (var item in rejected) { int newreturnorderitemid = context.ReturnOrderItems.Select(x => x.ReturnOrderItemID).Max(); newreturnorderitemid++; int orderDetailID = (from x in context.Products from y in x.OrderDetails where x.ItemName == item.ItemName && y.OrderID == orderid select y.OrderDetailID).FirstOrDefault(); returnorderlist.Add(new ReturnOrderItem() { ReturnOrderItemID = newreturnorderitemid, ReceiveOrderID = newrecieveorderid, OrderDetailID = orderDetailID, UnOrderedItem = null, ItemQuantity = item.ItemQuantity, Comment = item.Reason, VendorProductID = null, OrderDetail = (from x in context.OrderDetails where x.OrderDetailID == orderDetailID select x).FirstOrDefault(), ReceiveOrder = (from x in context.ReceiveOrders where x.ReceiveOrderID == newrecieveorderid select x).FirstOrDefault() }); } } ReceiveOrder receiveOrder = new ReceiveOrder { ReceiveOrderID = newrecieveorderid, OrderID = orderid, ReceiveDate = DateTime.Now, EmployeeID = 56, Employee = (from x in context.Employees where x.EmployeeID == 56 select x).FirstOrDefault(), Order = (from x in context.Orders where x.OrderID == orderid select x).FirstOrDefault(), ReceiveOrderItems = recieveorderlist, ReturnOrderItems = returnorderlist }; context.ReceiveOrders.Add(receiveOrder); foreach (var item in recieveorderlist.ToList()) { ReceiveOrderItem receiveOrderItem = new ReceiveOrderItem { ReceiveOrderItemID = item.ReceiveOrderItemID, ReceiveOrderID = item.ReceiveOrderID, OrderDetailID = item.OrderDetailID, ItemQuantity = item.ItemQuantity, OrderDetail = item.OrderDetail, ReceiveOrder = item.ReceiveOrder }; var query = (from x in context.OrderDetails join prod in context.Products on x.ProductID equals prod.ProductID where x.OrderDetailID == receiveOrderItem.OrderDetailID select prod).FirstOrDefault(); query.QuantityOnHand = query.QuantityOnHand + receiveOrderItem.ItemQuantity; query.QuantityOnOrder = query.QuantityOnOrder - receiveOrderItem.ItemQuantity; } if (returnorderlist.Count > 0) { foreach (var item in returnorderlist.ToList()) { ReturnOrderItem returnOrderItem = new ReturnOrderItem() { ReturnOrderItemID = item.ReturnOrderItemID, ReceiveOrderID = item.ReceiveOrderID, OrderDetailID = item.OrderDetailID, UnOrderedItem = item.UnOrderedItem, ItemQuantity = item.ItemQuantity, Comment = item.Comment, VendorProductID = item.VendorProductID, OrderDetail = item.OrderDetail, ReceiveOrder = item.ReceiveOrder }; var query = (from x in context.OrderDetails join prod in context.Products on x.ProductID equals prod.ProductID where x.OrderDetailID == returnOrderItem.OrderDetailID select prod).FirstOrDefault(); } } context.SaveChanges(); } if (errors.Count > 0) { throw new BusinessRuleException("Receive Shipment", errors); } } }
public NukeStrikeCountDialog(ReceiveOrder receiveOrder, List <int> args) { this.receiveOrder = receiveOrder; this.args = args; InitializeComponent(); }
private void SaveItem(int isTemp) { bool IsStock = bool.Parse(ConfigurationManager.AppSettings["IsStock"]); //更新订单状态为正式订单 IList <ICriterion> qryList = new List <ICriterion>(); qryList.Add(Expression.Eq("OrderNO", OrderNO)); ReceiveOrder orderInfo = Core.Container.Instance.Resolve <IServiceReceiveOrder>().GetEntityByFields(qryList); orderInfo.OrderDate = DateTime.Parse(dpStartDate.Text); orderInfo.OrderAmount = decimal.Parse(lblAmount.Text); orderInfo.IsTemp = isTemp; orderInfo.OrderNumber = decimal.Parse(lblCount.Text); orderInfo.UserID = int.Parse(ddlSuplier.SelectedValue); orderInfo.UserName = ddlSuplier.SelectedText; orderInfo.WareHouseID = int.Parse(ddlWH.SelectedValue); orderInfo.Operator = User.Identity.Name; Core.Container.Instance.Resolve <IServiceReceiveOrder>().Update(orderInfo); //正式订单,更新入库信息及流水信息等 if (isTemp == 0) { #region 出库单信息 if (IsStock) { // 出库单信息 WHOutBoundOrder storageOrder = new WHOutBoundOrder(); storageOrder.BOrderNO = OrderNO; storageOrder.Operator = User.Identity.Name; storageOrder.OrderAmount = orderInfo.OrderAmount; storageOrder.OrderNumber = orderInfo.OrderNumber; storageOrder.OrderDate = orderInfo.OrderDate; storageOrder.OrderNO = string.Format("CK{0}", DateTime.Now.ToString("yyyyMMddHHmmss")); storageOrder.OrderType = 2; storageOrder.OutOrderNO = ""; storageOrder.Remark = "领用出库"; storageOrder.SuplierID = orderInfo.UserID; storageOrder.WareHouseID = orderInfo.WareHouseID; // 出库商品明细信息 IList <ICriterion> qryListDetail = new List <ICriterion>(); qryListDetail.Add(Expression.Eq("OrderNO", OrderNO)); Order[] orderList = new Order[1]; Order orderli = new Order("ID", true); orderList[0] = orderli; IList <ReceiveOrderDetail> list = Core.Container.Instance.Resolve <IServiceReceiveOrderDetail>().GetAllByKeys(qryList, orderList); //写入出库商品明细 foreach (ReceiveOrderDetail detail in list) { decimal amount = detail.GoodsNumber; decimal goodsAmount = 0; IList <ICriterion> qryWHList = new List <ICriterion>(); qryWHList.Add(Expression.Eq("GoodsID", detail.GoodsID)); qryWHList.Add(Expression.Eq("WareHouseID", storageOrder.WareHouseID)); WHGoodsDetail whGoodsDetail = Core.Container.Instance.Resolve <IServiceWHGoodsDetail>().GetEntityByFields(qryWHList); WHOrderGoodsDetail orderDetail = new WHOrderGoodsDetail(); orderDetail.GoodsID = detail.GoodsID; orderDetail.GoodsUnit = detail.GoodsUnit; orderDetail.OrderDate = storageOrder.OrderDate; orderDetail.OrderNO = storageOrder.OrderNO; orderDetail.GoodsNumber = amount; //获取出库单价和金额 orderDetail.GoodsUnitPrice = whGoodsDetail.InventoryUnitPrice; orderDetail.GoodTotalPrice = Math.Round(orderDetail.GoodsNumber * orderDetail.GoodsUnitPrice, 2); orderDetail.TaxAmount = 0; orderDetail.TaxPoint = 0; orderDetail.TotalPriceNoTax = 0; orderDetail.UnitPriceNoTax = 0; //保存出库明细信息 Core.Container.Instance.Resolve <IServiceWHOrderGoodsDetail>().Create(orderDetail); //更新商品变动明细信息(出库) new InventoryHelper().UpdateGoodsJournal(storageOrder.WareHouseID, detail.GoodsID, OrderNO, "LY", 2 , -orderDetail.GoodsNumber, orderDetail.GoodsUnitPrice , -orderDetail.GoodTotalPrice, "" , orderInfo.OrderDate); //累计计算订单成本金额 goodsAmount += orderDetail.GoodTotalPrice; //更新商品库存信息 new InventoryHelper().UpdateWareHouseStock(storageOrder.WareHouseID, detail.GoodsID, -detail.GoodsNumber, 0, -goodsAmount, 0); } //创建出库单信息 Core.Container.Instance.Resolve <IServiceWHOutBoundOrder>().Create(storageOrder); } #endregion 入库单信息 } }
public IHttpActionResult PostReceiveOrder(int Id, ReceiveOrder receiveOrder) { var pageName = Request.RequestUri.LocalPath.getRouteName(); var kkk = pageName.Substring(3, 7); var receipt = db.ReceiveOrders.Where(x => x.IsActive == true && x.Id == Id).FirstOrDefault(); receipt.SupplierInvoice = receiveOrder.SupplierInvoice; receipt.IsActive = true; //receipt.ReceiptOrderItems = receiveOrder.ReceiptOrderItems; int? TotalQuantity = 0; decimal?TotalCost = 0; foreach (var a in receiveOrder.ReceiptOrderItems) { if (a.ProductId != null) { TotalQuantity += a.Quantity01 + a.Quantity02 + a.Quantity03 + a.Quantity04 + a.Quantity05 + a.Quantity06 + a.Quantity07 + a.Quantity08 + a.Quantity09 + a.Quantity10 + a.Quantity11 + a.Quantity12 + a.Quantity13 + a.Quantity14 + a.Quantity15 + a.Quantity16 + a.Quantity17 + a.Quantity18 + a.Quantity19 + a.Quantity20 + a.Quantity21 + a.Quantity22 + a.Quantity23 + a.Quantity24 + a.Quantity25 + a.Quantity26 + a.Quantity27 + a.Quantity28 + a.Quantity29 + a.Quantity30; a.SalesCost = (a.Quantity01 ?? 0) * (a.Cost01 ?? 0) + (a.Quantity02 ?? 0) * (a.Cost02 ?? 0) + (a.Quantity03 ?? 0) * (a.Cost03 ?? 0) + (a.Quantity04 ?? 0) * (a.Cost04 ?? 0) + (a.Quantity05 ?? 0) * (a.Cost05 ?? 0) + (a.Quantity06 ?? 0) * (a.Cost06 ?? 0) + (a.Quantity07 ?? 0) * (a.Cost07 ?? 0) + (a.Quantity08 ?? 0) * (a.Cost08 ?? 0) + (a.Quantity09 ?? 0) * (a.Cost09 ?? 0) + (a.Quantity10 ?? 0) * (a.Cost10 ?? 0) + (a.Quantity11 ?? 0) * (a.Cost11 ?? 0) + (a.Quantity12 ?? 0) * (a.Cost12 ?? 0) + (a.Quantity13 ?? 0) * (a.Cost13 ?? 0) + (a.Quantity14 ?? 0) * (a.Cost15 ?? 0) + (a.Quantity16 ?? 0) * (a.Cost16 ?? 0) + (a.Quantity17 ?? 0) * (a.Cost17 ?? 0) + (a.Quantity18 ?? 0) * (a.Cost18 ?? 0) + (a.Quantity19 ?? 0) * (a.Cost19 ?? 0) + (a.Quantity20 ?? 0) * (a.Cost20 ?? 0) + (a.Quantity21 ?? 0) * (a.Cost21 ?? 0) + (a.Quantity22 ?? 0) * (a.Cost22 ?? 0) + (a.Quantity23 ?? 0) * (a.Cost23 ?? 0) + (a.Quantity24 ?? 0) * (a.Cost24 ?? 0) + (a.Quantity25 ?? 0) * (a.Cost25 ?? 0) + (a.Quantity26 ?? 0) * (a.Cost26 ?? 0) + (a.Quantity27 ?? 0) * (a.Cost27 ?? 0) + (a.Quantity28 ?? 0) * (a.Cost28 ?? 0) + (a.Quantity29 ?? 0) * (a.Cost29 ?? 0) + (a.Quantity30 ?? 0) * (a.Cost30 ?? 0); TotalCost += a.SalesCost; a.IsActive = true; db.ReceiptOrderItems.Add(a); db.SaveChanges(); StockWarehouseTransaction transaction = new StockWarehouseTransaction(); transaction.Quantity01 = a.Quantity01; transaction.Quantity02 = a.Quantity02; transaction.Quantity03 = a.Quantity03; transaction.Quantity04 = a.Quantity04; transaction.Quantity05 = a.Quantity05; transaction.Quantity06 = a.Quantity06; transaction.Quantity07 = a.Quantity07; transaction.Quantity08 = a.Quantity08; transaction.Quantity09 = a.Quantity09; transaction.Quantity10 = a.Quantity10; transaction.Quantity11 = a.Quantity11; transaction.Quantity12 = a.Quantity12; transaction.Quantity13 = a.Quantity13; transaction.Quantity14 = a.Quantity14; transaction.Quantity15 = a.Quantity15; transaction.Quantity16 = a.Quantity16; transaction.Quantity17 = a.Quantity17; transaction.Quantity18 = a.Quantity18; transaction.Quantity19 = a.Quantity19; transaction.Quantity20 = a.Quantity20; transaction.Quantity21 = a.Quantity21; transaction.Quantity22 = a.Quantity22; transaction.Quantity23 = a.Quantity23; transaction.Quantity24 = a.Quantity24; transaction.Quantity25 = a.Quantity25; transaction.Quantity26 = a.Quantity26; transaction.Quantity27 = a.Quantity27; transaction.Quantity28 = a.Quantity28; transaction.Quantity29 = a.Quantity29; transaction.Quantity30 = a.Quantity30; transaction.PrimaryID = a.Id; transaction.StockTransactionTypeId = 1; transaction.TransactionReferenceID = db.TrasactionReferences.Where(x => x.Task == kkk).FirstOrDefault().Id; transaction.ProductID = a.ProductId; transaction.IsActive = true; db.StockWarehouseTransactions.Add(transaction); var stock = db.StockInventories.Where(x => x.IsActive == true && x.ProductID == a.ProductId).FirstOrDefault(); if (stock != null) { stock.Quantity01 = stock.Quantity01 + a.Quantity01 ?? 0; stock.Quantity02 = stock.Quantity02 + a.Quantity02 ?? 0; stock.Quantity03 = stock.Quantity03 + a.Quantity03 ?? 0; stock.Quantity04 = stock.Quantity04 + a.Quantity04 ?? 0; stock.Quantity05 = stock.Quantity05 + a.Quantity05 ?? 0; stock.Quantity06 = stock.Quantity06 + a.Quantity06 ?? 0; stock.Quantity07 = stock.Quantity07 + a.Quantity07 ?? 0; stock.Quantity08 = stock.Quantity08 + a.Quantity08 ?? 0; stock.Quantity09 = stock.Quantity09 + a.Quantity09 ?? 0; stock.Quantity10 = stock.Quantity10 + a.Quantity10 ?? 0; stock.Quantity11 = stock.Quantity11 + a.Quantity11 ?? 0; stock.Quantity12 = stock.Quantity12 + a.Quantity12 ?? 0; stock.Quantity13 = stock.Quantity13 + a.Quantity13 ?? 0; stock.Quantity14 = stock.Quantity14 + a.Quantity14 ?? 0; stock.Quantity15 = stock.Quantity15 + a.Quantity15 ?? 0; stock.Quantity16 = stock.Quantity16 + a.Quantity16 ?? 0; stock.Quantity17 = stock.Quantity17 + a.Quantity17 ?? 0; stock.Quantity18 = stock.Quantity18 + a.Quantity18 ?? 0; stock.Quantity19 = stock.Quantity19 + a.Quantity19 ?? 0; stock.Quantity20 = stock.Quantity20 + a.Quantity20 ?? 0; stock.Quantity21 = stock.Quantity21 + a.Quantity21 ?? 0; stock.Quantity22 = stock.Quantity01 + a.Quantity22 ?? 0; stock.Quantity23 = stock.Quantity01 + a.Quantity23 ?? 0; stock.Quantity24 = stock.Quantity01 + a.Quantity24 ?? 0; stock.Quantity25 = stock.Quantity01 + a.Quantity25 ?? 0; stock.Quantity26 = stock.Quantity01 + a.Quantity26 ?? 0; stock.Quantity27 = stock.Quantity01 + a.Quantity27 ?? 0; stock.Quantity28 = stock.Quantity01 + a.Quantity28 ?? 0; stock.Quantity29 = stock.Quantity01 + a.Quantity29 ?? 0; stock.Quantity30 = stock.Quantity01 + a.Quantity30 ?? 0; db.SaveChanges(); } else { var model = new StockInventory(); model.Quantity01 = a.Quantity01 ?? 0; model.Quantity02 = a.Quantity02 ?? 0; model.Quantity03 = a.Quantity03 ?? 0; model.Quantity04 = a.Quantity04 ?? 0; model.Quantity05 = a.Quantity05 ?? 0; model.Quantity06 = a.Quantity06 ?? 0; model.Quantity07 = a.Quantity07 ?? 0; model.Quantity08 = a.Quantity08 ?? 0; model.Quantity09 = a.Quantity09 ?? 0; model.Quantity10 = a.Quantity10 ?? 0; model.Quantity11 = a.Quantity11 ?? 0; model.Quantity12 = a.Quantity12 ?? 0; model.Quantity13 = a.Quantity13 ?? 0; model.Quantity14 = a.Quantity14 ?? 0; model.Quantity15 = a.Quantity15 ?? 0; model.Quantity16 = a.Quantity16 ?? 0; model.Quantity17 = a.Quantity17 ?? 0; model.Quantity18 = a.Quantity18 ?? 0; model.Quantity19 = a.Quantity19 ?? 0; model.Quantity20 = a.Quantity20 ?? 0; model.Quantity21 = a.Quantity21 ?? 0; model.Quantity22 = a.Quantity22 ?? 0; model.Quantity23 = a.Quantity23 ?? 0; model.Quantity24 = a.Quantity24 ?? 0; model.Quantity25 = a.Quantity25 ?? 0; model.Quantity26 = a.Quantity26 ?? 0; model.Quantity27 = a.Quantity27 ?? 0; model.Quantity28 = a.Quantity28 ?? 0; model.Quantity29 = a.Quantity29 ?? 0; model.Quantity30 = a.Quantity30 ?? 0; model.IsActive = true; model.ProductID = a.ProductId; model.LogId = 2; model.ColorID = 1; model.BracketNumber = 1; db.StockInventories.Add(model); } } } receipt.TotalQuantity = TotalQuantity; receipt.TotalCost = TotalCost; receipt.IsActive = true; db.SaveChanges(); return(Ok(true)); }
public IHttpActionResult EditReceiveOrder1(int Id, ReceiveOrder receiveOrder) { var receipt = db.ReceiveOrders.Where(x => x.IsActive == true && x.Id == Id).Include(x => x.ReceiptOrderItems).FirstOrDefault(); receipt.SupplierInvoice = receiveOrder.SupplierInvoice; receipt.IsActive = true; int? TotalQuantity = 0; decimal?TotalCost = 0; foreach (var a in receiveOrder.ReceiptOrderItems) { if (a.ProductId != null) { var receiptUpdate = receipt.ReceiptOrderItems.Where(x => x.IsActive == true && x.ProductId == a.ProductId && x.Id == a.Id).FirstOrDefault(); receiptUpdate.Quantity01 = a.Quantity01; receiptUpdate.Quantity02 = a.Quantity02; receiptUpdate.Quantity03 = a.Quantity03; receiptUpdate.Quantity04 = a.Quantity04; receiptUpdate.Quantity05 = a.Quantity05; receiptUpdate.Quantity06 = a.Quantity06; receiptUpdate.Quantity07 = a.Quantity07; receiptUpdate.Quantity08 = a.Quantity08; receiptUpdate.Quantity09 = a.Quantity09; receiptUpdate.Quantity10 = a.Quantity10; receiptUpdate.Quantity11 = a.Quantity11; receiptUpdate.Quantity12 = a.Quantity12; receiptUpdate.Quantity13 = a.Quantity13; receiptUpdate.Quantity14 = a.Quantity14; receiptUpdate.Quantity15 = a.Quantity15; receiptUpdate.Quantity16 = a.Quantity16; receiptUpdate.Quantity17 = a.Quantity17; receiptUpdate.Quantity18 = a.Quantity18; receiptUpdate.Quantity19 = a.Quantity19; receiptUpdate.Quantity20 = a.Quantity20; receiptUpdate.Quantity21 = a.Quantity21; receiptUpdate.Quantity22 = a.Quantity22; receiptUpdate.Quantity23 = a.Quantity23; receiptUpdate.Quantity24 = a.Quantity24; receiptUpdate.Quantity25 = a.Quantity25; receiptUpdate.Quantity26 = a.Quantity26; receiptUpdate.Quantity27 = a.Quantity27; receiptUpdate.Quantity28 = a.Quantity28; receiptUpdate.Quantity29 = a.Quantity29; receiptUpdate.Quantity30 = a.Quantity30; TotalQuantity += a.Quantity01 + a.Quantity02 + a.Quantity03 + a.Quantity04 + a.Quantity05 + a.Quantity06 + a.Quantity07 + a.Quantity08 + a.Quantity09 + a.Quantity10 + a.Quantity11 + a.Quantity12 + a.Quantity13 + a.Quantity14 + a.Quantity15 + a.Quantity16 + a.Quantity17 + a.Quantity18 + a.Quantity19 + a.Quantity20 + a.Quantity21 + a.Quantity22 + a.Quantity23 + a.Quantity24 + a.Quantity25 + a.Quantity26 + a.Quantity27 + a.Quantity28 + a.Quantity29 + a.Quantity30; a.SalesCost = (a.Quantity01 ?? 0) * (a.Cost01 ?? 0) + (a.Quantity02 ?? 0) * (a.Cost02 ?? 0) + (a.Quantity03 ?? 0) * (a.Cost03 ?? 0) + (a.Quantity04 ?? 0) * (a.Cost04 ?? 0) + (a.Quantity05 ?? 0) * (a.Cost05 ?? 0) + (a.Quantity06 ?? 0) * (a.Cost06 ?? 0) + (a.Quantity07 ?? 0) * (a.Cost07 ?? 0) + (a.Quantity08 ?? 0) * (a.Cost08 ?? 0) + (a.Quantity09 ?? 0) * (a.Cost09 ?? 0) + (a.Quantity10 ?? 0) * (a.Cost10 ?? 0) + (a.Quantity11 ?? 0) * (a.Cost11 ?? 0) + (a.Quantity12 ?? 0) * (a.Cost12 ?? 0) + (a.Quantity13 ?? 0) * (a.Cost13 ?? 0) + (a.Quantity14 ?? 0) * (a.Cost15 ?? 0) + (a.Quantity16 ?? 0) * (a.Cost16 ?? 0) + (a.Quantity17 ?? 0) * (a.Cost17 ?? 0) + (a.Quantity18 ?? 0) * (a.Cost18 ?? 0) + (a.Quantity19 ?? 0) * (a.Cost19 ?? 0) + (a.Quantity20 ?? 0) * (a.Cost20 ?? 0) + (a.Quantity21 ?? 0) * (a.Cost21 ?? 0) + (a.Quantity22 ?? 0) * (a.Cost22 ?? 0) + (a.Quantity23 ?? 0) * (a.Cost23 ?? 0) + (a.Quantity24 ?? 0) * (a.Cost24 ?? 0) + (a.Quantity25 ?? 0) * (a.Cost25 ?? 0) + (a.Quantity26 ?? 0) * (a.Cost26 ?? 0) + (a.Quantity27 ?? 0) * (a.Cost27 ?? 0) + (a.Quantity28 ?? 0) * (a.Cost28 ?? 0) + (a.Quantity29 ?? 0) * (a.Cost29 ?? 0) + (a.Quantity30 ?? 0) * (a.Cost30 ?? 0); receiptUpdate.SalesCost = a.SalesCost; TotalCost += a.SalesCost; a.IsActive = true; db.SaveChanges(); } } receipt.TotalQuantity = TotalQuantity; receipt.TotalCost = TotalCost; receipt.IsActive = true; var receiptOrderItemList = receiveOrder.ReceiptOrderItems; foreach (var item in receiptOrderItemList) { if (item.ProductId != null) { var stock = db.StockInventories.Where(x => x.IsActive == true && x.ProductID == item.ProductId).FirstOrDefault(); if (stock != null) { stock.Quantity01 = item.Quantity01 ?? 0; stock.Quantity02 = item.Quantity02 ?? 0; stock.Quantity03 = item.Quantity03 ?? 0; stock.Quantity04 = item.Quantity04 ?? 0; stock.Quantity05 = item.Quantity05 ?? 0; stock.Quantity06 = item.Quantity06 ?? 0; stock.Quantity07 = item.Quantity07 ?? 0; stock.Quantity08 = item.Quantity08 ?? 0; stock.Quantity09 = item.Quantity09 ?? 0; stock.Quantity10 = item.Quantity10 ?? 0; stock.Quantity11 = item.Quantity11 ?? 0; stock.Quantity12 = item.Quantity12 ?? 0; stock.Quantity13 = item.Quantity13 ?? 0; stock.Quantity14 = item.Quantity14 ?? 0; stock.Quantity15 = item.Quantity15 ?? 0; stock.Quantity16 = item.Quantity16 ?? 0; stock.Quantity17 = item.Quantity17 ?? 0; stock.Quantity18 = item.Quantity18 ?? 0; stock.Quantity19 = item.Quantity19 ?? 0; stock.Quantity20 = item.Quantity20 ?? 0; stock.Quantity21 = item.Quantity21 ?? 0; stock.Quantity22 = item.Quantity22 ?? 0; stock.Quantity23 = item.Quantity23 ?? 0; stock.Quantity24 = item.Quantity24 ?? 0; stock.Quantity25 = item.Quantity25 ?? 0; stock.Quantity26 = item.Quantity26 ?? 0; stock.Quantity27 = item.Quantity27 ?? 0; stock.Quantity28 = item.Quantity28 ?? 0; stock.Quantity29 = item.Quantity29 ?? 0; stock.Quantity30 = item.Quantity30 ?? 0; db.SaveChanges(); } else { var model = new StockInventory(); model.Quantity01 = item.Quantity01 ?? 0; model.Quantity02 = item.Quantity02 ?? 0; model.Quantity03 = item.Quantity03 ?? 0; model.Quantity04 = item.Quantity04 ?? 0; model.Quantity05 = item.Quantity05 ?? 0; model.Quantity06 = item.Quantity06 ?? 0; model.Quantity07 = item.Quantity07 ?? 0; model.Quantity08 = item.Quantity08 ?? 0; model.Quantity09 = item.Quantity09 ?? 0; model.Quantity10 = item.Quantity10 ?? 0; model.Quantity11 = item.Quantity11 ?? 0; model.Quantity12 = item.Quantity12 ?? 0; model.Quantity13 = item.Quantity13 ?? 0; model.Quantity14 = item.Quantity14 ?? 0; model.Quantity15 = item.Quantity15 ?? 0; model.Quantity16 = item.Quantity16 ?? 0; model.Quantity17 = item.Quantity17 ?? 0; model.Quantity18 = item.Quantity18 ?? 0; model.Quantity19 = item.Quantity19 ?? 0; model.Quantity20 = item.Quantity20 ?? 0; model.Quantity21 = item.Quantity21 ?? 0; model.Quantity22 = item.Quantity22 ?? 0; model.Quantity23 = item.Quantity23 ?? 0; model.Quantity24 = item.Quantity24 ?? 0; model.Quantity25 = item.Quantity25 ?? 0; model.Quantity26 = item.Quantity26 ?? 0; model.Quantity27 = item.Quantity27 ?? 0; model.Quantity28 = item.Quantity28 ?? 0; model.Quantity29 = item.Quantity29 ?? 0; model.Quantity30 = item.Quantity30 ?? 0; model.IsActive = true; model.ProductID = item.ProductId; model.LogId = 2; model.ColorID = 1; model.BracketNumber = 1; db.StockInventories.Add(model); db.SaveChanges(); } } } return(Ok(true)); }
public bool SaveReceiveOrder(ReceiveOrder objReceiveOrder, List <ReceiveOrderLine> receiveorderlines, ArrayList PrevRecvQty, ArrayList OrderQty, string supplyorder, int num, ref string msg) { return(DataAccessManager.SaveReceiveOrder(objReceiveOrder, receiveorderlines, PrevRecvQty, OrderQty, supplyorder, num, ref msg)); }
/// <summary> /// Adds a new ReceiveOrderDetails /// </summary> /// <param name="receivingOrder"></param> public void ReceiveOrder(int orderId, List <ReceivingItems> receivingOrder) { using (var context = new ToolsContext()) { bool orderCanBeClosed = true; // Creates a new Receive Order ReceiveOrder receiveOrder = new ReceiveOrder() { PurchaseOrderID = orderId, ReceiveDate = DateTime.Now }; context.ReceiveOrders.Add(receiveOrder); // Loops through each item to add a ReceiveOrderDetails and/or ReturnedOrderDetails foreach (var item in receivingOrder) { // Gets StockItemID and PurchaseOrderDetailID int stockItemId = item.StockItemID; int purchaseOrderDetailID = (from purchaseOrderDetail in context.PurchaseOrderDetails where purchaseOrderDetail.PurchaseOrderID == orderId && purchaseOrderDetail.StockItemID == stockItemId select purchaseOrderDetail.PurchaseOrderDetailID).SingleOrDefault(); if (item.QuantityReceived > 0) { // Creates a new ReceiveOrderDetails ReceiveOrderDetail newReceiveOrderDetails = new ReceiveOrderDetail(); newReceiveOrderDetails.PurchaseOrderDetailID = purchaseOrderDetailID; newReceiveOrderDetails.QuantityReceived += item.QuantityReceived; newReceiveOrderDetails.ReceiveOrder = receiveOrder; context.ReceiveOrderDetails.Add(newReceiveOrderDetails); // Updates Stock Item information (Quantity on Hand and Quantity on Order) StockItem stockItem = context.StockItems.Attach(context.StockItems.Find(stockItemId)); stockItem.QuantityOnHand = stockItem.QuantityOnHand + item.QuantityReceived; stockItem.QuantityOnOrder = stockItem.QuantityOnOrder - item.QuantityReceived; var dbItem = context.Entry(stockItem); dbItem.State = EntityState.Modified; } if (item.QuantityReturned > 0) { // Creates a new ReturnedOrderDetails ReturnedOrderDetail returnedOrderDetails = new ReturnedOrderDetail(); returnedOrderDetails.PurchaseOrderDetailID = purchaseOrderDetailID; returnedOrderDetails.ItemDescription = item.StockItemDescription; returnedOrderDetails.Quantity += item.QuantityReturned; returnedOrderDetails.Reason = item.ReturnReason; returnedOrderDetails.ReceiveOrder = receiveOrder; context.ReturnedOrderDetails.Add(returnedOrderDetails); } // Checks if outstanding quantity is zero so the order can be closed int outstandingQuantity = item.QuantityOutstanding - item.QuantityReceived; if (outstandingQuantity > 0) { orderCanBeClosed = false; } } // Checks if the order can be closed if (orderCanBeClosed) { PurchaseOrder purchaseOrder = context.PurchaseOrders.Attach(context.PurchaseOrders.Find(orderId)); purchaseOrder.Closed = true; var dbItem = context.Entry(purchaseOrder); dbItem.State = EntityState.Modified; } context.SaveChanges(); } }
public HelpDialog(ReceiveOrder receiveOrder, int minister) { this.receiveOrder = receiveOrder; this.minister = minister; InitializeComponent(); }
public void Add_ReceivedOrders(List <NewReceiveOrderPOCO> receiveNewOrders) { using (var context = new eBikeContext()) { int id = 0; //this int will hold future PK for update; ReceiveOrder receivedOrdersData = new ReceiveOrder(); ReceiveOrderDetail receivedOrdersDetailsData = null; ReturnedOrderDetail returnOrdersDetailsData = null; receivedOrdersData.PurchaseOrderID = receiveNewOrders[0].PurchaseOrderID; receivedOrdersData.ReceiveDate = DateTime.Now; receivedOrdersData = context.ReceiveOrders.Add(receivedOrdersData); id = receivedOrdersData.ReceiveOrderDetails.Count() + 1; foreach (NewReceiveOrderPOCO item in receiveNewOrders) { if (item.QuantityReceived != 0) { //Part table if (item.QuantityReceived <= item.Outstanding) { receivedOrdersDetailsData = new ReceiveOrderDetail(); receivedOrdersDetailsData.PurchaseOrderDetailID = item.PurchaseOrderDetailID; receivedOrdersDetailsData.ReceiveOrderID = id; receivedOrdersDetailsData.QuantityReceived = item.QuantityReceived; receivedOrdersData.ReceiveOrderDetails.Add(receivedOrdersDetailsData); var checkPartExists = (from p in context.Parts where p.PartID == item.PartID select p).SingleOrDefault(); if (checkPartExists != null) { if (checkPartExists.QuantityOnOrder >= item.Outstanding) { checkPartExists.QuantityOnHand += item.QuantityReceived; checkPartExists.QuantityOnOrder -= item.QuantityReceived; } else { throw new Exception("The quantity on order is less than outstanding quantity."); } } else { throw new Exception("Sorry there is no such part number in database."); } } else { throw new Exception("The received quantity can't be more than outstanding."); } } //ReturnOrderDetails Table if (!string.IsNullOrEmpty(item.QuantityReturned.ToString()) && !string.IsNullOrEmpty(item.Notes)) { returnOrdersDetailsData = new ReturnedOrderDetail(); returnOrdersDetailsData.ReceiveOrderID = id; returnOrdersDetailsData.PurchaseOrderDetailID = item.PurchaseOrderDetailID; returnOrdersDetailsData.ItemDescription = item.PartDescription; returnOrdersDetailsData.Quantity = item.QuantityReturned; returnOrdersDetailsData.Reason = item.Notes; returnOrdersDetailsData.VendorPartNumber = item.PartID.ToString(); receivedOrdersData.ReturnedOrderDetails.Add(returnOrdersDetailsData); } } int outstanding = receiveNewOrders.Sum(item => item.Outstanding); int received = receiveNewOrders.Sum(item => item.QuantityReceived); if ((outstanding - received) == 0) { PurchaseOrder poData = context.PurchaseOrders.Find(receiveNewOrders[0].PurchaseOrderID); if (poData != null) { poData.Closed = true; } } context.SaveChanges(); } }