<?php

	include "library.php";

	$cxn = start_code( true );

	$cxn_common = db_common_login();

	$userid = val( $_SESSION, 'userid' );

    $practice = val( $_SESSION, "logged_in_practice" );
    
    page_header( "Quotes", $cxn );
    
   
	$query = "SELECT * FROM quote WHERE practice = '".$practice."' ORDER BY effective_date DESC";

 	$result = run_query( $query, $cxn );

    if (query_num_rows($result) == 0)
    {
        echo black( "<br><br>You have no quotes to list.<br><br>" );
    }
    else
    {
     	echo "<table width='100%'>";
     	
     	echo "<tr><td width='8%'>".black( "<i>Quote number</i>&nbsp;&nbsp;" )."</td><td width='8%'>".black( "<i>Quote date</i>&nbsp;&nbsp;" )."</td><td width='8%'>".black( "<i>Document type</i>&nbsp;&nbsp;" )."</td><td width='18%'>".black( "<i>Clients</i>&nbsp;&nbsp;" )."</td><td width='8%'>".black( "<i>Amount ex GST</i>" )."</td><td width='8%'>".black( "<i>GST</i>" )."</td><td width='8%'>".black( "<i>Total</i>" )."</td><td width='8%'>".black( "<i>Status</i>" )."</td><td width='35%'>&nbsp;</td></tr>";
    
        echo "<tr><td>&nbsp;</td></tr>";
        
        
    	for ($i=0; $i < query_num_rows($result); $i++)
    	{
    	    $status = "";

    		$data = get_row( $result );

            echo "<tr><td>".$data['id']."</td>";

            echo "<td>".ad_format_date( $data['effective_date'], "dd/mm/yyyy" )."</td>";

            if ($data['task_type'] == "soa")
                $task_type = "SOA";
            else
            if ($data['task_type'] == "roa")
                $task_type = "ROA";
            else
                $task_type = "Other";
                
            echo "<td>".$task_type."</td>";

            echo "<td>".$data['client_names']."</td>";

            echo "<td>".$data['amount_ex_gst']."</td>";

            echo "<td>".number_format( $data['gst'], 2)."</td>";

            echo "<td>".number_format( $data['total'], 2)."</td>";

//            if (substr( $data['gst'], strlen( $data['gst'] )-2, 1 ) == ".")
//               echo "<td>".$data['gst']."0</td>";
//            else    
//                echo "<td>".$data['gst']."</td>";

//            if (substr( $data['total'], strlen( $data['total'] )-2, 1 ) == ".")
//                echo "<td>".$data['total']."0</td>";
//            else
//                echo "<td>".$data['total']."</td>";

            if ($data['status'] == "sent")
                $status = "<span class='ggreen'>Sent</span>";
            else
            if ($data['status'] == "accepted")
                $status = "<span class='ggreen'>Accepted</span>";
            else
                $status = black( sentence_case( $data['status'] ) );

            echo "<td>".$status."</td>";

            if ($data['status'] == "accepted")
                echo "<td>&nbsp;</td>";
            else
                echo "<td>".show_link( "Accept quote", "accept_quote.php", "id", $data['id'] )."</td>";
                
            echo "</tr>";
            
    	}
    	
    	echo "</table>";
    }	
	
?>