-
Akihiko
Newbie
-
Posts: 4
Threads: 2
Joined: Mar 2017
Reputation:
0
Hi, I want to ask why when i change value from my table on DB, TCPDF not generate complete page. Here the example : i have table called orders and there status column (it ranges from 0-6), when order have 5 in its status column the TCPDF generate page flawlessly, but when i change the status column to 0-3, TCPDF generate incomplete page.
I literally doesnt know what i missed in my codes
Here my code:
Controller :
PHP Code: function printorder($idorder) { $order = $this->order_model->getorderforprint($idorder)->result();
$i = 0; $tmp = array(); $temp2 = array(); foreach ($order as $key) {
$temp = $this->order_model->getcompleteoneorder($key->id)->result(); $j=0; foreach ($temp as $key2) { $temp2[$j] = array( 'namabarang' => $key2->nama_barang, 'size' => $key2->size, 'jumlah' => $key2->quantity, 'harga' => $key2->price, ); $j++; }
$tmp[$i] = array( 'id' =>$key->id, 'nama' => $key->first_name, 'tanggal' => $key->date, 'status' => $key->order_status, 'alamat' => $key->alamat, 'ongkir' => $key->ongkir, 'ekspedisi' => $key->ekspedisi.' '.$key->paketekspedisi, 'pembayaran' => $key->statusbayar, 'barang' => $temp2, ); $i++;
} $this->data['detail'] = $tmp; $this->load->view('admin/order/pdfperorder', $this->data); }
PDF View :
PHP Code: <?php $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetHeaderData('','', PDF_HEADER_TITLE, PDF_HEADER_STRING); $pdf->setFooterData(array(0,64,0), array(0,64,128)); $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); $pdf->setFontSubsetting(false); $pdf->SetFont('helvetica', '', 14, '', true); ob_start(); foreach ($detail as $key) { $yyyy = substr($key['tanggal'], 0,4); $mm = substr($key['tanggal'], 5,2); $dd = substr($key['tanggal'], 8,2); $pdf->SetTitle('Order '.$key['nama'].' '.$dd.'-'.$mm.'-'.$yyyy); $pdf->SetSubject('Order'); ?> <head> <style> body { background-color: linen; } table.pdf1{ border: 1px solid black; } tr.pdf1{ border: 1px solid black; } td.pdf1{ border: 1px solid black; } th.pdf1{ border: 1px solid black; } .mid{ text-align: center; } .right{ text-align: right; } </style> </head> <table class=""> <tr> <td width="110px">Nama</td> <td width="15px">:</td> <td width="520px"><?php echo $key['nama']; ?></td> </tr> <tr> <td>Tanggal</td> <td>:</td> <td><?php echo $dd.'-'.$mm.'-'.$yyyy; ?></td> </tr> <tr> <td>Status</td> <td>:</td> <td><?php echo $key['status']; ?></td> </tr> <tr> <td>Alamat</td> <td>:</td> <td><?php echo $key['alamat']; ?></td> </tr> <tr> <td>Ekspedisi</td> <td>:</td> <td><?php echo strtoupper($key['ekspedisi']); ?></td> </tr> <tr> <td>Ongkir</td> <td>:</td> <td><?php echo "Rp " .number_format($key['ongkir'],0,',','.'); ?></td> </tr> <tr> <td>Pembayaran</td> <td>:</td> <td><?php echo $key['pembayaran']; ?></td> </tr> <tr> <td>Barang</td> <td>:</td> </tr> </table> <br><br> <table class="pdf1"> <tr class="pdf1"> <th width="40px" class="pdf1">NO</th> <th width="230px" class="pdf1">Nama Barang</th> <th width="65px" class="pdf1">Ukuran</th> <th width="65px" class="pdf1">Jumlah</th> <th width="120px" class="pdf1">Harga</th> <th width="120px" class="pdf1">Subtotal</th> </tr> <?php $i=1; $grandtotal = 0; foreach ($key['barang'] as $key2) { ?> <tr class="pdf1"> <td class="pdf1 mid"><?php echo $i; ?></td> <td class="pdf1"><?php echo $key2['namabarang']; ?></td> <td class="pdf1 mid"><?php echo $key2['size']; ?></td> <td class="pdf1 mid"><?php echo $key2['jumlah']; ?></td> <td class="pdf1 mid"><?php echo "Rp " .number_format($key2['harga'],0,',','.'); ?></td> <td class="pdf1 right"><?php echo "Rp " .number_format($key2['jumlah']*$key2['harga'],0,',','.'); ?></td> </tr> <?php $grandtotal = $grandtotal + ($key2['jumlah']*$key2['harga']); $i++;} ?> <tr> <th colspan="5" class="pdf1"><center>Jumlah</center></th> <td class="pdf1 right"><?php echo "Rp " . number_format($grandtotal,0,',','.'); ?></td> </tr> <tr> <th colspan="5" class="pdf1"><center>Jumlah + Ongkir</center></th> <td class="pdf1 right"><?php echo "Rp " . number_format($grandtotal+$key['ongkir'],0,',','.'); ?></td> </tr> </table> <?php $pdf->AddPage(); $cont = ob_get_contents(); $pdf->writeHTML($cont, true, false, true, false, ''); ob_end_clean(); } $pdf->IncludeJS("print();"); $pdf->Output('Order '.$key['nama'].' '.$dd.'-'.$mm.'-'.$yyyy.'.pdf', 'I'); ?>
Model :
PHP Code: function getorderforprint($idorder) { $this->db->select("cm_tb_orders.id, users.first_name, cm_tb_orders.date, cm_order_status.order_status, cm_tb_orders.ongkir, cm_tb_orders.alamat, cm_tb_orders.ekspedisi, cm_tb_orders.paketekspedisi, CASE WHEN cm_tb_orders.statusbayar = 0 THEN 'Belum Bayar' ELSE 'Sudah Bayar' END AS statusbayar"); $this->db->from('cm_tb_orders'); $this->db->join('cm_order_status','cm_tb_orders.status = cm_order_status.id'); $this->db->join('users','cm_tb_orders.customerid = users.id'); $this->db->where('cm_tb_orders.id', $idorder); return $this->db->get(); }
|