

<?php $__env->startSection('title'); ?>
	@parent
	Бюджет для "<?php echo $workProject->name; ?>"
<?php $__env->stopSection(); ?>

<?php $__env->startSection('breadcrumbs'); ?>
	<?php echo Breadcrumbs::render('budget', $workProject); ?>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
	<script src="<?php echo asset('js/plugin/x-editable/x-editable.min.js'); ?>"></script>
	<script src="<?php echo asset('js/kmk-support.js'); ?>"></script>
	<script src="<?php echo asset('js/deb-operation.js'); ?>"></script>
	<script>
		function reload () {
			var params = kmkGiveGetParams(location.search);
			params['endDate'] = $('#endDate').val();
			kmkSetBrowserAddressParams(kmkObjectToGetString(params, false));
			location.reload();
		}

		$(document).ready(function() {
			$('.editable').editable({
				url: '/budget/update',
				emptytext: 0
			}).on('hidden', function(e, reason) {
				if(reason === 'save') {
					$(this).html(humanizeNumber($(this).html()));
				}
			});

			$('.editable').on('save', function(e, params) {
				if (params.response.status == 'success') {
					$('#planAmountAll').html(humanizeNumber(params.response.planAmountAll));
					$('#profit').html(humanizeNumber(params.response.profit));
				}
			});

			$('.month-plan').editable({ // бюджет проекта на месяц
				url: '/budget/updatemonth',
				emptytext: 0
			}).on('hidden', function(e, reason) {
				if(reason === 'save') {
					var newMonthPlan = $(this).html(),
						  groupPercentSumTotal = 0,
			        groupSumRestTotal = 0;
					$(this).data('value', newMonthPlan);
					$(this).html(humanizeNumber(newMonthPlan));
					$('body').find('.groupPercentSum').each(function() { //пересчет полей при изменении суммы бюджета на месяц
					  var current = $(this),
					      groupMonthPlan = current.closest('tr').find('.group-month-plan').html(), // бюджет группы в процентах
							  groupFactSum = current.closest('tr').find('.groupFactSum').data('value'); // сумма расходов группы
						groupMonthPlan = groupMonthPlan.split(',').join('.');
						var groupPercentSum = Math.round(newMonthPlan*groupMonthPlan)/100; // бюджет группы в руб.
            current.data('value', groupPercentSum).html(humanizeNumber(groupPercentSum)); // поле бюджет в руб.
					  current.closest('tr').find('.groupSumRest').html(humanizeNumber( (Math.round(groupPercentSum*100 - groupFactSum*100))/100 )).data('value', (Math.round(groupPercentSum*100 - groupFactSum*100))/100 );// поле остаток
						groupPercentSumTotal += groupPercentSum;
          });
				  $('body').find('#groupPercentSumTotal').attr('title', 'Нераспределенный бюджет: '+ (Math.round(+newMonthPlan*100 - groupPercentSumTotal*100))/100 +' руб.').html(humanizeNumber((Math.round(groupPercentSumTotal*100))/100));
				  $('body').find('.groupSumRest').each(function() {//пересчет неиспользованного остатка бюджета проекта
						if($(this).data('value') > 0){
						  groupSumRestTotal += $(this).data('value');
						}
          });
					$('.planAmountRest').html(humanizeNumber((Math.round(groupSumRestTotal*100))/100));
	      }
			});

      $('.group-month-plan').editable({ //бюджет группы
				url: '/budget/updatepercent/'+$('#endDate').val(),
				emptytext: 0
			}).on('hidden', function(e, reason) {
				if(reason === 'save') {
					$(this).html($(this).html());
					$(this).data('value', $(this).html());
				}
			});

			$('.group-month-plan').on('save', function(e, params) {
				if (params.response.status == 'success') {
					var currentRow = $(this).closest('tr'),
					    groupPercentSumTotal = 0,
							groupSumRestTotal = 0,
							monthPlan = $('.month-plan').data('value');
				  currentRow.find('.groupPercentSum').data('value', params.response.groupPercentSum).html(humanizeNumber(params.response.groupPercentSum));
				  currentRow.find('.groupSumRest').html(humanizeNumber(params.response.groupSumRest));
					currentRow.find('.groupSumRest').data('value', params.response.groupSumRest);
					$('#groupPercentTotal').attr('title', 'Нераспределенный бюджет: '+ (Math.round(100*100 - params.response.groupPercentTotal*100))/100 +'%').html(params.response.groupPercentTotal);
					$('body').find('.groupPercentSum').each(function() {//пересчет общей распланированной суммы при изменении % групп
						groupPercentSumTotal += $(this).data('value');
          });
				$('#groupPercentSumTotal').attr('title', 'Нераспределенный бюджет: '+ (Math.round(monthPlan*100 - groupPercentSumTotal*100))/100 +' руб.').html(humanizeNumber((Math.round(groupPercentSumTotal*100))/100));
				}
				$('body').find('.groupSumRest').each(function() {//пересчет неиспользованного остатка бюджета проекта
					if($(this).data('value') > 0){
						groupSumRestTotal += $(this).data('value');
					}
          });
				$('.planAmountRest').html(humanizeNumber((Math.round(groupSumRestTotal*100))/100));
				var curr = $('#groupPercentTotal'),
				    groupPercentTotal = curr.html();
			  if (groupPercentTotal > 100) {
				  curr.removeClass('text-success').addClass('text-danger');
			  } else if (groupPercentTotal < 100) {
				  curr.removeClass('text-danger').addClass('text-success');
			  } else {
					curr.removeClass('text-success').removeClass('text-danger');
				}
			});

				var curr = $('#groupPercentTotal'),
				    groupPercentTotal = curr.html();
			  if (groupPercentTotal > 100) {
				  curr.addClass('text-danger');
			  } else if (groupPercentTotal < 100) {
				  curr.addClass('text-success');
			  }

			$('a.to-humanize').each(function() {
				$(this).html(humanizeNumber($(this).html()));
			});

			var endDate = $('#endDate')
				.datepicker({
					onClose: function( selectedDate ) {
						reload();
					}
				});

			var today = new Date();
			$("#todayDate").data('date', today.getDate()+'.'+(parseInt(today.getMonth())+1)+'.'+today.getFullYear());
			today.setDate(today.getDate()-1);
			$("#yeasterdayDate").data('date', today.getDate()+'.'+(parseInt(today.getMonth())+1)+'.'+today.getFullYear());

			$('.btn-set-date').unbind('click').on('click', function(){
				$('#startDate').val($(this).data('date'));
				$('#endDate').val($(this).data('date'));
				reload();
				return false;
			});
			// --> сворачивание групп в таблице Информация по расходам
			var minusSign = '<em class="fa fa-minus-circle"></em>',
			    plusSign = '<em class="fa fa-plus-circle"></em>';

		  $.fn.slideFadeToggle = function(speed, easing, callback){
        return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
      };

      $('body').on('click', '.group-header', function(){
				var raw = $(this).closest('.group-header-raw');
		    raw.nextUntil('.group-header-raw').slideFadeToggle('fast');

				if( raw.hasClass('open-header') ){
					raw.removeClass('open-header').addClass('close-header');
					$(this).find('.collapse-sign-my').html(plusSign);
				}else{
					raw.removeClass('close-header').addClass('open-header');
					$(this).find('.collapse-sign-my').html(minusSign);
				}
		    return false;
      });

			$('.collapse-sign-all').click(function(){
				var current = $(this);
				if( current.hasClass('open-group') ){
					current.html('<em class="fa fa-plus-circle" title="Развернуть детали групп"></em>');
					current.removeClass('open-group').addClass('close-group');

					$('.open-header').each(function(){
					  $(this).find('.group-header').click();
				  });
				}else{
					current.html('<em class="fa fa-minus-circle" title="Свернуть детали групп"></em>');
					current.removeClass('close-group').addClass('open-group');

					$('.close-header').each(function(){
					  $(this).find('.group-header').click();
				  });
				}
			});
			// <--
	  });
	</script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
	<div class="row">
		<div class="col-md-12">
			<div class="panel panel-default">
				<?php echo $__env->make('budget/menu', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
				<div class="panel-body">
					<form class="form-inline" role="form">
						<div class="form-group">
							Состояние на <input id="endDate" name="endDate" class="form-control input-sm" value="<?php echo $endDate; ?>"/>
						</div>
						<div class="form-group">
							<button id="yeasterdayDate" class="btn btn-default btn-set-date" data-date="">Вчера</button>
							<button id="todayDate" class="btn btn-default btn-set-date">Сегодня</button>
						</div>
					</form>
					<br/>
					<div class="row">
						<div class="col-md-6">
							<div class="well well-sm">
								<div class="table-responsive">
									<table class="table table-condensed">
										<thead>
											<tr>
												<th>Информация по счетам</th>
												<th></th>
											</tr>
										</thead>
										<tbody>
											<?php foreach($workProject->budgetAccounts as $budgetAccount): ?>
											<tr>
												<td><?php echo $budgetAccount->name; ?></td>
												<td class="text-right"><span class="to-humanize"><?php echo $budgetAccount->getSum($endDate); ?></span> <i class="fa fa-rub"></i></td>
											</tr>
											<?php endforeach; ?>
											<tr>
												<td><b>Всего</b></td>
												<td class="text-right"><b><span class="to-humanize"><?php echo $workProject->getSum($endDate); ?></span> <i class="fa fa-rub"></i></b></td>
											</tr>
											<?php if(User::find(Auth::user()->id)->hasRole(Role::ROLE_BUDGET)): ?>
											<tr>
												<td><b>Остаток после полной оплаты<br/>всех планируемых расходов</b></td>
												<td class="text-right"><b><span id="profit" class="to-humanize"><?php echo $workProject->getProfit(); ?></span> <i class="fa fa-rub"></i></b></td>
											</tr>
											<tr>
												<td><b>Остаток после полной оплаты<br/>всех планируемых расходов<br/>и возврата/получения всех долгов</b></td>
												<td class="text-right"><b><span id="profit" class="to-humanize"><?php echo $workProject->getProfitAll(); ?></span> <i class="fa fa-rub"></i></b></td>
											</tr>
											<?php endif; ?>
										</tbody>
									</table>
								</div>
								<div class="table-responsive">
									<table class="table table-condensed">
										<thead>
											<tr>
												<th>Cчет</th>
												<th class="text-right">Приход</th>
												<th class="text-right">Расход</th>
											</tr>
										</thead>
										<tbody>
											<?php foreach($workProject->budgetAccounts as $budgetAccount): ?>
											<tr>
												<td><?php echo $budgetAccount->name; ?></td>
												<td class="text-right" style="white-space:nowrap"><span class="to-humanize"><?php echo $budgetAccount->getInSum($endDate); ?></span> <i class="fa fa-rub"></i></td>
												<td class="text-right" style="white-space:nowrap"><span class="to-humanize"><?php echo $budgetAccount->getOutSum($endDate); ?></span> <i class="fa fa-rub"></i></td>
											</tr>
											<?php endforeach; ?>
											<tr>
												<td><b>Итого</b></td>
												<td class="text-right" style="white-space:nowrap"><b><span class="to-humanize"><?php echo $workProject->getInSum($endDate); ?></span> <i class="fa fa-rub"></i></b></td>
												<td class="text-right" style="white-space:nowrap"><b><span class="to-humanize"><?php echo $workProject->getOutSum($endDate); ?></span> <i class="fa fa-rub"></i></b></td>
											</tr>
											<tr>
												<td><b>Прибыль</b></td>
												<td colspan="2" class="text-right" style="white-space:nowrap"><b><span class="to-humanize"><?php echo round( ($workProject->getInSum($endDate) - $workProject->getOutSum($endDate)), 2 ); ?></span> <i class="fa fa-rub"></i></b></td>
											</tr>
										</tbody>
									</table>
								</div>
							</div>
						</div>
						<div class="col-md-6">
							<div class="well well-sm">
								<div class="table-responsive">
									<table class="table table-condensed">
										<thead>
											<tr>
												<th>Информация по долговым контрагентам</th>
												<th>Долг нам</th>
												<th>Долг ему</th>
											</tr>
										</thead>
										<tbody>
											<?php foreach($workProject->budgetDebtPartners as $debtPartner): ?>
											<tr>
												<td><a href="#" class="debt-partners" data-action="<?php echo action('BudgetController@showDebtPartnersOperations', array($workProject->id, '', '', '') ); ?>" data-project-id="<?php echo $workProject->id; ?>" data-partner-id="<?php echo $debtPartner->id; ?>"><?php echo $debtPartner->name? $debtPartner->name : $debtPartner->deb_project['name']; ?></a></td>
												<?php
													$debt = $debtPartner->getSum($endDate);
												?>
												<td class="text-right" style="white-space:nowrap"><?php if($debt > 0): ?> <span class="to-humanize"><?php echo round($debt, 2); ?></span> <i class="fa fa-rub"></i> <?php else: ?> 0 <?php endif; ?></td>
												<td class="text-right" style="white-space:nowrap"><?php if($debt < 0): ?> <span class="to-humanize"><?php echo round(abs($debt), 2); ?></span> <i class="fa fa-rub"></i> <?php else: ?> 0 <?php endif; ?></td>
											</tr>
											<?php endforeach; ?>
											<tr>
												<td><b>Всего</b></td>
												<?php
													$debt = $workProject->getDebtSum($endDate);
												?>
												<td class="text-right" style="white-space:nowrap"><?php if($debt > 0): ?> <span class="to-humanize"><?php echo round($debt, 2); ?></span> <i class="fa fa-rub"></i> <?php else: ?> 0 <?php endif; ?></td>
												<td class="text-right" style="white-space:nowrap"><?php if($debt < 0): ?> <span class="to-humanize"><?php echo round(abs($debt), 2); ?></span> <i class="fa fa-rub"></i> <?php else: ?> 0 <?php endif; ?></td>
											</tr>
										</tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<?php if(User::find(Auth::user()->id)->hasAnyRole(array(Role::ROLE_BUDGET_VIEW_OPERATIONS, Role::ROLE_BUDGET))): ?>
			      <?php
						  $budgetCostsGroups = BudgetCostGroup::whereIn('project_id', array($workProject->id, 0))
							                                    ->orderBy('name')
																                  ->get();
						  $groupPercentTotal = 0; // сумма процентов всех групп
							$groupPercentSumTotal = 0; // сумма бюджетов групп
							$noDebtNoPlanGroups = ''; // часть таблицы с группами без плана и расходов
							$noDebtOrNoPlanGroups = ''; // часть таблицы с группами c планом и без расходов (+ есть расход, нет плана)
					  ?>
						<div class="col-md-12 col-lg-12">
							<div class="well well-sm">
								<p class="text-center"><b>Информация по расходам за <?php echo $workProject->getMonthName(); ?></b></p>
								<div class="table-responsive">
									<table class="table table-condensed table-hover">
										<thead>
											<tr>
												<th>
													<button class="btn-info collapse-sign-all close-group">
														<em class="fa fa-plus-circle" title="Развернуть детали групп"></em>
													</button>
													Группы расходов</th>
												<th class="text-right col-md-6">План, %</th>
												<th class="text-right">План, <i class="fa fa-rub"></i></th>
												<th class="text-right">Факт</th>
												<th class="text-right">Остаток</th>
											</tr>
										</thead>
										<tbody>
										<?php foreach($budgetCostsGroups as $budgetCostsGroup): ?>
										  <?php
											  $groupFactSum        = $budgetCostsGroup->getGroupSum($workProject->id, $endDate);
											  $groupFactSumOutcome = $budgetCostsGroup->getGroupSumOutcome($workProject->id, $endDate);
												$groupPercent = $budgetCostsGroup->getGroupPercent($workProject->id);
												$groupPercentAmount = round($groupPercent['amount'] / 100, 2); // бюджет группы в процентах
												$groupPercentId = $groupPercent['id'];
												$groupPercentSum = round($workProject->getCurrentBudgetMonthPlan()*$groupPercentAmount / 100, 2); // бюджет группы в руб.
												$groupPercentTotal += $groupPercentAmount; // сумма процентов всех групп
												$groupPercentSumTotal += $groupPercentSum;
											?>
										  <?php if($groupFactSum && $groupPercentAmount): ?>
											  <?php $noDebtCosts = ''; // часть группы без расходов	?>
											  <tr class="group-header-raw close-header">
												  <td class="group-header">
														<b class="collapse-sign-my">
															<em class="fa fa-plus-circle"></em>
														</b>
													  <b>
													  	<a href="#"><?php echo $budgetCostsGroup->name; ?></a>
													  </b>
												  </td>
												  <td class="text-right col-md-6" style="white-space:nowrap"><b><a href="#" class="group-month-plan" data-name="<?php echo $workProject->id; ?>_<?php echo $budgetCostsGroup->id; ?>" data-type="text" data-pk="<?php echo $groupPercentId; ?>" data-value="<?php echo $groupPercentAmount; ?>"><?php echo ($groupPercentAmount)? round($groupPercentAmount, 2):0; ?> </a></b></td>
													<td class="text-right" style="white-space:nowrap"><b><span class="to-humanize groupPercentSum" data-value="<?php echo ($groupPercentSum)? $groupPercentSum:0; ?>"><?php echo ($groupPercentSum)? round($groupPercentSum, 2):0; ?></span> <i class="fa fa-rub"></i></b></td>
												  <td class="text-right" style="white-space:nowrap"><b><span class="to-humanize groupFactSumOutcome" data-value="<?php echo $groupFactSumOutcome; ?>"><?php echo round($groupFactSumOutcome, 2); ?></span> <i class="fa fa-rub"></i></b>
												    <b class="text-td-small"><span class="to-humanize groupFactSum" data-value="<?php echo $groupFactSum; ?>"><?php echo round($groupFactSum, 2); ?></span> <i class="fa fa-rub"></i></b>
													</td>
											  	<td class="text-right" style="white-space:nowrap"><b><span class="to-humanize groupSumRestOutcome" data-value="<?php echo round($groupPercentSum-$groupFactSumOutcome, 2); ?>"><?php echo round($groupPercentSum-$groupFactSumOutcome, 2); ?></span> <i class="fa fa-rub"></i></b>
										        <b class="text-td-small"><span class="to-humanize groupSumRest" data-value="<?php echo round($groupPercentSum-$groupFactSum, 2); ?>"><?php echo round($groupPercentSum-$groupFactSum, 2); ?></span> <i class="fa fa-rub"></i></b>
													</td>
											  </tr>
												<?php
												  $budgetCostsGroup->budgetCosts = $budgetCostsGroup->budgetCosts->sortBy(function ($budgetCost) {
                            return $budgetCost->name;
                          });
												?>
											  <?php foreach($budgetCostsGroup->budgetCosts as $budgetCost): ?>
											  <?php
												  $costSum        = $budgetCost->getSum($workProject->id, $endDate);
												  $costSumOutcome = $budgetCost->getSumOutcome($workProject->id, $endDate);
												?>
												  <?php if($costSum): ?>
													  <tr style="display: none;">
														  <td><span class="table-list-child"><?php echo str_replace($budgetCostsGroup->name . '. ', '', $budgetCost->name); ?></span></td>
														  <td></td>
														  <td></td>
														  <td class="text-right" style="white-space:nowrap"><span class="to-humanize"><?php echo $costSumOutcome; ?></span> <i class="fa fa-rub"></i>
														    <span class="text-right text-td-small" style="white-space:nowrap"><span class="to-humanize"><?php echo $costSum; ?></span> <i class="fa fa-rub"></i></span>
															</td>
														  <td></td>
														  <td></td>
													  </tr>
													<?php endif; ?>
													<?php if(!$costSum): ?>
													  <?php
													  $noDebtCosts .=
														  '<tr style="display: none;">
														    <td><span class="table-list-child">'. str_replace($budgetCostsGroup->name . '. ', '', $budgetCost->name).'</span></td>
														    <td></td>
														    <td></td>
														    <td class="text-right" style="white-space:nowrap"><span class="to-humanize">'. $costSumOutcome .'</span> <i class="fa fa-rub"></i>
																  <span class="text-right text-td-small" style="white-space:nowrap"><span class="to-humanize">'. $costSum .'</span> <i class="fa fa-rub"></i></span>
																</td>
														    <td></td>
														    <td></td>
													    </tr>';
													  ?>
													<?php endif; ?>
											  <?php endforeach; ?>
												<?php echo $noDebtCosts; ?>

											<?php endif; ?>
											<?php if( (!$groupFactSum && $groupPercentAmount) || ($groupFactSum && !$groupPercentAmount)): ?>
											  <?php
												  $noDebtCosts = ''; // часть группы без расходов
													$noDebtOrNoPlanGroups .=
											  '<tr class="group-header-raw close-header">
												  <td class="group-header">
														<b class="collapse-sign-my">
															<em class="fa fa-plus-circle"></em>
														</b>

													  	<a href="#">'. $budgetCostsGroup->name .'</a>

												  </td>
												  <td class="text-right col-md-6" style="white-space:nowrap"><b><a href="#" class="group-month-plan" data-name="'. $workProject->id .'_'. $budgetCostsGroup->id .'" data-type="text" data-pk="'. $groupPercentId .'" data-value="'. $groupPercentAmount .'">'. round($groupPercentAmount, 2) .' </a></b></td>
													<td class="text-right" style="white-space:nowrap"><b><span class="to-humanize groupPercentSum" data-value="'.$groupPercentSum.'">'. $groupPercentSum .'</span> <i class="fa fa-rub"></i></b></td>
												  <td class="text-right" style="white-space:nowrap"><b><span class="to-humanize groupFactSumOutcome" data-value="'. $groupFactSumOutcome .'">'. round($groupFactSumOutcome, 2) .'</span> <i class="fa fa-rub"></i></b>
												    <span class="text-right text-td-small" style="white-space:nowrap"><b><span class="to-humanize groupFactSum" data-value="'. $groupFactSum .'">'. round($groupFactSum, 2) .'</span> <i class="fa fa-rub"></i></b></span>
													</td>
											  	<td class="text-right" style="white-space:nowrap"><b><span class="to-humanize groupSumRestOutcome" data-value="'.round($groupPercentSum-$groupFactSumOutcome, 2) .'">'. round($groupPercentSum-$groupFactSumOutcome, 2) .'</span> <i class="fa fa-rub"></i></b>
											  	  <b class="text-td-small"><span class="to-humanize groupSumRest" data-value="'.round($groupPercentSum-$groupFactSum, 2) .'">'. round($groupPercentSum-$groupFactSum, 2) .'</span> <i class="fa fa-rub"></i></b>
													</td>
											  </tr>';

												  $budgetCostsGroup->budgetCosts = $budgetCostsGroup->budgetCosts->sortBy(function ($budgetCost) {
                            return $budgetCost->name;
                          });
												?>
											  <?php foreach($budgetCostsGroup->budgetCosts as $budgetCost): ?>
											  <?php
												  $costSum        = $budgetCost->getSum($workProject->id, $endDate);
												  $costSumOutcome = $budgetCost->getSumOutcome($workProject->id, $endDate);
												?>
												  <?php if($costSum): ?>
													<?php
													  $noDebtOrNoPlanGroups .=
													  '<tr style="display: none;">
														  <td><span class="table-list-child">'. str_replace($budgetCostsGroup->name . '. ', '', $budgetCost->name) .'</span></td>
														  <td></td>
														  <td></td>
														  <td class="text-right" style="white-space:nowrap"><span class="to-humanize">'. $costSumOutcome .'</span> <i class="fa fa-rub"></i>
														    <span class="text-right text-td-small" style="white-space:nowrap"><span class="to-humanize">'. $costSum .'</span> <i class="fa fa-rub"></i></span>
															</td>
														  <td></td>
													  </tr>';
													?>
													<?php endif; ?>
													<?php if(!$costSum): ?>
													  <?php
													  $noDebtCosts .=
														  '<tr style="display: none;">
														    <td><span class="table-list-child">'. str_replace($budgetCostsGroup->name . '. ', '', $budgetCost->name).'</span></td>
														    <td></td>
														    <td></td>
														    <td class="text-right" style="white-space:nowrap"><span class="to-humanize">'. $costSumOutcome .'</span> <i class="fa fa-rub"></i>
														      <span class="text-right text-td-small" style="white-space:nowrap"><span class="to-humanize">'. $costSum .'</span> <i class="fa fa-rub"></i></span>
																</td>
														    <td></td>
													    </tr>';
													  ?>
													<?php endif; ?>
											  <?php endforeach; ?>
												<?php  $noDebtOrNoPlanGroups .= $noDebtCosts; ?>
											<?php endif; ?>
											<?php if(!$groupFactSum && !$groupPercentAmount): ?>
											<?php
											  $noDebtNoPlanGroups .=
											  '<tr class="group-header-raw ">
												  <td><b>'.$budgetCostsGroup->name.'</b></td>
												  <td class="text-right col-md-6" style="white-space:nowrap"><b><a href="#" class="group-month-plan" data-name="'. $workProject->id .'_'. $budgetCostsGroup->id .'" data-type="text" data-pk="'. $groupPercentId .'" data-value="'. $groupPercentAmount .'">'.round($groupPercentAmount, 2).' </a></b></td>
													<td class="text-right" style="white-space:nowrap"><b><span class="to-humanize groupPercentSum" data-value="'.$groupPercentSum.'">'. $groupPercentSum.'</span> <i class="fa fa-rub"></i></b></td>
												  <td class="text-right" style="white-space:nowrap"><b><span class="to-humanize groupFactSumOutcome" data-value="'. $groupFactSumOutcome .'">'. round($groupFactSumOutcome, 2) .'</span> <i class="fa fa-rub"></i></b>
												    <span class="text-right text-td-small" style="white-space:nowrap"><b><span class="to-humanize groupFactSum" data-value="'. $groupFactSum .'">'. round($groupFactSum, 2) .'</span> <i class="fa fa-rub"></i></b></span>
													</td>
												  <td class="text-right" style="white-space:nowrap"><b><span class="to-humanize groupSumRestOutcome" data-value="'. round($groupPercentSum-$groupFactSumOutcome, 2) .'">'. round($groupPercentSum-$groupFactSumOutcome, 2) .'</span> <i class="fa fa-rub"></i></b>
												    <b class="text-td-small"><span class="to-humanize groupSumRest" data-value="'. round($groupPercentSum-$groupFactSum, 2) .'">'. round($groupPercentSum-$groupFactSum, 2) .'</span> <i class="fa fa-rub"></i></b>
												  </td>
											  </tr>';
											?>
											<?php endif; ?>
										<?php endforeach; ?>
										<?php echo $noDebtOrNoPlanGroups; ?>

										<?php echo $noDebtNoPlanGroups; ?>

										<?php
										  $budgetCostsUnknown = BudgetCost::whereIn('project_id', array($workProject->id, 0))
							                                        ->whereBudgetCostGroupId(0)
														                          ->orderBy('name')
															                        ->get();
										?>
										<?php if($budgetCostsUnknown): ?>
										  <tr class="group-header-raw">
												<td><b>Без группы</b></td>
												<td></td>
												<td class="text-right"></td>
												<td class="text-right" style="white-space:nowrap"><b><span class="to-humanize"><?php echo $workProject->getUnknownGroupSumOutcome($endDate); ?></span> <i class="fa fa-rub"></i></b>
												  <b class="text-td-small"><span class="to-humanize"><?php echo $workProject->getUnknownGroupSum($endDate); ?></span> <i class="fa fa-rub"></i></b>
									      </td>
												<td></td>
											</tr>
										  <?php foreach($budgetCostsUnknown as $budgetCostUnknown): ?>
											  <tr>
													<td><span class="table-list-child"><?php echo $budgetCostUnknown->name; ?></span></td>
													<td></td>
													<td></td>
												  <td class="text-right" style="white-space:nowrap"><span class="to-humanize"><?php echo $budgetCostUnknown->getSumOutcome($workProject->id, $endDate); ?></span> <i class="fa fa-rub"></i>
												    <span class="text-right text-td-small" style="white-space:nowrap"><span class="to-humanize"><?php echo $budgetCostUnknown->getSum($workProject->id, $endDate); ?></span> <i class="fa fa-rub"></i>
													</td>
												  <td></td>
											  </tr>
											<?php endforeach; ?>
										<?php endif; ?>
											<tr>
												<td title="Включено в итоговую сумму"><b>Без категории</b></td>
												<td></td>
												<td class="text-right"></td>
												<td class="text-right" style="white-space:nowrap" title="Включено в итоговую сумму"><b><span class="to-humanize"><?php echo $workProject->getUnknownSumOutcome($endDate); ?></span> <i class="fa fa-rub"></i></b>
												  <b class="text-td-small"><span class="to-humanize"><?php echo $workProject->getUnknownSum($endDate); ?></span> <i class="fa fa-rub"></i></b>
												</td>
											  <td></td>
											</tr>
											<tr>
												<td><b>На долги (входит в сумму итога)</b>
												    <span class="text-td-small">На долги (не входит в сумму итога)</span>
												</td>
												<td></td>
												<td class="text-right"></td>
												<td class="text-right" style="white-space:nowrap"><b><span class="to-humanize" title="Включено в итоговую сумму факт. расходов"><?php echo $unknownDebtSumOutcome = $workProject->getUnknownDebtSumOutcome($endDate); ?></span> <i class="fa fa-rub"></i></b>
											    <b class="text-td-small"><span class="to-humanize" title="Не включено в итоговую сумму факт. расходов"><?php echo $unknownDebtSum = $workProject->getUnknownDebtSum($endDate); ?></span> <i class="fa fa-rub"></i></b>
												</td>
											  <td></td>
											</tr>
											<tr>
												<td><b>Всего</b></td>
												<td class="text-right" style="white-space:nowrap"><b><span id="groupPercentTotal" title="Нераспределенный бюджет:  <?php echo round((100 - $groupPercentTotal), 2); ?>%"><?php echo round($groupPercentTotal, 2); ?></span> %</b></td>
												<td class="text-right" style="white-space:nowrap"><b><span class="to-humanize" id="groupPercentSumTotal" title="Нераспределенный бюджет:  <?php echo round(($workProject->getCurrentBudgetMonthPlan() - $groupPercentSumTotal), 2); ?> руб."><?php echo round($groupPercentSumTotal, 2); ?></span></b> <i class="fa fa-rub"></i></td>
												<td class="text-right" style="white-space:nowrap">
													<b><span class="to-humanize"><?php echo $workProject->getAllCostOutcome($endDate); ?></span> <i class="fa fa-rub"></i></b>
													<b class="text-td-small"><span class="to-humanize"><?php echo $workProject->getAllCost($endDate) - $unknownDebtSum; ?></span> <i class="fa fa-rub"></i></b>
												</td>
												<td class="text-right" style="white-space:nowrap"> <b><span class="to-humanize planAmountRestOutcome"><?php echo round($workProject->getPlanAmountRestOutcome(), 2); ?></span></b><!-- !! Уточнить как считать остаток -->
													<b class="text-td-small"><span class="to-humanize planAmountRest"><?php echo round($workProject->getPlanAmountRest(), 2); ?></span></b>
												</td>
											</tr>
										</tbody>
									</table>
									<?php if($user->hasRole(Role::ROLE_BUDGET)): ?>
										<a class="btn btn-sm btn-default pull-right" href="<?php echo action('BudgetController@costExport', array($workProject->id, $endDate)); ?>" target="_blank">Экспорт в Excel</a>
										<a class="btn btn-sm btn-primary pull-right" href="<?php echo action('BudgetController@ddsReport', array($workProject->id, $endDate)); ?>" target="_blank">Отчет ДДС</a>
										<div class="clearfix"></div>
									<?php endif; ?>
								</div>
							</div>
						</div>
						<?php endif; ?>
						<div class="col-md-4 pull-right">
							<div class="well well-sm">
							  <b>Сумма расходов на <?php echo $workProject->getMonthName(); ?></b>
								<div class="pull-right">
									<a href="#" class="to-humanize month-plan" data-type="text" data-pk="<?php echo $workProject->id; ?>" data-value="<?php echo $workProject->getCurrentBudgetMonthPlan(); ?>"><?php echo $workProject->getCurrentBudgetMonthPlan(); ?></a> <i class="fa fa-rub"></i>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
  <?php $__env->startSection('modals'); ?>
	  <?php echo $__env->make('budget/modal', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
	<?php $__env->stopSection(); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.default', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>