Server IP : 164.52.202.56 / Your IP : 216.73.216.204 Web Server : Apache System : Linux e2e-70-56.ssdcloudindia.net 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Tue Nov 5 04:50:16 EST 2024 x86_64 User : rubyaromatics ( 1052) PHP Version : 7.2.34 Directory (0755) : /home/rubyaromatics/public_html/crm/application/views/warehouse/../purchase/ |
[ Home ] | [ Terminal ] | [ Upload File ] |
---|
<?php defined('BASEPATH') OR exit('No direct script access allowed'); $p = array('admin','purchaser','manager'); if(!(in_array($this->session->userdata('type'),$p))){ redirect('auth'); } $this->load->view('layout/header'); ?> <!-- Content Wrapper. Contains page content --> <div class="content-wrapper"> <!-- Content Header (Page header) --> <section class="content-header"> <h5> <ol class="breadcrumb"> <li><a href="<?php echo base_url('auth/dashboard'); ?>"><i class="fa fa-dashboard"></i> <?php echo $this->lang->line('header_dashboard'); ?></a></li> <li><a href="<?php echo base_url('purchase'); ?>"><?php echo $this->lang->line('header_purchase'); ?></a></li> <li class="active"><?php echo $this->lang->line('purchase_add_purchase'); ?></li> </ol> </h5> </section> <!-- Main content --> <section class="content"> <div class="row"> <!-- right column --> <div class="col-sm-12"> <div class="box"> <div class="box-header with-border"> <h3 class="box-title"><?php echo $this->lang->line('purchase_add_new_purchase'); ?></h3> </div> <!-- /.box-header --> <div class="box-body"> <div class="row"> <form role="form" id="form" method="post" action="<?php echo base_url('purchase/addPurchase');?>"> <div class="col-sm-6"> <div class="form-group"> <label for="date"><?php echo $this->lang->line('purchase_date'); ?><span class="validation-color">*</span></label> <input type="text" class="form-control datepicker" id="date" name="date" value="<?php echo date("Y-m-d"); ?>"> <span class="validation-color" id="err_date"><?php echo form_error('date'); ?></span> </div> <?php if($reference_no==null){ $no = sprintf('%06d',intval(1)); } else{ foreach ($reference_no as $value) { $no = sprintf('%06d',intval($value->purchase_id)+1); } } ?> <div class="form-group"> <label for="reference_no"><?php echo $this->lang->line('purchase_reference_no'); ?><span class="validation-color">*</span></label> <input type="text" class="form-control" id="reference_no" name="reference_no" value="RE-<?php echo $no;?>" readonly> <span class="validation-color" id="err_reference_no"><?php echo form_error('reference_no'); ?></span> </div> </div> <div class="col-sm-6"> <div class="form-group"> <label for="warehouse"><?php echo $this->lang->line('purchase_select_warehouse'); ?><span class="validation-color">*</span></label> <select class="form-control select2" id="warehouse" name="warehouse" style="width: 100%;"> <option value=""><?php echo $this->lang->line('product_select'); ?></option> <?php foreach ($warehouse as $row) { echo "<option value='$row->warehouse_id'".set_select('warehouse_id',$row->warehouse_id).">$row->warehouse_name</option>"; } ?> </select> <span class="validation-color" id="err_warehouse"><?php echo form_error('warehouse'); ?></span> </div> <div class="form-group"> <label for="supplier"><?php echo $this->lang->line('purchase_select_supplier'); ?> <span class="validation-color">*</span></label> <select class="form-control select2" id="supplier" name="supplier" style="width: 100%;"> <option value=""><?php echo $this->lang->line('product_select'); ?></option> <?php foreach ($supplier as $row) { echo "<option value='$row->supplier_id'".set_select('supplier_id',$row->supplier_id).">$row->supplier_name</option>"; } ?> </select> <span class="validation-color" id="err_supplier"><?php echo form_error('supplier'); ?></span> </div> </div> <div class="col-sm-12"> <br><br><br><br> <div class="col-sm-2"></div> <div class="col-sm-5"> <div class="form-group"> <select class="form-control select2" id="product" name="product" style="width: 100%;"> <option value=""><?php echo $this->lang->line('purchase_select_product'); ?></option> <?php foreach ($product as $value) { echo "<option value='$value->product_id'".set_select('product_id',$value->product_id).">$value->name ($value->code)</option>"; } ?> </select> </div> <!--/form group --> </div> <!--/col-md-6 --> <div class="col-sm-4"> <span class="validation-color" id="err_product"></span> </div> </div> <!--/col-md-12 --> <div class="col-sm-12"> <div class="form-group"> <label><?php echo $this->lang->line('purchase_inventory_items'); ?></label> <div style="overflow-y: auto;"> <table class="table items table-striped table-bordered table-condensed table-hover product_table" name="product_data" id="product_data"> <thead> <tr> <th style="width: 20px;"><img src="<?php echo base_url(); ?>assets/images/bin1.png" /></th> <th class="span2"><?php echo $this->lang->line('product_code'); ?></th> <th class="span2"><?php echo $this->lang->line('purchase_product_description'); ?></th> <th class="span2"><?php echo $this->lang->line('product_hsn_sac_code'); ?></th> <th class="span2" width="10%"><?php echo $this->lang->line('product_quantity'); ?></th> <th class="span2"><?php echo $this->lang->line('product_available_quantity'); ?></th> <th class="span2"><?php echo $this->lang->line('product_unit'); ?></th> <th class="span2"><?php echo $this->lang->line('product_price'); ?></th> <th class="span2" width="10%"><?php echo $this->lang->line('purchase_sub_total'); ?></th> <th class="span2" width="15%"><?php echo $this->lang->line('header_discount'); ?></th> <th class="span2"><?php echo $this->lang->line('purchase_taxable_value'); ?></th> <th class="span2" width="15%"><?php echo $this->lang->line('header_tax'); ?></th> <th class="span2" width="10%"><?php echo $this->lang->line('purchase_total'); ?></th> </tr> </thead> <tbody> </tbody> </table> </div> <input type="hidden" name="total_value" id="total_value"> <input type="hidden" name="total_discount" id="total_discount"> <input type="hidden" name="total_tax" id="total_tax"> <input type="hidden" name="grand_total" id="grand_total"> <input type="hidden" name="table_data" id="table_data"> <table class="table table-striped table-bordered table-condensed table-hover"> <tr> <td align="right" width="80%"><?php echo $this->lang->line('purchase_total_value'); ?></td> <td align='right'><?php echo $this->session->userdata('symbol'); ?><span id="totalValue"> 0.00</span></td> </tr> <tr> <td align="right"><?php echo $this->lang->line('purchase_total_discount'); ?></td> <td align='right'><?php echo $this->session->userdata('symbol'); ?> <span id="totalDiscount"> 0.00</span> </td> </tr> <tr> <td align="right"><?php echo $this->lang->line('purchase_total_tax'); ?></td> <td align='right'><?php echo $this->session->userdata('symbol'); ?> <span id="totalTax"> 0.00</span> </td> </tr> <tr> <td align="right"><?php echo $this->lang->line('purchase_total'); ?></td> <td align='right'><?php echo $this->session->userdata('symbol'); ?><span id="grandTotal"> 0.00</span></td> </tr> </table> </div> </div> <div class="col-sm-12"> <div class="form-group"> <label for="note"><?php echo $this->lang->line('purchase_note'); ?></label> <textarea class="form-control" id="note" name="note"><?php echo set_value('details'); ?></textarea> <span class="validation-color" id="err_details"><?php echo form_error('details'); ?></span> </div> </div> </div> <div class="col-sm-12"> <div class="box-footer"> <button type="submit" id="submit" class="btn btn-info"> <?php echo $this->lang->line('product_add'); ?> </button> <span class="btn btn-default" id="cancel" style="margin-left: 2%" onclick="cancel('purchase')"><?php echo $this->lang->line('product_cancel'); ?></span> </div> </div> </form> </div> <!-- /.box-body --> </div> <!--/.col (right) --> </div> <!-- /.row --> </section> <!-- /.content --> </div> <!-- /.content-wrapper --> <?php $this->load->view('layout/footer'); ?> <script> $(document).ready(function(){ var i = 0; var product_data = new Array(); var counter = 1; $('#product').change(function(){ var id = $('#product').val(); $('#err_product').text(''); var flag = 0; if(id != ""){ $.ajax({ url: "<?php echo base_url('purchase/getProductAjax') ?>/"+id, type: "GET", data:{ '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>' }, datatype: "JSON", success: function(d){ data = JSON.parse(d); //alert(data); // alert(data[0]['product_id']); $("table.product_table").find('input[name^="product_id"]').each(function () { if(data[0].product_id == +$(this).val()){ flag = 1; } }); if(flag == 0){ var id = data[0].product_id; var code = data[0].code; var hsn_sac_code = data[0].hsn_sac_code; var name = data[0].name; var price = data[0].cost var product = { "product_id" : id, "cost" :price }; product_data[i] = product; length = product_data.length - 1 ; var select_discount = ""; select_discount += '<div class="form-group">'; select_discount += '<select class="form-control select2" id="item_discount" name="item_discount" style="width: 100%;">'; select_discount += '<option value="">Select</option>'; for(a=0;a<data['discount'].length;a++){ select_discount += '<option value="' + data['discount'][a].discount_id + '">' + data['discount'][a].discount_name+'('+data['discount'][a].discount_value +'%)'+ '</option>'; } select_discount += '</select></div>'; var select_tax = ""; select_tax += '<div class="form-group">'; select_tax += '<select class="form-control select2" id="item_tax" name="item_tax" style="width: 100%;">'; select_tax += '<option value="">Select</option>'; for(b=0;b<data['tax'].length;b++){ select_tax += '<option value="' + data['tax'][b].tax_id + '">' + data['tax'][b].tax_name+ '</option>'; } select_tax += '</select></div>'; var newRow = $("<tr>"); var cols = ""; cols += "<td><a class='deleteRow'> <img src='<?php echo base_url(); ?>assets/images/bin3.png' /> </a><input type='hidden' name='id' name='id' value="+i+"><input type='hidden' name='product_id' name='product_id' value="+id+"></td>"; cols += "<td>"+code+"</td>"; cols += "<td>"+name+"</td>"; cols += "<td>"+hsn_sac_code+"</td>"; cols += "<td>" +"<input type='number' class='form-control text-center' value='0' data-rule='quantity' min='1' name='qty"+ counter +"' id='qty"+ counter +"' >" +"</td>"; cols += "<td align='right'>"+data[0].quantity+"</td>"; cols += "<td>"+data[0].unit+"</td>"; cols += "<td align='right'>" +"<span id='price'>" +"<input type='hidden' name='price"+ counter +"' id='price"+ counter +"' value='"+price +"'>"+price +"</span>" +"</td>"; 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>"; cols += '<td><input type="hidden" id="discount_value" name="discount_value"><input type="hidden" id="hidden_discount" name="hidden_discount">'+select_discount+'</td>'; cols += '<td align="right"><span id="taxable_value"></span></td>'; cols += '<td><input type="hidden" id="tax_value" name="tax_value"><input type="hidden" id="hidden_tax" name="hidden_tax">'+select_tax+'</td>'; cols += '<td><input type="text" class="form-control text-right" id="product_total" name="product_total" readonly></td>'; cols += "</tr>"; counter++; newRow.append(cols); $("table.product_table").append(newRow); var table_data = JSON.stringify(product_data); $('#table_data').val(table_data); i++; } else{ $('#err_product').text('Product Already Added').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000); } /*var quantity = $('input[name^="quantity"]').val(); var price = $('input[name^="price"]').val();*/ }, error: function(xhr, status, error) { $('#err_product').text('Enter Product Code / Name').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000); } }); } }); $("table.product_table").on("click", "a.deleteRow", function (event) { deleteRow($(this).closest("tr")); $(this).closest("tr").remove(); calculateGrandTotal(); }); function deleteRow(row){ var id = +row.find('input[name^="id"]').val(); var array_id = product_data[id].product_id; //product_data.splice(id, 1); product_data[id] = null; //alert(product_data); var table_data = JSON.stringify(product_data); $('#table_data').val(table_data); } $("table.product_table").on("change", 'input[name^="price"], input[name^="qty"]', function (event) { calculateRow($(this).closest("tr")); calculateDiscountTax($(this).closest("tr")); calculateGrandTotal(); }); $("table.product_table").on("change",'#item_discount',function (event) { var row = $(this).closest("tr"); var discount = +row.find('#item_discount').val(); if(discount != ""){ $.ajax({ url: '<?php echo base_url('purchase/getDiscountValue/') ?>'+discount, type: "GET", data:{ '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>' }, datatype: JSON, success: function(value){ data = JSON.parse(value); row.find('#discount_value').val(data[0].discount_value); calculateDiscountTax(row,data[0].discount_value); calculateGrandTotal(); } }); } else{ row.find('#discount_value').val('0'); calculateDiscountTax(row,0); calculateGrandTotal(); } }); $("table.product_table").on("change",'#item_tax',function (event) { var row = $(this).closest("tr"); var tax = +row.find('#item_tax').val(); if(tax != ""){ $.ajax({ url: '<?php echo base_url('purchase/getTaxValue/') ?>'+tax, type: "GET", data:{ '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>' }, datatype: JSON, success: function(value){ data = JSON.parse(value); row.find('#tax_value').val(data[0].purchase_tax_value); calculateDiscountTax(row,0,data[0].purchase_tax_value); calculateGrandTotal(); } }); } else{ row.find('#tax_value').val('0'); calculateDiscountTax(row,0,0); calculateGrandTotal(); } }); function calculateDiscountTax(row,data = 0,data1 = 0){ var discount; var tax; if(data == 0 ){ discount = +row.find('#discount_value').val(); } else{ discount = data; } if(data1 == 0 ){ tax = +row.find('#tax_value').val(); } else{ tax = data1; } var sales_total = +row.find('input[name^="linetotal"]').val(); var total_discount = sales_total*discount/100; var taxable_value = sales_total - total_discount; row.find('#taxable_value').text(taxable_value); var total_tax = taxable_value*tax/100; row.find('#product_total').val(taxable_value + total_tax); row.find('#hidden_discount').val(total_discount); row.find('#hidden_tax').val(total_tax); var key = +row.find('input[name^="id"]').val(); product_data[key].discount = total_discount; product_data[key].discount_value = +row.find('#discount_value').val(); product_data[key].discount_id = +row.find('#item_discount').val(); product_data[key].tax = total_tax; product_data[key].tax_value = +row.find('#tax_value').val(); product_data[key].tax_id = +row.find('#item_tax').val(); var table_data = JSON.stringify(product_data); $('#table_data').val(table_data); } function calculateRow(row) { var key = +row.find('input[name^="id"]').val(); var price = +row.find('input[name^="price"]').val(); var qty = +row.find('input[name^="qty"]').val(); row.find('input[name^="linetotal"]').val((price * qty).toFixed(2)); product_data[key].quantity = qty; product_data[key].total = (price * qty).toFixed(2); var table_data = JSON.stringify(product_data); $('#table_data').val(table_data); } function calculateGrandTotal() { var totalValue = 0; var totalDiscount = 0; var grandTax = 0; var grandTotal = 0; $("table.product_table").find('input[name^="linetotal"]').each(function () { totalValue += +$(this).val(); }); $("table.product_table").find('input[name^="hidden_discount"]').each(function () { totalDiscount += +$(this).val(); }); $("table.product_table").find('input[name^="hidden_tax"]').each(function () { grandTax += +$(this).val(); }); $("table.product_table").find('input[name^="product_total"]').each(function () { grandTotal += +$(this).val(); }); $('#totalValue').text(totalValue); $('#total_value').val(totalValue); $('#totalDiscount').text(totalDiscount.toFixed(2)); $('#total_discount').val(totalDiscount.toFixed(2)); $('#totalTax').text(grandTax.toFixed(2)); $('#total_tax').val(grandTax.toFixed(2)); $('#grandTotal').text(grandTotal.toFixed(2)); $('#grand_total').val(grandTotal.toFixed(2)); } }); </script> <script> $(document).ready(function(){ $("#submit").click(function(event){ var name_regex = /^[a-zA-Z]+$/; var sname_regex = /^[a-zA-Z0-9]+$/; var num_regex = /^[0-9]+$/; var date_regex = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/; var date = $('#date').val(); var warehouse = $('#warehouse').val(); var supplier = $('#supplier').val(); var grand_total = $('#grand_total').val(); if(date==null || date==""){ $("#err_date").text("Please Enter Date"); $('#date').focus(); return false; } else{ $("#err_date").text(""); } if (!date.match(date_regex) ) { $('#err_date').text(" Please Enter Valid Date "); $('#date').focus(); return false; } else{ $("#err_date").text(""); } //date codevalidation complite. if(warehouse==""){ $("#err_warehouse").text("Please Enter Warehouse"); $('#warehouse').focus(); return false; } else{ $("#err_warehouse").text(""); } //warehouse code validation complite. if(supplier==""){ $("#err_supplier").text("Please Enter Supplier"); $('#supplier').focus(); return false; } else{ $("#err_supplier").text(""); } //supplier code validation complite. if(grand_total=="" || grand_total==null || grand_total==0.00){ $("#err_product").text("Please Select Product OR Product Quantity is less than 0"); $('#product').focus(); return false; } }); $("#date").blur(function(event){ var date = $('#date').val(); var date_regex = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/; if(date==null || date==""){ $("#err_date").text("Please Enter Date"); $('#date').focus(); return false; } else{ $("#err_date").text(""); } if (!date.match(date_regex) ) { $('#err_date').text(" Please Enter Valid Date "); $('#date').focus(); return false; } else{ $("#err_date").text(""); } }); $("#warehouse").change(function(event){ var warehouse = $('#warehouse').val(); if(warehouse==""){ $("#err_warehouse").text("Please Enter Warehouse"); $('#warehouse').focus(); return false; } else{ $("#err_warehouse").text(""); } }); $("#supplier").change(function(event){ var supplier = $('#supplier').val(); if(supplier==""){ $("#err_supplier").text("Please Enter Supplier"); $('#supplier').focus(); return false; } else{ $("#err_supplier").text(""); } }); }); </script>