ok
Direktori : /home2/selectio/public_html/lilyexpresslive/expense-invoice/ |
Current File : /home2/selectio/public_html/lilyexpresslive/expense-invoice/invoice-add-1.php |
<?php include "header.php"; $statement = $pdo->prepare("SELECT count(*) as total_invoice_num FROM `tbl_invoice` WHERE type=1"); $statement->execute(); $results = $statement->fetchAll(PDO::FETCH_ASSOC); $no=sprintf("%03d", $results[0]['total_invoice_num']+1); $invoice_num="SL".($no); if(isset($_POST['add_invoice'])){ try{ $date = date('Y-m-d h:i:s', time()); $statement = $pdo->prepare("SELECT count(*) as total_invoice_num FROM `tbl_invoice` WHERE type=1"); $statement->execute(); $results = $statement->fetchAll(PDO::FETCH_ASSOC); $invoice_id=$results[0]['total_invoice_num']+1; $statement = $pdo->prepare("INSERT INTO `tbl_invoice`(`inv_no`, `client_id`, `invoice_amount`, `date`, `period`, `year`, `gst_percentage`, `final_amount`, `submitted_status`, `remark`, `tax_type`,`type`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"); $result=$statement->execute(array($_POST['inv_no'],$_POST['client'],$_POST['final_payable_amount'],$_POST['inv_date'],$_POST['period'],$_POST['year'],$_POST['tax_percentage'],$_POST['final_invoice_amount'],1,' ',$_POST['tax_type'],1)); if($result){ for($n=0;$n<sizeof($_POST['item_description']);$n++){ $statement = $pdo->prepare("INSERT INTO `tbl_invoice_items`(`invoice_id`, `item_name`, `amount`,`type`) VALUES (?,?,?,?)"); $result=$statement->execute(array($invoice_id,$_POST['item_description'][$n],$_POST['item_amount'][$n],1)); } if(isset($_POST['reduction_item_name'])){ for($n=0;$n<sizeof($_POST['reduction_item_name']);$n++){ $statement = $pdo->prepare("INSERT INTO `tbl_invoice_items`(`invoice_id`, `item_name`, `amount`,`type`) VALUES (?,?,?,?)"); $result=$statement->execute(array($invoice_id,$_POST['reduction_item_name'][$n],$_POST['reduction_item_amount'][$n],2)); } } $message = 'Invoice is added successfully!'; unset($_POST); }else{ $warning="Something went wrong try again..."; } }catch(Exception $e){ $error=$e; } } ?> ?> <div class="content-wrapper"> <section class="content-header"> <h1>Add Invoice</h1> <ol class="breadcrumb"> <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li> <li class="active">Add 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"> <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" 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) { echo "<option value=".$result['id'].">".$result['name']."</option>"; }?> </select> </div> </div> <div class="col-md-2"> <div class="form-group"> <label class="required" for="location">Invoice Number</label> <input type="text" name="inv_no" placeholder="Enter Invoice Number" value="<?=$invoice_num?>" 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="" 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);?> <option value="<?=$f_y?>" <?php if(date("Y")==$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="<?=date("Y-m-d")?>" class="form-control datetimepicker tip" id="inv_date" required="required" /> </div> </div> <div class="col-md-12" > <div class="col-md-6" > <center><b style='font-size: 16px;color: crimson;'>Invoice Amount Details Update Or Add Here</b></center> <div class="col-md-6"> <div class="form-group"> <label class="required" for="role">Description</label> <input type="text" name="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="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"> <label for="role">Action</label> <br> <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> </div> </div> <div class="row" id="variations"> </div> </div> <div class="col-md-6" > <center><b style='font-size: 16px;color: crimson;'>Reduction Amount Details Update Or Add Here</b> <div class="row" id="variationss"> </div> <center><a id="add_packate_variations" 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> </center> </div> </div> <div class="col-md-12" > <div class="col-md-6" > <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="" 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">GST</option> <option value="2">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">0 %</option> <option value="5">5 %</option> <option value="10">10 %</option> <option value="12">12 %</option> <option value="18">18 %</option> <option value="28">28 %</option> </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" 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="" class="form-control tip" id="final_amount" required="required" placeholder="Auto Calculate Based on Tax and Invoice Amount" /></div> </div> <div class="col-md-6" > <hr> <div class="col-md-6" style="text-align: right;"><label class="required" for="role">Total Invoice Amount (With Tax)</label></div> <div class="col-md-6"><input type="text" min="5" name="final_invoice_amount" value="" class="form-control tip" id="final_invoice_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">Total Reduction Amount</label></div> <div class="col-md-6"><input type="text" min="5" name="final_reduction_amount" value="" class="form-control tip" id="final_reduction_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 Payable Amount</label></div> <div class="col-md-6"><input type="text" min="5" name="final_payable_amount" value="" class="form-control tip" id="final_payable_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="add_invoice" value="Add Invoice" class="btn btn-success" /> </form> </div> <div class="form-group" style="text-align:center;"> <a href="invoice-add.php"><button class="btn btn-primary" ><i class="fa fa-refresh"></i> Reset Form</button></a> <a href="invoice.php"><button class="btn btn-warning" ><i class="fa fa-chevron-left"></i> Back to List</button></a> </div> </div> </div> </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(); }); $(document).on('click', '.remove_variations', function() { $(this).closest('.rowss').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="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="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="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="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 calculation_final_amt(){ var item_amount = 0; $('.item_amount').each(function(){ item_amount += parseFloat(this.value); }); $('#invoice_amount').val(item_amount); var reduction_item_amount = 0; $('.reduction_item_amount').each(function(){ reduction_item_amount += parseFloat(this.value); }); $('#final_reduction_amount').val(reduction_item_amount); var amount=$('#invoice_amount').val(); var tax=$('#tax_percentage').val(); if(tax!=0){ $('#tax_amount').val(amount*tax/100); $('#final_amount').val(parseFloat(amount)+parseFloat(amount*tax/100)); $('#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($('#invoice_amount').val()); $('#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";?>