/// <summary> /// 提交出库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDelivery_Click(object sender, EventArgs e) { bool isAudit = false; bool isInventLess = false; bool isDelivery = false; string errMessage = ""; List <int> deliveryIDs = this.Master.GetSelectedIds(this.grdvSaleDelivery); if (deliveryIDs.Count <= 0) { base.ShowMessage("你没有选择任何记录"); return; } else { //判断是否已经全部审核 foreach (int ID in deliveryIDs) { var saleDelivery = base.XMSaleDeliveryService.GetXMSaleDeliveryById(ID); if (saleDelivery != null) { bool deliveryIsAudit = saleDelivery.IsAudit == null ? false : saleDelivery.IsAudit.Value; if (!deliveryIsAudit) { isAudit = true; errMessage = errMessage + saleDelivery.Ref + ";"; } if (saleDelivery.BillStatus == 1000) //出库单已出库 { isDelivery = true; errMessage = errMessage + saleDelivery.Ref + ";"; } } } if (isAudit) { base.ShowMessage("出库单号为:" + errMessage + "未通过审核,无法出库!"); this.BindGrid(this.Master.PageIndex, this.Master.PageSize); return; } if (isDelivery) { base.ShowMessage("出库单号为:" + errMessage + "已出库,出库失败!"); this.BindGrid(this.Master.PageIndex, this.Master.PageSize); return; } #region 判断商品库存是否充足 List <SaleDeliveryProduct> List = new List <SaleDeliveryProduct>(); //统计选中所有商品 foreach (int ID in deliveryIDs) { var saleDelivery = base.XMSaleDeliveryService.GetXMSaleDeliveryById(ID); if (saleDelivery != null) { var saleDeliveryDetail = base.XMSaleDeliveryProductDetailsService.GetXMSaleDeliveryProductDetailsBySaleDeliveryID(saleDelivery.Id); if (saleDeliveryDetail != null && saleDeliveryDetail.Count > 0) { foreach (XMSaleDeliveryProductDetails parm in saleDeliveryDetail) { SaleDeliveryProduct list = new SaleDeliveryProduct(); list.pcode = parm.PlatformMerchantCode; list.saleDeliveryCount = parm.SaleCount.Value; list.wareHoueseID = saleDelivery.WareHouseId; List.Add(list); } } } } if (List != null && List.Count > 0) { var List2 = from l in List group l by new { l.pcode, l.wareHoueseID } into g select new { pcode = g.Key.pcode, wareHoueseID = g.Key.wareHoueseID, saleDeliveryCount = g.Sum(a => a.saleDeliveryCount) }; if (List2 != null && List2.Count() > 0) { foreach (var parm in List2) { var inventInfo = base.XMInventoryInfoService.GetXMInventoryInfoByParm(parm.pcode, parm.wareHoueseID); if (inventInfo == null) { isInventLess = true; //库存不足 errMessage = errMessage + parm.pcode + ";"; break; } else { if (inventInfo.StockNumber == null) { isInventLess = true; //库存不足 errMessage = errMessage + parm.pcode + ";"; break; } else { if (inventInfo.StockNumber == 0 || inventInfo.StockNumber < 0 || (inventInfo.StockNumber > 0 && inventInfo.StockNumber < parm.saleDeliveryCount)) { isInventLess = true; //库存不足 errMessage = errMessage + parm.pcode + ";"; break; } } } } } } #endregion } if (isInventLess) { base.ShowMessage("商品编码为:" + errMessage + "库存不足,无法出库!"); this.BindGrid(this.Master.PageIndex, this.Master.PageSize); return; } if (deliveryIDs.Count <= 0) { base.ShowMessage("你没有选择任何记录"); return; } else { //提交出库 foreach (int ID in deliveryIDs) { using (TransactionScope scope = new TransactionScope()) { var deliveryInfo = base.XMSaleDeliveryService.GetXMSaleDeliveryById(ID); if (deliveryInfo != null && deliveryInfo.BillStatus == 0) { deliveryInfo.BillStatus = 1000; //状态更新为已出库 deliveryInfo.UpdateDate = DateTime.Now; deliveryInfo.UpdateID = HozestERPContext.Current.User.CustomerID; base.XMSaleDeliveryService.UpdateXMSaleDelivery(deliveryInfo); //更新产品库存表(减掉出库数量) var deliveryProductDetails = base.XMSaleDeliveryProductDetailsService.GetXMSaleDeliveryProductDetailsBySaleDeliveryID(deliveryInfo.Id); if (deliveryProductDetails != null && deliveryProductDetails.Count > 0) { foreach (XMSaleDeliveryProductDetails parm in deliveryProductDetails) { string code = parm.PlatformMerchantCode; //商品编码 int wfID = deliveryInfo.WareHouseId; //出库仓库ID var InventoryInfo = base.XMInventoryInfoService.GetXMInventoryInfoByParm(code, wfID); if (InventoryInfo != null) //商品编码为code的产品在库存表中已经存在 更新库存数量 { InventoryInfo.StockNumber = InventoryInfo.StockNumber - parm.SaleCount; //库存减掉出库量 InventoryInfo.CanOrderCount = InventoryInfo.StockNumber; InventoryInfo.UpdateDate = DateTime.Now; InventoryInfo.UpdateID = HozestERPContext.Current.User.CustomerID; base.XMInventoryInfoService.UpdateXMInventoryInfo(InventoryInfo); // UpdateSaleDeliveryBarCodes(InventoryInfo.Id, parm.Id); } //更新库存总账主表数据 从表添加一条记录 UpdateInventoryLederInfo(deliveryInfo.WareHouseId, parm); //删除库存商品条形码 //UpdateInventoryBarCodeInfo(InventoryInfo.Id, parm.Id); } } } scope.Complete(); } } this.BindGrid(this.Master.PageIndex, this.Master.PageSize); base.ShowMessage("提交出库成功!"); } }
/// <summary> /// 退货提交出库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnRejectedDelivery_Click(object sender, EventArgs e) { bool isAudit = false; bool isInventLess = false; string errMessage = ""; List <int> rejectedIDs = this.Master.GetSelectedIds(this.grdvRejected); if (rejectedIDs.Count <= 0) { base.ShowMessage("你没有选择任何记录"); return; } else { List <SaleDeliveryProduct> List = new List <SaleDeliveryProduct>(); foreach (int ID in rejectedIDs) { int warehousesID = 1; var storageRejected = base.XMPurchaseRejectedService.GetXMPurchaseRejectedById(ID); if (storageRejected != null) { var storages = base.XMStorageService.GetXMStorageById(storageRejected.MId); if (storages != null) { warehousesID = storages.WareHouseId; } var rejectedProductDetails = base.XMPurchaseRejectedProductDetailsService.GetXMPurchaseRejectedProductDetailsByRejectedID(storageRejected.Id); if (rejectedProductDetails != null && rejectedProductDetails.Count > 0) { foreach (XMPurchaseRejectedProductDetails Info in rejectedProductDetails) { SaleDeliveryProduct list = new SaleDeliveryProduct(); list.pcode = Info.PlatformMerchantCode; list.saleDeliveryCount = Info.RejectionCount; list.wareHoueseID = warehousesID; list.InventoryInfoID = int.Parse(Info.InventoryInfoID.ToString()); List.Add(list); } } bool RejectedIsAudit = storageRejected.IsAudit == null ? false : storageRejected.IsAudit.Value; if (!RejectedIsAudit) { isAudit = true; errMessage = errMessage + storageRejected.Ref + ";"; break; } } } if (List != null && List.Count > 0) { var List2 = from l in List group l by new { l.pcode, l.wareHoueseID, l.InventoryInfoID } into g select new { pcode = g.Key.pcode, wareHoueseID = g.Key.wareHoueseID, saleDeliveryCount = g.Sum(a => a.saleDeliveryCount), InventoryInfoID = g.Key.InventoryInfoID }; if (List2 != null && List2.Count() > 0) { foreach (var parm in List2) { var inventInfo = base.XMInventoryInfoService.GetXMInventoryInfoById(parm.InventoryInfoID); if (inventInfo == null) { isInventLess = true; //库存不足 errMessage = errMessage + parm.pcode + ";"; break; } else { if (inventInfo.StockNumber == null) { isInventLess = true; //库存不足 errMessage = errMessage + parm.pcode + ";"; break; } else { if (inventInfo.StockNumber == 0 || inventInfo.StockNumber < 0 || (inventInfo.StockNumber > 0 && inventInfo.StockNumber < parm.saleDeliveryCount)) { isInventLess = true; //库存不足 errMessage = errMessage + parm.pcode + ";"; break; } } } } } } } if (isAudit) { base.ShowMessage("已入库退货单号为:" + errMessage + "未通过审核,无法出库!"); this.BindGrid(this.Master.PageIndex, this.Master.PageSize); return; } if (isInventLess) { base.ShowMessage("已入库退货单号为:" + errMessage + "库存不足,无法出库!"); this.BindGrid(this.Master.PageIndex, this.Master.PageSize); return; } if (rejectedIDs.Count <= 0) { base.ShowMessage("你没有选择任何记录"); return; } else { //提交出库 foreach (int ID in rejectedIDs) { using (TransactionScope scope = new TransactionScope()) { int warehousesID = 1; var rejectedInfo = base.XMPurchaseRejectedService.GetXMPurchaseRejectedById(ID); if (rejectedInfo != null && rejectedInfo.BillStatus == 0) { rejectedInfo.BillStatus = 1000; //状态更新为已出库 rejectedInfo.UpdateDate = DateTime.Now; rejectedInfo.UpdateID = HozestERPContext.Current.User.CustomerID; base.XMPurchaseRejectedService.UpdateXMPurchaseRejected(rejectedInfo); //更新产品库存表(减掉出库数量) var storageInfo = base.XMStorageService.GetXMStorageById(rejectedInfo.MId); if (storageInfo != null) { warehousesID = storageInfo.WareHouseId; //入库仓库ID } var rejectedProductDetails = base.XMPurchaseRejectedProductDetailsService.GetXMPurchaseRejectedProductDetailsByRejectedID(rejectedInfo.Id); if (rejectedProductDetails != null && rejectedProductDetails.Count > 0) { foreach (XMPurchaseRejectedProductDetails parm in rejectedProductDetails) { string code = parm.PlatformMerchantCode; //商品编码 var InventoryInfo = base.XMInventoryInfoService.GetXMInventoryInfoById(int.Parse(parm.InventoryInfoID.ToString())); if (InventoryInfo != null) //商品编码为code的产品在库存表中已经存在 更新库存数量 { InventoryInfo.StockNumber = InventoryInfo.StockNumber - parm.RejectionCount; //库存减掉出库量 InventoryInfo.CanOrderCount = InventoryInfo.StockNumber; InventoryInfo.UpdateDate = DateTime.Now; InventoryInfo.UpdateID = HozestERPContext.Current.User.CustomerID; base.XMInventoryInfoService.UpdateXMInventoryInfo(InventoryInfo); } //更新库存总账主表数据 从表添加一条记录 UpdateInventoryLederInfo(warehousesID, parm); } } } scope.Complete(); } } this.BindGrid(this.Master.PageIndex, this.Master.PageSize); base.ShowMessage("提交出库成功!"); } }
/// <summary> /// 发货单赠品热敏打印 /// </summary> public void DeliveryDirectThermalPrint(List <int> IDs, string ExpressId) { string paramSign = ""; //项目名称 string paramWantId = ""; //网名 string paramMobile = ""; //接收手机 string paramLogisticsName = ""; //快递名称 string paramLogisticsNumber = ""; //物流单号 string paramContent = ""; //包裹内容 int paramMDeliveryDype = 0; string printer = ""; string cp_code = ""; string emsCustomerCode = ""; this.documentIDs.Value = ""; StringBuilder t = new StringBuilder(); List <HozestERP.BusinessLogic.ManageProject.XMDelivery> list = new List <HozestERP.BusinessLogic.ManageProject.XMDelivery>(); if (ExpressId == "1")//中国邮政 { cp_code = "POSTB"; printer = "Xprinter XP-DT108A LABEL"; emsCustomerCode = "客户代码..90000009451762"; } else if (ExpressId == "470")//申通快递 { cp_code = "STO"; printer = "QR-586 LABEL"; } else if (ExpressId == "505")//顺丰速运 { cp_code = "SF"; printer = "HPRT HLP106S"; } else if (ExpressId == "500")//中通快递 { cp_code = "ZTO"; printer = "KM-106 Printer"; } var deliverylist = base.XMDeliveryService.GetXMDeliveryByListIds(IDs); foreach (var delivery in deliverylist) //foreach (int ID in IDs) { //var delivery = base.XMDeliveryService.GetXMDeliveryById(ID); if (delivery != null) { if (delivery.PrintQuantity > 0 && delivery.LogisticsId.ToString() != ExpressId) { base.ShowMessage("发货单号:" + delivery.DeliveryNumber + ",的快递单已用其他快递公司打印,请先取消该物流单号!"); return; } if (string.IsNullOrEmpty(delivery.Mobile) || string.IsNullOrEmpty(delivery.DeliveryAddress)) { base.ShowMessage("发货单号:" + delivery.DeliveryNumber + ",的发货单的手机号或地址为空!"); return; } list.Add(delivery); } } string Template = base.XMOrderInfoAPIService.GetisvTemplates("1", cp_code);//获取商家的模板自定义区 if (Template == "" || Template.IndexOf("http:") == -1) { base.ShowMessage("获取申通电子面单模板失败!"); return; } t.Append("{\"cmd\": \"print\",\"requetid\": \"" + DateTime.Now.ToString("yyMMddHHmmddfff") + "\",\"verson\": \"1.0\","); t.Append("\"task\": {\"taskID\": \"\",\"preview\": false,\"printer\": \"" + printer + "\",\"documents\":[");//preview:是否预览 //打印批次 int PrintBatch = 1; //取发货单表中 打印批次倒序最后条 var xMDeliveryListByPrintBatch = base.XMDeliveryService.GetFirstXMDelivery(); if (xMDeliveryListByPrintBatch != null) { if (xMDeliveryListByPrintBatch.PrintBatch != null) { PrintBatch = xMDeliveryListByPrintBatch.PrintBatch.Value + 1; } } var XMOrderInfoAppList = base.XMOrderInfoAppService.GetXMOrderInfoAppByID(10);//天猫城市爱情旗舰店 ITopClient client = new DefaultTopClient(XMOrderInfoAppList.ServerUrl, XMOrderInfoAppList.AppKey, XMOrderInfoAppList.AppSecret); #region 先判断库存 var isInventList = new List <HozestERP.BusinessLogic.ManageProject.XMDelivery>(); foreach (HozestERP.BusinessLogic.ManageProject.XMDelivery Info in list) { bool isInventLess = false; string errMessage = ""; //根据发货单ID 查询进销存系统销售出库单记录 更新出库状态 更新库存信息 List <SaleDeliveryProduct> List = new List <SaleDeliveryProduct>(); var saleDeliveryInfo = base.XMSaleDeliveryService.GetXMSaleDeliveryListByParm(Info.Id); if (saleDeliveryInfo != null && saleDeliveryInfo.Count > 0) { foreach (var info in saleDeliveryInfo) { var saleDelivery = base.XMSaleDeliveryService.GetXMSaleDeliveryById(info.Id); if (saleDelivery != null) { var saleDeliveryDetail = base.XMSaleDeliveryProductDetailsService.GetXMSaleDeliveryProductDetailsBySaleDeliveryID(saleDelivery.Id); if (saleDeliveryDetail != null && saleDeliveryDetail.Count > 0) { foreach (XMSaleDeliveryProductDetails parm in saleDeliveryDetail) { SaleDeliveryProduct list2 = new SaleDeliveryProduct(); list2.pcode = parm.PlatformMerchantCode; list2.saleDeliveryCount = parm.SaleCount.Value; list2.wareHoueseID = saleDelivery.WareHouseId; List.Add(list2); } } } } } if (List != null && List.Count > 0) { var List2 = from l in List group l by new { l.pcode, l.wareHoueseID } into g select new { pcode = g.Key.pcode, wareHoueseID = g.Key.wareHoueseID, saleDeliveryCount = g.Sum(a => a.saleDeliveryCount) }; if (List2 != null && List2.Count() > 0) { foreach (var parm in List2) { var inventInfo = base.XMInventoryInfoService.GetXMInventoryInfoByParm(parm.pcode, parm.wareHoueseID); if (inventInfo == null) { isInventLess = true; //库存不足 errMessage = errMessage + parm.pcode + ";"; break; } else { if (inventInfo.StockNumber == null) { isInventLess = true; //库存不足 errMessage = errMessage + parm.pcode + ";"; break; } else { if (inventInfo.StockNumber == 0 || inventInfo.StockNumber < 0 || (inventInfo.StockNumber > 0 && inventInfo.StockNumber < parm.saleDeliveryCount)) { isInventLess = true; //库存不足 errMessage = errMessage + parm.pcode + ";"; break; } } } } } } if (isInventLess) //库存不足 { base.ShowMessage("出库单号为:" + errMessage + "库存不足,无法出库!"); //return; } else //库存充足 减掉库存 { isInventList.Add(Info); //库存充足的获取运单号 if (saleDeliveryInfo != null && saleDeliveryInfo.Count > 0) { paramContent = ""; //重置包裹内容 foreach (var info in saleDeliveryInfo) { if (info.BillStatus == 0) { info.BillStatus = 1000; info.UpdateDate = DateTime.Now; info.UpdateID = HozestERPContext.Current.User.CustomerID; base.XMSaleDeliveryService.UpdateXMSaleDelivery(info); //更新产品库存表(减掉出库数量) var deliveryProductDetails = base.XMSaleDeliveryProductDetailsService.GetXMSaleDeliveryProductDetailsBySaleDeliveryID(info.Id); if (deliveryProductDetails != null && deliveryProductDetails.Count > 0) { foreach (XMSaleDeliveryProductDetails parm in deliveryProductDetails) { string code = parm.PlatformMerchantCode; //商品编码 int wfID = info.WareHouseId; //出库仓库ID var InventoryInfo = base.XMInventoryInfoService.GetXMInventoryInfoByParm(code, wfID); if (InventoryInfo != null) //商品编码为code的产品在库存表中已经存在 更新库存数量 { InventoryInfo.StockNumber = InventoryInfo.StockNumber - parm.SaleCount; //库存减掉出库量 InventoryInfo.CanOrderCount = InventoryInfo.StockNumber; InventoryInfo.UpdateDate = DateTime.Now; InventoryInfo.UpdateID = HozestERPContext.Current.User.CustomerID; base.XMInventoryInfoService.UpdateXMInventoryInfo(InventoryInfo); paramContent += parm.ProductName + "+"; } //更新库存总账主表数据 从表添加一条记录 UpdateInventoryLederInfo(info.WareHouseId, parm); } } } if ((info.ProjectId == 5 || info.ProjectId == 22) && paramMDeliveryDype == 481) //曲美、伊丽丝项目 { if (paramContent.Length > 0) { paramContent = paramContent.Substring(0, paramContent.Length - 1); } bool SendReturn = this.UseSensSms(paramSign, paramWantId, paramMobile, paramLogisticsName, paramLogisticsNumber, paramContent); if (!SendReturn) { throw new Exception("短信发送失败,物流单号:" + paramLogisticsNumber + ",请联系管理员"); } } } } } } #endregion foreach (HozestERP.BusinessLogic.ManageProject.XMDelivery Info in isInventList) { string str = base.XMOrderInfoAPIService.GetCaiNiaoWaybilInfo(Info, cp_code, XMOrderInfoAppList, client); if (str == "") { base.ShowMessage("发货单号:" + Info.DeliveryNumber + ",的发货单获取物流服务商电子面单号失败!"); return; } else { string OrderCode = Info.OrderCode; string PremiumsInfo = ""; string IsInvoiced = "无"; string waybill_code = str; string remark = Info.OrderRemarks; int a = str.IndexOf("<waybill_code>"); waybill_code = waybill_code.Substring(a, str.Length - a - 1); int b = waybill_code.IndexOf("</waybill_code>"); waybill_code = waybill_code.Substring(0, b).Replace("<waybill_code>", "").Replace("</waybill_code>", ""); string print_data = str; int c = str.IndexOf("<print_data>"); print_data = print_data.Substring(c, str.Length - c - 1); int d = print_data.IndexOf("</print_data>"); print_data = print_data.Substring(0, d).Replace("<print_data>", "").Replace("</print_data>", ""); var OrderInfo = base.XMOrderInfoService.GetXMOrderInfoByOrderCode(OrderCode); //物流单号,物流公司 Info.LogisticsId = int.Parse(ExpressId); Info.LogisticsNumber = waybill_code; //Info.IsDelivery = true; Info.PrintQuantity = Info.PrintQuantity == null ? 1 : Info.PrintQuantity + 1; //打印次数 Info.PrintBatch = PrintBatch; Info.PrintDateTime = DateTime.Now; //打印时间 Info.UpdateId = HozestERPContext.Current.User.CustomerID; Info.UpdateDate = DateTime.Now; if (OrderInfo != null && OrderInfo.IsInvoiced != null && OrderInfo.IsInvoiced == true) { IsInvoiced = "有"; } var XMDeliveryDetailsList = base.XMDeliveryDetailsService.GetXMDeliveryDetailsByDeliveryId(Info.Id); if (XMDeliveryDetailsList != null && XMDeliveryDetailsList.Count > 0) { foreach (var item in XMDeliveryDetailsList) { if (PremiumsInfo == "") { PremiumsInfo = item.PrdouctName + "(" + item.Specifications + ")" + " * " + item.ProductNum; } else { PremiumsInfo += "," + item.PrdouctName + "(" + item.Specifications + ")" + " * " + item.ProductNum; } } } t = GetJsonStr(t, print_data, Template, PremiumsInfo, OrderCode, remark, IsInvoiced, emsCustomerCode, Info); //发送短信参数 paramLogisticsName = Info.ExpressName; paramLogisticsNumber = Info.LogisticsNumber; paramSign = Info.NickName; paramWantId = Info.WantID; paramMobile = Info.Mobile; paramMDeliveryDype = int.Parse(Info.DeliveryTypeId.ToString()); } } t.Append("]}}"); var count = base.XMDeliveryService.UpdateXMDelivery(isInventList); if (count > 0) { Session["DirectThermalPrint-Delivery"] = list; JObject JsonStr = JObject.Parse(t.ToString()); Page.ClientScript.RegisterStartupScript(Page.GetType(), "DeliveryDirectThermalPrint", "<script>doSetPrinterConfig(" + JsonStr + ");</script>"); } }