155 lines
6.4 KiB
PHP
155 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Http\Requests\ProfileRequest;
|
|
use App\Http\Requests\PasswordRequest;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Http\Request;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Illuminate\Support\Facades\Session;
|
|
use PDF;
|
|
|
|
class ProfileController extends Controller
|
|
{
|
|
/**
|
|
* Show the form for editing the profile.
|
|
*
|
|
* @return \Illuminate\View\View
|
|
*/
|
|
public function edit()
|
|
{
|
|
// return view('profile.edit');
|
|
return view('includes.profile');
|
|
}
|
|
|
|
/**
|
|
* Update the profile
|
|
*
|
|
* @param \App\Http\Requests\ProfileRequest $request
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function update(ProfileRequest $request)
|
|
{
|
|
if (auth()->user()->id == 1) {
|
|
return back()->withErrors(['not_allow_profile' => __('You are not allowed to change data for a default user.')]);
|
|
}
|
|
|
|
auth()->user()->update($request->all());
|
|
|
|
return back()->withStatus(__('Berjaya dikemaskini.'));
|
|
}
|
|
|
|
/**
|
|
* Change the password
|
|
*
|
|
* @param \App\Http\Requests\PasswordRequest $request
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function password(PasswordRequest $request)
|
|
{
|
|
if (auth()->user()->id == 1) {
|
|
return back()->withErrors(['not_allow_password' => __('You are not allowed to change the password for a default user.')]);
|
|
}
|
|
|
|
auth()->user()->update(['password' => Hash::make($request->get('password'))]);
|
|
|
|
return back()->withPasswordStatus(__('Password successfully updated.'));
|
|
}
|
|
|
|
public function printSuratWakil($kodcaw, $norujukan)
|
|
{
|
|
$api_url = config('api.url');
|
|
$current = Carbon::now();
|
|
$current = new Carbon();
|
|
$t_cetak = $current->toDateString();
|
|
|
|
$tarikh_cetak = date('d-m-Y');
|
|
$check_norujukan = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/checksurat/' . $kodcaw . '/' . $norujukan)->json();
|
|
if ($check_norujukan == $norujukan) {
|
|
|
|
//get details gadai && detail customer
|
|
|
|
$update_wakil = Http::withOptions(['verify' => config('app.api_verify')])->put(config('api.url') . '/api/updatewakil/' . $kodcaw . '/' . $norujukan)->json();
|
|
|
|
$gadai = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/gadai/norujukan/' . $norujukan)->json();
|
|
$gadai_details = $gadai[0][0];
|
|
|
|
$noic = $gadai_details['nokp'];
|
|
$customer_detail = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/customers/' . $noic)->json();
|
|
|
|
$cawangan = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/cawangan/detail/' . $kodcaw)->json();
|
|
|
|
$cawangan_detail = $cawangan[0];
|
|
|
|
$nosiri = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/nosiri/wakil/' . $kodcaw . '/' . $norujukan)->json();
|
|
|
|
// $pdf=PDF::loadView('print.surat_wakil', compact('customer_detail','current','auth_user','api_url','cawangan_detail'))
|
|
// ->setPaper('A4','potrait');
|
|
// return $pdf->download('notislelong_'.'.pdf');
|
|
// dd($gadai_details);
|
|
|
|
|
|
// return view('print.surat_wakil', compact('customer_detail', 'current', 'kodcaw', 'api_url', 'cawangan_detail', 'tarikh_cetak', 'gadai_details', 'noic', 'nosiri'));
|
|
$pdf = PDF::loadView('print.surat_wakil', compact('customer_detail', 'current', 'kodcaw', 'api_url', 'cawangan_detail', 'tarikh_cetak', 'gadai_details', 'noic', 'nosiri'))
|
|
->setPaper('a4', 'potrait');
|
|
return $pdf->download('Surat Wakil.pdf');
|
|
} else {
|
|
|
|
// insert into wakil_surat
|
|
|
|
$current_year = substr($current->year, 2, 2);
|
|
$current_month = sprintf("%02d", $current->month);
|
|
$current_day = sprintf("%02d", $current->day);
|
|
|
|
|
|
$surat_wakil = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/wakil/' . $kodcaw . '/' . $t_cetak)->json();
|
|
if ($surat_wakil) {
|
|
$new_suratid = $surat_wakil['nosiri'] + 1;
|
|
} else {
|
|
$new_suratid = 1;
|
|
}
|
|
|
|
|
|
$new_surat = sprintf("%04d", $new_suratid);
|
|
|
|
$no_surat = 'WK' . $current_year . $current_month . $current_day . '-' . $new_surat;
|
|
Session::put('norujukan', $norujukan);
|
|
Session::put('no_surat', $no_surat);
|
|
Session::put('page_reload', true);
|
|
$gadai = Http::withOptions(['verify' => config('app.api_verify')])->post(config('api.url') . '/api/wakil/' . $kodcaw, [
|
|
'nosiri' => $new_suratid,
|
|
'no_surat' => $no_surat,
|
|
'norujukan' => $norujukan,
|
|
't_cetak' => $t_cetak,
|
|
|
|
]);
|
|
|
|
//get details gadai && detail customer
|
|
|
|
$gadai = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/gadai/norujukan/' . $norujukan)->json();
|
|
$gadai_details = $gadai[0][0];
|
|
|
|
$noic = $gadai_details['nokp'];
|
|
$customer_detail = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/customers/' . $noic)->json();
|
|
|
|
$cawangan = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/cawangan/detail/' . $kodcaw)->json();
|
|
|
|
$cawangan_detail = $cawangan[0];
|
|
|
|
$nosiri = Http::withOptions(['verify' => config('app.api_verify')])->get(config('api.url') . '/api/nosiri/wakil/' . $kodcaw . '/' . $norujukan)->json();
|
|
|
|
|
|
// $pdf=PDF::loadView('print.surat_wakil', compact('customer_detail','current','auth_user','api_url','cawangan_detail'))
|
|
// ->setPaper('A4','potrait');
|
|
// return $pdf->download('notislelong_'.'.pdf');
|
|
|
|
// return view('print.surat_wakil', compact('customer_detail', 'current', 'kodcaw', 'api_url', 'cawangan_detail', 'tarikh_cetak', 'gadai_details', 'noic', 'nosiri'));
|
|
$pdf = PDF::loadView('print.surat_wakil', compact('customer_detail', 'current', 'kodcaw', 'api_url', 'cawangan_detail', 'tarikh_cetak', 'gadai_details', 'noic', 'nosiri'))
|
|
->setPaper('a4', 'potrait');
|
|
return $pdf->download('Surat Wakil.pdf');
|
|
}
|
|
}
|
|
}
|