first commit
This commit is contained in:
@@ -0,0 +1,324 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use DB;
|
||||
use App\Barang;
|
||||
use Illuminate\Http\Request;
|
||||
use Auth;
|
||||
|
||||
class BarangController extends Controller
|
||||
{
|
||||
|
||||
public function showAllBarangs()
|
||||
{
|
||||
return response()->json(DB::table('TMLogBarang')->get());
|
||||
}
|
||||
|
||||
public function showOneBarang($id)
|
||||
{
|
||||
return response()->json(Barang::find($id));
|
||||
}
|
||||
|
||||
public function showStockAll()
|
||||
{
|
||||
return response()->json(DB::table('TMLogBarang')
|
||||
->leftJoin('TMLogReference as r1','TMLogBarang.KodeSatuan','=','r1.Kode')
|
||||
->join('TTLogMutasiBarang as m','TMLogBarang.Kode','=','m.KodeBarang')
|
||||
->join('TMLogBarangStock as bs','TMLogBarang.Kode','=','bs.KodeBarang')
|
||||
->join('TMStock as s','m.StStock','=','s.Kode')
|
||||
->select(DB::raw('m.StStock,TMLogBarang.Kode,TMLogBarang.Nama,r1.Nama as satuan,s.Nama as jenis,sum(m.StockAkhir) as jmlStok,bs.HJual,bs.HPP,TMLogBarang.StFornas,TMLogBarang.StRes'))
|
||||
->where([
|
||||
['m.KodePeriode','=',date('Ym')],
|
||||
['bs.StStock','=',DB::raw('cast(m.StStock as int)')],
|
||||
['TMLogBarang.Aktif','=',1]
|
||||
])
|
||||
->groupBy('s.Kode','TMLogBarang.Kode','TMLogBarang.Nama','r1.Nama','s.Nama','bs.HPP','bs.HJual','m.StStock','TMLogBarang.StFornas','TMLogBarang.StRes')
|
||||
->orderBy(DB::raw('sum(m.StockAkhir)'),'desc')
|
||||
// ->having(DB::raw('sum(m.StockAkhir)'),'>',0)
|
||||
->get());
|
||||
}
|
||||
|
||||
public function showStockByDepo($depo, $stStok)
|
||||
{
|
||||
return response()->json(DB::table('TMLogBarang')
|
||||
->leftJoin('TMLogReference as r1','TMLogBarang.KodeSatuan','=','r1.Kode')
|
||||
->join('TTLogMutasiBarang as m','TMLogBarang.Kode','=','m.KodeBarang')
|
||||
->join('TMLogBarangStock as bs','TMLogBarang.Kode','=','bs.KodeBarang')
|
||||
->join('TMStock as s','m.StStock','=','s.Kode')
|
||||
->select(DB::raw('TMLogBarang.Kode,TMLogBarang.Nama,r1.Nama as satuan,s.Nama as jenis,sum(m.StockAkhir) as jmlStok,bs.HJual,bs.HPP,bs.StStock,TMLogBarang.StRes'))
|
||||
->where([
|
||||
['m.KodePeriode','=',date('Ym')],
|
||||
['bs.StStock','=',DB::raw('cast(m.StStock as int)')],
|
||||
['m.KodeDepo','=',$depo],
|
||||
['bs.StStock','=',$stStok],
|
||||
['TMLogBarang.Aktif','=',1]
|
||||
])
|
||||
->groupBy('TMLogBarang.Kode','TMLogBarang.Nama','r1.Nama','s.Nama','bs.HPP','bs.HJual','bs.StStock','TMLogBarang.StRes')
|
||||
->having(DB::raw('sum(m.StockAkhir)'),'>',0)
|
||||
->orderBy(DB::raw('sum(m.StockAkhir)'),'desc')
|
||||
->get());
|
||||
}
|
||||
|
||||
public function showAllStockByDepo($depo)
|
||||
{
|
||||
$tmp_all_stok = DB::table('TMLogBarang')
|
||||
->leftJoin('TMLogReference as r1','TMLogBarang.KodeSatuan','=','r1.Kode')
|
||||
->join('TTLogMutasiBarang as m','TMLogBarang.Kode','=','m.KodeBarang')
|
||||
->join('TMLogBarangStock as bs','TMLogBarang.Kode','=','bs.KodeBarang')
|
||||
->join('TMStock as s','m.StStock','=','s.Kode')
|
||||
->select(DB::raw('TMLogBarang.Kode,TMLogBarang.Nama,r1.Nama as satuan,s.Nama as jenis,sum(m.StockAkhir) as jmlStok,bs.HJual,bs.HPP,bs.StStock,TMLogBarang.StRes'))
|
||||
->where([
|
||||
['m.KodePeriode','=',date('Ym')],
|
||||
['bs.StStock','=',DB::raw('cast(m.StStock as int)')],
|
||||
['m.KodeDepo','=',$depo],
|
||||
['TMLogBarang.Aktif','=',1]
|
||||
])
|
||||
->groupBy('TMLogBarang.Kode','TMLogBarang.Nama','r1.Nama','s.Nama','bs.HPP','bs.HJual','bs.StStock','TMLogBarang.StRes')
|
||||
->orderBy(DB::raw('sum(m.StockAkhir)'),'desc')
|
||||
// ->having(DB::raw('sum(m.StockAkhir)'),'>',0)
|
||||
->get();
|
||||
$arr_all_stok = [];
|
||||
foreach($tmp_all_stok as $row) {
|
||||
$arr_all_stok[$row->Kode.';'.$row->StStock] = [
|
||||
'Kode'=>$row->Kode,
|
||||
'Nama'=>$row->Nama,
|
||||
'satuan'=>$row->satuan,
|
||||
'jenis'=>$row->jenis,
|
||||
'jmlStok'=>$row->jmlStok,
|
||||
'HJual'=>$row->HJual,
|
||||
'HPP'=>$row->HPP,
|
||||
'StStock'=>$row->StStock
|
||||
];
|
||||
}
|
||||
return response()->json($arr_all_stok);
|
||||
}
|
||||
|
||||
public function showAllStockByDepoByName($depo,$nama)
|
||||
{
|
||||
$nama = urldecode($nama);
|
||||
$query = DB::table('TMLogBarang')
|
||||
->leftJoin('TMLogReference as r1','TMLogBarang.KodeSatuan','=','r1.Kode')
|
||||
->join('TTLogMutasiBarang as m','TMLogBarang.Kode','=','m.KodeBarang')
|
||||
->join('TMLogBarangStock as bs','TMLogBarang.Kode','=','bs.KodeBarang')
|
||||
->join('TMStock as s','m.StStock','=','s.Kode')
|
||||
->select(DB::raw('TMLogBarang.Kode,TMLogBarang.Nama,r1.Nama as satuan,s.Nama as jenis,sum(m.StockAkhir) as jmlStok,bs.HJual,bs.HPP,bs.StStock as kodeStok,TMLogBarang.KodeJenis,TMLogBarang.StRes'))
|
||||
->where([
|
||||
['m.KodePeriode','=',date('Ym')],
|
||||
['bs.StStock','=',DB::raw('cast(m.StStock as int)')],
|
||||
['m.KodeDepo','=',$depo],
|
||||
['TMLogBarang.Aktif','=',1],
|
||||
['TMLogBarang.Nama','like','%'.$nama.'%']
|
||||
])
|
||||
->groupBy('TMLogBarang.Kode','TMLogBarang.Nama','r1.Nama','s.Nama','bs.HPP','bs.HJual','bs.StStock','TMLogBarang.KodeJenis','TMLogBarang.StRes')
|
||||
->orderBy(DB::raw('sum(m.StockAkhir)'),'desc')
|
||||
// ->having(DB::raw('sum(m.StockAkhir)'),'>',0)
|
||||
->get();
|
||||
|
||||
return response()->json($query);
|
||||
}
|
||||
|
||||
public function showAllStockAskesByName($nama)
|
||||
{
|
||||
$nama = urldecode($nama);
|
||||
$query = DB::table('TMLogBarang')
|
||||
->leftJoin('TMLogReference as r1','TMLogBarang.KodeSatuan','=','r1.Kode')
|
||||
->join('TTLogMutasiBarang as m','TMLogBarang.Kode','=','m.KodeBarang')
|
||||
->join('TMLogBarangStock as bs','TMLogBarang.Kode','=','bs.KodeBarang')
|
||||
->join('TMStock as s','m.StStock','=','s.Kode')
|
||||
->join('TMOrgDepo as d','m.KodeDepo','=','d.Kode')
|
||||
->select(DB::raw('TMLogBarang.Kode,TMLogBarang.Nama,r1.Nama as satuan,s.Nama as jenis,sum(m.StockAkhir) as jmlStok,bs.HJual,bs.HPP,bs.StStock as kodeStok,TMLogBarang.KodeJenis,TMLogBarang.StRes'))
|
||||
->where([
|
||||
['m.KodePeriode','=',date('Ym')],
|
||||
['bs.StStock','=',DB::raw('cast(m.StStock as int)')],
|
||||
['d.statusPasien','=','ASKES'],
|
||||
['TMLogBarang.Aktif','=',1],
|
||||
['TMLogBarang.Nama','like','%'.$nama.'%']
|
||||
])
|
||||
->groupBy('TMLogBarang.Kode','TMLogBarang.Nama','r1.Nama','s.Nama','bs.HPP','bs.HJual','bs.StStock','TMLogBarang.KodeJenis','TMLogBarang.StRes')
|
||||
->orderBy(DB::raw('sum(m.StockAkhir)'),'desc')
|
||||
// ->having(DB::raw('sum(m.StockAkhir)'),'>',0)
|
||||
->get();
|
||||
|
||||
return response()->json($query);
|
||||
}
|
||||
|
||||
public function showAllStockHibah()
|
||||
{
|
||||
$query = DB::table('TMLogBarang')
|
||||
->leftJoin('TMLogReference as r1','TMLogBarang.KodeSatuan','=','r1.Kode')
|
||||
->join('TTLogMutasiBarang as m','TMLogBarang.Kode','=','m.KodeBarang')
|
||||
->join('TMLogBarangStock as bs','TMLogBarang.Kode','=','bs.KodeBarang')
|
||||
->join('TMStock as s','m.StStock','=','s.Kode')
|
||||
->join('TMOrgDepo as d','m.KodeDepo','=','d.Kode')
|
||||
->select(DB::raw('TMLogBarang.Kode,TMLogBarang.Nama,r1.Nama as satuan,s.Nama as jenis,sum(m.StockAkhir) as jmlStok,bs.HJual,bs.HPP,bs.StStock as kodeStok,TMLogBarang.KodeJenis,TMLogBarang.StRes'))
|
||||
->where([
|
||||
['m.KodePeriode','=',date('Ym')],
|
||||
['bs.StStock','=',DB::raw('cast(m.StStock as int)')],
|
||||
['s.Kode','=','6'],
|
||||
['TMLogBarang.Aktif','=',1],
|
||||
])
|
||||
->groupBy('TMLogBarang.Kode','TMLogBarang.Nama','r1.Nama','s.Nama','bs.HPP','bs.HJual','bs.StStock','TMLogBarang.KodeJenis','TMLogBarang.StRes')
|
||||
->orderBy(DB::raw('sum(m.StockAkhir)'),'desc')
|
||||
// ->having(DB::raw('sum(m.StockAkhir)'),'>',0)
|
||||
->get();
|
||||
|
||||
return response()->json($query);
|
||||
}
|
||||
|
||||
public function showAlkesAll()
|
||||
{
|
||||
return response()->json(DB::table('TMLogBarang')
|
||||
->leftJoin('TMLogReference as r1','TMLogBarang.KodeSatuan','=','r1.Kode')
|
||||
->join('TTLogMutasiBarang as m','TMLogBarang.Kode','=','m.KodeBarang')
|
||||
->join('TMLogBarangStock as bs','TMLogBarang.Kode','=','bs.KodeBarang')
|
||||
->join('TMStock as s','m.StStock','=','s.Kode')
|
||||
->select(DB::raw('TMLogBarang.Kode,TMLogBarang.Nama,r1.Nama as satuan,s.Nama as jenis,sum(m.StockAkhir) as jmlStok,bs.HJual,bs.HPP,bs.StStock,'))
|
||||
->where([
|
||||
['m.KodePeriode','=',date('Ym')],
|
||||
['bs.StStock','=',DB::raw('cast(m.StStock as int)')],
|
||||
['TMLogBarang.Aktif','=',1]
|
||||
])
|
||||
->whereIn('TMLogBarang.KodeKelompok',['ALK','ALKES','ALKDOK','ALKHUS'])
|
||||
->groupBy('TMLogBarang.Kode','TMLogBarang.Nama','r1.Nama','s.Nama','bs.HPP','bs.HJual','bs.StStock')
|
||||
->orderBy(DB::raw('sum(m.StockAkhir)'),'desc')
|
||||
->get());
|
||||
}
|
||||
|
||||
public function showAlkes($id)
|
||||
{
|
||||
return response()->json(DB::table('TMLogBarang')
|
||||
->leftJoin('TMLogReference as r1','TMLogBarang.KodeSatuan','=','r1.Kode')
|
||||
->join('TTLogMutasiBarang as m','TMLogBarang.Kode','=','m.KodeBarang')
|
||||
->join('TMLogBarangStock as bs','TMLogBarang.Kode','=','bs.KodeBarang')
|
||||
->join('TMStock as s','m.StStock','=','s.Kode')
|
||||
->select(DB::raw('s.Kode as kodeStok,TMLogBarang.Kode,TMLogBarang.Nama,TMLogBarang.StFornas, r1.Nama as satuan,s.Nama as jenis,sum(m.StockAkhir) as jmlStok,bs.HJual,bs.HPP'))
|
||||
->where([
|
||||
['m.KodePeriode','=',date('Ym')],
|
||||
['bs.StStock','=',DB::raw('cast(m.StStock as int)')],
|
||||
['TMLogBarang.Aktif','=',1],
|
||||
['TMLogBarang.Nama','like','%'.$id.'%']
|
||||
])
|
||||
->whereIn('TMLogBarang.KodeKelompok',['ALK','ALKES','ALKDOK','ALKHUS'])
|
||||
->groupBy('s.Kode','TMLogBarang.Kode','TMLogBarang.Nama','TMLogBarang.StFornas','r1.Nama','s.Nama','bs.HPP','bs.HJual','m.StStock')
|
||||
->orderBy(DB::raw('sum(m.StockAkhir)'),'desc')
|
||||
->get());
|
||||
}
|
||||
|
||||
public function showAlkesDepo($depo)
|
||||
{
|
||||
return response()->json(DB::table('TMLogBarang')
|
||||
->leftJoin('TMLogReference as r1','TMLogBarang.KodeSatuan','=','r1.Kode')
|
||||
->join('TTLogMutasiBarang as m','TMLogBarang.Kode','=','m.KodeBarang')
|
||||
->join('TMLogBarangStock as bs','TMLogBarang.Kode','=','bs.KodeBarang')
|
||||
->join('TMStock as s','m.StStock','=','s.Kode')
|
||||
->select(DB::raw('TMLogBarang.Kode,TMLogBarang.Nama,r1.Nama as satuan,s.Nama as jenis,sum(m.StockAkhir) as jmlStok,bs.HJual,bs.HPP,bs.StStock'))
|
||||
->where([
|
||||
['m.KodePeriode','=',date('Ym')],
|
||||
['bs.StStock','=',DB::raw('cast(m.StStock as int)')],
|
||||
['m.KodeDepo','=',$depo],
|
||||
['TMLogBarang.Aktif','=',1]
|
||||
])
|
||||
->whereIn('TMLogBarang.KodeKelompok',['ALK','ALKES','ALKDOK','ALKHUS'])
|
||||
->groupBy('TMLogBarang.Kode','TMLogBarang.Nama','r1.Nama','s.Nama','bs.HPP','bs.HJual','bs.StStock')
|
||||
->orderBy(DB::raw('sum(m.StockAkhir)'),'desc')
|
||||
// ->having(DB::raw('sum(m.StockAkhir)'),'>',0)
|
||||
->get());
|
||||
}
|
||||
|
||||
public function showAlkesJknByName($nama)
|
||||
{
|
||||
$nama = urldecode($nama);
|
||||
return response()->json(DB::table('TMLogBarang')
|
||||
->leftJoin('TMLogReference as r1','TMLogBarang.KodeSatuan','=','r1.Kode')
|
||||
->join('TTLogMutasiBarang as m','TMLogBarang.Kode','=','m.KodeBarang')
|
||||
->join('TMLogBarangStock as bs','TMLogBarang.Kode','=','bs.KodeBarang')
|
||||
->join('TMStock as s','m.StStock','=','s.Kode')
|
||||
->join('TMOrgDepo as d','m.KodeDepo','=','d.Kode')
|
||||
->select(DB::raw('TMLogBarang.Kode,TMLogBarang.Nama,r1.Nama as satuan,s.Nama as jenis,sum(m.StockAkhir) as jmlStok,bs.HJual,bs.HPP,bs.StStock'))
|
||||
->where([
|
||||
['m.KodePeriode','=',date('Ym')],
|
||||
['bs.StStock','=',DB::raw('cast(m.StStock as int)')],
|
||||
['d.statusPasien','=','ASKES'],
|
||||
['TMLogBarang.Aktif','=',1],
|
||||
['TMLogBarang.Nama','like','%'.$nama.'%']
|
||||
])
|
||||
->whereIn('TMLogBarang.KodeKelompok',['ALK','ALKES','ALKDOK','ALKHUS'])
|
||||
->groupBy('TMLogBarang.Kode','TMLogBarang.Nama','r1.Nama','s.Nama','bs.HPP','bs.HJual','bs.StStock')
|
||||
->orderBy(DB::raw('sum(m.StockAkhir)'),'desc')
|
||||
// ->having(DB::raw('sum(m.StockAkhir)'),'>',0)
|
||||
->get());
|
||||
}
|
||||
|
||||
public function showStock($id)
|
||||
{
|
||||
$query = DB::table('TMLogBarang')
|
||||
->leftJoin('TMLogReference as r1','TMLogBarang.KodeSatuan','=','r1.Kode')
|
||||
->join('TTLogMutasiBarang as m','TMLogBarang.Kode','=','m.KodeBarang')
|
||||
->join('TMLogBarangStock as bs','TMLogBarang.Kode','=','bs.KodeBarang')
|
||||
->join('TMStock as s','m.StStock','=','s.Kode')
|
||||
->select(DB::raw('s.Kode as kodeStok,TMLogBarang.Kode,TMLogBarang.Nama,TMLogBarang.StFornas, r1.Nama as satuan,s.Nama as jenis,sum(m.StockAkhir) as jmlStok,bs.HJual,bs.HPP,TMLogBarang.KodeJenis, TMLogBarang.StRes'))
|
||||
->where([
|
||||
['m.KodePeriode','=',date('Ym')],
|
||||
['bs.StStock','=',DB::raw('cast(m.StStock as int)')],
|
||||
['TMLogBarang.Aktif','=',1],
|
||||
['TMLogBarang.Nama','like','%'.$id.'%']
|
||||
])
|
||||
->groupBy('s.Kode','TMLogBarang.Kode','TMLogBarang.Nama','TMLogBarang.StFornas','r1.Nama','s.Nama','bs.HPP','bs.HJual','m.StStock','TMLogBarang.KodeJenis','TMLogBarang.StRes')
|
||||
->orderBy(DB::raw('sum(m.StockAkhir)'),'desc')
|
||||
->get();
|
||||
$result = response()->json($query);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function showStockAdv($depo, $kode, $ststock)
|
||||
{
|
||||
$query = DB::table('TMLogBarang')
|
||||
->leftJoin('TMLogReference as r1','TMLogBarang.KodeSatuan','=','r1.Kode')
|
||||
->join('TTLogMutasiBarang as m','TMLogBarang.Kode','=','m.KodeBarang')
|
||||
->join('TMLogBarangStock as bs','TMLogBarang.Kode','=','bs.KodeBarang')
|
||||
->join('TMStock as s','m.StStock','=','s.Kode')
|
||||
->select(DB::raw('s.Kode as kodeStok,TMLogBarang.Kode,TMLogBarang.Nama,TMLogBarang.StFornas, r1.Nama as satuan,s.Nama as jenis,sum(m.StockAkhir) as jmlStok,bs.HJual,bs.HPP,TMLogBarang.KodeJenis'))
|
||||
->where([
|
||||
['m.KodePeriode','=',date('Ym')],
|
||||
['bs.StStock','=',DB::raw('cast(m.StStock as int)')],
|
||||
['TMLogBarang.Aktif','=',1],
|
||||
['m.KodeDepo','=',$depo],
|
||||
['bs.StStock','=',$ststock],
|
||||
['TMLogBarang.Kode','=',$kode]
|
||||
])
|
||||
->groupBy('s.Kode','TMLogBarang.Kode','TMLogBarang.Nama','TMLogBarang.StFornas','r1.Nama','s.Nama','bs.HPP','bs.HJual','m.StStock','TMLogBarang.KodeJenis')
|
||||
->orderBy(DB::raw('sum(m.StockAkhir)'),'desc')
|
||||
->get();
|
||||
$result = response()->json($query);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function showStatusStok()
|
||||
{
|
||||
return response()->json(DB::table('TMStock')->where('aktif',1)->get());
|
||||
}
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$author = Barang::create($request->all());
|
||||
|
||||
return response()->json($author, 201);
|
||||
}
|
||||
|
||||
public function update($id, Request $request)
|
||||
{
|
||||
$author = Barang::findOrFail($id);
|
||||
$author->update($request->all());
|
||||
|
||||
return response()->json($author, 200);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
Barang::findOrFail($id)->delete();
|
||||
return response('Deleted Successfully', 200);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user