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

function display_selected_iou_details_for_expenses($batch_no)
{
    $result = get_batch_i_owe_you_details($batch_no);
    
    start_table(TABLESTYLE, "width=90%");

    $th = array(_("Id"),_("Type"), "Project",
                _("Date"),_("Employee Name"), "Task",
                _("Amount"), "Comment", "Batch No");
    table_header($th);

    $j = 1;
    $k=0; //row colour counter

    $total = 0;
    while ($myrow = db_fetch($result)){
        alt_table_row_color($k);
        
        $iou_link = get_petty_cash_trans_view_str(ST_I_OWE_YOU, $myrow["iou_id"]);
        label_cells('',$iou_link);
//        label_cells('',$myrow["id"]);
        label_cells('',$myrow["type_name"]);
        label_cells('',$myrow["project_description"]);
        label_cells('',sql2date($myrow["tran_date"]));
        label_cells('', get_group_company_employee_formatted_long_name($myrow["company_code"], $myrow["employee_code"]));
        label_cells('',$myrow["task_description"]);

        qty_cell($myrow["amount"], false, 2);
        $total += $myrow["amount"];

        label_cells('',$myrow["comments"]);
        $batch_link = get_petty_cash_trans_view_str(ST_I_OWE_YOU_BATCH, $myrow["batch_no"]);
        label_cells('',$batch_link,'', "align=center");

        $_POST['project_id'] = $myrow["project_id"];
        hidden("project_id", $_POST['project_id']);
        end_row();
        $j++;
        If ($j == 12)
        {
            $j = 1;
            table_header($th);
        }
    }
    start_row();
    label_cell('Total', "align=right colspan=6");
    amount_cell($total);
    end_row();

    end_table(1);
}


function display_iou_payments_for_expenses($batch_no)
{
    display_heading('I Owe You Payments');
    
    start_table(TABLESTYLE2, "width=60%");
    $payment = get_batch_i_owe_you_payments($batch_no);

    $th = array( "IOU Id", _("IOU Type"), _("Pmnt. Id"),_("Date"), _("Comment"),_("Amount"),_("Paid"));
    table_header($th);
    
    $j = 1;
    $k=0; 
    $total = 0;
    while ($myrow = db_fetch($payment))    {
            alt_table_row_color($k);
            
//            label_cell($myrow["iou_id"]);
            $iou_link = get_petty_cash_trans_view_str(ST_I_OWE_YOU, $myrow["iou_id"]);
            label_cells('',$iou_link,'', "align=center");
            
            label_cell($myrow["iou_type_name"]);
//            qty_cell($myrow["id"], false, 0);
            $payment_link = get_petty_cash_trans_view_str(ST_I_OWE_YOU_PAYMENT, $myrow["id"]);
            label_cells('',$payment_link,'', "align=center");
        
            label_cell(sql2date($myrow["payment_date"]), "align=center");
            label_cell($myrow["comment"]);
            amount_cell($myrow["amount"]);   
            label_cell($myrow['paid'] == 1 ? "Yes" : "", "align=center");
            $total += $myrow["amount"];
            //edit_button_cell("Edit".$myrow['id'], _("Edit"));
            //delete_button_cell("Delete".$myrow['id'], _("Delete"));
          
            end_row();
            $j++;
  
    }
    start_row();
    label_cell("", "colspan=4");
    label_cell("Total", "align=right");
    label_cell(number_format($total,2), "align=right");
    end_row();

end_table(1);
}

function display_i_owe_you_batch_header($batch_no, $total_paid = 0)
{
    global $approval_statuses;
    
    $batch = get_i_owe_you_batch_header($batch_no);
    
    div_start('batch_header');
    
    $header_text = 'Expenses Batch' . " #$batch_no.";
    display_heading($header_text);
//    echo "<br>";
    start_table(TABLESTYLE2, "width=95%");

    $th = array("Date", _("Project"), _("Float"), _("Total"), 
                _("Total Paid"), _("Status"), "Reimbr.");
      
    table_header($th);
    alt_table_row_color($k);     
   
    label_cell(sql2date($batch["tran_date"]));
    label_cell($batch["project_description"],null);
    label_cell($batch["float_name"],null);
    amount_decimal_cell($batch["amount"]);
    amount_decimal_cell($total_paid); 
    
    if($batch["complete"] == 1){
        $status = $approval_statuses[AS_COMPLETED];
    }
    elseif($batch["display_status"] == ""){
        $status = $approval_statuses[$batch["approval_status"]];
    }
    else{
        $status = $batch["display_status"];
    }
    $s = get_project_trans_view_str(ST_APPROVAL_LOG, $batch_no."&source_type_id=".ST_I_OWE_YOU_BATCH, $status);
//    label_cells($s,$approval_statuses[$mr_header['approval_status']], "class='tableheader2'");
    label_cell($s,"align=center");
    
    $link = get_petty_cash_float_reimbursement_details_view_str(ST_I_OWE_YOU_BATCH, $batch_no, number_format($batch['reimbursed_amount'],2));
//$link = get_petty_cash_trans_view_str(ST_PETTY_CASH_FLOAT_REIMBUR, $myrow['reimbursed_amount']);
    label_cell($link, "align=right");
    
//    $link = get_petty_cash_trans_view_str(ST_PETTY_CASH_FLOAT_REIMBUR, $batch['float_reimbursement_id'], number_format($batch['reimbursed_amount'],2));
//    label_cell($link, "align=center");

    end_table();

    div_end();    

}


function display_i_owe_you_header($iou_id)
{
    global $approval_statuses;
    
    $i_owe_you = get_i_owe_you_row($iou_id);
    
    div_start('price_table');
    
    if($i_owe_you['batch_no'] > 0){
        $header_text = 'I Owe You' . " #$iou_id"." (Batch #".$i_owe_you['batch_no'].")";
    }
    else{
        $header_text = 'I Owe You' . " #$iou_id.";
    }
    display_heading($header_text);
    echo "<br>";
    start_table(TABLESTYLE2, "width=95%");

    $th = array("IOU #", _("Employee"), _("Type"), _("Project"), _("Date"),
                _("Amount"), "Advances", _("Comments"), _("Status"), 
                _("Batch No"));
    table_header($th);
    alt_table_row_color($k);     
    $iou_link = get_petty_cash_trans_view_str(ST_I_OWE_YOU, $iou_id);
    display_pety_cash_detail_row($iou_link,"align=center");
    
    $emp_full_name = get_group_company_employee_formatted_long_name($i_owe_you['company_code'], $i_owe_you['employee_code']);
    display_pety_cash_detail_row($emp_full_name,null);
    display_pety_cash_detail_row($i_owe_you["type_name"],null);
    display_pety_cash_detail_row($i_owe_you["project"],null);
    display_pety_cash_detail_row(sql2date($i_owe_you["tran_date"]),"align=center");
    amount_decimal_cell($i_owe_you["amount"]);
    amount_decimal_cell($i_owe_you["advance_amount"]);
    //display_pety_cash_detail_row("Family Member:",$i_owe_you["family_member_name"]); 
    //display_pety_cash_detail_row("Relationship:",$i_owe_you["relationship_name"]); 
    display_pety_cash_detail_row($i_owe_you["comments"],null);
    
    if($i_owe_you["batch_complete"] == 1){
        $status = "Completed";
    }
    elseif($i_owe_you["display_status"] == ""){
        $status = $approval_statuses[$i_owe_you["approval_status"]];
    }
    else{
        $status = $i_owe_you["display_status"];
    }
    $s = get_project_trans_view_str(ST_APPROVAL_LOG, $iou_id."&source_type_id=".ST_I_OWE_YOU, $status);
    display_pety_cash_detail_row($s,null);
    display_pety_cash_detail_row($i_owe_you["batch_no"],"align=center");

    hidden("iou_id", $i_owe_you['id']);
    hidden("employee_code", $i_owe_you['employee_code']);

    end_table();

    div_end();    

    return $i_owe_you;
}

function display_petty_cash_header($petty_cash_id)
{
    global $approval_statuses;
    
    $i_owe_you = get_petty_cash_expenses_header($petty_cash_id);
    
    div_start('price_table');
    
    if($i_owe_you['batch_no'] > 0){
        $header_text = 'Petty Cash Expense' . " #$petty_cash_id"." (Batch #".$i_owe_you['batch_no'].")";
    }
    else{
        $header_text = 'Petty Cash Expense' . " #$petty_cash_id.";
    }
    display_heading($header_text);
//    echo "<br>";
    start_table(TABLESTYLE2, "width=80%");

    $th = array("PC #", _("Employee"), _("Type"), _("Project"), _("Date"),
                _("Amount"),_("Comments"), _("Batch No"));
    table_header($th);
    alt_table_row_color($k);     
    $iou_link = get_petty_cash_trans_view_str(ST_PETTY_CASH, $petty_cash_id);
    display_pety_cash_detail_row($iou_link,"align=center");
    
    $emp_full_name = get_group_company_employee_formatted_long_name($i_owe_you['company_code'], $i_owe_you['employee_code']);
    display_pety_cash_detail_row($emp_full_name,null);
    display_pety_cash_detail_row($i_owe_you["type_name"],null);
    display_pety_cash_detail_row($i_owe_you["project_description"],null);
    display_pety_cash_detail_row(sql2date($i_owe_you["tran_date"]),"align=center");
    amount_decimal_cell($i_owe_you["amount"]);
    //display_pety_cash_detail_row("Family Member:",$i_owe_you["family_member_name"]); 
    //display_pety_cash_detail_row("Relationship:",$i_owe_you["relationship_name"]); 
    display_pety_cash_detail_row($i_owe_you["comments"],null);
    
    if($i_owe_you["batch_complete"] == 1){
        $status = "Completed";
    }
    elseif($i_owe_you["display_status"] == ""){
        $status = $approval_statuses[$i_owe_you["approval_status"]];
    }
    else{
        $status = $i_owe_you["display_status"];
    }
//    $s = get_project_trans_view_str(ST_APPROVAL_LOG, $petty_cash_id."&source_type_id=".ST_I_OWE_YOU, $status);
//    display_pety_cash_detail_row($s,null);
    display_pety_cash_detail_row($i_owe_you["batch_no"],"align=center");

    hidden("iou_id", $i_owe_you['id']);
    hidden("employee_code", $i_owe_you['employee_code']);

    end_table();

    div_end();    

    return $i_owe_you;
}



function display_pety_cash_detail_row($name, $value)
{
          
    label_cell($name, $value, "width=200px class='tableheader2'", "width=200px");
  
    
}

function build_iou_all_payments_array(&$payments, $iou_id)
{
    $payments_res = get_i_owe_you_payments($iou_id);
    while ($payment_row = db_fetch($payments_res))
    {
        $a["type"] = ST_I_OWE_YOU_PAYMENT;
        $a["id"] = $payment_row["id"];
        $a["payment_date"] = $payment_row["payment_date"];
        $a["comment"] = $payment_row["comment"];
        $a["amount"] = $payment_row["amount"];
        $a["paid"] = $payment_row["paid"];
        $a["paid_on"] = $payment_row["paid_on"];
        $a['batch_no'] = 0;       
        $a["float_name"] = '';
        $a["iou_id"] = $iou_id;
        
        $payments[] = $a;
    }
    
    $q = view_i_owe_you_advances($iou_id);
    while ($adv = db_fetch($q))
    { 
        
        $a["type"] = ST_I_OWE_YOU_ADVANCES;
        $a["id"] = $adv["id"];
        $a["payment_date"] = $adv["tran_date"];
        $a["comment"] = '';
        $a["amount"] = $adv["amount"];
        $a["paid"] = 1;
        $a["paid_on"] = $adv["tran_date"];
        $a['batch_no'] = $adv["batch_no"];       
        $a["float_name"] = $adv["float_name"];
        $a["iou_id"] = $iou_id;
        
        $payments[] = $a;
    }
    
    $w = get_bank_trans(ST_IOU_BANKPAYMENT, null, PT_IOU, $iou_id);
    while ($bpay = db_fetch($w))
    { 
        
        $a["type"] = ST_IOU_BANKPAYMENT;
        $a["id"] = $bpay["trans_no"];
        $a["payment_date"] = $bpay["trans_date"];
        $a["comment"] = '';
        $a["amount"] = -$bpay["amount"];
        $a["paid"] = 1;
        $a["paid_on"] = $bpay["trans_date"];
        $a['batch_no'] = 0;       
        $a["float_name"] = '';
        $a["iou_id"] = $iou_id;
        
        
        $payments[] = $a;
    }
    
    $w = get_bank_trans(ST_IOU_BANKPAYMENT_RETURN, null, PT_IOU, $iou_id);
    while ($bpayr = db_fetch($w))
    { 
        
        $a["type"] = ST_IOU_BANKPAYMENT_RETURN;
        $a["id"] = $bpayr["trans_no"];
        $a["payment_date"] = $bpayr["trans_date"];
        $a["comment"] = '';
        $a["amount"] = -$bpayr["amount"];
        $a["paid"] = 1;
        $a["paid_on"] = $bpayr["trans_date"];
        $a['batch_no'] = 0;       
        $a["float_name"] = '';
        
        $payments[] = $a;
    }
    
    $price = array();
    foreach ($payments as $key => $row)
    {
        $price[$key] = $row['payment_date'];
    }
    array_multisort($price, SORT_ASC, $payments);

}


function display_i_owe_you_payments($iou_id, $editable)
{
    echo "<br>";
    div_start('payments_table');
    display_heading('Payments');
    start_table(TABLESTYLE2, "width=50%");

    $payments_res = get_i_owe_you_payments($iou_id);

    $th = array(("ID"), _("Date"), _("Comment"), _("amount"), "Paid", "Paid On", "", "");
    table_header($th);
    
    $j = 1;
    $k=0; 
    $payment_total = 0;
    while ($payment_row = db_fetch($payments_res))
    {
            alt_table_row_color($k);
            
//            label_cell($payment_row["id"]);
            $payment_link = get_petty_cash_trans_view_str(ST_PETTY_CASH_PAYMENT, $payment_row["id"]);
            label_cell($payment_link);
            label_cell(sql2date($payment_row["payment_date"]),"align=center"); 
            label_cell($payment_row["comment"]);
            
            amount_cell($payment_row["amount"]); 
            $payment_total += $payment_row["amount"];
            
            label_cell($payment_row["paid"] == 1 ? "Yes": "");
            
            if($payment_row["paid"] == 1){
                label_cell(sql2date($payment_row["paid_on"])." ".substr($payment_row["paid_on"],10,6),"align=center"); 
            }
            else{
                label_cell("", "align=center"); 
            }
                       
            if($payment_row["paid"] == 0 && $editable){
                edit_button_cell("Edit".$payment_row['id'], _("Edit"));
                delete_button_cell("Delete".$payment_row['id'], _("Delete"));
//                label_cell("&nbsp"); 
            }
            else{
                label_cell("&nbsp"); 
                label_cell("&nbsp");
//                label_cell("&nbsp");
            }          

            end_row();
            $j++;
  
    }
    start_row();
    //label_cell("", "colspan=1");
    label_cell("");
    label_cell("Total", "align=right colspan=2");
    label_cell(number_format($payment_total,2), "align=right");
    label_cell("", "colspan=4");
    end_row();

    end_table(1);

    br();

    div_end();
    
    return $payment_total;
}


function display_i_owe_you_all_payments($iou_id, $editable)
{
    global $systypes_array;
    
    echo "<br>";
    div_start('payments_table');
    display_heading('Payments');
    start_table(TABLESTYLE2, "width=60%");

    $payments = array();
    
    build_iou_all_payments_array($payments, $iou_id);

    $th = array(("Type"), ("#"), _("Date"), _("Comment"), _("amount"), "Paid", "Paid On");
    if($editable){
        array_append($th, array("", ""));
    }
    table_header($th);
    
    $j = 1;
    $k=0; 
    $payment_total = 0;
    foreach ($payments as $payment_row) {
            alt_table_row_color($k);
            
            label_cell($systypes_array[$payment_row["type"]]);
//            label_cell($payment_row["id"]);
        switch ($payment_row["type"]) {
            case ST_I_OWE_YOU_PAYMENT:
                $payment_link = get_trans_view_str($payment_row["type"], $payment_row["id"]);
                break;
            case ST_I_OWE_YOU_ADVANCES:
                $payment_link = get_trans_view_str($payment_row["type"], $iou_id, $payment_row["id"]);
                break;
            case ST_IOU_BANKPAYMENT:
                $payment_link = get_trans_view_str($payment_row["type"], $payment_row["id"]);
                break;
            case ST_IOU_BANKPAYMENT_RETURN:
                $payment_link = get_trans_view_str($payment_row["type"], $payment_row["id"]);
                break;

            default:
                break;
        }
            
            label_cell($payment_link,"align=center"); 
            label_cell(sql2date($payment_row["payment_date"]),"align=center"); 
            label_cell($payment_row["comment"]);
            
            amount_cell($payment_row["amount"]); 
            $payment_total += $payment_row["amount"];
            
            label_cell($payment_row["paid"] == 1 ? "Yes": "","align=center"); 
            
            if($payment_row["paid"] == 1){
//                label_cell(sql2date($payment_row["paid_on"])." ".substr($payment_row["paid_on"],10,6),"align=center"); 
                label_cell(sql2date($payment_row["paid_on"]),"align=center"); 
            }
            else{
                label_cell("", "align=center"); 
            }
                       
            if($editable){
                if($payment_row["paid"] == 0){
                    edit_button_cell("Edit".$payment_row['id'], _("Edit"));
                    delete_button_cell("Delete".$payment_row['id'], _("Delete"));
    //                label_cell("&nbsp"); 
                }else{
                    label_cell("&nbsp"); 
                    label_cell("&nbsp");
                }
            }
            else{
//                label_cell("&nbsp"); 
//                label_cell("&nbsp");
//                label_cell("&nbsp");
            }          

            end_row();
            $j++;
  
    }
    start_row();
    //label_cell("", "colspan=1");
    label_cell("");
    label_cell("Total", "align=right colspan=3");
    label_cell(number_format($payment_total,2), "align=right");
    if($editable){
        label_cell("", "colspan=4");
    }else{
        label_cell("", "colspan=2");
    }
    end_row();

    end_table(1);

    br();

    div_end();
    
    return $payment_total;
}

function display_petty_cash_payments($expense_source, $expense_id, $editable)
{
    echo "<br>";
    div_start('payments_table');
    display_heading('Payments');
    start_table(TABLESTYLE2, "width=50%");

    $payments_res = get_petty_cash_payments($expense_source, $expense_id);
    
    
    $th = array(("ID"), _("Date"), _("Comment"), _("amount"), "Paid", "Paid On", "", "");
    table_header($th);
    
    $j = 1;
    $k=0; 
    $payment_total = 0;
    while ($payment_row = db_fetch($payments_res))
    {
            alt_table_row_color($k);
            
            $payment_link = get_petty_cash_trans_view_str(ST_PETTY_CASH_PAYMENT, $payment_row["id"]);
            label_cell($payment_link);
            label_cell(sql2date($payment_row["payment_date"]),"align=center"); 
            label_cell($payment_row["comment"]);
            
            amount_cell($payment_row["amount"]); 
            $payment_total += $payment_row["amount"];
            
            label_cell($payment_row["paid"] == 1 ? "Yes": "");
            
            if($payment_row["paid"] == 1){
                label_cell(sql2date($payment_row["paid_on"])." ".substr($payment_row["paid_on"],10,6),"align=center"); 
            }
            else{
                label_cell("", "align=center"); 
            }
                       
            if($payment_row["paid"] == 0 && $editable){
                edit_button_cell("Edit".$payment_row['id'], _("Edit"));
                delete_button_cell("Delete".$payment_row['id'], _("Delete"));
//                label_cell("&nbsp"); 
            }
            else{
                label_cell("&nbsp"); 
                label_cell("&nbsp");
//                label_cell("&nbsp");
            }          

            end_row();
            $j++;
  
    }
    start_row();
    //label_cell("", "colspan=1");
    label_cell("");
    label_cell("Total", "align=right colspan=2");
    label_cell(number_format($payment_total,2), "align=right");
    label_cell("", "colspan=4");
    end_row();

    end_table(1);

    br();

    div_end();
    
    return $payment_total;
}


function display_i_owe_you_batch_expences($batch_no, $total_paid = 0)
{
    global $expense_categories;
    
    div_start('expences_table');

    display_i_owe_you_batch_header($batch_no, $total_paid);
    
    br();
    
    display_heading('Batch #'.$batch_no.' Common Expenses');
    start_table(TABLESTYLE2, "width=95%");
    $expences_iou = get_batch_i_owe_you_expences($batch_no);

    $th = array("Expense Category", "Expense Item", "Expense Type", "Budget", _("Date"),_("Invoice No"),_("Description"),_("Job"),_("Amount"), "Status", "Apr. Amount");
    table_header($th);
    
    $j = 1;
    $k = 0; 
    $total = $approved_total = 0;
    while ($myrow = db_fetch($expences_iou))
    {
            alt_table_row_color($k);
           
            if($myrow["expense_category_id"] > 0){
                label_cell($expense_categories[$myrow["expense_category_id"]]);
            }
            else{
                label_cell('');
            }
            
            $expense_item_name = '';
            switch ($myrow['expense_category_id']) {
                case EC_PETTY_CASH_EXPENSE:
                    $expense_item_name = '';
                    break;
                case EC_STOCK_ITEM_RECEIPT:
                    $receipts_res = get_petty_cash_item_receive_items_by_source_type(ST_I_OWE_YOU_BATCH, $myrow["id"]);
                    $receipts = db_fetch($receipts_res);
                    $receipt_tran_no = 0;
                    if(is_array($receipts)){
                        $receipt_tran_no = $receipts['trans_no'];
                    }
                    $link = get_inventory_trans_view_str(ST_PETTY_CASH_ITEM_RECEIPT, $receipt_tran_no, "Received items");
//                    $link = get_petty_cash_item_receive_str(ST_PETTY_CASH_ITEM_RECEIPT, $batch_no, $myrow["id"], "Receive items");
                    $expense_item_name = $link;
                    break;
                case EC_VEHICLE_MAINTENANCE:
                    $expense_item_name = get_vehicle_formatted_name($myrow["expense_item_id"]);
                    break;
                case EC_UTILITY_ITEM:
                    $utility_item = get_listvalue_by_id($myrow["expense_item_id"]);
                    $expense_item_name = $utility_item['value_name'];
                    break;
                case EC_ASSET_MAINTENANCE:
                    $expense_item_name = get_asset_formatted_name($myrow["expense_item_id"]);
                    break;

                default:
                    break;
            }
            label_cell($expense_item_name);            
            label_cell($myrow["expense_type_name"]);
            label_cell($myrow["task_description"]);
            label_cell(sql2date($myrow["expence_date"]));
            label_cell($myrow["bill_no"]);
            label_cell($myrow["expence_description"]);
            label_cell($myrow["project_site_description"]);
            amount_cell($myrow["amount"]);  
            
            $status_name = $myrow["document_status_name"];
            label_cell($status_name, "align=center");
            
            amount_cell($myrow["approved_amount"]);  
            $total += $myrow["amount"];
            $approved_total += $myrow["approved_amount"];
            

            end_row();
            $j++;
  
    }
    start_row();
    label_cell("", "colspan=7");
    label_cell(text_bold("Total"), "align=right");
    label_cell(text_bold(number_format($total,2)), "align=right");
    label_cell("");
    label_cell(text_bold(number_format($approved_total,2)), "align=right");
    end_row();
    
    end_table(1);

//    br();

    div_end();
}


function display_petty_cash_batch_expenses($batch_no)
{
    display_i_owe_you_batch_header($batch_no, $total_paid = 0);
            
    div_start('expences_table');


    br();
    
    display_heading('Batch #'.$batch_no.' Expenses');
    start_table(TABLESTYLE2, "width=60%");
    $expences_iou = get_batch_i_owe_you_expences($batch_no);

    $th = array("Budget", _("Date"),_("Invoice No"),_("Description"),_("Amount"), "Status", "Apr. Amount");
    table_header($th);
    
    $j = 1;
    $k = 0; 
    $total = $approved_total = 0;
    while ($myrow = db_fetch($expences_iou))
    {
            alt_table_row_color($k);
           
            label_cell($myrow["task_description"]);
            label_cell(sql2date($myrow["expence_date"]));
            label_cell($myrow["bill_no"]);
            label_cell($myrow["expence_description"]);
            amount_cell($myrow["amount"]);  
            
            $status_name = $myrow["document_status_name"];
            label_cell($status_name, "align=center");
            
            amount_cell($myrow["approved_amount"]);  
            $total += $myrow["amount"];
            $approved_total += $myrow["approved_amount"];
            

            end_row();
            $j++;
  
    }
    start_row();
    label_cell("", "colspan=3");
    label_cell("Total", "align=right");
    label_cell(number_format($total,2), "align=right");
    label_cell("");
    label_cell(number_format($approved_total,2), "align=right");
    end_row();
    
    end_table(1);

    br();

    div_end();
}

function display_batch_i_owe_yous($batch_no, $iou_id)
{
    $total_paid = 0;
    
    $batch_q = get_batch_i_owe_yous($batch_no, $iou_id);
    if(db_num_rows($batch_q) > 0){
        while ($iou = db_fetch($batch_q))
        {
            display_i_owe_you_header($iou['id']);
            
            if($iou_id == $iou['id']){
                $editable = true;
            }
            else{
                $editable = false;
            }
//            $total_paid += display_i_owe_you_payments($iou['id'], $editable);
            $total_paid += display_i_owe_you_all_payments($iou['id'], $editable);
            
        }
    }
    
    return $total_paid;
}
?>