

<?php
/* $Id: index.php 6941 2014-10-26 23:18:08Z daintree $*/
error_reporting(E_ALL & ~E_NOTICE);
$PageSecurity=0;
ob_start();
include('includes/session.inc');
$Title=_('ERP Home');
include('includes/newheader.php');

include('includes/SQL_CommonFunctions.inc');
include('includes/GetPaymentMethods.php');
include('includes/GetPrice.inc');


$userid = $_SESSION['UserID'];

?>

		
  					
	<script src="angular/angular.min.js"></script>  
        
 
     
     
		
		
  					
	<script src="angular/angular.min.js"></script>  
        
 
     
      <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.16/b-1.5.1/b-flash-1.5.1/b-html5-1.5.1/b-print-1.5.1/datatables.min.css"/>
 <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.5.1/css/buttons.dataTables.min.css"/>
 <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css"/>
 
   <script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js"></script>
	<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.flash.min.js"></script>
	<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.html5.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.5.1/js/buttons.print.min.js"></script>
     
		<script language="JavaScript" type="text/javascript"src="js/Chart.js"></script>
 <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">



<!-- Latest compiled JavaScript -->
<script src="js/bootstrap.min.js"></script>

   

<button id="alltrans">All Trans</button>
<button id="trans">Outstng Trans</button>
 <button id="email">Email Statement</button>
<button id="pdfprint">Print Statement</button>
<button id="pdfprintinv">Print Statement incl Outstanding Invoices</button>
<button id="pdfprintall">Print All Statement</button>

<div class="modal fade" id="modelWindow" role="dialog">
            <div class="modal-dialog modal-xl vertical-align-center">
              <div class="modal-content">
                <div class="modal-header">
                  <button id = "close1"  type="button" class="close" data-dismiss="modal">&times;</button>
                  <h4 class="modal-title">Transactions</h4>
                </div>
                <div class="modal-body">
                   <table id="userTable" border="1" class="table-responsive" >
      <thead> 
        <tr>
          <th >Type</th>
          <th>No</th>
          <th>Date</th>
          <th >Total</th>
			
			<th >Outstanding Amount</th>
        </tr>
      </thead>
    <tbody> <button onclick="exportTableToCSV('trans.csv')">Export to CSV File</button> </tbody>
   </table>
                </div>
                <div class="modal-footer">
                    <button id = "close" type="button" data-dismiss="modal" class="btn btn-default">Close</button>
                </div>
              </div>
            </div>
        </div>
  

	<script>
					
					function downloadCSV(csv, filename) {
    var csvFile;
    var downloadLink;

    // CSV file
    csvFile = new Blob([csv], {type: "text/csv"});

    // Download link
    downloadLink = document.createElement("a");

    // File name
    downloadLink.download = filename;

    // Create a link to the file
    downloadLink.href = window.URL.createObjectURL(csvFile);

    // Hide download link
    downloadLink.style.display = "none";

    // Add the link to DOM
    document.body.appendChild(downloadLink);

    // Click download link
    downloadLink.click();
}
					
										function exportTableToCSV(filename) {
    var csv = [];
    var rows = document.querySelectorAll("[id=userTable] tr");
    
    for (var i = 0; i < rows.length; i++) {
        var row = [], cols = rows[i].querySelectorAll("td, th");
        
        for (var j = 0; j < cols.length; j++) 
            row.push(cols[j].innerText);
        
        csv.push(row.join(","));        
    }

    // Download CSV file
    downloadCSV(csv.join("\n"), filename);
}
										
										
										</script>	
 									
									<?php
//this is where you paste. Below paste it:
echo '<div class="row">';

	echo '<div class="col-sm-12">';
echo "DEBTORS AGEING REPORT GROUP BY ACCOUNT NUMBER";
	
	

	//include('includes/footer.inc');


	
	if (isset($_POST['PrintPDF']) AND (isset($_POST['department']))){

//check balances from debtoraccount
			
			$sqlbalances="SELECT account_number, debtorno, departmentid,balance, current,1month,2month,3month_plus
					FROM debtoraccount
					WHERE debtorno = '" . $_POST['department']."'";
		$resultfromdebtoraccount =DB_query($sqlbalances);

		
	
	
echo '<div class="table-responsive"><table id="projectreport" class="table">';
	echo '<thead> <tr class="info">
			<th>' . _('Debtor No:') . '</th>
			
			<th>' . _('Debtor Name') . '</th>
			<th>' . _('Account Number') . '</th>
			<th>' . _('Department') . '</th>
			<th>' . _('Balance') . '</th>
			<th>' . _('Current') . '</th>
			<th>' . _('30 Days ') . '</th>
			<th>' . _('60 Days') . '</th>
			<th>' . _('90 Days') . '</th>
			<th>' . _('120 Days ') . '</th>
			<th>' . _('150 Days ') . '</th>
			<th>' . _('180 Days') . '</th>
			<th>' . _('180 Days Plus') . '</th>
			<th>' . _('Last Paid') . '</th>
			<th>' . _('Last Paid Date') . '</th>
				<th>' . _('Retention Balance') . '</th>
	
			</thead></tr>';

			while ($myrowfromdebtoraccount = DB_fetch_array($resultfromdebtoraccount)){
				
				
				
				
			$SQL9 = "SELECT 
			                departmentname
			
														
		                            FROM department
									
			WHERE departmentid = '".$myrowfromdebtoraccount['departmentid']."'";
			$result9=DB_query($SQL9);
			$myrow9=DB_fetch_array($result9);
				$departmentname = $myrow9['departmentname'];
					$balance = $myrowfromdebtoraccount['balance'];
			
			$current = $myrowfromdebtoraccount['current'];
			$onemonth = $myrowfromdebtoraccount['1month'];
			$twomonth = $myrowfromdebtoraccount['2month'];
			$threemonthplus = $myrowfromdebtoraccount['3month'];
				
			$accountnumber = 	$myrowfromdebtoraccount['account_number'];
				
				$SQL = "SELECT 
				debtorsmaster.name,
				debtorsmaster.lastpaid,
				debtorsmaster.lastpaiddate,
				debtortrans.account_number,
				
				paymentterms.terms,
			
				SUM(
					debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc - debtortrans.ptax - debtortrans.retention
				) AS balance,
				SUM(debtortrans.ptax) AS ptaxbalance,
						SUM(debtortrans.retention) AS retentionbalance,
				SUM(
					CASE WHEN (paymentterms.daysbeforedue > 0)
					THEN
						CASE WHEN (TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate)) >= paymentterms.daysbeforedue
						THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc - debtortrans.ptax - debtortrans.retention
						ELSE 0 END
					ELSE
						CASE WHEN TO_DAYS(Now()) - TO_DAYS(DATE_ADD(DATE_ADD(debtortrans.trandate, " . INTERVAL('1', 'MONTH') . "), " . INTERVAL('(paymentterms.dayinfollowingmonth - DAYOFMONTH(debtortrans.trandate))', 'DAY') .")) >= 0
						THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc - debtortrans.ptax - debtortrans.retention ELSE 0 END
					END
				) AS due,
					
				SUM(
					CASE WHEN (paymentterms.daysbeforedue > 0)
					THEN
						CASE WHEN (TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate)) > paymentterms.daysbeforedue AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= (paymentterms.daysbeforedue + " . $_SESSION['PastDueDays2'] . ")
						THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc - debtortrans.ptax - debtortrans.retention ELSE 0 END
					ELSE
						CASE WHEN TO_DAYS(Now()) - TO_DAYS(DATE_ADD(DATE_ADD(debtortrans.trandate, " . INTERVAL ('1', 'MONTH') . "), " . INTERVAL('(paymentterms.dayinfollowingmonth - DAYOFMONTH(debtortrans.trandate))', 'DAY') . ")) >= " . $_SESSION['PastDueDays2'] . "
						THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc - debtortrans.ptax - debtortrans.retention
						ELSE 0 END
					END
				) AS overdue2,
					SUM(
					CASE WHEN (paymentterms.daysbeforedue > 0)
					THEN
						CASE WHEN (TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate)) > paymentterms.daysbeforedue AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= (paymentterms.daysbeforedue + 90)
						THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc - debtortrans.ptax - debtortrans.retention ELSE 0 END
					ELSE
						CASE WHEN TO_DAYS(Now()) - TO_DAYS(DATE_ADD(DATE_ADD(debtortrans.trandate, " . INTERVAL ('3', 'MONTH') . "), " . INTERVAL('(paymentterms.dayinfollowingmonth - DAYOFMONTH(debtortrans.trandate))', 'DAY') . ")) >= 90
						THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc - debtortrans.ptax - debtortrans.retention
						ELSE 0 END
					END
				) AS overdue3,
					SUM(
					CASE WHEN (paymentterms.daysbeforedue > 0)
					THEN
						CASE WHEN (TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate)) > paymentterms.daysbeforedue AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= (paymentterms.daysbeforedue + 120)
						THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc - debtortrans.ptax - debtortrans.retention ELSE 0 END
					ELSE
						CASE WHEN TO_DAYS(Now()) - TO_DAYS(DATE_ADD(DATE_ADD(debtortrans.trandate, " . INTERVAL ('4', 'MONTH') . "), " . INTERVAL('(paymentterms.dayinfollowingmonth - DAYOFMONTH(debtortrans.trandate))', 'DAY') . ")) >= 120
						THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc - debtortrans.ptax - debtortrans.retention
						ELSE 0 END
					END
				) AS overdue4,
					SUM(
					CASE WHEN (paymentterms.daysbeforedue > 0)
					THEN
						CASE WHEN (TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate)) > paymentterms.daysbeforedue AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= (paymentterms.daysbeforedue + 150)
						THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc - debtortrans.ptax - debtortrans.retention ELSE 0 END
					ELSE
						CASE WHEN TO_DAYS(Now()) - TO_DAYS(DATE_ADD(DATE_ADD(debtortrans.trandate, " . INTERVAL ('5', 'MONTH') . "), " . INTERVAL('(paymentterms.dayinfollowingmonth - DAYOFMONTH(debtortrans.trandate))', 'DAY') . ")) >= 150
						THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc - debtortrans.ptax - debtortrans.retention
						ELSE 0 END
					END
				) AS overdue5,
					SUM(
					CASE WHEN (paymentterms.daysbeforedue > 0)
					THEN
						CASE WHEN (TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate)) > paymentterms.daysbeforedue AND TO_DAYS(Now()) - TO_DAYS(debtortrans.trandate) >= (paymentterms.daysbeforedue + 180)
						THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc - debtortrans.ptax - debtortrans.retention ELSE 0 END
					ELSE
						CASE WHEN TO_DAYS(Now()) - TO_DAYS(DATE_ADD(DATE_ADD(debtortrans.trandate, " . INTERVAL ('6', 'MONTH') . "), " . INTERVAL('(paymentterms.dayinfollowingmonth - DAYOFMONTH(debtortrans.trandate))', 'DAY') . ")) >= 180
						THEN debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount - debtortrans.alloc - debtortrans.ptax - debtortrans.retention
						ELSE 0 END
					END
				) AS overdue6
				FROM debtorsmaster,
					paymentterms,
					
					debtortrans
				WHERE debtorsmaster.paymentterms = paymentterms.termsindicator
				
			AND debtortrans.account_number = '" . $accountnumber."'
					
					AND debtorsmaster.debtorno =  '" . $myrowfromdebtoraccount['debtorno']."'
						AND debtortrans.settled=0
				AND debtortrans.cancelled = '0'
				AND debtortrans.trandate > '2020-12-31 00:00:00'
				
					 ";

		
			
	$ErrMsg = _('This customer could not be added because');
			$result4 = DB_query($SQL,$ErrMsg);
	
				
				
			
		$AgedAnalysis = DB_fetch_array($result4);
			
			
			
			$CurrDecimalPlaces = $AgedAnalysis['decimalplaces'];
				$DisplayDue = locale_number_format($AgedAnalysis['due']-$AgedAnalysis['overdue1'],$CurrDecimalPlaces);
		$DisplayCurrent = locale_number_format($AgedAnalysis['balance']-$AgedAnalysis['due'],$CurrDecimalPlaces);
		$DisplayBalance = locale_number_format(($AgedAnalysis['balance']),$CurrDecimalPlaces);
		$DisplayOverdue1 = locale_number_format($AgedAnalysis['overdue1']-$AgedAnalysis['overdue2'],$CurrDecimalPlaces);
		$DisplayOverdue2 = locale_number_format($AgedAnalysis['overdue2'],$CurrDecimalPlaces);
		$Lastpaid = locale_number_format($AgedAnalysis['lastpaid'],$CurrDecimalPlaces);
		$Lastpaiddate =  $AgedAnalysis['lastpaiddate'];                  
		
		
		$TotBal = $AgedAnalysis['balance'];
		$TotDue = ($AgedAnalysis['due']-$AgedAnalysis['overdue1']);
		$TotCurr = ($AgedAnalysis['balance']-$AgedAnalysis['due']);
	
		$TotOD1 = ($AgedAnalysis['overdue1']-$AgedAnalysis['overdue2']);
		$TotOD2 = $AgedAnalysis['overdue2']-$AgedAnalysis['overdue3'];
			
			$TotOD3 = $AgedAnalysis['overdue3']-$AgedAnalysis['overdue4'];
				$TotOD4 = $AgedAnalysis['overdue3']-$AgedAnalysis['overdue4'];
				$TotOD5 = $AgedAnalysis['overdue4']-$AgedAnalysis['overdue5'];
				$TotOD6 = $AgedAnalysis['overdue5']-$AgedAnalysis['overdue6'];
			
			$TotOD7 = $AgedAnalysis['overdue6'];	
	$DisplayTotBalance = locale_number_format($TotBal,$CurrDecimalPlaces);
	$DisplayTotDue = locale_number_format($TotDue,$CurrDecimalPlaces);
	$DisplayTotCurrent = locale_number_format($TotCurr,$CurrDecimalPlaces);
	$DisplayTotOverdue1 = locale_number_format($TotOD1,$CurrDecimalPlaces);
	$DisplayTotOverdue2 = locale_number_format($TotOD2,$CurrDecimalPlaces);
			
			
			
			
			
			$finalbalance = $TotBal ;
		
				
				$retentionBalance = locale_number_format($AgedAnalysis['retentionbalance'],2);
			
		echo 		
					'<tr><td>' . $myrowfromdebtoraccount['debtorno'].'</td>
					 
					
					<td>' . $AgedAnalysis['name']. '</td>
					<td>' . $accountnumber. '</td>
					<td>' . $departmentname. '</td>
					<td>' . round($finalbalance,2). '</td>
					<td>' . $TotCurr. '</td>
					<td>' . $DisplayTotDue. '</td>
					<td>' . $TotOD2. '</td>
					<td>' . round($TotOD3,2). '</td>
					<td>' . round($TotOD4,2). '</td>
					<td>' . round($TotOD5,2). '</td>
					<td>' . round($TotOD6,2). '</td>
					<td>' . round($TotOD7,2). '</td>
					<td>' . $Lastpaid . '</td>
					<td>' . $Lastpaiddate . '</td>
			       <td>' . $retentionBalance . '</td>
				
					</tr>';
		
	
			//$ac[]=	$accountnumber;
				//$cust=$AgedAnalysis['name'];
				
				//$bal[]=$finalbalance;
				//$cur[] = $finalcurrent;
			//	$thirty[]= $final30days;
			//	$sixty[]= $final60days;
			//	$ninety[]= $final90daysplus;
				
				
				// $data_arr[] = array("customer" =>$cust,"account" =>$accountnumber,"bal" =>$finalbalance,"cur" =>$finalcurrent,"thirty" =>$final30days,"sixty" =>$final60days,"ninety" =>$final90daysplus);
		}

	?>
 				<div class="row">
									
<div class="col-sm-4">
<a href="AgedDebtorsReport-customers.php">  <button type="button" name="report" id="report" class="btn btn-success">Back to search other customers</button></a>
	  </div></div>
<?php
echo '</div>



</div>';
}
else{
	
		echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">';
        echo '<div>';
		echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
?>

<td>Select Customer </td>
<td><select name="department" id = "department" >;
							<?php
	
							$SQL = "SELECT *
				                            
		                            FROM debtorsmaster
		                            ";

$result=DB_query($SQL);
//echo '<option value="0">0 - ' . _('None Available') . '</option>';
			echo '<option value="0">' . _('None') . '</option>';
 //echo '<option value="All">' . _('All Department') . '</option>';
	
while ($myrow=DB_fetch_array($result)){
	
			echo '<option value="' . $myrow['debtorno'] . '">' . $myrow['name'].' - ' .$myrow['debtorno'] . '</option>';
	
	
		
	
}
echo '</select>';
		echo '<div class="centre">
				<input type="submit" id= "Print" name="PrintPDF" value="' .
                _('Show All Accounts from selected customer').'" />
			</div>';
        echo '</div>
              </form>';
	
	
	}
	echo '<br /><br /><br />';
	

echo '<div class="row">';
echo '<div class="col-sm-12">';



		echo '<div id= "example-table" >';

echo '</div>';
		
echo '</div></div></div>';
	
	
	?>
						

		
					</div>
				</div>
			</div>
					
					

						<!--end:: Widgets/Stats-->

						<!--Begin::Section-->
						

		<!-- end::Quick Sidebar -->

		<!-- begin::Scroll Top -->
		<div id="m_scroll_top" class="m-scroll-top">
			<i class="la la-arrow-up"></i>
		</div>

		<!-- end::Scroll Top -->

		<!-- begin::Quick Nav -->
		

		<!-- begin::Quick Nav -->
<script src="includes/vendors/owl.carousel/dist/owl.carousel.js" type="text/javascript"></script>

		<!--end::Page Scripts -->
	</body>

	<!-- end::Body -->
</html>
 
      
<?php



/*The module link codes are hard coded in a switch statement below to determine the options to show for each tab */
include('includes/MainMenuLinksArray.php');

if (isset($SupplierLogin) AND $SupplierLogin==1){
	echo '<table class="table_index">
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SupplierTenders.php?TenderType=1">' . _('View or Amend outstanding offers') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SupplierTenders.php?TenderType=2">' . _('Create a new offer') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SupplierTenders.php?TenderType=3">' . _('View any open tenders without an offer') . '</a></p>
			</td>
			</tr>
		</table>';
	include('includes/footer.inc');
	exit;
} elseif (isset($CustomerLogin) AND $CustomerLogin==1){
	echo '<table class="table_index">
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/CustomerInquiry.php?CustomerID=' . $_SESSION['CustomerID'] . '">' . _('Account Status') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SelectOrderItems.php?NewOrder=Yes">' . _('Place An Order') . '</a></p>
			</td>
			</tr>
			<tr>
			<td class="menu_group_item">
				<p>&bull; <a href="' . $RootPath . '/SelectCompletedOrder.php?SelectedCustomer=' . $_SESSION['CustomerID'] . '">' . _('Order Status') . '</a></p>
			</td>
			</tr>
		</table>';

	include('includes/footer.inc');
	exit;
}

if (isset($_GET['Application'])){ /*This is sent by this page (to itself) when the user clicks on a tab */
	$_SESSION['Module'] = $_GET['Application'];
}








//include('includes/footer.inc');

function GetRptLinks($GroupID) {
/*
This function retrieves the reports given a certain group id as defined in /reports/admin/defaults.php
in the acssociative array $ReportGroups[]. It will fetch the reports belonging solely to the group
specified to create a list of links for insertion into a table to choose a report. Two table sections will
be generated, one for standard reports and the other for custom reports.
*/
	global $db, $RootPath, $ReportList;
	require_once('reportwriter/languages/en_US/reports.php');
	require_once('reportwriter/admin/defaults.php');
	$GroupID=$ReportList[$GroupID];
	$Title= array(_('Custom Reports'), _('Standard Reports and Forms'));

	$sql= "SELECT id,
				reporttype,
				defaultreport,
				groupname,
				reportname
			FROM reports
			ORDER BY groupname,
					reportname";
	$Result=DB_query($sql,'','',false,true);
	$ReportList = '';
	while ($Temp = DB_fetch_array($Result)) $ReportList[] = $Temp;

	$RptLinks = '';
	for ($Def=1; $Def>=0; $Def--) {
        $RptLinks .= '<li class="menu_group_headers">';
        $RptLinks .= '<b>' .  $Title[$Def] . '</b>';
        $RptLinks .= '</li>';
		$NoEntries = true;
		if ($ReportList) { // then there are reports to show, show by grouping
			foreach ($ReportList as $Report) {
				if ($Report['groupname']==$GroupID AND $Report['defaultreport']==$Def) {
                    $RptLinks .= '<li class="menu_group_item">';
					$RptLinks .= '<p>&bull; <a href="' . $RootPath . '/reportwriter/ReportMaker.php?action=go&amp;reportid=' . $Report['id'] . '">' . _($Report['reportname']) . '</a></p>';
					$RptLinks .= '</li>';
					$NoEntries = false;
				}
			}
			// now fetch the form groups that are a part of this group (List after reports)
			$NoForms = true;
			foreach ($ReportList as $Report) {
				$Group=explode(':',$Report['groupname']); // break into main group and form group array
				if ($NoForms AND $Group[0]==$GroupID AND $Report['reporttype']=='frm' AND $Report['defaultreport']==$Def) {
                    $RptLinks .= '<li class="menu_group_item">';
					$RptLinks .= '<img src="' . $RootPath . '/css/' . $_SESSION['Theme'] . '/images/folders.gif" width="16" height="13" alt="" />&nbsp;';
					$RptLinks .= '<p>&bull; <a href="' . $RootPath . '/reportwriter/FormMaker.php?id=' . $Report['groupname'] . '"></p>';
					$RptLinks .= $FormGroups[$Report['groupname']] . '</a>';
					$RptLinks .= '</li>';
					$NoForms = false;
					$NoEntries = false;
				}
			}
		}
		if ($NoEntries) $RptLinks .= '<li class="menu_group_item">' . _('There are no reports to show!') . '</li>';
	}
	return $RptLinks;
}
	
?>
<!-- Modal HTML embedded directly into document -->
<div id="ex1" class="modal">
  <p>Thanks for clicking. That felt good.</p>
  <a href="#" rel="modal:close">Close</a>
</div>


<!-- Modal -->
 <div class="modal fade" id="getCodeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog modal-lg">
      <div class="modal-content">
       <div class="modal-header">
         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
         <h4 class="modal-title" id="myModalLabel"> API CODE </h4>
       </div>
       <div class="modal-body" id="getCode" style="overflow-x: scroll;">
       
          
          
       </div>
    </div>
   </div>
 </div>


<script>$(document).ready(function() {
   var table = $('#projectreport').DataTable( {
        dom: 'Bfrtip',
	    order: [[ 3, 'desc' ]],
        buttons: [
           
		{
                extend: 'pdfHtml5',
                orientation: 'landscape',
			pageSize: 'A4',
			
			
                customize: function(doc) {
      doc.defaultStyle.fontSize = 12; //<-- set fontsize to 16 instead of 10 
					  
   }  
            },
			{
                extend: 'excelHtml5'},
			
			{
                extend: 'copyHtml5'}
			
			
		],
	   
	   
	   
	   
    } );
		
		
		 
    $('#projectreport tbody').on('click', 'tr', function () {
        $(this).toggleClass('selected');
		  

		
    } );
		   $('#pdfprint').click( function () {
		   
		   var data = table.row( '.selected' ).data();
			//   window.open('PrintStatements.php?FromCust='+data[0]+'&accountnumber='+data[2]);
			   
   		window.location.href = "PrintStatements.php?FromCust="+data[0]+"&accountnumber="+data[2]+"&department="+data[3];
 
    } );
		   $('#pdfprintinv').click( function () {
		   
		   var data = table.row( '.selected' ).data();
			//   window.open('PrintStatements.php?FromCust='+data[0]+'&accountnumber='+data[2]);
			   
   		window.location.href = "PrintStatementsInvoices.php?FromCust="+data[0]+"&accountnumber="+data[2]+"&department="+data[3];
 
    } );
		 $('#pdfprintall').click( function () {
		   
		   //var data = table.row( '.selected' ).data();
			//   window.open('PrintStatements.php?FromCust='+data[0]+'&accountnumber='+data[2]);
			   
   		window.location.href = "PrintAllStatements.php";
 
    } );
		 $('#email').click( function () {
		   
		   var data = table.row( '.selected' ).data();
			   
			   $.ajax({
      url:'debtors/EmailStatementsSingle.php',
      method:"POST",
      data:{FromCust:data[2]}
		 
	
     }) 

	  

    } );
		
			 $('#trans').click( function () {
		   
		   var data = table.row( '.selected' ).data();
			   
			   $.ajax({
      url:'debtors/OutstandingTrans.php',
      method:"POST",
      data:{FromCust:data[2]},
		 dataType: 'JSON', 
		
      success:function(response)
     {
		  
	  
		 var len = response.length;
            for(var i=0; i<len; i++){
                var Type = response[i].Type;
                var No = response[i].No;
                var Date = response[i].Date;
                var TotalInvoice= response[i].TotalInvoice;
				
				 var Outstanding= response[i].Outstanding;

                var tr_str = "<tr>" +
                  
                    "<td align='center'>" + Type + "</td>" +
                    "<td align='center'>" + No + "</td>" +
                    "<td align='center'>" + Date + "</td>" +
					 "<td align='center'>" + TotalInvoice + "</td>" +
					 "<td align='center'>" + Outstanding + "</td>" +
                    "</tr>";

                $("#userTable tbody").append(tr_str);
            }

		 
    
      }
     }) 

	   $('#modelWindow').modal('show');

    } );
		   
				 $('#alltrans').click( function () {
		   
		   var data = table.row( '.selected' ).data();
			   
			   $.ajax({
      url:'debtors/AllTrans.php',
      method:"POST",
      data:{FromCust:data[2]},
		 dataType: 'JSON', 
		
      success:function(response)
     {
		  
	  
		 var len = response.length;
            for(var i=0; i<len; i++){
                var Type = response[i].Type;
                var No = response[i].No;
                var Date = response[i].Date;
                var TotalInvoice= response[i].TotalInvoice;
				
				 var Outstanding= response[i].Outstanding;

                var tr_str = "<tr>" +
                  
                    "<td align='center'>" + Type + "</td>" +
                    "<td align='center'>" + No + "</td>" +
                    "<td align='center'>" + Date + "</td>" +
					 "<td align='center'>" + TotalInvoice + "</td>" +
					 "<td align='center'>" + Outstanding + "</td>" +
                    "</tr>";

                $("#userTable tbody").append(tr_str);
            }

		 
    
      }
     }) 

	   $('#modelWindow').modal('show');

    } );
		 $('#close').click( function () {
			 
			 $('#userTable tbody').empty();
		 })
		
		 $('#close1').click( function () {
			 
			 $('#userTable tbody').empty();
		 })
} );
	
	</script>
