2022-08-20 13:21:23 +07:00
|
|
|
<?php
|
|
|
|
namespace App\Helpers;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class Helperku {
|
|
|
|
public static function get_stok_jenis_barang($id_jenis_barang) {
|
|
|
|
|
|
|
|
$data = DB::table('tbl_barang')->where('jenis_barang_id',$id_jenis_barang)->sum('jumlah_barang');
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_stok_barang($id_barang,$jenis_barang = '')
|
|
|
|
{
|
|
|
|
|
|
|
|
$data_barang = DB::table('tbl_barang')->where('id',$id_barang)->get();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($jenis_barang == 'pinjam')
|
|
|
|
{
|
|
|
|
|
|
|
|
$data_barang_pinjam = DB::table('tbl_barang_keluar')->where('barang_id',$id_barang)->where('jenis_keluar','pinjam')->sum('jumlah_keluar');
|
|
|
|
if($data_barang_pinjam == NULL){
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
|
|
return $data_barang_pinjam;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}else if($jenis_barang == 'rusak')
|
|
|
|
{
|
|
|
|
$data_barang_rusak = DB::table('tbl_barang_keluar')->where('barang_id',$id_barang)->where('jenis_keluar','rusak')->sum('jumlah_keluar');
|
|
|
|
if($data_barang_rusak == 0){
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}else{
|
|
|
|
|
|
|
|
|
|
|
|
return $data_barang_rusak;
|
|
|
|
|
|
|
|
}
|
|
|
|
}else if($jenis_barang == 'now' ){
|
|
|
|
$data_barang_pinjam = DB::table('tbl_barang_keluar')->where('barang_id',$id_barang)->where('jenis_keluar','pinjam')->sum('jumlah_keluar');
|
|
|
|
$data_barang_rusak = DB::table('tbl_barang_keluar')->where('barang_id',$id_barang)->where('jenis_keluar','rusak')->sum('jumlah_keluar');
|
|
|
|
|
|
|
|
|
|
|
|
return intval($data_barang[0]->jumlah_barang) - intval($data_barang_pinjam) - intval($data_barang_rusak) ;
|
|
|
|
}else if($jenis_barang == 'awal'){
|
|
|
|
return intval($data_barang[0]->jumlah_barang);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-08-21 12:39:35 +07:00
|
|
|
|
|
|
|
public function get_join_barang($id_barang,$table = '')
|
|
|
|
{
|
|
|
|
|
|
|
|
$data = DB::table('tbl_barang')
|
|
|
|
->where('id',$id_barang)
|
|
|
|
->get();
|
|
|
|
|
|
|
|
$data_join = DB::table('tbl_barang')
|
|
|
|
->join('tbl_satuan','tbl_satuan.id','=','tbl_barang.satuan_id')
|
|
|
|
->join('tbl_jenis_barang','tbl_jenis_barang.id','=','tbl_barang.jenis_barang_id')
|
|
|
|
->join('tbl_kategori_simak','tbl_jenis_barang.id','=','tbl_barang.kategori_simak_id')
|
|
|
|
->where('id',$id_barang)
|
|
|
|
->get();
|
|
|
|
if($table == 'jenis'){
|
|
|
|
|
|
|
|
return $data_join[0]->nama_jenis;
|
|
|
|
}else if($table == 'kategori_simak'){
|
|
|
|
|
|
|
|
return $data_join[0]->nama_kategori;
|
|
|
|
}else if($table == 'satuan'){
|
|
|
|
return $data_join[0]->nama_satuan;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-08-20 13:21:23 +07:00
|
|
|
public static function get_image_barang($id_barang){
|
|
|
|
|
|
|
|
$data = DB::table('tbl_barang')
|
|
|
|
->where('id',$id_barang)
|
|
|
|
->get();
|
|
|
|
if(empty($data[0]->image)){
|
|
|
|
|
|
|
|
return secure_url('/upload_image/default.png');
|
|
|
|
}else{
|
|
|
|
|
|
|
|
return secure_url('/upload_image/'.$data[0]->image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_jumlah_pinjam($id_pengguna)
|
|
|
|
{
|
|
|
|
|
|
|
|
$data = DB::table('tbl_barang_keluar')
|
|
|
|
->join('tbl_pengguna','tbl_pengguna.id','=','tbl_barang_keluar.pengguna_id')
|
|
|
|
->where('tbl_barang_keluar.pengguna_id',$id_pengguna)
|
|
|
|
->sum('tbl_barang_keluar.jumlah_keluar');
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_jumlah_pengguna_barang()
|
|
|
|
{
|
|
|
|
|
|
|
|
$data = DB::table('tbl_pengguna')->count();
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
public static function get_total_barang_keluar()
|
|
|
|
{
|
|
|
|
|
|
|
|
$data = DB::table('tbl_barang_keluar')->sum('jumlah_keluar');
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get_total_divisi()
|
|
|
|
{
|
|
|
|
|
|
|
|
$data = DB::table('tbl_divisi')->count();
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
public static function get_total_barang()
|
|
|
|
{
|
|
|
|
|
|
|
|
$data = DB::table('tbl_barang')->sum('jumlah_barang');
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
public static function get_total_pengguna()
|
|
|
|
{
|
|
|
|
|
|
|
|
$data = DB::table('tbl_pengguna')->count();
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|