<?php
ob_start();
include('includes/session.inc');
$Title = _('Banking Batch');
include('includes/SQL_CommonFunctions.inc');
error_reporting(E_ALL);
?> 


      <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>


<?php

	
//collect reasons for cancelation


					$userid = $_SESSION['UserID'];

include('includes/newheader.php');
echo '<p> </p> <p></p><p class="page_title_text"><img alt="" src="'.$RootPath.'/css/'.$Theme.
		'/images/printer.png" title="' .// Icon image.
		_('Reasons for Cancellation .  ') . '" /> ' .// Icon title.
		_('Please this process needs to be done by the Finance Team in charge of banking') . '</p>';// Page title.
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';
	echo '<div class="col-sm-12">';// div class=?
	echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<table id= "firsttable" class="table">';

	echo '<tr>

		<td>' . _('Date when it will be banked') . ':</td>';

echo '<td>   <input  type="text" name="order_date" id="datepicker"  placeholder="" required = "required" /></td>

      </tr>';
$SQL = "SELECT bankaccountname,
				bankaccounts.accountcode,
				bankaccounts.bankaccountnumber,
				bankaccounts.bank_name
		FROM bankaccounts
				
		ORDER BY bankaccountname";

$ErrMsg = _('The bank accounts could not be retrieved because');
$DbgMsg = _('The SQL used to retrieve the bank accounts was');
$AccountsResults = DB_query($SQL,$ErrMsg,$DbgMsg);


echo '
	<tr>
		<td>' . _('Bank Account') . ':</td>
		 <td><select tabindex="1" autofocus="autofocus" name="BankAccount" onchange="ReloadForm(form1.BatchInput)" required = "required">';


	echo '<option value="">Select Bank Account</option>';
	while ($myrow=DB_fetch_array($AccountsResults)){
		/*list the bank account names */
	
			echo '<option value="' . $myrow['accountcode'] . '">' . $myrow['bankaccountnumber'].'-'. $myrow['bankaccountname']. ' - ' . $myrow['bank_name'] . '</option>';
		
	}
	echo '</select></td>
		</tr>';

echo '<tr>
			<td>' ._('Reference'). ':</td>
			<td><input tabindex="'.$j.'" type="text" maxlength="200" size="50" required="required" name="reason"  /></td>
		</tr></table>';


?><div class="table-responsive">
 <table id="invoice-item-table" class="table ">
 <thead> 
                    <tr>

                      <th>Receipt No:</th>
						

                      <th>Tran Date</th>
					  

                      <th>Customer</th>
						<th>A/c No</th>

                      <th>Payment Method</th>

                     <th>Amount</th>
						 <th >Drawers Bank/Branch</th>
						 <th >Drawers Account Number</th>
						<th >Drawers Cheque Number</th>
						<th >Reference</th>

                      <th></th>

                    </tr>

                    <tr>

                      <th></th>

                      <th></th>

                      <th></th>

                      <th></th>

                      <th></th>
						 <th></th>

                      <th></th>

                      <th></th>
                        <th></th>
                  
                      <th></th>
                    
                 <thead>    </tr>

                  
<?php

										$sqlbalances="SELECT debtortrans.transno, debtortrans.trandate,debtortrans.account_number, debtortrans.ovamount,debtortrans.payment_method,debtortrans.reference,debtortrans.drawer_bank,debtortrans.drawer_accountnumber,debtortrans.drawer_chqnumber,debtorsmaster.name
					FROM debtortrans
					INNER JOIN debtorsmaster on debtorsmaster.debtorno = debtortrans.debtorno
					WHERE debtortrans.type = 12
					AND debtortrans.receipt_banked = 0
					ORDER By debtortrans.transno DESC 
					";
		$resultfromdebtoraccount =DB_query($sqlbalances);
	 
	 $cashtotal = 0;
	 $chequetotal =0;
	 $count =0;
while ($myrowfromdebtoraccount = DB_fetch_array($resultfromdebtoraccount)){


	if ($myrowfromdebtoraccount['payment_method'] == "Cheque" ) {
	
          		
          		echo 		
					'<tr id= "row_id_' . $count . '" ><td>' . $myrowfromdebtoraccount['transno'].'<input type="hidden" name="transno[]" value="'.$myrowfromdebtoraccount['transno'].'"/></td>
					 
					
							
					<td>' . $myrowfromdebtoraccount['trandate']. '<input type="hidden" name="trandate[]" value="'.$myrowfromdebtoraccount['trandate'].'"/></td>
					<td>' . $myrowfromdebtoraccount['name']. '<input type="hidden" name="name[]" value="'.$myrowfromdebtoraccount['name'].'"/></td>
					<td>' . $myrowfromdebtoraccount['account_number']. '<input type="hidden" name="account_number[]"value="'.$myrowfromdebtoraccount['account_number'].'" /></td>
					<td>' . $myrowfromdebtoraccount['payment_method']. '<input type="hidden" name="payment_method[]" value="'.$myrowfromdebtoraccount['payment_method'].'"/></td>
					<td>' . -$myrowfromdebtoraccount['ovamount']. '<input type="hidden" name="ovamount[]" value="'.$myrowfromdebtoraccount['ovamount'].'"/></td>
					<td><input type="text" name="drawer_bank[]" value="'.$myrowfromdebtoraccount['drawer_bank'].'"  /></td>
					<td><input type="text" name="drawer_accountnumber[]" value="'.$myrowfromdebtoraccount['drawer_accountnumber'].'"  /></td>
					<td><input type="text" name="drawer_chqnumber[]"  value="'.$myrowfromdebtoraccount['drawer_chqnumber'].'" /></td>
					<td><input type="text" name="reference[]"  value="'.$myrowfromdebtoraccount['reference'].'" /></td>
			      <td><button type="button" name="remove_row" id="'.$count.'"class="btn btn-danger btn-xs remove_row">X</button></td>
				
					</tr>';
		
		
		$chequetotal += $myrowfromdebtoraccount['ovamount'];
		
			$u = $myrowfromdebtoraccount['ovamount'];
			
			echo '<input type="hidden" name="chqt" id="chqt" value="'.$u.'" />';
		$count++;
	}
	
		
		if ($myrowfromdebtoraccount['payment_method'] == "Cash" ) {
	
          		echo 		
					'<tr id= "row_id_' . $count . '" ><td>' . $myrowfromdebtoraccount['transno'].'<input type="hidden" name="transno[]" value="'.$myrowfromdebtoraccount['transno'].'"/></td>
					 
					
							
							
					<td>' . $myrowfromdebtoraccount['trandate']. '<input type="hidden" name="trandate[]" value="'.$myrowfromdebtoraccount['trandate'].'"/></td>
					<td>' . $myrowfromdebtoraccount['name']. '<input type="hidden" name="name[]" value="'.$myrowfromdebtoraccount['name'].'"/></td>
					<td>' . $myrowfromdebtoraccount['account_number']. '<input type="hidden" name="account_number[]"value="'.$myrowfromdebtoraccount['account_number'].'" /></td>
					<td>' . $myrowfromdebtoraccount['payment_method']. '<input type="hidden" name="payment_method[]" value="'.$myrowfromdebtoraccount['payment_method'].'"/></td>
					<td>' . -$myrowfromdebtoraccount['ovamount']. '<input type="hidden" name="ovamount[]" value="'.$myrowfromdebtoraccount['ovamount'].'"/></td>
					<td><input type="text" name="drawer_bank[]"  /></td>
					<td><input type="text" name="drawer_accountnumber[]"   /></td>
					<td><input type="text" name="drawer_chqnumber[]"   /></td>
					<td><input type="text" name="reference[]"  value="'.$myrowfromdebtoraccount['reference'].'" /></td>
					
			       <td><button type="button" name="remove_row" id="'.$count.'"class="btn btn-danger btn-xs remove_row">X</button></td>
				
					</tr>';

		$cashtotal += $myrowfromdebtoraccount['ovamount'];
			
			$t = $myrowfromdebtoraccount['ovamount'];
			
			echo '<input type="hidden" name="casht" id="casht" value="'.$t.'" />';
			$count++;
		}
	
		
	
	
			//$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);
		}
				?>						
				

                  </table>




<?php



echo '</br>
<input type="hidden" name="total_item" id="total_item" value="'.$count.'" />
<input type="hidden" name="receiptno" />
      <input type="submit" name="process" id="process" value="' ._('Process & Print Banking batch-PDF') . '" />
		 <input type="submit" name="excelbank" id="excelbank" value="' ._('Process & Print Banking batch-Excel') . '" />
		';



echo '</div> </form>';

echo '</div>';

$reasons = $_POST['reason'];

$sqldate= FormatDateForSQL(DB_escape_string($_POST['order_date'] ));

$bankedinto =$_POST["BankAccount"];



if (isset($_POST['process']) ){
	
	
		
	$SQL= "SELECT bank_name,
	           bankaccountname,
				bankaccountnumber
			FROM bankaccounts 
			WHERE accountcode='" . $bankedinto. "'
			";

	$ErrMsg = _('An error occurred getting the header information about the receipt batch number') ;
	$DbgMsg = _('The SQL used to get the receipt header information that failed was');
	$Result=DB_query($SQL,$ErrMsg,$DbgMsg);


	/* OK get the row of receipt batch header info from the BankTrans table */
	$myrow = DB_fetch_array($Result);
	
	$bankname = $myrow['bank_name'];
	$bankaccountname = $myrow['bankaccountname'];
	$bankaccountnumber= $myrow['bankaccountnumber'];
	
	
	

		include('includes/PDFStarter.php');

	/*PDFStarter.php has all the variables for page size and width set up depending on the users default preferences for paper size */

	$pdf->addInfo('Title',_('Banking Summary'));
	$pdf->addInfo('Subject',_('Banking Summary Number') . ' ' . $_POST['BatchNo']);
	$line_height=12;
	$PageNumber = 0;
	
	$cashdeposit = 0;
	$cheqdeposit = 0;
	$TotalBanked = 0;
 $subtotalonchqaccount=0;
	include ('includes/PDFBankingSummaryPageHeader.inc');
	
	 for($count=0; $count<$_POST["total_item"]; $count++) {
	//before canceling this invoice unallocate invoices if there are any allocations
		 
		 
		 $sqlbalances1="SELECT debtortrans.transno, debtortrans.trandate,debtortrans.account_number, debtortrans.ovamount,debtortrans.payment_method,debtorsmaster.name
					FROM debtortrans
					INNER JOIN debtorsmaster on debtorsmaster.debtorno = debtortrans.debtorno
					WHERE debtortrans.type = 12
					AND debtortrans.transno = '" . $_POST["transno"][$count]. "'
					
					";
		$resultfromdebtoraccount1 =DB_query($sqlbalances1);
	$myrowfromdebtoraccount1 = DB_fetch_array($resultfromdebtoraccount1);
		 
		 
	
			 
			 
			
			 
			 
		 //update database

		
		 if ($_POST["payment_method"][$count] == "Cheque"){
			 
			 
			 
										
			 	  	 //display pdf 
			 
			 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,-(locale_number_format($_POST["ovamount"][$count],2)), 'right');
		$LeftOvers = $pdf->addTextWrap($Left_Margin+65,$YPos,250,$FontSize,$myrowfromdebtoraccount1['name']. ' A/C: '.$myrowfromdebtoraccount1['account_number']. ' Type: '.$_POST["payment_method"][$count] , 'left');
		$LeftOvers = $pdf->addTextWrap($Left_Margin+355,$YPos,150,$FontSize,$_POST["drawer_bank"][$count]._('-') .$_POST["drawer_accountnumber"][$count], 'left');
		$LeftOvers = $pdf->addTextWrap($Left_Margin+440,$YPos,150,$FontSize,'Chq No: '.$_POST["drawer_chqnumber"][$count], 'left');
	
			 
		$SQL="INSERT INTO banktrans (type,
								transno,
								client_account_number,
								bankact,
								ref,
								exrate,
								
								transdate,
								banktranstype,
								amount,
								currcode,
								drawer_bank,
								drawer_accountnumber,
								drawer_chqnumber,
								drawer_chqdate
								)
		VALUES (
			12,
			'" . $_POST["transno"][$count]. "',
			'" . $_POST["account_number"][$count]. "',
			'" . $_POST["BankAccount"]. "',
			'" . trim($_POST["reason"]). "',
			'1',
			
			'" .$sqldate . "',
			'" .$_POST["payment_method"][$count]. "',
			'" . -$_POST["ovamount"][$count] . "',
			'FJD',
			'" . trim($_POST["drawer_bank"][$count]). "',
			'" . trim($_POST["drawer_accountnumber"][$count]). "',
			'" . trim($_POST["drawer_chqnumber"][$count]). "',
			'" . trim($_POST["drawer_chqdate"][$count]). "'
		)";
	$DbgMsg = _('The SQL that failed to insert the bank account transaction was');
	$ErrMsg = _('Cannot insert a bank transaction');
	$result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
			 
			 
			 $cheqdeposit += $_POST["ovamount"][$count];
			 
			 $oldacc= $myrowfromdebtoraccount1['account_number'];
			 
			

		 }
		  	 if ($_POST["payment_method"][$count] == "Cash"){
				 
				 
				 	  	 //display pdf 
			 
			 $LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,-(locale_number_format($_POST["ovamount"][$count],2)), 'right');
		$LeftOvers = $pdf->addTextWrap($Left_Margin+65,$YPos,250,$FontSize,$myrowfromdebtoraccount1['name']. ' A/C: '.$myrowfromdebtoraccount1['account_number']. ' Type: '.$_POST["payment_method"][$count] , 'left');
	//	$LeftOvers = $pdf->addTextWrap($Left_Margin+215,$YPos,300,$FontSize,_('Bank: ').trim($_POST["drawer_bank"][$count])._('-') .trim($_POST["drawer_accountnumber"][$count]), 'left');
		//$LeftOvers = $pdf->addTextWrap($Left_Margin+400,$YPos,200,$FontSize,'Chq No: '.trim($_POST["drawer_chqnumber"][$count]), 'left');
				 
		 
		$SQL="INSERT INTO banktrans (type,
								transno,
								client_account_number,
								bankact,
								ref,
								exrate,
								
								transdate,
								banktranstype,
								amount,
								currcode
								)
		VALUES (
			12,
				'" . $_POST["transno"][$count]. "',
			'" . $_POST["account_number"][$count]. "',
			'" . $_POST["BankAccount"]. "',
			'" . trim($_POST["reason"]). "',
			'1',
			
				'" .$sqldate . "',
			'" .$_POST["payment_method"][$count]. "',
			'" . -$_POST["ovamount"][$count] . "',
			'FJD'
		)";
	$DbgMsg = _('The SQL that failed to insert the bank account transaction was');
	$ErrMsg = _('Cannot insert a bank transaction');
	$result = DB_query($SQL,$ErrMsg,$DbgMsg,true);
				 
				  $cashdeposit += $_POST["ovamount"][$count];

		 }
		
	$sql4012 =  "UPDATE debtortrans set receipt_banked = '1'
				WHERE transno = '" . $_POST["transno"][$count]. "'
				AND type = 12
				";

	$ErrMsg = _('This customer could not be added because');
			$result4012 = DB_query($sql4012,$ErrMsg);
	
	
		 
		
		 
		 
     //  $ListCount ++;

				



		$YPos -= $line_height;// Increment a line down for the next line item.

		 
		if ($YPos - (2 *$line_height) < $Bottom_Margin){
			/*Then set up a new page */
			include ('includes/PDFBankingSummaryPageHeader.inc');
		} /*end of new page header  */
		 

	 }
			
		 $TotalBanked = $cheqdeposit + $cashdeposit;
	
	
	$YPos-=$line_height;
	/*draw a line */
$pdf->line($XPos, $YPos,$Page_Width-$Right_Margin, $YPos);
	//$LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,_('---------------------'), 'right');
		$YPos-=$line_height;
	$LeftOvers = $pdf->addTextWrap($Left_Margin,$YPos,60,$FontSize,_('$').-(locale_number_format($TotalBanked,2)), 'right');
	$LeftOvers = $pdf->addTextWrap($Left_Margin+65,$YPos,300,$FontSize,_('TOTAL Banked (cash:')._('$').-$cashdeposit.', Cheque:'._('$').-$cheqdeposit . ')', 'left');
	
	//$pdf->line($XPos, $Bottom_Margin,$XPos, $YPos);
	
$pdf->addTextWrap($Left_Margin+230,$Bottom_Margin-10,300,$FontSize,_('Powered by E-Business ERP 2.0'), 'left');
	//$pdf->OutputD($_SESSION['DatabaseName'] . '_BankingSummary_' . date('Y-m-d').'.pdf');
	
ob_end_clean();
		$pdf->OutputD('Banking_summary_wormald_' . $bankname . date('d-m-Y').'.pdf');
	$pdf->__destruct();
	
	unset($_POST['order_date']);
	unset($_POST['BankAccount']);
	unset($_POST['reason']);
	
}

if (isset($_POST['excelbank'])) {
	
	
	
	
if (PHP_SAPI == 'cli')
	die('This example should only be run from a Web Browser');

/** Include PHPExcel */
//include_once('Classes/PHPExcel.php');


include_once('Classes/PHPExcel/IOFactory.php');

$inputFileName = 'printing/wormaldbanking.xlsx';
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory;
PHPExcel_Settings::setCacheStorageMethod($cacheMethod);


/*check point*/

// Read the existing excel file
//$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(false);
$objPHPExcel = $objReader->load($inputFileName);
	
	$empty = '';
	
	  $objPHPExcel->getActiveSheet()->setCellValue('D3', $empty );
		$objPHPExcel->getActiveSheet()->setCellValue('D4',  $empty );
		$objPHPExcel->getActiveSheet()->setCellValue('D5', $empty );
		$objPHPExcel->getActiveSheet()->setCellValue('D6', $empty );
	
	$cellcount = 9;	
	
	$lastrecord= $cellcount + $_POST["total_item"];
	
while ($cellcount < 500 ) {
	
		
	
		
		
	
		
	    $objPHPExcel->getActiveSheet()->setCellValue('A'.$cellcount, $empty);
		
		$objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount, $empty);
		$objPHPExcel->getActiveSheet()->setCellValue('C'.$cellcount, $empty);
		$objPHPExcel->getActiveSheet()->setCellValue('D'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('E'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('F'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('G'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('H'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('I'.$cellcount, $empty);
	$objPHPExcel->getActiveSheet()->setCellValue('J'.$cellcount, $empty);
	
		$cellcount++;
		
			
	
	
}
	
	
//now write to this
	$SQL = "SELECT 
				bankaccounts.bankaccountnumber,
				bankaccounts.bank_name
		FROM bankaccounts
				
		WHERE accountcode ='" . $_POST["BankAccount"]. "'";

$ErrMsg = _('The bank accounts could not be retrieved because');
$DbgMsg = _('The SQL used to retrieve the bank accounts was');
$bank = DB_query($SQL,$ErrMsg,$DbgMsg);
	$myrow = DB_fetch_array($bank);
	
	
        $objPHPExcel->getActiveSheet()->setCellValue('D3', $_POST['order_date']);
		$objPHPExcel->getActiveSheet()->setCellValue('D4', $myrow['bank_name']);
		$objPHPExcel->getActiveSheet()->setCellValue('D5', $myrow['bankaccountnumber']);
		$objPHPExcel->getActiveSheet()->setCellValue('D6', 'Evergreen Int(Fiji) Ltd');
	
	
	$count=0;
	
 for($cellcount=9; $cellcount < 500; $cellcount++) {
	//before canceling this invoice unallocate invoices if there are any allocations
		 
		 
		 $sqlbalances1="SELECT debtortrans.transno, debtortrans.trandate,debtortrans.account_number, debtortrans.ovamount,debtortrans.payment_method,debtortrans.reference,debtorsmaster.name
					FROM debtortrans
					INNER JOIN debtorsmaster on debtorsmaster.debtorno = debtortrans.debtorno
					WHERE debtortrans.type = 12
					AND debtortrans.transno = '" . $_POST["transno"][$count]. "'
					
					";
		$resultfromdebtoraccount1 =DB_query($sqlbalances1);
	$myrowfromdebtoraccount1 = DB_fetch_array($resultfromdebtoraccount1);
		 
	  
			  $objPHPExcel->getActiveSheet()->setCellValue('A'.$cellcount,$myrowfromdebtoraccount1["transno"]);
			   $objPHPExcel->getActiveSheet()->setCellValue('B'.$cellcount,$myrowfromdebtoraccount1["trandate"]);
			 
	          $objPHPExcel->getActiveSheet()->setCellValue('C'.$cellcount,$myrowfromdebtoraccount1["name"]);
			   $objPHPExcel->getActiveSheet()->setCellValue('D'.$cellcount,$myrowfromdebtoraccount1["account_number"]);
	 $objPHPExcel->getActiveSheet()->setCellValue('E'.$cellcount,$myrowfromdebtoraccount1["payment_method"]);
			   $objPHPExcel->getActiveSheet()->setCellValue('F'.$cellcount,-$_POST["ovamount"][$count]);
	 $objPHPExcel->getActiveSheet()->setCellValue('G'.$cellcount,$_POST["drawer_bank"][$count]);
			   $objPHPExcel->getActiveSheet()->setCellValue('H'.$cellcount,$_POST["drawer_accountnumber"][$count]);
	 $objPHPExcel->getActiveSheet()->setCellValue('I'.$cellcount,$_POST["drawer_chqnumber"][$count]);
			
	  $objPHPExcel->getActiveSheet()->setCellValue('J'.$cellcount,$_POST["reference"][$count]);
		
	
	 
	 
	 
	 
	 
	
	 	$cellcount++;
		 
	$count++;
}
	
	
	
		

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//$objWriter->save($inputFileName);
$objWriter->save($inputFileName);


    
    //<?php
	
echo '<br /><p></p><p></p> <p></p> <p></p> <p></p>  <p class="page_title_text"><a href="' . $inputFileName . '">' . _('File generated o.k. Click to view this  excel File ') . '</p>';




//echo $AccountCode;



$objPHPExcel->disconnectWorksheets();
unset($objPHPExcel);
			
		

}
		
			    
		
	


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

?>

  <script>


  $( function() {

    $( "#datepicker" ).datepicker({

    dateFormat: 'dd/mm/yy',//check change

    changeMonth: true,

    changeYear: true

});

  } );

	  

 
 

	  jQuery(document).ready(function($){
		  
		  
		  
		  
		  $(document).on('click', '.remove_row', function(){

          var row_id = $(this).attr("id");

        
          $('#row_id_'+row_id).remove();
			  
			  var counttotal =  $('#total_item').val();

         counttotal --;

          $('#total_item').val(counttotal);
			  
			  
			  
        });

		   $('#process').click(function(){

          


			

			$('#process').hide();
			   
			  



        });
		  
		  var table = $('#invoice-item-table1').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'}
			
			
		],
	   
	   
	   
	   
    } );
		
		
		  
		  
		  
		  	 });
	  
	  

  </script>	
