Esempio n. 1
0
function add_to_ledger($data)
{
    // debug_print ("INFO: 2 ", $data, basename(__FILE__).' LINE '.__LINE__);
    global $connection;
    // Create the insert "SET" clauses
    $ledger_fields = array('transaction_group_id', 'source_type', 'source_key', 'target_type', 'target_key', 'amount', 'text_key', 'effective_datetime', 'posted_by', 'replaced_by', 'timestamp', 'basket_id', 'bpid', 'site_id', 'delivery_id', 'pvid');
    $query_set_array = array();
    // If we do not already have a source_key, then lookup account_number for internal source_type
    if ($data['source_type'] == 'internal' && !is_numeric($data['source_key'])) {
        $data['source_key'] = get_internal_account_id($data['source_key'], $data['text_key']);
    }
    // If we do not already have a target_key, then lookup account_number for internal target_type
    if ($data['target_type'] == 'internal' && !is_numeric($data['target_key'])) {
        $data['target_key'] = get_internal_account_id($data['target_key'], $data['text_key']);
    }
    // If effective_datetime is not set, then use the current datetime
    if (strtotime($data['effective_datetime'])) {
        $data['effective_datetime'] = date('Y-m-d H:i:s', strtotime($data['effective_datetime']));
    } else {
        $data['effective_datetime'] = date('Y-m-d H:i:s', time());
    }
    // Cycle through all the possible fields
    foreach ($ledger_fields as $field) {
        // Add "SET" values to any fields that have data to post except the transaction_id,
        // which is auto-increment and may not be specified on an INSERT.
        if ($data[$field]) {
            $query_set = $field . ' = "' . mysql_real_escape_string($data[$field]) . '"';
            array_push($query_set_array, $query_set);
        }
    }
    // Combine the "SET" clauses with commas
    $query_set = implode(",\n        ", $query_set_array);
    $query = '
      INSERT INTO ' . NEW_TABLE_LEDGER . '
      SET
        ' . $query_set;
    $result = mysql_query($query, $connection) or die(debug_print("ERROR: 850302 ", array($query, mysql_error()), basename(__FILE__) . ' LINE ' . __LINE__));
    $new_transaction_id = mysql_insert_id();
    $affected_rows = mysql_affected_rows();
    if ($affected_rows != 1) {
        die(debug_print("ERROR: 860324 ", "Data error. Updates ({$affected_rows}) not equal to one", basename(__FILE__) . ' LINE ' . __LINE__));
    }
    // Now go post any transaction messages
    add_transaction_messages($new_transaction_id, $data['messages']);
    return $new_transaction_id;
}
        // ID for the logged-in member
        $new_ledger_info['posted_by'] = $_SESSION['member_id'];
        // Keep all this stuff the same as before
        $new_ledger_info['basket_id'] = $row_old_ledger_info['basket_id'];
        $new_ledger_info['bpid'] = $row_old_ledger_info['bpid'];
        $new_ledger_info['site_id'] = $row_old_ledger_info['site_id'];
        $new_ledger_info['delivery_id'] = $row_old_ledger_info['delivery_id'];
        $new_ledger_info['pvid'] = $row_old_ledger_info['pvid'];
        // We are targeting a specific transaction_id
        //        $new_ledger_info['match_keys'] = array ('transaction_id');
        // Create the messages array
        $messages['ledger comment'] = $_REQUEST['message'];
        $new_ledger_info['messages'] = $messages;
        // Post the updated transaction
        $affected_transaction_id = add_transaction($new_ledger_info);
        $response .= add_transaction_messages($affected_transaction_id, $new_ledger_info['messages']);
    }
    echo $response;
    exit(0);
}
////////////////////////////////////////////////////////////////////////////////////
//                                                                                //
// This is the main ajax call to get ledger information for display of            //
// the adjustment form controls. It will also get display basket information,     //
// if there is one and handle updates from the form.                              //
//                                                                                //
// REQUIRED arguments:               transaction_id=[transaction_id]              //
// OPTIONAL arguments:                         bpid=[basket product id]           //
//                                                                                //
////////////////////////////////////////////////////////////////////////////////////
// Get the adjustment dialogue for changing, deleting, or adding adjustments