AeliaWCEU_VAT_AssistantReportsWC22Sales_List_Report

Renders the report containing the EU VAT for each country in a specific period.

Defined (1)

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

/src/lib/classes/reporting/reports/WC22/sales_list_report.php  
  1. class Sales_List_Report extends \Aelia\WC\EU_VAT_Assistant\Reports\Base_Sales_Report { 
  2. /** 
  3. * Returns the refunds data. 
  4. * @param array tax_data The tax data produced by EU_VAT_By_Country_Report::get_tax_data(). 
  5. * @return array The tax data, including the refunds. 
  6. * @see \Aelia\WC\EU_VAT_Assistant\Base_EU_VAT_By_Country_Report::get_tax_data() 
  7. */ 
  8. protected function get_refunds_data() { 
  9. global $wpdb; 
  10.  
  11. $px = $wpdb->prefix; 
  12. $SQL = " 
  13. SELECT 
  14. REFUNDS.ID 
  15. , REFUNDS.post_date 
  16. , ORDERS.ID AS order_id 
  17. , OM.meta_value AS order_vat_data 
  18. -- , meta__eu_vat_data.meta_value 
  19. -- Refund items 
  20. , RI.order_item_id AS refund_item_id 
  21. , RI.order_item_name AS refund_item_name 
  22. , RI.order_item_type AS refund_item_type 
  23. -- Item/shipping tax refund data 
  24. , RIM2.meta_key AS tax_refund_data_type 
  25. , RIM2.meta_value AS tax_refund_data 
  26. -- Item/shipping price refund data 
  27. , RIM3.meta_key AS price_refund_data_type 
  28. , RIM3.meta_value AS price_refund_data 
  29. FROM 
  30. {$px}posts AS REFUNDS 
  31. JOIN 
  32. {$px}posts AS ORDERS ON 
  33. (ORDERS.ID = REFUNDS.post_parent) 
  34. JOIN 
  35. -- Order Meta 
  36. {$px}postmeta AS OM ON 
  37. (OM.post_id = ORDERS.ID) AND 
  38. (OM.meta_key = '_eu_vat_data') 
  39. JOIN 
  40. -- Refund items 
  41. {$px}woocommerce_order_items RI ON 
  42. (RI.order_id = REFUNDS.ID) AND 
  43. (RI.order_item_type IN ('line_item', 'shipping')) 
  44. JOIN 
  45. -- Refund items meta - Find refund items 
  46. {$px}woocommerce_order_itemmeta RIM1 ON 
  47. (RIM1.order_item_id = RI.order_item_id) AND 
  48. (RIM1.meta_key = '_refunded_item_id') AND 
  49. (RIM1.meta_value > 0) 
  50. JOIN 
  51. -- Refund items meta - Find item/shipping tax refund data 
  52. {$px}woocommerce_order_itemmeta RIM2 ON 
  53. (RIM2.order_item_id = RI.order_item_id) AND 
  54. (RIM2.meta_key IN ('_line_tax_data', 'taxes')) 
  55. LEFT JOIN 
  56. -- Refund items meta - Find item/shipping price refund data 
  57. {$px}woocommerce_order_itemmeta RIM3 ON 
  58. (RIM3.order_item_id = RI.order_item_id) AND 
  59. (RIM3.meta_key IN ('cost', '_line_total')) 
  60. WHERE 
  61. (REFUNDS.post_type IN ('shop_order_refund')) AND 
  62. (REFUNDS.post_status IN ('wc-processing', 'wc-completed')) AND 
  63. (REFUNDS.post_date >= '" . date('Y-m-d', $this->start_date) . "') AND 
  64. (REFUNDS.post_date < '" . date('Y-m-d', strtotime('+1 DAY', $this->end_date)) . "') 
  65. "; 
  66. // Debug 
  67. if($this->debug) { 
  68. var_dump($SQL); 
  69. $dataset = $wpdb->get_results($SQL); 
  70.  
  71. // Debug 
  72. //var_dump("REFUNDS RESULT", $dataset); 
  73. return $dataset;