
<?php $__env->startSection('title'); ?>
@parent
Статистика за день
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>

<?php if (Sentry::check() ): ?>
	<div class="col-md-8 col-md-offset-2">
		<div class="panel panel-default">
			 <div class="panel-heading">
				<h3 class="panel-title">Статистика
					<div class="btn-group btn-group-sm">
						<?php if (isset($stat[0])): ?>
						<a class="btn <?php if ($date == $stat[0]->date): ?> btn-success active <?php else: ?> btn-default <?php endif; ?>" href="/">Сегодня (<?php echo $stat[0]->cntAll; ?>)</a>
						<?php endif; ?>
						<?php if (isset($stat[1])): ?>
						<a class="btn <?php if ($date == $stat[1]->date): ?> btn-success active <?php else: ?> btn-default <?php endif; ?>" href="/?date=<?php echo $stat[1]->date; ?>">Вчера (<?php echo $stat[1]->cntAll; ?>)</a>
						<?php endif; ?>
						<?php if (isset($stat[2])): ?>
						<a class="btn <?php if ($date == $stat[2]->date): ?> btn-success active <?php else: ?> btn-default <?php endif; ?>" href="/?date=<?php echo $stat[2]->date; ?>">Позавчера (<?php echo $stat[2]->cntAll; ?>)</a>
						<?php endif; ?>
					</div>
				</h3>
			</div>
			<table class="table table-striped table-hover lead-stat">
				<thead>
					<tr>
						<th>Проект</th>
						<th class="text-center">Новые</th>
						<th class="text-center">В&nbsp;работе</th>
						<th class="text-center">Всего</th>
					</tr>
				</thead>
				<tbody>
					<?php foreach ($projects as $project): ?>
					<?php
						$entrypoints = $project->leadsWithTrashed()->whereRaw($dateWhere)->groupBy('entrypoint')->get(array(DB::raw('COUNT(id) as cntAll, SUM((CASE WHEN (deleted_at IS NULL) THEN 1 ELSE 0 END)) as cntIsNew, SUM((CASE WHEN (isbad != 1 AND deleted_at IS NOT NULL) THEN 1 ELSE 0 END)) as cntIsOk, entrypoint as name')));
					?>
					<tr>
						<td>
							<p><b><?php echo $project->name; ?></b></p>
							<p>
								<?php foreach ($entrypoints as $entrypoint): ?>
									<?php if ($entrypoint->name): ?>
										&nbsp;&nbsp;&nbsp;<?php echo $entrypoint->name; ?><br/>
									<?php else: ?>
										&nbsp;&nbsp;&nbsp;&mdash;<br/>
									<?php endif; ?>
								<?php endforeach; ?>
							</p>
						</td>
						<td>
							<?php
								$projectLeadCnt = $project->leads()->whereRaw($dateWhere)->count();
							?>
							<p class="text-center"><span class="leadCntAll"><?php echo $projectLeadCnt; ?></span></p>
							<p class="text-center">
								<?php foreach ($entrypoints as $entrypoint): ?>
								<span class="leadCnt"><?php echo $entrypoint->cntIsNew; ?></span><br/>
								<?php endforeach; ?>
							</p>
						</td>
						<td>
							<?php
								$projectLeadCnt = $project->leadsWithTrashed()->whereIsbad(0)->whereNotNull('deleted_at')->whereRaw($dateWhere)->count();
							?>
							<p class="text-center"><span class="leadCntAll"><?php echo $projectLeadCnt; ?></span></p>
							<p class="text-center">
								<?php foreach ($entrypoints as $entrypoint): ?>
								<span class="leadCnt"><?php echo $entrypoint->cntIsOk; ?></span><br/>
								<?php endforeach; ?>
							</p>
						</td>
						<td>
							<?php
								$projectLeadCnt = $project->leadsWithTrashed()->whereRaw($dateWhere)->count();
								$projectdiff = $projectLeadCnt - $project->leads()->whereRaw('TIME(created_at)<TIME(NOW()) AND DATE(created_at)=DATE(DATE_SUB(?, INTERVAL 1 DAY))', array($date))->count();
							?>
							<p class="text-center"><span class="leadCntAll"><?php echo $projectLeadCnt; ?></span><?php if ($today && $projectdiff): ?><span class="<?php if ($projectdiff<0): ?> diff-minus <?php elseif ($projectdiff>0): ?> diff-plus <?php endif; ?>"><?php if($projectdiff>0): ?>+<?php endif; ?><?php echo $projectdiff; ?></span><?php endif; ?></p>
							<p class="text-center">
								<?php foreach ($entrypoints as $entrypoint): ?>
								<?php
									$diff = $entrypoint->cntAll - $entrypoint->getBeforeCnt($project->id, $entrypoint->name, $date);
								?>
								<span class="leadCnt"><?php echo $entrypoint->cntAll; ?></span><?php if ($today && $diff): ?><span class="<?php if ($diff<0): ?> diff-minus <?php elseif ($diff>0): ?> diff-plus <?php endif; ?>"><?php if($diff>0): ?>+<?php endif; ?><?php echo $diff; ?></span><?php endif; ?><br/>
								<?php endforeach; ?>
							</p>
						</td>
					</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
		</div>
	</div>
<?php endif; ?>


<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.default', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>