Advertisement
jamboljack

Parsing Tapping

Apr 9th, 2019
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.99 KB | None | 0 0
  1. public function open_dir()
  2.     {
  3.         $dir  = FCPATH . '/tap';
  4.         $tamp = array();
  5.         // Open a directory, and read its contents
  6.         if (is_dir($dir)) {
  7.             if ($dh = opendir($dir)) {
  8.                 while (($file = readdir($dh)) !== false) {
  9.                     if (substr($file, -3) == "bin") {
  10.                         array_push($tamp, $file);
  11.                     }
  12.                 }
  13.                 closedir($dh);
  14.             }
  15.         }
  16.  
  17.         return $tamp;
  18.     }
  19.  
  20.     public function open($title)
  21.     {
  22.         // print_r($data);
  23.         $file = file('tap/' . $title);
  24.         $tamp = array();
  25.         foreach ($file as $line) {
  26.             if (strpos($line, ":")) {
  27.                 $charSet = preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $line);
  28.                 $charSet = trim(strtolower($charSet));
  29.                 $r_data  = str_replace(' ', '', $charSet);
  30.                 $row     = explode(":", $r_data);
  31.                 $key     = array($row[0]);
  32.                 $val     = array(str_replace(',', '', $row[1]));
  33.                 $x_tamp  = array_combine($key, $val);
  34.                 array_push($tamp, $x_tamp);
  35.             }
  36.         }
  37.  
  38.         return $tamp;
  39.     }
  40.     public function read_data()
  41.     {
  42.         $dir = $this->open_dir();
  43.         echo "<pre>";
  44.         for ($i = 0; $i < count($dir); $i++) {
  45.             $data_file = $this->open($dir[$i]);
  46.             // echo "nama File =================================== > " . $dir[$i] . '<br>';
  47.             foreach ($data_file as $txt) {
  48.                 // $npwpd   = $txt['npwpd'];
  49.                 // echo $npwpd;
  50.                 // $noorder = $txt['noorder']; // Misalnya
  51.                 // $checkNo = $this->db->get_where('tax_transaksi', array('transaksi_noorder' => $noorder))->row();
  52.                 // if (count($checkNo) == 0) {
  53.                 //     $checkWP = $this->db->get_where('tax_wajibpajak', array('wp_npwpd' => $npwpd))->row();
  54.                 //     // Disini saja nanti kroscek no_order mas
  55.                 //     $data_r = array(
  56.                 //         'wp_id'              => $checkWP->wp_id,
  57.                 //         'transaksi_file'     => $file,
  58.                 //         'transaksi_noorder'  => strtoupper($noorder),
  59.                 //         'transaksi_tgl'      => date('Y-m-d', strtotime($txt['tanggal'])),
  60.                 //         'transaksi_subtotal' => intval($txt['subtotal']),
  61.                 //         'transaksi_diskon'   => intval($txt['diskon']),
  62.                 //         'transaksi_pajak'    => intval($txt['pajakdaerah']),
  63.                 //         'transaksi_total'    => intval($txt['total']),
  64.                 //         'transaksi_update'   => date('Y-m-d H:i:s'),
  65.                 //     );
  66.  
  67.                 //     $this->db->insert('tax_transaksi', $data_r);
  68.                 // }
  69.  
  70.                 foreach ($txt as $label => $val) {
  71.                     echo $label . ' : ' . $val . '<br>';
  72.                 }
  73.             }
  74.         }
  75.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement