コード例 #1
0
        public async Task <IActionResult> List(GatePassModel model, IFormCollection form)
        {
            try
            {
                string bName = "";
                int    bId   = 0;
                var    user  = await _userMasterService.GetUserByIdAsync(Convert.ToInt32(HttpContext.User.FindFirst(claim => claim.Type == System.Security.Claims.ClaimTypes.NameIdentifier)?.Value));

                if (model.OutTo == VehicleOutToEnum.Showroom.ToString())
                {
                    foreach (var v in model.AllotedVehicleDetails.Where(x => x.IsSelected.Selected == true))
                    {
                        var vehicle = await _vehicleAllotmentService.GetByIdAsync(v.AllotId);

                        var showroomVeh = new ShowroomVehiclesDetails
                        {
                            VehicleId       = vehicle.VehicleId,
                            CustomerId      = vehicle.CustomerId,
                            ScId            = vehicle.Scid,
                            SubDealerId     = vehicle.SubDealer,
                            VehicleCameFrom = "Godown",
                            DateCreated     = DateTime.UtcNow,
                            BranchId        = (int)vehicle.BranchId,
                            ByUser          = user.Id
                        };
                        await _showroomVehiclesService.InsertAsync(showroomVeh);

                        bName = v.BranchName;
                        bId   = showroomVeh.BranchId;
                    }
                }
                else
                {
                    foreach (var v in model.AllotedVehicleDetails.Where(x => x.IsSelected.Selected == true))
                    {
                        var pVehicle = await _vehicleAllotmentService.GetByIdAsync(v.AllotId);

                        var pdiVeh = new PdiVehiclesDetails
                        {
                            VehicleId       = pVehicle.VehicleId,
                            CustomerId      = pVehicle.CustomerId,
                            ScId            = pVehicle.Scid,
                            SubDealerId     = pVehicle.SubDealer,
                            VehicleCameFrom = "Godown",
                            DateCreated     = DateTime.UtcNow,
                            BranchId        = (int)pVehicle.BranchId,
                            ByUser          = user.Id
                        };
                        await _pdiVehicesService.InsertAsync(pdiVeh);

                        bName = v.BranchName;
                        bId   = pdiVeh.BranchId;
                    }
                }

                //add entry in gate pass tale
                var gatePass = new GatePassDetails
                {
                    VehicleOutTo  = model.OutTo,
                    VehicleOutFor = bName,
                    BranchId      = bId,
                    ByHand        = model.ByHand,
                    Status        = "Successfull",
                    DateCreated   = DateTime.UtcNow,
                    ByUser        = user.Id
                };
                await _gatePassService.InsertAsync(gatePass);

                foreach (var v in model.AllotedVehicleDetails.Where(x => x.IsSelected.Selected == true))
                {
                    var pVehicle1 = await _vehicleAllotmentService.GetByIdAsync(v.AllotId);

                    var gatePassVehicles = new GatePassVehicles
                    {
                        GatePassId  = gatePass.Id,
                        VehicleId   = (int)pVehicle1.VehicleId,
                        CustomerId  = (int)pVehicle1.CustomerId,
                        SubDealerId = pVehicle1.SubDealer,
                        DateCreated = DateTime.UtcNow
                    };
                    await _gatePassService.InsertGatePassVehicleAsync(gatePassVehicles);

                    //update alloted vehicle status
                    pVehicle1.IsVehicleOutFromGodown = true;
                    pVehicle1.DateUpdated            = DateTime.UtcNow;
                    await _vehicleAllotmentService.UpdateAsync(pVehicle1);

                    // update vehicle track status in vehicle master table
                    var vehicleInfo = await _vehicleMasterService.GetByIdAsync((int)pVehicle1.VehicleId);

                    vehicleInfo.TrackStatus = model.OutTo;
                    vehicleInfo.DateUpdated = DateTime.UtcNow;
                    await _vehicleMasterService.UpdateAsync(vehicleInfo);
                }



                //generate gate pass
                model.GatePassDate  = DateTime.UtcNow.ToString("dd-MMM-yyyy");
                model.GatePassNo    = gatePass.Id.ToString();
                model.VehicleoutTo  = model.OutTo;
                model.VehicleoutFor = bName;
                model.AuthPerson    = user.FirstName + " " + user.LastName;
                var gatepass = await _viewToStringRendererService.RenderToStringAsync("GatePassMaster/GatePassTemplate", model);

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

                return(File(pdf, "application/pdf", "gatepass.pdf"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #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));
        }