-
Notifications
You must be signed in to change notification settings - Fork 12
HP-2282 Bill since/till is not updated after sale is closed #95
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,4 +36,6 @@ class BillCreationDto | |
| public $charges; | ||
|
|
||
| public $state; | ||
|
|
||
| public $usageInterval; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,10 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace hiqdev\php\billing\bill; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use DateTimeImmutable; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use hiqdev\billing\hiapi\action\UsageIntervalHydrator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use hiqdev\php\billing\action\UsageInterval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Default bill factory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -23,7 +27,7 @@ class BillFactory implements BillFactoryInterface | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function create(BillCreationDto $dto) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new Bill( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $bill = new Bill( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $dto->id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $dto->type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $dto->time, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -35,5 +39,21 @@ public function create(BillCreationDto $dto) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $dto->charges ?: [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $dto->state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!empty($dto->usageInterval)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($dto->usageInterval instanceof UsageInterval) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $interval = $dto->usageInterval; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $month = $dto->usageInterval['month']['date']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $start = $dto->usageInterval['start']['date']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $end = $dto->usageInterval['end']['date'];; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove extra semicolon. There's a double semicolon at the end of the line. - $end = $dto->usageInterval['end']['date'];;
+ $end = $dto->usageInterval['end']['date'];📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $interval = UsageInterval::withinMonth( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new DateTimeImmutable($month), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new DateTimeImmutable($start), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| new DateTimeImmutable($end) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $bill->setUsageInterval($interval); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+42
to
+56
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for date parsing and array access. The current implementation lacks error handling for:
Consider wrapping the date parsing in a try-catch block and validating array structure: if (!empty($dto->usageInterval)) {
if ($dto->usageInterval instanceof UsageInterval) {
$interval = $dto->usageInterval;
} else {
+ if (!isset($dto->usageInterval['month']['date']) ||
+ !isset($dto->usageInterval['start']['date']) ||
+ !isset($dto->usageInterval['end']['date'])) {
+ throw new InvalidArgumentException('Invalid usage interval structure');
+ }
$month = $dto->usageInterval['month']['date'];
$start = $dto->usageInterval['start']['date'];
$end = $dto->usageInterval['end']['date'];
+ try {
$interval = UsageInterval::withinMonth(
new DateTimeImmutable($month),
new DateTimeImmutable($start),
new DateTimeImmutable($end)
);
+ } catch (\Exception $e) {
+ throw new InvalidArgumentException('Invalid date format in usage interval', 0, $e);
+ }
}
$bill->setUsageInterval($interval);
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $bill; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -46,7 +46,7 @@ public function mergeBill(BillInterface $first, BillInterface $other): BillInter | |||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| $charges = $this->mergeCharges(array_merge($first->getCharges(), $other->getCharges())); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return new Bill( | ||||||||||||||||||||||||||
| $bill = new Bill( | ||||||||||||||||||||||||||
| $this->mergeId($first, $other), | ||||||||||||||||||||||||||
| $first->getType(), | ||||||||||||||||||||||||||
| $first->getTime(), | ||||||||||||||||||||||||||
|
|
@@ -57,6 +57,8 @@ public function mergeBill(BillInterface $first, BillInterface $other): BillInter | |||||||||||||||||||||||||
| $first->getPlan(), | ||||||||||||||||||||||||||
| $charges | ||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||
| $bill->setUsageInterval($first->getUsageInterval()); | ||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider merging usage intervals instead of just copying from first bill. The current implementation copies the usage interval from the first bill without considering the other bill's interval. This might lead to loss of information if the bills have different intervals. Consider extending the intervals: - $bill->setUsageInterval($first->getUsageInterval());
+ $firstInterval = $first->getUsageInterval();
+ $otherInterval = $other->getUsageInterval();
+ if ($firstInterval !== null && $otherInterval !== null) {
+ $bill->setUsageInterval($firstInterval->extend($otherInterval));
+ } elseif ($firstInterval !== null) {
+ $bill->setUsageInterval($firstInterval);
+ } elseif ($otherInterval !== null) {
+ $bill->setUsageInterval($otherInterval);
+ }📝 Committable suggestion
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Здається, має бути так |
||||||||||||||||||||||||||
| return $bill; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
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.
🛠️ Refactor suggestion
Improve JSON serialization to handle DateTime objects and control property exposure.
The current implementation using
get_object_varsmight expose internal state and doesn't properly handle DateTime objects.Consider explicitly defining which properties to serialize and their format:
public function jsonSerialize(): array { - return array_filter(get_object_vars($this)); + return [ + 'month' => [ + 'date' => $this->month->format('Y-m-d\TH:i:s\Z') + ], + 'start' => [ + 'date' => $this->start->format('Y-m-d\TH:i:s\Z') + ], + 'end' => [ + 'date' => $this->end->format('Y-m-d\TH:i:s\Z') + ] + ]; }