fix duplicated bill plz problem

This commit is contained in:
omair saleh
2022-01-22 14:18:04 +08:00
parent ffefea75c0
commit 0fe4b6d3e3
+7 -1
View File
@@ -35,7 +35,13 @@ class TransactionResource extends JsonResource
'status' => (int) $this->status,
'details' => TransactionDetailResource::collection($this->transactionDetails),
'documents' => new DocumentResource($this->documents()->first()),
'customer_booking' => new TransactionResource($this->when((int) $this->type === TransactionType::BILL, $this->booking->transactions()->payments()->complete()->where('original_amount', '=', $this->original_amount)->where('id', '<', $this->id)->orderByDesc('id')->first())),
'customer_booking' => new TransactionResource($this->when((int) $this->type === TransactionType::BILL, function(){
$key = 0;
$bills = $this->booking->transactions()->bills()->where('original_amount', '=', $this->original_amount)->get();
if(count($bills) > 1){ $key = $bills->search(function($bill){ return $bill->id === $this->id; }); }
return $this->booking->transactions()->payments()->complete()->where('original_amount', '=', $this->original_amount)->skip($key)->first();
})),
'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:i:s A'),
'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A')
];