private void UpdateSaleOrder()//销售付款创建完毕后 如果该客户有应付款记录 开始执行对应操作 { if (ent.Name == "自动销账") { sql = @"select * from SHHG_AimExamine..SaleOrders where InvoiceType='收据' and CId='" + CId + "' and State is null and (PayState is null or PayState='部分付款') order by CreateTime asc"; IList <EasyDictionary> dics = DataHelper.QueryDictList(sql); decimal payamount = ent.Money.Value; ent.CorrespondInvoice = ""; foreach (EasyDictionary dic in dics) { if (payamount > 0) { SaleOrder oiEnt = SaleOrder.Find(dic.Get <string>("Id")); decimal unpayAmount = oiEnt.TotalMoney.Value - (oiEnt.ReceiptAmount.HasValue ? oiEnt.ReceiptAmount.Value : 0) - (oiEnt.DiscountAmount.HasValue ? oiEnt.DiscountAmount.Value : 0) - (oiEnt.ReturnAmount.HasValue ? oiEnt.ReturnAmount.Value : 0); if (payamount >= unpayAmount) { payamount = payamount - unpayAmount; oiEnt.ReceiptAmount = (oiEnt.ReceiptAmount.HasValue ? oiEnt.ReceiptAmount.Value : 0) + unpayAmount; oiEnt.PayState = "已全部付款"; ent.CorrespondInvoice += oiEnt.Number + "_" + unpayAmount + ","; } else { oiEnt.ReceiptAmount = (oiEnt.ReceiptAmount.HasValue ? oiEnt.ReceiptAmount.Value : 0) + payamount; ent.CorrespondInvoice += oiEnt.Number + "_" + payamount + ","; payamount = 0; } oiEnt.DoUpdate(); } } ent.CorrespondState = "已对应"; ent.DoUpdate(); } if (ent.Name == "手动销账") { string[] SaleOrderArray = ent.CorrespondInvoice.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); ent.CorrespondInvoice = ""; foreach (string str in SaleOrderArray) { SaleOrder oiEnt = SaleOrder.FindAllByProperty(SaleOrder.Prop_Number, str).FirstOrDefault <SaleOrder>(); decimal unpayAmount = oiEnt.TotalMoney.Value - (oiEnt.ReceiptAmount.HasValue ? oiEnt.ReceiptAmount.Value : 0) - (oiEnt.DiscountAmount.HasValue ? oiEnt.DiscountAmount.Value : 0) - (oiEnt.ReturnAmount.HasValue ? oiEnt.ReturnAmount.Value : 0); ent.CorrespondInvoice += oiEnt.Number + "_" + unpayAmount + ","; oiEnt.ReceiptAmount = (oiEnt.ReceiptAmount.HasValue ? oiEnt.ReceiptAmount.Value : 0) + unpayAmount; oiEnt.PayState = "已全部付款"; oiEnt.DoUpdate(); } ent.CorrespondState = "已对应"; ent.DoUpdate(); } if (ent.Name == "暂不销账") { ent.CorrespondInvoice = ""; ent.DoUpdate(); } }
protected void Page_Load(object sender, EventArgs e) { op = RequestData.Get <string>("op"); id = RequestData.Get <string>("id"); if (!string.IsNullOrEmpty(id)) { ent = ReturnOrder.Find(id); } switch (RequestActionString) { case "update": ent = GetMergedData <ReturnOrder>(); ent.DoUpdate(); break; case "create": ent = this.GetPostedData <ReturnOrder>(); ent.Number = DataHelper.QueryValue("select SHHG_AimExamine.dbo.fun_getReturnOrderNumber()") + ""; //自动生成流水号 ent.State = "已生成"; ent.DoCreate(); soent = SaleOrder.FindAllByProperty("Number", ent.OrderNumber).FirstOrDefault <SaleOrder>(); soent.ReturnAmount = (soent.ReturnAmount.HasValue ? soent.ReturnAmount.Value : 0) + ent.ReturnMoney; soent.DoUpdate(); //将退货金额反写到销售单 if (soent.InvoiceState == "已全部开发票") { ent.IsDiscount = "T"; ent.DoUpdate(); } InWarehouse inwh = new InWarehouse { PublicInterface = ent.Id, //退货单Id InWarehouseNo = DataHelper.QueryValue("select SHHG_AimExamine.dbo.fun_getInWarehouseNo()").ToString(), InWarehouseType = "退货入库", WarehouseId = ent.WarehouseId, WarehouseName = ent.WarehouseName, State = "未入库" }; inwh.DoCreate(); ProcessDetail(inwh); break; case "GetSaleOrderPart": string orderNumber = RequestData.Get <string>("OrderNumber"); soent = SaleOrder.FindAllByProperty("Number", orderNumber).FirstOrDefault <SaleOrder>(); PageState.Add("Result", OrdersPart.FindAllByProperty(OrdersPart.Prop_OId, soent.Id)); break; default: DoSelect(); break; } }
protected void Page_Load(object sender, EventArgs e) { id = RequestData.Get <string>("id"); if (!string.IsNullOrEmpty(id)) { roEnt = ReturnOrder.Find(id); } switch (RequestActionString) { case "delete": //先删除入库单及入库明细 InWarehouse iwEnt = InWarehouse.FindAllByProperty(InWarehouse.Prop_PublicInterface, roEnt.Id).FirstOrDefault <InWarehouse>(); IList <OtherInWarehouseDetail> oiwdEnts = OtherInWarehouseDetail.FindAllByProperty(OtherInWarehouseDetail.Prop_InWarehouseId, iwEnt.Id); foreach (OtherInWarehouseDetail oiwdEnt in oiwdEnts) { oiwdEnt.DoDelete(); } iwEnt.DoDelete(); //更新销售单及销售明细 SaleOrder soEnt = SaleOrder.FindAllByProperty(SaleOrder.Prop_Number, roEnt.OrderNumber).FirstOrDefault <SaleOrder>(); soEnt.ReturnAmount = (soEnt.ReturnAmount.HasValue ? soEnt.ReturnAmount.Value : 0) - (roEnt.ReturnMoney.HasValue ? roEnt.ReturnMoney.Value : 0); soEnt.DoUpdate(); IList <ReturnOrderPart> ropEnts = ReturnOrderPart.FindAllByProperty(ReturnOrderPart.Prop_ReturnOrderId, roEnt.Id); foreach (ReturnOrderPart ropEnt in ropEnts) { OrdersPart opEnt = OrdersPart.Find(ropEnt.OrderPartId); opEnt.ReturnCount = (opEnt.ReturnCount.HasValue ? opEnt.ReturnCount.Value : 0) - ropEnt.Count; opEnt.DoUpdate(); ropEnt.DoDelete(); } roEnt.DoDelete(); break; default: DoSelect(); break; } }
private void DoBatchDelete() { IList <object> idList = RequestData.GetList <object>("IdList"); string db = ConfigurationManager.AppSettings["ExamineDB"]; if (idList != null && idList.Count > 0) { OrdersPart op = null; OrdersPart[] ops = null; DelieryOrderPart[] dops = null; DeliveryOrder dorder = null; SaleOrder order = null; string count = ""; //更新订单状态,同时删除DeliveryOrderPart表数据 foreach (object obj in idList) { dorder = DeliveryOrder.TryFind(obj); if (dorder == null) { DelieryOrderPart.DeleteAll("DId='" + obj + "'"); //删除DeliveryOrderPart continue; } dops = DelieryOrderPart.FindAllByProperty("DId", obj); foreach (DelieryOrderPart dop in dops) { //更新订单状态 op = OrdersPart.TryFind(dop.PId); if (op != null) { op.OutCount = (op.OutCount == null ? 0 : Convert.ToInt32(op.OutCount)) - Convert.ToInt32(dop.Count); op.DoSave(); } } //更新order的json string jsons = ""; order = SaleOrder.FindAllByProperty("Id", dorder.PId).FirstOrDefault <SaleOrder>(); if (order == null) { DelieryOrderPart.DeleteAll("DId='" + obj + "'"); //删除DeliveryOrderPart continue; } ops = OrdersPart.FindAllByProperty("OId", order.Id); //拼json foreach (OrdersPart opt in ops) { jsons += "{"; jsons += "Id:'" + opt.PId + "',"; jsons += "Isbn:'" + opt.Isbn + "',"; jsons += "Code:'" + opt.PCode + "',"; jsons += "Name:'" + opt.PName + "',"; jsons += "Unit:'" + opt.Unit + "',"; jsons += "MinSalePrice:'" + opt.MinSalePrice + "',"; jsons += "Price:'" + opt.SalePrice + "',"; jsons += "Amount:'" + opt.Amount + "',"; jsons += "Count:'" + opt.Count + "',"; jsons += "OutCount:'" + opt.OutCount + "',"; jsons += "Remark:'" + opt.Remark + "'"; jsons += "},"; } count = DataHelper.QueryValue("select count(1) from " + db + "..OrdersPart where OId='" + order.Id + "' and OutCount=[Count]") + ""; if (count == "0") { order.DeliveryState = ""; } else { order.DeliveryState = "部分生成出库单"; } order.Child = "[" + jsons.Substring(0, jsons.Length - 1) + "]"; order.DoSave(); DelieryOrderPart.DeleteAll("DId='" + obj + "'"); //删除DeliveryOrderPart } DeliveryOrder.DoBatchDelete(idList.ToArray()); } }
protected void Page_Load(object sender, EventArgs e) { string ids = RequestData.Get <string>("ids"); string[] idArray = null; if (!string.IsNullOrEmpty(ids)) { idArray = ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); } id = RequestData.Get <string>("id"); if (!string.IsNullOrEmpty(id)) { piEnt = PaymentInvoice.Find(id); } switch (RequestActionString) { case "CancelCorrespond": foreach (string str in idArray) //可以同时对多个付款进行撤销对应 { piEnt = PaymentInvoice.Find(str); string[] invoiceArray = piEnt.CorrespondInvoice.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < invoiceArray.Length; i++) { int index = invoiceArray[i].IndexOf("_"); string number = invoiceArray[i].Substring(0, index); //找到对应的发票号和销账金额 对发票进行回滚 decimal amount = Convert.ToDecimal(invoiceArray[i].Substring(index + 1)); SaleOrder oiEnt = SaleOrder.FindAllByProperty(SaleOrder.Prop_Number, number).FirstOrDefault <SaleOrder>(); oiEnt.ReceiptAmount = (oiEnt.ReceiptAmount.HasValue ? oiEnt.ReceiptAmount.Value : 0) - amount; oiEnt.PayState = oiEnt.ReceiptAmount > 0 ? "部分付款" : null; oiEnt.DoUpdate(); } piEnt.CorrespondInvoice = ""; piEnt.CorrespondState = ""; piEnt.Name = "暂不销账"; piEnt.DoUpdate(); } break; case "AutoCorrespond": sql = @"select sum(TotalMoney-isnull(DiscountAmount,0)-isnull(ReturnAmount,0)-isnull(ReceiptAmount,0)) from SHHG_AimExamine..SaleOrders where CId='" + piEnt.CId + "' and State is null and InvoiceType='收据' and (PayState is null or PayState='部分付款')"; decimal TotalArrearage = DataHelper.QueryValue <decimal>(sql); if (TotalArrearage >= piEnt.Money) { sql = @"select * from SHHG_AimExamine..SaleOrders where InvoiceType='收据' and CId='" + piEnt.CId + "' and State is null and (PayState is null or PayState='部分付款') order by CreateTime asc"; IList <EasyDictionary> dics = DataHelper.QueryDictList(sql); decimal payamount = piEnt.Money.Value; piEnt.CorrespondInvoice = ""; foreach (EasyDictionary dic in dics) { if (payamount > 0) { SaleOrder oiEnt = SaleOrder.Find(dic.Get <string>("Id")); decimal unpayAmount = oiEnt.TotalMoney.Value - (oiEnt.ReceiptAmount.HasValue ? oiEnt.ReceiptAmount.Value : 0) - (oiEnt.DiscountAmount.HasValue ? oiEnt.DiscountAmount.Value : 0) - (oiEnt.ReturnAmount.HasValue ? oiEnt.ReturnAmount.Value : 0); if (payamount >= unpayAmount) { payamount = payamount - unpayAmount; oiEnt.ReceiptAmount = (oiEnt.ReceiptAmount.HasValue ? oiEnt.ReceiptAmount.Value : 0) + unpayAmount; oiEnt.PayState = "已全部付款"; piEnt.CorrespondInvoice += oiEnt.Number + "_" + unpayAmount + ","; } else { oiEnt.ReceiptAmount = (oiEnt.ReceiptAmount.HasValue ? oiEnt.ReceiptAmount.Value : 0) + payamount; piEnt.CorrespondInvoice += oiEnt.Number + "_" + payamount + ","; payamount = 0; } oiEnt.DoUpdate(); } } piEnt.CorrespondState = "已对应"; piEnt.Name = "自动销账"; piEnt.DoUpdate(); PageState.Add("Result", "T"); } else { PageState.Add("Result", "F"); } break; case "delete": foreach (string str in idArray) { piEnt = PaymentInvoice.Find(str); piEnt.DoDelete(); } break; default: DoSelect(); break; } }