
                <!DOCTYPE html>
    
                <html>
    
                <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
                  
    
                  <meta http-equiv="X-UA-Compatible" content="IE=edge">
    
                  <title>Faktur <?php echo $result['order']['customer_name'] ?> <?php echo $result['order']['bill_no'] ?> <?php echo $result['order']['tanggal_order'] ?></title>
    
                  <!-- Tell the browser to be responsive to screen width -->
    
                  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    
                  <!-- Bootstrap 3.3.7 -->
    
                  <link rel="stylesheet" href="https://texapp.is3.cloudhost.id/api/v2/assets/print/bootstrap.min.css">
    
                  <!-- Font Awesome -->
    
                  <link rel="stylesheet" href="https://texapp.is3.cloudhost.id/api/v2/assets/print/font-awesome.min.css">
    
                  <link rel="stylesheet" href="https://texapp.is3.cloudhost.id/api/v2/assets/print/AdminLTE.min.css">
    
                  <link rel="stylesheet" href="https://texapp.is3.cloudhost.id/api/v2/assets/print/templates.css">
    
                </head>
    
                <body>
    
                <header class="clearfix">
    
                <div id="logo" style="width:100%;">
    
                    <img style="max-height:125px;" src="https://app.texprint.my.id/assets/images/logo.png">
    
                </div>
    
                
    
                <div id="client">
    
                    <h4><?php echo $result['order']['customer_name'] ?></h4>
    
                    <?php echo $result['order']['customer_address'] ?> <br />
    
                    <?php echo $result['order']['customer_phone'] ?>
    
                </div>
    
    
    
                <div id="company">
    
                    <h4>Texprint</h4>
    
                    Green Sedayu Bizpark Daan Mogot, Blok <br />
    
                    DM 11 No 26, Kalideres <br />
    
                    Jakarta Barat 11840 <?php echo $result['order']['tanggal_order'] ?><br />
    
    
    
                    
    
                </div>
    
                </header>
    
                
    
                <main>
                                <?php
                // Tanggal awal dari $result['order']['datetime']
                $order_date = date('d-m-Y', $result['order']['date_time']);
                $jatuhtempo = date('d-m-Y', strtotime($order_date . ' +30 days'));
                // Format tanggal jatuh tempo ke dalam dd/mm/yyyy

                // Output tanggal jatuh tempo

                ?>
                    <div class="invoice-details clearfix">
    
                        <table>
    
                            <tr>
    
                    <td>Tanggal Invoice : </td>
    
                    <td><?php echo $order_date; ?></td>
    
                    </tr>
    
                    <tr>
    
                    <td>Tanggal Jatuh Tempo : </td>
    
                    <td>
                    <?php echo $jatuhtempo; ?>

                        </td>
    
                    </tr>
    
                    <tr>
    
                    <td>Jumlah yang harus dibayar :</td>
    
                    <td><p id="totalatas"></p></td>
    
                    </tr>
    
                    <tr>
    
                        <td>Metode Pembayaran :</td>
    
                        <td>Transfer Bank BCA 5215410410 A/N Texprint Maju Indonesia</td>
    
                    </tr>
    
    
                    </table>
    
                    </div>
    
                    <?php
// Fungsi untuk memformat angka menjadi format Rupiah
function format_rupiah($angka){
    $rupiah = number_format($angka, 0, ',', '.');
    return "Rp ".$rupiah;
}

?>
    
                    <h1 class="invoice-title">Faktur <?php echo $result['order']['customer_name'] ?> <?php echo $result['order']['bill_no'] ?></h1>
    
                    
                    <?php if (!empty($result['order_item'])): ?>

                      <table class="item-table">
    
                                        <thead> 

                                
                                        <tr>
                                
                                            <th class="item-name">Item</th>
                                
                                            <th class="item-desc">Deskripsi</th>
                                
                                            <th class="item-amount text-right">Ukuran</th>
                                
                                            <th class="item-price text-right">Qty</th>
                                
                                            <th class="item-amount text-right">Harga</th>
                                
                                            <th class="item-total text-right">Total</th>
                                
                                        </tr>
                                
                                        </thead>
                                
                                        <tbody>                                          <?php $total = 0; $totalItems = count($result['order_item']);  foreach ($result['order_item'] as $cartItem): $subtotal = $cartItem['amount'];
                                            $total += $subtotal; // Menambahkan subtotal ke total  ?>                                            
<tr>
                                
                                                            <td><?php 
                                                                    $productName = '';
                                                                    foreach($result['product'] as $product) {
                                                                        if($product['id'] == $cartItem['product_id']) {
                                                                            $productName = $product['name'];
                                                                            break;
                                                                        }
                                                                    }
                                                                    echo $productName;
                                                                ?></td>
                                
                                                            <td><?= $cartItem['details'] ?></td>
                                
                                                            <td class="text-right"><?= $cartItem['width'] ?> X <?= $cartItem['length'] ?></td>
                                
                                                            <td class="text-right"><?php
                                                              if ($cartItem['tipe'] === 'meter') {
                                                                  // Jika tipe adalah meter, tampilkan qty
                                                                  echo $cartItem['qty'];
                                                              } else {
                                                                  // Jika tipe bukan meter, tampilkan pcs
                                                                  echo $cartItem['pcs'];
                                                              }
                                                              ?>
                                                            </td>
                                
                                                            <td class="text-right"><?= 'Rp.'.number_format($cartItem['rate'], 0, '', ',') ?> / <?= $cartItem['tipe'] ?></td>
                                
                                                            <td class="text-right"><?= 'Rp.'.number_format($cartItem['amount'], 0, '', ',') ?> </td>
                                
                                                          </tr><?php endforeach; ?></tbody>
    
                          
    
                          
    
                      </table>
    
                      <?php else: ?>

                      <p>Tidak ada invoice yang dipilih.</p>

                      <?php endif; ?>
                          
                <div class="row">
    
                      
    
                      <div class="col-xs-6 pull pull-right" style="padding-left: 80px;">
    
    
    
                        <div class="table-responsive">
    
                          <table class="table" border="0">
    
                            <tr>
    
                              <th style="width:50%" class="text-right">Total</th>
                              <td class="text-right"><p id="subtotalz"></p></td>
                              <input type ="hidden"  name="subtotal"  id="subtotal" class="form-control" value="<?php echo floatval($result['order']['net_amount']); ?>" autocomplete="off">

                            </tr> <tr>
    
                              <th class="text-right">Dibayar</th>
    
                              <td class="text-right"><p id="paid"></p></td>
                              <input  type ="hidden" hidden name="payment" hidden id="payment" class="form-control" value="<?php echo floatval($result['totalNetAmount']); ?>" autocomplete="off">

                         </tr>
    
                            <tr>
    
                              <th class="text-right">Tertagih</th>
    
                              <td class="text-right"><p id="total"></p></td>
    
                            </tr>
    
                            <tr>
    
                              <th class="text-right">Status Pembayaran</th>
    
                              <td class="text-right"><?php
                                // Mengambil nilai status dari variabel $result['order']['paid_status']
                                $status = $result['order']['paid_status'];

                                // Menggunakan struktur kontrol switch untuk menentukan tindakan berdasarkan nilai status
                                switch ($status) {
                                    case 1:
                                        echo "Dibayar";
                                        break;
                                    case 2:
                                        echo "Belum Dibayar";
                                        break;
                                    case 3:
                                        echo "Parsial";
                                        break;
                                    default:
                                        echo "Status tidak valid";
                                }
                                ?>
                              </td>
    
                            </tr>
    
                          </table>
    
                        </div>
    
                      </div>
    
                      <!-- /.col -->
    
                    </div>
    
                    <!-- /.row -->
    
                    <div style="text-align:center;">
    
                    <p style="font-style:italic;">Notes</p>
    
                    <hr width="100%">
    
                    <p style="font-style:italic;"><?php echo $result['order']['notes'] ?></p>
    
                    </div>
    
                </main>
    
            
    
    
    
                   
    
    
    
                    
    
                  </section>
    
                  <!-- /.content -->
                  <script src="https://is3.cloudhost.id/texapp/api/v2/assets/vendors/core/core.js"></script>

                </div>
                <script>

$(document).ready(function() {
  subAmount();
  function subAmount() {
    var paidamount = Number($("#payment").val());
    var paidamount2 = Number($("#subtotal").val());
    var totalbill= paidamount2 - paidamount;
    var formattedsubTotal = formatRupiah(paidamount2);
    var formattedTotal = formatRupiah(totalbill);
    var formattedpaid = formatRupiah(paidamount);

    $("#subtotalz").text("Rp. " + formattedsubTotal);
$("#paid").text("Rp. " + formattedpaid);
$("#total").text("Rp. " + formattedTotal);
$("#totalatas").text("Rp. " + formattedTotal);

window.print()
  }

  function formatRupiah(angka) {
  var reverse = angka.toString().split('').reverse().join('');
  var ribuan = reverse.match(/\d{1,3}/g);
  var formatted = ribuan.join('.').split('').reverse().join('');
  return formatted;
}

});
</script>
            </body>
    
        </html>
