Example #1
0
        public static void CopyFromEntity(DriverOrderDetailDto dto, TeleOrder order, Driver drv = null)
        {
            dto.order_id             = order.TeleOrdID;
            dto.invoice_number       = order.InvoiceNumber;
            dto.order_date           = Common.ToDateFormat(order.OrderDate);
            dto.order_time           = order.OrderTime.ToString(@"hh\:mm");
            dto.delivery_status_id   = order.TeleOrderDeliveries.Count > 0 ? order.TeleOrderDeliveries.Where(x => x.TeleOrdID == order.TeleOrdID).FirstOrDefault().StatusId : 0;
            dto.order_status_id      = order.StatusId;
            dto.agent_admin_phone_no = order.AgentAdmin != null ? order.AgentAdmin.MobileNumber : string.Empty;
            if (order.TeleCustomers.Count > 0)
            {
                var teleConsumer = order.TeleCustomers.Where(x => x.TeleOrdID == order.TeleOrdID).FirstOrDefault();
                if (teleConsumer != null)
                {
                    dto.consumer_name    = teleConsumer.CustomerName;
                    dto.consumer_mobile  = teleConsumer.MobileNumber;
                    dto.consumer_address = teleConsumer.Address;
                    dto.latitude         = teleConsumer.Latitude;
                    dto.longitude        = teleConsumer.Longitude;
                }
            }

            dto.delivery_timeslot_id = Convert.ToInt32(order.DeliverySlotID);
            dto.grand_total          = order.GrantTotal;
        }
        public static OrderInvoiceDto GetOrderInvoiceOrReciept(int user_id, OrdersServices.OrderType order_type, int order_id, bool isConReceipt)
        {
            OrderInvoiceDto response = new OrderInvoiceDto();

            if (order_type == OrdersServices.OrderType.OrderApp)
            {
                using (OrderDao dao = new OrderDao())
                {
                    //Order ord = (isConReceipt ? dao.GetConsumerOrder(user_id, order_id) : dao.GetAgentOrder(user_id, order_id));
                    Order           ord = dao.GetDriverOrder(user_id, order_id);
                    OrderInvoiceDto dto = new OrderInvoiceDto();
                    DriverHelper.CopyFromEntity(dto, ord);
                    response = dto;
                }
            }
            else if (order_type == OrdersServices.OrderType.OrderTelp)
            {
                using (TeleOrderDao dao = new TeleOrderDao())
                {
                    TeleOrder       ord = dao.GetDriverOrder(user_id, order_id);
                    OrderInvoiceDto dto = new OrderInvoiceDto();
                    DriverHelper.CopyFromEntity(dto, ord);
                    response = dto;
                }
            }
            return(response);
        }
Example #3
0
        public ConfirmPickupOrderResponse ConfirmPickupOrder(ConfirmPickupOrderRequest request)
        {
            ConfirmPickupOrderResponse response = new ConfirmPickupOrderResponse();

            try
            {
                if (!AgentAdminServices.CheckAdmin(request.user_id, request.auth_token, response))
                {
                    return(response);
                }
                using (TeleOrderDao dao = new TeleOrderDao())
                {
                    TeleOrder order = dao.FindById(request.order_id, true);
                    order.StatusId = OrdersServices.ID_ORDER_CLOSED;
                    string invNo = InvoiceService.GenerateInvoiceNumber(order.AgentAdmin.AgenID);
                    order.InvoiceNumber = invNo;
                    dao.Update(order);
                    dao.Update(order);
                    OrderPickupHelper.CopyFromEntity(response, order);

                    response.code         = 0;
                    response.has_resource = 1;
                    response.message      = MessagesSource.GetMessage("cnfrm.pickup.order");
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }

            return(response);
        }
Example #4
0
        public static void CopyFromEntity(OrderFullDetailsBossDto dto, TeleOrder order, Driver drv = null)
        {
            dto.order_id      = order.TeleOrdID;
            dto.order_date    = Common.ToDateFormat(order.OrderDate);
            dto.delivery_date = Common.ToDateFormat(order.DeliveryDate.Value);

            //dto.delivery_date = order.DeliveryDate.ToDateTime();
            if (!(order.MDeliverySlot == null))
            {
                dto.time_slot_id   = order.MDeliverySlot.SlotID;
                dto.time_slot_name = order.MDeliverySlot.SlotName;
            }
            dto.invoice_number   = order.InvoiceNumber;
            dto.order_status     = order.StatusId;
            dto.consumer_name    = order.TeleCustomers?.FirstOrDefault()?.CustomerName;
            dto.consumer_mobile  = order.TeleCustomers?.FirstOrDefault()?.MobileNumber;
            dto.consumer_address = order.TeleCustomers?.FirstOrDefault()?.Address;
            dto.grand_total      = order.GrantTotal;
            if (drv != null)
            {
                dto.driver_details = new DriverDetailsBossDto();
                CopyFromEntity(dto.driver_details, drv);
                if (!(order.MOrderStatu == null))
                {
                    dto.driver_details.delivery_status = order.MOrderStatu.OrstID.ToInt();
                }
            }

            List <ProductsBossDto> pdtos = new List <ProductsBossDto>();

            foreach (TeleOrderDetail det in order.TeleOrderDetails)
            {
                ProductsBossDto pdt = new ProductsBossDto();
                pdt.product_name   = det.Product?.ProductName;
                pdt.product_promo  = det.PromoProduct.ToDecimal();
                pdt.quantity       = det.Quantity;
                pdt.shipping_cost  = det.ShippingCharge.ToDecimal();
                pdt.shipping_promo = det.PromoShipping.ToDecimal();
                pdt.sub_total      = det.SubTotal;
                pdt.unit_price     = det.UnitPrice;
                pdt.grand_total    = det.TotalAmount;
                pdtos.Add(pdt);
            }
            dto.product_details = pdtos;
            dto.has_exchange    = (order.TeleOrderPrdocuctExchanges.Count > 0 ? 1 : 0);
            if (dto.has_exchange == 1)
            {
                if (dto.exchange == null)
                {
                    dto.exchange = new List <ExchangeDto>();
                }
                foreach (var item in order.TeleOrderPrdocuctExchanges)
                {
                    ExchangeDto exDto = new ExchangeDto();
                    TeleOrderHelper.CopyFromEntity(exDto, item);
                    dto.exchange.Add(exDto);
                }
            }
        }
 //public static void CopyToEntity(TeleOrderDetail order, PlaceOrderPickupRequest request)
 //{
 //    order.ProdID = request.products.product_id; // user_id, auth_token, grand_total
 //    order.Quantity = request.products.quantity;
 //    order.UnitPrice = request.products.unit_price;
 //    order.SubTotal = request.products.sub_total;
 //    order.PromoProduct = request.products.product_promo;
 //}
 public static void CopyFromEntity(PlaceOrderPickupResponse response, TeleOrder order)
 {
     if (response.order_details == null)
     {
         response.order_details = new PickupOrderResponseDto();
     }
     response.order_details.order_id       = order.TeleOrdID;
     response.order_details.invoice_number = order.InvoiceNumber;
 }
 public static void CopyFromEntity(AddTeleOrderResponse dto, TeleOrder order)
 {
     if (dto.order_details == null)
     {
         dto.order_details = new TeleOrderDto();
     }
     dto.order_details.order_id       = order.TeleOrdID; // order_status
     dto.order_details.invoice_number = order.InvoiceNumber;
     dto.order_details.order_status   = order.MOrderStatu.OrderStatus;
 }
Example #7
0
 private static void PopulateOrder(TeleOrder ord)
 {
     ord.StatusId      = OrdersServices.ID_ORDER_ACCEPTED;//2;
     ord.OrderTime     = DateTime.Now.TimeOfDay;
     ord.OrderDate     = DateTime.Now.Date;
     ord.InvoiceNumber = "";
     ord.CreatedDate   = DateTime.Now;
     ord.UpdatedDate   = ord.CreatedDate;
     ord.DeliveryDate  = null;
     ord.DeliveryType  = false; //0 for pickup 1 for telp
 }
Example #8
0
 private void PopulateOrder(TeleOrder ord, int teleCustID, AddTeleOrderRequest request, AgentAdmin admin)
 {
     ord.StatusId      = OrdersServices.ID_ORDER_ACTIVE;// 1;
     ord.OrderTime     = DateTime.Now.TimeOfDay;
     ord.OrderDate     = DateTime.Now.Date;
     ord.InvoiceNumber = "";
     ord.CreatedDate   = DateTime.Now;
     ord.UpdatedDate   = ord.CreatedDate;
     ord.DeliveryDate  = request.delivery_date;
     ord.DeliveryType  = true; //0 for pickup 1 for telp
     ord.AgadmID       = admin.AgadmID;
     ord.CreatedBy     = admin.AgadmID;
     ord.UpdatedBy     = admin.AgadmID;
 }
Example #9
0
 public static void CopyFromEntity(DriverOrderDetailsDto odt, TeleOrder order)
 {
     odt.order_id       = order.TeleOrdID;
     odt.order_type     = OrdersServices.OrderType.OrderTelp.ToString();
     odt.invoice_number = order.InvoiceNumber;
     odt.order_date     = Common.ToDateFormat(order.OrderDate);
     odt.order_time     = order.OrderTime.ToString();
     if (order.TeleCustomers.Count > 0)
     {
         TeleCustomer cust = order.TeleCustomers.First();
         odt.consumer_address = cust.Address;
         odt.consumer_mobile  = cust.MobileNumber;
         odt.consumer_name    = cust.CustomerName;
     }
     odt.grand_total          = order.GrantTotal;
     odt.delivery_timeslot_id = order.DeliverySlotID ?? 0;
 }
        public static void CopyFromEntity(ConfirmPickupOrderResponse response, TeleOrder order)
        {
            PickupOrderDto odt = new PickupOrderDto();

            response.orders    = odt;
            odt.order_id       = order.TeleOrdID;
            odt.order_date     = Common.ToDateFormat(order.OrderDate);
            odt.invoice_number = order.InvoiceNumber;
            odt.order_status   = order.StatusId;
            odt.grand_total    = order.GrantTotal;

            //dto.oder = odtos.ToArray();
            List <ProductsDto> pdtos = new List <ProductsDto>();

            foreach (TeleOrderDetail det in order.TeleOrderDetails)
            {
                ProductsDto pdt = new ProductsDto();
                pdt.product_id      = det.Product.ProdID;
                pdt.product_name    = det.Product.ProductName;
                pdt.product_promo   = det.PromoProduct ?? 0M;
                pdt.quantity        = det.Quantity;
                pdt.shipping_cost   = det.ShippingCharge ?? 0M;
                pdt.shipping_promo  = det.PromoShipping ?? 0M;
                pdt.refill_price    = det.RefillPrice;
                pdt.refill_promo    = det.PromoRefill;
                pdt.refill_quantity = det.RefillQuantity;
                pdt.sub_total       = det.SubTotal;
                pdt.unit_price      = det.UnitPrice;
                pdtos.Add(pdt);
            }
            odt.products     = pdtos.ToArray();
            odt.has_exchange = (order.TeleOrderPrdocuctExchanges.Count > 0 ? 1 : 0);
            if (odt.has_exchange == 1)
            {
                if (odt.exchange == null)
                {
                    odt.exchange = new List <ExchangeDto>();
                }
                foreach (var item in order.TeleOrderPrdocuctExchanges)
                {
                    ExchangeDto exDto = new ExchangeDto();
                    TeleOrderHelper.CopyFromEntity(exDto, item);
                    odt.exchange.Add(exDto);
                }
            }
        }
Example #11
0
        public static DriverProductsDto[] CopyFromEntity(TeleOrder teleOrder)
        {
            List <DriverProductsDto> pdtos = new List <DriverProductsDto>();

            foreach (TeleOrderDetail det in teleOrder.TeleOrderDetails)
            {
                DriverProductsDto pdt = new DriverProductsDto();
                pdt.product_id      = det.Product.ProdID;
                pdt.product_name    = det.Product.ProductName;
                pdt.product_promo   = det.PromoProduct.HasValue ? det.PromoProduct.Value : 0;
                pdt.quantity        = det.Quantity;
                pdt.shipping_cost   = det.ShippingCharge.HasValue ? det.ShippingCharge.Value : 0;
                pdt.shipping_promo  = det.PromoShipping.HasValue ? det.PromoShipping.Value : 0;
                pdt.refill_price    = det.RefillPrice;
                pdt.refill_promo    = det.PromoRefill;
                pdt.refill_quantity = det.RefillQuantity;
                pdt.sub_total       = det.SubTotal;
                pdt.unit_price      = det.UnitPrice;
                pdtos.Add(pdt);
            }
            return(pdtos.ToArray());
        }
Example #12
0
        public static void CopyFromEntity(OrderInvoiceDto dto, TeleOrder order)
        {
            dto.order_id       = order.TeleOrdID;
            dto.invoice_number = order.InvoiceNumber;
            dto.order_date     = Common.ToDateFormat(order.OrderDate);
            if (order.TeleCustomers.Count > 0)
            {
                TeleCustomer cust = order.TeleCustomers.First();
                dto.consumer_name    = cust.CustomerName;
                dto.consumer_mobile  = cust.MobileNumber;
                dto.consumer_address = cust.Address;
            }
            List <ProductsDto> pdtos            = new List <ProductsDto>();
            decimal            sumPromoProduct  = 0;
            decimal            sumPromoShipping = 0;
            decimal            sumPromoRefill   = 0;
            decimal            sumPromoExchange = 0;

            foreach (TeleOrderDetail det in order.TeleOrderDetails)
            {
                ProductsDto pdt = new ProductsDto();
                pdt.product_id      = det.Product.ProdID;
                pdt.product_name    = det.Product.ProductName;
                pdt.product_promo   = det.PromoProduct ?? 0.0M;
                pdt.quantity        = det.Quantity;
                pdt.shipping_cost   = det.ShippingCharge ?? 0M;
                pdt.shipping_promo  = det.PromoShipping ?? 0M;
                pdt.sub_total       = det.SubTotal;
                pdt.unit_price      = det.UnitPrice;
                pdt.refill_price    = det.RefillPrice;
                pdt.refill_promo    = det.PromoRefill;
                pdt.refill_quantity = det.RefillQuantity;
                pdtos.Add(pdt);
                if (order.DeliveryType)
                {
                    if (det.PromoProduct != Convert.ToDecimal(0))
                    {
                        sumPromoShipping += det.PromoShipping ?? 0M;
                    }
                    if (det.RefillQuantity > 0)
                    {
                        sumPromoShipping += det.PromoShipping ?? 0M;
                    }
                }
                sumPromoProduct += det.PromoProduct ?? 0M;
                sumPromoRefill  += det.PromoRefill;
                dto.has_exchange = (order.TeleOrderPrdocuctExchanges.Count > 0 ? 1 : 0);
                if (dto.has_exchange == 1)
                {
                    if (dto.exchange == null)
                    {
                        dto.exchange = new List <Pertamina.LPG.API.DTOs.Orders.ExchangeDto>();
                    }
                    foreach (var item in order.TeleOrderPrdocuctExchanges)
                    {
                        Pertamina.LPG.API.DTOs.Orders.ExchangeDto exDto = new Pertamina.LPG.API.DTOs.Orders.ExchangeDto();
                        TeleOrderHelper.CopyFromEntity(exDto, item);
                        dto.exchange.Add(exDto);
                        sumPromoExchange += exDto.exchange_promo_price;
                        if (order.DeliveryType)
                        {
                            sumPromoShipping += det.PromoShipping ?? 0M;
                        }
                    }
                }
            }
            dto.agency_id       = order.AgentAdmin.Agency.AgenID;
            dto.agency_name     = order.AgentAdmin.Agency.AgencyName;
            dto.agency_address  = order.AgentAdmin.Agency.MRegion.RegionName;
            dto.agency_location = order.AgentAdmin.Agency.MRegion.RegionName;
            //dto.agency_address = order.AgentAdmin.Agency.Region;
            //dto.agency_location = order.AgentAdmin.Agency.Region;
            dto.grand_total               = order.GrantTotal;
            dto.grand_discount            = (Math.Abs(sumPromoProduct) + Math.Abs(sumPromoShipping) + Math.Abs(sumPromoRefill) + Math.Abs(sumPromoExchange)) * -1;
            dto.grand_total_with_discount = dto.grand_total + Math.Abs(dto.grand_discount);
            dto.products = pdtos.ToArray();
        }
Example #13
0
 public void Insert(TeleOrder ord)
 {
     _context.TeleOrders.Add(ord);
     _context.SaveChanges();
 }
        public static void CopyFromEntity(ConfirmTeleOrderResponse response, TeleOrder order)
        {
            TeleOrderFullDetailsDto dto = new TeleOrderFullDetailsDto();

            response.orders        = dto;
            dto.order_id           = order.TeleOrdID;
            dto.order_date         = Common.ToDateFormat(order.OrderDate);
            dto.order_time         = order.OrderTime;
            dto.delivery_date      = Common.ToDateFormat(order.DeliveryDate ?? DateTime.MinValue);
            dto.delivery_time_slot = order.MDeliverySlot.SlotName;
            dto.invoice_number     = order.InvoiceNumber;
            dto.order_status       = order.StatusId;
            if (order.TeleCustomers.Count > 0)
            {
                TeleCustomer cust = order.TeleCustomers.First();
                dto.consumer_name     = cust.CustomerName;
                dto.consumer_mobile   = cust.MobileNumber;
                dto.consumer_address  = cust.Address;
                dto.consumer_location = null;
            }
            dto.driver = new DriverDetailsDto();
            if (order.Driver != null)
            {
                dto.driver = new DriverDetailsDto();
                CopyDriverFromEntity(dto.driver, order.Driver);
            }

            List <ProductsDto> pdtos = new List <ProductsDto>();

            foreach (TeleOrderDetail det in order.TeleOrderDetails)
            {
                ProductsDto pdt = new ProductsDto();
                pdt.product_id      = det.Product.ProdID;
                pdt.product_name    = det.Product.ProductName;
                pdt.product_promo   = det.PromoProduct ?? 0.0M;
                pdt.quantity        = det.Quantity;
                pdt.shipping_cost   = det.ShippingCharge ?? 0.0M;
                pdt.shipping_promo  = det.PromoShipping ?? 0.0M;
                pdt.refill_price    = det.RefillPrice;
                pdt.refill_promo    = det.PromoRefill;
                pdt.refill_quantity = det.RefillQuantity;
                pdt.sub_total       = det.SubTotal;
                pdt.unit_price      = det.UnitPrice;
                pdt.grand_total     = det.TotalAmount;
                pdtos.Add(pdt);
            }
            dto.grand_total  = order.GrantTotal;
            dto.products     = pdtos.ToArray();
            dto.has_exchange = (order.TeleOrderPrdocuctExchanges.Count > 0 ? 1 : 0);
            if (dto.has_exchange == 1)
            {
                if (dto.exchange == null)
                {
                    dto.exchange = new List <ExchangeDto>();
                }
                foreach (var item in order.TeleOrderPrdocuctExchanges)
                {
                    ExchangeDto exDto = new ExchangeDto();
                    CopyFromEntity(exDto, item);
                    dto.exchange.Add(exDto);
                }
            }
        }
Example #15
0
        public PlaceOrderPickupResponse PlacePickupOrder(PlaceOrderPickupRequest request)
        {
            PlaceOrderPickupResponse response = new PlaceOrderPickupResponse();

            try
            {
                AgentAdmin admin = AgentAdminServices.GetAuthAdmin(request.user_id, request.auth_token, response);
                if (admin == null)
                {
                    return(response);
                }

                UpdatePickupOrderRequest(request); // To update request from mobile, Reason : not passing expected values from mobile

                TeleOrder ord = new TeleOrder();
                PopulateOrder(ord);
                ord.AgadmID   = admin.AgadmID;
                ord.CreatedBy = admin.AgadmID;
                ord.UpdatedBy = admin.AgadmID;
                AddProductsToOrder(ord, request.products);
                using (TeleOrderDao dao = new TeleOrderDao())
                {
                    if (request.has_exchange)
                    {
                        if (request.exchange == null)
                        {
                            MakeInvalidExchangeInputResponse(response);
                            return(response);
                        }
                        foreach (ExchangeDto item in request.exchange)
                        {
                            ProductExchange           pxg  = dao.FindProductExchangeById(item.exchange_id);
                            TeleOrderPrdocuctExchange opex = new TeleOrderPrdocuctExchange();
                            if (pxg == null)
                            {
                                MakeInvalidExchangeInputResponse(response);
                                return(response);
                            }
                            opex.ProdID             = pxg.ProdID;
                            opex.ExchangePrice      = item.exchange_price;
                            opex.CreatedDate        = DateTime.Now;
                            opex.ExchangePromoPrice = item.exchange_promo_price * item.exchange_quantity;
                            opex.ExchangeQuantity   = item.exchange_quantity;
                            opex.ExchangeWith       = item.exchange_with;
                            opex.StatusId           = true;//TODO
                            //ord.GrantTotal -= (opex.ExchangePrice - opex.ExchangePromoPrice) * opex.ExchangeQuantity;
                            //opex.TeleOrder = ord;
                            opex.SubTotal = item.exchange_price * item.exchange_quantity;
                            //ord.GrandTotal -= (opex.ExchangePrice - opex.ExchangePromoPrice) * opex.ExchangeQuantity;

                            var product = request.products.Where(p => p.product_id == pxg.ProdID).FirstOrDefault();
                            if (product == null)
                            {
                                //MakeInvalidExchangeInputResponse(response);
                                response.code         = 1;
                                response.has_resource = 0;
                                response.message      = "Cannot find product with id " + pxg.ProdID + " in the products array";
                                return(response);
                            }
                            opex.TotalAmount = opex.SubTotal + opex.ExchangePromoPrice;
                            ord.TeleOrderPrdocuctExchanges.Add(opex);
                            //ord.ShippingCharge += (product.shipping_cost * item.exchange_quantity);
                            //ord.PromoShipping += (product.shipping_promo * item.exchange_quantity);
                            ord.NumberOfProducts += item.exchange_quantity;
                            ord.ExchangeSubTotal += opex.SubTotal;
                            ord.PromoExchange    += opex.ExchangePromoPrice;
                            ord.GrantTotal       += opex.TotalAmount;
                        }
                    }
                    int agId = admin.AgenID;
                    lock (InvoiceService.monitor)
                    {
                        ord.InvoiceNumber = InvoiceService.GenerateInvoiceNumber(agId);
                        dao.Insert(ord);
                    }

                    OrderPickupHelper.CopyFromEntity(response, ord);
                    response.code         = 0;
                    response.has_resource = 1;
                    response.message      = MessagesSource.GetMessage("place.pickup.order");
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }

            return(response);
        }
Example #16
0
        public ConfirmTeleOrderResponse ConfirmTeleOrder(ConfirmTeleOrderRequest request)
        {
            ConfirmTeleOrderResponse response = new ConfirmTeleOrderResponse();

            try
            {
                if (!AgentAdminServices.CheckAdmin(request.user_id, request.auth_token, response))
                {
                    return(response);
                }
                using (TeleOrderDao dao = new TeleOrderDao())
                {
                    TeleOrder order = dao.FindById(request.order_id, true);
                    if (order == null)
                    {
                        MakeNoTeleOrderFoundResponse(response);
                        return(response);
                    }
                    order.StatusId = OrdersServices.ID_ORDER_ACCEPTED;//2;
                    order.DrvrID   = request.driver_id;
                    //Driver drv = order.Driver;
                    //int agId = drv.AgenID;
                    Driver drv = null;
                    using (DriverDao ddao = new DriverDao())
                    {
                        drv = ddao.FindById(request.driver_id);
                        if (drv == null)
                        {
                            DriverServices.MakeNoDriverResponse(response);
                            return(response);
                        }
                        TeleOrderDelivery odel = new TeleOrderDelivery();
                        odel.DrvrID       = drv.DrvrID;
                        odel.AgadmID      = request.user_id;
                        odel.CreatedDate  = DateTime.Now;
                        odel.DeliveryDate = order.DeliveryDate;
                        odel.AcceptedDate = DateTime.Now;
                        odel.StatusId     = OrdersServices.DELIVERY_STATUS_ASSIGNED;//1;
                        odel.TeleOrder    = order;
                        order.TeleOrderDeliveries.Add(odel);
                    }
                    lock (InvoiceService.monitor)
                    {
                        string invNo = InvoiceService.GenerateInvoiceNumber(drv.AgenID);
                        order.InvoiceNumber = invNo;
                        dao.Update(order);
                    }
                    TeleOrderHelper.CopyFromEntity(response, order);
                    using (ConsumerReviewDao conReviewDao = new ConsumerReviewDao())
                    {
                        List <ConsumerReview> conReview = new List <ConsumerReview>();
                        conReview = conReviewDao.GetReviewByDriver(request.driver_id);
                        response.orders.driver.driver_rating = conReview.Count > 0 ? Convert.ToDecimal(conReview.Average(x => x.Rating)) : 0;
                    }

                    if (order.DeliveryDate.HasValue && order.DeliveryDate.Value.ToShortDateString() == DateTime.Now.ToShortDateString())
                    {
                        int orderCount = dao.GetAssignedOrderCount(request.driver_id, OrdersServices.ID_ORDER_ACCEPTED);
                        using (OrderDao ordDao = new OrderDao())
                        {
                            orderCount += ordDao.GetAssignedOrderCount(request.driver_id, OrdersServices.ID_ORDER_ACCEPTED);
                        }
                        _orderService.ReadAndSendPushNotification(OrdersServices.APPSETTING_MSG_TO_ASSIGNED_DRIVER, OrdersServices.APPSETTING_TITLE_FOR_ASSIGNED_DRIVER, drv.AppToken, request.order_id, request.driver_id, orderCount, PushMessagingService.APPSETTING_APPLICATION_ID_DRIVER, PushMessagingService.APPSETTING_SENDER_ID_DRIVER, (int)PushMessagingService.PushType.TypeOne);
                    }

                    response.code         = 0;
                    response.has_resource = 1;
                    response.message      = MessagesSource.GetMessage("cnfrm.tele.order");
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }

            return(response);
        }
Example #17
0
        public AddTeleOrderResponse AddTeleOrder(AddTeleOrderRequest request)
        {
            AddTeleOrderResponse response = new AddTeleOrderResponse();

            try
            {
                AgentAdmin admin = AgentAdminServices.GetAuthAdmin(request.user_id, request.auth_token, response);
                if (admin == null)
                {
                    return(response);
                }

                if (request.delivery_date <= DateTime.MinValue)
                {
                    _orderService.MakeInvalidDeliveryDateFormat(response);
                    return(response);
                }

                UpdateTeleOrderRequest(request); // To update request from mobile, Reason : not passing expected values from mobile

                TeleCustomer cons = new TeleCustomer();
                cons.Address      = request.customer_details.customer_address;
                cons.CustomerName = request.customer_details.customer_name;
                cons.MobileNumber = request.customer_details.customer_mobile;
                cons.StatusId     = true;
                //cons.Latitude = request.customer_details.latitude;
                //cons.Longitude = request.customer_details.longitude;
                cons.CreatedBy   = admin.AgadmID;
                cons.CreatedDate = DateTime.Now;

                TeleOrder ord = new TeleOrder();
                PopulateOrder(ord, cons.TeleCustID, request, admin);
                AddProductsToOrder(ord, request.products);

                ord.DrvrID         = request.driver_id;
                ord.DeliverySlotID = (short)request.time_slot_id;
                //ord.DeliveredDate = null;

                using (TeleOrderDao odao = new TeleOrderDao())
                {
                    if (request.has_exchange)
                    {
                        if (request.exchange == null)
                        {
                            _orderService.MakeInvalidExchangeInputResponse(response);
                            return(response);
                        }

                        foreach (ExchangeDto exdto in request.exchange)
                        {
                            TeleOrderPrdocuctExchange opex = new TeleOrderPrdocuctExchange();
                            ProductExchange           pxg  = odao.FindProductExchangeById(exdto.exchange_id);
                            if (pxg == null)
                            {
                                _orderService.MakeInvalidExchangeInputResponse(response);
                                return(response);
                            }
                            opex.ProdID             = pxg.ProdID;
                            opex.ExchangePrice      = exdto.exchange_price;
                            opex.CreatedDate        = DateTime.Now;
                            opex.ExchangePromoPrice = exdto.exchange_promo_price * exdto.exchange_quantity;
                            opex.ExchangeQuantity   = exdto.exchange_quantity;
                            opex.ExchangeWith       = exdto.exchange_with;
                            opex.StatusId           = true;//TODO
                            opex.SubTotal           = exdto.exchange_price * exdto.exchange_quantity;
                            //ord.GrandTotal -= (opex.ExchangePrice - opex.ExchangePromoPrice) * opex.ExchangeQuantity;

                            var product = request.products.Where(p => p.product_id == pxg.ProdID).FirstOrDefault();
                            if (product == null)
                            {
                                //MakeInvalidExchangeInputResponse(response);
                                response.code         = 1;
                                response.has_resource = 0;
                                response.message      = "Cannot find product with id " + pxg.ProdID + " in the products array";
                                return(response);
                            }
                            opex.TotalAmount = opex.SubTotal + opex.ExchangePromoPrice + (product.shipping_cost * exdto.exchange_quantity) + (product.shipping_promo * exdto.exchange_quantity);
                            ord.TeleOrderPrdocuctExchanges.Add(opex);
                            ord.ShippingCharge   += (product.shipping_cost * exdto.exchange_quantity);
                            ord.PromoShipping    += (product.shipping_promo * exdto.exchange_quantity);
                            ord.NumberOfProducts += exdto.exchange_quantity;
                            ord.ExchangeSubTotal += opex.SubTotal;
                            ord.PromoExchange    += opex.ExchangePromoPrice;
                            ord.GrantTotal       += opex.TotalAmount;
                        }
                    }
                    //cons.TeleOrder = ord;
                    odao.Insert(ord);
                    cons.TeleOrdID = ord.TeleOrdID;
                    using (TeleOrderCustomerDao tcDao = new TeleOrderCustomerDao())
                    {
                        tcDao.Insert(cons);
                    }
                    ord = odao.FindById(ord.TeleOrdID, true);
                    TeleOrderHelper.CopyFromEntity(response, ord);
                    response.code         = 0;
                    response.has_resource = 1;
                    response.message      = MessagesSource.GetMessage("add.tele.order");
                }
            }
            catch (Exception ex)
            {
                response.MakeExceptionResponse(ex);
            }

            return(response);
        }
Example #18
0
 public void Update(TeleOrder order)
 {
     _context.Entry(order).State = System.Data.EntityState.Modified;
     _context.SaveChanges();
 }
Example #19
0
        private void AddProductsToOrder(TeleOrder ord, ProductsDto[] products)
        {
            if (ord.ShippingCharge == null)
            {
                ord.ShippingCharge = 0;
            }
            if (ord.PromoShipping == null)
            {
                ord.PromoShipping = 0;
            }
            if (ord.PromoProduct == null)
            {
                ord.PromoProduct = 0;
            }

            foreach (var prd in products)
            {
                TeleOrderDetail od = new TeleOrderDetail();
                od.TeleOrder   = ord;
                od.ProdID      = prd.product_id;
                od.CreatedDate = ord.CreatedDate;

                od.Quantity       = prd.quantity;
                od.UnitPrice      = prd.unit_price;
                od.SubTotal       = prd.unit_price * prd.quantity; //prd.sub_total;
                od.PromoProduct   = prd.product_promo;
                od.ShippingCharge = prd.shipping_cost;
                od.PromoShipping  = prd.shipping_promo;

                od.RefillQuantity = prd.refill_quantity;
                od.RefillPrice    = prd.refill_price;
                od.PromoRefill    = prd.refill_promo;
                od.RefillSubTotal = prd.refill_price * prd.refill_quantity;

                if (prd.quantity > 0)
                {
                    ord.ShippingCharge += (prd.shipping_cost * prd.quantity);
                    ord.PromoShipping  += (prd.shipping_promo * prd.quantity);
                    od.TotalAmount      = od.SubTotal + prd.product_promo + (prd.shipping_promo * prd.quantity) + (prd.shipping_cost * prd.quantity); //prd.sub_total;
                }
                if (prd.refill_quantity > 0)
                {
                    ord.ShippingCharge  += (prd.shipping_cost * prd.quantity);
                    ord.PromoShipping   += (prd.shipping_promo * prd.quantity);
                    od.RefillTotalAmount = od.RefillSubTotal + prd.refill_promo + (prd.shipping_promo * prd.refill_quantity) + (prd.shipping_cost * prd.refill_quantity); //prd.sub_total;
                }
                ord.SubTotal        += od.SubTotal;
                ord.RefillSubTotal  += od.RefillSubTotal;
                ord.PromoProduct    += od.PromoProduct.Value;
                ord.PromoRefill     += od.PromoRefill;
                ord.GrantTotal      += (od.TotalAmount + od.RefillTotalAmount); //prd.sub_total;
                ord.NumberOfProducts = prd.quantity + prd.refill_quantity;
                ord.TeleOrderDetails.Add(od);


                //TeleOrderDetail od = new TeleOrderDetail();
                //od.TeleOrder = ord;
                //od.ProdID = prd.product_id;
                //od.CreatedDate = ord.CreatedDate;
                //od.PromoProduct = (prd.unit_price - prd.product_promo) * prd.quantity;
                //od.PromoShipping = (prd.shipping_cost - prd.shipping_promo) * prd.quantity;
                //od.ShippingCharge = prd.shipping_cost;
                //od.SubTotal = prd.sub_total;
                //od.Quantity = prd.quantity;
                //od.UnitPrice = prd.unit_price;
                //ord.SubTotal += prd.sub_total;
                //ord.ShippingCharge += prd.shipping_cost * prd.quantity;
                //ord.PromoProduct += (prd.product_promo - prd.unit_price) * prd.quantity;
                //ord.PromoShipping += (prd.shipping_promo - prd.shipping_cost) * prd.quantity;
                //ord.TeleOrderDetails.Add(od);
                //ord.GrantTotal += (prd.unit_price - prd.product_promo + prd.shipping_cost - prd.shipping_promo) * prd.quantity;
            }
        }
Example #20
0
        public static void CopyFromEntity(OrderFullDetailsDto dto, TeleOrder teleOrder, Driver drv = null)
        {
            dto.order_id           = teleOrder.TeleOrdID;
            dto.delivery_date      = Common.ToDateFormat(teleOrder.DeliveryDate.HasValue ? teleOrder.DeliveryDate.Value : DateTime.MinValue);
            dto.delivery_time_slot = teleOrder.MDeliverySlot.SlotName;
            dto.invoice_number     = teleOrder.InvoiceNumber;
            dto.order_status       = teleOrder.StatusId;
            if (teleOrder.TeleCustomers.Count > 0)
            {
                var teleConsumer = teleOrder.TeleCustomers.Where(x => x.TeleOrdID == teleOrder.TeleOrdID).FirstOrDefault();
                if (teleConsumer != null)
                {
                    dto.consumer_name     = teleConsumer.CustomerName;
                    dto.consumer_mobile   = teleConsumer.MobileNumber;
                    dto.consumer_address  = teleConsumer.Address;
                    dto.consumer_location = teleConsumer.Address;
                    //dto.latitude = teleConsumer.Latitude;
                    //dto.longitude = teleConsumer.Longitude;
                }
            }

            dto.driver = new DriverDetailsDto();
            if (teleOrder.TeleOrderDetails.Count > 0)
            {
                TeleOrderDetail od = teleOrder.TeleOrderDetails.First();
                dto.driver = new DriverDetailsDto();
                if (drv == null)
                {
                    drv = teleOrder.Driver;
                }
                CopyFromEntity(dto.driver, drv);
                //dto.driver.driver_id = od.Driver.DrvrID;
                //dto.driver.driver_image = od.Driver.ProfileImage;
                //dto.driver.driver_mobile = od.Driver.MobileNumber;
                //dto.driver.driver_name = od.Driver.DriverName;
                ////dto.driver.driver_rating = od.Driver.ra
            }

            List <ProductsDto> pdtos = new List <ProductsDto>();

            foreach (TeleOrderDetail det in teleOrder.TeleOrderDetails)
            {
                ProductsDto pdt = new ProductsDto();
                pdt.product_id      = det.Product.ProdID;
                pdt.product_name    = det.Product.ProductName;
                pdt.product_promo   = det.PromoProduct.HasValue ? det.PromoProduct.Value : 0;
                pdt.quantity        = det.Quantity;
                pdt.shipping_cost   = det.ShippingCharge.HasValue ? det.ShippingCharge.Value : 0;
                pdt.shipping_promo  = det.PromoShipping.HasValue ? det.PromoShipping.Value : 0;
                pdt.sub_total       = det.SubTotal;
                pdt.unit_price      = det.UnitPrice;
                pdt.refill_price    = det.RefillPrice;
                pdt.refill_promo    = det.PromoRefill;
                pdt.refill_quantity = det.RefillQuantity;
                pdtos.Add(pdt);
            }
            dto.grand_total  = teleOrder.GrantTotal;
            dto.products     = pdtos.ToArray();
            dto.has_exchange = (teleOrder.TeleOrderPrdocuctExchanges.Count > 0 ? 1 : 0);
            if (dto.has_exchange == 1)
            {
                if (dto.exchange == null)
                {
                    dto.exchange = new List <ExchangeDto>();
                }
                foreach (var item in teleOrder.TeleOrderPrdocuctExchanges)
                {
                    ExchangeDto exDto = new ExchangeDto();
                    TeleOrderHelper.CopyFromEntity(exDto, item);
                    dto.exchange.Add(exDto);
                }
            }
        }