HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: /var/www/html/taxicamera/applicationold/views/admin/report/income_report/list.php
<div class="main-content">
	<div class="content-wrapper">
		<div class="container-fluid">
			<!-- Basic form layout section start -->
			<section id="basic-form-layouts">
				<!--<div class="row">
		<div class="col-sm-12">
			<h2 class="content-header">Driver Master</h2>
		</div>
	</div>-->
				<div class="row">
					<div class="col-md-12">
						<div class="card">
							<div class="card-header">
								<div class="page-title-wrap">
									<h4 class="card-title">Income Report</h4>

								</div>


								<!--<p class="mb-0">This is the most basic and cost estimation form is the default position.</p>-->
							</div>
							<div class="card-body">
								<div class="px-3">
									<form class="form custom_form_style">
										<div class="form-body">
											<div class="user_permission_top">
												<div class="row">
													<div class="col-md-3">
														<div class="form-group">
															<label>Company Name</label>
															<select name="company_id" id="company_id" class="js-select2" data-show-subtext="true" data-live-search="true">
																<option value="">Select Company</option>
																<?php foreach ($company_list as $company) { ?>
																	<option value="<?= $company['company_id'] ?>"><?= $company['company_name'] ?></option>
																<?php } ?>
															</select>
														</div>
													</div>
													<div class="col-md-3">
														<div class="form-group">
															<label>Select Car</label>
															<select class="js-select2" id="car_id" data-show-subtext="true" data-live-search="true">
																<option value="">Select Car</option>
																<?php if (!empty($car_list)) {
																	foreach ($car_list as $car) { ?>
																		<option value="<?= $car['car_id'] ?>"><?= $car['registration_no'] ?></option>

																<?php }
																} ?>
															</select>
														</div>
													</div>
													
													<div class="col-md-3">
														<div class="form-group">
															<label>From Date</label>
															<div class="input-group">
																<input type="text" id="from_date" class="form-control pickadate" placeholder="" />
																<div class="input-group-append">
																	<span class="input-group-text">
																		<span class="fa fa-calendar-o"></span>
																	</span>
																</div>
															</div>
														</div>
													</div>
													<div class="col-md-3">
														<div class="form-group">
															<label>To Date</label>
															<div class="input-group">
																<input type="text" id="to_date" class="form-control pickadate" placeholder="" />
																<div class="input-group-append">
																	<span class="input-group-text">
																		<span class="fa fa-calendar-o"></span>
																	</span>
																</div>
															</div>
														</div>
													</div>
													<div class="col-md-1">
														<div class="form-group">
															<label class="blank_lbl">&nbsp;</label>
															<button type="button" class="btn btn-success" onclick="populate_income_list();">
																<i class="fa fa-search" aria-hidden="true"></i> Search
															</button>
														</div>
													</div>
													<div class="col-md-1" style="margin-left: 20px;">
										<div class="form-group">
											<label class="blank_lbl">&nbsp;</label>
											<button id="download_pdf" type="button" class="btn btn-success">
												<i class="fa fa-download" aria-hidden="true"></i>PDF
											</button>
										</div>
									</div>
												</div>

											</div>


										</div>

										
									</form>
									<div class="row ">

										<div class="table-responsive custom_table_area export_table_area">
											<table id="income_table" class="table table-striped table-bordered export_btn_dt c_table_style file-export">
												<thead>
													<tr>
														<th>SL No.</th>
														<th style="min-width: 70px;">Date</th>
														<th>Car No.</th>
														<th>Shift</th>
														<th>Levy Count</th>
														<th>Meter Total</th>
														<th>Fuel</th>
														<th>Other Expenses</th>
														<th>Driver Commission</th>
														<th>Owner Income </th>
														<th>Lifting Fees </th>
													</tr>
												</thead>
												<tbody id="tbody_income_table">
													
												</tbody>
												<tfoot id="tfoot_income_table">
												</tfoot>
											</table>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</section>
			<!-- // Basic form layout section end -->
		</div>
	</div>
</div>
<script>
	$(document).ready(function() {
		populate_datepicker();
		populate_income_list();
	});

	function populate_datepicker(){
		
		var from_$input = $('#from_date').pickadate({
				format: 'dd/mm/yyyy',
				autoclose: true
			}),
			from_picker = from_$input.pickadate('picker')

		var to_$input = $('#to_date').pickadate({
				format: 'dd/mm/yyyy',
				autoclose: true
			}),
			to_picker = to_$input.pickadate('picker')

		// Check if there’s a “from” or “to” date to start with.
		if (from_picker.get('value')) {
			to_picker.set('min', from_picker.get('select'))
		}
		if (to_picker.get('value')) {
			from_picker.set('max', to_picker.get('select'))
		}

		// When something is selected, update the “from” and “to” limits.
		from_picker.on('set', function(event) {

			if (event.select) {
				to_picker.set('min', from_picker.get('select'));
			} else if ('clear' in event) {
				to_picker.set('min', false);
			}
		})

		to_picker.on('set', function(event) {

			if (event.select) {
				from_picker.set('max', to_picker.get('select'));
			} else if ('clear' in event) {
				from_picker.set('max', false);
			}
		})

	}

	$(document).on('change', '#company_id', function() {
		var company_id = $(this).val();
		$.ajax({
				url: "<?php echo base_url('admin/report/get_car_against_company'); ?>",
				type: "POST",
				data: {
					'company_id': company_id,
				},
				dataType: "json",
				encode: true
			})
			.done(function(data) {

				if (data.status) {
					var optionHTML = '<option value="">Select Car</option>';
					$.each(data.car_list, function(key, value) {
						optionHTML += `<option value="` + value.car_id + `">` + value.registration_no + `</option>`;
					})
					$("#car_id").html(optionHTML);

				}
			})
			.fail(function(result) {
				$.alert({
					type: 'red',
					title: 'Alert!',
					content: 'Oops!Something went wrong...',
				});
			})
	})

	function populate_income_list() {
		
		var start_date = $("#from_date").val();
		var end_date = $("#to_date").val();
		var car_id = $("#car_id").val();
		var company_id = $("#company_id").val();
		var resulthtml = footerhtml='';
		$.ajax({
				url: "<?php echo base_url('admin/report/get_income_report'); ?>",
				type: "POST",
				data: {
					'company_id': company_id,
					'car_id': car_id,
					'start_date': start_date,
					'end_date': end_date,
				},
				dataType: "json",
				encode: true,
				//async: false
			})
			.done(function(data) {

				if (data.status) {

					if (data.income_list) {
						var i = 0;
						var shift_name ;
						var total_levy = total_metered_fares = total_expense_total_fuel = total_expense_total_other = total_driver_commission_amt = total_owner_commission_amt = total_total_lifting_fees = 0 *1;
						$.each(data.income_list, function(key, value) {
							i++;
							var driver_commission_amt = 0;
							var owner_commission_amt = 0;
							if (value.driver_commission_share && value.owner_commission_share) {
								driver_commission_amt = Number((value.metered_fares * value.driver_commission_share / 100));
								owner_commission_amt =  Number((value.metered_fares * value.owner_commission_share / 100));
							}
							else{
								driver_commission_amt = 0;
								owner_commission_amt =  Number(value.metered_fares);
							}
							resulthtml += '<tr>';
							resulthtml += '<td>' + i + '</td>';
							resulthtml += '<td>' + value.payin_date + '</td>';
							resulthtml += '<td>' + value.registration_no + '</td>';
							
							if(value.shift_name == "D"){
								shift_name = "Day";
							}
							else if(value.shift_name == "H"){
								shift_name = "Hungry";
							}
							else{
								shift_name = "Night";
							}
							resulthtml += '<td>' + shift_name + '</td>';
							resulthtml += '<td>' + value.levy + '</td>';
							resulthtml += '<td>' + value.metered_fares + '</td>';
							resulthtml += '<td>' + value.expense_total_fuel + '</td>';
							resulthtml += '<td>' + value.expense_total_other + '</td>';
							resulthtml += '<td>' + driver_commission_amt + '</td>';
							resulthtml += '<td>' + owner_commission_amt + '</td>';
							resulthtml += '<td>' + value.total_lifting_fees + '</td>';
							resulthtml += '</tr>';

							total_levy +=Number(value.levy);
							total_metered_fares +=Number(value.metered_fares);
							total_expense_total_fuel +=Number(value.expense_total_fuel); 
							total_expense_total_other +=Number(value.expense_total_other); 
							total_driver_commission_amt +=Number(driver_commission_amt); 
							total_owner_commission_amt +=Number(owner_commission_amt);
							total_total_lifting_fees +=Number(value.total_lifting_fees);
						})
						footerhtml +='<tr style="background: #1db5bd;color: #fff;"><td colspan="4"><strong>TOTAL</strong></td>';
						footerhtml +='<td><strong>'+parseFloat(total_levy).toFixed(2)+'<strong></td>';
						footerhtml +='<td><strong>'+parseFloat(total_metered_fares).toFixed(2)+'</td>';
						footerhtml +='<td><strong>'+parseFloat(total_expense_total_fuel).toFixed(2)+'</strong></td>';
						footerhtml +='<td><strong>'+parseFloat(total_expense_total_other).toFixed(2)+'</strong></td>';
						footerhtml +='<td><strong>'+parseFloat(total_driver_commission_amt).toFixed(2)+'</strong></td>';
						footerhtml +='<td><strong>'+parseFloat(total_owner_commission_amt).toFixed(2)+'</strong></td>';
						footerhtml +='<td><strong>'+parseFloat(total_total_lifting_fees).toFixed(2)+'</strong></td>';
						footerhtml+='</tr>';
						var now = new Date();
						var date = now.getFullYear() + ":" + now.getMonth() + ":" + now.getDate();
						$("#income_table").dataTable().fnDestroy();
						$("#tbody_income_table").html(resulthtml);
						$("#tfoot_income_table").html(footerhtml);
						$('#income_table').DataTable({
							pageLength: 100,
							dom: 'Bfrtip',
							buttons: [{
									extend: 'excel',
									text: 'Download Excel',
									className: 'btn btn-outline-primary mr-1',
									filename: 'income_report' + date
								}
								//'copy', 'csv', 'excel', 'pdf', 'print'
							]
						});


					}

				} else {
					$.alert({
						type: 'red',
						title: 'Alert!',
						content: 'Oops!Something went wrong...',
					});
				}
			})
			.fail(function(result) {
				$.alert({
					type: 'red',
					title: 'Alert!',
					content: 'Oops!Something went wrong...',
				});
			})
	}

	$(document).on('click','#download_pdf',function(){
		var start_date = $("#from_date").val();
		var end_date = $("#to_date").val();
		var car_id = $("#car_id").val();
		var company_id = $("#company_id").val();

		var format_start_date=start_date.split("/").reverse().join("-");
		var format_end_date=end_date.split("/").reverse().join("-");
		
		window.location.href = "<?=base_url()?>admin/report/download_pdf_income_report/"+car_id+"/"+format_start_date+"/"+format_end_date+"/"+company_id;
		

	})

</script>