<?php 
	
	include ('includes/db1config.php');
	include ('../includes/mysql_connect.php');

    $query = "SELECT * FROM customer_invoices where customer_id = ".$_POST['id']." && master_record = 1 ORDER BY recordkey DESC";
	$rt    = mysql_query($query); // query executed

	echo mysql_error(); // if any error is there that will be printed to the screen
   
    $str = '<center>
            <tr>
                <td colspan="2" style="text-align:center";>
                    <a style="float: right;margin-top: 10px;width: 150px;" class="popup add-menu-item" id="save-button" data-user-id="'.$_POST['id'].'" data-popup-id="add">Add Invoice</a>
                </td>
                <td></td>
            </tr>
            <table width=100% cellpadding=5 cellspacing=5 id="invoiceTable" >
            <tr>
                <td>
                    <strong>Invoice Number</strong>
                </td>
                <td>
                    <strong>Invoice Total</strong>
                </td>
                <td>
                    <strong>Invoice Date</strong>
                </td>
                <td>
                    <strong>Due Date</strong>
                </td>
                <td>
                    <strong>Status</strong>
                </td>
                <td>
                    <!--<strong>One Time / Recurring </strong>--><strong>One Time / Recurring </strong>
                </td>
                <td style="width: 35%;" >
                    <strong>Action(s)</strong>
                </td>
                
            </tr>
            <tr class="appendInvoice">
                <td colspan="8"><hr /></td>
            </tr>';
            while ( $row = mysql_fetch_array($rt)) {
                    
                    if( $row['paid'] == 1 ){
                        $status= 'Paid';
                        $btn    = '';
                    } else {
                        $status = 'Un-Paid';
                        $btn    = '&nbsp;<a style="width:50px;" class="SendInvoiceinMail" id="save-button"  data-user-id="'.$row['recordkey'].'" data-custid="'.$_POST['id'].'" data-invno="'.$row['invoice_number'].'" >Send an email</a>';
                    } 

                    if( $row['recurring'] == 1 ){
                        $recurring = 'Recurring';
                    } else {
                        $recurring = 'One Time';
                    } 

                    $str.='<tr>
                            <td width=10%>' . $row['invoice_number'] . '</td>
                            <td width=10%>' . $row['invoice_total'] . '</td>
                            <td width=10%>' . $row['invoice_date'] . '</td>
                            <td width=10%>' . $row['due_date'] . '</td>
                            <td width=10%>' . $status . ' </td>
                            <td width=10%>' . $recurring . ' </td>
                            <td style="padding:4px 4px;" width=25%>
                            <a style="width:50px;" class="popup add-menu-item" id="save-button" data-user-id="'.$row['recordkey'].'" data-custid="'.$_POST['id'].'" data-popup-id="edit">View / Edit</a>&nbsp;<a style="width:50px;" class="deletemaster" id="save-button"  data-user-id="'.$row['recordkey'].'" data-custid="'.$_POST['id'].'" data-invno="'.$row['invoice_number'].'" >Delete</a>'.$btn.'
                            </td>
                        </tr>';
            }

            $str.='<tr>
                    <td colspan="4"></td>
                </tr>
                
            </table>
            </table>
            </center>';
    echo $str;
?>