@extends('layouts.default')

@section('title')
@parent
  Заявки на расход :: Бюджет для "{{ $workProject->name }}"
@stop

@section('breadcrumbs')
	{{ Breadcrumbs::render('budget.costsrequests', $workProject) }}
@stop

@section('css')
  <link rel="stylesheet" href="{{asset('css/jquery.fileupload.css')}}">
	<link rel="stylesheet" href="{{ asset('css/bootstrap-validator.min.css') }}">
@stop

@section('js')
  <script src="{{asset('js/jquery.fileupload.js')}}"></script>
	<script src="{{asset('js/jquery.iframe-transport.js')}}"></script>
	<script src="{{ asset('js/plugin/x-editable/x-editable.min.js') }}"></script>
	<script src="{{ asset('js/plugin/bootstrapvalidator/bootstrapValidator.min.js') }}"></script>
	<script src="{{ asset('js/kmk-support.js') }}"></script>
	<script src="{{ asset('js/costsRequests.js') }}"></script>
@stop

@section('content')
<div class="row">
	<?php 
		$projectAmount = $workProject->getCurrentBudgetMonthPlan(); // бюджет проекта
		$userType = '';
		$signRequest = 0;
		if( Auth::user()->hasRole(Role::ROLE_BUDGET_OUTCOMING_REQUEST) ){
			$userType = 1;
		}else if( Auth::user()->hasRole(Role::ROLE_BUDGET_CFO) ){
			$userType = 2;
		}else if( Auth::user()->hasAnyRole(array(Role::ROLE_BUDGET_ACCOUNTANT, Role::ROLE_BUDGET_ACC_SECRETARY)) ){
			$userType = 3;
		}
		
		if( Auth::user()->hasRole(Role::ROLE_BUDGET_SIGN_COST_REQUEST) ){
			$signRequest = 1;
		}
		$statusType = Session::get('statusType');
		Session::put('userType', $userType);
		Session::put('signRequest', $signRequest);
	?>
  <div class="col-md-12 col-lg-12 col-sm-12">
		<div class="panel panel-default">
			@include('budget/menu')
			<div class="panel-body">
			  @include('budget/costsrequests/btns')
				<!--<form class="form-inline pull-right" role="form">
					<div class="form-group">
						<input id="startDate" name="startDate" class="form-control input-sm" value="{{-- $startDate --}}"/>
					</div>
					<div class="form-group">
						<input id="endDate" name="endDate" class="form-control input-sm" value="{{-- $endDate --}}"/>
					</div>
				</form>-->
				<div class="clearfix"></div>
				<div class="table-responsive">
					<table class="table table-condensed table-hover">
						<thead>
							<tr>
                <th>
                  <a href="{{ action('BudgetCostsRequestsController@costsRequestsSearch', ['type' => isset($input['type'])? $input['type'] : '', 'content' => isset($input['content'])? $input['content']: '', 'datetype' => isset($input['datetype'])? $input['datetype']: '', 'beginDate' => isset($input['beginDate'])? $input['beginDate'] : '', 'endDate' => isset($input['endDate'])? $input['endDate'] : '', 'direction' => ($direction == 'asc' ? 'desc' : 'asc'), 'orderBy' => 'id']) }}"><span class="fa fa-slack"> <span class="fa fa-unsorted"></span></span></a>
                </th>
								<th>
                  <a href="{{ action('BudgetCostsRequestsController@costsRequestsSearch', ['type' => isset($input['type'])? $input['type'] : '', 'content' => isset($input['content'])? $input['content']: '', 'datetype' => isset($input['datetype'])? $input['datetype']: '', 'beginDate' => isset($input['beginDate'])? $input['beginDate'] : '', 'endDate' => isset($input['endDate'])? $input['endDate'] : '', 'direction' => ($direction == 'asc' ? 'desc' : 'asc'), 'orderBy' => 'created_at']) }}">Дата <span class="fa fa-unsorted"></span> </a> /
                  <a href="{{ action('BudgetCostsRequestsController@costsRequestsSearch', ['type' => isset($input['type'])? $input['type'] : '', 'content' => isset($input['content'])? $input['content']: '', 'datetype' => isset($input['datetype'])? $input['datetype']: '', 'beginDate' => isset($input['beginDate'])? $input['beginDate'] : '', 'endDate' => isset($input['endDate'])? $input['endDate'] : '', 'direction' => ($direction == 'asc' ? 'desc' : 'asc'), 'orderBy' => 'project_id']) }}">Проект <span class="fa fa-unsorted"></span></a>
                </th>
								<th>
                  <a href="{{ action('BudgetCostsRequestsController@costsRequestsSearch', ['type' => isset($input['type'])? $input['type'] : '', 'content' => isset($input['content'])? $input['content']: '', 'datetype' => isset($input['datetype'])? $input['datetype']: '', 'beginDate' => isset($input['beginDate'])? $input['beginDate'] : '', 'endDate' => isset($input['endDate'])? $input['endDate'] : '', 'direction' => ($direction == 'asc' ? 'desc' : 'asc'), 'orderBy' => 'budget_cost_request_id']) }}">Статья расходов <span class="fa fa-unsorted"></span></a>
                </th>
								@if( $userType != 3 )
								  <th class="text-center">Бюджет</th>
								@else
								<th class="text-right" title="Номер платежного поручения при безналичной оплате">№ п/п</th>
								@endif
								<th>Файлы</th>
								<th class="text-right">
                  <a href="{{ action('BudgetCostsRequestsController@costsRequestsSearch', ['type' => isset($input['type'])? $input['type'] : '', 'content' => isset($input['content'])? $input['content']: '', 'datetype' => isset($input['datetype'])? $input['datetype']: '', 'beginDate' => isset($input['beginDate'])? $input['beginDate'] : '', 'endDate' => isset($input['endDate'])? $input['endDate'] : '', 'direction' => ($direction == 'asc' ? 'desc' : 'asc'), 'orderBy' => 'requested_amount']) }}">Сумма <span class="fa fa-unsorted"></span></a>
                </th>
                <th class="table-comment">
                  <a href="{{ action('BudgetCostsRequestsController@costsRequestsSearch', ['type' => isset($input['type'])? $input['type'] : '', 'content' => isset($input['content'])? $input['content']: '', 'datetype' => isset($input['datetype'])? $input['datetype']: '', 'beginDate' => isset($input['beginDate'])? $input['beginDate'] : '', 'endDate' => isset($input['endDate'])? $input['endDate'] : '', 'direction' => ($direction == 'asc' ? 'desc' : 'asc'), 'orderBy' => 'request_comment']) }}">Комментарий <span class="fa fa-unsorted"></span></a>
                </th>
							</tr>
						</thead>
						<tbody id='budgetCostsRequestContainer'>
							@foreach($costsRequests as $costsRequest)
							  @include('budget/costsrequests/searchoperation')
							@endforeach
						</tbody> 
					</table>
				</div>
				<dl class="dl-horizontal">
					<dt>Заявок на сумму: </dt>
					<dd><span id="totalRequestsSum" class="to-humanize"> </span> из <span class="to-humanize"> {{ ( count($costsRequests) != 0 )? $sum : '' }}</span> <i class="fa fa-rub"></i></dd>
					<dt>Кол-во: </dt>
					<dd>
            @if( count($costsRequests) != 0 )
            <span class="to-humanize">{{ $costsRequests->getFrom() }}</span> - 
            <span class="to-humanize">{{ $costsRequests->getTo() }}</span> из
            <span class="to-humanize">{{ $costsRequests->getTotal() }}</span>
            @else
            <span>0</span>
            @endif
          </dd>
				</dl>
        <div class="text-center">
          {{ ( count($costsRequests) != 0 )? $costsRequests->appends(Input::all())->links() : '' }}
        </div>
			</div>
		</div>
	</div>
</div>

	@section('modals')
		@include('budget/costsrequests/modal')
	@stop
@stop