Skip to content

Commit

Permalink
Handling company kennitala
Browse files Browse the repository at this point in the history
Assigns the company name as the customer name in DK if the first two digits of the kennitala is more than 40.
  • Loading branch information
aldavigdis committed Aug 5, 2024
1 parent 3b2d2c4 commit c142547
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/Export/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,37 @@ public static function to_dk_customer_body_from_order(
$ledger_code = Config::get_international_customer_ledger_code();
}

$kennitala_date_integer = intval(
substr( OrderHelper::get_kennitala( $wc_order ), 0, 2 )
);

if (
( OrderHelper::get_kennitala( $wc_order ) !== Config::get_default_kennitala() ) &&
( $kennitala_date_integer > 40 ) && ( $kennitala_date_integer < 72 )
) {
$customer_kennitala_is_company = true;
} else {
$customer_kennitala_is_company = false;
}

if (
$customer_kennitala_is_company &&
! empty( $wc_order->get_billing_company() )
) {
$customer_name = $wc_order->get_billing_company();
$contacts = array(
(object) array(
'Name' => $wc_order->get_formatted_billing_full_name(),
),
);
} else {
$customer_name = $wc_order->get_formatted_billing_full_name();
$contacts = array();
}

return (object) array(
'Number' => OrderHelper::get_kennitala( $wc_order ),
'Name' => $wc_order->get_formatted_billing_full_name(),
'Name' => $customer_name,
'Address1' => $wc_order->get_billing_address_1(),
'Address2' => $wc_order->get_billing_address_2(),
'Country' => $wc_order->get_billing_country(),
Expand All @@ -275,6 +303,7 @@ public static function to_dk_customer_body_from_order(
'PaymentMode' => $payment_mapping->dk_mode,
'PaymentTerm' => $payment_mapping->dk_term,
'LedgerCode' => $ledger_code,
'Contacts' => $contacts,
);
}
}

0 comments on commit c142547

Please sign in to comment.