fadlyshafa

Untitled

Jun 21st, 2020
1,347
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.  
  3.   var yi = 0; /* Set Global Variable i */
  4.   var j = 0; /* Set Global Variable i */
  5.   var k = 0; /* Set Global Variable i */
  6.   var product_data = new Array();
  7.   var additional_data = new Array();
  8.   var service_data = new Array();
  9.  
  10.   function storedatatemp()
  11.   {
  12.     var container = document.getElementById("kurscontainer");
  13.     var children = container.childNodes;
  14.  
  15.     var e = document.getElementById("terminnumber");
  16.     var number2 = e.options[e.selectedIndex].value;
  17.     var container2 = document.getElementById("termincontainer");
  18.  
  19.  
  20.     var iyv = 0;
  21.     var iyx = 0;
  22.     var iyy = 0;
  23.     var iyz = 0;
  24.     var iya = 0;
  25.     var iyb = 0;
  26.  
  27.     for (ik = 0; ik < number2; ik++)
  28.     {
  29.       var a = document.getElementsByName("terminvalue[]"), i;
  30.       localStorage.removeItem("terminvalue" + ik);
  31.       localStorage.setItem("terminvalue" + ik, a[ik].value);
  32.       var b = document.getElementsByName("tanggalterminvalue[]"), i;
  33.       localStorage.removeItem("tanggalterminvalue" + ik);
  34.       localStorage.setItem("tanggalterminvalue" + ik, b[ik].value);
  35.       var c = document.getElementsByName("terminket[]"), i;
  36.       localStorage.removeItem("terminket" + ik);
  37.       localStorage.setItem("terminket" + ik, c[ik].value);
  38.     }
  39.  
  40.  
  41.     for (var im = 0; im < children.length; im++)
  42.     {
  43.  
  44.       if (children[im].tagName == "INPUT" && children[im].name == 'kursdatavalue[]')
  45.       {
  46.         var v = document.getElementsByName("kursdatavalue[]"), i;
  47.         localStorage.removeItem("kursdatavalue" + iyv);
  48.         localStorage.setItem("kursdatavalue" + iyv, v[iyv].value);
  49.         iyv++;
  50.       }
  51.  
  52.  
  53.     }
  54.  
  55.   }
  56.  
  57.   $(document).ready(function () {
  58.     $('#customer').val(<?php echo $data[0]->customer_id; ?>).trigger('change');
  59.  
  60.     $('input[name=paymenterms][value=<?php echo $data[0]->paid_by; ?>]').prop('checked', true).click();
  61.     if ('termin' == '<?php echo $data[0]->paid_by; ?>') {
  62.  
  63.       var e = document.getElementById("terminnumber");
  64.       var number = e.options[e.selectedIndex].value;
  65.       getfromaddFields = number;
  66.       var container = document.getElementById("termincontainer");
  67.       while (container.hasChildNodes())
  68.       {
  69.         container.removeChild(container.lastChild);
  70.       }
  71.       $("#kursdata").val(<?php echo $data[0]->kurs_id; ?>).trigger('change');
  72.  
  73.       var mode_of_transport = $("#mode_of_transport").val();
  74.       var transporter_name = $("#transporter_name").val();
  75.       var transporter_code = $("#transporter_code").val();
  76.       var vehicle_regn_no = $("#vehicle_regn_no").val();
  77.       if (mode_of_transport || transporter_name || vehicle_regn_no) {
  78.         $("#transporter").prop('checked', false).click();
  79.       }
  80.  
  81.       var container = container.appendChild(document.createElement("table"));
  82.       container.className = "table table-bordered";
  83.       var container = container.appendChild(document.createElement("tbody"));
  84.       var artermin = <?php echo json_encode($termin); ?>;
  85.       for (i = 0; i < number; i++)
  86.       {
  87.         var containertr = container.appendChild(document.createElement("tr"));
  88.         var containertd = containertr.appendChild(document.createElement("td"));
  89.         z = document.createElement('span');
  90.         z.innerHTML = "Termin Ke  % " + (i + 1) + "  :";
  91.         z.className = "text-danger";
  92.         containertd.appendChild(z);
  93.         var input = document.createElement("input");
  94.         input.type = "number";
  95.         input.name = "terminvalue[" + (i + 1) + "]";
  96.         input.id = "terminvalue[" + (i + 1)+"]";
  97.         input.className = "getterminvalue";
  98.         input.value = artermin[i].persen;
  99.         input.min = 1;
  100.         input.max = 100;
  101.         input.maxlength = "2";
  102.         // input.onkeypress = isNumber_max_100;
  103.         var containertd = containertr.appendChild(document.createElement("td"));
  104.         containertd.appendChild(input);
  105.         z = document.createElement('span');
  106.         z.className = "text-primary";
  107.         z.innerHTML = ' Ket: ';
  108.         var containertd = containertr.appendChild(document.createElement("td"));
  109.         containertd.appendChild(z);
  110.         var input2 = document.createElement("input");
  111.         input2.type = "text";
  112.         input2.name = "terminket[" + (i + 1) + "]";
  113.         input2.id = "terminket[" + (i + 1)+"]";
  114.         input2.className = "getterminket";
  115.         input2.value = artermin[i].keterangan;
  116.         var containertd = containertr.appendChild(document.createElement("td"));
  117.         containertd.appendChild(input2);
  118.       }
  119.     }
  120.  
  121.     var counter = 1;
  122.     var aritem = <?php echo json_encode($items); ?>;
  123.     console.log(aritem);
  124.     for (itemrec = 0; itemrec < aritem.length; itemrec++) {
  125.       (function (counter) {
  126.         var getnewRow;
  127.         var quotationid = aritem[itemrec].id;
  128.         var itemquantity = aritem[itemrec].qty;
  129.         var itemprice = aritem[itemrec].qprice;
  130.         var itemdiscountid = aritem[itemrec].discount_id;
  131.         var desc = aritem[itemrec].serial_no;
  132.         var itemdiscountvalue = aritem[itemrec].discount_value;
  133.         var itemdiscount = aritem[itemrec].discount;
  134.         var itemgross_total = aritem[itemrec].gross_total;
  135.         var product_id = aritem[itemrec].product_id;
  136.         var flag = 0;
  137.         $('#err_product').text('');
  138.         $.ajax({
  139.           async : false,
  140.           url: "<?php echo base_url('sales/getProduct_old') ?>/" + product_id,
  141.           type: "GET",
  142.           dataType: "JSON",
  143.           data: {
  144.             '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  145.           },
  146.           success: function (data) {
  147.             $("table.product_table").find('input[name^="product_id"]').each(function () {
  148.               // if (data[0].product_id == +$(this).val()) {
  149.               //   flag = 1;
  150.               // }
  151.             });
  152.             if (flag == 0) {
  153.               var id = data[0].product_id;
  154.               var price = itemprice;
  155.               var code = data[0].code;
  156.               var name = data[0].name;
  157.               var product_bonus = data[0].product_bonus;
  158.               var item_namebyp = data[0].item_namebyp;
  159.               var product = {"product_id": id,
  160.               "price": price
  161.             };
  162.  
  163.             // discount
  164.             //de
  165.             // item_discount
  166.             // discount_value
  167.  
  168.             product_data[yi] = product;
  169.             length = product_data.length - 1;
  170.  
  171.             var select_discount = "";
  172.             select_discount += '<div class="form-group">';
  173.             select_discount += '<select class="form-control select2" id="item_discount" name="item_discount'+ counter +'" style="width: 100%;">';
  174.             select_discount += '<option value="">Select</option>';
  175.             var selected = '';
  176.             for (a = 0; a < data['discount'].length; a++) {
  177.               if (data['discount'][a].discount_id == itemdiscountid) {
  178.                 selected = 'selected ';
  179.               } else {
  180.                 selected = '';
  181.               }
  182.               select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  183.             }
  184.             select_discount += '</select></div>';
  185.  
  186.             var select_bonus = "";
  187.             select_bonus += '<div class="form-group">';
  188.             select_bonus += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
  189.             select_bonus += '<option value="">Select</option>';
  190.             for (a = 0; a < data['bonus1'].length; a++) {
  191.               select_bonus += '<option ' + selected + 'value="' + data['bonus1'][a].product + '">' + data['bonus1'][a].product_bonus + '</option>';
  192.             }
  193.            
  194.             select_bonus += '</select></div>';
  195.            
  196.             var newRow = $("<tr id='tr" + yi + "'>");
  197.             var cols = "";
  198.             cols += "<td><a class='deleteRow'> <img src='<?php echo base_url(); ?>assets/images/bin3.png' /> </a><input type='hidden' name='id' name='id' value=" + yi + "><input type='hidden' name='product_id' name='product_id' value=" + id + "></td>";
  199.             cols += "<td>" + code + "</td>";
  200.             cols += "<td>"
  201.             + "<input type='hidden' value='" + data[0].name + "' name='nameProduct" + counter + "' id='nameProduct" + counter + "'>"
  202.             + "<input type='hidden' value='" + data[0].product_id + "' name='idProduct" + counter + "' id='idProduct" + counter + "'>"
  203.             + name + "</td>";
  204.  
  205.            
  206.             // total
  207.             // "<input type='hidden' value='" + data[0].name + "' name='penanda[]' id=''>";
  208.            
  209.             cols += "<td><input type='hidden' id='discount_value' name='discount_value'><input type='hidden' id='hidden_discount' name='hidden_discount'>" + select_bonus + "<input type='hidden' value='" + id + "' name='idProducts[]' id='idProduct[]'><input type='hidden' class='form-control text-center' value='" + itemquantity + "' data-rule='quantity' name='quantitys[]' id='qty[]' min='1' max='" + itemquantity + "'><input step='0.01' type='hidden' class='form-control text-right' value='" + price + "' name='prices[]' id='price[]'></td><input type='hidden' class='form-control text-right' style='' value='" + itemgross_total + "' name='totals[]' id='total[]'>";
  210.  
  211.             // tambahan
  212.             // cols += "";
  213.  
  214.             // cols += "";
  215.  
  216.             // cols += "";
  217.  
  218.             // cols += "";
  219.  
  220.             // cols += "<input type='hidden' id='hidden_discount' name='hidden_discount' value='"+data['discount'][a].discount_id+"'>";
  221.  
  222.             cols += "<input value='" + itemdiscountvalue + "' type='hidden' id='discount_value' name='discount_values"+ counter +"'>";
  223.             // end tambahan
  224.            
  225.             cols += "<td><input type='text' name='description" + counter + "' id='description"+ counter + "' value='" + desc + "' class='form-control'></td>";
  226.             cols += "<td>"
  227.             + "<input type='number' class='form-control text-center' value='" + itemquantity + "' data-rule='quantity' name='qty" + counter + "' id='qty" + counter + "' min='1' max='" + itemquantity + "'>"
  228.             + "</td>";
  229.             cols += "<td>" + data[0].quantity
  230.             + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'>"
  231.             + "</td>";
  232.             cols += "<td>" + data[0].unit + "</td>";
  233.             cols += "<td align='right'>"
  234.             + "<span>"
  235.             + "<input step='0.01' type='text' class='form-control text-right' value='" + price + "' name='price" + counter + "' id='price" + counter + "'>"
  236.             + "</span>"
  237.             + "</td>";
  238.             cols += "<td>"
  239.             + "<span id='sub_total'>"
  240.             + "<input type='text' class='form-control text-right subtotal' style='' value='" + itemgross_total + "' name='linetotal" + counter + "' id='linetotal" + counter + "' readonly>"
  241.             + "</span>"
  242.             + "</td>";
  243.             cols += '<td><input value="' + itemdiscountvalue + '" type="hidden" id="discount_value" name="discount_value"><input type="hidden" id="hidden_discount" name="hidden_discount">' + select_discount + '</td>';
  244.            
  245.             cols += '<td><input type="text" class="form-control text-right salestotal" id="product_total" name="product_total" readonly>';
  246.  
  247.  
  248.  
  249.             cols += '</td>';
  250.            
  251.             cols += "</tr>";
  252.  
  253.            
  254.  
  255.             newRow.append(cols);
  256.             getnewRow = newRow;
  257.             $("table.product_table").append(newRow);
  258.             calculateRow($('tr#tr' + yi));
  259.             $.calculateDiscount($('tr#tr' + yi));
  260.             $.calculateGrandTotal();
  261.             counter++;
  262.             var table_data = JSON.stringify(product_data);
  263.             $('#table_data').val(table_data);
  264.             yi++;
  265.           } else {
  266.             $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  267.           }
  268.         }
  269.       });
  270. })(itemrec);
  271. }
  272.  
  273. var aritem = <?php echo json_encode($additional); ?>;
  274. for (itemrec = 0; itemrec < aritem.length; itemrec++) {
  275.   (function (counter) {
  276.     var getnewRow;
  277.     var quotationid = aritem[itemrec].id;
  278.     var itemquantity = aritem[itemrec].quantity;
  279.     var itemprice = aritem[itemrec].qprice;
  280.     var itemdiscountid = aritem[itemrec].discount_id;
  281.     var desc = aritem[itemrec].desc;
  282.     var itemdiscountvalue = aritem[itemrec].discount_value;
  283.     var itemdiscount = aritem[itemrec].discount;
  284.    
  285.     var itemgross_total = aritem[itemrec].gross_total;
  286.     var product_id = aritem[itemrec].product_id;
  287.     var flag = 0;
  288.     $('#err_product').text('');
  289.     $.ajax({
  290.       async : false,
  291.       url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
  292.       type: "GET",
  293.       dataType: "JSON",
  294.       data: {
  295.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  296.       },
  297.       success: function (data) {
  298.         $("table.additional_table").find('input[name^="additional_id"]').each(function () {
  299.           // if (data[0].product_id == +$(this).val()) {
  300.           //   flag = 1;
  301.           // }
  302.         });
  303.         if (flag == 0) {
  304.           var id = data[0].product_id;
  305.           var price = itemprice;
  306.           var code = data[0].code;
  307.           var name = data[0].name;
  308.           var item_namebyp = data[0].item_namebyp;
  309.  
  310.           var product = {"additional_id": id,
  311.           "price": price
  312.         };
  313.         additional_data[j] = product;
  314.         length = additional_data.length - 1;
  315.         var select_discount = "";
  316.         select_discount += '<div class="form-group">';
  317.         select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
  318.         select_discount += '<option value="">Select</option>';
  319.         var selected = '';
  320.         for (a = 0; a < data['discount'].length; a++) {
  321.           if (data['discount'][a].discount_id == itemdiscountid) {
  322.             selected = 'selected ';
  323.           } else {
  324.             selected = '';
  325.           }
  326.           select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  327.         }
  328.         select_discount += '</select></div>';
  329.  
  330.         var newRow = $("<tr id='tra" + j + "'>");
  331.         var cols = "";
  332.         cols += "<td><a class='deleteRow'> <img src='<?php echo base_url(); ?>assets/images/bin3.png' /> </a><input type='hidden' name='id' name='id' value=" + j + "><input type='hidden' name='product_id' name='product_id' value=" + id + "></td>";
  333.         cols += "<td>" + code + "</td>";
  334.         cols += "<td>"
  335.         + "<input type='hidden' value='" + data[0].name + "' name='nameProduct" + counter + "' id='nameProduct" + counter + "'>"
  336.         + "<input type='hidden' value='" + data[0].product_id + "' name='idProduct" + counter + "' id='idProduct" + counter + "'>"
  337.         + name + "</td>";
  338.         cols += "<td>" + item_namebyp + "</td>";
  339.         cols += "<td><input type='text' name='description" + counter + "' id='description"+ counter + "' value='" + desc + "' class='form-control'></td>";
  340.         cols += "<td>"
  341.         + "<input type='number' class='form-control text-center' value='" + itemquantity + "' data-rule='quantity' name='qty" + counter + "' id='qty" + counter + "' min='1' max='" + itemquantity + "'>"
  342.         + "</td>";
  343.         cols += "<td>" + data[0].quantity
  344.         + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'>"
  345.         + "</td>";
  346.         cols += "<td>" + data[0].unit + "</td>";
  347.         cols += "<td align='right'>"
  348.         + "<span>"
  349.         + "<input step='0.01' type='text' class='form-control text-right' value='" + price + "' name='price" + counter + "' id='price" + counter + "'>"
  350.         + "</span>"
  351.         + "</td>";
  352.         cols += "<td>"
  353.         + "<span id='sub_total'>"
  354.         + "<input type='text' class='form-control text-right' style='' value='" + itemgross_total + "' name='linetotal" + counter + "' id='linetotal" + counter + "' readonly>"
  355.         + "</span>"
  356.         + "</td>";
  357.         cols += '<td><input value="' + itemdiscountvalue + '" type="hidden" id="discount_value" name="discount_value"><input type="hidden" id="hidden_discount" name="hidden_discount">' + select_discount + '</td>';
  358.  
  359.         cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
  360.         cols += "</tr>";
  361.  
  362.         newRow.append(cols);
  363.         getnewRow = newRow;
  364.         $("table.additional_table").append(newRow);
  365.         calculateRowAdditional($('tr#tra' + j));
  366.         $.calculateDiscountAdditional($('tr#tra' + j));
  367.         $.calculateGrandTotal();
  368.         counter++;
  369.         var table_data = JSON.stringify(additional_data);
  370.         $('#tableadditional_data').val(table_data);
  371.         j++;
  372.       } else {
  373.         $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  374.       }
  375.     }
  376.   });
  377. })(itemrec);
  378. }
  379.  
  380. var aritem = <?php echo json_encode($serviceitems); ?>;
  381. for (itemrec = 0; itemrec < aritem.length; itemrec++) {
  382.   (function (counter) {
  383.     var getnewRowService;
  384.     var quotationid = aritem[itemrec].id;
  385.     var itemquantity = aritem[itemrec].quantity;
  386.     var itemprice = aritem[itemrec].price;
  387.     var itemdiscountid = aritem[itemrec].discount_id;
  388.     var itemdiscountvalue = aritem[itemrec].discount_value;
  389.     var itemdiscount = aritem[itemrec].discount;
  390.  
  391.     var itemgross_total = aritem[itemrec].gross_total;
  392.     var service_id = aritem[itemrec].service_id;
  393.     var flag = 0;
  394.     $('#err_service').text('');
  395.     $.ajax({
  396.       url: "<?php echo base_url('sales/getService') ?>/" + service_id,
  397.       type: "GET",
  398.       dataType: "JSON",
  399.       data: {
  400.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  401.       },
  402.       success: function (data) {
  403.  
  404.         $("table.service_table").find('input[name^="service_id"]').each(function () {
  405.           if (data[0].service_id == +$(this).val()) {
  406.             flag = 1;
  407.           }
  408.         });
  409.         if (flag == 0)
  410.         {
  411.           var id = data[0].service_id;
  412.           var code = data[0].code;
  413.           var name = data[0].service_title;
  414.           var hsn_sac_code = '';
  415.           var price = itemprice;
  416.           var tax_id = data[0].tax_id;
  417.           var tax_value = data[0].tax_value;
  418.           if (tax_value == null) {
  419.             tax_value = 0;
  420.           }
  421.           var product = {"service_id": id,
  422.           "price": price
  423.         };
  424.         service_data[k] = product;
  425.         length = service_data.length - 1;
  426.         var select_discount = "";
  427.         select_discount += '<div class="form-group">';
  428.         select_discount += '<select class="form-control select2" id="item_discountservice" name="item_discountservice" style="width: 100%;">';
  429.         select_discount += '<option value="">Select</option>';
  430.         var selected = '';
  431.         for (a = 0; a < data['discount'].length; a++) {
  432.           if (data['discount'][a].discount_id == itemdiscountid) {
  433.             selected = 'selected ';
  434.           } else {
  435.             selected = '';
  436.           }
  437.           select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  438.         }
  439.         select_discount += '</select></div>';
  440.  
  441.         var newRowService = $("<tr id='trv" + counter + "'>");
  442.         var cols = "";
  443.         cols += "<td><a class='deleteRow'> <img src='<?php echo base_url(); ?>assets/images/bin3.png' /> </a><input type='hidden' name='idservice' value=" + k + "><input type='hidden' name='service_id' name='service_id' value=" + id + "></td>";
  444.         cols += "<td>" + code + "</td>";
  445.         cols += "<td>"
  446.         + "<input type='hidden' value='' name='nameService" + counter + "' id='nameService" + counter + "'>"
  447.         + name + "</td>";
  448.         cols += "<td>"
  449.         + "<input type='number' class='form-control text-center' value='" + itemquantity + "' data-rule='quantity' name='qtyservice" + counter + "' id='qtyservice" + counter + "' min='0' max='2'>"
  450.         + "</td>";
  451.         cols += "<td align='right'>"
  452.         + "<span id='price'>"
  453.         + "<input step='0.01' type='text' class='form-control text-right' name='priceservice" + counter + "' id='priceservice" + counter + "' value='" + price
  454.         + "'>"
  455.         + "</span>"
  456.         + "</td>";
  457.         cols += "<td>"
  458.         + "<span id='sub_total'>"
  459.         + "<input type='text' class='form-control text-right' style='' value='" + itemgross_total + "' name='linetotalservice" + counter + "' id='linetotalservice" + counter + "' readonly>"
  460.         + "</span>"
  461.         + "</td>";
  462.         cols += '<td><input type="hidden" value="' + itemdiscountvalue + '" id="discountservice_value" name="discountservice_value"><input type="hidden" id="hidden_discountservice" name="hidden_discountservice">' + select_discount + '</td>';
  463.  
  464.         cols += '<td><input type="text" class="form-control text-right" id="service_total" name="service_total" readonly></td>';
  465.         cols += "</tr>";
  466.         newRowService.append(cols);
  467.         getnewRowService = newRowService;
  468.         $("table.service_table").append(newRowService);
  469.         calculateRowService($('tr#trv' + counter));
  470.         $.calculateDiscountService($('tr#trv' + counter));
  471.         $.calculateGrandTotal();
  472.         counter++;
  473.         var table_data = JSON.stringify(service_data);
  474.         $('#tableservice_data').val(table_data);
  475.         k++;
  476.       } else {
  477.         $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  478.       }
  479.     }
  480.   });
  481. })(itemrec);
  482. }
  483.  
  484. function calculateRow(row) {
  485.  
  486.   var key = +row.find('input[name^="id"]').val();
  487.   var price = +row.find('input[name^="price"]').val();
  488.   var desc = row.find('input[name^="description"]').val();
  489.   var qty = +row.find('input[name^="qty"]').val();
  490.  
  491.   row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
  492.   product_data[key].quantity = qty;
  493.   product_data[key].desc = desc;
  494.   product_data[key].total = (price * qty).toFixed(2);
  495.   var table_data = JSON.stringify(product_data);
  496.   $('#table_data').val(table_data);
  497. }
  498.  
  499. function calculateRowAdditional(row) {
  500.  
  501.   var key = +row.find('input[name^="id"]').val();
  502.   var price = +row.find('input[name^="price"]').val();
  503.   var desc = row.find('input[name^="description"]').val();
  504.   var qty = +row.find('input[name^="qty"]').val();
  505.  
  506.   row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
  507.   additional_data[key].quantity = qty;
  508.   additional_data[key].desc = desc;
  509.   additional_data[key].total = (price * qty).toFixed(2);
  510.   var table_data = JSON.stringify(additional_data);
  511.   $('#tableadditional_data').val(table_data);
  512. }
  513.  
  514. function calculateRowService(row)
  515. {
  516.   var key = +row.find('input[name^="idservice"]').val();
  517.   var price = +row.find('input[name^="priceservice"]').val();
  518.   var qty = +row.find('input[name^="qtyservice"]').val();
  519.   var total = +row.find('input[name^="linetotalservice"]').val();
  520.   row.find('input[name^="linetotalservice"]').val((price * qty).toFixed(2));
  521.   service_data[key].price = price;
  522.   service_data[key].quantity = qty;
  523.   service_data[key].total = total;
  524.   var table_data = JSON.stringify(service_data);
  525.   $('#tableservice_data').val(table_data);
  526. }
  527.  
  528. });
  529.  
  530.  
  531.  
  532. $(document).ready(function () {
  533.   $("button#submitBooking").click(function (e) {
  534.     if (e.target instanceof HTMLAnchorElement)
  535.       e.preventDefault();
  536.     $.ajax({
  537.       type: "POST",
  538.       url: "<?php echo base_url('item_request/addSales') ?>",
  539.       data: $('form.bookingmodal').serialize(),
  540.       success: function (message) {
  541.         alert(message);
  542.  
  543.         var formObj = {};
  544.         var inputs = $('form.bookingmodal').serializeArray()
  545.         $.each(inputs, function (i, input) {
  546.           formObj[input.name] = input.value;
  547.         });
  548.         var qty = +$('#'+formObj.type).find('input[name^="available_quantity"]').val();
  549.         var z = +formObj.qty + +qty;
  550.         $('#'+formObj.type).find('input[name^="qty"]').attr("max", z);
  551.         $('#'+formObj.type).find('input[name^="qty"]').val(z);
  552.  
  553.         $("#bookingmodal").modal('hide');
  554.       },
  555.       error: function () {
  556.         alert("Error");
  557.       }
  558.     });
  559.     return false;
  560.   });
  561.  
  562.  
  563.   $(document).on('change', '#kursdata', function ()
  564.   {
  565.     $.calculateGrandTotal();
  566.  
  567.   });
  568.  
  569.   $(document).on('change', '#taxx', function ()
  570.   {
  571.     $.calculateGrandTotal();
  572.  
  573.   });
  574.  
  575.   $(document).on('keyup', '#shipping_charge', function ()
  576.   {
  577.     $.calculateGrandTotal();
  578.   });
  579.   $(document).on('keyup', '#totalDiscountUmum', function ()
  580.   {
  581.     $.calculateGrandTotal();
  582.   });
  583.   $(document).on('keyup', '#DiscountFix', function ()
  584.   {
  585.     $.calculateGrandTotal();
  586.   });
  587.   $(document).on('keyup', '#diskonpersen_text', function ()
  588.   {
  589.     var diskonval = 0;
  590.     var diskonval2 = 0;
  591.     var diskonpersen = 0;
  592.     diskonpersen = $('#diskonpersen_text').val();
  593.     $.calculateGrandTotal();
  594.     diskonval2 = $('#grand_total').val();
  595.     diskonval = (diskonpersen / 100) * diskonval2;
  596.     $('#totalDiscountUmum').text(diskonval.toFixed(2));
  597.     $('#totalDiscountUmum').val(diskonval.toFixed(2));
  598.     $.calculateGrandTotal();
  599.   });
  600.   $(document).on('keyup', '#DiscountPersen', function ()
  601.   {
  602.     $.calculateGrandTotal();
  603.   });
  604. });
  605. </script>
  606. <script type="text/javascript">
  607.   $(document).ready(function () {
  608.  
  609.     $(".getterminvalue").on("change paste", function () {
  610.       var id_data = $(this).attr("id");
  611.       var valdata_cek = $(this).val();
  612.       if (valdata_cek.match(/^\d+$/)) {
  613.         $(".getterminvalue").each(function (index, element) {
  614.           valueget = $(element).val();
  615.  
  616.         })
  617.       } else {
  618.         alert('Data Must Numeric');
  619.       }
  620.  
  621.     });
  622.  
  623.     //datepicker
  624.     $('.datepicker').datepicker({
  625.       autoclose: true,
  626.       format: "yyyy-mm-dd",
  627.       todayHighlight: true,
  628.       orientation: "auto",
  629.       todayBtn: true,
  630.       todayHighlight: true,
  631.     });
  632.   });
  633.   function transport() {
  634.     $('.transporter').toggle();
  635.   }
  636. </script>
  637. <!-- close datepicker  -->
  638. <script>
  639.   function addRevisi() {
  640.     var e = document.getElementById("status");
  641.     var number = e.options[e.selectedIndex].value;
  642.  
  643.     if (number == 3) {
  644.       document.getElementById('divrevisi').style.display = 'block';
  645.  
  646.     } else {
  647.       document.getElementById('divrevisi').style.display = 'none';
  648.     }
  649.   }
  650.  
  651.   function addFields()
  652.   {
  653.     var e = document.getElementById("terminnumber");
  654.     var number = e.options[e.selectedIndex].value;
  655.     getfromaddFields = number;
  656.     var container = document.getElementById("termincontainer");
  657.     while (container.hasChildNodes())
  658.     {
  659.       container.removeChild(container.lastChild);
  660.     }
  661.  
  662.     var container = container.appendChild(document.createElement("table"));
  663.     container.className = "table table-bordered";
  664.     var container = container.appendChild(document.createElement("tbody"));
  665.  
  666.     for (i = 0; i < number; i++)
  667.     {
  668.       var containertr = container.appendChild(document.createElement("tr"));
  669.       var containertd = containertr.appendChild(document.createElement("td"));
  670.       z = document.createElement('span');
  671.       z.innerHTML = "Termin Ke  % " + (i + 1) + "  :";
  672.       z.className = "text-danger";
  673.       containertd.appendChild(z);
  674.       var input = document.createElement("input");
  675.       input.type = "number";
  676.       input.name = "terminvalue[" + (i + 1) + "]";
  677.       input.id = "terminvalue" + (i + 1);
  678.       input.className = "getterminvalue";
  679.       input.min = 1;
  680.       input.max = 100;
  681.       input.maxlength = "2";
  682.       // input.onkeypress = isNumber_max_100;
  683.       var containertd = containertr.appendChild(document.createElement("td"));
  684.       containertd.appendChild(input);
  685.       z = document.createElement('span');
  686.       z.className = "text-primary";
  687.       z.innerHTML = ' Ket: ';
  688.       var containertd = containertr.appendChild(document.createElement("td"));
  689.       containertd.appendChild(z);
  690.       var input2 = document.createElement("input");
  691.       input2.type = "text";
  692.       input2.name = "terminket[" + (i + 1) + "]";
  693.       input2.id = "terminket" + (i + 1);
  694.       input2.className = "getterminket";
  695.       var containertd = containertr.appendChild(document.createElement("td"));
  696.       containertd.appendChild(input2);
  697.     }
  698.   }
  699.  
  700.   function showc1()
  701.   {
  702.     var container = document.getElementById("kurscontainer");
  703.  
  704.     while (container.hasChildNodes())
  705.     {
  706.       container.removeChild(container.lastChild);
  707.     }
  708.  
  709.     document.getElementById('divc1').style.display = 'block';
  710.     document.getElementById('divc2').style.display = 'none';
  711.   }
  712.  
  713.   function showc2()
  714.   {
  715.     document.getElementById('divc2').style.display = 'block';
  716.     document.getElementById('divc1').style.display = 'none';
  717.     addKursFields();
  718.   }
  719.  
  720.   function addKursFields()
  721.   {
  722.     var e = document.getElementById("kursid2");
  723.     var options = document.getElementById('kursid2').options, count = 0;
  724.     var options2 = document.getElementById('kursdata');
  725.  
  726.     var arrayman = [];
  727.     var arraymankurs = [];
  728.     for (var i = 0; i < options.length; i++)
  729.     {
  730.       arraymankurs[count] = options2[i].value;
  731.       if (options[i].selected)
  732.       {
  733.         arrayman[count] = e.options[i].text;
  734.         count++;
  735.       }
  736.     }
  737.  
  738.   //var number = document.getElementById("terminnumber").value;
  739.   var container = document.getElementById("kurscontainer");
  740.  
  741.   while (container.hasChildNodes())
  742.   {
  743.     container.removeChild(container.lastChild);
  744.   }
  745.  
  746.  
  747.  
  748.   for (i = 0; i < count; i++)
  749.   {
  750.     container.appendChild(document.createTextNode("Nilai Kurs   " + arrayman[i] + "  :"));
  751.     var input = document.createElement("input");
  752.     input.type = "number";
  753.     input.name = "kursdatavalue[]";
  754.     input.id = "kursdatavalue" + (i + 1);
  755.     input.min = 1;
  756.  
  757.     input.value = localStorage.getItem("kursdatavalue" + i);
  758.  
  759.     input.onkeyup = function ()
  760.     {
  761.  
  762.       var container = document.getElementById("kurscontainer");
  763.       var children = container.childNodes;
  764.  
  765.       var iy = 0;
  766.       for (var im = 0; im < children.length; im++)
  767.       {
  768.         if (children[im].tagName == "INPUT" && children[im].name == 'kursdatavalue[]')
  769.         {
  770.           var rate = document.getElementsByName("rate")[0].value;
  771.  
  772.           var nominal = children[im].value;
  773.           var numberPattern = /\d+/g;
  774.           nominal = nominal.replace(/\D/g, "");
  775.           nominal = parseFloat(nominal);
  776.  
  777.           var y = document.getElementsByName("premikursdatavalue[]"), i;
  778.  
  779.           if (nominal.length == 0)
  780.           {
  781.             nominal = 1;
  782.           }
  783.  
  784.           if (rate.length == 0)
  785.           {
  786.             rate = 1;
  787.           }
  788.  
  789.           var hasil = (nominal * rate) / 100;
  790.  
  791.           y[iy].value = hasil;
  792.  
  793.           iy++;
  794.         }
  795.       }
  796.  
  797.       storedatatemp();
  798.     };
  799.  
  800.  
  801.     container.appendChild(input);
  802.     container.appendChild(document.createElement("br"));
  803.  
  804.  
  805.     input.min = 1;
  806.     container.appendChild(input);
  807.     container.appendChild(document.createElement("br"));
  808.  
  809.     container.appendChild(document.createElement("br"));
  810.     container.appendChild(document.createElement("br"));
  811.   }
  812. }
  813.  
  814. function showo1() {
  815.   var container = document.getElementById("termincontainer");
  816.   while (container.hasChildNodes()) {
  817.     container.removeChild(container.lastChild);
  818.   }
  819.   document.getElementById('divo1').style.display = 'block';
  820.   document.getElementById('divo2').style.display = 'none';
  821.   document.getElementById('divo3').style.display = 'none';
  822. }
  823.  
  824. function showo2() {
  825.   document.getElementById('divo1').style.display = 'none';
  826.   document.getElementById('divo2').style.display = 'block';
  827.   document.getElementById('divo3').style.display = 'none';
  828. }
  829.  
  830. function showo3() {
  831.   var container = document.getElementById("termincontainer");
  832.   while (container.hasChildNodes()) {
  833.     container.removeChild(container.lastChild);
  834.   }
  835.   document.getElementById('divo1').style.display = 'none';
  836.   document.getElementById('divo2').style.display = 'none';
  837.   document.getElementById('divo3').style.display = 'block';
  838. }
  839.  
  840. function showdis1()
  841. {
  842.   document.getElementById('divdis1').style.display = 'block';
  843.   document.getElementById('divdis2').style.display = 'none';
  844. }
  845.  
  846. function showdis2() {
  847.   document.getElementById('divdis1').style.display = 'none';
  848.   document.getElementById('divdis2').style.display = 'block';
  849. }
  850.  
  851.  
  852. $(document).ready(function () {
  853.   $('#customer').change(function () {
  854.     var customer_id = $(this).val();
  855.     $.ajax({
  856.       url: "<?php echo base_url('sales/getCustomerData') ?>/" + customer_id,
  857.       type: "GET",
  858.       dataType: "JSON",
  859.       data: {
  860.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  861.       },
  862.       success: function (data) {
  863.  
  864.         $('#company_id').text('');
  865.         $('#company_name').text('');
  866.         $('#customer_name').text('');
  867.         $('#mobilephone').text('');
  868.         $('#email').text('');
  869.         $('#npwp').text('');
  870.         $('#alamat_npwp').text('');
  871.         $('#npwp').val(data['data'][0].gstid);
  872.         $('#alamat_npwp').val(data['data'][0].cf2);
  873.         $('#company_id').val(data['data'][0].cf1);
  874.         $('#company_name').val(data['data'][0].company_name);
  875.         $('#customer_name').val(data['data'][0].customer_name);
  876.         $('#mobilephone').val(data['data'][0].mobile);
  877.         $('#email').val(data['data'][0].email);
  878.  
  879.         if (typeof data['address'][0] != 'undefined') {
  880.           var cid = data['address'][0].customer_id;
  881.           for (a = 0; a < data['address'].length; a++) {
  882.             if (data['address'][a].type == 0) {
  883.               $('#customer_address').append('<option value="' + data['address'][a].id + '">' + data['address'][a].address + '</option>');
  884.             }
  885.           }
  886.         } else {
  887.           var cid = "";
  888.         }
  889.  
  890.         if (typeof data['address'][0] != 'undefined') {
  891.           var cid = data['address'][0].customer_id;
  892.           for (a = 0; a < data['address'].length; a++) {
  893.             if (data['address'][a].type == 1) {
  894.               $('#customer_addressa').append('<option value="' + data['address'][a].id + '">' + data['address'][a].address + '</option>');
  895.             }
  896.           }
  897.         } else {
  898.           var cid = "";
  899.         }
  900.  
  901.         $("#reference_no").empty().trigger("change");
  902.         var customer_id = $('#customer').val();
  903.         $.ajax({
  904.           url: "<?php echo base_url('sales/getRecordAjax') ?>/" + customer_id,
  905.           type: "GET",
  906.           dataType: "JSON",
  907.           data: {
  908.             '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  909.           },
  910.           success: function (data) {
  911.             for (a = 0; a < data['data'].length; a++) {
  912.               if (data['data'][a].reference_no2 != null) {
  913.                 number = data['data'][a].reference_no2;
  914.               } else {
  915.                 number = data['data'][a].reference_no;
  916.               }
  917.               $('#reference_no').append('<option value="' + data['data'][a].quotation_id + '">' + number + '</option>').trigger('change');
  918.             }
  919.             $("#reference_no").trigger({
  920.               type: 'select2:select',
  921.             });
  922.             var selectstr = <?php echo json_encode(unserialize($data[0]->reference_no)); ?>;
  923.             $('#preference_no').find('#reference_no').val(selectstr).trigger('change');
  924.           }
  925.         });
  926.  
  927.         $('#customer_address').val(<?php echo $data[0]->shipto; ?>).trigger('change');
  928.         $('#customer_addressa').val(<?php echo $data[0]->billto; ?>).trigger('change');
  929.       }
  930.     });
  931.   }).change();
  932. });
  933.  
  934. $(document).ready(function () {
  935.   $('#customer_address').change(function () {
  936.     var customerAddress_id = $(this).val();
  937.     $.ajax({
  938.       url: "<?php echo base_url('sales/getCustomerAddressData') ?>/" + customerAddress_id,
  939.       type: "GET",
  940.       dataType: "JSON",
  941.       data: {
  942.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  943.       },
  944.       success: function (data) {
  945.         $('#country').text('');
  946.         $('#state').text('');
  947.         $('#city').text('');
  948.         $('#err_country').text('');
  949.         $('#err_state').text('');
  950.         $('#err_city').text('');
  951.         $('#country').val(data['address'][0].cname);
  952.         $('#state').val(data['address'][0].sname);
  953.         $('#city').val(data['address'][0].ctname);
  954.         var s = data['address'][0].baddress;
  955.         tinyMCE.get('addresscustomer').setContent(s);
  956.       }
  957.     });
  958.   }).change();
  959. });
  960.  
  961. $(document).ready(function () {
  962.   $('#customer_addressa').change(function () {
  963.     var customerAddress_id = $(this).val();
  964.     $.ajax({
  965.       url: "<?php echo base_url('sales/getCustomerAddressData') ?>/" + customerAddress_id,
  966.       type: "GET",
  967.       dataType: "JSON",
  968.       data: {
  969.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  970.       },
  971.       success: function (data) {
  972.         $('#countrya').text('');
  973.         $('#statea').text('');
  974.         $('#citya').text('');
  975.         $('#err_countrya').text('');
  976.         $('#err_statea').text('');
  977.         $('#err_citya').text('');
  978.         $('#countrya').val(data['address'][0].coname);
  979.         $('#statea').val(data['address'][0].sname);
  980.         $('#citya').val(data['address'][0].ciname);
  981.         var s = data['address'][0].baddress;
  982.         tinyMCE.get('addresscustomera').setContent(s);
  983.       }
  984.     });
  985.   }).change();
  986. });
  987. </script>
  988.  
  989. <script>
  990.   $(document).ready(function () {
  991.     var counter = 1;
  992.     $('#brand').change(function () {
  993.       $('#code_item').html('');
  994.       $('#code_item').html('<option value="">Select Part Number</option>');
  995.       var brand_id = $('#brand').val();
  996.       $.ajax({
  997.         url: "<?php echo base_url('sales/getPartNumber') ?>/" + brand_id,
  998.         type: "GET",
  999.         dataType: "JSON",
  1000.         data: {
  1001.           '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1002.         },
  1003.         success: function (data) {
  1004.           for (a = 0; a < data.length; a++) {
  1005.             $('#code_item').append('<option value="' + data[a].code + '">' + data[a].code + '</option>');
  1006.           }
  1007.         }
  1008.       });
  1009.     });
  1010.  
  1011.     $('#code_item').change(function () {
  1012.       $('#product').html('');
  1013.       $('#product').html('<option value="">Select Product</option>');
  1014.       var code = $('#code_item').val();
  1015.       $.ajax({
  1016.         url: "<?php echo base_url('sales/getCodeProduct') ?>/" + code,
  1017.         type: "GET",
  1018.         dataType: "JSON",
  1019.         data: {
  1020.           '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1021.         },
  1022.         success: function (data) {
  1023.           for (a = 0; a < data.length; a++) {
  1024.             $('#product').append('<option value="' + data[a].product_id + '">' + data[a].name + '</option>');
  1025.           }
  1026.         }
  1027.       });
  1028.     });
  1029.  
  1030.     $('#product').change(function () {
  1031.       var id = $(this).val();
  1032.       var product_id = $('#product').val();
  1033.  
  1034.       var flag = 0;
  1035.       $('#err_product').text('');
  1036.       console.log(flag);
  1037.       $.ajax({
  1038.         url: "<?php echo base_url('sales/getProduct_old') ?>/" + product_id,
  1039.         type: "GET",
  1040.         dataType: "JSON",
  1041.         data: {
  1042.           '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1043.         },
  1044.         success: function (data) {
  1045.  
  1046.           $("table.product_table").find('input[name^="product_id"]').each(function () {
  1047.             // if (data[0].product_id == +$(this).val()) {
  1048.             //   flag = 1;
  1049.             // }
  1050.           });
  1051.           if (flag == 0) {
  1052.             var id = data[0].product_id;
  1053.             var code = data[0].code;
  1054.             var name = data[0].name;
  1055.             var item_namebyp = data[0].item_namebyp;
  1056.             var price = data[0].cost;
  1057.  
  1058.             var product = {"product_id": id,
  1059.             "price": price
  1060.           };
  1061.           product_data[yi] = product;
  1062.           length = product_data.length - 1;
  1063.  
  1064.           var select_discount = "";
  1065.           select_discount += '<div class="form-group">';
  1066.           select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
  1067.           select_discount += '<option value="">Select</option>';
  1068.           for (a = 0; a < data['discount'].length; a++) {
  1069.             select_discount += '<option value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  1070.           }
  1071.           select_discount += '</select></div>';
  1072.  
  1073.  
  1074.           var newRow = $("<tr id='tr"+ yi +"'>");
  1075.           var cols = "";
  1076.           cols += "<td><a class='deleteRow'> <img src='<?php echo base_url(); ?>assets/images/bin3.png' /> </a><input type='hidden' name='id' name='id' value=" + yi + "><input type='hidden' name='product_id' name='product_id' value=" + id + "></td>";
  1077.           cols += "<td>" + code + "</td>";
  1078.           cols += "<td><input type='hidden' value='" + data[0].name + "' name='nameProduct" + counter + "' id='nameProduct" + counter + "'><input type='hidden' value='" + data[0].product_id + "' name='idProduct" + counter + "' id='idProduct" + counter + "'>" + name + "</td>";
  1079.           cols += "<td>" + item_namebyp + "</td>";
  1080.           cols += "<td><input type='text' name='description" + counter + "' id='description"+ counter + "' value='" + name + "' class='form-control'></td>";
  1081.           cols += "<td><input type='number' class='form-control text-center' value='0' data-rule='quantity' name='qty" + counter + "' id='qty" + counter + "' min='1' max='" + data[0].quantity + "'></td>";
  1082.           cols += "<td>" + data[0].quantity + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'></td>";
  1083.           cols += "<td>" + data[0].unit + "</td>";
  1084.           cols += "<td step='0.01' align='right'><span id='price'><input type='text' class='form-control text-right' name='price" + counter + "' id='price" + counter + "' value='" + price + "'></span></td>";
  1085.           cols += "<td><span id='sub_total'><input type='text' class='form-control text-right' style='' value='0.00' name='linetotal" + counter + "' id='linetotal" + counter + "' readonly></span></td>";
  1086.           cols += '<td><input type="hidden" id="discount_value" name="discount_value"><input type="hidden" id="hidden_discount" name="hidden_discount">' + select_discount + '</td>';
  1087.  
  1088.           cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
  1089.           cols += "</tr>";
  1090.           counter++;
  1091.           newRow.append(cols);
  1092.           $("table.product_table").append(newRow);
  1093.           var table_data = JSON.stringify(product_data);
  1094.           $('#table_data').val(table_data);
  1095.           yi++;
  1096.         } else {
  1097.           $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  1098.         }
  1099.       }
  1100.     });
  1101. });
  1102.  
  1103. $('#a_brand').change(function () {
  1104.   $('#a_code_item').html('');
  1105.   $('#a_code_item').html('<option value="">Select Part Number</option>');
  1106.   var brand_id = $('#a_brand').val();
  1107.   $.ajax({
  1108.     url: "<?php echo base_url('sales/getPartNumber') ?>/" + brand_id,
  1109.     type: "GET",
  1110.     dataType: "JSON",
  1111.     data: {
  1112.       '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1113.     },
  1114.     success: function (data) {
  1115.       for (a = 0; a < data.length; a++) {
  1116.         $('#a_code_item').append('<option value="' + data[a].code + '">' + data[a].code + '</option>');
  1117.       }
  1118.     }
  1119.   });
  1120. });
  1121.  
  1122. $('#a_code_item').change(function () {
  1123.   $('#a_product').html('');
  1124.   $('#a_product').html('<option value="">Select Product</option>');
  1125.   var code = $('#a_code_item').val();
  1126.   $.ajax({
  1127.     url: "<?php echo base_url('sales/getCodeProduct') ?>/" + code,
  1128.     type: "GET",
  1129.     dataType: "JSON",
  1130.     data: {
  1131.       '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1132.     },
  1133.     success: function (data) {
  1134.       for (a = 0; a < data.length; a++) {
  1135.         $('#a_product').append('<option value="' + data[a].product_id + '">' + data[a].name + '</option>');
  1136.       }
  1137.     }
  1138.   });
  1139. });
  1140.  
  1141. $('#a_product').change(function () {
  1142.   var id = $(this).val();
  1143.   var product_id = $('#a_product').val();
  1144.   var flag = 0;
  1145.   $('#err_a_product').text('');
  1146.   $.ajax({
  1147.     url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
  1148.     type: "GET",
  1149.     dataType: "JSON",
  1150.     data: {
  1151.       '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1152.     },
  1153.     success: function (data) {
  1154.  
  1155.       $("table.additional_table").find('input[name^="product_id"]').each(function () {
  1156.         if (data[0].additional_id == +$(this).val()) {
  1157.           flag = 1;
  1158.         }
  1159.       });
  1160.  
  1161.       if (flag == 0) {
  1162.         var id = data[0].product_id;
  1163.         var price = data[0].cost;
  1164.         var code = data[0].code;
  1165.         var name = data[0].name;
  1166.         var itembyp = data[0].item_namebyp;
  1167.         var stock = data[0].quantity;
  1168.         var uom = data[0].uom;
  1169.         var product = {"additional_id": id, "price": 0
  1170.       };
  1171.  
  1172.       additional_data[j] = product;
  1173.       length = additional_data.length - 1;
  1174.  
  1175.       var select_discount = "";
  1176.       select_discount += '<div class="form-group">';
  1177.       select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
  1178.       select_discount += '<option value="">Select</option>';
  1179.       for (a = 0; a < data['discount'].length; a++) {
  1180.         select_discount += '<option value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  1181.       }
  1182.       select_discount += '</select></div>';
  1183.  
  1184.       var newRow = $("<tr id='tra"+ j +"'>");
  1185.       var cols = "";
  1186.       cols += "<td><a class='deleteRow'> <img src='<?php echo base_url(); ?>assets/images/bin3.png' /> </a><input type='hidden' name='id' name='id' value=" + j + "><input type='hidden' name='additional_id' name='additional_id' value=" + id + "></td>";
  1187.       cols += "<td>" + code + "</td>";
  1188.       cols += "<td><input type='hidden' value='" + data[0].name + "' name='nameProduct" + counter + "' id='nameProduct" + counter + "'><input type='hidden' value='" + data[0].product_id + "' name='idProduct" + counter + "' id='idProduct" + counter + "'>" + name + "</td>";
  1189.       cols += "<td>" + itembyp + "</td>";
  1190.       cols += "<td><input type='text' name='description" + counter + "' id='description"+ counter + "' value='" + name + "' class='form-control'></td>";
  1191.       cols += "<td>"
  1192.       + "<input type='number' class='form-control text-center' value='0' data-rule='quantity' name='qty" + counter + "' id='qty" + counter + "' min='1' max='" + data[0].quantity + "'>"
  1193.       + "</td>";
  1194.       cols += "<td>" + data[0].quantity + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'></td>";
  1195.       cols += "<td>" + data[0].unit + "</td>";
  1196.       cols += "<td align='right'><span id='price" + counter + "'><input type='number' class='form-control text-right' name='price" + counter + "' step='0.01' id='price" + counter + "' value='"+ price +"'></span></td>";
  1197.       cols += "<td><span id='sub_total'><input type='text' class='form-control text-right' style='' value='0.00' name='linetotal" + counter + "' id='linetotal" + counter + "' readonly></span></td>";
  1198.       cols += '<td><input type="hidden" id="discount_value" name="discount_value"><input type="hidden" id="hidden_discount" name="hidden_discount">' + select_discount + '</td>';
  1199.  
  1200.       cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
  1201.       cols += "</tr>";
  1202.       counter++;
  1203.       newRow.append(cols);
  1204.       $("table.additional_table").append(newRow);
  1205.       var table_data = JSON.stringify(additional_data);
  1206.       $('#tableadditional_data').val(table_data);
  1207.       j++;
  1208.     } else {
  1209.       $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  1210.     }
  1211.   }
  1212. });
  1213. });
  1214.  
  1215. $('#service').change(function () {
  1216.   var id = $(this).val();
  1217.   var service_id = $('#service').val();
  1218.  
  1219.   var flag = 0;
  1220.   $('#err_service').text('');
  1221.   $.ajax({
  1222.     url: "<?php echo base_url('sales/getService') ?>/" + service_id,
  1223.     type: "GET",
  1224.     dataType: "JSON",
  1225.     data: {
  1226.       '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1227.     },
  1228.     success: function (data) {
  1229.       $("table.service_table").find('input[name^="service_id"]').each(function () {
  1230.         if (data[0].service_id == +$(this).val()) {
  1231.           flag = 1;
  1232.         }
  1233.       });
  1234.       if (flag == 0) {
  1235.         var id = data[0].service_id;
  1236.         var code = data[0].code;
  1237.         var name = data[0].service_title;
  1238.         var hsn_sac_code = '';
  1239.         var price = data[0].price;
  1240.  
  1241.         var product = {"service_id": id,
  1242.         "price": price
  1243.       };
  1244.       service_data[k] = product;
  1245.  
  1246.       length = service_data.length - 1;
  1247.  
  1248.       var select_discount = "";
  1249.       select_discount += '<div class="form-group">';
  1250.       select_discount += '<select class="form-control select2" id="item_discountservice" name="item_discountservice" style="width: 100%;">';
  1251.       select_discount += '<option value="">Select</option>';
  1252.       for (a = 0; a < data['discount'].length; a++) {
  1253.         select_discount += '<option value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  1254.       }
  1255.       select_discount += '</select></div>';
  1256.  
  1257.       var newRow = $("<tr>");
  1258.       var cols = "";
  1259.       cols += "<td><a class='deleteRow'> <img src='<?php echo base_url(); ?>assets/images/bin3.png' /> </a><input type='hidden' name='idservice' name='idservice' value=" + k + "><input type='hidden' name='service_id' value=" + id + "></td>";
  1260.       cols += "<td>" + code + "</td>";
  1261.       cols += "<td>" + name + "</td>";
  1262.       cols += "<td>"
  1263.       + "<input type='number' class='form-control text-center' value='0' data-rule='quantity' name='qtyservice" + counter + "' id='qtyservice" + counter + "' min='0' max='2'>"
  1264.       + "</td>";
  1265.       cols += "<td align='right'>"
  1266.       + "<span id='price'>"
  1267.       + "<input type='text' step='0.01' class='form-control text-right' name='priceservice" + counter + "' id='priceservice" + counter + "' value='" + price
  1268.       + "'>"
  1269.       + "</span>"
  1270.       + "</td>";
  1271.       cols += "<td>"
  1272.       + "<span id='sub_total'>"
  1273.       + "<input type='text' class='form-control text-right' style='' value='0.00' name='linetotalservice" + counter + "' id='linetotalservice" + counter + "' readonly>"
  1274.       + "</span>"
  1275.       + "</td>";
  1276.       cols += '<td><input type="hidden" id="discountservice_value" name="discountservice_value"><input type="hidden" id="hidden_discountservice" name="hidden_discountservice">' + select_discount + '</td>';
  1277.  
  1278.       cols += '<td><input type="text" class="form-control text-right" id="service_total" name="service_total" readonly></td>';
  1279.       cols += "</tr>";
  1280.       counter++;
  1281.  
  1282.       newRow.append(cols);
  1283.       $("table.service_table").append(newRow);
  1284.       var table_data = JSON.stringify(service_data);
  1285.       $('#tableservice_data').val(table_data);
  1286.       k++;
  1287.     } else {
  1288.       $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  1289.     }
  1290.   }
  1291. });
  1292. });
  1293.  
  1294.  
  1295.  
  1296.  
  1297. $("table.product_table").on("click", "a.deleteRow", function (event) {
  1298.   deleteRow($(this).closest("tr"));
  1299.   $(this).closest("tr").remove();
  1300.   $.calculateGrandTotal();
  1301. });
  1302.  
  1303. $("table.additional_table").on("click", "a.deleteRow", function (event) {
  1304.   deleteRowAdditional($(this).closest("tr"));
  1305.   $(this).closest("tr").remove();
  1306.   $.calculateGrandTotal();
  1307. });
  1308.  
  1309.  
  1310. $("table.service_table").on("click", "a.deleteRow", function (event) {
  1311.   deleteRowService($(this).closest("tr"));
  1312.   $(this).closest("tr").remove();
  1313.   $.calculateGrandTotal();
  1314. });
  1315.  
  1316. function deleteRow(row) {
  1317.   var id = +row.find('input[name^="id"]').val();
  1318.   var array_id = product_data[id].product_id;
  1319.   product_data[id] = null;
  1320.   var table_data = JSON.stringify(product_data);
  1321.   $('#table_data').val(table_data);
  1322. }
  1323.  
  1324. function deleteRowAdditional(row) {
  1325.   var id = +row.find('input[name^="id"]').val();
  1326.   additional_data[id] = null;
  1327.   var table_data = JSON.stringify(additional_data);
  1328.   $('#tableadditional_data').val(table_data);
  1329. }
  1330.  
  1331. function deleteRowService(row) {
  1332.   var id = +row.find('input[name^="idservice"]').val();
  1333.   service_data[id] = null;
  1334.   var table_data = JSON.stringify(service_data);
  1335.   $('#tableservice_data').val(table_data);
  1336. }
  1337.  
  1338. $("table.product_table").on("change", 'input[name^="price"], input[name^="qty"]', function (event) {
  1339.  
  1340.   calculateRow($(this).closest("tr"));
  1341.   $.calculateDiscount($(this).closest("tr"));
  1342.   $.calculateGrandTotal();
  1343.  
  1344. });
  1345.  
  1346. $("table.product_table").on("change", 'input[name^="qty"]', function (event) {
  1347.   row = $(this).closest("tr");
  1348.   var key = +row.find('input[name^="id"]').val();
  1349.   var price = +row.find('input[name^="price"]').val();
  1350.   var qty = +row.find('input[name^="qty"]').val();
  1351.   var desc = row.find('input[name^="description"]').val();
  1352.   var nqty = row.find('input[name^="qty"]').attr('name');
  1353.   var availableqty = +row.find('input[name^="available_quantity"]').val();
  1354.   var nameproductval = row.find('input[name^="nameProduct"]').val();
  1355.   var idproductval = +row.find('input[name^="idProduct"]').val();
  1356.   var bookqty = qty - availableqty;
  1357.   if (bookqty > 0) {
  1358.     $("#m_id_product").val(idproductval);
  1359.     $("#qtytitle").text(nqty);
  1360.     $("#m_name_product").val(nameproductval);
  1361.     $("#m_ref").val($('#sales_order').text());
  1362.     $("#m_type").val('tr'+key);
  1363.     $("#m_qty").val(bookqty);
  1364.     $("#m_price").val(price);
  1365.     $("#m_date").val($('#sales_date').val());
  1366.     $("#bookingmodal").modal("show");
  1367.   }
  1368. });
  1369.  
  1370. $("table.additional_table").on("change", 'input[name^="price"], input[name^="qty"]', function (event) {
  1371.  
  1372.   calculateRowAdditional($(this).closest("tr"));
  1373.   $.calculateDiscountAdditional($(this).closest("tr"));
  1374.   $.calculateGrandTotal();
  1375.  
  1376. });
  1377.  
  1378. $("table.additional_table").on("change", 'input[name^="qty"]', function (event) {
  1379.   row = $(this).closest("tr");
  1380.   var key = +row.find('input[name^="id"]').val();
  1381.   var price = +row.find('input[name^="price"]').val();
  1382.   var qty = +row.find('input[name^="qty"]').val();
  1383.   var desc = row.find('input[name^="description"]').val();
  1384.   var nqty = row.find('input[name^="qty"]').attr('name');
  1385.   var availableqty = +row.find('input[name^="available_quantity"]').val();
  1386.   var nameproductval = row.find('input[name^="nameProduct"]').val();
  1387.   var idproductval = +row.find('input[name^="idProduct"]').val();
  1388.   var bookqty = qty - availableqty;
  1389.   if (bookqty > 0) {
  1390.     $("#m_id_product").val(idproductval);
  1391.     $("#qtytitle").text(nqty);
  1392.     $("#m_name_product").val(nameproductval);
  1393.     $("#m_ref").val($('#sales_order').text());
  1394.     $("#m_type").val('tr'+key);
  1395.     $("#m_qty").val(bookqty);
  1396.     $("#m_price").val(price);
  1397.     $("#m_date").val($('#sales_date').val());
  1398.     $("#bookingmodal").modal("show");
  1399.   }
  1400. });
  1401.  
  1402. $("table.service_table").on("change", 'input[name^="priceservice"], input[name^="qtyservice"]', function (event) {
  1403.  
  1404.   calculateRowService($(this).closest("tr"));
  1405.   $.calculateDiscountService($(this).closest("tr"));
  1406.   $.calculateGrandTotal();
  1407. });
  1408.  
  1409. $("table.product_table").on("change", 'input[name ^= "linetotal"]', function (event) {
  1410.  
  1411.   calculateRow2($(this).closest("tr"));
  1412.   $.calculateDiscount($(this).closest("tr"));
  1413.   $.calculateGrandTotal();
  1414. });
  1415.  
  1416. $("table.additional_table").on("change", 'input[name ^= "linetotal"]', function (event) {
  1417.  
  1418.   calculateRowAdditional2($(this).closest("tr"));
  1419.   $.calculateDiscountAdditional($(this).closest("tr"));
  1420.   $.calculateGrandTotal();
  1421. });
  1422.  
  1423. $("table.service_table").on("change", 'input[name^="linetotalservice"]', function (event)
  1424. {
  1425.  
  1426.   calculateRowService2($(this).closest("tr"));
  1427.   $.calculateDiscountService($(this).closest("tr"));
  1428.   $.calculateGrandTotal();
  1429. });
  1430.  
  1431. nilai_diskon = 0;
  1432.  
  1433. $("table.product_table").on("change", '#item_discount', function (event) {
  1434.   var row = $(this).closest("tr");
  1435.   var discount = +row.find('#item_discount').val();
  1436.   var diskon = $(this).val();
  1437.   // console.log(diskon);
  1438.   if (diskon != "") {
  1439.     $.ajax({
  1440.       url: '<?php echo base_url('purchase/getDiscountValue/') ?>' + diskon,
  1441.       type: "GET",
  1442.       data: {
  1443.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1444.       },
  1445.       datatype: JSON,
  1446.       success: function (value) {
  1447.         data = JSON.parse(value);
  1448.         console.log(data);
  1449.         // row.find('#discount_value').val(data[0].discount_value);
  1450.         // $.calculateDiscount(row, data[0].discount_value);
  1451.         // $.calculateGrandTotal();
  1452.  
  1453.         var diskon = data[0].discount_value / 100;
  1454.         diskon = parseFloat(diskon);
  1455.  
  1456.         var subtotal = row.find('.subtotal').val();
  1457.         subtotal = parseFloat(subtotal);
  1458.         console.log(diskon);
  1459.  
  1460.         diskon = diskon * subtotal;
  1461.         nilai_diskon += diskon;
  1462.  
  1463.         subtotal = subtotal - diskon;
  1464.  
  1465.         row.find('.salestotal').val(subtotal);
  1466.  
  1467.       }
  1468.     });
  1469.   } else {
  1470.     // row.find('#discount_value').val('0');
  1471.     // $.calculateDiscount(row, 0);
  1472.     // $.calculateGrandTotal();
  1473.   }
  1474. });
  1475.  
  1476. $("table.additional_table").on("change", '#item_discount', function (event) {
  1477.   var row = $(this).closest("tr");
  1478.   var discount = +row.find('#item_discount').val();
  1479.   if (discount != "") {
  1480.     $.ajax({
  1481.       url: '<?php echo base_url('purchase/getDiscountValue/') ?>' + discount,
  1482.       type: "GET",
  1483.       data: {
  1484.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1485.       },
  1486.       datatype: JSON,
  1487.       success: function (value) {
  1488.         data = JSON.parse(value);
  1489.         row.find('#discount_value').val(data[0].discount_value);
  1490.         $.calculateDiscountAdditional(row, data[0].discount_value);
  1491.         $.calculateGrandTotal();
  1492.       }
  1493.     });
  1494.   } else {
  1495.     row.find('#discount_value').val('0');
  1496.     $.calculateDiscountAdditional(row, 0);
  1497.     $.calculateGrandTotal();
  1498.   }
  1499. });
  1500.  
  1501. $("table.service_table").on("change", '#item_discountservice', function (event) {
  1502.   var row = $(this).closest("tr");
  1503.   var discount = +row.find('#item_discountservice').val();
  1504.   if (discount != "") {
  1505.     $.ajax({
  1506.       url: '<?php echo base_url('purchase/getDiscountValue/') ?>' + discount,
  1507.       type: "GET",
  1508.       data: {
  1509.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1510.       },
  1511.       datatype: JSON,
  1512.       success: function (value) {
  1513.         data = JSON.parse(value);
  1514.         row.find('#discountservice_value').val(data[0].discount_value);
  1515.         $.calculateDiscountService(row, data[0].discount_value);
  1516.         $.calculateGrandTotal();
  1517.       }
  1518.     });
  1519.   } else {
  1520.     row.find('#discountservice_value').val('0');
  1521.     $.calculateDiscountService(row, 0);
  1522.     $.calculateGrandTotal();
  1523.   }
  1524. });
  1525.  
  1526. function calculateRow(row) {
  1527.   var key = +row.find('input[name^="id"]').val();
  1528.   var price = +row.find('input[name^="price"]').val();
  1529.   var desc = row.find('input[name^="description"]').val();
  1530.   var qty = +row.find('input[name^="qty"]').val();
  1531.  
  1532.   row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
  1533.   product_data[key].price = price;
  1534.   product_data[key].quantity = qty;
  1535.   product_data[key].desc = desc;
  1536.   product_data[key].total = (price * qty).toFixed(2);
  1537.   var table_data = JSON.stringify(product_data);
  1538.   $('#table_data').val(table_data);
  1539. }
  1540.  
  1541. function calculateRowAdditional(row) {
  1542.   var key = +row.find('input[name^="id"]').val();
  1543.   var price = +row.find('input[name^="price"]').val();
  1544.   var desc = row.find('input[name^="description"]').val();
  1545.   var qty = +row.find('input[name^="qty"]').val();
  1546.  
  1547.   row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
  1548.   additional_data[key].price = price;
  1549.   additional_data[key].quantity = qty;
  1550.   additional_data[key].desc = desc;
  1551.   additional_data[key].total = (price * qty).toFixed(2);
  1552.   var table_data = JSON.stringify(additional_data);
  1553.   $('#tableadditional_data').val(table_data);
  1554. }
  1555.  
  1556. function calculateRowService(row)
  1557. {
  1558.   var key = +row.find('input[name^="idservice"]').val();
  1559.   var price = +row.find('input[name^="priceservice"]').val();
  1560.   var qty = +row.find('input[name^="qtyservice"]').val();
  1561.   var total = +row.find('input[name^="linetotalservice"]').val();
  1562.   row.find('input[name^="linetotalservice"]').val((price * qty).toFixed(2));
  1563.   service_data[key].price = price;
  1564.   service_data[key].quantity = qty;
  1565.   service_data[key].total = total;
  1566.   var table_data = JSON.stringify(service_data);
  1567.   $('#tableservice_data').val(table_data);
  1568. }
  1569.  
  1570.  
  1571. });
  1572.  
  1573. </script>
  1574. <script>
  1575.   $(document).ready(function () {
  1576.     $('#previewmodal').on('hidden.bs.modal', function () {
  1577.       $("#view_table-body tr").remove();
  1578.       $("#table-termin-body tr").remove();
  1579.       $("#ptotal").text('');
  1580.       $("#pdiscount").text('');
  1581.       $("#pdiskonumum").text('');
  1582.       $("#ptax").text('');
  1583.       $("#pshipping").text('');
  1584.       $("#pbalance").text('');
  1585.       $("#pcurrency").text('');
  1586.       $("#pinternal_note").text('');
  1587.       $("#pnote").text('');
  1588.       $("#main").text('');
  1589.       $("#cc").text('');
  1590.       $("#ppaid_by").text('');
  1591.       $("#preference_no").text('');
  1592.       $("#pdate").text('');
  1593.       $("#pcostumer_name").text('');
  1594.       $("#pcostumer_address").text('');
  1595.       $("#pcostumer_jalan").text('');
  1596.       $("#pcostumer_city").text('');
  1597.       $("#pcostumer_country").text('');
  1598.       $("#pcostumer_mobile").text('');
  1599.       $("#pcostumer_email").text('');
  1600.       $("#pcompany_name").text('');
  1601.       $("#pwarehouse_name").text('');
  1602.       $("#pbranch_address").text('');
  1603.       $("#pbranch_city").text('');
  1604.       $("#pcompany_phone").text('');
  1605.       $("#company_email").text('');
  1606.       $('#pctrade').text('');
  1607.       $('#termin-other-value').text('');
  1608.     });
  1609.  
  1610.     $('#preview').on('click',function(){
  1611.  
  1612.       var id_customer =$('#customer').val();
  1613.       var internal_note =$('#internal_note').val();
  1614.       var note =$('#note').val();
  1615.       var upcc =$('#main').val();
  1616.       var upcc2 =$('#cc').val();
  1617.       var radios = document.getElementsByName('paymenterms');
  1618.       var reference_no =$('#quotanumb').val();
  1619.       var date =$('#quotadate').val();
  1620.       var table_data = $('#table_data').val();
  1621.       var tableadditional_data =$('#tableadditional_data').val();
  1622.       var tableservice_data =$('#tableservice_data').val();
  1623.       var ptotal =$('#totalValue').text();
  1624.       var pdiscount =$('#DiscountProduct').text();
  1625.       var ptax =$('#totalTax').text();
  1626.       var dpersen =$('#JumlahDiskonPersen').text();
  1627.       var dfix =$('#DiscountFix').text();
  1628.       var pshipping =$('#shipping_charge').text();
  1629.       var pbalance =$('#grandTotal').text();
  1630.       var pcurrency =$('#grandCurrency').text();
  1631.       var othervalue =$('#others').text();
  1632.       var additional_description =$('#additional_description').val();
  1633.       var service_description =$('#service_description').val();
  1634.       var counter = 1;
  1635.       var product = new Array();
  1636.       var additional = new Array();
  1637.       var service = new Array();
  1638.  
  1639.       for (var i = 0, length = radios.length; i < length; i++)
  1640.       {
  1641.        if (radios[i].checked)
  1642.        {
  1643.         paid_by = radios[i].value;
  1644.         break;
  1645.       }
  1646.     }
  1647.  
  1648.     $("#ptotal").text(ptotal);
  1649.     $("#pdiscount").text(pdiscount);
  1650.     $("#pdiskonumum").text(dpersen + dfix);
  1651.     $("#ptax").text(ptax);
  1652.     $("#pshipping").text(pshipping);
  1653.     $("#pbalance").text(pbalance);
  1654.     $("#pcurrency").text(pcurrency);
  1655.     $("#pinternal_note").text(internal_note);
  1656.     $("#pnote").text(note);
  1657.     $("#pupcc").text(upcc);
  1658.     $("#pupcc2").text(upcc2);
  1659.     $("#ppaid_by").text(paid_by);
  1660.     $("#preference_no").text(reference_no);
  1661.     $("#pdate").text(date);
  1662.  
  1663.     if (table_data) {
  1664.       product = JSON.parse(table_data);
  1665.     }
  1666.  
  1667.     if (product.length > 0) {
  1668.       for (a = 0; a < product.length; a++) {
  1669.  
  1670.         var getnewRow;
  1671.         var product_id = product[a].product_id;
  1672.         var desc = product[a].desc;
  1673.         var quantity = product[a].quantity;
  1674.         var price = product[a].price;
  1675.         var discount = product[a].discount;
  1676.         var tax = product[a].tax;
  1677.         $.ajax({
  1678.           async : false,
  1679.           url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
  1680.           type: "GET",
  1681.           dataType: "JSON",
  1682.           data: {
  1683.             '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1684.           },
  1685.           success: function (data) {
  1686.             var id = data[0].product_id;
  1687.             var code = data[0].code;
  1688.             var name = data[0].name;
  1689.             var itembyp = data[0].item_namebyp;
  1690.             var unit = data[0].unit;
  1691.  
  1692.             var newRow = $("<tr>");
  1693.             var cols = "";
  1694.             cols += "<td>" + counter + "</td>";
  1695.             cols += "<td>" + code + "</td>";
  1696.             cols += "<td>" + name + "</td>";
  1697.             cols += "<td>" + desc + "</td>";
  1698.             cols += "<td>" + quantity + "</td>";
  1699.             cols += "<td>" + unit + "</td>";
  1700.             cols += "<td>" + price + "</td>";
  1701.             cols += "<td>" + (price * quantity) + "</td>";
  1702.             cols += "<td>" + discount + "</td>";
  1703.             cols += "<td>" + ((price * quantity) - discount) + "</td>";
  1704.             cols += "<td>" + tax + "</td>";
  1705.             cols += "<td>" + (((price * quantity) - discount) + tax) + "</td>";
  1706.             cols += "</tr>";
  1707.             newRow.append(cols);
  1708.             getnewRow = newRow;
  1709.             $("#view_table-body").append(newRow);
  1710.             counter++;
  1711.           }
  1712.         });
  1713.       }
  1714.     }
  1715.  
  1716.     if (tableadditional_data) {
  1717.       additional = JSON.parse(tableadditional_data);
  1718.     }
  1719.  
  1720.     if (additional.length > 0) {
  1721.      if (additional_description) {
  1722.       var newRow = $("<tr>");
  1723.       var cols = "";
  1724.       cols += "<td colspan='12' align='left'>" + additional_description + "</td>";
  1725.       cols += "</tr>";
  1726.       newRow.append(cols);
  1727.       getnewRow = newRow;
  1728.       $("#view_table-body").append(newRow);
  1729.     }
  1730.  
  1731.     for (itemrec = 0; itemrec < additional.length; itemrec++) {
  1732.  
  1733.       var additional_id = additional[itemrec].additional_id;
  1734.       var desc = additional[itemrec].desc;
  1735.       var quantity = additional[itemrec].quantity;
  1736.       var price = additional[itemrec].price;
  1737.       var discount = additional[itemrec].discount;
  1738.       var tax = additional[itemrec].tax;
  1739.       var flag = 0;
  1740.       $.ajax({
  1741.         async: false,
  1742.         url: "<?php echo base_url('sales/getProduct') ?>/" + additional_id,
  1743.         type: "GET",
  1744.         dataType: "JSON",
  1745.         data: {
  1746.           '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1747.         },
  1748.         success: function (data) {
  1749.           var id = data[0].product_id;
  1750.           var code = data[0].code;
  1751.           var name = data[0].name;
  1752.           var itembyp = data[0].item_namebyp;
  1753.           var unit = data[0].unit;
  1754.  
  1755.           var newRow = $("<tr>");
  1756.           var cols = "";
  1757.           cols += "<td>" + counter + "</td>";
  1758.           cols += "<td>" + code + "</td>";
  1759.           cols += "<td>" + name + "</td>";
  1760.           cols += "<td>" + desc + "</td>";
  1761.           cols += "<td>" + quantity + "</td>";
  1762.           cols += "<td>" + unit + "</td>";
  1763.           cols += "<td>" + price + "</td>";
  1764.           cols += "<td>" + (price * quantity) + "</td>";
  1765.           cols += "<td>" + discount + "</td>";
  1766.           cols += "<td>" + ((price * quantity) - discount) + "</td>";
  1767.           cols += "<td>" + tax + "</td>";
  1768.           cols += "<td>" + (((price * quantity) - discount) + tax) + "</td>";
  1769.           cols += "</tr>";
  1770.           newRow.append(cols);
  1771.           getnewRow = newRow;
  1772.           $("#view_table-body").append(newRow);
  1773.           counter++;
  1774.         }
  1775.       });
  1776.     }
  1777.   }
  1778.  
  1779.  
  1780.   if (tableservice_data) {
  1781.     service = JSON.parse(tableservice_data);
  1782.   }
  1783.  
  1784.   if (service.length > 0) {
  1785.     if (service_description) {
  1786.       var newRow = $("<tr>");
  1787.       var cols = "";
  1788.       cols += "<td colspan='12' align='left'>" + service_description + "</td>";
  1789.       cols += "</tr>";
  1790.       newRow.append(cols);
  1791.       getnewRow = newRow;
  1792.       $("#view_table-body").append(newRow);
  1793.     }
  1794.     for (b = 0; b < service.length; b++) {
  1795.       var getnewRow;
  1796.       var service_id = service[b].service_id;
  1797.       var quantity = service[b].quantity;
  1798.       var price = service[b].price;
  1799.       var discount = service[b].discount;
  1800.       var tax = service[b].tax;
  1801.       var flag = 0;
  1802.       $.ajax({
  1803.         async : false,
  1804.         url: "<?php echo base_url('sales/getService') ?>/" + service_id,
  1805.         type: "GET",
  1806.         dataType: "JSON",
  1807.         data: {
  1808.           '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1809.         },
  1810.         success: function (data) {
  1811.           var code = data[0].code;
  1812.           var name = data[0].service_title;
  1813.           var itembyp = data[0].item_namebyp;
  1814.           var unit = data[0].unit;
  1815.  
  1816.           var newRow = $("<tr>");
  1817.           var cols = "";
  1818.           cols += "<td>" + counter + "</td>";
  1819.           cols += "<td>" + code + "</td>";
  1820.           cols += "<td>" + name + "</td>";
  1821.           cols += "<td>-</td>";
  1822.           cols += "<td>" + quantity + "</td>";
  1823.           cols += "<td>-</td>";
  1824.           cols += "<td>" + price + "</td>";
  1825.           cols += "<td>" + (price * quantity) + "</td>";
  1826.           cols += "<td>" + discount + "</td>";
  1827.           cols += "<td>" + ((price * quantity) - discount) + "</td>";
  1828.           cols += "<td>" + tax + "</td>";
  1829.           cols += "<td>" + (((price * quantity) - discount) + tax) + "</td>";
  1830.           cols += "</tr>";
  1831.           newRow.append(cols);
  1832.           getnewRow = newRow;
  1833.           $("#view_table-body").append(newRow);
  1834.           counter++;
  1835.         }
  1836.       });
  1837.     }
  1838.   }
  1839.  
  1840.  
  1841.   if (id_customer) {
  1842.     $.ajax({
  1843.       url  : "<?php echo base_url('quotation/customer/') ?>" + id_customer,
  1844.       type: "GET",
  1845.       data: {
  1846.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1847.       },
  1848.       datatype: "JSON",
  1849.       success: function (data)
  1850.       {
  1851.         customer = JSON.parse(data);
  1852.         var customer_name = customer[0].customer_name;
  1853.         var customer_address = customer[0].address;
  1854.         var customer_jalan = customer[0].jalan;
  1855.         var customer_city = customer[0].ciname;
  1856.         var customer_country = customer[0].coname;
  1857.         var customer_mobile = customer[0].mobile;
  1858.         var customer_email = customer[0].email;
  1859.         $("#pcostumer_name").text(customer_name);
  1860.         $("#pcostumer_address").text(customer_address);
  1861.         $("#pcostumer_jalan").text(customer_jalan);
  1862.         $("#pcostumer_city").text(customer_city);
  1863.         $("#pcostumer_country").text(customer_country);
  1864.         $("#pcostumer_mobile").text(customer_mobile);
  1865.         $("#pcostumer_email").text(customer_email);
  1866.  
  1867.       },
  1868.       error: function (xhr, status, error)
  1869.       {
  1870.         alert(error);
  1871.       }
  1872.  
  1873.     });
  1874.   }
  1875.  
  1876.   $.ajax({
  1877.     url  : "<?php echo base_url('quotation/company/') ?>",
  1878.     type: "GET",
  1879.     data: {
  1880.       '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1881.     },
  1882.     datatype: "JSON",
  1883.     success: function (data)
  1884.     {
  1885.       customer = JSON.parse(data);
  1886.       var company_name = customer[0].name;
  1887.       var company_city = customer[0].city_name;
  1888.       var company_country = customer[0].country_name;
  1889.       var company_address = customer[0].billing_address;
  1890.       var company_phone = customer[0].phone;
  1891.       var company_email = customer[0].email;
  1892.  
  1893.       $("#pcompany_name").text(company_name);
  1894.       $("#pwarehouse_name").text(company_name);
  1895.       $("#pbranch_address").text(company_address);
  1896.       $("#pbranch_city").text(company_city);
  1897.       $("#pcompany_phone").text(company_phone);
  1898.       $("#company_email").text(company_email);
  1899.  
  1900.     },
  1901.     error: function (xhr, status, error)
  1902.     {
  1903.       alert(error);
  1904.     }
  1905.  
  1906.   });
  1907.  
  1908.   var id = $('#kursdata').val();
  1909.   $.ajax({
  1910.     url: "<?php echo base_url('sales/getCurrencyAjax') ?>/" + id,
  1911.     type: "GET",
  1912.     data: {
  1913.       '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1914.     },
  1915.     datatype: "JSON",
  1916.     success: function (d)
  1917.     {
  1918.       data = JSON.parse(d);
  1919.       var nominalkurs = data[0].nominal;
  1920.       $('#pctrade').text(nominalkurs);
  1921.     },
  1922.     error: function (xhr, status, error)
  1923.     {
  1924.       alert(error);
  1925.     }
  1926.  
  1927.   });
  1928.  
  1929.   if (paid_by == 'advance') {
  1930.    document.getElementById('termin-other').style.display = 'none';
  1931.    document.getElementById('termin-bulan').style.display = 'none';
  1932.  }
  1933.  if (paid_by == 'termin') {
  1934.    document.getElementById('termin-bulan').style.display = 'block';
  1935.    document.getElementById('termin-other').style.display = 'none';
  1936.  
  1937.    var termins =$('#terminnumber').val();
  1938.  
  1939.  
  1940.  
  1941.    for (var i = 1, length = termins; i <= termins; i++)
  1942.    {
  1943.     var nominal = $('#terminvalue'+i).val();
  1944.     var ket = $('#terminket'+i).val();
  1945.     var newRow = $("<tr>");
  1946.     var cols = "";
  1947.     cols += "<td>" + i + "</td>";
  1948.     cols += "<td>" + ((nominal * pbalance)/100)  + "</td>";
  1949.     cols += "<td>" + nominal + "</td>";
  1950.     cols += "<td>" + ket + "</td>";
  1951.     cols += "</tr>";
  1952.     newRow.append(cols);
  1953.     getnewRow = newRow;
  1954.     $("#table-termin-body").append(newRow);
  1955.   }
  1956.  
  1957. }
  1958. if (paid_by == 'others') {
  1959.  document.getElementById('termin-bulan').style.display = 'none';
  1960.  document.getElementById('termin-other').style.display = 'block';
  1961.  $('#termin-other-value').text(othervalue);
  1962. }
  1963. });
  1964.  
  1965. $("#submit").click(function (event) {
  1966.   var name_regex = /^[a-zA-Z]+$/;
  1967.   var sname_regex = /^[a-zA-Z0-9]+$/;
  1968.   var num_regex = /^[0-9]+$/;
  1969.   var date_regex = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/;
  1970.   var date = $('#date').val();
  1971.   var reference_no = $('#reference_no').val();
  1972.   var biller = $('#biller').val();
  1973.   var product = $('#product').val();
  1974.   var customer = $('#customer').val();
  1975.   var discount = $('#discount').val();
  1976.   var internal_note = $('#internal_note').val();
  1977.   var grand_total = $('#grand_total').val();
  1978.  
  1979.   if (customer == "") {
  1980.     $("#err_customer").text("Please Enter Customer");
  1981.     $('#customer').focus();
  1982.     return false;
  1983.   } else {
  1984.     $("#err_customer").text("");
  1985.   }
  1986.             //customer code validation complite.
  1987.  
  1988.             if (grand_total == "" || grand_total == null || grand_total == 0.00) {
  1989.               ;
  1990.               $("#err_product").text("Please Select Product");
  1991.               $('#product').focus();
  1992.               return false;
  1993.             }
  1994.  
  1995.           });
  1996.  
  1997. $("#customer").change(function (event) {
  1998.   var customer = $('#customer').val();
  1999.   if (customer == "") {
  2000.     $("#err_customer").text("Please Enter Customer");
  2001.     $('#customer').focus();
  2002.     return false;
  2003.   } else {
  2004.     $("#err_customer").text("");
  2005.   }
  2006. });
  2007.  
  2008. $("#discount").change(function (event) {
  2009.   var discount = $('#discount').val();
  2010.   if (discount == "") {
  2011.     $("#err_discount").text("Please Enter Discount");
  2012.     $('#discount').focus();
  2013.     return false;
  2014.   } else {
  2015.     $("#err_discount").text("");
  2016.   }
  2017.   if (discount != "") {
  2018.     $.ajax({
  2019.       url: "<?php echo base_url('sales/getDiscountAjax') ?>/" + discount,
  2020.       type: "get",
  2021.       dataType: "json",
  2022.       success: function (data) {
  2023.         var type = data[0].discount_type;
  2024.         var value = data[0].discount_value;
  2025.         var amount = parseInt(data[0].amount);
  2026.         var grand_total = $('#grand_total').val();
  2027.         $('#discount_type').val(type);
  2028.         $('#total_discount').val(value);
  2029.         $('#discount_amount').val(amount);
  2030.         if (grand_total > 0 && grand_total != null) {
  2031.           if (type == "Fixed") {
  2032.             var t = grand_total - value;
  2033.             if (grand_total < amount) {
  2034.               var t = grand_total;
  2035.             }
  2036.             $('#lasttotal').text(t);
  2037.             $('#last_total').val(t);
  2038.             $('#totaldiscount').text(value);
  2039.             $('#total_discount').val(value);
  2040.             $('#discount_type').val(type);
  2041.             $('#discount_amount').val(amount);
  2042.             $('#showdiscount').text(" (Rs " + value + ")");
  2043.           } else {
  2044.             var total = (grand_total * value) / 100;
  2045.             var t = grand_total - total;
  2046.             $('#totaldiscount').text(total);
  2047.             $('#total_discount').val(value);
  2048.             $('#discount_type').val('');
  2049.             $('#discount_amount').val('');
  2050.             $('#lasttotal').text(t);
  2051.             $('#last_total').val(t);
  2052.             $('#showdiscount').text(" (" + value + "%)");
  2053.           }
  2054.         }
  2055.       }
  2056.     });
  2057.   }
  2058. });
  2059.  
  2060. $("#product").blur(function (event) {
  2061.   var sname_regex = /^[a-zA-Z0-9]+$/;
  2062.   var product = $('#product').val();
  2063.   if (product == null || product == "") {
  2064.     $("#err_product").text("Please Enter Product Code/Name");
  2065.     $('#product').focus();
  2066.     return false;
  2067.   } else {
  2068.     $("#err_product").text("");
  2069.   }
  2070.   if (!product.match(sname_regex)) {
  2071.     $('#err_product').text(" Please Enter Valid Product Code/Name ");
  2072.     $('#product').focus();
  2073.     return false;
  2074.   } else {
  2075.     $("#err_product").text("");
  2076.   }
  2077. });
  2078. });
  2079. </script>
  2080. <script type="text/javascript">
  2081.   var hitung = 1;
  2082.   var getfromaddFields = 123;
  2083.  
  2084.   function isNumber(evt) {
  2085.     evt = (evt) ? evt : window.event;
  2086.     var charCode = (evt.which) ? evt.which : evt.keyCode;
  2087.     if (charCode > 31 && (charCode < 48 || charCode > 57)) {
  2088.       return true;
  2089.     }
  2090.     return true;
  2091.   }
  2092.  
  2093.   function isNumber_max_100(evt) {
  2094.     evt = (evt) ? evt : window.event;
  2095.     var charCode = (evt.which) ? evt.which : evt.keyCode;
  2096.     if (charCode > 31 && (charCode < 48 || charCode > 57)) {
  2097.       return false;
  2098.     }
  2099.     getvarhit = hitung;
  2100.     get_nax_100(getvarhit);
  2101.     return true;
  2102.   }
  2103.  
  2104.   function get_nax_100(getvarhitloop) {
  2105.     if (getvarhitloop == 1) {
  2106.       $(".getterminvalue").on("change paste", function () {
  2107.  
  2108.         hitjumlah = 0;
  2109.         for (i = 0; i < getfromaddFields; i++) {
  2110.           new_id = "terminvalue" + (i + 1);
  2111.           number = document.getElementById(new_id).value;
  2112.           if (number) {
  2113.             hitjumlah = parseInt(hitjumlah) + parseInt(number);
  2114.           }
  2115.         }
  2116.         if (hitjumlah > 100) {
  2117.           alert('Termin melebihi 100')
  2118.         }
  2119.       });
  2120.     }
  2121.     hitung = 2;
  2122.   }
  2123.  
  2124.   jQuery.calculateDiscount = function calculateDiscount(row, data = 0) {
  2125.     var discount;
  2126.     if (data == 0) {
  2127.       discount = +row.find('#discount_value').val();
  2128.     } else {
  2129.       discount = data;
  2130.     }
  2131.  
  2132.     var sales_total = +row.find('input[name^="linetotal"]').val();
  2133.     var total_discount = sales_total * discount / 100;
  2134.     row.find('#product_total').val(sales_total - total_discount);
  2135.     row.find('#hidden_discount').val(total_discount);
  2136.     var key = +row.find('input[name^="id"]').val();
  2137.     product_data[key].discount = total_discount;
  2138.     product_data[key].discount_value = +row.find('#discount_value').val();
  2139.     product_data[key].discount_id = +row.find('#item_discount').val();
  2140.     var table_data = JSON.stringify(product_data);
  2141.     $('#table_data').val(table_data);
  2142.   }
  2143.  
  2144.   jQuery.calculateDiscountAdditional = function calculateDiscountAdditional(row, data = 0) {
  2145.     var discount;
  2146.  
  2147.     if (data == 0) {
  2148.       discount = +row.find('#discount_value').val();
  2149.     } else {
  2150.       discount = data;
  2151.     }
  2152.  
  2153.     var sales_total = +row.find('input[name^="linetotal"]').val();
  2154.     var total_discount = sales_total * discount / 100;
  2155.  
  2156.     row.find('#product_total').val(sales_total - total_discount);
  2157.     row.find('#hidden_discount').val(total_discount);
  2158.  
  2159.     var key = +row.find('input[name^="id"]').val();
  2160.     additional_data[key].discount = total_discount;
  2161.     additional_data[key].discount_value = +row.find('#discount_value').val();
  2162.     additional_data[key].discount_id = +row.find('#item_discount').val();
  2163.  
  2164.     var table_data = JSON.stringify(additional_data);
  2165.     $('#tableadditional_data').val(table_data);
  2166.   }
  2167.  
  2168.   jQuery.calculateDiscountService = function calculateDiscountService(row, data = 0)
  2169.   {
  2170.     var discount;
  2171.  
  2172.     if (data == 0) {
  2173.       discount = +row.find('#discountservice_value').val();
  2174.     } else {
  2175.       discount = data;
  2176.     }
  2177.  
  2178.     var sales_total = +row.find('input[name^="linetotalservice"]').val();
  2179.     var total_discount = sales_total * discount / 100;
  2180.  
  2181.     row.find('#service_total').val(sales_total - total_discount);
  2182.     row.find('#hidden_discountservice').val(total_discount);
  2183.  
  2184.     var key = +row.find('input[name^="idservice"]').val();
  2185.     service_data[key].discount = total_discount;
  2186.     service_data[key].discount_value = +row.find('#discountservice_value').val();
  2187.     service_data[key].discount_id = +row.find('#item_discountservice').val();
  2188.  
  2189.     var table_data = JSON.stringify(service_data);
  2190.     $('#tableservice_data').val(table_data);
  2191.  
  2192.   }
  2193.  
  2194.   jQuery.calculateGrandTotal = function calculateGrandTotal(discountdatatext) {
  2195.  
  2196.     var totalValue = 0;
  2197.     var DiscountProduct = 0;
  2198.     var grandTax = 0;
  2199.     var grandTotal = 0;
  2200.     var grandDiskon = 0;
  2201.     var shippingCharge = 0;
  2202.     $("table.service_table").find('input[name^="linetotalservice"]').each(function () {
  2203.       totalValue += +$(this).val();
  2204.     });
  2205.     $("table.service_table").find('input[name^="hidden_discountservice"]').each(function () {
  2206.       DiscountProduct += +$(this).val();
  2207.     });
  2208.  
  2209.     $("table.servicetable").find('input[name^="service_total"]').each(function () {
  2210.       grandTotal += +$(this).val();
  2211.     });
  2212.     $("table.product_table").find('input[name^="linetotal"]').each(function () {
  2213.       totalValue += +$(this).val();
  2214.     });
  2215.     $("table.product_table").find('input[name^="hidden_discount"]').each(function () {
  2216.       DiscountProduct += +$(this).val();
  2217.     });
  2218.  
  2219.     $("table.product_table").find('input[name^="product_total"]').each(function () {
  2220.       grandTotal += +$(this).val();
  2221.     });
  2222.     $("table.summary_table").find('input[name^="shipping_charge"]').each(function () {
  2223.       shippingCharge = +$(this).val();
  2224.     });
  2225.  
  2226.     $("table.additional_table").find('input[name^="linetotal"]').each(function () {
  2227.       totalValue += +$(this).val();
  2228.     });
  2229.     $("table.additional_table").find('input[name^="hidden_discount"]').each(function () {
  2230.       DiscountProduct += +$(this).val();
  2231.     });
  2232.  
  2233.     $("table.additional_table").find('input[name^="product_total"]').each(function () {
  2234.       grandTotal += +$(this).val();
  2235.     });
  2236.  
  2237.  
  2238.     var totaldiskon = 0;
  2239.     grandDiskon = DiscountProduct;
  2240.     var diskonval = 0;
  2241.     var diskonval2 = 0;
  2242.     var diskonpersen = 0;
  2243.     diskonpersen = +$('#DiscountPersen').val();
  2244.     diskonval2 = totalValue - DiscountProduct;
  2245.     diskonval = (diskonpersen / 100) * diskonval2;
  2246.     grandDiskon += diskonval;
  2247.     grandDiskon += +$('#DiscountFix').val();
  2248.     $('Span#totalDiscount').text(grandDiskon);
  2249.     totaldiskon = grandDiskon;
  2250.     grandTotal = grandTotal - totaldiskon + shippingCharge;
  2251.  
  2252.     var taxx = $('#taxx').val();
  2253.     grandTax = ((totalValue - totaldiskon) + shippingCharge) * (taxx / 100);
  2254.     grandTotal = totalValue - totaldiskon + shippingCharge + grandTax;
  2255.  
  2256.     var id = $('#kursdata').val();
  2257.     $.ajax({
  2258.       url: "<?php echo base_url('sales/getCurrencyAjax') ?>/" + id,
  2259.       type: "GET",
  2260.       data: {
  2261.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2262.       },
  2263.       datatype: "JSON",
  2264.       success: function (d)
  2265.       {
  2266.         //alert(d);
  2267.         data = JSON.parse(d);
  2268.         var symbolkurs = data[0].symbol;
  2269.         var nominalkurs = data[0].nominal;
  2270.         var grandval = $('#grand_total').val();
  2271.         var totalkurs = (grandval * nominalkurs);
  2272.  
  2273.         $('#kurs_symbol').text(symbolkurs);
  2274.         $('#kurs_symbol1').text(symbolkurs);
  2275.         $('#kurs_symbol2').text(symbolkurs);
  2276.         $('#kurs_symbol3').text(symbolkurs);
  2277.         $('#kurs_symbol4').text(symbolkurs);
  2278.         $('#kurs_symbol5').text(symbolkurs);
  2279.         $('#kurs_symbol6').text(symbolkurs);
  2280.         $('#kurs_symbol7').text(symbolkurs);
  2281.         $('#grandCurrency').text("Rp. " + totalkurs.toFixed(2));
  2282.         $('#grandCurrency').val("Rp. " + totalkurs.toFixed(2));
  2283.         $('#grand_currency').val(totalkurs.toFixed(2));
  2284.       },
  2285.       error: function (xhr, status, error)
  2286.       {
  2287.         alert(error);
  2288.       }
  2289.  
  2290.     });
  2291.     $('#totalValue').text(totalValue.toFixed(2));
  2292.     $('#total_value').val(totalValue.toFixed(2));
  2293.     $('#DiscountProduct').text(DiscountProduct.toFixed(2));
  2294.     $('#total_discount').val(totaldiskon);
  2295.     $('#totalTax').text(grandTax.toFixed(2));
  2296.     $('#total_tax').val(grandTax.toFixed(2));
  2297.     $('#grandTotal').text(grandTotal.toFixed(2));
  2298.     $('#grand_total').val(grandTotal.toFixed(2));
  2299.   }
  2300. </script>
  2301. <script type="text/javascript">
  2302.  
  2303.   $('#customer').change(function () {
  2304.     var customer_id = $(this).val();
  2305.     $.ajax({
  2306.       url: "<?php echo base_url('sales/getCustomerData') ?>/" + customer_id,
  2307.       type: "GET",
  2308.       dataType: "JSON",
  2309.       data: {
  2310.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2311.       },
  2312.       success: function (data) {
  2313.  
  2314.         $('#company_id').text('');
  2315.         $('#company_name').text('');
  2316.         $('#customer_name').text('');
  2317.         $('#mobilephone').text('');
  2318.         $('#email').text('');
  2319.         $('#npwp').text('');
  2320.         $('#alamat_npwp').text('');
  2321.         $('#npwp').val(data['data'][0].gstid);
  2322.         $('#alamat_npwp').val(data['data'][0].cf2);
  2323.         $('#company_id').val(data['data'][0].cf1);
  2324.         $('#company_name').val(data['data'][0].company_name);
  2325.         $('#po_cust').val(data['data'][0].company_name);
  2326.         $('#customer_name').val(data['data'][0].customer_name);
  2327.         $('#mobilephone').val(data['data'][0].mobile);
  2328.         $('#email').val(data['data'][0].email);
  2329.  
  2330.         $('#customer_address')
  2331.         .find('option')
  2332.         .remove()
  2333.         .end()
  2334.         .append('<option value="">Select Shipping</option>')
  2335.         ;
  2336.  
  2337.         $('#customer_addressa')
  2338.         .find('option')
  2339.         .remove()
  2340.         .end()
  2341.         .append('<option value="">Select Billing</option>')
  2342.         ;
  2343.  
  2344.         $('#country').val('');
  2345.         $('#state').val('');
  2346.         $('#city').val('');
  2347.  
  2348.         if (typeof data['address'][0] != 'undefined') {
  2349.           var cid = data['address'][0].customer_id;
  2350.           for (a = 0; a < data['address'].length; a++) {
  2351.             if (data['address'][a].type == 0) {
  2352.               $('#customer_address').append('<option value="' + data['address'][a].id + '">' + data['address'][a].address + '</option>');
  2353.             }
  2354.           }
  2355.         } else {
  2356.           var cid = "";
  2357.         }
  2358.  
  2359.         if (typeof data['address'][0] != 'undefined') {
  2360.           var cid = data['address'][0].customer_id;
  2361.           for (a = 0; a < data['address'].length; a++) {
  2362.             if (data['address'][a].type == 1) {
  2363.               $('#customer_addressa').append('<option value="' + data['address'][a].id + '">' + data['address'][a].address + '</option>');
  2364.             }
  2365.           }
  2366.         } else {
  2367.           var cid = "";
  2368.         }
  2369.       }
  2370.     });
  2371.  
  2372.     $("#single-input").empty().trigger("change");
  2373.     number = '';
  2374.     $('#single-input')
  2375.     .find('option')
  2376.     .remove()
  2377.     .end()
  2378.     .append('<option value="">Select Quotation</option>')
  2379.     ;
  2380.     $.ajax({
  2381.       url: "<?php echo base_url('sales/getRecordAjax') ?>/" + customer_id,
  2382.       type: "GET",
  2383.       dataType: "JSON",
  2384.       data: {
  2385.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2386.       },
  2387.       success: function (data) {
  2388.         for (a = 0; a < data['data'].length; a++) {
  2389.           if (data['data'][a].reference_no2 != null) {
  2390.             number = data['data'][a].reference_no2;
  2391.           } else {
  2392.             number = data['data'][a].reference_no;
  2393.           }
  2394.           $('#single-input').append('<option value="' + data['data'][a].quotation_id + '">' + number + '</option>');
  2395.         }
  2396.       },
  2397.       error: function (jqxhr, status, exception) {
  2398.         alert('Exception:', exception);
  2399.       }
  2400.     });
  2401.  
  2402.     $("#multiple-input").empty().trigger("change");
  2403.     number = '';
  2404.     $('#multiple-input')
  2405.     .find('option')
  2406.     .remove()
  2407.     .end()
  2408.     .append('<option value="">Select Quotation</option>')
  2409.     ;
  2410.     $.ajax({
  2411.       async: false,
  2412.       url: "<?php echo base_url('sales/getRecordAjax') ?>/" + customer_id,
  2413.       type: "GET",
  2414.       dataType: "JSON",
  2415.       data: {
  2416.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2417.       },
  2418.       success: function (data) {
  2419.         for (a = 0; a < data['data'].length; a++) {
  2420.           if (data['data'][a].reference_no2 != null) {
  2421.             number = data['data'][a].reference_no2;
  2422.           } else {
  2423.             number = data['data'][a].reference_no;
  2424.           }
  2425.           $('#multiple-input').append('<option value="' + data['data'][a].quotation_id + '">' + number + '</option>');
  2426.           $("#multiple-input").trigger("change");
  2427.         }
  2428.       },
  2429.       error: function (jqxhr, status, exception) {
  2430.         alert('Exception:', exception);
  2431.       }
  2432.     });
  2433.  
  2434.   });
  2435.  
  2436. $('#selectmultiple').change(function (){
  2437.   var select = $(this).val();
  2438.   if (select == 1) {
  2439.     $('.single').show();
  2440.     $('#single-input').attr('name', 'reference_no');
  2441.     $('.multiple').hide();
  2442.     $('#multiple-input').removeAttr('name','');
  2443.     document.getElementById('preference_no').style.display = 'none';
  2444.   } else {
  2445.    $('.single').hide();
  2446.    $('#single-input').attr('name', 'reference_no');
  2447.    $('.multiple').show();
  2448.    $('#multiple-input').removeAttr('name','');
  2449.    document.getElementById('preference_no').style.display = 'none';
  2450.  }
  2451. });
  2452.  
  2453. $('#multiple-input').change(function () {
  2454.   var single = $('#selectmultiple').val();
  2455.   if (single == 1) {
  2456.     var refno = $(this).val();
  2457.     if (refno != null) {
  2458.       $.ajax({
  2459.         url: "<?php echo base_url('quotation/getDataQuotation') ?>/" + refno,
  2460.         type: "GET",
  2461.         dataType: "JSON",
  2462.         data: refno,
  2463.         success: function (data) {
  2464.           $('#DiscountPersen').val(parseInt(data[0].diskonpersen));
  2465.           $('#DiscountFix').val(parseInt(data[0].diskon));
  2466.           $('#shipping_charge').val(parseInt(data[0].shipping_charge));
  2467.           $('#note').val(data[0].note);
  2468.           $('#internal_note').val(data[0].internal_note);
  2469.           $('#term_and_condition').val(data[0].term_and_condition);
  2470.           $('#upcc').val(data[0].upcc);
  2471.           $('#upcc2').val(data[0].upcc2);
  2472.           $('#tax option[value='+ data[0].attn +']').attr('selected','selected');
  2473.           $('#terminnumber option[value='+ data['termin'].length +']').attr('selected','selected');
  2474.  
  2475.           $('input[name=paymenterms][value='+ data[0].paid_by +']').prop('checked', true).click();
  2476.           if ('termin' == data[0].paid_by) {
  2477.             var e = document.getElementById("terminnumber");
  2478.             var number = e.options[e.selectedIndex].value;
  2479.             getfromaddFields = number;
  2480.             var container = document.getElementById("termincontainer");
  2481.             while (container.hasChildNodes())
  2482.             {
  2483.               container.removeChild(container.lastChild);
  2484.             }
  2485.  
  2486.  
  2487.             var container = container.appendChild(document.createElement("table"));
  2488.             container.className = "table table-bordered";
  2489.             var container = container.appendChild(document.createElement("tbody"));
  2490.             var artermin = data['termin'];
  2491.             for (i = 0; i < number; i++)
  2492.             {
  2493.               var containertr = container.appendChild(document.createElement("tr"));
  2494.               var containertd = containertr.appendChild(document.createElement("td"));
  2495.               z = document.createElement('span');
  2496.               z.innerHTML = "Termin Ke  % " + (i + 1) + "  :";
  2497.               z.className = "text-danger";
  2498.               containertd.appendChild(z);
  2499.               var input = document.createElement("input");
  2500.               input.type = "number";
  2501.               input.name = "terminvalue[" + (i + 1) + "]";
  2502.               input.id = "terminvalue[" + (i + 1)+"]";
  2503.               input.className = "getterminvalue";
  2504.               input.value = artermin[i].persen;
  2505.               input.min = 1;
  2506.               input.max = 100;
  2507.               input.maxlength = "2";
  2508.               input.onkeypress = isNumber_max_100;
  2509.               var containertd = containertr.appendChild(document.createElement("td"));
  2510.               containertd.appendChild(input);
  2511.               z = document.createElement('span');
  2512.               z.className = "text-primary";
  2513.               z.innerHTML = ' Ket: ';
  2514.               var containertd = containertr.appendChild(document.createElement("td"));
  2515.               containertd.appendChild(z);
  2516.               var input2 = document.createElement("input");
  2517.               input2.type = "text";
  2518.               input2.name = "terminket[" + (i + 1) + "]";
  2519.               input2.id = "terminket[" + (i + 1)+"]";
  2520.               input2.className = "getterminket";
  2521.               input2.value = artermin[i].keterangan;
  2522.               var containertd = containertr.appendChild(document.createElement("td"));
  2523.               containertd.appendChild(input2);
  2524.             }
  2525.           }
  2526.         },
  2527.         error: function (jqxhr, status, exception) {
  2528.         }
  2529.       });
  2530.     }
  2531.   } else {
  2532.     var refno = $(this).val().join('_');
  2533.   }
  2534.   $.ajax({
  2535.     url: "<?php echo base_url('quotation/getQuotationItemsAjax') ?>/" + refno,
  2536.     type: "GET",
  2537.     dataType: "JSON",
  2538.     data: refno,
  2539.     success: function (data) {
  2540.       product_data = Array();
  2541.       $.generateItem(data);
  2542.     },
  2543.     error: function (jqxhr, status, exception) {
  2544.     }
  2545.   });
  2546.   $.ajax({
  2547.     url: "<?php echo base_url('quotation/getQuotationAdditionalAjax') ?>/" + refno,
  2548.     type: "GET",
  2549.     dataType: "JSON",
  2550.     data: refno,
  2551.     success: function (data) {
  2552.       additional_data = Array();
  2553.       $.generateAdditionalItem(data);
  2554.     },
  2555.     error: function (jqxhr, status, exception) {
  2556.     }
  2557.   });
  2558.   $.ajax({
  2559.     url: "<?php echo base_url('quotation/getQuotationServiceItemsAjax') ?>/" + refno,
  2560.     type: "GET",
  2561.     dataType: "JSON",
  2562.     data: refno,
  2563.     success: function (data) {
  2564.       service_data = Array();
  2565.       $.generateServiceItem(data);
  2566.     },
  2567.     error: function (jqxhr, status, exception) {
  2568.     }
  2569.   });
  2570. });
  2571.  
  2572. $('#single-input').change(function () {
  2573.   var single = $('#selectmultiple').val();
  2574.   if (single == 1) {
  2575.     var refno = $(this).val();
  2576.     if (refno != null) {
  2577.       $.ajax({
  2578.         url: "<?php echo base_url('quotation/getDataQuotation') ?>/" + refno,
  2579.         type: "GET",
  2580.         dataType: "JSON",
  2581.         data: refno,
  2582.         success: function (data) {
  2583.           $('#DiscountPersen').val(parseInt(data[0].diskonpersen));
  2584.           $('#DiscountFix').val(parseInt(data[0].diskon));
  2585.           $('#shipping_charge').val(parseInt(data[0].shipping_charge));
  2586.           $('#note').val(data[0].note);
  2587.           $('#internal_note').val(data[0].internal_note);
  2588.           $('#term_and_condition').val(data[0].term_and_condition);
  2589.           $('#upcc').val(data[0].upcc);
  2590.           $('#upcc2').val(data[0].upcc2);
  2591.           $('#tax option[value='+ data[0].attn +']').attr('selected','selected');
  2592.           $('#terminnumber option[value='+ data['termin'].length +']').attr('selected','selected');
  2593.  
  2594.           $('input[name=paymenterms][value='+ data[0].paid_by +']').prop('checked', true).click();
  2595.           if ('termin' == data[0].paid_by) {
  2596.             var e = document.getElementById("terminnumber");
  2597.             var number = e.options[e.selectedIndex].value;
  2598.             getfromaddFields = number;
  2599.             var container = document.getElementById("termincontainer");
  2600.             while (container.hasChildNodes())
  2601.             {
  2602.               container.removeChild(container.lastChild);
  2603.             }
  2604.  
  2605.  
  2606.             var container = container.appendChild(document.createElement("table"));
  2607.             container.className = "table table-bordered";
  2608.             var container = container.appendChild(document.createElement("tbody"));
  2609.             var artermin = data['termin'];
  2610.             for (i = 0; i < number; i++)
  2611.             {
  2612.               var containertr = container.appendChild(document.createElement("tr"));
  2613.               var containertd = containertr.appendChild(document.createElement("td"));
  2614.               z = document.createElement('span');
  2615.               z.innerHTML = "Termin Ke  % " + (i + 1) + "  :";
  2616.               z.className = "text-danger";
  2617.               containertd.appendChild(z);
  2618.               var input = document.createElement("input");
  2619.               input.type = "number";
  2620.               input.name = "terminvalue[" + (i + 1) + "]";
  2621.               input.id = "terminvalue[" + (i + 1)+"]";
  2622.               input.className = "getterminvalue";
  2623.               input.value = artermin[i].persen;
  2624.               input.min = 1;
  2625.               input.max = 100;
  2626.               input.maxlength = "2";
  2627.               input.onkeypress = isNumber_max_100;
  2628.               var containertd = containertr.appendChild(document.createElement("td"));
  2629.               containertd.appendChild(input);
  2630.               z = document.createElement('span');
  2631.               z.className = "text-primary";
  2632.               z.innerHTML = ' Ket: ';
  2633.               var containertd = containertr.appendChild(document.createElement("td"));
  2634.               containertd.appendChild(z);
  2635.               var input2 = document.createElement("input");
  2636.               input2.type = "text";
  2637.               input2.name = "terminket[" + (i + 1) + "]";
  2638.               input2.id = "terminket[" + (i + 1)+"]";
  2639.               input2.className = "getterminket";
  2640.               input2.value = artermin[i].keterangan;
  2641.               var containertd = containertr.appendChild(document.createElement("td"));
  2642.               containertd.appendChild(input2);
  2643.             }
  2644.           }
  2645.         },
  2646.         error: function (jqxhr, status, exception) {
  2647.         }
  2648.       });
  2649.     }
  2650.   } else {
  2651.     var refno = $(this).val().join('_');
  2652.   }
  2653.   $.ajax({
  2654.     url: "<?php echo base_url('quotation/getQuotationItemsAjax') ?>/" + refno,
  2655.     type: "GET",
  2656.     dataType: "JSON",
  2657.     data: refno,
  2658.     success: function (data) {
  2659.       product_data = Array();
  2660.       $.generateItem(data);
  2661.     },
  2662.     error: function (jqxhr, status, exception) {
  2663.     }
  2664.   });
  2665.   $.ajax({
  2666.     url: "<?php echo base_url('quotation/getQuotationAdditionalAjax') ?>/" + refno,
  2667.     type: "GET",
  2668.     dataType: "JSON",
  2669.     data: refno,
  2670.     success: function (data) {
  2671.       additional_data = Array();
  2672.       $.generateAdditionalItem(data);
  2673.     },
  2674.     error: function (jqxhr, status, exception) {
  2675.     }
  2676.   });
  2677.   $.ajax({
  2678.     url: "<?php echo base_url('quotation/getQuotationServiceItemsAjax') ?>/" + refno,
  2679.     type: "GET",
  2680.     dataType: "JSON",
  2681.     data: refno,
  2682.     success: function (data) {
  2683.       service_data = Array();
  2684.       $.generateServiceItem(data);
  2685.     },
  2686.     error: function (jqxhr, status, exception) {
  2687.     }
  2688.   });
  2689. });
  2690.  
  2691. jQuery.generateItem = function generateItem(items) {
  2692.  
  2693.   var counter = 1;
  2694.   var aritem = items;
  2695.   for (itemrec = 0; itemrec < aritem.length; itemrec++) {
  2696.     (function (counter) {
  2697.       var getnewRow;
  2698.       var quotationid = aritem[itemrec].id;
  2699.       var itemquantity = aritem[itemrec].quantity;
  2700.       var itemprice = aritem[itemrec].qprice;
  2701.       var itemdiscountid = aritem[itemrec].discount_id;
  2702.       var itemdiscountid = aritem[itemrec].discount_id;
  2703.       var itemdiscountvalue = aritem[itemrec].discount_value;
  2704.       var itemdiscount = aritem[itemrec].discount;
  2705.       var itemgross_total = aritem[itemrec].gross_total;
  2706.       var product_id = aritem[itemrec].product_id;
  2707.       var itemdesc = aritem[itemrec].serial_no;
  2708.  
  2709.       if (product_id == null) {
  2710.         alert('Product Tidak Terdaftar Lagi');
  2711.       } else {
  2712.         var flag = 0;
  2713.         $('#err_product').text('');
  2714.         $.ajax({
  2715.           url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
  2716.           type: "GET",
  2717.           dataType: "JSON",
  2718.           data: {
  2719.             '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2720.           },
  2721.           success: function (data) {
  2722.             $("table.product_table").find('input[name^="product_id"]').each(function () {
  2723.               // if (data[0].product_id == +$(this).val()) {
  2724.               //   flag = 1;
  2725.               // }
  2726.             });
  2727.             if (flag == 0) {
  2728.               var id = data[0].product_id;
  2729.               var price = itemprice;
  2730.               var code = data[0].code;
  2731.               var name = data[0].name;
  2732.               var itembyp = data[0].item_namebyp;
  2733.               var product = {"product_id": id,
  2734.               "price": price, "desc": itemdesc
  2735.             };
  2736.             product_data[yi] = product;
  2737.             length = product_data.length - 1;
  2738.  
  2739.             var select_discount = "";
  2740.             select_discount += '<div class="form-group">';
  2741.             select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
  2742.             select_discount += '<option value="">Select</option>';
  2743.             var selected = '';
  2744.             for (a = 0; a < data['discount'].length; a++) {
  2745.               if (data['discount'][a].discount_id == itemdiscountid) {
  2746.                 selected = 'selected ';
  2747.               } else {
  2748.                 selected = '';
  2749.               }
  2750.               select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  2751.             }
  2752.             select_discount += '</select></div>';
  2753.  
  2754.             var newRow = $("<tr id='tr" + yi + "'>");
  2755.             var cols = "";
  2756.             cols += "<td><a class='deleteRow'> <img src='<?php echo base_url(); ?>assets/images/bin3.png' /> </a><input type='hidden' name='id' name='id' value=" + yi + "><input type='hidden' name='product_id' name='product_id' value=" + id + "></td>";
  2757.             cols += "<td>" + code + "</td>";
  2758.             cols += "<td>"
  2759.             + "<input type='hidden' value='" + data[0].code + "' name='nameProduct" + counter + "' id='nameProduct" + counter + "'>"
  2760.             + "<input type='hidden' value='" + data[0].product_id + "' name='idProduct" + counter + "' id='idProduct" + counter + "'>"
  2761.             + name + "</td>";
  2762.             cols += "<td>" + itembyp + "</td>";
  2763.             cols += "<td><input type='text' class='form-control text-center' value='" + itemdesc + "' name='description" + counter + "' id='description" + counter + "' ></td>";
  2764.             cols += "<td><input type='number' class='form-control text-center' value='" + itemquantity + "' data-rule='quantity' name='qty" + counter + "' id='qty" + counter + "' min='1' max='" + data[0].quantity + "'></td>";
  2765.             cols += "<td id='column-color'>" + data[0].quantity + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'></td>";
  2766.             cols += "<td>" + data[0].unit + "</td>";
  2767.  
  2768.             cols += "<td align='right'><span><input type='text' class='form-control text-right' value='" + price + "' name='price" + counter + "' id='price" + counter + "'></span></td>";
  2769.  
  2770.             cols += "<td><span id='sub_total'><input type='text' class='form-control text-right' style='' value='" + itemgross_total + "' name='linetotal" + counter + "' id='linetotal" + counter + "' readonly></span></td>";
  2771.  
  2772.             cols += '<td><input value="' + itemdiscountvalue + '" type="hidden" id="discount_value" name="discount_value"><input type="hidden" id="hidden_discount" name="hidden_discount">' + select_discount + '</td>';
  2773.  
  2774.             cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
  2775.             cols += "</tr>";
  2776.  
  2777.             newRow.append(cols);
  2778.             getnewRow = newRow;
  2779.             $("table.product_table").append(newRow);
  2780.             calculateRow($('tr#tr' + yi));
  2781.             $.calculateDiscount($('tr#tr' + yi));
  2782.             $.calculateGrandTotal();
  2783.             counter++;
  2784.             var table_data = JSON.stringify(product_data);
  2785.             $('#table_data').val(table_data);
  2786.             yi++;
  2787.           } else {
  2788.             $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  2789.           }
  2790.         }
  2791.       });
  2792. }
  2793. })(itemrec);
  2794. }
  2795.  
  2796.  
  2797.  
  2798. function calculateRow(row) {
  2799.  
  2800.   var key = +row.find('input[name^="id"]').val();
  2801.   var price = +row.find('input[name^="price"]').val();
  2802.   var qty = +row.find('input[name^="qty"]').val();
  2803.   var desc = row.find('input[name^="description"]').val();
  2804.  
  2805.   row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
  2806.  
  2807.   var availableqty = +row.find('input[name^="available_quantity"]').val();
  2808.   var bookqty = qty - availableqty;
  2809.   if (bookqty > 0) {
  2810.     row.find('td[id^="column-color"]').css({'background-color': 'red'});
  2811.   }
  2812.  
  2813.   product_data[key].quantity = qty;
  2814.   product_data[key].price = price;
  2815.   product_data[key].desc = desc;
  2816.   product_data[key].total = (price * qty).toFixed(2);
  2817.   var table_data = JSON.stringify(product_data);
  2818.   $('#table_data').val(table_data);
  2819. }
  2820.  
  2821. }
  2822.  
  2823. jQuery.generateAdditionalItem = function generateAdditionalItem(additional) {
  2824.  
  2825.   var counter = 1;
  2826.   var aritem = additional;
  2827.   for (itemrec = 0; itemrec < aritem.length; itemrec++) {
  2828.     (function (counter) {
  2829.       var getnewRow;
  2830.       var quotationid = aritem[itemrec].id;
  2831.       var itemquantity = aritem[itemrec].quantity;
  2832.       var itemprice = aritem[itemrec].qprice;
  2833.       var itemdiscountid = aritem[itemrec].discount_id;
  2834.       var itemdiscountid = aritem[itemrec].discount_id;
  2835.       var itemdiscountvalue = aritem[itemrec].discount_value;
  2836.       var itemdiscount = aritem[itemrec].discount;
  2837.       var itemgross_total = aritem[itemrec].gross_total;
  2838.       var product_id = aritem[itemrec].product_id;
  2839.       var itemdesc = aritem[itemrec].desc;
  2840.  
  2841.       if (product_id == null) {
  2842.         alert('Additional Product Tidak Terdaftar Lagi');
  2843.       } else {
  2844.  
  2845.         var flag = 0;
  2846.         $('#err_product').text('');
  2847.         $.ajax({
  2848.           url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
  2849.           type: "GET",
  2850.           dataType: "JSON",
  2851.           data: {
  2852.             '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2853.           },
  2854.           success: function (data) {
  2855.             $("table.additional_table").find('input[name^="additional_id"]').each(function () {
  2856.               // if (data[0].product_id == +$(this).val()) {
  2857.               //   flag = 1;
  2858.               // }
  2859.             });
  2860.             if (flag == 0) {
  2861.               var id = data[0].product_id;
  2862.               var price = itemprice;
  2863.               var code = data[0].code;
  2864.               var name = data[0].name;
  2865.               var itembyp = data[0].item_namebyp;
  2866.               var product = {"additional_id": id,
  2867.               "price": price, "desc": itemdesc
  2868.             };
  2869.             additional_data[j] = product;
  2870.             length = additional_data.length - 1;
  2871.  
  2872.             var select_discount = "";
  2873.             select_discount += '<div class="form-group">';
  2874.             select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
  2875.             select_discount += '<option value="">Select</option>';
  2876.             var selected = '';
  2877.             for (a = 0; a < data['discount'].length; a++) {
  2878.               if (data['discount'][a].discount_id == itemdiscountid) {
  2879.                 selected = 'selected ';
  2880.               } else {
  2881.                 selected = '';
  2882.               }
  2883.               select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  2884.             }
  2885.             select_discount += '</select></div>';
  2886.  
  2887.             var newRow = $("<tr id='tra" + j + "'>");
  2888.             var cols = "";
  2889.             cols += "<td><a class='deleteRow'> <img src='<?php echo base_url(); ?>assets/images/bin3.png' /> </a><input type='hidden' name='id' name='id' value=" + j + "><input type='hidden' name='additional_id' name='additional_id' value=" + id + "></td>";
  2890.             cols += "<td>" + code + "</td>";
  2891.             cols += "<td>"
  2892.             + "<input type='hidden' value='" + data[0].code + "' name='nameProduct" + counter + "' id='nameProduct" + counter + "'>"
  2893.             + "<input type='hidden' value='" + data[0].product_id + "' name='idProduct" + counter + "' id='idProduct" + counter + "'>"
  2894.             + name + "</td>";
  2895.             cols += "<td>" + itembyp + "</td>";
  2896.             cols += "<td><input type='text' class='form-control text-center' value='" + itemdesc + "' name='description" + counter + "' id='description" + counter + "' ></td>";
  2897.             cols += "<td><input type='number' class='form-control text-center' value='" + itemquantity + "' data-rule='quantity' name='qty" + counter + "' id='qty" + counter + "' min='1' max='" + data[0].quantity + "'></td>";
  2898.             cols += "<td>" + data[0].quantity + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'></td>";
  2899.             cols += "<td>" + data[0].unit + "</td>";
  2900.  
  2901.             cols += "<td align='right'><span><input type='text' class='form-control text-right' value='" + price + "' name='price" + counter + "' id='price" + counter + "'></span></td>";
  2902.  
  2903.             cols += "<td><span id='sub_total'><input type='text' class='form-control text-right' style='' value='" + itemgross_total + "' name='linetotal" + counter + "' id='linetotal" + counter + "' readonly></span></td>";
  2904.  
  2905.             cols += '<td><input value="' + itemdiscountvalue + '" type="hidden" id="discount_value" name="discount_value"><input type="hidden" id="hidden_discount" name="hidden_discount">' + select_discount + '</td>';
  2906.  
  2907.             cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
  2908.             cols += "</tr>";
  2909.  
  2910.             newRow.append(cols);
  2911.             getnewRow = newRow;
  2912.             $("table.additional_table").append(newRow);
  2913.             calculateRowAdditional($('tr#tra' + j));
  2914.             $.calculateDiscountAdditional($('tr#tra' + j));
  2915.             $.calculateGrandTotal();
  2916.             counter++;
  2917.             var table_data = JSON.stringify(additional_data);
  2918.             $('#tableadditional_data').val(table_data);
  2919.             j++;
  2920.           } else {
  2921.             $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  2922.           }
  2923.         }
  2924.       });
  2925. }
  2926. })(itemrec);
  2927. }
  2928.  
  2929.  
  2930.  
  2931. function calculateRowAdditional(row) {
  2932.  
  2933.   var key = +row.find('input[name^="id"]').val();
  2934.   var price = +row.find('input[name^="price"]').val();
  2935.   var qty = +row.find('input[name^="qty"]').val();
  2936.   var desc = row.find('input[name^="description"]').val();
  2937.  
  2938.   row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
  2939.  
  2940.   var availableqty = +row.find('input[name^="available_quantity"]').val();
  2941.   var bookqty = qty - availableqty;
  2942.   if (bookqty > 0) {
  2943.     row.find('td[id^="column-color"]').css({'background-color': 'red'});
  2944.   }
  2945.  
  2946.   additional_data[key].quantity = qty;
  2947.   additional_data[key].price = price;
  2948.   additional_data[key].desc = desc;
  2949.   additional_data[key].total = (price * qty).toFixed(2);
  2950.   var table_data = JSON.stringify(additional_data);
  2951.   $('#tableadditional_data').val(table_data);
  2952. }
  2953.  
  2954. }
  2955.  
  2956. jQuery.generateServiceItem = function generateServiceItem(serviceitem) {
  2957.   var counter = 1;
  2958.   var aritem = serviceitem;
  2959.   for (itemrec = 0; itemrec < aritem.length; itemrec++) {
  2960.     (function (counter) {
  2961.       var getnewRowService;
  2962.       var quotationid = aritem[itemrec].id;
  2963.       var itemquantity = aritem[itemrec].quantity;
  2964.       var itemprice = aritem[itemrec].qprice;
  2965.       var itemdiscountid = aritem[itemrec].discount_id;
  2966.       var itemdiscountvalue = aritem[itemrec].discount_value;
  2967.       var itemdiscount = aritem[itemrec].discount;
  2968.       var itemgross_total = aritem[itemrec].gross_total;
  2969.       var service_id = aritem[itemrec].service_id;
  2970.       var flag = 0;
  2971.       $('#err_service').text('');
  2972.       $.ajax({
  2973.         url: "<?php echo base_url('sales/getService') ?>/" + service_id,
  2974.         type: "GET",
  2975.         dataType: "JSON",
  2976.         data: {
  2977.           '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2978.         },
  2979.         success: function (data) {
  2980.           $("table.service_table").find('input[name^="service_id"]').each(function () {
  2981.             if (data[0].service_id == +$(this).val()) {
  2982.               flag = 1;
  2983.             }
  2984.           });
  2985.           if (flag == 0)
  2986.           {
  2987.             var id = data[0].service_id;
  2988.             var code = data[0].code;
  2989.             var name = data[0].service_title;
  2990.             var price = itemprice;
  2991.             if (price == null) {
  2992.               price = 0;
  2993.             }
  2994.             var product = {"service_id": id,
  2995.             "price": price
  2996.           };
  2997.           service_data[k] = product;
  2998.           length = service_data.length - 1;
  2999.  
  3000.           var select_discount = "";
  3001.           select_discount += '<div class="form-group">';
  3002.           select_discount += '<select class="form-control select2" id="item_discountservice" name="item_discountservice" style="width: 100%;">';
  3003.           select_discount += '<option value="">Select</option>';
  3004.           var selected = '';
  3005.           for (a = 0; a < data['discount'].length; a++) {
  3006.             if (data['discount'][a].discount_id == itemdiscountid) {
  3007.               selected = 'selected ';
  3008.             } else {
  3009.               selected = '';
  3010.             }
  3011.             select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  3012.           }
  3013.           select_discount += '</select></div>';
  3014.  
  3015.           var newRowService = $("<tr id='trv" + counter + "'>");
  3016.           var cols = "";
  3017.           cols += "<td><a class='deleteRow'> <img src='<?php echo base_url(); ?>assets/images/bin3.png' /> </a><input type='hidden' name='idservice' name='idservice' value=" + k + "><input type='hidden' name='service_id' name='service_id' value=" + id + "></td>";
  3018.           cols += "<td>" + code + "</td>";
  3019.           cols += "<td>"
  3020.           + "<input type='hidden' value='' name='nameService" + counter + "' id='nameService" + counter + "'>"
  3021.           + name + "</td>";
  3022.           cols += "<td>"
  3023.           + "<input type='number' class='form-control text-center' value='" + itemquantity + "' data-rule='quantity' name='qtyservice" + counter + "' id='qtyservice" + counter + "' min='0' max='2'>"
  3024.           + "</td>";
  3025.           cols += "<td align='right'>"
  3026.           + "<span id='price'>"
  3027.           + "<input type='text' class='form-control text-right' name='priceservice" + counter + "' id='priceservice" + counter + "' value='" + price
  3028.           + "'>"
  3029.           + "</span>"
  3030.           + "</td>";
  3031.           cols += "<td>"
  3032.           + "<span id='sub_total'>"
  3033.           + "<input type='text' class='form-control text-right' style='' value='" + itemgross_total + "' name='linetotalservice" + counter + "' id='linetotalservice" + counter + "' readonly>"
  3034.           + "</span>"
  3035.           + "</td>";
  3036.           cols += '<td><input type="hidden" value="' + itemdiscountvalue + '" id="discountservice_value" name="discountservice_value"><input type="hidden" id="hidden_discountservice" name="hidden_discountservice">' + select_discount + '</td>';
  3037.           cols += '<td><input type="text" class="form-control text-right" id="service_total" name="service_total" readonly></td>';
  3038.           cols += "</tr>";
  3039.           newRowService.append(cols);
  3040.           getnewRowService = newRowService;
  3041.           $("table.service_table").append(newRowService);
  3042.           calculateRowService($('tr#trv' + k));
  3043.           $.calculateDiscountService($('tr#trv' + k));
  3044.           $.calculateGrandTotal();
  3045.           counter++;
  3046.           var table_data = JSON.stringify(service_data);
  3047.           $('#tableservice_data').val(table_data);
  3048.           k++;
  3049.         } else {
  3050.           $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  3051.         }
  3052.       }
  3053.     });
  3054. })(itemrec);
  3055. }
  3056.  
  3057. function calculateRowService(row)
  3058. {
  3059.   var key = +row.find('input[name^="idservice"]').val();
  3060.   var price = +row.find('input[name^="priceservice"]').val();
  3061.   var qty = +row.find('input[name^="qtyservice"]').val();
  3062.   var total = +row.find('input[name^="linetotalservice"]').val();
  3063.   row.find('input[name^="linetotalservice"]').val((price * qty).toFixed(2));
  3064.   service_data[key].price = price;
  3065.   service_data[key].quantity = qty;
  3066.   service_data[key].total = total;
  3067.   var table_data = JSON.stringify(service_data);
  3068.   $('#tableservice_data').val(table_data);
  3069. }
  3070. }
  3071. </script>
  3072. <script>
  3073.   $(document).ready(function () {
  3074.     $.ajax({
  3075.       url: "<?php echo base_url('customer/getState') ?>/" + 102,
  3076.       type: "GET",
  3077.       dataType: "JSON",
  3078.       data: {
  3079.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  3080.       },
  3081.       success: function (data) {
  3082.         for (a = 0; a < data.length; a++) {
  3083.           $('#statec').append('<option value="' + data[a].id + '">' + data[a].name + '</option>');
  3084.         }
  3085.       }
  3086.     });
  3087.   });
  3088.  
  3089.   $('#countryc').change(function () {
  3090.     $('#statec').html('');
  3091.     $('#statec').html('<option value="">Select State</option>');
  3092.     var country_id = $('#countryc').val();
  3093.     $.ajax({
  3094.       url: "<?php echo base_url('customer/getState') ?>/" + country_id,
  3095.       type: "GET",
  3096.       dataType: "JSON",
  3097.       data: {
  3098.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  3099.       },
  3100.       success: function (data) {
  3101.         for (a = 0; a < data.length; a++) {
  3102.           $('#statec').append('<option value="' + data[a].id + '">' + data[a].name + '</option>');
  3103.         }
  3104.       }
  3105.     });
  3106.   });
  3107.  
  3108.   $('#statec').change(function () {
  3109.     $('#cityc').html('');
  3110.     $('#cityc').html('<option value="">Select City</option>');
  3111.     var state_id = $('#statec').val();
  3112.     $.ajax({
  3113.       url: "<?php echo base_url('customer/getCity') ?>/" + state_id,
  3114.       type: "GET",
  3115.       dataType: "JSON",
  3116.       data: {
  3117.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  3118.       },
  3119.       success: function (data) {
  3120.         for (a = 0; a < data.length; a++) {
  3121.           $('#cityc').append('<option value="' + data[a].id + '">' + data[a].name + '</option>');
  3122.         }
  3123.       }
  3124.     });
  3125.   });
  3126.  
  3127.   $('#btn_submit').click(function (e) {
  3128.     e.preventDefault();
  3129.     $.ajax({
  3130.       url: '<?php echo base_url('customer/test') ?>',
  3131.       datatype: 'JSON',
  3132.       method: 'POST',
  3133.       data: {
  3134.         'customer_name': $('#c_name').val(),
  3135.         'address': $("#c_address").val(),
  3136.         'country': $("#countryc").val(),
  3137.         'state': $("#statec").val(),
  3138.         'city': $("#cityc").val(),
  3139.         'mobile': $('#c_mobile').val()
  3140.       },
  3141.       success: function (data) {
  3142.         if (data == 1) {
  3143.           $('#myModal').modal('hide');
  3144.           updateCostumer();
  3145.         } else {
  3146.           alert("Try again");
  3147.         }
  3148.       }
  3149.     })
  3150.   })
  3151.  
  3152.   function updateCostumer() {
  3153.     $('#customer').html('');
  3154.     $('#customer').html('<option value="">Select Customer</option>');
  3155.     $.ajax({
  3156.       url: "<?php echo base_url('customer/getData') ?>",
  3157.       type: "GET",
  3158.       dataType: "JSON",
  3159.       data: {
  3160.         '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  3161.       },
  3162.       success: function (data) {
  3163.         for (a = 0; a < data.length; a++) {
  3164.           $('#customer').append('<option value="' + data[a].customer_id + '">' + data[a].customer_name + '</option>');
  3165.         }
  3166.       }
  3167.     });
  3168.   }
  3169.  
  3170.   function checkAvailability() {
  3171.     $("#loaderIcon").show();
  3172.     jQuery.ajax({
  3173.       url: "<?php echo base_url('customer/checkCompany_name') ?>",
  3174.       data: 'company_name=' + $("#company_name").val(),
  3175.       type: "POST",
  3176.       success: function(data) {
  3177.         $("#user-availability-status").html(data);
  3178.         $("#loaderIcon").hide();
  3179.       },
  3180.       error: function() {}
  3181.     });
  3182.   }
  3183. </script>
RAW Paste Data