79 lines
2.0 KiB
PHP
79 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Customer;
|
|
use App\Gadai;
|
|
use App\Lelong;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CustomerController extends Controller
|
|
{
|
|
|
|
public function showAllCustomers()
|
|
{
|
|
return response()->json(Customer::on('mysql2')->get());
|
|
}
|
|
|
|
public function showOneCustomer($id)
|
|
{
|
|
return response()->json(Customer::on('mysql2')->find($id));
|
|
}
|
|
|
|
public function showOneCustomerByIC($ic){
|
|
|
|
$customer = Customer::on('mysql2')
|
|
->where('kplama','=',$ic)
|
|
->orWhere('kpbaru','=',$ic)
|
|
->first();
|
|
|
|
return response()->json($customer);
|
|
}
|
|
|
|
public function showOneCustomerGadai($ic,$status){
|
|
if($status == 'belum_tebus'){
|
|
$gadai_status = '';
|
|
}elseif($status == 'sudah_tebus'){
|
|
$gadai_status = 'T';
|
|
}elseif($status == 'lelong'){
|
|
$gadai_status = 'L';
|
|
}
|
|
|
|
if($status == 'belum_tebus' || $status == 'sudah_tebus'){
|
|
$gadai = Gadai::on('mysql2')
|
|
->where([['sttebus','=',$gadai_status],['nokp','=',$ic]])
|
|
->get();
|
|
}elseif($status == 'lelong'){
|
|
$gadai = Gadai::on('mysql2')
|
|
->where([['sttebus','=',$gadai_status],['nokp','=',$ic]])
|
|
->rightJoin('lelong', 'gadai.norujukan', '=', 'lelong.norujukan')
|
|
->get();
|
|
}
|
|
|
|
return response()->json($gadai);
|
|
}
|
|
|
|
public function create(Request $request)
|
|
{
|
|
$this->validate($request, [
|
|
|
|
]);
|
|
$customer = Customer::create($request->all());
|
|
|
|
return response()->json($customer, 201);
|
|
}
|
|
|
|
public function update($id, Request $request)
|
|
{
|
|
$customer = Customer::findOrFail($id);
|
|
$customer->update($request->all());
|
|
|
|
return response()->json($customer, 200);
|
|
}
|
|
|
|
public function delete($id)
|
|
{
|
|
Customer::findOrFail($id)->delete();
|
|
return response('Deleted Successfully', 200);
|
|
}
|
|
} |