<?php

function view_iou_header($iou_id) {
    global $approval_statuses;
    
    $myrow = view_i_owe_you_header($iou_id);
    
    $current_user_id = $_SESSION['wa_current_user']->user;
        
    $can_access_project = can_access_project($myrow['project_id'], $current_user_id);
        if ($can_access_project['success'] === false) {
            display_error($can_access_project['message']);
            display_footer_exit();
        }
        
    display_heading("I Owe You #".$iou_id);
    
    br();
    

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

    start_row();

//    $iou_link = get_petty_cash_trans_view_str(ST_I_OWE_YOU, $myrow['iou_id']);
//    label_cells(_("I Owe You No"), $iou_link, "class='tableheader2'");
//    end_row();
    label_cells(_("Reference"), $myrow['reference'], "class='tableheader2'");
    end_row();
    label_cells(_("Type"), $myrow['type_name'], "class='tableheader2'");
    end_row();
    label_cells(_("Project"), $myrow['project_description'], "class='tableheader2'");
    end_row();

    
    $cmp_name = get_group_company_name($myrow['company_code']);
    label_cells(_("Company"), $cmp_name, "class='tableheader2'");
    end_row();
    
    $emp_name = get_group_company_employee_formatted_long_name($myrow['company_code'], $myrow['employee_code']);
    label_cells(_("Employee"), $emp_name, "class='tableheader2'");
    end_row();
    label_cells(_("Float"), $myrow['float_name'], "class='tableheader2'");
    end_row();
    
    label_cells(_("Date"), sql2date($myrow['tran_date']), "class='tableheader2'");
    end_row();
    label_cells(_("Amount"), number_format($myrow['amount'],2), "class='tableheader2'");
    end_row();
    
    $advance_amount_link = get_petty_cash_trans_view_str(ST_I_OWE_YOU_ADVANCES, $iou_id, $myrow["advance_amount"]);
    label_cells(_("Advances"), $advance_amount_link, "class='tableheader2'");
    end_row();
    label_cells(_("Comment"), $myrow['comments'], "class='tableheader2'");
    end_row();
    
    if($myrow['batch_complete'] == 1){
        $status = $approval_statuses[AS_COMPLETED];
    }
    else{
        $status = $approval_statuses[$myrow['approval_status']];
    }
    $s = get_project_trans_view_str(ST_APPROVAL_LOG, $iou_id."&source_type_id=".ST_I_OWE_YOU, "Approval Status");
    label_cells($s,$status, "class='tableheader2'");
//    label_cells(_("Approval Status"), $s, "class='tableheader2'");
    end_row();
    label_cells(_("Batch No"), get_petty_cash_trans_view_str(ST_I_OWE_YOU_BATCH, $myrow['batch_no']), "class='tableheader2'");
    end_row();
    
    end_table();
    
}

function view_iou_details($iou_id) {
    display_heading2("I Owe You Details");
    

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

    $th = array(_("Budget"), _("Amount"), _("Comment"));
    table_header($th);

    $iou_total = 0;
    $k=0; //row colour counter

        $result = view_i_owe_you_details($iou_id);
            while ($iou_line = db_fetch($result))
            {
                alt_table_row_color($k);

                    //label_cells('',$myrow["id"]);
                    label_cell($iou_line["task_description"]);
                    amount_decimal_cell($iou_line["amount"]);
                    label_cell($iou_line["comments"]);

                $iou_total += $iou_line["amount"];
            }

    start_row();
        label_cell("Total", "colspan=1 align=right");
        amount_cell($iou_total, true);
        label_cell("");
    end_row();
    
    end_table(1);
    div_end();
}