OrderStickBillsApplicationService.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Linq.Dynamic.Core;
  7. using System.Threading.Tasks;
  8. using Abp.Application.Services.Dto;
  9. using Abp.Authorization;
  10. using Abp.Collections.Extensions;
  11. using Abp.Domain.Repositories;
  12. using Abp.Extensions;
  13. using Abp.Json;
  14. using Abp.Timing;
  15. using Abp.UI;
  16. using IwbZero.AppServiceBase;
  17. using IwbZero.Auditing;
  18. using IwbZero.IdentityFramework;
  19. using Microsoft.AspNet.SignalR.Hubs;
  20. using ShwasherSys.Authorization.Permissions;
  21. using ShwasherSys.BaseSysInfo;
  22. using ShwasherSys.Common;
  23. using ShwasherSys.CustomerInfo;
  24. using ShwasherSys.EntityFramework;
  25. using ShwasherSys.Invoice.Dto;
  26. using ShwasherSys.Lambda;
  27. using ShwasherSys.OrderSendInfo;
  28. using ShwasherSys.OrderSendInfo.Dto;
  29. namespace ShwasherSys.Invoice
  30. {
  31. [AbpAuthorize]
  32. public class OrderStickBillAppService : ShwasherAsyncCrudAppService<OrderStickBill, OrderStickBillDto, string, PagedRequestDto, OrderStickBillCreateDto, OrderStickBillUpdateDto >, IOrderStickBillAppService
  33. {
  34. protected IRepository<ViewCustomerStick> ViewCustomerStickRepository;
  35. protected IRepository<ViewOrderSendStickBill> ViewOrderSendStickBillRepository;
  36. public IRepository<OrderSendBill, string> OrderSendBillRepository;
  37. protected IRepository<Customer,string> CustomerRepository;
  38. protected IRepository<OrderSend> OrderSendRepository;
  39. protected ISqlExecuter SqlExecute;
  40. protected IRepository<BusinessLog> BusinessLogRepository { get; }
  41. protected IRepository<ViewStickBill,string> ViewStickBillRepository { get; }
  42. protected IRepository<ViewStatementBill> ViewStatementBillRepository { get; }
  43. public OrderStickBillAppService(IRepository<OrderStickBill, string> repository, IRepository<ViewCustomerStick> viewCustomerStickRepository, ISqlExecuter sqlExecute, IRepository<Customer, string> customerRepository, IRepository<OrderSend> orderSendRepository, IRepository<BusinessLog> businessLogRepository, IRepository<ViewStickBill, string> viewStickBillRepository,IRepository<ViewOrderSendStickBill> viewOrderSendStickBillRepository, IRepository<OrderSendBill, string> orderSendBillRepository, IRepository<ViewStatementBill> viewStatementBillRepository) : base(repository)
  44. {
  45. ViewCustomerStickRepository = viewCustomerStickRepository;
  46. SqlExecute = sqlExecute;
  47. CustomerRepository = customerRepository;
  48. OrderSendRepository = orderSendRepository;
  49. BusinessLogRepository = businessLogRepository;
  50. ViewStickBillRepository = viewStickBillRepository;
  51. ViewOrderSendStickBillRepository = viewOrderSendStickBillRepository;
  52. OrderSendBillRepository = orderSendBillRepository;
  53. ViewStatementBillRepository = viewStatementBillRepository;
  54. KeyIsAuto = false;
  55. }
  56. protected override string GetPermissionName { get; set; } = PermissionNames.PagesInvoiceInfoInvoiceMg;
  57. protected override string GetAllPermissionName { get; set; } = PermissionNames.PagesInvoiceInfoInvoiceMg;
  58. protected override string CreatePermissionName { get; set; } = PermissionNames.PagesInvoiceInfoInvoiceCreateCreate;
  59. protected override string UpdatePermissionName { get; set; } = PermissionNames.PagesInvoiceInfoInvoiceMgUpdate;
  60. protected override string DeletePermissionName { get; set; } = PermissionNames.PagesInvoiceInfoInvoiceMgDelete;
  61. public async Task<PagedResultDto<ViewStickBill>> GetViewAll(PagedRequestDto input)
  62. {
  63. CheckGetAllPermission();
  64. var query = ViewStickBillRepository.GetAll();
  65. if (input.SearchList != null && input.SearchList.Count > 0)
  66. {
  67. List<LambdaObject> objList = new List<LambdaObject>();
  68. foreach (var o in input.SearchList)
  69. {
  70. if (o.KeyWords.IsNullOrEmpty())
  71. continue;
  72. object keyWords = o.KeyWords;
  73. objList.Add(new LambdaObject
  74. {
  75. FieldType = (LambdaFieldType)o.FieldType,
  76. FieldName = o.KeyField,
  77. FieldValue = keyWords,
  78. ExpType = (LambdaExpType)o.ExpType
  79. });
  80. }
  81. var exp = objList.GetExp<ViewStickBill>();
  82. query = query.Where(exp);
  83. }
  84. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  85. query = query.OrderByDescending(i => i.CreatDate);
  86. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  87. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  88. var dtos = new PagedResultDto<ViewStickBill>(
  89. totalCount,
  90. entities
  91. );
  92. return dtos;
  93. }
  94. //[AbpAuthorize(PermissionNames.PagesInvoiceInfoInvoiceCreateQueryPage)]
  95. //public async Task<List<ViewCustomerStick>> GetAllCreateView(PagedRequestDto input)
  96. //{
  97. // var query = ViewCustomerStickRepository.GetAll();
  98. // if (input.SearchList != null && input.SearchList.Count > 0)
  99. // {
  100. // List<LambdaObject> objList = new List<LambdaObject>();
  101. // foreach (var o in input.SearchList)
  102. // {
  103. // if (o.KeyWords.IsNullOrEmpty())
  104. // continue;
  105. // object keyWords = o.KeyWords;
  106. // /*if (o.KeyField == "sendDate" && (LambdaExpType)o.ExpType == LambdaExpType.LessOrEqual)
  107. // ]
  108. // keyWords = Convert.ToDateTime(keyWords).AddDays(1);
  109. // }*/
  110. // objList.Add(new LambdaObject
  111. // {
  112. // FieldType = (LambdaFieldType)o.FieldType,
  113. // FieldName = o.KeyField,
  114. // FieldValue = keyWords,
  115. // ExpType = (LambdaExpType)o.ExpType
  116. // });
  117. // }
  118. // var exp = objList.GetExp<ViewCustomerStick>();
  119. // query = query.Where(exp).OrderByDescending(i=>i.SendDate);
  120. // }
  121. // var entities = await AsyncQueryableExecuter.ToListAsync(query);
  122. // return entities;
  123. //}
  124. [AbpAuthorize(PermissionNames.PagesInvoiceInfoInvoiceCreateQueryPage)]
  125. public async Task<List<ViewStatementBill>> GetAllCreateView(PagedRequestDto input)
  126. {
  127. var query = ViewStatementBillRepository.GetAll();
  128. if (input.SearchList != null && input.SearchList.Count > 0)
  129. {
  130. List<LambdaObject> objList = new List<LambdaObject>();
  131. foreach (var o in input.SearchList)
  132. {
  133. if (o.KeyWords.IsNullOrEmpty())
  134. continue;
  135. object keyWords = o.KeyWords;
  136. /*if (o.KeyField == "sendDate" && (LambdaExpType)o.ExpType == LambdaExpType.LessOrEqual)
  137. ]
  138. keyWords = Convert.ToDateTime(keyWords).AddDays(1);
  139. }*/
  140. objList.Add(new LambdaObject
  141. {
  142. FieldType = (LambdaFieldType)o.FieldType,
  143. FieldName = o.KeyField,
  144. FieldValue = keyWords,
  145. ExpType = (LambdaExpType)o.ExpType
  146. });
  147. }
  148. var exp = objList.GetExp<ViewStatementBill>();
  149. query = query.Where(exp).OrderByDescending(i => i.CreationTime);
  150. }
  151. query = query.Where(i => i.OrderStickBillNo == null || i.OrderStickBillNo == "");
  152. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  153. return entities;
  154. }
  155. [AbpAuthorize(PermissionNames.PagesInvoiceInfoInvoiceCreateCreate),AuditLog("创建发票")]
  156. public override async Task<OrderStickBillDto> Create(OrderStickBillCreateDto input)
  157. {
  158. //CheckCreatePermission();
  159. if (input.OrderSendIds.IsNullOrEmpty())
  160. {
  161. throw new UserFriendlyException("无效参数!");
  162. }
  163. var entity = Repository.FirstOrDefault(input.Id);
  164. if (entity != null)
  165. {
  166. throw new UserFriendlyException("该发票号已存在,请勿重复创建相同发票号!");
  167. }
  168. string sql = $"update StatementBill set StatementState=1,OrderStickBillNo='{input.StickNum}' where Id in ({input.OrderSendIds});";
  169. sql += $"update OrderSend set OrderStickBillNo='{input.StickNum}' where StatementBillNo in (select StatementBillNo from StatementBill where Id in ({input.OrderSendIds}));";
  170. //SqlExecute.Execute("update OrderSend set OrderStickBillNo='"+input.StickNum+"' where OrderSendId in ("+ input.OrderSendIds + ") ");
  171. SqlExecute.Execute(sql);
  172. //input.Amount = 0;
  173. input.InvoiceState = InvoiceState.NotPay.ToInt();
  174. input.InvoiceType = InvoiceTypeDefinition.Normal;
  175. return await CreateEntity(input);
  176. }
  177. [AbpAuthorize(PermissionNames.PagesInvoiceInfoInvoiceMgCreateRed),AuditLog("创建红冲发票")]
  178. public async Task<OrderStickBillDto> CreateRed(RedOrderStickBillCreateDto input)
  179. {
  180. var entity =await Repository.FirstOrDefaultAsync(input.Id);
  181. if (entity != null)
  182. {
  183. throw new UserFriendlyException("该发票号已存在,请勿重复创建相同发票号!");
  184. }
  185. var oi = await Repository.FirstOrDefaultAsync(a => a.StickNum == input.OriginalStickNum);
  186. if (oi == null)
  187. {
  188. throw new UserFriendlyException("原发票号不存在,请检查后再试!");
  189. }
  190. if ( input.InvoiceType != InvoiceTypeDefinition.RedLess && input.Amount> oi.Amount)
  191. {
  192. throw new UserFriendlyException($"退还金额不能大于原发票金额【{oi.Amount}】。");
  193. }
  194. entity = MapToEntity(input);
  195. entity.StickNum = entity.Id;
  196. entity.InvoiceState = InvoiceState.NotPay.ToInt();
  197. entity.CustomerId = oi.CustomerId;
  198. if (entity.InvoiceType== InvoiceTypeDefinition.RedOver || entity.InvoiceType== InvoiceTypeDefinition.RedReturn)
  199. {
  200. entity.Amount = entity.Amount > 0 ? 0 - entity.Amount : entity.Amount;
  201. }
  202. if (string.IsNullOrEmpty(entity.StickMan))
  203. {
  204. entity.StickMan = AbpSession.UserName;
  205. }
  206. //entity.InvoiceType = InvoiceTypeDefinition.RedReturn;
  207. entity.OriginalStickNum = input.OriginalStickNum;
  208. entity.OrderNo = input.OrderNo;
  209. entity.ReturnOrderNo = input.ReturnOrderNo;
  210. entity = await Repository.InsertAsync(entity);
  211. return MapToEntityDto(entity);
  212. }
  213. [AuditLog("作废发票")]
  214. public override async Task Delete(EntityDto<string> input)
  215. {
  216. CheckDeletePermission();
  217. var entity = Repository.Get(input.Id);
  218. var orderSends = OrderSendRepository.GetAllList(i => i.OrderStickBillNo == entity.Id);
  219. foreach (var send in orderSends)
  220. {
  221. send.OrderStickBillNo = "";
  222. send.TimeLastMod = Clock.Now;
  223. send.UserIDLastMod = AbpSession.UserName;
  224. await OrderSendRepository.UpdateAsync(send);
  225. }
  226. string sql = $"update StatementBill set StatementState=0,OrderStickBillNo='' where OrderStickBillNo ='{entity.Id}';";
  227. await SqlExecute.ExecuteAsync(sql);
  228. BusinessLogTypeEnum.OrderSend.WriteLog(BusinessLogRepository, "撤销发票", $"发票{entity.ToJsonString()}撤销");
  229. //this.Logger.Info("撤销发票!" + entity.ToString());
  230. await Repository.DeleteAsync(input.Id);
  231. }
  232. [AuditLog("修改发票号")]
  233. public async Task<OrderStickBill> UpdateStickNum(OrderStickBillUpdateDto input)
  234. {
  235. CheckUpdatePermission();
  236. if (Repository.FirstOrDefault(i => i.StickNum == input.StickNum) != null)
  237. {
  238. throw new UserFriendlyException("该发票号已存在,请勿重复创建相同发票号!");
  239. }
  240. var entity = Repository.Get(input.Id);
  241. entity.StickNum = input.StickNum;
  242. entity.TimeLastMod = Clock.Now;
  243. entity.UserIDLastMod = AbpSession.UserName;
  244. this.Logger.Info("修改发票号!" + entity.ToString());
  245. return await Repository.UpdateAsync(entity);
  246. }
  247. [AbpAuthorize(PermissionNames.PagesInvoiceInfoInvoiceMgUpdateState), AuditLog("修改发票状态")]
  248. public async Task<OrderStickBill> UpdateState(OrderStickBillUpdateDto input)
  249. {
  250. var entity = Repository.Get(input.Id);
  251. entity.Amount = input.Amount;
  252. if (entity.InvoiceType== InvoiceTypeDefinition.RedOver || entity.InvoiceType== InvoiceTypeDefinition.RedReturn)
  253. {
  254. entity.Amount = entity.Amount > 0 ? 0 - entity.Amount : entity.Amount;
  255. }
  256. entity.InvoiceState = InvoiceState.HasPay.ToInt();
  257. entity.TimeLastMod = Clock.Now;
  258. entity.UserIDLastMod = AbpSession.UserName;
  259. this.Logger.Info("修改发票状态!" + entity.ToJsonString());
  260. return await Repository.UpdateAsync(entity);
  261. }
  262. [AuditLog("导出发票")]
  263. public async Task<string> ExportInvoice(EntityDto<string> input)
  264. {
  265. var orderSends =
  266. ViewOrderSendStickBillRepository.GetAll().Where(i => i.OrderStickBillNo == input.Id).OrderBy(i => i.SendDate).ToList();
  267. var bill = ObjectMapper.Map<OrderSendBillDto>(
  268. OrderSendBillRepository.Get(orderSends.First().OrderSendBillNo));
  269. var customerInfo = await CustomerRepository.FirstOrDefaultAsync(bill.CustomerId);
  270. string path = AppDomain.CurrentDomain.BaseDirectory + "Resources/InvoiceTemplate/发票导出模板.xlsx";
  271. var savePath = "Download/Excel/InvoiceBill";
  272. var work = ExcelHelper.CreateWorkBook07(path);
  273. var sheet1 = work.GetSheet("Worksheet");
  274. sheet1.GenerateCell(4, 4).SetCellValue(customerInfo.CustomerName);
  275. sheet1.GenerateCell(4, 11).SetCellValue(bill.SendAddress);
  276. sheet1.GenerateCell(5, 4).SetCellValue(bill.ContactTels);
  277. sheet1.GenerateCell(5, 11).SetCellValue(bill.ContactMan);
  278. sheet1.GenerateCell(6, 4).SetCellValue(input.Id);
  279. sheet1.GenerateCell(6, 8).SetCellValue("日期:" + DateTime.Now.ToString("yyyy年MM月dd日"));
  280. if (orderSends.Count>1)
  281. {
  282. sheet1.InsertRows(8, orderSends.Count-1);
  283. }
  284. int index = 0;
  285. decimal ldAccontTotal = 0;
  286. decimal ldNoTaxTotal = 0;
  287. string currencyId = "CNY";
  288. bool isCanViewPrice = PermissionChecker.IsGranted(PermissionNames.PagesOrderInfoOrderMgQueryOrderPrice);
  289. foreach (var send in orderSends)
  290. {
  291. var sendQuantity = $"{send.SendQuantity ?? 0:N3}";
  292. var price = $"{send.Price:N3}";
  293. var noTaxprice = $"{send.AfterTaxPrice:N3}";
  294. var logisticsFee = string.Format("{0:N3}", send.LogisticsFee);
  295. var moldFee = string.Format("{0:N3}", send.MoldFee);
  296. var totalprice = $"{send.totalprice:N3}";
  297. var totalNoTaxprice = $"{(send.SendQuantity ?? 0) * send.AfterTaxPrice:N3}";
  298. var sendDate = $"{send.SendDate:yyyy-MM-dd}";
  299. currencyId = send.CurrencyId;
  300. sheet1.GenerateCell(8 + index, 1).SetValue<int>(index + 1);
  301. sheet1.GenerateCell(8 + index, 2).SetValue(send.StockNo ?? send.OrderNo);
  302. sheet1.GenerateCell(8 + index, 3).SetValue(send.OrderSendBillNo ?? "");
  303. sheet1.GenerateCell(8 + index, 4).SetValue(sendDate);
  304. sheet1.GenerateCell(8 + index, 5).SetValue(send.PartNo ?? "");
  305. sheet1.GenerateCell(8 + index, 6).SetValue(send.Model ?? "");
  306. sheet1.GenerateCell(8 + index, 7).SetValue(send.ProductName ?? "");
  307. sheet1.GenerateCell(8 + index, 8).SetValue(send.Rigidity ?? "");
  308. sheet1.GenerateCell(8 + index, 9).SetValue(send.SurfaceColor ?? "");
  309. sheet1.GenerateCell(8 + index, 10).SetValue<decimal>(sendQuantity);
  310. sheet1.GenerateCell(8 + index, 11).SetValue(send.OrderUnitName??"");
  311. if (isCanViewPrice)
  312. {
  313. sheet1.GenerateCell(8 + index, 12).SetValue<decimal>(price);
  314. sheet1.GenerateCell(8 + index, 13).SetValue<decimal>(noTaxprice);
  315. sheet1.GenerateCell(8 + index, 14).SetValue<decimal>(logisticsFee);
  316. sheet1.GenerateCell(8 + index, 15).SetValue<decimal>(moldFee);
  317. sheet1.GenerateCell(8 + index, 16).SetValue<decimal>(totalprice);
  318. sheet1.GenerateCell(8 + index, 17).SetValue<decimal>(totalNoTaxprice);
  319. }
  320. ldAccontTotal += send.totalprice;
  321. ldNoTaxTotal += (send.SendQuantity ?? 0) * send.AfterTaxPrice;
  322. index++;
  323. }
  324. sheet1.GenerateCell(8 + index, 15).SetValue($"总金额({currencyId})");
  325. sheet1.GenerateCell(8 + index, 16).SetValue<decimal>(ldAccontTotal);
  326. sheet1.GenerateCell(8 + index, 17).SetValue<decimal>(ldNoTaxTotal);
  327. var fileName = $"发票单-{Clock.Now:yyMMddHHmmss}.xlsx";
  328. var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  329. if (!result.IsNullOrEmpty())
  330. {
  331. //CheckErrors(IwbIdentityResult.Failed(result));
  332. return null;
  333. }
  334. return $"/{savePath}/{fileName}";
  335. }
  336. [AuditLog("导出发票"),AbpAuthorize(PermissionNames.PagesInvoiceInfoInvoiceMgExportInvoices)]
  337. public async Task<string> ExportInvoices(PagedRequestDto input)
  338. {
  339. var query = ViewStickBillRepository.GetAll();
  340. if (input.SearchList != null && input.SearchList.Count > 0)
  341. {
  342. List<LambdaObject> objList = new List<LambdaObject>();
  343. foreach (var o in input.SearchList)
  344. {
  345. if (o.KeyWords.IsNullOrEmpty())
  346. continue;
  347. object keyWords = o.KeyWords;
  348. objList.Add(new LambdaObject
  349. {
  350. FieldType = (LambdaFieldType)o.FieldType,
  351. FieldName = o.KeyField,
  352. FieldValue = keyWords,
  353. ExpType = (LambdaExpType)o.ExpType
  354. });
  355. }
  356. var exp = objList.GetExp<ViewStickBill>();
  357. query = query.Where(exp);
  358. }
  359. var list =await query.OrderByDescending(i => i.CreatDate).ToListAsync();
  360. if (!list.Any())
  361. {
  362. CheckErrors(IwbIdentityResult.Failed("未查询到记录!"));
  363. return null;
  364. }
  365. string path = AppDomain.CurrentDomain.BaseDirectory + "Resources/InvoiceTemplate/多发票导出模板.xlsx";
  366. var savePath = "Download/Excel/InvoiceBills";
  367. var work = ExcelHelper.CreateWorkBook07(path);
  368. var sheet = work.GetSheet("Worksheet");
  369. sheet.InsertRows(2,list.Count-1);
  370. var index = 2;
  371. foreach (var l in list)
  372. {
  373. sheet.GenerateCell(index,1).SetValue(l.Id);
  374. sheet.GenerateCell(index,2).SetValue(l.CustomerId);
  375. sheet.GenerateCell(index,3).SetValue(l.CustomerName);
  376. sheet.GenerateCell(index,4).SetValue<DateTime>(l.CreatDate??DateTime.MinValue);
  377. sheet.GenerateCell(index,5).SetValue(l.StickMan);
  378. sheet.GenerateCell(index,6).SetValue<decimal>(l.TotalPrice??0);
  379. sheet.GenerateCell(index,7).SetValue<decimal>(l.AfterTaxTotalPrice??0);
  380. sheet.GenerateCell(index,8).SetValue(l.InvoiceState==1?"未收款":"已收款");
  381. sheet.GenerateCell(index,9).SetValue<decimal>(l.Amount??0);
  382. sheet.GenerateCell(index,10).SetValue(l.CurrencyId);
  383. index++;
  384. }
  385. var fileName = $"发票单-{Clock.Now:yyMMddHHmmss}.xlsx";
  386. var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  387. if (!result.IsNullOrEmpty())
  388. {
  389. //CheckErrors(IwbIdentityResult.Failed(result));
  390. return null;
  391. }
  392. return $"/{savePath}/{fileName}";
  393. }
  394. [AuditLog("导出对账单")]
  395. public async Task<string> ExportStatementBill(EntityDto<string> input)
  396. {
  397. var orderSends =
  398. ViewOrderSendStickBillRepository.GetAll().Where(i => i.StatementBillNo == input.Id).OrderBy(i=>i.SendDate).ThenBy(i => i.StatementBillSort).ToList();
  399. var bill = ObjectMapper.Map<OrderSendBillDto>(
  400. OrderSendBillRepository.Get(orderSends.First().OrderSendBillNo));
  401. var customerInfo = await CustomerRepository.FirstOrDefaultAsync(bill.CustomerId);
  402. string path = AppDomain.CurrentDomain.BaseDirectory + "Resources/InvoiceTemplate/对账单导出模板.xlsx";
  403. var savePath = "Download/Excel/InvoiceBill";
  404. var work = ExcelHelper.CreateWorkBook07(path);
  405. var sheet1 = work.GetSheet("Worksheet");
  406. sheet1.GenerateCell(4, 4).SetCellValue(customerInfo.CustomerName);
  407. sheet1.GenerateCell(4, 12).SetCellValue(bill.SendAddress);
  408. sheet1.GenerateCell(5, 4).SetCellValue(bill.ContactTels);
  409. sheet1.GenerateCell(5, 12).SetCellValue(bill.ContactMan);
  410. sheet1.GenerateCell(6, 4).SetCellValue(input.Id);
  411. sheet1.GenerateCell(6, 9).SetCellValue("日期:" + DateTime.Now.ToString("yyyy年MM月dd日"));
  412. if (orderSends.Count>1)
  413. {
  414. sheet1.InsertRows(8, orderSends.Count-1);
  415. }
  416. int index = 0;
  417. decimal ldAccontTotal = 0;
  418. decimal ldNoTaxTotal = 0;
  419. string currencyId = "CNY";
  420. bool isCanViewPrice = PermissionChecker.IsGranted(PermissionNames.PagesOrderInfoOrderMgQueryOrderPrice);
  421. foreach (var send in orderSends)
  422. {
  423. var sendQuantity = $"{send.SendQuantity ?? 0:N3}";
  424. var price = $"{send.Price:N3}";
  425. var noTaxprice = $"{send.AfterTaxPrice:N3}";
  426. var logisticsFee = string.Format("{0:N3}", send.LogisticsFee);
  427. var moldFee = string.Format("{0:N3}", send.MoldFee);
  428. var totalprice = $"{send.totalprice:N3}";
  429. var totalNoTaxprice = $"{(send.SendQuantity ?? 0) * send.AfterTaxPrice:N3}";
  430. var sendDate = $"{send.SendDate:yyyy-MM-dd}";
  431. currencyId = send.CurrencyId;
  432. sheet1.GenerateCell(8 + index, 1).SetValue<int>(index + 1);
  433. sheet1.GenerateCell(8 + index, 2).SetValue(send.StockNo ?? send.OrderNo);
  434. sheet1.GenerateCell(8 + index, 3).SetValue(send.OrderSendBillNo ?? "");
  435. sheet1.GenerateCell(8 + index, 4).SetValue(sendDate);
  436. sheet1.GenerateCell(8 + index, 5).SetValue(send.PartNo ?? "");
  437. sheet1.GenerateCell(8 + index, 6).SetValue(send.Model ?? "");
  438. sheet1.GenerateCell(8 + index, 7).SetValue(send.Material ?? "");
  439. sheet1.GenerateCell(8 + index, 8).SetValue(send.ProductName ?? "");
  440. sheet1.GenerateCell(8 + index, 9).SetValue(send.Rigidity ?? "");
  441. sheet1.GenerateCell(8 + index, 10).SetValue(send.SurfaceColor ?? "");
  442. sheet1.GenerateCell(8 + index, 11).SetValue<decimal>(sendQuantity);
  443. sheet1.GenerateCell(8 + index, 12).SetValue(send.OrderUnitName??"");
  444. if (isCanViewPrice)
  445. {
  446. sheet1.GenerateCell(8 + index, 13).SetValue<decimal>(price);
  447. sheet1.GenerateCell(8 + index, 14).SetValue<decimal>(noTaxprice);
  448. sheet1.GenerateCell(8 + index, 15).SetValue<decimal>(logisticsFee);
  449. sheet1.GenerateCell(8 + index, 16).SetValue<decimal>(moldFee);
  450. sheet1.GenerateCell(8 + index, 17).SetValue<decimal>(totalprice);
  451. sheet1.GenerateCell(8 + index, 18).SetValue<decimal>(totalNoTaxprice);
  452. }
  453. ldAccontTotal += send.totalprice;
  454. ldNoTaxTotal += (send.SendQuantity ?? 0) * send.AfterTaxPrice;
  455. index++;
  456. }
  457. sheet1.GenerateCell(8 + index, 16).SetValue($"总金额({currencyId})");
  458. sheet1.GenerateCell(8 + index, 17).SetValue<decimal>(ldAccontTotal);
  459. sheet1.GenerateCell(8 + index, 18).SetValue<decimal>(ldNoTaxTotal);
  460. var fileName = $"对账单-{Clock.Now:yyMMddHHmmss}.xlsx";
  461. var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  462. if (!result.IsNullOrEmpty())
  463. {
  464. //CheckErrors(IwbIdentityResult.Failed(result));
  465. return null;
  466. }
  467. return $"/{savePath}/{fileName}";
  468. }
  469. }
  470. }