Advertisement
fadlyshafa

Untitled

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