From e7e4a416d2032042157e3e17f70989f28285b462 Mon Sep 17 00:00:00 2001 From: GuilhermeLinkNacional Date: Tue, 26 Mar 2024 15:40:05 -0300 Subject: [PATCH] feat: Add page to display only subscription #23 --- admin/class-wc-invoice-payment-admin.php | 542 ++++++++++-------- admin/class-wc-invoice-payment-table.php | 34 +- .../class-wc-invoice-payment-subscription.php | 7 +- languages/wc-invoice-payment-pt_BR.po | 8 +- languages/wc-invoice-payment.pot | 6 + 5 files changed, 327 insertions(+), 270 deletions(-) diff --git a/admin/class-wc-invoice-payment-admin.php b/admin/class-wc-invoice-payment-admin.php index 8dcabee..d41883b 100755 --- a/admin/class-wc-invoice-payment-admin.php +++ b/admin/class-wc-invoice-payment-admin.php @@ -172,6 +172,17 @@ public function add_setting_session(): void { 1 ); + add_submenu_page( + 'wc-invoice-payment', + __('List Subscriptions', 'wc-invoice-payment'), + __('Subscriptions', 'wc-invoice-payment'), + 'manage_woocommerce', + 'wc-subscription-payment', + array($this, 'render_subscription_list_page'), + 1 + ); + + add_submenu_page( 'wc-invoice-payment', __('Settings', 'wc-invoice-payment'), @@ -179,7 +190,7 @@ public function add_setting_session(): void { 'manage_woocommerce', 'settings', array($this, 'render_settings_page'), - 1 + 2 ); } @@ -748,27 +759,60 @@ public function render_invoice_list_page(): void { return; } ?> -
- + + + +
+

+
+ prepare_items(); + $object->display(); + ?> +
+
+
+ -

-
- prepare_items(); - $object->display(); ?> -
- - - +
+ + +
+

+
+ prepare_items(true); + $object->display(); + ?> +
+
+
+ -
-

- -
- -
-

- -

-
-
-
- - -
-
- - -
-
- - -
-
- - -
-
-
+
+

+ + + +
+

+ +

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
-
-
- - -
-
- - +
+ +
+
+
+ +
+
+ + +
-
- - +
+
-
-
-
- -
-
-
- -
-
- - +

+ +

+
-
-
-
- -
-
-
-

- -

-
-
-
- - -
-
- - +
+
+ + +
+
+ + +
+
+ +
+
-
+
+
+ class="btn btn-add-line" + onclick="lkn_wcip_add_amount_row()" + >
-
-
-
- -
-
-
-
-

- -

-
-
- - +
+
+

+ +

+
+
+ + +
+
-
+
- -
- - + document.addEventListener('DOMContentLoaded', () => { + startTinyMce('lkn-wc-invoice-payment-footer-notes', 'submit') + }) + + lkn_wcip_list_table_data($order_by, $order, $search_term, $invoiceList); + $found_data = $this->lkn_wcip_list_table_data($order_by, $order, $search_term, $invoiceList, $showSubscriptions); $this->items = array_slice($found_data, (($current_page-1)*$per_page), $per_page); $this->set_pagination_args([ @@ -1502,7 +1502,7 @@ public function handle_row_actions($item, $column_name, $primary) { * * @return array */ - public function lkn_wcip_list_table_data($order_by = '', $order = '', $search_term = '', $invoiceList) { + public function lkn_wcip_list_table_data($order_by = '', $order = '', $search_term = '', $invoiceList, $showSubscriptions) { ?>
get_meta('lkn_exp_date'); - $dueDate = empty($dueDate) ? '-' : date($dateFormat, strtotime($dueDate)); - $iniDate = $invoice->get_meta('lkn_ini_date'); - $iniDate = empty($iniDate) ? '-' : date($dateFormat, strtotime($iniDate)); - - $data_array[] = [ - 'lkn_wcip_id' => $invoiceId, - 'lkn_wcip_client' => $invoice->get_billing_first_name(), - 'lkn_wcip_status' => ucfirst(wc_get_order_status_name($invoice->get_status())), - 'lkn_wcip_total_price' => get_woocommerce_currency_symbol($invoice->get_currency()) . ' ' . number_format($invoice->get_total(), wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()), - 'lkn_wcip_exp_date' => $dueDate, - 'lkn_wcip_ini_date' => $iniDate, - ]; + if($showSubscriptions == $invoice->get_meta('lkn_is_subscription')){ + $dueDate = $invoice->get_meta('lkn_exp_date'); + $dueDate = empty($dueDate) ? '-' : date($dateFormat, strtotime($dueDate)); + $iniDate = $invoice->get_meta('lkn_ini_date'); + $iniDate = empty($iniDate) ? '-' : date($dateFormat, strtotime($iniDate)); + $data_array[] = [ + 'lkn_wcip_id' => $invoiceId, + 'lkn_wcip_client' => $invoice->get_billing_first_name(), + 'lkn_wcip_status' => ucfirst(wc_get_order_status_name($invoice->get_status())), + 'lkn_wcip_total_price' => get_woocommerce_currency_symbol($invoice->get_currency()) . ' ' . number_format($invoice->get_total(), wc_get_price_decimals(), wc_get_price_decimal_separator(), wc_get_price_thousand_separator()), + 'lkn_wcip_exp_date' => $dueDate, + 'lkn_wcip_ini_date' => $iniDate, + ]; + } } } ?>
calculate_next_due_date( $subscription_interval_number, $subscription_interval_type ); $next_due_date = $result['next_due_date']; $order->add_meta_data('lkn_time_removed', $result['time_removed']); + $order->add_meta_data('lkn_is_subscription', true); $order->save(); $this->schedule_next_invoice_generation( $order_id, $next_due_date ); } @@ -171,6 +172,7 @@ function create_next_invoice( $order_id ) { $billing_last_name = $order->get_billing_last_name(); $payment_method = $order->get_payment_method(); $time_removed = $order->get_meta('lkn_time_removed'); + $is_subscription = $order->get_meta('lkn_is_subscription'); $iniDate = new DateTime(); $iniDateFormatted = $iniDate->format('Y-m-d'); $iniDate->modify("+" . $time_removed); @@ -186,10 +188,7 @@ function create_next_invoice( $order_id ) { $new_order->set_payment_method($payment_method); $new_order->add_meta_data('lkn_ini_date', $iniDateFormatted); $new_order->add_meta_data('lkn_exp_date', $expDateFormatted); - - add_option("lkn_ini_dateTeste".$order_id, $iniDateFormatted); - add_option("lkn_exp_dateTeste".$order_id, $expDateFormatted); - add_option("time_removedTeste".$order_id, $time_removed); + $new_order->add_meta_data('lkn_is_subscription', $is_subscription);; if ( ! $new_order ) { return; diff --git a/languages/wc-invoice-payment-pt_BR.po b/languages/wc-invoice-payment-pt_BR.po index 851b6c7..e3fdcba 100755 --- a/languages/wc-invoice-payment-pt_BR.po +++ b/languages/wc-invoice-payment-pt_BR.po @@ -183,4 +183,10 @@ msgid "Months" msgstr "Meses" msgid "Years" -msgstr "Anos" \ No newline at end of file +msgstr "Anos" + +msgid "Subscriptions" +msgstr "Assinaturas" + +msgid "List Subscriptions" +msgstr "Listar assinaturas" \ No newline at end of file diff --git a/languages/wc-invoice-payment.pot b/languages/wc-invoice-payment.pot index ca24a15..e9ca474 100755 --- a/languages/wc-invoice-payment.pot +++ b/languages/wc-invoice-payment.pot @@ -183,4 +183,10 @@ msgid "Months" msgstr "" msgid "Years" +msgstr "" + +msgid "Subscriptions" +msgstr "" + +msgid "List Subscriptions" msgstr "" \ No newline at end of file