AeliaWCEU_VAT_AssistantReportsManager

Registers the reports introduced by the EU VAT Assistant.

Defined (1)

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

/src/lib/classes/reporting/reports_manager.php  
  1. class ReportsManager extends \Aelia\WC\Base_Class { 
  2. // @var array An array of WooCommerce version => Namespace pairs. The namespace will be used to load the appropriate class to override reports 
  3. protected static $reports_namespaces = array( 
  4. '2.1' => 'WC21',  
  5. '2.2' => 'WC22',  
  6. ); 
  7.  
  8. // @var string The namespace to use to load the reports. 
  9. protected static $report_namespace = null; 
  10.  
  11. protected static function get_report_namespace() { 
  12. if(empty(self::$report_namespace)) { 
  13. krsort(self::$reports_namespaces); 
  14. foreach(self::$reports_namespaces as $supported_version => $namespace) { 
  15. if(version_compare(wc()->version, $supported_version, '>=')) { 
  16. self::$report_namespace = $namespace; 
  17. break; 
  18.  
  19. if(empty(self::$report_namespace)) { 
  20. trigger_error(sprintf(__('Reports could not be found for this WooCommerce version. ' . 
  21. 'Supported version are from %s to: %s.', Definitions::TEXT_DOMAIN),  
  22. min(array_keys(self::$reports_namespaces)),  
  23. max(array_keys(self::$reports_namespaces))),  
  24. E_USER_WARNING); 
  25. return '\\' . __NAMESPACE__ . '\\Reports\\' . self::$report_namespace; 
  26.  
  27. /** 
  28. * Constructor 
  29. */ 
  30. public static function init() { 
  31. add_action('woocommerce_admin_reports', array(__CLASS__, 'woocommerce_admin_reports')); 
  32.  
  33. /** 
  34. * Registers the new EU VAT reports within WooCommerce. 
  35. * @param array reports An array of reports passed by WooCommerce. 
  36. * @return array 
  37. */ 
  38. public static function woocommerce_admin_reports($reports) { 
  39. if(isset($reports['taxes'])) { 
  40. $reports['taxes']['reports']['eu_vat_by_country_report'] = array( 
  41. 'title' => __('EU VAT by Country', Definitions::TEXT_DOMAIN),  
  42. 'description' => '',  
  43. 'hide_title' => true,  
  44. 'callback' => array(__CLASS__, 'eu_vat_by_country_report'),  
  45. ); 
  46.  
  47. // VIES Report 
  48. $reports['taxes']['reports']['vies_report'] = array( 
  49. 'title' => __('VIES', Definitions::TEXT_DOMAIN),  
  50. 'description' => '',  
  51. 'hide_title' => true,  
  52. 'callback' => array(__CLASS__, 'vies_report'),  
  53. ); 
  54.  
  55. // INTRASTAT Report 
  56. $reports['taxes']['reports']['intrastat_report'] = array( 
  57. 'title' => __('INTRASTAT', Definitions::TEXT_DOMAIN),  
  58. 'description' => '',  
  59. 'hide_title' => true,  
  60. 'callback' => array(__CLASS__, 'intrastat_report'),  
  61. ); 
  62.  
  63. // Reports for WooCommerce 2.2 and later 
  64. if(version_compare(wc()->version, '2.2', '>=')) { 
  65. // Sales list 
  66. // TODO Implement sales list report 
  67. //$reports['taxes']['reports']['sales_list_report'] = array( 
  68. // 'title' => __('Sales List', Definitions::TEXT_DOMAIN),  
  69. // 'description' => '',  
  70. // 'hide_title' => true,  
  71. // 'callback' => array(__CLASS__, 'sales_list_report'),  
  72. //); 
  73.  
  74. // Sales Summary Report (used for VAT RTD) 
  75. $reports['taxes']['reports']['sales_summary_report'] = array( 
  76. 'title' => __('Sales Summary (VAT RTD)', Definitions::TEXT_DOMAIN),  
  77. 'description' => '',  
  78. 'hide_title' => true,  
  79. 'callback' => array(__CLASS__, 'sales_summary_report'),  
  80. ); 
  81. return $reports; 
  82.  
  83. /** 
  84. * Callback to render the Sales List report. 
  85. */ 
  86. public static function sales_list_report() { 
  87. $report_class = self::get_report_namespace() . '\Sales_List_Report'; 
  88. $report = new $report_class(); 
  89. $report->output_report(); 
  90.  
  91. /** 
  92. * Callback to render the VIES report. 
  93. */ 
  94. public static function vies_report() { 
  95. $report_class = self::get_report_namespace() . '\VIES_Report'; 
  96. $report = new $report_class(); 
  97. $report->output_report(); 
  98.  
  99. /** 
  100. * Callback to render the INTRASTAT report. 
  101. */ 
  102. public static function intrastat_report() { 
  103. $report_class = self::get_report_namespace() . '\INTRASTAT_Report'; 
  104. $report = new $report_class(); 
  105. $report->output_report(); 
  106.  
  107. /** 
  108. * Callback to render the EU VAT report. 
  109. */ 
  110. public static function eu_vat_by_country_report() { 
  111. $report_class = self::get_report_namespace() . '\EU_VAT_By_Country_Report'; 
  112. $report = new $report_class(); 
  113. $report->output_report(); 
  114.  
  115. /** 
  116. * Callback to render the Sales Summary report. 
  117. * @since 1.5.8.160112 
  118. */ 
  119. public static function sales_summary_report() { 
  120. $report_class = self::get_report_namespace() . '\Sales_Summary_Report'; 
  121. $report = new $report_class(); 
  122. $report->output_report();