1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: WooCommerce Accounting |
---|
4 | Text Domain: accounting-for-woocommerce |
---|
5 | Description: All you need to transfer accounting data from Woocommerce to accounting softwares! |
---|
6 | Author: N.O.U.S. Open Useful and Simple |
---|
7 | Author URI: https://apps.avecnous.eu/?mtm_campaign=wp-plugin&mtm_kwd=accounting-for-woocommerce&mtm_medium=dashboard&mtm_source=author |
---|
8 | Version: 1.6.4 |
---|
9 | */ |
---|
10 | if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
---|
11 | |
---|
12 | /* |
---|
13 | Forked from Ro_meow's WooCommerce Book-keeper |
---|
14 | |
---|
15 | This program is free software; you can redistribute it and/or modify |
---|
16 | it under the terms of the GNU General Public License, version 2 and later, as |
---|
17 | published by the Free Software Foundation. |
---|
18 | |
---|
19 | This program is distributed in the hope that it will be useful, |
---|
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
22 | GNU General Public License for more details. |
---|
23 | |
---|
24 | You should have received a copy of the GNU General Public License |
---|
25 | along with this program; if not, write to the Free Software |
---|
26 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
27 | |
---|
28 | */ |
---|
29 | |
---|
30 | add_action('init', function(){ |
---|
31 | // Check if WC is active |
---|
32 | if ( !is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
---|
33 | return; |
---|
34 | } |
---|
35 | load_plugin_textdomain( 'accounting-for-woocommerce' ); |
---|
36 | $inc_path = plugin_dir_path( __FILE__ ) . 'inc'; |
---|
37 | $includes = scandir($inc_path); |
---|
38 | foreach($includes as $include){ |
---|
39 | if(is_file("{$inc_path}/{$include}")){ |
---|
40 | include "{$inc_path}/{$include}"; |
---|
41 | } |
---|
42 | } |
---|
43 | add_action('admin_init', 'woocommerce_accounting_install'); |
---|
44 | add_action ('admin_menu', 'woocommerce_accounting_exporter_page', 50); |
---|
45 | |
---|
46 | //actions for export |
---|
47 | add_action('admin_post_woocommerce_accounting_export','woocommerce_accounting_export_data'); |
---|
48 | add_action('admin_post_woocommerce_accounting_refunds_export','woocommerce_accounting_export_refunds_data'); |
---|
49 | |
---|
50 | |
---|
51 | add_filter('plugin_action_links_'.plugin_basename( __FILE__ ), 'woocommerce_accounting_plugin_settings_link' ); |
---|
52 | add_filter('plugin_row_meta', 'woocommerce_accounting_plugin_row_meta', 10, 4 ); |
---|
53 | }); |
---|
54 | |
---|
55 | /** |
---|
56 | * Create the admin pages links |
---|
57 | * |
---|
58 | * @return void |
---|
59 | */ |
---|
60 | function woocommerce_accounting_exporter_page() { |
---|
61 | //Menu pages |
---|
62 | add_submenu_page ('woocommerce', __( 'Accounting Export' , 'accounting-for-woocommerce' ), __( 'Accounting Export' , 'accounting-for-woocommerce' ), 'manage_woocommerce', 'woocommerce_accounting_exporter', 'woocommerce_accounting_exporter'); |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * Enqueue scripts and style |
---|
67 | * |
---|
68 | * @return [type] [description] |
---|
69 | */ |
---|
70 | function woocommerce_accounting_load_export_scripts(){ |
---|
71 | wp_enqueue_script('jquery-ui-datepicker'); |
---|
72 | wp_enqueue_script('jquery-ui-sortable'); |
---|
73 | wp_register_style('jquery-ui-css', plugins_url('assets/jquery-ui.css', __FILE__)); |
---|
74 | wp_enqueue_style('jquery-ui-css'); |
---|
75 | } |
---|
76 | |
---|
77 | /** |
---|
78 | * Displays export page |
---|
79 | * |
---|
80 | * @return void |
---|
81 | */ |
---|
82 | function woocommerce_accounting_exporter() { |
---|
83 | if (! current_user_can('manage_woocommerce')) { |
---|
84 | wp_die( __('Insuffisant permissions', 'accounting-for-woocommerce') ); |
---|
85 | } |
---|
86 | woocommerce_accounting_load_export_scripts(); |
---|
87 | require ( dirname(__FILE__).'/views/export.php'); |
---|
88 | } |
---|
89 | |
---|
90 | /** |
---|
91 | * Displays refund export page |
---|
92 | * |
---|
93 | * @return void |
---|
94 | */ |
---|
95 | function woocommerce_accounting_exporter_refunds_export() { |
---|
96 | if (! current_user_can('manage_woocommerce')) { |
---|
97 | wp_die( __('Insuffisant permissions', 'accounting-for-woocommerce') ); |
---|
98 | } |
---|
99 | woocommerce_accounting_load_export_scripts(); |
---|
100 | require ( dirname(__FILE__).'/views/refunds-page.php'); |
---|
101 | } |
---|
102 | |
---|
103 | /** |
---|
104 | * Called at plugin install. |
---|
105 | * Create default options |
---|
106 | * |
---|
107 | * @return void |
---|
108 | */ |
---|
109 | function woocommerce_accounting_install() { |
---|
110 | $order_status = get_option('woocommerce_accounting_status'); |
---|
111 | if (empty($order_status)){ |
---|
112 | $order_status_install = array( |
---|
113 | 'wc-completed', |
---|
114 | 'wc-refunded' |
---|
115 | ); |
---|
116 | update_option('woocommerce_accounting_status', $order_status_install); |
---|
117 | } |
---|
118 | //register our export settings |
---|
119 | add_option( 'woocommerce_accounting_export_start_date'); |
---|
120 | add_option( 'woocommerce_accounting_export_end_date'); |
---|
121 | add_option( 'woocommerce_accounting_export_date_format'); |
---|
122 | add_option( 'woocommerce_accounting_export_separator'); |
---|
123 | add_option( 'woocommerce_accounting_export_date_opt'); |
---|
124 | add_option( 'woocommerce_accounting_export_pay_opt'); |
---|
125 | add_option( 'woocommerce_accounting_export_prod_opt'); |
---|
126 | add_option( 'woocommerce_accounting_export_taxes_opt'); |
---|
127 | add_option( 'woocommerce_accounting_export_ship_opt'); |
---|
128 | add_option( 'woocommerce_accounting_export_factnum_opt'); |
---|
129 | add_option( 'woocommerce_accounting_export_cust_opt'); |
---|
130 | add_option( 'woocommerce_accounting_export_decimal_separator'); |
---|
131 | add_option( 'woocommerce_accounting_export_zero_opt'); |
---|
132 | add_option( 'woocommerce_accounting_export_coupon_opt'); |
---|
133 | |
---|
134 | //register our export settings |
---|
135 | add_option( 'woocommerce_accounting_refunds_export_start_date'); |
---|
136 | add_option( 'woocommerce_accounting_refunds_export_end_date'); |
---|
137 | add_option( 'woocommerce_accounting_export_refunds_date_format'); |
---|
138 | add_option( 'woocommerce_accounting_refunds_export_separator'); |
---|
139 | add_option( 'woocommerce_accounting_refunds_export_date_opt'); |
---|
140 | add_option( 'woocommerce_accounting_refunds_export_pay_opt'); |
---|
141 | add_option( 'woocommerce_accounting_refunds_export_prod_opt'); |
---|
142 | add_option( 'woocommerce_accounting_refunds_export_taxes_opt'); |
---|
143 | add_option( 'woocommerce_accounting_refunds_export_ship_opt'); |
---|
144 | add_option( 'woocommerce_accounting_refunds_export_factnum_opt'); |
---|
145 | add_option( 'woocommerce_accounting_refunds_export_cust_opt'); |
---|
146 | add_option( 'woocommerce_accounting_refunds_export_decimal_separator'); |
---|
147 | add_option( 'woocommerce_accounting_refunds_export_zero_opt'); |
---|
148 | } |
---|
149 | |
---|
150 | /** |
---|
151 | * Settings link on the plugins page |
---|
152 | * |
---|
153 | * @param array $plugin_links |
---|
154 | */ |
---|
155 | function woocommerce_accounting_plugin_settings_link( $plugin_links ) { |
---|
156 | $plugin_links['settings'] = '<a href="'.add_query_arg(array( |
---|
157 | 'page'=>'wc-settings', |
---|
158 | 'tab'=>'accounting', |
---|
159 | ), 'admin.php').'">'.__('Settings', 'accounting-for-woocommerce').'</a>'; |
---|
160 | return $plugin_links; |
---|
161 | } |
---|
162 | |
---|
163 | /** |
---|
164 | * Add settings link in the plugins list |
---|
165 | * |
---|
166 | * @param array $plugin_meta |
---|
167 | * @param string $plugin_file |
---|
168 | * @param array $plugin_data |
---|
169 | * @param string $status |
---|
170 | * |
---|
171 | * @see `woocommerce_accounting:export_form:pro_features` filter |
---|
172 | * |
---|
173 | * @return array |
---|
174 | */ |
---|
175 | function woocommerce_accounting_plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) { |
---|
176 | if($plugin_file == plugin_basename( __FILE__ )){ |
---|
177 | $pro_link = apply_filters('woocommerce_accounting:export_form:pro_features', '<a href="https://apps.avecnous.eu/produit/woocommerce-accounting/?mtm_campaign=wp-plugin&mtm_kwd=accounting-for-woocommerce" target="_blank">' . __( 'Pro addon', 'accounting-for-woocommerce' ) . '</a>'); |
---|
178 | if($pro_link){ |
---|
179 | $plugin_meta['pro_link'] = $pro_link; |
---|
180 | } |
---|
181 | } |
---|
182 | return $plugin_meta; |
---|
183 | } |
---|
184 | |
---|
185 | /** |
---|
186 | * [woocommerce_accounting_date_format description] |
---|
187 | * |
---|
188 | * @param string $date |
---|
189 | * @param integer $format |
---|
190 | * |
---|
191 | * @return string |
---|
192 | */ |
---|
193 | function woocommerce_accounting_date_format($date, $format){ |
---|
194 | $formatted_date = $date; |
---|
195 | $time = strtotime( $formatted_date ); |
---|
196 | //Date Format |
---|
197 | $order_year = date_i18n( 'Y', $time ); |
---|
198 | $order_month = date_i18n( 'm', $time ); |
---|
199 | $order_day = date_i18n ( 'd', $time ) ; |
---|
200 | if ($format == "1") { |
---|
201 | $formatted_date = $order_day . '-' . $order_month . '-' . $order_year; |
---|
202 | } elseif ($format == "2") { |
---|
203 | $formatted_date = $order_month . '-' . $order_day . '-' . $order_year; |
---|
204 | } elseif ($format == "3") { |
---|
205 | $formatted_date = $order_year . '-' . $order_month . '-' . $order_day; |
---|
206 | } elseif ($format == "4") { |
---|
207 | $formatted_date��= $order_day . '/' . $order_month . '/' . $order_year; |
---|
208 | } elseif ($format == "5") { |
---|
209 | $formatted_date = $order_month . '/' . $order_day . '/' . $order_year; |
---|
210 | } elseif ($format == "6") { |
---|
211 | $formatted_date = $order_year . '/' . $order_month . '/' . $order_day; |
---|
212 | } |
---|
213 | |
---|
214 | return $formatted_date; |
---|
215 | } |
---|
216 | |
---|
217 | add_action('woocommerce_accounting:export_form:before_title', function (){ |
---|
218 | if('no_orders' === filter_input(INPUT_GET, 'error')){ |
---|
219 | ?> |
---|
220 | <div id='message' class='error fade'> |
---|
221 | <p> |
---|
222 | <?php _e('No data to export. Please try with another period.', 'accounting-for-woocommerce'); ?> |
---|
223 | </p> |
---|
224 | </div> |
---|
225 | <?php |
---|
226 | } |
---|
227 | }); |
---|