<h3 class="text-center" style="margin:30px 0px 30px;">Ежегодные финансовые показатели</h3>

<div class="chart-container" style="position: relative; height:40vh; width:100%; margin-bottom:50px;">
	<canvas id="Deals10age"></canvas>
</div>
<script>
var ctxdeals10age = document.getElementById("Deals10age").getContext('2d');
var Deals10age = new Chart(ctxdeals10age, {
	type: 'line',
	data: {
		labels: ["<?php echo date("Y",strtotime("- 4 years")); ?>", "<?php echo date("Y",strtotime("- 3 years")); ?>", "<?php echo date("Y",strtotime("- 2 years")); ?>", "<?php echo date("Y",strtotime("- 1 years")); ?>", "<?php echo date("Y"); ?>"],
		datasets: [{
			label: 'Расходы',
			stack: 'Stack 2',
			data: [-<?php echo deals_year_sum('ac', 'cost', '4'); ?>, -<?php echo deals_year_sum('ac', 'cost', '3'); ?>, -<?php echo deals_year_sum('ac', 'cost', '2'); ?>, -<?php echo deals_year_sum('ac', 'cost', '1'); ?>, -<?php echo deals_year_sum('ac', 'cost', '0'); ?>],
			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: 'Прибыль',
			stack: 'Stack 1',
			data: [<?php echo deals_year_diff('ac', '4'); ?>, <?php echo deals_year_diff('ac', '3'); ?>, <?php echo deals_year_diff('ac', '2'); ?>, <?php echo deals_year_diff('ac', '1'); ?>, <?php echo deals_year_diff('ac', '0'); ?>],
			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: 'Доходы',
			stack: 'Stack 0',
			data: [<?php echo deals_year_sum('ac', 'deal', '4'); ?>, <?php echo deals_year_sum('ac', 'deal', '3'); ?>, <?php echo deals_year_sum('ac', 'deal', '2'); ?>, <?php echo deals_year_sum('ac', 'deal', '1'); ?>, <?php echo deals_year_sum('ac', 'deal', '0'); ?>],
			backgroundColor: [ 'rgba(212,219,89, 0.0)' ],
			borderColor: 'rgba(212,219,89, 1.0)',
			borderWidth: 2,
			tension: 0,
			pointStyle: 'circle',
			pointRadius: 3,
			pointBackgroundColor: 'rgba(212,219,89, 1.0)'
		}]
	},
	options: {
		scales: {
			yAxes: [{
				ticks: {
					beginAtZero:true
				}
			}]
		},
		responsive: true,
		maintainAspectRatio: false,
		legend: {
			position: 'bottom'
		}
	}
});
</script>
<div class="row">
	<div class="col-lg-4">
		<div class="panel panel-default">
			<div class="panel-body">
				<div class="row">
					<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">Доходы за весь период:</div>
					<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5" style="text-align:right;"><b title="<?php echo conv_price( $StatPrice , 'long' , 'руб.' );?>"><?php echo conv_price( $StatPrice , 'short' , '<i class="fa fa-sm fa-rub"></i>' );?></b></div>
				</div>
				<hr/>
				<div class="row">
					<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">Расходы за весь период:</div>
					<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5" style="text-align:right;"><b title="<?php echo conv_price( $StatCosts , 'long' , 'руб.' );?>"><?php echo conv_price( $StatCosts , 'short' , '<i class="fa fa-sm fa-rub"></i>' );?></b></div>
				</div>
				<hr/>
				<div class="row">
					<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">Прибыль за весь период:</div>
					<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5" style="text-align:right;"><b title="<?php echo conv_price( $StatProfit , 'long' , 'руб.' );?>"><?php echo conv_price( $StatProfit , 'short' , '<i class="fa fa-sm fa-rub"></i>' );?></b></div>
				</div>
				<hr/>
				<div class="row">
					<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">Рентабельность общая:</div>
					<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5" style="text-align:right;"><b><?php if($StatPrice > 0){echo round($StatProfit / $StatPrice * 100 , 1);} else {echo '0';} ?> %</b></div>
				</div>
			</div>
		</div>
	</div>
	<div class="col-lg-4">
		<div class="panel panel-default">
			<div class="panel-body">
				<div class="row">
					<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">Доходы за текущий год:</div>
					<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5" style="text-align:right;"><b title="<?php echo conv_price( $StatPriceYear , 'long' , 'руб.' );?>"><?php echo conv_price( $StatPriceYear , 'short' , '<i class="fa fa-sm fa-rub"></i>' );?></b> <?php echo percent2(deals_year_sum('ac', 'deal', '1')/12, deals_year_sum('ac', 'deal', '0')/date("n"),'sup_info'); ?></div>
				</div>
				<hr/>
				<div class="row">
					<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">Расходы за текущий год:</div>
					<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5" style="text-align:right;"><b title="<?php echo conv_price( $StatCostsYear , 'long' , 'руб.' );?>"><?php echo conv_price( $StatCostsYear , 'short' , '<i class="fa fa-sm fa-rub"></i>' );?></b> <?php echo percent2(deals_year_sum('ac', 'cost', '1')/12, deals_year_sum('ac', 'cost', '0')/date("n"),'sup_info'); ?></div>
				</div>
				<hr/>
				<div class="row">
					<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">Прибыль за текущий год:</div>
					<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5" style="text-align:right;">
						<b title="<?php echo conv_price( $StatProfitYear , 'long' , 'руб.' );?>">
							<?php echo conv_price( $StatProfitYear , 'short' , '<i class="fa fa-sm fa-rub"></i>' );?>
						</b> <?php echo percent2(deals_year_diff('ac', '1')/12, deals_year_diff('ac', '0')/date("n"),'sup_info'); ?>
					</div>
				</div>
				<hr/>
				<div class="row">
					<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">Рентабельность за год:</div>
					<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5" style="text-align:right;"><b><?php echo profit_year('deal', 'ac', '0'); ?> %</b> <?php echo difference(profit_year('deal', 'ac', '1'), profit_year('deal', 'ac', '0'),'sup_info','%'); ?></div>
				</div>
			</div>
		</div>
	</div>
	<div class="col-lg-4">
		<div class="panel panel-default">
			<div class="panel-body">
				<div class="row">
					<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">Средний доход сделки:</div>
					<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5" style="text-align:right;">
						<?php 
						$dealsCount = multi_count_deal('deal-a', '', date("Y"), '', '') + multi_count_deal('deal-c', '', date("Y"), '', '');
						if($dealsCount > 0) {$averageDeal = $StatPriceYear / $dealsCount;} else {$averageDeal = 0;}
						?>
						<b title="<?php echo conv_price( $averageDeal , 'long' , 'руб.' );?>"><?php echo conv_price( $averageDeal , 'short' , '<i class="fa fa-sm fa-rub"></i>' );?></b>
					</div>
				</div>
				<hr/>
				<div class="row">
					<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">Средняя прибыль в месяц:</div>
					<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5" style="text-align:right;"><b title="<?php echo conv_price( $StatProfitYear/date("n") , 'long' , 'руб.' );?>"><?php echo conv_price( $StatProfitYear/date("n") , 'short' , '<i class="fa fa-sm fa-rub"></i>' );?></b></div>
				</div>
				<hr/>
				<div class="row">
					<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">Средний доход в день:</div>
					<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5" style="text-align:right;"><b title="<?php echo conv_price( $countDayPrice , 'long' , 'руб.' );?>"><?php echo conv_price( $countDayPrice , 'short' , '<i class="fa fa-sm fa-rub"></i>' );?></b></div>
				</div>
				<hr/>
				<div class="row">
					<div class="col-lg-7 col-md-7 col-sm-7 col-xs-7">Общая сумма долгов:</div>
					<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5" style="text-align:right;"><b title="<?php echo conv_price( count_deals_debt_summ('', '', '', '') , 'long' , 'руб.' );?>"><?php echo conv_price( count_deals_debt_summ('', '', '', '') , 'short' , '<i class="fa fa-sm fa-rub"></i>' );?></b></div>
				</div>
			</div>
		</div>
	</div>
</div>
<h3 class="text-center" style="margin:30px 0px 30px;">Средние ежемесячные финансовые показатели</h3>
<div class="chart-container" style="position: relative; height:40vh; width:100%; margin-top:50px;">
	<canvas id="Deals10ageAv"></canvas>
</div>
<script>
var ctxdeals10ageav = document.getElementById("Deals10ageAv").getContext('2d');
var Deals10ageAv = new Chart(ctxdeals10ageav, {
	type: 'line',
	data: {
		labels: ["<?php echo date("Y",strtotime("- 4 years")); ?>", "<?php echo date("Y",strtotime("- 3 years")); ?>", "<?php echo date("Y",strtotime("- 2 years")); ?>", "<?php echo date("Y",strtotime("- 1 years")); ?>", "<?php echo date("Y"); ?>"],
		datasets: [{
			label: 'Ежемес.Расходы',
			stack: 'Stack 2',
			data: [-<?php echo deals_year_average('cost', '4'); ?>, -<?php echo deals_year_average('cost', '3'); ?>, -<?php echo deals_year_average('cost', '2'); ?>, -<?php echo deals_year_average('cost', '1'); ?>, -<?php echo deals_year_average('cost', '0'); ?>],
			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: 'Ежемес.Прибыль',
			stack: 'Stack 1',
			data: [<?php echo deals_year_average('paid', '4'); ?>, <?php echo deals_year_average('paid', '3'); ?>, <?php echo deals_year_average('paid', '2'); ?>, <?php echo deals_year_average('paid', '1'); ?>, <?php echo deals_year_average('paid', '0'); ?>],
			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: 'Ежемес.Доходы',
			stack: 'Stack 0',
			data: [<?php echo deals_year_average('deal', '4'); ?>, <?php echo deals_year_average('deal', '3'); ?>, <?php echo deals_year_average('deal', '2'); ?>, <?php echo deals_year_average('deal', '1'); ?>, <?php echo deals_year_average('deal', '0'); ?>],
			backgroundColor: [ 'rgba(212,219,89, 0.0)' ],
			borderColor: 'rgba(212,219,89, 1.0)',
			borderWidth: 2,
			tension: 0,
			pointStyle: 'circle',
			pointRadius: 3,
			pointBackgroundColor: 'rgba(212,219,89, 1.0)'
		}]
	},
	options: {
		scales: {
			yAxes: [{
				ticks: {
					beginAtZero:true
				}
			}]
		},
		responsive: true,
		maintainAspectRatio: false,
		legend: {
			position: 'bottom'
		}
	}
});
</script>