Anons79 Mini Shell

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

<?php

namespace App;

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

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


    public function satuan_stok()
    {
        return $this->belongsTo(Satuan::class,'kd_satuan_stok')->withTrashed();
    }

    public function kategori()
    {
    	return $this->belongsTo(Kategori::class,'kd_kategori')->withTrashed();
    }

    public function rak()
    {
    	return $this->belongsTo(Rak::class,'kd_rak')->withTrashed();
    }

    public function harga_barang()
    {
        return $this->hasMany(HargaBarang::class,'kd_barang');
    }

    public function paket()
    {
        return $this->hasMany(DetailPaket::class,'kd_barang', 'kd_barang');
    }

    public function getGambarBarangAttribute($value)
    {
        return ($value) ?? 'coming-soon.jpg';
    }

    public function getStokAwalAttribute()
    {    
        $stok_awal = $this->stok;
        $hargas = $this->harga_barang;

        foreach ($hargas as $e) {
            foreach ($e->detail_penjualan as $a) {
                $stok_awal += $a->jumlah;
            }
        }

        return $stok_awal;
    }

    public function getStokTerjualAttribute()
    {    
        $stok = 0;
        $hargas = $this->harga_barang;

        foreach ($hargas as $e) {
            foreach ($e->detail_penjualan as $a) {
                $stok += $a->jumlah;
            }
        }

        return $stok;
    }

   

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

    public function getQtyAttribute()
    {
        $qty = 0;
        $hargas = $this->harga_barang;

        foreach ($hargas as $e) {
            foreach ($e->detail_penjualan as $a) {
                $qty += $a->jumlah;
            }
        }

        return $qty;
    }
}

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