<?php
	include(__DIR__.'/../includes/sysinit.php');
	$date = new DateTime($_POST['booking_date']);
	$sql = "select team_name, pm_name, SUM(txn_amount) as amount
			from finance 
			inner join payment_method on payment_method.pm_id = finance.pm_id 
			inner join booking_schedule on booking_schedule.bs_id = finance.bs_id 
			inner join team on team.team_id = booking_schedule.team_id 
			where (DATE(finance.txn_date) = '".$date->format('Y-m-d')."') and (finance.txn_type_id = 3)
			group by team.team_id, finance.pm_id 
			order by team.team_id, payment_method.pm_name";
	
	$rows = $sableDB->getRows($sql);
	
	$html = '<div class="row forms-grid">
				<div class="col-md-12">
					<table>
						<tr>
							<td class="booking_heading" width="20%">Team</td>
							<td width="1%"></td>
							<td class="booking_heading" width="20%">Payment Method</td>
							<td width="1%"></td>
							<td class="booking_heading" width="78%">Amount</td>
						</tr>';
		$on = false;
		foreach($rows as $row)
		{
			$cls = $on ? "booking_info_alt booking_info" : "booking_info";
			$amt = floatval($row['amount']) * -1; //make it positive again...
			$html .='<tr>
						<td class="'.$cls.'">'.$row['team_name'].'</td>
						<td>&nbsp;</td>
						<td class="'.$cls.'">'.$row['pm_name'].'</td>
						<td>&nbsp;</td>
						<td class="'.$cls.'">R'.number_format($amt, 2).'</td>
					</tr>';
			$on = !$on;
		}
	$html .= '		</table>
				</div>
			</div>';
	SableSystem::ajaxFillField($html, 'divTeamIncomeResults');