<?php
/**********************************************************************
***********************************************************************/
  
function display_unallocated_suppler_payments_and_credit_notes($supplier_id, $settled = false)
{
    if(!($supplier_id > 0)){
        $supplier_id = -99;
    }
    $sql = get_allocatable_from_supp_sql($supplier_id, $settled);
    
    $result = db_query($sql, "Could not display_unallocated_suppler_payments_and_credit_notes");
    if(!(db_num_rows($result) > 0)){
        return;
    }
    
    start_table(TABLESTYLE, "width=90%");
    
    $th = array(_("Transaction Type"), _("#"), "Supplier Ref", "Date", "Currency",
	"Total", "Other Allocations", "Left to Allocate","Due Date", "PO#", "Comment", '');
    
    	table_header($th);
        
    global $systypes_array;
    $k = 0;
    
    while ($myrow = db_fetch($result)){
        alt_table_row_color($k);

        label_cell($systypes_array[$myrow['type']]);
        
        $s = get_trans_view_str($myrow["type"], $myrow["trans_no"]);
        label_cell($s);
        label_cell($myrow['reference']);
        label_cell(sql2date($myrow['tran_date']), "align=center");
        label_cell($myrow['curr_code']);
        amount_decimal_cell(-$myrow['Total']);
        
//        amount_decimal_cell($myrow['alloc']);
        $parameters = "type=".$myrow['type']."&trans_no=".$myrow["trans_no"];
        $amount_link = get_data_view_str(DV_SUPPLIER_ALLOCATIONS_FROM, $parameters, number_format($myrow['alloc'],2));
        label_cell($amount_link, "align=right");
                    
        amount_decimal_cell((-$myrow["Total"]-$myrow["alloc"]));
        
        label_cell(sql2date($myrow['due_date']), "align=center");
        
        $comment_q = get_comments($myrow["type"], $myrow["trans_no"]);
        $comment = db_fetch($comment_q);
        
        if($myrow['po_no'] > 0){
            $po_link = get_supplier_trans_view_str(ST_PURCHORDER, $myrow["po_no"]);
            label_cell($po_link, "align=center");
        }
        else{
            label_cell("");
        }
        
        label_cell($comment['memo_']);

        $alloc_link = pager_link(_("Allocate"), "/purchasing/allocations/supplier_allocate.php?trans_no="
                                        .$myrow["trans_no"] . "&trans_type=" . $myrow["type"], ICON_ALLOC);
        
        label_cell($alloc_link);
        
        end_row();        
    }
    
    
    end_table(1);
    
}



?>