fadlyshafa

Untitled

May 12th, 2020
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. $p = array('1','31','32','51','52', '21','22');
  4. if(!(in_array($this->session->userdata('type'),$p))){
  5. redirect('auth/dashboard');
  6. }
  7. $this->load->view('layout/header');
  8. ?>
  9. <div class="content-wrapper">
  10. <section class="content-header">
  11. <h5>
  12. <ol class="breadcrumb">
  13. <li><a href="<?php echo base_url('auth/dashboard'); ?>"><i class="fa fa-dashboard"></i> <?php echo $this->lang->line('header_dashboard'); ?></a></li>
  14. <li><a href="<?php echo base_url('purchase'); ?>"><?php echo $this->lang->line('header_purchase'); ?></a></li>
  15. <li class="active"><?php echo $this->lang->line('purchase_edit_purchase'); ?></li>
  16. </ol>
  17. </h5>
  18. </section>
  19.  
  20. <section class="content">
  21. <div class="row">
  22. <div class="col-sm-12">
  23. <div class="box">
  24. <?php foreach($data as $row) { ?>
  25. <div class="box-header with-border">
  26. <h3 class="box-title"><?php echo $this->lang->line('purchase_edit_purchase'); ?></h3>
  27. <div class="text-right">
  28. <?php if ($row->status == 3) { ?>
  29. <span class="text-danger"><?= $row->ditolakdesc ?></span>
  30. <?php } ?>
  31. </div>
  32. </div>
  33. <div class="box-body">
  34. <div class="row">
  35. <form role="form" id="form" method="post" action="<?php echo base_url('purchase/editPurchase');?>" enctype="multipart/form-data">
  36. <div class="col-sm-6">
  37. <div class="form-group">
  38. <label for="reference_no">Nomor PO : <span class="validation-color">*</span></label>
  39. <input type="text" class="form-control" id="reference_no" name="reference_no" value="<?php echo $row->reference_no;?>" readonly>
  40. <span class="validation-color" id="err_reference_no"><?php echo form_error('reference_no'); ?></span>
  41. </div>
  42.  
  43. <div class="form-group">
  44. <label for="reference_no">Nomor Revisi : </label>
  45. <input type="text" class="form-control" id="norevisi" name="norevisi" value="<?php echo $row->norevisi;?>" readonly>
  46. </div>
  47.  
  48. <div class="form-group">
  49. <label for="date">Created Date : <span class="validation-color">*</span></label>
  50. <input type="text" class="form-control datepicker" id="date" name="date" value="<?= date("Y-m-d", strtotime($row->date)) ?>">
  51. <input type="hidden" name="purchase_id" value="<?php echo $row->purchase_id;?>">
  52. <span class="validation-color" id="err_date"><?php echo form_error('date'); ?></span>
  53. </div>
  54.  
  55. <div class="form-group">
  56. <label for="po_date">PO Date : <span class="validation-color">*</span></label>
  57. <input type="text" class="form-control datepicker" id="po_date" name="po_date" value="<?php echo date("Y-m-d",strtotime($data[0]->podate)); ?>">
  58. <span class="validation-color" ><?php echo form_error('podate'); ?></span>
  59. </div>
  60.  
  61.  
  62.  
  63. <div class="form-group">
  64. <label for="principal">Principal : <span class="validation-color">*</span></label>
  65. <select class="form-control select2" id="supplier" name="supplier" style="width: 100%;">
  66. <option value=""><?php echo $this->lang->line('product_select'); ?></option>
  67. <?php
  68. foreach ($supplier as $key) {
  69. ?>
  70. <option value='<?php echo $key->supplier_id ?>' <?php if($key->supplier_id == $row->supplier_id){echo "selected";} ?>><?php echo $key->cf1. ' - ' .$key->supplier_name ?></option>
  71. <?php
  72. }
  73. ?>
  74. </select>
  75. <span class="validation-color" id="err_supplier"><?php echo form_error('supplier'); ?></span>
  76. </div>
  77.  
  78. <div class="form-group">
  79. <label for="tax">Tax : </label>
  80. <select name="tax" class="form-control">
  81. <option value='1' <?= ($row->taxdesc==1)?"selected='selected'":''; ?>>Tax Include</option>
  82. <option value='2' <?= ($row->taxdesc==2)?"selected='selected'":''; ?>>Tax Exclude</option>
  83. <option value='0' <?= ($row->taxdesc==0)?"selected='selected'":''; ?>>No-Tax</option>
  84. </select>
  85. </div>
  86.  
  87. <div class="form-group">
  88. <label for="kursdata">Currency : <span class="validation-color">*</span></label>
  89. <select class="form-control" id="kursdata" name="kursdata">
  90. <?php
  91. foreach($kursdata as $kursd)
  92. {
  93. echo "<option value='".$kursd->kurs_id."'>".$kursd->kurs."</option>";
  94. }
  95. ?>
  96. </select>
  97. </div>
  98.  
  99. <div class="form-group" id="currency" style="display: none;">
  100. <label for="ckurs">Currency Exchange : </label>
  101. <input type="text" class="form-control" id="ckurs" name="ckurs" value="">
  102. <input type="hidden" class="form-control" id="symbol" value="">
  103. </div>
  104.  
  105.  
  106.  
  107.  
  108. </div>
  109.  
  110. <div class="col-sm-6">
  111.  
  112. <div class="form-group">
  113. <label for="principal">Reference No : </label>
  114. <input type="text" class="form-control" id="refer_no" name="refer_no" value="<?= $row->refer_no ?>">
  115. </div>
  116.  
  117. <div class="form-group">
  118. <label for="quotaattn">Purchase ATTN to :</label>
  119. <div class="row">
  120. <div class="col-md-6">
  121. <label for="main">Main</label>
  122. <input type="text" class="form-control" id="main" name="main" value="<?= $row->upcc ?>">
  123. </div>
  124. <div class="col-md-6">
  125. <label for="cc">CC</label>
  126. <input type="text" class="form-control" id="cc" name="cc" value="<?= $row->upcc2 ?>">
  127. </div>
  128. </div>
  129. </div>
  130.  
  131. <div class="form-group">
  132. <label for="paymenterms">Payment Terms : <span class="validation-color">*</span></label>
  133. <div class="row">
  134. <div class="col-md-12">
  135. <label class="radio-inline">
  136. <input type="radio" name="paymenterms" value="advance" onclick="showo1()" checked> Advance
  137. </label>
  138. <label class="radio-inline">
  139. <input type="radio" name="paymenterms" value="termin" onclick="showo2()"> Termin
  140. </label>
  141. <label class="radio-inline">
  142. <input type="radio" name="paymenterms" value="others" onclick="showo3()"> Others
  143. </label>
  144. </div>
  145. </div>
  146. <div id="divo1" style="display: none;">
  147. </div>
  148. <div id="divo3" style="display: none;">
  149. <input type="text" class="form-control" id="others" name="others" value="">
  150. </div>
  151. <div id="divo2" style="display: none;position: relative;top: 7px">
  152. <label class="control-label nopadding">Jumlah Termin Kredit</label>
  153. <div class="input-group">
  154. <select id="terminnumber" name="terminnumber" onclick="addFields()" class="form-control" >
  155. <?php
  156. for ($i = 1; $i <= 100; $i++) {
  157. $selected = (count($termin) == $i) ? 'selected ' : '';
  158. echo "<option " . $selected . "value='" . $i . "'>" . $i . "</option>";
  159. }
  160. ?>
  161. </select>
  162. </div>
  163. </div>
  164. <br>
  165. <br>
  166. <div id="termincontainer">
  167. </div>
  168. </div>
  169.  
  170.  
  171. <div class="form-group">
  172. <label for="shipping_address">Shipp To : <span class="validation-color"></span></label>
  173. <select class="form-control select2" name="shipping_address" >
  174. <?php
  175. $shipping_address = explode(';', $company[0]->shipping_address);
  176. foreach($shipping_address as $address){
  177. echo '<option value="' . $address . '">' . $address . '</option>';
  178. }
  179. ?>
  180. </select>
  181. </div>
  182.  
  183. <div class="form-group">
  184. <label for="billing_address">Bill To :<span class="validation-color"></span></label>
  185. <select class="form-control select2" name="billing_address">
  186. <?php
  187. $billing_address = explode(';', $company[0]->billing_address);
  188. foreach($billing_address as $address){
  189. echo '<option value="' . $address . '">' . $address . '</option>';
  190. }
  191. ?>
  192. </select>
  193. </div>
  194.  
  195. <div class="form-group">
  196. <label for="dateestimate">Estimated Delivery Date<span class="validation-color"></span></label>
  197. <input type="text" name="dateestimate" class="form-control datepicker" value="<?= $row->dateestimate ?>">
  198. </div>
  199.  
  200.  
  201.  
  202. </div>
  203.  
  204. <div class="col-sm-12">
  205. <div class="col-sm-12">
  206. <div class="col-sm-3">
  207. <div class="form-group">
  208. <select class="form-control select2" id="brand" name="brand" style="width: 100%;">
  209. <option value="">Select Brand</option>
  210. <?php foreach ($brands as $brand) { ?>
  211. <option value='<?= $brand->id ?>'><?= $brand->brand_name ?></option>
  212. <?php } ?>
  213. </select>
  214. <span class="validation-color" id="err_warehouse"><?php echo form_error('warehouse'); ?></span>
  215. </div>
  216. </div>
  217. <div class="col-sm-3">
  218. <div class="form-group">
  219. <select class="form-control select2" id="code_item" name="code_item" style="width: 100%;">
  220. <option value="">Select Part Number</option>
  221. </select>
  222. </div>
  223. </div>
  224. <div class="col-sm-3">
  225. <div class="form-group">
  226. <select class="form-control" id="product" name="product" style="width: 100%;">
  227. <option value=""><?php echo $this->lang->line('purchase_select_product'); ?></option>
  228. </select>
  229. </div>
  230. </div>
  231. <div class="col-sm-3">
  232. <a href="<?php echo base_url('product/add'); ?>" target="_blank" class="btn btn-info"><?php echo $this->lang->line('header_add'); ?> New Products</a>
  233. <span class="validation-color" id="err_product"></span>
  234. </div>
  235. </div>
  236.  
  237. <div class="col-sm-12">
  238. <div class="form-group">
  239. <label><?php echo $this->lang->line('purchase_inventory_items'); ?></label>
  240.  
  241. <table class="table items table-striped table-bordered table-condensed table-hover product_table" name="product_data" id="product_data">
  242. <thead>
  243. <tr>
  244. <th width="3%"><img src="<?php echo base_url(); ?>assets/images/bin1.png" /></th>
  245. <th class="span2" width="5%">Part Number</th>
  246. <th class="span2" width="8%">Item Name</th>
  247. <th class="span2" width="10%">Vendor or Item Name</th>
  248. <th class="span2" width="8%">Description</th>
  249. <th class="span2" width="8%">Qty</th>
  250. <th class="span2" width="5%">Stock</th>
  251. <th class="span2" width="5%">UOM</th>
  252. <th class="span2" width="8%">Price</th>
  253. <th class="span2" width="8%">Sales Total</th>
  254. <th class="span2" width="8%">Discount</th>
  255. <th class="span2" width="8%">Total</th>
  256. </tr>
  257. </thead>
  258. <tbody>
  259. </tbody>
  260. </table>
  261.  
  262. </div>
  263. </div>
  264.  
  265. <input type="hidden" name="total_value" id="total_value" value=''>
  266. <input type="hidden" name="total_discount" id="total_discount" value=''>
  267. <input type="hidden" name="total_tax" id="total_tax" value=''>
  268. <input type="hidden" name="grand_total" id="grand_total" value=''>
  269. <input type="hidden" name="grand_currency" id="grand_currency" value=''>
  270. <input type="hidden" name="biayaTotal" id="biayaTotal" value=''>
  271.  
  272. <input type="hidden" name="table_data" id="table_data">
  273. <table class="table table-striped table-bordered table-condensed table-hover">
  274. <tr>
  275. <td align="right" width="80%"><?php echo $this->lang->line('purchase_total_value').'/Total Harga'; ?></td>
  276. <td align='right'><span id="kurs_symbol"></span><span id="totalValue"></span></td>
  277. </tr>
  278. <tr>
  279. <td align="right"><?php echo $this->lang->line('purchase_total_discount'); ?></td>
  280. <td align='right'>
  281. <span id="kurs_symbol1"></span> <span id="totalDiscount"></span>
  282. </td>
  283. </tr>
  284. <tr>
  285. <td align="right"><?php echo "Diskon %"; ?></td>
  286. <td align='right'>
  287. <input type="number" class="text-right" onkeypress="return isNumber(event)" id="diskonpersen_text" step="0.01" name="diskonpersen_text" value="<?= $data[0]->diskonpersen ?>">
  288. </td>
  289. </tr>
  290.  
  291. <tr style="display:none;">
  292. <td align="right"><?php echo 'Jumlah Diskon %'; ?></td>
  293. <td align='right'><span id="kurs_symbol2"></span>
  294. <span id="JumlahDiskonPersen">&nbsp;0.00</span>
  295. </td>
  296. </tr>
  297.  
  298. <tr>
  299. <td align="right"><?php echo "Diskon Fix"; ?></td>
  300. <td align='right'><span id="kurs_symbol3"></span>
  301. <input type="number" step='0.01' class="text-right" onkeypress="return isNumber(event)" id="diskon_text" name="diskon_text" value="<?= $data[0]->diskon ?>">
  302. </td>
  303. </tr>
  304.  
  305.  
  306. <tr>
  307. <td align="right"><?php echo $this->lang->line('purchase_total_discount')." Umum"; ?></td>
  308. <td align='right'><span id="kurs_symbol4"></span>
  309. <span id="totalDiscountUmum">&nbsp;0.00</span>
  310. </td>
  311. </tr>
  312.  
  313. <tr>
  314. <td align="right">Tax</td>
  315. <td align='right'>
  316. <select class="form-control" name="taxx" id="taxx">
  317. <option value="">Select Tax</option>
  318. <?php foreach ($tax as $value) { ?>
  319. <option value="<?= $value->tax_value ?>"><?= $value->tax_name ?></option>
  320. <?php } ?>
  321. </select>
  322. </td>
  323. </tr>
  324.  
  325. <tr>
  326. <td align="right"><?php echo $this->lang->line('purchase_total_tax').'/Total Pajak'; ?></td>
  327. <td align='right'>
  328. <span id="kurs_symbol5"></span> <span id="totalTax"></span>
  329. </td>
  330. </tr>
  331.  
  332.  
  333.  
  334. <tr>
  335. <td align="right"><?php echo $this->lang->line('purchase_total').'/Total Harga'; ?></td>
  336. <td align='right'><span id="kurs_symbol6"></span><span id="grandTotal"><?php echo $row->total; ?></span></td>
  337. </tr>
  338.  
  339.  
  340. <tr>
  341. <td align="right"><?php echo 'Currency Total :'; ?> </td>
  342. <td align='right'><span id="grandCurrency"><?php echo $row->nominalcurrency; ?></span></td>
  343. </tr>
  344.  
  345. </table>
  346. <hr>
  347. <a id="add-biaya" class="btn btn-success">Add Biaya</a>
  348. <hr>
  349.  
  350. <table class="table table-bordered" border="1" id="tbl_biaya">
  351. <thead>
  352. <tr>
  353. <td>Jenis Biaya</td>
  354. <td>Keterangan</td>
  355. <td>Add To Doc</td>
  356. <td>File Upload</td>
  357. <td>Nominal</td>
  358. <td></td>
  359. </tr>
  360. </thead>
  361. <tbody>
  362.  
  363. </tbody>
  364. <tfoot>
  365. <tr>
  366. <td colspan="4" align="right">Total Biaya</td>
  367. <td colspan="2">
  368. <span id="totalBiaya">&nbsp;0.00</span>
  369. </td>
  370. </tr>
  371. </tfoot>
  372. </table>
  373.  
  374. </div>
  375. </div>
  376.  
  377.  
  378.  
  379. <div class="col-sm-12">
  380. <div class="form-group">
  381. <label for="details"><?php echo $this->lang->line('purchase_note'); ?></label>
  382. <textarea class="form-control" id="note" name="note"><?php echo $row->note;?></textarea>
  383. <span class="validation-color" id="err_details"><?php echo form_error('details'); ?></span>
  384. </div>
  385. </div>
  386.  
  387.  
  388. <div class="col-sm-12">
  389. <div class="box-footer">
  390. <input type="submit" name="submit" id="submit" class="btn btn-info" value="Update">
  391. <input type="submit" name="submit" id="submit" value="Save As Draft" class="btn btn-warning">
  392. <a href="#" data-toggle="modal" data-target="#previewmodal" id="preview" class="btn btn-default">Preview</a>
  393. <span class="btn btn-default" id="cancel" style="margin-left: 2%" onclick="cancel('purchase')"><?php echo $this->lang->line('product_cancel'); ?></span>
  394. </div>
  395. </div>
  396. <?php } ?>
  397. </form>
  398. </div>
  399. </div>
  400. </div>
  401. </div>
  402. </div>
  403. </section>
  404. </div>
  405. <script>
  406. var yi = 0;
  407.  
  408. $(document).ready(function () {
  409.  
  410. $('input[name=paymenterms][value=<?php echo $data[0]->pterm; ?>]').prop('checked', true).click();
  411. if ('termin' == '<?php echo $data[0]->pterm; ?>') {
  412.  
  413. var e = document.getElementById("terminnumber");
  414. var number = e.options[e.selectedIndex].value;
  415. getfromaddFields = number;
  416. var container = document.getElementById("termincontainer");
  417. while (container.hasChildNodes())
  418. {
  419. container.removeChild(container.lastChild);
  420. }
  421. $("#kursdata").val(<?php echo $data[0]->kurs_id; ?>).trigger('change');
  422.  
  423. var mode_of_transport = $("#mode_of_transport").val();
  424. var transporter_name = $("#transporter_name").val();
  425. var transporter_code = $("#transporter_code").val();
  426. var vehicle_regn_no = $("#vehicle_regn_no").val();
  427. if (mode_of_transport || transporter_name || vehicle_regn_no) {
  428. $("#transporter").prop('checked', false).click();
  429. }
  430.  
  431. var container = container.appendChild(document.createElement("table"));
  432. container.className = "table table-bordered";
  433. var container = container.appendChild(document.createElement("tbody"));
  434. var artermin = <?php echo json_encode($termin); ?>;
  435. for (i = 0; i < number; i++)
  436. {
  437. var containertr = container.appendChild(document.createElement("tr"));
  438. var containertd = containertr.appendChild(document.createElement("td"));
  439. z = document.createElement('span');
  440. z.innerHTML = "Termin Ke % " + (i + 1) + " :";
  441. z.className = "text-danger";
  442. containertd.appendChild(z);
  443. var input = document.createElement("input");
  444. input.type = "number";
  445. input.name = "terminvalue[" + (i + 1) + "]";
  446. input.id = "terminvalue[" + (i + 1)+"]";
  447. input.className = "form-control getterminvalue";
  448. input.value = artermin[i].persen;
  449. input.min = 1;
  450. input.max = 100;
  451. input.maxlength = "2";
  452. input.onkeypress = isNumber_max_100;
  453. var containertd = containertr.appendChild(document.createElement("td"));
  454. containertd.appendChild(input);
  455. }
  456. }
  457.  
  458. var counter = 1;
  459. var aritem = <?php echo json_encode($items); ?>;
  460. for (itemrec = 0; itemrec < aritem.length; itemrec++) {
  461. (function (counter) {
  462. var getnewRow;
  463. var itemquantity = aritem[itemrec].quantity;
  464. var itemprice = aritem[itemrec].qprice;
  465. if (itemprice == null || !itemprice) { itemprice = 0; }
  466. var itemdiscountid = aritem[itemrec].discount_id;
  467. var desc = aritem[itemrec].desc;
  468. var itemdiscountvalue = aritem[itemrec].discount_value;
  469. var itemdiscount = aritem[itemrec].discount;
  470. var itemgross_total = aritem[itemrec].gross_total;
  471. var product_id = aritem[itemrec].product_id;
  472. var flag = 0;
  473. $('#err_product').text('');
  474. $.ajax({
  475. async : false,
  476. url: "<?php echo base_url('purchase/getProductAjax') ?>/" + product_id,
  477. type: "GET",
  478. dataType: "JSON",
  479. data: {
  480. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  481. },
  482. success: function (data) {
  483. $("table.product_table").find('input[name^="product_id"]').each(function () {
  484. if (data[0].product_id == +$(this).val()) {
  485. flag = 1;
  486. }
  487. });
  488. if (flag == 0) {
  489. var id = data[0].product_id;
  490. var price = itemprice;
  491. var code = data[0].code;
  492. var name = data[0].name;
  493. var item_namebyp = data[0].item_namebyp;
  494.  
  495. var product = {"product_id": id,
  496. "price": price
  497. };
  498. product_data[yi] = product;
  499. length = product_data.length - 1;
  500. var select_discount = "";
  501. select_discount += '<div class="form-group">';
  502. select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
  503. select_discount += '<option value="">Select</option>';
  504. var selected = '';
  505. for (a = 0; a < data['discount'].length; a++) {
  506. if (data['discount'][a].discount_id == itemdiscountid) {
  507. selected = 'selected ';
  508. } else {
  509. selected = '';
  510. }
  511. select_discount += '<option ' + selected + 'value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name + '(' + data['discount'][a].discount_value + '%)' + '</option>';
  512. }
  513. select_discount += '</select></div>';
  514.  
  515. var newRow = $("<tr id='tr" + yi + "'>");
  516. var cols = "";
  517. 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>";
  518. cols += "<td>" + code + "</td>";
  519. cols += "<td>"
  520. + "<input type='hidden' value='" + data[0].name + "' name='nameProduct" + counter + "' id='nameProduct" + counter + "'>"
  521. + "<input type='hidden' value='" + data[0].product_id + "' name='idProduct" + counter + "' id='idProduct" + counter + "'>"
  522. + name + "</td>";
  523. cols += "<td>" + item_namebyp + "</td>";
  524. cols += "<td><input type='text' name='description" + counter + "' id='description"+ counter + "' value='" + desc + "' class='form-control'></td>";
  525. cols += "<td>"
  526. + "<input type='number' class='form-control text-center' value='" + itemquantity + "' data-rule='quantity' name='qty" + counter + "' id='qty" + counter + "' min='1'>"
  527. + "</td>";
  528. cols += "<td>" + data[0].quantity
  529. + "<input type='hidden' name='available_quantity" + counter + "' id='available_quantity" + counter + "' value='" + data[0].quantity + "'>"
  530. + "</td>";
  531. cols += "<td>" + data[0].unit + "</td>";
  532. cols += "<td align='right'>"
  533. + "<span>"
  534. + "<input step='0.01' type='number' class='form-control text-right' value='" + itemprice + "' name='price" + counter + "' id='price" + counter + "'>"
  535. + "</span>"
  536. + "</td>";
  537. cols += "<td>"
  538. + "<span id='sub_total'>"
  539. + "<input type='text' class='form-control text-right' style='' value='" + itemgross_total + "' name='linetotal" + counter + "' id='linetotal" + counter + "' readonly>"
  540. + "</span>"
  541. + "</td>";
  542. 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>';
  543.  
  544. cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
  545. cols += "</tr>";
  546.  
  547. newRow.append(cols);
  548. getnewRow = newRow;
  549. $("table.product_table").append(newRow);
  550. counter++;
  551. var table_data = JSON.stringify(product_data);
  552. $('#table_data').val(table_data);
  553. calculateRow($('tr#tr' + yi));
  554. calculateDiscount($('tr#tr' + yi));
  555. calculateGrandTotal();
  556. yi++;
  557. } else {
  558. $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  559. }
  560. }
  561. });
  562. })(itemrec);
  563. }
  564.  
  565. var bi = 1;
  566. var biaya = <?php echo json_encode($biaya); ?>;
  567. for (itemrec = 0; itemrec < biaya.length; itemrec++) {
  568. var getnewRow;
  569. var biayaid = biaya[itemrec].id;
  570. var jenis = biaya[itemrec].jenis_biaya;
  571. var keterangan = biaya[itemrec].keterangan;
  572. var file_upload = biaya[itemrec].file_upload;
  573. var pdf = biaya[itemrec].pdf;
  574. var nominal = biaya[itemrec].nominal;
  575. if (pdf == 1) {
  576. pdf = "checked='checked'";
  577. } else {
  578. pdf = ""
  579. }
  580. if (nominal == null || !nominal) { nominal = 0; }
  581. var js = '';
  582. var jh = '';
  583. var jc = '';
  584. var jl = '';
  585. var jo = '';
  586. if (jenis == 1) {
  587. js = 'selected ';
  588. } else if (jenis == 2) {
  589. jh = 'selected ';
  590. } else if (jenis == 3) {
  591. jc = 'selected ';
  592. } else if (jenis == 4) {
  593. jl = 'selected ';
  594. } else if (jenis == 5) {
  595. jo = 'selected ';
  596. }
  597.  
  598. var newRow = $("<tr id='"+ bi +"'>");
  599. var cols = "";
  600.  
  601. cols += "<td><select name='jenis_biaya[]' id='jenis_biaya' class='form-control'>";
  602. cols += "<option value='1' "+ js +">Shipping</option>";
  603. cols += "<option value='2' "+ jh +">Handling dan Packing</option>";
  604. cols += "<option value='3' "+ jc +">Custom Clearance</option>";
  605. cols += "<option value='4' "+ jl +">Loading</option>";
  606. cols += "<option value='5' "+ jo +">Others</option>";
  607. cols += "</select></td>";
  608. cols += '<td><input class="form-control" type="text" name="keterangan[]" value="'+ keterangan +'">' ;
  609. cols += '<input type="hidden" name="biaya_id[]" value="'+ biayaid +'"></td>' ;
  610. cols += '<td><input type="checkbox" class="form-check-input center" name="pdf[]" value="1" '+ pdf +'></td>' ;
  611. cols += '<td><input type="file" name="file[]" id="filenya" value="">';
  612. cols += '<a href="<?= base_url() ?>assets/doc/'+ file_upload +'">'+file_upload+'</a>';
  613. cols += '</td>';
  614. cols += '<td><input step="0.01" class="form-control" type="number" name="nominal[]" id="nominal" value="'+ nominal +'"></td>';
  615. cols += "<td><a class='deleteRow'><img src='<?php echo base_url(); ?>assets/images/bin3.png' /> </a></td>";
  616. cols += "</tr>";
  617.  
  618. newRow.append(cols);
  619. $('table#tbl_biaya tbody').append(newRow);
  620. calculateGrandTotal2();
  621. bi++;
  622. }
  623. });
  624.  
  625. function newdatatemp()
  626. {
  627. var container = document.getElementById("kurscontainer");
  628. var iyv=0;
  629. var iyx=0;
  630. var iyy=0;
  631. var iyz=0;
  632.  
  633. <?php
  634.  
  635.  
  636.  
  637. $iy=0;
  638.  
  639. if(!empty($termins))
  640. {
  641. foreach (@$termins as $termindata)
  642. {
  643. ?>
  644. localStorage.setItem("terminvalue"+<?php echo $iy; ?>, <?php echo $termindata->persen;?>);
  645. localStorage.setItem("tanggalterminvalue"+<?php echo $iy; ?>, <?php echo$termindata->tanggalbayar;?>);
  646.  
  647. <?php
  648. $iy++;
  649. }
  650. }
  651. ?>
  652.  
  653. }
  654.  
  655.  
  656. window.onload = newdatatemp();
  657.  
  658. var i = 0;
  659. function increment()
  660. {
  661. i += 1;
  662. }
  663.  
  664. function storedatatemp()
  665. {
  666.  
  667. var e = document.getElementById("terminnumber");
  668. var number2 = e.options[e.selectedIndex].value;
  669. var container2 = document.getElementById("termincontainer");
  670.  
  671.  
  672. var iyv=0;
  673. var iyx=0;
  674. var iyy=0;
  675. var iyz=0;
  676. var iya=0;
  677. var iyb=0;
  678.  
  679. for (ik=0;ik<number2;ik++)
  680. {
  681. var a= document.getElementsByName("terminvalue[]"), i;
  682. localStorage.removeItem("terminvalue"+ik);
  683. localStorage.setItem("terminvalue"+ik, a[ik].value);
  684.  
  685.  
  686. var b= document.getElementsByName("tanggalterminvalue[]"), i;
  687. localStorage.removeItem("tanggalterminvalue"+ik);
  688. localStorage.setItem("tanggalterminvalue"+ik, b[ik].value);
  689. }
  690.  
  691.  
  692.  
  693. }
  694.  
  695.  
  696. function showc1()
  697. {
  698. var container = document.getElementById("kurscontainer");
  699.  
  700. while (container.hasChildNodes())
  701. {
  702. container.removeChild(container.lastChild);
  703. }
  704.  
  705. document.getElementById('divc1').style.display ='block';
  706. document.getElementById('divc2').style.display ='none';
  707. }
  708.  
  709. function showc2()
  710. {
  711. document.getElementById('divc2').style.display ='block';
  712. document.getElementById('divc1').style.display ='none';
  713. addKursFields();
  714. }
  715.  
  716. function addKursFields()
  717. {
  718. var e = document.getElementById("kursid2");
  719. var options = document.getElementById('kursid2').options, count = 0;
  720. var options2 = document.getElementById('kursdata');
  721.  
  722. var arrayman = [];
  723. var arraymankurs = [];
  724. for (var i=0; i < options.length; i++)
  725. {
  726. arraymankurs[count]=options2[i].value;
  727. if (options[i].selected)
  728. {
  729. arrayman[count]=e.options[i].text;
  730. count++;
  731. }
  732. }
  733.  
  734. var container = document.getElementById("kurscontainer");
  735.  
  736. while (container.hasChildNodes())
  737. {
  738. container.removeChild(container.lastChild);
  739. }
  740.  
  741.  
  742.  
  743. for (i=0;i<count;i++)
  744. {
  745. container.appendChild(document.createTextNode("Nilai Kurs " + arrayman[i] +" :"));
  746. var input = document.createElement("input");
  747. input.type = "number";
  748. input.name = "kursdatavalue[]";
  749. input.id = "kursdatavalue"+(i+1);
  750. input.min = 1;
  751.  
  752. input.value = localStorage.getItem("kursdatavalue"+i);
  753.  
  754. input.onkeyup=function ()
  755. {
  756.  
  757. var container = document.getElementById("kurscontainer");
  758. var children = container.childNodes;
  759.  
  760. var iy=0;
  761. for(var im = 0; im<children.length; im++)
  762. {
  763. if( children[im].tagName == "INPUT" && children[im].name=='kursdatavalue[]' )
  764. {
  765. var rate=document.getElementsByName("rate")[0].value;
  766.  
  767. var nominal=children[im].value;
  768. var numberPattern = /\d+/g;
  769. nominal=nominal.replace(/\D/g, "");
  770. nominal=parseFloat(nominal);
  771.  
  772. var y= document.getElementsByName("premikursdatavalue[]"), i;
  773.  
  774. if(nominal.length==0)
  775. {
  776. nominal=1;
  777. }
  778.  
  779. if(rate.length==0)
  780. {
  781. rate=1;
  782. }
  783.  
  784. var hasil=(nominal*rate)/100;
  785.  
  786. y[iy].value=hasil;
  787.  
  788. iy++;
  789. }
  790. }
  791.  
  792. storedatatemp();
  793. };
  794.  
  795.  
  796. container.appendChild(input);
  797. container.appendChild(document.createElement("br"));
  798.  
  799.  
  800. input.min = 1;
  801. container.appendChild(input);
  802. container.appendChild(document.createElement("br"));
  803.  
  804. container.appendChild(document.createElement("br"));
  805. container.appendChild(document.createElement("br"));
  806. }
  807. }
  808.  
  809. function addRevisi()
  810. {
  811. var e = document.getElementById("status");
  812. var number = e.options[e.selectedIndex].value;
  813.  
  814. if(number==3)
  815. {
  816. document.getElementById('divrevisi').style.display ='block';
  817.  
  818. }
  819. else
  820. {
  821. document.getElementById('divrevisi').style.display ='none';
  822. }
  823.  
  824. }
  825.  
  826. function addFields()
  827. {
  828. var e = document.getElementById("terminnumber");
  829. var number = e.options[e.selectedIndex].value;
  830. var container = document.getElementById("termincontainer");
  831.  
  832. while (container.hasChildNodes())
  833. {
  834. container.removeChild(container.lastChild);
  835. }
  836.  
  837. for (i=0;i<number;i++)
  838. {
  839. container.appendChild(document.createTextNode("Termin Ke % " + (i+1) +" :"));
  840. var input = document.createElement("input");
  841. input.type = "number";
  842. input.name = "terminvalue"+(i+1);
  843. input.id = "terminvalue"+(i+1);
  844. input.min = 1;
  845. input.max = 100;
  846. container.appendChild(input);
  847. container.appendChild(document.createElement("br"));
  848. }
  849. }
  850.  
  851. function showo1()
  852. {
  853. var container = document.getElementById("termincontainer");
  854.  
  855. while (container.hasChildNodes())
  856. {
  857. container.removeChild(container.lastChild);
  858. }
  859. document.getElementById('divo1').style.display ='block';
  860. document.getElementById('divo2').style.display ='none';
  861. document.getElementById('divo3').style.display ='none';
  862. }
  863.  
  864.  
  865. function showo2()
  866. {
  867. document.getElementById('divo1').style.display ='none';
  868. document.getElementById('divo2').style.display ='block';
  869. document.getElementById('divo3').style.display ='none';
  870. }
  871.  
  872. function showo3()
  873. {
  874. var container = document.getElementById("termincontainer");
  875. while (container.hasChildNodes())
  876. {
  877. container.removeChild(container.lastChild);
  878. }
  879. document.getElementById('divo1').style.display ='none';
  880. document.getElementById('divo2').style.display ='none';
  881. document.getElementById('divo3').style.display ='block';
  882. }
  883.  
  884. function showdis1()
  885. {
  886. document.getElementById('divdis1').style.display ='block';
  887. document.getElementById('divdis2').style.display ='none';
  888. }
  889.  
  890. function showdis2()
  891. {
  892. document.getElementById('divdis1').style.display ='none';
  893. document.getElementById('divdis2').style.display ='block';
  894. }
  895.  
  896.  
  897. $(document).ready(function(){
  898. var i = <?php echo $i++; ?>;
  899. var product_data = new Array();
  900. var counter = <?php echo count($items); ?>;
  901.  
  902. $('#brand').change(function () {
  903. $('#code_item').html('');
  904. $('#code_item').html('<option value="">Select Part Number</option>');
  905. var brand_id = $('#brand').val();
  906. $.ajax({
  907. url: "<?php echo base_url('sales/getPartNumber') ?>/" + brand_id,
  908. type: "GET",
  909. dataType: "JSON",
  910. data: {
  911. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  912. },
  913. success: function (data) {
  914. for (a = 0; a < data.length; a++) {
  915. $('#code_item').append('<option value="' + data[a].code + '">' + data[a].code + '</option>');
  916. }
  917. }
  918. });
  919. });
  920.  
  921. $('#code_item').change(function () {
  922. $('#product').html('');
  923. $('#product').html('<option value="">Select Product</option>');
  924. var code = $('#code_item').val();
  925. $.ajax({
  926. url: "<?php echo base_url('sales/getCodeProduct') ?>/" + code,
  927. type: "GET",
  928. dataType: "JSON",
  929. data: {
  930. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  931. },
  932. success: function (data) {
  933. for (a = 0; a < data.length; a++) {
  934. $('#product').append('<option value="' + data[a].product_id + '">' + data[a].name + '</option>');
  935. }
  936. }
  937. });
  938. });
  939.  
  940. $('#product').change(function(){
  941. var id = $('#product').val();
  942. $('#err_product').text('');
  943. var flag = 0;
  944. if(id != ""){
  945. $.ajax({
  946. url: "<?php echo base_url('index.php/purchase/getProductAjax') ?>/"+id,
  947. type: "GET",
  948. data:{
  949. '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>'
  950. },
  951. datatype: "JSON",
  952. success: function(d){
  953. data = JSON.parse(d);
  954. $("table.product_table").find('input[name^="product_id"]').each(function () {
  955. if(data[0].product_id == +$(this).val()){
  956. flag = 1;
  957. }
  958. });
  959. if(flag == 0){
  960. var id = data[0].product_id;
  961. var code = data[0].code;
  962. var item_namebyp = data[0].item_namebyp;
  963. var name = data[0].name;
  964. var price = data[0].cost
  965. var product = { "product_id" : id,
  966. "price" :price
  967. };
  968.  
  969.  
  970. product_data[yi] = product;
  971.  
  972. length = product_data.length - 1 ;
  973.  
  974. var select_discount = "";
  975. select_discount += '<div class="form-group">';
  976. select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">';
  977. select_discount += '<option value="">Select</option>';
  978. for(a=0;a<data['discount'].length;a++){
  979. select_discount += '<option value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name+'('+data['discount'][a].discount_value +'%)'+ '</option>';
  980. }
  981. select_discount += '</select></div>';
  982.  
  983.  
  984. var newRow = $("<tr>");
  985. var cols = "";
  986. 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>";
  987. cols += "<td>"+code+"</td>";
  988. cols += "<td>"+name+"</td>";
  989. cols += "<td>"+item_namebyp+"</td>";
  990. cols += "<td align='right'><span id='description'><input type='text' class='form-control text-right' name='description" + counter + "' id='description" + counter + "' value=''></span></td>";
  991. cols += "<td>"
  992. +"<input type='number' class='form-control text-center' value='0' data-rule='quantity' min='1' name='qty"+ counter +"' id='qty"+ counter +"' >"
  993. +"</td>";
  994. cols += "<td align='right'>"+data[0].quantity+"</td>";
  995. cols += "<td>"+data[0].unit+"</td>";
  996. cols += "<td align='right'>"
  997. +"<input step='0.01' type='number' name='price"+ counter +"' id='price"+ counter +"' value='"+price
  998. +"'>"
  999. +"</td>";
  1000. cols += "<td>"
  1001. +"<span id='sub_total'>"
  1002. +"<input type='text' class='form-control text-right' style='' value='0.00' name='linetotal"+ counter +"' id='linetotal"+ counter +"' readonly>"
  1003. +"</span>"
  1004. +"</td>";
  1005. cols += '<td><input type="hidden" id="discount_value" name="discount_value"><input type="hidden" id="hidden_discount" name="hidden_discount">'+select_discount+'</td>';
  1006.  
  1007. cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>';
  1008.  
  1009. cols += "</tr>";
  1010. counter++;
  1011.  
  1012. newRow.append(cols);
  1013. $("table.product_table").append(newRow);
  1014. var table_data = JSON.stringify(product_data);
  1015. $('#table_data').val(table_data);
  1016. yi++;
  1017. }
  1018. else{
  1019. $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  1020. }
  1021. },
  1022. error: function(xhr, status, error) {
  1023. $('#err_product').text('Enter Product Code / Name').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000);
  1024. }
  1025. });
  1026. }
  1027. });
  1028.  
  1029.  
  1030. $("table.product_table").on("click", "a.deleteRow", function (event) {
  1031. deleteRow($(this).closest("tr"));
  1032. $(this).closest("tr").remove();
  1033. calculateGrandTotal();
  1034. });
  1035.  
  1036. function deleteRow(row){
  1037. var id = +row.find('input[name^="id"]').val();
  1038. var array_id = product_data[id].product_id;
  1039. product_data[id] = null;
  1040. var table_data = JSON.stringify(product_data);
  1041. $('#table_data').val(table_data);
  1042. }
  1043.  
  1044.  
  1045. $("table.product_table").on("change", 'input[name^="price"], input[name^="description"], input[name^="qty"]', function (event) {
  1046. calculateRow($(this).closest("tr"));
  1047. calculateDiscount($(this).closest("tr"));
  1048. calculateGrandTotal();
  1049.  
  1050. });
  1051.  
  1052.  
  1053. $("table.product_table").on("keyup", 'input[name^="price"], input[name^="description"], input[name^="qty"]', function (event) {
  1054. calculateRow($(this).closest("tr"));
  1055. calculateDiscount($(this).closest("tr"));
  1056. calculateGrandTotal();
  1057.  
  1058. });
  1059.  
  1060. $("table.product_table").on("change",'#item_discount',function (event) {
  1061. var row = $(this).closest("tr");
  1062. var discount = +row.find('#item_discount').val();
  1063. if(discount != ""){
  1064. $.ajax({
  1065. url: '<?php echo base_url('purchase/getDiscountValue/') ?>'+discount,
  1066. type: "GET",
  1067. data:{
  1068. '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>'
  1069. },
  1070. datatype: JSON,
  1071. success: function(value){
  1072. data = JSON.parse(value);
  1073. row.find('#discount_value').val(data[0].discount_value);
  1074. calculateRow(row);
  1075. calculateDiscount(row,data[0].discount_value);
  1076. calculateGrandTotal();
  1077. }
  1078. });
  1079. }
  1080. else{
  1081. row.find('#discount_value').val('0');
  1082. calculateRow(row);
  1083. calculateDiscount(row,0);
  1084. calculateGrandTotal();
  1085. }
  1086. });
  1087.  
  1088. $(document).on('change', '#kursdata', function()
  1089. {
  1090. changekurs();
  1091.  
  1092. });
  1093.  
  1094. $(document).on('change', '#taxx', function()
  1095. {
  1096. calculateGrandTotal();
  1097.  
  1098. });
  1099.  
  1100. $(document).on('keyup', '#ckurs', function()
  1101. {
  1102. calculateGrandTotal();
  1103. });
  1104.  
  1105.  
  1106. $(document).on('keyup', '#diskon_text', function()
  1107. {
  1108. calculateGrandTotal();
  1109. });
  1110.  
  1111. $(document).on('keyup', '#diskonpersen_text', function()
  1112. {
  1113. calculateGrandTotal();
  1114. });
  1115.  
  1116. $("table#tbl_biaya").on("change", function(event) {
  1117. calculateGrandTotal2();
  1118. });
  1119.  
  1120. });
  1121.  
  1122. </script>
  1123.  
  1124. <script>
  1125. $(document).ready(function(){
  1126. $("#submit").click(function(event){
  1127. var name_regex = /^[a-zA-Z]+$/;
  1128. var sname_regex = /^[a-zA-Z0-9]+$/;
  1129. var num_regex = /^[0-9]+$/;
  1130. var date_regex = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/;
  1131. var date = $('#date').val();
  1132. var warehouse = $('#warehouse').val();
  1133. var supplier = $('#supplier').val();
  1134. var grand_total = $('#grand_total').val();
  1135.  
  1136.  
  1137. if(date==null || date==""){
  1138. $("#err_date").text("Please Enter Date");
  1139. $('#date').focus();
  1140. return false;
  1141. }
  1142. else{
  1143. $("#err_date").text("");
  1144. }
  1145. if (!date.match(date_regex) ) {
  1146. $('#err_date').text(" Please Enter Valid Date ");
  1147. $('#date').focus();
  1148. return false;
  1149. }
  1150. else{
  1151. $("#err_date").text("");
  1152. }
  1153.  
  1154.  
  1155. if(warehouse==""){
  1156. $("#err_warehouse").text("Please Enter Warehouse");
  1157. $('#warehouse').focus();
  1158. return false;
  1159. }
  1160. else{
  1161. $("#err_warehouse").text("");
  1162. }
  1163. //warehouse code validation complite.
  1164.  
  1165. if(supplier==""){
  1166. $("#err_supplier").text("Please Enter Supplier");
  1167. $('#supplier').focus();
  1168. return false;
  1169. }
  1170. else{
  1171. $("#err_supplier").text("");
  1172. }
  1173. //supplier code validation complite.
  1174.  
  1175. if(grand_total=="" || grand_total==null || grand_total==0.00){
  1176. $("#err_product").text("Please Select Product");
  1177. $('#product').focus();
  1178. return false;
  1179. }
  1180.  
  1181. });
  1182.  
  1183. $("#date").blur(function(event){
  1184. var date = $('#date').val();
  1185. var date_regex = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/;
  1186. if(date==null || date==""){
  1187. $("#err_date").text("Please Enter Date");
  1188. $('#date').focus();
  1189. return false;
  1190. }
  1191. else{
  1192. $("#err_date").text("");
  1193. }
  1194. if (!date.match(date_regex) ) {
  1195. $('#err_date').text(" Please Enter Valid Date ");
  1196. $('#date').focus();
  1197. return false;
  1198. }
  1199. else{
  1200. $("#err_date").text("");
  1201. }
  1202. });
  1203. $("#warehouse").change(function(event){
  1204. var warehouse = $('#warehouse').val();
  1205. if(warehouse==""){
  1206. $("#err_warehouse").text("Please Enter Warehouse");
  1207. $('#warehouse').focus();
  1208. return false;
  1209. }
  1210. else{
  1211. $("#err_warehouse").text("");
  1212. }
  1213. });
  1214. $("#supplier").change(function(event){
  1215. var supplier = $('#supplier').val();
  1216. if(supplier==""){
  1217. $("#err_supplier").text("Please Enter Supplier");
  1218. $('#supplier').focus();
  1219. return false;
  1220. }
  1221. else{
  1222. $("#err_supplier").text("");
  1223. }
  1224. });
  1225.  
  1226.  
  1227.  
  1228. });
  1229. </script>
  1230.  
  1231.  
  1232. <script type="text/javascript">
  1233. $(document).ready(function() {
  1234. $("#add-biaya").on("click", function(event) {
  1235.  
  1236. var newRow = $("<tr>");
  1237. var cols = "";
  1238.  
  1239. cols += "<td><select name='jenis_biaya[]' id='jenis_biaya' class='form-control'>";
  1240. cols += "<option value='1'>Shipping</option>";
  1241. cols += "<option value='2'>Handling dan Packing</option>";
  1242. cols += "<option value='3'>Custom Clearance</option>";
  1243. cols += "<option value='4'>Loading</option>";
  1244. cols += "<option value='5'>Others</option>";
  1245. cols += "</select></td>";
  1246. cols += '<td><input class="form-control" type="text" name="keterangan[]" value=""></td>' ;
  1247. cols += '<td><input type="checkbox" class="form-check-input center" value="1" name="pdf[]"></td>' ;
  1248. cols += '<td><input type="file" name="file[]" id="file[]"></td>';
  1249. cols += '<td><input class="form-control" type="number" name="nominal[]" id="nominal" value=""></td>';
  1250. cols += "<td><a class='deleteRow'><img src='<?php echo base_url(); ?>assets/images/bin3.png' /> </a></td>";
  1251. cols += "</tr>";
  1252.  
  1253. newRow.append(cols);
  1254. $('table#tbl_biaya tbody').append(newRow);
  1255. });
  1256. $("table#tbl_biaya").on("click", "a.deleteRow", function(event) {
  1257. row = $(this).closest("tr");
  1258. var key = +row.find('input[name^="biaya_id"]').val();
  1259. if (key != null || !key) {
  1260. $.ajax({
  1261. async : false,
  1262. url: "<?php echo base_url('purchase/deleteBiaya/') ?>" + key,
  1263. type: "POST",
  1264. dataType: "JSON",
  1265. data: {
  1266. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1267. },
  1268. success: function (data) {
  1269. alert('Row Deleted');
  1270. }
  1271. });
  1272. }
  1273. $(this).closest("tr").remove();
  1274.  
  1275. });
  1276. });
  1277. </script>
  1278.  
  1279. <script type="text/javascript">
  1280. $(document).ready(function () {
  1281. $('#previewmodal').on('hidden.bs.modal', function () {
  1282. $("#view_table-body tr").remove();
  1283. $("#table-termin-body tr").remove();
  1284. $("#ptotal").text('');
  1285. $("#pdiscount").text('');
  1286. $("#pdiskonumum").text('');
  1287. $("#ptax").text('');
  1288. $("#pshipping").text('');
  1289. $("#pbalance").text('');
  1290. $("#pcurrency").text('');
  1291. $("#main").text('');
  1292. $("#cc").text('');
  1293. $("#ppaid_by").text('');
  1294. $("#preference_no").text('');
  1295. $("#ppurchase_date").text('');
  1296. $("#psupplier_name").text('');
  1297. $("#psupplier_address").text('');
  1298. $("#psupplier_city").text('');
  1299. $("#psupplier_mobile").text('');
  1300. $("#psupplier_email").text('');
  1301. $("#pcompany_name").text('');
  1302. $("#pwarehouse_name").text('');
  1303. $("#pbranch_address").text('');
  1304. $("#pbranch_city").text('');
  1305. $("#pcompany_phone").text('');
  1306. $("#company_email").text('');
  1307. $('#termin-other-value').text('');
  1308. });
  1309.  
  1310. $('#preview').on('click',function(){
  1311.  
  1312. var id_supplier =$('#supplier').val();
  1313. var upcc =$('#main').val();
  1314. var upcc2 =$('#cc').val();
  1315. var radios = document.getElementsByName('paymenterms');
  1316. var reference_no =$('#reference_no').val();
  1317. var date =$('#date').val();
  1318. var table_data = $('#table_data').val();
  1319. var ptotal =$('#totalValue').text();
  1320. var pdiscount =$('#totalDiscount').text();
  1321. var ptax =$('#totalTax').text();
  1322. var dfix =$('#totalDiskon').text();
  1323. var pshipping =$('#shipping_charge').text();
  1324. var pbalance =$('#grandTotal').text();
  1325. var pcurrency =$('#grandCurrency').text();
  1326. var othervalue =$('#others').text();
  1327. var counter = 1;
  1328. var product = new Array();
  1329.  
  1330.  
  1331. for (var i = 0, length = radios.length; i < length; i++)
  1332. {
  1333. if (radios[i].checked)
  1334. {
  1335. paid_by = radios[i].value;
  1336. break;
  1337. }
  1338. }
  1339.  
  1340. $("#ppaid_by").text(paid_by);
  1341. $("#pcurrency").text(pcurrency);
  1342. $("#pbalance").text(pbalance);
  1343. $("#ptax").text(ptax);
  1344. $("#pdiskonumum").text(dfix - pdiscount);
  1345. $("#pdiscount").text(pdiscount);
  1346. $("#ptotal").text(ptotal);
  1347. $("#ppurchase_date").text(date);
  1348. $("#preference_no").text(reference_no);
  1349.  
  1350. if (table_data) {
  1351. product = JSON.parse(table_data);
  1352. }
  1353.  
  1354. var array = $.map(product, function(value, index) {
  1355. return [value];
  1356. });
  1357.  
  1358. if (array.length > 0) {
  1359. for (a = 0; a < array.length; a++) {
  1360.  
  1361. var getnewRow;
  1362. var product_id = array[a].product_id;
  1363. var desc = array[a].desc;
  1364. var quantity = array[a].quantity;
  1365. var price = array[a].price;
  1366. var discount = array[a].discount;
  1367. var tax = array[a].tax;
  1368. $.ajax({
  1369. async : false,
  1370. url: "<?php echo base_url('sales/getProduct') ?>/" + product_id,
  1371. type: "GET",
  1372. dataType: "JSON",
  1373. data: {
  1374. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1375. },
  1376. success: function (data) {
  1377. var id = data[0].product_id;
  1378. var code = data[0].code;
  1379. var name = data[0].name;
  1380. var itembyp = data[0].item_namebyp;
  1381. var unit = data[0].unit;
  1382. var stock = data[0].quantity;
  1383.  
  1384. var newRow = $("<tr>");
  1385. var cols = "";
  1386. cols += "<td>" + counter + "</td>";
  1387. cols += "<td>" + code + "</td>";
  1388. cols += "<td>" + name + "</td>";
  1389. cols += "<td>" + itembyp + "</td>";
  1390. cols += "<td>" + desc + "</td>";
  1391. cols += "<td>" + quantity + "</td>";
  1392. cols += "<td>" + stock + "</td>";
  1393. cols += "<td>" + unit + "</td>";
  1394. cols += "<td>" + price + "</td>";
  1395. cols += "<td>" + (price * quantity) + "</td>";
  1396. cols += "<td>" + discount + "</td>";
  1397. cols += "<td>" + ((price * quantity) - discount) + "</td>";
  1398. cols += "<td>" + tax + "</td>";
  1399. cols += "<td>" + (((price * quantity) - discount) + tax) + "</td>";
  1400. cols += "</tr>";
  1401. newRow.append(cols);
  1402. getnewRow = newRow;
  1403. $("#view_table-body").append(newRow);
  1404. counter++;
  1405. }
  1406. });
  1407. }
  1408. }
  1409.  
  1410.  
  1411. if (id_supplier) {
  1412. $.ajax({
  1413. url : "<?php echo base_url('supplier/supplier/') ?>" + id_supplier,
  1414. type: "GET",
  1415. data: {
  1416. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1417. },
  1418. datatype: "JSON",
  1419. success: function (data)
  1420. {
  1421. supplier = JSON.parse(data);
  1422. var supplier_name = supplier[0].supplier_name;
  1423. var supplier_address = supplier[0].address;
  1424. var supplier_city = supplier[0].ciname;
  1425. var supplier_mobile = supplier[0].mobile;
  1426. var supplier_email = supplier[0].email;
  1427. $("#psupplier_name").text(supplier_name);
  1428. $("#psupplier_address").text(supplier_address);
  1429. $("#psupplier_city").text(supplier_city);
  1430. $("#psupplier_mobile").text(supplier_mobile);
  1431. $("#psupplier_email").text(supplier_email);
  1432.  
  1433. },
  1434. error: function (xhr, status, error)
  1435. {
  1436. alert(error);
  1437. }
  1438.  
  1439. });
  1440. }
  1441.  
  1442. $.ajax({
  1443. url : "<?php echo base_url('quotation/company/') ?>",
  1444. type: "GET",
  1445. data: {
  1446. '<?php echo $this->security->get_csrf_token_name(); ?>': '<?php echo $this->security->get_csrf_hash(); ?>'
  1447. },
  1448. datatype: "JSON",
  1449. success: function (data)
  1450. {
  1451. company = JSON.parse(data);
  1452. var company_name = company[0].name;
  1453. var company_city = company[0].city_name;
  1454. var company_country = company[0].country_name;
  1455. var company_address = company[0].billing_address;
  1456. var company_phone = company[0].phone;
  1457. var company_email = company[0].email;
  1458.  
  1459. $("#pcompany_name").text(company_name);
  1460. $("#pwarehouse_name").text(company_name);
  1461. $("#pbranch_address").text(company_address);
  1462. $("#pbranch_city").text(company_city);
  1463. $("#pcompany_phone").text(company_phone);
  1464. $("#pcompany_email").text(company_email);
  1465.  
  1466. },
  1467. error: function (xhr, status, error)
  1468. {
  1469. alert(error);
  1470. }
  1471.  
  1472. });
  1473.  
  1474. if (paid_by == 'advance') {
  1475. document.getElementById('termin-other').style.display = 'none';
  1476. document.getElementById('termin-bulan').style.display = 'none';
  1477. }
  1478. if (paid_by == 'termin') {
  1479. document.getElementById('termin-bulan').style.display = 'block';
  1480. document.getElementById('termin-other').style.display = 'none';
  1481.  
  1482. var termins =$('#terminnumber').val();
  1483.  
  1484.  
  1485.  
  1486. for (var i = 1, length = termins; i <= termins; i++)
  1487. {
  1488. var nominal = $('#terminvalue'+i).val();
  1489. var newRow = $("<tr>");
  1490. var cols = "";
  1491. cols += "<td>" + i + "</td>";
  1492. cols += "<td>" + ((nominal * pbalance)/100) + "</td>";
  1493. cols += "<td>" + nominal + "</td>";
  1494. cols += "</tr>";
  1495. newRow.append(cols);
  1496. getnewRow = newRow;
  1497. $("#table-termin-body").append(newRow);
  1498. }
  1499.  
  1500. }
  1501. if (paid_by == 'others') {
  1502. document.getElementById('termin-bulan').style.display = 'none';
  1503. document.getElementById('termin-other').style.display = 'block';
  1504. $('#termin-other-value').text(othervalue);
  1505. }
  1506. });
  1507. });
  1508.  
  1509. window.onload = function () {
  1510. changekurs();
  1511. }
  1512.  
  1513. function changekurs() {
  1514.  
  1515. var id = $('#kursdata').val();
  1516.  
  1517. $.ajax({
  1518. url: "<?php echo base_url('index.php/purchase/getCurrencyAjax') ?>/"+id,
  1519. type: "GET",
  1520. data:{
  1521. '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>'
  1522. },
  1523. datatype: "JSON",
  1524. success: function(d)
  1525. {
  1526. data = JSON.parse(d);
  1527. var nominalkurs=data[0].nominal;
  1528. var symbolkurs=data[0].symbol;
  1529.  
  1530. showKurs(nominalkurs, symbolkurs);
  1531.  
  1532. },
  1533. error: function(xhr, status, error)
  1534. {
  1535. alert(error);
  1536. }
  1537.  
  1538. });
  1539. }
  1540.  
  1541. function showKurs(kurs, symbol){
  1542. document.getElementById('currency').style.display ='block';
  1543.  
  1544. $('#ckurs').val(kurs);
  1545. $('#symbol').val(symbol);
  1546. calculateGrandTotal();
  1547. }
  1548.  
  1549. function isNumber(evt) {
  1550. evt = (evt) ? evt : window.event;
  1551. var charCode = (evt.which) ? evt.which : evt.keyCode;
  1552. if (charCode > 31 && (charCode < 48 || charCode > 57)) {
  1553. return true;
  1554. }
  1555. return true;
  1556. }
  1557.  
  1558. function isNumber_max_100(evt) {
  1559. evt = (evt) ? evt : window.event;
  1560. var charCode = (evt.which) ? evt.which : evt.keyCode;
  1561. if (charCode > 31 && (charCode < 48 || charCode > 57)) {
  1562. return false;
  1563. }
  1564. getvarhit = hitung;
  1565. get_nax_100(getvarhit);
  1566. return true;
  1567. }
  1568.  
  1569. function calculateGrandTotal()
  1570. {
  1571. var totalValue = 0;
  1572. var totalDiscount = 0;
  1573. var grandTax = 0;
  1574. var grandTotal = 0;
  1575.  
  1576. $("table.product_table").find('input[name^="linetotal"]').each(function () {
  1577. totalValue += +$(this).val();
  1578. });
  1579. $("table.product_table").find('input[name^="hidden_discount"]').each(function () {
  1580. totalDiscount += +$(this).val();
  1581. });
  1582.  
  1583. $("table.product_table").find('input[name^="product_total"]').each(function () {
  1584. grandTotal += +$(this).val();
  1585. });
  1586.  
  1587. var totaldiskon = 0;
  1588. var diskonval = 0;
  1589. var diskonval2 = 0;
  1590. var diskonpersen = 0;
  1591. grandDiskon = totalDiscount;
  1592. diskonpersen = +$('#diskonpersen_text').val();
  1593. diskonval2 = totalValue - totalDiscount;
  1594. diskonval = (diskonpersen / 100) * diskonval2;
  1595. grandDiskon += diskonval;
  1596. grandDiskon += +$('#diskon_text').val();
  1597. $('Span#totalDiskon').text(grandDiskon);
  1598. $('#totalDiscountUmum').text(grandDiskon.toFixed(2));
  1599. $('#totalDiscountUmum').val(grandDiskon.toFixed(2));
  1600. totaldiskon = grandDiskon;
  1601. grandTotal = grandTotal - totaldiskon;
  1602.  
  1603. var taxx = $('#taxx').val();
  1604. grandTax = (totalValue - totaldiskon) * (taxx / 100);
  1605. grandTotal = totalValue - totaldiskon + grandTax;
  1606.  
  1607. var symbol = $('#symbol').val();
  1608. var kurs = $('#ckurs').val();
  1609.  
  1610. var totalkurs=(grandTotal*kurs);
  1611.  
  1612. $('#kurs_symbol').text(symbol);
  1613. $('#kurs_symbol1').text(symbol);
  1614. $('#kurs_symbol2').text(symbol);
  1615. $('#kurs_symbol3').text(symbol);
  1616. $('#kurs_symbol4').text(symbol);
  1617. $('#kurs_symbol5').text(symbol);
  1618. $('#kurs_symbol6').text(symbol);
  1619. $('#grandCurrency').text("Rp. "+totalkurs.toFixed(2));
  1620. $('#grandCurrency').val("Rp. "+totalkurs.toFixed(2));
  1621. $('#grand_currency').val(totalkurs.toFixed(2));
  1622.  
  1623. $('#totalValue').text(totalValue);
  1624. $('#total_value').val(totalValue);
  1625. $('#totalDiscount').text(totalDiscount.toFixed(2));
  1626. $('#total_discount').val(totaldiskon); //OKE
  1627. $('#totalTax').text(grandTax.toFixed(2)); //OKE
  1628. $('#total_tax').val(grandTax.toFixed(2));
  1629. $('#grandTotal').text(grandTotal.toFixed(2));
  1630. $('#grand_total').val(grandTotal.toFixed(2));
  1631. }
  1632.  
  1633. function calculateRow(row) {
  1634. var key = +row.find('input[name^="id"]').val();
  1635. var price = +row.find('input[name^="price"]').val();
  1636. var qty = +row.find('input[name^="qty"]').val();
  1637. var desc = +row.find('input[name^="description"]').val();
  1638. var product_id = +row.find('input[name^="product_id"]').val();
  1639. row.find('input[name^="linetotal"]').val((price * qty).toFixed(2));
  1640. if(product_data[key]==null){
  1641. var temp = {
  1642. "product_id" : product_id,
  1643. "cost" : price,
  1644. "quantity" : qty,
  1645. "total" : (price * qty).toFixed(2)
  1646. };
  1647. product_data[key] = temp;
  1648. }
  1649. product_data[key].price = price;
  1650. product_data[key].desc = desc;
  1651. product_data[key].quantity = qty;
  1652. product_data[key].total = (price * qty).toFixed(2);
  1653. var table_data = JSON.stringify(product_data);
  1654. $('#table_data').val(table_data);
  1655. }
  1656.  
  1657. function calculateDiscount(row,data = 0){
  1658. var discount;
  1659.  
  1660. if(data == 0 ){
  1661. discount = +row.find('#discount_value').val();
  1662. }
  1663. else{
  1664. discount = data;
  1665. }
  1666.  
  1667. var sales_total = +row.find('input[name^="linetotal"]').val();
  1668. var total_discount = sales_total*discount/100;
  1669.  
  1670. row.find('#product_total').val(sales_total - total_discount);
  1671.  
  1672. row.find('#hidden_discount').val(total_discount);
  1673.  
  1674.  
  1675. var key = +row.find('input[name^="id"]').val();
  1676. product_data[key].discount = total_discount;
  1677. product_data[key].discount_value = +row.find('#discount_value').val();
  1678. product_data[key].discount_id = +row.find('#item_discount').val();
  1679.  
  1680. var table_data = JSON.stringify(product_data);
  1681. $('#table_data').val(table_data);
  1682. }
  1683.  
  1684. function calculateGrandTotal2()
  1685. {
  1686. var totalBiaya = 0;
  1687. $("table#tbl_biaya").find('input[name^="nominal"]').each(function () {
  1688. totalBiaya += +$(this).val();
  1689. });
  1690. $('#biayaTotal').val(totalBiaya.toFixed(2));
  1691. $('#totalBiaya').text(totalBiaya.toFixed(2));
  1692. }
  1693. </script>
  1694. <?php
  1695. $this->load->view('layout/product_footer');
  1696. ?>
  1697.  
  1698. <div id="previewmodal" class="modal fade" role="dialog">
  1699. <div class="modal-dialog modal-lg">
  1700. <!-- Modal content-->
  1701. <div class="modal-content">
  1702. <div class="modal-header">
  1703. <button type="button" class="close" data-dismiss="modal">&times;</button>
  1704. <h4>
  1705. Preview Data
  1706. </h4>
  1707. </div>
  1708. <div class="modal-body">
  1709. <div class="control-group">
  1710. <div class="controls">
  1711. <div class="tabbable">
  1712. <div class="box-body">
  1713. <div class="col-sm-12 well well-sm">
  1714. <div class="col-sm-5">
  1715. <div class="col-sm-2">
  1716. <i class="fa fa-3x fa-truck padding010 text-muted"></i>
  1717. </div>
  1718. <div class="col-sm-10">
  1719. <b><h4><span id="pcompany_name"></span></h4></b>
  1720. <br>
  1721. <span id="pwarehouse_name"></span>
  1722. <br>
  1723. <span id="pbranch_address"></span>
  1724. <br>
  1725. <span id="pbranch_city"></span>
  1726. <br><br>
  1727. <?php echo $this->lang->line('purchase_mobile')." : ";?> <span id="pcompany_phone"></span>
  1728. <br>
  1729. <?php echo $this->lang->line('company_setting_email')." : ";?><span id="pcompany_email"></span>
  1730. </div>
  1731. </div>
  1732. <div class="col-md-4">
  1733. <div class="col-sm-2">
  1734. <i class="fa fa-3x fa-building padding010 text-muted"></i>
  1735. </div>
  1736. <div class="col-sm-10">
  1737. <b><h4><span id="psupplier_name"></span></h4></b>
  1738. <br>
  1739. <span id="psupplier_address"></span>
  1740. <br>
  1741. <span id="psupplier_city"></span>
  1742. <br><br>
  1743. <?php echo $this->lang->line('purchase_mobile')." : "; ?><span id="psupplier_mobile"></span>
  1744. <br>
  1745. <?php echo $this->lang->line('company_setting_email')." : "; ?><span id="psupplier_email"></span>
  1746. </div>
  1747. </div>
  1748. <div class="col-md-3">
  1749. <div class="col-sm-3">
  1750. <i class="fa fa-3x fa-file-text-o padding010 text-muted"></i>
  1751. </div>
  1752. <div class="col-sm-9">
  1753. <b><h4><span id="preference_no"></span></h4></b>
  1754. <br>
  1755. <b><?php echo $this->lang->line('purchase_date')." : "; ?><span id="ppurchase_date"></span></b>
  1756. <br>
  1757. Peyment Terms : <span id="ppaid_by"></span>
  1758. </div>
  1759. </div>
  1760. </div>
  1761. <div class="col-sm-12" style="overflow-y: auto;">
  1762. <table class="table table-hover table-bordered">
  1763. <thead>
  1764. <tr>
  1765. <th width="3%">No</th>
  1766. <th class="span2" width="5%">Part Number</th>
  1767. <th class="span2" width="8%">Item Name</th>
  1768. <th class="span2" width="10%">Vendor or Item Name</th>
  1769. <th class="span2" width="8%">Description</th>
  1770. <th class="span2" width="8%">Qty</th>
  1771. <th class="span2" width="5%">Stock</th>
  1772. <th class="span2" width="5%">UOM</th>
  1773. <th class="span2" width="8%">Price</th>
  1774. <th class="span2" width="8%">Sales Total</th>
  1775. <th class="span2" width="8%">Discount</th>
  1776. <th class="span2" width="8%">Taxable Value</th>
  1777. <th class="span2" width="8%">Tax</th>
  1778. <th class="span2" width="8%">Total</th>
  1779. </tr>
  1780. </thead>
  1781. <tbody id="view_table-body" class="view_table-body">
  1782. </tbody>
  1783. <tfoot>
  1784. <tr>
  1785. <td colspan="11" align="right"><b><?php echo $this->lang->line('purchase_total_value'); ?></b></td>
  1786. <td align="right" colspan="3"><?php echo $this->session->userdata('symbol'); ?>
  1787. <span id="ptotal"></span>
  1788. </td>
  1789. </tr>
  1790.  
  1791. <tr>
  1792. <td colspan="11" align="right"><b><?php echo $this->lang->line('purchase_total_discount'); ?></b></td>
  1793. <td align="right" colspan="3"><?php echo $this->session->userdata('symbol');?><span id="pdiscount"></span></td>
  1794. </tr>
  1795. <tr>
  1796. <td colspan="11" align="right"><b><?php echo "Total Diskon Umum"; ?></b></td>
  1797. <td align="right" colspan="3"><?php echo $this->session->userdata('symbol');?><span id="pdiskonumum"></span></td>
  1798. </tr>
  1799. <tr>
  1800. <td colspan="11" align="right"><b><?php echo $this->lang->line('purchase_total_tax'); ?></b></td>
  1801. <td align="right" colspan="3"><?php echo $this->session->userdata('symbol');?><span id="ptax"></span></td>
  1802. </tr>
  1803.  
  1804. <tr>
  1805. <td colspan="11" align="right"><b><?php echo $this->lang->line('purchase_total_amount'); ?></b></td>
  1806. <td align="right" colspan="7"><?php echo $this->session->userdata('symbol'); ?><span id="pbalance"></span></td>
  1807. </tr>
  1808.  
  1809. <tr>
  1810. <td colspan="11" align="right"><b><?php echo "Currency Total "; ?></b></td>
  1811. <td align="right" colspan="3"><?php echo $this->session->userdata('symbol'); ?><span id="pcurrency"></span></td>
  1812. </tr>
  1813. </tfoot>
  1814. </table>
  1815. </div>
  1816.  
  1817. <div class="col-sm-12" style="overflow-y: auto; display: none;" id="termin-bulan" >
  1818. <h3 class="box-title"><?php echo "Termin Details"; ?></h3>
  1819. <table class="table table-hover table-bordered table-termin">
  1820. <thead>
  1821. <th style="text-align: center;"><?php echo "No"; ?></th>
  1822. <th width="40%"><?php echo "Nominal"; ?></th>
  1823. <th width="10%"><?php echo "Tanggal Bayar"; ?></th>
  1824.  
  1825. </thead>
  1826. <tbody id="table-termin-body">
  1827. </tbody>
  1828. </table>
  1829. </div>
  1830.  
  1831. <div class="col-sm-12" style="overflow-y: auto; display: none;" id="termin-other">
  1832. <h3 class="box-title"><?php echo "Termin Details"; ?></h3>
  1833. <span id="termin-other-value"></span>
  1834. </div>
  1835.  
  1836. </div>
  1837. </div>
  1838. </div>
  1839. </div> <!-- /controls -->
  1840. </div> <!-- /control-group -->
  1841. </div>
  1842. </div>
  1843. </div>
RAW Paste Data