ok
Direktori : /home2/selectio/public_html/vijay-gases/ |
Current File : /home2/selectio/public_html/vijay-gases/purchase-edit.php |
<?php include "header.php"; // purchase table $id = $_REQUEST['id']; $statement = $pdo->prepare("SELECT * FROM `tbl_purchase` WHERE id =$id "); $statement->execute(); $p_result = $statement->fetchAll(PDO::FETCH_ASSOC); $purchaseId = $p_result[0]['id']; //purchase_item $productStatement = $pdo->prepare("SELECT tbl_product.sku, tbl_product.product_name, tbl_purchase_item.* FROM `tbl_purchase_item` LEFT JOIN tbl_product ON tbl_purchase_item.product_id = tbl_product.id WHERE tbl_product.product_type = 1 AND tbl_purchase_item.type = 1 AND tbl_purchase_item.purchase_id = :purchase_id"); $productStatement->bindParam(':purchase_id', $purchaseId, PDO::PARAM_INT); $productStatement->execute(); $pr_result = $productStatement->fetchAll(PDO::FETCH_ASSOC); $totalData = $productStatement->rowCount(); // Purchase new Cylinder $productStatement_new = $pdo->prepare("SELECT tbl_product.sku, tbl_product.product_name, tbl_purchase_item.* FROM `tbl_purchase_item` LEFT JOIN tbl_product ON tbl_purchase_item.product_id = tbl_product.id WHERE tbl_product.product_type = 1 AND tbl_purchase_item.type = 2 AND tbl_purchase_item.purchase_id = :purchase_id"); $productStatement_new->bindParam(':purchase_id', $purchaseId, PDO::PARAM_INT); $productStatement_new->execute(); $new_result = $productStatement_new->fetchAll(PDO::FETCH_ASSOC); $newtotalData = $productStatement_new->rowCount(); // echo "<script> console.log('" . json_encode($pr_result) . "'); </script>"; // echo "<script> console.log('" . json_encode($totalData) . "'); </script>"; echo "<script> console.log('" . json_encode($new_result) . "'); </script>"; ?> <div class="content-wrapper"> <section class="content-header"> <h1>Edit Purchase</h1> <ol class="breadcrumb"> <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li> <li class="active">Add Purchase</li> </ol> </section> <div class="col-lg-12 alerts"> <div id="custom-alerts" style="display:none;"> <div class="alert alert-dismissable"> <div class="custom-msg"></div> </div> </div> <?php if ($error) { ?> <div class="alert alert-danger alert-dismissable"> <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button> <h4><i class="icon fa fa-ban"></i> Error</h4> <?= $error; ?> </div> <?php $error=0;} if ($warning) { ?> <div class="alert alert-warning alert-dismissable"> <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button> <h4><i class="icon fa fa-warning"></i> Warning</h4> <?= $warning; ?> </div> <?php $warning=0;} if ($message) { ?> <div class="alert alert-success alert-dismissable"> <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button> <h4> <i class="icon fa fa-check"></i> Success</h4> <?= $message; ?> </div> <?php $message=0; } ?> </div> <div class="clearfix"></div> <section class="content"> <div class="row"> <div class="col-xs-12"> <div class="box box-primary"> <div class="box-header"> <div class="box-header"> <div class="row" style=""> <div class="col-md-10 col-sm-10 col-xs-8"> <div style="list-style: none; padding-inline-start: 0px; padding: 5px 0px 5px 0px;"> <?php include "header/purchase_header.php"; ?> </div> </div> <div class="col-md-2 col-sm-2 col-xs-4"> <?php //include "header/buttons-ui.php"; ?> </div> </div> </div> </div> <div class="box-body"> <div class="col-lg-12"> <form enctype="multipart/form-data" method="post" id="add_purchase_form"> <input hidden type="text" name="id" value="<?= $_REQUEST['id']?>" /> <input hidden type="text" name="purchaseId" value="<?=$purchaseId?>"/> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label class="required" for="name">Purchase Date</label> <input type="date" name="purchase_date" value="<?=$p_result[0]['purchase_date']?>" class="form-control tip" id="purchase_date" required="required" /> </div> </div> <div class="col-sm-4"> <div class="form-group"> <label class="control-label" for="departement_id">Select Supplier</label> <select name="supplier" class="form-control tip select2" style="width:100%" id="supplier"> <option value="">All Supplier</option> <?php $statement = $pdo->prepare("SELECT * FROM `tbl_customer` where status='1' and cust_type='2'"); $statement->execute(); $location_result = $statement->fetchAll(PDO::FETCH_ASSOC); foreach ($location_result as $result) { echo "<option value='" . $result['id'] . "'" . ($result['id'] == $p_result[0]['supplier'] ? ' selected' : '') . ">" . $result['customer_name'] . "</option>"; }?> </select> </div> <span></span> </div> <div class="col-sm-4"> <div class="form-group"> <label class="control-label" for="departement_id">Select Location</label> <select name="location" class="form-control select2" style="width:100%" id="location"> <option value="">All Location</option> <?php $statement = $pdo->prepare("SELECT * FROM `tbl_location` where status='1'"); $statement->execute(); $location_result = $statement->fetchAll(PDO::FETCH_ASSOC); foreach ($location_result as $result) { // echo "<option value=".$result['id'].">".$result['name']."</option>"; echo "<option value='". $result['id'] . "'" . ($result['id'] == $p_result[0]['location_id'] ? ' selected' : '') . ">" . $result['name'] . "</option>"; }?> </select> </div> </div> </div> <div class="row"> <div class="col-md-6"> <center><b>Purchase Refil Cylinder</b></center> <div class="row"> <div class="col-md-12"> <div class="form-group search-box"> <label class="" for="pro_category">Search Product info</label> <input type="text" name="search_item" placeholder="Search Product" class="form-control tip " id="search_text" style='text-transform:uppercase'/> <div class="result"></div> </div> </div> </div> <div class="row"> <div class="col-md-12"> <table id="table_refill_cylinder"> <thead> <tr> <th>SKU No</th> <th>Product Name</th> <th>Purchase Rate</th> <th>Sell Rate</th> <th>Quantity</th> <th>Action</th> </tr> </thead> <tbody id="purchase_table"> <?php if($totalData>0) { foreach ( $pr_result as $pr_data){ ?> <tr class="remove_refill_cylinder_row"> <td><input type="text" name="sku_no[]" class="form-control tip" id="sku_no" required="required" value="<?=$pr_data['sku']?>" readonly/><input type="hidden" name="product_id[]" class="form-control pro_ids tip" id="product_id" required="required" value="'.$pr_data['id'].'" /></td> <td><input type="text" name="product_name[]" class="form-control tip" id="product_name" required="required" value="<?=$pr_data['product_name']?>" readonly/></td> <td><input type="text" name="purchase_rate[]" class="form-control tip" id="purchase_rate" required="required" value="<?=$pr_data['purchase_price']?>" readonly/></td> <td><input type="text" name="sell_rate[]" class="form-control tip sell_rate" id="sell_rate" value="<?=$pr_data['sell_price']?>" required="required" value="0"/></td> <td><input type="text" name="quantity[]" class="form-control tip" id="quantity" value="1" required="required" readonly /></td> <td><center><span class="btn btn-danger btn-sm remove_refill_cylinder" style="width:100%;height:33px;"><i class="fa fa-trash-o" style="font-size:14px;"></i></span></center></td> </tr> <?php } }?> <tr style="background-color: burlywood;"> <td></td> <td></td> <td></td> <td><input type="text" name="total_sell_rate" value="<?=$p_result[0]['sell_price'] ?>" class="form-control tip total_sell_rate" readonly/></td> <td></td> <td></td> </tr> </tbody> </table> </div> </div> </div> <div class="col-md-6"> <center><b>Purchase New Cylinder</b></center><br> <center><span id="add_new_purchase" class="btn btn-warning btn-sm"><i class="fa fa-plus"></i>Purchase New Cylinder</span></center> <br> <table id="add_purchase_new_cylinder"> <thead> <tr> <th>Product Name</th> <th>Sku No</th> <th>Purchase Price</th> <th>Stock</th> <th>Sell Price</th> <th>Action</th> </tr> </thead> <tbody> <?php if($newtotalData>0) { foreach ( $new_result as $new_data){ ?> <tr class="cylinder_row"><td><input type="text" name="new_product_name[]" value="<?=$new_data['product_name']?>" class="form-control tip" required="required"/></td> <td><input type="text" name="new_sku_no[]" class="form-control tip" value="<?=$new_data['sku']?>" required="required"/></td> <td><input type="text" name="new_purchse_price[]" class="form-control tip" value="<?=$new_data['purchase_price']?>"required="required"/></td> <td><input type="text" name="new_stock[]" class="form-control tip" value="1" required="required" readonly/></td> <td><input type="text" name="new_sell_price[]" class="form-control tip new_cylinder_sell_price"value="<?=$new_data['sell_price']?>" required="required"/></td> <td><button class="btn btn-danger btn-sm remove_rows"><i class="fa fa-trash-o"></i></button></td></tr> <?php } }?> </tbody> <tfoot> <tr style="background-color: burlywood;"> <td></td> <td></td> <td></td> <td></td> <td><input type="text" name="total_new_sell_rate" value="0" class="form-control tip total_new_cylinder_sell_rate" readonly/></td> <td></td> </tr> </tfoot> </table> </div> </div> <br> <div class="row"> <div class="col-md-6"></div> <div class="col-md-6"> <div class="row"> <div class="col-md-4"></div> <div class="col-md-4"> <div class="form-group"> <label class="required" for="name">Total Amount</label> <input type="text" name="total_amount" value="<?=$p_result[0]['total_amount'] ?>" class="form-control tip total_final_amount" id="total_amount" required="required" readonly/> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="required" for="name">Advance Amount</label> <input type="text" name="advance_amount" value="<?=$p_result[0]['paid_amount'] ?>" class="form-control tip" id="advance_amount"/> </div> </div> </div> </div> </div> <div class="form-group" style="text-align:center;"> <input type="submit" name="add_purchase" value="Add Purchase" class="btn btn-success" /> </form> </div> </div> <div class="form-group" style="text-align:center;"> <a href="purchase-add.php"><button class="btn btn-primary" ><i class="fa fa-refresh"></i> Reset Form</button></a> <a href="purchase.php"><button class="btn btn-warning" ><i class="fa fa-chevron-left"></i> Back to List</button></a> </div> <div class="clearfix"></div> </div> </div> </div> </div> </section> <script> $(document).on('click', '.remove_rows', function() { $(this).closest('.cylinder_row').remove(); }); $('#add_new_purchase').on('click', function() { html = '<tr class="cylinder_row"><td><input type="text" name="new_product_name[]" class="form-control tip" required="required"/></td><td><input type="text" name="new_sku_no[]" class="form-control tip" required="required"/></td><td><input type="text" name="new_purchse_price[]" class="form-control tip" required="required"/></td><td><input type="text" name="new_stock[]" class="form-control tip" value="1" required="required" readonly/></td><td><input type="text" name="new_sell_price[]" class="form-control tip new_cylinder_sell_price" required="required"/></td><td><button class="btn btn-danger btn-sm remove_rows"><i class="fa fa-trash-o"></i></button></td></tr>'; $('#add_purchase_new_cylinder').append(html); }); </script> <script> $(document).ready(function(){ var n=''; n=parseInt(n) || 0; //console.log('bn Value='+n); $('.search-box input[type="text"]').on("keyup input", function(){ var search_text = $(this).val(); var resultDropdown = $(this).siblings(".result"); if(search_text.length>1){ $.get("apis/purchase-search-api.php", {search_text: search_text}).done(function(data){ resultDropdown.html(data); }); } else{ resultDropdown.empty(); } }); }); function append_row(id){ /*console.log('table row added'+id);*/ $('.search-box input[type="text"]').val(''); $(".result").empty(); $('.search-box input[type="text"]').focus(); } function product_selection(id){ var is_new = 1; $(".pro_ids").each(function(){ if(id==$(this).val()){ is_new=0; return false; } }); if(is_new==1){ // console.log('table row added'+id); $.ajax({ url: 'apis/get-search-purchase-edit.php?id', type: 'post', dataType: 'text', data:{pro_id:id}, success: function (response) { // console.log('Id :'+id); $('#purchase_table').prepend(response); $('.search-box input[type="text"]').val(''); $(".result").empty(); $('.search-box input[type="text"]').focus(); } }); }else{ alert('this product Already Added..'); $('.search-box input[type="text"]').val(''); $(".result").empty(); $('.search-box input[type="text"]').focus(); } } </script> <script> // ************************** INSERT AJAX START ****************************** $(document).ready(function(){ $('#add_purchase_form').on('submit', function(e){ e.preventDefault(); $("#add_purchase").attr('disabled','disabled'); console.log('Purchase Submit Option Start...'); var formData = new FormData(this); formData.append('type', 'update_new_purchase'); $.ajax({ url: 'apis/purchase-update-api.php?purchaseId=$purchaseId', type: 'post', dataType: 'json', data: formData, cache: false, contentType: false, processData: false, enctype: 'multipart/form-data', success: function (response) { console.log(response); console.log("Response id " +response['id']); if(response['status']==200){ //put success coode $('#add_purchase_form').trigger("reset"); $("#add_purchase").removeAttr('disabled'); alert(response['message']); }else{ //put falied code alert(response['message']); $("#add_purchase").removeAttr('disabled'); } } }); }); }); // ************************** INSERT AJAX END ****************************** </script> <script> $(document).ready(function(){ }); </script> <script> $(document).ready(function(){ final_calculation(); $('table#table_refill_cylinder tbody').on('change keyup', 'tr.remove_refill_cylinder_row', function() { final_calculation(); }); function final_calculation(){ console.log('BRINDHA'); var sum = 0; $(".sell_rate").each(function(){ sum += +$(this).val(); }); $(".total_sell_rate").val(sum); total_final_amount(); } $('table#add_purchase_new_cylinder tbody').on('change keyup', 'tr.cylinder_row', function() { console.log('Table Calculation'); new_cylinder_calculation(); }); function new_cylinder_calculation(){ var sum = 0; $(".new_cylinder_sell_price").each(function(){ console.log('Venkateshan Anna'); sum += +$(this).val(); }); $(".total_new_cylinder_sell_rate").val(sum); total_final_amount(); } function total_final_amount(){ console.log('Final Calculation Starts Here'); console.log('BRINDHA'); var sum = 0; $(".total_sell_rate").each(function(){ sum += +$(this).val(); }); $(".total_new_cylinder_sell_rate").each(function(){ sum += +$(this).val(); }); $(".total_final_amount").val(sum); } }); </script> <?php include "footer.php"; ?> <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" /> <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script> <style> .select2-container--default .select2-selection--multiple .select2-selection__choice { background-color: rgb(228, 228, 228); box-sizing: border-box; display: inline-block; margin-left: 5px; margin-top: 5px; position: relative; max-width: 100%; text-overflow: ellipsis; vertical-align: bottom; white-space-collapse: collapse; text-wrap: nowrap; border-width: 1px; border-style: solid; border-color: rgb(170, 170, 170); border-image: initial; border-radius: 4px; padding: 0px 10px 0px 20px; overflow: hidden; color: black; font-weight: 800; } .select2-container--default .select2-selection--multiple { background-color: white; border: 1px solid #aaa; border-radius: 4px; cursor: text; height: 100px; padding-bottom: 5px; padding-right: 5px; position: relative; } </style> <style> table { border-collapse: collapse; width: 100%; } tr:nth-child(even){background-color: #f2f2f2} th{ background-color: #b34923; color: white; text-align: center; padding-top: 5px; padding-bottom: 5px; } </style> <style> body { font-weight: bolder; background: white; } .search-box{ width: auto; display: inline-block; font-size: 14px; } .search-box { padding: 5px 10px; font-size: 14px; } .result{ position: absolute; z-index: 999; top: 89%; left: 0; } .search-box, .result{ width: 100%; box-sizing: border-box; } /* Formatting result items */ .result div{ margin: 0; background: white; padding: 7px 10px; border: 1px solid #CCCCCC; border-top: none; cursor: pointer; margin-top:-10px; } .result div:hover{ background: blue; color: white; } </style> <script> $(document).on('click', '.remove_refill_cylinder', function() { $(this).closest('.remove_refill_cylinder_row').remove(); });</script>