PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_virtuemart/html/admin.booking_import.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 67 lines | 50 code | 16 blank | 1 comment | 5 complexity | f4a16ca6366c6b7144f071ef78ddc350 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. global $psdb;
  4. $psdb = new ps_DB();
  5. function updateBooking($row) {
  6. global $psdb;
  7. //$order_number = $row->user_id.'_'.md5($row->rec);
  8. $total_gross = $row->price;
  9. $total_net = ($row->price / 1.105);
  10. $total_tax = ($row->price - ($row->price / 1.105));
  11. $state_tax = ($row->price - ($row->price / 1.06));
  12. $resort_tax = ($row->price - ($row->price / 1.045));
  13. $start = $row->start;
  14. $end = $row->end;
  15. $created = strtotime($row->rectime);
  16. $concat = $row->rec.'|'.$row->price.'|'.$order_number."\n";
  17. if (!$psdb->query("insert INTO #__{vm}_order_booking set
  18. order_id='".$row->rec."',
  19. property_id='".$row->prop_id."',
  20. people='".$row->people."',
  21. arrival='".$start."',
  22. departure='".$end."',
  23. total='".$total_gross."',
  24. subtotal='".$total_net."',
  25. original='".$total_gross."',
  26. tax_total='".$total_tax."',
  27. tax_state='".$state_tax."',
  28. tax_resort='".$resort_tax."'
  29. ")) {
  30. file_put_contents(dirname(__FILE__).'/failed_bookings.txt',$concat,FILE_APPEND);
  31. } else {
  32. echo 'Done : '.$row->rec.'<br />';
  33. }
  34. }
  35. $db = new ps_DB();
  36. $db->setQuery("select
  37. tu.user_id,
  38. ui.user_info_id,
  39. tp.prop_id,
  40. tb.*
  41. from temp_bookings tb
  42. left join temp_users tu on tb.custid=tu.rec
  43. left join jos_users u on tu.user_id=u.id
  44. left join jos_vm_user_info ui on u.id=ui.user_id
  45. left join temp_props tp on tb.name=tp.old_property
  46. where tp.prop_id != 0 AND tp.imported = 0 and tp.prop_id is not null");
  47. $rows = $db->loadObjectList();
  48. foreach ($rows as $row) {
  49. updateBooking($row);
  50. }
  51. ?>