JezK
Edit File: invoicesNew.php
<?php include("header.php"); $optionData=''; $quotationids=$wareHouseAdminObj->get_wareHouseData($_SESSION['company_id']); foreach($quotationids as $id){ $optionData.='<option value='.$id['quotation_id'].'>'.$id['quotation_id'].'</option>'; } ?> <a href="javascript:history.go(-1)"><img src="images/back_main.png" class="pb-3 px-5"></a> <div class="container px-md-5 px-3"> <h4><?php echo $lang['ADD_INVOICES'];?></h4> <form action="app/invoices-app.php" method="post"> <div class="containercontent"> <div class="card-1 shadow-sm p-3 mb-5 bg-white rounded"> <div class="card-body invoices_page_div"> <div class="row"> <div class="col-md-6 col-lg-3 col-sm-12 form-group"> <label for="invoices"><?php echo $lang['QUOTATION_ID'];?></label> <select id="quotationId" name="quotationid" class="form-control frm-input " onchange="selectQuationId()"> <option value=""><?php echo $lang['SELECT'];?></option> <?php echo $optionData ?> </select> <div class="error quotationid_error"></div> </div> <div class="col-md-6 col-lg-3 col-sm-12 form-group"> <label for="invoices"><?php echo $lang['QUOTATION_VALUE'];?></label> <div class="row"> <div class="col-8" style="padding-right: 0px !important;"> <input type="text" class=" form-control " id="invoices" placeholder="" name="invoices" ></div> <div class="col-4" style="padding-left: 2px !important;"><input class="form-control" id="invoiceCountry"></div> </div> <div class="error Invoicevalue_error"></div> </div> <div class="col-md-6 col-lg-3 col-sm-12 form-group"> <label for="whname"><?php echo $lang['WAREHOUSE_NAME'];?></label> <input type="text" class="form-control" id="whname" placeholder="" name="whname" readonly> <div class="error whname_error"></div> </div> <div class="col-md-6 col-lg-3 col-sm-12 form-group"> <label for="whnumber"><?php echo $lang['WAREHOUSE_NUMBER'];?></label> <input type="text" class="form-control" id="whnumber" placeholder="" name="whnumber" readonly> <div class="error whnumber_error"></div> </div> </div> <div class="row"> <div class="col-md-6 col-lg-3 col-sm-12 form-group"> <label for="customer"><?php echo $lang['CUSTOMER_NAME'];?></label> <input type="text" class="customer_name form-control" id="customer" placeholder="" name="customer" readonly> <div class="error customer_error"></div> </div> <div class="col-md-6 col-lg-3 col-sm-12 form-group"> <label for="date"><?php echo $lang['DATE'];?></label> <span> <input type="text" class="date form-control" id="date" placeholder="" name="date"> <span class="position-absolute" style="right:20px; top:40px "><i class="fa fa-calendar" aria-hidden="true"></i></span> </span> <div class="error date_error"></div> <!-- <div class="error date_error"></div> --> </div> </div> <div class="row"> <div class="col-md-12 form-group"> <label for="customer"><?php echo $lang['DESCRIPTION'];?></label> <textarea id="DescriptionMsg" name="DescriptionMsg" rows="3" class="form-control"></textarea> <div class="error customer_error"></div> </div> </div> <!-- <div class="row"> <div class="col-md-3"> <label for="invoices"><?php echo $lang['QUOTATION_ID'];?>:</label> </div> <div class="col-md-3"> <select id="quotationId" name="quotationid" class="form-control frm-input " onchange="selectQuationId()"> <option value=""><?php echo $lang['SELECT'];?></option> <?php echo $optionData ?> </select> <div class="error quotationid_error"></div> </div> <div class="col-md-3"> <label for="invoices"><?php echo $lang['QUOTATION_VALUE'];?>:</label> </div> <div class="col-md-3 "> <input type="text" class="InvoiceValue form-control" id="invoices" placeholder="" name="invoices" ><span class="" id="invoiceCountry"></span> <div class="error Invoicevalue_error"></div> </div> </div> --> <!-- <div class="row"> <div class="col-md-2"> <label for="whname"><?php echo $lang['WAREHOUSE_NAME'];?>:</label> </div> <div class="col-md-3"> <input type="text" class="" id="whname" placeholder="" name="whname" readonly> <div class="error whname_error"></div> </div> <div class="col-md-2"> <label for="whnumber"><?php echo $lang['WAREHOUSE_NUMBER'];?>:</label> </div> <div class="col-md-3"> <input type="text" class="" id="whnumber" placeholder="" name="whnumber" readonly> <div class="error whnumber_error"></div> </div> </div> --> <!-- <div class="row"> <div class="col-md-2"> <label for="customer"><?php echo $lang['CUSTOMER_NAME'];?>:</label> </div> <div class="col-md-3"> <input type="text" class="customer_name" id="customer" placeholder="" name="customer" readonly> <div class="error customer_error"></div> </div> <div class="col-md-2 justify-content-end"> <label for="date"><?php echo $lang['DATE'];?>:</label> </div> <div class="col-md-3"> <span> <input type="text" class="date" id="date" placeholder="" name="date"> <span class="position-absolute" style="right:20px"><i class="fa fa-calendar" aria-hidden="true"></i></span> </span> <div class="error date_error"></div> </div> </div> --> <!-- <div class="row"> <div class="col-md-2 pl-3 mt-2"> <label for="customer"><?php echo $lang['DESCRIPTION'];?>:</label> </div> <div class="col-md-8"> <textarea id="DescriptionMsg" name="DescriptionMsg" rows="2" class="form-control"></textarea> <div class="error customer_error"></div> </div> </div> --> </div> <!-- <div class="row"> <div class="col-md-2"> <label for="whname">Description:</label> </div> <div class="col-md-2"> <input type="text" class="" id="description" placeholder="" name="description"> </div> </div> --> <input type="hidden" name="user_id" id="user_id"/> <input type="hidden" name="warehouse_id" id="warehouse_id"/> <div class="table-responsive"> <table class="table table-bordered table_body newRow_add" id="myTable"> <thead class="theadcolor"> <tr> <th><?php echo $lang['ITEM_NO'];?></th> <th><?php echo $lang['DESCRIPTION'];?></th> <th><?php echo $lang['NUMBER_OF_PALLETS_SPACE'];?></th> <th><?php echo $lang['QUANTITY'];?></th> <th id="currencyLabel"><?php echo $lang['PRICE'];?></th> <th><?php echo $lang['TOTAL'];?></th> </tr> </thead> <tbody> <tr> <td><input type="text" id="item_no" name="Item_No[]" ></td> <td><input type="text" id="description" name="Description[]"></td> <td><input type="text" id="number_of_Pallets" name="Number_of_Pallets[]" onkeypress="return checkPhone(event)"></td> <td><input type="text" id="quantity" name="Quantity[]" onkeypress="return checkPhone(event)"></td> <td><input type="text" id="price" name="Price[]" onkeypress="return checkPhone(event)"></td> <td><input type="text" id="Total" name="Total[]" ></td> </tr> </tbody> </table> </div> <div class="error rowadd_error"></div> <div class="error Item_No_error"></div> <div class="error Description_error"></div> <div class="error Number_of_Pallets_error"></div> <div class="error Quantity_error"></div> <div class="error Price_error"></div> <div class="error Total_error"></div> <!-- <div class="d-flex justify-content-end align-items-baseline"> --> <!-- <label><strong>total</strong></label> <span class="inputWidth"> <input type="text" class="form-control" id="totalvalue"/> </span> --> <div class="d-flex justify-content-between align-items-baseline borderdashed"> <div> <label><strong><?php echo $lang['GRAND_TOTAL'];?><strong></label> </div> <div class="inputwid"> <span class="inputWidth"> <input type="text" class="form-control" id="totalvalue" name="totalvalue"/> </span> </div> </div> <!-- </div> --> <button id="addRow" disabled><?php echo $lang['ADD'];?></button> <button id="addRowSave" name="addInvoices" onclick="return newinvoicesvalidations();"><?php echo $lang['SAVE'];?></button> <!--<div class="d-flex justify-content-end"> <div>Total 150 Dinar </div> </div>--> </div> </div> </form> <?php include("footer.php"); ?> <style> .newRow_add tr td { padding: 0px !important; } .newRow_add tr td input{ width:100% !important;border:none;background:#eaeffa;padding: 10px;border-bottom: 1px solid #3663c88c; } button#addRow ,button#addRowSave{ background: #3663c8; border: none; padding: 5px 15px; color: #fff; } /* .invoices_page_div input, .invoices_page_div textarea { width: 100%; border: 1px solid #3663c8; border-radius: 5px; padding: 0px 5px; } */ input.InvoiceValue { width: 75%; } .currencyType1 { /* position: absolute; */ /* margin-left: 8px !important; */ color: #2c60d0; font-weight: bold; /* border: 1px solid #49505752; */ /* padding: 6px; */ } .inputwid{ width: 149px; } span.inputWidth input.form-control { background: #eaeffa; border:none; outline:none; color:black; font-weight:bold; } .borderdashed { margin-bottom: 10px; border-top: 1px dashed; border-bottom: 1px dashed; padding: 3px; } table#myTable input,span.inputWidth input { text-align: center; } </style> <script> $('.newRow_add tbody input').change(function(event){ var len=0; $(".newRow_add tbody input").each(function(){ if(this.value != ""){ len++; } if(len==4){ $("#addRow").removeAttr("disabled"); $("#addRow").removeClass("btn-color"); } }); }) var counter = 0; $ = jQuery; $('#addRow').click(function(event){ event.preventDefault(); $('.error').html(''); var valid = 0; $(".newRow_add tbody input").each(function(){ if(this.value == ""){ valid++; } }) if(valid==0){ counter++; var newRow = $('<tr id='+counter+'><td><input type="text" id="Item_No'+counter+'" name="Item_No[]"/></td><td><input type="text" id="Description'+counter+'" name="Description[]"/></td><td><input type="text" id="Number_of_Pallets'+counter+'" name="Number_of_Pallets[]"/></td><td><input type="text" id="Quantity'+counter+'" name="Quantity[]" onkeypress="return checkPhone(event)"/></td><td><input type="text" id="Price'+counter+'" name="Price[]" onkeypress="return checkPhone(event)"/></td><td><input type="text" id="Total'+counter+'"name="Total[]"/></td></tr>'); jQuery('table.newRow_add').append(newRow); } else{ $('.rowadd_error').html('* <?php echo $lang['PLEASE_FILL_ALL_THE_REQUIRED_FIELDS']; ?>'); } }); $('#date').datetimepicker({ format: 'DD-MM-YYYY', minDate:new Date() }); function selectQuationId(){ var id = $("#quotationId").val(); jQuery.ajax({ type:"POST", url:'ajax.php', data:({action:"get_quotations",quotationId:id}), success:function(data){ data1=JSON.parse(data); console.log(data1.result); document.getElementById('invoices').value=data1.result.admin_expected_rate; document.getElementById('whname').value=data1.result.warehouse_name; document.getElementById('whnumber').value=data1.result.warehouse_number; document.getElementById('customer').value=data1.result.first_name; document.getElementById('user_id').value=data1.result.user_id; document.getElementById('warehouse_id').value=data1.result.warehouse_id; document.getElementById('invoiceCountry').value=data1.result.currency; document.getElementById('currencyLabel').innerText=" <?php echo $lang['PRICE'];?> ("+ data1.result.currency +")"; //~ document.getElementById('wadmin_id').value=data1.result.wadmin_id; } }) $('#invoiceCountry').addClass('currencyType1') } function newinvoicesvalidations(){ let quotationId =document.getElementById('quotationId').value; let invoices=document.getElementById('invoices').value; let whname=document.getElementById('whname').value; let whnumber=document.getElementById('whnumber').value; let customer=document.getElementById('customer').value; let date=document.getElementById('date').value; // alert(total_days); let itemcode=document.getElementById('item_no').value let item_desc=document.getElementById('description').value let qty=document.getElementById('number_of_Pallets').value let ref_number=document.getElementById('quantity').value let cost=document.getElementById('price').value let pallet_no=document.getElementById('Total').value $('.error').html(''); if(quotationId==''){ $('.quotationid_error').html('<?php echo $lang['SELECT_QUOTATION_ID']; ?>'); $('#qutationid').focus(); return false; exit; } else if(invoices=='' ){ // alert('hello') $('.Invoicevalue_error').html('<?php echo $lang['INVOICE_VALUE_REQUIRED']; ?>'); $('#invoices').focus() return false; } else if(whname==''){ $('.whname_error').html('<?php echo $lang['WAREHOUSE_NAME_REQUIRED']; ?>'); $('#whname').focus(); return false; } else if(whnumber==''){ $('.whnumber_error').html('<?php echo $lang['WAREHOUSE_NUMBER_REQUIRED']; ?>'); $('#whnumber').focus() return false; } else if(customer==''){ $('.customer_error').html('<?php echo $lang['CUSTOMER_NAME_REQUIRED']; ?>'); $('#customer').focus(); return false; } else if(date==''){ $('.date_error').html('<?php echo $lang['PLEASE_ENTER_DATE']; ?>'); $('#date').focus(); return false; } else if(itemcode==''){ $('.Item_No_error').html('<?php echo $lang['PLEASE_ENTER_ITEMCODE']; ?>'); $('#Item_No').focus(); return false; } else if(item_desc==''){ $('.Description_error').html('<?php echo $lang['PLEASE_ENTER_ITEM_DESC']; ?>'); $('#Description').focus(); return false; } else if(qty==''){ $('.Number_of_Pallets_error').html('<?php echo $lang['PLEASE_ENTER_NUMBER_PALLETS']; ?>'); $('#Number_of_Pallets').focus(); return false; } else if(ref_number==''){ $('.Quantity_error').html('<?php echo $lang['PLEASE_ENTER_QUANTITY']; ?>'); $('#Quantity').focus(); return false; } else if(cost==''){ $('.Price_error').html('<?php echo $lang['PLEASE_ENTER_PRICE']; ?>'); $('#Price').focus(); return false; } else if(pallet_no==''){ $('.Total_error').html('<?php echo $lang['PLEASE_ENTER_TOTAL']; ?>'); $('#Total').focus(); return false; } let itemcodeval=document.getElementsByName('Item_No[]') let item_descval=document.getElementsByName('Description[]') let qtyval=document.getElementsByName('Number_of_Pallets[]') let ref_numberval=document.getElementsByName('Quantity[]') let costval=document.getElementsByName('Price[]') let pallet_noval=document.getElementsByName('Total[]') for(x=0 ;x< itemcodeval.length ; x++) { if(itemcodeval[x].value == '' || itemcodeval[x].value == '0') { $(".Item_No_error").html('* <?php echo $lang['PLEASE_ENTER_ITEMCODE']; ?>'); itemcodeval[x].focus(); return false; } else if(item_descval[x].value == '' || item_descval[x].value == '0') { $(".Description_error").html('* <?php echo $lang['PLEASE_ENTER_ITEM_DESC']; ?>'); item_descval[x].focus(); return false; } else if(qtyval[x].value == '') { $(".Number_of_Pallets_error").html('* <?php echo $lang['PLEASE_ENTER_NUMBER_PALLETS']; ?>'); qtyval[x].focus(); return false; } else if(ref_numberval[x].value == '' || ref_numberval[x].value == '0') { $(".Quantity_error").html('* <?php echo $lang['PLEASE_ENTER_QUANTITY']; ?>'); ref_numberval[x].focus(); return false; } else if(costval[x].value == '' || costval[x].value == '0') { $(".Price_error").html('* <?php echo $lang['PLEASE_ENTER_PRICE']; ?>'); costval[x].focus(); return false; } else if(pallet_noval[x].value == '' || pallet_noval[x].value == '0') { $(".Price_error").html('* <?php echo $lang['PLEASE_ENTER_PRICE']; ?>'); pallet_noval[x].focus(); return false; } } } $("#price,#quantity").on("input",function(){ let quantityVal=$("#quantity").val(); let priceVal=$('#price').val(); if(quantityVal==""&& priceVal==""){ $(".Price_error").html('* <?php echo $lang['PLEASE_ENTER_QUANTITY_AND_PRICE']; ?>'); $("#quantity").focus(); } else{ let totalVal=quantityVal*priceVal; $("#Total").val(totalVal) } var totalValue=0; $('[id^=Total]').each(function(){ totalValue+=parseInt(this.value); }) $('#totalvalue').val(totalValue); }) $(document).on("input","[id^=Price],[id^=Quantity]",function(){ var val = $(this).attr("id").slice(-1) var price = $("#Price"+val).val(); let quantityVal=$("#Quantity"+val).val(); if(quantityVal==""){ $(".Price_error").html('* <?php echo $lang['PLEASE_ENTER_QUANTITY']; ?>'); } else{ let totalVal=quantityVal*price; $("#Total"+val).val(totalVal) } var totalValue=0; $('[id^=Total]').each(function(){ totalValue+=parseInt(this.value); }) $('#totalvalue').val(totalValue); }) // $(document).on("input","[id^=quantity]",function(){ // var price = $(this).val(); // var val = $(this).attr("id").slice(-1) // let quantityVal=$("#Quantity"+val).val(); // if(quantityVal==""){ // $(".Price_error").html('*please enter quantity'); // } // else{ // let totalVal=quantityVal*price; // $("#Total"+val).val(totalVal) // } // var totalValue=0; // $('[id^=Total]').each(function(){ // totalValue+=parseInt(this.value); // }) // $('#totalvalue').val(totalValue); // }) // function getTotaalval(){ // let rowCount = $('#myTable tbody tr').length; // let rowCount1=rowCount-1; // let quantityVal=$("#Quantity"+rowCount1).val(); // let priceVal=$("#Price"+rowCount1).val(); // if(quantityVal==""){ // $(".Price_error").html('*please enter quantity'); // $("#Quantity"+rowCount1).focus(); // } // else{ // let totalVal=quantityVal*priceVal; // $("#Total"+rowCount1).val(totalVal) // } // } function checkPhone(e){ // alert(e) var key = e.keyCode || e.charCode; if(key == 13 || key == 43 || (key >= 48 && key <= 57) || key == 8 || key == 46) { return true; } else { return false; } // if() } </script>