Advertisement
fadlyshafa

Untitled

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