Skip to content

Commit

Permalink
Adding a DK invoice column [wip]
Browse files Browse the repository at this point in the history
  • Loading branch information
aldavigdis committed Jul 18, 2024
1 parent 9527ad4 commit 130c156
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/Export/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public static function to_dk_invoice_body(
$invoice_body = ExportOrder::to_dk_order_body( $wc_order );

$invoice_body['SalesPerson'] = Config::get_default_sales_person_number();
$invoice_body['Text2'] = $wc_order->get_customer_note( 'view' );

$payment_mapping = Config::get_payment_mapping(
$wc_order->get_payment_method()
Expand Down
84 changes: 76 additions & 8 deletions src/Hooks/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use NineteenEightyFour\NineteenEightyWoo\Export\Customer;
use NineteenEightyFour\NineteenEightyWoo\Helpers\Product as ProductHelper;
use stdClass;
use WC_Order;
use WP_Screen;

/**
Expand All @@ -34,9 +35,17 @@ public function __construct() {

add_action( 'admin_menu', array( __CLASS__, 'add_menu_page' ) );

// Superlobal is not passed into anything.
// phpcs:ignore WordPress.Security.NonceVerification
if ( ( isset( $_GET['page'] ) ) && ( $_GET['page'] === '1984-dk-woo' ) ) {
if (
(
isset( $_GET['page'] )
)
&&
(
// Superlobal is not passed into anything.
// phpcs:ignore WordPress.Security.NonceVerification
$_GET['page'] === '1984-dk-woo' || $_GET['page'] === 'wc-orders'
)
) {
add_action(
'admin_init',
array( __CLASS__, 'enqueue_styles_and_scripts' )
Expand All @@ -49,6 +58,19 @@ public function __construct() {
10
);

add_filter(
'woocommerce_shop_order_list_table_columns',
array( __CLASS__, 'add_dk_invoice_column' ),
10
);

add_action(
'woocommerce_shop_order_list_table_custom_column',
array( __CLASS__, 'dk_invoice_column' ),
10,
2
);

if ( Config::get_product_convertion_to_variation_enabled() ) {
add_filter(
'bulk_actions-edit-product',
Expand All @@ -65,6 +87,51 @@ public function __construct() {
}
}

public static function add_dk_invoice_column( array $columns ): array {
$first = array_slice( $columns, 0, 2, true );
$last = array_slice( $columns, 2, null, true );
return array_merge(
$first,
array( 'dk_invoice_id' => esc_html__( 'DK Invoice', '1984-dk-woo' ) ),
$last
);
}

public static function dk_invoice_column(
string $column_name,
WC_Order $wc_order
) {
if ( $column_name === 'dk_invoice_id' ) {
$invoice_number = $wc_order->get_meta(
'1984_woo_dk_invoice_number',
true,
'view'
);

$invoice_creation_error = $wc_order->get_meta(
'1984_dk_woo_invoice_creation_error',
true,
'view'
);

if ( ! empty( $invoice_number ) ) {
echo '<span class="dashicons dashicons-yes debit_invoice"></span> ';
echo '<span class="debit_invoice">';
echo esc_html( $invoice_number );
echo '</span>';
return;
}

if ( ! empty( $invoice_creation_error ) ) {
echo '<span class="dashicons dashicons-no invoice_error"></span> ';
echo '<span class="invoice_error">';
echo 'Error';
echo '</span>';
return;
}
}
}

/**
* Enqueue the styles and scripts for the products screen
*
Expand All @@ -78,11 +145,6 @@ public static function enqueue_products_styles_and_scripts(
current_user_can( 'edit_others_posts' ) &&
$current_screen->id === 'edit-product'
) {
wp_enqueue_style(
handle: 'nineteen-eighty-woo-products',
src: plugins_url( 'style/products.css', dirname( __DIR__ ) ),
ver: self::ASSET_VERSION
);

wp_enqueue_script(
'nineteen-eighty-woo',
Expand Down Expand Up @@ -213,6 +275,12 @@ public static function enqueue_styles_and_scripts(): void {
ver: self::ASSET_VERSION
);

wp_enqueue_style(
handle: 'nineteen-eighty-woo-products',
src: plugins_url( 'style/products.css', dirname( __DIR__ ) ),
ver: self::ASSET_VERSION
);

wp_enqueue_script(
'nineteen-eighty-woo',
plugins_url( 'js/admin.js', dirname( __DIR__ ) ),
Expand Down
14 changes: 14 additions & 0 deletions style/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,20 @@ body.woocommerce_page_1984-dk-woo .wrap {
display: none;
}

.column-dk_invoice_id .dashicons {
padding: 4px 0px 4px 4px;
}

.column-dk_invoice_id .debit_invoice {
color: rgb(0, 50, 100);
font-weight: 600;
}

.column-dk_invoice_id .invoice_error {
color: #900;
font-weight: 600;
}

@media screen and (max-width: 782px) {
#nineteen-eighty-woo-wrap h1 {
margin-left: 21px;
Expand Down

0 comments on commit 130c156

Please sign in to comment.