<?php 
	$pageTitle 	= 'Архив сделок и предложений';
	
	if(!isset($_GET['view']) AND !isset($_GET['edit'])){$filters = '1';}
	
	require_once(ROOT . 'templates/header.php'); 
	
	require_once(ROOT . 'modules/deals/list-deals-archive.php'); 
	
	if(isset($_POST["selectClient"])){$chartClient=$_POST["selectClient"];}else{$chartClient = '';}
	
	require_once(ROOT . 'templates/main-menu.php');
?>
<div class="container<?php global $designView; echo $designView; ?>">
	<div class="row">
		<div class="col-lg-3 col-lg-push-9 col-md-4 col-md-push-8 col-sm-12">
			<?php require_once(ROOT . 'templates/side-block.php'); ?>
		</div>
		<div class="col-lg-9 col-lg-pull-3 col-md-8 col-md-pull-4 col-sm-12">
		
			<h1><a href="javascript: ;" onclick="history.go(-1)"><i class="fa fa-fw fa-angle-double-left" aria-hidden="true" title="Вернуться к списку"></i></a> Архив сделок<span class="hidden-xs"> и предложений</span> <?php if(isset($_POST["checkYear"])) {?>за <?php echo $currentYear;?> год<?php } ?><span class="list-num"><i class="fa fa-fw fa-angle-double-down" aria-hidden="true"></i> <?php if(isset($_POST["selectDealType"]) AND isset($_POST["selectClient"]) AND isset($_POST["inputPriceS"]) AND isset($_POST["inputPriceE"]) AND isset($_POST["checkYear"])){echo multi_count_deal($_POST["selectDealType"], $_POST["selectClient"], $sel_year, $_POST["inputPriceS"], $_POST["inputPriceE"]);}else{echo multi_count_deal('', '', $sel_year, '', '');} ?></span></h1>
			
			<?php require_once(ROOT . 'templates/search-form.php'); ?>
			
			<?php if (isset( $_POST["checkDealType"] ) and isset( $_POST["checkYear"]) or isset( $_POST["radioPrice"]) and isset( $_POST["checkYear"]) or isset( $_POST["checkClient"] ) and isset( $_POST["checkYear"])) {?>
			<div class="chart-container" style="position: relative; height:40vh; width:100%;margin-bottom:30px;">
				<canvas id="myChart"></canvas>
			</div>
			<script>
			var ctx = document.getElementById("myChart").getContext('2d');
			var myChart = new Chart(ctx, {
				type: 'line',
				data: {
					labels: ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
					datasets: [{
						label: 'Расходы',
						data: [
							-<?php echo count_deals_price_summ($sel_type, 'costs', $chartClient, $sel_year, '01');?>,
							-<?php echo count_deals_price_summ($sel_type, 'costs', $chartClient, $sel_year, '02');?>,
							-<?php echo count_deals_price_summ($sel_type, 'costs', $chartClient, $sel_year, '03');?>,
							-<?php echo count_deals_price_summ($sel_type, 'costs', $chartClient, $sel_year, '04');?>,
							-<?php echo count_deals_price_summ($sel_type, 'costs', $chartClient, $sel_year, '05');?>,
							-<?php echo count_deals_price_summ($sel_type, 'costs', $chartClient, $sel_year, '06');?>,
							-<?php echo count_deals_price_summ($sel_type, 'costs', $chartClient, $sel_year, '07');?>,
							-<?php echo count_deals_price_summ($sel_type, 'costs', $chartClient, $sel_year, '08');?>,
							-<?php echo count_deals_price_summ($sel_type, 'costs', $chartClient, $sel_year, '09');?>,
							-<?php echo count_deals_price_summ($sel_type, 'costs', $chartClient, $sel_year, '10');?>,
							-<?php echo count_deals_price_summ($sel_type, 'costs', $chartClient, $sel_year, '11');?>,
							-<?php echo count_deals_price_summ($sel_type, 'costs', $chartClient, $sel_year, '12');?>
						],
						backgroundColor: [ 'rgba(219, 90, 89, 0.25)' ],
						borderColor: 'rgba(219, 90, 89, 1.0)',
						borderWidth: 2,
						tension: 0,
						pointStyle: 'circle',
						pointRadius: 3,
						pointBackgroundColor: 'rgba(219, 90, 89, 1.0)'
					},{
						label: 'Прибыль',
						data: [
							<?php echo count_deals_profit_summ($sel_type, $chartClient, $sel_year, '01');?>,
							<?php echo count_deals_profit_summ($sel_type, $chartClient, $sel_year, '02');?>,
							<?php echo count_deals_profit_summ($sel_type, $chartClient, $sel_year, '03');?>,
							<?php echo count_deals_profit_summ($sel_type, $chartClient, $sel_year, '04');?>,
							<?php echo count_deals_profit_summ($sel_type, $chartClient, $sel_year, '05');?>,
							<?php echo count_deals_profit_summ($sel_type, $chartClient, $sel_year, '06');?>,
							<?php echo count_deals_profit_summ($sel_type, $chartClient, $sel_year, '07');?>,
							<?php echo count_deals_profit_summ($sel_type, $chartClient, $sel_year, '08');?>,
							<?php echo count_deals_profit_summ($sel_type, $chartClient, $sel_year, '09');?>,
							<?php echo count_deals_profit_summ($sel_type, $chartClient, $sel_year, '10');?>,
							<?php echo count_deals_profit_summ($sel_type, $chartClient, $sel_year, '11');?>,
							<?php echo count_deals_profit_summ($sel_type, $chartClient, $sel_year, '12');?>,
						],
						backgroundColor: [ 'rgba(122, 178, 98, 0.25)' ],
						borderColor: 'rgba(122, 178, 98, 1.0)',
						borderWidth: 2,
						tension: 0,
						pointStyle: 'circle',
						pointRadius: 3,
						pointBackgroundColor: 'rgba(122, 178, 98, 1.0)'
					},{
						label: 'Доходы',
						data: [
							<?php echo count_deals_price_summ($sel_type, 'price', $chartClient, $sel_year, '01');?>,
							<?php echo count_deals_price_summ($sel_type, 'price', $chartClient, $sel_year, '02');?>,
							<?php echo count_deals_price_summ($sel_type, 'price', $chartClient, $sel_year, '03');?>,
							<?php echo count_deals_price_summ($sel_type, 'price', $chartClient, $sel_year, '04');?>,
							<?php echo count_deals_price_summ($sel_type, 'price', $chartClient, $sel_year, '05');?>,
							<?php echo count_deals_price_summ($sel_type, 'price', $chartClient, $sel_year, '06');?>,
							<?php echo count_deals_price_summ($sel_type, 'price', $chartClient, $sel_year, '07');?>,
							<?php echo count_deals_price_summ($sel_type, 'price', $chartClient, $sel_year, '08');?>,
							<?php echo count_deals_price_summ($sel_type, 'price', $chartClient, $sel_year, '09');?>,
							<?php echo count_deals_price_summ($sel_type, 'price', $chartClient, $sel_year, '10');?>,
							<?php echo count_deals_price_summ($sel_type, 'price', $chartClient, $sel_year, '11');?>,
							<?php echo count_deals_price_summ($sel_type, 'price', $chartClient, $sel_year, '12');?>
						],
						backgroundColor: [ 'rgba(64, 73, 91, 0.0)' ],
						borderColor: 'rgba(64, 73, 91, 1.0)',
						borderWidth: 2,
						tension: 0,
						pointStyle: 'circle',
						pointRadius: 3,
						pointBackgroundColor: 'rgba(64, 73, 91, 1.0)'
					},{
						label: 'Долги',
						data: [
							-<?php echo count_deals_debt_summ($sel_type, $chartClient, $sel_year, '01');?>,
							-<?php echo count_deals_debt_summ($sel_type, $chartClient, $sel_year, '02');?>,
							-<?php echo count_deals_debt_summ($sel_type, $chartClient, $sel_year, '03');?>,
							-<?php echo count_deals_debt_summ($sel_type, $chartClient, $sel_year, '04');?>,
							-<?php echo count_deals_debt_summ($sel_type, $chartClient, $sel_year, '05');?>,
							-<?php echo count_deals_debt_summ($sel_type, $chartClient, $sel_year, '06');?>,
							-<?php echo count_deals_debt_summ($sel_type, $chartClient, $sel_year, '07');?>,
							-<?php echo count_deals_debt_summ($sel_type, $chartClient, $sel_year, '08');?>,
							-<?php echo count_deals_debt_summ($sel_type, $chartClient, $sel_year, '09');?>,
							-<?php echo count_deals_debt_summ($sel_type, $chartClient, $sel_year, '10');?>,
							-<?php echo count_deals_debt_summ($sel_type, $chartClient, $sel_year, '11');?>,
							-<?php echo count_deals_debt_summ($sel_type, $chartClient, $sel_year, '12');?>
						],
						backgroundColor: [ 'rgba(89, 149, 219, 0.25)' ],
						borderColor: 'rgba(89, 149, 219, 1.0)',
						borderWidth: 2,
						tension: 0,
						pointStyle: 'circle',
						pointRadius: 3,
						pointBackgroundColor: 'rgba(589, 149, 219, 1.0)'
					}],
				},
				options: {
					scales: {
						yAxes: [{
							ticks: {
								beginAtZero:true
							}
						}]
					},
					responsive: true,
					maintainAspectRatio: false,
					legend: {
						position: 'bottom'
					}
				}
			});
			</script>
			<?php } ?>
			
			<div class="table-responsive">
				<table id="all-deals" class="table table-hover all-deals deals-inwork">
					<thead> 
						<tr> 
							<th width="6%"></th> 
							<th width="25%">Наименование</th>
							<th width="15%" style="text-align:right!important;">Сумма</th>
							<th width="6%" title="Рентабельность"><i class="fa fa-fw fa-line-chart" aria-hidden="true"></i></th>
							<th width="15%" data-sorter="shortDate" data-date-format="yyyymmdd">Добавление</th> 
							<th width="15%" data-sorter="shortDate" data-date-format="yyyymmdd">Завершение</th>
							<th width="6%" title="Время выполнения, дней"><i class="fa fa-hourglass-half" aria-hidden="true"></i></th> 
							<th width="6%"></th>
							<th width="6%"></th>
						</tr> 
					</thead> 
					<tbody>
						<?php require_once(ROOT . 'modules/deals/list-deals-m.php'); ?>
					</tbody>
				</table>
			</div>
			<?php require_once(ROOT . 'templates/table-pager.php'); ?>
		</div>
	</div>
</div>
<?
	require_once(ROOT . 'templates/modal-wind.php');
	require_once(ROOT . 'templates/footer.php');
?>
	</body>
</html>