Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- var yi = 0; /* Set Global Variable i */
- var j = 0; /* Set Global Variable i */
- var k = 0; /* Set Global Variable i */
- var product_data = new Array();
- var additional_data = new Array();
- var service_data = new Array();
- function storedatatemp()
- {
- var container = document.getElementById("kurscontainer");
- var children = container.childNodes;
- var e = document.getElementById("terminnumber");
- var number2 = e.options[e.selectedIndex].value;
- var container2 = document.getElementById("termincontainer");
- var iyv = 0;
- var iyx = 0;
- var iyy = 0;
- var iyz = 0;
- var iya = 0;
- var iyb = 0;
- for (ik = 0; ik < number2; ik++)
- {
- var a = document.getElementsByName("terminvalue[]"), i;
- localStorage.removeItem("terminvalue" + ik);
- localStorage.setItem("terminvalue" + ik, a[ik].value);
- var b = document.getElementsByName("tanggalterminvalue[]"), i;
- localStorage.removeItem("tanggalterminvalue" + ik);
- localStorage.setItem("tanggalterminvalue" + ik, b[ik].value);
- var c = document.getElementsByName("terminket[]"), i;
- localStorage.removeItem("terminket" + ik);
- localStorage.setItem("terminket" + ik, c[ik].value);
- }
- for (var im = 0; im < children.length; im++)
- {
- if (children[im].tagName == "INPUT" && children[im].name == 'kursdatavalue[]')
- {
- var v = document.getElementsByName("kursdatavalue[]"), i;
- localStorage.removeItem("kursdatavalue" + iyv);
- localStorage.setItem("kursdatavalue" + iyv, v[iyv].value);
- iyv++;
- }
- }
- }
- $(document).ready(function () {
- $('#customer').val(<?php echo $data[0]->customer_id; ?>).trigger('change');
- $('input[name=paymenterms][value=<?php echo $data[0]->paid_by; ?>]').prop('checked', true).click();
- if ('termin' == '<?php echo $data[0]->paid_by; ?>') {
- var e = document.getElementById("terminnumber");
- var number = e.options[e.selectedIndex].value;
- getfromaddFields = number;
- var container = document.getElementById("termincontainer");
- while (container.hasChildNodes())
- {
- container.removeChild(container.lastChild);
- }
- $("#kursdata").val(<?php echo $data[0]->kurs_id; ?>).trigger('change');
- var mode_of_transport = $("#mode_of_transport").val();
- var transporter_name = $("#transporter_name").val();
- var transporter_code = $("#transporter_code").val();
- var vehicle_regn_no = $("#vehicle_regn_no").val();
- if (mode_of_transport || transporter_name || vehicle_regn_no) {
- $("#transporter").prop('checked', false).click();
- }
- var container = container.appendChild(document.createElement("table"));
- container.className = "table table-bordered";
- var container = container.appendChild(document.createElement("tbody"));
- var artermin = <?php echo json_encode($termin); ?>;
- for (i = 0; i < number; i++)
- {
- var containertr = container.appendChild(document.createElement("tr"));
- var containertd = containertr.appendChild(document.createElement("td"));
- z = document.createElement('span');
- z.innerHTML = "Termin Ke % " + (i + 1) + " :";
- z.className = "text-danger";
- containertd.appendChild(z);
- var input = document.createElement("input");
- input.type = "number";
- input.name = "terminvalue[" + (i + 1) + "]";
- input.id = "terminvalue[" + (i + 1)+"]";
- input.className = "getterminvalue";
- input.value = artermin[i].persen;
- input.min = 1;
- input.max = 100;
- input.maxlength = "2";
- // input.onkeypress = isNumber_max_100;
- var containertd = containertr.appendChild(document.createElement("td"));
- containertd.appendChild(input);
- z = document.createElement('span');
- z.className = "text-primary";
- z.innerHTML = ' Ket: ';
- var containertd = containertr.appendChild(document.createElement("td"));
- containertd.appendChild(z);
- var input2 = document.createElement("input");
- input2.type = "text";
- input2.name = "terminket[" + (i + 1) + "]";
- input2.id = "terminket[" + (i + 1)+"]";
- input2.className = "getterminket";
- input2.value = artermin[i].keterangan;
- var containertd = containertr.appendChild(document.createElement("td"));
- containertd.appendChild(input2);
- }
- }
- var counter = 1;
- var aritem = <?php echo json_encode($items); ?>;
- // console.log(aritem);
- for (itemrec = 0; itemrec < aritem.length; itemrec++) {
- (function (counter) {
- var getnewRow;
- var quotationid = aritem[itemrec].id;
- var itemquantity = aritem[itemrec].quantity;
- var itemprice = aritem[itemrec].qprice;
- var itemdiscountid = aritem[itemrec].discount_id;
- var desc = aritem[itemrec].serial_no;
- var itemdiscountvalue = aritem[itemrec].discount_value;
- var itemdiscount = aritem[itemrec].discount;
- var itemgross_total = aritem[itemrec].gross_total;
- var product_id = aritem[itemrec].product_id;
- var sales_id = aritem[itemrec].sales_id;
- // console.log(sales_id);
- var flag = 0;
- $('#err_product').text('');
- $.ajax({
- async : false,
- url: "<?php echo base_url('sales/getProduct') ?>/" + product_id + '/' + sales_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- $("table.product_table").find('input[name^="product_id"]').each(function () {
- // if (data[0].product_id == +$(this).val()) {
- // flag = 1;
- // }
- });
- // console.log(data);
- if (flag == 0) {
- $.each(data.items,function(i,v){
- console.log(v);
- // console.log(v.product_id);
- // discount_id
- var id = v.product_id;
- var price = itemprice;
- var code = v.code;
- var name = v.name;
- var product_bonus = v.product_bonus;
- var item_namebyp = v.item_namebyp;
- var product = {"product_id": id,
- "price": price
- };
- product_data[yi] = product;
- length = product_data.length - 1;
- var select_discount = "";
- select_discount += '<div class="form-group">';
- select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
- select_discount += '<option value="">Select</option>';
- var selected = '';
- for (a = 0; a < data['discount'].length; a++) {
- if (data['discount'][a].discount_id == itemdiscountid) {
- selected = 'selected ';
- } else {
- selected = '';
- }
- select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
- }
- select_discount += '</select></div>';
- var select_bonus = "";
- select_bonus += '<div class="form-group">';
- select_bonus += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
- select_bonus += '<option value="">Select</option>';
- for (a = 0; a < data['bonus1'].length; a++) {
- select_bonus += '<option ' + selected + 'value="' + data['bonus1'][a].product + '">' + data['bonus1'][a].product_bonus + '</option>';
- }
- select_bonus += '</select></div>';
- var newRow = $("<tr id='tr" + yi + "'>");
- var cols = "";
- 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[]' value='"+v.product_id+"'></td>";
- // console.log(v.product_id);
- cols += "<td>" + code + "</td>";
- cols += "<td>"
- + "<input type='hidden' value='" + v.name + "' name='nameProduct" + i + "' id='nameProduct" + i + "'>"
- + "<input type='hidden' value='" + v.product_id + "' name='idProduct" + i + "' id='idProduct" + i + "'>"
- + name + "</td>";
- cols += '<td><input type="hidden" id="discount_value" name="discount_value"><input type="hidden" id="hidden_discount" name="hidden_discount">' + select_bonus + '</td>';
- cols += "<td><input type='text' name='description" + i + "' id='description"+ i + "' value='" + desc + "' class='form-control'></td>";
- cols += "<td>"
- + "<input type='number' class='form-control text-center' value='" + v.qty + "' data-rule='quantity' name='qty" + i + "' id='qty" + i + "' min='1' max='" + v.qty + "'>"
- + "</td>";
- cols += "<td>" + v.quantity
- + "<input type='hidden' name='available_quantity" + i + "' id='available_quantity" + i + "' value='" + v.quantity + "'>"
- + "</td>";
- cols += "<td>" + v.unit + "</td>";
- cols += "<td align='right'>"
- + "<span>"
- + "<input step='0.01' type='text' class='form-control text-right' value='" + v.harga_si + "' name='price" + i + "' id='price" + i + "'>"
- + "</span>"
- + "</td>";
- cols += "<td>"
- + "<span id='sub_total'>"
- + "<input type='text' class='form-control text-right' style='' value='" + v.grossTotal + "' name='subtotal" + i + "' id='linetotal" + i + "' readonly>"
- + "</span>"
- + "</td>";
- 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>';
- // serial_no
- cols += '<input value="' + v.discount_id + '" type="hidden" name="discount_id'+i+'">';
- cols += '<input value="' + v.discount_value + '" type="hidden" name="discount_value'+i+'">';
- cols += '<input value="' + v.serial_no + '" type="hidden" name="serial_no'+i+'">';
- cols += '<input value="' + v.discount + '" type="hidden" name="discount'+i+'">';
- cols += '<td><input type="text" class="form-control text-right salestotal" id="" name="salestotal" value="' + v.total + '" readonly></td>';
- // console.log(v.total);
- cols += "</tr>";
- newRow.append(cols);
- getnewRow = newRow;
- $("table.product_table").append(newRow);
- })
- calculateRow($('tr#tr' + yi));
- $.calculateDiscount($('tr#tr' + yi));
- $.calculateGrandTotal();
- counter++;
- var table_data = JSON.stringify(product_data);
- $('#table_data').val(table_data);
- yi++;
- } else {
- $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
- }
- }
- });
- })(itemrec);
- }
- var aritem = <?php echo json_encode($additional); ?>;
- for (itemrec = 0; itemrec < aritem.length; itemrec++) {
- (function (counter) {
- var getnewRow;
- var quotationid = aritem[itemrec].id;
- var itemquantity = aritem[itemrec].quantity;
- var itemprice = aritem[itemrec].qprice;
- var itemdiscountid = aritem[itemrec].discount_id;
- var desc = aritem[itemrec].desc;
- var itemdiscountvalue = aritem[itemrec].discount_value;
- var itemdiscount = aritem[itemrec].discount;
- var itemgross_total = aritem[itemrec].gross_total;
- var product_id = aritem[itemrec].product_id;
- var flag = 0;
- $('#err_product').text('');
- $.ajax({
- async : false,
- url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- $("table.additional_table").find('input[name^="additional_id"]').each(function () {
- // if (data[0].product_id == +$(this).val()) {
- // flag = 1;
- // }
- });
- if (flag == 0) {
- var id = data[0].product_id;
- var price = itemprice;
- var code = data[0].code;
- var name = data[0].name;
- var item_namebyp = data[0].item_namebyp;
- var product = {"additional_id": id,
- "price": price
- };
- additional_data[j] = product;
- length = additional_data.length - 1;
- var select_discount = "";
- select_discount += '<div class="form-group">';
- select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
- select_discount += '<option value="">Select</option>';
- var selected = '';
- for (a = 0; a < data['discount'].length; a++) {
- if (data['discount'][a].discount_id == itemdiscountid) {
- selected = 'selected ';
- } else {
- selected = '';
- }
- select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
- }
- select_discount += '</select></div>';
- var newRow = $("<tr id='tra" + j + "'>");
- var cols = "";
- 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>";
- cols += "<td>" + code + "</td>";
- 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>";
- cols += "<td>" + item_namebyp + "</td>";
- cols += "<td><input type='text' name='description" + counter + "' id='description"+ counter + "' value='" + desc + "' class='form-control'></td>";
- cols += "<td>"
- + "<input type='number' class='form-control text-center' value='" + itemquantity + "' data-rule='quantity' name='qty" + counter + "' id='qty" + counter + "' min='1' max='" + itemquantity + "'>"
- + "</td>";
- cols += "<td>" + data[0].quantity
- + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'>"
- + "</td>";
- cols += "<td>" + data[0].unit + "</td>";
- cols += "<td align='right'>"
- + "<span>"
- + "<input step='0.01' type='text' class='form-control text-right' value='" + price + "' name='price" + counter + "' id='price" + counter + "'>"
- + "</span>"
- + "</td>";
- 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>";
- 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>';
- cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
- cols += "</tr>";
- newRow.append(cols);
- getnewRow = newRow;
- $("table.additional_table").append(newRow);
- calculateRowAdditional($('tr#tra' + j));
- $.calculateDiscountAdditional($('tr#tra' + j));
- $.calculateGrandTotal();
- counter++;
- var table_data = JSON.stringify(additional_data);
- $('#tableadditional_data').val(table_data);
- j++;
- } else {
- $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
- }
- }
- });
- })(itemrec);
- }
- var aritem = <?php echo json_encode($serviceitems); ?>;
- for (itemrec = 0; itemrec < aritem.length; itemrec++) {
- (function (counter) {
- var getnewRowService;
- var quotationid = aritem[itemrec].id;
- var itemquantity = aritem[itemrec].quantity;
- var itemprice = aritem[itemrec].price;
- var itemdiscountid = aritem[itemrec].discount_id;
- var itemdiscountvalue = aritem[itemrec].discount_value;
- var itemdiscount = aritem[itemrec].discount;
- var itemgross_total = aritem[itemrec].gross_total;
- var service_id = aritem[itemrec].service_id;
- var flag = 0;
- $('#err_service').text('');
- $.ajax({
- url: "<?php echo base_url('sales/getService') ?>/" + service_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- $("table.service_table").find('input[name^="service_id"]').each(function () {
- if (data[0].service_id == +$(this).val()) {
- flag = 1;
- }
- });
- if (flag == 0)
- {
- var id = data[0].service_id;
- var code = data[0].code;
- var name = data[0].service_title;
- var hsn_sac_code = '';
- var price = itemprice;
- var tax_id = data[0].tax_id;
- var tax_value = data[0].tax_value;
- if (tax_value == null) {
- tax_value = 0;
- }
- var product = {"service_id": id,
- "price": price
- };
- service_data[k] = product;
- length = service_data.length - 1;
- var select_discount = "";
- select_discount += '<div class="form-group">';
- select_discount += '<select class="form-control select2" id="item_discountservice" name="item_discountservice" style="width: 100%;">';
- select_discount += '<option value="">Select</option>';
- var selected = '';
- for (a = 0; a < data['discount'].length; a++) {
- if (data['discount'][a].discount_id == itemdiscountid) {
- selected = 'selected ';
- } else {
- selected = '';
- }
- select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
- }
- select_discount += '</select></div>';
- var newRowService = $("<tr id='trv" + counter + "'>");
- var cols = "";
- 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>";
- cols += "<td>" + code + "</td>";
- cols += "<td>"
- + "<input type='hidden' value='' name='nameService" + counter + "' id='nameService" + counter + "'>"
- + name + "</td>";
- cols += "<td>"
- + "<input type='number' class='form-control text-center' value='" + itemquantity + "' data-rule='quantity' name='qtyservice" + counter + "' id='qtyservice" + counter + "' min='0' max='2'>"
- + "</td>";
- cols += "<td align='right'>"
- + "<span id='price'>"
- + "<input step='0.01' type='text' class='form-control text-right' name='priceservice" + counter + "' id='priceservice" + counter + "' value='" + price
- + "'>"
- + "</span>"
- + "</td>";
- cols += "<td>"
- + "<span id='sub_total'>"
- + "<input type='text' class='form-control text-right' style='' value='" + itemgross_total + "' name='linetotalservice" + counter + "' id='linetotalservice" + counter + "' readonly>"
- + "</span>"
- + "</td>";
- 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>';
- cols += '<td><input type="text" class="form-control text-right" id="service_total" name="service_total" readonly></td>';
- cols += "</tr>";
- newRowService.append(cols);
- getnewRowService = newRowService;
- $("table.service_table").append(newRowService);
- calculateRowService($('tr#trv' + counter));
- $.calculateDiscountService($('tr#trv' + counter));
- $.calculateGrandTotal();
- counter++;
- var table_data = JSON.stringify(service_data);
- $('#tableservice_data').val(table_data);
- k++;
- } else {
- $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
- }
- }
- });
- })(itemrec);
- }
- function calculateRow(row) {
- var key = +row.find('input[name^="id"]').val();
- var price = +row.find('input[name^="price"]').val();
- var desc = row.find('input[name^="description"]').val();
- var qty = +row.find('input[name^="qty"]').val();
- row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
- product_data[key].quantity = qty;
- product_data[key].desc = desc;
- product_data[key].total = (price * qty).toFixed(2);
- var table_data = JSON.stringify(product_data);
- $('#table_data').val(table_data);
- }
- function calculateRowAdditional(row) {
- var key = +row.find('input[name^="id"]').val();
- var price = +row.find('input[name^="price"]').val();
- var desc = row.find('input[name^="description"]').val();
- var qty = +row.find('input[name^="qty"]').val();
- row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
- additional_data[key].quantity = qty;
- additional_data[key].desc = desc;
- additional_data[key].total = (price * qty).toFixed(2);
- var table_data = JSON.stringify(additional_data);
- $('#tableadditional_data').val(table_data);
- }
- function calculateRowService(row)
- {
- var key = +row.find('input[name^="idservice"]').val();
- var price = +row.find('input[name^="priceservice"]').val();
- var qty = +row.find('input[name^="qtyservice"]').val();
- var total = +row.find('input[name^="linetotalservice"]').val();
- row.find('input[name^="linetotalservice"]').val((price * qty).toFixed(2));
- service_data[key].price = price;
- service_data[key].quantity = qty;
- service_data[key].total = total;
- var table_data = JSON.stringify(service_data);
- $('#tableservice_data').val(table_data);
- }
- });
- $(document).ready(function () {
- $("button#submitBooking").click(function (e) {
- if (e.target instanceof HTMLAnchorElement)
- e.preventDefault();
- $.ajax({
- type: "POST",
- url: "<?php echo base_url('item_request/addSales') ?>",
- data: $('form.bookingmodal').serialize(),
- success: function (message) {
- alert(message);
- var formObj = {};
- var inputs = $('form.bookingmodal').serializeArray()
- $.each(inputs, function (i, input) {
- formObj[input.name] = input.value;
- });
- var qty = +$('#'+formObj.type).find('input[name^="available_quantity"]').val();
- var z = +formObj.qty + +qty;
- $('#'+formObj.type).find('input[name^="qty"]').attr("max", z);
- $('#'+formObj.type).find('input[name^="qty"]').val(z);
- $("#bookingmodal").modal('hide');
- },
- error: function () {
- alert("Error");
- }
- });
- return false;
- });
- $(document).on('change', '#kursdata', function ()
- {
- $.calculateGrandTotal();
- });
- $(document).on('change', '#taxx', function ()
- {
- $.calculateGrandTotal();
- });
- $(document).on('keyup', '#shipping_charge', function ()
- {
- $.calculateGrandTotal();
- });
- $(document).on('keyup', '#totalDiscountUmum', function ()
- {
- $.calculateGrandTotal();
- });
- $(document).on('keyup', '#DiscountFix', function ()
- {
- $.calculateGrandTotal();
- });
- $(document).on('keyup', '#diskonpersen_text', function ()
- {
- var diskonval = 0;
- var diskonval2 = 0;
- var diskonpersen = 0;
- diskonpersen = $('#diskonpersen_text').val();
- $.calculateGrandTotal();
- diskonval2 = $('#grand_total').val();
- diskonval = (diskonpersen / 100) * diskonval2;
- $('#totalDiscountUmum').text(diskonval.toFixed(2));
- $('#totalDiscountUmum').val(diskonval.toFixed(2));
- $.calculateGrandTotal();
- });
- $(document).on('keyup', '#DiscountPersen', function ()
- {
- $.calculateGrandTotal();
- });
- });
- </script>
- <script type="text/javascript">
- $(document).ready(function () {
- $(".getterminvalue").on("change paste", function () {
- var id_data = $(this).attr("id");
- var valdata_cek = $(this).val();
- if (valdata_cek.match(/^\d+$/)) {
- $(".getterminvalue").each(function (index, element) {
- valueget = $(element).val();
- })
- } else {
- alert('Data Must Numeric');
- }
- });
- //datepicker
- $('.datepicker').datepicker({
- autoclose: true,
- format: "yyyy-mm-dd",
- todayHighlight: true,
- orientation: "auto",
- todayBtn: true,
- todayHighlight: true,
- });
- });
- function transport() {
- $('.transporter').toggle();
- }
- </script>
- <!-- close datepicker -->
- <script>
- function addRevisi() {
- var e = document.getElementById("status");
- var number = e.options[e.selectedIndex].value;
- if (number == 3) {
- document.getElementById('divrevisi').style.display = 'block';
- } else {
- document.getElementById('divrevisi').style.display = 'none';
- }
- }
- function addFields()
- {
- var e = document.getElementById("terminnumber");
- var number = e.options[e.selectedIndex].value;
- getfromaddFields = number;
- var container = document.getElementById("termincontainer");
- while (container.hasChildNodes())
- {
- container.removeChild(container.lastChild);
- }
- var container = container.appendChild(document.createElement("table"));
- container.className = "table table-bordered";
- var container = container.appendChild(document.createElement("tbody"));
- for (i = 0; i < number; i++)
- {
- var containertr = container.appendChild(document.createElement("tr"));
- var containertd = containertr.appendChild(document.createElement("td"));
- z = document.createElement('span');
- z.innerHTML = "Termin Ke % " + (i + 1) + " :";
- z.className = "text-danger";
- containertd.appendChild(z);
- var input = document.createElement("input");
- input.type = "number";
- input.name = "terminvalue[" + (i + 1) + "]";
- input.id = "terminvalue" + (i + 1);
- input.className = "getterminvalue";
- input.min = 1;
- input.max = 100;
- input.maxlength = "2";
- // input.onkeypress = isNumber_max_100;
- var containertd = containertr.appendChild(document.createElement("td"));
- containertd.appendChild(input);
- z = document.createElement('span');
- z.className = "text-primary";
- z.innerHTML = ' Ket: ';
- var containertd = containertr.appendChild(document.createElement("td"));
- containertd.appendChild(z);
- var input2 = document.createElement("input");
- input2.type = "text";
- input2.name = "terminket[" + (i + 1) + "]";
- input2.id = "terminket" + (i + 1);
- input2.className = "getterminket";
- var containertd = containertr.appendChild(document.createElement("td"));
- containertd.appendChild(input2);
- }
- }
- function showc1()
- {
- var container = document.getElementById("kurscontainer");
- while (container.hasChildNodes())
- {
- container.removeChild(container.lastChild);
- }
- document.getElementById('divc1').style.display = 'block';
- document.getElementById('divc2').style.display = 'none';
- }
- function showc2()
- {
- document.getElementById('divc2').style.display = 'block';
- document.getElementById('divc1').style.display = 'none';
- addKursFields();
- }
- function addKursFields()
- {
- var e = document.getElementById("kursid2");
- var options = document.getElementById('kursid2').options, count = 0;
- var options2 = document.getElementById('kursdata');
- var arrayman = [];
- var arraymankurs = [];
- for (var i = 0; i < options.length; i++)
- {
- arraymankurs[count] = options2[i].value;
- if (options[i].selected)
- {
- arrayman[count] = e.options[i].text;
- count++;
- }
- }
- //var number = document.getElementById("terminnumber").value;
- var container = document.getElementById("kurscontainer");
- while (container.hasChildNodes())
- {
- container.removeChild(container.lastChild);
- }
- for (i = 0; i < count; i++)
- {
- container.appendChild(document.createTextNode("Nilai Kurs " + arrayman[i] + " :"));
- var input = document.createElement("input");
- input.type = "number";
- input.name = "kursdatavalue[]";
- input.id = "kursdatavalue" + (i + 1);
- input.min = 1;
- input.value = localStorage.getItem("kursdatavalue" + i);
- input.onkeyup = function ()
- {
- var container = document.getElementById("kurscontainer");
- var children = container.childNodes;
- var iy = 0;
- for (var im = 0; im < children.length; im++)
- {
- if (children[im].tagName == "INPUT" && children[im].name == 'kursdatavalue[]')
- {
- var rate = document.getElementsByName("rate")[0].value;
- var nominal = children[im].value;
- var numberPattern = /\d+/g;
- nominal = nominal.replace(/\D/g, "");
- nominal = parseFloat(nominal);
- var y = document.getElementsByName("premikursdatavalue[]"), i;
- if (nominal.length == 0)
- {
- nominal = 1;
- }
- if (rate.length == 0)
- {
- rate = 1;
- }
- var hasil = (nominal * rate) / 100;
- y[iy].value = hasil;
- iy++;
- }
- }
- storedatatemp();
- };
- container.appendChild(input);
- container.appendChild(document.createElement("br"));
- input.min = 1;
- container.appendChild(input);
- container.appendChild(document.createElement("br"));
- container.appendChild(document.createElement("br"));
- container.appendChild(document.createElement("br"));
- }
- }
- function showo1() {
- var container = document.getElementById("termincontainer");
- while (container.hasChildNodes()) {
- container.removeChild(container.lastChild);
- }
- document.getElementById('divo1').style.display = 'block';
- document.getElementById('divo2').style.display = 'none';
- document.getElementById('divo3').style.display = 'none';
- }
- function showo2() {
- document.getElementById('divo1').style.display = 'none';
- document.getElementById('divo2').style.display = 'block';
- document.getElementById('divo3').style.display = 'none';
- }
- function showo3() {
- var container = document.getElementById("termincontainer");
- while (container.hasChildNodes()) {
- container.removeChild(container.lastChild);
- }
- document.getElementById('divo1').style.display = 'none';
- document.getElementById('divo2').style.display = 'none';
- document.getElementById('divo3').style.display = 'block';
- }
- function showdis1()
- {
- document.getElementById('divdis1').style.display = 'block';
- document.getElementById('divdis2').style.display = 'none';
- }
- function showdis2() {
- document.getElementById('divdis1').style.display = 'none';
- document.getElementById('divdis2').style.display = 'block';
- }
- $(document).ready(function () {
- $('#customer').change(function () {
- var customer_id = $(this).val();
- $.ajax({
- url: "<?php echo base_url('sales/getCustomerData') ?>/" + customer_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- $('#company_id').text('');
- $('#company_name').text('');
- $('#customer_name').text('');
- $('#mobilephone').text('');
- $('#email').text('');
- $('#npwp').text('');
- $('#alamat_npwp').text('');
- $('#npwp').val(data['data'][0].gstid);
- $('#alamat_npwp').val(data['data'][0].cf2);
- $('#company_id').val(data['data'][0].cf1);
- $('#company_name').val(data['data'][0].company_name);
- $('#customer_name').val(data['data'][0].customer_name);
- $('#mobilephone').val(data['data'][0].mobile);
- $('#email').val(data['data'][0].email);
- if (typeof data['address'][0] != 'undefined') {
- var cid = data['address'][0].customer_id;
- for (a = 0; a < data['address'].length; a++) {
- if (data['address'][a].type == 0) {
- $('#customer_address').append('<option value="' + data['address'][a].id + '">' + data['address'][a].address + '</option>');
- }
- }
- } else {
- var cid = "";
- }
- if (typeof data['address'][0] != 'undefined') {
- var cid = data['address'][0].customer_id;
- for (a = 0; a < data['address'].length; a++) {
- if (data['address'][a].type == 1) {
- $('#customer_addressa').append('<option value="' + data['address'][a].id + '">' + data['address'][a].address + '</option>');
- }
- }
- } else {
- var cid = "";
- }
- $("#reference_no").empty().trigger("change");
- var customer_id = $('#customer').val();
- $.ajax({
- url: "<?php echo base_url('sales/getRecordAjax') ?>/" + customer_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- for (a = 0; a < data['data'].length; a++) {
- if (data['data'][a].reference_no2 != null) {
- number = data['data'][a].reference_no2;
- } else {
- number = data['data'][a].reference_no;
- }
- $('#reference_no').append('<option value="' + data['data'][a].quotation_id + '">' + number + '</option>').trigger('change');
- }
- $("#reference_no").trigger({
- type: 'select2:select',
- });
- var selectstr = <?php echo json_encode(unserialize($data[0]->reference_no)); ?>;
- $('#preference_no').find('#reference_no').val(selectstr).trigger('change');
- }
- });
- $('#customer_address').val(<?php echo $data[0]->shipto; ?>).trigger('change');
- $('#customer_addressa').val(<?php echo $data[0]->billto; ?>).trigger('change');
- }
- });
- }).change();
- });
- $(document).ready(function () {
- $('#customer_address').change(function () {
- var customerAddress_id = $(this).val();
- $.ajax({
- url: "<?php echo base_url('sales/getCustomerAddressData') ?>/" + customerAddress_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- $('#country').text('');
- $('#state').text('');
- $('#city').text('');
- $('#err_country').text('');
- $('#err_state').text('');
- $('#err_city').text('');
- $('#country').val(data['address'][0].cname);
- $('#state').val(data['address'][0].sname);
- $('#city').val(data['address'][0].ctname);
- var s = data['address'][0].baddress;
- tinyMCE.get('addresscustomer').setContent(s);
- }
- });
- }).change();
- });
- $(document).ready(function () {
- $('#customer_addressa').change(function () {
- var customerAddress_id = $(this).val();
- $.ajax({
- url: "<?php echo base_url('sales/getCustomerAddressData') ?>/" + customerAddress_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- $('#countrya').text('');
- $('#statea').text('');
- $('#citya').text('');
- $('#err_countrya').text('');
- $('#err_statea').text('');
- $('#err_citya').text('');
- $('#countrya').val(data['address'][0].coname);
- $('#statea').val(data['address'][0].sname);
- $('#citya').val(data['address'][0].ciname);
- var s = data['address'][0].baddress;
- tinyMCE.get('addresscustomera').setContent(s);
- }
- });
- }).change();
- });
- </script>
- <script>
- $(document).ready(function () {
- var counter = 1;
- $('#brand').change(function () {
- $('#code_item').html('');
- $('#code_item').html('<option value="">Select Part Number</option>');
- var brand_id = $('#brand').val();
- $.ajax({
- url: "<?php echo base_url('sales/getPartNumber') ?>/" + brand_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- for (a = 0; a < data.length; a++) {
- $('#code_item').append('<option value="' + data[a].code + '">' + data[a].code + '</option>');
- }
- }
- });
- });
- $('#code_item').change(function () {
- $('#product').html('');
- $('#product').html('<option value="">Select Product</option>');
- var code = $('#code_item').val();
- $.ajax({
- url: "<?php echo base_url('sales/getCodeProduct') ?>/" + code,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- for (a = 0; a < data.length; a++) {
- $('#product').append('<option value="' + data[a].product_id + '">' + data[a].name + '</option>');
- }
- }
- });
- });
- $('#product').change(function () {
- var id = $(this).val();
- var product_id = $('#product').val();
- var flag = 0;
- $('#err_product').text('');
- $.ajax({
- url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- $("table.product_table").find('input[name^="product_id"]').each(function () {
- // if (data[0].product_id == +$(this).val()) {
- // flag = 1;
- // }
- });
- if (flag == 0) {
- var id = data[0].product_id;
- var code = data[0].code;
- var name = data[0].name;
- var item_namebyp = data[0].item_namebyp;
- var price = data[0].cost;
- var product = {"product_id": id,
- "price": price
- };
- product_data[yi] = product;
- length = product_data.length - 1;
- var select_discount = "";
- select_discount += '<div class="form-group">';
- select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
- select_discount += '<option value="">Select</option>';
- for (a = 0; a < data['discount'].length; a++) {
- select_discount += '<option value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
- }
- select_discount += '</select></div>';
- var newRow = $("<tr id='tr"+ yi +"'>");
- var cols = "";
- 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>";
- cols += "<td>" + code + "</td>";
- 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>";
- cols += "<td>" + item_namebyp + "</td>";
- cols += "<td><input type='text' name='description" + counter + "' id='description"+ counter + "' value='" + name + "' class='form-control'></td>";
- 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>";
- cols += "<td>" + data[0].quantity + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'></td>";
- cols += "<td>" + data[0].unit + "</td>";
- 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>";
- 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>";
- cols += '<td><input type="hidden" id="discount_value" name="discount_value"><input type="hidden" id="hidden_discount" name="hidden_discount">' + select_discount + '</td>';
- cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
- cols += "</tr>";
- counter++;
- newRow.append(cols);
- $("table.product_table").append(newRow);
- var table_data = JSON.stringify(product_data);
- $('#table_data').val(table_data);
- yi++;
- } else {
- $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
- }
- }
- });
- });
- $('#a_brand').change(function () {
- $('#a_code_item').html('');
- $('#a_code_item').html('<option value="">Select Part Number</option>');
- var brand_id = $('#a_brand').val();
- $.ajax({
- url: "<?php echo base_url('sales/getPartNumber') ?>/" + brand_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- for (a = 0; a < data.length; a++) {
- $('#a_code_item').append('<option value="' + data[a].code + '">' + data[a].code + '</option>');
- }
- }
- });
- });
- $('#a_code_item').change(function () {
- $('#a_product').html('');
- $('#a_product').html('<option value="">Select Product</option>');
- var code = $('#a_code_item').val();
- $.ajax({
- url: "<?php echo base_url('sales/getCodeProduct') ?>/" + code,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- for (a = 0; a < data.length; a++) {
- $('#a_product').append('<option value="' + data[a].product_id + '">' + data[a].name + '</option>');
- }
- }
- });
- });
- $('#a_product').change(function () {
- var id = $(this).val();
- var product_id = $('#a_product').val();
- var flag = 0;
- $('#err_a_product').text('');
- $.ajax({
- url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- $("table.additional_table").find('input[name^="product_id"]').each(function () {
- if (data[0].additional_id == +$(this).val()) {
- flag = 1;
- }
- });
- if (flag == 0) {
- var id = data[0].product_id;
- var price = data[0].cost;
- var code = data[0].code;
- var name = data[0].name;
- var itembyp = data[0].item_namebyp;
- var stock = data[0].quantity;
- var uom = data[0].uom;
- var product = {"additional_id": id, "price": 0
- };
- additional_data[j] = product;
- length = additional_data.length - 1;
- var select_discount = "";
- select_discount += '<div class="form-group">';
- select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
- select_discount += '<option value="">Select</option>';
- for (a = 0; a < data['discount'].length; a++) {
- select_discount += '<option value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
- }
- select_discount += '</select></div>';
- var newRow = $("<tr id='tra"+ j +"'>");
- var cols = "";
- 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>";
- cols += "<td>" + code + "</td>";
- 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>";
- cols += "<td>" + itembyp + "</td>";
- cols += "<td><input type='text' name='description" + counter + "' id='description"+ counter + "' value='" + name + "' class='form-control'></td>";
- 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>";
- cols += "<td>" + data[0].quantity + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'></td>";
- cols += "<td>" + data[0].unit + "</td>";
- 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>";
- 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>";
- cols += '<td><input type="hidden" id="discount_value" name="discount_value"><input type="hidden" id="hidden_discount" name="hidden_discount">' + select_discount + '</td>';
- cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
- cols += "</tr>";
- counter++;
- newRow.append(cols);
- $("table.additional_table").append(newRow);
- var table_data = JSON.stringify(additional_data);
- $('#tableadditional_data').val(table_data);
- j++;
- } else {
- $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
- }
- }
- });
- });
- $('#service').change(function () {
- var id = $(this).val();
- var service_id = $('#service').val();
- var flag = 0;
- $('#err_service').text('');
- $.ajax({
- url: "<?php echo base_url('sales/getService') ?>/" + service_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- $("table.service_table").find('input[name^="service_id"]').each(function () {
- if (data[0].service_id == +$(this).val()) {
- flag = 1;
- }
- });
- if (flag == 0) {
- var id = data[0].service_id;
- var code = data[0].code;
- var name = data[0].service_title;
- var hsn_sac_code = '';
- var price = data[0].price;
- var product = {"service_id": id,
- "price": price
- };
- service_data[k] = product;
- length = service_data.length - 1;
- var select_discount = "";
- select_discount += '<div class="form-group">';
- select_discount += '<select class="form-control select2" id="item_discountservice" name="item_discountservice" style="width: 100%;">';
- select_discount += '<option value="">Select</option>';
- for (a = 0; a < data['discount'].length; a++) {
- select_discount += '<option value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
- }
- select_discount += '</select></div>';
- var newRow = $("<tr>");
- var cols = "";
- 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>";
- cols += "<td>" + code + "</td>";
- cols += "<td>" + name + "</td>";
- cols += "<td>"
- + "<input type='number' class='form-control text-center' value='0' data-rule='quantity' name='qtyservice" + counter + "' id='qtyservice" + counter + "' min='0' max='2'>"
- + "</td>";
- cols += "<td align='right'>"
- + "<span id='price'>"
- + "<input type='text' step='0.01' class='form-control text-right' name='priceservice" + counter + "' id='priceservice" + counter + "' value='" + price
- + "'>"
- + "</span>"
- + "</td>";
- cols += "<td>"
- + "<span id='sub_total'>"
- + "<input type='text' class='form-control text-right' style='' value='0.00' name='linetotalservice" + counter + "' id='linetotalservice" + counter + "' readonly>"
- + "</span>"
- + "</td>";
- cols += '<td><input type="hidden" id="discountservice_value" name="discountservice_value"><input type="hidden" id="hidden_discountservice" name="hidden_discountservice">' + select_discount + '</td>';
- cols += '<td><input type="text" class="form-control text-right" id="service_total" name="service_total" readonly></td>';
- cols += "</tr>";
- counter++;
- newRow.append(cols);
- $("table.service_table").append(newRow);
- var table_data = JSON.stringify(service_data);
- $('#tableservice_data').val(table_data);
- k++;
- } else {
- $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
- }
- }
- });
- });
- $("table.product_table").on("click", "a.deleteRow", function (event) {
- deleteRow($(this).closest("tr"));
- $(this).closest("tr").remove();
- $.calculateGrandTotal();
- });
- $("table.additional_table").on("click", "a.deleteRow", function (event) {
- deleteRowAdditional($(this).closest("tr"));
- $(this).closest("tr").remove();
- $.calculateGrandTotal();
- });
- $("table.service_table").on("click", "a.deleteRow", function (event) {
- deleteRowService($(this).closest("tr"));
- $(this).closest("tr").remove();
- $.calculateGrandTotal();
- });
- function deleteRow(row) {
- var id = +row.find('input[name^="id"]').val();
- var array_id = product_data[id].product_id;
- product_data[id] = null;
- var table_data = JSON.stringify(product_data);
- $('#table_data').val(table_data);
- }
- function deleteRowAdditional(row) {
- var id = +row.find('input[name^="id"]').val();
- additional_data[id] = null;
- var table_data = JSON.stringify(additional_data);
- $('#tableadditional_data').val(table_data);
- }
- function deleteRowService(row) {
- var id = +row.find('input[name^="idservice"]').val();
- service_data[id] = null;
- var table_data = JSON.stringify(service_data);
- $('#tableservice_data').val(table_data);
- }
- $("table.product_table").on("change", 'input[name^="price"], input[name^="qty"]', function (event) {
- calculateRow($(this).closest("tr"));
- $.calculateDiscount($(this).closest("tr"));
- $.calculateGrandTotal();
- });
- $("table.product_table").on("change", 'input[name^="qty"]', function (event) {
- row = $(this).closest("tr");
- var key = +row.find('input[name^="id"]').val();
- var price = +row.find('input[name^="price"]').val();
- var qty = +row.find('input[name^="qty"]').val();
- var desc = row.find('input[name^="description"]').val();
- var nqty = row.find('input[name^="qty"]').attr('name');
- var availableqty = +row.find('input[name^="available_quantity"]').val();
- var nameproductval = row.find('input[name^="nameProduct"]').val();
- var idproductval = +row.find('input[name^="idProduct"]').val();
- var bookqty = qty - availableqty;
- if (bookqty > 0) {
- $("#m_id_product").val(idproductval);
- $("#qtytitle").text(nqty);
- $("#m_name_product").val(nameproductval);
- $("#m_ref").val($('#sales_order').text());
- $("#m_type").val('tr'+key);
- $("#m_qty").val(bookqty);
- $("#m_price").val(price);
- $("#m_date").val($('#sales_date').val());
- $("#bookingmodal").modal("show");
- }
- });
- $("table.additional_table").on("change", 'input[name^="price"], input[name^="qty"]', function (event) {
- calculateRowAdditional($(this).closest("tr"));
- $.calculateDiscountAdditional($(this).closest("tr"));
- $.calculateGrandTotal();
- });
- $("table.additional_table").on("change", 'input[name^="qty"]', function (event) {
- row = $(this).closest("tr");
- var key = +row.find('input[name^="id"]').val();
- var price = +row.find('input[name^="price"]').val();
- var qty = +row.find('input[name^="qty"]').val();
- var desc = row.find('input[name^="description"]').val();
- var nqty = row.find('input[name^="qty"]').attr('name');
- var availableqty = +row.find('input[name^="available_quantity"]').val();
- var nameproductval = row.find('input[name^="nameProduct"]').val();
- var idproductval = +row.find('input[name^="idProduct"]').val();
- var bookqty = qty - availableqty;
- if (bookqty > 0) {
- $("#m_id_product").val(idproductval);
- $("#qtytitle").text(nqty);
- $("#m_name_product").val(nameproductval);
- $("#m_ref").val($('#sales_order').text());
- $("#m_type").val('tr'+key);
- $("#m_qty").val(bookqty);
- $("#m_price").val(price);
- $("#m_date").val($('#sales_date').val());
- $("#bookingmodal").modal("show");
- }
- });
- $("table.service_table").on("change", 'input[name^="priceservice"], input[name^="qtyservice"]', function (event) {
- calculateRowService($(this).closest("tr"));
- $.calculateDiscountService($(this).closest("tr"));
- $.calculateGrandTotal();
- });
- $("table.product_table").on("change", 'input[name ^= "linetotal"]', function (event) {
- calculateRow2($(this).closest("tr"));
- $.calculateDiscount($(this).closest("tr"));
- $.calculateGrandTotal();
- });
- $("table.additional_table").on("change", 'input[name ^= "linetotal"]', function (event) {
- calculateRowAdditional2($(this).closest("tr"));
- $.calculateDiscountAdditional($(this).closest("tr"));
- $.calculateGrandTotal();
- });
- $("table.service_table").on("change", 'input[name^="linetotalservice"]', function (event)
- {
- calculateRowService2($(this).closest("tr"));
- $.calculateDiscountService($(this).closest("tr"));
- $.calculateGrandTotal();
- });
- $("table.product_table").on("change", '#item_discount', function (event) {
- var row = $(this).closest("tr");
- var discount = +row.find('#item_discount').val();
- if (discount != "") {
- $.ajax({
- url: '<?php echo base_url('purchase/getDiscountValue/') ?>' + discount,
- type: "GET",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- datatype: JSON,
- success: function (value) {
- data = JSON.parse(value);
- row.find('#discount_value').val(data[0].discount_value);
- $.calculateDiscount(row, data[0].discount_value);
- $.calculateGrandTotal();
- }
- });
- } else {
- row.find('#discount_value').val('0');
- $.calculateDiscount(row, 0);
- $.calculateGrandTotal();
- }
- });
- $("table.additional_table").on("change", '#item_discount', function (event) {
- var row = $(this).closest("tr");
- var discount = +row.find('#item_discount').val();
- if (discount != "") {
- $.ajax({
- url: '<?php echo base_url('purchase/getDiscountValue/') ?>' + discount,
- type: "GET",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- datatype: JSON,
- success: function (value) {
- data = JSON.parse(value);
- row.find('#discount_value').val(data[0].discount_value);
- $.calculateDiscountAdditional(row, data[0].discount_value);
- $.calculateGrandTotal();
- }
- });
- } else {
- row.find('#discount_value').val('0');
- $.calculateDiscountAdditional(row, 0);
- $.calculateGrandTotal();
- }
- });
- $("table.service_table").on("change", '#item_discountservice', function (event) {
- var row = $(this).closest("tr");
- var discount = +row.find('#item_discountservice').val();
- if (discount != "") {
- $.ajax({
- url: '<?php echo base_url('purchase/getDiscountValue/') ?>' + discount,
- type: "GET",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- datatype: JSON,
- success: function (value) {
- data = JSON.parse(value);
- row.find('#discountservice_value').val(data[0].discount_value);
- $.calculateDiscountService(row, data[0].discount_value);
- $.calculateGrandTotal();
- }
- });
- } else {
- row.find('#discountservice_value').val('0');
- $.calculateDiscountService(row, 0);
- $.calculateGrandTotal();
- }
- });
- function calculateRow(row) {
- var key = +row.find('input[name^="id"]').val();
- var price = +row.find('input[name^="price"]').val();
- var desc = row.find('input[name^="description"]').val();
- var qty = +row.find('input[name^="qty"]').val();
- row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
- product_data[key].price = price;
- product_data[key].quantity = qty;
- product_data[key].desc = desc;
- product_data[key].total = (price * qty).toFixed(2);
- var table_data = JSON.stringify(product_data);
- $('#table_data').val(table_data);
- }
- function calculateRowAdditional(row) {
- var key = +row.find('input[name^="id"]').val();
- var price = +row.find('input[name^="price"]').val();
- var desc = row.find('input[name^="description"]').val();
- var qty = +row.find('input[name^="qty"]').val();
- row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
- additional_data[key].price = price;
- additional_data[key].quantity = qty;
- additional_data[key].desc = desc;
- additional_data[key].total = (price * qty).toFixed(2);
- var table_data = JSON.stringify(additional_data);
- $('#tableadditional_data').val(table_data);
- }
- function calculateRowService(row)
- {
- var key = +row.find('input[name^="idservice"]').val();
- var price = +row.find('input[name^="priceservice"]').val();
- var qty = +row.find('input[name^="qtyservice"]').val();
- var total = +row.find('input[name^="linetotalservice"]').val();
- row.find('input[name^="linetotalservice"]').val((price * qty).toFixed(2));
- service_data[key].price = price;
- service_data[key].quantity = qty;
- service_data[key].total = total;
- var table_data = JSON.stringify(service_data);
- $('#tableservice_data').val(table_data);
- }
- });
- </script>
- <script>
- $(document).ready(function () {
- $('#previewmodal').on('hidden.bs.modal', function () {
- $("#view_table-body tr").remove();
- $("#table-termin-body tr").remove();
- $("#ptotal").text('');
- $("#pdiscount").text('');
- $("#pdiskonumum").text('');
- $("#ptax").text('');
- $("#pshipping").text('');
- $("#pbalance").text('');
- $("#pcurrency").text('');
- $("#pinternal_note").text('');
- $("#pnote").text('');
- $("#main").text('');
- $("#cc").text('');
- $("#ppaid_by").text('');
- $("#preference_no").text('');
- $("#pdate").text('');
- $("#pcostumer_name").text('');
- $("#pcostumer_address").text('');
- $("#pcostumer_jalan").text('');
- $("#pcostumer_city").text('');
- $("#pcostumer_country").text('');
- $("#pcostumer_mobile").text('');
- $("#pcostumer_email").text('');
- $("#pcompany_name").text('');
- $("#pwarehouse_name").text('');
- $("#pbranch_address").text('');
- $("#pbranch_city").text('');
- $("#pcompany_phone").text('');
- $("#company_email").text('');
- $('#pctrade').text('');
- $('#termin-other-value').text('');
- });
- $('#preview').on('click',function(){
- var id_customer =$('#customer').val();
- var internal_note =$('#internal_note').val();
- var note =$('#note').val();
- var upcc =$('#main').val();
- var upcc2 =$('#cc').val();
- var radios = document.getElementsByName('paymenterms');
- var reference_no =$('#quotanumb').val();
- var date =$('#quotadate').val();
- var table_data = $('#table_data').val();
- var tableadditional_data =$('#tableadditional_data').val();
- var tableservice_data =$('#tableservice_data').val();
- var ptotal =$('#totalValue').text();
- var pdiscount =$('#DiscountProduct').text();
- var ptax =$('#totalTax').text();
- var dpersen =$('#JumlahDiskonPersen').text();
- var dfix =$('#DiscountFix').text();
- var pshipping =$('#shipping_charge').text();
- var pbalance =$('#grandTotal').text();
- var pcurrency =$('#grandCurrency').text();
- var othervalue =$('#others').text();
- var additional_description =$('#additional_description').val();
- var service_description =$('#service_description').val();
- var counter = 1;
- var product = new Array();
- var additional = new Array();
- var service = new Array();
- for (var i = 0, length = radios.length; i < length; i++)
- {
- if (radios[i].checked)
- {
- paid_by = radios[i].value;
- break;
- }
- }
- $("#ptotal").text(ptotal);
- $("#pdiscount").text(pdiscount);
- $("#pdiskonumum").text(dpersen + dfix);
- $("#ptax").text(ptax);
- $("#pshipping").text(pshipping);
- $("#pbalance").text(pbalance);
- $("#pcurrency").text(pcurrency);
- $("#pinternal_note").text(internal_note);
- $("#pnote").text(note);
- $("#pupcc").text(upcc);
- $("#pupcc2").text(upcc2);
- $("#ppaid_by").text(paid_by);
- $("#preference_no").text(reference_no);
- $("#pdate").text(date);
- if (table_data) {
- product = JSON.parse(table_data);
- }
- if (product.length > 0) {
- for (a = 0; a < product.length; a++) {
- var getnewRow;
- var product_id = product[a].product_id;
- var desc = product[a].desc;
- var quantity = product[a].quantity;
- var price = product[a].price;
- var discount = product[a].discount;
- var tax = product[a].tax;
- $.ajax({
- async : false,
- url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- var id = data[0].product_id;
- var code = data[0].code;
- var name = data[0].name;
- var itembyp = data[0].item_namebyp;
- var unit = data[0].unit;
- var newRow = $("<tr>");
- var cols = "";
- cols += "<td>" + counter + "</td>";
- cols += "<td>" + code + "</td>";
- cols += "<td>" + name + "</td>";
- cols += "<td>" + desc + "</td>";
- cols += "<td>" + quantity + "</td>";
- cols += "<td>" + unit + "</td>";
- cols += "<td>" + price + "</td>";
- cols += "<td>" + (price * quantity) + "</td>";
- cols += "<td>" + discount + "</td>";
- cols += "<td>" + ((price * quantity) - discount) + "</td>";
- cols += "<td>" + tax + "</td>";
- cols += "<td>" + (((price * quantity) - discount) + tax) + "</td>";
- cols += "</tr>";
- newRow.append(cols);
- getnewRow = newRow;
- $("#view_table-body").append(newRow);
- counter++;
- }
- });
- }
- }
- if (tableadditional_data) {
- additional = JSON.parse(tableadditional_data);
- }
- if (additional.length > 0) {
- if (additional_description) {
- var newRow = $("<tr>");
- var cols = "";
- cols += "<td colspan='12' align='left'>" + additional_description + "</td>";
- cols += "</tr>";
- newRow.append(cols);
- getnewRow = newRow;
- $("#view_table-body").append(newRow);
- }
- for (itemrec = 0; itemrec < additional.length; itemrec++) {
- var additional_id = additional[itemrec].additional_id;
- var desc = additional[itemrec].desc;
- var quantity = additional[itemrec].quantity;
- var price = additional[itemrec].price;
- var discount = additional[itemrec].discount;
- var tax = additional[itemrec].tax;
- var flag = 0;
- $.ajax({
- async: false,
- url: "<?php echo base_url('sales/getProduct') ?>/" + additional_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- var id = data[0].product_id;
- var code = data[0].code;
- var name = data[0].name;
- var itembyp = data[0].item_namebyp;
- var unit = data[0].unit;
- var newRow = $("<tr>");
- var cols = "";
- cols += "<td>" + counter + "</td>";
- cols += "<td>" + code + "</td>";
- cols += "<td>" + name + "</td>";
- cols += "<td>" + desc + "</td>";
- cols += "<td>" + quantity + "</td>";
- cols += "<td>" + unit + "</td>";
- cols += "<td>" + price + "</td>";
- cols += "<td>" + (price * quantity) + "</td>";
- cols += "<td>" + discount + "</td>";
- cols += "<td>" + ((price * quantity) - discount) + "</td>";
- cols += "<td>" + tax + "</td>";
- cols += "<td>" + (((price * quantity) - discount) + tax) + "</td>";
- cols += "</tr>";
- newRow.append(cols);
- getnewRow = newRow;
- $("#view_table-body").append(newRow);
- counter++;
- }
- });
- }
- }
- if (tableservice_data) {
- service = JSON.parse(tableservice_data);
- }
- if (service.length > 0) {
- if (service_description) {
- var newRow = $("<tr>");
- var cols = "";
- cols += "<td colspan='12' align='left'>" + service_description + "</td>";
- cols += "</tr>";
- newRow.append(cols);
- getnewRow = newRow;
- $("#view_table-body").append(newRow);
- }
- for (b = 0; b < service.length; b++) {
- var getnewRow;
- var service_id = service[b].service_id;
- var quantity = service[b].quantity;
- var price = service[b].price;
- var discount = service[b].discount;
- var tax = service[b].tax;
- var flag = 0;
- $.ajax({
- async : false,
- url: "<?php echo base_url('sales/getService') ?>/" + service_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- var code = data[0].code;
- var name = data[0].service_title;
- var itembyp = data[0].item_namebyp;
- var unit = data[0].unit;
- var newRow = $("<tr>");
- var cols = "";
- cols += "<td>" + counter + "</td>";
- cols += "<td>" + code + "</td>";
- cols += "<td>" + name + "</td>";
- cols += "<td>-</td>";
- cols += "<td>" + quantity + "</td>";
- cols += "<td>-</td>";
- cols += "<td>" + price + "</td>";
- cols += "<td>" + (price * quantity) + "</td>";
- cols += "<td>" + discount + "</td>";
- cols += "<td>" + ((price * quantity) - discount) + "</td>";
- cols += "<td>" + tax + "</td>";
- cols += "<td>" + (((price * quantity) - discount) + tax) + "</td>";
- cols += "</tr>";
- newRow.append(cols);
- getnewRow = newRow;
- $("#view_table-body").append(newRow);
- counter++;
- }
- });
- }
- }
- if (id_customer) {
- $.ajax({
- url : "<?php echo base_url('quotation/customer/') ?>" + id_customer,
- type: "GET",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- datatype: "JSON",
- success: function (data)
- {
- customer = JSON.parse(data);
- var customer_name = customer[0].customer_name;
- var customer_address = customer[0].address;
- var customer_jalan = customer[0].jalan;
- var customer_city = customer[0].ciname;
- var customer_country = customer[0].coname;
- var customer_mobile = customer[0].mobile;
- var customer_email = customer[0].email;
- $("#pcostumer_name").text(customer_name);
- $("#pcostumer_address").text(customer_address);
- $("#pcostumer_jalan").text(customer_jalan);
- $("#pcostumer_city").text(customer_city);
- $("#pcostumer_country").text(customer_country);
- $("#pcostumer_mobile").text(customer_mobile);
- $("#pcostumer_email").text(customer_email);
- },
- error: function (xhr, status, error)
- {
- alert(error);
- }
- });
- }
- $.ajax({
- url : "<?php echo base_url('quotation/company/') ?>",
- type: "GET",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- datatype: "JSON",
- success: function (data)
- {
- customer = JSON.parse(data);
- var company_name = customer[0].name;
- var company_city = customer[0].city_name;
- var company_country = customer[0].country_name;
- var company_address = customer[0].billing_address;
- var company_phone = customer[0].phone;
- var company_email = customer[0].email;
- $("#pcompany_name").text(company_name);
- $("#pwarehouse_name").text(company_name);
- $("#pbranch_address").text(company_address);
- $("#pbranch_city").text(company_city);
- $("#pcompany_phone").text(company_phone);
- $("#company_email").text(company_email);
- },
- error: function (xhr, status, error)
- {
- alert(error);
- }
- });
- var id = $('#kursdata').val();
- $.ajax({
- url: "<?php echo base_url('sales/getCurrencyAjax') ?>/" + id,
- type: "GET",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- datatype: "JSON",
- success: function (d)
- {
- data = JSON.parse(d);
- var nominalkurs = data[0].nominal;
- $('#pctrade').text(nominalkurs);
- },
- error: function (xhr, status, error)
- {
- alert(error);
- }
- });
- if (paid_by == 'advance') {
- document.getElementById('termin-other').style.display = 'none';
- document.getElementById('termin-bulan').style.display = 'none';
- }
- if (paid_by == 'termin') {
- document.getElementById('termin-bulan').style.display = 'block';
- document.getElementById('termin-other').style.display = 'none';
- var termins =$('#terminnumber').val();
- for (var i = 1, length = termins; i <= termins; i++)
- {
- var nominal = $('#terminvalue'+i).val();
- var ket = $('#terminket'+i).val();
- var newRow = $("<tr>");
- var cols = "";
- cols += "<td>" + i + "</td>";
- cols += "<td>" + ((nominal * pbalance)/100) + "</td>";
- cols += "<td>" + nominal + "</td>";
- cols += "<td>" + ket + "</td>";
- cols += "</tr>";
- newRow.append(cols);
- getnewRow = newRow;
- $("#table-termin-body").append(newRow);
- }
- }
- if (paid_by == 'others') {
- document.getElementById('termin-bulan').style.display = 'none';
- document.getElementById('termin-other').style.display = 'block';
- $('#termin-other-value').text(othervalue);
- }
- });
- $("#submit").click(function (event) {
- var name_regex = /^[a-zA-Z]+$/;
- var sname_regex = /^[a-zA-Z0-9]+$/;
- var num_regex = /^[0-9]+$/;
- var date_regex = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/;
- var date = $('#date').val();
- var reference_no = $('#reference_no').val();
- var biller = $('#biller').val();
- var product = $('#product').val();
- var customer = $('#customer').val();
- var discount = $('#discount').val();
- var internal_note = $('#internal_note').val();
- var grand_total = $('#grand_total').val();
- if (customer == "") {
- $("#err_customer").text("Please Enter Customer");
- $('#customer').focus();
- return false;
- } else {
- $("#err_customer").text("");
- }
- //customer code validation complite.
- if (grand_total == "" || grand_total == null || grand_total == 0.00) {
- ;
- $("#err_product").text("Please Select Product");
- $('#product').focus();
- return false;
- }
- });
- $("#customer").change(function (event) {
- var customer = $('#customer').val();
- if (customer == "") {
- $("#err_customer").text("Please Enter Customer");
- $('#customer').focus();
- return false;
- } else {
- $("#err_customer").text("");
- }
- });
- $("#discount").change(function (event) {
- var discount = $('#discount').val();
- if (discount == "") {
- $("#err_discount").text("Please Enter Discount");
- $('#discount').focus();
- return false;
- } else {
- $("#err_discount").text("");
- }
- if (discount != "") {
- $.ajax({
- url: "<?php echo base_url('sales/getDiscountAjax') ?>/" + discount,
- type: "get",
- dataType: "json",
- success: function (data) {
- var type = data[0].discount_type;
- var value = data[0].discount_value;
- var amount = parseInt(data[0].amount);
- var grand_total = $('#grand_total').val();
- $('#discount_type').val(type);
- $('#total_discount').val(value);
- $('#discount_amount').val(amount);
- if (grand_total > 0 && grand_total != null) {
- if (type == "Fixed") {
- var t = grand_total - value;
- if (grand_total < amount) {
- var t = grand_total;
- }
- $('#lasttotal').text(t);
- $('#last_total').val(t);
- $('#totaldiscount').text(value);
- $('#total_discount').val(value);
- $('#discount_type').val(type);
- $('#discount_amount').val(amount);
- $('#showdiscount').text(" (Rs " + value + ")");
- } else {
- var total = (grand_total * value) / 100;
- var t = grand_total - total;
- $('#totaldiscount').text(total);
- $('#total_discount').val(value);
- $('#discount_type').val('');
- $('#discount_amount').val('');
- $('#lasttotal').text(t);
- $('#last_total').val(t);
- $('#showdiscount').text(" (" + value + "%)");
- }
- }
- }
- });
- }
- });
- $("#product").blur(function (event) {
- var sname_regex = /^[a-zA-Z0-9]+$/;
- var product = $('#product').val();
- if (product == null || product == "") {
- $("#err_product").text("Please Enter Product Code/Name");
- $('#product').focus();
- return false;
- } else {
- $("#err_product").text("");
- }
- if (!product.match(sname_regex)) {
- $('#err_product').text(" Please Enter Valid Product Code/Name ");
- $('#product').focus();
- return false;
- } else {
- $("#err_product").text("");
- }
- });
- });
- </script>
- <script type="text/javascript">
- var hitung = 1;
- var getfromaddFields = 123;
- function isNumber(evt) {
- evt = (evt) ? evt : window.event;
- var charCode = (evt.which) ? evt.which : evt.keyCode;
- if (charCode > 31 && (charCode < 48 || charCode > 57)) {
- return true;
- }
- return true;
- }
- function isNumber_max_100(evt) {
- evt = (evt) ? evt : window.event;
- var charCode = (evt.which) ? evt.which : evt.keyCode;
- if (charCode > 31 && (charCode < 48 || charCode > 57)) {
- return false;
- }
- getvarhit = hitung;
- get_nax_100(getvarhit);
- return true;
- }
- function get_nax_100(getvarhitloop) {
- if (getvarhitloop == 1) {
- $(".getterminvalue").on("change paste", function () {
- hitjumlah = 0;
- for (i = 0; i < getfromaddFields; i++) {
- new_id = "terminvalue" + (i + 1);
- number = document.getElementById(new_id).value;
- if (number) {
- hitjumlah = parseInt(hitjumlah) + parseInt(number);
- }
- }
- if (hitjumlah > 100) {
- alert('Termin melebihi 100')
- }
- });
- }
- hitung = 2;
- }
- jQuery.calculateDiscount = function calculateDiscount(row, data = 0) {
- var discount;
- if (data == 0) {
- discount = +row.find('#discount_value').val();
- } else {
- discount = data;
- }
- var sales_total = +row.find('input[name^="linetotal"]').val();
- var total_discount = sales_total * discount / 100;
- row.find('#product_total').val(sales_total - total_discount);
- row.find('#hidden_discount').val(total_discount);
- var key = +row.find('input[name^="id"]').val();
- product_data[key].discount = total_discount;
- product_data[key].discount_value = +row.find('#discount_value').val();
- product_data[key].discount_id = +row.find('#item_discount').val();
- var table_data = JSON.stringify(product_data);
- $('#table_data').val(table_data);
- }
- jQuery.calculateDiscountAdditional = function calculateDiscountAdditional(row, data = 0) {
- var discount;
- if (data == 0) {
- discount = +row.find('#discount_value').val();
- } else {
- discount = data;
- }
- var sales_total = +row.find('input[name^="linetotal"]').val();
- var total_discount = sales_total * discount / 100;
- row.find('#product_total').val(sales_total - total_discount);
- row.find('#hidden_discount').val(total_discount);
- var key = +row.find('input[name^="id"]').val();
- additional_data[key].discount = total_discount;
- additional_data[key].discount_value = +row.find('#discount_value').val();
- additional_data[key].discount_id = +row.find('#item_discount').val();
- var table_data = JSON.stringify(additional_data);
- $('#tableadditional_data').val(table_data);
- }
- jQuery.calculateDiscountService = function calculateDiscountService(row, data = 0)
- {
- var discount;
- if (data == 0) {
- discount = +row.find('#discountservice_value').val();
- } else {
- discount = data;
- }
- var sales_total = +row.find('input[name^="linetotalservice"]').val();
- var total_discount = sales_total * discount / 100;
- row.find('#service_total').val(sales_total - total_discount);
- row.find('#hidden_discountservice').val(total_discount);
- var key = +row.find('input[name^="idservice"]').val();
- service_data[key].discount = total_discount;
- service_data[key].discount_value = +row.find('#discountservice_value').val();
- service_data[key].discount_id = +row.find('#item_discountservice').val();
- var table_data = JSON.stringify(service_data);
- $('#tableservice_data').val(table_data);
- }
- jQuery.calculateGrandTotal = function calculateGrandTotal(discountdatatext) {
- var totalValue = 0;
- var DiscountProduct = 0;
- var grandTax = 0;
- var grandTotal = 0;
- var grandDiskon = 0;
- var shippingCharge = 0;
- $("table.service_table").find('input[name^="linetotalservice"]').each(function () {
- totalValue += +$(this).val();
- });
- $("table.service_table").find('input[name^="hidden_discountservice"]').each(function () {
- DiscountProduct += +$(this).val();
- });
- $("table.servicetable").find('input[name^="service_total"]').each(function () {
- grandTotal += +$(this).val();
- });
- $("table.product_table").find('input[name^="linetotal"]').each(function () {
- totalValue += +$(this).val();
- });
- $("table.product_table").find('input[name^="hidden_discount"]').each(function () {
- DiscountProduct += +$(this).val();
- });
- $("table.product_table").find('input[name^="salestotal"]').each(function () {
- grandTotal += +$(this).val();
- });
- $("table.summary_table").find('input[name^="shipping_charge"]').each(function () {
- shippingCharge = +$(this).val();
- });
- $("table.additional_table").find('input[name^="subtotal"]').each(function () {
- totalValue += +$(this).val();
- });
- $("table.additional_table").find('input[name^="hidden_discount"]').each(function () {
- DiscountProduct += +$(this).val();
- });
- $("table.additional_table").find('input[name^="salestotal"]').each(function () {
- grandTotal += +$(this).val();
- });
- var totaldiskon = 0;
- grandDiskon = DiscountProduct;
- var diskonval = 0;
- var diskonval2 = 0;
- var diskonpersen = 0;
- diskonpersen = +$('#DiscountPersen').val();
- diskonval2 = totalValue - DiscountProduct;
- diskonval = (diskonpersen / 100) * diskonval2;
- grandDiskon += diskonval;
- grandDiskon += +$('#DiscountFix').val();
- $('Span#totalDiscount').text(grandDiskon);
- totaldiskon = grandDiskon;
- grandTotal = grandTotal - totaldiskon + shippingCharge;
- var taxx = $('#taxx').val();
- grandTax = ((totalValue - totaldiskon) + shippingCharge) * (taxx / 100);
- grandTotal = totalValue - totaldiskon + shippingCharge + grandTax;
- var id = $('#kursdata').val();
- $.ajax({
- url: "<?php echo base_url('sales/getCurrencyAjax') ?>/" + id,
- type: "GET",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- datatype: "JSON",
- success: function (d)
- {
- //alert(d);
- data = JSON.parse(d);
- var symbolkurs = data[0].symbol;
- var nominalkurs = data[0].nominal;
- var grandval = $('#grand_total').val();
- var totalkurs = (grandval * nominalkurs);
- $('#kurs_symbol').text(symbolkurs);
- $('#kurs_symbol1').text(symbolkurs);
- $('#kurs_symbol2').text(symbolkurs);
- $('#kurs_symbol3').text(symbolkurs);
- $('#kurs_symbol4').text(symbolkurs);
- $('#kurs_symbol5').text(symbolkurs);
- $('#kurs_symbol6').text(symbolkurs);
- $('#kurs_symbol7').text(symbolkurs);
- $('#grandCurrency').text("Rp. " + totalkurs.toFixed(2));
- $('#grandCurrency').val("Rp. " + totalkurs.toFixed(2));
- $('#grand_currency').val(totalkurs.toFixed(2));
- },
- error: function (xhr, status, error)
- {
- alert(error);
- }
- });
- $('#totalValue').text(totalValue.toFixed(2));
- $('#total_value').val(totalValue.toFixed(2));
- $('#DiscountProduct').text(DiscountProduct.toFixed(2));
- $('#total_discount').val(totaldiskon);
- $('#totalTax').text(grandTax.toFixed(2));
- $('#total_tax').val(grandTax.toFixed(2));
- $('#grandTotal').text(grandTotal.toFixed(2));
- $('#grand_total').val(grandTotal.toFixed(2));
- }
- </script>
- <script type="text/javascript">
- $('#customer').change(function () {
- var customer_id = $(this).val();
- $.ajax({
- url: "<?php echo base_url('sales/getCustomerData') ?>/" + customer_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- $('#company_id').text('');
- $('#company_name').text('');
- $('#customer_name').text('');
- $('#mobilephone').text('');
- $('#email').text('');
- $('#npwp').text('');
- $('#alamat_npwp').text('');
- $('#npwp').val(data['data'][0].gstid);
- $('#alamat_npwp').val(data['data'][0].cf2);
- $('#company_id').val(data['data'][0].cf1);
- $('#company_name').val(data['data'][0].company_name);
- $('#po_cust').val(data['data'][0].company_name);
- $('#customer_name').val(data['data'][0].customer_name);
- $('#mobilephone').val(data['data'][0].mobile);
- $('#email').val(data['data'][0].email);
- $('#customer_address')
- .find('option')
- .remove()
- .end()
- .append('<option value="">Select Shipping</option>')
- ;
- $('#customer_addressa')
- .find('option')
- .remove()
- .end()
- .append('<option value="">Select Billing</option>')
- ;
- $('#country').val('');
- $('#state').val('');
- $('#city').val('');
- if (typeof data['address'][0] != 'undefined') {
- var cid = data['address'][0].customer_id;
- for (a = 0; a < data['address'].length; a++) {
- if (data['address'][a].type == 0) {
- $('#customer_address').append('<option value="' + data['address'][a].id + '">' + data['address'][a].address + '</option>');
- }
- }
- } else {
- var cid = "";
- }
- if (typeof data['address'][0] != 'undefined') {
- var cid = data['address'][0].customer_id;
- for (a = 0; a < data['address'].length; a++) {
- if (data['address'][a].type == 1) {
- $('#customer_addressa').append('<option value="' + data['address'][a].id + '">' + data['address'][a].address + '</option>');
- }
- }
- } else {
- var cid = "";
- }
- }
- });
- $("#single-input").empty().trigger("change");
- number = '';
- $('#single-input')
- .find('option')
- .remove()
- .end()
- .append('<option value="">Select Quotation</option>')
- ;
- $.ajax({
- url: "<?php echo base_url('sales/getRecordAjax') ?>/" + customer_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- for (a = 0; a < data['data'].length; a++) {
- if (data['data'][a].reference_no2 != null) {
- number = data['data'][a].reference_no2;
- } else {
- number = data['data'][a].reference_no;
- }
- $('#single-input').append('<option value="' + data['data'][a].quotation_id + '">' + number + '</option>');
- }
- },
- error: function (jqxhr, status, exception) {
- alert('Exception:', exception);
- }
- });
- $("#multiple-input").empty().trigger("change");
- number = '';
- $('#multiple-input')
- .find('option')
- .remove()
- .end()
- .append('<option value="">Select Quotation</option>')
- ;
- $.ajax({
- async: false,
- url: "<?php echo base_url('sales/getRecordAjax') ?>/" + customer_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- for (a = 0; a < data['data'].length; a++) {
- if (data['data'][a].reference_no2 != null) {
- number = data['data'][a].reference_no2;
- } else {
- number = data['data'][a].reference_no;
- }
- $('#multiple-input').append('<option value="' + data['data'][a].quotation_id + '">' + number + '</option>');
- $("#multiple-input").trigger("change");
- }
- },
- error: function (jqxhr, status, exception) {
- alert('Exception:', exception);
- }
- });
- });
- $('#selectmultiple').change(function (){
- var select = $(this).val();
- if (select == 1) {
- $('.single').show();
- $('#single-input').attr('name', 'reference_no');
- $('.multiple').hide();
- $('#multiple-input').removeAttr('name','');
- document.getElementById('preference_no').style.display = 'none';
- } else {
- $('.single').hide();
- $('#single-input').attr('name', 'reference_no');
- $('.multiple').show();
- $('#multiple-input').removeAttr('name','');
- document.getElementById('preference_no').style.display = 'none';
- }
- });
- $('#multiple-input').change(function () {
- var single = $('#selectmultiple').val();
- if (single == 1) {
- var refno = $(this).val();
- if (refno != null) {
- $.ajax({
- url: "<?php echo base_url('quotation/getDataQuotation') ?>/" + refno,
- type: "GET",
- dataType: "JSON",
- data: refno,
- success: function (data) {
- $('#DiscountPersen').val(parseInt(data[0].diskonpersen));
- $('#DiscountFix').val(parseInt(data[0].diskon));
- $('#shipping_charge').val(parseInt(data[0].shipping_charge));
- $('#note').val(data[0].note);
- $('#internal_note').val(data[0].internal_note);
- $('#term_and_condition').val(data[0].term_and_condition);
- $('#upcc').val(data[0].upcc);
- $('#upcc2').val(data[0].upcc2);
- $('#tax option[value='+ data[0].attn +']').attr('selected','selected');
- $('#terminnumber option[value='+ data['termin'].length +']').attr('selected','selected');
- $('input[name=paymenterms][value='+ data[0].paid_by +']').prop('checked', true).click();
- if ('termin' == data[0].paid_by) {
- var e = document.getElementById("terminnumber");
- var number = e.options[e.selectedIndex].value;
- getfromaddFields = number;
- var container = document.getElementById("termincontainer");
- while (container.hasChildNodes())
- {
- container.removeChild(container.lastChild);
- }
- var container = container.appendChild(document.createElement("table"));
- container.className = "table table-bordered";
- var container = container.appendChild(document.createElement("tbody"));
- var artermin = data['termin'];
- for (i = 0; i < number; i++)
- {
- var containertr = container.appendChild(document.createElement("tr"));
- var containertd = containertr.appendChild(document.createElement("td"));
- z = document.createElement('span');
- z.innerHTML = "Termin Ke % " + (i + 1) + " :";
- z.className = "text-danger";
- containertd.appendChild(z);
- var input = document.createElement("input");
- input.type = "number";
- input.name = "terminvalue[" + (i + 1) + "]";
- input.id = "terminvalue[" + (i + 1)+"]";
- input.className = "getterminvalue";
- input.value = artermin[i].persen;
- input.min = 1;
- input.max = 100;
- input.maxlength = "2";
- input.onkeypress = isNumber_max_100;
- var containertd = containertr.appendChild(document.createElement("td"));
- containertd.appendChild(input);
- z = document.createElement('span');
- z.className = "text-primary";
- z.innerHTML = ' Ket: ';
- var containertd = containertr.appendChild(document.createElement("td"));
- containertd.appendChild(z);
- var input2 = document.createElement("input");
- input2.type = "text";
- input2.name = "terminket[" + (i + 1) + "]";
- input2.id = "terminket[" + (i + 1)+"]";
- input2.className = "getterminket";
- input2.value = artermin[i].keterangan;
- var containertd = containertr.appendChild(document.createElement("td"));
- containertd.appendChild(input2);
- }
- }
- },
- error: function (jqxhr, status, exception) {
- }
- });
- }
- } else {
- var refno = $(this).val().join('_');
- }
- $.ajax({
- url: "<?php echo base_url('quotation/getQuotationItemsAjax') ?>/" + refno,
- type: "GET",
- dataType: "JSON",
- data: refno,
- success: function (data) {
- product_data = Array();
- $.generateItem(data);
- },
- error: function (jqxhr, status, exception) {
- }
- });
- $.ajax({
- url: "<?php echo base_url('quotation/getQuotationAdditionalAjax') ?>/" + refno,
- type: "GET",
- dataType: "JSON",
- data: refno,
- success: function (data) {
- additional_data = Array();
- $.generateAdditionalItem(data);
- },
- error: function (jqxhr, status, exception) {
- }
- });
- $.ajax({
- url: "<?php echo base_url('quotation/getQuotationServiceItemsAjax') ?>/" + refno,
- type: "GET",
- dataType: "JSON",
- data: refno,
- success: function (data) {
- service_data = Array();
- $.generateServiceItem(data);
- },
- error: function (jqxhr, status, exception) {
- }
- });
- });
- $('#single-input').change(function () {
- var single = $('#selectmultiple').val();
- if (single == 1) {
- var refno = $(this).val();
- if (refno != null) {
- $.ajax({
- url: "<?php echo base_url('quotation/getDataQuotation') ?>/" + refno,
- type: "GET",
- dataType: "JSON",
- data: refno,
- success: function (data) {
- $('#DiscountPersen').val(parseInt(data[0].diskonpersen));
- $('#DiscountFix').val(parseInt(data[0].diskon));
- $('#shipping_charge').val(parseInt(data[0].shipping_charge));
- $('#note').val(data[0].note);
- $('#internal_note').val(data[0].internal_note);
- $('#term_and_condition').val(data[0].term_and_condition);
- $('#upcc').val(data[0].upcc);
- $('#upcc2').val(data[0].upcc2);
- $('#tax option[value='+ data[0].attn +']').attr('selected','selected');
- $('#terminnumber option[value='+ data['termin'].length +']').attr('selected','selected');
- $('input[name=paymenterms][value='+ data[0].paid_by +']').prop('checked', true).click();
- if ('termin' == data[0].paid_by) {
- var e = document.getElementById("terminnumber");
- var number = e.options[e.selectedIndex].value;
- getfromaddFields = number;
- var container = document.getElementById("termincontainer");
- while (container.hasChildNodes())
- {
- container.removeChild(container.lastChild);
- }
- var container = container.appendChild(document.createElement("table"));
- container.className = "table table-bordered";
- var container = container.appendChild(document.createElement("tbody"));
- var artermin = data['termin'];
- for (i = 0; i < number; i++)
- {
- var containertr = container.appendChild(document.createElement("tr"));
- var containertd = containertr.appendChild(document.createElement("td"));
- z = document.createElement('span');
- z.innerHTML = "Termin Ke % " + (i + 1) + " :";
- z.className = "text-danger";
- containertd.appendChild(z);
- var input = document.createElement("input");
- input.type = "number";
- input.name = "terminvalue[" + (i + 1) + "]";
- input.id = "terminvalue[" + (i + 1)+"]";
- input.className = "getterminvalue";
- input.value = artermin[i].persen;
- input.min = 1;
- input.max = 100;
- input.maxlength = "2";
- input.onkeypress = isNumber_max_100;
- var containertd = containertr.appendChild(document.createElement("td"));
- containertd.appendChild(input);
- z = document.createElement('span');
- z.className = "text-primary";
- z.innerHTML = ' Ket: ';
- var containertd = containertr.appendChild(document.createElement("td"));
- containertd.appendChild(z);
- var input2 = document.createElement("input");
- input2.type = "text";
- input2.name = "terminket[" + (i + 1) + "]";
- input2.id = "terminket[" + (i + 1)+"]";
- input2.className = "getterminket";
- input2.value = artermin[i].keterangan;
- var containertd = containertr.appendChild(document.createElement("td"));
- containertd.appendChild(input2);
- }
- }
- },
- error: function (jqxhr, status, exception) {
- }
- });
- }
- } else {
- var refno = $(this).val().join('_');
- }
- $.ajax({
- url: "<?php echo base_url('quotation/getQuotationItemsAjax') ?>/" + refno,
- type: "GET",
- dataType: "JSON",
- data: refno,
- success: function (data) {
- product_data = Array();
- $.generateItem(data);
- },
- error: function (jqxhr, status, exception) {
- }
- });
- $.ajax({
- url: "<?php echo base_url('quotation/getQuotationAdditionalAjax') ?>/" + refno,
- type: "GET",
- dataType: "JSON",
- data: refno,
- success: function (data) {
- additional_data = Array();
- $.generateAdditionalItem(data);
- },
- error: function (jqxhr, status, exception) {
- }
- });
- $.ajax({
- url: "<?php echo base_url('quotation/getQuotationServiceItemsAjax') ?>/" + refno,
- type: "GET",
- dataType: "JSON",
- data: refno,
- success: function (data) {
- service_data = Array();
- $.generateServiceItem(data);
- },
- error: function (jqxhr, status, exception) {
- }
- });
- });
- jQuery.generateItem = function generateItem(items) {
- var counter = 1;
- var aritem = items;
- for (itemrec = 0; itemrec < aritem.length; itemrec++) {
- (function (counter) {
- var getnewRow;
- var quotationid = aritem[itemrec].id;
- var itemquantity = aritem[itemrec].quantity;
- var itemprice = aritem[itemrec].qprice;
- var itemdiscountid = aritem[itemrec].discount_id;
- var itemdiscountid = aritem[itemrec].discount_id;
- var itemdiscountvalue = aritem[itemrec].discount_value;
- var itemdiscount = aritem[itemrec].discount;
- var itemgross_total = aritem[itemrec].gross_total;
- var product_id = aritem[itemrec].product_id;
- var itemdesc = aritem[itemrec].serial_no;
- if (product_id == null) {
- alert('Product Tidak Terdaftar Lagi');
- } else {
- var flag = 0;
- $('#err_product').text('');
- $.ajax({
- url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- $("table.product_table").find('input[name^="product_id"]').each(function () {
- // if (data[0].product_id == +$(this).val()) {
- // flag = 1;
- // }
- });
- if (flag == 0) {
- var id = data[0].product_id;
- var price = itemprice;
- var code = data[0].code;
- var name = data[0].name;
- var itembyp = data[0].item_namebyp;
- var product = {"product_id": id,
- "price": price, "desc": itemdesc
- };
- product_data[yi] = product;
- length = product_data.length - 1;
- var select_discount = "";
- select_discount += '<div class="form-group">';
- select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
- select_discount += '<option value="">Select</option>';
- var selected = '';
- for (a = 0; a < data['discount'].length; a++) {
- if (data['discount'][a].discount_id == itemdiscountid) {
- selected = 'selected ';
- } else {
- selected = '';
- }
- select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
- }
- select_discount += '</select></div>';
- var newRow = $("<tr id='tr" + yi + "'>");
- var cols = "";
- 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>";
- cols += "<td>" + code + "</td>";
- cols += "<td>"
- + "<input type='hidden' value='" + data[0].code + "' name='nameProduct" + counter + "' id='nameProduct" + counter + "'>"
- + "<input type='hidden' value='" + data[0].product_id + "' name='idProduct" + counter + "' id='idProduct" + counter + "'>"
- + name + "</td>";
- cols += "<td>" + itembyp + "</td>";
- cols += "<td><input type='text' class='form-control text-center' value='" + itemdesc + "' name='description" + counter + "' id='description" + counter + "' ></td>";
- 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>";
- cols += "<td id='column-color'>" + data[0].quantity + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'></td>";
- cols += "<td>" + data[0].unit + "</td>";
- cols += "<td align='right'><span><input type='text' class='form-control text-right' value='" + price + "' name='price" + counter + "' id='price" + counter + "'></span></td>";
- 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>";
- 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>';
- cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
- cols += "</tr>";
- newRow.append(cols);
- getnewRow = newRow;
- $("table.product_table").append(newRow);
- calculateRow($('tr#tr' + yi));
- $.calculateDiscount($('tr#tr' + yi));
- $.calculateGrandTotal();
- counter++;
- var table_data = JSON.stringify(product_data);
- $('#table_data').val(table_data);
- yi++;
- } else {
- $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
- }
- }
- });
- }
- })(itemrec);
- }
- function calculateRow(row) {
- var key = +row.find('input[name^="id"]').val();
- var price = +row.find('input[name^="price"]').val();
- var qty = +row.find('input[name^="qty"]').val();
- var desc = row.find('input[name^="description"]').val();
- row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
- var availableqty = +row.find('input[name^="available_quantity"]').val();
- var bookqty = qty - availableqty;
- if (bookqty > 0) {
- row.find('td[id^="column-color"]').css({'background-color': 'red'});
- }
- product_data[key].quantity = qty;
- product_data[key].price = price;
- product_data[key].desc = desc;
- product_data[key].total = (price * qty).toFixed(2);
- var table_data = JSON.stringify(product_data);
- $('#table_data').val(table_data);
- }
- }
- jQuery.generateAdditionalItem = function generateAdditionalItem(additional) {
- var counter = 1;
- var aritem = additional;
- for (itemrec = 0; itemrec < aritem.length; itemrec++) {
- (function (counter) {
- var getnewRow;
- var quotationid = aritem[itemrec].id;
- var itemquantity = aritem[itemrec].quantity;
- var itemprice = aritem[itemrec].qprice;
- var itemdiscountid = aritem[itemrec].discount_id;
- var itemdiscountid = aritem[itemrec].discount_id;
- var itemdiscountvalue = aritem[itemrec].discount_value;
- var itemdiscount = aritem[itemrec].discount;
- var itemgross_total = aritem[itemrec].gross_total;
- var product_id = aritem[itemrec].product_id;
- var itemdesc = aritem[itemrec].desc;
- if (product_id == null) {
- alert('Additional Product Tidak Terdaftar Lagi');
- } else {
- var flag = 0;
- $('#err_product').text('');
- $.ajax({
- url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- $("table.additional_table").find('input[name^="additional_id"]').each(function () {
- // if (data[0].product_id == +$(this).val()) {
- // flag = 1;
- // }
- });
- if (flag == 0) {
- var id = data[0].product_id;
- var price = itemprice;
- var code = data[0].code;
- var name = data[0].name;
- var itembyp = data[0].item_namebyp;
- var product = {"additional_id": id,
- "price": price, "desc": itemdesc
- };
- additional_data[j] = product;
- length = additional_data.length - 1;
- var select_discount = "";
- select_discount += '<div class="form-group">';
- select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
- select_discount += '<option value="">Select</option>';
- var selected = '';
- for (a = 0; a < data['discount'].length; a++) {
- if (data['discount'][a].discount_id == itemdiscountid) {
- selected = 'selected ';
- } else {
- selected = '';
- }
- select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
- }
- select_discount += '</select></div>';
- var newRow = $("<tr id='tra" + j + "'>");
- var cols = "";
- 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>";
- cols += "<td>" + code + "</td>";
- cols += "<td>"
- + "<input type='hidden' value='" + data[0].code + "' name='nameProduct" + counter + "' id='nameProduct" + counter + "'>"
- + "<input type='hidden' value='" + data[0].product_id + "' name='idProduct" + counter + "' id='idProduct" + counter + "'>"
- + name + "</td>";
- cols += "<td>" + itembyp + "</td>";
- cols += "<td><input type='text' class='form-control text-center' value='" + itemdesc + "' name='description" + counter + "' id='description" + counter + "' ></td>";
- 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>";
- cols += "<td>" + data[0].quantity + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'></td>";
- cols += "<td>" + data[0].unit + "</td>";
- cols += "<td align='right'><span><input type='text' class='form-control text-right' value='" + price + "' name='price" + counter + "' id='price" + counter + "'></span></td>";
- 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>";
- 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>';
- cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
- cols += "</tr>";
- newRow.append(cols);
- getnewRow = newRow;
- $("table.additional_table").append(newRow);
- calculateRowAdditional($('tr#tra' + j));
- $.calculateDiscountAdditional($('tr#tra' + j));
- $.calculateGrandTotal();
- counter++;
- var table_data = JSON.stringify(additional_data);
- $('#tableadditional_data').val(table_data);
- j++;
- } else {
- $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
- }
- }
- });
- }
- })(itemrec);
- }
- function calculateRowAdditional(row) {
- var key = +row.find('input[name^="id"]').val();
- var price = +row.find('input[name^="price"]').val();
- var qty = +row.find('input[name^="qty"]').val();
- var desc = row.find('input[name^="description"]').val();
- row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
- var availableqty = +row.find('input[name^="available_quantity"]').val();
- var bookqty = qty - availableqty;
- if (bookqty > 0) {
- row.find('td[id^="column-color"]').css({'background-color': 'red'});
- }
- additional_data[key].quantity = qty;
- additional_data[key].price = price;
- additional_data[key].desc = desc;
- additional_data[key].total = (price * qty).toFixed(2);
- var table_data = JSON.stringify(additional_data);
- $('#tableadditional_data').val(table_data);
- }
- }
- jQuery.generateServiceItem = function generateServiceItem(serviceitem) {
- var counter = 1;
- var aritem = serviceitem;
- for (itemrec = 0; itemrec < aritem.length; itemrec++) {
- (function (counter) {
- var getnewRowService;
- var quotationid = aritem[itemrec].id;
- var itemquantity = aritem[itemrec].quantity;
- var itemprice = aritem[itemrec].qprice;
- var itemdiscountid = aritem[itemrec].discount_id;
- var itemdiscountvalue = aritem[itemrec].discount_value;
- var itemdiscount = aritem[itemrec].discount;
- var itemgross_total = aritem[itemrec].gross_total;
- var service_id = aritem[itemrec].service_id;
- var flag = 0;
- $('#err_service').text('');
- $.ajax({
- url: "<?php echo base_url('sales/getService') ?>/" + service_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- $("table.service_table").find('input[name^="service_id"]').each(function () {
- if (data[0].service_id == +$(this).val()) {
- flag = 1;
- }
- });
- if (flag == 0)
- {
- var id = data[0].service_id;
- var code = data[0].code;
- var name = data[0].service_title;
- var price = itemprice;
- if (price == null) {
- price = 0;
- }
- var product = {"service_id": id,
- "price": price
- };
- service_data[k] = product;
- length = service_data.length - 1;
- var select_discount = "";
- select_discount += '<div class="form-group">';
- select_discount += '<select class="form-control select2" id="item_discountservice" name="item_discountservice" style="width: 100%;">';
- select_discount += '<option value="">Select</option>';
- var selected = '';
- for (a = 0; a < data['discount'].length; a++) {
- if (data['discount'][a].discount_id == itemdiscountid) {
- selected = 'selected ';
- } else {
- selected = '';
- }
- select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
- }
- select_discount += '</select></div>';
- var newRowService = $("<tr id='trv" + counter + "'>");
- var cols = "";
- 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>";
- cols += "<td>" + code + "</td>";
- cols += "<td>"
- + "<input type='hidden' value='' name='nameService" + counter + "' id='nameService" + counter + "'>"
- + name + "</td>";
- cols += "<td>"
- + "<input type='number' class='form-control text-center' value='" + itemquantity + "' data-rule='quantity' name='qtyservice" + counter + "' id='qtyservice" + counter + "' min='0' max='2'>"
- + "</td>";
- cols += "<td align='right'>"
- + "<span id='price'>"
- + "<input type='text' class='form-control text-right' name='priceservice" + counter + "' id='priceservice" + counter + "' value='" + price
- + "'>"
- + "</span>"
- + "</td>";
- cols += "<td>"
- + "<span id='sub_total'>"
- + "<input type='text' class='form-control text-right' style='' value='" + itemgross_total + "' name='linetotalservice" + counter + "' id='linetotalservice" + counter + "' readonly>"
- + "</span>"
- + "</td>";
- 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>';
- cols += '<td><input type="text" class="form-control text-right" id="service_total" name="service_total" readonly></td>';
- cols += "</tr>";
- newRowService.append(cols);
- getnewRowService = newRowService;
- $("table.service_table").append(newRowService);
- calculateRowService($('tr#trv' + k));
- $.calculateDiscountService($('tr#trv' + k));
- $.calculateGrandTotal();
- counter++;
- var table_data = JSON.stringify(service_data);
- $('#tableservice_data').val(table_data);
- k++;
- } else {
- $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
- }
- }
- });
- })(itemrec);
- }
- function calculateRowService(row)
- {
- var key = +row.find('input[name^="idservice"]').val();
- var price = +row.find('input[name^="priceservice"]').val();
- var qty = +row.find('input[name^="qtyservice"]').val();
- var total = +row.find('input[name^="linetotalservice"]').val();
- row.find('input[name^="linetotalservice"]').val((price * qty).toFixed(2));
- service_data[key].price = price;
- service_data[key].quantity = qty;
- service_data[key].total = total;
- var table_data = JSON.stringify(service_data);
- $('#tableservice_data').val(table_data);
- }
- }
- </script>
- <script>
- $(document).ready(function () {
- $.ajax({
- url: "<?php echo base_url('customer/getState') ?>/" + 102,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- for (a = 0; a < data.length; a++) {
- $('#statec').append('<option value="' + data[a].id + '">' + data[a].name + '</option>');
- }
- }
- });
- });
- $('#countryc').change(function () {
- $('#statec').html('');
- $('#statec').html('<option value="">Select State</option>');
- var country_id = $('#countryc').val();
- $.ajax({
- url: "<?php echo base_url('customer/getState') ?>/" + country_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- for (a = 0; a < data.length; a++) {
- $('#statec').append('<option value="' + data[a].id + '">' + data[a].name + '</option>');
- }
- }
- });
- });
- $('#statec').change(function () {
- $('#cityc').html('');
- $('#cityc').html('<option value="">Select City</option>');
- var state_id = $('#statec').val();
- $.ajax({
- url: "<?php echo base_url('customer/getCity') ?>/" + state_id,
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- for (a = 0; a < data.length; a++) {
- $('#cityc').append('<option value="' + data[a].id + '">' + data[a].name + '</option>');
- }
- }
- });
- });
- $('#btn_submit').click(function (e) {
- e.preventDefault();
- $.ajax({
- url: '<?php echo base_url('customer/test') ?>',
- datatype: 'JSON',
- method: 'POST',
- data: {
- 'customer_name': $('#c_name').val(),
- 'address': $("#c_address").val(),
- 'country': $("#countryc").val(),
- 'state': $("#statec").val(),
- 'city': $("#cityc").val(),
- 'mobile': $('#c_mobile').val()
- },
- success: function (data) {
- if (data == 1) {
- $('#myModal').modal('hide');
- updateCostumer();
- } else {
- alert("Try again");
- }
- }
- })
- })
- function updateCostumer() {
- $('#customer').html('');
- $('#customer').html('<option value="">Select Customer</option>');
- $.ajax({
- url: "<?php echo base_url('customer/getData') ?>",
- type: "GET",
- dataType: "JSON",
- data: {
- '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
- },
- success: function (data) {
- for (a = 0; a < data.length; a++) {
- $('#customer').append('<option value="' + data[a].customer_id + '">' + data[a].customer_name + '</option>');
- }
- }
- });
- }
- function checkAvailability() {
- $("#loaderIcon").show();
- jQuery.ajax({
- url: "<?php echo base_url('customer/checkCompany_name') ?>",
- data: 'company_name=' + $("#company_name").val(),
- type: "POST",
- success: function(data) {
- $("#user-availability-status").html(data);
- $("#loaderIcon").hide();
- },
- error: function() {}
- });
- }
- </script>
- <script type="text/javascript">
- $(document).ready(function(){
- var totalnya = 0;
- $('.salestotal').each(function(i,v){
- // console.log($(this).val());
- var nilai = $(this).val();
- nilai = parseInt(nilai);
- totalnya += nilai;
- });
- $('#totalValue').text(totalnya);
- })
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement