<?php 
	$pageTitle 	= 'Список платежей';
	
	if(!isset($_GET['view']) AND !isset($_GET['edit'])){$moreinfo = '1';}
	
	require_once(ROOT . 'templates/header.php'); 
	
	require_once(ROOT . 'modules/deals/list-payments.php'); 
	
	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> 
				Список платежей <?php echo 'за '. $currentYear . ' год'; ?> <span class="list-num"><i class="fa fa-fw fa-angle-double-down" aria-hidden="true"></i> <?php echo $countPayment; ?>
				</span>
			</h1>

			<form method="POST">
				<div class="row">
					<div class="col-lg-4">
						<div class="input-group" style="margin-bottom:15px;">
							<span class="input-group-addon"><i class="fa fa-fw fa-briefcase" aria-hidden="true"></i></span>
							<select class="form-control" name="NewPaymentDeal">
								<?
								$dom_d = new DOMDocument;
								$dom_d->load($baseD);
								$xpath_d = new DOMXPath($dom_d);
								$deals_a = $xpath_d->query('/deals/deal[@type="deal-a"]');
								?>
								<option value="-">--- пусто ---</option>
								<?
								foreach ($deals_a as $deal) {
									$DealId 		= $deal->getAttribute('id');
									$DealNumber 	= $deal->getElementsByTagName("num")->item(0)->nodeValue;
									$DealCommentSm 	= mb_substr(strip_tags($deal->getElementsByTagName("comment")->item(0)->nodeValue), 0, 50, 'UTF-8') . '...';
									$DealClient 	= $deal->getAttribute('client');
									$DealType 		= $deal->getAttribute('type');
									echo '<option value="'.$DealId.'">'.$nCRMdeals.' '.$DealNumber.' - '.get_client_name($DealClient).' - "'.$DealCommentSm.'"</option>';
								}
								?>
							</select>
						</div>
					</div>
					<div class="col-lg-5">
						<div class="input-group" style="margin-bottom:15px;width:auto;">
							<span class="input-group-addon checkbox">
								<input type="checkbox" value="yes" name="checkConfirm" id="checkConfirm" checked="checked"/>
								<label for="checkConfirm" title="Подтверждение платежа"><label>
							</span>
							<div class="input-group-btn">
								<select class="form-control" style="width:auto;" name="NewPaymentType">
									<option value="profit" class="clr_low" selected="">Доход</option>
									<option value="cost" class="clr_high">Расход</option>
								</select>
							</div>
							<input type="number" class="form-control" name="NewPayment" value="0" min="0" max="99999999" step="0.01" required>
							<span class="input-group-addon">руб.</span>
						</div>
					</div>
					<div class="col-lg-3">
						<div class="input-group date-pick" style="position:relative;margin-bottom:15px;width:auto;">
							<span class="input-group-addon" style="cursor:pointer;" title="Дата добавления"><i class="fa fa-fw fa-calendar-plus-o" aria-hidden="true"></i></span>
							<input type="text" class="form-control dateS" name="inputDateStart" placeholder="ГГГГ-ММ-ДД" value="<?php if(isset($DateStart)){echo $DateStart;} else {echo date("Y-m-d");} ?>" required />
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-lg-9">
						<input list="all-paymentscom" type="text" class="form-control" style="margin-bottom:15px;" name="NewPaymentComm" value="" placeholder="Комментарий">
						<datalist id="all-paymentscom">
							<?php
							$dox = new DOMDocument;
							$dox->load($baseP);
							$xpathx = new DOMXPath($dox);
							$alltagspayment = $xpathx->query('/payments/payment');
							$sourses_arr = array();
							$i = 0;
							foreach ($alltagspayment as $payment) {
								$listSourceName = $payment->getElementsByTagName("com")->item(0)->nodeValue;
								$countSource = count($xmlpayment->xpath('/payments/payment[com="'.$listSourceName.'"]'));
								$sourses_arr[$listSourceName] =  $countSource;
								$i++;
							}
							$sources = $sourses_arr;
							foreach ($sources as $key => $value){
								if($value > 0 and $key != ''){
										echo '<option value="' . $key . '"></option>';
								}
							}
							?>
						</datalist>
					</div>
					<div class="col-lg-3">
						<div class="btn-group btn-group-justified"  style="width:100%;margin:0px 0px 15px 0px;">
							<button type="submit" name="AddPayment" style="width:100%;" class="btn btn-info" style="color:#fff;">Добавить</button>
						</div>
					</div>
				</div>
			</form>

			<canvas id="myChart" style="width:100%;height:300px;min-height:300px;max-height:300px;margin:30px 0px;"></canvas>
			<script>
			var ctx = document.getElementById("myChart").getContext('2d');
			var myChart = new Chart(ctx, {
				type: 'line',
				data: {
					labels: ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
					datasets: [{
						label: 'Доходы',
						data: [
							<?php echo count_payments_val('profit', $sel_year, '01');?>,
							<?php echo count_payments_val('profit', $sel_year, '02');?>,
							<?php echo count_payments_val('profit', $sel_year, '03');?>,
							<?php echo count_payments_val('profit', $sel_year, '04');?>,
							<?php echo count_payments_val('profit', $sel_year, '05');?>,
							<?php echo count_payments_val('profit', $sel_year, '06');?>,
							<?php echo count_payments_val('profit', $sel_year, '07');?>,
							<?php echo count_payments_val('profit', $sel_year, '08');?>,
							<?php echo count_payments_val('profit', $sel_year, '09');?>,
							<?php echo count_payments_val('profit', $sel_year, '10');?>,
							<?php echo count_payments_val('profit', $sel_year, '11');?>,
							<?php echo count_payments_val('profit', $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_payments_val('cost', $sel_year, '01');?>,
							<?php echo count_payments_val('cost', $sel_year, '02');?>,
							<?php echo count_payments_val('cost', $sel_year, '03');?>,
							<?php echo count_payments_val('cost', $sel_year, '04');?>,
							<?php echo count_payments_val('cost', $sel_year, '05');?>,
							<?php echo count_payments_val('cost', $sel_year, '06');?>,
							<?php echo count_payments_val('cost', $sel_year, '07');?>,
							<?php echo count_payments_val('cost', $sel_year, '08');?>,
							<?php echo count_payments_val('cost', $sel_year, '09');?>,
							<?php echo count_payments_val('cost', $sel_year, '10');?>,
							<?php echo count_payments_val('cost', $sel_year, '11');?>,
							<?php echo count_payments_val('cost', $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)'
					}],
				},
				options: {
					scales: {
						yAxes: [{
							ticks: {
								beginAtZero:true
							}
						}]
					},
					legend: {
						position: 'bottom'
					}
				}
			});
			</script>
			
			<?php require_once(ROOT . 'templates/search-form.php'); ?>
			
			<?php require_once(ROOT . 'modules/deals/list-payments-m.php'); ?>
			<?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>