D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
thread-self
/
root
/
proc
/
self
/
root
/
home
/
shubmkcj
/
urbane.createerp.com
/
Filename :
edit-invoice2.php
back
Copy
<?php ob_start(); session_start(); include 'config.php'; $login = $_SESSION['login_email']; if($login == ''){ echo '<script>location.replace("index.php")</script>'; } ?> <!DOCTYPE html> <?php $invoice_type = ""; $id = $_GET['id']; $item = ""; $sqlitem = "SELECT * FROM invoice_items order by item_name"; $resultitem = mysqli_query($conn,$sqlitem); if($resultitem){ if(mysqli_num_rows($resultitem) > 0){ while( $rowitem = mysqli_fetch_assoc($resultitem)){ $item .= "<option value='". $rowitem['id'] ."'>".$rowitem['item_name']."</option> "; } } } $billing_company_name = ""; $billing_address_id = ""; $shipping_address_id = ""; $invoiceedit1 = "SELECT * FROM invoice where id = '$id'"; $invoiceresult1 = mysqli_query($conn,$invoiceedit1); while( $invoice1 = mysqli_fetch_array($invoiceresult1)){ $billing_company_name = $invoice1['billing_company_name']; $billing_address_id = $invoice1['billing_address_id']; $shipping_address_id = $invoice1['shipping_address_id']; $invoice_type = $invoice1['invoice_type']; } $billingAdd = "<option value=''>--Select--</option>"; $shippingAdd = "<option value=''>--Select--</option>"; $sqlGetBillingAddress = "SELECT a.* FROM contact_address a LEFT JOIN contact_manager b ON a.contact_id = b.id WHERE b.company_name = '$billing_company_name'"; $resultGetBillingAddress = mysqli_query($conn, $sqlGetBillingAddress); if($resultGetBillingAddress){ if(mysqli_num_rows($resultGetBillingAddress) > 0){ while($rowGetBillingAddress = mysqli_fetch_assoc($resultGetBillingAddress)){ $addressId = $rowGetBillingAddress["id"]; $address = $rowGetBillingAddress["address"]; $city = $rowGetBillingAddress["city"]; $state = $rowGetBillingAddress["state"]; $country = $rowGetBillingAddress["country"]; if($billing_address_id == $rowGetBillingAddress["id"]){ $billingAdd .= "<option value='".$rowGetBillingAddress["id"]."' selected>".$address.", ".$city.", ".$state.", ".$country."</option>"; // echo "<script>getBillingAddress('".$rowGetBillingAddress["id"]."');</script>"; } else{ $billingAdd .= "<option value='".$rowGetBillingAddress["id"]."'>".$address.", ".$city.", ".$state.", ".$country."</option>"; } if($shipping_address_id == $rowGetBillingAddress["id"]){ $shippingAdd .= "<option value='".$rowGetBillingAddress["id"]."' selected>".$address.", ".$city.", ".$state.", ".$country."</option>"; // echo "<script>getShippingAddress('".$rowGetBillingAddress["id"]."');</script>"; } else{ $shippingAdd .= "<option value='".$rowGetBillingAddress["id"]."'>".$address.", ".$city.", ".$state.", ".$country."</option>"; } } } } ?> <html> <head> <meta charset="utf-8" /> <title>Invoice Management | Invoice</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <meta content="A fully featured admin theme which can be used to build CRM, CMS, etc." name="description" /> <meta content="Coderthemes" name="author" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <!-- Font Awsome --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <!-- App favicon --> <link rel="shortcut icon" href="assets/images/favicon.png"> <!-- Pie Chart Css --> <!--<link href="assets/pie charts/style.css" rel="stylesheet" type="text/css" />--> <!-- App css --> <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" /> <link href="assets/css/icons.css" rel="stylesheet" type="text/css" /> <link href="assets/css/metismenu.min.css" rel="stylesheet" type="text/css" /> <link href="assets/css/style.css" rel="stylesheet" type="text/css" /> <link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/css/select2.min.css'> <link href="https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet"> <script> function getInvoicePrefix(companyId) { $.ajax({ url: "getInvoicePrefix.php?companyId=" + companyId, method: "GET", async: false, success: function(response) { var str = response.split(","); var myArray = str[0].split(/([0-9]+)/); // for(var j = 0; j<myArray.length; j++){ // console.log(myArray[j]); // } var lastNumber = "0"+str[1]; var prev = ""; var i = 0; do{ prev = prev+""+myArray[i]; i++; }while(i < myArray.length-2); if(Number.isInteger(parseInt(myArray[myArray.length-2]))){ var val = parseInt(parseInt(myArray[myArray.length-2])+ parseInt(lastNumber)); $("#invoice_id").val("#"+prev + "" + val); } else{ $("#invoice_id").val("#"+prev+""+lastNumber); } // $("#invoice_id").val("#" + str[0] + "/" + str[1]); $("#invoice_number").val(str[1]); }, error: function(jqXHR, textStatus, errorThrown) { alert('Internal error: ' + jqXHR.responseText); } }) } </script> </head> <body> <!-- Begin page --> <div id="wrapper"> <!-- Top Bar Start --> <?php include 'top-header.php'; ?> <!-- Top Bar End --> <!-- ========== Left Sidebar Start ========== --> <?php include 'left-sidebar.php'; ?> <!-- Left Sidebar End --> <!-- ============================================================== --> <!-- Start right Content here --> <!-- ============================================================== --> <div class="content-page"> <!-- Start content --> <div class="content"> <div class="container-fluid"> <div class="row"> <div class="col-12"> <div class="page-title-box"> <h4 class="page-title float-left"><?php if($invoice_type == "Performa Invoice"){ echo "Update Performa"; } else { echo "Update Invoice";} ?></h4> <ol class="breadcrumb float-right"> <li class="breadcrumb-item"><a href="#">Sales</a></li> <li class="breadcrumb-item active"><?php if($invoice_type == "Performa Invoice"){ echo "Update Performa"; } else { echo "Update Invoice";} ?></li> </ol> <div class="clearfix"></div> </div> </div> </div> <!-- end row --> <form action="update_invoice.php?id=<?php echo $id ?>" method="post" class="form-horizontal" role="form"> <div class="card-box"> <?php $invoiceedit = "SELECT * FROM invoice where id = '$id'"; $invoiceresult = mysqli_query($conn,$invoiceedit); while( $invoice = mysqli_fetch_array($invoiceresult)){ $discountValueqty = explode(',', $invoice['discount_value_qty']); $itemname = explode(',', $invoice['item_name']); $price = explode(',', $invoice['price']); $itemquantity = explode(',', $invoice['quantity']); $itemtax = explode(',', $invoice['tax']); $itemtotalamount = explode(',', $invoice['total_amount']); $itemdis_app = explode(',', $invoice['discount_applied']); $itemdis_cat = explode(',', $invoice['discount_category']); $itemtax_value = explode(',', $invoice['tax_value']); $count = sizeof($itemname); ?> <input type="hidden" class="form-control" name="invoice_number" id="invoice_number" value="<?php echo $invoice["invoice_number"]; ?>" readonly> <input type="hidden" class="form-control" name="billingCompany" value="<?php echo $invoice['company_id'] ?>" readonly> <div class="row"> <!-- <div class="col-md-6"> <div class="form-group"> <label for="inputEmail3" class="col-form-label">Select Corporate Profile</label> <?php $com = ""; $idd = $invoice['company_id']; $sqlGetCompanyName = "SELECT * FROM company_details where id = '$idd'"; $resultGetCompanyName = mysqli_query($conn, $sqlGetCompanyName); if($resultGetCompanyName){ if(mysqli_num_rows($resultGetCompanyName) > 0){ while($rowGetCompanyName = mysqli_fetch_array($resultGetCompanyName)){ $com = $rowGetCompanyName['company_name'] ; } } } ?> </select> <input type="text" class="form-control" value="<?php echo $com ?>" readonly> </div> </div> --> <div class="col-md-6"> <div class="form-group"> <label for="inputPassword3" class="col-form-label"><?php if($invoice_type == "Performa Invoice"){ echo "Performa Id"; } else { echo "Invoice";} ?></label> <input type="text" class="form-control" name="invoice_id" id="invoice_id" value="<?php echo $invoice['invoice'] ?>" readonly> </div> </div> </div> <div class="row"> <div class="col-lg-4"> <div class="form-group"> <label for="inputPassword4" class="col-form-label">Date</label> <input type="text" class="form-control" name="date" id="date" value="<?php echo $invoice['date'] ?>"> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="terms" class="col-form-label">Terms</label> <select class="form-control" name="terms" id="terms"> <option value="">--Select--</option> <option value="Paid" <?php if($invoice["terms"] == "Paid") { echo "selected"; } ?>>Paid</option> <option value="Net 7" <?php if($invoice["terms"] == "Net 7") { echo "selected"; } ?>>Net 7</option> <option value="Net 15" <?php if($invoice["terms"] == "Net 15") { echo "selected"; } ?>>Net 15</option> <option value="Net 30" <?php if($invoice["terms"] == "Net 30") { echo "selected"; } ?>>Net 30</option> <option value="Net 60" <?php if($invoice["terms"] == "Net 60") { echo "selected"; } ?>>Net 60</option> <option value="Due end of the month" <?php if($invoice["terms"] == "Due end of the month") { echo "selected"; } ?>>Due end of the month</option> <option value="Due end of the next month" <?php if($invoice["terms"] == "Due end of the next month") { echo "selected"; } ?>>Due end of the next month</option> <option value="Due on reciept" <?php if($invoice["terms"] == "Due on reciept") { echo "selected"; } ?>>Due on reciept</option> <option value="Custom" <?php if($invoice["terms"] == "Custom") { echo "selected"; } ?>>Custom</option> </select> </div> </div> <div class="col-md-4"> <div class="form-group"> <label for="inputPassword4" class="col-form-label">Due Date</label> <input type="text" class="form-control" name="due_date" id="due_date" value="<?php echo $invoice['due_date'] ?>"> </div> </div> </div> <div class="row"> <div class="col-md-12"> <div class="form-group"> <label for="inputEmail3" class="col-form-label">Select Customer / Client</label> <select class="form-control" name="users" onchange="showUser(this.value)" required> <option value="">--Select--</option> <?php $sql = "SELECT * FROM contact_manager where trim(data_delete) != 'yes'"; $result = mysqli_query($conn,$sql); while( $row = mysqli_fetch_array($result)){ $company_name = $row['customer_client']; if($company_name == 'company name'){ ?> <option value="<?php echo $row['id'] ?>" <?php if($invoice["billing_company_name"] == $row["company_name"]){ echo "selected"; } ?>> <?php echo $row["company_name"] ?></option> <?php }else { ?> <option value="<?php echo $row['id'] ?>" <?php if($invoice["billing_company_name"] == $row["contact_person_name"]){ echo "selected"; } ?>> <?php echo $row['contact_person_name'] ?></option> <?php } } ?> </select> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label for="inputPassword4" class="col-form-label">Billing Address</label> <select name="billingAddress" id="billingAddress" class="form-control" onchange="getBillingAddress(this.value)"> <?php echo $billingAdd; ?> </select> </div> </div> <div class="col-md-6"> <div class="form-group"> <label for="inputPassword4" class="col-form-label">Shipping Address</label> <select name="shippingAddress" id="shippingAddress" class="form-control" onchange="getShippingAddress(this.value)"> <?php echo $shippingAdd; ?> </select> </div> </div> </div> <div class="row"> <div class="col-md-6"> <div class="form-group"> <div id="txtHint"><b>Billing Address info will be listed here...</b> <p></p> </div> </div> </div> <div class="col-md-6"> <div class="form-group"> <div id="txtHint1"><b>Shipping Address info will be listed here...</b> <p></p> </div> </div> </div> </div> <div class="row"> <button id="add" class="btn add-more button-yellow uppercase" type="button">+ Add Line Item</button> <table class="table"> <thead> <tr style="width:100%"> <th style="width:50%">Item Name</th> <th>Price</th> <th>Quantity</th> <th>Tax</th> <th>Total</th> <th style="display:none"></th> <th style="display:none"></th> <th style="display:none"></th> <th style="display:none"></th> <th></th> </tr> </thead> <tbody id='itemsadd'> <?php for($i = 0 ; $i < $count; $i++){ ?> <tr style="width:100%"> <td style="width:50%"> <div id="text"> <select class="form-control select itemClass" name="item[]" onchange="showitem(this)"> <?php $sqlitem = "SELECT * FROM inventory_manager order by item_name"; $resultitem = mysqli_query($conn,$sqlitem); if($resultitem){ if(mysqli_num_rows($resultitem) > 0){ while( $rowitem = mysqli_fetch_assoc($resultitem)){ if($rowitem["id"] == $itemname[$i]){ echo "<option value='". $rowitem['id'] ."' selected>".$rowitem['item_name']."</option> "; } else{ echo "<option value='". $rowitem['id'] ."'>".$rowitem['item_name']."</option> "; } } } } ?> </select> </td> <td style="width:20%"> <input class='form-control priceClass' name='price[]' type='text' value='<?php echo $price[$i] ?>' ondrop='return false;' onpaste='return false;' readonly> </td> <td style="width:5%"> <input class='form-control quantityClass' name="qty[]" type="text" value="<?php echo $itemquantity[$i] ?>" ondrop='return false;' onpaste='return false;'> </td> <td style="width:10%"> <input class='form-control taxamount' name="tax[]" value="<?php echo $itemtax[$i] ?>" type='text'> </td> <td style="width:15%"> <input type="text" name="total_amt[]" value="<?php echo $itemtotalamount[$i] ?>" class='form-control totalClass' readonly> </td> <td style="width:0%; display:none;"> <input type="hidden" name="applied_discount[]" value="<?php echo $itemdis_app[$i] ?>" class="discountAppliedClass"> </td> <td style="width:0%; display:none;"> <input type="hidden" name="discountValueqty[]" class="discountValueqty" value="<?php echo $discountValueqty[$i] ?>"> </td> <td style="width:0%; display:none;"> <input type="hidden" name="category_discount[]" value="<?php echo $itemdis_cat[$i] ?>" class="discountCategoryClass"> </td> <td style="width:0%; display:none;"> <input type='hidden' name="tax_val[]" value="<?php echo $itemtax_value[$i] ?>" class='form-control taxClass' readonly> </td> <td><button type='button' class='btn btn-xs btn-danger delete'><span class='fa fa-trash'></span></button></td> </tr> <?php } ?> </tbody> </table> </div> <div class="row"> <div class="col-md-6"> </div> <div class="col-md-6"> <div class="form-group row"> <label class="col-4 col-form-label" for="example-email">Total Discount : </label> <div class="col-8"> <input type="text" id="disamountvalue" class="form-control" name="total_discount" value="<?php echo $invoice['total_discount'] ?>" readonly> </div> </div> <div class="form-group row"> <label class="col-4 col-form-label" for="example-email">Total Tax : </label> <div class="col-8"> <input type="text" id="taxvalue" class="form-control" name="total_tax" value="<?php echo $invoice['total_tax'] ?>" readonly> </div> </div> <div class="form-group row"> <label class="col-4 col-form-label" for="example-email">Subtotal : </label> <div class="col-8"> <input type="text" id="a4" class="form-control" name="subtotal" value="<?php echo $invoice['sub_total'] ?>" readonly> </div> </div> <div class="form-group row"> <label class="col-4 col-form-label" for="example-email">Amount Paid : </label> <div class="col-8"> <input type="text" id="amountvalue" class="form-control" name="amount_paid" value="<?php echo $invoice['amount_paid'] ?>" readonly> </div> </div> </div> </div> <button type="submit" class="btn btn-info waves-effect waves-light">Update</button> </form> <?php } ?> </div> </div> </div> <!-- container --> </div> <!-- content --> <?php include 'copyrignt.php' ?> </div> <!-- ============================================================== --> <!-- End Right content here --> <!-- ============================================================== --> </div> <!-- END wrapper --> <!-- Chart Js --> <script src='https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.3/Chart.js'></script> <!-- jQuery --> <script src="assets/js/jquery.min.js"></script> <script src="assets/js/popper.min.js"></script><!-- Popper for Bootstrap --> <script src="assets/js/bootstrap.min.js"></script> <script src="assets/js/metisMenu.min.js"></script> <!--<script src="assets/js/waves.js"></script>--> <script src="assets/js/jquery.slimscroll.js"></script> <!-- Dashboard init --> <script src="assets/pages/jquery.dashboard.js"></script> <!-- App js --> <script src="assets/js/jquery.core.js"></script> <script src="assets/js/jquery.app.js"></script> <!-- Chart Js --> <!-- <script src="assets/pie charts/script.js"></script>--> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script> <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.min.js'></script> <script src="assets/js/modernizr.min.js"></script> <!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> --> <script type="text/javascript" src="script.js"></script> <script> $(document).ready(function() { // $(".delete").hide(); //when the Add Field button is clicked $("#add").click(function(e) { $(".delete").fadeIn("1500"); //Append a new row of code to the "#items" div $("#itemsadd").append( "<tr id='next-referral'><td><div><select class='form-control select itemClass' name='item[]' onchange='showitem(this)'><option value=''>--Select Item--</option><?php echo $item ?></select></div></td><td><input class='form-control priceClass' name='price[]' type='text' ondrop='return false;' onpaste='return false;' readonly></td><td><input name='qty[]' type='text' class='form-control quantityClass' keyup='keyupMethod(this)' ondrop='return false;' onpaste='return false;'></td><td><input type='text' name='tax[]' class='form-control taxamount'></td><td><input type='text' name='total_amt[]' value='' class='form-control totalClass' readonly></td><td style='display:none;'><input type='hidden' name='applied_discount[]' class='discountAppliedClass' ></td><td style='display:none;'><input type='hidden' name='discountValueqty[]' class='discountValueqty' ></td><td style='display:none;'> <input type='hidden' name='category_discount[]' class='discountCategoryClass'></td><td style='display:none;'><input type='hidden' name='tax_val[]' class='form-control taxClass' readonly></td><td> <button type='button' class='btn btn-xs btn-danger delete'><span class='fa fa-trash'></span></button></td></tr>" ); forSelect(); }); //("body").on("click", ".delete", function(e) { //$("#next-referral").last().remove(); //}); }); </script> <script> function selectOption() { $('.select').select2(); } $(document).ready(function() { forSelect(); }); function forSelect() { selectOption(); $('#add').click(function() { var text = $('#text').html(); $('#demo').append(text); $('#demo .select').select2(); $('#demo .select').last().next().next().remove(); }); } $(document).on('keyup', '.quantityClass', function() { var sum = 0; var gsum = 0; var price = 0; var quantity = 0; var tax = 0; var discountApplied = 0; var discountCategory = ""; var discountValue = 0; var thisRow = $(this).closest('tr'); thisRow.find('.priceClass').each(function() { if (this.value == null || this.value == '') price = 0; else price = this.value; }); thisRow.find('.quantityClass').each(function() { if (this.value == null || this.value == '') quantity = 0; else quantity = this.value; }); thisRow.find('.taxClass').each(function() { if (this.value == null || this.value == '') tax = 0; else tax = this.value; }); thisRow.find('.discountAppliedClass').each(function() { if (this.value == null || this.value == '') discountApplied = 0; else discountApplied = this.value; }); thisRow.find('.discountCategoryClass').each(function() { discountCategory = this.value; }); var decreaseValue = parseInt(price) * parseInt(quantity); if (discountCategory == "percent") { var disamountpercent = parseFloat((discountApplied / 100) * decreaseValue); var disamount = parseFloat(decreaseValue) - parseFloat(disamountpercent); discountValue = parseInt(disamountpercent); } else if (discountCategory == "flat") { var disamountpercent = discountApplied; discountValue = parseFloat(disamountpercent) * parseFloat(quantity); var disamount = parseFloat(decreaseValue) - parseFloat(discountValue); } var taxInclude = parseFloat((tax / 100) * disamount).toFixed(2); // var subTotal = (parseFloat(disamount) + parseFloat(taxInclude)).toFixed(2); var subTotal = (parseFloat(disamount)).toFixed(2); thisRow.find('.totalClass').val(subTotal); thisRow.find('.taxamount').val(taxInclude); thisRow.find('.discountValueqty').val(discountValue); var totalColumn = $(this).closest('tr').parent(); // for total amount var totalPrice = 0; totalColumn.find('.totalClass').each(function() { totalPrice = (parseFloat(totalPrice) + parseFloat(this.value)).toFixed(2); }); $("#a4").val(totalPrice); //----------------------------- // for total amount var totaldiscount = 0; totalColumn.find('.discountValueqty').each(function() { totaldiscount = parseFloat(totaldiscount) + parseFloat(this.value); // alert(totaldiscount); }); $("#disamountvalue").val(parseFloat(totaldiscount).toFixed(2)); //----------------------------- // for total amount var totaltaxInclude = 0; totalColumn.find('.taxamount').each(function() { totaltaxInclude = (parseFloat(totaltaxInclude) + parseFloat(this.value)).toFixed(2); }); $("#taxvalue").val(totaltaxInclude); //----------------------------- // alert(totaltax); //payableamount = (parseFloat(totaltax) + parseFloat(totalPrice)).toFixed(2); $("#amountvalue").val((parseFloat($("#taxvalue").val()) + parseFloat($("#a4").val())).toFixed(2)); }); $(document).on('click', '.delete', function() { var totalColumn = $(this).closest('tr').parent(); $(this).closest('tr').remove(); // for total amount var totalPrice = 0; totalColumn.find('.totalClass').each(function() { totalPrice = (parseFloat(totalPrice) + parseFloat(this.value)).toFixed(2); // alert(totalPrice); // alert('ok'); }); $("#a4").val(totalPrice); //----------------------------- // for total amount var totaldiscount = 0; totalColumn.find('.discountValueqty').each(function() { totaldiscount = parseFloat(totaldiscount) + parseFloat(this.value); // alert(totaldiscount); }); $("#disamountvalue").val(parseFloat(totaldiscount).toFixed(2)); //----------------------------- // for total amount var totaltaxInclude = 0; totalColumn.find('.taxamount').each(function() { totaltaxInclude = (parseFloat(totaltaxInclude) + parseFloat(this.value)).toFixed(2); }); $("#taxvalue").val(totaltaxInclude); //----------------------------- // alert(totaltax); //payableamount = (parseFloat(totaltax) + parseFloat(totalPrice)).toFixed(2); $("#amountvalue").val((parseFloat($("#taxvalue").val()) + parseFloat($("#a4").val())).toFixed(2)); }); $(document).ready(function() { $("#s").change(function() { if (!this.checked) { $("#due_date").removeAttr('disabled'); $("#due_date").removeAttr('readonly'); if ($("#due_date").val() == "Paid") { $("#due_date").val("<?php echo date('j F Y'); ?> "); } } else { $("#due_date").attr('disabled', 'disabled'); $("#due_date").attr('readonly', 'true'); $("#due_date").val("Paid"); } }); //triger change event in case checkbox checked when user accessed page $("#s").trigger("change") }); $(document).ready(function() { $("#due_date,#date").datepicker({ dateFormat: 'dd MM yy' }); }); $(document).ready(function(){ $("#terms").change(function(){ var date1 = $('#date').val(); var date = new Date( Date.parse( date1 ) ); var terms = $( "#terms option:selected" ).val(); if(terms === "Paid"){ } else if(terms === "Net 7"){ date.setDate( date.getDate() + 7 ); var newDate = date.toDateString(); newDate = new Date( Date.parse( newDate ) ); $('#due_date').datepicker('setDate', newDate ); } else if(terms === "Net 15"){ date.setDate( date.getDate() + 15 ); var newDate = date.toDateString(); newDate = new Date( Date.parse( newDate ) ); $('#due_date').datepicker('setDate', newDate ); } else if(terms === "Net 30"){ date.setDate( date.getDate() + 30 ); var newDate = date.toDateString(); newDate = new Date( Date.parse( newDate ) ); $('#due_date').datepicker('setDate', newDate ); } else if(terms === "Net 60"){ date.setDate( date.getDate() + 60 ); var newDate = date.toDateString(); newDate = new Date( Date.parse( newDate ) ); $('#due_date').datepicker('setDate', newDate ); } else if(terms === "Due end of the month"){ $('#due_date').datepicker('setDate', new Date(date.getFullYear(), date.getMonth() + 1, 0)); } else if(terms === "Due end of the next month"){ $('#due_date').datepicker('setDate', new Date(date.getFullYear(), date.getMonth() + 2, 0)); } }); }); $(document).ready(function(){ $("#date").change(function(){ $("#terms").trigger("change"); }); $("#due_date").change(function(){ $('#terms option[value="Custom"]').attr("selected", "selected"); }); }); </script> </body> </html>