diff --git a/application/controllers/Teknisi.php b/application/controllers/Teknisi.php index 221b5df..32cc8b8 100644 --- a/application/controllers/Teknisi.php +++ b/application/controllers/Teknisi.php @@ -142,6 +142,9 @@ class Teknisi extends CI_Controller { $aksi = ' + '; $result[] = [ @@ -221,6 +224,97 @@ class Teknisi extends CI_Controller { ]); } + public function get_form_barang_bawaan_data() + { + $user_id = (int)$this->input->get('user_id'); + + if (!$user_id) { + echo json_encode(['status' => false, 'message' => 'ID teknisi tidak valid']); + return; + } + + $info = $this->ptm->get_teknisi_info($user_id); + if (!$info) { + echo json_encode(['status' => false, 'message' => 'Teknisi tidak ditemukan']); + return; + } + + $items = $this->ptm->get_teknisi_items_full($user_id); + $noFaktur = 'GRJN/K/' . date('d/m/Y'); + $tanggal = date('d F Y'); + + $itemsData = []; + $no = 1; + foreach ($items as $item) { + $itemsData[] = [ + 'no' => $no++, + 'barcode' => $item->barcode ?? '-', + 'nama_barang' => $item->nama_barang ?? '-', + 'serial_number' => $item->serial_number ?? '-', + 'jumlah' => isset($item->qty_sisa) ? (int)$item->qty_sisa : 1, + 'keterangan' => '' + ]; + } + + echo json_encode([ + 'status' => true, + 'data' => [ + 'no_faktur' => $noFaktur, + 'tanggal' => $tanggal, + 'teknisi' => $info->full_name, + 'teknisi_id' => $info->id, + 'employee_code' => $info->employee_code, + 'position_name' => $info->position_name, + 'department_name' => $info->department_name, + 'total_item' => count($itemsData), + 'items' => $itemsData + ] + ]); + } + + public function generate_pdf_barang_bawaan($user_id = null) + { + if ($this->session->userdata('role') != 'Admin') { + show_error('Akses ditolak', 403); + } + + $user_id = (int)$user_id; + if (!$user_id) { + show_error('ID teknisi tidak valid', 400); + } + + if (ob_get_length()) { + ob_end_clean(); + } + + $info = $this->ptm->get_teknisi_info($user_id); + if (!$info) { + show_error('Teknisi tidak ditemukan', 404); + } + + $items = $this->ptm->get_teknisi_items_full($user_id); + $noFaktur = 'GRJN/K/' . date('d/m/Y'); + $tanggal = date('d F Y'); + + require_once(APPPATH . 'third_party/fpdf/fpdf.php'); + require_once(APPPATH . 'libraries/PDF_BarangBawaan.php'); + + $pdf = new PDF_BarangBawaan('L', 'mm', 'A5'); + $pdf->AliasNbPages(); + $pdf->SetMargins(5, 5, 5); + $pdf->SetAutoPageBreak(true, 10); + + $pdf->setFormInfo($noFaktur, $tanggal, $info->full_name); + + $pdf->AddPage('L', 'A5'); + $pdf->BarangBawaanTable($items); + $pdf->SignatureArea(); + + $namaFile = 'FORM_BARANG_BAWAAN_' . str_replace(' ', '_', $info->full_name) . '_' . date('Ymd') . '.pdf'; + $pdf->Output('I', $namaFile); + exit; + } + public function get_transfer_data() { $data = $this->ptm->get_transfer_data(); diff --git a/application/libraries/PDF_BarangBawaan.php b/application/libraries/PDF_BarangBawaan.php new file mode 100644 index 0000000..3296e0a --- /dev/null +++ b/application/libraries/PDF_BarangBawaan.php @@ -0,0 +1,206 @@ +SetDisplayMode('fullpage'); + } + + function SetMargins($left, $top, $right = null) + { + parent::SetMargins(10, $top, 10); + } + + public function setFormInfo($noFaktur, $tanggal, $teknisi) + { + $this->noFaktur = $noFaktur; + $this->tanggal = $tanggal; + $this->teknisi = $teknisi; + } + + function Header() + { + $this->SetFont('Arial', 'B', 11); + $this->SetTextColor(245, 140, 0); + $this->Cell(0, 6, 'FORM BARANG BAWAAN TEKNISI', 0, 1, 'L'); + $this->SetTextColor(0, 0, 0); + $this->Ln(2); + + $this->SetFont('Arial', '', 8); + $this->Cell(0, 5, 'Tanggal : ' . $this->tanggal . ' Teknisi : ' . $this->teknisi . ' No. Faktur : ' . $this->noFaktur, 0, 1, 'C'); + $this->Ln(2); + $this->_drawTableHeader(); + } + + function Footer() + { + $this->SetY(-8); + $this->SetFont('Arial', 'I', 7); + $this->Cell(0, 4, 'Hal ' . $this->PageNo(), 0, 0, 'C'); + } + + private function _drawTableHeader() + { + $startX = $this->lMargin; + $this->SetX($startX); + $this->SetFillColor(245, 140, 0); + $this->SetTextColor(255, 255, 255); + $this->SetFont('Arial', 'B', 7); + + $headers = ['No', 'Barcode', 'Nama Barang', 'Serial Number', 'Jumlah', 'Keterangan']; + foreach ($headers as $i => $h) { + $this->Cell($this->colWidths[$i], 7, $h, 1, 0, 'C', true); + } + $this->Ln(); + + $this->SetTextColor(0, 0, 0); + } + + public function BarangBawaanTable($items) + { + $this->SetFont('Arial', '', 7); + $lineH = 5.5; + $minRowH = 8; + $no = 1; + + $colsMultiCell = [false, false, true, true, false, true]; + $cellAligns = ['C', 'C', 'L', 'L', 'C', 'L']; + + foreach ($items as $item) { + $keterangan = isset($item->keterangan) ? $item->keterangan : ''; + $namaBarang = $item->nama_barang ?? '-'; + $serial = $item->serial_number ?? '-'; + $barcode = $item->barcode ?? '-'; + $jumlah = isset($item->qty_sisa) ? (int)$item->qty_sisa : 1; + + $cellValues = [ + (string)$no, + $barcode, + $namaBarang, + $serial, + (string)$jumlah, + $keterangan + ]; + + $maxLines = 1; + foreach ($cellValues as $i => $val) { + if ($colsMultiCell[$i]) { + $lines = $this->NbLines($this->colWidths[$i], $val); + if ($lines > $maxLines) { + $maxLines = $lines; + } + } + } + + $rowH = max($minRowH, $maxLines * $lineH); + + if ($this->GetY() + $rowH > $this->PageBreakTrigger) { + $this->AddPage(); + } + + $startX = $this->lMargin; + $startY = $this->GetY(); + + $currentX = $startX; + foreach ($this->colWidths as $i => $w) { + $this->Rect($currentX, $startY, $w, $rowH); + $currentX += $w; + } + + $currentX = $startX; + foreach ($cellValues as $i => $val) { + $this->SetXY($currentX, $startY); + if ($colsMultiCell[$i]) { + $contentH = $maxLines * $lineH; + $offsetY = ($rowH - $contentH) / 2; + $this->SetXY($currentX, $startY + $offsetY); + $this->MultiCell($this->colWidths[$i], $lineH, $val, 0, $cellAligns[$i]); + } else { + $this->Cell($this->colWidths[$i], $rowH, $val, 0, 0, $cellAligns[$i]); + } + $currentX += $this->colWidths[$i]; + } + + $this->SetXY($startX, $startY + $rowH); + $no++; + } + } + + public function SignatureArea() + { + $this->Ln(6); + + $sigW = 56; + $gapW = 11; + $blockW = 3 * $sigW + 2 * $gapW; + $startX = $this->lMargin + ($this->w - $this->lMargin - $this->rMargin - $blockW) / 2; + + $signatures = [ + ['title' => 'Admin Gudang', 'name' => 'Gono Soewisto'], + ['title' => 'Leader Teknisi', 'name' => 'Chandra Nursani'], + ['title' => 'Mengetahui', 'name' => 'Tito Ngudiana'], + ]; + + $sigY = $this->GetY(); + + foreach ($signatures as $i => $sig) { + $x = $startX + $i * ($sigW + $gapW); + + $this->SetXY($x, $sigY); + $this->SetFont('Arial', '', 8); + $this->Cell($sigW, 5, $sig['title'], 0, 1, 'C'); + + $this->SetX($x); + $this->Ln(10); + + $this->SetX($x); + $this->SetFont('Arial', 'U', 8); + $this->Cell($sigW, 5, ' ', 0, 1, 'C'); + + $this->SetX($x); + $this->SetFont('Arial', 'I', 7); + $this->Cell($sigW, 4, $sig['name'], 0, 1, 'C'); + } + + $this->SetY($sigY + 5 + 10 + 5 + 4); + } + + private function NbLines($w, $txt) + { + $cw = &$this->CurrentFont['cw']; + if ($w == 0) { + $w = $this->w - $this->rMargin - $this->x; + } + $wmax = ($w - 2 * $this->cMargin) * 1000 / $this->FontSize; + $s = str_replace("\r", '', $txt); + $nb = strlen($s); + if ($nb > 0 && $s[$nb - 1] == "\n") { $nb--; } + $sep = -1; + $i = 0; + $j = 0; + $l = 0; + $nl = 1; + while ($i < $nb) { + $c = $s[$i]; + if ($c == "\n") { $i++; $sep = -1; $j = $i; $l = 0; $nl++; continue; } + if ($c == ' ') { $sep = $i; } + $l += isset($cw[ord($c)]) ? $cw[ord($c)] : 600; + if ($l > $wmax) { + if ($sep == -1) { if ($i == $j) $i++; } + else { $i = $sep + 1; } + $sep = -1; $j = $i; $l = 0; $nl++; + } else { $i++; } + } + return $nl; + } +} \ No newline at end of file diff --git a/application/models/PeralatanTeknisi_model.php b/application/models/PeralatanTeknisi_model.php index 8db874d..1473e93 100644 --- a/application/models/PeralatanTeknisi_model.php +++ b/application/models/PeralatanTeknisi_model.php @@ -483,4 +483,29 @@ class PeralatanTeknisi_model extends CI_Model { ->get() ->row(); } + + public function get_teknisi_items_full($user_id) + { + return $this->db + ->select(" + it.barcode, + i.nama_barang, + ib.serial_number, + ib.qty_sisa, + it.status + ") + ->from('item_technician it') + ->join('items i', 'i.id = it.item_id', 'left') + ->join('item_barcodes ib', 'ib.barcode = it.barcode', 'left') + ->where('it.user_id', $user_id) + ->where('it.status', 'active') + ->order_by('it.created_at', 'ASC') + ->get() + ->result(); + } + + public function generate_no_faktur() + { + return 'GRJN/K/' . date('d/m/Y'); + } } diff --git a/application/views/items/draft_items.php b/application/views/items/draft_items.php index 4a27f10..c01586c 100644 --- a/application/views/items/draft_items.php +++ b/application/views/items/draft_items.php @@ -811,10 +811,10 @@ function rupiahToNumber(value){ if(!value) return 0; - return parseInt( - value.toString() - .replace(/[^\d]/g,'') - ) || 0; + let s = value.toString().trim(); + s = s.replace(/\.(?=\d{3}(\.|$))/g, ''); + s = s.replace(/,/g, ''); + return parseFloat(s) || 0; } diff --git a/application/views/peralatan_teknisi/layout.php b/application/views/peralatan_teknisi/layout.php index 0326945..ae67352 100644 --- a/application/views/peralatan_teknisi/layout.php +++ b/application/views/peralatan_teknisi/layout.php @@ -416,7 +416,7 @@ body { Kode Karyawan Departemen Jumlah Item - Aksi + Aksi @@ -494,7 +494,67 @@ body { + + + +