@extends('admin.master')
@section('content')
@section('title','Generate Salary Sheet')
<style>
	.table>tbody>tr>td {
		padding: 5px 7px;
	}
	.address{
		margin-top: 22px;
	}
	.employeeName{
		position: relative;
	}
	#employee_id-error{
		position: absolute;
		top: 66px;
		left: 0;
		width: 100%he;
		width: 100%;
		height: 100%;
	}
	.icon-question {
		color: #7460ee;
		font-size: 16px;
		vertical-align: text-bottom;
	}

</style>
<div class="container-fluid">
	<div class="row bg-title">
		<div class="col-lg-5 col-md-5 col-sm-5 col-xs-12">
			<ol class="breadcrumb">
				<li class="active breadcrumbColor"><a href="{{ url('dashboard') }}"><i class="fa fa-home"></i> Dashboard</a></li>
				<li>@yield('title')</li>

			</ol>
		</div>
		<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12">
			<a href="{{route('generateSalarySheet.index')}}"  class="btn btn-success pull-right m-l-20 hidden-xs hidden-sm waves-effect waves-light"><i class="fa fa-list-ul" aria-hidden="true"></i>  Generate Payslip</a>
		</div>
	</div>
	<div class="row">
		<div class="col-md-12">
			<div class="panel panel-info">
				<div class="panel-heading"><i class="mdi mdi-clipboard-text fa-fw"></i> @yield('title')</div>
				<div class="panel-wrapper collapse in" aria-expanded="true">
					<div class="panel-body">
						@if($errors->any())
							<div class="alert alert-danger alert-dismissible" role="alert">
								<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
								@foreach($errors->all() as $error)
									<strong>{!! $error !!}</strong><br>
								@endforeach
							</div>
						@endif
						@if(session()->has('success'))
							<div class="alert alert-success alert-dismissable">
								<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
								<i class="cr-icon glyphicon glyphicon-ok"></i>&nbsp;<strong>{{ session()->get('success') }}</strong>
							</div>
						@endif
						@if(session()->has('error'))
							<div class="alert alert-danger alert-dismissable">
								<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
								&nbsp;<strong>{{ session()->get('error') }}</strong>
							</div>
						@endif
						{{ Form::open(array('route' => 'generateSalarySheet.calculateEmployeeSalary','method'=>'GET','id'=>'calculateEmployeeSalaryForm')) }}
						<div class="form-body">
							<div class="row">
								<div class="col-md-offset-2 col-md-3">
									<div class="form-group employeeName">
										<label for="exampleInput">Employee<span class="validateRq">*</span></label>
										{{ Form::select('employee_id',$employeeList, (isset($employee_id)) ? $employee_id : '', array('class' => 'form-control employee_id select2 required')) }}
									</div>
								</div>
								<div class="col-md-3">
									<label for="exampleInput">Month<span class="validateRq">*</span></label>
									<div class="input-group">
										<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
										{!! Form::text('month', (isset($month)) ? $month : '', $attributes = array('class'=>'form-control required monthField','id'=>'month','placeholder'=>'Enter month')) !!}
									</div>
								</div>
								<div class="col-md-2">
									<div class="form-group">
										<button type="submit" class="btn btn-info " style="margin-top: 24px"> Generate Salary</button>
									</div>
								</div>
							</div>
						</div>
						{{ Form::close() }}
					</div>
				</div>
			</div>

            <?php
				$grossSalary = 0;
            	$totalOvertimeAmount = 0;
            	$totalAbsenceAmount = 0;
            	$totalLateAmount = 0;
            	$totalDeduction = 0;

            ?>
			@if(isset($basicSalary) || isset($allowances))
			<div class="panel panel-info">
				<div class="panel-heading"><i class="mdi mdi-clipboard-text fa-fw"></i> Employee Salary Details</div>
				<div class="panel-wrapper collapse in" aria-expanded="true">
					<div class="panel-body">
						<div class="form-body">
							{{ Form::open(array('route' => 'saveEmployeeSalaryDetails.store')) }}
							<div class="table-responsive">
								<table class="table table-bordered table-hover">
									<thead class="tr_header">
									<tr>
										<th style="width: 100px">#</th>
										<th>Description</th>
										<th style="width: 300px">Amount</th>
									</tr>
									</thead>
									<tbody>
									<tr>
										<td colspan="3"><b>Basic Salary</b></td>
									</tr>
									<tr>
										<td>1</td>
										<td>Basic Salary</td>
										<td>
											<div class="input-group">
												<span class="input-group-addon">TK</span>
												<input type="text" readonly  class="form-control add" value="{{$basicSalary}}">
											</div>
										</td>
									</tr>
									{{--Allowance--}}
									@php $allowanceSl = 0 @endphp
									@if(count($allowances['allowanceArray'] ) > 0)
										<tr>
											<td colspan="3"><b>Allowance</b></td>
										</tr>

										@foreach($allowances['allowanceArray'] as $allowance)
										<tr>
											<td>{{++$allowanceSl}}</td>
											<td>
												{{$allowance['allowance_name']}}
												<span class="icon-question  btn-outline tooltip-primary" data-toggle="tooltip" data-placement="top" title=""
													  data-original-title="
															@if($allowance['percentage_of_basic'] !=0)
													  			{{"Percentage of basic"}} {{$allowance['percentage_of_basic']}},
													  			{{"Max limit per month"}} {{$allowance['limit_per_month']}} Tk.
													        @else
													  			{{"Max limit per month"}} {{$allowance['limit_per_month']}} Tk.
													  		@endif">
											</td>
											<td>
												<div class="input-group">
													<span class="input-group-addon">TK</span>
													<input type="hidden"  class="form-control allowance" name="allowance_id[]" value="{{$allowance['allowance_id']}}">
													<input type="text"  class="form-control allowance" readonly name="amount_of_allowance[]" value="{{$allowance['amount_of_allowance']}}">
												</div>
											</td>
										</tr>
										@endforeach
									@endif
									{{-- ovar Time--}}
									@if($employeeAllInfo['totalOvertimeAmount'] !=0)
										@if($allowanceSl == 0)
											<tr>
												<td colspan="3"><b>Allowance</b></td>
											</tr>
										@endif
										<tr>
											<td>{{++$allowanceSl}}</td>
											<td> Over Time
												<span class="icon-question  btn-outline tooltip-primary" data-toggle="tooltip" data-placement="top" title=""
													  data-original-title="Total over time hour {{$employeeAllInfo['totalOverTimeHour']}}, Overtime rate per hour {{$employeeAllInfo['overtime_rate']}}">
											</span>
											</td>
											<td>
												<div class="input-group">
													<span class="input-group-addon">TK</span>
													<input type="hidden" name="overtime_rate" class="form-control allowance" value="{{$employeeAllInfo['overtime_rate']}}">
													<input type="hidden" name="total_over_time_hour" class="form-control allowance" value="{{$employeeAllInfo['totalOverTimeHour']}}">
													<input type="text" readonly  name="total_overtime_amount" class="form-control allowance" value="{{$employeeAllInfo['totalOvertimeAmount']}}">
												</div>
											</td>
										</tr>
									@endif


									{{--Deduction--}}
									@php $deductionSl = 0 @endphp
									@if(count($deductions['deductionArray']) > 0)
										<tr>
											<td colspan="3"><b>Deduction</b></td>
										</tr>
										@foreach($deductions['deductionArray'] as $deduction)
											@php $totalDeduction+= $deduction['amount_of_deduction'];@endphp
										<tr>
											<td>{{++$deductionSl}}</td>
											<td>
												{{$deduction['deduction_name']}}
												<span class="icon-question  btn-outline tooltip-primary" data-toggle="tooltip" data-placement="top" title=""
													  data-original-title="
															@if($deduction['percentage_of_basic'] !=0)
													 			 {{"Percentage of basic"}} {{$deduction['percentage_of_basic']}},
													  			{{"Max limit per month"}} {{$deduction['limit_per_month']}} Tk.
													        @else
													 			 {{"Max limit per month"}} {{$deduction['limit_per_month']}} Tk.
													  		@endif">
											</td>
											<td>
												<div class="input-group">
													<span class="input-group-addon">TK</span>
													<input type="hidden"  class="form-control deduction" name="deduction_id[]" value="{{$deduction['deduction_id']}}">
													<input type="text"  class="form-control deduction" readonly name="amount_of_deduction[]" value="{{$deduction['amount_of_deduction']}}">
												</div>
											</td>
										</tr>
										@endforeach
									@endif
									{{-- Late Count --}}

									@if($employeeAllInfo['totalLateAmount'] !=0)
									@if($deductionSl == 0)
										<tr>
											<td colspan="3"><b>Deduction</b></td>
										</tr>
									@endif
									<tr>
										<td>{{++$deductionSl}}</td>
										<td>
											Late
											<span class="icon-question  btn-outline tooltip-primary" data-toggle="tooltip" data-placement="top" title=""
												  data-original-title="Total Late {{  $employeeAllInfo['totalLate'] }} days">
											</span>
										</td>
										<td>
											<div class="input-group">
												<span class="input-group-addon">TK</span>
												<input type="hidden"  name="total_late"  class="form-control deduction" value="{{$employeeAllInfo['totalLate']}}">
												<input type="text" readonly name="total_late_amount"  class="form-control deduction" value="{{$employeeAllInfo['totalLateAmount']}}">
											</div>
										</td>
									</tr>
									@endif
									{{-- Absence  --}}

									@if($employeeAllInfo['totalAbsence'] !=0)
									@if($deductionSl == 0)
										<tr>
											<td colspan="3"><b>Deduction</b></td>
										</tr>
									@endif
									<tr>
										<td>{{++$deductionSl}}</td>
										<td>
											Absence
											<span class="icon-question  btn-outline tooltip-primary" data-toggle="tooltip" data-placement="top" title=""
												  data-original-title="Total working days {{$employeeAllInfo['totalWorkingDays']}},Total absence  {{$employeeAllInfo['totalAbsence']}} days">
											</span>
										</td>
										<td>
											<div class="input-group">
												<span class="input-group-addon">TK</span>
												<input type="hidden" name="total_absence"  class="form-control deduction" value="{{$employeeAllInfo['totalAbsence']}}">
												<input type="text" readonly name="total_absence_amount"  class="form-control deduction" value="{{$employeeAllInfo['totalAbsenceAmount']}}">
											</div>
										</td>
									</tr>
									@endif
									{{-- Tax --}}

										<tr>
											<td>{{++$deductionSl}}</td>
										<td>Tax</td>
										<td>
											<div class="input-group">
												<span class="input-group-addon">TK</span>
												<input type="text" readonly   class="form-control deduction" value="{{$tax}}">
											</div>
										</td>
									</tr>

									@php
										$totalOvertimeAmount = $employeeAllInfo['totalOvertimeAmount'];
										$totalAbsenceAmount = $employeeAllInfo['totalAbsenceAmount'];
										$totalLateAmount = $employeeAllInfo['totalLateAmount'];
										$sumOfTotalDeduction =$totalDeduction + $tax + $totalLateAmount + $totalAbsenceAmount;
										$grossSalary = ($basicSalary + $allowances['totalAllowance'] + $totalOvertimeAmount) - $sumOfTotalDeduction;
									@endphp

									{{--total--}}

									<input type="hidden" name="total_present" value="{{$employeeAllInfo['totalPresent']}}">
									<input type="hidden" name="total_leave" value="{{$employeeAllInfo['totalLeave']}}">
									<input type="hidden" name="total_working_days" value="{{$employeeAllInfo['totalWorkingDays']}}">
									<input type="hidden" name="employee_id" value="{{$employee_id}}">
									<input type="hidden" name="month_of_salary" value="{{$month}}">
									<input type="hidden" name="action" value="monthlySalary">
									<input type="hidden" name="tax" readonly  class="form-control tax" value="{{$tax}}">

									<tr>
										<td colspan="2" class="text-right"><b>Basic Salary</b></td>
										<td>
											<div class="input-group">
												<span class="input-group-addon"><b>TK</b></span>
												<input type="text" readonly  class="form-control basic_salary" name="basic_salary" value="{{$basicSalary}}">
											</div>
										</td>
									</tr>
									<tr>
										<td colspan="2" class="text-right"><b>Total Allowance</b></td>
										<td>
											<div class="input-group">
												<span class="input-group-addon"><b>TK</b></span>
												<input type="text" readonly  class="form-control total_allowance" name="total_allowance" value="{{$allowances['totalAllowance']+$totalOvertimeAmount}}">
											</div>
										</td>
									</tr>
									<tr>
										<td colspan="2" class="text-right"><b>Total Deduction</b></td>
										<td>
											<div class="input-group">
												<span class="input-group-addon"><b>TK</b></span>
												<input type="text" readonly  class="form-control total_deduction" name="total_deduction" value="{{$sumOfTotalDeduction}}">
											</div>
										</td>
									</tr>

									<tr>
										<td colspan="2" class="text-right"><b>Gross Salary</b></td>
										<td>
											<div class="input-group">
												<span class="input-group-addon"><b>TK</b></span>
												<input type="text" readonly name="gross_salary" class="form-control gross_salary" value="{{round($grossSalary)}}">
											</div>
										</td>
									</tr>
									</tbody>
								</table>

								<div class="col-md-12 text-center">
									<div class="form-group">
										<button type="submit" class="btn btn-info btn_style"><i class="fa fa-check"></i> Save</button>
									</div>
								</div>

							</div>

							{{ Form::close() }}
						</div>
					</div>
				</div>
			</div>
				@endif
		</div>
	</div>
</div>
@endsection

@section('page_scripts')
	<script type="text/javascript">
        jQuery(function(){
            $("#calculateEmployeeSalaryForm").validate();
        });
	</script>
@endsection
