<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_UTILITY_BILL_CREDIT_NOTE_VIEW';
$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/gl/includes/db/utility_bill_credit_note_inquiry_db.inc");


$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
page(_($help_context = "View Utility Bill Credit Note"), true, false, "", $js);

//-------------------------------------------------------------------------------------------------
$woid = 0;
if ($_GET['trans_no'] != "")
{
    $utility_bill_id = $_GET['trans_no'];
}

display_heading("Utility Bill Credit Note No: " . $utility_bill_id);


start_table(TABLESTYLE2, "width=60%");

$ubcnh = view_utiltiy_bill_cn($utility_bill_id);

start_row();
label_cells("Reference", $ubcnh['reference'], "class='tableheader2'");
end_row();

label_cells(_("Project"), $ubcnh['project_name'], "class='tableheader2'");
end_row();

label_cells(_("Supplier"), $ubcnh['supp_name'], "class='tableheader2'");
end_row();

label_cells(_("Date"), sql2date($ubcnh['date']), "class='tableheader2'");
end_row();

if($ubcnh['rate_include_taxes'] == 1){
    $rate_include_tax = "Yes";
}else{
    $rate_include_tax = "No";
}
label_cells(_("Rate Include Taxes"), $rate_include_tax, "class='tableheader2'");
end_row();

label_cells(_("Tax Group"), $ubcnh['tax_group_name'], "class='tableheader2'");
end_row();

label_cells(_("Taxes"), $ubcnh['taxes'], "class='tableheader2'");
end_row();

label_cells(_("Total"), $ubcnh['total'], "class='tableheader2'");
end_row();

$s = get_project_trans_view_str(ST_APPROVAL_LOG, $utility_bill_id."&source_type_id=".ST_UTILITY_BILL_CREDIT_NOTE, "Approval Status");
label_cells($s,$approval_statuses[$ubcnh['approval_status']], "class='tableheader2'");
end_row();

end_table(2);

//--------------------------------------------------------------------------------------------------

start_table(TABLESTYLE2, "width=80%");

display_heading("Details");

$result = view_utility_bill_cn_details($utility_bill_id);

$th = array(_("Bill NO"),_("Bill Reference"), _('Description'),
            _("Period From"),_("Period To"),_('Amount'), _("Budeget")/*,_("Expense Type")*/);  
                          

    table_header($th);
    $k = $utility_bill_total = 0; //row colour counter
   // $total = 0;

while($row_b = db_fetch($result)){
    
    alt_table_row_color($k);
     
    label_cell($row_b['bill_no']);
    label_cell($row_b['bill_reference']);
    label_cell($row_b['description']);
    
    
    label_cell(sql2date($row_b['period_from']), "align=center");
    label_cell(sql2date($row_b['period_to']), "align=center");
    
    $line_total = $row_b['amount'];
    label_cell(number_format($line_total, 2), "align=right");
    
    label_cell($row_b['task_description']);
//    label_cell($row_b['expense_description']);
    
    end_row();
    
    $utility_bill_total += $line_total;
    $k++;
}

start_row();
label_cell("Total", "colspan=5 align=right");
label_cell(number_format($utility_bill_total, 2), "align=right");
label_cell("");

end_row();

end_table(1);

//--------------------------------------------------------------------------------------------------

display_heading("Taxes");

start_table(TABLESTYLE2, "width=30%");


start_table(TABLESTYLE2, "width=30%");
    start_row();
        label_cells("Amount Total:", $ubcnh['total'], "class='tableheader2'", "align=right");
 
$tax_result = view_utility_bill_cn_taxes($utility_bill_id);

while($tax_row = db_fetch($tax_result)){
  
    start_row();   
        label_cells($tax_row['tax_type_name']."(".$tax_row['rate']."%)", $tax_row['amount'], "class='tableheader2'", "align=right");  
    end_row(); 
      
}

   start_row();
        label_cells("Taxes Total:", $ubcnh['taxes'], "class='tableheader2'", "align=right");
        
   
end_table();             

br(2);

$final_total = $ubcnh['total'] + $ubcnh['taxes'];
display_allocations_from(PT_SUPPLIER, $ubcnh['supplier_id'], ST_UTILITY_BILL_CREDIT_NOTE, $utility_bill_id, $final_total);


end_page(true, false, false, ST_UTILITY_BILL_CREDIT_NOTE, $utility_bill_id);




?>
