chronous

Traits laporan

Sep 24th, 2025
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.04 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Traits;
  4.  
  5. use App\Libraries\Log;
  6. use App\Modules\Defaults\Auth\Model\MainModel;
  7. use Core\Facades\Session;
  8.  
  9. trait HeaderLaporanDynamic
  10. {
  11.     private $systemPdamData = null;
  12.     private $orientationPage = null;
  13.  
  14.     /**
  15.      * Initialize system PDAM data from the database based on session pdam_id.
  16.      * This method should be called from the consuming class's constructor.
  17.      */
  18.     protected function initSystemPdamData($orientationPage)
  19.     {
  20.         // $pdam_id = Session::get('user')['pdam_id'];
  21.  
  22.         // if (!$pdam_id) {
  23.             // Handle if pdam_id is not found in session
  24.             // Log::error("pdam_id not found in session for HeaderLaporanDynamic trait.");
  25.         //     echo "DEBUG: pdam_id not found in session for HeaderLaporanDynamic trait.<br>";
  26.         //     return;
  27.         // }
  28.  
  29.         $this->systemPdamData = MainModel::findFirst([
  30.             'conditions' => 'id = :id:', // Asumsi nama kolom primary key adalah 'id'
  31.             'bind' => ['id' => 4]
  32.         ]);
  33.  
  34.         $this->orientationPage = $orientationPage;
  35.  
  36.         if (!$this->systemPdamData) {
  37.             // Log::warning("No system PDAM data found for pdam_id: " . $pdam_id);
  38.             // echo "DEBUG: No system PDAM data found for pdam_id: " . $pdam_id . "<br>";
  39.         } else {
  40.             // echo "DEBUG: System PDAM data found for pdam_id: " . $pdam_id . "<br>";
  41.             // echo "DEBUG: systemPdamData: " . print_r($this->systemPdamData, true) . "<br>";
  42.         }
  43.     }
  44.  
  45.     // Header Pdf Versi 1
  46.     function Header()
  47.     {
  48.         $versi = $this->getVersiPdam();
  49.         switch ($versi) {
  50.             case '1':
  51.                 if ($this->orientationPage == 'L') {
  52.                     $this->_renderHeaderLandscapeV1();
  53.                 } else {
  54.                     $this->_renderHeaderPortraitV1();
  55.                 }
  56.                 break;
  57.             default:
  58.                 if ($this->orientationPage == 'L') {
  59.                     $this->_renderHeaderLandscapeV1();
  60.                 } else {
  61.                     $this->_renderHeaderPortraitV1();
  62.                 }
  63.                 break;
  64.         }
  65.     }
  66.  
  67.  
  68.     private function _renderHeaderLandscapeV1()
  69.     {
  70.         // Ukuran A4 landscape: 29.7cm x 21cm, margin kiri-kanan 0.5cm
  71.         $pageWidth = 29.7 - 1; // 28.7cm usable width (margin 0.5cm kiri-kanan)
  72.         $leftMargin = 0.5;
  73.         $rightMargin = 0.5;
  74.  
  75.         // Logo
  76.         $imagePath = BASEPATH . '/public/external_img/' . $this->getImageHeaderPdam();
  77.         $this->Image($imagePath, $this->getImgX(), $this->getImgY(), $this->getImgW(), $this->getImgH());
  78.         // Logo di kiri atas, tinggi 2cm, lebar proporsional
  79.         // $this->Image($imagePath, 5.4, 0.3, 3.3, 3.3);
  80.  
  81.         // Geser pointer ke kanan setelah logo, untuk header text
  82.         $this->SetXY($leftMargin, 0.7);
  83.  
  84.         // Nama PDAM (besar, bold, center)
  85.         $this->SetFont('arial', 'B', 18);
  86.         $this->SetTextColor(0, 0, 0);
  87.         // Cell(width, height, text, border, ln, align)
  88.         $this->SetXY($leftMargin, 0.7);
  89.         $this->Cell($pageWidth, 0.9, strtoupper($this->getNamaPdam()), 0, 2, 'C');
  90.  
  91.         // Alamat (center)
  92.         $this->SetFont('arial', '', 10);
  93.         $this->SetX($leftMargin);
  94.         $this->Cell($pageWidth, 0.6, $this->getAlamatPdam(), 0, 2, 'C');
  95.  
  96.         // Telp/Fax/Kota (center)
  97.         $this->SetX($leftMargin);
  98.         $telpFax = 'Telp. ' . $this->getNoTelpPdam() . 'Fax. 021-88961608 - ' . $this->getKotaKabPdam();
  99.         $this->Cell($pageWidth, 0.6, $telpFax, 0, 2, 'C');
  100.  
  101.         // Website (center, biru, underline)
  102.         $this->SetX($leftMargin);
  103.         $this->SetTextColor(0, 0, 255);
  104.         $this->SetFont('arial', 'U', 10);
  105.         $this->Cell($pageWidth, 0.6, 'www.pdamtirtapatriot.co', 0, 2, 'C', false, 'https://tirtapatriot.co.id');
  106.         $this->SetFont('arial', '', 10);
  107.         $this->SetTextColor(0, 0, 0);
  108.  
  109.         // Garis bawah tebal & tipis (full width, tepat di bawah header)
  110.         $yLine = $this->GetY() + 0.2;
  111.         $this->SetLineWidth(0.04);
  112.         $this->Line(1.2, $yLine, 28.7 - $rightMargin, $yLine);
  113.         $this->SetLineWidth(0.01);
  114.         $this->Line(1.2, $yLine + 0.15, 28.7 - $rightMargin, $yLine + 0.15);
  115.  
  116.         // Spasi ke bawah sebelum konten
  117.         $this->Ln(0.8);
  118.     }
  119.  
  120.    
  121.     private function _renderHeaderPortraitV1()
  122.     {
  123.         $imagePath = BASEPATH . '/public/external_img/' . $this->getImageHeaderPdam();
  124.         $this->Image($imagePath, $this->getImgX(), $this->getImgY(), $this->getImgW(), $this->getImgH());
  125.  
  126.         $this->SetFont('helvetica', 'B', 19);
  127.         $this->SetTextColor(0, 0, 0);
  128.         $this->Cell(2);
  129.         $this->Cell(0, 0.6, $this->getNamaPdam(), 0, 0, 'C');
  130.         // $this->SetFont('helvetica', 'I', 6);
  131.         // $this->Cell(5.3, 0.5, 'Page ' . $this->PageNo() . '/{nb}', 0, 0, 'R');
  132.         // $this->Ln();
  133.         // $this->SetTextColor(0, 0, 0);
  134.         // $this->Cell(17, 0.1, '', 0, 'L', 'R', 0);
  135.         // $this->Cell(0, 0, "Dicetak pada : " . date('d-m-Y'), 0, 0, 'L');
  136.         $this->Ln();
  137.         $this->SetFont('helvetica', '', 11);
  138.         $this->Cell(2);
  139.         $this->Cell(0, 0.6, $this->getAlamatPdam(), 0, 0, 'C');
  140.         $this->Ln();
  141.         $this->Cell(2);
  142.         $this->Cell(0, 0.5, 'Telp. ' . $this->getNoTelpPdam() . "Fax. 021-88961608 - " . $this->getKotaKabPdam() ."", 0, 0, 'C');
  143.         $this->Ln();
  144.         $this->Cell(2);
  145.         $this->SetTextColor(0, 0, 255);
  146.         $this->SetFont('', 'U');
  147.         $this->Cell(0, 0.5, 'www.tirtapatriot.co.id', 0, 0, 'C', false, 'https://tirtapatriot.co.id');
  148.         $this->SetFont('', '');
  149.         $this->SetTextColor(0, 0, 0);        
  150.         $this->Line(0.5, 3, 20.5, 3);
  151.         $this->Line(0.5, 3.1, 20.5, 3.1);
  152.         $this->Ln(1.5);
  153.     }
  154.  
  155.     /**
  156.      * Get the 'direktori' from system PDAM data.
  157.      * @return string|null
  158.      */
  159.     public function getDirektoriPdam()
  160.     {
  161.         return $this->systemPdamData ? $this->systemPdamData->direktori : null;
  162.     }
  163.  
  164.     /**
  165.      * Get the 'nama_pdam' from system PDAM data.
  166.      * @return string|null
  167.      */
  168.     public function getNamaPdam()
  169.     {
  170.         return $this->systemPdamData ? $this->systemPdamData->nama_pdam : null;
  171.     }
  172.  
  173.     /**
  174.      * Get the 'nama_aplikasi' from system PDAM data.
  175.      * @return string|null
  176.      */
  177.     public function getNamaAplikasiPdam()
  178.     {
  179.         return $this->systemPdamData ? $this->systemPdamData->nama_aplikasi : null;
  180.     }
  181.  
  182.     /**
  183.      * Get the 'nama_panjang_aplikasi' from system PDAM data.
  184.      * @return string|null
  185.      */
  186.     public function getNamaPanjangAplikasiPdam()
  187.     {
  188.         return $this->systemPdamData ? $this->systemPdamData->nama_panjang_aplikasi : null;
  189.     }
  190.  
  191.     /**
  192.      * Get the 'pemerintah_kota_kab' from system PDAM data.
  193.      * @return string|null
  194.      */
  195.     public function getPemerintahKotaKabPdam()
  196.     {
  197.         return $this->systemPdamData ? $this->systemPdamData->pemerintah_kota_kab : null;
  198.     }
  199.  
  200.     /**
  201.      * Get the 'kota_kab' from system PDAM data.
  202.      * @return string|null
  203.      */
  204.     public function getKotaKabPdam()
  205.     {
  206.         return $this->systemPdamData ? $this->systemPdamData->kota_kab : null;
  207.     }
  208.  
  209.     /**
  210.      * Get the 'alamat' from system PDAM data.
  211.      * @return string|null
  212.      */
  213.     public function getAlamatPdam()
  214.     {
  215.         return $this->systemPdamData ? $this->systemPdamData->alamat : null;
  216.     }
  217.  
  218.     /**
  219.      * Get the 'no_telp_pdam' from system PDAM data.
  220.      * @return string|null
  221.      */
  222.     public function getNoTelpPdam()
  223.     {
  224.         return $this->systemPdamData ? $this->systemPdamData->no_telp_pdam : null;
  225.     }
  226.  
  227.     /**
  228.      * Get the 'email' from system PDAM data.
  229.      * @return string|null
  230.      */
  231.     public function getEmailPdam()
  232.     {
  233.         return $this->systemPdamData ? $this->systemPdamData->email : null;
  234.     }
  235.  
  236.     /**
  237.      * Get the 'latitude' from system PDAM data.
  238.      * @return string|null
  239.      */
  240.     public function getLatitudePdam()
  241.     {
  242.         return $this->systemPdamData ? $this->systemPdamData->latitude : null;
  243.     }
  244.  
  245.     /**
  246.      * Get the 'longitude' from system PDAM data.
  247.      * @return string|null
  248.      */
  249.     public function getLongitudePdam()
  250.     {
  251.         return $this->systemPdamData ? $this->systemPdamData->longitude : null;
  252.     }
  253.  
  254.     /**
  255.      * Get the 'image_logo' from system PDAM data.
  256.      * @return string|null
  257.      */
  258.     public function getImageLogoPdam()
  259.     {
  260.         return $this->systemPdamData ? $this->systemPdamData->image_logo : null;
  261.     }
  262.  
  263.     /**
  264.      * Get the 'image_header' from system PDAM data.
  265.      * @return string|null
  266.      */
  267.     public function getImageHeaderPdam()
  268.     {
  269.         return $this->systemPdamData ? $this->systemPdamData->image_header : null;
  270.     }
  271.  
  272.     /**
  273.      * Get the 'image_watermark' from system PDAM data.
  274.      * @return string|null
  275.      */
  276.     public function getImageWatermarkPdam()
  277.     {
  278.         return $this->systemPdamData ? $this->systemPdamData->image_watermark : null;
  279.     }
  280.  
  281.     /**
  282.      * Get the 'image_footer' from system PDAM data.
  283.      * @return string|null
  284.      */
  285.     public function getImageFooterPdam()
  286.     {
  287.         return $this->systemPdamData ? $this->systemPdamData->image_footer : null;
  288.     }
  289.  
  290.     /**
  291.      * Get the 'img_x' from system PDAM data.
  292.      * @return string|null
  293.      */
  294.     public function getImgX()
  295.     {
  296.         return $this->systemPdamData ? $this->systemPdamData->img_x : null;
  297.     }
  298.  
  299.     /**
  300.      * Get the 'img_y' from system PDAM data.
  301.      * @return string|null
  302.      */
  303.     public function getImgY()
  304.     {
  305.         return $this->systemPdamData ? $this->systemPdamData->img_y : null;
  306.     }
  307.  
  308.     /**
  309.      * Get the 'img_w' from system PDAM data.
  310.      * @return string|null
  311.      */
  312.     public function getImgW()
  313.     {
  314.         return $this->systemPdamData ? $this->systemPdamData->img_w : null;
  315.     }
  316.  
  317.     /**
  318.      * Get the 'img_h' from system PDAM data.
  319.      * @return string|null
  320.      */
  321.     public function getImgH()
  322.     {
  323.         return $this->systemPdamData ? $this->systemPdamData->img_h : null;
  324.     }
  325.  
  326.     /**
  327.      * Get the 'versi' from system PDAM data.
  328.      * @return string|null
  329.      */
  330.     public function getVersiPdam()
  331.     {
  332.         return $this->systemPdamData ? $this->systemPdamData->versi_header : null;
  333.     }
  334. }
  335.  
Advertisement
Add Comment
Please, Sign In to add comment