예제 #1
0
        public ActionResult Index(PurchaseListFiltersModel filters)
        {
            var todayPurchases    = _purchaseService.GetTodayPurchasesByShopId(_currentUser.Shop.Id, filters.BranchOfficeId).ToList();
            var purchaseListModel = new PurchaseListModel(todayPurchases, filters);

            return(View(purchaseListModel));
        }
예제 #2
0
        private PurchaseListModel FillListModel(Purchase purchase)
        {
            var model = new PurchaseListModel
            {
                Id    = purchase.Id,
                Title = purchase.Title,
                User  = new UserListModel
                {
                    Name = purchase.User.Name,
                    Cpf  = purchase.User.Cpf
                },
                Value            = purchase.Value.FormatValue(),
                RegistrationDate = purchase.RegistrationDate
            };

            if (purchase.Itens != null && purchase.Itens.Any())
            {
                model.Products = purchase.Itens.Select(i => new ItemProductListModel
                {
                    Description = i.Product.Name,
                    Name        = i.Product.Name,
                    UnitPrice   = i.Product.Price.FormatValue(),
                    Stock       = i.Product.Stock,
                    Total       = i.Value.FormatValue(),
                    Amount      = i.Amount
                });
            }

            return(model);
        }
예제 #3
0
        public PurchaseListModel PreparePurchaseListModel(PurchaseSearchRequest p)
        {
            if (p == null)
            {
                throw new ArgumentNullException(nameof(p));
            }

            DateTime?FromDate = null;

            if (!string.IsNullOrWhiteSpace(p.FromPurchaseDate))
            {
                FromDate = Convert.ToDateTime(p.FromPurchaseDate);
            }
            DateTime?ToDate = null;

            if (!string.IsNullOrWhiteSpace(p.ToPurchaseDate))
            {
                ToDate = Convert.ToDateTime(p.ToPurchaseDate);
            }
            int statusId = 0;

            if (!string.IsNullOrWhiteSpace(p.PurchaseStatusId))
            {
                statusId = Int32.Parse(p.PurchaseStatusId);
            }
            int processId = 0;

            if (!string.IsNullOrWhiteSpace(p.PurchaseProcessId))
            {
                processId = Int32.Parse(p.PurchaseProcessId);
            }

            var items = _purchaseService.SearchPurchases(p.VendorName, p.ProductName, FromDate,
                                                         ToDate, p.PurchaseNo, statusId, processId);

            var purchases = CreatePurchaseModelList(items);

            var purchaseListModel = new PurchaseListModel();

            purchaseListModel.Purchases       = purchases;
            purchaseListModel.HasNextPage     = items.HasNextPage;
            purchaseListModel.HasPreviousPage = items.HasPreviousPage;
            purchaseListModel.PageIndex       = items.PageIndex;
            purchaseListModel.PageSize        = items.PageSize;
            purchaseListModel.TotalCount      = items.TotalCount;
            purchaseListModel.TotalPages      = items.TotalPages;
            purchaseListModel.PurchaseStatus  = p.PurchaseStatusId.Equals("0") ? SelectListHelper.GetPurchaseStatus(false, "ALL")
                                                : SelectListHelper.GetPurchaseStatus(true, p.PurchaseStatusName);
            purchaseListModel.PurchaseProcessStatus = p.PurchaseProcessId.Equals("0") ? SelectListHelper.GetPurchaseProcess(false, "ALL")
                                                : SelectListHelper.GetPurchaseProcess(true, p.PurchaseProcessName);
            return(purchaseListModel);
        }
예제 #4
0
        /// <summary>
        /// 采购一览表
        /// </summary>
        /// <param name="currentUser"></param>
        /// <returns></returns>
        public async Task <ResponseObject <PurchaseListModel> > GetPurchaseCountList(RequestGet request, CurrentUser currentUser)
        {
            try
            {
                List <PurchaseCountListModel> queryData = null; //查询结果集对象
                RefAsync <int> totalNumber = -1;                //总记录数
                var            query       = _db.Instance.Queryable <TPSMPurchaseOrderDetailDbModel, TPSMPurchaseOrderMainDbModel
                                                                     , TBMDictionaryDbModel, TBMSupplierFileDbModel, TSMUserAccountDbModel, TBMMaterialFileDbModel>(
                    (t1, t2, t3, t4, t5, t6) => new object[]
                {
                    JoinType.Left, t1.MainId == t2.ID,
                    JoinType.Left, t2.OrderTypeId == t1.ID,
                    JoinType.Left, t1.SupplierId == t4.ID,
                    JoinType.Left, t2.BuyerId == t5.ID,
                    JoinType.Left, t1.MaterialId == t6.ID
                }
                    ).Where((t1, t2, t3, t4, t5, t6) => t2.CompanyId == currentUser.CompanyID)
                                             .OrderBy((t1, t2, t3, t4, t5, t6) => t2.OrderNo);
                //查询条件
                if (request.QueryConditions != null && request.QueryConditions.Count > 0)
                {
                    var conditionals = SqlSugarUtil.GetConditionalModels(request.QueryConditions);

                    foreach (ConditionalModel item in conditionals)
                    {
                        if (item.FieldName.ToLower() == "orderdate" ||
                            item.FieldName.ToLower() == "supplierid" ||
                            item.FieldName.ToLower() == "ordertypeid" ||
                            item.FieldName.ToLower() == "orderno")
                        {
                            item.FieldName = $"t2.{item.FieldName}";
                            continue;
                        }
                    }
                    query.Where(conditionals);
                }
                //排序条件
                if (request.OrderByConditions != null && request.OrderByConditions.Count > 0)
                {
                    foreach (var item in request.OrderByConditions)
                    {
                        var exp = SqlSugarUtil.GetOrderByLambda <TPSMPurchaseOrderMainDbModel>(item.Column);
                        if (exp == null)
                        {
                            continue;
                        }
                        if (item.Condition.ToLower() != "asc" &&
                            item.Condition.ToLower() != "desc")
                        {
                            continue;
                        }
                        query.OrderBy($"t2.{item.Column} {item.Condition}");
                    }
                }

                PurchaseListModel _list = new PurchaseListModel();
                _list.Total_Number = query.Count();
                #region 统计数量
                var PurchaseNum = query.Select((t1, t2, t3, t4, t5, t6) => SqlFunc.AggregateSum(t1.PurchaseNum)).ToList();
                _list.Total_Num = PurchaseNum.Count > 0 ? Convert.ToDecimal(PurchaseNum.ToList()[0]) : 0;
                #endregion
                #region 统计金额
                var PurchaseAmount = query.Select((t1, t2, t3, t4, t5, t6) => SqlFunc.AggregateSum(t1.PurchaseAmount)).ToList();
                _list.Total_Amount = PurchaseAmount.Count > 0 ? Convert.ToDecimal(PurchaseAmount.ToList()[0]) : 0;
                #endregion
                if (request.IsPaging)
                {
                    int skipNum = request.PageSize * (request.PageIndex - 1);
                    queryData = await query
                                .Select((t1, t2, t3, t4, t5, t6) => new PurchaseCountListModel
                    {
                        OrderNo        = t2.OrderNo,
                        OrderTypeId    = t2.OrderTypeId,
                        OrderTypeName  = t3.DicValue,
                        MaterialCode   = t6.MaterialCode,
                        MaterialName   = t6.MaterialName,
                        SupplierId     = Convert.ToInt32(t1.SupplierId),
                        SupplierName   = t4.SupplierName,
                        BuyerId        = t2.BuyerId,
                        BuyerName      = t5.AccountName,
                        PurchaseNum    = t1.PurchaseNum,
                        UnitPrice      = t1.UnitPrice,
                        PurchaseAmount = t1.PurchaseAmount,
                        AuditStatus    = (byte)t2.AuditStatus,
                        OrderDate      = t2.OrderDate
                    }).Skip(skipNum).Take(request.PageSize).ToListAsync();
                }
                else
                {
                    queryData = await query
                                .Select((t1, t2, t3, t4, t5, t6) => new PurchaseCountListModel
                    {
                        OrderNo        = t2.OrderNo,
                        OrderTypeId    = t2.OrderTypeId,
                        OrderTypeName  = t3.DicValue,
                        MaterialCode   = t6.MaterialCode,
                        MaterialName   = t6.MaterialName,
                        SupplierId     = Convert.ToInt32(t1.SupplierId),
                        SupplierName   = t4.SupplierName,
                        BuyerId        = t2.BuyerId,
                        BuyerName      = t5.AccountName,
                        PurchaseNum    = t1.PurchaseNum,
                        UnitPrice      = t1.UnitPrice,
                        PurchaseAmount = t1.PurchaseAmount,
                        AuditStatus    = (byte)t2.AuditStatus,
                        OrderDate      = t2.OrderDate
                    })
                                .ToListAsync();
                }
                _list.List = queryData;
                return(ResponseUtil <PurchaseListModel> .SuccessResult(_list));
            }
            catch (Exception ex)
            {
                return(ResponseUtil <PurchaseListModel>
                       .FailResult(null, $"统计采购列表发生异常{System.Environment.NewLine} {ex.Message}"));
            }
        }