Пример #1
0
        private async Task <PriceListMaster> PrepareRepositoryTable(DataRow dataRow)
        {
            var modelCode   = Convert.ToString(dataRow["ModelCode"]);
            var varient     = Convert.ToString(dataRow["Varient"]);
            var varientType = Convert.ToString(dataRow["VarientType"]);

            if (string.IsNullOrEmpty(modelCode) || string.IsNullOrEmpty(varientType))
            {
                return(null);
            }

            var isModelPriceExist = await _priceListMasterService.GetModelPriceByModelCodeAsync(modelCode, varient, varientType);

            if (isModelPriceExist != null)
            {
                return(null);
            }

            var modelPrice = new PriceListMaster();

            if (dataRow.Table.Columns.Contains("ModelCode"))
            {
                modelPrice.ModelCode = Convert.ToString(dataRow["ModelCode"]);
            }

            if (dataRow.Table.Columns.Contains("Varient"))
            {
                modelPrice.ModelVarient = Convert.ToString(dataRow["Varient"]);
            }

            if (dataRow.Table.Columns.Contains("VarientType"))
            {
                modelPrice.VarientType = Convert.ToString(dataRow["VarientType"]);
            }

            if (dataRow.Table.Columns.Contains("ExShowroomPrice"))
            {
                modelPrice.ExShowroomPrice = Convert.ToDecimal(dataRow["ExShowroomPrice"]);
            }

            if (dataRow.Table.Columns.Contains("FastTag"))
            {
                modelPrice.FastTag = Convert.ToDecimal(dataRow["FastTag"]);
            }

            if (dataRow.Table.Columns.Contains("TCS"))
            {
                modelPrice.Tcs = Convert.ToDecimal(dataRow["TCS"]);
            }

            if (dataRow.Table.Columns.Contains("HAInsurance"))
            {
                modelPrice.Hainsurance = Convert.ToDecimal(dataRow["HAInsurance"]);
            }

            if (dataRow.Table.Columns.Contains("HANilDepWithKeyProtect"))
            {
                modelPrice.HanilDepWithKeyProtect = Convert.ToDecimal(dataRow["HANilDepWithKeyProtect"]);
            }

            if (dataRow.Table.Columns.Contains("HARTIWithEngineProtect"))
            {
                modelPrice.HartiwithEngineProtect = Convert.ToDecimal(dataRow["HARTIWithEngineProtect"]);
            }

            if (dataRow.Table.Columns.Contains("RTOIndividual"))
            {
                modelPrice.Rtoindividual = Convert.ToDecimal(dataRow["RTOIndividual"]);
            }

            if (dataRow.Table.Columns.Contains("AccessoryComboKit"))
            {
                modelPrice.AccessoryComboKit = Convert.ToDecimal(dataRow["AccessoryComboKit"]);
            }

            if (dataRow.Table.Columns.Contains("ExtendedWarranty"))
            {
                modelPrice.ExtendedWarranty = Convert.ToDecimal(dataRow["ExtendedWarranty"]);
            }

            if (dataRow.Table.Columns.Contains("RSA"))
            {
                modelPrice.Rsa = Convert.ToDecimal(dataRow["RSA"]);
            }

            if (dataRow.Table.Columns.Contains("ClayBar"))
            {
                modelPrice.ClayBar = Convert.ToDecimal(dataRow["ClayBar"]);
            }

            if (dataRow.Table.Columns.Contains("Antirust"))
            {
                modelPrice.Antirust = Convert.ToDecimal(dataRow["Antirust"]);
            }

            if (dataRow.Table.Columns.Contains("CarpetLamination"))
            {
                modelPrice.CarpetLamination = Convert.ToDecimal(dataRow["CarpetLamination"]);
            }

            if (dataRow.Table.Columns.Contains("TotatPrice"))
            {
                modelPrice.TotatPrice = Convert.ToDecimal(dataRow["TotatPrice"]);
            }



            modelPrice.DateCreated = DateTime.UtcNow;
            modelPrice.DateUpdated = DateTime.UtcNow;
            modelPrice.ByUser      = Convert.ToInt32(HttpContext.User.FindFirst(claim => claim.Type == System.Security.Claims.ClaimTypes.NameIdentifier)?.Value);;
            return(modelPrice);
        }
Пример #2
0
        public async Task <IActionResult> GenarateQuote(GenerateQuotationModel model, IFormCollection form)
        {
            decimal totalAmount = 0;
            var     custId      = Convert.ToInt32(form["CustId"]);
            var     varientInfo = _varientMasterService.GetVarientByIdAsync(model.VarientId);
            var     priceList   = await _priceListMasterService.GetModelPriceByModelCodeAsync(varientInfo.VarientCode, varientInfo.VerientName, model.VarientType);

            if (priceList != null)
            {
                model.CustomerDetails.CustomerName = form["CustomerName"].ToString();
                model.CustomerDetails.Address1     = form["Address1"].ToString();
                model.CustomerDetails.Address2     = !string.IsNullOrEmpty(form["Address2"].ToString()) ? form["Address2"].ToString() : string.Empty;
                model.CustomerDetails.EmailId      = form["EmailId"].ToString();
                model.CustomerDetails.Pin          = form["Pin"].ToString();
                model.CustomerDetails.MobileNo1    = Convert.ToDecimal(form["MobileNo1"]);
                model.CustomerDetails.MobileNo2    = Convert.ToDecimal(form["MobileNo2"]);

                var custInfo = await _customerService.GetAllCustomerByIdAsync(custId);

                if (custInfo == null)
                {
                    //create cust entry
                    var customer = new CustomerDetailsTable
                    {
                        CustomerName = form["CustomerName"],
                        Address1     = form["Address1"],
                        Address2     = !string.IsNullOrEmpty(form["Address2"].ToString()) ? form["Address2"].ToString() : string.Empty,
                        EmailId      = form["EmailId"],
                        Pin          = form["Pin"],
                        Taluka       = form["Taluka"],
                        District     = form["District"],
                        State        = Convert.ToInt32(form["StateId"]),
                        MobileNo1    = Convert.ToDecimal(form["MobileNo1"]),
                        MobileNo2    = Convert.ToDecimal(form["MobileNo2"]),
                        DateUpdated  = DateTime.UtcNow,
                        DateCreated  = DateTime.UtcNow
                    };
                    await _customerService.InsertAsync(customer);

                    custId = customer.Id;
                }

                //add quotation info
                var quotation = new QuotationDetails
                {
                    BranchId      = 1,
                    ModelId       = model.ModelId,
                    VarientId     = model.VarientId,
                    VarientType   = model.VarientType,
                    ColourId      = model.VarientColourId,
                    CustomerId    = custId,
                    ScId          = model.SalesConsultantId,
                    LeadSource    = model.SourceOfEnquiry,
                    BookingAmount = model.BookingAmount,
                    DateCretaed   = DateTime.UtcNow,
                    CreatedBy     = Convert.ToInt32(HttpContext.User.FindFirst(claim => claim.Type == System.Security.Claims.ClaimTypes.NameIdentifier)?.Value)
                };
                await _quotationManagerService.InsertAsync(quotation);

                //prepare quote model
                model.QuoteDate = DateTime.UtcNow.ToString("dd/MM/yyyy");
                model.quoteNo   = quotation.Id;
                var scInfo = await _userMasterService.GetUserByIdAsync(model.SalesConsultantId);

                model.ModelName      = _modelsMasterService.GetModelbyIdAsync(model.ModelId).ModelName;
                model.VarientName    = varientInfo.VerientName;
                model.ColourName     = _colourMasterService.GetColourByIdAsync(model.VarientColourId).ColourName;
                model.SCName         = scInfo.FirstName + " " + scInfo.LastName;
                model.SCMobileNumber = scInfo.ContactNumber.ToString();
                var tlInfo = await _userMasterService.GetUserByIdAsync(model.TeamLeaderId);

                model.TLName = tlInfo.FirstName + " " + tlInfo.LastName;

                if (Convert.ToBoolean(form["Ex Showroom Price"]))
                {
                    model.VehiclePriceList.ExShowroomPrice = Convert.ToDecimal(priceList.ExShowroomPrice);
                    totalAmount += Convert.ToDecimal(priceList.ExShowroomPrice);
                }

                if (Convert.ToBoolean(form["Fast Tag"]))
                {
                    model.VehiclePriceList.FastTag = Convert.ToDecimal(priceList.FastTag);
                    totalAmount += Convert.ToDecimal(priceList.FastTag);
                }

                if (Convert.ToBoolean(form["TCS"]))
                {
                    model.VehiclePriceList.TCS = Convert.ToDecimal(priceList.Tcs);
                    totalAmount += Convert.ToDecimal(priceList.Tcs);
                }

                if (Convert.ToBoolean(form["Honda Assure Insurance"]))
                {
                    model.VehiclePriceList.Insurance = Convert.ToDecimal(priceList.Hainsurance);
                    totalAmount += Convert.ToDecimal(priceList.Hainsurance);
                }

                if (Convert.ToBoolean(form["Honda Assure Insurance + Key Protect"]))
                {
                    model.VehiclePriceList.InsuranceWithKeyProtect = Convert.ToDecimal(priceList.HanilDepWithKeyProtect);
                    totalAmount += Convert.ToDecimal(priceList.HanilDepWithKeyProtect);
                }

                if (Convert.ToBoolean(form["Honda Assure Insurance + Engine Protect"]))
                {
                    model.VehiclePriceList.InsuranceWithEngineProtect = Convert.ToDecimal(priceList.HartiwithEngineProtect);
                    totalAmount += Convert.ToDecimal(priceList.HartiwithEngineProtect);
                }

                if (Convert.ToBoolean(form["Registration (Indv/Comp)"]))
                {
                    model.VehiclePriceList.Registration = Convert.ToDecimal(priceList.Rtoindividual);
                    totalAmount += Convert.ToDecimal(priceList.Rtoindividual);
                }

                if (Convert.ToBoolean(form["Accessory Combo Kit"]))
                {
                    model.VehiclePriceList.Accessories = Convert.ToDecimal(priceList.AccessoryComboKit);
                    totalAmount += Convert.ToDecimal(priceList.AccessoryComboKit);
                }

                if (Convert.ToBoolean(form["Extended Warranty"]))
                {
                    model.VehiclePriceList.ExtendedWarranty = Convert.ToDecimal(priceList.ExtendedWarranty);
                    totalAmount += Convert.ToDecimal(priceList.ExtendedWarranty);
                }

                if (Convert.ToBoolean(form["RSA"]))
                {
                    model.VehiclePriceList.RSA = Convert.ToDecimal(priceList.Rsa);
                    totalAmount += Convert.ToDecimal(priceList.Rsa);
                }

                if (Convert.ToBoolean(form["Clay Bar"]))
                {
                    model.VehiclePriceList.ClayBar = Convert.ToDecimal(priceList.ClayBar);
                    totalAmount += Convert.ToDecimal(priceList.ClayBar);
                }

                if (Convert.ToBoolean(form["Antirust"]))
                {
                    model.VehiclePriceList.Antirust = Convert.ToDecimal(priceList.Antirust);
                    totalAmount += Convert.ToDecimal(priceList.Antirust);
                }

                if (Convert.ToBoolean(form["Carpet Lamination"]))
                {
                    model.VehiclePriceList.Lamination = Convert.ToDecimal(priceList.CarpetLamination);
                    totalAmount += Convert.ToDecimal(priceList.CarpetLamination);
                }

                model.VehiclePriceList.Total      = totalAmount;
                model.VehiclePriceList.GrandTotal = model.VehiclePriceList.Total;

                model.Url = HttpContext.Request.Scheme + "://" + HttpContext.Request.Host.Value;

                //generate quote
                var quote = await _viewToStringRendererService.RenderToStringAsync("GenerateQuotation/QuoteTemplate", model);

                HtmlToPdf   converter = new HtmlToPdf();
                PdfDocument doc       = converter.ConvertHtmlString(quote.ToString());
                byte[]      pdf       = doc.Save();
                doc.Close();

                return(File(pdf, "application/pdf", "quote.pdf"));
            }

            model.IsErrorFound = true;
            model.Error        = "Vehicle price list not found";
            return(View(model));
        }