Skip to content

Commit

Permalink
Add _makePaymentsCommentsInput() with Salaries / Fees dropdown to rec…
Browse files Browse the repository at this point in the history
…oncile Payment

Automatically fills the Comments & Amount inputs.
  • Loading branch information
francoisjacquet committed Sep 3, 2019
1 parent 501f8ee commit baae444
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -7,6 +7,7 @@ Changes in 5.1
- Add dash between Salary / Fee title and Comment in DailyTransactions.php
- CSS Fix for ChosenSelect overflow in stylesheet.css & wkhtmltopdf.css
- CSS add list-wrapper class to empty list (having add row) in ListOutput.fnc.php
- Add \_makePaymentsCommentsInput() with Salaries / Fees dropdown to reconcile Payment in Accounting/functions.inc.php & Student_Billing/functions.inc.php

Changes in 5.0.5
----------------
Expand Down
5 changes: 5 additions & 0 deletions WHATS_NEW.md
Expand Up @@ -8,6 +8,11 @@ New in 5.1
Student Fields:
- Search Medical Immunization or Physical, sponsored by Asian Hope

Student Billing:
- Payments: Fees dropdown to reconcile Payment.

Accounting:
- Staff Payments: Salaries dropdown to reconcile Payment.

New in 5.0
----------
Expand Down
7 changes: 5 additions & 2 deletions modules/Accounting/StaffPayments.php
Expand Up @@ -104,7 +104,7 @@
'REMOVE' => '_makePaymentsRemove',
'AMOUNT' => '_makePaymentsAmount',
'PAYMENT_DATE' => 'ProperDate',
'COMMENTS' => '_makePaymentsTextInput',
'COMMENTS' => '_makePaymentsCommentsInput',
);

$payments_RET = DBGet( "SELECT '' AS REMOVE,ID,AMOUNT,PAYMENT_DATE,COMMENTS
Expand Down Expand Up @@ -149,7 +149,7 @@
'REMOVE' => button( 'add' ),
'AMOUNT' => _makePaymentsTextInput( '', 'AMOUNT' ),
'PAYMENT_DATE' => _makePaymentsDateInput( DBDate(), 'PAYMENT_DATE' ),
'COMMENTS' => _makePaymentsTextInput( '', 'COMMENTS' ),
'COMMENTS' => _makePaymentsCommentsInput( '', 'COMMENTS' ),
);
}

Expand Down Expand Up @@ -195,5 +195,8 @@
&& AllowEdit() )
{
echo '</form>';

// Add space to bottom for Chosen dropdown.
echo '<br /><br /><br /><br /><br />';
}
}
77 changes: 77 additions & 0 deletions modules/Accounting/functions.inc.php
Expand Up @@ -112,6 +112,83 @@ function _makePaymentsTextInput( $value, $name )
return TextInput( $value, 'values[' . $id . '][' . $name . ']', '', $extra );
}


/**
* Make Payments Comments Input
* Add Salaries dropdown to reconcile Payment:
* Automatically fills the Comments & Amount inputs.
*
* @since 5.1
*
* @uses _makePaymentsTextInput()
*
* @param string $value Comments value.
* @param string $name Column name, 'COMMENTS'.
*
* @return string Text input if not new or if no Salaries found, else Text input & Salaries dropdown.
*/
function _makePaymentsCommentsInput( $value, $name )
{
global $THIS_RET;

$text_input = _makePaymentsTextInput( $value, $name );

if ( $THIS_RET['ID'] )
{
return $text_input;
}

// Add Salaries dropdown to reconcile Payment.
$salaries_RET = DBGet( "SELECT ID,TITLE,ASSIGNED_DATE,DUE_DATE,AMOUNT
FROM ACCOUNTING_SALARIES
WHERE STAFF_ID='" . UserStaffID() . "'
AND SYEAR='" . UserSyear() . "'
ORDER BY ASSIGNED_DATE DESC
LIMIT 100" );

if ( ! $salaries_RET )
{
return $text_input;
}

$salaries_options = array();

foreach ( $salaries_RET as $salary )
{
$salaries_options[ $salary['AMOUNT'] . '|' . $salary['TITLE'] ] = ProperDate( $salary['ASSIGNED_DATE'], 'short' ) .
' — ' . Currency( $salary['AMOUNT'] ) .
' — ' . $salary['TITLE'];
}

// JS automatically fills the Comments & Amount inputs.
ob_start();
?>
<script>
var accountingPaymentsSalariesReconcile = function( amountComments ) {
var separatorIndex = amountComments.indexOf( '|' ),
amount = amountComments.substring( 0, separatorIndex ),
comments = amountComments.substring( separatorIndex + 1 );

$('#valuesnewAMOUNT').val( amount );
$('#valuesnewCOMMENTS').val( comments );
};
</script>
<?php
$js = ob_get_clean();

// Chosen select so we can search Salaries by date, amount, & title.
$select_input = ChosenSelectInput(
'',
'accounting_salaries',
'',
$salaries_options,
'N/A',
'onchange="accountingPaymentsSalariesReconcile(this.options[selectedIndex].value);"'
);

return $text_input . ' ' . $js . $select_input;
}

function _makeSalariesAmount($value,$column)
{ global $salaries_total;

Expand Down
13 changes: 10 additions & 3 deletions modules/Student_Billing/StudentPayments.php
Expand Up @@ -102,6 +102,10 @@
FROM BILLING_PAYMENTS
WHERE ID='" . $_REQUEST['id'] . "'" );

$comments = $payment_RET[1]['COMMENTS'] ?
$payment_RET[1]['COMMENTS'] . ' &mdash; ' . _( 'Refund' ) :
_( 'Refund' );

DBQuery( "INSERT INTO BILLING_PAYMENTS (ID,SYEAR,SCHOOL_ID,STUDENT_ID,AMOUNT,
PAYMENT_DATE,COMMENTS,REFUNDED_PAYMENT_ID)
VALUES(" .
Expand All @@ -111,7 +115,7 @@
UserStudentID() . "','" .
( $payment_RET[1]['AMOUNT'] * -1 ) . "','" .
DBDate() . "','" .
DBEscapeString( $payment_RET[1]['COMMENTS'] . " " . _( 'Refund' ) ) . "','" .
DBEscapeString( $comments ) . "','" .
$_REQUEST['id'] . "')" );

// Unset modfunc & ID & redirect URL.
Expand All @@ -130,7 +134,7 @@
'REMOVE' => '_makePaymentsRemove',
'AMOUNT' => '_makePaymentsAmount',
'PAYMENT_DATE' => 'ProperDate',
'COMMENTS' => '_makePaymentsTextInput',
'COMMENTS' => '_makePaymentsCommentsInput',
'LUNCH_PAYMENT' => '_lunchInput',
);

Expand Down Expand Up @@ -191,7 +195,7 @@
'REMOVE' => button( 'add' ),
'AMOUNT' => _makePaymentsTextInput( '', 'AMOUNT' ),
'PAYMENT_DATE' => _makePaymentsDateInput( DBDate(), 'PAYMENT_DATE' ),
'COMMENTS' => _makePaymentsTextInput( '', 'COMMENTS' ),
'COMMENTS' => _makePaymentsCommentsInput( '', 'COMMENTS' ),
'LUNCH_PAYMENT' => _lunchInput( '', 'LUNCH_PAYMENT' ),
);
}
Expand Down Expand Up @@ -255,5 +259,8 @@
&& AllowEdit() )
{
echo '</form>';

// Add space to bottom for Chosen dropdown.
echo '<br /><br /><br /><br /><br />';
}
}
85 changes: 82 additions & 3 deletions modules/Student_Billing/functions.inc.php
Expand Up @@ -53,6 +53,8 @@ function _makePaymentsRemove( $value, $column )
AND p.SCHOOL_ID='" . UserSchool() . "'", array(), array( 'REFUNDED_PAYMENT_ID' ) );
}

$return = '';

if ( ! $THIS_RET['REFUNDED_PAYMENT_ID']
&& empty( $refunded_payments_RET[ $THIS_RET['ID'] ] ) )
{
Expand All @@ -61,11 +63,11 @@ function _makePaymentsRemove( $value, $column )
_( 'Refund' ),
'"Modules.php?modname=' . $_REQUEST['modname'] .
'&modfunc=refund&id=' . $THIS_RET['ID'] . '"'
);
) . ' ';
}
elseif ( $refunded_payments_RET[ $THIS_RET['ID'] ] )
elseif ( ! empty( $refunded_payments_RET[ $THIS_RET['ID'] ] ) )
{
$return = '<span class="center" style="color:#00A642">' . _( 'Refunded' ) . '</span>';
$return = '<span style="color:#00A642">' . _( 'Refunded' ) . '</span> ';
}

return $return . button(
Expand Down Expand Up @@ -161,6 +163,83 @@ function _makePaymentsTextInput( $value, $name )
return TextInput( $value, 'values[' . $id . '][' . $name . ']', '', $extra );
}

/**
* Make Payments Comments Input
* Add Fees dropdown to reconcile Payment:
* Automatically fills the Comments & Amount inputs.
*
* @since 5.1
*
* @uses _makePaymentsTextInput()
*
* @param string $value Comments value.
* @param string $name Column name, 'COMMENTS'.
*
* @return string Text input if not new or if no Fees found, else Text input & Fees dropdown.
*/
function _makePaymentsCommentsInput( $value, $name )
{
global $THIS_RET;

$text_input = _makePaymentsTextInput( $value, $name );

if ( $THIS_RET['ID'] )
{
return $text_input;
}

// Add Fees dropdown to reconcile Payment.
$fees_RET = DBGet( "SELECT ID,TITLE,ASSIGNED_DATE,DUE_DATE,AMOUNT
FROM BILLING_FEES
WHERE STUDENT_ID='" . UserStudentID() . "'
AND SYEAR='" . UserSyear() . "'
AND (WAIVED_FEE_ID IS NULL OR WAIVED_FEE_ID='')
ORDER BY ASSIGNED_DATE DESC
LIMIT 100" );

if ( ! $fees_RET )
{
return $text_input;
}

$fees_options = array();

foreach ( $fees_RET as $fee )
{
$fees_options[ $fee['AMOUNT'] . '|' . $fee['TITLE'] ] = ProperDate( $fee['ASSIGNED_DATE'], 'short' ) .
' — ' . Currency( $fee['AMOUNT'] ) .
' — ' . $fee['TITLE'];
}

// JS automatically fills the Comments & Amount inputs.
ob_start();
?>
<script>
var billingPaymentsFeeReconcile = function( amountComments ) {
var separatorIndex = amountComments.indexOf( '|' ),
amount = amountComments.substring( 0, separatorIndex ),
comments = amountComments.substring( separatorIndex + 1 );

$('#valuesnewAMOUNT').val( amount );
$('#valuesnewCOMMENTS').val( comments );
};
</script>
<?php
$js = ob_get_clean();

// Chosen select so we can search Fees by date, amount, & title.
$select_input = ChosenSelectInput(
'',
'billing_fees',
'',
$fees_options,
'N/A',
'onchange="billingPaymentsFeeReconcile(this.options[selectedIndex].value);"'
);

return $text_input . ' ' . $js . $select_input;
}

function _makePaymentsDateInput( $value, $name )
{
global $THIS_RET;
Expand Down

0 comments on commit baae444

Please sign in to comment.