Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Display invoice date in invoices table #18

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions number-store-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function search_box( $text, $input_id ) {
<?php
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that you added this extra line by accident.

/**
* This function renders most of the columns in the list table.
*
Expand Down Expand Up @@ -121,6 +122,15 @@ public function column_default( $item, $column_name ) {
$value = '<strong>' . __('Unknown', 'woocommerce-pdf-ips-number-tools') .'</strong>';
}
break;
case 'date_display' :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a remark, not related with this PR, for those interested: When you select No for the Display invoice date option:

image

The invoice date is selected by default:

image

$order = $this->get_base_order( wc_get_order( $item->order_id ) );
if ( ! empty( $order ) ) {
$invoice = wcpdf_get_document( 'invoice', $order );
$value = $invoice->document_display_date();
} else {
$value = '<strong>' . __('Unknown', 'woocommerce-pdf-ips-number-tools') .'</strong>';
}
break;
default:
$value = isset( $item->$column_name )
? $item->$column_name
Expand Down Expand Up @@ -150,6 +160,12 @@ public function get_columns() {
if ( ! isset( WPO_WCPDF()->settings->debug_settings['calculate_document_numbers'] ) ) {
unset( $columns['calculated_number'] );
}

if( ! isset( $_GET['table_name'] ) ||
( isset( $_GET['table_name'] ) && 'wp_wcpdf_invoice_number' === $_GET['table_name'] )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new column is only displayed for the invoice number store for the current year, but not for past years.

Since v2.11.0, we handle the number stores separated by year (introduced in PR#164). For instance, for a shop that is generating invoices since 2021, you could have these tables in your database:

  1. wp_wcpdf_invoice_number: Current year
  2. wp_wcpdf_invoice_number_2022: Invoice numbers from 2022
  3. wp_wcpdf_invoice_number_2021: Invoice numbers from 2021

Therefore, instead of checking for the exact value, you should check if the wp_wcpdf_invoice_number part is present on the $_GET['table_name'].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for readable purposes, this line should be moved to :164, that is, the whole condition in a single line. Also, remember to add a space after the if statement.

) {
$columns['date_display'] = __( 'Display Invoice Date', 'woocommerce-pdf-ips-number-tools' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have two spaces after the assignment operator.

}
return apply_filters( 'wpo_wcpdf_number_tools_columns', $columns );
}

Expand Down