ReceivableService.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using LeaRun.Application.Entity.CustomerManage;
  2. using LeaRun.Application.IService.CustomerManage;
  3. using LeaRun.Data.Repository;
  4. using LeaRun.Util;
  5. using LeaRun.Util.Extension;
  6. using LeaRun.Util.WebControl;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. namespace LeaRun.Application.Service.CustomerManage
  11. {
  12. /// <summary>
  13. /// 版 本 6.1
  14. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  15. /// 创 建:佘赐雄
  16. /// 日 期:2016-04-06 17:24
  17. /// 描 述:应收账款
  18. /// </summary>
  19. public class ReceivableService : RepositoryFactory<ReceivableEntity>, IReceivableService
  20. {
  21. private IOrderService orderIService = new OrderService();
  22. #region 获取数据
  23. /// <summary>
  24. /// 获取收款单列表
  25. /// </summary>
  26. /// <param name="pagination">分页</param>
  27. /// <param name="queryJson">查询参数</param>
  28. /// <returns>返回分页列表</returns>
  29. public IEnumerable<OrderEntity> GetPaymentPageList(Pagination pagination, string queryJson)
  30. {
  31. var expression = LinqExtensions.True<OrderEntity>();
  32. var queryParam = queryJson.ToJObject();
  33. //单据日期
  34. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  35. {
  36. DateTime startTime = queryParam["StartTime"].ToDate();
  37. DateTime endTime = queryParam["EndTime"].ToDate().AddDays(1);
  38. expression = expression.And(t => t.OrderDate >= startTime && t.OrderDate <= endTime);
  39. }
  40. //单据编号
  41. if (!queryParam["OrderCode"].IsEmpty())
  42. {
  43. string OrderCode = queryParam["OrderCode"].ToString();
  44. expression = expression.And(t => t.OrderCode.Contains(OrderCode));
  45. }
  46. //客户名称
  47. if (!queryParam["CustomerName"].IsEmpty())
  48. {
  49. string CustomerName = queryParam["CustomerName"].ToString();
  50. expression = expression.And(t => t.CustomerName.Contains(CustomerName));
  51. }
  52. //销售人员
  53. if (!queryParam["SellerName"].IsEmpty())
  54. {
  55. string SellerName = queryParam["SellerName"].ToString();
  56. expression = expression.And(t => t.SellerName.Contains(SellerName));
  57. }
  58. return new RepositoryFactory().BaseRepository().FindList<OrderEntity>(expression, pagination);
  59. }
  60. /// <summary>
  61. /// 获取收款记录列表
  62. /// </summary>
  63. /// <param name="orderId">订单主键</param>
  64. /// <returns></returns>
  65. public IEnumerable<ReceivableEntity> GetPaymentRecord(string orderId)
  66. {
  67. return this.BaseRepository().IQueryable(t => t.OrderId.Equals(orderId)).OrderByDescending(t => t.CreateDate).ToList();
  68. }
  69. #endregion
  70. #region 提交数据
  71. /// <summary>
  72. /// 保存表单(新增)
  73. /// </summary>
  74. /// <param name="entity">实体对象</param>
  75. /// <returns></returns>
  76. public void SaveForm(ReceivableEntity entity)
  77. {
  78. ICashBalanceService icashbalanceservice = new CashBalanceService();
  79. OrderEntity orderEntity = orderIService.GetEntity(entity.OrderId);
  80. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  81. try
  82. {
  83. //更改订单状态
  84. orderEntity.ReceivedAmount = orderEntity.ReceivedAmount + entity.PaymentPrice;
  85. if (orderEntity.ReceivedAmount == orderEntity.Accounts)
  86. {
  87. orderEntity.PaymentState = 3;
  88. }
  89. else
  90. {
  91. orderEntity.PaymentState = 2;
  92. }
  93. db.Update(orderEntity);
  94. //添加收款
  95. entity.Create();
  96. db.Insert(entity);
  97. //添加账户余额
  98. icashbalanceservice.AddBalance(db, new CashBalanceEntity
  99. {
  100. ObjectId = entity.ReceivableId,
  101. ExecutionDate = entity.PaymentTime,
  102. CashAccount = entity.PaymentAccount,
  103. Receivable = entity.PaymentPrice,
  104. Abstract = entity.Description
  105. });
  106. db.Commit();
  107. }
  108. catch (Exception)
  109. {
  110. db.Rollback();
  111. throw;
  112. }
  113. }
  114. #endregion
  115. }
  116. }