|
|
|
|
@ -249,6 +249,9 @@ class Orders extends SoftDeletesModel
|
|
|
|
|
$order_items = $this->orderItems()->get();
|
|
|
|
|
|
|
|
|
|
switch ($this->status) {
|
|
|
|
|
case self::STATUS_FINISHED:
|
|
|
|
|
$total = $order_items->sum("total");
|
|
|
|
|
break;
|
|
|
|
|
case self::STATUS_UNCONFIRMED:
|
|
|
|
|
case self::STATUS_UNASSIGNED:
|
|
|
|
|
case self::STATUS_ONGOING:
|
|
|
|
|
@ -257,20 +260,15 @@ class Orders extends SoftDeletesModel
|
|
|
|
|
$price = $this->price;
|
|
|
|
|
if ($order_items->last()) {
|
|
|
|
|
$days = max(0, Carbon::parse($order_items->last()->service_date)->diffInDays($this->to_date, false));
|
|
|
|
|
if (Carbon::parse($order_items->last()->service_date)->greaterThan($this->to_date)) {
|
|
|
|
|
$this->to_date = $order_items->last()->service_date;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$days = max(0, Carbon::parse($this->from_date)->diffInDays($this->to_date, false) + 1);
|
|
|
|
|
}
|
|
|
|
|
$un_generated_total = $price * $days;
|
|
|
|
|
$total = $items_total + $un_generated_total;
|
|
|
|
|
break;
|
|
|
|
|
case self::STATUS_FINISHED:
|
|
|
|
|
$total = $order_items->sum("total");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($order_items->last()) {
|
|
|
|
|
if (Carbon::parse($order_items->last()->service_date)->greaterThan($this->to_date)) {
|
|
|
|
|
$this->to_date = $order_items->last()->service_date;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$paid_total = $order_items->filter(function ($item) {
|
|
|
|
|
|