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;
            }
        }
Beispiel #2
0
        public async Task <IActionResult> CustomerVehicleAllotment(IFormCollection form)
        {
            try
            {
                var custId   = Convert.ToInt32(form["CustId"]);
                var vehId    = Convert.ToInt32(form["item.VID"]);
                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 record in table
                if (vehId != 0)
                {
                    var vehicleAllotDetails = new VehicleAllotmentDetails
                    {
                        VehicleId   = Convert.ToInt32(form["item.VID"]),
                        CustomerId  = custId,
                        ModelId     = Convert.ToInt32(form["ModelId"]),
                        VarientId   = Convert.ToInt32(form["VarientId"]),
                        ColourId    = Convert.ToInt32(form["VarientColourId"]),
                        VarientType = form["VarientType"],
                        Scid        = Convert.ToInt32(form["SalesConsultantId"]),
                        BranchId    = Convert.ToInt32(form["BranchId"]),
                        DateCreated = DateTime.UtcNow,
                        DateUpdated = DateTime.UtcNow,
                        AllotedBy   = Convert.ToInt32(HttpContext.User.FindFirst(claim => claim.Type == System.Security.Claims.ClaimTypes.NameIdentifier)?.Value),
                    };
                    await _vehicleAllotmentService.InsertAsync(vehicleAllotDetails);

                    //update vehicle status in vehicle master
                    var vehicle = await _vehicleMasterService.GetByIdAsync(vehId);

                    if (vehicle != null)
                    {
                        vehicle.TrackStatus = vehicleAllotDetails.IsAlloted ? VehicleStatusEnum.Alloted.ToString() : VehicleStatusEnum.PartiallyAlloted.ToString();
                        vehicle.DateUpdated = DateTime.UtcNow;
                        await _vehicleMasterService.UpdateAsync(vehicle);
                    }
                }

                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }