function basket_item_to_ledger($new_data) { // debug_print ("INFO: 1 ", $new_data, basename(__FILE__).' LINE '.__LINE__); // Begin by checking the ledger for prior entries like this one $old_data = search_ledger($new_data); // What data is already in the ledger? if ($old_data == 0) { // Nothing to report, so we can post this data as new $new_transaction_id = add_to_ledger($new_data); } elseif (is_array($old_data)) { // One ledger entry found, so compare it... $different_fields = compare_ledger_fields($new_data, $old_data); // Need to do an update if there are changed messages // Or if there is any changed field besides replaced_by if (count($new_data['messages']) || count($different_fields) >= 1 && !in_array('replaced_by', $different_fields) || count($different_fields) > 2 && in_array('replaced_by', $different_fields)) { // Add the new transaction $new_transaction_id = add_to_ledger($new_data); // And delete the old one replace_ledger_transaction($old_data['transaction_id'], $new_transaction_id); } } else { // Multiple ledger entries -- should not happen die(debug_print("ERROR: 750820 ", 'Multiple [' . $old_data . '] existing basket_item entries already in ledger', basename(__FILE__) . ' LINE ' . __LINE__)); } }
work_zip = "' . mysql_real_escape_string($work_zip) . '", home_phone = "' . mysql_real_escape_string($home_phone) . '", work_phone = "' . mysql_real_escape_string($work_phone) . '", mobile_phone = "' . mysql_real_escape_string($mobile_phone) . '", fax = "' . mysql_real_escape_string($fax) . '", toll_free = "' . mysql_real_escape_string($toll_free) . '", email_address = "' . mysql_real_escape_string($email_address) . '", email_address_2 = "' . mysql_real_escape_string($email_address_2) . '", home_page = "' . mysql_real_escape_string($home_page) . '", how_heard_id = "' . mysql_real_escape_string($how_heard_id) . '", no_postal_mail = "' . mysql_real_escape_string($no_postal_mail) . '"'; $result = @mysql_query($query, $connection) or die(debug_print("ERROR: 793032 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__)); $member_id = mysql_insert_id(); include_once 'func.update_ledger.php'; // Post the membership receivable $transaction_row = add_to_ledger(array('transaction_group_id' => '', 'source_type' => 'member', 'source_key' => $member_id, 'target_type' => 'internal', 'target_key' => 'membership_dues', 'amount' => $initial_cost, 'text_key' => 'membership dues', 'posted_by' => $member_id)); // Figure out what sort of "welcome" to give the new member... if ($pending == 1) { $membership_disposition = ' <p>Thanks for becoming a member! Your membership number will be #' . $member_id . '. Your membership application will be reviewed by an administrator and you will be notified when it becomes active. Until then, you will not be able to log in.</p>'; } else { $membership_disposition = ' <p class="welcome_message">Thanks for becoming a member! Your membership number is #' . $member_id . '. Your membership has been automatically activated and you may <a href="' . PATH . 'index.php?action=login"> sign in</a> immediately.</p>'; } // Add taxes for taxable membership fees (based upon the STATE tax rate) $membership_taxes = 0; if (MEMBERSHIP_IS_TAXED) {
function add_extra_money($username, $account, $amount, $description) { if (!in_array($account, array('savings', 'tithing', 'spending', 'all'))) { die("Bad account in extra money"); } if ($account == 'all') { add_to_ledger($username, $amount * 0.1, 'tithing', $description); add_to_ledger($username, $amount * 0.5, 'savings', $description); add_to_ledger($username, $amount * 0.4, 'spending', $description); add_allowance($username, $amount); } else { add_to_ledger($username, $amount, $account, $description); add_money($username, $account, $amount); } $allowance = allowance($username); return $allowance[$username]; }
ofs_put_status('paypal_txn_id', $_POST['txn_id'], $_POST['payment_gross'], PAYPAL_TTL); // Prepare to post the accounting $payment_message_array = array(); $payment_message_array['ledger comment'] = $_POST['memo']; $paypal_message_array = array(); $paypal_message_array['ledger paypal comment'] = 'From: ' . $_POST['payer_email']; $effective_datetime = date('Y-m-d H:i:s', strtotime($_POST['payment_date'])); $transaction_group_id = get_new_transaction_group_id(); include_once 'func.update_ledger.php'; // First, post the PayPal fee $paypal_transaction_id = add_to_ledger(array('transaction_group_id' => $transaction_group_id, 'source_type' => 'internal', 'source_key' => 'paypal charges', 'target_type' => 'internal', 'target_key' => 'payment sent', 'amount' => $_POST['payment_fee'], 'text_key' => 'paypal charges', 'effective_datetime' => $effective_datetime, 'posted_by' => $number, 'replaced_by' => '', 'timestamp' => '', 'basket_id' => '', 'bpid' => '', 'site_id' => '', 'delivery_id' => '', 'pvid' => '', 'messages' => $paypal_message_array)); if (!is_numeric($paypal_transaction_id)) { debug_print("ERROR: 275378 ", array('Level' => 'WARNING', 'Scope' => 'PayPal API', 'File ' => __FILE__ . ' at line ' . __LINE__, 'Details' => array('Message' => 'Did not receive transaction_id when posting PayPal fee', 'IPN Data' => $_POST))); } // Second, post the Gross payment $payment_transaction_id = add_to_ledger(array('transaction_group_id' => $transaction_group_id, 'source_type' => 'internal', 'source_key' => 'payment received', 'target_type' => 'member', 'target_key' => $number, 'amount' => $_POST['payment_gross'], 'text_key' => 'payment received', 'effective_datetime' => $effective_datetime, 'posted_by' => $number, 'replaced_by' => '', 'timestamp' => '', 'basket_id' => '', 'bpid' => '', 'site_id' => '', 'delivery_id' => '', 'pvid' => '', 'messages' => $payment_message_array)); if (!is_numeric($payment_transaction_id)) { debug_print("ERROR: 372755 ", array('Level' => 'WARNING', 'Scope' => 'PayPal API', 'File ' => __FILE__ . ' at line ' . __LINE__, 'Details' => array('Message' => 'Did not receive transaction_id when posting PayPal payment', 'IPN Data' => $_POST))); } } else { die(debug_print("ERROR: 879023 ", array('Level' => 'FATAL', 'Scope' => 'PayPal API', 'File ' => __FILE__ . ' at line ' . __LINE__, 'Details' => array('Message' => 'Custom field (' . $_POST['custom'] . ') insufficient to determine PayPal credit target', 'IPN Data' => $_POST)))); } } } // Use an array like the following to preload values and call the function with // paypal_display_form ($paypal_arguments) // // $paypal_arguments = array ( // 'form_id' => 'paypal_form1', // 'span1_content' => 'Pay $', // 'span2_content' => ' now with PayPal',
$new_bpid = $_REQUEST['bpid']; // Site ID $new_site_id = $_REQUEST['site_id']; // Delivery ID $new_delivery_id = $_REQUEST['delivery_id']; // Product/Version ID $new_pvid = $_REQUEST['pvid']; // Message $new_messages = $_REQUEST['adjustment_message']; include_once 'func.update_ledger.php'; $messages = array(); if ($_REQUEST['adjustment_message'] != '') { $messages['ledger comment'] = $_REQUEST['adjustment_message']; } // Add the transaction into the ledger $ledger_status = add_to_ledger(array('source_type' => $new_source_type, 'source_key' => $new_source_key, 'target_type' => $new_target_type, 'target_key' => $new_target_key, 'amount' => $new_amount, 'text_key' => $new_text_key, 'posted_by' => $_SESSION['member_id'], 'effective_datetime' => $new_effective_datetime, 'basket_id' => $new_basket_id, 'bpid' => $new_bpid, 'site_id' => $new_site_id, 'delivery_id' => $new_delivery_id, 'pvid' => $new_pvid, 'messages' => $messages)); // Having completed the update, we need to do two things: // 1. Replace the transaction row we just modified // 2. Get the new transaction // $transaction_data = get_transaction($target); // if (count ($transaction_data)) $row_markup = get_transaction_row ($transaction_data); // // Now take the replaced_by to get the new transaction information // $new_transaction_data = get_transaction($transaction_data['replaced_by']); // if (count ($new_transaction_data)) $row_markup .= get_transaction_row ($new_transaction_data); // By returning BOTH rows (actually tbody elements, we insert them together echo $row_markup; } function get_heading_row() { // Set some classes if ($transaction_data['replaced_by'] != '') {
function renew_membership($member_id, $membership_type_id) { global $connection; // First see if the member can sign up for this particular membership_type $membership_info = get_membership_info($member_id); $renewal_info = check_membership_renewal($membership_info); // Compare the member's current membership_type to what they have requested if (!in_array($membership_type_id, explode(',', $membership_info['may_convert_to']))) { // Requested membership_type is not allowed for this membership_type return 'Requested membership_type is not allowed.'; } // Check if this member can renew at the requested membership_type $query_membership_type = ' SELECT * FROM ' . TABLE_MEMBERSHIP_TYPES . ' WHERE ( enabled_type = "2" OR enabled_type = "3") AND FIND_IN_SET(membership_type_id,"' . $membership_info['may_convert_to'] . '")'; $result_membership_type = mysql_query($query_membership_type, $connection) or die(debug_print("ERROR: 683080 ", array($query_membership_type, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__)); if (!($row_membership_type = mysql_fetch_array($result_membership_type))) { // Requested membership_type is not allowed return 'Requested membership_type is not allowed.'; } // Everything is good to here... so prepare to post the membership. // When switching membership types, we will use the suggested_renewal_date for the // new membership_renewal_date. When keeping the same membership type, we will // use the standard_renewal_date. if ($renewal_info['membership_expired'] == false && $renewal_info['membership_type_id'] == $row_membership_type['membership_type_id']) { $renewal_date = $renewal_info['standard_renewal_date']; } elseif ($renewal_info['suggested_renewal_date'] != '') { $renewal_date = $renewal_info['suggested_renewal_date']; } else { $renewal_date = date('Y-m-d', time()); } // If this is a renewal, then we use the renewal costs but if it // is a switch to a different type, then we use the initial cost if ($membership_info['membership_type_id'] == $membership_type_id) { // Renewal $target_field = 'renew_cost'; } else { // Switch type $target_field = 'initial_cost'; } // Post the membership receivable $transaction_row = add_to_ledger(array('transaction_group_id' => '', 'source_type' => 'member', 'source_key' => $member_id, 'target_type' => 'internal', 'target_key' => 'membership_dues', 'amount' => $row_membership_type[$target_field], 'text_key' => 'membership dues', 'posted_by' => $_SESSION['member_id'])); // Now update the members table $query_members = ' UPDATE ' . TABLE_MEMBER . ' SET last_renewal_date = "' . mysql_real_escape_string($renewal_date) . '", membership_type_id = "' . mysql_real_escape_string($membership_type_id) . '" WHERE member_id = "' . mysql_real_escape_string($member_id) . '"'; $result_members = mysql_query($query_members, $connection) or die(debug_print("ERROR: 683080 ", array($query_members, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__)); if (mysql_affected_rows()) { return 'Successfully updated membership.'; } }
$transaction_group_id = get_new_transaction_group_id(); include_once 'func.update_ledger.php'; $paypal_transaction_id = add_to_ledger(array('transaction_group_id' => $transaction_group_id, 'source_type' => 'internal', 'source_key' => 'paypal charges', 'target_type' => 'internal', 'target_key' => 'payment sent', 'amount' => $_POST['paypal_fee'], 'text_key' => 'paypal charges', 'effective_datetime' => $_POST['effective_datetime'], 'posted_by' => $_SESSION['member_id'], 'replaced_by' => '', 'timestamp' => '', 'basket_id' => $row['basket_id'], 'bpid' => '', 'site_id' => $row['site_id'], 'delivery_id' => $row['delivery_id'], 'pvid' => '', 'messages' => $paypal_message_array)); if (!is_numeric($paypal_transaction_id)) { array_push($error_array, 'DATABASE ERROR: Problem posting the paypal payment.'); } } // if no errors, then post the payment, if any if (count($error_array) == 0 && $_POST['amount'] != 0) { // For negative payments received (payments MADE TO members), we will change the source_key to match $text_key = 'payment received'; if ($_POST['amount'] < 0) { $text_key = 'payment made'; } include_once 'func.update_ledger.php'; $payment_transaction_id = add_to_ledger(array('transaction_group_id' => $transaction_group_id, 'source_type' => 'internal', 'source_key' => $text_key, 'target_type' => 'member', 'target_key' => $_POST['member_id'], 'amount' => $_POST['amount'], 'text_key' => $text_key, 'effective_datetime' => $_POST['effective_datetime'], 'posted_by' => $_SESSION['member_id'], 'replaced_by' => '', 'timestamp' => '', 'basket_id' => $row['basket_id'], 'bpid' => '', 'site_id' => $row['site_id'], 'delivery_id' => $row['delivery_id'], 'pvid' => '', 'messages' => $payment_message_array)); if (!is_numeric($payment_transaction_id)) { array_push($error_array, 'DATABASE ERROR: Problem posting the customer payment.'); } } // All done, so return what we know... if (count($error_array) == 0) { $return_content = 'ACCEPT '; } else { $error_message = ' <div class="error_message"> <p class="message">The information was not accepted. Please correct the following problems and resubmit. <ul class="error_list"> <li>' . implode("</li>\n<li>", $error_array) . '</li> </ul> </p>