<?php


function display_allocations($alloc_result, $total, $payments=false)
{
	global $systypes_array;

	if (!$alloc_result || db_num_rows($alloc_result) == 0)
		return;

    display_heading2(($payments ? _("Payments") : _("Allocations")));

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

    $th = array( _("Type"), _("Number"), _("Date"), _("Total Amount"),
    	_("Left to Allocate"), _("This Allocation"), _("Allocation Date"));
	table_header($th);
    $k = $total_allocated = 0;

    while ($alloc_row = db_fetch($alloc_result))
    {

    	alt_table_row_color($k);

    	label_cell($systypes_array[$alloc_row['type']]);
    	label_cell(get_trans_view_str($alloc_row['type'],$alloc_row['trans_no']));
    	label_cell(sql2date($alloc_row['tran_date']));
    	$alloc_row['Total'] = round2($alloc_row['Total'], user_price_dec());
    	$alloc_row['amt'] = round2($alloc_row['amt'], user_price_dec());
        
        //if ($payments && ($alloc_row['type'] == ST_SUPPAYMENT || $alloc_row['type'] == ST_BANKPAYMENT || $alloc_row['type'] == ST_SUPPCREDIT))
    	if ($payments && ($alloc_row['type'] == ST_SUPPAYMENT || $alloc_row['type'] == ST_SUPPCREDIT || $alloc_row['type'] == ST_UTILITY_BILL_CREDIT_NOTE)){
    		$alloc_row['Total'] = -$alloc_row['Total'];
        }
        elseif ($payments && ($alloc_row['type'] == ST_BANKPAYMENT)){
    		$alloc_row['Total'] = $alloc_row['Total'];
        }
    	amount_cell($alloc_row['Total']);
   		amount_cell($alloc_row['Total'] - $alloc_row['amt']);
    	amount_cell($alloc_row['amt']);
        label_cell(sql2date($alloc_row['date_alloc']),'align=center');
    	end_row();

    	$total_allocated += $alloc_row['amt'];
    }
    start_row();
   	label_cell(_("Total Allocated:"), "align=right colspan=5");
	amount_cell($total_allocated);
        label_cell('');
    end_row();
    start_row();
        label_cell(_("Left to Allocate:"), "align=right colspan=5");
        $total = round2($total, user_price_dec());
        amount_cell($total - $total_allocated);
        label_cell('');
    end_row();

    end_table(1);
}


function display_allocations_from($person_type, $person_id, $type, $type_no, $total)
{
	switch ($person_type)
	{
		case PT_CUSTOMER :
			$alloc_result = get_allocatable_to_cust_transactions($person_id, $type_no, $type);
			display_allocations($alloc_result, $total);
			return;
		case PT_SUPPLIER :
			$alloc_result = get_allocatable_to_supp_transactions($person_id, $type_no, $type);
			display_allocations($alloc_result, $total);
			return;
	}
}

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

function display_allocations_to($person_type, $person_id, $type, $type_no, $total)
{
	switch ($person_type)
	{
		case PT_CUSTOMER :
			$alloc_result = get_allocatable_from_cust_transactions($person_id, $type_no, $type);
			display_allocations($alloc_result, $total, true);
			return;
		case PT_SUPPLIER :
			$alloc_result = get_allocatable_from_supp_transactions($person_id, $type_no, $type);
			display_allocations($alloc_result, $total, true);
			return;
	}
}



function get_imports_trans_view_str($type, $trans_no, $label="", $icon=false, 
	$class='', $id='')
{
	$viewer = "imports/view/";
	if ($type == ST_IMPORT_PO_COST_DETAIL_EDIT){
            $viewer = "imports/manage/";
            $viewer .= "import_purch_order_costing_detail.php";
        }
        elseif ($type == ST_IMPORT_PO_COST_DETAILS){
            $viewer .= "view_import_po_cost_details.php";
        }       
        elseif ($type == ST_IMPORT_PURCHORDER){
            $viewer .= "view_import_purchase_order.php";
        }       
        
    
	else{
		return null;
        }
        
	$viewer .= "?trans_no=$trans_no";

	if ($label == "")
		$label = $trans_no;

	return viewer_link($label, $viewer, $class, $id,  $icon);
}

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

function get_gl_account_trans_str($params, $label="", $force=false, $class='', $id='') {
	if (! $force && !user_show_gl_info()) {
            return "";
        }

	$icon = false;

        $viewer = "gl/view/view_gl_account_trans.php?$params";

	return viewer_link($label, $viewer, $class, $id, $icon);
}

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




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

function get_fi_view_str($type, $trans_no, $label="", $force=false, $class='', $id='')
{
	if (!$force && !user_show_gl_info())
		return "";

	$icon = false;
	if ($label == "")
	{
		$label = _("GL");
		$icon = ICON_GL;
	}	

	return viewer_link($label, 
		"gl/view/fi_trans_view.php?type_id=$type&trans_no=$trans_no", 
		$class, $id, $icon);
}

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



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

function get_po_all_transactions_payments_view_str($type, $trans_no, $label="", $class='', $id='')
{
	$icon = false;
	if ($label == "")
	{
		$label = _("View Purchase Order all payments"); 
	}	

	return viewer_link($label, 
		"purchasing/view/view_po_all_payments.php?type_id=$type&trans_no=$trans_no", 
		$class, $id, $icon);
}

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


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


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


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

function get_asset_trans_view_str($type, $trans_no, $label="", 
	$icon=false, $class='', $id='')
{
	$viewer = "assets/view/";

    if ($type == ST_TOOL_REQUEST)
        $viewer .= "view_tool_request.php";
    elseif ($type == ST_TOOL_ISSUE)
        $viewer .= "view_tool_issue.php";
    elseif ($type == ST_TOOL_RETURN)
        $viewer .= "view_tool_return.php";
    elseif ($type == ST_TOOL_USAGE_CHARGE)
        $viewer .= "view_tool_usage_charge.php";
    elseif ($type == ST_TOOL_ISSUE_DETAIL_USAGE_CHARGES)
        $viewer .= "view_tool_issue_detail_usage_charges.php";
    elseif ($type == ST_STOCK_ASSET_TRANSFER)
        $viewer .= "view_stock_asset_transfer.php";
    elseif ($type == ST_ASSET_TRANSFER_REQUEST)
        $viewer .= "view_asset_transfer_request.php"; 
    elseif ($type == ST_ASSET_TRANSFER || $type == ST_ASSET_REQUISITION_TRANSFER || $type == ST_ASSET_TRANSFER_RECEIPT)
        $viewer .= "view_asset_transfer.php";
    elseif ($type == ST_ASSET_QUANTITY_ADJUSTMENT_REQUEST)
        $viewer .= "view_asset_quantity_adjustment_request.php";
    elseif ($type == ST_ASSET_QUANTITY_ADJUSTMENT)
        $viewer .= "view_asset_quantity_adjustment.php";
    elseif ($type == ST_DAILY_TOOL_ISSUE)
            $viewer .= "view_daily_tool_issue.php";
    elseif ($type == ST_DAILY_TOOL_RETURN)
            $viewer .= "view_daily_tool_return.php";
    elseif ($type == ST_ASSET_VERIFICATION)
            $viewer .= "view_asset_verification_count.php";

	else
		return null;

        $viewer .= "?trans_no=$trans_no&type=$type";

	if ($label == "")
		$label = $trans_no;

	return viewer_link($label, $viewer, $class, $id,  $icon);
}

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

function get_transport_trans_view_str($type, $trans_no, $label="", 
	$icon=false, $class='', $id='')
{
	$viewer = "transport/view/";

	if ($type == ST_VEHICLE_REQUEST)
        $viewer .= "view_vehicle_request.php";
    elseif ($type == ST_VEHICLE_ALLOCATION)
        $viewer .= "view_vehicle_allocation.php";
    elseif ($type == ST_VEHICLE_RUNNING_CHART)
        $viewer .= "view_vehicle_running_chart.php";
    elseif ($type == ST_VEHICLE_RUNNING_CHART_BATCH)
        $viewer .= "view_vehicle_running_chart_batch.php";
    elseif ($type == ST_SUPPLIER_TRANSPORT_INVOICES)
        $viewer .= "view_supplier_transport_invoice.php";
    

	else
		return null;
	$viewer .= "?trans_no=$trans_no";

	if ($label == "")
		$label = $trans_no;

	return viewer_link($label, $viewer, $class, $id,  $icon);
}
//--------------------------------------------------------------------------------------


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

/*
	Journal entry or cost update postings link
*/

function get_gl_batch_trans_view_str($type, $trans_no, $label="", $icon=false, 
	$class='', $id='')
{
 
        if(in_array($type, array(ST_GL_BATCH,
                                    ST_GL_BATCH_MATERIAL_ISSUE,
                                    ST_GL_BATCH_MATERIAL_RETURN,
                                    ST_GL_BATCH_SITE_MATERIAL_RETURN,
                                    ST_GL_BATCH_INVENTORY_RECEIPT,
                                    ST_GL_BATCH_INVENTORY_ISSUE,
                                    ST_GL_BATCH_INVADJUST,
                                    ST_GL_BATCH_STOCK_COUNT,
                                    ST_GL_BATCH_ITEM_COSTUPDATE,
                                    ST_GL_BATCH_UTILITY_BILLS,
                                    ST_GL_BATCH_UTILITY_BILL_CREDIT_NOTE,
                                    ST_GL_BATCH_PROJECT_INVOICE,
                                    ST_GL_BATCH_PROJECT_CREDIT_NOTE,
                                    ST_GL_BATCH_SUBCONTRACTOR_INVOICE,
                                    ST_GL_BATCH_SUBCONTRACTOR_CREDIT_NOTE,
                                    ST_GL_BATCH_SALESINVOICE,
                                    ST_GL_BATCH_CUSTDELIVERY,
                                    ST_GL_BATCH_CUSTOMER_PAYMENT_RETURN,
                                    ST_GL_BATCH_CUSTCREDIT,
                                    ST_GL_BATCH_CUSTPAYMENT,
                                    ST_GL_BATCH_SUPPRECEIVE,
                                    ST_GL_BATCH_SUPPINVOICE,
                                    ST_GL_BATCH_SUPPCREDIT,
                                    ST_GL_BATCH_SUPPAYMENT,
                                    ST_GL_BATCH_PR_ISSUE,
                                    ST_GL_BATCH_PR_RETURN,
                                    ST_GL_BATCH_PETTY_CASH_FLOAT_ADJ,
                                    ST_GL_BATCH_PETTY_CASH_FLOAT_REIMBUR,
                                    ST_GL_BATCH_I_OWE_YOU_BATCH,
                                    ST_GL_BATCH_PETTY_CASH_DIRECT_PAYMENTS,
                                    ST_GL_BATCH_I_OWE_YOU_PAYMENT,
                                    ST_GL_BATCH_PETTY_CASH_PAYMENT,
                                    ST_GL_BATCH_I_OWE_YOU_ADVANCES,
                                    ST_GL_BATCH_SUPPLIER_TRANSPORT_INVOICES,
                                    ST_GL_BATCH_COMP_LOAN_REPAYMENT,
                                    ST_GL_BATCH_DAILY_ITEM_ISSUE,
                                    ST_GL_BATCH_DAILY_ITEM_RETURN,
                                    ST_GL_BATCH_PETTY_CASH_ITEM_RECEIPT)))
		$viewer = "gl/view/view_gl_batch.php?type_id=".$type."&trans_no=$trans_no";  
    
	else
		return null;

	if ($label == "")
		$label = $trans_no;

	return viewer_link($label, $viewer, $class, $id,  $icon);
}

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



function get_batch_item_issue_transactions_str($type, $line_id, $label="", $force=false, $class='', $id='')
{

	return viewer_link($label, 
		"inventory/manage/batch_item_issue_transactions.php?type_id=$type&line_id=$line_id", 
		$class, $id);
}


function get_petty_cash_trans_view_str($type, $trans_no, $label="", $icon=false, 
	$class='', $id='')
{
    if($trans_no == 0){
        return null;
    }
    
	if($type == ST_I_OWE_YOU)
		$viewer = "petty_cash/view/view_i_owe_you.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_I_OWE_YOU_BATCH)
		$viewer = "petty_cash/view/view_i_owe_you_batch.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_PETTY_CASH_FLOAT_ADJ)
		$viewer = "petty_cash/view/view_petty_cash_float_adjustement.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_PETTY_CASH_FLOAT_REIMBUR)
		$viewer = "petty_cash/view/view_petty_cash_float_reimbursement.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_I_OWE_YOU_ADVANCES_BATCH)
		$viewer = "petty_cash/view/view_i_owe_you_advances_batch.php?type_id=$type&trans_no=$trans_no";    
    elseif($type == ST_PETTY_CASH_DIRECT_PAYMENTS)
		$viewer = "petty_cash/view/view_petty_cash_direct_payments.php?type_id=$type&trans_no=$trans_no";    
    elseif($type == ST_PETTY_CASH)
		$viewer = "petty_cash/view/view_petty_cash_expenses.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_I_OWE_YOU_PAYMENT)
		$viewer = "petty_cash/view/view_petty_cash_payment.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_PETTY_CASH_PAYMENT)
		$viewer = "petty_cash/view/view_petty_cash_payment.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_I_OWE_YOU_ADVANCES)
		$viewer = "petty_cash/view/view_i_owe_you_advances.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_PROJECT_ADVANCE_BATCH)
		$viewer = "petty_cash/view/view_project_advance_batch.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_PROJECT_FLOAT_ADJ)
		$viewer = "petty_cash/view/view_project_float_adjustement.php?type_id=$type&trans_no=$trans_no";   
    elseif($type == ST_FLOAT_RECEIPT)
		$viewer = "petty_cash/view/view_petty_cash_float_adjustement.php?type_id=$type&trans_no=$trans_no";    
    elseif($type == ST_FLOAT_PAYMENT)
		$viewer = "petty_cash/view/view_petty_cash_float_adjustement.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_FLOAT_TRANSFER)
		$viewer = "petty_cash/view/view_petty_cash_float_adjustement.php?type_id=$type&trans_no=$trans_no";
    
	else
		return null;

	if ($label == "")
		$label = $trans_no;

	return viewer_link($label, $viewer, $class, $id,  $icon);
}

function get_finance_trans_view_str($type, $trans_no, $label="", $icon=false, 
	$class='', $id='')
{
    if($trans_no == 0){
        return null;
    }
    
	if($type == ST_BONDS)
		$viewer = "finance/view/view_bonds.php?type_id=$type&trans_no=$trans_no";
    
    elseif($type == ST_COMPANY_LOAN_INSTALLMENTS)
		$viewer = "finance/view/view_company_loan_installments.php?type_id=$type&trans_no=$trans_no";
    
    elseif($type == ST_LETTERS_OF_CREDIT)
		$viewer = "finance/view/view_letters_of_credit.php?type_id=$type&trans_no=$trans_no";
    
    elseif($type == ST_INSURED_ITEMS)
		$viewer = "finance/view/view_insured_items.php?type_id=$type&trans_no=$trans_no";
    
    elseif($type == ST_FIXED_DEPOSIT)
		$viewer = "finance/view/view_fixed_deposit.php?type_id=$type&trans_no=$trans_no";
    
    elseif($type == ST_COMP_LOAN_REPAYMENT)
		$viewer = "finance/view/view_company_loan_repayment.php?type_id=$type&trans_no=$trans_no";
    
    
    else
		return null;

	if ($label == "")
		$label = $trans_no;

	return viewer_link($label, $viewer, $class, $id,  $icon);
}


function get_loyalty_trans_view_str($type, $trans_no, $label="", $icon=false, 
	$class='', $id='')
{
	if ($type == ST_POINTSUPDATE)
		$viewer = "loyalty/view/view_benefit.php?type_id=$type&trans_no=$trans_no";
	else
		return null;

	if ($label == "")
		$label = $trans_no;

	return viewer_link($label, $viewer, $class, $id,  $icon);
}

function get_payroll_trans_view_str($type, $trans_no, $label="", $icon=false, 
	$class='', $id='', $db_name='')
{
	if ($type == ST_ATTENDANCE)
		$viewer = "payroll/view/view_attendance.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_PAYROLL)
		$viewer = "payroll/view/view_payroll.php?type_id=$type&trans_no=$trans_no&comp=$db_name";
    elseif($type == ST_LOAN)
		$viewer = "payroll/view/view_loan_details.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_SALARY_ADVANCE_PAYMENT)
		$viewer = "payroll/view/view_salary_advance.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_EMPLOYEE)
		$viewer = "payroll/view/view_employee_details.php?type_id=$type&trans_no=$trans_no";
    elseif($type == ST_SALARY_ADVANCE)
		$viewer = "payroll/view/view_salary_advances.php?type_id=$type&trans_no=$trans_no";
    else
		return null;

	if ($label == "")
		$label = $trans_no;

	return viewer_link($label, $viewer, $class, $id,  $icon);
}


function get_jobq_request_view_str($type, $trans_no, $label="", $icon=false, 
	$class='', $id='')
{
	if ($type == ST_JOB_QUEUE)
                $viewer = "jobq/view/view_jobq_request.php?type_id=$type&trans_no=$trans_no";
//        if ($type == ST_I_OWE_YOU)
//                $viewer = "view/view_petty_cash.php?type_id=$type&trans_no=$trans_no";
    else
        return null;

	if ($label == "")
		$label = $trans_no;

	return viewer_link($label, $viewer, $class, $id,  $icon);
}



function get_task_cost_details_view_str($task_id, $label="", $icon=false, 
	$class='', $id='')
{
         $viewer = "projects/view/view_project_task_cost_details.php?task_id=$task_id";

	return viewer_link($label, $viewer, $class, $id,  $icon);
}




function get_fi_remaining_transactions_view_str($type_id, $cutoff_date, $count, $label="", $icon=false, 
	$class='', $id='')
{
         $viewer = "gl/view/view_fi_remaining_transactions.php?type_id=$type_id&date=$cutoff_date";
         
         if ($label == "")
		$label = $count;

	return viewer_link($label, $viewer, $class, $id,  $icon);
}



function get_unreconciled_transactions_view_str($rec_id, $amount, $label="", $icon=false, 
	$class='', $id='')
{
         $viewer = "gl/view/view_unreconciled_transactions.php?rec_id=$rec_id";
         
         if ($label == "")
		$label = $amount;

	return viewer_link($label, $viewer, $class, $id,  $icon);
}



function get_reconciled_account_difference_view_str($rec_id, $amount, $label="", $icon=false, 
	$class='', $id='')
{
         $viewer = "gl/view/view_reconciled_account_difference.php?rec_id=$rec_id";
         
         if ($label == "")
		$label = $amount;

	return viewer_link($label, $viewer, $class, $id,  $icon);
}



function get_petty_cash_float_reimbursement_details_view_str($type, $trans_no, $label="", $icon=false, 
	$class='', $id='')
{
         $viewer = "petty_cash/view/view_petty_cash_float_reimbursement_details.php?type=$type&trans_no=$trans_no";
        if ($label == ""){
		$label = $trans_no;
        }
                
	return viewer_link($label, $viewer, $class, $id,  $icon);
}

function get_task_cost_allocation_details_view_str($task_id, $label="", $icon=false, 
	$class='', $id='')
{
         $viewer = "projects/view/view_project_task_cost_allocation_details.php?task_id=$task_id";

	return viewer_link($label, $viewer, $class, $id,  $icon);
}

function get_estimation_trans_view_str($type, $trans_no, $label="", $icon=false, 
	$class='', $id='')
{   
        
        if ($type == ST_EST_PROJECT_BOQ_ITEM_DETAIL_EDIT)
                $viewer = "estimation/manage/est_project_boq_item_detail_edit.php?trans_no=$trans_no";
        
        elseif ($type == ST_EST_PROJECT_BOQ_ITEM_GROUP)
                $viewer = "estimation/view/view_est_project_boq_group.php?trans_no=$trans_no"; 
        
        elseif ($type == ST_EST_PROJECT_BOQ_ITEM)
                $viewer = "estimation/view/view_est_project_boq_item.php?trans_no=$trans_no";
        
        elseif ($type == ST_EST_PROJECT_BOQ_ITEM_GROUPS_SUMMARY)
                $viewer = "estimation/view/view_est_project_boq_groups_summary.php?trans_no=$trans_no";  
        
        else
		return null;

	if ($label == ""){
		$label = $trans_no;
    }

	return viewer_link($label, $viewer, $class, $id,  $icon);
}


function get_project_trans_view_str($type, $trans_no, $label="", $icon=false, 
	$class='', $id='')
{   
        if ($type == ST_APPROVAL_LOG)
                $viewer = "projects/view/view_approval_log.php?type_id=$type&trans_no=$trans_no";
        
        elseif ($type == ST_APPROVAL_GROUP)
                $viewer = "projects/view/view_approval_group.php?type_id=$type&trans_no=$trans_no";
        
        elseif ($type == ST_PROJECT_COST_ADJUST)
                $viewer = "projects/view/view_project_cost.php?trans_no=$trans_no";
        
        elseif ($type == ST_PROJECT_ALLOC_ADJUST)
                $viewer = "projects/view/view_project_cost_allocation.php?trans_no=$trans_no";
        
        elseif ($type == ST_PROJECT_WORK_DONE)
                $viewer = "projects/view/view_project_work_done.php?trans_no=$trans_no";
        
        elseif ($type == ST_PROJECT_BOQ_ITEM)
                $viewer = "projects/view/view_project_boq_item.php?trans_no=$trans_no";
        
        elseif ($type == ST_PROJECT_BOQ_ITEM_DETAIL_EDIT)
                $viewer = "projects/manage/project_boq_item_detail_edit.php?trans_no=$trans_no";
        
        elseif ($type == ST_PROJECT_PAY_APP_BOQ_GROUPS)
                $viewer = "projects/view/view_payment_application_boq_groups.php?trans_no=$trans_no";
        
        elseif ($type == ST_PROJECT_PAY_APP_BOQ_ITEMS)
                $viewer = "projects/view/view_payment_application_boq_items.php?trans_no=$trans_no";
        
        elseif ($type == ST_PROJECT_WORK_DONE)
                $viewer = "projects/view/view_project_work_done.php?trans_no=$trans_no";       
        
        elseif ($type == ST_PROJECT_BOQ_GROUP_WORK_DONE)
                $viewer = "projects/view/view_project_boq_group_work_done.php?trans_no=$trans_no";        
        
        elseif ($type == ST_PROJECT_BOQ_ITEM_WORK_DONE)
                $viewer = "projects/view/view_project_boq_item_work_done.php?trans_no=$trans_no";  
        
        elseif ($type == ST_PROJECT_PAYMENT_APPLICATION)
                $viewer = "projects/view/view_project_payment_application.php?trans_no=$trans_no";  
        
        elseif ($type == ST_PROJECT_SALES_ORDERS)
                $viewer = "projects/view/view_project_sales_order.php?trans_no=$trans_no";  
        
        elseif ($type == ST_PROJECT_INVOICE)
                $viewer = "projects/view/view_manual_project_invoice.php?trans_no=$trans_no";  
        
        elseif ($type == ST_PROJECT_INVOICE)
                $viewer = "projects/view/view_manual_project_invoice.php?trans_no=$trans_no";  
        
        elseif ($type == ST_PROJECT_CREDIT_NOTE)
                $viewer = "projects/view/view_project_credit_note.php?trans_no=$trans_no";  
        
        elseif ($type == ST_SUBCONTRACTOR_INVOICE)
                $viewer = "projects/view/view_subcontractor_invoice.php?trans_no=$trans_no";  
        
        elseif ($type == ST_PROJECT_BOQ_ITEM_GROUP)
                $viewer = "projects/view/view_project_boq_group.php?trans_no=$trans_no";  
        
        elseif ($type == ST_PROJECT_BOQ_ITEM_GROUPS_SUMMARY)
                $viewer = "projects/view/view_project_boq_groups_summary.php?trans_no=$trans_no";  
        
        elseif ($type == ST_PROJECT_BUDGET_GROUP)
                $viewer = "projects/view/view_project_budget_group.php?trans_no=$trans_no"; 
        
        elseif ($type == ST_SUBCONTRACTOR_PURCH_ORDER)
                $viewer = "projects/view/view_subcontractor_purchase_order.php?trans_no=$trans_no";  
        
        elseif ($type == ST_DOCUMENT_BUDGET_STATUS)
                $viewer = "projects/view/view_document_task_status.php?trans_no=$trans_no";  
        
        elseif ($type == ST_SUBCONTRACTOR_CREDIT_NOTE)
                $viewer = "projects/view/view_subcontractor_credit_note.php?trans_no=$trans_no"; 
        
        elseif ($type == ST_MISCELLANEOUS_PROJECT_COST)
                $viewer = "projects/view/view_miscellaneous_project_cost.php?trans_no=$trans_no"; 
        
        
        
        
        
        
        
        else
		return null;

	if ($label == ""){
		$label = $trans_no;
    }

	return viewer_link($label, $viewer, $class, $id,  $icon);
}



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



function get_petty_cash_item_receive_str($source_type, $source_trans_no, $source_detail_id, $label)
{
	if ($source_type == ST_I_OWE_YOU_BATCH)
		$viewer = "inventory/manage/petty_cash_item_receive.php?stype=$source_type&strn_no=$source_trans_no&sd_id=$source_detail_id";
	else
		return null;


	return viewer_link($label, $viewer);
}
//--------------------------------------------------------------------------------------




function get_data_view_str($data_view_type, $parameters, $label, $icon=false, 
	$class='', $id='')
{   
    switch ($data_view_type) {
        case DV_PROJECT_TRANSACTION_TYPE_TRANSACTIONS:
            $viewer = "projects/view/view_project_transaction_type_transactions.php?".$parameters;
            break;
        case DV_PROJECT_WIP_COSTS:
            $viewer = "projects/view/view_project_wip_costs.php?".$parameters;
            break;
        case DV_SUPPLIER_ALLOCATIONS_TO:
            $viewer = "purchasing/view/view_supp_allocations_to.php?".$parameters;
            break;
        case DV_SUPPLIER_ALLOCATIONS_FROM:
            $viewer = "purchasing/view/view_supp_allocations_from.php?".$parameters;
            break;
        case DV_CUSTOMER_ALLOCATIONS_TO:
            $viewer = "sales/view/view_cust_allocations_to.php?".$parameters;
            break;
        case DV_CUSTOMER_ALLOCATIONS_FROM:
            $viewer = "sales/view/view_cust_allocations_from.php?".$parameters;
            break;
    // Assets    
        case DV_TOOL_ISSUE_DETAIL_COSTS:
            $viewer = "assets/view/view_tool_issue_detail_costs.php?".$parameters;
            break;
        case DV_TOOL_USAGE_CHARGES_LOG:
            $viewer = "assets/view/view_tool_usage_charges_log.php?".$parameters;
            break;
        case DV_COMPANY_CASH_FLOW_TRANSACTIONS:
            $viewer = "gl/view/view_company_cash_flow_transactions.php?".$parameters;
            break;
        case DV_COMPANY_PL_TRANSACTIONS:
            $viewer = "gl/view/view_company_pl_transactions.php?".$parameters;
            break;
        case DV_GL_ACCOUNT_TRANSACTIONS:
            $viewer = "gl/view/view_gl_account_transactions.php?".$parameters;
            break;
        case DV_STOCL_STATUS_DETAILS:
            $viewer = "inventory/view/view_stock_status_details.php?".$parameters;
            break;
        case DV_ITEM_TRANSACTION_SUMMARY:
            $viewer = "inventory/view/view_item_transaction_summary_details.php?".$parameters;
            break;

        default:
            return null;
    }		

    return viewer_link($label, $viewer, $class, $id,  $icon);
}



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



function get_dashboard_view_str($type, $parameters, $label, $icon=false, $class='', $id='') {   
    switch ($type) {
        case DASH_SC_PURCHASE_PURCHASE_ORDERS: 
            $viewer = "dashboard/views/view_dashboard_purchase_orders.php?$parameters";
            break;
        case DASH_SC_PURCHASE_PURCHASE_REQUISITIONS: 
            $viewer = "dashboard/views/view_dashboard_purchase_requisitions.php?$parameters";
            break;
        case DASH_SC_PURCHASE_TOP_SUPPLIERS:
            $viewer = "dashboard/views/view_dashboard_top_suppliers.php?$parameters";
            break;
        case DASH_SC_PURCHASE_NEW_SUPPLIERS:
            $viewer = "dashboard/views/view_dashboard_new_suppliers.php?$parameters";
            break;
        case DASH_SC_PURCHASE_TOP_ITEMS:
            $viewer = "dashboard/views/view_dashboard_top_items.php?$parameters";
            break;
        case DASH_SC_PURCHASE_PRICE_VARIANCE:
            $viewer = "dashboard/views/view_dashboard_purchase_price_variance.php?$parameters";
            break;
        case DASH_SC_PURCHASE_SUPPLIER_DELIVERY_LEAD_TIME:
            $viewer = "dashboard/views/view_dashboard_supplier_delivery_lead_time.php?$parameters";
            break;
         case DASH_SC_PURCHASE_DATA_ENTRY:
            $viewer = "dashboard/views/view_dashboard_purchasing_data_entry.php?$parameters";
            break;
        
        
        
        case DASH_SC_PETTY_CASH_EXPENSES:
            $viewer = "dashboard/views/view_dashboard_petty_cash_expenses.php?$parameters";
            break;
        case DASH_SC_PETTY_CASH_EMPLOYEE_OUTSTANDING:
            $viewer = "dashboard/views/view_dashboard_petty_cash_employee_outstanding.php?$parameters";
            break;
        case DASH_SC_PETTY_CASH_DATA_ENTRY:
            $viewer = "dashboard/views/view_dashboard_petty_cash_data_entry.php?$parameters";
            break;
        case DASH_SC_DEPARTMENT_PETTY_CASH_EXPENSES:
            $viewer = "dashboard/views/view_dashboard_department_petty_cash_expenses.php?$parameters";
            break;
        case DASH_SC_INVENTORY_MOVEMENT_TYPES:
            $viewer = "dashboard/views/view_dashboard_inventory_movement_types.php?$parameters";
            break;
        case DASH_SC_TRANSPORT_ITEM_CONSUMPTION:
            $viewer = "dashboard/views/view_dashboard_transport_item_consumption.php?$parameters";
            break;
        case DASH_SC_TRANSPORT_PETTY_CASH_EXPENSES:
            $viewer = "dashboard/views/view_dashboard_transport_petty_cash_expenses.php?$parameters";
            break;
        case DASH_SC_TRANSPORT_UTILITY_EXPENSES:
            $viewer = "dashboard/views/view_dashboard_transport_utility_expenses.php?$parameters";
            break;
        case DASH_SC_PROJECT_EXPENSES:
            $viewer = "dashboard/views/view_dashboard_project_expenses.php?$parameters";
            break;
        case DASH_SC_PROJECT_ITEM_CONSUMPTION:
            $viewer = "dashboard/views/view_dashboard_inventory_item_consumption.php?$parameters";
            break;
        case DASH_SC_PROJECT_CASH_FLOW:
            $viewer = "dashboard/views/view_dashboard_project_cash_flow.php?$parameters";
            break;
        case DASH_SC_UTILITY_EXPENSES: 
            $viewer = "dashboard/views/view_dashboard_utility_expenses.php?$parameters";
            break;
        case DASH_SC_PETTY_CASH_I_OWE_YOUS: 
            $viewer = "dashboard/views/view_dashboard_petty_cash_i_owe_yous.php?$parameters";
            break;
        case DASH_SC_INVENTORY_MATERIAL_REQUISITIONS: 
            $viewer = "dashboard/views/view_dashboard_inventory_material_requisitions.php?$parameters";
            break;
        case DASH_SC_INVENTORY_ITEM_CONSUMPTION:
            $viewer = "dashboard/views/view_dashboard_inventory_item_consumption.php?$parameters";
            break;
        case DASH_SC_PETTY_CASH_APPROVALS:
            $viewer = "dashboard/views/view_dashboard_petty_cash_approvals.php?$parameters";
            break;
        case DASH_SC_PURCHASING_APPROVALS:
            $viewer = "dashboard/views/view_dashboard_purchasing_approvals.php?$parameters";
            break;
        case DASH_SC_PROJECT_APPROVALS:
            $viewer = "dashboard/views/view_dashboard_project_approvals.php?$parameters";
            break;
        case DASH_SC_INVENTORY_APPROVALS:
            $viewer = "dashboard/views/view_dashboard_inventory_approvals.php?$parameters";
            break;
        case DASH_SC_TRANSPORT_APPROVALS:
            $viewer = "dashboard/views/view_dashboard_transport_approvals.php?$parameters";
            break;
        case DASH_SC_UTILITY_APPROVALS:
            $viewer = "dashboard/views/view_dashboard_utility_approvals.php?$parameters";
            break;
        
        
        
        
        case DASH_SC_SALES_TOP_ITEMS:
            $viewer = "dashboard/views/view_dashboard_sales_top_items.php?$parameters";
            break;
        case DASH_SC_SALES_ITEMS_DELIVRY_OUTSTANDING:
            $viewer = "dashboard/views/view_dashboard_sales_delivery_outstanding.php?$parameters";
            break;
        case DASH_SC_SALES_ORDERS;
        case DASH_SC_SALES_QUOTATIONS;
            $viewer = "dashboard/views/view_dashboard_sales_orders.php?$parameters";
            break;
        case DASH_SC_SALES_INVOICES;
            $viewer = "dashboard/views/view_dashboard_sales_invoices.php?$parameters";
        case DASH_SC_SALES_REP_ORDERS;
            $viewer = "dashboard/views/view_dashboard_sales_rep_orders.php?$parameters";
            break; 
        
        
        
        case DASH_SC_HR_LEAVES;
            $viewer = "dashboard/views/view_dashboard_hr_leaves.php?$parameters";
            break; 
        case DASH_VW_HR_EMPLYEE_COUNT_CATEGORY;
        case DASH_VW_HR_EMPLYEE_COUNT_DEPARTMENT;
            $viewer = "dashboard/views/view_dashboard_hr_employee_count.php?$parameters";
            break; 
        case DASH_VW_HR_SALARY_COMPONENT;
            $viewer = "dashboard/views/view_dashboard_hr_salary_component.php?$parameters";
            break; 
        case DASH_VW_HR_EMPLOYEE_ATTENDANCE;
            $viewer = "dashboard/views/view_dashboard_hr_employee_attendance.php?$parameters";
            break; 
        
        
        case DASH_VW_PROJECT_NONEDITABLE_ITEM_ISSUES;
            $viewer = "dashboard/views/view_dashboard_project_noneditable_item_issues.php?$parameters";
            break; 
        
        case DASH_SC_SALES_PNL: 
            $viewer = "dashboard/views/view_dashboard_sales_pnl.php?$parameters";
            break;
       
        

        default:
            return null;
    }		

    return viewer_link($label, $viewer, $class, $id,  $icon);
}



function get_js_parent_passing_item($name){
    echo '
    <script type="text/javascript">
    function pass_to_parent(val){
        var evt = opener.document.createEvent("HTMLEvents");
        evt.initEvent("blur", false, true);
        
        opener.document.getElementsByName("_'.$name.'_edit")[0].value=val;
        opener.document.getElementsByName("_'.$name.'_edit")[0].dispatchEvent(evt);
        edit = opener.document.getElementsByName("_'.$name.'_edit")[0].focus();
        self.close();
    }
    </script>
    ';
}