<html>
	<head>
	  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	</head>
	<body>
		@if (User::find(Auth::user()->id)->hasRole(Role::ROLE_BUDGET))
			<?php $budgetCostsGroups = BudgetCostGroup::orderBy('name')->get(); ?>
			<table class="table table-condensed table-hover">
				<thead>
					<tr>
						<td style="font-size: 12; font-weight: bold; text-align: right">Архивные общие расходы по проектам за период {{ $startDate }} - {{ $endDate }}</td>
					</tr>
					<tr>
						<th>Группы расходов</th>
						<th class="text-right">Итого</th>
						@foreach ($user->notNullCostsBudjetProjects($startDate, $endDate) as $project)
							@if($project->usebudget == 1)
								<th class="text-right">{{ $project->name }}</th>
							@elseif($project->usebudget == 0)
							<th>{{ $project->name }}</th>
							@endif
						@endforeach
					</tr>
				</thead>
				<tbody>
				@foreach ($budgetCostsGroups as $budgetCostsGroup)
						<tr class="group-header-raw close-header">
							<td class="group-header">
								<b>
									<a>{{ $budgetCostsGroup->name }}</a>
								</b>
							</td>
							<td class="text-right" style="white-space:nowrap">
								<b><span class="to-humanize">{{ round($budgetCostsGroup->getArchiveTotalGroupSumOutcome($startDate, $endDate), 2) }}</span></b>
							</td>
							@foreach ($user->notNullCostsBudjetProjects($startDate, $endDate) as $project)
								<?php $groupFactSum        = $budgetCostsGroup->getArchiveGroupSum($project->id, $startDate, $endDate);
											$groupFactSumOutcome = $budgetCostsGroup->getArchiveGroupSumOutcome($project->id, $startDate, $endDate); ?>
								<td class="text-right" style="white-space:nowrap">
									<b><span class="to-humanize" data-value="{{ round($groupFactSumOutcome, 2) }}">{{ round($groupFactSumOutcome, 2) }}</span></b>
								</td>
							@endforeach
						</tr>
						<?php
							$budgetCostsGroup->budgetCosts = $budgetCostsGroup->budgetCosts->sortBy(function ($budgetCost) {
								return $budgetCost->name;
							});
						?>
						@foreach ($budgetCostsGroup->budgetCosts as $budgetCost)
							<tr style="display: none;">
								<td><span class="table-list-child">{{ str_replace($budgetCostsGroup->name . '. ', '', $budgetCost->name) }}</span></td>
								<td class="text-right" style="white-space:nowrap">
									<span class="to-humanize">{{ $budgetCost->getArchiveTotalSumOutcome($startDate, $endDate) }}</span>
								</td>
								@foreach ($user->notNullCostsBudjetProjects($startDate, $endDate) as $project)
									<?php $costSum = $budgetCost->getArchivedSum($project->id, $startDate, $endDate);
												$costSumOutcome = $budgetCost->getArchivedSumOutcome($project->id, $startDate, $endDate); ?>
									<td class="text-right" style="white-space:nowrap">
										<span class="to-humanize">{{ $costSumOutcome }}</span>
									</td>
								@endforeach
							</tr>
						@endforeach
				@endforeach
					<tr class="group-header-raw">
						<td><b>Без группы</b></td>
						<td class="text-right" style="white-space:nowrap">
							<b><span class="to-humanize">{{ $project->getArchiveTotalUnknownGroupSumOutcome($startDate, $endDate) }}</span></b>
						</td>
						@foreach ($user->notNullCostsBudjetProjects($startDate, $endDate) as $project)
							<td class="text-right" style="white-space:nowrap">
								<b><span class="to-humanize">{{ $project->getArchiveUnknownGroupSumOutcome($startDate, $endDate) }}</span></b>
							</td>
						@endforeach
					</tr>
					<tr>
						<td title="Включено в итоговую сумму расходов проекта"><b>Без категории</b></td>
						<td class="text-right" style="white-space:nowrap" title="Включено в итоговую сумму расходов проекта">
							<b><span class="to-humanize">{{ $project->getArchiveTotalUnknownSumOutcome($startDate, $endDate) }}</span></b>
						</td>
						@foreach ($user->notNullCostsBudjetProjects($startDate, $endDate) as $project)
							<td class="text-right" style="white-space:nowrap" title="Включено в итоговую сумму расходов проекта">
								<b><span class="to-humanize">{{ $project->getArchiveUnknownSumOutcome($startDate, $endDate) }}</span></b>
							</td>
						@endforeach
					</tr>
					<tr>
						<td><b>На долги(входит в сумму итога)</b>
						<td class="text-right" style="white-space:nowrap">
							<b><span class="to-humanize" title="Включено в итоговую сумму факт. расходов">{{ $project->getArchiveTotalUnknownDebtSumOutcome($startDate, $endDate) }}</span></b>
						</td>
						@foreach ($user->notNullCostsBudjetProjects($startDate, $endDate) as $project)
							<td class="text-right" style="white-space:nowrap">
								<b><span class="to-humanize" title="Включено в итоговую сумму факт. расходов">{{ $project->getArchiveUnknownDebtSumOutcome($startDate, $endDate) }}</span></b>
							</td>
						@endforeach
					</tr>
					<tr>
						<td><b>Итого</b></td>
						<td class="text-right" style="white-space:nowrap">
							<b><span class="to-humanize">{{ $project->getArchiveAllProjectsAllCostOutcome($startDate, $endDate) }} {{-- $project->getArchiveTotalUnknownDebtSumOutcome($startDate, $endDate) --}}</span></b>
						</td>
						@foreach ($user->notNullCostsBudjetProjects($startDate, $endDate) as $project)
							<td class="text-right" style="white-space:nowrap">
								<b><span class="to-humanize">{{ $project->getArchiveAllCostOutcome($startDate, $endDate) }} {{-- $project->getArchiveUnknownDebtSumOutcome($startDate, $endDate) --}}</span></b>
							</td>
						@endforeach
					</tr>
				</tbody>
			</table>
		@endif
	</body>
</html>