/[drupal]/contributions/modules/openresort/openresort.ecommerce.patch
ViewVC logotype

Contents of /contributions/modules/openresort/openresort.ecommerce.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download) (as text)
Sun Jan 27 22:20:59 2008 UTC (22 months ago) by marcingy
Branch: MAIN
CVS Tags: DRUPAL-5--1-16-6, HEAD
Changes since 1.8: +18 -17 lines
File MIME type: text/x-patch
*** empty log message ***
1 Index: cart/cart.module
2 ===================================================================
3 --- cart/cart.module (revision 2661)
4 +++ cart/cart.module (working copy)
5 @@ -8,14 +8,15 @@
6 /**
7 * Declare a block or set of blocks
8 */
9 -function cart_block($op = "list", $delta = 0, $edit = array()) {
10 + //TODO convert shopping cart block to display bookings/itenary
11 +/*function cart_block($op = "list", $delta = 0, $edit = array()) {
12 if ($op == 'list') {
13 $blocks[0]['info'] = t('Shopping Cart');
14 return $blocks;
15 }
16 /* We don't need to display this on the cart page. */
17 //elseif ($_GET['q'] != "cart" && !strstr($_GET['q'], "cart/")) {
18 - else if ($op == 'view') {
19 + /*else if ($op == 'view') {
20 switch($delta) {
21 case 0:
22 $item_count = count(cart_get_items());
23 @@ -35,14 +36,14 @@
24 elseif ($op == 'save' && isset($edit['cart_empty_hide'])) {
25 variable_set('cart_empty_hide', $edit['cart_empty_hide']);
26 }
27 -}
28 +}*/
29
30 /**
31 * Perform periodic actions
32 */
33 function cart_cron() {
34 // Remove items from the cart table that haven't been touched for more than a month.
35 - db_query('DELETE FROM {ec_cart} WHERE changed < %d', strtotime('Last month'));
36 + db_query('DELETE FROM {ec_cart} WHERE changed < %d', strtotime('-'.variable_get('accommodation_hold_cust_time',900).' seconds'));
37 // Optimize table query removed - users can now install DB maintenance module
38 // for this.
39 }
40 @@ -292,14 +293,23 @@
41 }
42
43 // Build the cart form
44 + $breadcrumbs[] = l(t('Home'), "");
45 + drupal_set_breadcrumb($breadcrumbs);
46 $items = cart_get_items();
47 if ($items) {
48 return drupal_get_form('cart_view_form', $items);
49 }
50 else {
51 - return '<p>'. t('Your shopping cart is empty. You may continue shopping from our !product-page.', array('!product-page' => l(t('Product page'), 'product'))). '</p>';
52 + drupal_set_title('itinerary');
53 + if (module_exists('openresort')){
54 + return openresort_empty_cart();
55 + }else{
56 + //single property only so we take the ecommerce enable business
57 + $result = db_result(db_query('SELECT nid FROM {business} WHERE ecommerce = 1'));
58 + return '<p>'. t('Your itinerary is empty. You may add to it by clicking !product-page.', array('!product-page' => l(t('here'), 'node/'.$result))). '</p>';
59 }
60 }
61 +}
62
63 /**
64 * This is a form to handle the cart view
65 @@ -308,36 +318,47 @@
66 $form['items'] = array('#tree' => TRUE);
67 foreach ($items as $i) {
68 $node = node_load($i->nid);
69 - $form['items'][$node->nid]['#node'] = $node;
70 - $form['items'][$node->nid]['title'] = array(
71 + $form['items'][$node->nid.'-'.$i->changed]['#node'] = $node;
72 + $form['items'][$node->nid.'-'.$i->changed]['title'] = array(
73 '#value' => l($node->title, "node/". ($node->pparent ? $node->pparent : $node->nid))
74 );
75 - $form['items'][$node->nid]['#total'] = product_has_quantity($node) ? $i->price * $i->qty : $i->price;
76 - $form['items'][$node->nid]['#specials'] = product_get_specials($i, 'cart', TRUE);
77 + $form['items'][$node->nid.'-'.$i->changed]['#total'] = $i->price;
78 + $form['items'][$node->nid.'-'.$i->changed]['#specials'] = product_get_specials($i, 'cart', true);
79 if ($node->is_recurring) {
80 - $form['items'][$node->nid]['recurring'] = array(
81 + $form['items'][$node->nid.'-'.$i->changed]['recurring'] = array(
82 '#value' => theme('recurring_schedule', $node->schedule)
83 );
84 }
85 if ($node->ptype == 'tangible' && $node->availability != NULL && $node->availability != 1) {
86 - $form['items'][$node->nid]['availability'] = array(
87 + $form['items'][$node->nid.'-'.$i->changed]['availability'] = array(
88 '#value' => availability_get_message($node->availability)
89 );
90 }
91 + //we need to add something in here to deal with nights stay
92 + //and arrival date
93 + $subitem = $i->subitem;
94 + //unit type is also required
95 + //change this so as we use the key - we also need to read from accom inventory
96 + //and join on the node table
97 + while($key = key($subitem)){
98 + //foreach ($subitem as $s){
99 + $form['items'][$node->nid.'-'.$i->changed]['#arrive'] = $subitem[$key]->date;
100 + $form['items'][$node->nid.'-'.$i->changed]['#unitname'] = db_result(db_query("SELECT title FROM node n inner join accommodation_inventory i on n.nid = i.unit_id inner join accommodation_availability a on a.iid = i.iid where a.aid = " . $key ));
101 + break;
102 + }
103 + $form['items'][$node->nid.'-'.$i->changed]['#days'] = $i->days;
104 +
105 if (product_has_quantity($node)) {
106 - $form['items'][$node->nid]['qty'] = array(
107 + //commented out so as no quantity displayed for booking
108 + //will need to readd and think of another solution once we
109 + //have activities
110 + /*$form['items'][$node->nid]['qty'] = array(
111 '#type' => 'textfield',
112 '#default_value' => $i->qty,
113 '#size' => 2,
114 '#maxlength' => 2
115 - );
116 + );*/
117 }
118 - else {
119 - $form['items'][$node->nid]['qty'] = array(
120 - '#type' => 'value',
121 - '#value' => $i->qty,
122 - );
123 - }
124
125 if ($extra = product_invoke_productapi($i, 'cart form')) {
126 $form['items'][$node->nid]['extra'] = $extra;
127 @@ -345,8 +366,7 @@
128 }
129 }
130
131 - $form['submit'] = array('#type' => 'submit', '#value' => t('Update Cart'));
132 - $form['checkout'] = array('#type' => 'submit', '#value' => t('Checkout'));
133 + $form['checkout'] = array('#type' => 'submit', '#value' => t('book it'));
134
135 return $form;
136 }
137 @@ -361,7 +381,7 @@
138 cart_update_item_object((object)$form_values);
139 return 'cart/view';
140
141 - case t('Checkout'):
142 + case t('book it'):
143 // force it not to validate so we see the update quantity page again.
144 return 'cart/checkout';
145 }
146 @@ -573,7 +593,7 @@
147 drupal_goto('cart/checkout', 'op=next');
148 }
149
150 - drupal_set_title(t('Please review and submit your order'));
151 + drupal_set_title(t('Please review and submit your itinerary'));
152
153 foreach ($data->review_screens as $module) {
154 $function = "{$module}_checkoutapi";
155 @@ -585,7 +605,7 @@
156 }
157 }
158
159 - $form['submit'] = array('#type' => 'submit', '#value' => t('Place your order'));
160 + $form['submit'] = array('#type' => 'submit', '#value' => t('book it'));
161
162 $form['txn'] = array(
163 '#type' => 'value',
164 @@ -636,7 +656,7 @@
165
166 // If the user is submitting the order then process it, other-wise just
167 // save it.
168 - if ($form_values['op'] == t('Place your order')) {
169 + if ($form_values['op'] == t('book it')) {
170
171 // Make sure we have a user id
172 if (!$txn->uid) {
173 @@ -735,16 +755,24 @@
174 $price = store_adjust_misc($txn, $product);
175 $node = node_load($product->nid);
176 $subtotal = product_has_quantity($node) ? ($price * $product->qty) : $price;
177 -
178 - $form['items'][$product->nid] = array(
179 + $subitem = $product->subitem;
180 + $txn->subtotal += $subtotal;
181 + foreach ($subitem as $s){
182 + $date = $s->date;
183 + break;
184 + }
185 + $itemdata = $product;
186 + $form['items'][$product->nid.'-'.$product->changed] = array(
187 'qty' => array('#value' => product_has_quantity($node) ? $product->qty : ''),
188 - 'item' => array('#type' => 'value', '#value' => $product), // allow more info to be displayed by the theme
189 + 'item' => array('#type' => 'value', '#value' => $itemdata), // allow more info to be displayed by the theme
190 'price' => array('#value' => $price),
191 - 'subtotal' => array('#value' => $subtotal),
192 + 'subtotal' => array('#value' => $txn->subtotal),
193 + 'days' => array('#value' => $product->days),
194 + 'date' => array('#value' => $date),
195 + 'ptype' => array('#value' => $node->ptype),
196 'options' => array('#value' => $txn->type == 'cart' ? l(t('Change'), 'cart/view') : '')
197 );
198
199 - $txn->subtotal += $subtotal;
200 }
201
202 $form['totals'] = array();
203 @@ -1042,7 +1070,22 @@
204 function cart_remove_item($nid) {
205
206 if (!$nid) return NULL;
207 - db_query("DELETE FROM {ec_cart} WHERE cookie_id = '%s' AND nid = %d", cart_get_id(), $nid);
208 + $splitkey = explode('-',$nid);
209 + //need to update accommodation availability
210 + //subitem in the data field will give aid - go through the key
211 + if(module_exists('accommodation')){
212 + $transaction = db_fetch_object(db_query("SELECT * FROM {ec_cart} WHERE cookie_id = '%s' AND nid = %d AND changed= %d", cart_get_id(), $splitkey[0],$splitkey[1]));
213 + //need to work out how to upack the object
214 + $transaction = unserialize($transaction->data);
215 + $localsubitem = $transaction->subitem;
216 + while($key = key($localsubitem)){
217 + //use the aid to local up the iid
218 + $row = db_fetch_object(db_query("SELECT iid,date from accommodation_availability where aid = ".$key));
219 + db_query("UPDATE accommodation_availability SET reserved_date = '". date('Y-m-d H:i:s',time()) ."' WHERE aid = " . $key);
220 + next($localsubitem);
221 + }
222 + }
223 + db_query("DELETE FROM {ec_cart} WHERE cookie_id = '%s' AND nid = %d AND changed= %d", cart_get_id(), $splitkey[0],$splitkey[1]);
224 drupal_set_message(t('Your item has been removed.'));
225 cache_clear_all();
226 }
227 @@ -1085,11 +1128,12 @@
228 while ($cart = db_fetch_object($result)) {
229 $cart = drupal_unpack($cart, 'data');
230 $p = product_load($cart);
231 - foreach ($p as $key => $value) {
232 - $cart->$key = $value;
233 + //foreach ($p as $key => $value) {
234 + // $cart->$key = $value;
235 + //}
236 + //change so as based on the key for none quantity driven items
237 + $items[$id][$cart->nid.$cart->changed] = $cart;
238 }
239 - $items[$id][$cart->nid] = $cart;
240 - }
241 if (!$items[$id]) {
242 $items[$id] = array();
243 }
244 Index: ec_anon/ec_anon.install
245 ===================================================================
246 --- ec_anon/ec_anon.install (revision 2484)
247 +++ ec_anon/ec_anon.install (working copy)
248 @@ -3,7 +3,9 @@
249 * @author Sammy Spets thanks to Synerger Pty Ltd
250 */
251
252 +if(function_exists('drupal_get_path')){
253 require_once (drupal_get_path('module', 'ec_anon') .'/ec_anon.module');
254 +}
255
256 /**
257 * Installs E-Commerce anonymous purchasing tables into the database
258 @@ -51,8 +53,13 @@
259 }
260 variable_set('ec_anon_policy', $newval);
261
262 + if(function_exists('ec_anon_policy_list')){
263 $plist = ec_anon_policy_list(false);
264 drupal_set_message(t('Anonymous purchasing policy for the site has been set to <b>!policy</b>. You can change it on the <a href="@settingsurl">store settings page</a>.',
265 array('!policy' => $plist[$newval], '@settingsurl' => url('admin/ecsettings'))));
266 + }
267 }
268
269 +
270 +
271 +
272 Index: ec_anon/ec_anon.module
273 ===================================================================
274 --- ec_anon/ec_anon.module (revision 2484)
275 +++ ec_anon/ec_anon.module (working copy)
276 @@ -422,7 +422,8 @@
277 $form['mail'] = array(
278 '#type' => 'textfield',
279 '#title' => t('Email'),
280 - '#default_value' => $txn->mail
281 + '#default_value' => $txn->mail,
282 + '#required' => true,
283 );
284 $form[] = array('#type' => 'submit', '#value' => t('Continue'));
285
286 Index: ec_mail/ec_mail.install
287 ===================================================================
288 --- ec_mail/ec_mail.install (revision 2484)
289 +++ ec_mail/ec_mail.install (working copy)
290 @@ -4,9 +4,10 @@
291 * ec_mail.install
292 * @author Sammy Spets thanks to Synerger Pty Ltd
293 */
294 +if(function_exists('drupal_get_path')){
295 + require_once(drupal_get_path('module', 'store') . '/store.deps.inc');
296 +}
297
298 -require_once(drupal_get_path('module', 'store') . '/store.deps.inc');
299 -
300 /**
301 * ec_mail_install()
302 *
303 @@ -44,6 +45,7 @@
304 }
305 }
306
307 +
308 /**
309 * Implementation of hook_uninstall().
310 *
311 @@ -54,4 +56,4 @@
312 if (db_table_exists('ec_mail')) {
313 db_query('DROP TABLE {ec_mail}');
314 }
315 -}
316 \ No newline at end of file
317 +}
318 Index: product/product.install
319 ===================================================================
320 --- product/product.install (revision 2484)
321 +++ product/product.install (working copy)
322 @@ -1,8 +1,9 @@
323 <?php
324 // $Id: product.install,v 1.7.4.2.2.2 2007/07/27 04:53:22 gordon Exp $
325 +if(function_exists('drupal_get_path')){
326 + require_once(drupal_get_path('module', 'store') . '/store.deps.inc');
327 +}
328
329 -require_once(drupal_get_path('module', 'store') . '/store.deps.inc');
330 -
331 /**
332 * E-Commerce product module schema
333 */
334 Index: store/store.inc
335 ===================================================================
336 --- store/store.inc (revision 2484)
337 +++ store/store.inc (working copy)
338 @@ -41,16 +41,16 @@
339 if (db_result(db_query('SELECT COUNT(txnid) FROM {ec_transaction_address} WHERE txnid = %d AND type = \'%s\'', $address->txnid, $type))) {
340 db_query('UPDATE {ec_transaction_address} ' .
341 "SET firstname = '%s', lastname = '%s', street1 = '%s', street2 = '%s', " .
342 - "zip = '%s', city = '%s', state = '%s', country = '%s' " .
343 + "zip = '%s', city = '%s', state = '%s', country = '%s',phone = '%s' " .
344 "WHERE txnid = %d AND type = '%s'",
345 $address->firstname, $address->lastname, $address->street1, $address->street2,
346 - $address->zip, $address->city, $address->state, $address->country, $address->txnid, $type);
347 + $address->zip, $address->city, $address->state, $address->country,$address->phone, $address->txnid, $type);
348 }
349 else {
350 - db_query('INSERT INTO {ec_transaction_address} (firstname, lastname, street1, street2, zip, city, state, country, txnid, type) VALUES' .
351 - "('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s')",
352 + db_query('INSERT INTO {ec_transaction_address} (firstname, lastname, street1, street2, zip, city, state, country,phone, txnid, type) VALUES' .
353 + "('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s','%s', %d, '%s')",
354 $address->firstname, $address->lastname, $address->street1, $address->street2,
355 - $address->zip, $address->city, $address->state, $address->country, $address->txnid, $type);
356 + $address->zip, $address->city, $address->state, $address->country,$address->phone, $address->txnid, $type);
357 }
358 }
359
360 @@ -380,6 +380,16 @@
361 '#default_value' => ($address->country ? $address->country : variable_get('ec_country', '')),
362 '#options' => store_build_countries(),
363 );
364 + $form['phone'] = array(
365 + '#type' => 'textfield',
366 + '#title' => t('Phone Number'),
367 + '#default_value' => $address->phone,
368 + '#size' => 50,
369 + '#maxlength' => 100,
370 + '#description' => null,
371 + '#attributes' => null,
372 + '#required' => false,
373 + );
374 return $form;
375 }
376
377 Index: store/store.install
378 ===================================================================
379 --- store/store.install (revision 2484)
380 +++ store/store.install (working copy)
381 @@ -1,7 +1,9 @@
382 <?php
383 // $Id: store.install,v 1.20.2.1.2.12.2.11 2007/07/27 13:10:56 gordon Exp $
384
385 +if(function_exists('drupal_get_path')){
386 require_once(drupal_get_path('module', 'store') . '/store.deps.inc');
387 +}
388
389 /**
390 * E-Commerce store.module schema
391 @@ -39,6 +41,7 @@
392 city varchar(32) NOT NULL default '',
393 state varchar(32) NOT NULL default '',
394 country varchar(2) NOT NULL default '',
395 + phone varchar(45) NOT NULL default '',
396 PRIMARY KEY (txnid,type)
397 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
398 db_query("CREATE TABLE {ec_transaction_product} (
399 @@ -49,7 +52,10 @@
400 price decimal(10,2) NOT NULL default '0.00',
401 qty int(10) unsigned NOT NULL default '0',
402 data text,
403 - UNIQUE KEY txnid (txnid,nid),
404 + last_notify INTEGER UNSIGNED NOT NULL default 0,
405 + dataid INTEGER UNSIGNED NOT NULL default 0,
406 + item_status INTEGER UNSIGNED NOT NULL default 0,
407 + PRIMARY KEY(txnid, nid, last_notify),
408 KEY txnid_2 (txnid)
409 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
410 db_query("CREATE TABLE {ec_transaction_misc} (
411 Index: store/store.module
412 ===================================================================
413 --- store/store.module (revision 2661)
414 +++ store/store.module (working copy)
415 @@ -81,7 +81,12 @@
416 day and then adjust the shipping workflow after a given time period, such
417 as 2 week (in case of returns or something) rather than automatically
418 closing it here. */
419 - db_query('UPDATE {ec_transaction} SET workflow = 6 WHERE workflow = 3 AND payment_status = 2');
420 + $query = db_query("SELECT txnid FROM {ec_transaction} WHERE workflow = 1 AND payment_status = 1 AND changed < '".strtotime('-'.variable_get('accommodation_hold_cust_time',900).' seconds')."'");
421 + while($txnid = db_fetch_object($query)){
422 + $t = store_transaction_load($txnid->txnid);
423 + $t->workflow = 5;
424 + store_transaction_save($t);
425 + }
426
427 if (variable_get('payment_notices', 0)) {
428 global $base_url;
429 @@ -640,10 +645,10 @@
430 */
431 function store_transaction_workflow() {
432 $transaction_workflow = array (
433 - EC_WORKFLOW_RECEIVED => t('received'),
434 - EC_WORKFLOW_INVOICED => t('invoiced'),
435 - EC_WORKFLOW_SHIPPED => t('shipped'),
436 - EC_WORKFLOW_AWAITING_RESPONSE => t('awaiting customer response'),
437 + EC_WORKFLOW_RECEIVED => t('booking received'),
438 + EC_WORKFLOW_INVOICED => t('awaiting accommodator response'),
439 + EC_WORKFLOW_SHIPPED => t('booking confirmed'),
440 + EC_WORKFLOW_AWAITING_RESPONSE => t('accommodator payed'),
441 EC_WORKFLOW_CANCELED => t('canceled'),
442 EC_WORKFLOW_COMPLETED => t('completed'),
443 EC_WORKFLOW_SECURITY_VIOLATION => t('security violation'),
444 @@ -748,7 +753,7 @@
445 }
446
447 function store_transaction_product_fields() {
448 - return array('txnid', 'nid', 'vid', 'title', 'price', 'qty', 'data');
449 + return array('txnid', 'nid', 'vid', 'title', 'price', 'qty', 'data','last_notify','dataid','item_status');
450 }
451
452 function store_transaction_misc_fields() {
453 @@ -925,29 +930,55 @@
454 * Save transaction products.
455 */
456 function store_transaction_save_product($item) {
457 - static $product_cache = array();
458 + //static $product_cache = array();
459 $product_fields = store_transaction_product_fields();
460 -
461 - if (!$product_cache[$item->txnid]) {
462 + if(!$item->last_notify){
463 + $item->last_notify = rand();
464 + }
465 + /*if (!$product_cache[$item->txnid]) {
466 $result = db_query("SELECT vid FROM {ec_transaction_product} WHERE txnid = %d", $item->txnid);
467 while ($row = db_fetch_object($result)) {
468 $product_cache[$item->txnid][] = $row->vid;
469 }
470 - }
471 + }*/
472 // Serialize the data field so that it is saved to the database.
473 if (isset($item->data)) {
474 + $localdata = $item->data;
475 + $dataid = 0;
476 + if(isset($localdata->subitem)){
477 + $localsubitem = $localdata->subitem;
478 + while($key = key($localsubitem)){
479 + if($status != 2){
480 + $queryresult = db_fetch_object(db_query("SELECT unit_id,status FROM {accommodation_availability} a INNER JOIN {accommodation_inventory} i ON a.iid = i.iid" .
481 + " WHERE aid =%d",$key));
482 + if($dataid ==0){
483 + $dataid = $queryresult->unit_id;
484 + }
485 + if($status == 0||$status != $queryresult->status){
486 + $status = $queryresult->status;
487 + }
488 + }
489 + next($localsubitem);
490 + }
491 + }else{
492 + $dataid = $item->nid;
493 + }
494 + $item -> dataid = $dataid;
495 + $item -> item_status = $status;
496 $item->data = serialize($item->data);
497 + }else{
498 + $item -> dataid = $item->nid;
499 }
500
501 - if (is_array($product_cache[$item->txnid]) && in_array($item->vid, $product_cache[$item->txnid])) {
502 - // Update product
503 + $count = db_result(db_query("SELECT count(*) FROM {ec_transaction_product} WHERE vid = %d AND txnid = %d AND last_notify = %d",$item->vid,$item->txnid,$item->last_notify));
504 + if($count > 0){
505 foreach($product_fields as $key) {
506 if (isset($item->$key)) {
507 $q[] = db_escape_string($key) ." = '%s'";
508 $v[] = $item->$key;
509 }
510 }
511 - db_query('UPDATE {ec_transaction_product} SET '. implode(', ', $q) ." WHERE txnid = '". $item->txnid ."' AND vid = '".$item->vid ."'", $v);
512 + db_query('UPDATE {ec_transaction_product} SET '. implode(', ', $q) ." WHERE txnid = '%s' AND vid = '%s' AND last_notify = '%s'", $v,$item->txnid,$item->vid,$item->last_notify);
513 module_invoke($item->ptype, 'productapi', $item, 'transaction', 'update');
514 }
515 else {
516 @@ -1137,6 +1168,8 @@
517
518 function store_send_invoice_email($txnid, $preview = null) {
519 $t = store_transaction_load($txnid);
520 + $variables = token_get_values('global',$t);
521 + $from = variable_get("site_mail", ini_get("sendmail_from"));
522
523 if ($t->mail && valid_email_address($t->mail)) {
524 $to = $t->mail;
525 @@ -1149,8 +1182,20 @@
526 return ec_mail_preview($mid, $to, $t);
527 }
528 elseif ($to && valid_email_address($to)) {
529 - return ec_mail_send_mid($mid, $to, $t);
530 + $adminemail = db_result(db_query("SELECT mail FROM {users} WHERE uid = '1'"));
531 + ec_mail_send_mid($mid, $adminemail, $t,variable_get('reservation_email',variable_get('site_mail','')));
532 + //this doesn't work need to load the transaction
533 +
534 + $emaillist = array();
535 + foreach($t->items as $item){
536 + $owner = db_result(db_query("SELECT distinct mail FROM {users} u join {node} n on n.uid = u.uid where n.nid = %d", $item->dataid));
537 + if (!array_key_exists ($owner,$emaillist)){
538 + ec_mail_send_mid($mid,$owner,$t,variable_get('reservation_email',variable_get('site_mail','')));
539 + $emaillist[$owner] = $owner;
540 }
541 + }
542 + return ec_mail_send_mid($mid,$to,$t,variable_get('reservation_email',variable_get('site_mail','')));
543 + }
544 else {
545 return false;
546 }
547 @@ -1754,7 +1799,7 @@
548 // Now that we know the tables, apply the correct column display map.
549 $column_map = array(
550 'users' => array(array('data' => t('user'), 'field' => 'u.uid')),
551 - 'ec_transaction' => array(array('data' => t('txnid'), 'field' => 'st.txnid', 'sort' => 'desc'), array('data' => t('user'), 'field' => 'st.uid'), array('data' => t('payment status'), 'field' => 'st.payment_status'), array('data' => t('workflow'), 'field' => 'st.workflow'), array('data' => t('gross'), 'field' => 'st.gross'), array('data' => t('created'), 'field' => 'st.created'), array('data' => t('changed'), 'field' => 'st.changed'), array('data' => t('duedate'), 'field' => 'st.duedate'))
552 + 'ec_transaction' => array(array('data' => t('txnid'), 'field' => 'st.txnid', 'sort' => 'desc'), array('data' => t('user'), 'field' => 'st.uid'), array('data' => t('payment status'), 'field' => 'st.payment_status'), array('data' => t('workflow'), 'field' => 'st.workflow'), array('data' => t('gross'), 'field' => 'st.gross'), array('data' => t('changed'), 'field' => 'st.changed'))
553 );
554
555 // Expand all query parts.
556 @@ -1775,7 +1820,7 @@
557 }
558 $columns = array_unique($columns);
559 $header = _store_array_distinct($table, 'data');
560 - $header[] = t('items ordered');
561 + //$header[] = t('items ordered');
562 $header[] = t('operations');
563
564 // Get SQL sort clause.
565 @@ -1794,11 +1839,11 @@
566 // fields need special formatting.
567 foreach ($columns as $col) {
568
569 - if (($col == 'created' || $col == 'changed' || $col == 'expires') && $data->$col != 0) {
570 + if (($col == 'changed' || $col == 'expires') && $data->$col != 0) {
571 $row[] = format_date($data->$col, 'small');
572 }
573 elseif ($col == 'duedate') {
574 - $row[] = $data->$col ? format_date($data->$col, 'small') : '';
575 + // $row[] = $data->$col ? format_date($data->$col, 'small') : '';
576 }
577 elseif ($col == 'uid') {
578 $username = db_result(db_query('SELECT name FROM {users} WHERE uid = %d', $data->$col));
579 @@ -1844,8 +1889,8 @@
580 }
581
582 // Count the number of items in this transaction
583 - $num_items = db_result(db_query("SELECT SUM(qty) as items FROM {ec_transaction_product} WHERE txnid = %d", $data->txnid));
584 - $row[] = l(format_plural($num_items, '1 item', '@count items'), "admin/store/transaction/product/view/$data->txnid", array('onclick' => "window.open(this.href, 'items_ordered', 'width=480,height=480,scrollbars=yes,status=yes'); return false"));
585 + //$num_items = db_result(db_query("SELECT SUM(qty) as items FROM {ec_transaction_product} WHERE txnid = %d", $data->txnid));
586 + //$row[] = l(format_plural($num_items, '1 item', '@count items'), "admin/store/transaction/product/view/$data->txnid", array('onclick' => "window.open(this.href, 'items_ordered', 'width=480,height=480,scrollbars=yes,status=yes'); return false"));
587
588 $row[] = l(t('edit'), $edit_uri, array(), $edit_params) .
589 '<br />&nbsp;&nbsp;&nbsp;'. l(t('addresses'), "admin/store/transaction/edit/$data->txnid", array(), "section=addresses&". drupal_get_destination()) .
590 @@ -1877,18 +1922,37 @@
591 }
592 }
593 }
594 - return $output;
595 + return '<div class="trantab">'.$output.'</div>';
596 }
597
598 function store_transaction_item_list(&$txn) {
599 $rows = array();
600 foreach (array_keys($txn->items) as $key) {
601 $p =& $txn->items[$key];
602 - $rows[] = array($p->title, l(t('edit'), "admin/store/transaction/product/edit/$txn->txnid/$p->nid", array(), drupal_get_destination()));
603 + $node = node_load($p->nid);
604 + $price = store_adjust_misc($txn, $p);
605 + if($p->dataid > 0){
606 + $unitname = db_result(db_query("SELECT title FROM node n where n.nid = " . $p->dataid));
607 + }else{
608 + $unitname ='';
609 }
610 -
611 + $data = $p->data;
612 + $localsubitem = $data->subitem;
613 + $first = true;
614 + while($key = key($localsubitem)){
615 + if($first == true){
616 + $arrivaldate = $localsubitem[$key]->date;
617 + $propertyowner = $key;
618 + $first = false;
619 + }
620 + next($localsubitem);
621 + }
622 + $occupants = $p->data->occupants;
623 + $rows[] =array(array('data' => $p->qty, 'align' => 'center', 'valign' => 'top'),array('data' => $p->title, 'align' => 'center', 'valign' => 'top'),array('data' => $occupants, 'align' => 'center', 'valign' => 'top'),array('data' => $unitname, 'align' => 'center', 'valign' => 'top'),array('data' => $arrivaldate, 'align' => 'center', 'valign' => 'top'),array('data' => $p->data->days, 'align' => 'center', 'valign' => 'top'),array('data' => payment_format($price), 'valign' => 'top', 'align' => 'right'));;
624 + }
625 + $header = array(t('Quantity'), t('Item'),t('People'),t('Type'),t('Arrival'),t('Nights'), t('Price'));
626 if (count($rows)) {
627 - return theme('table', array('product', 'op'), $rows);
628 + return theme('table', $header, $rows);
629 }
630
631 return '';
632 @@ -1926,7 +1990,7 @@
633 }
634 $form['items'] = array(
635 '#type' => 'item',
636 - '#title' => t('Transaction items'),
637 + '#title' => t(''),
638 '#value' => $items
639 );
640 $form['txnid'] = array(
641 @@ -1934,21 +1998,6 @@
642 '#value' => $txn->txnid
643 );
644
645 - $form['products'] = array(
646 - '#type' => 'fieldset',
647 - '#title' => t('Products'),
648 - );
649 - $form['products']['nids'] = array(
650 - '#type' => 'textfield',
651 - '#title' => t('Product IDs'),
652 - '#default_value' => $txn->nids,
653 - '#autocomplete_path' => 'product/autocomplete/all',
654 - '#size' => 60,
655 - '#maxlength' => 128,
656 - '#description' => t('Enter a comma separated list of product ids to add to this transaction. Here is a <a href="!product_quicklist" onclick="window.open(this.href, \'!product_quicklist\', \'width=480,height=480,scrollbars=yes,status=yes\'); return false">list of all products</a>.', array('!product_quicklist' => url('admin/store/products/quicklist')))
657 - );
658 - $form['products'][] = array('#type' => 'submit', '#value' => t('Add products'));
659 -
660 return $form;
661 }
662
663 @@ -2254,11 +2303,10 @@
664
665 $header = array(
666 array('data' => t('ID'), 'field' => 'st.txnid', 'sort' => 'desc'),
667 - array('data' => t('payment status'), 'field' => 'st.payment_status'),
668 + //array('data' => t('payment status'), 'field' => 'st.payment_status'),
669 array('data' => t('workflow'), 'field' => 'st.workflow'),
670 array('data' => t('total'), 'field' => 'st.gross'),
671 array('data' => t('created'), 'field' => 'st.created'),
672 - array('data' => t('due date'), 'field' => 'st.duedate'),
673 t('items ordered'),
674 t('operations')
675 );
676 @@ -2275,17 +2323,16 @@
677 }
678
679 $operations = array(l(t('view'), "store/transaction/view/$txn->txnid"));
680 - if ($txn->payment_status == payment_get_status_id('pending')) {
681 + /*if ($txn->payment_status == payment_get_status_id('pending')) {
682 $operations[] = l(t('make payment'), "store/payment/{$txn->txnid}");
683 - };
684 + };*/
685
686 $rows[] = array(
687 $txn->txnid,
688 - payment_get_status($txn->payment_status),
689 + //payment_get_status($txn->payment_status),
690 transaction_get_workflow($txn->workflow),
691 module_invoke('payment', 'format', $txn->gross),
692 format_date($txn->created, 'small'),
693 - $txn->duedate ? (($txn->duedate > time()) ? format_date($txn->duedate, 'small') : t('Overdue')) : '',
694 format_plural($num_items, '1 item', '@count items'),
695 implode('<br />', $operations)
696 );
697 @@ -2616,8 +2663,8 @@
698 * Implements hook_token_list() from the token module.
699 */
700 function store_token_list($type = 'all') {
701 - if (in_array($type, array('all', STORE_TOKEN_TYPE, ECMAIL_TYPE_CUSTOMER_INVOICE,
702 - ECMAIL_TYPE_PROCESSING_ERROR, ECMAIL_TYPE_CANCEL_TXN, ECMAIL_TYPE_ASK_CUSTOMER,
703 + if (in_array($type, array('all', STORE_TOKEN_TYPE, ECMAIL_TYPE_CUSTOMER_INVOICE,ECMAIL_TYPE_CUSTOMER_INVOICE_INSTANT,
704 + ECMAIL_TYPE_PROCESSING_ERROR, ECMAIL_TYPE_CANCEL_TXN, ECMAIL_TYPE_ASK_CUSTOMER,ECMAIL_TYPE_CONFIRMATION,
705 ECMAIL_TYPE_SHIP_NOTICE))) {
706 $vars[STORE_TOKEN_TYPE]['txn-id'] = t('Transaction ID.');
707 $vars[STORE_TOKEN_TYPE]['txn-balance'] = t('Transaction balance.');
708 @@ -2639,31 +2686,66 @@
709 $vars[STORE_TOKEN_TYPE]['txn-bill-plus-ship'] = t('Three other transaction tokens joined together: [txn-ship-to] [txn-shipping-method] [txn-bill-to].');
710 $vars[STORE_TOKEN_TYPE]['txn-items'] = t('Listing of items in the transaction.');
711 $vars[STORE_TOKEN_TYPE]['site-url-brief'] = t('Site url without the protocol (http://).');
712 + $vars[STORE_TOKEN_TYPE]['billing-name'] = t('Name of the person receiving the bill');
713 + $vars[STORE_TOKEN_TYPE]['ourfernie-email'] = t('Reservations email');
714 + $vars[STORE_TOKEN_TYPE]['ourfernie-uri'] = t('Reservations uri');
715 + $vars[STORE_TOKEN_TYPE]['ourfernie-date'] = t('Date when email was generated');
716 + $vars[STORE_TOKEN_TYPE]['ourfernie-owner'] = t('The owner of the properties email address');
717 + $vars[STORE_TOKEN_TYPE]['checkin'] =t('Checkin instructions');
718 }
719
720 return $vars;
721 }
722
723 +
724 /**
725 * Implements hook_token_values() from the token module.
726 */
727 function store_token_values($type, $object = NULL) {
728 if (in_array($type, array(STORE_TOKEN_TYPE, ECMAIL_TYPE_CUSTOMER_INVOICE,
729 - ECMAIL_TYPE_PROCESSING_ERROR, ECMAIL_TYPE_CANCEL_TXN,
730 - ECMAIL_TYPE_ASK_CUSTOMER, ECMAIL_TYPE_SHIP_NOTICE))) {
731 + ECMAIL_TYPE_PROCESSING_ERROR, ECMAIL_TYPE_CANCEL_TXN,ECMAIL_TYPE_CONFIRMATION,
732 + ECMAIL_TYPE_CUSTOMER_INVOICE_INSTANT,ECMAIL_TYPE_ASK_CUSTOMER, ECMAIL_TYPE_SHIP_NOTICE))) {
733 global $base_url;
734 + $billing_name = ucfirst($transaction->address['billing']->firstname). ' '. ucfirst($transaction->address['billing']->lastname);
735
736 $txn = (object) $object;
737
738 $items = "";
739 $subtotal = 0;
740 + $checkinlist = array();
741 if ($txn->items) {
742 foreach ($txn->items as $p) {
743 $product = product_load($p);
744 - $subtotal += $p->qty * $p->price;
745 - $items .= t('@order of @title at @price each', array('@order' => format_plural($p->qty, '1 order', '@count orders'), '@title' => $p->title, '@price' => payment_format($p->price))). "\n";
746 + $transactions = $p->data;
747 +
748 + $first = true;
749 + $localsubitem = $transactions->subitem;
750 + while($key = key($localsubitem)){
751 + if($first == true){
752 + $arrivaldate = $localsubitem[$key]->date;
753 + $propertyowner = $key;
754 + $first = false;
755 + $unitname = db_result(db_query("SELECT title FROM node n inner join accommodation_inventory i on n.nid = i.unit_id inner join accommodation_availability a on a.iid = i.iid where a.aid = " . $key ));
756 + }
757 + next($localsubitem);
758 }
759 + //needs to take into account unit as well as check policy could be at unit level
760 + if (!array_key_exists ($p->nid,$checkinlist)){
761 + $checkinlist[$p->nid] = array($p->dataid => $p->dataid);
762 + }else{
763 + $checkinlist[$p->nid][$p->dataid] = $p->dataid;
764 + }
765 + //%night stay at %title arriving on %date
766 + //we need to check the type - lift ticket??
767 + if($product->ptype == 'liftticket'){
768 + $items .= t('%title at %price ', array('%title' => $transactions->title,'%price' => payment_format($p->price))). "\r\n\r\n";
769 + }else{
770 + $occupants = $transactions->occupants;
771 + $items .= t('@title for @occupants people staying in a(n) @unitname arriving on @arrival at @price ', array('@title' => $transactions->title,'@unitname' => $unitname, '@arrival' => $arrivaldate,'@price' => payment_format($p->price),'@occupants'=>$occupants)). "\r\n\r\n";
772 + }
773 }
774 + $checkin .= business_format_address($checkinlist);
775 + }
776
777 $values['txn-id'] = $txn->txnid;
778 $values['txn-balance'] = payment_format($txn->gross);
779 @@ -2685,11 +2767,18 @@
780 $values['txn-bill-plus-ship'] = check_plain($values['txn-ship-to'] . $values['txn-shipping-method'] . $values['txn-bill-to']);
781 $values['txn-items'] = $items;
782 $values['site-url-brief'] = substr($base_url, strlen("http://"));
783 + $values['billing-name'] = $billing_name;
784 + $values['ourfernie-email'] = variable_get('reservation_email',variable_get('site_mail',''));
785 + $values['ourfernie-uri'] = variable_get('reservation_email',variable_get('site_mail',''));
786 + $values['ourfernie-date'] = format_date(time());
787 + $values['ourfernie-owner'] = $propertyowner;
788 + $values['checkin'] = $checkin;
789 }
790
791 return $values;
792 }
793
794 +
795 /**
796 * Implementation of hook_mail_types() from ec_mail module.
797 */

  ViewVC Help
Powered by ViewVC 1.1.2