Skip to content

Commit

Permalink
Afisare facturi client
Browse files Browse the repository at this point in the history
Afisare facturi client
  • Loading branch information
MihaiCraciun88 authored Dec 3, 2024
2 parents 3f8d498 + 36a4601 commit 23cee8c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
13 changes: 8 additions & 5 deletions includes/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,22 +650,25 @@ function _wp_oblio_add_content() {
global $wpdb;

$auth_id = get_current_user_id();

$field_name = 'post_id';
$order_table = $wpdb->posts;
$order_meta_table = OrdersTableDataStore::get_meta_table_name();
$performance_tables_active = get_option('woocommerce_custom_orders_table_enabled');
$order_meta_table = $wpdb->postmeta;
$clientCondition = "JOIN {$order_meta_table} pm ON(pm.{$field_name}=p.ID AND pm.meta_key='_customer_user' AND pm.meta_value={$auth_id}) ";

$performance_tables_active = get_option('woocommerce_custom_orders_table_enabled');
if ($performance_tables_active === 'yes') {
$field_name = 'order_id';
$order_table = "{$wpdb->prefix}wc_orders";
$order_table = OrdersTableDataStore::get_orders_table_name();
$order_meta_table = OrdersTableDataStore::get_meta_table_name();
$clientCondition = "WHERE p.customer_id={$auth_id} ";
}

$sql = "SELECT p.ID, pmol.meta_value AS link, pmos.meta_value AS series_name, pmon.meta_value AS number " .
"FROM {$order_table} p " .
"JOIN {$order_meta_table} pmol ON(pmol.{$field_name}=p.ID AND pmol.meta_key='oblio_invoice_link' AND pmol.meta_value<>'') " .
"JOIN {$order_meta_table} pmol ON(pmol.{$field_name}=p.ID AND pmol.meta_key='oblio_invoice_link') " .
"JOIN {$order_meta_table} pmon ON(pmon.{$field_name}=p.ID AND pmon.meta_key='oblio_invoice_number') " .
"JOIN {$order_meta_table} pmos ON(pmos.{$field_name}=p.ID AND pmos.meta_key='oblio_invoice_series_name') " .
"JOIN {$order_meta_table} pmos ON(pmos.{$field_name}=p.ID AND pmos.meta_key='oblio_invoice_series_name' AND pmol.meta_value<>'') " .
$clientCondition;
$invoices = $wpdb->get_results($sql);
include WP_OBLIO_DIR . '/view/account_invoices_page.php';
Expand Down
8 changes: 2 additions & 6 deletions src/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,8 @@ public static function get_order_by_proforma($seriesName, $number) {
return null;
}

$field_name = 'post_id';
$order_meta_table = OrdersTableDataStore::get_meta_table_name();
$performance_tables_active = get_option('woocommerce_custom_orders_table_enabled');
if ($performance_tables_active === 'yes') {
$field_name = 'order_id';
}
$field_name = self::get_meta_table_field_name();
$order_meta_table = self::get_meta_table_name();

$seriesName = esc_sql($seriesName);
$number = esc_sql($number);
Expand Down
6 changes: 4 additions & 2 deletions woocommerce-oblio.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ function _wp_oblio_generate_invoice($order_id, $options = array()) {

$normalRate = 19;
$vatIncluded = $order->get_prices_include_tax();

$price_decimals = wc_get_price_decimals();

$measuringUnit = get_option('oblio_invoice_measuring_unit') ? get_option('oblio_invoice_measuring_unit') : 'buc';
$measuringUnitTranslation = $data['language'] == 'RO' ? '' : get_option('oblio_invoice_measuring_unit_translation', '');
Expand All @@ -339,8 +341,8 @@ function _wp_oblio_generate_invoice($order_id, $options = array()) {
$vatPercentage = 0;
}

$subtotal = number_format(round($item->get_subtotal() + $item->get_subtotal_tax(), 2) / $item['quantity'], 4, '.', '');
$price = number_format(round($item->get_total() + $item->get_total_tax(), 2) / $item['quantity'], 4, '.', '');
$subtotal = number_format(round($item->get_subtotal() + $item->get_subtotal_tax(), $price_decimals) / $item['quantity'], 4, '.', '');
$price = number_format(round($item->get_total() + $item->get_total_tax(), $price_decimals) / $item['quantity'], 4, '.', '');
if ($subtotal === $price && !empty($product)) {
$regular_price = $product->get_regular_price();
if ($item->get_variation_id() > 0) {
Expand Down

0 comments on commit 23cee8c

Please sign in to comment.