diff --git a/js/admin.js b/js/admin.js
index 455aa83..b73ab8c 100644
--- a/js/admin.js
+++ b/js/admin.js
@@ -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
}
diff --git a/src/Config.php b/src/Config.php
index 1341aa0..4e3d6d4 100644
--- a/src/Config.php
+++ b/src/Config.php
@@ -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
*
@@ -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
+ );
+ }
}
diff --git a/src/Rest/Settings.php b/src/Rest/Settings.php
index 2892a43..ce582e3 100644
--- a/src/Rest/Settings.php
+++ b/src/Rest/Settings.php
@@ -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
);
diff --git a/style/admin.css b/style/admin.css
index 21c843e..9f8346c 100644
--- a/style/admin.css
+++ b/style/admin.css
@@ -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;
}
@@ -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;
}
}
diff --git a/views/admin.php b/views/admin.php
index 42575cb..635f851 100644
--- a/views/admin.php
+++ b/views/admin.php
@@ -173,7 +173,7 @@ class="regular-text api-key-input"
);
?>
-