Server IP : 164.52.202.56 / Your IP : 216.73.216.208 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/sales/ |
[ Home ] | [ Terminal ] | [ Upload File ] |
---|
<?php defined('BASEPATH') OR exit('No direct script access allowed'); $p = array('admin','sales_person','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('sales'); ?>"><?php echo $this->lang->line('header_sales'); ?></a></li> <li class="active"><?php echo $this->lang->line('sales_add_sales'); ?></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('sales_add_new_sales'); ?></h3> </div> <!-- /.box-header --> <div class="box-body"> <div class="row"> <form role="form" id="form" method="post" action="<?php echo base_url('sales/addSales');?>"> <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('%04d',intval(1)); } else{ foreach ($reference_no as $value) { $no = sprintf('%04d',intval($value->sales_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="19-20-<?php echo $no;?>" > <span class="validation-color" id="err_reference_no"><?php echo form_error('reference_no'); ?></span> </div> <!--<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'>$row->warehouse_name</option>"; } ?> </select> <span class="validation-color" id="err_warehouse"><?php echo form_error('warehouse');?></span> </div> --> <input type="hidden" id="warehouse" value='1' name="warehouse"> <input type="hidden" id="biller" name="biller" value='1'"> <div class="form-group"> <label for="customer"><?php echo $this->lang->line('sales_select_customer'); ?> <span class="validation-color">*</span></label> <select class="form-control select2" id="customer" name="customer" style="width: 100%;"> <option value=""><?php echo $this->lang->line('product_select'); ?></option> <?php foreach ($customer as $row) { echo "<option value='$row->customer_id'>$row->company_name</option>"; } ?> </select> <a href="" data-toggle="modal" data-target="#myModal">Add New Customer </a> <span class="validation-color" id="err_customer"><?php echo form_error('customer');?></span> </div> <div class="form-group"> <label for="gr_num">RR/GR Number:<span class="validation-color">*</span></label> <input type="text" class="form-control" id="gr_num" name="gr_num" > </div> <div class="form-group"> <label for="gr_date">RR/GR Date:<span class="validation-color">*</span></label> <input type="text" class="form-control datepicker" id="gr_date" name="gr_date" > </div> <div class="form-group"> <label for="shipping_charge">Shipping Charge</label> <input type="text" class="form-control text-right" id="shipping_charge" name="shipping_charge" value="<?php echo set_value('shipping_charge'); ?>"> <span class="validation-color" id="err_shipping_charge"><?php echo form_error('shipping_charge'); ?></span> </div> <div class="form-group"> <input type="checkbox" name="transporter" id="transporter" onchange="transport()"> <label> Enable Transport Details</label> </div> <div class="transporter"> <div class="form-group"> <label for="mode_of_transport">Mode of Transport</label> <input type="text" class="form-control" id="mode_of_transport" name="mode_of_transport" value="<?php echo set_value('mode_of_transport'); ?>"> <span class="validation-color" id="err_mode_of_transport"><?php echo form_error('mode_of_transport'); ?></span> </div> <div class="form-group"> <label for="transporter_name">Transporter Name</label> <input type="text" class="form-control" id="transporter_name" name="transporter_name" value="<?php echo set_value('transporter_name'); ?>"> <span class="validation-color" id="err_transporter_name"><?php echo form_error('transporter_name'); ?></span> </div> <div class="form-group"> <label for="transporter_code">Transporter Code</label> <input type="text" class="form-control" id="transporter_code" name="transporter_code" value="<?php echo set_value('transporter_code'); ?>"> <span class="validation-color" id="err_transporter_code"><?php echo form_error('transporter_code'); ?></span> </div> <div class="form-group"> <label for="vehicle_regn_no">Vehicle Regn No.</label> <input type="text" class="form-control" id="vehicle_regn_no" name="vehicle_regn_no" value="<?php echo set_value('vehicle_regn_no'); ?>"> <span class="validation-color" id="err_vehicle_regn_no"><?php echo form_error('vehicle_regn_no'); ?></span> </div> </div> <script> $('.transporter').hide(); </script> </div> <div class="col-sm-6"> <div class="well well-small"> <h4>Shipping Address</h4><br> <div class="form-group"> <label for="country"><!-- Country --> <?php echo $this->lang->line('biller_lable_country'); ?> <span class="validation-color">*</span> </label> <select class="form-control select2" id="country" name="country" style="width: 100%;"> <option value=""> <!-- Select --> <?php echo $this->lang->line('add_biller_select'); ?> </option> </select> <span class="validation-color" id="err_country"><?php echo form_error('country'); ?></span> </div> <div class="form-group"> <label for="state"><!-- State --> <?php echo $this->lang->line('add_biller_state'); ?> <span class="validation-color">*</span> </label> <select class="form-control select2" id="state" name="state" style="width: 100%;"> <option value=""><!-- Select --> <?php echo $this->lang->line('add_biller_select'); ?> </option> </select> <span class="validation-color" id="err_state"><?php echo form_error('state'); ?></span> </div> <div class="form-group"> <label for="city"><!-- City --> <?php echo $this->lang->line('biller_lable_city'); ?> <span class="validation-color">*</span> </label> <select class="form-control select2" id="city" name="city" style="width: 100%;"> <option value=""><!-- Select --> <?php echo $this->lang->line('add_biller_select'); ?> </option> </select> <span class="validation-color" id="err_city"><?php echo form_error('city'); ?></span> </div> <div class="form-group"> <label for="address"><!-- Address --> <?php echo $this->lang->line('add_biller_address'); ?> <span class="validation-color">*</span> </label> <textarea class="form-control" id="address" rows="2" name="address"><?php echo set_value('address'); ?></textarea> <span class="validation-color" id="err_address"><?php echo form_error('address'); ?></span> </div> </div> <div class="form-group"> <label for="gst_payable">GST Payable On Reverse Charge</label> <input type="checkbox" class="" id="gst_payable" name="gst_payable" value="YES"> <span class="validation-color" id="err_gst_payable"><?php echo form_error('gst_payable'); ?></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> ?> </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> <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('sales_total_sales'); ?></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'); ?> </tr> </thead> <tbody id="product_table_body"> </tbody> </table> <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'><span id="totalValue"> 0.00</span></td> </tr> <tr> <td align="right"><?php echo $this->lang->line('purchase_total_discount'); ?></td> <td align='right'> <span id="totalDiscount"> 0.00</span> </td> </tr> <tr> <td align="right"><?php echo $this->lang->line('purchase_total_tax'); ?></td> <td align='right'> <span id="totalTax"> 0.00</span> </td> </tr> <tr> <td align="right"><?php echo $this->lang->line('purchase_total'); ?> </td> <td align='right'><span id="grandTotal"> 0.00</span></td> </tr> </table> </div> </div> <div class="col-sm-12"> <div class="control-group"> <div class="controls"> <div class="tabbable"> <ul class="nav nav-tabs"> <li> <a href="#note" data-toggle="tab"><?php echo $this->lang->line('purchase_note'); ?></a> </li> <li class="active"><a href="#internal_note" data-toggle="tab"><?php echo $this->lang->line('sales_internal_note'); ?></a></li> </ul> <br> <div class="tab-content"> <div class="tab-pane" id="note"> <textarea class="col-sm-12 form-control" id="note" name="note" value=""></textarea> <span style="color:red;" id="err_note"></span> </div> <div class="tab-pane active" id="internal_note"> <textarea class="col-sm-12 form-control" id="note" name="internal_note" value=""></textarea> <span style="color:red;" id="err_note"></span> </div> </div> </div> </div> <!-- /controls --> </div> <!-- /control-group --> </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('sales')"><?php echo $this->lang->line('product_cancel'); ?></span> </div> </div> </form> </div> <!-- /.box-body --> </div> <!--/.col (right) --> </div> <!-- /.row --> </section> <!-- /.content --> </div> <!-- /.content-wrapper --> <div id="myModal" class="modal fade" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4><!-- <?php echo $this->lang->line('product_hsn_sac_lookup'); ?> --> Add New Customer </h4> </div> <div class="modal-body"> <div class="control-group"> <div class="controls"> <div class="tabbable"> <div class="box-body"> <div class="row"> <form> <div class="col-md-9"> <div class="form-group"> <label for="customer_name"> <?php echo $this->lang->line('add_customer_cname'); ?> </label> <input type="text" class="form-control" id="customer_name" name="customer_name" value="<?php echo set_value('customer_name'); ?>"> </div> <div class="form-group"> <label for="address"> <?php echo $this->lang->line('add_biller_address'); ?> </label> <textarea class="form-control" id="address" rows="4" name="address"><?php echo set_value('address'); ?></textarea> </div> <?php $country=$this->db->get('countries')->result(); ?> <div class="form-group"> <label for="country"><!-- Country --> <?php echo $this->lang->line('biller_lable_country'); ?> </label> <select class="form-control select2" id="country" name="country" style="width: 100%;"> <option value=""><?php echo $this->lang->line('add_biller_select'); ?></option> <?php foreach ($country as $key) { ?> <option value='<?php echo $key->id ?>' <?php if($key->id == 101){ echo "selected";}?>> <?php echo $key->name; ?> </option> <?php } ?> </select> </div> <?php /*$country=$this->db->get('states')->where('s.country_id')->result();*/ $country= $this->db->select('s.*') ->from('states s') ->join('countries c','c.id = s.country_id') ->where('s.country_id',101) ->get() ->result(); ?> <div class="form-group"> <label for="state"><!-- State --> <?php echo $this->lang->line('add_biller_state'); ?> </label> <select class="form-control select2" id="statee" name="state" style="width: 100%;"> <option value=""><!-- Select --> <?php echo $this->lang->line('add_biller_select'); ?> </option> <?php foreach ($country as $key) { ?> <option value='<?php echo $key->id ?>' <?php if($key->id == 101){ echo "selected";}?>> <?php echo $key->name; ?> </option> <?php } ?> </select> </div> <?php $this->db->select('c.*') ->from('cities c') ->join('states s','s.id = c.state_id') ->where('c.state_id',12) ->get() ->result(); ?> <div class="form-group"> <label for="city"><!-- City --> <?php echo $this->lang->line('biller_lable_city'); ?> </label> <select class="form-control select2" id="cityy" name="city" style="width: 100%;"> <option value=""><!-- Select --> <?php echo $this->lang->line('add_biller_select'); ?> </option> <?php foreach ($country as $key) { ?> <option value='<?php echo $key->id ?>' <?php if($key->id == 101){ echo "selected";}?>> <?php echo $key->name; ?> </option> <?php } ?> </select> </div> <div class="form-group"> <label for="mobile"><!-- Mobile --> <?php echo $this->lang->line('add_biller_mobile'); ?> </label> <input type="text" class="form-control" id="mobile" name="mobile" value="<?php echo set_value('mobile'); ?>"> </div> </div> <div class="col-sm-12"> <div class="box-footer"> <button type="submit" id="btn_submit" class="btn btn-info" class="close" data-dismiss="modal"> <!-- Add --> <?php echo $this->lang->line('add_user_btn'); ?> </button> <!-- <span class="btn btn-default" id="cancel" style="margin-left: 2%" onclick="cancel('customer')"> <?php echo $this->lang->line('add_user_btn_cancel'); ?></span> --> </div> </div> </form> </div> <!-- /.box-body --> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal"><?php echo $this->lang->line('product_close'); ?></button> </div> </div> </div> </div> <!-- /controls --> </div> <!-- /control-group --> </div> </div> </div> </div> <?php $this->load->view('layout/product_footer'); ?> <script src="<?php echo base_url('assets/jquery/jquery-3.1.1.js')?>"></script> <script src="<?php echo base_url('assets/datatables/js/jquery.dataTables.min.js')?>"></script> <script src="<?php echo base_url('assets/bootstrap-datepicker/js/bootstrap-datepicker.min.js')?>"></script> <script> $('#btn_submit').click(function(){ $.ajax({ url : '<?php echo base_url('customer/test') ?>', datatype : 'JSON', method : 'POST', data:{ 'customer_name':$('#customer_name').val(), 'address':$("#address").val(), 'country':$("#country").val(), 'state':$("#state").val(), 'city':$("#city").val(), 'mobile':$('#mobile').val() }, success : function(data){ window.location.href='<?php echo base_url('sales/add')?>'; if(data==1) { $('#myModal').modal('hide'); } else { alert("Try again"); } } }); }); </script> <script type="text/javascript"> $(document).ready(function() { //datepicker $('.datepicker').datepicker({ autoclose: true, format: "yyyy-mm-dd", todayHighlight: true, orientation: "auto", todayBtn: true, todayHighlight: true, }); }); function transport(){ $('.transporter').toggle(); } </script> <!-- close datepicker --> <script> $(document).ready(function(){ $('#customer').change(function(){ var customer_id = $(this).val(); $.ajax({ url: "<?php echo base_url('sales/getCustomerData') ?>/"+customer_id, type: "GET", dataType: "JSON", data:{ '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>' }, success: function(data){ $('#country').text(''); $('#state').text(''); $('#city').text(''); $('#err_country').text(''); $('#err_state').text(''); $('#err_city').text(''); for(a=0;a<data['country'].length;a++){ $('#country').append('<option value="' + data['country'][a].id + '">' + data['country'][a].name+'</option>'); } for(a=0;a<data['state'].length;a++){ $('#state').append('<option value="' + data['state'][a].id + '">' + data['state'][a].name+'</option>'); } for(a=0;a<data['city'].length;a++){ $('#city').append('<option value="' + data['city'][a].id + '">' + data['city'][a].name+'</option>'); } $('#country').val(data['data'][0].country_id).attr("selected","selected"); $('#state').val(data['data'][0].state_id).attr("selected","selected"); $('#city').val(data['data'][0].city_id).attr("selected","selected"); $('#address').val(data['data'][0].address); } }); }); }); </script> <script> $('#country').change(function(){ var id = $(this).val(); $('#state').html('<option value="">Select</option>'); $('#city').html('<option value="">Select</option>'); $.ajax({ url: "<?php echo base_url('customer/getState') ?>/"+id, type: "GET", dataType: "JSON", success: function(data){ for(i=0;i<data.length;i++){ $('#state').append('<option value="' + data[i].id + '">' + data[i].name + '</option>'); } } }); }); </script> <script> $('#state').change(function(){ var id = $(this).val(); $('#city').html('<option value="">Select</option>'); $.ajax({ url: "<?php echo base_url('customer/getCity') ?>/"+id, type: "GET", dataType: "JSON", success: function(data){ for(i=0;i<data.length;i++){ $('#city').append('<option value="' + data[i].id + '">' + data[i].name + '</option>'); } } }); }); $('#statee').change(function(){ var id = $(this).val(); $('#cityy').html('<option value="">Select</option>'); $.ajax({ url: "<?php echo base_url('customer/getCity') ?>/"+id, type: "GET", dataType: "JSON", success: function(data){ for(i=0;i<data.length;i++){ $('#cityy').append('<option value="' + data[i].id + '">' + data[i].name + '</option>'); } } }); }); </script> <script> $(document).ready(function(){ var i = 0; var product_data = new Array(); var counter = 1; $('#warehouse').change(function(){ $('#product').html(''); $('#product').html('<option value="">Select Product</option>'); var warehouse_id = $('#warehouse').val(); if(warehouse_id != ""){ $.ajax({ url: "<?php echo base_url('sales/getProducts') ?>/"+warehouse_id, type: "GET", dataType: "JSON", data:{ '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>' }, success: function(data){ for(a=0;a<data.length;a++){ $('#product').append('<option value="' + data[a].product_id + '">' + data[a].name+' ( '+data[a].code+' )</option>'); } } }); } }); $.ajax({ url: "<?php echo base_url('sales/getProducts') ?>/1", type: "GET", dataType: "JSON", data:{ '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>' }, success: function(data){ for(a=0;a<data.length;a++){ $('#product').append('<option value="' + data[a].product_id + '">' + data[a].name+' ( '+data[a].code+' )</option>'); } } }); $('#product').change(function(){ var id = $(this).val(); var product_id = $('#product').val(); var warehouse_id = $('#warehouse').val(); var flag = 0; $('#err_product').text(''); if(warehouse != ""){ $.ajax({ url: "<?php echo base_url('sales/getProduct') ?>/"+product_id+"/1", type: "GET", dataType: "JSON", data:{ '<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>' }, success: function(data){ $("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 name = data[0].name; var hsn_sac_code = data[0].hsn_sac_code; var price = data[0].price; var tax_id = data[0].tax_id; var tax_value = data[0].tax_value; if(tax_value==null){ tax_value = 0; } var product = { "product_id" : id, }; 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' name='qty"+ counter +"' id='qty"+ counter +"' min='0.000' step='0.001' >" +"</td>"; /* cols += "<td>"+data[0].quantity +"<input type='hidden' name='available_quantity' id='available_quantity' value='"+data[0].quantity+"'>" +"</td>"; */ cols += "<td>"+data[0].unit+"</td>"; cols += "<td align='right'>" +"<input type='text' class='form-control text-right' style='width:80px;' name='price"+ counter +"' id='price"+ counter +"' value='"+price+"'>" +"<span style='display:none;' id='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_id" name="tax_id" value="'+tax_id+'"><input type="hidden" id="tax_value" name="tax_value" value="'+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); } } }); } // warehouse else{ $('#err_product').text('Please Select Warehouse.').animate({opacity: '0.0'}, 2000).animate({opacity: '0.0'}, 1000).animate({opacity: '1.0'}, 2000); } }); //product , keyup $("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) { var tax_id = $(this).closest("tr").find('input[name^="tax_id"]').val(); var tax_id_value = $(this).closest("tr").find('#item_tax').val(); if(tax_id_value == ""){ $(this).closest("tr").find('select[name^="item_tax"]').val(tax_id).attr("selected","selected"); } 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].tax_value); calculateDiscountTax(row,0,data[0].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); } /*$("table.product_table").on("change",'#item_tax',function (event) { var row = $(this).closest("tr"); row.find('#hidden_tax').val($(this).val()); });*/ 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].price = price; 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); $('#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 reference_no = $('#reference_no').val(); var warehouse = $('#warehouse').val(); var biller = $('#biller').val(); var product = $('#product').val(); var customer = $('#customer').val(); var discount = $('#discount').val(); var note = $('#note').val(); var internal_note = $('#internal_note').val(); var grand_total = $('#grand_total').val(); var address = $('#address').val(); var city = $('#city').val(); var state = $('#state').val(); var country = $('#country').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_code').text(" Please Enter Valid Date "); $('#date').focus(); return false; } else{ $("#err_code").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(biller==""){ $("#err_biller").text("Please Enter Biller"); $('#biller').focus(); return false; } else{ $("#err_biller").text(""); } //biller code validation complite. if(customer==""){ $("#err_customer").text("Please Enter Customer"); $('#customer').focus(); return false; } else{ $("#err_customer").text(""); } //customer code validation complite. if(address==null || address==""){ $("#err_address").text(" Please Enter Address"); return false; } else{ $("#err_address").text(""); } //Address validation complite. if(country==null || country==""){ $("#err_country").text("Please Select Country "); return false; } else{ $("#err_country").text(""); } //country validation complite. if(state==null || state==""){ $("#err_state").text("Please Select State "); return false; } else{ $("#err_state").text(""); } //state validation complite. if(city==null || city==""){ $("#err_city").text("Please Select City "); return false; } else{ $("#err_city").text(""); } //city validation complite. if(grand_total=="" || grand_total==null || grand_total==0.00){; $("#err_product").text("Please Select Product"); $('#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_code').text(" Please Enter Valid Date "); $('#date').focus(); return false; } else{ $("#err_code").text(""); } }); $("#warehouse").change(function(event){ var warehouse = $('#warehouse').val(); $('#product_table_body').empty(); $('#table_data').val('clear'); $('#last_total').val(''); $('#grand_total').val(''); $('#grandtotal').text('0.00'); $('#totaldiscount').text('0.00'); $('#lasttotal').text('0.00'); if(warehouse==""){ $("#err_warehouse").text("Please Enter Warehouse"); $('#warehouse').focus(); return false; } else{ $("#err_warehouse").text(""); } }); $("#biller").change(function(event){ var biller = $('#biller').val(); if(biller==""){ $("#err_biller").text("Please Enter Biller"); $('#biller').focus(); return false; } else{ $("#err_biller").text(""); } }); $("#customer").change(function(event){ var customer = $('#customer').val(); if(customer==""){ $("#err_customer").text("Please Enter Customer"); $('#customer').focus(); return false; } else{ $("#err_customer").text(""); } }); $("#discount").change(function(event){ var discount = $('#discount').val(); if(discount==""){ $("#err_discount").text("Please Enter Discount"); $('#discount').focus(); return false; } else{ $("#err_discount").text(""); } if(discount!=""){ $.ajax({ url: "<?php echo base_url('sales/getDiscountAjax') ?>/"+discount, type: "get", dataType: "json", success: function(data){ //alert(data[0].discount_id); var type = data[0].discount_type; var value = data[0].discount_value; var amount = parseInt(data[0].amount); var grand_total = $('#grand_total').val(); $('#discount_type').val(type); $('#total_discount').val(value); $('#discount_amount').val(amount); if(grand_total > 0 && grand_total!=null){ if(type == "Fixed"){ var t = grand_total - value; if(grand_total < amount){ var t = grand_total; } $('#lasttotal').text(t); $('#last_total').val(t); $('#totaldiscount').text(value); $('#total_discount').val(value); $('#discount_type').val(type); $('#discount_amount').val(amount); $('#showdiscount').text(" (Rs "+value+")"); } else{ var total = (grand_total*value)/100; var t = grand_total - total; $('#totaldiscount').text(total); $('#total_discount').val(value); $('#discount_type').val(''); $('#discount_amount').val(''); $('#lasttotal').text(t); $('#last_total').val(t); $('#showdiscount').text(" ("+value+"%)"); } } } }); } }); $("#product").blur(function(event){ var sname_regex = /^[a-zA-Z0-9]+$/; var product = $('#product').val(); if(product==null || product==""){ $("#err_product").text("Please Enter Product Code/Name"); $('#product').focus(); return false; } else{ $("#err_product").text(""); } if (!product.match(sname_regex) ) { $('#err_product').text(" Please Enter Valid Product Code/Name "); $('#product').focus(); return false; } else{ $("#err_product").text(""); } }); $("#address").on("blur keyup", function (event){ var address = $('#address').val(); if(address==null || address==""){ $("#err_address").text(" Please Enter Address"); return false; } else{ $("#err_address").text(""); } }); $("#city").change(function(event){ var city = $('#city').val(); $('#city').val(city); if(city==null || city==""){ $("#err_city").text("Please Select City "); return false; } else{ $("#err_city").text(""); } }); $("#state").change(function(event){ var state = $('#state').val(); $('#state').val(state); if(state==null || state==""){ $("#err_state").text("Please Select State "); return false; } else{ $("#err_state").text(""); } }); }); </script>