Anons79 Mini Shell

Directory : /home/aplikasiposinfo/public_html/hayyumart.com/app/
Upload File :
Current File : /home/aplikasiposinfo/public_html/hayyumart.com/app/PermintaanBarang.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class PermintaanBarang extends Model
{
    use SoftDeletes;
    protected $guarded = [];

    public function prepared()
    {
        return $this->belongsTo(User::class,'prepared_id')->withTrashed();
    }

    public function approved()
    {
        return $this->belongsTo(User::class,'approved_id')->withTrashed();
    }

    public function rejected()
    {
        return $this->belongsTo(User::class,'rejected_id')->withTrashed();
    }

    public function detail()
    {
    	return $this->hasMany(DetailPermintaanBarang::class)->withTrashed();
    }

    public function getStatusAttribute()
    {
        $status = 'Prepared';
        if ($this->approved_id) {
            $status = 'Approved';
        }

        if ($this->rejected_id) {
            $status = 'Rejected';
        }
        
        return $status;
    }

    public function getNextStatusAttribute()
    {
        $nextStatus = 'Prepared';
        if ($this->status == 'Prepared') {
            $nextStatus = 'Approve';
        }
        
        return $nextStatus;
    }

    public function delete(){
        $this->detail()->delete();
        parent::delete();
    }


    public function getQtyBarangAttribute()
    {   
        $total = 0;
        foreach ($this->detail as $detail) {
            $total += $detail->qty;
        }

        return $total;
    }

    public function getHargaBarangAttribute()
    {   
        $total = 0;
        foreach ($this->detail as $detail) {
            $total += $detail->harga;
        }

        return $total;
    }

    public function getGrandTotalAttribute()
    {   
        $total = 0;
        foreach ($this->detail as $detail) {
            $total += $detail->harga * $detail->qty;
        }

        return $total;
    }
}

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]