<?php

function _makeFeesRemove($value,$column)
{	global $THIS_array,$waived_fees_array;
	
	if(!$waived_fees_array)
		$waived_fees_array = db_request(db_execute("SELECT f.WAIVED_FEE_ID FROM BILLING_STUDENT_FEES f WHERE f.STUDENT_ID='".get_student_id()."' AND f.WAIVED_FEE_ID IS NOT NULL AND f.SCHOOL_YEAR='".get_school_year()."' AND f.SCHOOL_ID='".get_school_id()."'"),array(),array('WAIVED_FEE_ID'));

	if(!$THIS_array['WAIVED_FEE_ID'] && !$waived_fees_array[$THIS_array['ID']])
		$return = button('remove',_('Decline'),"modloader.php?servicemod=$_REQUEST[servicemod]&servicefunction=waive&id=$THIS_array[ID]");
	elseif($waived_fees_array[$THIS_array['ID']])
//		$return = '<center><font color=#00FF66>'._('Declined').'</font></center>';
		$return = '<center><font color=blue><B>'._('Declined').'</B></font></center>';
	return $return.button('remove',_('Delete'),"modloader.php?servicemod=$_REQUEST[servicemod]&servicefunction=remove&id=$THIS_array[ID]");
}

function _makePaymentsRemove($value,$column)
{	global $THIS_array,$refunded_payments_array;
	
	if(!$refunded_payments_array)
		$refunded_payments_array = db_request(db_execute("SELECT p.REFUNDED_PAYMENT_ID FROM BILLING_STUDENT_PAYMENTS p WHERE p.STUDENT_ID='".get_student_id()."' AND (p.REFUNDED_PAYMENT_ID IS NOT NULL AND p.REFUNDED_PAYMENT_ID!='') AND p.SCHOOL_YEAR='".get_school_year()."' AND p.SCHOOL_ID='".get_school_id()."'"),array(),array('REFUNDED_PAYMENT_ID'));

	if(!$THIS_array['REFUNDED_PAYMENT_ID'] && !$refunded_payments_array[$THIS_array['ID']])
		$return = button('remove',_('Refund'),"modloader.php?servicemod=$_REQUEST[servicemod]&servicefunction=refund&id=$THIS_array[ID]");
	elseif($refunded_payments_array[$THIS_array['ID']])
		$return = '<center><font color=#00FF66>'._('Refunded').'</font></center>';
	return $return.button('remove',_('Delete'),"modloader.php?servicemod=$_REQUEST[servicemod]&servicefunction=remove&id=$THIS_array[ID]");
}

function _makeFeesTextInput($value,$name)
{	global $THIS_array;

	if($THIS_array['WAIVED_FEE_ID'])
		$THIS_array['row_colow'] = 'FFFFFF';
	if($THIS_array['ID'])
	{
		$id = $THIS_array['ID'];
		$div = 'force';
	}
	else
	{
		$id = 'new';
		$div = false;
	}
	
	if($name=='AMOUNT')
		$addition = 'size=5 maxlength=10';
	
	return TextInput($value,'values['.$id.']['.$name.']','',$addition,$div);
}

function _makeFeesDateInput($value='',$name)
{	global $THIS_array;

	if($THIS_array['ID'])
		$id = $THIS_array['ID'];
	else
		$id = 'new';
	
	$name = '['.$id.']['.$name.']';
	return DateInput($value,$name);
}

function _makeFeesAmount($value,$column)
{	global $fees_total;

	$fees_total += $value;
	return Currency($value);
}

function _makePaymentsTextInput($value,$name)
{	global $THIS_array;
	
	if($THIS_array['ID'])
		$id = $THIS_array['ID'];
	else
		$id = 'new';
	
	if($name=='AMOUNT')
		$addition = 'size=5 maxlength=10';
	
	return TextInput($value,'values['.$id.']['.$name.']','',$addition);
}

function _makePaymentsAmount($value,$column)
{	global $payments_total;

	$payments_total += $value;
	return Currency($value);
}

function _lunchInput($value,$column)
{	global $THIS_array;

	if($THIS_array['ID'])
		$id = $THIS_array['ID'];
	else
	{
		$id = 'new';
		$new = true;
	}
	
	return CheckboxInput($value,'values['.$id.']['.$column.']','','',$new,_('Yes'),_('No'));
}

function _createPaip($value,$title)
{
    global $THIS_array;
    $id = $THIS_array['ID'];
    $balance=$THIS_array['BALANCE_DEBT'];
    $debt=$THIS_array['DEBT'];
    $div='force';
    //var_dump($THIS_array);
    $addition="width=70px";
    if($value=='Y')
    {
        //deactivate_button.gif
       return "<p><IMG SRC=images/check.gif height=14></p>";
    }
    elseif($value=='N')
    {
        $sql_get_payment="SELECT SUM(cancellation) as summ FROM billing_student_payments WHERE student_id='".$_SESSION['student_id']."' AND school_year='".$_SESSION['get_school_year']."' AND school_id='".$_SESSION['get_school_id']."'";
        $row_payment=db_request(db_execute($sql_get_payment));
        //var_dump($row_payment);
        $cancellation=$row_payment[1]['SUMM'];
        if($cancellation>=$debt)
        {
        /*$create_sel="<select name='values[".$id."][".$title."]'>";
        $create_sel.="<option value='N'>"._('It is not paid');
        $create_sel.="<option value='Y'>"._('Pay');
        $create_sel.="</select> <IMG SRC=images/deactivate_button.gif height=14></p>";*/
        $create_sel="<input type=checkbox name='values[".$id."][".$title."]'>";
        }
        else
        {
            $create_sel="<IMG SRC=images/deactivate_button.gif height=14>";
        }
        return $create_sel;
    }
    return $value;
}

function _makeSelectCat($value,$column)
{
    global $sfc_array, $THIS_array;
    $div = $THIS_array['ID']?'force':false;
    $id = $THIS_array['ID']?$THIS_array['ID']:'new';
    if($sfc_array)
    {
        foreach($sfc_array as $col)
            $sfc_options[$col['ID']] = $col['TITLE'];
    }
    return SelectInput($value, 'values['.$id.']['.$column.']', '',$sfc_options, '', '', $div, 'BILLING_STUDENT_FEES_'.$column, false);
}

?>