Skip to content

Commit

Permalink
Adding ledger code sIupport for customers
Browse files Browse the repository at this point in the history
  • Loading branch information
aldavigdis committed Jul 4, 2024
1 parent 8fc9932 commit bab5112
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 11 deletions.
2 changes: 2 additions & 0 deletions js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class NineteenEightyWoo {
make_invoice_if_kennitala_is_missing: Boolean( formData.get( 'make_invoice_if_kennitala_is_missing' ) ),
email_invoice: Boolean( formData.get( 'email_invoice' ) ),
make_credit_invoice: Boolean( formData.get( 'make_credit_invoice' ) ),
domestic_customer_ledger_code: formData.get( 'domestic_customer_ledger_code' ),
international_customer_ledger_code: formData.get( 'international_customer_ledger_code' ),
fetch_products: true
}

Expand Down
69 changes: 69 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class Config {
const DEFAULT_LEDGER_CODE_REDUCED_SALE = 's003';
const DEFAULT_LEDGER_CODE_REDUCED_PURCHASE = '';

const DEFAULT_LEDGER_CODE_DOMESTIC_CUSTOMERS = '0001';
const DEFAULT_LEDGER_CODE_INTERNATIONAL_CUSTOMERS = '0002';

/**
* Get the DK API key
*
Expand Down Expand Up @@ -652,4 +655,70 @@ public static function get_make_credit_invoice(): bool {
public static function set_make_credit_invoice( bool $value ): bool {
return update_option( 'make_credit_invoice', (int) $value );
}

/**
* Get the ledger code for domestic customers
*
* This is the ledger code that is used of the customer's country is the
* same as the shop's country.
*
* @return string The ledger code.
*/
public static function get_domestic_customer_ledger_code(): string {
return (string) (
get_option(
'1984_woo_dk_domestic_customer_ledger_code',
self::DEFAULT_LEDGER_CODE_DOMESTIC_CUSTOMERS
)
);
}

/**
* Set the ledger code for domestic customers
*
* @param string $value The ledger code to set.
*
* @return bool True on success, false on failure.
*/
public static function set_domestic_customer_ledger_code(
string $value
): bool {
return update_option(
'1984_woo_dk_domestic_customer_ledger_code',
(string) $value
);
}

/**
* Get the ledger code for international customers
*
* This is the ledger code that is used of the customer's country is not the
* same as the shop's country.
*
* @return string The ledger code.
*/
public static function get_international_customer_ledger_code(): string {
return (string) (
get_option(
'1984_woo_dk_international_customer_ledger_code',
self::DEFAULT_LEDGER_CODE_INTERNATIONAL_CUSTOMERS
)
);
}

/**
* Set the ledger code for international customers
*
* @param string $value The ledger code to set.
*
* @return bool True on success, false on failure.
*/
public static function set_international_customer_ledger_code(
string $value
): bool {
return update_option(
'1984_woo_dk_international_customer_ledger_code',
(string) $value
);
}
}
19 changes: 13 additions & 6 deletions src/Rest/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,19 @@ public static function rest_api_callback(
);
}

if (
true === property_exists(
$rest_json,
'enable_kennitala_in_block'
)
) {
if ( property_exists( $rest_json, 'domestic_customer_ledger_code' ) ) {
Config::set_domestic_customer_ledger_code(
$rest_json->domestic_customer_ledger_code
);
}

if ( property_exists( $rest_json, 'international_customer_ledger_code' ) ) {
Config::set_international_customer_ledger_code(
$rest_json->international_customer_ledger_code
);
}

if ( property_exists( $rest_json, 'enable_kennitala_in_block' ) ) {
Config::set_kennitala_block_field_enabled(
$rest_json->enable_kennitala_in_block
);
Expand Down
8 changes: 4 additions & 4 deletions style/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ body.woocommerce_page_1984-dk-woo .wrap {
font-size: 1.5rem;
}

#dk-ledger-codes-table {
.dk-ledger-codes-table {
width: auto;
}

#dk-ledger-codes-table td, #dk-ledger-codes-table th[scope=col] {
.dk-ledger-codes-table td, .dk-ledger-codes-table th[scope=col] {
width: 6em;
}

#dk-ledger-codes-table input {
.dk-ledger-codes-table input {
width: 4em;
}

Expand Down Expand Up @@ -200,7 +200,7 @@ body.woocommerce_page_1984-dk-woo .wrap {
display: block;
}

#dk-ledger-codes-table td, #dk-ledger-codes-table th[scope=col] {
.dk-ledger-codes-table td, .dk-ledger-codes-table th[scope=col] {
width: auto;
}
}
39 changes: 38 additions & 1 deletion views/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class="regular-text api-key-input"
);
?>
</p>
<table id="dk-ledger-codes-table" class="form-table">
<table id="dk-ledger-codes-table" class="form-table dk-ledger-codes-table">
<thead>
<tr>
<th></th>
Expand Down Expand Up @@ -513,7 +513,44 @@ class="regular-text api-key-input"
</p>
</td>
</tr>
</tbody>
</table>
</section>

<section class="section">
<h2><?php esc_html_e( 'Customers', '1984-dk-woo' ); ?></h2>
<table id="customers-table" class="form-table dk-ledger-codes-table">
<tbody>
<tr>
<th scope="row" class="column-title column-primary">
<label for="domestic_customer_ledger_code_field">
<?php esc_html_e( 'Ledger Code for Domestic Customers', '1984-dk-woo' ); ?>
</label>
</th>
<td>
<input
id="domestic_customer_ledger_code_field"
name="domestic_customer_ledger_code"
type="text"
value="<?php echo esc_attr( Config::get_domestic_customer_ledger_code() ); ?>"
/>
</td>
</tr>
<tr>
<th scope="row" class="column-title column-primary">
<label for="international_customer_ledger_code_field">
<?php esc_html_e( 'Ledger Code for International Customers', '1984-dk-woo' ); ?>
</label>
</th>
<td>
<input
id="international_customer_ledger_code_field"
name="international_customer_ledger_code"
type="text"
value="<?php echo esc_attr( Config::get_international_customer_ledger_code() ); ?>"
/>
</td>
</tr>
</tbody>
</table>
</section>
Expand Down

0 comments on commit bab5112

Please sign in to comment.