public ActionResult SettlementOrder(SaleSettlementModel model) { try { SaleOrderService.Settlement(model); return(new BetterJsonResult()); } catch (Exception ex) { return(new BetterJsonResult(ex.Message)); } }
/// <summary> /// 结算销售单 /// </summary> /// <param name="model"></param> public void Settlement(SaleSettlementModel model) { if (model == null) { return; } var order = SaleOrderRepository.GetModel(model.SaleOrderId); if (order == null) { throw new Exception("销售单不存在。"); } if (order.Status != EnumSaleOrderStatus.Outbound) { throw new Exception("只能结算已出库的销售单。"); } if (order.SettlementStatus == EnumSettlementStatus.Completed) { throw new Exception("只能结算未结算的销售单。"); } order.SettlementStatus = model.SettlementStatus; order.SettlementAmount = order.SettlementAmount + model.SettlementAmount; if (order.SettlementAmount >= order.Amount && order.SettlementStatus == EnumSettlementStatus.PartCompleted) { throw new Exception("结算金额已超过销售单总金额,不允许部分结算。"); } var financeOrder = new FinanceOrder(); financeOrder.Code = this.FinanceOrderRepository.GetSequenceNextCode(); financeOrder.Amount = model.SettlementAmount; financeOrder.Remark = model.SettlementRemark; SaleOrderRepository.Settlement(order, financeOrder); }