ok
Direktori : /home2/selectio/public_html/lilyexpresslive/expense-invoice/ |
Current File : /home2/selectio/public_html/lilyexpresslive/expense-invoice/expense-edit.php |
<?php include "header.php"; if(isset($_POST['update_expense'])){ try{ $date = date('Y-m-d h:i:s', time()); if(isset($_FILES['logo']['name']) && $_FILES['logo']['name']!=""){ // create random image file name $extension1 = end(explode(".", $_FILES["logo"]["name"])); $menu_image1 = rand(10,1000000). "-" . date("Y-m-d H-i-s") . "." . $extension1; if($_POST['existing_img']!="expense-proof/default-img.png"){ unlink($_POST['existing_img']); } // upload new image $upload_logo = move_uploaded_file($_FILES['logo']['tmp_name'], 'expense-proof/' . $menu_image1); // insert new data to menu table $upload_logo_image = 'expense-proof/' . $menu_image1; }else{ $upload_logo_image=$_POST['existing_img']; } if(isset($_FILES['logo2']['name']) && $_FILES['logo2']['name']!=""){ $extension1 = end(explode(".", $_FILES["logo2"]["name"])); $menu_image1 = rand(10,1000000). "-" . date("Y-m-d H-i-s") . "." . $extension1; if($_POST['existing_img2']!="expense-proof/default-img.png"){ unlink($_POST['existing_img2']); } $upload_logo = move_uploaded_file($_FILES['logo2']['tmp_name'], 'expense-proof/' . $menu_image1); $upload_logo_image2 = 'expense-proof/' . $menu_image1; }else{ $upload_logo_image2=$_POST['existing_img2']; } if(isset($_FILES['logo3']['name']) && $_FILES['logo3']['name']!=""){ $extension1 = end(explode(".", $_FILES["logo3"]["name"])); $menu_image1 = rand(10,1000000). "-" . date("Y-m-d H-i-s") . "." . $extension1; if($_POST['existing_img3']!="expense-proof/default-img.png"){ unlink($_POST['existing_img3']); } $upload_logo = move_uploaded_file($_FILES['logo3']['tmp_name'], 'expense-proof/' . $menu_image1); $upload_logo_image3 = 'expense-proof/' . $menu_image1; }else{ $upload_logo_image3=$_POST['existing_img3']; } if(isset($_FILES['logo4']['name']) && $_FILES['logo4']['name']!=""){ $extension1 = end(explode(".", $_FILES["logo4"]["name"])); $menu_image1 = rand(10,1000000). "-" . date("Y-m-d H-i-s") . "." . $extension1; if($_POST['existing_img4']!="expense-proof/default-img.png"){ unlink($_POST['existing_img4']); } $upload_logo = move_uploaded_file($_FILES['logo4']['tmp_name'], 'expense-proof/' . $menu_image1); $upload_logo_image4 = 'expense-proof/' . $menu_image1; }else{ $upload_logo_image4=$_POST['existing_img4']; } if(isset($_FILES['logo5']['name']) && $_FILES['logo5']['name']!=""){ $extension1 = end(explode(".", $_FILES["logo5"]["name"])); $menu_image1 = rand(10,1000000). "-" . date("Y-m-d H-i-s") . "." . $extension1; if($_POST['existing_img5']!="expense-proof/default-img.png"){ unlink($_POST['existing_img5']); } $upload_logo = move_uploaded_file($_FILES['logo5']['tmp_name'], 'expense-proof/' . $menu_image1); $upload_logo_image5 = 'expense-proof/' . $menu_image1; }else{ $upload_logo_image5=$_POST['existing_img5']; } $statement = $pdo->prepare("UPDATE tbl_expense SET user_id=?,expense_date=?,amount=?, ref_no=?,category_id=?,employee_id=?,expense_for=?,payment_method=?,location=?,note=?,location=?,updated_at=?,proof_image=?,proof_image2=?,proof_image3=?,proof_image4=?,proof_image5=? WHERE id=?"); $result=$statement->execute(array($_SESSION['lily']['id'],$_POST['start_date'],$_POST['amount'],$_POST['reference_no'],$_POST['category'],$_POST['employee'] ,$_POST['expense_for'],$_POST['payment_method'],$_POST['location'],$_POST['notes'],$_POST['location'],$date,$upload_logo_image,$upload_logo_image2,$upload_logo_image3,$upload_logo_image4,$upload_logo_image5,$_POST['ids'])); if($result){ $message = 'Expense is updated successfully!'; unset($_POST); }else{ $warning="Something went wrong try again..."; } }catch(Exception $e){ $error=$e; } } $ids=$_GET['id']; $statement = $pdo->prepare("SELECT * FROM tbl_expense e where e.id=".$ids); $statement->execute(); $emp_data = $statement->fetchAll(PDO::FETCH_ASSOC); $totalData = $statement->rowCount(); if($totalData==1){ ?> <script> $(document).ready(function() { $("#amount_error").hide(); getEmployeeDetails(); $('#location').on('change', function() { getEmployeeDetails(); calclulate_amount(); }); $('#amount').on('input', function() { calclulate_amount(); }); $('#payment_method').on('change', function() { calclulate_amount(); }); function calclulate_amount(){ var location =$('#location').val(); var amount =$('#amount').val(); var payment_method =$('#payment_method').val(); if(location!=""){ $.ajax({ type: 'POST', url: 'api/custom-function.php', data: {type:'get_inhand_expense_amount',location:location,payment_method:payment_method}, success: function(response) { var res=parseInt(response); if(amount>res){ $("#amount_error").show(); $('#add_expense_div').hide(); $("#amount_error").text("In Hand Amount is "+res+" Use less than Only"); console.log("amount less than"); $("#amount_details").text(""); }else{ $("#amount_error").hide(); $('#add_expense_div').show(); $("#amount_error").text(""); $("#amount_details").text("In Hand Amount is "+res+" Use less than or Equal Amount Only"); } } }); } } function getEmployeeDetails(){ // location and Employee Details Set var location = $("#location").val(); var employee_id = $("#employee_id").val(); console.log(location); if(location==""){ $('#employee').empty(); $('#employee').append($("<option></option>") .attr("value", "") .text("Select Location First!")); }else{ $.ajax({ url: 'api/custom-function.php', type: 'post', data: {location:location,type:2}, dataType: 'text', success: function(response) { console.log(response); var datas = JSON.parse(response) // alert(datas); console.log(datas); $('#employee').empty(); $("#employee").val(null).trigger("change"); var tot = datas.length; if(tot==0) { $('#employee').append($("<option></option>") .attr("value", "") .text("Employee Not Available")); }else{ $('#employee').append($("<option></option>") .attr("value", "") .text("Select Employee Name")); } for (var index = 0; index < tot; index++) { if(employee_id==datas[index]['id']){ $('#employee') .append($("<option></option>") .attr("value", datas[index]['id']) .text(datas[index]['employee_name']).attr('selected','selected')); $("#employee").val(datas[index]['id']).trigger("change"); }else{ $('#employee') .append($("<option></option>") .attr("value", datas[index]['id']) .text(datas[index]['employee_name'])); } } } }); } } calclulate_amount(); }); </script> <div class="content-wrapper"> <section class="content-header"> <h1>Edit Expense</h1> <ol class="breadcrumb"> <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li> <li class="active">Edit Expense</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"> <h3 class="box-title">Please fill in the information below</h3> </div> <div class="box-body"> <div class="col-lg-12"> <form action="" class="validation" enctype="multipart/form-data" method="post" accept-charset="utf-8"> <input type="hidden" name="ids" value="<?=$emp_data[0]['id']?>" class="form-control tip" id="id" required="required" /> <input type="hidden" name="employee_id" value="<?=$emp_data[0]['employee_id']?>" class="form-control tip" id="employee_id" required="required" /> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label class="required" for="name">Expense Date</label> <input type="text" name="start_date" value="<?=$emp_data[0]['expense_date']?>" class="form-control datetimepicker" id="start_date" required="required" /> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="required" for="email">Expense Category</label> <select name="category" class="form-control select2" style="width:100%" id="category" required="required"> <option value="">Selcet Expense Category</option> <?php $statement = $pdo->prepare("SELECT * FROM `tbl_exp_category`"); $statement->execute(); $location_result = $statement->fetchAll(PDO::FETCH_ASSOC); foreach ($location_result as $result) { ?> <option value="<?php echo $result['id']; ?>" <?php if($result['id']==$emp_data[0]['category_id']){ echo "selected";} ?>> <?php echo $result['category']; ?> </option> <?php }?> </select> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="required" for="email">Select Location</label> <select name="location" class="form-control select2" style="width:100%" id="location" required="required"> <option value="">Select Location</option> <?php $statement = $pdo->prepare("SELECT * FROM `tbl_exp_location`"); $statement->execute(); $location_result = $statement->fetchAll(PDO::FETCH_ASSOC); foreach ($location_result as $result) { ?> <option value="<?php echo $result['id']; ?>" <?php if($result['id']==$emp_data[0]['location']){ echo "selected";} ?>> <?php echo $result['office']; ?> </option> <?php }?> </select> </div> </div> </div> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label class="required" for="role">Select Employee</label> <select name="employee" class="form-control select2" style="width:100%" id="employee" required="required"> <option value="">Select Employee</option> </select> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="required" for="role">Expense For</label> <input type="text" name="expense_for" value="<?=$emp_data[0]['expense_for']?>" class="form-control tip" id="expense_for" required="required" placeholder="Enter Expense For" /> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="required" for="role">Expense Ref No</label> <input type="text" name="reference_no" value="<?=$emp_data[0]['ref_no']?>" class="form-control tip" id="reference_no" required="required" placeholder="Enter Expense Ref No" /> </div> </div> </div> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label class="required" for="role">Expense Amount</label><span style="color: red;" id="amount_error"></span> <span style="color: green;" id="amount_details"></span> <input type="number" min="5" name="amount" value="<?=$emp_data[0]['amount']?>" class="form-control tip" id="amount" required="required" placeholder="Enter Expense Ref No" /> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="required" for="role">Expense Payment Methode</label> <select name="payment_method" class="form-control select2" style="width:100%" id="payment_method" required="required"> <option value="">Select Expense Payment Type</option> <option value="Cash" <?php if($emp_data[0]['payment_method']=="Cash"){ echo "selected";} ?> >Cash</option> <option value="Card" <?php if($emp_data[0]['payment_method']=="Card"){ echo "selected";} ?> >Card</option> <option value="UPI Transfer" <?php if($emp_data[0]['payment_method']=="UPI Transfer"){ echo "selected";} ?> >UPI Transfer</option> <option value="Account Transfer" <?php if($emp_data[0]['payment_method']=="Account Transfer"){ echo "selected";} ?> >Account Transfer</option> <option value="Cheque" <?php if($emp_data[0]['payment_method']=="Cheque"){ echo "selected";} ?> >Cheque</option> </select> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="role">Expense Notes</label> <textarea name="notes" id="notes" class="form-control tip"><?=$emp_data[0]['note']?> </textarea> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="logo">Upload Expense Proof</label> <input type="file" id="logo" name="logo" accept="image/png, image/jpeg" /> <input type="text" name="existing_img" value='<?=$emp_data[0]['proof_image']?>' hidden> <br><img src="<?=$emp_data[0]['proof_image']?>" style="width:250px;height:300px;"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="logo">Upload Expense Proof-2</label> <input type="file" id="logo2" name="logo2" accept="image/png, image/jpeg" /> <input type="text" name="existing_img2" value='<?=$emp_data[0]['proof_image2']?>' hidden> <br><img src="<?=$emp_data[0]['proof_image2']?>" style="width:250px;height:300px;"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="logo">Upload Expense Proof-3</label> <input type="file" id="logo3" name="logo3" accept="image/png, image/jpeg" /> <input type="text" name="existing_img3" value='<?=$emp_data[0]['proof_image3']?>' hidden> <br><img src="<?=$emp_data[0]['proof_image3']?>" style="width:250px;height:300px;"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="logo">Upload Expense Proof-4</label> <input type="file" id="logo4" name="logo4" accept="image/png, image/jpeg" /> <input type="text" name="existing_img4" value='<?=$emp_data[0]['proof_image4']?>' hidden> <br><img src="<?=$emp_data[0]['proof_image4']?>" style="width:250px;height:300px;"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="logo">Upload Expense Proof-5</label> <input type="file" id="logo5" name="logo5" accept="image/png, image/jpeg" /> <input type="text" name="existing_img5" value='<?=$emp_data[0]['proof_image5']?>' hidden> <br><img src="<?=$emp_data[0]['proof_image5']?>" style="width:250px;height:300px;"> </div> </div> </div> <div class="form-group" style="text-align:center;"> <input type="submit" name="update_expense" value="Update Expense" class="btn btn-success" /> </form> </div> </div> <div class="form-group" style="text-align:center;"> <?php echo "<a href=expense-edit.php?id=".$ids."><button class='btn btn-primary' ><i class='fa fa-refresh'></i> Reset Form</button></a>"; ?> <a href="expense.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> <?php } include "footer.php";?>