848 lines
38 KiB
PHP
848 lines
38 KiB
PHP
<?php
|
||
|
||
namespace Modules\Konfirmasibank\Http\Controllers;
|
||
|
||
use Illuminate\Contracts\Support\Renderable;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Routing\Controller;
|
||
use Illuminate\Support\Facades\Auth;
|
||
use Modules\Konfirmasibank\DataTables\ViewAccountDataTable;
|
||
use Modules\Konfirmasibank\Entities\ViewAccount;
|
||
use Modules\Konfirmasibank\Entities\LimitReference;
|
||
use Modules\Konfirmasibank\Entities\Fasilitas;
|
||
use Modules\Konfirmasibank\Entities\Signer;
|
||
use Modules\Konfirmasibank\Entities\Letters;
|
||
use Modules\Konfirmasibank\Entities\Category;
|
||
use Modules\Konfirmasibank\Entities\Company;
|
||
use Modules\Konfirmasibank\Entities\Account;
|
||
use Modules\Konfirmasibank\Entities\Arrangement;
|
||
use Modules\Konfirmasibank\Entities\TermAmount;
|
||
use Dompdf\Dompdf;
|
||
use Dompdf\Options;
|
||
use Carbon\Carbon;
|
||
use PhpOffice\PhpWord\PhpWord;
|
||
use PhpOffice\PhpWord\IOFactory;
|
||
use PhpOffice\PhpWord\Element\Table;
|
||
use PhpOffice\PhpWord\SimpleType\TblWidth;
|
||
use PhpOffice\PhpWord\Element\Section;
|
||
use Response;
|
||
use Exception;
|
||
use Illuminate\Support\Facades\View;
|
||
use Illuminate\Support\Facades\Validator;
|
||
use Illuminate\Support\Facades\Storage;
|
||
use Modules\Konfirmasibank\Http\Requests\Fasilitas\StoreFasilitasRequest;
|
||
class KonfirmasiBankController extends Controller
|
||
{
|
||
public $user;
|
||
|
||
public function __construct()
|
||
{
|
||
$this->middleware(function ($request, $next) {
|
||
$this->user = Auth::guard('web')->user();
|
||
return $next($request);
|
||
});
|
||
|
||
addVendor('chained-select');
|
||
|
||
}
|
||
public function index(Request $request)
|
||
{
|
||
|
||
if (is_null($this->user) || !$this->user->can('konfirmasibank.create')) {
|
||
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
||
}
|
||
// dd($request);
|
||
$data = [];
|
||
$no_req_surat = '';
|
||
// Contoh tanggal saat ini
|
||
$today = Carbon::now();
|
||
|
||
// Menambahkan 1 tahun ke tanggal saat ini
|
||
$currentYear = $today->format("Y");
|
||
//get month in roman
|
||
$dateRoman = $this->numberToRoman($today->format('n'));
|
||
|
||
// Menambahkan 5 tahun ke tanggal saat ini
|
||
$pastYear = $today->subYear(3)->format('Y');
|
||
|
||
$signer = Signer::where('status',1)->get();
|
||
$company = Company::all();
|
||
$infoSurat = Letters::orderBy('created_at','desc')->first();
|
||
|
||
if($infoSurat){
|
||
$no_req_surat = $infoSurat['no_req_surat'];
|
||
}else{
|
||
$no_req_surat = '001/SUBDIT.OPS/'. $dateRoman.'/'.$currentYear;
|
||
}
|
||
|
||
$data['currentYear'] = $currentYear;
|
||
$data['pastYear'] = $pastYear;
|
||
$data['signer'] = $signer;
|
||
$data['company'] = $company;
|
||
$data['no_req_surat'] = $no_req_surat;
|
||
|
||
return view('konfirmasibank::pages.index',compact('data','request'));
|
||
|
||
}
|
||
|
||
public function create(){
|
||
return view('konfirmasibank::pages.index',compact('data'));
|
||
|
||
}
|
||
|
||
|
||
public function getData(Request $request)
|
||
{
|
||
|
||
|
||
$data = [];
|
||
$Account = new ViewAccount;
|
||
$arrAccount = [];
|
||
$startDate = Carbon::parse($request->startDate);
|
||
$dateCore = $startDate->subDays(2)->format('m/d/Y');
|
||
|
||
|
||
$Accounts = $Account->getSearchAccount($request->cif,$arrAccount,$request->kodecabang, $dateCore)->get();
|
||
|
||
// $product = '';
|
||
// foreach ($Accounts as $key => $account) {
|
||
// $Arrangement = $Account->getAAaccount($request->cif , $account->ACCOUNT_NUMBER)->first();
|
||
|
||
// $data[$key]['CUSTOMER_NO'] = $account->CUSTOMER_NO;
|
||
// $data[$key]['INACTIV_MARKER'] = $account->INACTIV_MARKER;
|
||
// $data[$key]['ACCOUNT_NUMBER'] = $account->ACCOUNT_NUMBER;
|
||
// $data[$key]['COMPANY_NAME'] = $account->COMPANY_NAME;
|
||
// $data[$key]['SHORT_TITLE'] = $account->SHORT_TITLE;
|
||
// $data[$key]['WORKING_BALANCE'] = $account->WORKING_BALANCE;
|
||
// $data[$key]['SHORT_NAME'] = $account->SHORT_NAME;
|
||
// $data[$key]['CURRENCY'] = $account->CURRENCY;
|
||
// $data[$key]['BATCH_DATE'] = $account->BATCH_DATE;
|
||
// $data[$key]['OPENING_DATE'] = '';
|
||
// $data[$key]['MATURITY_DATE'] = '';
|
||
// $data[$key]['PRODUCT'] = '';
|
||
|
||
// }
|
||
|
||
return json_encode($Accounts );
|
||
}
|
||
|
||
/*
|
||
----- export pdf -----
|
||
*/
|
||
public function export(Request $request) {
|
||
|
||
|
||
if (is_null($this->user) || !$this->user->can('konfirmasibank.report')) {
|
||
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
||
}
|
||
|
||
$arrAccount = explode("," , $request['acc_no']);
|
||
$startDate = Carbon::parse($request['startDate']);
|
||
$dateCore = $startDate->subDays(2);
|
||
|
||
|
||
$ViewAccount = new ViewAccount;
|
||
$data = [];
|
||
$DataAccounts = [];
|
||
$DataPinjaman = [];
|
||
$DataLimit = [];
|
||
$DataAA = [];
|
||
|
||
//get No Surat
|
||
$noSurat = $this->generateNomorSurat();
|
||
|
||
//submit info surat
|
||
$this->postInfoSurat($request ,$noSurat);
|
||
//Get Info Surat
|
||
$letter = new Letters;
|
||
$infoSuratNew = $letter->where('no_cif',$request['cus_no'])->orderBy('created_at','desc')->first();
|
||
$infoSuratOld = $letter->where('no_cif',$request['cus_no'])->orderBy('created_at','asc')->first();
|
||
|
||
$listAccount = $ViewAccount->getAccount($request['cus_no'],$arrAccount,$request['kode_cabang'], $dateCore)->get();
|
||
|
||
$GetCustomer = $ViewAccount->getCustomer($request['cus_no'])->first();
|
||
|
||
// dd( $Arrangement);
|
||
|
||
$MaturityDate = '';
|
||
$product = '';
|
||
$AAID= '';
|
||
foreach ($listAccount as $key1 => $account) {
|
||
//$Arrangement = $ViewAccount->getAAaccount($account->CUSTOMER_NO,$account->ACCOUNT_NUMBER);
|
||
$Arrangement = $ViewAccount->getAAaccount($request['cus_no'] , $account->ACCOUNT_NUMBER)->first();
|
||
$months = '';
|
||
|
||
if($Arrangement != null && $Arrangement->TERM != null){
|
||
$arrTerm = substr($Arrangement->TERM,-1);
|
||
if($arrTerm[1] = 'Y'){
|
||
$monthsInYear = 12;
|
||
$months = int($arrTerm[0]) * $monthsInYear;
|
||
// $term = $days;
|
||
}elseif ($arrTerm[1] = 'D') {
|
||
$averageDaysInMonth = 30.44;
|
||
$months = int($arrTerm[0]) / $averageDaysInMonth;
|
||
// return $days;
|
||
}
|
||
}
|
||
|
||
|
||
$DataAccounts[$key1]['ACCOUNT_NUMBER'] = $account->ACCOUNT_NUMBER;
|
||
$DataAccounts[$key1]['OPENING_DATE'] = $account->OPENING_DATE;
|
||
$DataAccounts[$key1]['BATCH_DATE'] = $account->BATCH_DATE;
|
||
$DataAccounts[$key1]['CUSTOMER_NO'] = $account->CUSTOMER_NO;
|
||
$DataAccounts[$key1]['SHORT_NAME'] = $account->SHORT_NAME;
|
||
$DataAccounts[$key1]['CURRENCY'] = $account->CURRENCY;
|
||
$DataAccounts[$key1]['PRODUCT'] = $Arrangement->PRODUCT ?? '';
|
||
$DataAccounts[$key1]['COMPANY_NAME'] = $account->COMPANY_NAME;
|
||
$DataAccounts[$key1]['WORKING_BALANCE'] = $account->WORKING_BALANCE;
|
||
$DataAccounts[$key1]['MATURITY_DATE'] = $Arrangement->MATURITY_DATE ?? '' ;
|
||
$DataAccounts[$key1]['ARRANGEMENT_ID'] = $Arrangement->ARRANGEMENT_ID ?? '';
|
||
$DataAccounts[$key1]['FIXED_RATE'] = $Arrangement->FIXED_RATE ?? '';
|
||
$DataAccounts[$key1]['TERM'] = $months ?? '';
|
||
}
|
||
|
||
|
||
$ListPinjaman =$ViewAccount->getPinjaman($request['cus_no'],$arrAccount , $dateCore )->get();
|
||
|
||
$ListLimits = $ViewAccount->getLimit($request['cus_no'],$request['periode']);
|
||
$fasilitas = Fasilitas::where('nomor_cif',$request['cus_no'] )->where('status',1)->get();
|
||
|
||
$signer = Signer::where('id', $request['signer'])->where('status',1)->get();
|
||
$currentDate = Carbon::now();
|
||
$tanggalIndonesia = $currentDate->locale('id')->isoFormat('D MMMM YYYY');
|
||
// dd($infoSuratOld,$infoSuratNew,$GetCustomer);
|
||
$data['DataAccounts'] = $DataAccounts;
|
||
$data['DataPinjaman'] = $ListPinjaman;
|
||
$data['DataLimit'] = $ListLimits;
|
||
$data['DataFasilitas'] = $fasilitas;
|
||
$data['DataSigner'] = $signer;
|
||
$data['DataCustomer'] = $GetCustomer ?? '';
|
||
$data['localDate'] = $tanggalIndonesia;
|
||
$data['infoSuratOld'] = $infoSuratOld;
|
||
$data['infoSuratNew'] = $infoSuratNew;
|
||
|
||
// Inisialisasi DOMPDF
|
||
$options = new Options();
|
||
$options->set('isHtml5ParserEnabled', true);
|
||
$options->set('isPhpEnabled', true);
|
||
$options->set(['padding-top' => 39, 'padding-right' => 10, 'padding-bottom' => 20, 'padding-left' => 15]);
|
||
$dompdf = new Dompdf($options);
|
||
$html = View::make('konfirmasibank::exportPdf', ['data' => $data])->render();
|
||
// Konfigurasi DOMPDF
|
||
|
||
$dompdf->loadHtml($html);
|
||
|
||
// Mengatur jenis kertas
|
||
$dompdf->setPaper('f4', 'portrait')->set_option('defaultFont', 'Arial');
|
||
|
||
|
||
// Render HTML menjadi PDF
|
||
$dompdf->render();
|
||
|
||
|
||
// Keluarkan file PDF ke browser
|
||
$dompdf->stream('"Konfirmasi_bank_"'.$data['DataCustomer']->SHORT_NAME.'"'. $currentDate.'".pdf"');
|
||
|
||
return response()->download($dompdf);
|
||
|
||
}
|
||
|
||
|
||
private function postInfoSurat($request, $noSurat){
|
||
|
||
|
||
// $request->validate([
|
||
// 'signer' => ['required'],
|
||
// 'no_req_surat' => ['required', 'max:100'],
|
||
// 'tgl_req_surat' => ['required'],
|
||
// 'email' => ['email'],
|
||
// 'tlp' => ['numeric', 'max:10'],
|
||
// 'nama_tujuan' => ['required'],
|
||
// 'alamat' => ['required']
|
||
// ]);
|
||
|
||
$currentDate = Carbon::now();
|
||
$tglSurat = $currentDate->format('Y-m-d');
|
||
$letter = new Letters();
|
||
$letter->no_cif = $request->cus_no;
|
||
$letter->no_surat = $noSurat;
|
||
$letter->tgl_surat = $tglSurat;
|
||
$letter->no_req_surat = $request->no_req_surat;
|
||
$letter->tgl_req_surat = $request->tgl_req_surat;
|
||
$letter->email = $request->email ;
|
||
$letter->tlp = $request->tlp ;
|
||
$letter->nama_tujuan = $request->nama_tujuan ;
|
||
$letter->alamat = $request->alamat ;
|
||
$letter->created_at = $currentDate;
|
||
$letter->status = 1;
|
||
$letter->save();
|
||
|
||
}
|
||
|
||
private function generateNomorSurat(){
|
||
$latesNoSurat = '';
|
||
$latestRecord = letters::latest('no_surat')->select('no_surat')->first();
|
||
$tanggal = now();
|
||
$tahun = $tanggal->format('Y');
|
||
// Fungsi untuk mengonversi angka bulan menjadi romawi
|
||
$bulanRomawi = $this->numberToRoman($tanggal->format('n'));
|
||
|
||
if($latestRecord){
|
||
$squence = substr($latestRecord['no_surat'], 0, 3);
|
||
$latesNoSurat = str_pad(intval($squence), 3, '0', STR_PAD_LEFT);
|
||
$NoUrut = str_pad(intval($latesNoSurat + 1), 3, '0', STR_PAD_LEFT);
|
||
$noSurat = " $NoUrut/SUBDIT.OPS/$bulanRomawi/$tahun";
|
||
return $noSurat;
|
||
}else {
|
||
$noSurat = "001/SUBDIT.OPS/$bulanRomawi/$tahun";
|
||
return $noSurat;
|
||
}
|
||
|
||
}
|
||
|
||
function numberToRoman($num)
|
||
{
|
||
// Be sure to convert the given parameter into an integer
|
||
$n = intval($num);
|
||
$result = '';
|
||
|
||
// Declare a lookup array that we will use to traverse the number:
|
||
$lookup = array(
|
||
'M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400,
|
||
'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40,
|
||
'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1
|
||
);
|
||
|
||
foreach ($lookup as $roman => $value)
|
||
{
|
||
// Look for number of matches
|
||
$matches = intval($n / $value);
|
||
|
||
// Concatenate characters
|
||
$result .= str_repeat($roman, $matches);
|
||
|
||
// Substract that from the number
|
||
$n = $n % $value;
|
||
}
|
||
|
||
return $result;
|
||
}
|
||
|
||
|
||
|
||
public function signer(Request $request){
|
||
if (is_null($this->user) || !$this->user->can('konfirmasibank.create')) {
|
||
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
||
}
|
||
|
||
$data = [];
|
||
// $signer = Signer::paginate(10);
|
||
$signer = Signer::where('status',1)->paginate(10);
|
||
$data['signer'] = $signer;
|
||
// dd( $data['signer']);
|
||
|
||
return view('konfirmasibank::pages.index_signer',compact('data'));
|
||
|
||
}
|
||
|
||
public function exportWord(Request $request){
|
||
//ob_start();
|
||
$currentDate = Carbon::now();
|
||
$arrAccount = explode("," , $request['acc_no']);
|
||
$startDate = Carbon::parse($request['startDate']);
|
||
$dateCore = $startDate->subDays(2);
|
||
|
||
|
||
$ViewAccount = new ViewAccount;
|
||
$data = [];
|
||
$DataAccounts = [];
|
||
$DataPinjaman = [];
|
||
$DataLimit = [];
|
||
$DataAA = [];
|
||
|
||
$listAccount = $ViewAccount->getAccount($request['cus_no'],$arrAccount,$request['kode_cabang'], $dateCore)->get();
|
||
|
||
$GetCustomer = $ViewAccount->getCustomer($request['cus_no'])->first();
|
||
|
||
// dd( $Arrangement);
|
||
|
||
$MaturityDate = '';
|
||
$product = '';
|
||
$AAID= '';
|
||
foreach ($listAccount as $key1 => $account) {
|
||
//$Arrangement = $ViewAccount->getAAaccount($account->CUSTOMER_NO,$account->ACCOUNT_NUMBER);
|
||
$Arrangement = $ViewAccount->getAAaccount($request['cus_no'] , $account->ACCOUNT_NUMBER)->first();
|
||
$DataAccounts[$key1]['SHORT_NAME'] = $account->SHORT_NAME;
|
||
$DataAccounts[$key1]['OPENING_DATE'] = $account->OPENING_DATE;
|
||
$DataAccounts[$key1]['WORKING_BALANCE'] = $account->WORKING_BALANCE;
|
||
$DataAccounts[$key1]['TERM'] = $Arrangement->TERM ?? 'NIHIL';
|
||
$DataAccounts[$key1]['FIXED_RATE'] = $Arrangement->FIXED_RATE ?? 'NIHIL';
|
||
$DataAccounts[$key1]['MATURITY_DATE'] = $Arrangement->MATURITY_DATE ?? 'NIHIL' ;
|
||
}
|
||
|
||
$ListPinjaman =$ViewAccount->getPinjaman($request['cus_no'],$arrAccount , $dateCore )->get();
|
||
foreach ($ListPinjaman as $key2 => $pinjaman) {
|
||
//$Arrangement = $ViewAccount->getAAaccount($request['cus_no'] , $account->ACCOUNT_NUMBER)->first();
|
||
$DataPinjaman[$key2]['JENIS_PINJAMAN'] = $pinjaman->PRODUCT_LINE;
|
||
$DataPinjaman[$key2]['TGL_REALISASI'] = $pinjaman->START_DATE;
|
||
$DataPinjaman[$key2]['SALDO'] = $pinjaman->WORKING_BALANCE;
|
||
$DataPinjaman[$key2]['JANGKA_WAKTU'] = $pinjaman->TERM ?? 'NIHIL';
|
||
$DataPinjaman[$key2]['FIXED_RATE'] = $pinjaman->FIXED_RATE ?? 'NIHIL';
|
||
$DataPinjaman[$key2]['MATURITY_DATE'] = $pinjaman->MATURITY_DATE ?? 'NIHIL' ;
|
||
$DataPinjaman[$key2]['KET'] = '';
|
||
|
||
}
|
||
|
||
$signer = Signer::where('id', $request['signer'])->where('status',1)->first();
|
||
$currentDate = Carbon::now();
|
||
$tanggalIndonesia = $currentDate->locale('id')->isoFormat('D MMMM YYYY');
|
||
$GetCustomer = $ViewAccount->getCustomer($request['cus_no'])->first();
|
||
|
||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||
$section = $phpWord->addSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 2500, 'marginBottom' => 600) );
|
||
$header = array('size' => 10, 'bold' => false);
|
||
|
||
|
||
$styleTable = array('borderSize' => 2, 'borderColor' => '00000');
|
||
$styleFirstRow = array('bgColor' => 'CCCCCC','cellMargin' => 0, 'spaceBefore' => 0,'spaceAfter' => 0,'spacing' => 0);
|
||
$styleCell = array('valign' => 'center','spaceBefore' => 0,'spaceAfter' => 0,'spacing' => 0, 'bgColor' => 'CCCCCC');
|
||
$styleCellBTLR = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
|
||
$fontStyle = array('align' => 'center', 'size' => 10, );
|
||
|
||
$section->addText(htmlspecialchars('NOMOR : --------------------------'), $fontStyle);
|
||
$section->addText(htmlspecialchars('TANGGAL : --------------------------'), $fontStyle);
|
||
$section->addTextBreak(1);
|
||
$section->addText(htmlspecialchars($GetCustomer->STREET), $fontStyle);
|
||
$section->addText(htmlspecialchars($GetCustomer->ADDRESS), $fontStyle);
|
||
$section->addText(htmlspecialchars('Sesuai dengan surat saudara Nomor --------------------------- tanggal ----------------------- dengan ini kami sampaikan data – data nasabah sesuai permintaan saudara sebagai berikut :'), $fontStyle);
|
||
|
||
$section->addText(htmlspecialchars('NAMA NASABAH : '.$GetCustomer->SHORT_NAME.''), $fontStyle);
|
||
$section->addText(htmlspecialchars('NOMOR CIF : '.$GetCustomer->CUSTOMER_NO.''), $fontStyle);
|
||
$section->addTextBreak(1);
|
||
|
||
// $phpWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow);
|
||
$section->addText(htmlspecialchars('SIMPANAN NASABAH YANG BERSANGKUTAN PADA BANK'), $header);
|
||
$section->addText(htmlspecialchars("{$tanggalIndonesia}"), $header);
|
||
$table = $section->addTable(array('borderSize' => 6, 'fontSize' =>10, 'borderColor' => 'black', 'width' => 10500, 'unit' => TblWidth::TWIP));
|
||
$table->addRow(300);
|
||
$table->addCell(600, $styleCell)->addText(htmlspecialchars("NO"), $fontStyle, array('align' => 'center','spaceAfter'=>0));
|
||
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('JENIS REKENING'), $fontStyle,array('align' => 'center','spaceAfter'=>0));
|
||
$table->addCell(1500, $styleCell)->addText(htmlspecialchars('TGL REALISASI'), $fontStyle,array('align' => 'center','spaceAfter'=>0));
|
||
$table->addCell(1000, $styleCell)->addText(htmlspecialchars('SALDO'), $fontStyle,array('align' => 'center','spaceAfter'=>0));
|
||
$table->addCell(1500, $styleCell)->addText(htmlspecialchars('JANGKA WAKTU'), $fontStyle,array('align' => 'center','spaceAfter'=>0));
|
||
$table->addCell(1000, $styleCell)->addText(htmlspecialchars('SUKU BUNGA'), $fontStyle,array('align' => 'center','spaceAfter'=>0));
|
||
$table->addCell(1500, $styleCell)->addText(htmlspecialchars('TGL JT TEMPO'), $fontStyle,array('align' => 'center','spaceAfter'=>0));
|
||
$table->addCell(1000, $styleCell)->addText(htmlspecialchars('KET'), $fontStyle,array('align' => 'center','spaceAfter'=>0));
|
||
$no = 1;
|
||
foreach ($DataAccounts as $key1 => $value1) {
|
||
$rupiah = $this->convertToRupiah($value1['WORKING_BALANCE']);
|
||
$table->addRow();
|
||
$table->addCell(600)->addText(htmlspecialchars($no++), $fontStyle, array('align' => 'center','spaceAfter'=>0));
|
||
$table->addCell(2000)->addText(htmlspecialchars(" {$value1['SHORT_NAME']}"), array('align' => 'left','spaceAfter'=>0));
|
||
$table->addCell(1500)->addText(htmlspecialchars(" {$value1['OPENING_DATE']}"), array('align' => 'center','spaceAfter'=>0));
|
||
$table->addCell(1000)->addText(htmlspecialchars(" {$rupiah}"), array('align' => 'left','spaceAfter'=>0));
|
||
$table->addCell(1500)->addText(htmlspecialchars(" {$value1['TERM']}"), array('align' => 'center','spaceAfter'=>0));
|
||
$table->addCell(1000)->addText(htmlspecialchars(" {$value1['FIXED_RATE']}"), array('align' => 'center','spaceAfter'=>0));
|
||
$table->addCell(1500)->addText(htmlspecialchars(" {$value1['MATURITY_DATE']}"), array('align' => 'center','spaceAfter'=>0));
|
||
$table->addCell(1000)->addText(htmlspecialchars(""), array('align' => 'center','spaceAfter'=>0));
|
||
}
|
||
|
||
// 3. Table Pinjaman
|
||
$section->addTextBreak(1);
|
||
$section->addText(htmlspecialchars('PINJAMAN YANG DIBERIKAN BANK KEPADA NASABAH'), $header);
|
||
$section->addText(htmlspecialchars("{$tanggalIndonesia}"), $header);
|
||
$table2 = $section->addTable(array('borderSize' => 6, 'fontSize' =>10, 'borderColor' => 'black', 'width' => 10500, 'unit' => TblWidth::TWIP));
|
||
$table2->addRow(300);
|
||
$table2->addCell(600, $styleCell)->addText(htmlspecialchars("NO"), $fontStyle, array('align' => 'center','spaceAfter'=>0));
|
||
$table2->addCell(2000, $styleCell)->addText(htmlspecialchars('JENIS REKENING'), $fontStyle, array('align' => 'center'));
|
||
$table2->addCell(1500, $styleCell)->addText(htmlspecialchars('TGL REALISASI'), $fontStyle, array('align' => 'center'));
|
||
$table2->addCell(1000, $styleCell)->addText(htmlspecialchars('SALDO'), $fontStyle, array('align' => 'center'));
|
||
$table2->addCell(1500, $styleCell)->addText(htmlspecialchars('JANGKA WAKTU'), $fontStyle, array('align' => 'center'));
|
||
$table2->addCell(1000, $styleCell)->addText(htmlspecialchars('SUKU BUNGA'), $fontStyle, array('align' => 'center'));
|
||
$table2->addCell(1500, $styleCell)->addText(htmlspecialchars('TGL JT TEMPO'), $fontStyle, array('align' => 'center'));
|
||
$table2->addCell(1000, $styleCell)->addText(htmlspecialchars('KET'), $fontStyle, array('align' => 'center'));
|
||
$no = 1;
|
||
foreach ($DataPinjaman as $key2 => $value2) {
|
||
$rupiah = $this->convertToRupiah($value2['SALDO']);
|
||
$table2->addRow();
|
||
$table2->addCell(600)->addText(htmlspecialchars($no++), $fontStyle, array('align' => 'center'));
|
||
$table2->addCell(1500)->addText(htmlspecialchars(" {$value2['JENIS_PINJAMAN']}"), array('align' => 'center'));
|
||
$table2->addCell(1000)->addText(htmlspecialchars(" {$value2['TGL_REALISASI']}"), array('align' => 'center'));
|
||
$table2->addCell(1500)->addText(htmlspecialchars(" {$rupiah}"), array('align' => 'right'));
|
||
$table2->addCell(1000)->addText(htmlspecialchars(" {$value2['JANGKA_WAKTU']}"), array('align' => 'center'));
|
||
$table2->addCell(1500)->addText(htmlspecialchars(" {$value2['FIXED_RATE']}"), array('align' => 'center'));
|
||
$table2->addCell(1500)->addText(htmlspecialchars(" {$value2['MATURITY_DATE']}"), array('align' => 'center'));
|
||
$table2->addCell(1000)->addText(htmlspecialchars(""));
|
||
}
|
||
//Table Signature
|
||
$section->addTextBreak(1);
|
||
$section->addText(htmlspecialchars('Demikian data ini kami sampaikan agar dapat digunakan sebagaimana mestinya'), $header);
|
||
|
||
$signatureStyle = array('size'=>10, 'align' =>'center' );
|
||
$table3 = $section->addTable(array('width' => 2000, 'unit' => 'pct', 'align' => 'left'));
|
||
|
||
$table3->addRow(1000);
|
||
$table3->addCell(2000)->addText(htmlspecialchars(''));
|
||
$table3->addCell(2000)->addText(htmlspecialchars(''), $signatureStyle);
|
||
$table3->addRow();
|
||
$table3->addCell(2000)->addText(htmlspecialchars('Frangky'), array('marginLeft' => 600,'size'=>10, ));
|
||
$table3->addCell(2000)->addText(htmlspecialchars('Sifera Officer'), $signatureStyle);
|
||
$table3->addRow();
|
||
$table3->addCell(2000)->addText(htmlspecialchars('Director'), array('marginLeft' => 600,'size'=>10, ));
|
||
$table3->addCell(2000)->addText(htmlspecialchars('Executive Officer'), $signatureStyle);
|
||
|
||
|
||
$filename = 'KonfirmasiBank_'.$currentDate->format('YmdHis').'.docx';
|
||
|
||
// Create writer to convert document to xml
|
||
|
||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
|
||
$objWriter->save($filename);
|
||
|
||
header('Content-Description: File Transfer');
|
||
header('Content-Type: application/octet-stream');
|
||
header('Content-Disposition: attachment; filename='.$filename);
|
||
header('Content-Transfer-Encoding: binary');
|
||
header('Expires: 0');
|
||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||
header('Pragma: public');
|
||
header('Content-Length: ' . filesize($filename));
|
||
flush();
|
||
readfile($filename);
|
||
unlink($filename); // deletes the temporary file
|
||
|
||
|
||
$objWriter->save($filename);
|
||
|
||
}
|
||
|
||
|
||
public function convertToRupiah($amount)
|
||
{
|
||
$formattedAmount = number_format($amount, 0, ',', '.');
|
||
return $formattedAmount;
|
||
}
|
||
|
||
public function postSigner(Request $request){
|
||
|
||
if (is_null($this->user) || !$this->user->can('konfirmasibank.create')) {
|
||
abort(403, 'Sorry !! You are Unauthorized to create any konfirmasibank.create !');
|
||
}
|
||
|
||
|
||
$currentDate = Carbon::now();
|
||
$validated = $request->validate([
|
||
'deputy_director' => 'required|string',
|
||
'executive_officer' => 'required|string',
|
||
'signer_type' => 'required|string'
|
||
]);
|
||
|
||
if ($validated) {
|
||
try {
|
||
// Create New User
|
||
$signer = new Signer();
|
||
$signer->deputy_director_name = $request->deputy_director;
|
||
$signer->executive_officer_name = $request->executive_officer;
|
||
$signer->signer_type = $request->signer_type;
|
||
$signer->created_at = $currentDate;
|
||
$signer->status = 1;
|
||
$signer->save();
|
||
// return redirect()->route('konfirmasibank.addFasilitas')->with('success', 'Data berhasil ditambahkan');
|
||
echo json_encode(['status' => 'success', 'message' => ' Add signer successfully .']);
|
||
|
||
} catch (Exception $e) {
|
||
return json_encode([
|
||
'status' => 'error',
|
||
'message' => $e->getMessage()
|
||
]);
|
||
}
|
||
}
|
||
|
||
return false;
|
||
|
||
}
|
||
|
||
/**
|
||
* Show the form for editing the specified resource.
|
||
*
|
||
* @param int $id
|
||
*
|
||
* @return Response
|
||
*/
|
||
public function editSigner(Request $request)
|
||
{
|
||
|
||
if (is_null($this->user) || !$this->user->can('konfirmasibank.update')) {
|
||
abort(403, 'Sorry !! You are Unauthorized to edit any role !');
|
||
}
|
||
|
||
$signer = Signer::find($request->id);
|
||
|
||
return json_encode( $signer);
|
||
}
|
||
|
||
|
||
public function fasilitas(Request $request){
|
||
|
||
if (is_null($this->user) || !$this->user->can('konfirmasibank.create')) {
|
||
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
||
}
|
||
|
||
$data = [];
|
||
|
||
$fasilitas = Fasilitas::where('status',1)->where('nomor_cif',$request->query()['cus_no_fasilitas'])->paginate(10)->appends($request->query()['cus_no_fasilitas'],$request->query()['company_name'],$request->query()['startDateFasilitas']);
|
||
|
||
$Category = Category::all();
|
||
$Company = Company::all();
|
||
// dd($fasilitas);
|
||
$limitReference = LimitReference::all();
|
||
$data['queryParam'] = $request->query();
|
||
$data['fasilitas'] = $fasilitas;
|
||
$data['limitReference'] = $limitReference;
|
||
$data['Category'] = $Category;
|
||
$data['Company'] = $Company;
|
||
|
||
return view('konfirmasibank::pages.index_fasilitas',compact('data'));
|
||
|
||
}
|
||
|
||
|
||
|
||
public function updateSigner(Request $request)
|
||
{
|
||
|
||
if (is_null($this->user) || !$this->user->can('konfirmasibank.update')) {
|
||
abort(403, 'Sorry !! You are Unauthorized to edit any role !');
|
||
}
|
||
|
||
$today = Carbon::now();
|
||
|
||
$validator = Validator::make($request->all(), [
|
||
'deputy_director' => 'required|string',
|
||
'executive_officer' => 'required|string',
|
||
'signer_type' => 'required|string'
|
||
]);
|
||
|
||
if ($validator->fails()) {
|
||
return response()->json(['errors' => $validator->errors()], 422); // Return validation errors as JSON
|
||
}
|
||
|
||
|
||
if ($validator) {
|
||
try {
|
||
$signer = Signer::findOrFail($request->id);
|
||
$signer->deputy_director_name = $request->deputy_director;
|
||
$signer->executive_officer_name = $request->executive_officer;
|
||
$signer->signer_type = $request->signer_type;
|
||
$signer->updated_at = $today;
|
||
$signer->save();
|
||
|
||
echo json_encode(['status' => 'success', 'message' => ' signer updated successfully.']);
|
||
|
||
} catch (Exception $e) {
|
||
echo json_encode(['status' => 'error', 'message' => ' signer updated failed.']);
|
||
}
|
||
|
||
return;
|
||
|
||
}
|
||
echo json_encode(['status' => 'error', 'message' => ' signer updated failed.']);
|
||
}
|
||
|
||
|
||
|
||
public function postFasilitas(Request $request){
|
||
|
||
|
||
if (is_null($this->user) || !$this->user->can('konfirmasibank.create')) {
|
||
abort(403, 'Sorry !! You are Unauthorized to create any konfirmasibank.create !');
|
||
}
|
||
|
||
$validated = $request->validate([
|
||
'nomor_rekening' => 'required|string|max:10|unique:fasilitas,nomor_rekening',
|
||
'jenis_fasilitas' => 'required|string',
|
||
'cabang' => 'required|string',
|
||
'mata_uang' => 'required|string',
|
||
'jenis_rekening' => 'required|string',
|
||
'saldo' => 'required|string',
|
||
'start_date' => 'required|string',
|
||
'due_date' => 'required|string',
|
||
'fixed_rate' => 'required|string'
|
||
]);
|
||
|
||
|
||
$startDate = Carbon::parse($request->start_date);
|
||
$endDate = Carbon::parse($request->due_date);
|
||
$jangkaWaktu = $endDate->diffInDays($startDate);
|
||
|
||
if ($validated) {
|
||
try {
|
||
// Create New User
|
||
$fasilitas = new Fasilitas();
|
||
$fasilitas->nomor_cif = $request->nomor_cif;
|
||
$fasilitas->nomor_rekening = $request->nomor_rekening;
|
||
$fasilitas->cabang = $request->cabang;
|
||
$fasilitas->jenis_fasilitas = $request->jenis_fasilitas;
|
||
$fasilitas->jenis_rekening = $request->jenis_rekening;
|
||
$fasilitas->mata_uang = $request->mata_uang;
|
||
$fasilitas->saldo = $request->saldo;
|
||
$fasilitas->start_date = $request->start_date;
|
||
$fasilitas->due_date = $request->due_date;
|
||
$fasilitas->jangka_waktu = $jangkaWaktu;
|
||
$fasilitas->fixed_rate = $request->fixed_rate;
|
||
$fasilitas->keterangan = $request->keterangan;
|
||
|
||
$fasilitas->save();
|
||
|
||
echo json_encode(['status' => 'success', 'message' => 'Add fasilitas successfully.']);
|
||
|
||
} catch (Exception $e) {
|
||
|
||
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
||
|
||
// return json_encode([
|
||
// 'status' => 'error',
|
||
// 'message' => $e->getMessage()
|
||
// ]);
|
||
}
|
||
}
|
||
|
||
return false;
|
||
|
||
}
|
||
|
||
/**
|
||
* Show the form for editing the specified resource.
|
||
*
|
||
* @param int $id
|
||
*
|
||
* @return Response
|
||
*/
|
||
public function editFasilitas(Request $request)
|
||
{
|
||
|
||
if (is_null($this->user) || !$this->user->can('konfirmasibank.update')) {
|
||
abort(403, 'Sorry !! You are Unauthorized to edit any role !');
|
||
}
|
||
|
||
$fasilitas = Fasilitas::find($request->id);
|
||
|
||
return json_encode( $fasilitas);
|
||
}
|
||
|
||
/**
|
||
* Update the specified resource in storage.
|
||
*
|
||
* @param Request $request
|
||
* @param int $id
|
||
*
|
||
* @return Response
|
||
*/
|
||
public function updateFasilitas(Request $request)
|
||
{
|
||
|
||
if (is_null($this->user) || !$this->user->can('konfirmasibank.update')) {
|
||
abort(403, 'Sorry !! You are Unauthorized to edit any role !');
|
||
}
|
||
|
||
$today = Carbon::now();
|
||
// Menambahkan 1 tahun ke tanggal saat ini
|
||
// $currentYear = $today->format("YYYY-MM-DD");
|
||
|
||
// Validation Data\
|
||
$validator = Validator::make($request->all(), [
|
||
'nomor_rekening_edit' => 'required|string',
|
||
'cabang_edit' => 'required|string',
|
||
'jenis_fasilitas_edit' => 'required|string',
|
||
'jenis_rekening_edit' => 'required|string',
|
||
'mata_uang_edit' => 'required|string',
|
||
'saldo_edit' => 'required|string',
|
||
'start_date_edit' => 'required|string',
|
||
'due_date_edit' => 'required|string',
|
||
'fixed_rate_edit' => 'required|string'
|
||
// Other validation rules
|
||
]);
|
||
|
||
|
||
if ($validator->fails()) {
|
||
return response()->json(['errors' => $validator->errors()], 422); // Return validation errors as JSON
|
||
}
|
||
|
||
$startDate = Carbon::parse($request->start_date_edit);
|
||
$endDate = Carbon::parse($request->due_date_edit);
|
||
$jangkaWaktu = $endDate->diffInDays($startDate);
|
||
if ($validator) {
|
||
try {
|
||
$fasilitas = Fasilitas::findOrFail($request->id);
|
||
$fasilitas->nomor_rekening = $request->nomor_rekening_edit;
|
||
$fasilitas->cabang = $request->cabang_edit;
|
||
$fasilitas->jenis_fasilitas = $request->jenis_fasilitas_edit;
|
||
$fasilitas->jenis_rekening = $request->jenis_rekening_edit;
|
||
$fasilitas->mata_uang = $request->mata_uang_edit;
|
||
$fasilitas->saldo = $request->saldo_edit;
|
||
$fasilitas->start_date = $request->start_date_edit;
|
||
$fasilitas->due_date = $request->due_date_edit;
|
||
$fasilitas->jangka_waktu = $jangkaWaktu;
|
||
$fasilitas->fixed_rate = $request->fixed_rate_edit;
|
||
$fasilitas->keterangan = $request->keterangan_edit;
|
||
$fasilitas->updated_at = $today;
|
||
$fasilitas->save();
|
||
|
||
echo json_encode(['status' => 'success', 'message' => ' fasilitas updated successfully.']);
|
||
|
||
} catch (Exception $e) {
|
||
echo json_encode(['status' => 'error', 'message' => ' fasilitas updated failed.']);
|
||
}
|
||
|
||
return;
|
||
|
||
}
|
||
echo json_encode(['status' => 'error', 'message' => ' fasilitas updated failed.']);
|
||
}
|
||
|
||
|
||
/**
|
||
* Remove the specified resource from storage.
|
||
*
|
||
* @param int $id
|
||
*
|
||
* @return Renderable
|
||
*/
|
||
public function destroyFasilitas(Request $request)
|
||
{
|
||
if (is_null($this->user) || !$this->user->can('konfirmasibank.delete')) {
|
||
abort(403, 'Sorry !! You are Unauthorized to delete any konfirmasibank module !');
|
||
}
|
||
|
||
$fasilitas = Fasilitas::findOrFail($request->id);
|
||
|
||
try {
|
||
$fasilitas->status = 0;
|
||
$fasilitas->save();
|
||
echo json_encode(['status' => 'success', 'message' => ' fasilitas deleted successfully.']);
|
||
} catch (Exception $e) {
|
||
echo json_encode(['status' => 'error', 'message' => ' fasilitas deleted failed.']);
|
||
}
|
||
}
|
||
|
||
public function destroySigner(Request $request)
|
||
{
|
||
if (is_null($this->user) || !$this->user->can('konfirmasibank.delete')) {
|
||
abort(403, 'Sorry !! You are Unauthorized to delete any konfirmasibank module !');
|
||
}
|
||
|
||
|
||
$signer = Signer::findOrFail($request->id);
|
||
|
||
|
||
try {
|
||
$signer->status = 0;
|
||
$signer->save();
|
||
echo json_encode(['status' => 'success', 'message' => ' Signer deleted successfully.']);
|
||
} catch (Exception $e) {
|
||
echo json_encode(['status' => 'error', 'message' => ' Signer deleted failed.']);
|
||
}
|
||
}
|
||
|
||
|
||
} |