Anons79 Mini Shell

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

<?php

namespace App;

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

class Pembelian extends Model
{
    use SoftDeletes;
    protected $guarded = [];
    protected $primaryKey = "no_pembelian";
    public $incrementing = false;

    public function supplier()
    {
    	return $this->belongsTo(Supplier::class,'kd_supplier')->withTrashed();
    }

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

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

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

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

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

    public function detail()
    {
    	return $this->hasMany(DetailPembelian::class,'no_pembelian')->withTrashed();
    }

    public function getJumlahAttribute()
    {
        $jumlah = 0;
        foreach ($this->detail as $e) {
            $jumlah += $e->jumlah;
        }
        return $jumlah;
    }

    public function getStatusAttribute()
    {
        $status = 'Prepared';
        if ($this->reviewed_id) {
            $status = 'Reviewed';
            if ($this->received_id) {
                $status = 'Received';
            }
        }

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

    public function getNextStatusAttribute()
    {
        $nextStatus = 'Review';
        if ($this->reviewed_id) {
            $nextStatus = 'Receive';
        }
        
        return $nextStatus;
    }

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

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