Skip to content
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

Merged
merged 18 commits into from
Mar 30, 2021

Conversation

drewroberts
Copy link
Member

No description provided.

src/Models/Location.php Outdated Show resolved Hide resolved
@chx2
Copy link
Contributor

chx2 commented Mar 29, 2021

@drewroberts A significant amount of the location methods involve generating paths. Should any of these functions remain in the model?

@drewroberts
Copy link
Member Author

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:

Comment on lines 276 to 343
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);
}
}

Copy link
Member Author

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.

Copy link
Contributor

@pdbreen pdbreen Mar 29, 2021

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.

Copy link
Member Author

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!

@drewroberts drewroberts merged commit fab51ee into main Mar 30, 2021
@drewroberts drewroberts deleted the drewroberts/feature/92-location-methods branch March 30, 2021 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants