ok
Direktori : /home2/selectio/public_html/lilyexpresslive/expense-invoice/ |
Current File : /home2/selectio/public_html/lilyexpresslive/expense-invoice/expense-add.php |
<?php include "header.php"; if(isset($_POST['add_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; // 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='expense-proof/default-img.png'; } 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; $upload_logo = move_uploaded_file($_FILES['logo2']['tmp_name'], 'expense-proof/' . $menu_image1); $upload_logo_image2 = 'expense-proof/' . $menu_image1; }else{ $upload_logo_image2='expense-proof/default-img.png'; } 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; $upload_logo = move_uploaded_file($_FILES['logo3']['tmp_name'], 'expense-proof/' . $menu_image1); $upload_logo_image3 = 'expense-proof/' . $menu_image1; }else{ $upload_logo_image3='expense-proof/default-img.png'; } if(isset($_FILES['logo4']['name']) && $_FILES['logo2']['name']!=""){ $extension1 = end(explode(".", $_FILES["logo4"]["name"])); $menu_image1 = rand(10,1000000). "-" . date("Y-m-d H-i-s") . "." . $extension1; $upload_logo = move_uploaded_file($_FILES['logo4']['tmp_name'], 'expense-proof/' . $menu_image1); $upload_logo_image4 = 'expense-proof/' . $menu_image1; }else{ $upload_logo_image4='expense-proof/default-img.png'; } if(isset($_FILES['logo5']['name']) && $_FILES['logo2']['name']!=""){ $extension1 = end(explode(".", $_FILES["logo5"]["name"])); $menu_image1 = rand(10,1000000). "-" . date("Y-m-d H-i-s") . "." . $extension1; $upload_logo = move_uploaded_file($_FILES['logo5']['tmp_name'], 'expense-proof/' . $menu_image1); $upload_logo_image5 = 'expense-proof/' . $menu_image1; }else{ $upload_logo_image5='expense-proof/default-img.png'; } $statement = $pdo->prepare("INSERT INTO `tbl_expense`(`user_id`, `expense_date`, `amount`, `ref_no`, `category_id`, `employee_id`, `expense_for`, `payment_method`, `location`, `note`, `created_at`,`proof_image`, `proof_image2`, `proof_image3`, `proof_image4`, `proof_image5`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); $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'],$date,$upload_logo_image,$upload_logo_image2,$upload_logo_image3,$upload_logo_image4,$upload_logo_image5)); if($result){ $message = 'Expense is added successfully!'; unset($_POST); }else{ $warning="Something went wrong try again..."; } }catch(Exception $e){ $error=$e; } } ?> <script> $(document).ready(function() { $("#amount_error").hide(); $('#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); console.log("amount : "+res+" payment_method :"+payment_method); if(amount>res){ $("#amount_error").show(); $('#add_expense_div').hide(); $("#amount_error").text("In Hand Amount is "+res+" Use less than Only"); $("#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(); 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++) { $('#employee') .append($("<option></option>") .attr("value", datas[index]['id']) .text(datas[index]['employee_name'])); } } }); } } }); </script> <div class="content-wrapper"> <section class="content-header"> <h1>Add Expense</h1> <ol class="breadcrumb"> <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li> <li class="active">Add 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"> <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="<?=date("Y-m-d")?>" 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` where status=1"); $statement->execute(); $location_result = $statement->fetchAll(PDO::FETCH_ASSOC); foreach ($location_result as $result) { echo "<option value=".$result['id'].">".$result['category']."</option>"; }?> </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` where status=1"); $statement->execute(); $location_result = $statement->fetchAll(PDO::FETCH_ASSOC); foreach ($location_result as $result) { echo "<option value=".$result['id'].">".$result['office']."</option>"; }?> </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="" 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="" 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 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">Cash</option> <option value="Card">Card</option> <option value="UPI Transfer">UPI Transfer</option> <option value="Acc Transfer">Acc Transfer</option> </select> </div> </div> <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="" 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 for="role">Expense Notes</label> <textarea name="notes" id="notes" class="form-control tip"> </textarea> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="logo">Upload Expense Proof</label> <input type="file" id="logo" name="logo" accept="image/png, image/jpeg" /> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="logo">Upload Expense Proof-2</label> <input type="file" id="logo2" name="logo2" accept="image/png, image/jpeg" /> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="logo">Upload Expense Proof-3</label> <input type="file" id="logo3" name="logo3" accept="image/png, image/jpeg" /> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="logo">Upload Expense Proof-4</label> <input type="file" id="logo4" name="logo4" accept="image/png, image/jpeg" /> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="logo">Upload Expense Proof-5</label> <input type="file" id="logo5" name="logo5" accept="image/png, image/jpeg" /> </div> </div> </div> <div class="form-group" style="text-align:center;" id="add_expense_div"> <input type="submit" name="add_expense" value="Add Expense" id="add_expense" class="btn btn-success" /> </form> </div> </div> <div class="form-group" style="text-align:center;"> <a href="expense-add.php"><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";?>