update format export surat
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
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;
|
||||
@ -52,22 +53,33 @@
|
||||
}
|
||||
// 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;
|
||||
// dd($data);
|
||||
$data['no_req_surat'] = $no_req_surat;
|
||||
|
||||
return view('konfirmasibank::pages.index',compact('data','request'));
|
||||
|
||||
@ -135,6 +147,16 @@
|
||||
$DataLimit = [];
|
||||
$DataAA = [];
|
||||
|
||||
//get No Surat
|
||||
$noSurat = $this->generateNomorSurat();
|
||||
|
||||
|
||||
//submit info surat
|
||||
$this->postInfoSurat($request['cus_no'],$request['no_req_surat'],$request['tgl_req_surat'],$noSurat,$request['email'],$request['tlp'],$request['nama_tujuan'],$request['alamat']);
|
||||
//Get Info Surat
|
||||
$letter = new Letters;
|
||||
$infoSurat = $letter->where('no_cif',$request['cus_no'])->orderBy('created_at','desc')->first();
|
||||
|
||||
$listAccount = $ViewAccount->getAccount($request['cus_no'],$arrAccount,$request['kode_cabang'], $dateCore)->get();
|
||||
|
||||
$GetCustomer = $ViewAccount->getCustomer($request['cus_no'])->first();
|
||||
@ -179,7 +201,7 @@
|
||||
$data['DataSigner'] = $signer;
|
||||
$data['DataCustomer'] = $GetCustomer ?? '';
|
||||
$data['localDate'] = $tanggalIndonesia;
|
||||
|
||||
$data['infoSurat'] = $infoSurat;
|
||||
|
||||
// Inisialisasi DOMPDF
|
||||
$options = new Options();
|
||||
@ -207,173 +229,76 @@
|
||||
|
||||
}
|
||||
|
||||
public function exportWord2(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 = [];
|
||||
|
||||
$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]['ACCOUNT_NUMBER'] = $account->ACCOUNT_NUMBER;
|
||||
$DataAccounts[$key1]['COMPANY_NAME'] = $account->COMPANY_NAME;
|
||||
$DataAccounts[$key1]['SHORT_NAME'] = $account->SHORT_NAME;
|
||||
// $DataAccounts[$key1]['CUSTOMER_NO'] = $account->CUSTOMER_NO;
|
||||
$DataAccounts[$key1]['CURRENCY'] = $account->CURRENCY;
|
||||
// $DataAccounts[$key1]['PRODUCT'] = $Arrangement->PRODUCT ?? 'NIHIL';
|
||||
$DataAccounts[$key1]['WORKING_BALANCE'] = $account->WORKING_BALANCE;
|
||||
// $DataAccounts[$key1]['ARRANGEMENT_ID'] = $Arrangement->ARRANGEMENT_ID ?? 'NIHIL';
|
||||
$DataAccounts[$key1]['TERM'] = $Arrangement->TERM ?? 'NIHIL';
|
||||
$DataAccounts[$key1]['FIXED_RATE'] = $Arrangement->FIXED_RATE ?? 'NIHIL';
|
||||
$DataAccounts[$key1]['OPENING_DATE'] = $account->OPENING_DATE;
|
||||
$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'] = '';
|
||||
|
||||
}
|
||||
|
||||
|
||||
// $ListLimits = $Viewpinjaman->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)->first();
|
||||
private function postInfoSurat($cif,$noReqSurat,$tglReqSurat,$noSurat,$email,$tlp,$tujuan,$alamat){
|
||||
$currentDate = Carbon::now();
|
||||
$tanggalIndonesia = $currentDate->locale('id')->isoFormat('D MMMM YYYY');
|
||||
|
||||
|
||||
//You can get xml code of your table and insert it insite template
|
||||
|
||||
//Create table
|
||||
$document_with_table = new PhpWord();
|
||||
$section = $document_with_table->addSection();
|
||||
$table = $section->addTable(array('borderSize' => 12, 'fontSize' =>10, 'borderColor' => 'green', 'width' => 11200, 'unit' => TblWidth::TWIP));
|
||||
|
||||
//Add Tablle 1
|
||||
// Add header row with custom styling Table1
|
||||
$headerRow = $table->addRow();
|
||||
$headerRow->addCell(2000, ['bgColor' => 'CCCCCC'])->addText('Rekening');
|
||||
$headerRow->addCell(2000, ['bgColor' => 'CCCCCC'])->addText('Cabang');
|
||||
$headerRow->addCell(2000, ['bgColor' => 'CCCCCC'])->addText('Jenis Rekening');
|
||||
$headerRow->addCell(1000, ['bgColor' => 'CCCCCC'])->addText('Mata Uang');
|
||||
$headerRow->addCell(2000, ['bgColor' => 'CCCCCC'])->addText('Saldo');
|
||||
$headerRow->addCell(1000, ['bgColor' => 'CCCCCC'])->addText('Jangka Waktu');
|
||||
$headerRow->addCell(1000, ['bgColor' => 'CCCCCC'])->addText('Suku Bunga');
|
||||
$headerRow->addCell(2000, ['bgColor' => 'CCCCCC'])->addText('Tgl Realisasi');
|
||||
$headerRow->addCell(2000, ['bgColor' => 'CCCCCC'])->addText('Jatuh Tempo');
|
||||
// Add a row to the table
|
||||
|
||||
|
||||
// Add data rows dynamically
|
||||
foreach ($DataAccounts as $key => $rowData) {
|
||||
$dataRow = $table->addRow();
|
||||
foreach ($rowData as $cellData) {
|
||||
$dataRow->addCell()->addText($cellData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Membuat tabel kedua
|
||||
$section->addTextBreak(1);
|
||||
|
||||
|
||||
// // $section->addText("");
|
||||
// $table2 = $section->addTable(array('borderSize' => 12, 'fontSize' =>10, 'borderColor' => 'green', 'width' => 11200, 'unit' => TblWidth::TWIP));
|
||||
// $headerRow2 = $table2->addRow();
|
||||
// $headerRow2->addCell(2000, ['bgColor' => 'CCCCCC'])->addText('Rekening');
|
||||
// $headerRow2->addCell(2000, ['bgColor' => 'CCCCCC'])->addText('Cabang');
|
||||
// $headerRow2->addCell(2000, ['bgColor' => 'CCCCCC'])->addText('Jenis Rekening');
|
||||
// $headerRow2->addCell(1000, ['bgColor' => 'CCCCCC'])->addText('Mata Uang');
|
||||
// $headerRow2->addCell(2000, ['bgColor' => 'CCCCCC'])->addText('Saldo');
|
||||
// $headerRow2->addCell(1000, ['bgColor' => 'CCCCCC'])->addText('Jangka Waktu');
|
||||
// $headerRow2->addCell(1000, ['bgColor' => 'CCCCCC'])->addText('Suku Bunga');
|
||||
|
||||
// foreach ($DataPinjaman as $key2 => $rowData2) {
|
||||
// $dataRow2 = $table2->addRow();
|
||||
// foreach ($rowData2 as $cellData2) {
|
||||
// $dataRow2->addCell()->addText($cellData2);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Set border properties for the entire table
|
||||
$table->getStyle()->setBorderSize(1); // Set border size in pt
|
||||
$table->getStyle()->setBorderColor('000000'); // Set border color (black)
|
||||
|
||||
// Alternatively, you can set border properties for individual cells
|
||||
foreach ($table->getRows() as $row) {
|
||||
foreach ($row->getCells() as $cell) {
|
||||
$cell->getStyle()->setBorderSize(1);
|
||||
$cell->getStyle()->setBorderColor('000000');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Create writer to convert document to xml
|
||||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($document_with_table, 'Word2007');
|
||||
|
||||
// Get all document xml code
|
||||
$fullxml = $objWriter->getWriterPart('Document')->write();
|
||||
|
||||
// Get only table xml code
|
||||
$tablexml = preg_replace('/^[\s\S]*(<w:tbl\b.*<\/w:tbl>).*/', '$1', $fullxml);
|
||||
|
||||
//Open template with ${table}
|
||||
$template_document = new \PhpOffice\PhpWord\TemplateProcessor('konfirmasibank_template.docx');
|
||||
|
||||
// Replace mark by xml code of table
|
||||
$template_document->setValues([
|
||||
'table1'=> $tablexml,
|
||||
'street'=> $GetCustomer->ADDRESS,
|
||||
'address'=> $GetCustomer->STREET,
|
||||
'customerName'=> $GetCustomer->SHORT_NAME,
|
||||
'customerNo'=> $GetCustomer->CUSTOMER_NO,
|
||||
'director'=> $signer->deputy_director_name,
|
||||
'executiveOfficer'=> $signer->executive_officer_name,
|
||||
'date' => $tanggalIndonesia
|
||||
]);
|
||||
|
||||
$template_document->saveAs("Konfirmasibank_".$currentDate->format('YmdHis').".docx");
|
||||
|
||||
return json_encode(['status' => 'success', 'message' => ' Download Surat successfully .']);
|
||||
$tglSurat = $currentDate->format('Y-m-d');
|
||||
$letter = new Letters();
|
||||
$letter->no_cif = $cif;
|
||||
$letter->no_surat = $noSurat;
|
||||
$letter->tgl_surat = $tglSurat;
|
||||
$letter->no_req_surat = $noReqSurat;
|
||||
$letter->tgl_req_surat = $tglReqSurat ;
|
||||
$letter->email = $email ;
|
||||
$letter->tlp = $tlp ;
|
||||
$letter->nama_tujuan = $tujuan ;
|
||||
$letter->alamat = $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')) {
|
||||
|
Reference in New Issue
Block a user