<?php
/**********************************************************************
***********************************************************************/

$page_security = 'SA_PROJECT_CREDIT_NOTE_INQ';
$path_to_root = "../..";

include($path_to_root . "/includes/session.inc");

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/projects/includes/db/project_credit_notes_inquiry_db.inc");
include_once($path_to_root . "/projects/includes/db/project_credit_notes_db.inc");

$js = '';

if ($SysPrefs->use_popup_windows) {
	$js .= get_js_open_window(900, 500);
}

if (user_use_date_picker()) {
	$js .= get_js_date_picker();
}

page($help_context = "View Project Credit Note", false, false, "", $js);


if (isset($_GET["trans_no"]))
{
    $trans_no = $_GET["trans_no"];
}

$pcn_header = view_project_credit_note_header($trans_no);

display_heading('Project Credit Note' . " #$trans_no");

echo "<br>";
start_table(TABLESTYLE2, "width=40%");

start_row();

label_cells(_("Project"), $pcn_header['project_name'], "class='tableheader2'");
end_row();
label_cells(_("Customer"), $pcn_header['customer_name'], "class='tableheader2'");
end_row();
label_cells(_("Branch"), $pcn_header['branch_name'], "class='tableheader2'");
end_row();
label_cells(_("Reference"), $pcn_header['reference'], "class='tableheader2'");
end_row();
label_cells(_("Order Date"), sql2date($pcn_header['ord_date']), "class='tableheader2'");
end_row();
label_cells(_("Sales Person"), $pcn_header['salesman_name'], "class='tableheader2'");
end_row();
label_cells(_("Rate Include Taxes"), number_format($pcn_header['rate_include_taxes'], 2), "class='tableheader2'");
end_row();
label_cells(_("Tax Group"), $pcn_header['tax_group_name'], "class='tableheader2'");
end_row();
label_cells(_("Project Invoice"), $pcn_header['invoice_order_no']."-".$pcn_header['invoice_reference']."-".$pcn_header['invoice_order_date']."-".$pcn_header['invoice_total'], "class='tableheader2'");
end_row();

label_cells(_("Comments"), $pcn_header['comment'], "class='tableheader2'");
end_row();

$s = get_project_trans_view_str(ST_APPROVAL_LOG, $pcn_header['order_no']."&source_type_id=".ST_PROJECT_CREDIT_NOTE, "Approval Status");
        label_cells($s,$approval_statuses[$pcn_header['approval_status']], "class='tableheader2'");  

end_table(1);

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

display_heading('Project Credit Note Taxes');


start_table(TABLESTYLE2, "width=40%");
    start_row();  
    label_cells("Total Amount (without taxes):", number_format($pcn_header['total'], 2), "class='tableheader2'", "align=right");  
    start_row(); 
    label_cells("Tax Group", $pcn_header['tax_group_name'], "class='tableheader2'");  

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

end_table();               

br();

start_table(TABLESTYLE, "width=98%");

$th = array(_("Seq."), _("Details"), _("Date"),_("Unit"), 
            _("Quantity"), _("Rate"), _("Amount"), _("Category"), 
            _("Debit Account"), _("Credit Account"), ("Comment"));                   

display_heading('Project Credit Note Details');
table_header($th);

$pcn_lines = view_project_credit_note_details($trans_no);
$k = 0;
$lines_total = 0;
while ($item = db_fetch($pcn_lines))
{
    alt_table_row_color($k);
  
    label_cell($item['sequence']);
    label_cell($item['description']);
    
    if($item['completed_date'] == '0000-00-00'){
        label_cell('');
    }else{
        label_cell(sql2date($item['completed_date']), "align=center");      
    }
   
    label_cell($item['unit_name']);
    label_cell($item['quantity'], "align=right");
    label_cell($item['rate'], "align=right");
    
        if($item["unit_name"] != ''){
            $amount = $item["quantity"] * $item["rate"];
            label_cell(number_format($amount, 2), "align=right");
        }else{
            label_cell(number_format($item['amount'], 2), "align=right");
        }
   
    label_cell($item['category_name']);
    
    if($item['debit_account'] != null){
        label_cell($item['debit_code']." - ".$item['debit_account']);
    }else{
        label_cell('');
    }
    
    if($item['credit_account'] != null){
        label_cell($item['credit_code']." - ".$item['credit_account']);
    }else{
        label_cell('');
    }
    
    label_cell($item['line_comment']);
    
        
    end_row();    
	  
}
            
end_table(1);

end_page(true, false, false, ST_PROJECT_CREDIT_NOTE, $trans_no);




?>