@extends('layouts.default')

@section('title')
	@parent
	Создание нового контрагента для "{{ $workProject->name }}"
@stop

@section('content')
<div class="row">
	<div class="col-md-6 col-md-offset-3">
		{{ Form::open(array('action' => 'BudgetPartnersController@store')) }}
		<h2>Создание нового контрагента для "{{ $workProject->name }}"</h2>

		<div class="form-group {{ ($errors->has('name')) ? 'has-error' : '' }}">
			{{ Form::label( 'name', 'Название:', array('class' => 'control-label') ) }}
			{{ Form::text('name', null, array('class' => 'form-control', 'placeholder' => 'Название', 'autofocus')) }}
			{{ ($errors->has('name') ? $errors->first('name') : '') }}
		</div>

		<div class="form-group {{ ($errors->has('city')) ? 'has-error' : '' }}">
			{{ Form::label( 'city', 'Город:', array('class' => 'control-label') ) }}
			{{ Form::text('city', null, array('class' => 'form-control', 'placeholder' => 'Город', 'autofocus')) }}
			{{ ($errors->has('city') ? $errors->first('city') : '') }}
		</div>

		<div class="form-group {{ ($errors->has('current_account')) ? 'has-error' : '' }}">
			{{ Form::label( 'current_account', 'Расчетный счет:', array('class' => 'control-label') ) }}
			{{ Form::text('current_account', null, array('class' => 'form-control', 'placeholder' => 'Расчетный счет')) }}
			{{ ($errors->has('current_account') ? $errors->first('current_account') : '') }}
		</div>

		<div class="form-group {{ ($errors->has('cost_id')) ? 'has-error' : '' }}">
			<label for="cost_id" class="control-label">Статья расходов, связанная с контрагентом</label>
			<select class="form-control" name="cost_id" id="cost_id">
				<?php $budgetCostsGroups = BudgetCost::whereIn('project_id', array($workProject->id, 0))
																							->with('budgetCostGroup')
																							->orderBy('name')
																							->groupBy('budget_cost_group_id')->get(); ?>
					<option value="0">Нет</option>
				@foreach ($budgetCostsGroups as $budgetCostsGroup)
				<optgroup label="{{ ($budgetCostsGroup->budgetCostGroup)? $budgetCostsGroup->budgetCostGroup->name:'Без группы' }}">
					<?php
						$costsToSelect = BudgetCost::whereIn('project_id', array($workProject->id, 0))
																				->where('budget_cost_group_id', '=', $budgetCostsGroup->budget_cost_group_id)
																				->orderBy('name')
																				->get(); ?>
					@foreach ($costsToSelect as $costToSelect)
					<option value="{{ $costToSelect->id }}">{{ $costToSelect->name }}</option>
					@endforeach
				</optgroup>
				@endforeach
			</select>
		</div>

		{{ Form::submit('Создать контрагента', array('class' => 'btn btn-primary')) }}
		{{ Form::button('Отмена', array('class' => 'btn btn-default', 'onclick'=>'location="'.URL::to('budget/partners').'"')) }}

    {{ Form::close() }}
	</div>
</div>

@stop