payment_for) { case 'so': return 'payment_receive'; break; case 'retainer_invoice': return 'payment_receive'; break; case 'invoice': return 'payment_receive'; break; } } protected static function writeCustomerChatLog() { return true; } public function taxDeducated() { return $this->hasOne(TaxDeducated::class); } public function saleOrders() { return $this->belongsToMany(SaleOrder::class, 'payment_details')->withPivot('payment_amount'); } public function retainerInvoices() { return $this->belongsToMany(RetainerInvoice::class, 'payment_details')->withPivot('payment_amount'); } public function invoices() { return $this->belongsToMany(Invoice::class, 'payment_details')->withPivot('payment_amount'); } public function purchaseOrders() { return $this->belongsToMany(PurchaseOrder::class, 'payment_details')->withPivot('payment_amount'); } public function labourOrders() { return $this->belongsToMany(LabourOrder::class, 'payment_details')->withPivot('payment_amount'); } public function bills() { return $this->belongsToMany(Bill::class, 'payment_details')->withPivot('payment_amount'); } public function billLo() { return $this->belongsToMany(BillLabourOrder::class, 'payment_details')->withPivot('payment_amount'); } public function chartOfAccount() { return $this->belongsTo(ChartOfAccount::class); } public function supplier() { return $this->belongsTo(Supplier::class); } public function customer() { return $this->belongsTo(Customer::class); } public function getSaleOrderAmountAttribute() { return $this->saleOrders()->sum("payment_amount") ?? 0; } public function getPurchaseOrderAmountAttribute() { return $this->purchaseOrders()->sum("payment_amount") ?? 0; } public function getLabourOrderAmountAttribute() { return $this->labourOrders()->sum("payment_amount") ?? 0; } public function getRetainerInvoiceAmountAttribute() { return $this->retainerInvoices()->sum("payment_amount") ?? 0; } public function getInvoiceAmountAttribute() { return $this->invoices()->sum("payment_amount") ?? 0; } public function getBillAmountAttribute() { return $this->bills()->sum("payment_amount") ?? 0; } public function getBillLoAmountAttribute() { return $this->billLo()->sum("payment_amount") ?? 0; } public function getTotalAmountAttribute() { return $this->sale_order_amount ?? $this->purchase_order_amount ?? $this->bill_amount ?? $this->invoice_amount ?? $this->retainer_invoice_amount ?? $this->labour_order_amount ?? $this->bill_lo_amount; } public function project() { return $this->belongsTo(Project::class); } }