using MyCode.Project.Repositories.Common; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using MyCode.Project.Domain.Message; using MyCode.Project.Domain.Model; using MyCode.Project.Domain.Repositories; using MyCode.Project.Infrastructure.Common; using MyCode.Project.Infrastructure.Search; using MyCode.Project.Domain.Message.Response.PurchaseOrder; using MyCode.Project.Domain.Message.Request.PurchaseOrder; using MyCode.Project.Infrastructure.Extensions; namespace MyCode.Project.Repositories { public class PurchaseOrderRepository: Repository, IPurchaseOrderRepository { public PurchaseOrderRepository(MyCodeSqlSugarClient context) : base(context) { } /// /// 采购订单分页列表 /// /// /// /// public PageResult GetPageList(PagedSearch search, string supplierId,string FPurchaseOrgId) { var condition = search.Condition; SearchCondition where = new SearchCondition(); where.AddCondition("a.FBillNo", condition.FBillNo, SqlOperator.Like, !string.IsNullOrWhiteSpace( condition.FBillNo)); if (condition.FDateEmd.HasValue) { DateTime end = condition.FDateEmd.Value.AddDays(1).Date; where.AddCondition("a.FDate", end, SqlOperator.LessThan, true); } if (condition.FDateBegin.HasValue) { DateTime begin = condition.FDateBegin.Value.AddDays(1).Date; where.AddCondition("a.[FDate]", begin, SqlOperator.MoreThanOrEqual, true); } where.AddCondition("a.supplierId", supplierId, SqlOperator.Equal, !string.IsNullOrWhiteSpace( supplierId)); where.AddCondition("a.FPurchaseOrgId", FPurchaseOrgId, SqlOperator.Equal, !string.IsNullOrWhiteSpace(FPurchaseOrgId) && FPurchaseOrgId != "-1"); where.AddCondition("b.MaterialCode", condition.MaterialCode, SqlOperator.Like, !string.IsNullOrWhiteSpace(condition.MaterialCode)); where.AddCondition("b.FMRPCloseStatus", condition.FMRPCloseStatus, SqlOperator.Equal, !string.IsNullOrWhiteSpace(condition.FMRPCloseStatus) && condition.FMRPCloseStatus != "-1"); string sql = $@"select a.[Id] AS FormId ,[SupplierName] ,[Purchaser] ,[PurchaserId] ,[PaymentMethod] ,[SettlementCcurrency] ,[PaymentTerms] ,A.[FCancelStatus] ,CONVERT(NVARCHAR(50),FDate,23) [FDate] ,[ExchangeRateType] ,[ExchangeRate] ,[FBillNo] ,FPurchaseOrgId,FPurchaseOrgName , FReceiveQty as SendedQty , B.FRemainReceiveQty as NotSendQty , a.FBILLTYPEID ,b.* FROM [PurchaseOrder] a left join PurchaseOrderItem b on a.fid=b.fid "; var list= this.SelectListPage(sql, where, search.Page, search.PageSize, " [FiD] desc,MaterialCode "); int fid = 0; list.DataList.ForEach(t=> { if (fid == t.FiD) t.IfHidden = 1; fid = t.FiD.SafeValue(); if (!string.IsNullOrWhiteSpace(t.ChengNuoJiaoQi)) { t.ChengNuoJiaoQi = DateTime.Parse(t.ChengNuoJiaoQi).ToString("yyyy-MM-dd") ; } if (!string.IsNullOrWhiteSpace(t.FDeliveryDate)) { t.FDeliveryDate = DateTime.Parse(t.FDeliveryDate).ToString("yyyy-MM-dd"); } if (!string.IsNullOrWhiteSpace(t.NewChengNuoJiaoQi)) { t.NewChengNuoJiaoQi = DateTime.Parse(t.NewChengNuoJiaoQi).ToString("yyyy-MM-dd"); } }); return list; } #region GetPurchaseOrderItemList(根据采购订单FID获取明细列表) /// /// 根据采购订单FID获取明细列表 /// /// /// public List GetPurchaseOrderItemList(PurchaseOrderItemSearch purchaseOrderItemSearch, string supplierId) { var condition = purchaseOrderItemSearch; SearchCondition where = new SearchCondition(); where.AddCondition("a.Fid", purchaseOrderItemSearch.Fid, SqlOperator.Equal, true); if (condition.ChengNuoJiaoQiBegin.HasValue) { DateTime begin = condition.ChengNuoJiaoQiBegin.Value.AddDays(1).Date; where.AddCondition("a.[ChengNuoJiaoQi]", begin, SqlOperator.MoreThanOrEqual, true); } if (condition.ChengNuoJiaoQiEnd.HasValue) { DateTime end = condition.ChengNuoJiaoQiEnd.Value.AddDays(1).Date; where.AddCondition("a.ChengNuoJiaoQi", end, SqlOperator.LessThan, true); } if (condition.NewChengNuoJiaoQiBegin.HasValue) { DateTime begin = condition.NewChengNuoJiaoQiBegin.Value.AddDays(1).Date; where.AddCondition("a.[NewChengNuoJiaoQi]", begin, SqlOperator.MoreThanOrEqual, true); } if (condition.NewChengNuoJiaoQiEnd.HasValue) { DateTime end = condition.NewChengNuoJiaoQiEnd.Value.AddDays(1).Date; where.AddCondition("a.NewChengNuoJiaoQi", end, SqlOperator.LessThan, true); } where.AddCondition("a.MaterialCode", condition.MaterialCode, SqlOperator.Like, condition.MaterialCode.HasValue && !string.IsNullOrWhiteSpace(condition.MaterialCode.ToString())); where.AddCondition("a.MaterialName", condition.MaterialName, SqlOperator.Like, !string.IsNullOrWhiteSpace(condition.MaterialName)); where.AddCondition("a.SpecificationModel", condition.SpecificationModel, SqlOperator.Like, !string.IsNullOrWhiteSpace(condition.SpecificationModel)); where.AddCondition("a.supplierId", supplierId, SqlOperator.Equal, !string.IsNullOrWhiteSpace(supplierId)); string sql = $@" select (a.qty-ProcessingQty-SendedQty) as NotSendQty , (a.qty-ProcessingQty-SendedQty) as NowSendQty, a.* from ( select isnull((select sum([Qty]) from [InvoiceOrderItem] b with(nolock) where b.PurchaseOrderItemId=a.id and [DeliveryDate] is null ),0) as ProcessingQty , isnull((select sum([Qty]) from [InvoiceOrderItem] b with(nolock) where b.PurchaseOrderItemId=a.id and [DeliveryDate] is not null ),0) as SendedQty,* from [PurchaseOrderItem] a) a "; return this.SelectList(sql, where).OrderBy(t=>t.EntityId).ToList(); } #endregion } }