fadlyshafa

Untitled

Jun 23rd, 2020
59
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. var select_discount = "";
  1065. select_discount += '<div class="form-group">';
  1066. select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
  1067. select_discount += '<option value="">Select</option>';
  1068. for (a = 0; a < data['discount'].length; a++) {
  1069. select_discount += '<option value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  1070. }
  1071. select_discount += '</select></div>';
  1072.  
  1073.  
  1074. var newRow = $("<tr id='tr"+ yi +"'>");
  1075. var cols = "";
  1076. cols += "<td><a class='deleteRow'> <img src='<?php echo base_url(); ?>assets/images/bin3.png' /> </a><input type='hidden' name='id' name='id' value=" + yi + "><input type='hidden' name='product_id' name='product_id' value=" + id + "></td>";
  1077. cols += "<td>" + code + "</td>";
  1078. cols += "<td><input type='hidden' value='" + data[0].name + "' name='nameProduct" + counter + "' id='nameProduct" + counter + "'><input type='hidden' value='" + data[0].product_id + "' name='idProduct" + counter + "' id='idProduct" + counter + "'>" + name + "</td>";
  1079. cols += "<td>" + item_namebyp + "</td>";
  1080. cols += "<td><input type='text' name='description" + counter + "' id='description"+ counter + "' value='" + name + "' class='form-control'></td>";
  1081.  
  1082. 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>";
  1083.  
  1084. cols += "<td>" + data[0].quantity + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'></td>";
  1085. cols += "<td>" + data[0].unit + "</td>";
  1086. 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>";
  1087. 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>";
  1088. cols += '<td><input type="hidden" id="discount_value" name="discount_value"><input type="hidden" id="hidden_discount" name="hidden_discount">' + select_discount + '</td>';
  1089.  
  1090. cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
  1091. cols += "</tr>";
  1092. counter++;
  1093. newRow.append(cols);
  1094. $("table.product_table").append(newRow);
  1095. var table_data = JSON.stringify(product_data);
  1096. $('#table_data').val(table_data);
  1097. yi++;
  1098. } else {
  1099. $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  1100. }
  1101. }
  1102. });
  1103. });
  1104.  
  1105. $('#a_brand').change(function () {
  1106. $('#a_code_item').html('');
  1107. $('#a_code_item').html('<option value="">Select Part Number</option>');
  1108. var brand_id = $('#a_brand').val();
  1109. $.ajax({
  1110. url: "<?php echo base_url('sales/getPartNumber') ?>/" + brand_id,
  1111. type: "GET",
  1112. dataType: "JSON",
  1113. data: {
  1114. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1115. },
  1116. success: function (data) {
  1117. for (a = 0; a < data.length; a++) {
  1118. $('#a_code_item').append('<option value="' + data[a].code + '">' + data[a].code + '</option>');
  1119. }
  1120. }
  1121. });
  1122. });
  1123.  
  1124. $('#a_code_item').change(function () {
  1125. $('#a_product').html('');
  1126. $('#a_product').html('<option value="">Select Product</option>');
  1127. var code = $('#a_code_item').val();
  1128. $.ajax({
  1129. url: "<?php echo base_url('sales/getCodeProduct') ?>/" + code,
  1130. type: "GET",
  1131. dataType: "JSON",
  1132. data: {
  1133. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1134. },
  1135. success: function (data) {
  1136. for (a = 0; a < data.length; a++) {
  1137. $('#a_product').append('<option value="' + data[a].product_id + '">' + data[a].name + '</option>');
  1138. }
  1139. }
  1140. });
  1141. });
  1142.  
  1143. $('#a_product').change(function () {
  1144. var id = $(this).val();
  1145. var product_id = $('#a_product').val();
  1146. var flag = 0;
  1147. $('#err_a_product').text('');
  1148. $.ajax({
  1149. url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
  1150. type: "GET",
  1151. dataType: "JSON",
  1152. data: {
  1153. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1154. },
  1155. success: function (data) {
  1156.  
  1157. $("table.additional_table").find('input[name^="product_id"]').each(function () {
  1158. if (data[0].additional_id == +$(this).val()) {
  1159. flag = 1;
  1160. }
  1161. });
  1162.  
  1163. if (flag == 0) {
  1164. var id = data[0].product_id;
  1165. var price = data[0].cost;
  1166. var code = data[0].code;
  1167. var name = data[0].name;
  1168. var itembyp = data[0].item_namebyp;
  1169. var stock = data[0].quantity;
  1170. var uom = data[0].uom;
  1171. var product = {"additional_id": id, "price": 0
  1172. };
  1173.  
  1174. additional_data[j] = product;
  1175. length = additional_data.length - 1;
  1176.  
  1177. var select_discount = "";
  1178. select_discount += '<div class="form-group">';
  1179. select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
  1180. select_discount += '<option value="">Select</option>';
  1181. for (a = 0; a < data['discount'].length; a++) {
  1182. select_discount += '<option value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  1183. }
  1184. select_discount += '</select></div>';
  1185.  
  1186. var newRow = $("<tr id='tra"+ j +"'>");
  1187. var cols = "";
  1188. 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>";
  1189. cols += "<td>" + code + "</td>";
  1190. 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>";
  1191. cols += "<td>" + itembyp + "</td>";
  1192. cols += "<td><input type='text' name='description" + counter + "' id='description"+ counter + "' value='" + name + "' class='form-control'></td>";
  1193. cols += "<td>"
  1194. + "<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 + "'>"
  1195. + "</td>";
  1196. cols += "<td>" + data[0].quantity + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'></td>";
  1197. cols += "<td>" + data[0].unit + "</td>";
  1198. 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>";
  1199. 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>";
  1200. cols += '<td><input type="hidden" id="discount_value" name="discount_value"><input type="hidden" id="hidden_discount" name="hidden_discount">' + select_discount + '</td>';
  1201.  
  1202. cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
  1203. cols += "</tr>";
  1204. counter++;
  1205. newRow.append(cols);
  1206. $("table.additional_table").append(newRow);
  1207. var table_data = JSON.stringify(additional_data);
  1208. $('#tableadditional_data').val(table_data);
  1209. j++;
  1210. } else {
  1211. $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  1212. }
  1213. }
  1214. });
  1215. });
  1216.  
  1217. $('#service').change(function () {
  1218. var id = $(this).val();
  1219. var service_id = $('#service').val();
  1220.  
  1221. var flag = 0;
  1222. $('#err_service').text('');
  1223. $.ajax({
  1224. url: "<?php echo base_url('sales/getService') ?>/" + service_id,
  1225. type: "GET",
  1226. dataType: "JSON",
  1227. data: {
  1228. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1229. },
  1230. success: function (data) {
  1231. $("table.service_table").find('input[name^="service_id"]').each(function () {
  1232. if (data[0].service_id == +$(this).val()) {
  1233. flag = 1;
  1234. }
  1235. });
  1236. if (flag == 0) {
  1237. var id = data[0].service_id;
  1238. var code = data[0].code;
  1239. var name = data[0].service_title;
  1240. var hsn_sac_code = '';
  1241. var price = data[0].price;
  1242.  
  1243. var product = {"service_id": id,
  1244. "price": price
  1245. };
  1246. service_data[k] = product;
  1247.  
  1248. length = service_data.length - 1;
  1249.  
  1250. var select_discount = "";
  1251. select_discount += '<div class="form-group">';
  1252. select_discount += '<select class="form-control select2" id="item_discountservice" name="item_discountservice" style="width: 100%;">';
  1253. select_discount += '<option value="">Select</option>';
  1254. for (a = 0; a < data['discount'].length; a++) {
  1255. select_discount += '<option value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  1256. }
  1257. select_discount += '</select></div>';
  1258.  
  1259. var newRow = $("<tr>");
  1260. var cols = "";
  1261. 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>";
  1262. cols += "<td>" + code + "</td>";
  1263. cols += "<td>" + name + "</td>";
  1264. cols += "<td>"
  1265. + "<input type='number' class='form-control text-center' value='0' data-rule='quantity' name='qtyservice" + counter + "' id='qtyservice" + counter + "' min='0' max='2'>"
  1266. + "</td>";
  1267. cols += "<td align='right'>"
  1268. + "<span id='price'>"
  1269. + "<input type='text' step='0.01' class='form-control text-right' name='priceservice" + counter + "' id='priceservice" + counter + "' value='" + price
  1270. + "'>"
  1271. + "</span>"
  1272. + "</td>";
  1273. cols += "<td>"
  1274. + "<span id='sub_total'>"
  1275. + "<input type='text' class='form-control text-right' style='' value='0.00' name='linetotalservice" + counter + "' id='linetotalservice" + counter + "' readonly>"
  1276. + "</span>"
  1277. + "</td>";
  1278. cols += '<td><input type="hidden" id="discountservice_value" name="discountservice_value"><input type="hidden" id="hidden_discountservice" name="hidden_discountservice">' + select_discount + '</td>';
  1279.  
  1280. cols += '<td><input type="text" class="form-control text-right" id="service_total" name="service_total" readonly></td>';
  1281. cols += "</tr>";
  1282. counter++;
  1283.  
  1284. newRow.append(cols);
  1285. $("table.service_table").append(newRow);
  1286. var table_data = JSON.stringify(service_data);
  1287. $('#tableservice_data').val(table_data);
  1288. k++;
  1289. } else {
  1290. $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  1291. }
  1292. }
  1293. });
  1294. });
  1295.  
  1296.  
  1297.  
  1298.  
  1299. $("table.product_table").on("click", "a.deleteRow", function (event) {
  1300. deleteRow($(this).closest("tr"));
  1301. $(this).closest("tr").remove();
  1302. $.calculateGrandTotal();
  1303. });
  1304.  
  1305. $("table.additional_table").on("click", "a.deleteRow", function (event) {
  1306. deleteRowAdditional($(this).closest("tr"));
  1307. $(this).closest("tr").remove();
  1308. $.calculateGrandTotal();
  1309. });
  1310.  
  1311.  
  1312. $("table.service_table").on("click", "a.deleteRow", function (event) {
  1313. deleteRowService($(this).closest("tr"));
  1314. $(this).closest("tr").remove();
  1315. $.calculateGrandTotal();
  1316. });
  1317.  
  1318. function deleteRow(row) {
  1319. var id = +row.find('input[name^="id"]').val();
  1320. var array_id = product_data[id].product_id;
  1321. product_data[id] = null;
  1322. var table_data = JSON.stringify(product_data);
  1323. $('#table_data').val(table_data);
  1324. }
  1325.  
  1326. function deleteRowAdditional(row) {
  1327. var id = +row.find('input[name^="id"]').val();
  1328. additional_data[id] = null;
  1329. var table_data = JSON.stringify(additional_data);
  1330. $('#tableadditional_data').val(table_data);
  1331. }
  1332.  
  1333. function deleteRowService(row) {
  1334. var id = +row.find('input[name^="idservice"]').val();
  1335. service_data[id] = null;
  1336. var table_data = JSON.stringify(service_data);
  1337. $('#tableservice_data').val(table_data);
  1338. }
  1339.  
  1340. $("table.product_table").on("change", 'input[name^="price"], input[name^="qty"]', function (event) {
  1341.  
  1342. calculateRow($(this).closest("tr"));
  1343. $.calculateDiscount($(this).closest("tr"));
  1344. $.calculateGrandTotal();
  1345.  
  1346. });
  1347.  
  1348. $("table.product_table").on("change", 'input[name^="qty"]', function (event) {
  1349. row = $(this).closest("tr");
  1350. var key = +row.find('input[name^="id"]').val();
  1351. var price = +row.find('input[name^="price"]').val();
  1352. var qty = +row.find('input[name^="qty"]').val();
  1353. var desc = row.find('input[name^="description"]').val();
  1354. var nqty = row.find('input[name^="qty"]').attr('name');
  1355. var availableqty = +row.find('input[name^="available_quantity"]').val();
  1356. var nameproductval = row.find('input[name^="nameProduct"]').val();
  1357. var idproductval = +row.find('input[name^="idProduct"]').val();
  1358. var bookqty = qty - availableqty;
  1359. if (bookqty > 0) {
  1360. $("#m_id_product").val(idproductval);
  1361. $("#qtytitle").text(nqty);
  1362. $("#m_name_product").val(nameproductval);
  1363. $("#m_ref").val($('#sales_order').text());
  1364. $("#m_type").val('tr'+key);
  1365. $("#m_qty").val(bookqty);
  1366. $("#m_price").val(price);
  1367. $("#m_date").val($('#sales_date').val());
  1368. $("#bookingmodal").modal("show");
  1369. }
  1370. });
  1371.  
  1372. $("table.additional_table").on("change", 'input[name^="price"], input[name^="qty"]', function (event) {
  1373.  
  1374. calculateRowAdditional($(this).closest("tr"));
  1375. $.calculateDiscountAdditional($(this).closest("tr"));
  1376. $.calculateGrandTotal();
  1377.  
  1378. });
  1379.  
  1380. $("table.additional_table").on("change", 'input[name^="qty"]', function (event) {
  1381. row = $(this).closest("tr");
  1382. var key = +row.find('input[name^="id"]').val();
  1383. var price = +row.find('input[name^="price"]').val();
  1384. var qty = +row.find('input[name^="qty"]').val();
  1385. var desc = row.find('input[name^="description"]').val();
  1386. var nqty = row.find('input[name^="qty"]').attr('name');
  1387. var availableqty = +row.find('input[name^="available_quantity"]').val();
  1388. var nameproductval = row.find('input[name^="nameProduct"]').val();
  1389. var idproductval = +row.find('input[name^="idProduct"]').val();
  1390. var bookqty = qty - availableqty;
  1391. if (bookqty > 0) {
  1392. $("#m_id_product").val(idproductval);
  1393. $("#qtytitle").text(nqty);
  1394. $("#m_name_product").val(nameproductval);
  1395. $("#m_ref").val($('#sales_order').text());
  1396. $("#m_type").val('tr'+key);
  1397. $("#m_qty").val(bookqty);
  1398. $("#m_price").val(price);
  1399. $("#m_date").val($('#sales_date').val());
  1400. $("#bookingmodal").modal("show");
  1401. }
  1402. });
  1403.  
  1404. $("table.service_table").on("change", 'input[name^="priceservice"], input[name^="qtyservice"]', function (event) {
  1405.  
  1406. calculateRowService($(this).closest("tr"));
  1407. $.calculateDiscountService($(this).closest("tr"));
  1408. $.calculateGrandTotal();
  1409. });
  1410.  
  1411. $("table.product_table").on("change", 'input[name ^= "linetotal"]', function (event) {
  1412.  
  1413. calculateRow2($(this).closest("tr"));
  1414. $.calculateDiscount($(this).closest("tr"));
  1415. $.calculateGrandTotal();
  1416. });
  1417.  
  1418. $("table.additional_table").on("change", 'input[name ^= "linetotal"]', function (event) {
  1419.  
  1420. calculateRowAdditional2($(this).closest("tr"));
  1421. $.calculateDiscountAdditional($(this).closest("tr"));
  1422. $.calculateGrandTotal();
  1423. });
  1424.  
  1425. $("table.service_table").on("change", 'input[name^="linetotalservice"]', function (event)
  1426. {
  1427.  
  1428. calculateRowService2($(this).closest("tr"));
  1429. $.calculateDiscountService($(this).closest("tr"));
  1430. $.calculateGrandTotal();
  1431. });
  1432.  
  1433. nilai_diskon = 0;
  1434.  
  1435. $("table.product_table").on("change", '#item_discount', function (event) {
  1436. var row = $(this).closest("tr");
  1437. var discount = +row.find('#item_discount').val();
  1438. var diskon = $(this).val();
  1439. // console.log(diskon);
  1440. if (diskon != "") {
  1441. $.ajax({
  1442. url: '<?php echo base_url('purchase/getDiscountValue/') ?>' + diskon,
  1443. type: "GET",
  1444. data: {
  1445. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1446. },
  1447. datatype: JSON,
  1448. success: function (value) {
  1449. data = JSON.parse(value);
  1450. console.log(data);
  1451. // row.find('#discount_value').val(data[0].discount_value);
  1452. // $.calculateDiscount(row, data[0].discount_value);
  1453. // $.calculateGrandTotal();
  1454.  
  1455. var diskon = data[0].discount_value / 100;
  1456. diskon = parseFloat(diskon);
  1457.  
  1458. var subtotal = row.find('.subtotal').val();
  1459. subtotal = parseFloat(subtotal);
  1460. console.log(diskon);
  1461.  
  1462. diskon = diskon * subtotal;
  1463. nilai_diskon += diskon;
  1464.  
  1465. subtotal = subtotal - diskon;
  1466.  
  1467. row.find('.salestotal').val(subtotal);
  1468.  
  1469. }
  1470. });
  1471. } else {
  1472. // row.find('#discount_value').val('0');
  1473. // $.calculateDiscount(row, 0);
  1474. // $.calculateGrandTotal();
  1475. }
  1476. });
  1477.  
  1478. $("table.additional_table").on("change", '#item_discount', function (event) {
  1479. var row = $(this).closest("tr");
  1480. var discount = +row.find('#item_discount').val();
  1481. if (discount != "") {
  1482. $.ajax({
  1483. url: '<?php echo base_url('purchase/getDiscountValue/') ?>' + discount,
  1484. type: "GET",
  1485. data: {
  1486. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1487. },
  1488. datatype: JSON,
  1489. success: function (value) {
  1490. data = JSON.parse(value);
  1491. row.find('#discount_value').val(data[0].discount_value);
  1492. $.calculateDiscountAdditional(row, data[0].discount_value);
  1493. $.calculateGrandTotal();
  1494. }
  1495. });
  1496. } else {
  1497. row.find('#discount_value').val('0');
  1498. $.calculateDiscountAdditional(row, 0);
  1499. $.calculateGrandTotal();
  1500. }
  1501. });
  1502.  
  1503. $("table.service_table").on("change", '#item_discountservice', function (event) {
  1504. var row = $(this).closest("tr");
  1505. var discount = +row.find('#item_discountservice').val();
  1506. if (discount != "") {
  1507. $.ajax({
  1508. url: '<?php echo base_url('purchase/getDiscountValue/') ?>' + discount,
  1509. type: "GET",
  1510. data: {
  1511. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1512. },
  1513. datatype: JSON,
  1514. success: function (value) {
  1515. data = JSON.parse(value);
  1516. row.find('#discountservice_value').val(data[0].discount_value);
  1517. $.calculateDiscountService(row, data[0].discount_value);
  1518. $.calculateGrandTotal();
  1519. }
  1520. });
  1521. } else {
  1522. row.find('#discountservice_value').val('0');
  1523. $.calculateDiscountService(row, 0);
  1524. $.calculateGrandTotal();
  1525. }
  1526. });
  1527.  
  1528. function calculateRow(row) {
  1529. var key = +row.find('input[name^="id"]').val();
  1530. var price = +row.find('input[name^="price"]').val();
  1531. var desc = row.find('input[name^="description"]').val();
  1532. var qty = +row.find('input[name^="qty"]').val();
  1533.  
  1534. row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
  1535. product_data[key].price = price;
  1536. product_data[key].quantity = qty;
  1537. product_data[key].desc = desc;
  1538. product_data[key].total = (price * qty).toFixed(2);
  1539. var table_data = JSON.stringify(product_data);
  1540. $('#table_data').val(table_data);
  1541. }
  1542.  
  1543. function calculateRowAdditional(row) {
  1544. var key = +row.find('input[name^="id"]').val();
  1545. var price = +row.find('input[name^="price"]').val();
  1546. var desc = row.find('input[name^="description"]').val();
  1547. var qty = +row.find('input[name^="qty"]').val();
  1548.  
  1549. row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
  1550. additional_data[key].price = price;
  1551. additional_data[key].quantity = qty;
  1552. additional_data[key].desc = desc;
  1553. additional_data[key].total = (price * qty).toFixed(2);
  1554. var table_data = JSON.stringify(additional_data);
  1555. $('#tableadditional_data').val(table_data);
  1556. }
  1557.  
  1558. function calculateRowService(row)
  1559. {
  1560. var key = +row.find('input[name^="idservice"]').val();
  1561. var price = +row.find('input[name^="priceservice"]').val();
  1562. var qty = +row.find('input[name^="qtyservice"]').val();
  1563. var total = +row.find('input[name^="linetotalservice"]').val();
  1564. row.find('input[name^="linetotalservice"]').val((price * qty).toFixed(2));
  1565. service_data[key].price = price;
  1566. service_data[key].quantity = qty;
  1567. service_data[key].total = total;
  1568. var table_data = JSON.stringify(service_data);
  1569. $('#tableservice_data').val(table_data);
  1570. }
  1571.  
  1572.  
  1573. });
  1574.  
  1575. </script>
  1576. <script>
  1577. $(document).ready(function () {
  1578. $('#previewmodal').on('hidden.bs.modal', function () {
  1579. $("#view_table-body tr").remove();
  1580. $("#table-termin-body tr").remove();
  1581. $("#ptotal").text('');
  1582. $("#pdiscount").text('');
  1583. $("#pdiskonumum").text('');
  1584. $("#ptax").text('');
  1585. $("#pshipping").text('');
  1586. $("#pbalance").text('');
  1587. $("#pcurrency").text('');
  1588. $("#pinternal_note").text('');
  1589. $("#pnote").text('');
  1590. $("#main").text('');
  1591. $("#cc").text('');
  1592. $("#ppaid_by").text('');
  1593. $("#preference_no").text('');
  1594. $("#pdate").text('');
  1595. $("#pcostumer_name").text('');
  1596. $("#pcostumer_address").text('');
  1597. $("#pcostumer_jalan").text('');
  1598. $("#pcostumer_city").text('');
  1599. $("#pcostumer_country").text('');
  1600. $("#pcostumer_mobile").text('');
  1601. $("#pcostumer_email").text('');
  1602. $("#pcompany_name").text('');
  1603. $("#pwarehouse_name").text('');
  1604. $("#pbranch_address").text('');
  1605. $("#pbranch_city").text('');
  1606. $("#pcompany_phone").text('');
  1607. $("#company_email").text('');
  1608. $('#pctrade').text('');
  1609. $('#termin-other-value').text('');
  1610. });
  1611.  
  1612. $('#preview').on('click',function(){
  1613.  
  1614. var id_customer =$('#customer').val();
  1615. var internal_note =$('#internal_note').val();
  1616. var note =$('#note').val();
  1617. var upcc =$('#main').val();
  1618. var upcc2 =$('#cc').val();
  1619. var radios = document.getElementsByName('paymenterms');
  1620. var reference_no =$('#quotanumb').val();
  1621. var date =$('#quotadate').val();
  1622. var table_data = $('#table_data').val();
  1623. var tableadditional_data =$('#tableadditional_data').val();
  1624. var tableservice_data =$('#tableservice_data').val();
  1625. var ptotal =$('#totalValue').text();
  1626. var pdiscount =$('#DiscountProduct').text();
  1627. var ptax =$('#totalTax').text();
  1628. var dpersen =$('#JumlahDiskonPersen').text();
  1629. var dfix =$('#DiscountFix').text();
  1630. var pshipping =$('#shipping_charge').text();
  1631. var pbalance =$('#grandTotal').text();
  1632. var pcurrency =$('#grandCurrency').text();
  1633. var othervalue =$('#others').text();
  1634. var additional_description =$('#additional_description').val();
  1635. var service_description =$('#service_description').val();
  1636. var counter = 1;
  1637. var product = new Array();
  1638. var additional = new Array();
  1639. var service = new Array();
  1640.  
  1641. for (var i = 0, length = radios.length; i < length; i++)
  1642. {
  1643. if (radios[i].checked)
  1644. {
  1645. paid_by = radios[i].value;
  1646. break;
  1647. }
  1648. }
  1649.  
  1650. $("#ptotal").text(ptotal);
  1651. $("#pdiscount").text(pdiscount);
  1652. $("#pdiskonumum").text(dpersen + dfix);
  1653. $("#ptax").text(ptax);
  1654. $("#pshipping").text(pshipping);
  1655. $("#pbalance").text(pbalance);
  1656. $("#pcurrency").text(pcurrency);
  1657. $("#pinternal_note").text(internal_note);
  1658. $("#pnote").text(note);
  1659. $("#pupcc").text(upcc);
  1660. $("#pupcc2").text(upcc2);
  1661. $("#ppaid_by").text(paid_by);
  1662. $("#preference_no").text(reference_no);
  1663. $("#pdate").text(date);
  1664.  
  1665. if (table_data) {
  1666. product = JSON.parse(table_data);
  1667. }
  1668.  
  1669. if (product.length > 0) {
  1670. for (a = 0; a < product.length; a++) {
  1671.  
  1672. var getnewRow;
  1673. var product_id = product[a].product_id;
  1674. var desc = product[a].desc;
  1675. var quantity = product[a].quantity;
  1676. var price = product[a].price;
  1677. var discount = product[a].discount;
  1678. var tax = product[a].tax;
  1679. $.ajax({
  1680. async : false,
  1681. url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
  1682. type: "GET",
  1683. dataType: "JSON",
  1684. data: {
  1685. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1686. },
  1687. success: function (data) {
  1688. var id = data[0].product_id;
  1689. var code = data[0].code;
  1690. var name = data[0].name;
  1691. var itembyp = data[0].item_namebyp;
  1692. var unit = data[0].unit;
  1693.  
  1694. var newRow = $("<tr>");
  1695. var cols = "";
  1696. cols += "<td>" + counter + "</td>";
  1697. cols += "<td>" + code + "</td>";
  1698. cols += "<td>" + name + "</td>";
  1699. cols += "<td>" + desc + "</td>";
  1700. cols += "<td>" + quantity + "</td>";
  1701. cols += "<td>" + unit + "</td>";
  1702. cols += "<td>" + price + "</td>";
  1703. cols += "<td>" + (price * quantity) + "</td>";
  1704. cols += "<td>" + discount + "</td>";
  1705. cols += "<td>" + ((price * quantity) - discount) + "</td>";
  1706. cols += "<td>" + tax + "</td>";
  1707. cols += "<td>" + (((price * quantity) - discount) + tax) + "</td>";
  1708. cols += "</tr>";
  1709. newRow.append(cols);
  1710. getnewRow = newRow;
  1711. $("#view_table-body").append(newRow);
  1712. counter++;
  1713. }
  1714. });
  1715. }
  1716. }
  1717.  
  1718. if (tableadditional_data) {
  1719. additional = JSON.parse(tableadditional_data);
  1720. }
  1721.  
  1722. if (additional.length > 0) {
  1723. if (additional_description) {
  1724. var newRow = $("<tr>");
  1725. var cols = "";
  1726. cols += "<td colspan='12' align='left'>" + additional_description + "</td>";
  1727. cols += "</tr>";
  1728. newRow.append(cols);
  1729. getnewRow = newRow;
  1730. $("#view_table-body").append(newRow);
  1731. }
  1732.  
  1733. for (itemrec = 0; itemrec < additional.length; itemrec++) {
  1734.  
  1735. var additional_id = additional[itemrec].additional_id;
  1736. var desc = additional[itemrec].desc;
  1737. var quantity = additional[itemrec].quantity;
  1738. var price = additional[itemrec].price;
  1739. var discount = additional[itemrec].discount;
  1740. var tax = additional[itemrec].tax;
  1741. var flag = 0;
  1742. $.ajax({
  1743. async: false,
  1744. url: "<?php echo base_url('sales/getProduct') ?>/" + additional_id,
  1745. type: "GET",
  1746. dataType: "JSON",
  1747. data: {
  1748. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1749. },
  1750. success: function (data) {
  1751. var id = data[0].product_id;
  1752. var code = data[0].code;
  1753. var name = data[0].name;
  1754. var itembyp = data[0].item_namebyp;
  1755. var unit = data[0].unit;
  1756.  
  1757. var newRow = $("<tr>");
  1758. var cols = "";
  1759. cols += "<td>" + counter + "</td>";
  1760. cols += "<td>" + code + "</td>";
  1761. cols += "<td>" + name + "</td>";
  1762. cols += "<td>" + desc + "</td>";
  1763. cols += "<td>" + quantity + "</td>";
  1764. cols += "<td>" + unit + "</td>";
  1765. cols += "<td>" + price + "</td>";
  1766. cols += "<td>" + (price * quantity) + "</td>";
  1767. cols += "<td>" + discount + "</td>";
  1768. cols += "<td>" + ((price * quantity) - discount) + "</td>";
  1769. cols += "<td>" + tax + "</td>";
  1770. cols += "<td>" + (((price * quantity) - discount) + tax) + "</td>";
  1771. cols += "</tr>";
  1772. newRow.append(cols);
  1773. getnewRow = newRow;
  1774. $("#view_table-body").append(newRow);
  1775. counter++;
  1776. }
  1777. });
  1778. }
  1779. }
  1780.  
  1781.  
  1782. if (tableservice_data) {
  1783. service = JSON.parse(tableservice_data);
  1784. }
  1785.  
  1786. if (service.length > 0) {
  1787. if (service_description) {
  1788. var newRow = $("<tr>");
  1789. var cols = "";
  1790. cols += "<td colspan='12' align='left'>" + service_description + "</td>";
  1791. cols += "</tr>";
  1792. newRow.append(cols);
  1793. getnewRow = newRow;
  1794. $("#view_table-body").append(newRow);
  1795. }
  1796. for (b = 0; b < service.length; b++) {
  1797. var getnewRow;
  1798. var service_id = service[b].service_id;
  1799. var quantity = service[b].quantity;
  1800. var price = service[b].price;
  1801. var discount = service[b].discount;
  1802. var tax = service[b].tax;
  1803. var flag = 0;
  1804. $.ajax({
  1805. async : false,
  1806. url: "<?php echo base_url('sales/getService') ?>/" + service_id,
  1807. type: "GET",
  1808. dataType: "JSON",
  1809. data: {
  1810. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1811. },
  1812. success: function (data) {
  1813. var code = data[0].code;
  1814. var name = data[0].service_title;
  1815. var itembyp = data[0].item_namebyp;
  1816. var unit = data[0].unit;
  1817.  
  1818. var newRow = $("<tr>");
  1819. var cols = "";
  1820. cols += "<td>" + counter + "</td>";
  1821. cols += "<td>" + code + "</td>";
  1822. cols += "<td>" + name + "</td>";
  1823. cols += "<td>-</td>";
  1824. cols += "<td>" + quantity + "</td>";
  1825. cols += "<td>-</td>";
  1826. cols += "<td>" + price + "</td>";
  1827. cols += "<td>" + (price * quantity) + "</td>";
  1828. cols += "<td>" + discount + "</td>";
  1829. cols += "<td>" + ((price * quantity) - discount) + "</td>";
  1830. cols += "<td>" + tax + "</td>";
  1831. cols += "<td>" + (((price * quantity) - discount) + tax) + "</td>";
  1832. cols += "</tr>";
  1833. newRow.append(cols);
  1834. getnewRow = newRow;
  1835. $("#view_table-body").append(newRow);
  1836. counter++;
  1837. }
  1838. });
  1839. }
  1840. }
  1841.  
  1842.  
  1843. if (id_customer) {
  1844. $.ajax({
  1845. url : "<?php echo base_url('quotation/customer/') ?>" + id_customer,
  1846. type: "GET",
  1847. data: {
  1848. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1849. },
  1850. datatype: "JSON",
  1851. success: function (data)
  1852. {
  1853. customer = JSON.parse(data);
  1854. var customer_name = customer[0].customer_name;
  1855. var customer_address = customer[0].address;
  1856. var customer_jalan = customer[0].jalan;
  1857. var customer_city = customer[0].ciname;
  1858. var customer_country = customer[0].coname;
  1859. var customer_mobile = customer[0].mobile;
  1860. var customer_email = customer[0].email;
  1861. $("#pcostumer_name").text(customer_name);
  1862. $("#pcostumer_address").text(customer_address);
  1863. $("#pcostumer_jalan").text(customer_jalan);
  1864. $("#pcostumer_city").text(customer_city);
  1865. $("#pcostumer_country").text(customer_country);
  1866. $("#pcostumer_mobile").text(customer_mobile);
  1867. $("#pcostumer_email").text(customer_email);
  1868.  
  1869. },
  1870. error: function (xhr, status, error)
  1871. {
  1872. alert(error);
  1873. }
  1874.  
  1875. });
  1876. }
  1877.  
  1878. $.ajax({
  1879. url : "<?php echo base_url('quotation/company/') ?>",
  1880. type: "GET",
  1881. data: {
  1882. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1883. },
  1884. datatype: "JSON",
  1885. success: function (data)
  1886. {
  1887. customer = JSON.parse(data);
  1888. var company_name = customer[0].name;
  1889. var company_city = customer[0].city_name;
  1890. var company_country = customer[0].country_name;
  1891. var company_address = customer[0].billing_address;
  1892. var company_phone = customer[0].phone;
  1893. var company_email = customer[0].email;
  1894.  
  1895. $("#pcompany_name").text(company_name);
  1896. $("#pwarehouse_name").text(company_name);
  1897. $("#pbranch_address").text(company_address);
  1898. $("#pbranch_city").text(company_city);
  1899. $("#pcompany_phone").text(company_phone);
  1900. $("#company_email").text(company_email);
  1901.  
  1902. },
  1903. error: function (xhr, status, error)
  1904. {
  1905. alert(error);
  1906. }
  1907.  
  1908. });
  1909.  
  1910. var id = $('#kursdata').val();
  1911. $.ajax({
  1912. url: "<?php echo base_url('sales/getCurrencyAjax') ?>/" + id,
  1913. type: "GET",
  1914. data: {
  1915. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1916. },
  1917. datatype: "JSON",
  1918. success: function (d)
  1919. {
  1920. data = JSON.parse(d);
  1921. var nominalkurs = data[0].nominal;
  1922. $('#pctrade').text(nominalkurs);
  1923. },
  1924. error: function (xhr, status, error)
  1925. {
  1926. alert(error);
  1927. }
  1928.  
  1929. });
  1930.  
  1931. if (paid_by == 'advance') {
  1932. document.getElementById('termin-other').style.display = 'none';
  1933. document.getElementById('termin-bulan').style.display = 'none';
  1934. }
  1935. if (paid_by == 'termin') {
  1936. document.getElementById('termin-bulan').style.display = 'block';
  1937. document.getElementById('termin-other').style.display = 'none';
  1938.  
  1939. var termins =$('#terminnumber').val();
  1940.  
  1941.  
  1942.  
  1943. for (var i = 1, length = termins; i <= termins; i++)
  1944. {
  1945. var nominal = $('#terminvalue'+i).val();
  1946. var ket = $('#terminket'+i).val();
  1947. var newRow = $("<tr>");
  1948. var cols = "";
  1949. cols += "<td>" + i + "</td>";
  1950. cols += "<td>" + ((nominal * pbalance)/100) + "</td>";
  1951. cols += "<td>" + nominal + "</td>";
  1952. cols += "<td>" + ket + "</td>";
  1953. cols += "</tr>";
  1954. newRow.append(cols);
  1955. getnewRow = newRow;
  1956. $("#table-termin-body").append(newRow);
  1957. }
  1958.  
  1959. }
  1960. if (paid_by == 'others') {
  1961. document.getElementById('termin-bulan').style.display = 'none';
  1962. document.getElementById('termin-other').style.display = 'block';
  1963. $('#termin-other-value').text(othervalue);
  1964. }
  1965. });
  1966.  
  1967. $("#submit").click(function (event) {
  1968. var name_regex = /^[a-zA-Z]+$/;
  1969. var sname_regex = /^[a-zA-Z0-9]+$/;
  1970. var num_regex = /^[0-9]+$/;
  1971. var date_regex = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/;
  1972. var date = $('#date').val();
  1973. var reference_no = $('#reference_no').val();
  1974. var biller = $('#biller').val();
  1975. var product = $('#product').val();
  1976. var customer = $('#customer').val();
  1977. var discount = $('#discount').val();
  1978. var internal_note = $('#internal_note').val();
  1979. var grand_total = $('#grand_total').val();
  1980.  
  1981. if (customer == "") {
  1982. $("#err_customer").text("Please Enter Customer");
  1983. $('#customer').focus();
  1984. return false;
  1985. } else {
  1986. $("#err_customer").text("");
  1987. }
  1988. //customer code validation complite.
  1989.  
  1990. if (grand_total == "" || grand_total == null || grand_total == 0.00) {
  1991. ;
  1992. $("#err_product").text("Please Select Product");
  1993. $('#product').focus();
  1994. return false;
  1995. }
  1996.  
  1997. });
  1998.  
  1999. $("#customer").change(function (event) {
  2000. var customer = $('#customer').val();
  2001. if (customer == "") {
  2002. $("#err_customer").text("Please Enter Customer");
  2003. $('#customer').focus();
  2004. return false;
  2005. } else {
  2006. $("#err_customer").text("");
  2007. }
  2008. });
  2009.  
  2010. $("#discount").change(function (event) {
  2011. var discount = $('#discount').val();
  2012. if (discount == "") {
  2013. $("#err_discount").text("Please Enter Discount");
  2014. $('#discount').focus();
  2015. return false;
  2016. } else {
  2017. $("#err_discount").text("");
  2018. }
  2019. if (discount != "") {
  2020. $.ajax({
  2021. url: "<?php echo base_url('sales/getDiscountAjax') ?>/" + discount,
  2022. type: "get",
  2023. dataType: "json",
  2024. success: function (data) {
  2025. var type = data[0].discount_type;
  2026. var value = data[0].discount_value;
  2027. var amount = parseInt(data[0].amount);
  2028. var grand_total = $('#grand_total').val();
  2029. $('#discount_type').val(type);
  2030. $('#total_discount').val(value);
  2031. $('#discount_amount').val(amount);
  2032. if (grand_total > 0 && grand_total != null) {
  2033. if (type == "Fixed") {
  2034. var t = grand_total - value;
  2035. if (grand_total < amount) {
  2036. var t = grand_total;
  2037. }
  2038. $('#lasttotal').text(t);
  2039. $('#last_total').val(t);
  2040. $('#totaldiscount').text(value);
  2041. $('#total_discount').val(value);
  2042. $('#discount_type').val(type);
  2043. $('#discount_amount').val(amount);
  2044. $('#showdiscount').text(" (Rs " + value + ")");
  2045. } else {
  2046. var total = (grand_total * value) / 100;
  2047. var t = grand_total - total;
  2048. $('#totaldiscount').text(total);
  2049. $('#total_discount').val(value);
  2050. $('#discount_type').val('');
  2051. $('#discount_amount').val('');
  2052. $('#lasttotal').text(t);
  2053. $('#last_total').val(t);
  2054. $('#showdiscount').text(" (" + value + "%)");
  2055. }
  2056. }
  2057. }
  2058. });
  2059. }
  2060. });
  2061.  
  2062. $("#product").blur(function (event) {
  2063. var sname_regex = /^[a-zA-Z0-9]+$/;
  2064. var product = $('#product').val();
  2065. if (product == null || product == "") {
  2066. $("#err_product").text("Please Enter Product Code/Name");
  2067. $('#product').focus();
  2068. return false;
  2069. } else {
  2070. $("#err_product").text("");
  2071. }
  2072. if (!product.match(sname_regex)) {
  2073. $('#err_product').text(" Please Enter Valid Product Code/Name ");
  2074. $('#product').focus();
  2075. return false;
  2076. } else {
  2077. $("#err_product").text("");
  2078. }
  2079. });
  2080. });
  2081. </script>
  2082. <script type="text/javascript">
  2083. var hitung = 1;
  2084. var getfromaddFields = 123;
  2085.  
  2086. function isNumber(evt) {
  2087. evt = (evt) ? evt : window.event;
  2088. var charCode = (evt.which) ? evt.which : evt.keyCode;
  2089. if (charCode > 31 && (charCode < 48 || charCode > 57)) {
  2090. return true;
  2091. }
  2092. return true;
  2093. }
  2094.  
  2095. function isNumber_max_100(evt) {
  2096. evt = (evt) ? evt : window.event;
  2097. var charCode = (evt.which) ? evt.which : evt.keyCode;
  2098. if (charCode > 31 && (charCode < 48 || charCode > 57)) {
  2099. return false;
  2100. }
  2101. getvarhit = hitung;
  2102. get_nax_100(getvarhit);
  2103. return true;
  2104. }
  2105.  
  2106. function get_nax_100(getvarhitloop) {
  2107. if (getvarhitloop == 1) {
  2108. $(".getterminvalue").on("change paste", function () {
  2109.  
  2110. hitjumlah = 0;
  2111. for (i = 0; i < getfromaddFields; i++) {
  2112. new_id = "terminvalue" + (i + 1);
  2113. number = document.getElementById(new_id).value;
  2114. if (number) {
  2115. hitjumlah = parseInt(hitjumlah) + parseInt(number);
  2116. }
  2117. }
  2118. if (hitjumlah > 100) {
  2119. alert('Termin melebihi 100')
  2120. }
  2121. });
  2122. }
  2123. hitung = 2;
  2124. }
  2125.  
  2126. jQuery.calculateDiscount = function calculateDiscount(row, data = 0) {
  2127. var discount;
  2128. if (data == 0) {
  2129. discount = +row.find('#discount_value').val();
  2130. } else {
  2131. discount = data;
  2132. }
  2133.  
  2134. var sales_total = +row.find('input[name^="linetotal"]').val();
  2135. var total_discount = sales_total * discount / 100;
  2136. row.find('#product_total').val(sales_total - total_discount);
  2137. row.find('#hidden_discount').val(total_discount);
  2138. var key = +row.find('input[name^="id"]').val();
  2139. product_data[key].discount = total_discount;
  2140. product_data[key].discount_value = +row.find('#discount_value').val();
  2141. product_data[key].discount_id = +row.find('#item_discount').val();
  2142. var table_data = JSON.stringify(product_data);
  2143. $('#table_data').val(table_data);
  2144. }
  2145.  
  2146. jQuery.calculateDiscountAdditional = function calculateDiscountAdditional(row, data = 0) {
  2147. var discount;
  2148.  
  2149. if (data == 0) {
  2150. discount = +row.find('#discount_value').val();
  2151. } else {
  2152. discount = data;
  2153. }
  2154.  
  2155. var sales_total = +row.find('input[name^="linetotal"]').val();
  2156. var total_discount = sales_total * discount / 100;
  2157.  
  2158. row.find('#product_total').val(sales_total - total_discount);
  2159. row.find('#hidden_discount').val(total_discount);
  2160.  
  2161. var key = +row.find('input[name^="id"]').val();
  2162. additional_data[key].discount = total_discount;
  2163. additional_data[key].discount_value = +row.find('#discount_value').val();
  2164. additional_data[key].discount_id = +row.find('#item_discount').val();
  2165.  
  2166. var table_data = JSON.stringify(additional_data);
  2167. $('#tableadditional_data').val(table_data);
  2168. }
  2169.  
  2170. jQuery.calculateDiscountService = function calculateDiscountService(row, data = 0)
  2171. {
  2172. var discount;
  2173.  
  2174. if (data == 0) {
  2175. discount = +row.find('#discountservice_value').val();
  2176. } else {
  2177. discount = data;
  2178. }
  2179.  
  2180. var sales_total = +row.find('input[name^="linetotalservice"]').val();
  2181. var total_discount = sales_total * discount / 100;
  2182.  
  2183. row.find('#service_total').val(sales_total - total_discount);
  2184. row.find('#hidden_discountservice').val(total_discount);
  2185.  
  2186. var key = +row.find('input[name^="idservice"]').val();
  2187. service_data[key].discount = total_discount;
  2188. service_data[key].discount_value = +row.find('#discountservice_value').val();
  2189. service_data[key].discount_id = +row.find('#item_discountservice').val();
  2190.  
  2191. var table_data = JSON.stringify(service_data);
  2192. $('#tableservice_data').val(table_data);
  2193.  
  2194. }
  2195.  
  2196. jQuery.calculateGrandTotal = function calculateGrandTotal(discountdatatext) {
  2197.  
  2198. var totalValue = 0;
  2199. var DiscountProduct = 0;
  2200. var grandTax = 0;
  2201. var grandTotal = 0;
  2202. var grandDiskon = 0;
  2203. var shippingCharge = 0;
  2204. $("table.service_table").find('input[name^="linetotalservice"]').each(function () {
  2205. totalValue += +$(this).val();
  2206. });
  2207. $("table.service_table").find('input[name^="hidden_discountservice"]').each(function () {
  2208. DiscountProduct += +$(this).val();
  2209. });
  2210.  
  2211. $("table.servicetable").find('input[name^="service_total"]').each(function () {
  2212. grandTotal += +$(this).val();
  2213. });
  2214. $("table.product_table").find('input[name^="linetotal"]').each(function () {
  2215. totalValue += +$(this).val();
  2216. });
  2217. $("table.product_table").find('input[name^="hidden_discount"]').each(function () {
  2218. DiscountProduct += +$(this).val();
  2219. });
  2220.  
  2221. $("table.product_table").find('input[name^="product_total"]').each(function () {
  2222. grandTotal += +$(this).val();
  2223. });
  2224. $("table.summary_table").find('input[name^="shipping_charge"]').each(function () {
  2225. shippingCharge = +$(this).val();
  2226. });
  2227.  
  2228. $("table.additional_table").find('input[name^="linetotal"]').each(function () {
  2229. totalValue += +$(this).val();
  2230. });
  2231. $("table.additional_table").find('input[name^="hidden_discount"]').each(function () {
  2232. DiscountProduct += +$(this).val();
  2233. });
  2234.  
  2235. $("table.additional_table").find('input[name^="product_total"]').each(function () {
  2236. grandTotal += +$(this).val();
  2237. });
  2238.  
  2239.  
  2240. var totaldiskon = 0;
  2241. grandDiskon = DiscountProduct;
  2242. var diskonval = 0;
  2243. var diskonval2 = 0;
  2244. var diskonpersen = 0;
  2245. diskonpersen = +$('#DiscountPersen').val();
  2246. diskonval2 = totalValue - DiscountProduct;
  2247. diskonval = (diskonpersen / 100) * diskonval2;
  2248. grandDiskon += diskonval;
  2249. grandDiskon += +$('#DiscountFix').val();
  2250. $('Span#totalDiscount').text(grandDiskon);
  2251. totaldiskon = grandDiskon;
  2252. grandTotal = grandTotal - totaldiskon + shippingCharge;
  2253.  
  2254. var taxx = $('#taxx').val();
  2255. grandTax = ((totalValue - totaldiskon) + shippingCharge) * (taxx / 100);
  2256. grandTotal = totalValue - totaldiskon + shippingCharge + grandTax;
  2257.  
  2258. var id = $('#kursdata').val();
  2259. $.ajax({
  2260. url: "<?php echo base_url('sales/getCurrencyAjax') ?>/" + id,
  2261. type: "GET",
  2262. data: {
  2263. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2264. },
  2265. datatype: "JSON",
  2266. success: function (d)
  2267. {
  2268. //alert(d);
  2269. data = JSON.parse(d);
  2270. var symbolkurs = data[0].symbol;
  2271. var nominalkurs = data[0].nominal;
  2272. var grandval = $('#grand_total').val();
  2273. var totalkurs = (grandval * nominalkurs);
  2274.  
  2275. $('#kurs_symbol').text(symbolkurs);
  2276. $('#kurs_symbol1').text(symbolkurs);
  2277. $('#kurs_symbol2').text(symbolkurs);
  2278. $('#kurs_symbol3').text(symbolkurs);
  2279. $('#kurs_symbol4').text(symbolkurs);
  2280. $('#kurs_symbol5').text(symbolkurs);
  2281. $('#kurs_symbol6').text(symbolkurs);
  2282. $('#kurs_symbol7').text(symbolkurs);
  2283. $('#grandCurrency').text("Rp. " + totalkurs.toFixed(2));
  2284. $('#grandCurrency').val("Rp. " + totalkurs.toFixed(2));
  2285. $('#grand_currency').val(totalkurs.toFixed(2));
  2286. },
  2287. error: function (xhr, status, error)
  2288. {
  2289. alert(error);
  2290. }
  2291.  
  2292. });
  2293. $('#totalValue').text(totalValue.toFixed(2));
  2294. $('#total_value').val(totalValue.toFixed(2));
  2295. $('#DiscountProduct').text(DiscountProduct.toFixed(2));
  2296. $('#total_discount').val(totaldiskon);
  2297. $('#totalTax').text(grandTax.toFixed(2));
  2298. $('#total_tax').val(grandTax.toFixed(2));
  2299. $('#grandTotal').text(grandTotal.toFixed(2));
  2300. $('#grand_total').val(grandTotal.toFixed(2));
  2301. }
  2302. </script>
  2303. <script type="text/javascript">
  2304.  
  2305. $('#customer').change(function () {
  2306. var customer_id = $(this).val();
  2307. $.ajax({
  2308. url: "<?php echo base_url('sales/getCustomerData') ?>/" + customer_id,
  2309. type: "GET",
  2310. dataType: "JSON",
  2311. data: {
  2312. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2313. },
  2314. success: function (data) {
  2315.  
  2316. $('#company_id').text('');
  2317. $('#company_name').text('');
  2318. $('#customer_name').text('');
  2319. $('#mobilephone').text('');
  2320. $('#email').text('');
  2321. $('#npwp').text('');
  2322. $('#alamat_npwp').text('');
  2323. $('#npwp').val(data['data'][0].gstid);
  2324. $('#alamat_npwp').val(data['data'][0].cf2);
  2325. $('#company_id').val(data['data'][0].cf1);
  2326. $('#company_name').val(data['data'][0].company_name);
  2327. $('#po_cust').val(data['data'][0].company_name);
  2328. $('#customer_name').val(data['data'][0].customer_name);
  2329. $('#mobilephone').val(data['data'][0].mobile);
  2330. $('#email').val(data['data'][0].email);
  2331.  
  2332. $('#customer_address')
  2333. .find('option')
  2334. .remove()
  2335. .end()
  2336. .append('<option value="">Select Shipping</option>')
  2337. ;
  2338.  
  2339. $('#customer_addressa')
  2340. .find('option')
  2341. .remove()
  2342. .end()
  2343. .append('<option value="">Select Billing</option>')
  2344. ;
  2345.  
  2346. $('#country').val('');
  2347. $('#state').val('');
  2348. $('#city').val('');
  2349.  
  2350. if (typeof data['address'][0] != 'undefined') {
  2351. var cid = data['address'][0].customer_id;
  2352. for (a = 0; a < data['address'].length; a++) {
  2353. if (data['address'][a].type == 0) {
  2354. $('#customer_address').append('<option value="' + data['address'][a].id + '">' + data['address'][a].address + '</option>');
  2355. }
  2356. }
  2357. } else {
  2358. var cid = "";
  2359. }
  2360.  
  2361. if (typeof data['address'][0] != 'undefined') {
  2362. var cid = data['address'][0].customer_id;
  2363. for (a = 0; a < data['address'].length; a++) {
  2364. if (data['address'][a].type == 1) {
  2365. $('#customer_addressa').append('<option value="' + data['address'][a].id + '">' + data['address'][a].address + '</option>');
  2366. }
  2367. }
  2368. } else {
  2369. var cid = "";
  2370. }
  2371. }
  2372. });
  2373.  
  2374. $("#single-input").empty().trigger("change");
  2375. number = '';
  2376. $('#single-input')
  2377. .find('option')
  2378. .remove()
  2379. .end()
  2380. .append('<option value="">Select Quotation</option>')
  2381. ;
  2382. $.ajax({
  2383. url: "<?php echo base_url('sales/getRecordAjax') ?>/" + customer_id,
  2384. type: "GET",
  2385. dataType: "JSON",
  2386. data: {
  2387. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2388. },
  2389. success: function (data) {
  2390. for (a = 0; a < data['data'].length; a++) {
  2391. if (data['data'][a].reference_no2 != null) {
  2392. number = data['data'][a].reference_no2;
  2393. } else {
  2394. number = data['data'][a].reference_no;
  2395. }
  2396. $('#single-input').append('<option value="' + data['data'][a].quotation_id + '">' + number + '</option>');
  2397. }
  2398. },
  2399. error: function (jqxhr, status, exception) {
  2400. alert('Exception:', exception);
  2401. }
  2402. });
  2403.  
  2404. $("#multiple-input").empty().trigger("change");
  2405. number = '';
  2406. $('#multiple-input')
  2407. .find('option')
  2408. .remove()
  2409. .end()
  2410. .append('<option value="">Select Quotation</option>')
  2411. ;
  2412. $.ajax({
  2413. async: false,
  2414. url: "<?php echo base_url('sales/getRecordAjax') ?>/" + customer_id,
  2415. type: "GET",
  2416. dataType: "JSON",
  2417. data: {
  2418. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2419. },
  2420. success: function (data) {
  2421. for (a = 0; a < data['data'].length; a++) {
  2422. if (data['data'][a].reference_no2 != null) {
  2423. number = data['data'][a].reference_no2;
  2424. } else {
  2425. number = data['data'][a].reference_no;
  2426. }
  2427. $('#multiple-input').append('<option value="' + data['data'][a].quotation_id + '">' + number + '</option>');
  2428. $("#multiple-input").trigger("change");
  2429. }
  2430. },
  2431. error: function (jqxhr, status, exception) {
  2432. alert('Exception:', exception);
  2433. }
  2434. });
  2435.  
  2436. });
  2437.  
  2438. $('#selectmultiple').change(function (){
  2439. var select = $(this).val();
  2440. if (select == 1) {
  2441. $('.single').show();
  2442. $('#single-input').attr('name', 'reference_no');
  2443. $('.multiple').hide();
  2444. $('#multiple-input').removeAttr('name','');
  2445. document.getElementById('preference_no').style.display = 'none';
  2446. } else {
  2447. $('.single').hide();
  2448. $('#single-input').attr('name', 'reference_no');
  2449. $('.multiple').show();
  2450. $('#multiple-input').removeAttr('name','');
  2451. document.getElementById('preference_no').style.display = 'none';
  2452. }
  2453. });
  2454.  
  2455. $('#multiple-input').change(function () {
  2456. var single = $('#selectmultiple').val();
  2457. if (single == 1) {
  2458. var refno = $(this).val();
  2459. if (refno != null) {
  2460. $.ajax({
  2461. url: "<?php echo base_url('quotation/getDataQuotation') ?>/" + refno,
  2462. type: "GET",
  2463. dataType: "JSON",
  2464. data: refno,
  2465. success: function (data) {
  2466. $('#DiscountPersen').val(parseInt(data[0].diskonpersen));
  2467. $('#DiscountFix').val(parseInt(data[0].diskon));
  2468. $('#shipping_charge').val(parseInt(data[0].shipping_charge));
  2469. $('#note').val(data[0].note);
  2470. $('#internal_note').val(data[0].internal_note);
  2471. $('#term_and_condition').val(data[0].term_and_condition);
  2472. $('#upcc').val(data[0].upcc);
  2473. $('#upcc2').val(data[0].upcc2);
  2474. $('#tax option[value='+ data[0].attn +']').attr('selected','selected');
  2475. $('#terminnumber option[value='+ data['termin'].length +']').attr('selected','selected');
  2476.  
  2477. $('input[name=paymenterms][value='+ data[0].paid_by +']').prop('checked', true).click();
  2478. if ('termin' == data[0].paid_by) {
  2479. var e = document.getElementById("terminnumber");
  2480. var number = e.options[e.selectedIndex].value;
  2481. getfromaddFields = number;
  2482. var container = document.getElementById("termincontainer");
  2483. while (container.hasChildNodes())
  2484. {
  2485. container.removeChild(container.lastChild);
  2486. }
  2487.  
  2488.  
  2489. var container = container.appendChild(document.createElement("table"));
  2490. container.className = "table table-bordered";
  2491. var container = container.appendChild(document.createElement("tbody"));
  2492. var artermin = data['termin'];
  2493. for (i = 0; i < number; i++)
  2494. {
  2495. var containertr = container.appendChild(document.createElement("tr"));
  2496. var containertd = containertr.appendChild(document.createElement("td"));
  2497. z = document.createElement('span');
  2498. z.innerHTML = "Termin Ke % " + (i + 1) + " :";
  2499. z.className = "text-danger";
  2500. containertd.appendChild(z);
  2501. var input = document.createElement("input");
  2502. input.type = "number";
  2503. input.name = "terminvalue[" + (i + 1) + "]";
  2504. input.id = "terminvalue[" + (i + 1)+"]";
  2505. input.className = "getterminvalue";
  2506. input.value = artermin[i].persen;
  2507. input.min = 1;
  2508. input.max = 100;
  2509. input.maxlength = "2";
  2510. input.onkeypress = isNumber_max_100;
  2511. var containertd = containertr.appendChild(document.createElement("td"));
  2512. containertd.appendChild(input);
  2513. z = document.createElement('span');
  2514. z.className = "text-primary";
  2515. z.innerHTML = ' Ket: ';
  2516. var containertd = containertr.appendChild(document.createElement("td"));
  2517. containertd.appendChild(z);
  2518. var input2 = document.createElement("input");
  2519. input2.type = "text";
  2520. input2.name = "terminket[" + (i + 1) + "]";
  2521. input2.id = "terminket[" + (i + 1)+"]";
  2522. input2.className = "getterminket";
  2523. input2.value = artermin[i].keterangan;
  2524. var containertd = containertr.appendChild(document.createElement("td"));
  2525. containertd.appendChild(input2);
  2526. }
  2527. }
  2528. },
  2529. error: function (jqxhr, status, exception) {
  2530. }
  2531. });
  2532. }
  2533. } else {
  2534. var refno = $(this).val().join('_');
  2535. }
  2536. $.ajax({
  2537. url: "<?php echo base_url('quotation/getQuotationItemsAjax') ?>/" + refno,
  2538. type: "GET",
  2539. dataType: "JSON",
  2540. data: refno,
  2541. success: function (data) {
  2542. product_data = Array();
  2543. $.generateItem(data);
  2544. },
  2545. error: function (jqxhr, status, exception) {
  2546. }
  2547. });
  2548. $.ajax({
  2549. url: "<?php echo base_url('quotation/getQuotationAdditionalAjax') ?>/" + refno,
  2550. type: "GET",
  2551. dataType: "JSON",
  2552. data: refno,
  2553. success: function (data) {
  2554. additional_data = Array();
  2555. $.generateAdditionalItem(data);
  2556. },
  2557. error: function (jqxhr, status, exception) {
  2558. }
  2559. });
  2560. $.ajax({
  2561. url: "<?php echo base_url('quotation/getQuotationServiceItemsAjax') ?>/" + refno,
  2562. type: "GET",
  2563. dataType: "JSON",
  2564. data: refno,
  2565. success: function (data) {
  2566. service_data = Array();
  2567. $.generateServiceItem(data);
  2568. },
  2569. error: function (jqxhr, status, exception) {
  2570. }
  2571. });
  2572. });
  2573.  
  2574. $('#single-input').change(function () {
  2575. var single = $('#selectmultiple').val();
  2576. if (single == 1) {
  2577. var refno = $(this).val();
  2578. if (refno != null) {
  2579. $.ajax({
  2580. url: "<?php echo base_url('quotation/getDataQuotation') ?>/" + refno,
  2581. type: "GET",
  2582. dataType: "JSON",
  2583. data: refno,
  2584. success: function (data) {
  2585. $('#DiscountPersen').val(parseInt(data[0].diskonpersen));
  2586. $('#DiscountFix').val(parseInt(data[0].diskon));
  2587. $('#shipping_charge').val(parseInt(data[0].shipping_charge));
  2588. $('#note').val(data[0].note);
  2589. $('#internal_note').val(data[0].internal_note);
  2590. $('#term_and_condition').val(data[0].term_and_condition);
  2591. $('#upcc').val(data[0].upcc);
  2592. $('#upcc2').val(data[0].upcc2);
  2593. $('#tax option[value='+ data[0].attn +']').attr('selected','selected');
  2594. $('#terminnumber option[value='+ data['termin'].length +']').attr('selected','selected');
  2595.  
  2596. $('input[name=paymenterms][value='+ data[0].paid_by +']').prop('checked', true).click();
  2597. if ('termin' == data[0].paid_by) {
  2598. var e = document.getElementById("terminnumber");
  2599. var number = e.options[e.selectedIndex].value;
  2600. getfromaddFields = number;
  2601. var container = document.getElementById("termincontainer");
  2602. while (container.hasChildNodes())
  2603. {
  2604. container.removeChild(container.lastChild);
  2605. }
  2606.  
  2607.  
  2608. var container = container.appendChild(document.createElement("table"));
  2609. container.className = "table table-bordered";
  2610. var container = container.appendChild(document.createElement("tbody"));
  2611. var artermin = data['termin'];
  2612. for (i = 0; i < number; i++)
  2613. {
  2614. var containertr = container.appendChild(document.createElement("tr"));
  2615. var containertd = containertr.appendChild(document.createElement("td"));
  2616. z = document.createElement('span');
  2617. z.innerHTML = "Termin Ke % " + (i + 1) + " :";
  2618. z.className = "text-danger";
  2619. containertd.appendChild(z);
  2620. var input = document.createElement("input");
  2621. input.type = "number";
  2622. input.name = "terminvalue[" + (i + 1) + "]";
  2623. input.id = "terminvalue[" + (i + 1)+"]";
  2624. input.className = "getterminvalue";
  2625. input.value = artermin[i].persen;
  2626. input.min = 1;
  2627. input.max = 100;
  2628. input.maxlength = "2";
  2629. input.onkeypress = isNumber_max_100;
  2630. var containertd = containertr.appendChild(document.createElement("td"));
  2631. containertd.appendChild(input);
  2632. z = document.createElement('span');
  2633. z.className = "text-primary";
  2634. z.innerHTML = ' Ket: ';
  2635. var containertd = containertr.appendChild(document.createElement("td"));
  2636. containertd.appendChild(z);
  2637. var input2 = document.createElement("input");
  2638. input2.type = "text";
  2639. input2.name = "terminket[" + (i + 1) + "]";
  2640. input2.id = "terminket[" + (i + 1)+"]";
  2641. input2.className = "getterminket";
  2642. input2.value = artermin[i].keterangan;
  2643. var containertd = containertr.appendChild(document.createElement("td"));
  2644. containertd.appendChild(input2);
  2645. }
  2646. }
  2647. },
  2648. error: function (jqxhr, status, exception) {
  2649. }
  2650. });
  2651. }
  2652. } else {
  2653. var refno = $(this).val().join('_');
  2654. }
  2655. $.ajax({
  2656. url: "<?php echo base_url('quotation/getQuotationItemsAjax') ?>/" + refno,
  2657. type: "GET",
  2658. dataType: "JSON",
  2659. data: refno,
  2660. success: function (data) {
  2661. product_data = Array();
  2662. $.generateItem(data);
  2663. },
  2664. error: function (jqxhr, status, exception) {
  2665. }
  2666. });
  2667. $.ajax({
  2668. url: "<?php echo base_url('quotation/getQuotationAdditionalAjax') ?>/" + refno,
  2669. type: "GET",
  2670. dataType: "JSON",
  2671. data: refno,
  2672. success: function (data) {
  2673. additional_data = Array();
  2674. $.generateAdditionalItem(data);
  2675. },
  2676. error: function (jqxhr, status, exception) {
  2677. }
  2678. });
  2679. $.ajax({
  2680. url: "<?php echo base_url('quotation/getQuotationServiceItemsAjax') ?>/" + refno,
  2681. type: "GET",
  2682. dataType: "JSON",
  2683. data: refno,
  2684. success: function (data) {
  2685. service_data = Array();
  2686. $.generateServiceItem(data);
  2687. },
  2688. error: function (jqxhr, status, exception) {
  2689. }
  2690. });
  2691. });
  2692.  
  2693. jQuery.generateItem = function generateItem(items) {
  2694.  
  2695. var counter = 1;
  2696. var aritem = items;
  2697. for (itemrec = 0; itemrec < aritem.length; itemrec++) {
  2698. (function (counter) {
  2699. var getnewRow;
  2700. var quotationid = aritem[itemrec].id;
  2701. var itemquantity = aritem[itemrec].quantity;
  2702. var itemprice = aritem[itemrec].qprice;
  2703. var itemdiscountid = aritem[itemrec].discount_id;
  2704. var itemdiscountid = aritem[itemrec].discount_id;
  2705. var itemdiscountvalue = aritem[itemrec].discount_value;
  2706. var itemdiscount = aritem[itemrec].discount;
  2707. var itemgross_total = aritem[itemrec].gross_total;
  2708. var product_id = aritem[itemrec].product_id;
  2709. var itemdesc = aritem[itemrec].serial_no;
  2710.  
  2711. if (product_id == null) {
  2712. alert('Product Tidak Terdaftar Lagi');
  2713. } else {
  2714. var flag = 0;
  2715. $('#err_product').text('');
  2716. $.ajax({
  2717. url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
  2718. type: "GET",
  2719. dataType: "JSON",
  2720. data: {
  2721. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2722. },
  2723. success: function (data) {
  2724. $("table.product_table").find('input[name^="product_id"]').each(function () {
  2725. // if (data[0].product_id == +$(this).val()) {
  2726. // flag = 1;
  2727. // }
  2728. });
  2729. if (flag == 0) {
  2730. var id = data[0].product_id;
  2731. var price = itemprice;
  2732. var code = data[0].code;
  2733. var name = data[0].name;
  2734. var itembyp = data[0].item_namebyp;
  2735. var product = {"product_id": id,
  2736. "price": price, "desc": itemdesc
  2737. };
  2738. product_data[yi] = product;
  2739. length = product_data.length - 1;
  2740.  
  2741. var select_discount = "";
  2742. select_discount += '<div class="form-group">';
  2743. select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
  2744. select_discount += '<option value="">Select</option>';
  2745. var selected = '';
  2746. for (a = 0; a < data['discount'].length; a++) {
  2747. if (data['discount'][a].discount_id == itemdiscountid) {
  2748. selected = 'selected ';
  2749. } else {
  2750. selected = '';
  2751. }
  2752. select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  2753. }
  2754. select_discount += '</select></div>';
  2755.  
  2756. var newRow = $("<tr id='tr" + yi + "'>");
  2757. var cols = "";
  2758. 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>";
  2759. cols += "<td>" + code + "</td>";
  2760. cols += "<td>"
  2761. + "<input type='hidden' value='" + data[0].code + "' name='nameProduct" + counter + "' id='nameProduct" + counter + "'>"
  2762. + "<input type='hidden' value='" + data[0].product_id + "' name='idProduct" + counter + "' id='idProduct" + counter + "'>"
  2763. + name + "</td>";
  2764. cols += "<td>" + itembyp + "</td>";
  2765. cols += "<td><input type='text' class='form-control text-center' value='" + itemdesc + "' name='description" + counter + "' id='description" + counter + "' ></td>";
  2766. 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>";
  2767. cols += "<td id='column-color'>" + data[0].quantity + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'></td>";
  2768. cols += "<td>" + data[0].unit + "</td>";
  2769.  
  2770. cols += "<td align='right'><span><input type='text' class='form-control text-right' value='" + price + "' name='price" + counter + "' id='price" + counter + "'></span></td>";
  2771.  
  2772. 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>";
  2773.  
  2774. 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>';
  2775.  
  2776. cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
  2777. cols += "</tr>";
  2778.  
  2779. newRow.append(cols);
  2780. getnewRow = newRow;
  2781. $("table.product_table").append(newRow);
  2782. calculateRow($('tr#tr' + yi));
  2783. $.calculateDiscount($('tr#tr' + yi));
  2784. $.calculateGrandTotal();
  2785. counter++;
  2786. var table_data = JSON.stringify(product_data);
  2787. $('#table_data').val(table_data);
  2788. yi++;
  2789. } else {
  2790. $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  2791. }
  2792. }
  2793. });
  2794. }
  2795. })(itemrec);
  2796. }
  2797.  
  2798.  
  2799.  
  2800. function calculateRow(row) {
  2801.  
  2802. var key = +row.find('input[name^="id"]').val();
  2803. var price = +row.find('input[name^="price"]').val();
  2804. var qty = +row.find('input[name^="qty"]').val();
  2805. var desc = row.find('input[name^="description"]').val();
  2806.  
  2807. row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
  2808.  
  2809. var availableqty = +row.find('input[name^="available_quantity"]').val();
  2810. var bookqty = qty - availableqty;
  2811. if (bookqty > 0) {
  2812. row.find('td[id^="column-color"]').css({'background-color': 'red'});
  2813. }
  2814.  
  2815. product_data[key].quantity = qty;
  2816. product_data[key].price = price;
  2817. product_data[key].desc = desc;
  2818. product_data[key].total = (price * qty).toFixed(2);
  2819. var table_data = JSON.stringify(product_data);
  2820. $('#table_data').val(table_data);
  2821. }
  2822.  
  2823. }
  2824.  
  2825. jQuery.generateAdditionalItem = function generateAdditionalItem(additional) {
  2826.  
  2827. var counter = 1;
  2828. var aritem = additional;
  2829. for (itemrec = 0; itemrec < aritem.length; itemrec++) {
  2830. (function (counter) {
  2831. var getnewRow;
  2832. var quotationid = aritem[itemrec].id;
  2833. var itemquantity = aritem[itemrec].quantity;
  2834. var itemprice = aritem[itemrec].qprice;
  2835. var itemdiscountid = aritem[itemrec].discount_id;
  2836. var itemdiscountid = aritem[itemrec].discount_id;
  2837. var itemdiscountvalue = aritem[itemrec].discount_value;
  2838. var itemdiscount = aritem[itemrec].discount;
  2839. var itemgross_total = aritem[itemrec].gross_total;
  2840. var product_id = aritem[itemrec].product_id;
  2841. var itemdesc = aritem[itemrec].desc;
  2842.  
  2843. if (product_id == null) {
  2844. alert('Additional Product Tidak Terdaftar Lagi');
  2845. } else {
  2846.  
  2847. var flag = 0;
  2848. $('#err_product').text('');
  2849. $.ajax({
  2850. url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
  2851. type: "GET",
  2852. dataType: "JSON",
  2853. data: {
  2854. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2855. },
  2856. success: function (data) {
  2857. $("table.additional_table").find('input[name^="additional_id"]').each(function () {
  2858. // if (data[0].product_id == +$(this).val()) {
  2859. // flag = 1;
  2860. // }
  2861. });
  2862. if (flag == 0) {
  2863. var id = data[0].product_id;
  2864. var price = itemprice;
  2865. var code = data[0].code;
  2866. var name = data[0].name;
  2867. var itembyp = data[0].item_namebyp;
  2868. var product = {"additional_id": id,
  2869. "price": price, "desc": itemdesc
  2870. };
  2871. additional_data[j] = product;
  2872. length = additional_data.length - 1;
  2873.  
  2874. var select_discount = "";
  2875. select_discount += '<div class="form-group">';
  2876. select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
  2877. select_discount += '<option value="">Select</option>';
  2878. var selected = '';
  2879. for (a = 0; a < data['discount'].length; a++) {
  2880. if (data['discount'][a].discount_id == itemdiscountid) {
  2881. selected = 'selected ';
  2882. } else {
  2883. selected = '';
  2884. }
  2885. select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  2886. }
  2887. select_discount += '</select></div>';
  2888.  
  2889. var newRow = $("<tr id='tra" + j + "'>");
  2890. var cols = "";
  2891. 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>";
  2892. cols += "<td>" + code + "</td>";
  2893. cols += "<td>"
  2894. + "<input type='hidden' value='" + data[0].code + "' name='nameProduct" + counter + "' id='nameProduct" + counter + "'>"
  2895. + "<input type='hidden' value='" + data[0].product_id + "' name='idProduct" + counter + "' id='idProduct" + counter + "'>"
  2896. + name + "</td>";
  2897. cols += "<td>" + itembyp + "</td>";
  2898. cols += "<td><input type='text' class='form-control text-center' value='" + itemdesc + "' name='description" + counter + "' id='description" + counter + "' ></td>";
  2899. 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>";
  2900. cols += "<td>" + data[0].quantity + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'></td>";
  2901. cols += "<td>" + data[0].unit + "</td>";
  2902.  
  2903. cols += "<td align='right'><span><input type='text' class='form-control text-right' value='" + price + "' name='price" + counter + "' id='price" + counter + "'></span></td>";
  2904.  
  2905. 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>";
  2906.  
  2907. 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>';
  2908.  
  2909. cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
  2910. cols += "</tr>";
  2911.  
  2912. newRow.append(cols);
  2913. getnewRow = newRow;
  2914. $("table.additional_table").append(newRow);
  2915. calculateRowAdditional($('tr#tra' + j));
  2916. $.calculateDiscountAdditional($('tr#tra' + j));
  2917. $.calculateGrandTotal();
  2918. counter++;
  2919. var table_data = JSON.stringify(additional_data);
  2920. $('#tableadditional_data').val(table_data);
  2921. j++;
  2922. } else {
  2923. $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  2924. }
  2925. }
  2926. });
  2927. }
  2928. })(itemrec);
  2929. }
  2930.  
  2931.  
  2932.  
  2933. function calculateRowAdditional(row) {
  2934.  
  2935. var key = +row.find('input[name^="id"]').val();
  2936. var price = +row.find('input[name^="price"]').val();
  2937. var qty = +row.find('input[name^="qty"]').val();
  2938. var desc = row.find('input[name^="description"]').val();
  2939.  
  2940. row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
  2941.  
  2942. var availableqty = +row.find('input[name^="available_quantity"]').val();
  2943. var bookqty = qty - availableqty;
  2944. if (bookqty > 0) {
  2945. row.find('td[id^="column-color"]').css({'background-color': 'red'});
  2946. }
  2947.  
  2948. additional_data[key].quantity = qty;
  2949. additional_data[key].price = price;
  2950. additional_data[key].desc = desc;
  2951. additional_data[key].total = (price * qty).toFixed(2);
  2952. var table_data = JSON.stringify(additional_data);
  2953. $('#tableadditional_data').val(table_data);
  2954. }
  2955.  
  2956. }
  2957.  
  2958. jQuery.generateServiceItem = function generateServiceItem(serviceitem) {
  2959. var counter = 1;
  2960. var aritem = serviceitem;
  2961. for (itemrec = 0; itemrec < aritem.length; itemrec++) {
  2962. (function (counter) {
  2963. var getnewRowService;
  2964. var quotationid = aritem[itemrec].id;
  2965. var itemquantity = aritem[itemrec].quantity;
  2966. var itemprice = aritem[itemrec].qprice;
  2967. var itemdiscountid = aritem[itemrec].discount_id;
  2968. var itemdiscountvalue = aritem[itemrec].discount_value;
  2969. var itemdiscount = aritem[itemrec].discount;
  2970. var itemgross_total = aritem[itemrec].gross_total;
  2971. var service_id = aritem[itemrec].service_id;
  2972. var flag = 0;
  2973. $('#err_service').text('');
  2974. $.ajax({
  2975. url: "<?php echo base_url('sales/getService') ?>/" + service_id,
  2976. type: "GET",
  2977. dataType: "JSON",
  2978. data: {
  2979. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  2980. },
  2981. success: function (data) {
  2982. $("table.service_table").find('input[name^="service_id"]').each(function () {
  2983. if (data[0].service_id == +$(this).val()) {
  2984. flag = 1;
  2985. }
  2986. });
  2987. if (flag == 0)
  2988. {
  2989. var id = data[0].service_id;
  2990. var code = data[0].code;
  2991. var name = data[0].service_title;
  2992. var price = itemprice;
  2993. if (price == null) {
  2994. price = 0;
  2995. }
  2996. var product = {"service_id": id,
  2997. "price": price
  2998. };
  2999. service_data[k] = product;
  3000. length = service_data.length - 1;
  3001.  
  3002. var select_discount = "";
  3003. select_discount += '<div class="form-group">';
  3004. select_discount += '<select class="form-control select2" id="item_discountservice" name="item_discountservice" style="width: 100%;">';
  3005. select_discount += '<option value="">Select</option>';
  3006. var selected = '';
  3007. for (a = 0; a < data['discount'].length; a++) {
  3008. if (data['discount'][a].discount_id == itemdiscountid) {
  3009. selected = 'selected ';
  3010. } else {
  3011. selected = '';
  3012. }
  3013. select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  3014. }
  3015. select_discount += '</select></div>';
  3016.  
  3017. var newRowService = $("<tr id='trv" + counter + "'>");
  3018. var cols = "";
  3019. 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>";
  3020. cols += "<td>" + code + "</td>";
  3021. cols += "<td>"
  3022. + "<input type='hidden' value='' name='nameService" + counter + "' id='nameService" + counter + "'>"
  3023. + name + "</td>";
  3024. cols += "<td>"
  3025. + "<input type='number' class='form-control text-center' value='" + itemquantity + "' data-rule='quantity' name='qtyservice" + counter + "' id='qtyservice" + counter + "' min='0' max='2'>"
  3026. + "</td>";
  3027. cols += "<td align='right'>"
  3028. + "<span id='price'>"
  3029. + "<input type='text' class='form-control text-right' name='priceservice" + counter + "' id='priceservice" + counter + "' value='" + price
  3030. + "'>"
  3031. + "</span>"
  3032. + "</td>";
  3033. cols += "<td>"
  3034. + "<span id='sub_total'>"
  3035. + "<input type='text' class='form-control text-right' style='' value='" + itemgross_total + "' name='linetotalservice" + counter + "' id='linetotalservice" + counter + "' readonly>"
  3036. + "</span>"
  3037. + "</td>";
  3038. 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>';
  3039. cols += '<td><input type="text" class="form-control text-right" id="service_total" name="service_total" readonly></td>';
  3040. cols += "</tr>";
  3041. newRowService.append(cols);
  3042. getnewRowService = newRowService;
  3043. $("table.service_table").append(newRowService);
  3044. calculateRowService($('tr#trv' + k));
  3045. $.calculateDiscountService($('tr#trv' + k));
  3046. $.calculateGrandTotal();
  3047. counter++;
  3048. var table_data = JSON.stringify(service_data);
  3049. $('#tableservice_data').val(table_data);
  3050. k++;
  3051. } else {
  3052. $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  3053. }
  3054. }
  3055. });
  3056. })(itemrec);
  3057. }
  3058.  
  3059. function calculateRowService(row)
  3060. {
  3061. var key = +row.find('input[name^="idservice"]').val();
  3062. var price = +row.find('input[name^="priceservice"]').val();
  3063. var qty = +row.find('input[name^="qtyservice"]').val();
  3064. var total = +row.find('input[name^="linetotalservice"]').val();
  3065. row.find('input[name^="linetotalservice"]').val((price * qty).toFixed(2));
  3066. service_data[key].price = price;
  3067. service_data[key].quantity = qty;
  3068. service_data[key].total = total;
  3069. var table_data = JSON.stringify(service_data);
  3070. $('#tableservice_data').val(table_data);
  3071. }
  3072. }
  3073. </script>
  3074. <script>
  3075. $(document).ready(function () {
  3076. $.ajax({
  3077. url: "<?php echo base_url('customer/getState') ?>/" + 102,
  3078. type: "GET",
  3079. dataType: "JSON",
  3080. data: {
  3081. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  3082. },
  3083. success: function (data) {
  3084. for (a = 0; a < data.length; a++) {
  3085. $('#statec').append('<option value="' + data[a].id + '">' + data[a].name + '</option>');
  3086. }
  3087. }
  3088. });
  3089. });
  3090.  
  3091. $('#countryc').change(function () {
  3092. $('#statec').html('');
  3093. $('#statec').html('<option value="">Select State</option>');
  3094. var country_id = $('#countryc').val();
  3095. $.ajax({
  3096. url: "<?php echo base_url('customer/getState') ?>/" + country_id,
  3097. type: "GET",
  3098. dataType: "JSON",
  3099. data: {
  3100. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  3101. },
  3102. success: function (data) {
  3103. for (a = 0; a < data.length; a++) {
  3104. $('#statec').append('<option value="' + data[a].id + '">' + data[a].name + '</option>');
  3105. }
  3106. }
  3107. });
  3108. });
  3109.  
  3110. $('#statec').change(function () {
  3111. $('#cityc').html('');
  3112. $('#cityc').html('<option value="">Select City</option>');
  3113. var state_id = $('#statec').val();
  3114. $.ajax({
  3115. url: "<?php echo base_url('customer/getCity') ?>/" + state_id,
  3116. type: "GET",
  3117. dataType: "JSON",
  3118. data: {
  3119. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  3120. },
  3121. success: function (data) {
  3122. for (a = 0; a < data.length; a++) {
  3123. $('#cityc').append('<option value="' + data[a].id + '">' + data[a].name + '</option>');
  3124. }
  3125. }
  3126. });
  3127. });
  3128.  
  3129. $('#btn_submit').click(function (e) {
  3130. e.preventDefault();
  3131. $.ajax({
  3132. url: '<?php echo base_url('customer/test') ?>',
  3133. datatype: 'JSON',
  3134. method: 'POST',
  3135. data: {
  3136. 'customer_name': $('#c_name').val(),
  3137. 'address': $("#c_address").val(),
  3138. 'country': $("#countryc").val(),
  3139. 'state': $("#statec").val(),
  3140. 'city': $("#cityc").val(),
  3141. 'mobile': $('#c_mobile').val()
  3142. },
  3143. success: function (data) {
  3144. if (data == 1) {
  3145. $('#myModal').modal('hide');
  3146. updateCostumer();
  3147. } else {
  3148. alert("Try again");
  3149. }
  3150. }
  3151. })
  3152. })
  3153.  
  3154. function updateCostumer() {
  3155. $('#customer').html('');
  3156. $('#customer').html('<option value="">Select Customer</option>');
  3157. $.ajax({
  3158. url: "<?php echo base_url('customer/getData') ?>",
  3159. type: "GET",
  3160. dataType: "JSON",
  3161. data: {
  3162. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  3163. },
  3164. success: function (data) {
  3165. for (a = 0; a < data.length; a++) {
  3166. $('#customer').append('<option value="' + data[a].customer_id + '">' + data[a].customer_name + '</option>');
  3167. }
  3168. }
  3169. });
  3170. }
  3171.  
  3172. function checkAvailability() {
  3173. $("#loaderIcon").show();
  3174. jQuery.ajax({
  3175. url: "<?php echo base_url('customer/checkCompany_name') ?>",
  3176. data: 'company_name=' + $("#company_name").val(),
  3177. type: "POST",
  3178. success: function(data) {
  3179. $("#user-availability-status").html(data);
  3180. $("#loaderIcon").hide();
  3181. },
  3182. error: function() {}
  3183. });
  3184. }
  3185. </script>
RAW Paste Data