fadlyshafa

Untitled

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