@extends('contractor.layout.master')
@section('ptitle','Customer Service')
@section('page_title', 'Dashboard')
@section('subpage', 'Graph & Summary Report')
@section('img_profile', asset($user->StaffDetail->user_pic))
@section('login_name', $user->StaffDetail->name )
@section('last_login', $user->last_login_at )

@section('content')
	<style>
		.ui-tabs .ui-tabs-nav li.ui-tabs-active a { color: #EA5730 !important; }
		.ui-widget-content .bRed { color: #fff !important; }
		.dt-buttons
		{
			background: -webkit-linear-gradient(top, #F8F8F8 0%, #EFEFEF 100%);
		}
		.icos-download
		{
			padding-top: 0px;
		}
		.buttons-excel
		{
			padding: 7px 12px;
			display: block;
			color: #808080;
			font-size: 11px;
		}
	</style>
	<!-- Table dealer -->
	<div class="fluid">
		<div class="widget grid12">		
			<div class="whead"><h6>Docket's List</h6></div>
			<div id="dyn1" class="shownpars cuss responsive">
				<a class="tOptions" title="Options"><img src="{{ url('assets/img/icons/options') }}" alt="" /></a>
				<table id="agent" cellpadding="0" cellspacing="0" border="0" class="dTable tMedia" width="100%">
					<thead>
						<tr>
							<th>#</th>
							<th>Docket</th>
							<th>W/O</th>
							<th>Nature Work</th>
							<th>Contractor</th>
							<th>Installer</th>
							<th>Building</th>
							<th>Contact No.</th>
							<th>Completed Date</th>
							<th>Rating</th>
							<th width="90">Actions</th>
						</tr>
					</thead>
				</table>
			</div> 		
		</div>
	</div>
@endsection

@section('external_js')
<script>

	$(document).ready(function(){

		var origin   = window.location.origin; 

			//===== Dynamic table toolbars =====//		
			
			$('#dyn1 .tOptions').click(function () {
				$('#dyn .tablePars').slideToggle(200);
			});	
			
			$('.tOptions').click(function () {
				$(this).toggleClass("act");
			});
			
			//======= Filter data table ========//

			var table = $('#agent').DataTable({
				"dom": 'Br<"tablePars"fl>t<"tableFooter"ip>',
				"buttons": [{
					extend:'excel',
					text:'<span class="icos-download"></span>Download as Excel',
					exportOptions: 
					{
						modifier: {
							sLengthMenu: 'all'
						}
					}
		            // 'copyHtml5', 'csv', 'excelHtml5', 'pdf', 'print'
		        }],
				"bJQueryUI": false,
				"bAutoWidth": true,
				"bSort": false,
				"sPaginationType": "full_numbers",
				// "sDom": '<"tablePars"fl>t<"tableFooter"ip>',
				"oLanguage": {
					"sLengthMenu": "<span class='showentries'>Show entries:</span> _MENU_"
				},
				"ordering": false,
				"serverSide": false,
				"processing": true,
				"ajax": "{{ url('/contractor/docket/get-docket-list/null/null/null') }}",
				"columns": [
				{ "data": "index","name": "index"},
				{ "data": "docket_id","name": "docket_id"},
				{ "data": "work_order_id","name": "work_order_id"},
				{ "data": "nature_work","name": "nature_work"},
				{ "data": "contractor_id","name": "contractor_id"},
				{ "data": "installer_name","name": "installer_name"},
				{ "data": "customer_id", "name": "customer_id"},
				{ "data": "installer_id","name": "installer_id"},
				{ "data": "end_job","name": "end_job"}, 
				{ "data": "rating","name": "rating"}, 
				{ "data": "action","name": "action"}, 
				],	
				"columnDefs": [
				{
					"render": function ( data, type, row ) {
						if (data.indexOf("New/") >= 0) {
							var split = data.split('/');
							return '<small class="label label-warning">'+split[0]+'</small>&nbsp;'+split[1];
						}else {
							return data;
						}
					},
					"targets": 0
				},
				{
					"render": function ( data, type, row ) {
						var split = data.split('/');
						var link1 = "{{ url('/contractor/docket/generate-pdf')}}"+"/"+split[0];
						var link2 = "{{ url('/contractor/work-order/generate-pdf') }}"+"/"+split[1];
						return '<a target="_blank" href="'+link1+'" class="tablectrl_medium bGreen tipS" title="View Docket PDF"><span class="iconb" data-icon=""></span></a> <a target="_blank" href="'+link2+'" class="tablectrl_medium bBlue tipS" title="View W/O PDF"><span class="iconb" data-icon=""></span></a>';
					},
					"targets": 10
				},
				],			
			});	

			//===== Modal =====//
			$('#fbyear,#fbmonth').change(function() 
			{
				var link = "{{ url('/contractor/docket/get-docket-list') }}" +"/"+$('#fbyear').val()+"/"+$('#fbmonth').val()+"/null";
				table.ajax.url( link ).load();
			});
		});
	</script>
@endsection