/** * Menyimpan setiap input form ke rownya masing-masing. */ public static function update_konfigurasi($input) { // update setiap value konfigurasi Konfigurasi::update(1, array('config_value' => $input['nama_kpp'])); Konfigurasi::update(2, array('config_value' => $input['nama_seksi'])); Konfigurasi::update(3, array('config_value' => $input['kode_surat'])); Konfigurasi::update(5, array('config_value' => $input['jumlah_baris_surat_masuk'])); Konfigurasi::update(6, array('config_value' => $input['jumlah_baris_surat_keluar'])); Konfigurasi::update(7, array('config_value' => $input['jumlah_baris_pencarian_surat'])); Konfigurasi::update(8, array('config_value' => $input['tampilkan_nomor_agenda'])); // rules untuk konfigurasi tahun agar tidak mengacaukan pengurutan nomor $max_tahun_used = Suratkeluar::max('tahun'); $msg_warning = NULL; if ($input['tahun_surat'] < $max_tahun_used) { // perubahan tahun tidak disimpan, return pesan warning $msg_warning = 'Perubahan tahun tidak dapat disimpan. ' . 'Untuk menggunakan kembali tahun: ' . $input['tahun_surat'] . ', silakan undo/batalkan semua Surat Keluar (<em>sangat tidak disarankan</em>) ' . 'yang telah menggunakan tahun: ' . $max_tahun_used . '.'; } else { Konfigurasi::update(4, array('config_value' => $input['tahun_surat'])); } // membuat message success dan warning ke dalam array $add_notes = isset($msg_warning) ? ' Lihat pesan warning!' : ''; $msg_success = 'Konfigurasi berhasil diupdate.' . $add_notes; $msg = array(); $msg['success'] = $msg_success; $msg['warning'] = $msg_warning; return $msg; }
/** * Rekam file CSV yang terupload. */ public static function upload_create($file, $input) { $csv_rows = array(); // detect delimiter antara ',' atau ';' $allowed_header = array('tujuan'); $csv_uploded = file($file, FILE_IGNORE_NEW_LINES); $csv_header = str_getcsv($csv_uploded[0], ','); $csv_header2 = str_getcsv($csv_uploded[0], ';'); if ($csv_header == $allowed_header) { $csv_delimiter = ','; } else { if ($csv_header2 == $allowed_header) { $csv_delimiter = ';'; } else { echo 'wrong delimiter'; // FIXME throw error exit; } } // push data csv ke array if (isset($csv_delimiter)) { foreach ($csv_uploded as $line) { $csv_rows[] = str_getcsv($line, $csv_delimiter); } // remove header dari file csv unset($csv_rows[0]); $i = $input; $cfg_kode_surat = Konfigurasi::find(3)->config_value; $cfg_tahun_surat = Konfigurasi::find(4)->config_value; $jenis = Jenissurat::find($i['jenis']); $pengirim = Disposisi::find($i['pengirim']); $tanggal = $i['tanggal']; $hal = $i['hal']; // remove header dari file csv unset($csv_rows[0]); $jumlah = 0; foreach ($csv_rows as $tujuan) { $tujuan = trim($tujuan[0]); if (!empty($tujuan)) { // Menentukan urutan selanjutnya untuk jenis surat X, dengan cara // "mengambil nomor urut jenis surat X terakhir" untuk nanti diincrement saat direkam ke database // -Fluent query- // Rulesnya: apabila tahun surat terakhir masih sama dengan tahun konfigurasi // surat, maka nomor urut dilanjutkan. // Apabila berbeda tahun, maka direset menjadi 1. $last_number = DB::table('surat_keluar')->where('jenis_surat', '=', $jenis->jenis_surat)->order_by('id', 'desc')->only('nomor_urut'); $last_surat_tahun = DB::table('surat_keluar')->where('jenis_surat', '=', $jenis->jenis_surat)->order_by('id', 'desc')->only('tahun'); if ($last_surat_tahun == $cfg_tahun_surat) { $now_number = $last_number + 1; } else { $now_number = 1; } // -Eloquent query- Suratkeluar::create(array('jenis_surat' => $jenis->jenis_surat, 'nomor_urut' => $now_number, 'kode_surat' => $cfg_kode_surat, 'tahun' => $cfg_tahun_surat, 'tgl_surat' => $tanggal, 'pengirim' => $pengirim->nama, 'tujuan' => $tujuan, 'hal' => $hal, 'perekam' => Auth::user()->username, 'diupdate' => Auth::user()->username)); $jumlah++; } } $message = 'Surat Keluar Seksi sebanyak ' . $jumlah . ' surat berhasil direkam.'; $a['message'] = $message; return $a['message']; } }
public function put_konfigurasi_update() { $input = Input::all(); $validation = Konfigurasi::validate($input); if ($validation->fails()) { return Redirect::to_route('settings_konfigurasi')->with_errors($validation); } else { $update = Konfigurasi::update_konfigurasi($input); return Redirect::to_route('settings_konfigurasi')->with('message', $update['success'])->with('warning', $update['warning']); } }
<div class="row morevspace"> <hr> <table class='displaytable'> <thead> <tr> <th class="span4">Nomor Surat</th> <th class="span1">Tanggal</th> <th class="span3">Tujuan</th> <th>Hal</th> <th>Pengirim</th> </tr> </thead> <tbody> <?php $nomor_surat = Jenissurat::find($input['jenis'])->jenis_surat . 'XXX' . Konfigurasi::find(3)->config_value . Konfigurasi::find(4)->config_value; ?> @foreach($csv_rows as $suratkeluar) <tr> <td>{{ $nomor_surat }}</td> <td>{{ $input['tanggal'] }}</td> <td>{{ e($suratkeluar[0]) }}</td> <td>{{ $input['hal'] }}</td> <td>{{ Disposisi::find($input['pengirim'])->nama }}</td> </tr> @endforeach @if (empty($csv_rows)) <tr> <td colspan="5"><em>Warning: file kosong....</em><td> </tr>
/** * Generate nomor agenda seksi, dalam hal terjadi pergantian tahun * maka nomor agenda direset ke 1. */ public static function generate_nomor_agenda_seksi() { $cfg_tahun_surat = Konfigurasi::find(4)->config_value; $last_surat_tahun = DB::table('surat_keluar')->order_by('id', 'desc')->only('tahun'); $last_number = Suratmasuk::order_by('id', 'desc')->where('tahun_buku', '=', Konfigurasi::find(4)->config_value)->only('nomor_agenda_seksi'); if (empty($last_number)) { $now_number = 1; } else { $now_number = $last_number + 1; } return $now_number; }
/** * Membuat query untuk fungsi print. */ public static function print_surat($input) { // sanitize page dan limit jika diinput secara manual $limit = is_numeric((int) $input['limit']) && $input['limit'] > 0 ? (int) $input['limit'] : Konfigurasi::find(7)->config_value; $page = is_numeric((int) $input['page']) && $input['page'] > 0 ? (int) $input['page'] : 1; // query pertama hanya mendapatkan id-nya saja, // ---query BELUM diexecute--- $qry = Suratkeluarlain::order_by('id', 'desc')->where('pengirim', 'LIKE', Suratkeluarlain::clean_id_pengirim($input['pengirim']))->where('nomor_surat', 'LIKE', '%' . $input['nomor_surat'] . '%')->where('tgl_surat', 'LIKE', '%' . $input['tanggal'] . '%')->where('tujuan', 'LIKE', '%' . $input['tujuan'] . '%')->where('hal', 'LIKE', '%' . $input['hal'] . '%'); // Cek apakah user mencoba mengakses page secara manual, lebih dari max page // // mengexecute query $qry di atas untuk mendapatkan total records yg didapat $total_records = $qry->count(); // rounding up untuk max page, misal total = 15, limit = 7, // maka max page = 2.14 -> round up menjadi 3 $max_page = ceil($total_records / $limit); // jika page diinput manual dan melebihi maxpage, maka diset ke max page $page = $page > $max_page ? $max_page : $page; // karena menggunakan pagination, maka rows yg diambil harus sesuai pagenya $skipped = ($page - 1) * $limit; // mengexecute query $qry di atas untuk mendapatkan recordsnya $rows = $qry->skip($skipped)->take($limit)->get(); // menyusun id dari query pertama ke dalam array // karena akan disort ulang, records yg didapat hanya diambil id-nya saja $id_array = array(); foreach ($rows as $r) { $id_array = array_merge($id_array, array($r->id)); } // query kedua mengambil row surat dgn order_by tanggal_rekam lalu pengirim $sk = Suratkeluarlain::where_in('id', $id_array)->order_by('created_at')->order_by('pengirim')->get(); return $sk; }
/** * Generate lembar disposisi menggunakan FPDF. */ public static function generate_lembar_disposisi($input) { $pdf = new Fpdf(); /** * TODO: * Ubah posisi y dari perhitungan manual menjadi menggunakan GetY SetY */ $pdf->SetLineWidth(0.01); // 0.01mm // specify margin variables, dalam unit milimeter $margin_left = 5; $margin_top = 10; $margin_right = 10; $pdf->SetMargins($margin_left, $margin_top, $margin_right); $pdf->AddPage(); $pdf->Image(URL::to_asset('img/logo.png'), $margin_left, $margin_top, 0, 25); // specify height variables $h1 = 6; $h2 = 1.5 * $h1; $h3 = 2 * $h1; /** * Bagian Header */ $span1 = 30; $span2 = 40; $span3 = 50; $span4 = 60; /* line 1 */ $pdf->SetFont('Times', 'B', 16); $pdf->Cell($span1, $h1, ''); $pdf->Cell(160, $h1, 'Direktorat Jenderal Pajak', 0, 0, 'C'); $pdf->Ln(); /* line 2 */ $pdf->SetFont('Times', 'B', 12); $pdf->Cell($span1, $h1, ''); $pdf->Cell(160, $h1, strtoupper($input->nama_kpp), 0, 0, 'C'); $pdf->Ln(); /* line 3 */ $pdf->Cell($span1, $h1, ''); $pdf->Cell(160, $h1, $input->nama_seksi, 0, 0, 'C'); $line_x1 = $margin_left + $span1; $line_y1 = $margin_top + 3 * $h1; $line_x2 = 210 - $margin_right; $line_y2 = $line_y1; $pdf->Line($line_x1, $line_y1, $line_x2, $line_y2); $pdf->Ln(); /* line 4 */ $pdf->SetFont('Times', '', 14); $pdf->Cell($span1, $h3, ''); $pdf->Cell(160, $h3, 'LEMBAR DISPOSISI', 0, 0, 'C'); $line_x1 = $margin_left + $span1 + 10; $line_y1 = $margin_top + 3 * $h1 + $h2; $line_x2 = 210 - $margin_right - 10; $line_y2 = $line_y1; $pdf->Line($line_x1, $line_y1, $line_x2, $line_y2); $pdf->Ln(); /* line 5, blank line */ $pdf->Cell(210 - $margin_left - $margin_right, $h3, ''); $pdf->Ln(); /** * variable font size */ $font_size = 10; /* line 6 */ // output label left $pdf->SetFont('Times', '', $font_size); $pdf->Cell($span1, $h2, 'Tanggal Diterima:'); $pdf->SetFont('Arial', '', $font_size); $pdf->Cell($span4 + 10, $h2, Printpdf::full_tanggal($input->tgl_diterima)); // divider $pdf->Cell(10, $h2, ''); //output label right $pdf->SetFont('Times', '', $font_size); $pdf->Cell($span1, $h2, 'Nomor Agenda:'); $pdf->SetFont('Arial', '', $font_size); // cek apakah nomor Agenda otomatis akan ikut dicetak? $tampilkan_nomor_agenda = Konfigurasi::find(8)->config_value; if ($tampilkan_nomor_agenda == 1) { $pdf->Cell($span4 + 5 - $margin_right, $h2, $input->nomor_agenda_seksi); } else { $pdf->Cell($span4 + 5 - $margin_right, $h2, ''); } // border-bottom dibuat secara manual agar posisinya bisa diatur dan tidak // dipengaruhi cell height // underline content left $line_x1 = $margin_left + $span1; $line_y1 = $margin_top + 4 * $h1 + 2 * $h3 + 1; $line_x2 = $line_x1 + $span4 + 10; $line_y2 = $line_y1; $pdf->Line($line_x1, $line_y1, $line_x2, $line_y2); // underline content right $line_x1 = 210 - $margin_right - ($span4 + 5 - $margin_right); $line_y1 = $line_y1; $line_x2 = 210 - $margin_right; $line_y2 = $line_y1; $pdf->Line($line_x1, $line_y1, $line_x2, $line_y2); $pdf->Ln(); /* line 7 */ // output label left $pdf->SetFont('Times', '', $font_size); $pdf->Cell($span1, $h2, 'Nomor Surat:'); $pdf->SetFont('Arial', '', $font_size); $pdf->Cell($span4 + 10, $h2, $input->nomor_surat); // divider $pdf->Cell(10, $h2, ''); //output label right $pdf->SetFont('Times', '', $font_size); $pdf->Cell($span1, $h2, 'No. Agenda Sekre:'); $pdf->SetFont('Arial', '', $font_size); $pdf->Cell($span4 + 5 - $margin_right, $h2, $input->nomor_agenda_sekre); // underline content left $line_x1 = $margin_left + $span1; $line_y1 = $line_y1 + $h2; $line_x2 = $line_x1 + $span4 + 10; $line_y2 = $line_y1; $pdf->Line($line_x1, $line_y1, $line_x2, $line_y2); // underline content right $line_x1 = 210 - $margin_right - ($span4 + 5 - $margin_right); $line_y1 = $line_y1; $line_x2 = 210 - $margin_right; $line_y2 = $line_y1; $pdf->Line($line_x1, $line_y1, $line_x2, $line_y2); $pdf->Ln(); /* line 8 */ // output label left $pdf->SetFont('Times', '', $font_size); $pdf->Cell($span1, $h2, 'Tanggal Surat:'); $pdf->SetFont('Arial', '', $font_size); $pdf->Cell($span4 + 10, $h2, Printpdf::full_tanggal($input->tgl_surat)); // underline content left $line_x1 = $margin_left + $span1; $line_y1 = $line_y1 + $h2; $line_x2 = $line_x1 + $span4 + 10; $line_y2 = $line_y1; $pdf->Line($line_x1, $line_y1, $line_x2, $line_y2); $pdf->Ln(); /* line 9 */ // output label left $pdf->SetFont('Times', '', $font_size); $pdf->Cell($span1, $h2, 'Nama Pengirim:'); $pdf->SetFont('Arial', '', $font_size); $pdf->Cell(210 - $margin_right - $margin_left - $span1, $h2, strtoupper($input->pengirim)); // underline content left $line_x1 = $margin_left + $span1; $line_y1 = $line_y1 + $h2; $line_x2 = 210 - $margin_right; $line_y2 = $line_y1; $pdf->Line($line_x1, $line_y1, $line_x2, $line_y2); $pdf->Ln(); /* line 10 */ // output label left $pdf->SetFont('Times', '', $font_size); $pdf->Cell($span1, $h2, 'Perihal:'); $pdf->SetFont('Arial', '', $font_size); $pdf->drawTextBox(strtoupper($input->hal), 210 - $margin_right - $margin_left - $span1, $h3 + $h1 / 2, 'L', 'T', 0, $h1 / 2); // underline content left $line_x1 = $margin_left + $span1; $line_y1 = $line_y1 + $h3 + $h1 / 2 + 1; $line_x2 = 210 - $margin_right; $line_y2 = $line_y1; $pdf->Line($line_x1, $line_y1, $line_x2, $line_y2); $pdf->Ln(); /* line 11 */ $pdf->SetFont('Times', '', $font_size); $y = $line_y1 + $h3; $pdf->SetY($y); $pdf->SetStyle("em", "Times", "I", 0, "0,0,0"); $pdf->SetStyle("p", "Times", "N", $font_size, "0,0,0", 0); $pdf->SetStyle("content", "Arial", "", 0, "0,0,0"); $pdf->SetStyle("strong", "Times", "B", 0, "0,0,0"); $pdf->WriteTag(210 - $margin_left - $margin_right, $h1, '<p>PERHATIAN: <em>Dilarang memisahkan sehelai surat pun dari berkas yang telah disusun.</em></p>', 0, 'C'); /** * line 12 * print daftar disposisi, daftar sifat, daftar petunjuk */ // set to correct y position $pdf->SetY($y + $h1); // create 3 column $spacer = 1; $box_width = (210 - $margin_left - $margin_right - 2) / 2; // box_width akan dipakai untuk dua kolom $checkbox_width = 8; $box_text_width = $box_width - $checkbox_width; // save y position $save_y_position = $pdf->GetY(); // print right box first $pdf->Cell($box_width + $spacer, $h1, ''); // padding-left hack :) $pdf->SetFont('Times', 'B', $font_size); $pdf->Cell($box_width, $h1, 'Ditujukan kepada:', 'LTR'); $pdf->Ln(); /* iterasi */ foreach ($input->daftar_disposisi as $row) { if ($row->aktif) { // padding-left hack :) $pdf->Cell($box_width + $spacer, $h1, ''); // draw checkbox Printpdf::draw_checkbox($pdf, in_array($row->id, $input->disposisi), $font_size, $h1, $checkbox_width); // print daftar nama $pdf->SetFont('Times', '', $font_size); $pdf->Cell($box_text_width, $h1, $row->nama, 'R'); $pdf->Ln(); } } // print daftar disposisi lain-lain if (!empty($input->lain_lain)) { // padding-left $pdf->Cell($box_width + $spacer, $h1, ''); // draw checkbox Printpdf::draw_checkbox($pdf, true, $font_size, $h1, $checkbox_width); // print lain-lain $pdf->SetFont('Times', '', $font_size); $pdf->Cell($box_text_width, $h1, $input->lain_lain, 'R'); $pdf->Ln(); } // bottom space and border $pdf->Cell($box_width + $spacer, $h1, ''); $pdf->Cell($box_width, $h1 / 2, '', 'RLB'); $pdf->Ln(); // save y position untuk reset posisi box catatan $catatan_box_y_position_1 = $pdf->GetY(); // reset y position, print left box $pdf->SetY($save_y_position); $pdf->SetFont('Times', 'B', $font_size); $pdf->Cell($box_width, $h1, 'Sifat:', 'LTR'); $pdf->Ln(); /* iterasi */ $pdf->SetFont('Times', '', $font_size); foreach ($input->daftar_sifat as $key => $value) { // draw checkbox Printpdf::draw_checkbox($pdf, in_array($key, $input->sifat), $font_size, $h1, $checkbox_width); // print daftar sifat $pdf->SetFont('Times', '', $font_size); $pdf->Cell($box_text_width, $h1, $value, 'R'); $pdf->Cell($spacer, $h1, '', ''); $pdf->Ln(); } // continue print left box $pdf->SetFont('Times', 'B', $font_size); $pdf->Cell($box_width, $h1, 'Petunjuk:', 'LR'); $pdf->Ln(); /* iterasi */ $pdf->SetFont('Times', '', $font_size); foreach ($input->daftar_petunjuk as $row) { // draw checkbox Printpdf::draw_checkbox($pdf, in_array($row->id, $input->petunjuk), $font_size, $h1, $checkbox_width); // print daftar petunjuk $pdf->SetFont('Times', '', $font_size); $pdf->Cell($box_text_width, $h1, $row->petunjuk, 'R'); $pdf->Cell($spacer, $h1, '', ''); $pdf->Ln(); } // copy $dots = '........'; if ($input->copy > 0) { $copy = ' ' . $input->copy . ' '; Printpdf::draw_checkbox($pdf, true, $font_size, $h1, $checkbox_width); } else { $copy = $dots; Printpdf::draw_checkbox($pdf, false, $font_size, $h1, $checkbox_width); } $pdf->SetFont('Times', '', $font_size); $pdf->Cell($box_text_width, $h1, 'Perbanyak: ' . $copy . ' kali, Asli ke: ' . $dots, 'R'); $pdf->Ln(); // bottom border $pdf->Cell($box_width, $h1 / 2, '', 'RLB'); $pdf->Ln(); // save y position untuk reset posisi box catatan $catatan_box_y_position_2 = $pdf->GetY(); /* line 13 */ // adjust y position $y = $catatan_box_y_position_1 > $catatan_box_y_position_2 ? $catatan_box_y_position_1 : $catatan_box_y_position_2; $pdf->SetY($y + 1); // print box catatan $pdf->SetFont('Times', 'U', $font_size); $pdf->Cell(0, $h1, 'CATATAN:', 'LTR'); $pdf->Ln(); // save y position $y = $pdf->GetY(); // print text catatan $pdf->SetFont('Arial', '', $font_size - 1); $pdf->drawTextBox(strtoupper($input->catatan), 210 - $margin_right - $margin_left, 'L', 'T', 1, $h1 / 2); // reset position, draw fake border $pdf->SetY($y); $pdf->Cell(0, $h3, '', 'LBR'); $pdf->Ln(); /* line 14 */ // adjust y position $y = $pdf->GetY(); $pdf->SetY($y + 2); // print field tambahan $pdf->SetFont('Times', '', $font_size); $pdf->Cell(0, 5, 'PENGELOLAAN PADA SEKSI TERKAIT:'); $pdf->Ln(); /* line 15 */ // dua kolom hal yang sama $half_width = (210 - $margin_left - $margin_right) / 2; $hw = $half_width; $padding_right = 20; $pdf->SetFont('Times', 'B', $font_size); $pdf->Cell($half_width, 7, 'Diteruskan ke:'); $pdf->Cell($half_width, 7, 'Diteruskan ke:'); $pdf->Ln(); $s1 = '1. Seksi: '; $s2 = '2. Diterima Seksi: '; $s3 = '3. Selesai diproses: '; $dot1 = str_repeat('.', 71); $dot2 = str_repeat('.', 56); $dot3 = str_repeat('.', 54); $w1 = $pdf->GetStringWidth($s1); $w2 = $pdf->GetStringWidth($s2); $w3 = $pdf->GetStringWidth($s3); $pdf->SetFont('Times', '', $font_size); // print text dengan dotted yang right-aligned $pdf->Cell($hw - ($hw - $w1) - $padding_right, 4, $s1); $pdf->Cell($hw - $w1, 4, $dot1, 0, '', 'R'); $pdf->Cell($padding_right, 4, ''); $pdf->Cell($hw - ($hw - $w1) - $padding_right, 4, $s1); $pdf->Cell($hw - $w1, 4, $dot1, 0, '', 'R'); $pdf->Cell($padding_right, 4, ''); $pdf->Ln(); $pdf->Cell($hw - ($hw - $w2) - $padding_right, 4, $s2); $pdf->Cell($hw - $w2, 4, $dot2, 0, '', 'R'); $pdf->Cell($padding_right, 4, ''); $pdf->Cell($hw - ($hw - $w2) - $padding_right, 4, $s2); $pdf->Cell($hw - $w2, 4, $dot2, 0, '', 'R'); $pdf->Cell($padding_right, 4, ''); $pdf->Ln(); $pdf->Cell($hw - ($hw - $w3) - $padding_right, 4, $s3); $pdf->Cell($hw - $w3, 4, $dot3, 0, '', 'R'); $pdf->Cell($padding_right, 4, ''); $pdf->Cell($hw - ($hw - $w3) - $padding_right, 4, $s3); $pdf->Cell($hw - $w3, 4, $dot3, 0, '', 'R'); $pdf->Cell($padding_right, 4, ''); $pdf->Ln(); // generate pdf ke folder 'public' subfolder 'pdf' $file_name = 'print' . time() . '.pdf'; $output_path = Printpdf::pdf_folder_path() . $file_name; $pdf->Output($output_path, 'F'); return $file_name; }