@extends('backend.layouts.master')

@section('title', 'Worker Report List')

@push('css')
<link rel="stylesheet" href="{{asset('backend/plugins/select2.min.css')}}">
<!-- bootstrap-datetimepicker -->
	<link rel="stylesheet" href="{{ asset('myfile/backend/assets/datepicker/zebra_datepicker.min.css') }}" type="text/css">
	<link rel="stylesheet" href="{{ asset('myfile/backend/assets/datepicker/examples.css') }}" type="text/css">
	<style>
		#search-btn{
			margin-top:24px;
		}
		/*thead{
			font-size: 11px;
		}
		tbody{
			font-size: 11px;
		}*/
	</style>
@endpush
@section('content')
	<div class="right_col" role="main">
        <div class="">
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_title">
							<a href="{{ route('report.worker_report')}}" calss="btn" ><h2><i class="fa fa-mail-reply"></i></h2></a>
                            <h2>Worker Wage Report</h2>
                            <ul class="nav navbar-right panel_toolbox">
                                <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                                </li>
                                <li class="dropdown">
                                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
                                       aria-expanded="false"><i class="fa fa-wrench"></i></a>
                                    <ul class="dropdown-menu" role="menu">
                                        <li><a href="#">Settings 1</a>
                                        </li>
                                        <li><a href="#">Settings 2</a>
                                        </li>
                                    </ul>
                                </li>
                                <li><a class="close-link"><i class="fa fa-close"></i></a>
                                </li>
                            </ul>
                            <div class="clearfix"></div>
                        </div>
                        <div class="x_content">
							<form id="demo-form2" action="{{ route('report.worker_reports')}}" method="post" data-parsley-validate class="form" enctype="multipart/form-data" >
								{{ csrf_field()}}
								<div class="row">
									<div class="col-sm-1"></div>
									<div class="col-sm-3">
										<div class="form-group">
											<label>Worker List *</label>
											<select name="worker_id" id="worker_id" class="form-control input-sm select2">
												<option value="All">All</option>
												@foreach($workers as $pr)
													<option value="{{ $pr->id}}">{{ $pr->name}} ({{$pr->phone}})</option>
												@endforeach
											</select>
										</div>
									</div>
									<div class="col-sm-2">
										<div class="form-group">
											<label>From</label>
											<input id="datepicker-range-start" type="text" name="from_date"  class="form-control" data-zdp_readonly_element="false">
										</div>
									</div>
									<div class="col-sm-2">
										<div class="form-group">
											<label>To</label>
											<input id="datepicker-range-end" type="text" name="to_date"  class="form-control" data-zdp_readonly_element="false">
										</div>
									</div>
									<div class="col-sm-2">
										<div class="form-group">
											<label>Report Type</label>
											<select class="form-control select2" name="report_type">
												<option value="Product" {{request()->report_type == 'Product' ? 'selected' : '' }}>Product Report</option>
												<option value="Wage" {{request()->report_type == 'Wage' ? 'selected' : '' }}>Wage Report</option>
											</select>
										</div>
									</div>
									<div class="col-sm-1">
										<div class="form-group">
											<button class="btn btn-info btn-xs" id="search-btn">
												<i class="ace-icon fa fa-search fa-2x icon-only"></i>
											</button>
										</div>
									</div>
									<div class="col-sm-1">
										<a href="#" id="search-btn" class="btn btn-info btn-xs" onclick="printDiv('printableArea')">
											<i class="ace-icon fa fa-print fa-2x icon-only"></i>
										</a>
									</div>
								</div>
							</form>
							<hr/>
							<div class="row">
								<div class="col-md-12 col-sm-12 col-xs-12">
									<div class="x_content" id="printableArea">
										<div class="row">
											<div class="col-xs-12 col-sm-12">
											@if($reports != '')
												<div class="row">
													<div class="col-xs-1"></div>
													<div class="col-xs-1">
														<img src="{{ asset('storage/about/'.about()->logo)}}" class="img-responsive img-thumbnail" alt="logo" width="85px" height="75px" >
													</div>
													<div class="col-xs-8">
														<div class="text-center">
															<h4>{{about()->english_name}}</h4>
															<h5>Worker Wage Report</h5>
															<p>Worker: {{$ty}}</p>
															<p>From: {{ date("d-m-Y", strtotime($from))}} - {{ date("d-m-Y", strtotime($to))}}</p>
														</div>
													</div>
													<div class="col-xs-2"></div>
												</div>
												@if(request()->report_type == 'Product')
												<table class="table table-condensed table-bordered">
													<thead>
														<tr>
															<th>SL</th>
															<th>Date</th>
                                                            @if(request()->worker_id == 'All')
															<th>Worker</th>
                                                            @endif
															<th>Category</th>
															<th>Product</th>
															<th>Quantity</th>
															<!--<th>Now Stock</th>-->
															<th>Wage</th>
														</tr>
													</thead>
													<tbody>
														@php
															$total = 0;
														@endphp
													@foreach($reports as $key=>$pur)
														@php
															$total += $pur->wage;
														@endphp
														<tr>
															<td>{{ $key + 1}}</td>
															<td>{{ date("d-m-Y", strtotime($pur->production_date))}}</td>
															@if(request()->worker_id == 'All')
															<td>{{ $pur->worker->name}}</td>
                                                            @endif
															<td>{{ $pur->category->name}}</td>
															<td>{{ $pur->product->product_name}}</td>
															<td>{{ $pur->quantity}}</td>
															<!--<td>{{ $pur->stock}}</td>-->
															<td>{{ $pur->wage}}</td>
														</tr>
													@endforeach
														<tr>
                                                        @if(request()->worker_id == 'All')
															<th colspan="2"></th>
                                                        @else
                                                            <th></th>
                                                        @endif
															<th colspan="4">Total=</th>
															<th>{{$total}}</th>
														</tr>
													</tbody>
												</table>
												@endif
												@if(request()->report_type == 'Wage')
												<table class="table table-condensed table-bordered">
													<thead>
														<tr>
															<th>SL</th>
															<th>Date</th>
                                                            @if(request()->worker_id == 'All')
															<th>Worker</th>
                                                            @endif
															<th>Amount</th>
														</tr>
													</thead>
													<tbody>
														@php
															$total = 0;
														@endphp
													@foreach($reports as $key=>$pur)
														@php
															$total += $pur->amount;
														@endphp
														<tr>
															<td>{{ $key + 1}}</td>
															<td>{{ date("d-m-Y", strtotime($pur->payment_date))}}</td>
															@if(request()->worker_id == 'All')
															<td>{{ $pur->name}}</td>
                                                            @endif
															<td>{{ $pur->amount}}</td>
														</tr>
													@endforeach
														<tr>
                                                        @if(request()->worker_id == 'All')
															<th colspan="2"></th>
                                                        @else
                                                            <th></th>
                                                        @endif
															<th>Total=</th>
															<th>{{$total}}</th>
														</tr>
													</tbody>
												</table>
												@endif
											@else
												<p align="center">Sory! no data found.</p>
											@endif
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
@endsection

@push('js')
<script src="{{asset('backend/plugins/select2.min.js')}}"></script>
<!-- Jquery Plugin For Date Calender-->
<script type="text/javascript" src="{{ asset('myfile/backend/assets/datepicker/zebra_datepicker.src.js') }}"></script>
<script type="text/javascript" src="{{ asset('myfile/backend/assets/datepicker/examples.js') }}"></script>
<script>
  $(document).ready(function() 
  {
	// select2 section
    $('.select2').select2()	;
	});

    function printDiv(divName) {
		 var printContents = document.getElementById(divName).innerHTML;
		 var originalContents = document.body.innerHTML;
		 document.body.innerHTML = printContents;
		 window.print();
		 document.body.innerHTML = originalContents;
	}
</script>
@endpush
    
 