AeliaWCEU_VAT_AssistantReportsWC21INTRASTAT_Report

Renders the INTRASTAT report.

Defined (1)

The class is defined in the following location(s).

/src/lib/classes/reporting/reports/WC21/intrastat_report.php  
  1. class INTRASTAT_Report extends \Aelia\WC\EU_VAT_Assistant\Reports\Base_INTRASTAT_Report { 
  2. /** 
  3. * Returns the sales data that will be included in the report. 
  4. * @return array 
  5. */ 
  6. protected function get_sales_data() { 
  7. global $wpdb; 
  8.  
  9. $px = $wpdb->prefix; 
  10. $SQL = sprintf(" 
  11. SELECT 
  12. ORDERS.ID AS order_id 
  13. , DATE(ORDERS.post_date) AS order_date 
  14. , ORDER_META1.meta_value AS eu_vat_evidence 
  15. , ORDER_META3.meta_value AS eu_vat_data 
  16. , ORDER_META4.meta_value AS order_currency 
  17. , ORDER_META2.meta_value AS order_total 
  18. FROM 
  19. {$px}posts AS ORDERS 
  20. INNER JOIN 
  21. {$px}term_relationships AS rel ON 
  22. (rel.object_ID = orders.ID) 
  23. INNER JOIN 
  24. {$px}term_taxonomy AS taxonomy ON 
  25. (taxonomy.term_taxonomy_id = rel.term_taxonomy_id) AND 
  26. (taxonomy.taxonomy = 'shop_order_status') 
  27. INNER JOIN 
  28. {$px}terms AS term ON 
  29. (term.term_id = taxonomy.term_id) AND 
  30. (term.slug IN ('%s')) 
  31. -- Fetch orders meta 
  32. INNER JOIN 
  33. {$px}postmeta AS ORDER_META1 ON 
  34. (ORDER_META1.post_id = ORDERS.ID) AND 
  35. (ORDER_META1.meta_key = '_eu_vat_evidence') 
  36. INNER JOIN 
  37. {$px}postmeta AS ORDER_META2 ON 
  38. (ORDER_META2.post_id = ORDERS.ID) AND 
  39. (ORDER_META2.meta_key = '_order_total') 
  40. INNER JOIN 
  41. {$px}postmeta AS ORDER_META3 ON 
  42. (ORDER_META3.post_id = ORDERS.ID) AND 
  43. (ORDER_META3.meta_key = '_eu_vat_data') 
  44. INNER JOIN 
  45. {$px}postmeta AS ORDER_META4 ON 
  46. (ORDER_META4.post_id = ORDERS.ID) AND 
  47. (ORDER_META4.meta_key = '_order_currency') 
  48. WHERE 
  49. (ORDERS.post_type IN ('shop_order')) AND 
  50. (ORDERS.post_date >= '" . date('Y-m-d', $this->start_date) . "') AND 
  51. (ORDERS.post_date < '" . date('Y-m-d', strtotime('+1 DAY', $this->end_date)) . "') 
  52. ",  
  53. implode("', '", $this->order_statuses_to_include(false))); 
  54.  
  55. // Debug 
  56. //var_dump($SQL); 
  57. $dataset = $wpdb->get_results($SQL); 
  58.  
  59. // Debug 
  60. //var_dump("SALES DATA", $dataset);die(); 
  61. return $dataset;