fadlyshafa

Untitled

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