View

View add_subcutting
mail@pastecode.io avatar
unknown
abap
2 years ago
16 kB
12
Indexable
Never
<div class="col-12">
  <div class="card">
    <div class="card-body">
      <div class="row pull-right">
        <div class="form-group">
          <label for="">Roll</label>
          <input class="form-control trp bg-danger text-black" type="text" name="total_roll" id="total_roll" readonly />
        </div>
        <div class="form-group">
          <label for="">Kg</label>
          <input class="form-control trp bg-danger text-black" type="text" name="total_kg" id="total_kg" readonly />
        </div>
        <input type="hidden" class="form-control" id="no_konsep" name="no_konsep" value="<?php echo $this->uri->segment(4); ?>">
      </div>
      <br>
      <button type="button" class="pull-left btn btn-info" data-toggle="modal" data-target="#modal_add">Tambah Data Cutting</button>
      </br>
      </br>
      <br>
      <div class="table-responsive">
        <table id="datatables" class="table table-bordered table-hover">
          <thead>
            <tr>
              <th style="text-align: left;">No.</th>
              <th>Konsep</th>
              <th>Bahan Baku</th>
              <th>ROLL</th>
              <th>KG</th>
              <th>Hasil</th>
              <th>Keterangan</th>
              <th>Dibuat</th>
              <th>Aksi</th>
            </tr>
          </thead>
          <tbody id="data_produkjual">

          </tbody>
        </table>

      </div>
      <div class="form-group text-center">
        <button class="col-md-4 btn btn-success add_databbb">Simpan Transaksi</button>
      </div>
      <a title="back" class="btn pull-right" href="<?= base_url() ?>Hpp"> <i class="fa fa-arrow-left"></i> </a>
    </div>

  </div>


</div>


</div>


<div class="modal fade" id="modal_add" tabindex="-1" role="dialog" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Tambah Data Cutting</h4>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <div class="alert alert-info">
          <button type="button" data-dismiss="alert" aria-hidden="true" class="close">×</button>
          <div class="icon hidden-xs">
            <i class="fa fa-info-circle"></i>
          </div>
          Silahkan Masukan Detail Bahan Baku, Untuk Bilangan Desimal Harus Menggunakan ( . ) Titik
        </div>
        <div class="row">
          <input type="hidden" name="no_konsep" class="form-control" id="no_konsep" value="<?php echo $this->uri->segment(4); ?>" />
          <input type="hidden" class="form-control" id="dibuat" name="dibuat" value="<?php echo $session = $this->session->userdata('namauser'); ?>" />
          <div class="form-group col-sm-6 col-md-3">
            <label>Bahan Baku</label>
            <select class="form-control dropdown" id="nama_bb" name="nama_bb">
              <option value="">Select Data</option>
              <?php foreach ($data_bahan as $roww) {
                echo '<option value="' . $roww['gabungan'] . '">' . $roww['gabungan'] . '</option>';
              }
              ?>

            </select>
          </div>
          <div class="form-group col-sm-6 col-md-3">
            <label for="harga_satuan">Harga Satuan</label>
            <input type="number" name="harga_satuan" class="form-control" id="harga_satuan" readonly onkeyup="sum();" />
          </div>
          <div class="form-group col-sm-6 col-md-3">
            <label for="harga_satuan">Stok (Roll)</label>
            <input type="text" name="jmlh_roll" class="form-control" id="jmlh_roll" readonly />
          </div>
          <div class="form-group col-sm-6 col-md-3">
            <label for="harga_satuan">Stok (KG)</label>
            <input type="text" name="jmlh_kg" class="form-control" id="jmlh_kg" readonly />
          </div>
        </div>
        <div class="row">

          <div class="form-group col-sm-6 col-md-3">
            <label>ROLL</label>
            <input class="form-control" type="number" name="jmlh_pakai_roll" id="jmlh_pakai_roll" required>
          </div>
          <div class="form-group col-sm-6 col-md-3">
            <label>KG</label>
            <input class="form-control" type="text" name="jmlh_pakai_kg" id="jmlh_pakai_kg" required onkeyup="sum();">
          </div>
          <div class="form-group col-sm-6 col-md-3">
            <label for="">Hasil</label>
            <input class="form-control" type="text" name="estimasi_hasil" id="estimasi_hasil" required>
          </div>
          <div class="form-group col-sm-6 col-md-3">
            <label for="">Keterangan</label>
            <input class="form-control" type="text" name="keterangan_cutting" id="keterangan_cutting" required>
          </div>
          <input type="hidden" name="sub_totalbbb" class="form-control" id="sub_totalbbb" readonly>
        </div>
      </div>
      <div class="modal-footer justify-content-between">
        <button type="button" class="btn btn-primary btn-block add_subcutting">Tambah</button>
      </div>
    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<script src="<?= base_url() ?>assets/js/core/jquery.3.2.1.min.js"></script>
<script>
  function number_format(number, decimals, dec_point, thousands_sep) {
    // Strip all characters but numerical ones.
    number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
      prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
      sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
      dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
      s = '',
      toFixedFix = function(n, prec) {
        var k = Math.pow(10, prec);
        return '' + Math.round(n * k) / k;
      };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
      s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
      s[1] = s[1] || '';
      s[1] += new Array(prec - s[1].length + 1).join('0');
    }
    return s.join(dec);
  }
  /* Fungsi */
  function formatRupiah(angka, prefix) {
    var number_string = angka.replace(/[^,\d]/g, '').toString(),
      split = number_string.split(','),
      sisa = split[0].length % 3,
      rupiah = split[0].substr(0, sisa),
      ribuan = split[0].substr(sisa).match(/\d{3}/gi);

    if (ribuan) {
      separator = sisa ? '.' : '';
      rupiah += separator + ribuan.join('.');
    }

    rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
    return prefix == undefined ? rupiah : (rupiah ? 'Rp. ' + rupiah : '');
  }
  $(document).ready(function() {
    $.ajaxSetup({
      data: {
        '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
      }
    });
    // FUNGSI ON CHANGE
    $('#nama_bb').on('change', function() {

      var nama_bb = $(this).val();
      $.ajax({
        type: "POST",
        url: "<?php echo base_url('Konsep/get_all_bahan') ?>",
        dataType: "JSON",
        data: {
          gabungan: $(this).val()
        },
        cache: false,
        success: function(data) {
          $('input[name="jmlh_kg"]').val(data.jmlh_kg)
          $('input[name="jmlh_roll"]').val(data.jmlh_roll)
          $('input[name="harga_satuan"]').val(data.harga_satuan)
        }
      });
      return false;
    });

    console.log()
    show_bbb(); //
    var dtable;
    //function show all product
    function show_bbb() {
      var no_konsep = $("#no_konsep").val();
      var token = '<?php echo $this->security->get_csrf_hash() ?>';

      $.ajax({

        type: 'POST',
        url: '<?php echo site_url('Konsep/getdataSubCutting') ?>',
        async: false,
        dataType: 'json',
        data: {
          no_konsep: no_konsep,
          csrf: token
        },
        // beforeSend: function(){
        //   swal({
        //     title: 'Tunggu',
        //     allowEscapeKey: false,
        //     allowOutsideClick: false,
        //     onOpen: () => {
        //       swal.showLoading();
        //     }
        //   })
        // },
        success: function(data) {
          var html = '';
          var i;
          var no;
          var total = 0;
          var totalroll = 0;
          var totalkg = 0;
          no = 0;
          dtable = $('#datatables').DataTable().clear().destroy();
          for (i = 0; i < data.length; i++) {
            no++;
            html += '<tr>' +
              '<td style="text-left: right; width:70px;">' + no + '</td>' +


              '<td>' + data[i].no_konsep + '</td>' +
              '<td>' + data[i].nama_bb + '</td>' +
              '<td>' + data[i].jmlh_roll + '</td>' +
              '<td>' + data[i].jmlh_kg + '</td>' +
              '<td>' + data[i].estimasi_hasil + '</td>' +
              '<td>' + data[i].keterangan_cutting + '</td>' +
              '<td>' + data[i].dibuat + '</td>' +
              '<td style="width:150px;">' +

              '<a title="Delete Data" href="javascript:void(0);" class="btn btn-link btn-danger btn-sm delete_data" data-id="' + data[i].id + '"  data-no_konsep="' + data[i].no_konsep + '"><i class="fa fa-trash"></i></a>' +
              '</td>' +

              '</tr>';
            totalroll += parseInt(data[i].jmlh_roll);
            totalkg += parseFloat(data[i].jmlh_kg);


          }
          subtotalroll = Math.round(totalroll);
          subtotalkg = Math.round(totalkg);


          $('#data_produkjual').html(html);
          $('#total_roll').val((totalroll));
          $('#total_kg').val((totalkg));

          dtable = $('#datatables').dataTable({
            "paging": true,
            "ordering": false,
            "info": false,
            "searching": false,
            "aLengthMenu": [
              [5, 10, 25, 50, 75, -1],
              [5, 10, 25, 50, 75, "All"]
            ]
          });
          swal.close();

        }

      });
    }
    $('.datepicker1').datepicker({
      autoclose: true,
      todayHighlight: true,
      format: "dd-mm-yyyy",
      orientation: "bottom"
    });
    $('.datepicker1').datepicker("setDate", new Date());
    $('.dropdown').each(function() {
      $(this).select2({
        theme: "bootstrap",

        placeholder: "Select Data"
      });
    });

    $("#no_konsep").on('change', function() {
      $(".tanggal").show();
      $(".dibuat").show();
    });


    //Save
    $('.add_subcutting').on('click', function(e) {
      e.preventDefault(); //Prevent Default Submission

      var no_konsep = $("#no_konsep").val();
      var nama_bb = $('#nama_bb').val();
      var jmlh_pakai_roll = $('#jmlh_pakai_roll').val();
      var jmlh_pakai_kg = $('#jmlh_pakai_kg').val();
      var estimasi_hasil = $('#estimasi_hasil').val();
      var keterangan_cutting = $('#keterangan_cutting').val();
      var dibuat = $('#dibuat').val();
      var token = '<?php echo $this->security->get_csrf_hash() ?>';
      console.log(nama_bb);
      console.log(jmlh_pakai_roll);
      console.log(jmlh_pakai_kg);
      console.log(estimasi_hasil);
      console.log(keterangan_cutting);

      $.ajax({
        type: "POST",
        url: "<?php echo site_url('Konsep/add_subcutting') ?>",
        data: {
          no_konsep: no_konsep,
          nama_bb: nama_bb,
          jmlh_pakai_roll: jmlh_pakai_roll,
          jmlh_pakai_kg: jmlh_pakai_kg,
          estimasi_hasil: estimasi_hasil,
          keterangan_cutting: keterangan_cutting,
          dibuat: dibuat,
          csrf: token
        },
        beforeSend: function() {
          swal({
            title: 'Tunggu',
            allowEscapeKey: false,
            allowOutsideClick: false,
            onOpen: () => {
              swal.showLoading();
            }
          })
        },
        success: function(html) {
          if (html == 'masukmasuk') {
            swal({
              type: 'success',
              title: 'Data Berhasil Di Tambahkan',
              showConfirmButton: false,
              timer: 1500
            }).then(function() {
              window.location.href = '<?= base_url() ?>Konsep';
            });

          } else if (html == 'gagal') {

            swal({
              type: 'error',
              title: 'Pengurangan Pemakaian Bahan Gagal!',
              text: 'Stok Tidak Mencukupi,Silahkan Konfirmasi Ke Gudang',
              showConfirmButton: true
            }).then(function() {
              window.location.href = '<?= base_url() ?>Konsep/Cutting';
            });


          }
        }
      });
      return false;
    });

    //Save
    $('.add_databbb').on('click', function(e) {
      e.preventDefault(); //Prevent Default Submission
      var no_konsep = $('#no_konsep').val();
      var total_roll = $('#total_roll').val();
      var total_roll = $('#total_roll').val();
      var total_kg = $('#total_kg').val();
      var total_pakai = $('#total_pakai').val();
      var token = '<?php echo $this->security->get_csrf_hash() ?>';

      $.ajax({
        type: "POST",
        url: "<?php echo site_url('Hpp/add_data_bb') ?>",
        data: {
          no_konsep: no_konsep,
          total_roll: total_roll,
          total_kg: total_kg,
          total_pakai: total_pakai,
          csrf: token
        },
        beforeSend: function() {
          swal({
            title: 'Tunggu',
            allowEscapeKey: false,
            allowOutsideClick: false,
            onOpen: () => {
              swal.showLoading();
            }
          })
        },
        success: function(data) {

          swal({
            type: 'success',
            title: 'Data Berhasil Di Tambahkan',
            showConfirmButton: false,
            timer: 1500
          }).then(function() {
            window.location.href = '<?= base_url() ?>Hpp';
          });




        }
      });
      return false;
    });



    $('#data_produkjual').on('click', '.delete_data', function() {

      var id = $(this).data('id');
      var no_konsep = $(this).data('no_konsep');
      var token = '<?php echo $this->security->get_csrf_hash() ?>';


      swal({
        title: 'Yakin Akan Hapus Data Ini?',
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#3085d6',
        cancelButtonColor: '#d33',
        confirmButtonText: 'Yes',
      }).then((result) => {
        if (result.value) {
          $.ajax({
            type: "POST",
            url: "<?= site_url('Hpp/delete_subbb') ?>",
            data: {
              id: id,
              csrf: token
            },
            beforeSend: function() {
              swal({
                title: 'Tunggu',
                allowEscapeKey: false,
                allowOutsideClick: false,
                onOpen: () => {
                  swal.showLoading();
                }
              })
            },
            success: function(html) {

              swal({
                type: 'success',
                title: 'Data Berhasil Dihapus',
                showConfirmButton: false,
                timer: 1500
              }).then(function() {
                show_bbb();
              });
            }

          });


          return false;
        }

      })



    });

  });

  function sum() {
    var txtFirstNumberValue = document.getElementById('harga_satuan').value;
    var txtSecondNumberValue = document.getElementById('jmlh_pakai_kg').value;
    var result = parseFloat(txtFirstNumberValue) * parseFloat(txtSecondNumberValue);
    if (!isNaN(result)) {
      document.getElementById('sub_totalbbb').value = result;
    }
  }
</script>