76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Marhun;
|
|
use App\Jemas;
|
|
use App\Cawangan;
|
|
use Illuminate\Http\Request;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
class MarhunController extends Controller
|
|
{
|
|
|
|
public function showAllMarhuns()
|
|
{
|
|
return response()->json(Marhun::all());
|
|
}
|
|
|
|
public function showOneMarhun($norujukan)
|
|
{
|
|
$cawangan_all = Cawangan::on('mysql7')->get();
|
|
$marhun_all = [];
|
|
foreach($cawangan_all as $index=>$cawangan){
|
|
$marhun = Marhun::on($cawangan['mysql'])->where('norujukan','=',$norujukan)->get();
|
|
if(sizeof($marhun) != 0){
|
|
array_push($marhun_all,$marhun);
|
|
}
|
|
}
|
|
|
|
return response()->json($marhun_all);
|
|
}
|
|
|
|
public function getAllJemas($kodcaw){
|
|
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
|
$jemas = Jemas::on($cawangan['mysql'])->get();
|
|
|
|
return response()->json($jemas);
|
|
}
|
|
|
|
public function create($kodcaw,Request $request)
|
|
{
|
|
$current = Carbon::now();
|
|
$current = new Carbon();
|
|
|
|
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
|
$marhun = Marhun::on($cawangan['mysql'])->create([
|
|
'kodcaw'=> $kodcaw,
|
|
'norujukan'=> $request->norujukan,
|
|
't_gadai' => $current->toDateString(),
|
|
'bil' => 1,
|
|
'marhun' => $request->marhun,
|
|
'nota' => $request->nota,
|
|
'karat' => $request->karat,
|
|
'berat' => $request->berat_emas,
|
|
'harga' => $request->harga,
|
|
'n_marhun' => $request->nilai_marhun
|
|
]);
|
|
|
|
return response()->json($marhun, 201);
|
|
}
|
|
|
|
public function update($id, Request $request)
|
|
{
|
|
$marhun = Marhun::findOrFail($id);
|
|
$marhun->update($request->all());
|
|
|
|
return response()->json($marhun, 200);
|
|
}
|
|
|
|
public function delete($id)
|
|
{
|
|
Marhun::findOrFail($id)->delete();
|
|
return response('Deleted Successfully', 200);
|
|
}
|
|
} |