<?php
if (isset($_REQUEST['card_id'])) {$card_id=$_REQUEST['card_id'];} else {$card_id=0;}
include('../config.php');
include('../units.php');
if ($card_id==0) exit;
$zapicey=0;
$kard_nomer=GetNomerDiscountKard($card_id);
$min_proc=GetMinSkidka($card_id);
echo 'Карточка № '.$kard_nomer.'<br>';
echo "<img src=\"barcode.php?code=".$kard_nomer."\"><br>";
echo "Мин. скидка %: <input type='text' style='width:30' id='min_proc' value='$min_proc'>";
if ($autorized_user_group<2) {
	echo "<input type='button' id='button-update-skudka' style='background: url(./img/ok.png) no-repeat top right' onclick='update_skidka($card_id);' value='  '>";
	}
//echo '<a href=#><img style=" margin: 0px;" id="imginfo" src="./img/ok.png" onclick="LoadTovarInfo('.$row['id_ttn'].');"></a><br>';
$sql = "SELECT * FROM client_shops WHERE id_card=".$card_id." AND date>=(NOW() - INTERVAL 12 MONTH);";
echo ' <table class="nice_table" cellspacing=1 cellpadding=2>
	<TR>
        <Th bgcolor="#C4D9F7">№</Th>
        <Th bgcolor="#C4D9F7">Дата покупки</Th>
        <Th bgcolor="#C4D9F7">Сумма без скидки</Th>
        <Th bgcolor="#C4D9F7">Сумма скидки</Th>
        <Th bgcolor="#C4D9F7">Сумма со скидкой</Th>
	</TR>';

foreach ($db->query($sql) as $row) {
	$zapicey++;
	$sum_so_ckidkoi=$row[3]-$row[4];
	if ($zapicey%2==0){ $mcolor='bgcolor="FBFCE8"';}else{ $mcolor='bgcolor="#FFFFF3"';}
		echo '<tr><td bgcolor="#ffffff">'.$zapicey.'</td>
		<td '.$mcolor.'>'.$row[1].'</td>
		<td '.$mcolor.'>'.CeniProbel($row[3]).'</td>
		<td '.$mcolor.'>'.CeniProbel($row[4]).'</td>
		<td '.$mcolor.'>'.CeniProbel($sum_so_ckidkoi).'</td>
		</tr>';			 
	}
echo '</TABLE>';
$sql = 'SELECT SUM(summ) FROM client_shops WHERE date>=(NOW() - INTERVAL 12 MONTH) AND id_card='.$card_id;
$summ_rub=0;
foreach ($db->query($sql) as $row) {
	$summ_rub=$row[0];
	break;}

echo '<div id="container" align="left">&nbsp;Записей: '.$zapicey.' | Итого: '.CeniProbel($summ_rub).' --> '.GetSkidka($card_id).'% скидки</div>';

?>
