['text' => 'Success', 'color' => 'bg-green-600', 'text_color' => 'text-green-600'], self::STATUS_WAIT_UPLOAD => ['text' => 'Upload bukti transfer', 'color' => 'bg-red-600', 'text_color' => 'text-red-600'], self::STATUS_WAIT_APPROVE => ['text' => 'Menunggu Approve', 'color' => 'bg-green-600', 'text_color' => 'text-green-600'], self::STATUS_WAIT_PAYMENT => ['text' => 'Menunggu Pembayaran', 'color' => 'bg-green-600', 'text_color' => 'text-green-600'], self::STATUS_INVALID => ['text' => 'Error', 'color' => 'bg-red-600', 'text_color' => 'text-red-600'], self::STATUS_REJECT => ['text' => 'Reject', 'color' => 'bg-red-600', 'text_color' => 'text-red-600'], ][$this->is_valid]; }); } public function formatHumanCreatedAt(): Attribute { return Attribute::make(get: function () { return Carbon::parse($this->created_at)->locale('id')->translatedFormat('d F Y'); }); } public function formatCreatedAt(): Attribute { return Attribute::make(get: function () { return Carbon::parse($this->created_at)->locale('id')->translatedFormat('d F Y H:i:s'); }); } public function amount(): Attribute { return Attribute::make(get: function () { if ($this->credit == 0) { return 'Rp' . number_format($this->debit, is_float($this->debit) ? 2 : 0, ',', '.'); } return '-Rp' . number_format($this->credit, is_float($this->credit) ? 2 : 0, ',', '.'); }); } public function imageProveUrl(): Attribute { return Attribute::make(get: function () { return $this->image_prove == null ? '' : asset($this->image_prove); }); } public function customer() { return $this->belongsTo(Customer::class); } public function account() { return $this->belongsTo(Account::class); } public function update_customer_balance() { $customer = Customer::find($this->customer_id); $customer->update(['deposit_balance' => $customer->deposit_balance + $this->debit - $this->credit]); } public function create_notification() { if ($this->payment_channel == Setting::PAYMENT_MANUAL) { $status = ""; if ($this->is_valid == self::STATUS_WAIT_APPROVE) { $status = " (bukti bayar di upload, membutuhkan konfirmasi)"; } Notification::create([ 'entity_type' => User::class, 'description' => $this->customer->fullname . ' melakukan deposit manual sebesar : ' . $this->amount . $status, ]); } if ($this->payment_channel == Setting::PAYMENT_MIDTRANS) { Notification::create([ 'entity_type' => User::class, 'description' => $this->customer->fullname . ' melakukan deposit via midtrans sebesar : ' . $this->amount, ]); } } public function create_notification_user() { Notification::create([ 'entity_id' => $this->customer_id, 'description' => 'Deposit ' . $this->description . ' sebesar ' . $this->amount . ' sudah sukses diterima', ]); } }