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 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(); }
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); } } }