protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["act"] == "edit") { isAdd = false; } else { isAdd = true; } if (!isAdd) { orderId = long.Parse(Request.QueryString["id"]); } if (!IsPostBack) { Session["PurchaseOrderItem"] = new PurchaseOrderItemManageDto(); var generalBll = new GeneralBLL(); paymentTerms = generalBll.GetDicValues(GeneralTableEnum.PAYMENT_TERM); taxRegion = generalBll.GetDicValues(GeneralTableEnum.TAX_REGION); shipCate = generalBll.GetDicValues(GeneralTableEnum.PAYMENT_SHIP_TYPE); itemDescType = generalBll.GetDicValues(GeneralTableEnum.ITEM_DESC_DISPLAY_TYPE); if (!isAdd) { orderEdit = bll.GetPurchaseOrder(orderId); } // 库存产品列表中创建采购订单 if (isAdd && (!string.IsNullOrEmpty(Request.QueryString["ids"]))) { Session["PurchaseOrderItem"] = new InventoryProductBLL().InitPurchaseOrderItems(Request.QueryString["ids"], out defaultVendorAccountId); } } else { var action = Request.Form["subAct"]; if (action == "Cancle") { Session.Remove("PurchaseOrderItem"); Response.Write("<script>window.close();</script>"); Response.End(); return; } var order = AssembleModel <ivt_order>(); var location = AssembleModel <crm_location>(); var items = Session["PurchaseOrderItem"] as PurchaseOrderItemManageDto; if (!string.IsNullOrEmpty(Request.Form["checkShowTaxCate"]) && Request.Form["checkShowTaxCate"].Equals("on")) { order.display_tax_cate = 1; } if (!string.IsNullOrEmpty(Request.Form["checkTaxSeparate"]) && Request.Form["checkTaxSeparate"].Equals("on")) { order.display_tax_seperate_line = 1; } var shipType = Request.Form["shipAddr"]; if (shipType == "0") { order.ship_to_type_id = (int)DicEnum.INVENTORY_ORDER_SHIP_ADDRESS_TYPE.WORK_ADDRESS; order.purchase_account_id = thisCompanyId; } else if (shipType == "1") { order.ship_to_type_id = (int)DicEnum.INVENTORY_ORDER_SHIP_ADDRESS_TYPE.OTHER_ADDRESS; } else if (shipType == "2") { order.ship_to_type_id = (int)DicEnum.INVENTORY_ORDER_SHIP_ADDRESS_TYPE.SELECTED_COMPANY; } else { Response.End(); return; } if (action == "SaveClose" || action == "SaveSubmit" || action == "SaveNew" || action == "SubmitEmail") { if (action == "SaveSubmit" || action == "SubmitEmail") { // TODO: 提交验证 order.status_id = (int)DicEnum.PURCHASE_ORDER_STATUS.SUBMITTED; order.submitted_resource_id = LoginUserId; order.submit_time = EMT.Tools.Date.DateHelper.ToUniversalTimeStamp(); } else { if (isAdd) { order.status_id = (int)DicEnum.PURCHASE_ORDER_STATUS.NEW; } } if (!isAdd) { order.id = orderId; bll.EditOrder(order, location, LoginUserId); } else { bll.AddOrder(order, items.items, location, LoginUserId); } if (action == "SaveClose") { Response.Write("<script>window.close();self.opener.location.reload();</script>"); Response.End(); } if (action == "SaveNew") { Response.Write("<script>window.location.href='AddPurchaseOrder.aspx?act=add';self.opener.location.reload();</script>"); Response.End(); } if (action == "SaveSubmit" || action == "SubmitEmail") { Response.Write("<script>window.close();self.opener.location.reload();</script>"); Response.End(); } } } }
/// <summary> /// 根据库存产品id列表获取采购订单的采购项信息 /// </summary> /// <param name="pdtIds"></param> /// <returns></returns> public PurchaseOrderItemManageDto InitPurchaseOrderItems(string pdtIds, out long vendorId) { vendorId = 0; PurchaseOrderItemManageDto dto = new PurchaseOrderItemManageDto(); string sql = $"select product_id,warehouse_id,(select name from ivt_product where id=product_id) as product,(select unit_cost from ivt_product where id=product_id) as unit_cost,(select name from ivt_warehouse where id=warehouse_id) as locationName,(quantity_maximum-quantity) as quantity from ivt_warehouse_product where id in({pdtIds})"; dto.items = dal.FindListBySql <PurchaseItemDto>(sql); for (var i = 0; i < dto.items.Count; ++i) { dto.items[i].id = dto.index++; if (dto.items[i].quantity < 0) { dto.items[i].quantity = 0; } } if (dto.items.Count == 0) { sql = $"select id,id as costId,product_id,(select id from ivt_warehouse where is_default=1 and delete_time=0) as warehouse_id,unit_cost,(select name from ivt_product where id=product_id) as product,(select name from ivt_warehouse where is_default=1 and delete_time=0) as locationName from ctt_contract_cost where id in({pdtIds})"; dto.items = dal.FindListBySql <PurchaseItemDto>(sql); if (dto.items.Count == 0) { return(dto); } QueryCommonBLL queryBll = new QueryCommonBLL(); QueryParaDto queryPara = new QueryParaDto(); queryPara.query_params = new List <Para>(); queryPara.query_type_id = (long)QueryType.PurchaseFulfillment; queryPara.para_group_id = 156; queryPara.page = 1; queryPara.page_size = 500; QueryResultDto queryResult = queryBll.GetResult(0, queryPara); if (queryResult.count == 0) { return(dto); } for (var i = 0; i < dto.items.Count; ++i) { var find = queryResult.result.Find(_ => _["成本id"].ToString().Equals(dto.items[i].id.ToString())); if (find == null) { continue; } dto.items[i].quantity = (int)(string.IsNullOrEmpty(find["采购数量"].ToString()) ? 0 : decimal.Parse(find["采购数量"].ToString())); dto.items[i].accountName = find["销售订单"].ToString() + "(" + find["客户"].ToString() + ")"; dto.items[i].contractName = find["工单或项目或合同"].ToString(); dto.items[i].id = dto.index++; } } string productIds = ""; for (var i = 0; i < dto.items.Count; ++i) { productIds += dto.items[i].product_id + ","; long lctPdtId = dal.FindSignleBySql <long>($"select id from ivt_warehouse_product where product_id={dto.items[i].product_id} and warehouse_id={dto.items[i].warehouse_id}"); var lctPdt = GetIvtProductEdit(lctPdtId); if (lctPdt != null) { dto.items[i].ivtQuantity = lctPdt.quantity; dto.items[i].onOrder = lctPdt.on_order; dto.items[i].max = lctPdt.quantity_maximum; dto.items[i].min = lctPdt.quantity_minimum; dto.items[i].reserved_picked = lctPdt.reserved_picked; dto.items[i].back_order = lctPdt.back_order; if (string.IsNullOrEmpty(lctPdt.reserved_picked)) { dto.items[i].avaCnt = ""; } else { dto.items[i].avaCnt = (lctPdt.quantity - int.Parse(lctPdt.reserved_picked)).ToString(); } } } // 获取采购项产品的默认供应商,如果只有一个默认供应商,则返回 if (productIds != "") { productIds = productIds.Substring(0, productIds.Length - 1); var ids = dal.FindListBySql <long>($"select vendor_account_id from ivt_product_vendor where is_default=1 and product_id in({productIds})"); if (ids != null && ids.Count == 1) { vendorId = ids[0]; } } return(dto); }