<?php
   // кол-во заявок для подписи
  $onSignButton = '';
  if(Auth::user()->hasRole(Role::ROLE_BUDGET_SIGN_COST_REQUEST) && !Auth::user()->isAdmin()){
		$countSign = BudgetCostsRequests::whereProjectId($workProject->id)->whereStatus(BudgetCostsRequests::STATUS_WORK)->whereDirectorId(Auth::user()->id)->count();
		if($countSign){$countSign = '('.$countSign.')';} else { $countSign = ''; }
		$btnUrl = URL::to('budget/costsrequests/sign');
		if (Request::is('budget/costsrequests/sign*')) {$isActive = ' active';} else {$isActive = '';}
		$onSignButton = '<a href="'.$btnUrl.'" class="btn btn-info'.$isActive.'"><i class="fa fa-pencil"></i> На подписи <b class="requestsQuant">'.$countSign.'</b></a>';
	}
	
	$mySignRequests = '';
  if(Auth::user()->hasRole(Role::ROLE_BUDGET_SIGN_COST_REQUEST) && !Auth::user()->hasRole(Role::ROLE_BUDGET_CFO)) {
		$btnUrl = URL::to('budget/costsrequests/mysign');
		if (Request::is('budget/costsrequests/mysign*')) {$isActive = ' active';} else {$isActive = '';}
		$mySignRequests = '<li class="'.$isActive.'"><a href="'.$btnUrl.'"><h5></h5><i class="fa fa-legal"></i> С моей подписью <h5></h5></a></li>';
	}
	 // кол-во возвратов от директора
	$requestsBackOff = BudgetCostsRequests::whereProjectId($workProject->id)
																					->whereApplicantId(Auth::user()->id)
																					->whereStatus(BudgetCostsRequests::STATUS_BACK_OFF)
																					->orderBy('created_at', 'DESC')
																					->count();
?>
<div class="row bottom-menu-small">
	<div class="col-md-9">
		<!-- раздел финдиректора ROLE_BUDGET_CFO-->
		@if ( Auth::user()->hasRole(Role::ROLE_BUDGET_CFO) && Request::is('budget/costsrequests*') && !Auth::user()->isAdmin())	
		<?php 
			$countSigned = BudgetCostsRequests::whereProjectId($workProject->id)->whereStatus(BudgetCostsRequests::STATUS_SIGNED)->whereProjectId($workProject->id)->count(); 
		?>
		<button id="openCreateRequestModal" data-toggle="modal" class="btn btn-success pull-left" style="margin-right:10px"><i class="fa fa-plus"></i> Создать заявку</button>	
		<div class="pull-left">
			{{ $onSignButton }}
			<a href="{{ URL::to('budget/costsrequests/new') }}" class="btn btn-default @if (Request::is('budget/costsrequests/new*')) active @endif"><i class="fa fa-pencil"></i> Подписано <b class="requestsQuant">{{ ($countSigned)? ('('.$countSigned.')') : '' }}</b></a>
			<a href="{{ URL::to('budget/costsrequests/agreed') }}" class="btn btn-default @if (Request::is('budget/costsrequests/agreed*')) active @endif"><i class="fa fa-thumbs-up text-success"></i> Одобрено </a>
			<a href="{{ URL::to('budget/costsrequests/rejected') }}" class="btn btn-default @if (Request::is('budget/costsrequests/rejected*')) active @endif"><i class="fa fa-ban text-danger"></i> Отказано</a>
			<a href="{{ URL::to('budget/costsrequests/paid') }}" class="btn btn-default @if (Request::is('budget/costsrequests/paid*')) active @endif"><i class="fa fa-check text-muted"></i> Оплачено</a>
			<a href="{{ URL::to('budget/costsrequests/my') }}" class="btn btn-default @if (Request::is('budget/costsrequests/my*')) active @endif"> Мои <b class="requestsQuant">{{ ($requestsBackOff)? ('('.$requestsBackOff.')') : '' }}</b></a>
			<!--<a href="{{ URL::to('budget/costsrequests/search') }}" class="btn btn-default text-bold @if (Request::is('budget/costsrequests/search*')) active @endif"><i> Поиск заявок </i></a>-->
		</div>

		<!-- раздел бухгалтерии ROLE_BUDGET_ACCOUNTANT, ROLE_BUDGET_ACC_SECRETARY -->
		@elseif (Auth::user()->hasAnyRole(array(Role::ROLE_BUDGET_ACCOUNTANT, Role::ROLE_BUDGET_ACC_SECRETARY)) && Request::is('budget/costsrequests*') && !Auth::user()->isAdmin())
		<?php 
			$countApprovedRequests = BudgetCostsRequests::whereStatus(BudgetCostsRequests::STATUS_APPROVED)->whereProjectId($workProject->id)->count();
		?>
		<button id="openCreateRequestModal" data-toggle="modal" class="btn btn-success pull-left" style="margin-right:10px"><i class="fa fa-plus"></i> Создать заявку</button>	
		<div class="pull-left">
			{{ $onSignButton }}
			<a href="{{ URL::to('budget/costsrequests/agreed') }}" class="btn btn-default @if (Request::is('budget/costsrequests/agreed*')) active @endif"><i class="fa fa-thumbs-up text-success"></i> Не оплачено <b class="requestsQuant">{{ ($countApprovedRequests)? ('('.$countApprovedRequests.')') : '' }}</b></a>
			<a href="{{ URL::to('budget/costsrequests/paid') }}" class="btn btn-default @if (Request::is('budget/costsrequests/paid*')) active @endif"><i class="fa fa-check text-muted"></i> Оплачено</a>
			<a href="{{ URL::to('budget/costsrequests/my') }}" class="btn btn-default @if (Request::is('budget/costsrequests/my*')) active @endif"> Мои <b class="requestsQuant">{{ ($requestsBackOff)? ('('.$requestsBackOff.')') : '' }}</b></a>
			{{-- $mySignRequests --}}
			<!--<a href="{{ URL::to('budget/costsrequests/search') }}" class="btn btn-default text-bold @if (Request::is('budget/costsrequests/search*')) active @endif"><i> Поиск заявок </i></a>-->
		</div>

		<!-- раздел ROLE_BUDGET_OUTCOMING_REQUEST-->
		@elseif (Auth::user()->hasRole(Role::ROLE_BUDGET_OUTCOMING_REQUEST) && Request::is('budget/costsrequests*'))
			<button id="openCreateRequestModal" data-toggle="modal" class="btn btn-success pull-left" style="margin-right:10px"><i class="fa fa-plus"></i> Создать заявку</button>
				@if( Request::is('budget/costsrequests/pattern') )
				<button id="openCreatePatternRequestModal" data-toggle="modal" class="btn btn-info pull-left" style="margin-right:10px">Добавить шаблон</button>
				@endif
			<div class="pull-left">
				{{ $onSignButton }}
				<a href="{{ URL::to('budget/costsrequests/new') }}" class="btn btn-default @if (Request::is('budget/costsrequests/new*')) active @endif"><i class="fa fa-spinner text-info"></i> Новые <b>{{ $requestsBackOff? '('.$requestsBackOff.')' : '' }}</b></a>
				<a href="{{ URL::to('budget/costsrequests/agreed') }}" class="btn btn-default @if (Request::is('budget/costsrequests/agreed*')) active @endif"><i class="fa fa-thumbs-up text-success"></i> Одобрено</a>
				<a href="{{ URL::to('budget/costsrequests/rejected') }}" class="btn btn-default @if (Request::is('budget/costsrequests/rejected*')) active @endif"><i class="fa fa-ban text-danger"></i> Отказано</a>
				<!--<a href="{{ URL::to('budget/costsrequests/search') }}" class="btn btn-default text-bold @if (Request::is('budget/costsrequests/search*')) active @endif"><i> Поиск заявок </i></a>-->
				
        <div class="btn-group">
					<a href="#" class="btn btn-default dropdown-toggle @if( Request::is('budget/costsrequests/paid*') || Request::is('budget/costsrequests/pattern*') || Request::is('budget/costsrequests/mysign') ) active @endif" data-toggle="dropdown"> Еще <b class="caret"></b> </a>
					<ul class="dropdown-menu">
						{{ $mySignRequests }}
						<li class="@if(Request::is('budget/costsrequests/paid*')) active @endif"><a href="{{ URL::to('budget/costsrequests/paid') }}"><h5></h5><i class="fa fa-check text-muted"></i> Оплачено <h5></h5></a></li>
						<li class="@if(Request::is('budget/costsrequests/pattern*')) active @endif"><a href="{{ URL::to('budget/costsrequests/pattern') }}"><h5></h5><i class="fa fa-copy"></i> Шаблоны <h5></h5></a></li>
					</ul>
				</div>
				
				
			</div>
		@endif
	</div>
	<div class="col-md-3 pull-right">
		<form action="{{ URL::to('budget/costsrequests/search') }}">
			<div class="input-group">
		<!--		<div class="input-group-btn">
					<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" tabindex="-1" aria-expanded="false">
						<span class="caret"></span>
					</button>
					<ul id="searchList" class="dropdown-menu" role="menu">
						<li><a href="#" id="searchAll" data-type="all">Все поля</a></li>
						<li class="divider"></li>
						<li><a href="#" id="searchId" data-type="id">#Номер</a></li>
						<li><a href="#" id="searchDateCreated" data-type="datecreated">Дата создания</a></li>
						<li><a href="#" id="searchCost" data-type="cost">Статья расхода</a></li>
						<li><a href="#" id="searchAmount" data-type="amount"> Сумма</a></li>
					</ul>
				</div>-->
				<div class="icon-addon addon-md">
					<input type="hidden" name="type" value="all">
					<input type="text" id="searchContent" name="content" placeholder="Поиск заявок" class="form-control">
          <input type="hidden" name="datetype" value="">
          <input type="hidden" name="beginDate" value="">
          <input type="hidden" name="endDate" value="">
				</div>
				<span class="input-group-btn">
					<button type="submit" id="fastSearch" class="btn btn-default" type="button"><i class="fa fa-search"></i></button>
				</span>
			</div>
		</form>
	</div>
</div>