public ActionResult Create()
        {
            IVehicleService vehicleServcie = new VehicleService();
            IProjectService projectService = new ProjectService();

            RunningchartModel model = new RunningchartModel();
            model.BillDate = DateTime.Now;
            model.Vehicles = ModelMapper.GetVehicleModelList(vehicleServcie.GetAllVehicles());
            model.Lubricants = ModelMapper.GetLubricantModelList(vehicleServcie.GetAllLubricantTypes());
            model.Projects = ModelMapper.GetProjectModelList(projectService.GetAllActiveProjects());

            ViewBag.Mode = "create";
            return View(model);
        }
        public ActionResult WorkDonePrint(DateTime startDate, DateTime endDate, int vehicleNo)
        {
            if (startDate.Equals(DateTime.MinValue))
                throw new ArgumentNullException("startDate");
            if (endDate.Equals(DateTime.MinValue))
                throw new ArgumentNullException("endDate");
            if (vehicleNo == 0)
                throw new InvalidArgumentException("Vehicle No can not be 0", EngineExceptionErrorID.InvalidArgument);

            IVehicleService vehicleService = new VehicleService();
            var vehicle = vehicleService.GetVehicle(vehicleNo);
            var compCode = string.IsNullOrWhiteSpace(vehicle.CompanyCode) || string.Equals(vehicle.CompanyCode.ToLower(), "no") ? "N/A" : vehicle.CompanyCode;
            var measure = vehicle.IsVehicle ? " Km" : " Hrs";
            var totalWorkDone = decimal.Zero;
            var totalFuelUsed = decimal.Zero;

            DataTable dataTable = GetWorkDoneReportTable(startDate, endDate, vehicleNo, measure, out totalWorkDone, out totalFuelUsed);
            ReportClass reportClass = new ReportClass();
            reportClass.FileName = Server.MapPath("~/Reports/WorkDoneReport.rpt");
            reportClass.Load();
            reportClass.SummaryInfo.ReportTitle = "Work Done Report – Vehicle/Machine";
            reportClass.Database.Tables["WorkDoneReport"].SetDataSource(dataTable);
            reportClass.SetParameterValue("StartDate", startDate.ToString("d"));
            reportClass.SetParameterValue("EndDate", endDate.ToString("d"));
            reportClass.SetParameterValue("VehicleNo", vehicle.VehicleNumber);
            reportClass.SetParameterValue("CompanyCode", compCode);
            reportClass.SetParameterValue("TotalWorkDone", totalWorkDone.ToString("C").Replace("$", string.Empty) + " " + measure);
            reportClass.SetParameterValue("TotalFuelUsed", totalFuelUsed.ToString("C").Replace("$", string.Empty) + " L");
            reportClass.SetParameterValue("WorkDoneHeading", "Work Done (" + measure.Trim() + ")");

            Stream compStream = reportClass.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            return File(compStream, "application/pdf");
        }
        public ActionResult WorkDone(DateTime startDate, DateTime endDate, int vehicleNo, int companyCode)
        {
            IVehicleService vehicleService = new VehicleService();
            var vehicle = vehicleService.GetVehicle(vehicleNo);
            var compCode = string.IsNullOrWhiteSpace(vehicle.CompanyCode) || string.Equals(vehicle.CompanyCode.ToLower(), "no") ? "N/A" : vehicle.CompanyCode;
            var report = reportService.GetWorkDoneReport(startDate, endDate, vehicleNo);
            var model = ModelMapper.GetWorkDoneReportModelList(report);

            ViewBag.StartDate = startDate;
            ViewBag.EndDate = endDate;
            ViewBag.VehicleNumber = vehicle.VehicleNumber;
            ViewBag.CompanyCode = compCode;
            ViewBag.IsVehicle = vehicle.IsVehicle;
            ViewBag.VehicleNo = vehicle.Id;

            return View(model);
        }
 public ActionResult WorkDone()
 {
     IVehicleService vehicleService = new VehicleService();
     ViewBag.Vehicles = ModelMapper.GetVehicleModelList(vehicleService.GetAllVehicles());
     return View();
 }
        public ActionResult HireBillPrivatePrint(DateTime startDate, DateTime endDate, int vehicleNo)
        {
            if (startDate.Equals(DateTime.MinValue))
                throw new ArgumentNullException("startDate");
            if (endDate.Equals(DateTime.MinValue))
                throw new ArgumentNullException("endDate");
            if (vehicleNo == 0)
                throw new InvalidArgumentException("Vehicle No can not be 0", EngineExceptionErrorID.InvalidArgument);

            IVehicleService vehicleService = new VehicleService();
            var vehicle = vehicleService.GetVehicle(vehicleNo);
            DataTable dataTable = GetHireBillPrivateReportTable(startDate, endDate, vehicleNo, vehicle.IsVehicle);
            ReportClass reportClass = new ReportClass();
            reportClass.FileName = Server.MapPath("~/Reports/HireBillPrivateReport.rpt");
            reportClass.Load();
            reportClass.SummaryInfo.ReportTitle = "Hire Bill (Private) Report";
            reportClass.Database.Tables["HireBillPrivateReport"].SetDataSource(dataTable);
            reportClass.SetParameterValue("StartDateParameter", startDate.ToString("d"));
            reportClass.SetParameterValue("EndDateParameter", endDate.ToString("d"));
            reportClass.SetParameterValue("VehicleNumberParameter", vehicle.VehicleNumber);
            reportClass.SetParameterValue("OwnerNameParameter", vehicle.OwnerName);
            string measure = vehicle.IsVehicle ? " Rs/Km" : " Rs/Hr";
            reportClass.SetParameterValue("HireRateParameter", vehicle.HireRate.ConvertToDecimalString() + measure);

            Stream compStream = reportClass.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            return File(compStream, "application/pdf");
        }
        public ActionResult HireBillPrivate(DateTime startDate, DateTime endDate, int vehicleNo)
        {
            IVehicleService vehicleService = new VehicleService();
            var vehicle = vehicleService.GetVehicle(vehicleNo);
            var reporthp = reportService.GetHireBillPrivateReport(startDate, endDate, vehicleNo);
            var modelhp = ModelMapper.GetHireBillPrivateReportModelList(reporthp);

            ViewBag.VehicleNo = vehicle.Id;
            ViewBag.IsVehicle = vehicle.IsVehicle;
            ViewBag.OwnerName = vehicle.OwnerName;
            ViewBag.HireRate = vehicle.HireRate.ConvertToDecimalString(); //.ToString("N");
            ViewBag.StartDate = startDate;
            ViewBag.EndDate = endDate;
            ViewBag.VehicleNumber = vehicle.VehicleNumber;

            return View(modelhp);
        }
 public ActionResult HireBillPrivate()
 {
     IVehicleService vehicleService = new VehicleService();
     ViewBag.Vehicles = ModelMapper.GetVehicleModelList(vehicleService.GetAllHiredVehicles());
     return View();
 }
        public ActionResult Create(RunningchartModel model)
        {
            try
            {
                Runningchart runningChart = ModelMapper.GetRunningchartFromRunningchartModel(model);
                runningChart.EnteredBy = (Session[SessionKeys.UserInfo] as UserModel).Id; // Set DEO
                int chartId = runningchartService.AddRunningchart(runningChart);
                return RedirectToAction("index", new { lastChartId = chartId });
            }
            catch
            {
                IVehicleService vehicleServcie = new VehicleService();
                IProjectService projectService = new ProjectService();

                model.RunningchartId = runningchartService.GetNextRunningchartId();
                model.Vehicles = ModelMapper.GetVehicleModelList(vehicleServcie.GetAllVehicles());
                model.Lubricants = ModelMapper.GetLubricantModelList(vehicleServcie.GetAllLubricantTypes());
                model.Projects = ModelMapper.GetProjectModelList(projectService.GetAllActiveProjects());

                return View(model);
            }
        }
        private RunningchartModel GetRunningchartModel(int runningChartId)
        {
            IVehicleService vehicleServcie = new VehicleService();
            IProjectService projectService = new ProjectService();
            IPumpstationService pumpstationService = new PumpstationService();
            var chart = runningchartService.GetRunningChart(runningChartId);
            var model = ModelMapper.GetRunningchartModel(chart);
            model.Vehicles = ModelMapper.GetVehicleModelList(vehicleServcie.GetAllVehicles());
            model.Lubricants = ModelMapper.GetLubricantModelList(vehicleServcie.GetAllLubricantTypes());
            model.Projects = ModelMapper.GetProjectModelList(projectService.GetAllActiveProjects());
            model.Pumpstations = ModelMapper.GetPumpStationModelList(pumpstationService.GetAllPumpstations());
            model.VehicleRentalTypes = new List<VehicleRentalTypeModel>()
            {
                new VehicleRentalTypeModel() { Id = (int)RentalType.Company, RentalTypeName = StringEnum.GetEnumStringValue(RentalType.Company) },
                new VehicleRentalTypeModel() { Id = (int)RentalType.CompanyHired, RentalTypeName = StringEnum.GetEnumStringValue(RentalType.CompanyHired) },
                new VehicleRentalTypeModel() { Id = (int)RentalType.Hired, RentalTypeName = StringEnum.GetEnumStringValue(RentalType.Hired) }
            }; // Not worth to do a DB call since this is very static

            return model;
        }
        public ActionResult Print(int id)
        {
            IVehicleService vehicleServcie = new VehicleService();
            IProjectService projectService = new ProjectService();
            IPumpstationService pumpstationService = new PumpstationService();
            var pumpstations = pumpstationService.GetAllPumpstations();
            var projects = projectService.GetAllActiveProjects();
            var lubricants = vehicleServcie.GetAllLubricantTypes();
            var vehicles = vehicleServcie.GetAllVehicles();
            var chart = runningchartService.GetRunningChart(id);

            dsRunningchart ds = new dsRunningchart();
            DataTable runningchartTable = ds.Tables["Runningchart"].Clone();
            DataTable runningchartDetailsTable = ds.Tables["RunningchartDetails"].Clone();
            DataTable runningchartPumpstationsTable = ds.Tables["RunningchartPumpstation"].Clone();
            DataTable runningchartLubricantsTable = ds.Tables["RunningchartLubricant"].Clone();

            PopulateRunningchartTable(chart, runningchartTable, vehicles);
            PopulateRunningchartDetailsTable(chart.RunningchartDetails, runningchartDetailsTable, projects);
            PopulateRunningchartPumpstationTable(chart.RunningchartPumpstation, runningchartPumpstationsTable, pumpstations);
            PopulateRunningchartLubricantTable(chart.RunningchartLubricants, runningchartLubricantsTable, pumpstations, lubricants);

            ReportClass reportClass = new ReportClass();
            reportClass.FileName = Server.MapPath("~/Reports/Runningchart.rpt");
            reportClass.Load();
            reportClass.SummaryInfo.ReportTitle = "Running Chart";
            reportClass.Database.Tables["Runningchart"].SetDataSource(runningchartTable);
            reportClass.Database.Tables["RunningchartDetails"].SetDataSource(runningchartDetailsTable);
            reportClass.Database.Tables["RunningchartPumpstation"].SetDataSource(runningchartPumpstationsTable);
            reportClass.Database.Tables["RunningchartLubricant"].SetDataSource(runningchartLubricantsTable);

            Stream compStream = reportClass.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            return File(compStream, "application/pdf");
        }
        public ActionResult PoulateLubricantItems(bool isAddingNewItem)
        {
            IVehicleService vehicleServcie = new VehicleService();
            RunningchartModel model = new RunningchartModel();
            List<ChartLubricantItemModel> existingLubricantItems = new List<ChartLubricantItemModel>();
            UpdateModel<List<ChartLubricantItemModel>>(existingLubricantItems);

            IPumpstationService pumpstationService = new PumpstationService();
            model.Pumpstations = ModelMapper.GetPumpStationModelList(pumpstationService.GetAllPumpstations());
            model.Lubricants = ModelMapper.GetLubricantModelList(vehicleServcie.GetAllLubricantTypes());
            model.SelectedLubricants = new List<ChartLubricantItemModel>();

            // Add existing chart items
            foreach (var item in existingLubricantItems)
            {
                if (!item.IsRemoving)
                {
                    model.SelectedLubricants.Add(item);
                }
            }

            // Add new chart item
            if (isAddingNewItem)
            {
                model.SelectedLubricants.Add(new ChartLubricantItemModel()
                {
                    SelectedPumpstationId = 0,
                    SelectedLubricantTypeId = 0,
                    PumpAmount = 0
                });
            }

            return PartialView("_Lubricants", model);
        }
        public ActionResult Index(int? lastChartId)
        {
            IVehicleService vehicleServcie = new VehicleService();
            List<Runningchart> runningCharts = new List<Runningchart>();
            if (Session[SessionKeys.UserInfo] == null)
            {
                return RedirectToAction("index", "home");
            }

            var user = Session[SessionKeys.UserInfo] as UserModel;

            if (user.Role == UserRole.Admin)
            {
                runningCharts = runningchartService.GetNoneApprovedRunningCharts();
            }
            else if (user.Role == UserRole.RunningChartInspector)
            {
                //TODO : Limit running charts by a criteria like inspector projects
                runningCharts = runningchartService.GetNoneApprovedRunningCharts();
            }
            else if (user.Role == UserRole.RunningChartOperator)
            {
                runningCharts = runningchartService.GetOperatorNoneApprovedRunningcharts(user.Id);
            }

            if (lastChartId.HasValue)
            {
                ViewBag.LastChartId = lastChartId.Value;
            }

            var model = ModelMapper.GetRunningchartModelList(runningCharts);
            ViewBag.Vehicles = ModelMapper.GetVehicleModelList(vehicleServcie.GetAllVehicles());
            return View(model);
        }
        public ActionResult History()
        {
            IVehicleService vehicleServcie = new VehicleService();
            List<Runningchart> runningCharts = new List<Runningchart>();
            var user = Session[SessionKeys.UserInfo] as UserModel;

            if (user.Role == UserRole.Admin)
            {
                runningCharts = runningchartService.GetApprovedRunningCharts();
            }
            else if (user.Role == UserRole.RunningChartInspector)
            {
                //TODO : Limit running charts by a criteria like inspector projects
                runningCharts = runningchartService.GetApprovedRunningCharts();
            }
            else if (user.Role == UserRole.RunningChartOperator)
            {
                runningCharts = runningchartService.GetOperatorApprovedRunningcharts(user.Id);
            }

            var model = ModelMapper.GetRunningchartModelList(runningCharts);
            ViewBag.Vehicles = ModelMapper.GetVehicleModelList(vehicleServcie.GetAllVehicles());
            return View(model);
        }