fix duplicated bill plz problem

This commit is contained in:
omair saleh
2022-01-22 13:59:55 +08:00
parent 0d2b2af6d5
commit ec4ef36cce
2 changed files with 8 additions and 31 deletions
+1 -18
View File
@@ -16,23 +16,6 @@ class TransactionResource extends JsonResource
*/
public function toArray($request)
{
if ($this->type === TransactionType::BILL){
$order = 1;
$bills = $this->booking->transactions()->bills()->where('original_amount', '=', $this->original_amount)->get();
if(count($bills) > 1){
$key = $bills->search(function($bill){
return $bill === $this->id;
});
$order = $key + 1;
}
$payment = $this->booking->transactions()->payments()->complete()->where('original_amount', '=', $this->original_amount)->get($order);
}
return [
'id' => $this->id,
'booking' => new BookingResource($this->booking),
@@ -52,7 +35,7 @@ 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, [])),
'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())),
'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')
];