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