ok
Direktori : /home2/selectio/www/lilyexpresslive/expense-invoice/ |
Current File : /home2/selectio/www/lilyexpresslive/expense-invoice/invoice-edit.php |
<?php include "header.php"; $ids=$_GET['id']; if(isset($_POST['update_invoice'])){ try{ if($_POST['po_date']==''){$_POST['po_date']='0000-00-00';} $statement = $pdo->prepare("UPDATE tbl_invoice SET inv_no=?,client_id=?,invoice_amount=?,date=?,period=?,year=?,gst_percentage=?,final_amount=?,tax_type=?,po_number=?,po_date=? WHERE id=?"); $result=$statement->execute(array($_POST['inv_no'],$_POST['client'],$_POST['invoice_amount'],$_POST['inv_date'],$_POST['period'],$_POST['year'],$_POST['tax_percentage'],$_POST['final_amount'],$_POST['tax_type'],$_POST['po_number'],$_POST['po_date'],$_POST['ids'])); if($result){ $message = 'Invoice updated successfully!'; if(isset($_POST['item_description'])){ for($n=0;$n<sizeof($_POST['item_description']);$n++){ $statement = $pdo->prepare("UPDATE `tbl_invoice_items` set item_name=?, amount=? where id=?"); $result=$statement->execute(array($_POST['item_description'][$n],$_POST['item_amount'][$n],$_POST['item_id'][$n])); } } if(isset($_POST['new_item_description'])){ for($n=0;$n<sizeof($_POST['new_item_description']);$n++){ $statement = $pdo->prepare("INSERT INTO `tbl_invoice_items`(`invoice_id`, `item_name`, `amount`,`type`) VALUES (?,?,?,?)"); $result=$statement->execute(array($_POST['ids'],$_POST['new_item_description'][$n],$_POST['new_item_amount'][$n],1)); } } // unset($_POST); ?><script> var id=<?=$_POST['ids']?>; var client_name='<?=$_POST['client_name']?>'; var inv_no='<?=$_POST['inv_no']?>'; var url="invoice-view.php?id="+id+"&inv_no="+client_name+inv_no; window.location.replace(url); </script><?php }else{ $warning="Something went wrong try again..."; } }catch(Exception $e){ $error=$e; } } $statement = $pdo->prepare("SELECT * FROM tbl_invoice e where e.id=".$ids); $statement->execute(); $invoice_data = $statement->fetchAll(PDO::FETCH_ASSOC); $totalData = $statement->rowCount(); if($totalData==1){ ?> <div class="content-wrapper"> <section class="content-header"> <h1>Edit Invoice</h1> <ol class="breadcrumb"> <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li> <li class="active">Edit Invoice</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="" enctype="multipart/form-data" method="post" accept-charset="utf-8"> <input type="hidden" name="ids" value="<?=$invoice_data[0]['id']?>" class="form-control tip" id="id" required="required" /> <div class="row"> <div class="col-md-4"> <div class="form-group"> <label class="required" for="email">Select Client</label> <select name="client" class="form-control" onchange="client_name()" style="width:100%" id="client" required="required"> <option value="">Select Client</option> <?php $statement = $pdo->prepare("SELECT * FROM `tbl_client` where type=1"); $statement->execute(); $location_result = $statement->fetchAll(PDO::FETCH_ASSOC); foreach ($location_result as $result) { if($result['id']==$invoice_data[0]['client_id']){ echo "<option value=".$result['id']." selected>".$result['name']."</option>"; }else{ echo "<option value=".$result['id'].">".$result['name']."</option>"; } }?> </select> <input type="hidden" id="client_name" name="client_name" value=""> </div> </div> <div class="col-md-2"> <div class="form-group"> <label class="required" for="location">Invoice Number</label> <input type="text" readonly name="inv_no" placeholder="Enter Invoice Number" value="<?=$invoice_data[0]['inv_no']?>" class="form-control tip" id="inv_no" required="required" /> </div> </div> <div class="col-md-2"> <div class="form-group"> <label class="required" for="location">Bill Period</label> <input type="text" name="period" placeholder="Enter Bill Period" value="<?=$invoice_data[0]['period']?>" class="form-control tip" id="period" required="required" /> </div> </div> <div class="col-md-2"> <div class="form-group"> <label class="required" for="location">Financial Year</label> <select name="year" class="form-control select2" id="year" data-placeholder="Payment Method" style="width:100%;"> <option value="">Select Financial Year</option> <?php for($y=2020;$y<2035;$y++){ $f_y=$y."-".($y+1-2000);?> <option value="<?=$f_y?>" <?php if($invoice_data[0]['year']==$f_y){ echo "selected";}?>><?=$f_y?></option> <?php } ?> </select> </div> </div> <div class="col-md-2"> <div class="form-group"> <label class="required" for="location">Invoice Date</label> <input type="text" name="inv_date" placeholder="Select Invoice Date" value="<?=$invoice_data[0]['date']?>" class="form-control datetimepicker tip" id="inv_date" required="required" /> </div> </div> <div class="col-md-2"> <div class="form-group"> <label class="optional" for="location">PO Number</label> <input type="text" name="po_number" placeholder="Enter PO Number" value="<?=$invoice_data[0]['po_number']?>" class="form-control tip" id="po_number" /> </div> </div> <div class="col-md-2"> <div class="form-group"> <label class="optional" for="location">PO Date</label> <input type="date" name="po_date" placeholder="Enter Bill Period" value="<?=$invoice_data[0]['po_date']?>" class="form-control tip" id="po_date" /> </div> </div> <div class="col-md-12" > <center><b style='font-size: 16px;color: crimson;'>Invoice Amount Details Update Or Add Here</b></center> <?php $statement = $pdo->prepare("SELECT * FROM tbl_invoice_items e where e.invoice_id=".$ids." and e.type=1"); $statement->execute(); $item_data = $statement->fetchAll(PDO::FETCH_ASSOC); $totalData = $statement->rowCount(); foreach($item_data as $item){ ?> <div class="col-md-6"> <div class="form-group"> <label class="required" for="role">Description</label> <input type="text" name="item_id[]" value="<?=$item['id']?>" hidden> <input type="text" name="item_description[]" class="form-control tip" value="<?=$item['item_name']?>" placeholder='item Description' required="required"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label class="required" for="role">Amount (Without Tax)</label> <input type="text" name="item_amount[]" value="<?=$item['amount']?>" onchange="calculatetaxamount()" onkeyup="calculatetaxamount()" class="form-control tip item_amount" id="amount1" onkeypress="return isNumberKey(this, event);" required="required" placeholder="Enter Invoice Amount" /> </div> </div> <div class="col-md-2"> <div class="form-group"> <label for="role">Action</label> <br> <a title="Add New Item" onclick="delete_item(<?=$item['id']?>)" class='btn btn-danger btn-sm' style="cursor: pointer;"><i class="fa fa-trash-o"> <b style='font-size:16px;'>Delete</b></i></a> </div> </div> <?php } ?> <div class="row" id="variations"> </div> <br><center><a id="add_packate_variation" title="Add New Item" style="cursor: pointer;"><i class="fa fa-plus-square-o fa-2x"> <b style='font-size:16px;'></b></i></a></center> </div> <div class="col-md-12" > <hr> <div class="col-md-6" style="text-align: right;"><label class="required" for="role">Total Invoice Amount (Without Tax)</label></div> <div class="col-md-6"><input type="text" min="5" name="invoice_amount" value="" readonly onchange="calculatetaxamount()" onkeyup="calculatetaxamount()" class="form-control tip" id="invoice_amount" onkeypress="return isNumberKey(this, event);" required="required" placeholder="Enter Invoice Amount" /></div> <br><br> <div class="col-md-6" style="text-align: right;"><label class="required" for="location">Tax Type</label></div> <div class="col-md-6"> <select name="tax_type" class="form-control select2" id="tax_type" data-placeholder="Payment Method" style="width:100%;"> <option value="1" <?php if($invoice_data[0]['tax_type']==1){ echo "selected";}?>>GST</option> <option value="2" <?php if($invoice_data[0]['tax_type']==2){ echo "selected";}?>>IGST</option> </select></div> <br><br> <div class="col-md-6" style="text-align: right;"><label class="required" for="location">Tax %</label> </div> <div class="col-md-6"> <select name="tax_percentage" class="form-control select2" id="tax_percentage" onchange="calculatetaxamount()" onkeyup="calculatetaxamount()" data-placeholder="Payment Method" style="width:100%;"> <option value="0" <?php if($invoice_data[0]['gst_percentage']==0){ echo "selected";}?>>0 %</option> <option value="5" <?php if($invoice_data[0]['gst_percentage']==5){ echo "selected";}?>>5 %</option> <option value="10" <?php if($invoice_data[0]['gst_percentage']==10){ echo "selected";}?>>10 %</option> <option value="12" <?php if($invoice_data[0]['gst_percentage']==12){ echo "selected";}?>>12 %</option> <option value="18" <?php if($invoice_data[0]['gst_percentage']==18){ echo "selected";}?>>18 %</option> <option value="28" <?php if($invoice_data[0]['gst_percentage']==28){ echo "selected";}?>>28 %</option> </select> </select> </div> <br><br> <div class="col-md-6" style="text-align: right;"><label class="required" for="role">Tax Amount</label></div> <div class="col-md-6"><input type="text"name="tax_amount" readonly value="" class="form-control tip" id="tax_amount" required="required" placeholder="Auto Calculate Based on Tax and Invoice Amount" /></div> <br><br> <div class="col-md-6" style="text-align: right;"><label class="required" for="role">Final Amount (With Tax)</label></div> <div class="col-md-6"><input type="text" min="5" name="final_amount" value="" readonly class="form-control tip" id="final_amount" required="required" placeholder="Auto Calculate Based on Tax and Invoice Amount" /></div> <br><br><div class="form-group" style="text-align:center;"> <input type="submit" name="update_invoice" value="Update Invoice" class="btn btn-success" /> </div> </form> <div class="form-group" style="text-align:center;"> <?php echo "<a href=invoice-edit.php?id=".$ids."> <button class='btn btn-primary' > <i class='fa fa-refresh'></i> Reset Form</button></a>"; ?> <a href="invoice.php" class="btn btn-warning" ><i class="fa fa-chevron-left"></i> Back to List</a> </div> </div> <div class="clearfix"></div> </div> </div> </div> </div> </section> <script> $(document).on('click', '.remove_variation', function() { $(this).closest('.rows').remove(); calculation_final_amt(); }); $('#add_packate_variation').on('click', function() { html ='<div class="rows">'+ '<div class="col-md-6">'+ '<div class="form-group">'+ '<label class="required" for="role">Description</label>'+ '<input type="text" name="new_item_description[]" class="form-control tip" placeholder="item Description" required="required">'+ '</div>'+ '</div>'+ '<div class="col-md-4">'+ '<div class="form-group">'+ '<label class="required" for="role">Amount (Without Tax)</label> '+ '<input type="text" name="new_item_amount[]" value="0" onchange="calculatetaxamount()" onkeyup="calculatetaxamount()" class="form-control tip item_amount" id="amount1" onkeypress="return isNumberKey(this, event);" required="required" placeholder="Enter Invoice Amount" />'+ '</div>'+ '</div>'+ '<div class="col-md-2"><div class="form-group"><br><a class="remove_variation text-danger" title="Remove variation of product" style="cursor: pointer;"><i class="fa fa-times fa-2x"></i></a></div></div></div>'; $('#variations').append(html); }); $('#add_packate_variations').on('click', function() { html ='<div class="rowss">'+ '<div class="col-md-6">'+ '<div class="form-group">'+ '<label class="required" for="role">Description</label>'+ '<input type="text" name="new_reduction_item_name[]" class="form-control tip" placeholder="item Description" required="required">'+ '</div>'+ '</div>'+ '<div class="col-md-3">'+ '<div class="form-group">'+ '<label class="required" for="role">Amount</label> '+ '<input type="text" name="new_reduction_item_amount[]" value="0" onchange="calculatetaxamount()" onkeyup="calculatetaxamount()" class="form-control tip reduction_item_amount" id="amount1" onkeypress="return isNumberKey(this, event);" required="required" placeholder="Enter Invoice Amount" />'+ '</div>'+ '</div>'+ '<div class="col-md-1"><div class="form-group"><br><a class="remove_variations text-danger" title="Remove variation of product" style="cursor: pointer;"><i class="fa fa-times fa-2x"></i></a></div></div></div>'; $('#variationss').append(html); }); </script> <script type="text/javascript"> $(document).ready(function() { calculatetaxamount(); }); function calculatetaxamount(){ calculation_final_amt(); } function delete_item(id){ let text = "If Confirm you want to Delete this row!"; if (confirm(text) == true) { $.ajax({ type: 'POST', url: 'api/delete.php', data: {type:'invoice_item_delete',delete_id:id}, success: function(response) { console.log(response); location.reload(); } }); } } function calculation_final_amt(){ var item_amount = 0; $('.item_amount').each(function(){ item_amount += parseFloat(this.value); }); $('#invoice_amount').val(parseFloat(item_amount).toFixed(2)); var amount=$('#invoice_amount').val(); var tax=$('#tax_percentage').val(); if(tax!=0){ $('#tax_amount').val(parseFloat(amount*tax/100).toFixed(2)); $('#final_amount').val(parseFloat(parseFloat(amount)+parseFloat(amount*tax/100)).toFixed(2)); // $('#final_invoice_amount').val(parseFloat(amount)+parseFloat(amount*tax/100)); $('#tax_text').text(tax+' % Tax Amount'); }else{ //$('#final_invoice_amount').val($('#invoice_amount').val()); $('#final_amount').val(parseFloat($('#invoice_amount').val()).toFixed(2)); $('#tax_text').text(tax+' % Tax Amount'); $('#tax_amount').val(0); } // $('#final_payable_amount').val($('#final_invoice_amount').val()-$('#final_reduction_amount').val()); } function isNumberKey(txt, evt) { var charCode = (evt.which) ? evt.which : evt.keyCode; if (charCode == 46) { //Check if the text already contains the . character if (txt.value.indexOf('.') === -1) { return true; } else { return false; } } else { if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; } return true; } </script> <?php } include "footer.php";?>