Advertisement
Guest User

sale_form.php

a guest
Apr 8th, 2020
1,202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 21.19 KB | None | 0 0
  1. <section class="content-header">
  2.     <h1>Sales
  3.         <small>Penjualan</small>
  4.     </h1>
  5.     <ol class="breadcrumb">
  6.         <li><a href="#"><i class="fa fa-dashboard"></i></a></li>
  7.         <li>Transaction</li>
  8.         <li class="active">Sales</li>
  9.     </ol>
  10. </section>
  11.  
  12. <section class="content">
  13.     <div class="row">
  14.         <div class="col-lg-4">
  15.             <div class="box box-widget">
  16.                 <div class="box-body">
  17.                     <table width="100%">
  18.                         <tr>
  19.                             <td style="vertical-align:top">
  20.                                 <label for="date">Date</label>
  21.                             </td>
  22.                             <td>
  23.                                 <div class="form-group">
  24.                                     <input type="date" id="date" value="<?=date('Y-m-d')?>" class="form-control">
  25.                                 </div>
  26.                             </td>
  27.                         </tr>
  28.                         <tr>
  29.                             <td style="vertical-align:top; width:30%">
  30.                                 <label for="user">Kasir</label>
  31.                             </td>
  32.                             <td>
  33.                                 <div class="form-group">
  34.                                     <input type="text" id="user" value="<?=$this->fungsi->user_login()->name?>" class="form-control" readonly>
  35.                                 </div>
  36.                             </td>
  37.                         </tr>
  38.                         <tr>
  39.                             <td style="vertical-align:top">
  40.                                 <label for="customer">Customer</label>
  41.                             </td>
  42.                             <td>
  43.                                 <div>
  44.                                     <select id="customer" class="form-control">
  45.                                         <option value="">Umum</option>
  46.                                         <?php foreach($customer as $cust => $value) {
  47.                                             echo '<option value="'.$value->customer_id.'">'.$value->name.'</option>';
  48.                                         } ?>
  49.                                     </select>
  50.                                 </div>    
  51.                             </td>
  52.                         </tr>
  53.                     </table>
  54.                 </div>
  55.             </div>
  56.         </div>
  57.  
  58.         <div class="col-lg-4">
  59.             <div class="box box-widget">
  60.                 <div class="box-body">
  61.                     <table width="100%">
  62.                         <tr>
  63.                             <td style="vertical-align:top; width:30%">
  64.                                 <label for="barcode">Barcode</label>
  65.                             </td>
  66.                             <td>
  67.                                 <div class="form-group input-group">
  68.                                     <input type="hidden" id="item_id">
  69.                                     <input type="hidden" id="price">
  70.                                     <input type="hidden" id="stock">
  71.                                     <input type="text" id="barcode" class="form-control" autofocus>
  72.                                     <span class="input-group-btn">
  73.                                         <button type="button" class="btn btn-info btn-flat" data-toggle="modal" data-target="#modal-item">
  74.                                             <i class="fa fa-search"></i>
  75.                                         </button>
  76.                                     </span>
  77.                                 </div>
  78.                             </td>
  79.                         </tr>
  80.                         <tr>
  81.                             <td style="vertical-align:top">
  82.                                 <label for="qty">Qty</label>
  83.                             </td>
  84.                             <td>
  85.                                 <div class="form-group">
  86.                                     <input type="number" id="qty" value="1" min="1" class="form-control">
  87.                                 </div>
  88.                             </td>
  89.                         </tr>
  90.                         <tr>
  91.                             <td></td>
  92.                             <td>
  93.                                 <div>
  94.                                     <button type="button" id="add_cart" class="btn btn-primary">
  95.                                         <i class="fa fa-cart-plus"></i> Add
  96.                                     </button>
  97.                                 </div>
  98.                             </td>
  99.                         </tr>
  100.                     </table>
  101.                 </div>
  102.             </div>
  103.         </div>
  104.  
  105.         <div class="col-lg-4">
  106.             <div class="box box-widget">
  107.                 <div class="box-body">
  108.                     <div align="right">
  109.                         <h4>Invoice <b><span id="invoice"><?= $invoice ?></span></b></h4>
  110.                         <h1><b><span id="grand_total2" style="font-size:50pt">0</span></b></h1>
  111.                     </div>
  112.                 </div>
  113.             </div>
  114.         </div>
  115.     </div>
  116.  
  117.     <div class="row">
  118.         <div class="col-lg-12">
  119.             <div class="box box-widget">
  120.                 <div class="box-body table-responsive">
  121.                     <table class="table table-bordered table-striped">
  122.                         <thead>
  123.                             <tr>
  124.                                 <th>#</th>
  125.                                 <th>Barcode</th>
  126.                                 <th>Product Item</th>
  127.                                 <th>Price</th>
  128.                                 <th>Qty</th>
  129.                                 <th width="10%">Discount Item</th>
  130.                                 <th width="15%">Total</th>
  131.                                 <th>Actions</th>
  132.                             </tr>
  133.                         </thead>
  134.                         <tbody id="cart_table">
  135.                            
  136.                             <?php $this->view('transaction/sale/cart_data') ?>
  137.  
  138.                         </tbody>
  139.                     </table>
  140.                 </div>
  141.             </div>
  142.         </div>
  143.     </div>
  144.  
  145.     <div class="row">
  146.         <div class="col-lg-3">
  147.             <div class="box box-widget">
  148.                 <div class="box-body">
  149.                     <table width="100%">
  150.                         <tr>
  151.                             <td style="vertical-align:top; width:30%">
  152.                                 <label for="sub_total">Sub Total</label>
  153.                             </td>
  154.                             <td>
  155.                                 <div class="form-group">
  156.                                     <input type="number" id="sub_total" value="" class="form-control" readonly>
  157.                                 </div>
  158.                             </td>
  159.                         </tr>
  160.                         <tr>
  161.                             <td style="vertical-align:top">
  162.                                 <label for="discount">Discount</label>
  163.                             </td>
  164.                             <td>
  165.                                 <div class="form-group">
  166.                                     <input type="number" id="discount" value="0" min="0" class="form-control">
  167.                                 </div>
  168.                             </td>
  169.                         </tr>
  170.                         <tr>
  171.                             <td style="vertical-align:top">
  172.                                 <label for="grand_total">Grand Total</label>
  173.                             </td>
  174.                             <td>
  175.                                 <div class="form-group">
  176.                                     <input type="number" id="grand_total" class="form-control" readonly>
  177.                                 </div>
  178.                             </td>
  179.                         </tr>
  180.                     </table>
  181.                 </div>
  182.             </div>
  183.         </div>
  184.  
  185.         <div class="col-lg-3">
  186.             <div class="box box-widget">
  187.                 <div class="box-body">
  188.                     <table width="100%">
  189.                         <tr>
  190.                             <td style="vertical-align:top; width:30%">
  191.                                 <label for="cash">Cash</label>
  192.                             </td>
  193.                             <td>
  194.                                 <div class="form-group">
  195.                                     <input type="number" id="cash" value="0" min="0" class="form-control">
  196.                                 </div>
  197.                             </td>
  198.                         </tr>
  199.                         <tr>
  200.                             <td style="vertical-align:top">
  201.                                 <label for="change">Change</label>
  202.                             </td>
  203.                             <td>
  204.                                 <div>
  205.                                     <input type="number" id="change" class="form-control" readonly>
  206.                                 </div>    
  207.                             </td>
  208.                         </tr>
  209.                     </table>
  210.                 </div>
  211.             </div>
  212.         </div>
  213.  
  214.         <div class="col-lg-3">
  215.             <div class="box box-widget">
  216.                 <div class="box-body">
  217.                     <table width="100%">
  218.                         <tr>
  219.                             <td style="vertical-align:top">
  220.                                 <label for="note">Note</label>
  221.                             </td>
  222.                             <td>
  223.                                 <div>
  224.                                     <textarea id="note" rows="3" class="form-control"></textarea>
  225.                                 </div>
  226.                             </td>
  227.                         </tr>
  228.                     </table>
  229.                 </div>
  230.             </div>
  231.         </div>
  232.  
  233.         <div class="col-lg-3">
  234.             <div>
  235.                 <button id="cancel_payment" class="btn btn-flat btn-warning">
  236.                     <i class="fa fa-refresh"></i> Cancel
  237.                 </button><br><br>
  238.                 <button id="process_payment" class="btn btn-flat btn-lg btn-success">
  239.                     <i class="fa fa-paper-plane-o"></i> Process Payment
  240.                 </button>
  241.             </div>
  242.         </div>
  243.     </div>
  244. </section>
  245.  
  246. <!-- Modal Add Product Item -->
  247. <div class="modal fade" id="modal-item">
  248.     <div class="modal-dialog">
  249.         <div class="modal-content">
  250.             <div class="modal-header">
  251.                 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  252.                     <span aria-hidden="true">&times;</span>
  253.                 </button>
  254.                 <h4 class="modal-title">Add Product Item</h4>
  255.             </div>
  256.             <div class="modal-body table-responsive">
  257.                 <table class="table table-bordered table-striped" id="table1">
  258.                     <thead>
  259.                         <tr>
  260.                             <th>Barcode</th>
  261.                             <th>Name</th>
  262.                             <th>Unit</th>
  263.                             <th>Price</th>
  264.                             <th>Stock</th>
  265.                             <th>Actions</th>
  266.                         </tr>
  267.                     </thead>
  268.                     <tbody>
  269.                         <?php foreach($item as $i => $data) { ?>
  270.                         <tr>
  271.                             <td><?=$data->barcode?></td>
  272.                             <td><?=$data->name?></td>
  273.                             <td><?=$data->unit_name?></td>
  274.                             <td class="text-right"><?=indo_currency($data->price)?></td>
  275.                             <td class="text-right"><?=$data->stock?></td>
  276.                             <td class="text-right">
  277.                                 <button class="btn btn-xs btn-info" id="select"
  278.                                     data-id="<?=$data->item_id?>"
  279.                                     data-barcode="<?=$data->barcode?>"
  280.                                     data-price="<?=$data->price?>"
  281.                                     data-stock="<?=$data->stock?>">
  282.                                     <i class="fa fa-check"></i> Select
  283.                                 </button>
  284.                             </td>
  285.                         </tr>
  286.                         <?php } ?>
  287.                     </tbody>
  288.                 </table>
  289.             </div>
  290.         </div>
  291.     </div>
  292. </div>
  293.  
  294. <!-- Modal Edit Cart Item -->
  295. <div class="modal fade" id="modal-item-edit">
  296.     <div class="modal-dialog modal-sm">
  297.         <div class="modal-content">
  298.             <div class="modal-header">
  299.                 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  300.                     <span aria-hidden="true">&times;</span>
  301.                 </button>
  302.                 <h4 class="modal-title">Update Product Item</h4>
  303.             </div>
  304.             <div class="modal-body">
  305.                 <input type="hidden" id="cartid_item">
  306.                 <div class="form-group">
  307.                     <label for="product_item">Product Item</label>
  308.                     <div class="row">
  309.                         <div class="col-md-5">
  310.                             <input type="text" id="barcode_item" class="form-control" readonly>
  311.                         </div>
  312.                         <div class="col-md-7">
  313.                             <input type="text" id="product_item" class="form-control" readonly>
  314.                         </div>
  315.                     </div>
  316.                 </div>
  317.                 <div class="form-group">
  318.                     <label for="price_item">Price</label>
  319.                     <input type="number" id="price_item" min="0" class="form-control">
  320.                 </div>
  321.                 <div class="form-group">
  322.                     <label for="qty_item">Qty</label>
  323.                     <input type="number" id="qty_item" min="1" class="form-control">
  324.                 </div>
  325.                 <div class="form-group">
  326.                     <label for="total_before">Total before Discount</label>
  327.                     <input type="number" id="total_before" class="form-control" readonly>
  328.                 </div>
  329.                 <div class="form-group">
  330.                     <label for="discount_item">Discount per Item</label>
  331.                     <input type="number" id="discount_item" min="0" class="form-control">
  332.                 </div>
  333.                 <div class="form-group">
  334.                     <label for="total_item">Total after Discount</label>
  335.                     <input type="number" id="total_item" class="form-control" readonly>
  336.                 </div>
  337.             </div>
  338.             <div class="modal-footer">
  339.                 <div class="pull-right">
  340.                     <button type="button" id="edit_cart" class="btn btn-flat btn-success">
  341.                         <i class="fa fa-paper-plane"></i> Save
  342.                     </button>
  343.                 </div>
  344.             </div>
  345.         </div>
  346.     </div>
  347. </div>
  348.  
  349.  
  350. <script>
  351. $(document).on('click', '#select', function() {
  352.     $('#item_id').val($(this).data('id'))
  353.     $('#barcode').val($(this).data('barcode'))
  354.     $('#price').val($(this).data('price'))
  355.     $('#stock').val($(this).data('stock'))
  356.     $('#modal-item').modal('hide')
  357. })
  358.  
  359. $(document).on('click', '#add_cart', function() {
  360.     var item_id = $('#item_id').val()
  361.     var price = $('#price').val()
  362.     var stock = $('#stock').val()
  363.     var qty = $('#qty').val()
  364.     if(item_id == '') {
  365.         alert('Product belum dipilih')
  366.         $('#barcode').focus()
  367.     } else if(stock < 1) {
  368.         alert('Stock tidak mencukupi')
  369.         $('#item_id').val('')
  370.         $('#barcode').val('')
  371.         $('#barcode').focus()
  372.     } else {
  373.         $.ajax({
  374.             type: 'POST',
  375.             url: '<?=site_url('sale/process')?>',
  376.             data: {'add_cart' : true, 'item_id' : item_id, 'price' : price, 'qty' : qty},
  377.             dataType: 'json',
  378.             success: function(result) {
  379.                 if(result.success == true) {
  380.                     $('#cart_table').load('<?=site_url('sale/cart_data')?>', function() {
  381.                         calculate()
  382.                     })
  383.                     $('#item_id').val('')
  384.                     $('#barcode').val('')
  385.                     $('#qty').val(1)
  386.                     $('#barcode').focus()
  387.                 } else {
  388.                     alert('Gagal tambah item cart')
  389.                 }
  390.             }
  391.         })
  392.     }
  393. })
  394.  
  395. $(document).on('click', '#del_cart', function() {
  396.     if(confirm('Apakah Anda yakin?')) {
  397.         var cart_id = $(this).data('cartid')
  398.         $.ajax({
  399.             type: 'POST',
  400.             url: '<?=site_url('sale/cart_del')?>',
  401.             dataType: 'json',
  402.             data: {'cart_id': cart_id},
  403.             success: function(result) {
  404.                 if(result.success == true) {
  405.                     $('#cart_table').load('<?=site_url('sale/cart_data')?>', function() {
  406.                         calculate()
  407.                     })
  408.                 } else {
  409.                     alert('Gagal hapus item cart');
  410.                 }
  411.             }
  412.         })
  413.     }
  414. })
  415.  
  416. $(document).on('click', '#update_cart', function() {
  417.     $('#cartid_item').val($(this).data('cartid'))
  418.     $('#barcode_item').val($(this).data('barcode'))
  419.     $('#product_item').val($(this).data('product'))
  420.     $('#price_item').val($(this).data('price'))
  421.     $('#qty_item').val($(this).data('qty'))
  422.     $('#total_before').val($(this).data('price') * $(this).data('qty'))
  423.     $('#discount_item').val($(this).data('discount'))
  424.     $('#total_item').val($(this).data('total'))
  425. })
  426. function count_edit_modal() {
  427.     var price = $('#price_item').val()
  428.     var qty = $('#qty_item').val()
  429.     var discount = $('#discount_item').val()
  430.  
  431.     total_before = price * qty
  432.     $('#total_before').val(total_before)
  433.  
  434.     total = (price - discount) * qty
  435.     $('#total_item').val(total)
  436.  
  437.     if(discount == '') {
  438.         $('#discount_item').val(0)
  439.     }
  440. }
  441. $(document).on('keyup mouseup', '#price_item, #qty_item, #discount_item', function() {
  442.     count_edit_modal()
  443. })
  444.  
  445. $(document).on('click', '#edit_cart', function() {
  446.     var cart_id = $('#cartid_item').val()
  447.     var price = $('#price_item').val()
  448.     var qty = $('#qty_item').val()
  449.     var discount = $('#discount_item').val()
  450.     var total = $('#total_item').val()
  451.     if(price == '' || price < 1) {
  452.         alert('Harga tidak boleh kosong')
  453.         $('#pice_item').focus()
  454.     } else if(qty == '' || qty < 1) {
  455.         alert('Qty tidak boleh kosong')
  456.         $('#qty_item').focus()
  457.     } else {
  458.         $.ajax({
  459.             type: 'POST',
  460.             url: '<?=site_url('sale/process')?>',
  461.             data: {'edit_cart' : true, 'cart_id' : cart_id, 'price' : price,
  462.                     'qty' : qty, 'discount' : discount, 'total' : total},
  463.             dataType: 'json',
  464.             success: function(result) {
  465.                 if(result.success == true) {
  466.                     $('#cart_table').load('<?=site_url('sale/cart_data')?>', function() {
  467.                         calculate()
  468.                     })
  469.                     alert('Item cart berhasil ter-update')
  470.                     $('#modal-item-edit').modal('hide');
  471.                 } else {
  472.                     alert('Data item cart tidak ter-update')
  473.                 }
  474.             }
  475.         })
  476.     }
  477. })
  478.  
  479.  
  480. function calculate() {
  481.     var subtotal = 0;
  482.     $('#cart_table tr').each(function() {
  483.         subtotal += parseInt($(this).find('#total').text())
  484.     })
  485.     isNaN(subtotal) ? $('#sub_total').val(0) : $('#sub_total').val(subtotal)
  486.  
  487.     var discount = $('#discount').val()
  488.     var grand_total = subtotal - discount
  489.     if(isNaN(grand_total)) {
  490.         $('#grand_total').val(0)
  491.         $('#grand_total2').text(0)
  492.     } else {
  493.         $('#grand_total').val(grand_total)
  494.         $('#grand_total2').text(grand_total)
  495.     }
  496.  
  497.     var cash = $('#cash').val();
  498.     cash != 0 ? $('#change').val(cash - grand_total) : $('#change').val(0)
  499.  
  500.     if(discount == '') {
  501.         $('#discount').val(0)
  502.     }
  503. }
  504. $(document).on('keyup mouseup', '#discount, #cash', function() {
  505.     calculate()
  506. })
  507.  
  508. $(document).ready(function() {
  509.     calculate()
  510. })
  511.  
  512. // process payment
  513. $(document).on('click', '#process_payment', function() {
  514.     var customer_id = $('#customer').val()
  515.     var subtotal = $('#sub_total').val()
  516.     var discount = $('#discount').val()
  517.     var grandtotal = $('#grand_total').val()
  518.     var cash = $('#cash').val()
  519.     var change = $('#change').val()
  520.     var note = $('#note').val()
  521.     var date = $('#date').val()
  522.     if(subtotal < 1) {
  523.         alert('Belum ada product item yang dipilih')
  524.         $('#barcode').focus()
  525.     } else if(cash < 1) {
  526.         alert('Jumlah uang cash belum diinput')
  527.         $('#cash').focus()
  528.     } else {
  529.         if(confirm('Yakin proses transaksi ini?')) {
  530.             $.ajax({
  531.                 type: 'POST',
  532.                 url: '<?=site_url('sale/process')?>',
  533.                 data: {'process_payment': true, 'customer_id': customer_id, 'subtotal': subtotal,
  534.                     'discount': discount, 'grandtotal': grandtotal, 'cash': cash, 'change': change,
  535.                     'note': note, 'date': date},
  536.                 dataType: 'json',
  537.                 success: function(result) {
  538.                     if(result.success) {
  539.                         alert('Transaksi berhasil');
  540.                        
  541.                     } else {
  542.                         alert('Transaksi gagal');
  543.                     }
  544.                     location.href='<?=site_url('sale')?>'
  545.                 }
  546.             })
  547.         }
  548.     }
  549. })
  550.  
  551. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement