<?php 
  $projectsName = Project::getProjectsNameList();
?>
<tr id="budgetOperation{{ $budgetOperation->id }}" class="operation-type-{{ $budgetOperation->type }} {{ $budgetOperation->getTrClassName() }}" data-id="{{ $budgetOperation->id }}" data-amount='{{ $budgetOperation->amount }}' @if ($budgetOperation->isnoincome) data-noincome='1' @elseif ($budgetOperation->isnooutcome) data-nooutcome='1' @endif>
	<td title="Нажмите для просмотра истории операции">
    <a href="#">
      <p class="{{ $budgetOperation->getClassName() }}" data-action="{{ action('BudgetOperationHistoryController@getHistory') }}">
        @if ($budgetOperation->type == BudgetOperation::TYPE_INCOMING)
        <i class="fa fa-plus"></i>
        @elseif ($budgetOperation->type == BudgetOperation::TYPE_OUTCOMING)
        <i class="fa fa-minus"></i>
        @elseif ($budgetOperation->type == BudgetOperation::TYPE_EXCHANGE)
        <i class="fa fa-exchange"></i>
        @elseif ($budgetOperation->type == BudgetOperation::TYPE_OPENING_BALANCE)
        <i class="fa fa-arrow-right"></i>
        @elseif ($budgetOperation->type == BudgetOperation::TYPE_OPENING_DEBT_IN)
        <i class="fa fa-arrow-down"></i>
        @elseif ($budgetOperation->type == BudgetOperation::TYPE_OPENING_DEBT_OUT)
        <i class="fa fa-arrow-up"></i>
        @endif
      </p>
    </a>
	</td>
	<td class="nowrap">
		<span title="{{ $budgetOperation->user->first_name }} {{ $budgetOperation->user->last_name }}, {{ $budgetOperation->created_at }}">
			@if ($budgetOperation->isuploaded || !$user->hasRole(Role::ROLE_BUDGET))
				<span>{{ $budgetOperation->getFormattedDate() }}</span>
			@else
				<a href="#" class="editable editable-date" data-type="combodate" data-pk="{{ $budgetOperation->id }}" data-name="date" data-value="{{ $budgetOperation->date }}" date-format="YYYY-MM-DD" data-viewformat="DD.MM.YYYY" data-template="D / MMMM / YYYY">{{ $budgetOperation->getFormattedDate() }}</a>
			@endif
		</span>
	</td>
	<td class="nowrap">
		@if ($budgetOperation->isuploaded || !$user->hasRole(Role::ROLE_BUDGET))
			<span>{{ $budgetOperation->getTypeName() }}</span>
		@else
			<a href="#" class="editable editable-select-type" data-type="select" data-pk="{{ $budgetOperation->id }}" data-name="type" data-value="{{ $budgetOperation->type }}">
				{{ $budgetOperation->getTypeName() }}
			</a>
		@endif
	</td>
	<td class="nowrap">
		@if ($budgetOperation->isuploaded || !$user->hasRole(Role::ROLE_BUDGET))
			@if ($budgetOperation->type == BudgetOperation::TYPE_INCOMING)
				<span>{{ isset($accounts[$budgetOperation->budget_in_account_id])? $accounts[$budgetOperation->budget_in_account_id] : '' }}</span>
			@elseif ($budgetOperation->type == BudgetOperation::TYPE_OUTCOMING)
				<span>{{ isset($accounts[$budgetOperation->budget_out_account_id])? $accounts[$budgetOperation->budget_out_account_id] : '' }}</span>
			@elseif ($budgetOperation->type == BudgetOperation::TYPE_EXCHANGE)
				<span>{{ isset($accounts[$budgetOperation->budget_out_account_id])? $accounts[$budgetOperation->budget_out_account_id] : '' }}</span>
			@elseif ($budgetOperation->type == BudgetOperation::TYPE_OPENING_BALANCE)
				<span>{{ isset($accounts[$budgetOperation->budget_in_account_id])? $accounts[$budgetOperation->budget_in_account_id] : '' }}</span>
			@endif
		@else
			@if ($budgetOperation->type == BudgetOperation::TYPE_INCOMING)
				<a href="#" class="editable editable-select-account" data-type="select" data-pk="{{ $budgetOperation->id }}" data-name="budget_in_account_id" data-value="{{ $budgetOperation->budget_in_account_id }}">
					{{ isset($accounts[$budgetOperation->budget_in_account_id])? $accounts[$budgetOperation->budget_in_account_id] : '' }}
				</a>
			@elseif ($budgetOperation->type == BudgetOperation::TYPE_OUTCOMING)
				<a href="#" class="editable editable-select-account" data-type="select" data-pk="{{ $budgetOperation->id }}" data-name="budget_out_account_id" data-value="{{ $budgetOperation->budget_out_account_id }}">
					{{ isset($accounts[$budgetOperation->budget_out_account_id])? $accounts[$budgetOperation->budget_out_account_id] : '' }}
				</a>
			@elseif ($budgetOperation->type == BudgetOperation::TYPE_EXCHANGE)
				<a href="#" class="editable editable-select-account" data-type="select" data-pk="{{ $budgetOperation->id }}" data-name="budget_out_account_id" data-value="{{ $budgetOperation->budget_out_account_id }}">
					{{ isset($accounts[$budgetOperation->budget_out_account_id])? $accounts[$budgetOperation->budget_out_account_id] : '' }}
				</a>
			@elseif ($budgetOperation->type == BudgetOperation::TYPE_OPENING_BALANCE)
				<a href="#" class="editable editable-select-account" data-type="select" data-pk="{{ $budgetOperation->id }}" data-name="budget_in_account_id" data-value="{{ $budgetOperation->budget_in_account_id }}">
					{{ isset($accounts[$budgetOperation->budget_in_account_id])? $accounts[$budgetOperation->budget_in_account_id] : '' }}
				</a>
			@endif
		@endif
	</td>
	<td>
		@if ($budgetOperation->type == BudgetOperation::TYPE_OPENING_DEBT_IN)
			<p class="text-danger">
				<b>Мы должны: {{ $budgetOperation->debtPartner->name }}</b>
			</p>
		@elseif ($budgetOperation->type == BudgetOperation::TYPE_OPENING_DEBT_OUT)
			<p class="text-info">
				<b>Нам должен: {{ $budgetOperation->debtPartner->name }}</b>
			</p>
		@elseif ($budgetOperation->isdebt)
			@if ($budgetOperation->type == BudgetOperation::TYPE_INCOMING)
				<p class="text-success">
					<b>Долговая операция с {{ ($budgetOperation->debtPartner->debet_project_id)? $projectsName[$budgetOperation->debtPartner->debet_project_id] : $budgetOperation->debtPartner->name }}, {{ $budgetOperation->debt_comment }}</b>
				</p>
			@elseif ($budgetOperation->type == BudgetOperation::TYPE_OUTCOMING)
				<p class="text-info">
					<b>Долговая операция с {{ ($budgetOperation->debtPartner->debet_project_id)? $projectsName[$budgetOperation->debtPartner->debet_project_id] : $budgetOperation->debtPartner->name }}, {{ $budgetOperation->debt_comment }}</b>
				</p>
			@endif
		@else
			@if ($budgetOperation->isuploaded || !$user->hasRole(Role::ROLE_BUDGET))
				@if ($budgetOperation->type == BudgetOperation::TYPE_INCOMING)
					{{ $budgetOperation->partner->name }}
				@elseif ($budgetOperation->type == BudgetOperation::TYPE_OUTCOMING)
					@if(!$user->hasRole(Role::ROLE_BUDGET))
						Потрачено на <b>
							@if ($budgetOperation->cost)
								{{ $budgetOperation->cost->name }}
							@endif
						</b>
					@else
						Потрачено на <b><a href="#" class="editable editable-select-cost" data-type="select" data-pk="{{ $budgetOperation->id }}" data-name="budget_cost_id" data-value="{{ $budgetOperation->budget_cost_id }}">
							@if ($budgetOperation->cost)
								{{ $budgetOperation->cost->name }}
							@endif
						</a></b>
					@endif
					<br/><small>{{ $budgetOperation->partner->name }}</small>
				@elseif ($budgetOperation->type == BudgetOperation::TYPE_EXCHANGE)
					Перевод на <b>{{ isset($accounts[$budgetOperation->budget_in_account_id])? $accounts[$budgetOperation->budget_in_account_id] : '' }}</b>
				@elseif ($budgetOperation->type == BudgetOperation::TYPE_OPENING_BALANCE)
					<b>Начальные остатки</b>
				@endif
			@else
				@if ($budgetOperation->type == BudgetOperation::TYPE_INCOMING)
					<a href="#" class="editable editable-select-partner" data-type="select" data-pk="{{ $budgetOperation->id }}" data-name="budget_partner_id" data-value="{{ $budgetOperation->budget_partner_id }}">
						{{ $budgetOperation->partner->name }}
					</a>
				@elseif ($budgetOperation->type == BudgetOperation::TYPE_OUTCOMING)
					<a href="#" class="editable editable-select-cost" data-type="select" data-pk="{{ $budgetOperation->id }}" data-name="budget_cost_id" data-value="{{ $budgetOperation->budget_cost_id }}">
						@if ($budgetOperation->cost)
							{{ $budgetOperation->cost->name }}
						@endif
					</a>
				@elseif ($budgetOperation->type == BudgetOperation::TYPE_EXCHANGE)
					Зачисление на
					<a href="#" class="editable editable-select-account" data-type="select" data-pk="{{ $budgetOperation->id }}" data-name="budget_in_account_id" data-value="{{ $budgetOperation->budget_in_account_id }}">
						{{ isset($accounts[$budgetOperation->budget_in_account_id])? $accounts[$budgetOperation->budget_in_account_id] : '' }}
					</a>
				@elseif ($budgetOperation->type == BudgetOperation::TYPE_OPENING_BALANCE)
					<b>Начальные остатки</b>
				@endif
			@endif
		@endif
	</td>
	<td class="text-right nowrap">
		@if ($budgetOperation->isuploaded || !$user->hasRole(Role::ROLE_BUDGET))
		<span class="to-humanize">{{ round($budgetOperation->amount, 2) }}</span> <i class="fa fa-rub"></i>
		@else
			<a href="#" class="to-humanize editable editable-select-amount" data-type="text" data-pk="{{ $budgetOperation->id }}" data-name="amount" data-value="{{ $budgetOperation->amount }}">{{ $budgetOperation->amount }}</a> <i class="fa fa-rub"></i>
		@endif
		@if ($budgetOperation->is_salary == 1)
		<?php
			$salaryOperationsSum = BudgetSalary::whereBudgetOperationId($budgetOperation->id)->sum('amount');
			if(!$salaryOperationsSum){
				$salaryOperationsSum = 0;
			};
		?>
		<span title="Нераспределенный на зарплату остаток">(З/п: <span class="to-humanize text-bold salary-balance">{{ round($budgetOperation->amount - $salaryOperationsSum/100, 2) }}</span>) <i class="fa fa-rub"></i></span>
		@endif
	</td>
	<td class="budget-operation-delete" data-child-deleted-id>
		<small>
			@if ($budgetOperation->istransit)
				<span class="label label-warning">транзитная</span>
			@endif
			@if ($budgetOperation->isnoincome)
				<span class="label label-info">не является доходом</span>
			@endif
			@if ($budgetOperation->isnooutcome)
				<span class="label label-info">не является расходом</span>
			@endif
			@if ($budgetOperation->isuploaded || !$user->hasRole(Role::ROLE_BUDGET))
				{{ $budgetOperation->comment }}
			@else
				<a href="#" class="editable editable-comment" data-type="text" data-pk="{{ $budgetOperation->id }}" data-name="comment" data-value="{{ e($budgetOperation->comment) }}">
					{{ $budgetOperation->comment }}
				</a>
			@endif
		</small>
		@if ($budgetOperation->type == BudgetOperation::TYPE_OUTCOMING && $budgetOperation->is_salary == 1)
		  <button class="btn btn-success btn-xs budget-operations-salary ladda-button" data-style="zoom-out" title="Список сотрудников по з/п операции" data-id="{{ $budgetOperation->id }}" data-action=""><i class="fa fa-reorder"></i>&nbsp; <i class="fa fa-user"></i></button>
		@endif
		@if ($budgetOperation->type == BudgetOperation::TYPE_INCOMING && !$budgetOperation->istransit)
			@if ($budgetOperation->isnoincome)
				<button class="btn btn-info btn-xs budget-operations-noincome ladda-button" data-style="zoom-out" title="Является доходом" data-id="{{ $budgetOperation->id }}" data-action="{{ action('BudgetController@noIncomeOperation') }}"><i class="fa fa-long-arrow-up"></i></button>
			@else
				<button class="btn btn-info btn-xs budget-operations-noincome ladda-button" data-style="zoom-out" title="Не является доходом" data-id="{{ $budgetOperation->id }}" data-action="{{ action('BudgetController@noIncomeOperation') }}"><i class="fa fa-long-arrow-down"></i></button>
			@endif
		@elseif ($budgetOperation->type == BudgetOperation::TYPE_OUTCOMING)
			@if ($budgetOperation->isnooutcome)
				<button class="btn btn-info btn-xs budget-operations-noincome ladda-button" data-style="zoom-out" title="Является расходом" data-id="{{ $budgetOperation->id }}" data-action="{{ action('BudgetController@noOutcomeOperation') }}"><i class="fa fa-long-arrow-down"></i></button>
			@else
				<button class="btn btn-info btn-xs budget-operations-noincome ladda-button" data-style="zoom-out" title="Не является расходом" data-id="{{ $budgetOperation->id }}" data-action="{{ action('BudgetController@noOutcomeOperation') }}"><i class="fa fa-long-arrow-up"></i></button>
			@endif
		@endif
		<button class="btn btn-warning btn-xs budget-operations-debt ladda-button" data-style="zoom-out" title="Долговая операция" data-id="{{ $budgetOperation->id }}"><i class="fa fa-life-ring"></i></button>
		@if ($budgetOperation->deleted_at)
			<button class="btn btn-info btn-xs budget-operations-restore ladda-button" data-style="zoom-out" title="Восстановить" data-id="{{ $budgetOperation->id }}" data-action="{{ action('BudgetController@restoreOperation') }}"><i class="fa fa-undo"></i></button>
		@else
			<button class="btn btn-danger btn-xs budget-operations-delete ladda-button" data-style="zoom-out" title="Удалить" data-id="{{ $budgetOperation->id }}" data-action="{{ action('BudgetController@deleteOperation') }}"><i class="fa fa-times"></i></button>
		@endif
	</td>
</tr>
