public void SubtractProductFromBasket(List <PurchaseItemDto> basket, int productId, uint ammount) { PurchaseItemDto purchase = basket.FirstOrDefault(p => p.Id == productId); if (purchase.Quantity <= ammount) { basket.Remove(purchase); return; } purchase.Quantity -= ammount; }
public void ModifyCountOfProductInBasket(List <PurchaseItemDto> basket, int productId, uint newAmmount) { PurchaseItemDto purchase = basket.FirstOrDefault(p => p.Id == productId); if (newAmmount == 0) { basket.Remove(purchase); return; } uint stockAmmount = GetProductStockQuantity(productId); if (newAmmount > stockAmmount) { purchase.Quantity = stockAmmount; return; } purchase.Quantity = newAmmount; }
public JsonResult Edit() { OperationResult res = new OperationResult(OperationResultType.Error, "修改失败"); var quantity = Request["Quantity"]; var id = Request["Id"]; int itemId; PurchaseItem pur; if (id != null && id != "" && quantity != null && quantity != "") { itemId = int.Parse(id); pur = _purchaseItemContract.PurchaseItems.Where(c => c.Id == itemId).FirstOrDefault(); if (pur != null) { pur.Quantity = Convert.ToInt32(quantity); pur.UpdatedTime = DateTime.Now; PurchaseItemDto purdto = AutoMapper.Mapper.Map <PurchaseItemDto>(pur); res = _purchaseItemContract.Update(purdto); } } return(Json(res)); }
public void AddProductToBasket(ICollection <PurchaseItemDto> basket, int productId, uint ammount) { PurchaseItemDto purchase = basket.FirstOrDefault(p => p.Id == productId); if (purchase is null) { var productFound = productsRepository.All().FirstOrDefault(x => x.Id == productId); if (productFound is null || productFound.Quantity == 0) { return; } purchase = mapper.Map <PurchaseItemDto>(productFound); //TO DO add handling of requesting details of non existing product! basket.Add(purchase); } uint maxAmmountPossible = GetProductStockQuantity(productId); if (purchase.Quantity + ammount > maxAmmountPossible) { purchase.Quantity = maxAmmountPossible; return; } purchase.Quantity += ammount; }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["act"] == "edit") { isAdd = false; } else { isAdd = true; } orderId = long.Parse(Request.QueryString["orderId"]); long productId = 0; if (!isAdd) { productId = long.Parse(Request.QueryString["productId"]); } warehosreList = new InventoryLocationBLL().GetLocationListUnResource(); if (!IsPostBack) { if (isAdd) // 新增 { product = null; } else // 编辑 { if (orderId != 0) // 采购订单已保存的采购项也已保存 { product = bll.GetOrderProduct(productId); } else { var items = Session["PurchaseOrderItem"] as PurchaseOrderItemManageDto; int index = items.items.FindIndex(_ => _.id == productId); if (index < 0) { Response.End(); return; } product = new ivt_order_product(); product.warehouse_id = items.items[index].warehouse_id; product.product_id = items.items[index].product_id; product.quantity = items.items[index].quantity; product.unit_cost = items.items[index].unit_cost; } } } else { if (orderId == 0) { var items = Session["PurchaseOrderItem"] as PurchaseOrderItemManageDto; PurchaseItemDto pdt = AssembleModel <PurchaseItemDto>(); pdt.locationName = warehosreList.Find(_ => _.id == pdt.warehouse_id).name; if (!isAdd) { pdt.id = productId; int index = items.items.FindIndex(_ => _.id == productId); if (index >= 0) { items.items.RemoveAt(index); } } else { pdt.id = items.index; items.index++; } items.items.Add(pdt); Session["PurchaseOrderItem"] = items; } else { if (isAdd) { ivt_order_product pdt = AssembleModel <ivt_order_product>(); pdt.order_id = orderId; pdt.was_auto_filled = 0; bll.AddOrderItem(pdt, LoginUserId); } else { ivt_order_product pdt = AssembleModel <ivt_order_product>(); pdt.order_id = orderId; pdt.id = productId; bll.EditOrderItem(pdt, LoginUserId); } } Response.Write("<script>window.close();self.opener.location.reload();</script>"); Response.End(); } }
/// <summary> /// 获取供应商包含指定供应商的采购项 /// </summary> /// <param name="onlyDefault">只有默认供应商</param> /// <param name="vendorId">供应商id</param> /// <returns></returns> public List <PurchaseItemDto> GetDefaultOrderItems(bool onlyDefault, long vendorId) { string sql = $"select * from ivt_product where id in(select product_id from ivt_product_vendor where vendor_account_id={vendorId}"; if (onlyDefault) { sql += " and is_default=1 "; } sql += " and delete_time=0 ) and delete_time=0"; var list = dal.FindListBySql <ivt_product>(sql); if (list == null) { return(new List <PurchaseItemDto>()); } List <PurchaseItemDto> itemList = new List <PurchaseItemDto>(); for (int i = 0; i < list.Count; ++i) { var lctList = dal.FindListBySql($"select id,warehouse_id,product_id,quantity,quantity_minimum,quantity_maximum,(select name from ivt_warehouse where id=warehouse_id) as bin from ivt_warehouse_product where product_id={list[i].id} and delete_time=0"); if (lctList == null || lctList.Count == 0) { continue; } foreach (var lctPdt in lctList) { if (lctPdt.quantity >= lctPdt.quantity_minimum) { continue; } PurchaseItemDto itm = new PurchaseItemDto(); itm.product = list[i].name; itm.product_id = list[i].id; itm.locationName = lctPdt.bin; itm.warehouse_id = (long)lctPdt.warehouse_id; itm.quantity = lctPdt.quantity_maximum - lctPdt.quantity; itm.unit_cost = list[i].unit_cost; itm.was_auto_filled = 1; itemList.Add(itm); } } for (var i = 0; i < itemList.Count; ++i) { long lctPdtId = dal.FindSignleBySql <long>($"select id from ivt_warehouse_product where product_id={itemList[i].product_id} and warehouse_id={itemList[i].warehouse_id}"); var lctPdt = GetIvtProductEdit(lctPdtId); if (lctPdt != null) { itemList[i].ivtQuantity = lctPdt.quantity; itemList[i].onOrder = lctPdt.on_order; itemList[i].max = lctPdt.quantity_maximum; itemList[i].min = lctPdt.quantity_minimum; itemList[i].reserved_picked = lctPdt.reserved_picked; itemList[i].back_order = lctPdt.back_order; if (string.IsNullOrEmpty(lctPdt.reserved_picked)) { itemList[i].avaCnt = ""; } else { itemList[i].avaCnt = (lctPdt.quantity - int.Parse(lctPdt.reserved_picked)).ToString(); } } } return(itemList); }