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.PurOrder; using MyCode.Project.Domain.Message.Act.Common; namespace MyCode.Project.Repositories { public class PurOrderRepository: Repository, IPurOrderRepository { public PurOrderRepository(MyCodeSqlSugarClient context) : base(context) { } public PageResult GetPurOrderMain(PagedSearch search) { SearchCondition where = new SearchCondition(); //where.AddSqlCondition("a.FDOCUMENTSTATUS='C' ", true); where.AddSqlCondition("1 = 1 ", true); string sql = $@" SELECT *,a.StockInQty/a.Qty AS 'StockInRate' FROM( SELECT a.FID AS 'Fid',C.FNAME AS 'SupplierName',a.FBILLNO,FORMAT(a.FDATE,'yyyy-MM-dd') AS 'FDate',SUM(D.FQTY) AS 'Qty',SUM(E.FSTOCKINQTY) AS'StockInQty' ,SUM(E.FREMAINSTOCKINQTY) AS 'RemainStockInQty' FROM t_PUR_POOrder A WITH(NOLOCK) LEFT JOIN T_BD_SUPPLIER Cccc WITH(NOLOCK) ON Cccc.FSUPPLIERID= A.FSUPPLIERID LEFT JOIN T_BD_SUPPLIER_L C WITH(NOLOCK) ON C.FSUPPLIERID= A.FSUPPLIERID AND C.FLOCALEID= 2052 LEFT JOIN t_PUR_POOrderEntry D WITH(NOLOCK) ON A.FID = D.FID LEFT JOIN t_PUR_POOrderEntry_R E WITH(NOLOCK) ON E.FENTRYID = D.FENTRYID GROUP BY a.FID,C.FNAME,a.FBILLNO,a.FDATE ) a"; var list = this.SelectListPage(sql, where, search.Page, search.PageSize, $@"FDate desc "); return list; } /// /// 销售订单详情 /// /// /// public PageResult GetPurOrderDetil(PagedSearch search) { SearchCondition where = new SearchCondition(); //where.AddSqlCondition("a.FDOCUMENTSTATUS='C' ", true); where.AddSqlCondition($"A.Fid = {search.Condition.Id} ", true); string sql = $@" SELECT A.FID AS 'Fid',C.FNAME AS 'MaterialName',D.FQTY AS 'Qty',E.FSTOCKINQTY AS'StockInQty',E.FREMAINSTOCKINQTY AS 'RemainStockInQty',E.FSTOCKINQTY/D.FQTY AS 'StockInRate' FROM t_PUR_POOrder A WITH(NOLOCK) LEFT JOIN t_PUR_POOrderEntry D WITH(NOLOCK) ON A.FID = D.FID LEFT JOIN t_PUR_POOrderEntry_R E WITH(NOLOCK) ON E.FENTRYID = D.FENTRYID LEFT JOIN T_BD_MATERIAL_L C WITH(NOLOCK) ON C.FMATERIALID = D.FMATERIALID AND C.FLOCALEID= 2052 WHERE 1=1 AND A.Fid = {search.Condition.Id} "; //var list = this.SelectListPage(sql, where, search.Page, search.PageSize, $@"Fid desc "); var result = new PageResult(); result.DataList = this.SelectList(sql); result.TotalCount = result.DataList.Count; return result; } } }