Files
api_arrahn/app/Http/Controllers/CustomerController.php
T
2021-01-05 14:25:59 +08:00

282 lines
10 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Customer;
use App\Gadai;
use App\Lelong;
use App\Cawangan;
use App\Poskod;
use Illuminate\Http\Request;
use Carbon\Carbon;
class CustomerController extends Controller
{
public function showAllCustomers()
{
$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 getLatestCustomer($kodcaw){
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
$customer = Customer::on($cawangan['mysql'])->orderBy('tarikhdaftar','desc')->orderBy('nosiri','desc')->first();
return response()->json($customer);
}
public function showAllCustomersByCawangan($kodcaw)
{
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
$customer = Customer::on($cawangan['mysql'])->get();
return response()->json($customer);
}
public function showOneCustomerByIC($ic){
$cawangan_all = Cawangan::on('mysql7')->get();
$customer_all = [];
foreach($cawangan_all as $index=>$cawangan){
$customer = Customer::on($cawangan['mysql'])
->where('kplama','=',$ic)
->orWhere('kpbaru','=',$ic)
->first();
if($customer != null){
array_push($customer_all,$customer);
}
}
return response()->json($customer_all);
}
public function showOneCustomerByICMobile($ic){
$cawangan_all = Cawangan::on('mysql7')->get();
$customer_all = [];
foreach($cawangan_all as $index=>$cawangan){
$customer = Customer::on($cawangan['mysql'])
->where('kplama','=',$ic)
->orWhere('kpbaru','=',$ic)
->first();
if($customer != null){
array_push($customer_all,$customer);
}
}
$customer_detail['nama'] = $customer_all[0]['nama'];
$customer_detail['nokp'] = $customer_all[0]['kpbaru'];
$customer_detail['nopelanggan'] = $customer_all[0]['nopelanggan'];
$customer_detail['telefon'] = $customer_all[0]['telefon'];
$customer_detail['telefon2'] = $customer_all[0]['telefon2'];
$customer_detail['alamat'] = $customer_all[0]['alamat1'];
$customer_detail['poskod'] = $customer_all[0]['poskod'];
return response()->json($customer_detail);
}
public function showOneCustomerGadai($ic,$status){
if($status == 'belum_tebus'){
$gadai_status = '';
}elseif($status == 'sudah_tebus'){
$gadai_status = 'T';
}elseif($status == 'lelong'){
$gadai_status = 'L';
}
$cawangan_all = Cawangan::on('mysql7')->get();
$gadai_all = [];
foreach($cawangan_all as $index=>$cawangan){
if($status == 'belum_tebus' || $status == 'sudah_tebus'){
$gadai = Gadai::on($cawangan['mysql'])
->where([['sttebus','=',$gadai_status],['nokp','=',$ic]])
->get();
if(sizeof($gadai) != 0){
array_push($gadai_all,$gadai);
}
}elseif($status == 'lelong'){
$gadai = Gadai::on($cawangan['mysql'])
->where([['sttebus','=',$gadai_status],['nokp','=',$ic]])
->rightJoin('lelong', 'gadai.norujukan', '=', 'lelong.norujukan')
->get();
if(sizeof($gadai) != 0){
array_push($gadai_all,$gadai);
}
}
}
return response()->json($gadai_all);
}
public function showOneCustomerGadaiMobile($ic,$status){
if($status == 'belum_tebus'){
$gadai_status = '';
}elseif($status == 'sudah_tebus'){
$gadai_status = 'T';
}elseif($status == 'lelong'){
$gadai_status = 'L';
}
$cawangan_all = Cawangan::on('mysql7')->get();
$gadai_all = [];
foreach($cawangan_all as $index=>$cawangan){
if($status == 'belum_tebus' || $status == 'sudah_tebus'){
$gadai = Gadai::on($cawangan['mysql'])
->where([['sttebus','=',$gadai_status],['nokp','=',$ic]])
->get();
if(sizeof($gadai) != 0){
foreach($gadai as $index => $gadai_detail){
array_push($gadai_all,['norujukan'=>$gadai_detail['norujukan'],'hargajualan'=>$gadai_detail['hargajualan'],'bakihargajualan'=>$gadai_detail['bakihargajualan']]);
}
}
}elseif($status == 'lelong'){
$gadai = Gadai::on($cawangan['mysql'])
->where([['sttebus','=',$gadai_status],['nokp','=',$ic]])
->rightJoin('lelong', 'gadai.norujukan', '=', 'lelong.norujukan')
->get();
if(sizeof($gadai) != 0){
foreach($gadai as $index => $gadai_detail){
array_push($gadai_all,['norujukan'=>$gadai_detail['norujukan'],'hargajualan'=>$gadai_detail['hargajualan'],'bakihargajualan'=>$gadai_detail['bakihargajualan']]);
}
}
}
}
return response()->json($gadai_all);
}
public function show6BlnGadai($ic){
$cawangan_all = Cawangan::on('mysql7')->get();
$gadai_all=[];
foreach($cawangan_all as $index=>$cawangan){
$gadai = Gadai::on($cawangan['mysql'])
->where([['sttebus','=',''],['nokp','=',$ic],['jbg','>=',6]])
->get();
if(sizeof($gadai) != 0){
foreach($gadai as $index => $gadai_detail){
array_push($gadai_all,['norujukan'=>$gadai_detail['norujukan'],'hargajualan'=>$gadai_detail['hargajualan'],'bakihargajualan'=>$gadai_detail['bakihargajualan']]);
}
}
}
return response()->json($gadai_all);
}
public function showOneCustomerGadaiByCawangan($ic,$status,$kodcaw){
if($status == 'belum_tebus'){
$gadai_status = '';
}elseif($status == 'sudah_tebus'){
$gadai_status = 'T';
}elseif($status == 'lelong'){
$gadai_status = 'L';
}
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
if($status == 'belum_tebus' || $status == 'sudah_tebus'){
$gadai = Gadai::on($cawangan['mysql'])
->where([['sttebus','=',$gadai_status],['nokp','=',$ic]])
->get();
}elseif($status == 'lelong'){
$gadai = Gadai::on($cawangan['mysql'])
->where([['sttebus','=',$gadai_status],['nokp','=',$ic]])
->rightJoin('lelong', 'gadai.norujukan', '=', 'lelong.norujukan')
->get();
}
return response()->json($gadai);
}
public function getLaporanCustomers($kodcaw, $tarikh)
{
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
$gadai = Customer::on($cawangan['mysql'])
->where('tarikhdaftar','=',$tarikh)
->orderBy('tarikhdaftar', 'desc')
->get();
return response()->json($gadai);
}
public function createCustomer($kodcaw,Request $request){
// dd($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,
'nosiri'=>$request->nosiri,
]);
return response()->json($customer, 201);
}
public function customerUpdate($nokp,Request $request){
$cawangan_all = Cawangan::on('mysql7')->get();
foreach($cawangan_all as $index=>$cawangan){
$customer = Customer::on($cawangan['mysql'])
->where('kplama','=',$nokp)
->orWhere('kpbaru','=',$nokp)
->first();
if($customer != null){
$poskod = Poskod::on('mysql7')->where('poskod','=',$request->poskod)->first();
$customer_update = Customer::on($cawangan['mysql'])
->where('kplama','=',$nokp)
->orWhere('kpbaru','=',$nokp)
->update(array(
'alamat1' => $request->alamat,
'alamat2' => '',
'poskod' => $request->poskod,
'koddaerah' => $poskod['koddaerah'],
'kodnegeri' => $poskod['kodnegeri'],
'telefon' => $request->telefon1,
'telefon2' => $request->telefon2
));
}
}
return response()->json($customer_update, 200);
}
public function delete($kodcaw,$nokp)
{
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
Customer::on($cawangan['mysql'])->where('kplama','=',$nokp)->orWhere('kpbaru','=',$nokp)->delete();
return response('Deleted Successfully', 200);
}
}