//搜尋客戶訂單
        public JsonResult SearchCustomerOrder(string CustomerCell)
        {
            MotaiDataEntities dbContext = new MotaiDataEntities();
            tCustomer         cust      = dbContext.tCustomers.Where(c => c.cCellPhone.Equals(CustomerCell)).FirstOrDefault();

            if (cust == null)
            {
                return(Json(new { result = false, msg = "查無此人" }));
            }
            else
            {
                int           custId    = cust.CustomerId;
                List <tOrder> orderlist = dbContext.tOrders.Where(o => o.oCustomerId == custId && o.oCheck == null).ToList();
                List <SearchCustomerOrderModel> searchlist = new List <SearchCustomerOrderModel>();
                foreach (var item in orderlist)
                {
                    SearchCustomerOrderModel search = new SearchCustomerOrderModel();
                    search.orderId       = item.OrderId;
                    search.purchaseDate  = item.oDate.ToString("yyyy/MM/dd");
                    search.WarehouseName = dbContext.tWarehouseNames.Where(wn => wn.WarehouseNameId == item.oWarehouseName).FirstOrDefault().WarehouseName;
                    OrderPayStatus payStatus = orderRespoitory.GetPayStatus(item.OrderId);
                    search.TotalAmount = payStatus.TotalAmount;
                    search.AlreadyPay  = payStatus.AlreadyPay;
                    search.Unpaid      = payStatus.Unpaid;
                    searchlist.Add(search);
                }
                return(Json(new { result = true, list = searchlist }));
            }
        }
Beispiel #2
0
        public OrderPayStatus GetPayStatus(int orderId)
        {
            tOrder order = dbContext.tOrders.Where(o => o.OrderId == orderId).FirstOrDefault();
            List <tOrderDetail> detaillist = dbContext.tOrderDetails.Where(od => od.oOrderId == orderId).ToList();
            List <tOrderPay>    paylist    = dbContext.tOrderPays.Where(op => op.oOrderId == orderId).ToList();
            OrderPayStatus      payStatus  = new OrderPayStatus();

            foreach (var detail in detaillist)
            {
                int price = Convert.ToInt32(dbContext.tProducts.Where(p => p.ProductId == detail.oProductId).FirstOrDefault().pPrice);
                payStatus.TotalAmount += detail.oProductQty * price;
            }
            tPromotion promotion = dbContext.tPromotions.Where(pm => pm.PromotionId == order.oPromotionId).FirstOrDefault();

            if (promotion != null)
            {
                payStatus.TotalAmount -= Convert.ToInt32(promotion.pDiscount);
            }
            if (paylist.Count() == 0)
            {
                payStatus.AlreadyPay = 0;
            }
            else
            {
                foreach (var payitem in paylist)
                {
                    payStatus.AlreadyPay += Convert.ToInt32(payitem.oPayment);
                }
            }
            payStatus.Unpaid = payStatus.TotalAmount - payStatus.AlreadyPay;
            return(payStatus);
        }