fadlyshafa

Untitled

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