示例#1
0
 /**
  * create_document.
  */
 function create_document($order_id, $invoice_type)
 {
     if (false == wcj_is_invoice_created($order_id, $invoice_type)) {
         wcj_create_invoice($order_id, $invoice_type);
     }
     /*
     if ( '' == get_post_meta( $order_id, '_wcj_invoicing_' . $invoice_type . '_number', true ) ) {
     	if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type . '_sequential_enabled' ) ) {
     		$the_invoice_number = get_option( 'wcj_invoicing_' . $invoice_type . '_numbering_counter', 1 );
     		update_option( 'wcj_invoicing_' . $invoice_type . '_numbering_counter', ( $the_invoice_number + 1 ) );
     	} else {
     		$the_invoice_number = $order_id;
     	}
     	update_post_meta( $order_id, '_wcj_invoicing_' . $invoice_type . '_number', $the_invoice_number );
     	update_post_meta( $order_id, '_wcj_invoicing_' . $invoice_type . '_date', time() );
     }
     */
 }
 /**
  * Renumerate invoices function.
  *
  * @version 2.3.10
  */
 function renumerate_invoices($invoice_type, $start_number, $start_date, $end_date, $order_statuses, $the_delete_all)
 {
     $output = '';
     if (0 != $start_number) {
         update_option('wcj_invoicing_' . $invoice_type . '_numbering_counter', $start_number);
     }
     $date_query_array = array(array('after' => $start_date, 'inclusive' => true));
     if ('' != $end_date) {
         $date_query_array[0]['before'] = $end_date;
     }
     $deleted_invoices_counter = 0;
     $created_invoices_counter = 0;
     $offset = 0;
     $block_size = 96;
     while (true) {
         $args = array('post_type' => 'shop_order', 'post_status' => 'any', 'posts_per_page' => $block_size, 'offset' => $offset, 'orderby' => 'date', 'order' => 'ASC', 'date_query' => $date_query_array);
         $loop = new WP_Query($args);
         if (!$loop->have_posts()) {
             break;
         }
         while ($loop->have_posts()) {
             $loop->the_post();
             $order_id = $loop->post->ID;
             if (in_array($loop->post->post_status, $order_statuses) && strtotime($loop->post->post_date) >= strtotime($start_date) && (strtotime($loop->post->post_date) <= strtotime($end_date) || '' == $end_date)) {
                 $the_order = wc_get_order($order_id);
                 if (0 != $the_order->get_total()) {
                     wcj_create_invoice($order_id, $invoice_type, strtotime($loop->post->post_date));
                     $created_invoices_counter++;
                 }
             } else {
                 if ($the_delete_all && wcj_is_invoice_created($order_id, $invoice_type)) {
                     wcj_delete_invoice($order_id, $invoice_type);
                     $deleted_invoices_counter++;
                 }
             }
         }
         $offset += $block_size;
     }
     $output .= '<p>' . sprintf(__('Total documents created: %d', 'woocommerce-jetpack'), $created_invoices_counter) . '</p>';
     $output .= '<p>' . sprintf(__('Total documents deleted: %d', 'woocommerce-jetpack'), $deleted_invoices_counter) . '</p>';
     return $output;
 }
 /**
  * add_pdf_invoices_action_links.
  *
  * @version 2.3.7
  */
 function add_pdf_invoices_action_links($actions, $the_order)
 {
     $invoice_types = wcj_get_enabled_invoice_types();
     foreach ($invoice_types as $invoice_type) {
         if (!wcj_is_invoice_created($the_order->id, $invoice_type['id'])) {
             continue;
         }
         $my_account_option_name = 'wcj_invoicing_' . $invoice_type['id'] . '_enabled_for_customers';
         if ('yes' === get_option($my_account_option_name, 'no')) {
             $the_action_id = $invoice_type['id'];
             $query_args = array('order_id' => $the_order->id, 'invoice_type_id' => $invoice_type['id'], 'get_invoice' => '1');
             if ('yes' === get_option('wcj_invoicing_' . $invoice_type['id'] . '_save_as_enabled', 'no')) {
                 $query_args['save_pdf_invoice'] = '1';
             }
             $the_url = add_query_arg($query_args);
             $the_name = get_option('wcj_invoicing_' . $invoice_type['id'] . '_link_text');
             if ('' == $the_name) {
                 $the_name = $invoice_type['title'];
             }
             $the_action = 'view ' . $invoice_type['id'];
             $actions[$the_action_id] = array('url' => $the_url, 'name' => $the_name, 'action' => $the_action);
         }
     }
     return $actions;
 }
 /**
  * Invoices Report function.
  */
 function get_invoices_report($year, $month)
 {
     $output = '';
     $data = array();
     $data[] = array(__('Invoice Nr.', 'woocommerce-jetpack'), __('Invoice Date', 'woocommerce-jetpack'), __('Order ID', 'woocommerce-jetpack'), __('Customer Country', 'woocommerce-jetpack'), __('Tax %', 'woocommerce-jetpack'), __('Order Total Tax Excl.', 'woocommerce-jetpack'), __('Order Taxes', 'woocommerce-jetpack'), __('Order Total', 'woocommerce-jetpack'), __('Order Currency', 'woocommerce-jetpack'));
     $total_sum = 0;
     $total_sum_excl_tax = 0;
     $total_tax = 0;
     $args = array('post_type' => 'shop_order', 'post_status' => 'any', 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'ASC', 'year' => $year, 'monthnum' => $month);
     $loop = new WP_Query($args);
     while ($loop->have_posts()) {
         $loop->the_post();
         $order_id = $loop->post->ID;
         $invoice_type_id = 'invoice';
         if (wcj_is_invoice_created($order_id, $invoice_type_id)) {
             $the_order = wc_get_order($order_id);
             $user_meta = get_user_meta($the_order->get_user_id());
             $billing_country = isset($user_meta['billing_country'][0]) ? $user_meta['billing_country'][0] : '';
             $shipping_country = isset($user_meta['shipping_country'][0]) ? $user_meta['shipping_country'][0] : '';
             $customer_country = '' == $billing_country ? $shipping_country : $billing_country;
             $order_total = $the_order->get_total();
             $order_tax = apply_filters('wcj_order_total_tax', $the_order->get_total_tax(), $the_order);
             //$order_tax_percent = ( isset( $taxes_by_countries_eu[ $customer_country ] ) ) ? $taxes_by_countries_eu[ $customer_country ] : 0;
             //$order_tax_percent /= 100;
             //$order_tax = $order_total * $order_tax_percent;
             $order_total_exlc_tax = $order_total - $order_tax;
             $order_tax_percent = 0 == $order_total ? 0 : $order_tax / $order_total_exlc_tax;
             $total_sum += $order_total;
             $total_sum_excl_tax += $order_total_exlc_tax;
             $total_tax += $order_tax;
             //$order_tax_html = ( 0 == $order_tax ) ? '' : sprintf( '$ %.2f', $order_tax );
             $order_tax_html = sprintf('%.2f', $order_tax);
             $data[] = array(wcj_get_invoice_number($order_id, $invoice_type_id), wcj_get_invoice_date($order_id, $invoice_type_id, 0, get_option('date_format')), $order_id, $customer_country, sprintf('%.0f %%', $order_tax_percent * 100), sprintf('%.2f', $order_total_exlc_tax), $order_tax_html, sprintf('%.2f', $order_total), $the_order->get_order_currency());
         }
     }
     /* $output .= '<h3>' . 'Total Sum Excl. Tax: ' . sprintf( '$ %.2f', $total_sum_excl_tax ) . '</h3>';
     		$output .= '<h3>' . 'Total Sum: ' . sprintf( '$ %.2f', $total_sum ) . '</h3>';
     		$output .= '<h3>' . 'Total Tax: ' . sprintf( '$ %.2f', $total_tax ) . '</h3>'; */
     $output .= wcj_get_table_html($data, array('table_class' => 'widefat'));
     /**/
     return $output;
 }
 }
 /**
  * delete_document.
  *
  * @version 2.3.0
  * @since   2.3.0
  */
 function delete_document($order_id, $invoice_type)
 {
     if (true == wcj_is_invoice_created($order_id, $invoice_type)) {
         wcj_delete_invoice($order_id, $invoice_type);
     }
 /**
 * add_pdf_invoice_icon_css.
 *
 	function add_pdf_invoice_icon_css() {
 		$invoice_types = wcj_get_enabled_invoice_types();
 		foreach ( $invoice_types as $invoice_type ) {
 			echo '<style> a.button.tips.view.' .      $invoice_type['id'] . ':after { content: "' . $invoice_type['icon'] . '" !important; } </style>';
 		}
 	}
 
     /**
 * add_pdf_invoices_action_links.
 */
 function add_pdf_invoices_action_links($actions, $the_order)
 {
     $invoice_types = wcj_get_enabled_invoice_types();
     foreach ($invoice_types as $invoice_type) {
         if (!wcj_is_invoice_created($the_order->id, $invoice_type['id'])) {
             continue;
         }
         //$admin_option_name = 'wcj_invoicing_' . $invoice_type['id'] . '_admin_orders_page';
         $my_account_option_name = 'wcj_invoicing_' . $invoice_type['id'] . '_enabled_for_customers';
         /*if ( ( 'woocommerce_admin_order_actions'          === current_filter() && 'add_action_link' === get_option( $admin_option_name, 'add_column' ) ) ||
           ( 'woocommerce_my_account_my_orders_actions' === current_filter() && 'yes' === apply_filters( 'wcj_get_option_filter', 'no', get_option( $my_account_option_name, 'no' ) ) ) ) {*/
         //if ( 'woocommerce_my_account_my_orders_actions' === current_filter() && 'yes' === apply_filters( 'wcj_get_option_filter', 'no', get_option( $my_account_option_name, 'no' ) ) ) {
         if ('yes' === get_option($my_account_option_name, 'no')) {
             $the_action_id = $invoice_type['id'];
             //$the_url = basename( $_SERVER['REQUEST_URI'] ) . '&order_id=' . $the_order->id . '&invoice_type_id=' . $invoice_type['id'] . '&get_invoice=1';
             $query_args = array('order_id' => $the_order->id, 'invoice_type_id' => $invoice_type['id'], 'get_invoice' => '1');
             if ('yes' === get_option('wcj_invoicing_' . $invoice_type['id'] . '_save_as_enabled', 'no')) {
                 $query_args['save_pdf_invoice'] = '1';
             }
             $the_url = add_query_arg($query_args);
             $the_name = $invoice_type['desc'];
             $the_action = 'view ' . $invoice_type['id'];
             /* if ( 'yes' === get_option( 'wcj_invoicing_' . $invoice_type['id'] . '_save_as_enabled', 'no' ) ) {
             				$the_url .= '&save_pdf_invoice=1';
             			} */
             $actions[$the_action_id] = array('url' => $the_url, 'name' => $the_name, 'action' => $the_action);
         }
     }
     return $actions;
 }
 /**
  * Renumerate invoices function.
  */
 public function renumerate_invoices($invoice_type, $start_number, $start_date, $order_statuses, $the_delete_all)
 {
     $output = '';
     if (0 != $start_number) {
         update_option('wcj_invoicing_' . $invoice_type . '_numbering_counter', $start_number);
     }
     $args = array('post_type' => 'shop_order', 'post_status' => 'any', 'posts_per_page' => -1, 'orderby' => 'date', 'order' => 'ASC');
     $loop = new WP_Query($args);
     $deleted_invoices_counter = 0;
     $created_invoices_counter = 0;
     while ($loop->have_posts()) {
         $loop->the_post();
         $order_id = $loop->post->ID;
         if (in_array($loop->post->post_status, $order_statuses) && strtotime($loop->post->post_date) >= strtotime($start_date)) {
             $the_order = wc_get_order($order_id);
             if (0 != $the_order->get_total()) {
                 wcj_create_invoice($order_id, $invoice_type, strtotime($loop->post->post_date));
                 $created_invoices_counter++;
             }
         } else {
             if ($the_delete_all && wcj_is_invoice_created($order_id, $invoice_type)) {
                 wcj_delete_invoice($order_id, $invoice_type);
                 $deleted_invoices_counter++;
             }
         }
     }
     $output .= '<p>' . sprintf(__('Total documents created: %d', 'woocommerce-jetpack'), $created_invoices_counter) . '</p>';
     $output .= '<p>' . sprintf(__('Total documents deleted: %d', 'woocommerce-jetpack'), $deleted_invoices_counter) . '</p>';
     return $output;
 }
 /**
  * Invoices Report Data function.
  *
  * @version 2.5.7
  * @since   2.5.7
  */
 function get_invoices_report_data($year, $month, $invoice_type_id)
 {
     $data = array();
     $data[] = array(__('Document Nr.', 'woocommerce-jetpack'), __('Document Date', 'woocommerce-jetpack'), __('Order ID', 'woocommerce-jetpack'), __('Customer Country', 'woocommerce-jetpack'), __('Customer VAT ID', 'woocommerce-jetpack'), __('Tax %', 'woocommerce-jetpack'), __('Order Total Tax Excl.', 'woocommerce-jetpack'), __('Order Taxes', 'woocommerce-jetpack'), __('Order Total', 'woocommerce-jetpack'), __('Order Currency', 'woocommerce-jetpack'), __('Refunds', 'woocommerce-jetpack'));
     $total_sum = 0;
     $total_sum_excl_tax = 0;
     $total_tax = 0;
     $first_minute = mktime(0, 0, 0, $month, 1, $year);
     $last_minute = mktime(23, 59, 59, $month, date('t', $first_minute), $year);
     $offset = 0;
     $block_size = 256;
     while (true) {
         $args = array('post_type' => 'shop_order', 'post_status' => 'any', 'posts_per_page' => $block_size, 'orderby' => 'meta_value_num', 'meta_key' => '_wcj_invoicing_' . $invoice_type_id . '_date', 'order' => 'ASC', 'meta_query' => array(array('key' => '_wcj_invoicing_' . $invoice_type_id . '_date', 'value' => array($first_minute, $last_minute), 'type' => 'numeric', 'compare' => 'BETWEEN')), 'offset' => $offset, 'fields' => 'ids');
         $loop = new WP_Query($args);
         if (!$loop->have_posts()) {
             break;
         }
         foreach ($loop->posts as $order_id) {
             if (wcj_is_invoice_created($order_id, $invoice_type_id)) {
                 $the_order = wc_get_order($order_id);
                 $user_meta = get_user_meta($the_order->get_user_id());
                 $billing_country = isset($user_meta['billing_country'][0]) ? $user_meta['billing_country'][0] : '';
                 $shipping_country = isset($user_meta['shipping_country'][0]) ? $user_meta['shipping_country'][0] : '';
                 $customer_country = '' == $billing_country ? $shipping_country : $billing_country;
                 $customer_vat_id = get_post_meta($order_id, '_billing_eu_vat_number', true);
                 $order_total = $the_order->get_total();
                 $order_tax = apply_filters('wcj_order_total_tax', $the_order->get_total_tax(), $the_order);
                 //					$order_tax_percent = ( isset( $taxes_by_countries_eu[ $customer_country ] ) ) ? $taxes_by_countries_eu[ $customer_country ] : 0;
                 //					$order_tax_percent /= 100;
                 //					$order_tax = $order_total * $order_tax_percent;
                 $order_total_exlc_tax = $order_total - $order_tax;
                 $order_total_tax_not_rounded = $the_order->get_cart_tax() + $the_order->get_shipping_tax();
                 $order_tax_percent = 0 == $order_total ? 0 : $order_total_tax_not_rounded / $order_total_exlc_tax;
                 $total_sum += $order_total;
                 $total_sum_excl_tax += $order_total_exlc_tax;
                 $total_tax += $order_tax;
                 //					$order_tax_html = ( 0 == $order_tax ) ? '' : sprintf( '$ %.2f', $order_tax );
                 $order_tax_html = sprintf('%.2f', $order_tax);
                 $data[] = array(wcj_get_invoice_number($order_id, $invoice_type_id), wcj_get_invoice_date($order_id, $invoice_type_id, 0, get_option('date_format')), $order_id, $customer_country, $customer_vat_id, sprintf('%.0f %%', $order_tax_percent * 100), sprintf('%.2f', $order_total_exlc_tax), $order_tax_html, sprintf('%.2f', $order_total), $the_order->get_order_currency(), $the_order->get_total_refunded());
             }
         }
         $offset += $block_size;
     }
     return $data;
 }