Changeset 3103642
- Timestamp:
- 06/17/2024 02:50:09 PM (3 weeks ago)
- Location:
- accounting-for-woocommerce/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
accounting-for-woocommerce/trunk/inc/export.php
r3074922 r3103642 40 40 $coupon_col = sanitize_text_field($_POST['woocommerce_accounting_export_coupon_col']); 41 41 $coupon_opt = sanitize_text_field($_POST['woocommerce_accounting_export_coupon_opt']); 42 $rounding_precision = sanitize_text_field($_POST['woocommerce_accounting_export_rounding_precision']);42 $rounding_precision = sanitize_text_field($_POST['woocommerce_accounting_export_rounding_precision']); 43 43 44 44 update_option( 'woocommerce_accounting_export_start_date',$ts1); … … 65 65 $order_status = get_option('woocommerce_accounting_status'); 66 66 67 68 69 70 71 72 73 74 75 67 76 $order_args = array( 68 'posts_per_page' => -1, 69 'post_type' => 'shop_order', 70 'post_status' => $order_status, 77 'limit' => -1, 78 'status' => $order_status, 71 79 'orderby' => 'ID', 72 80 'order' => 'ASC', 73 81 ); 74 82 75 if ($date_opt == "1") { 76 $order_args['meta_query'] = array( 77 array( 78 'key' => '_completed_date', 79 'value' => array($ts1, $ts2), 80 'compare' => 'BETWEEN', 81 'type' => 'DATE', 82 ) 83 ); 83 if(isset($date_options[$date_opt])){ 84 $order_args[$date_options[$date_opt]] = "{$ts1}...{$ts2}"; 84 85 } 85 elseif($date_opt == "0"){ 86 $order_args['date_query'] = array( 87 array( 88 'before' => $ts2, 89 'after' => $ts1, 90 'inclusive' => true 91 ) 92 ); 93 } 94 elseif ($date_opt == "3") { 95 $order_args['meta_query'] = array( 96 array( 97 'key' => '_paid_date', 98 'value' => array($ts1, $ts2), 99 'compare' => 'BETWEEN', 100 'type' => 'DATE' 101 ) 102 ); 103 } 86 104 87 $order_args = apply_filters('woocommerce_accounting:export:get_orders_args', $order_args, $date_opt, $order_status, array($ts1, $ts2)); 105 88 $orders = wc_get_orders($order_args); 106 89 do_action('woocommerce_accounting:export:launch', $orders); 107 108 109 //Collecting datas 110 if (!empty($orders)) { 90 $compiledOrders = array(); 91 92 if(!empty($orders)){ 111 93 //Generic accounts 112 94 $csv_headers = get_option ('woocommerce_accounting_columns_headers'); … … 126 108 $order_shipping_acc_list = get_option ('woocommerce_accounting_shipping_methods_accounting_account'); 127 109 $pdfoptions = get_option('wpo_wcpdf_template_settings'); 128 129 foreach ($orders as $order) { 130 131 if ($date_opt == "0") { 132 $order->piecedate = get_post_field( 'post_date', $order->ID ); 133 } 134 elseif ($date_opt == "1"){ 135 $order->piecedate = get_post_meta($order->ID,'_completed_date',true); 136 } 137 elseif ($date_opt == "3"){ 138 $order->piecedate = get_post_meta($order->ID,'_paid_date',true); 110 } 111 112 foreach ($orders as $wcOrder) 113 { 114 $order = (object) array(); 115 $order->ID = $wcOrder->get_id(); 116 $order->status = $wcOrder->get_status(); 117 $order->date_created = $wcOrder->get_date_created(); 118 $order->date_completed = $wcOrder->get_date_completed(); 119 $order->date_paid = $wcOrder->get_date_paid(); 120 121 if ($date_opt == "0") { 122 $order->piecedate = $order->date_created; 123 } 124 elseif ($date_opt == "1"){ 125 $order->piecedate = $order->date_completed; 126 } 127 elseif ($date_opt == "3"){ 128 $order->piecedate = $order->date_paid; 129 } 130 else { 131 $invoice_date = $wcOrder->get_meta('_wcpdf_invoice_date_formatted', true); 132 if (!empty($invoice_date)) { 133 $order->piecedate = $invoice_date; 139 134 } 140 135 else { 141 $invoice_date = get_post_meta($order->ID,'_wcpdf_invoice_date_formatted',true); 142 if (!empty($invoice_date)) { 143 $order->piecedate = $invoice_date; 144 } 145 else { 146 $order->piecedate = get_post_field( 'post_date', $order->ID ); 147 } 148 } 149 $order->original_date = $order->piecedate; 150 // Test PDF Invoices and Packing slips activated 151 152 if (class_exists('WPO_WCPDF')) { 153 154 $invoice_number_data = get_post_meta($order->ID,'_wcpdf_invoice_number_data'); 155 $invoice_number = get_post_meta($order->ID,'_wcpdf_invoice_number',true); 156 $invoice_date = get_post_meta($order->ID,'_wcpdf_invoice_date',true); 157 158 //Invoice number presence test 159 if ( ( !empty ($invoice_number) ) && ( empty ($invoice_number_data) ) && $factnum_opt == 0 ){ 160 //Creating invoices numbers 161 $prefix = $pdfoptions['invoice_number_formatting_prefix']; 162 $suffix = $pdfoptions['invoice_number_formatting_suffix']; 163 $padding = $pdfoptions['invoice_number_formatting_padding']; 164 165 $order_year = date_i18n( 'Y', strtotime( $order->piecedate ) ); 166 $order_month = date_i18n( 'm', strtotime( $order->piecedate ) ); 167 $order_day = date_i18n( 'd', strtotime( $order->piecedate ) ); 168 $invoice_year = date_i18n( 'Y', $invoice_date ); 169 $invoice_month = date_i18n( 'm', $invoice_date ); 170 $invoice_day = date_i18n( 'd', $invoice_date ); 171 172 $formats['prefix'] = isset($prefix)?$prefix:''; 173 $formats['suffix'] = isset($suffix)?$suffix:''; 174 $formats['padding'] = isset($padding)?$padding:''; 175 176 // Remplacement of invoices dates in invoices numbers 177 foreach ($formats as $key => $value) { 178 $value = str_replace('[order_year]', $order_year, $value); 179 $value = str_replace('[order_month]', $order_month, $value); 180 $value = str_replace('[order_day]', $order_day, $value); 181 $value = str_replace('[invoice_year]', $invoice_year, $value); 182 $value = str_replace('[invoice_month]', $invoice_month, $value); 183 $value = str_replace('[invoice_day]', $invoice_day, $value); 184 $formats[$key] = $value; 185 } 186 187 // Padding 188 if ( ctype_digit( (string)$formats['padding'] ) ) { 189 $invoice_number = sprintf('%0'.$formats['padding'].'d', $invoice_number); 190 } 191 $formatted_invoice_number = $formats['prefix'] . $invoice_number . $formats['suffix'] ; 192 193 //Invoice number OK 194 $order->number = $formatted_invoice_number; 195 } 196 else if ( ( !empty ($invoice_number) ) && $factnum_opt == 0 ){ 197 $order->number = $invoice_number; 198 } 199 else { 200 $order->number = $order->ID; 201 } 202 203 //Invoice number not OK (order number) 204 136 $order->piecedate = $wcOrder->get_date_created(); 137 } 138 } 139 $order->original_date = $order->piecedate; 140 141 $meta_order_tax = (float) $wcOrder->get_total_tax(); 142 $meta_order_shipping_tax = (float) intval($wcOrder->get_shipping_tax()); 143 144 $order->outcome = round($wcOrder->get_total(), $rounding_precision); 145 $order->income_tax = round($meta_order_tax > $small_number ? $meta_order_tax : 0, $rounding_precision) + round($meta_order_shipping_tax > $small_number ? $meta_order_shipping_tax : 0, $rounding_precision); 146 $order->income_fdpht = round($wcOrder->get_total_shipping(), $rounding_precision); 147 $order->income_prodht = ( ($order->outcome) - ( ($order->income_tax) + ($order->income_fdpht) ) ); 148 //WC pre 2.3 bug on coupons correcting to match legal statements 149 150 $order->order_discount = (int) $wcOrder->get_total_discount(); 151 152 $order->gatewayid = $wcOrder->get_payment_method(); 153 154 if (isset($wcOrder->bypass)) 155 { 156 $order->bypass = $wcOrder->bypass; 157 } 158 159 $order->number = $order->ID; 160 161 //Customers exports options 162 $order->account_cust = ''; 163 if ($cust_opt == "0") { 164 $order->account_cust = $gen_account_cust; 165 } 166 167 // Get the country only in label if prod by country 168 if ($prod_opt == "2") { 169 $country_label = get_post_meta($order->ID,'_shipping_country',true); 170 } 171 else { 172 $country_label = ""; 173 } 174 //Payment gateway indication in label 175 if ($pay_opt == "1") { 176 $pay_meth = substr(get_post_meta($order->ID,'_payment_method',true),0,1) . substr(get_post_meta($order->ID,'_payment_method',true), 3, 1) . substr(get_post_meta($order->ID,'_payment_method',true),-1) ; 177 $order->lib = remove_accents (strtoupper($pay_meth) . ' ' . get_option ('woocommerce_accounting_lib_prefix') . ' ' . strtoupper(get_post_meta($order->ID,'_billing_company',true)) . ' ' . ucfirst(get_post_meta($order->ID,'_billing_last_name',true)) . ' ' . ucfirst(get_post_meta($order->ID,'_billing_first_name',true)) . ' ' . $country_label); 178 $order->lib = trim($order->lib); 179 } 180 elseif ($pay_opt == "2") { 181 $order_pay_meth = get_post_meta($order->ID,'_payment_method',true); 182 if (!empty (get_option('woocommerce_accounting_gateways_libs')[$order_pay_meth]['lib'])) { 183 $listed_pay_lib = get_option('woocommerce_accounting_gateways_libs')[$order_pay_meth]['lib']; 184 $pay_meth = $listed_pay_lib; 205 185 } 206 186 else { 207 $order->number = $order->ID;208 }209 210 //Customers exports options211 $order->account_cust = '';212 if ($cust_opt =="0") {213 $order->account_cust = $gen_account_cust;214 }215 elseif ($cust_opt =="1"){216 $order->gatewayid = get_post_meta($order->ID,'_payment_method',true);217 if (!empty($order->gatewayid)) {218 $order->gatewayid = get_post_meta($order->ID,'_payment_method',true);219 $order_country_acc = get_option('woocommerce_accounting_gateways_libs');220 $order->account_cust = (is_array($order_country_acc) && isset($order_country_acc[$order->gatewayid])) ? $order_country_acc[$order->gatewayid]['acc'] : '';221 }222 }223 224 225 // Get the country only in label if prod by country226 if ($prod_opt == "2") {227 $country_label = get_post_meta($order->ID,'_shipping_country',true);228 }229 else {230 $country_label = "";231 }232 //Payment gateway indication in label233 if ($pay_opt == "1") {234 187 $pay_meth = substr(get_post_meta($order->ID,'_payment_method',true),0,1) . substr(get_post_meta($order->ID,'_payment_method',true), 3, 1) . substr(get_post_meta($order->ID,'_payment_method',true),-1) ; 235 $order->lib = remove_accents (strtoupper($pay_meth) . ' ' . get_option ('woocommerce_accounting_lib_prefix') . ' ' . strtoupper(get_post_meta($order->ID,'_billing_company',true)) . ' ' . ucfirst(get_post_meta($order->ID,'_billing_last_name',true)) . ' ' . ucfirst(get_post_meta($order->ID,'_billing_first_name',true)) . ' ' . $country_label); 236 $order->lib = trim($order->lib); 237 } 238 elseif ($pay_opt == "2") { 239 $order_pay_meth = get_post_meta($order->ID,'_payment_method',true); 240 if (!empty (get_option('woocommerce_accounting_gateways_libs')[$order_pay_meth]['lib'])) { 241 $listed_pay_lib = get_option('woocommerce_accounting_gateways_libs')[$order_pay_meth]['lib']; 242 $pay_meth = $listed_pay_lib; 243 } 244 else { 245 $pay_meth = substr(get_post_meta($order->ID,'_payment_method',true),0,1) . substr(get_post_meta($order->ID,'_payment_method',true), 3, 1) . substr(get_post_meta($order->ID,'_payment_method',true),-1) ; 246 }; 247 $order->lib = remove_accents (strtoupper($pay_meth) . ' ' . get_option ('woocommerce_accounting_lib_prefix') . ' ' . strtoupper(get_post_meta($order->ID,'_billing_company',true)) . ' ' . ucfirst(get_post_meta($order->ID,'_billing_last_name',true)) . ' ' . ucfirst(get_post_meta($order->ID,'_billing_first_name',true)) . ' ' . $country_label); 248 $order->lib = trim($order->lib); 249 } 250 else { 251 $order->lib = remove_accents (get_option ('woocommerce_accounting_lib_prefix') . ' ' . strtoupper(get_post_meta($order->ID,'_billing_company',true)) . ' ' . ucfirst(get_post_meta($order->ID,'_billing_last_name',true)) . ' ' . ucfirst(get_post_meta($order->ID,'_billing_first_name',true)) . ' ' . $country_label); 252 $order->lib = trim($order->lib); 253 } 254 255 if ( $factnum_opt == 1 ){ 256 257 if ( (!empty ($invoice_number) ) && ( empty ($invoice_number_data) ) ) { 258 //Creating invoices numbers 259 $prefix = $pdfoptions['invoice_number_formatting_prefix']; 260 $suffix = $pdfoptions['invoice_number_formatting_suffix']; 261 $padding = $pdfoptions['invoice_number_formatting_padding']; 262 263 $order_year = date_i18n( 'Y', strtotime( $order->piecedate ) ); 264 $order_month = date_i18n( 'm', strtotime( $order->piecedate ) ); 265 $order_day = date_i18n( 'd', strtotime( $order->piecedate ) ); 266 $invoice_year = date_i18n( 'Y', strtotime( $invoice_date ) ); 267 $invoice_month = date_i18n( 'm', strtotime( $invoice_date ) ); 268 $invoice_day = date_i18n( 'd', strtotime( $invoice_date ) ); 269 270 271 $formats['prefix'] = isset($prefix)?$prefix:''; 272 $formats['suffix'] = isset($suffix)?$suffix:''; 273 $formats['padding'] = isset($padding)?$padding:''; 274 275 // Invoices dates replacements in invoices 276 foreach ($formats as $key => $value) { 277 $value = str_replace('[order_year]', $order_year, $value); 278 $value = str_replace('[order_month]', $order_month, $value); 279 $value = str_replace('[order_day]', $order_day, $value); 280 $value = str_replace('[invoice_year]', $invoice_year, $value); 281 $value = str_replace('[invoice_month]', $invoice_month, $value); 282 $value = str_replace('[invoice_day]', $invoice_day, $value); 283 $formats[$key] = $value; 284 } 285 286 // Padding 287 if ( ctype_digit( (string)$formats['padding'] ) && $formats['padding'] > 3 ) { 288 $invoice_number = sprintf('%0'.$formats['padding'].'d', $invoice_number); 289 } 290 $formatted_invoice_number = $formats['prefix'] . $invoice_number . $formats['suffix'] ; 291 } 292 elseif ( !empty ($invoice_number) ) { 293 $formatted_invoice_number = $invoice_number; 294 } 295 296 if (isset($formatted_invoice_number)){ 297 $order->lib = $formatted_invoice_number . ' ' . $order->lib; 298 } 299 300 } 301 302 303 //Date Format 304 $order->piecedate = woocommerce_accounting_date_format($order->piecedate, $date_format_opt); 305 $order->date_format_opt = $date_format_opt; 306 307 $meta_order_tax = (float) get_post_meta($order->ID, '_order_tax', true, 0); 308 $meta_order_shipping_tax = (float) get_post_meta($order->ID, '_order_shipping_tax', true, 0); 309 310 $order->outcome = round(get_post_meta($order->ID,'_order_total',true), $rounding_precision); 311 $order->income_tax = round($meta_order_tax > $small_number ? $meta_order_tax : 0, $rounding_precision) + round($meta_order_shipping_tax > $small_number ? $meta_order_shipping_tax : 0, $rounding_precision); 312 $order->income_fdpht = round(get_post_meta($order->ID, '_order_shipping',true), $rounding_precision); 313 $order->income_prodht = ( ($order->outcome) - ( ($order->income_tax) + ($order->income_fdpht) ) ); 314 //WC pre 2.3 bug on coupons correcting to match legal statements 315 316 $order->order_discount = (int) get_post_meta($order->ID, '_order_discount',true); 317 318 if ($order->order_discount > 0) { 319 $order->order_ex_discount = $order->order_discount + $order->outcome; 320 321 //Calculating 322 $order->prodht_exdisc = $order->order_ex_discount - $order->income_tax - $order->income_fdpht ; 323 //Shipment 324 $quotient_fdp = $order->income_fdpht / $order->order_ex_discount; 325 //Products 326 $quotient_prod = $order->prodht_exdisc / $order->order_ex_discount; 327 //Taxes 328 $quotient_tax = $order->income_tax / $order->order_ex_discount; 329 //Recalculate the right amounts 330 //Products 331 $order->income_prodht = $order->outcome * $quotient_prod ; 332 //Shipment 333 $order->income_fdpht = $order->outcome * $quotient_fdp ; 334 //Taxes 335 $order->income_tax = $order->outcome * $quotient_tax; 336 } 337 338 do_action_ref_array('woocommerce_accounting:export:order_values', array(&$order)); 339 } // End foreach 340 188 }; 189 $order->lib = remove_accents (strtoupper($pay_meth) . ' ' . get_option ('woocommerce_accounting_lib_prefix') . ' ' . strtoupper(get_post_meta($order->ID,'_billing_company',true)) . ' ' . ucfirst(get_post_meta($order->ID,'_billing_last_name',true)) . ' ' . ucfirst(get_post_meta($order->ID,'_billing_first_name',true)) . ' ' . $country_label); 190 $order->lib = trim($order->lib); 191 } 192 else { 193 $order->lib = remove_accents (get_option ('woocommerce_accounting_lib_prefix') . ' ' . strtoupper(get_post_meta($order->ID,'_billing_company',true)) . ' ' . ucfirst(get_post_meta($order->ID,'_billing_last_name',true)) . ' ' . ucfirst(get_post_meta($order->ID,'_billing_first_name',true)) . ' ' . $country_label); 194 $order->lib = trim($order->lib); 195 } 196 197 if ( $factnum_opt == 1 ){ 198 199 if ( (!empty ($invoice_number) ) && ( empty ($invoice_number_data) ) ) { 200 //Creating invoices numbers 201 $prefix = $pdfoptions['invoice_number_formatting_prefix']; 202 $suffix = $pdfoptions['invoice_number_formatting_suffix']; 203 $padding = $pdfoptions['invoice_number_formatting_padding']; 204 205 $order_year = date_i18n( 'Y', strtotime( $order->piecedate ) ); 206 $order_month = date_i18n( 'm', strtotime( $order->piecedate ) ); 207 $order_day = date_i18n( 'd', strtotime( $order->piecedate ) ); 208 $invoice_year = date_i18n( 'Y', strtotime( $invoice_date ) ); 209 $invoice_month = date_i18n( 'm', strtotime( $invoice_date ) ); 210 $invoice_day = date_i18n( 'd', strtotime( $invoice_date ) ); 211 212 213 $formats['prefix'] = isset($prefix)?$prefix:''; 214 $formats['suffix'] = isset($suffix)?$suffix:''; 215 $formats['padding'] = isset($padding)?$padding:''; 216 217 // Invoices dates replacements in invoices 218 foreach ($formats as $key => $value) { 219 $value = str_replace('[order_year]', $order_year, $value); 220 $value = str_replace('[order_month]', $order_month, $value); 221 $value = str_replace('[order_day]', $order_day, $value); 222 $value = str_replace('[invoice_year]', $invoice_year, $value); 223 $value = str_replace('[invoice_month]', $invoice_month, $value); 224 $value = str_replace('[invoice_day]', $invoice_day, $value); 225 $formats[$key] = $value; 226 } 227 228 // Padding 229 if ( ctype_digit( (string)$formats['padding'] ) && $formats['padding'] > 3 ) { 230 $invoice_number = sprintf('%0'.$formats['padding'].'d', $invoice_number); 231 } 232 $formatted_invoice_number = $formats['prefix'] . $invoice_number . $formats['suffix'] ; 233 } 234 elseif ( !empty ($invoice_number) ) { 235 $formatted_invoice_number = $invoice_number; 236 } 237 238 if (isset($formatted_invoice_number)){ 239 $order->lib = $formatted_invoice_number . ' ' . $order->lib; 240 } 241 } 242 243 //Date Format 244 $order->piecedate = woocommerce_accounting_date_format($order->piecedate, $date_format_opt); 245 $order->date_format_opt = $date_format_opt; 246 247 if ($order->order_discount > 0) { 248 $order->order_ex_discount = $order->order_discount + $order->outcome; 249 250 //Calculating 251 $order->prodht_exdisc = $order->order_ex_discount - $order->income_tax - $order->income_fdpht ; 252 //Shipment 253 $quotient_fdp = $order->income_fdpht / $order->order_ex_discount; 254 //Products 255 $quotient_prod = $order->prodht_exdisc / $order->order_ex_discount; 256 //Taxes 257 $quotient_tax = $order->income_tax / $order->order_ex_discount; 258 //Recalculate the right amounts 259 //Products 260 $order->income_prodht = $order->outcome * $quotient_prod ; 261 //Shipment 262 $order->income_fdpht = $order->outcome * $quotient_fdp ; 263 //Taxes 264 $order->income_tax = $order->outcome * $quotient_tax; 265 } 266 267 268 $order = apply_filters('woocommerce_accounting:export:order', $order, $wcOrder); 269 do_action_ref_array('woocommerce_accounting:export:order_values', array(&$order)); 270 271 $compiledOrders[] = $order; 272 } 273 274 //Collecting datas 275 if (!empty($orders)) { 341 276 $output = fopen("php://output",'w') or die ("Can't open php://output"); 342 277 //CSV Headers … … 395 330 do_action_ref_array('woocommerce_accounting:export:after_headline', array(&$output, $col_map, $separator)); 396 331 397 foreach($ orders as $order) {332 foreach($rders as $order) { 398 333 $total_income = 0; 399 334 $total_outcome = 0; … … 843 778 } 844 779 845 do_action_ref_array('woocommerce_accounting:export:before_close', array(&$output, $ orders, $separator));780 do_action_ref_array('woocommerce_accounting:export:before_close', array(&$output, $rders, $separator)); 846 781 fclose($output) or die("Can't close php://output"); 847 782 exit; -
accounting-for-woocommerce/trunk/readme.txt
r3074924 r3103642 2 2 3 3 Contributors: bastho, leroysabrina, enzomangiante, agencenous 4 Tags: woocommerce, accounting, bookkeeping, vat, export , orders, money, bank4 Tags: woocommerce, accounting, bookkeeping, vat, export 5 5 Requires at least: 5.3 6 6 Requires PHP: 7.4 … … 67 67 At this time, exports have been tested on Cogilog and GnuCash. 68 68 ## Changelog 69 70 71 72 73 74 69 75 70 76 ### 1.6.3 -
accounting-for-woocommerce/trunk/woocommerce-accounting.php
r3074924 r3103642 6 6 Author: N.O.U.S. Open Useful and Simple 7 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. 38 Version: 1.6. 9 9 */ 10 10 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
Note: See TracChangeset
for help on using the changeset viewer.