Beispiel #1
0
        public async Task <ApiResult <WaitingOrderDto> > GetWaitingOrderDetailAsync(string orderId)
        {
            var order = await _context.Orders.FindAsync(orderId);

            if (order == null || order.TransactionStatusId != GlobalProperties.WaitingTransactionId)
            {
                return(new ApiResult <WaitingOrderDto>(HttpStatusCode.NotFound, $"Không tìm thấy đơn hàng chờ có mã: {orderId}"));
            }
            if (order.TransactionStatusId == GlobalProperties.WaitingTransactionId)
            {
                var totalAmount = await(from od in _context.OrderDetails
                                        where od.OrderId == order.Id
                                        select od.UnitPrice * od.Quantity).SumAsync();
                var customerDebt = await _context.Orders.Where(x => x.CustomerId == order.CustomerId && x.TransactionStatusId != GlobalProperties.CancelTransactionId &&
                                                               x.TransactionStatusId != GlobalProperties.WaitingTransactionId).SumAsync(x => x.TotalAmount) +
                                   await _context.PaymentVouchers.Where(x => x.CustomerId == order.CustomerId).SumAsync(x => x.Paid) -
                                   await _context.ReceiptVouchers.Where(x => x.CustomerId == order.CustomerId).SumAsync(x => x.Received);

                var resultOrder = await(from o in _context.Orders
                                        join ts in _context.TransactionStatuses on o.TransactionStatusId equals ts.Id
                                        join pm in _context.PaymentStatuses on o.PaymentStatusId equals pm.Id
                                        join customer in _context.Customers on o.CustomerId equals customer.Id
                                        into CustomerGroup
                                        from c in CustomerGroup.DefaultIfEmpty()
                                        where o.Id == orderId && o.TransactionStatusId == GlobalProperties.WaitingTransactionId
                                        select new WaitingOrderDto()
                {
                    Id = o.Id,
                    CustomerAddress = string.IsNullOrEmpty(c.Address)?o.CustomerAddress:c.Address,
                    CustomerId      = c.Id,
                    CustomerName    = string.IsNullOrEmpty(c.Name)?o.CustomerName:c.Name,
                    CustomerPhone   = !string.IsNullOrEmpty(c.PhoneNumber) ? c.PhoneNumber
                                                 : (!string.IsNullOrEmpty(_context.AppUsers.Where(x => x.Id == c.AppUserId).SingleOrDefault().PhoneNumber)?
                                                    _context.AppUsers.Where(x => x.Id == c.AppUserId).SingleOrDefault().PhoneNumber:o.CustomerPhone),
                    DateCreated  = o.DateCreated,
                    OrderDetails = (from od in _context.OrderDetails
                                    join product in _context.Products on od.ProductId equals product.Id
                                    into ProductGroup
                                    from p in ProductGroup.DefaultIfEmpty()
                                    where od.OrderId == o.Id
                                    select new OrderDetailsDto()
                    {
                        Id = od.Id,
                        Quantity = od.Quantity,
                        ProductId = od.ProductId,
                        ProductName = p.Name,
                        UnitPrice = od.UnitPrice,
                        ServiceName = od.ServiceName
                    }).ToList(),
                    TotalAmount  = totalAmount,
                    CustomerDebt = customerDebt
                }).SingleOrDefaultAsync();
                return(new ApiResult <WaitingOrderDto>(HttpStatusCode.OK, resultOrder));
            }
            return(new ApiResult <WaitingOrderDto>(HttpStatusCode.NotFound, $"Không tìm thấy đơn hàng chờ có mã: {orderId}"));
        }
Beispiel #2
0
        public async Task <ApiResult <ImportPurchaseOrderHistoriesDto> > GetImportPurchaseOrderHistory(string purchaseOrderId)
        {
            var checkPurchaseOrder =
                await _context.PurchaseOrders.Where(x => x.Id == purchaseOrderId).SingleOrDefaultAsync();

            if (checkPurchaseOrder == null)
            {
                return(new ApiResult <ImportPurchaseOrderHistoriesDto>(HttpStatusCode.NotFound, $"Không tìm thấy phiếu nhập hàng có mã: {purchaseOrderId}"));
            }
            var purchaseOrderHistory = await(from grn in _context.GoodReceivedNotes
                                             join w in _context.Warehouses on grn.WarehouseId equals w.Id
                                             join sa in _context.StockActions on grn.StockActionId equals sa.Id
                                             join employee in _context.Employees on grn.EmployeeId equals employee.Id
                                             into EmployeeGroup
                                             from e in EmployeeGroup.DefaultIfEmpty()
                                             where grn.PurchaseOrderId == purchaseOrderId
                                             select new ImportPurchaseOrderHistoriesDto()
            {
                Id              = grn.Id,
                Description     = grn.Description,
                ImportDate      = grn.ImportDate,
                EmployeeName    = e.Name,
                WarehouseName   = w.Name,
                StockActionName = sa.Name,
                Products        = (from grnd in _context.GoodsReceivedNoteDetails
                                   join product in _context.Products on grnd.ProductId equals product.Id
                                   into ProductGroup
                                   from p in ProductGroup.DefaultIfEmpty()
                                   where grnd.GoodsReceivedNoteId == grn.Id
                                   select new ImportPurchaseOrderHistoryDetailsDto()
                {
                    ProductId = grnd.ProductId,
                    Quantity = grnd.Quantity,
                    ProductName = p.Name
                }).ToList()
            }).SingleOrDefaultAsync();

            return(new ApiResult <ImportPurchaseOrderHistoriesDto>(HttpStatusCode.OK, purchaseOrderHistory));
        }