Update getUserByCustomerNumber references to getCustomerByIdOrCustomerNumber and enhance null-checking in requireSelected.

This commit is contained in:
Jeppe Bundgaard
2026-01-06 15:40:05 +01:00
parent 19c13977ca
commit 49589de98e
6 changed files with 37 additions and 16 deletions
@@ -125,9 +125,11 @@ class collected_order_invoices_o extends db
'economic_invoice_booked_id' => null, // This will be overwritten if the external id is set
'stripe' => null, // This will be overwritten if the processor is Stripe
'total_net_amount' => self::getTotalAmount(),
'user' => (array)(new users_o())->getUserByCustomerNumber($this->customer_number->value())->asArray(),
'user' => (new users_o())->getUserByCustomerNumber($this->customer_number->value()),
//'debug' => (new economic())->invoices->draft->get((new economic())->invoices->draft->get_from_external_id($this->getExternalId())),
];
// If the user exists, get the user details
$tmp['user'] = $tmp['user']->id ? (array)$tmp['user']->asArray() : [];
// If the external id is set, get the invoice draft id
if (!empty($this->external_id->value())) {
$tmp['economic_invoice_draft_id'] = self::isDraftExisting() ? self::getInvoiceDraftId() : null;
@@ -583,7 +585,7 @@ class collected_order_invoices_o extends db
private static function requireValidCustomer(string $customer_number): void
{
$customers = new users_o();
$customers->select($customer_number);
$customers->getUserByCustomerNumber((int)$customer_number);
$customers->requireSelected();
}
@@ -677,6 +679,10 @@ class collected_order_invoices_o extends db
self::requireSelected();
// Get the user object
$user = (new users_o())->getUserByCustomerNumber($this->customer_number->value());
// Check if the user exists
if (!$user->id) {
return;
}
// Check if the user has the onlyTankCleaning attribute
if ($user->doesUserHaveAttribute('onlyTankCleaning') && (int)$user->customer_number->value() !== 999) {
// Add the environmental fee & oil fees to the invoice draft
@@ -701,6 +707,11 @@ class collected_order_invoices_o extends db
// Get the user object
$user = (new users_o())->getUserByCustomerNumber($this->customer_number->value());
// Check if the user exists in our database
if (!$user->id) {
return;
}
// Check if the user is exempt from the administration fee
if ($user->doesUserHaveAttribute('exemptFromAdministrationFee')) {
return;
@@ -722,9 +733,9 @@ class collected_order_invoices_o extends db
// Add the fee order
$order = (new orders_o())->add(
(int)$user->id,
(int)$user->customer_number->value(),
1857,
'Administrations og miljøtillæg',
'',
'',
10,
'',
@@ -733,6 +744,10 @@ class collected_order_invoices_o extends db
);
// Assign the order to the invoice collection
$order->assignToInvoiceCollection($this->id);
// Set the order created_at date to 23:59:59 on the last day of the month the invoice collection was created
$invoice_collection_created_at = $this->created_at->value();
$last_day_of_month = date('Y-m-t', strtotime($invoice_collection_created_at)) . ' 23:59:59';
$order->created_at->set($last_day_of_month);
// Add the order item
(new order_items_o())->addItemToOrder(
(int)$order->id,