<?php
include("../include/session.php");

$userId = $_SESSION['username'];
date_default_timezone_set('Africa/Gaborone');
$entry_date = date("Y-m-d H:i:s"); 


$table_name = $_SESSION['db_prefix']."_compiled_jobs";
$update_query = "UPDATE $table_name SET  invoiced='yes', invoice_no='".$_SESSION['invoice_no']."',  invoice_date='".$_SESSION['invoice_date']."'  WHERE job_card_no = '".$_SESSION['job_card_no']."' ";
execsql($update_query);
	

$table_name = $_SESSION['db_prefix']."_invoices";
$inspection_query = "INSERT INTO $table_name (job_card_no, cust_id, invoice_amount, invoice_no, invoice_date, invoiced_by) VALUES ('".$_SESSION['job_card_no']."', '".$_SESSION['cust_id']."', '".$_SESSION['invoice_amount']."', '".$_SESSION['invoice_no']."', '".$_SESSION['invoice_date']."', '".$_SESSION['invoiced_by']."') ";
execsql($inspection_query);

$table_name6 = $_SESSION['db_prefix']."_order_history";
$history_query = "INSERT INTO $table_name6 (job_card_number, note_date, note_text, user_name ) VALUES ('".$_SESSION['job_card_no']."', '".$entry_date."', 'Job invoiced on invoice no ".$_SESSION['invoice_no'].", date: ".date("d-m-Y", strtotime($_SESSION['invoice_date']))." by ".$_SESSION['invoiced_by'].".', '".$_SESSION['username']."' ) ";
	execsql($history_query);


$table_name = $_SESSION['db_prefix']."_tracking_orders";
$trackingQuery = "INSERT INTO $table_name (entry_date, user_name, action, details_1, details_2, details_3, details_4) VALUES ('".$entry_date."' ,'".$_SESSION['username']."', '93', '".$_SESSION['job_card_no']."', '' ,'".$_SESSION['invoiced_by']."', '".$_SESSION['invoice_no']."' )";
$trackingResult = mySQL_query($trackingQuery);

include('../include/order_invoiced_alert.php');
	
	
$job_card_no = $_SESSION['job_card_no'];
$invoice_no = $_SESSION['invoice_no'];


$_SESSION['job_card_no']="";
$_SESSION['job_card_no']='';
$_SESSION['name']="";
$_SESSION['cust_id']='';

$_SESSION['invoice_amount']='';
$_SESSION['invoice_no']='';
$_SESSION['invoiced_by']='';
$_SESSION['invoice_date']=date("Y-m-d");
$_SESSION['invoice_notes']='';

?>

<script language="javascript" type="text/javascript">
        
		  window.location="invoice_report.php?job_card_no=<?php echo $job_card_no ?>&invoice_no=<?php echo $invoice_no ?> " ;
        
       </script>

