add customer
This commit is contained in:
@@ -9,17 +9,22 @@ use App\Cawangan;
|
||||
use App\Poskod;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
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));
|
||||
$cawangan_all = Cawangan::on('mysql7')->get();
|
||||
$customer_all = [];
|
||||
foreach($cawangan_all as $index=>$cawangan){
|
||||
$customer = Customer::on($cawangan['mysql'])->get();
|
||||
if($customer != null){
|
||||
array_push($customer_all,$customer);
|
||||
}
|
||||
}
|
||||
return response()->json($customer_all);
|
||||
}
|
||||
|
||||
public function showOneCustomerByIC($ic){
|
||||
@@ -97,25 +102,40 @@ class CustomerController extends Controller
|
||||
return response()->json($gadai);
|
||||
}
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
public function create($kodcaw,Request $request){
|
||||
$current = Carbon::now();
|
||||
$current = new Carbon();
|
||||
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
|
||||
$customer = Customer::on($cawangan['mysql'])->create([
|
||||
'kodcaw' => $request->kodcaw,
|
||||
'tarikhdaftar' => $current->toDateString(),
|
||||
'nopelanggan' => $request->nopelanggan,
|
||||
'kpbaru' => $request->nokp,
|
||||
'nama' => $request->nama,
|
||||
't_lahir' => $request->t_lahir,
|
||||
'jantina' => $request->jantina,
|
||||
'alamat1' => $request->alamat,
|
||||
'poskod' => $request->poskod,
|
||||
'koddaerah' => $request->koddaerah,
|
||||
'kodnegeri' => $request->kodnegeri,
|
||||
'telefon' => $request->telefon,
|
||||
'bumiputra' => $request->bumiputra,
|
||||
'warganegara' => $request->warganegara,
|
||||
'bangsa' => $request->bangsa,
|
||||
'kodugama' => $request->kodugama,
|
||||
'kodbank' => $request->kodbank,
|
||||
'noakaun' => $request->noakaun,
|
||||
'teller' => $request->teller,
|
||||
'aktif' => 'A',
|
||||
'telefon2' => $request->telefon2
|
||||
]);
|
||||
$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 updateOnline($nokp,Request $request){
|
||||
public function customerUpdate($nokp,Request $request){
|
||||
$cawangan_all = Cawangan::on('mysql7')->get();
|
||||
foreach($cawangan_all as $index=>$cawangan){
|
||||
$customer = Customer::on($cawangan['mysql'])
|
||||
@@ -142,9 +162,12 @@ class CustomerController extends Controller
|
||||
return response()->json($customer_update, 200);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
public function delete($kodcaw,$nokp)
|
||||
{
|
||||
Customer::findOrFail($id)->delete();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
|
||||
Customer::on($cawangan['mysql'])->where('kplama','=',$nokp)->orWhere('kpbaru','=',$nokp)->delete();
|
||||
|
||||
return response('Deleted Successfully', 200);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user