diff --git a/booking.manual_payment.inc b/booking.manual_payment.inc index 6460187..4cdd1b1 100644 --- a/booking.manual_payment.inc +++ b/booking.manual_payment.inc @@ -18,6 +18,7 @@ function booking_manual_payment_admin($nid) $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)'); + $payment_balance_options[2] = t('Manual Refund (subtracts this value from 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 " . @@ -163,16 +164,26 @@ function booking_manual_payment_admin_submit($form, &$form_state) { $person = node_load($key); if ($person) { + // Check whether this is a balance or total payment + $payment_type = $form_state['values']['payment-balance-type']; - //check whether this is a balance or total payment - $is_balance = $form_state['values']['payment-balance-type']; - - //balance payment - if ($is_balance == 1) { + // Refund + if ($payment_type == 2) + { + //subtract this payment to their existing balance + $total_paid = $person->booking_amount_paid - $price; + $invoice_type = "Refund"; + } + // Balance payment + elseif ($payment_type == 1) + { //add this payment to their existing balance - $total_paid = $person->booking_amount_paid + $price; - //total payment - } elseif ($is_balance == 0) { + $total_paid = $person->booking_amount_paid + $price; + $invoice_type = "ManualPayment"; + } + // Total payment + elseif ($payment_type == 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 @@ -181,6 +192,7 @@ function booking_manual_payment_admin_submit($form, &$form_state) { $newprice = $price - _booking_amount_paid($key, $person); watchdog('booking', 'Changing price for payment record from $!price to !newprice.', array('!price' => $price, '!newprice' => $newprice)); $price = $newprice; + $invoice_type = "ManualPayment"; } //check if they have now fully paid @@ -226,7 +238,7 @@ function booking_manual_payment_admin_submit($form, &$form_state) { 'booking_mc_currency' => 'AUD', 'booking_mc_fee' => '0.00', 'booking_quantity' => 1, - 'booking_invoice' => 'ManualPayment', + 'booking_invoice' => $invoice_type, 'booking_payer_id' => '', 'booking_payment_date' => $payment_date, 'booking_payment_status' => '',