
<?php $__env->startSection('title'); ?>
	@parent
	Статистика :: Производство
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
	<script src="<?php echo asset('js/bootstrap-datepicker.js'); ?>"></script>
	<script src="<?php echo asset('js/kmk-support.js'); ?>"></script>
	<script src="<?php echo asset('js/crm.js'); ?>"></script>
	<script>
		$(document).ready(function(){
			setTimeout(function(){
				window.location = "/production/stat";
			}, 5*60*1000);
		});
	</script>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div class="row">
  <div class="col-md-12">
		<div class="row">
			<div class="panel panel-default panel-production">
				<div class="panel-heading">
					<h3>Результат работы</h3>
				</div>
				<div class="panel-body">
					<table class="table table-striped table-hover">
						<thead>
							<th>Мастер</th>
							<th class="text-center">Сегодня</th>
							<th class="text-center">В этом месяце</th>
							<th class="text-center">В прошлом месяце</th>
						</thead>
						<tbody>
							<?php foreach ($masters as $masters): ?>
							<tr>
								<td>
									<h4><?php echo $masters->name; ?></h4>
									<?php foreach (ProductType::get() as $productType): ?>
										<p>&nbsp;&nbsp;&nbsp;<?php echo $productType->name; ?></p>
									<?php endforeach; ?>
								</td>
								<td class="text-center">
									<?php
										if ($masters->isseamstress) {
											$quant = Production::whereRaw('DATE(production_end_at)=CURRENT_DATE()')->count();
											$quantDiff = $quant - Production::whereRaw('TIME(production_end_at)<TIME(NOW()) AND DATE(production_end_at)=DATE(DATE_SUB(NOW(), INTERVAL 1 DAY))')->count();
										}
										else {
											$quant = Production::whereProductionMasterId($masters->id)->whereRaw('DATE(production_end_at)=CURRENT_DATE()')->count();
											$quantDiff = $quant - Production::whereProductionMasterId($masters->id)->whereRaw('TIME(production_end_at)<TIME(NOW()) AND DATE(production_end_at)=DATE(DATE_SUB(NOW(), INTERVAL 1 DAY))')->count();
										}
									?>
									<h4><?php echo $quant; ?><?php if ($quantDiff): ?><span class="<?php if ($quantDiff<0): ?> diff-minus <?php elseif ($quantDiff>0): ?> diff-plus <?php endif; ?>"><?php if($quantDiff>0): ?>+<?php endif; ?><?php echo $quantDiff; ?></span><?php endif; ?></h4>
									<?php foreach (ProductType::get() as $productType): ?>
										<?php
											if ($masters->isseamstress) {
												$quant = Production::whereProductTypeId($productType->id)->whereRaw('DATE(production_end_at)=CURRENT_DATE()')->count();
												$quantDiff = $quant - Production::whereProductTypeId($productType->id)->whereRaw('TIME(production_end_at)<TIME(NOW()) AND DATE(production_end_at)=DATE(DATE_SUB(NOW(), INTERVAL 1 DAY))')->count();
											}
											else {
												$quant = Production::whereProductionMasterId($masters->id)->whereProductTypeId($productType->id)->whereRaw('DATE(production_end_at)=CURRENT_DATE()')->count();
												$quantDiff = $quant - Production::whereProductionMasterId($masters->id)->whereProductTypeId($productType->id)->whereRaw('TIME(production_end_at)<TIME(NOW()) AND DATE(production_end_at)=DATE(DATE_SUB(NOW(), INTERVAL 1 DAY))')->count();
											}
										?>
										<p><?php echo $quant; ?><?php if ($quantDiff): ?><span class="<?php if ($quantDiff<0): ?> diff-minus <?php elseif ($quantDiff>0): ?> diff-plus <?php endif; ?>"><?php if($quantDiff>0): ?>+<?php endif; ?><?php echo $quantDiff; ?></span><?php endif; ?></p>
									<?php endforeach; ?>
								</td>
								<td class="text-center">
									<?php if ($masters->isseamstress): ?>
										<h4><?php echo Production::whereRaw('DATE_FORMAT(production_end_at, "%Y%m")=DATE_FORMAT(CURRENT_DATE(), "%Y%m")')->count(); ?></h4>
										<?php foreach (ProductType::get() as $productType): ?>
											<p><?php echo Production::whereProductTypeId($productType->id)->whereRaw('DATE_FORMAT(production_end_at, "%Y%m")=DATE_FORMAT(CURRENT_DATE(), "%Y%m")')->count(); ?></p>
										<?php endforeach; ?>
									<?php else: ?>
										<h4><?php echo Production::whereProductionMasterId($masters->id)->whereRaw('DATE_FORMAT(production_end_at, "%Y%m")=DATE_FORMAT(CURRENT_DATE(), "%Y%m")')->count(); ?></h4>
										<?php foreach (ProductType::get() as $productType): ?>
											<p><?php echo Production::whereProductionMasterId($masters->id)->whereProductTypeId($productType->id)->whereRaw('DATE_FORMAT(production_end_at, "%Y%m")=DATE_FORMAT(CURRENT_DATE(), "%Y%m")')->count(); ?></p>
										<?php endforeach; ?>
									<?php endif; ?>
								</td>
								<td class="text-center">
									<?php if ($masters->isseamstress): ?>
										<h4><?php echo Production::whereRaw('DATE_FORMAT(production_end_at, "%Y%m")=DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), "%Y%m")')->count(); ?></h4>
										<?php foreach (ProductType::get() as $productType): ?>
											<p><?php echo Production::whereProductTypeId($productType->id)->whereRaw('DATE_FORMAT(production_end_at, "%Y%m")=DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), "%Y%m")')->count(); ?></p>
										<?php endforeach; ?>
									<?php else: ?>
										<h4><?php echo Production::whereProductionMasterId($masters->id)->whereRaw('DATE_FORMAT(production_end_at, "%Y%m")=DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), "%Y%m")')->count(); ?></h4>
										<?php foreach (ProductType::get() as $productType): ?>
											<p><?php echo Production::whereProductionMasterId($masters->id)->whereProductTypeId($productType->id)->whereRaw('DATE_FORMAT(production_end_at, "%Y%m")=DATE_FORMAT(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), "%Y%m")')->count(); ?></p>
										<?php endforeach; ?>
									<?php endif; ?>
								</td>
							</tr>
							<?php endforeach; ?>
						</tbody>
					</table>
				</div>
			</div>
		</div>
  </div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.default', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>