Update balance/total payment for manual payment processing

This commit is contained in:
2016-02-17 10:20:28 +11:00
parent 274c4b9156
commit 6e54c92f61
2 changed files with 31 additions and 13 deletions

View File

@@ -16,9 +16,8 @@ function booking_manual_payment_admin($nid)
$early_price_applies = _booking_is_earlybird();
$payment_balance_options[0] = t('Balance Payment');
$payment_balance_options[1] = t('Total Payment');
$payment_balance_options[0] = t('Total Payment (sets total amount paid to this value)');
$payment_balance_options[1] = t('Balance Payment (adds this value to the total amount paid)');
//collect the various payment options
$result = db_query("SELECT pid, booking_price_descrip, booking_price, booking_late_price FROM {booking_price} where booking_eventid = :eid " .
@@ -35,7 +34,7 @@ function booking_manual_payment_admin($nid)
}
//any html to put at the start of the form
$prefix = t("<p>Manually enter payment details.<br /><strong>Note that this adds to the total amount paid already by each person - the choice below is not yet implemented.</strong></p>");
$prefix = t("<p>Manually enter payment details.</p>");
$form['booking_earlybird'] = array (
'#type' => 'hidden',
@@ -61,10 +60,10 @@ function booking_manual_payment_admin($nid)
$form['payment-balance-type'] = array(
'#type' => 'radios',
'#title' => t('Balance or total payment?'),
'#description' => t('If this is a total payment, the amount selected above will be added to any existing payment. ' .
'For balance payments, the amount paid is the total above minus any previous payments.<br />Select balance if the person had already paid their deposit and now has manually paid any outstanding balance.')
'#description' => t('For balance payments, the amount entered above will be added to any payments the person has already made.<br />' .
'A total payment will replace the person\'s total payment with the value entered above.'),
'#options' => $payment_balance_options,
'#default_value' => 0,
'#default_value' => 1,
'#required' => TRUE
);
@@ -123,7 +122,7 @@ function booking_manual_payment_admin_submit($form, &$form_state) {
$fully_paid = 'N';
$payment_date = REQUEST_TIME;
$checkboxes = $form_state['values']['table']; //$values['booking_price_active'];
//watchdog('booking', 'Formstate when setting buttons: @info', array ('@info' => var_export($form_state['values'], TRUE)));
watchdog('booking', 'Formstate when setting buttons: @info', array ('@info' => var_export($form_state['values'], TRUE)));
//watchdog('booking', 'Checkboxes when setting buttons: @info', array ('@info' => var_export($checkboxes, TRUE)));
//watchdog('booking', 'Manual payment form contents: @info', array('@info' => var_export($form_state['values'], TRUE)));
@@ -163,8 +162,23 @@ function booking_manual_payment_admin_submit($form, &$form_state) {
$person = node_load($key);
if ($person) {
//add this payment to their existing balance
$total_paid = $person->booking_amount_paid + $price;
//check whether this is a balance or total payment
$is_balance = $form_state['values']['payment-balance-type'];
//balance payment
if ($is_balance == 1) {
//add this payment to their existing balance
$total_paid = $person->booking_amount_paid + $price;
//total payment
} elseif ($is_balance == 0) {
//set this as the persons new balance
$total_paid = $price;
//change $price so that we add the correct dollar amount in the payment record
//the actual amount newly paid is the price entered in the form, subtracting what they had previously paid
watchdog('booking', 'Changing price for payment record from $!price to !newprice.', array('!price' => $price, '!newprice' => ($price - $person->booking_amount_paid)));
$price = $price - $person->booking_amount_paid;
}
//check if they have now fully paid
if ($total_paid >= _booking_total_due($person)) {
@@ -188,7 +202,7 @@ function booking_manual_payment_admin_submit($form, &$form_state) {
$status = 1;
*/
watchdog('booking', 'Setting payment for regn id !nid to $!price and status to !status',
watchdog('booking', 'New payment for regn id !nid of $!price and status is now !status',
array('!nid' => $key, '!price' => $price, '!status' => $status));
db_update('booking_person')

View File

@@ -1362,7 +1362,6 @@ function booking_form_submit($form, &$form_state) {
$node->booking_lifesaver = empty($values['booking_lifesaver']) ? 'N' : ($values['booking_lifesaver'] == 1 ? 'Y' : 'N');
$node->booking_doctor = empty($values['booking_doctor']) ? 'N' : ($values['booking_doctor'] == 1 ? 'Y' : 'N');
$node->booking_dietary = empty($values['booking_dietary']) ? 'N/A' : $values['booking_dietary'];
$node->booking_medical_conditions = empty($values['booking_medical_conditions']) ? 'N/A' : $values['booking_medical_conditions'];
$node->booking_mission_experience_details = empty($values['booking_mission_experience_details']) ? 'N/A' : $values['booking_mission_experience_details'];
$node->booking_has_mission_experience = empty($values['booking_has_mission_experience']) ? 'N' : ($values['booking_has_mission_experience'] == 1 ? 'Y' : 'N');
$node->booking_skills_builder = empty($values['booking_skills_builder']) ? 'N' : ($values['booking_skills_builder'] == 1 ? 'Y' : 'N');
@@ -1372,7 +1371,12 @@ function booking_form_submit($form, &$form_state) {
$node->booking_skills_language_details = empty($values['booking_skills_language_details']) ? 'N/A' : $values['booking_skills_language_details'];
$node->booking_skills_other = empty($values['booking_skills_other']) ? 'N' : ($values['booking_skills_other'] == 1 ? 'Y' : 'N');
$node->booking_skills_other_details = empty($values['booking_skills_other_details']) ? 'N/A' : $values['booking_skills_other_details'];
$node->booking_comment_field = empty($values['booking_comment_field']) ? '' : $values['booking_comment_field'];
//remove newlines from these fields so the CSV output doesn't get messed up
$medical = empty($values['booking_medical_conditions']) ? 'N/A' : $values['booking_medical_conditions'];
$comment = empty($values['booking_comment_field']) ? '' : $values['booking_comment_field'];
$node->booking_medical_conditions = str_replace(PHP_EOL, '', $medical);
$node->booking_comment_field = str_replace(PHP_EOL, '', $comment);
//potential fields for future
//$node->booking_payment_method = $payment_method;