=== modified file 'uc_order/uc_order.install' --- uc_order/uc_order.install 2009-01-30 15:57:34 +0000 +++ uc_order/uc_order.install 2009-02-19 21:43:11 +0000 @@ -370,6 +370,10 @@ 'not null' => TRUE, 'default' => 0, ), + 'data' => array( + 'description' => t('Serialized array of extra data.'), + 'type' => 'text', + ), ), 'indexes' => array( 'order_id' => array('order_id'), @@ -907,3 +911,13 @@ return $ret; } + +// add data field to uc_order_line_items +function uc_order_update_6007() { + + $ret = array(); + + db_add_field($ret, 'uc_order_line_items', 'data', array('type' => 'text')); + + return $ret; +} === modified file 'uc_order/uc_order.line_item.inc' --- uc_order/uc_order.line_item.inc 2008-10-15 20:20:43 +0000 +++ uc_order/uc_order.line_item.inc 2009-02-19 16:23:32 +0000 @@ -91,12 +91,12 @@ return TRUE; } -function uc_order_line_item_add($order_id, $type, $title, $amount, $weight = NULL) { +function uc_order_line_item_add($order_id, $type, $title, $amount, $weight = NULL, $data = NULL) { if (is_null($weight)) { $weight = _line_item_data($type, 'weight'); } - db_query("INSERT INTO {uc_order_line_items} (order_id, type, title, amount, weight) VALUES (%d, '%s', '%s', %f, %d)", $order_id, $type, $title, $amount, $weight); + db_query("INSERT INTO {uc_order_line_items} (order_id, type, title, amount, weight, data) VALUES (%d, '%s', '%s', %f, %d, '%s')", $order_id, $type, $title, $amount, $weight, serialize( $data )); return TRUE; } === modified file 'uc_order/uc_order.module' --- uc_order/uc_order.module 2009-02-20 18:39:24 +0000 +++ uc_order/uc_order.module 2009-02-23 21:09:24 +0000 @@ -1180,6 +1180,7 @@ 'title' => $row->title, 'amount' => $row->amount, 'weight' => $row->weight, + 'data' => unserialize( $row->data ), ); } } @@ -1198,6 +1199,7 @@ 'title' => $line['title'], 'amount' => $line['amount'], 'weight' => isset($line['weight']) ? $line['weight'] : $type['weight'], + 'data' => $line['data'], ); } } @@ -1436,6 +1438,7 @@ 'title' => $line['title'], 'amount' => $line['amount'], 'weight' => $item['weight'], + 'data' => $item['data'], ); } } === modified file 'uc_taxes/uc_taxes.ca.inc' --- uc_taxes/uc_taxes.ca.inc 2009-02-20 20:55:23 +0000 +++ uc_taxes/uc_taxes.ca.inc 2009-02-23 21:09:24 +0000 @@ -77,13 +77,14 @@ */ function uc_taxes_action_apply_tax($order, $tax) { $amount = 0; + $taxable_amount = 0; if (is_array($order->products)) { foreach ($order->products as $item) { $node = node_load($item->nid); // Tax products if they are of a taxed type and if it is shippable if // the tax only applies to shippable products. if (in_array($node->type, $tax->taxed_product_types) && ($tax->shippable == 0 || $node->shippable == 1)) { - $amount += $item->price * $item->qty * $tax->rate; + $taxable_amount += $item->price * $item->qty; } } } @@ -95,17 +96,23 @@ continue; } if (in_array($line_item['type'], $taxed_line_items)) { - $amount += $line_item['amount'] * $tax->rate; + $taxable_amount += $line_item['amount']; } } } if (isset($taxed_line_items['tax'])) { foreach ($order->taxes as $other_tax) { - $amount += $other_tax->amount * $tax->rate; + $taxable_amount += $other_tax['amount']; } } + $amount = $taxable_amount * $tax->rate; if ($amount) { $line_item = (object)array('id' => $tax->id, 'name' => $tax->name, 'amount' => $amount, 'weight' => $tax->weight); + $line_item->data = array( + 'tax_rate' => $tax->rate, + 'taxable_amount' => $taxable_amount, + 'tax_jurisdiction' => $tax->name, + ); return $line_item; } } === modified file 'uc_taxes/uc_taxes.install' --- uc_taxes/uc_taxes.install 2009-02-19 20:44:23 +0000 +++ uc_taxes/uc_taxes.install 2009-02-23 21:09:24 +0000 @@ -266,3 +266,36 @@ return $ret; } + +function uc_taxes_update_6003() { + $ret = array(); + + // Populate the new data column in uc_order_line_items with tax information. + if (db_column_exists('uc_order_line_items', 'data')) { + $result = db_query("SELECT name, rate FROM {uc_taxes}"); + while ($tax = db_fetch_object($result)) { + $lines = db_query("SELECT * FROM {uc_order_line_items} WHERE type = 'tax' AND title = '%s'", $tax->name); + while ($line_item = db_fetch_object($lines)) { + drupal_set_message('
'. print_r($line_item, TRUE) .'
'); + if (empty($line_item->data) || $line_item->data == 'N;') { + $data = array( + 'tax_rate' => $tax->rate, + // Fudge the taxable amount just a little. + 'taxable_amount' => $line_item->amount / $tax->rate, + 'tax_jurisdiction' => $tax->name, + ); + + drupal_set_message('
'. print_r($data, TRUE) .'
'); + db_query("UPDATE {uc_order_line_items} SET data = '%s' WHERE line_item_id = %d", serialize($data), $line_item->line_item_id); + } + } + } + $ret[] = array('success' => TRUE, 'query' => t('Added tax information to existing tax line items.')); + } + else { + drupal_set_message(t('Some updates are still pending. Please return to update.php and run the remaining updates.', array('@update-php' => base_path() .'update.php?op=selection')), 'warning', FALSE); + $ret['#abort'] = array('success' => FALSE, 'query' => t('Some updates are still pending.
Please re-run the update script.')); + } + + return $ret; +} === modified file 'uc_taxes/uc_taxes.module' --- uc_taxes/uc_taxes.module 2009-02-19 20:44:23 +0000 +++ uc_taxes/uc_taxes.module 2009-02-23 21:09:24 +0000 @@ -151,8 +151,10 @@ foreach ($arg1->line_items as $line) { if ($line['type'] == 'tax') { $delete = TRUE; + $sdata = serialize( $line['data'] ); foreach ($line_items as $id => $new_line) { - if ($new_line['title'] == $line['title']) { + if ($new_line['title'] == $line['title'] && + serialize( $new_line['data'] ) == $sdata) { if ($new_line['amount'] != $line['amount']) { uc_order_update_line_item($line['line_item_id'], $new_line['title'], $new_line['amount']); $changes[] = t('Changed %title to %amount.', array('%amount' => uc_currency_format($new_line['amount']), '%title' => $new_line['title'])); @@ -171,7 +173,7 @@ } if (is_array($line_items)) { foreach ($line_items as $line) { - uc_order_line_item_add($arg1->order_id, $line['id'], $line['title'], $line['amount'], $line['weight']); + uc_order_line_item_add($arg1->order_id, $line['id'], $line['title'], $line['amount'], $line['weight'], $line['data']); $changes[] = t('Added %amount for %title.', array('%amount' => uc_currency_format($line['amount']), '%title' => $line['title'])); } } @@ -215,6 +217,7 @@ 'title' => $tax->name, 'amount' => $tax->amount, 'weight' => variable_get('uc_li_tax_weight', 9) + $tax->weight / 10, + 'data' => $tax->data, ); } return $lines;