@extends('market.layout.master')
@section('ptitle', 'Marketing')
@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" style="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>
						</tr>
					</thead>
				</table>
			</div> 		
			<div class="dialog-delete" title="Delete Company">
		        <p id="inner-delete"></p>
		    </div>		
		</div>
	</div>
@endsection

@section('external_js')
<script>
	function deleteA(cid,name,email) {
		var cid = cid;
		var name = name;
		var email = email;

		$('.dialog-delete').attr('data-id' , cid); 
		document.getElementById("inner-delete").innerHTML = "<p>Are you sure want to delete this Agent ( " + name + " )?</p>";

		$('.dialog-delete').dialog('open');
		return false;
	};

	$(document).ready(function(){

		var origin   = window.location.origin; 
		var curr = '{{ $user->_id }}';

			//===== 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('/marketing/docket/get-docket-list') }}",
				"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"}, 
				],	
				 "columnDefs": [
				 {
						"render": function ( data, type, row ) {
							var link = "{{ url('/marketing/docket/generate-pdf') }}"+"/"+data;
							return '<a href="'+link+'" target="_blank"><b>'+data+'</b></a>';
						},
						"targets": 1
					},
				],			
			});	

			//===== Modal =====//
			$('.dialog-delete').dialog({
				autoOpen: false, 
				width: 400,
				modal: true,
				buttons: {
					"Yes!": function () {
						var id = $(this).data('id');
						// window.alert(email);
						$.ajax({
							type: "POST",
							url: "{{ url('/Marketing/Agent/delete-agent') }}",
							data: { "_token": "{{ csrf_token() }}", id: id },
							success:function(data)
							{
								if(data == "true"){
									window.location.reload();
								}else if(data == "false"){
									alert("ERROR!! Cant Delete Agent !");
								}
							}
						});
					},
					"Cancel": function () {
						$(this).dialog("close");
						$('.dialog-delete').removeAttr('data-id'); 
					}
				}
			});		

			$('#fbyear,#fbmonth').change(function() 
			{
				if($('#fbyear').val() != '' && $('#fbmonth').val() != '')
				{
					table.ajax.url( origin+'/marketing/docket/filter/'+$('#fbyear').val()+'/'+$('#fbmonth').val() ).load();
					// alert('TEST');
				}
				else if($('#fbyear').val() == '' && $('#fbmonth').val() == '')
				{
					table.ajax.url( origin+'/marketing/docket/filter/null/null' ).load();
				}

				else if($('#fbyear').val() != '' && $('#fbmonth').val() == '')
				{
					table.ajax.url( origin+'/marketing/docket/filter/'+$('#fbyear').val()+'/null' ).load();	
				}

			$('.tipS').tipsy({gravity: 's',fade: true, html:true});
			});
		});
	</script>
@endsection