-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Methods on Location Model #92 #93
Conversation
…methods' into drewroberts/feature/92-location-methods
@drewroberts A significant amount of the location methods involve generating paths. Should any of these functions remain in the model? |
I left the main one, but we're going to use Location-Based Pages for all the others moving forward: |
src/Models/Location.php
Outdated
public function getBookingsYesterdayAttribute() | ||
{ | ||
/** @var OrderInterface $service */ | ||
$service = findService(OrderInterface::class); | ||
if ($service) { | ||
return $service::itemFilter() | ||
->bySellableType(morphClass('booking') ?? '') | ||
->byLocation($this->id) | ||
->yesterday() | ||
->apply() | ||
->count(); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
public function getRevenueBookedYesterdayAttribute() | ||
{ | ||
/** @var OrderInterface $service */ | ||
$service = findService(OrderInterface::class); | ||
if ($service) { | ||
$amount = $service::itemFilter() | ||
->bySellableType(morphClass('booking') ?? '') | ||
->byLocation($this->id) | ||
->yesterday() | ||
->apply() | ||
->sum(function (OrderItemInterface $orderItem) { | ||
return $orderItem->getAmountTotal()->getDiscountedAmount(); | ||
}); | ||
|
||
return number_format($amount / 100, 2); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
public function getBookingsLastWeekAttribute() | ||
{ | ||
/** @var OrderInterface $service */ | ||
$service = findService(OrderInterface::class); | ||
if ($service) { | ||
return $service::itemFilter() | ||
->bySellableType(morphClass('booking') ?? '') | ||
->byLocation($this->id) | ||
->week() | ||
->apply() | ||
->count(); | ||
} | ||
} | ||
|
||
public function getRevenueBookedLastWeekAttribute() | ||
{ | ||
/** @var OrderInterface $service */ | ||
$service = findService(OrderInterface::class); | ||
if ($service) { | ||
$amount = $service::itemFilter() | ||
->bySellableType(morphClass('booking') ?? '') | ||
->byLocation($this->id) | ||
->week() | ||
->apply() | ||
->sum(function (OrderItemInterface $orderItem) { | ||
return $orderItem->getAmountTotal()->getDiscountedAmount(); | ||
}); | ||
|
||
return number_format($amount / 100, 2); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdbreen Could you add these 4 reporting functions to the checkout package and allow me to pass a location to them? They are currently used in email reports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are already implemented by the checkout package -- note they are using the OrderInterface::class
to provide an answer, but only when that service is available. Not sure what more you want done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it back. Thank you!
…tipoff/locations into drewroberts/feature/92-location-methods
No description provided.