<?php

function display_due_payments_filtering_parameters() {
    start_table(TABLESTYLE_NOBORDER);
        start_row();
            supplier_list_cells(_("Supplier: "), 'supplier_id', null, '', true, false);
            date_cells(_("Due Date:"), "due_date");
            submit_cells('RefreshInquiry', _("Search"),'',_('Refresh'), 'default');
        end_row();
    end_table(1);

    set_global_supplier($_POST['supplier_id']);
}

function display_due_payment_view_opening_balance($supplier_id, $due_date) {
    $balance = get_due_payment_view_opening_balance($supplier_id, $due_date);
    
    	start_row();
            label_cell(text_bold("Opening Balance"), 'align=left colspan=9');
            amount_cell($balance, true);
	end_row();
        
        return $balance;
}

function display_due_payments_view_details($supplier_id, $due_date_) {
    global $systypes_array;
    
    $due_date = date2sql($due_date_);
    
    start_table(TABLESTYLE, "width=98%");

        $th = array(_("Tran Date"), _("Type"), _("Trans #"), _("Reference"), _("Supplier"), _("Amount"), _("Paid Amount"), _("Balance"), _("Due. Date"), 
                    _("Current Outstanding"), _("Total Outstanding"));

        table_header($th);
        
            $total_outstanding = $op_balance = display_due_payment_view_opening_balance($supplier_id, $due_date);

            $k = $current_outstanding = 0;
            $result = get_due_payment_view_transactions($supplier_id, $due_date);
                while ($trans = db_fetch($result)) {
                    alt_table_row_color($k);	
                        label_cell(sql2date($trans['tran_date']), 'align=center');
                        label_cell($systypes_array[$trans['type']]);
                        $link = get_trans_view_str($trans['type'], $trans['trans_no']);
                        label_cell($link, 'align=center');
                        label_cell($trans['reference']);
                        label_cell(get_supplier_formatted_name($trans['supplier_id']));

                        $amount = ($trans['ov_amount'] + $trans['ov_gst']); 
                        $paid_amount = $trans['alloc'];
                        amount_cell($amount);
                        amount_cell($paid_amount);
                        
                        $balance = $amount - $paid_amount;
                        amount_cell($balance);
                        label_cell(sql2date($trans['due_date_u']), 'align=center');

                        $current_outstanding += $balance;
                        $total_outstanding += $balance;

                        amount_cell($current_outstanding);
                        amount_cell($total_outstanding);
                    end_row();
                }

    end_table(2);
}

?>