public static CustomerPaymentDTO ConvertToCustomerPaymentDto(ProductOrder productOrder, List <CustomerPaymentTransaction> customerPayments)
        {
            //TODO : Vimal please verify this logic whether we are showing sum of all order amount or single at a time for payments.
            // Means order payment can be done partially multiple time for single order or only one time ?
            decimal?totalCrAmountOfOrder = customerPayments.Sum(x => x.PaymentCrAmount);
            CustomerPaymentTransaction lastPaymentByCustomer = customerPayments.OrderByDescending(x => x.CustomerPaymentId).FirstOrDefault();

            CustomerPaymentDTO customerPaymentDTO = new CustomerPaymentDTO();

            customerPaymentDTO.CustomerId      = productOrder.Customer.CustomerId;
            customerPaymentDTO.CustomerName    = productOrder.Customer.Name;
            customerPaymentDTO.ProductName     = productOrder.ProductOrderDetails.FirstOrDefault().ProductSiteMapping.Product.ProductName;
            customerPaymentDTO.OrderNumber     = productOrder.OrderNumber;
            customerPaymentDTO.OrderId         = productOrder.OrderId;
            customerPaymentDTO.PaidAmount      = totalCrAmountOfOrder.Value;
            customerPaymentDTO.TotalAmount     = productOrder.OrderTotalPrice.GetValueOrDefault();
            customerPaymentDTO.PaymentCrAmount = totalCrAmountOfOrder.Value;
            customerPaymentDTO.PaymentDate     = lastPaymentByCustomer != null ? lastPaymentByCustomer.PaymentDate : DateTime.Now;
            PaymentMode modeOfPay = PaymentMode.Cash;

            if (lastPaymentByCustomer != null)
            {
                Enum.TryParse(lastPaymentByCustomer.PaymentMode, out modeOfPay);
            }
            customerPaymentDTO.PaymentMode       = modeOfPay;
            customerPaymentDTO.PaymentReceivedBy = lastPaymentByCustomer != null ? lastPaymentByCustomer.PaymentReceivedBy : "NA";
            customerPaymentDTO.Ref2 = lastPaymentByCustomer != null ? lastPaymentByCustomer.Ref2 : "NA";
            customerPaymentDTO.CustomerPaymentId = lastPaymentByCustomer != null ? lastPaymentByCustomer.CustomerPaymentId : 0;
            customerPaymentDTO.PaymentComments   = lastPaymentByCustomer != null ? lastPaymentByCustomer.Ref1 : "No Comments mentioned";
            customerPaymentDTO.OrderStatus       = productOrder.ProductOrderDetails.FirstOrDefault().OrderStatus.ToString();
            return(customerPaymentDTO);
        }
Exemplo n.º 2
0
        public void UpdateCustomerPayment(CustomerPaymentDTO customerPaymentDTO)
        {
            CustomerPaymentTransaction customerPaymentTransaction = null;

            CustomerPaymentConvertor.ConvertToCustomerPaymentEntity(ref customerPaymentTransaction, customerPaymentDTO, true);
            unitOfWork.CustomerPaymentRepository.Update(customerPaymentTransaction);
            unitOfWork.SaveChanges();
        }
Exemplo n.º 3
0
        public void AddCustomerPayment(CustomerPaymentDTO customerPaymentDTO)
        {
            CustomerPaymentTransaction customerPaymentTransaction = new CustomerPaymentTransaction();

            customerPaymentTransaction.CustomerPaymentId = unitOfWork.DashboardRepository.NextNumberGenerator("CustomerPaymentTransaction");
            CustomerPaymentConvertor.ConvertToCustomerPaymentEntity(ref customerPaymentTransaction, customerPaymentDTO, false);
            unitOfWork.CustomerPaymentRepository.Add(customerPaymentTransaction);
            this.UpdateCustomerWallet(customerPaymentDTO);
            unitOfWork.SaveChanges();
        }
Exemplo n.º 4
0
        public CustomerPaymentDTO GetCustomerPaymentById(int customerPaymentId)
        {
            CustomerPaymentDTO customerPaymentDTO = null;
            var customerPayment = unitOfWork.CustomerPaymentRepository.GetById(customerPaymentId);

            if (customerPayment != null)
            {
                customerPaymentDTO = CustomerPaymentConvertor.ConvertToCustomerPaymentDto(customerPayment);
            }
            return(customerPaymentDTO);
        }
Exemplo n.º 5
0
 private void UpdateAmountPaid(CustomerPaymentDTO customerPaymentDTO)
 {
     if (customerPaymentDTO.OrderId > 0)
     {
         var productOrder = unitOfWork.ProductOrderRepository.GetById(customerPaymentDTO.OrderId);
         if (productOrder != null)
         {
             productOrder.OrderPaidAmount += customerPaymentDTO.PaymentCrAmount;
             unitOfWork.ProductOrderRepository.Update(productOrder);
         }
     }
 }
Exemplo n.º 6
0
 private void UpdateOrderStatus(CustomerPaymentDTO customerPaymentDTO)
 {
     if (customerPaymentDTO.OrderId > 0)
     {
         var productOrder = unitOfWork.ProductOrderDtlRepository.GetByOrderId(customerPaymentDTO.OrderId);
         if (productOrder != null)
         {
             productOrder.OrderStatus = Convert.ToInt16(customerPaymentDTO.OrderStatus);
             unitOfWork.ProductOrderDtlRepository.Update(productOrder);
         }
     }
 }
Exemplo n.º 7
0
        public static CustomerPaymentDTO ConvertToCustomerPaymentDto(CustomerPaymentTransaction customerPaymentTransaction)
        {
            CustomerPaymentDTO customerPaymentDTO = new CustomerPaymentDTO();

            customerPaymentDTO.CustomerPaymentId = customerPaymentTransaction.CustomerPaymentId;
            customerPaymentDTO.CustomerId        = customerPaymentTransaction.CustomerId;
            customerPaymentDTO.OrderId           = customerPaymentTransaction.OrderId;
            customerPaymentDTO.PaymentCrAmount   = customerPaymentTransaction.PaymentCrAmount.GetValueOrDefault();
            customerPaymentDTO.PaymentDrAmount   = customerPaymentTransaction.PaymentDrAmount.GetValueOrDefault();
            customerPaymentDTO.PaymentDate       = customerPaymentTransaction.PaymentDate;
            customerPaymentDTO.PaymentReceivedBy = customerPaymentTransaction.PaymentReceivedBy;
            customerPaymentDTO.PaymentComments   = customerPaymentTransaction.Ref1;
            customerPaymentDTO.PaymentMode       = customerPaymentTransaction.Ref2;
            return(customerPaymentDTO);
        }
Exemplo n.º 8
0
        public IHttpActionResult Put(int id, [FromBody] CustomerPaymentDTO customerPaymentDTO)
        {
            try
            {
                customerPaymentDTO.CustomerPaymentId = id;
                if (customerPaymentDTO == null)
                {
                    return(BadRequest("Argument Null"));
                }

                _customerPaymentService.UpdateCustomerPayment(customerPaymentDTO);

                return(Ok());
            }
            catch (PlatformModuleException ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemplo n.º 9
0
        //   [Authorize]
        public IHttpActionResult Post([FromBody] CustomerPaymentDTO customerPaymentDTO)
        {
            try
            {
                if (customerPaymentDTO == null)
                {
                    return(BadRequest("Argument Null"));
                }

                _customerPaymentService.AddCustomerPayment(customerPaymentDTO);

                return(Ok());
            }
            catch (PlatformModuleException ex)
            {
                //Write Log Here
                return(BadRequest(ex.Message));
            }
        }
Exemplo n.º 10
0
        private void UpdateCustomerWallet(CustomerPaymentDTO customerPaymentDTO)
        {
            var customerWallet = unitOfWork.CustomerWalletRepository.GetByCustomerId(customerPaymentDTO.CustomerId);

            if (customerWallet != null)
            {
                customerWallet.WalletBalance -= customerPaymentDTO.PaymentCrAmount;
                if (customerWallet.WalletBalance > 0)
                {
                    customerWallet.AmountDueDate = DateTime.Now.AddDays(10);
                }
                unitOfWork.CustomerWalletRepository.Update(customerWallet);
            }
            else
            {
                customerWallet               = new CustomerWallet();
                customerWallet.WalletId      = unitOfWork.DashboardRepository.NextNumberGenerator("CustomerWallet");
                customerWallet.CustomerId    = customerPaymentDTO.CustomerId;
                customerWallet.WalletBalance = customerPaymentDTO.PaymentCrAmount;
                customerWallet.AmountDueDate = DateTime.Now.AddDays(10);
                unitOfWork.CustomerWalletRepository.Add(customerWallet);
            }
        }
Exemplo n.º 11
0
        public static void ConvertToCustomerPaymentEntity(ref CustomerPaymentTransaction customerPaymentTransaction, CustomerPaymentDTO customerPaymentDTO, bool isUpdate)
        {
            if (isUpdate)
            {
                customerPaymentTransaction.CustomerPaymentId = customerPaymentDTO.CustomerPaymentId;
            }

            customerPaymentTransaction.CustomerId        = customerPaymentDTO.CustomerId;
            customerPaymentTransaction.OrderId           = customerPaymentDTO.OrderId;
            customerPaymentTransaction.PaymentCrAmount   = customerPaymentDTO.PaymentCrAmount;
            customerPaymentTransaction.PaymentDrAmount   = customerPaymentDTO.PaymentDrAmount;
            customerPaymentTransaction.PaymentDate       = customerPaymentDTO.PaymentDate;
            customerPaymentTransaction.PaymentReceivedBy = customerPaymentDTO.PaymentReceivedBy;
            customerPaymentTransaction.Ref1 = customerPaymentDTO.PaymentComments;
            customerPaymentTransaction.Ref2 = customerPaymentDTO.PaymentMode;
        }