JezK
Edit File: page4.php
<?php include("header.php"); $_SESSION['sliFormPage'] = 'page4.php'; if(!isset($_SESSION['userID'])) { echo "<script>location.replace('page1.php');</script>"; } if(isset($_SESSION['saveSuccess'])) { echo "<script>alert('Data saved successfully.');</script>"; unset($_SESSION['saveSuccess']); } if(isset($_SESSION['page4SaveFailed'])) { echo "<script>alert('Error!!! Unable to save user details. Internal server error.');</script>"; unset($_SESSION['page4SaveFailed']); } if(isset($_SESSION['rawSaveFailed'])) { echo "<script>alert('Error!!! Unable to save raw material details. Internal server error.');</script>"; unset($_SESSION['rawSaveFailed']); } if(isset($_SESSION['rawUpdateFailed'])) { echo "<script>alert('Error!!! Unable to update raw material details. Internal server error.');</script>"; unset($_SESSION['rawUpdateFailed']); } if(isset($_SESSION['productSaveFailed'])) { echo "<script>alert('Error!!! Unable to save production details. Internal server error.');</script>"; unset($_SESSION['productSaveFailed']); } if(isset($_SESSION['productUpdateFailed'])) { echo "<script>alert('Error!!! Unable to update production details. Internal server error.');</script>"; unset($_SESSION['productUpdateFailed']); } if(isset($_SESSION['salesSaveFailed'])) { echo "<script>alert('Error!!! Unable to save sales details. Internal server error.');</script>"; unset($_SESSION['salesSaveFailed']); } if(isset($_SESSION['salesUpdateFailed'])) { echo "<script>alert('Error!!! Unable to update sales details. Internal server error.');</script>"; unset($_SESSION['salesUpdateFailed']); } if(isset($_SESSION['deleteSuccess'])) { echo "<script>alert('Data deleted succesfully.');</script>"; unset($_SESSION['deleteSuccess']); } if(isset($_SESSION['deleteFailed'])) { echo "<script>alert('Error!!! Unable to delete registration details. Internal server error.');</script>"; unset($_SESSION['deleteFailed']); } ?> <div class="container main"> <div class="row"> <form action = "app/page4App.php" class="form-horizontal" method="post" onsubmit="return validatePage4()"> <div class="col-md-12 text-cneter formContainer"> <section> <div class="<?=$rawMaterialBlock;?>"> <div class="removePadding col-md-12 materialClass"> <h3 class="col-md-11 removePadding">Details of raw material/commodities consumed/procured/traded in past 3 years</h3> <div class="text-right"><input type="button" class="btn btn-default addFieldsBtn" value="Add New" ></div> <div class="col-md-12 rowStyle"> <input type="hidden" value="<?php echo $previousYear3; ?>" name="previousYear3"> <input type="hidden" value="<?php echo $previousYear2; ?>" name="previousYear2"> <input type="hidden" value="<?php echo $previousYear1; ?>" name="previousYear1"> <label class="col-md-1">S.No</label> <label class="col-md-2">Raw Material</label> <label class="col-md-2"><?php echo $previousYear3; ?></label> <label class="col-md-2"><?php echo $previousYear2; ?></label> <label class="col-md-2"><?php echo $previousYear1; ?></label> </div> <div class="addMoreFields"> <?php echo $rawMaterialDetails; ?> </div> <div class="col-md-12 marginDiv totalBlock"> <span class="col-md-1"></span> <label class="col-md-2">Total</label> <input type="text" class="col-md-2" name="totalyear3RawMateril" id="totalyear3RawMateril" value="<?php echo $totalRawY3; ?>" readonly> <input type="text" class="col-md-2" name="totalyear2RawMateril" id="totalyear2RawMateril" value="<?php echo $totalRawY2; ?>" readonly> <input type="text" class="col-md-2" name="totalyear1RawMateril" id="totalyear1RawMateril" value="<?php echo $totalRawY1; ?>" readonly> </div> </div> </div> </section> <section> <div class="<?=$rawMaterialBlock;?>"> <div class="removePadding col-md-12"> <h3>A brief notes on the rawmaterials used/commodities traded in sources of procurement to be furnished</h3> <textarea style="width:100%" name="rawMaterialNotes" id="rawMaterialNotes" rows="7"><?php echo $rawMaterialNotes; ?></textarea> </div> </div> </section> <section> <div id="<?=$productsBlock;?>"> <div class="removePadding col-md-12 detailsBlock productionClass" id="block1"> <h3 class="col-md-11 removePadding">Details of production for past 3years ( ₹)</h3> <div class="text-right"><input type="button" class="btn btn-default addFieldsBtn1" value="Add New" ></div> <div class="col-md-12 marginDiv "> <label class="col-md-1">S.No</label> <label class="col-md-2">Product</label> <label class="col-md-2"><?php echo $previousYear3; ?></label> <label class="col-md-2"><?php echo $previousYear2; ?></label> <label class="col-md-2"><?php echo $previousYear1; ?></label> </div> <?php echo $productionDetails; ?> </div> <div class="col-md-12 marginDiv totalBlock"> <span class="col-md-1"></span> <label class="col-md-2">Total</label> <input type="text" class="col-md-2" name="totalyear3Production" id="totalyear3Production" value="<?php echo $totalProductionY3; ?>" readonly> <input type="text" class="col-md-2" name="totalyear2Production" id="totalyear2Production" value="<?php echo $totalProductionY2; ?>" readonly> <input type="text" class="col-md-2" name="totalyear1Production" id="totalyear1Production" value="<?php echo $totalProductionY1; ?>" readonly> </div> </div> </section> <section> <div id="<?=$salesBlock;?>"> <div class="removePadding col-md-12 detailsBlock salesClass" id="block2"> <h3 class="col-md-11 removePadding" >Sales Particulars for past 3years (₹)</h3> <div class="text-right"><input type="button" class="btn btn-default addFieldsBtn2" value="Add New" ></div> <div class="col-md-12 marginDiv"> <label class="col-md-1">S.No</label> <label class="col-md-2">Product </label> <label class="col-md-2"><?php echo $previousYear3; ?></label> <label class="col-md-2"><?php echo $previousYear2; ?></label> <label class="col-md-2"><?php echo $previousYear1; ?></label> </div> <?php echo $salesDetails; ?> </div> <div class="col-md-12 marginDiv totalBlock"> <span class="col-md-1"></span> <label class="col-md-2">Total</label> <input type="text" class="col-md-2" name="totalyear3Sales" id="totalyear3Sales" value="<?php echo $totalSalesY3; ?>" readonly> <input type="text" class="col-md-2" name="totalyear2Sales" id="totalyear2Sales" value="<?php echo $totalSalesY2; ?>" readonly> <input type="text" class="col-md-2" name="totalyear1Sales" id="totalyear1Sales" value="<?php echo $totalSalesY1; ?>" readonly> </div> </div> </section> <br> <div class="text-center"> <a href="page3.php"><input type="button" value="Back" class="btn btn-cs"></a> <input type="submit" value="Next" class="btn btn-cs"> </div> <div class="col-md-12 text-right">4 of 6</div> </div><!--end formContainer--> </form> </div> </div> <?php include"footer.php"?> <script> $(document).ready(function(){ //var max_fields = ; //maximum input boxes allowed var wrapper = $(".addMoreFields"); //Fields wrapper var add_button = $(".addFieldsBtn"); //Add button ID var flag; var j = <?php echo $rawMaterialsCount; ?>; //initlal text box count $(add_button).click(function(e) { /*material = document.getElementById('material'+j); y3 = document.getElementById('y3'+j); y2 = document.getElementById('y2'+j); y1 = document.getElementById('y1'+j);*/ materialLength = document.getElementsByName('material[]').length; for(i=0;i<materialLength;i++) { material = document.getElementsByName('material[]'); y3 = document.getElementsByName('y3[]'); y2 = document.getElementsByName('y2[]'); y1 = document.getElementsByName('y1[]'); if(material[i].value.trim() != "" && y3[i].value.trim() != "" && y2[i].value.trim() != "" && y1[i].value.trim() != "") { flag = 1; } else { flag = 0; break; } } if(flag == 1) { //on add input button click e.preventDefault(); // if(x < max_fields){ //max input box allowed j++; //text box increment $(wrapper).append('<div class="col-md-12 textBlock"><span class="col-md-1 jVal">'+j+'.</span><input type="hidden" value="" class="col-md-2" name="materialID[]" id="materialID'+j+'"><input type="text" class="col-md-2" name="material[]" id="material'+j+'"><input type="text" class="col-md-2 y3" name="y3[]" id="y3'+j+'" onkeypress="return number2(event)" onblur="calculateTotal(this)"><input type="text" class="col-md-2 y2" name="y2[]" id="y2'+j+'" onkeypress="return number2(event)" onblur="calculateTotal(this)"><input type="text" class="col-md-2 y1" name="y1[]" id="y1'+j+'" onkeypress="return number2(event)" onblur="calculateTotal(this)"><a class="action2" class="col-md-1"><i class="fa fa-trash remove_field" aria-hidden="true" ></i></a></div>'); //add input box //} } else { alert("Please fill all fields first."); } }); $(wrapper).on("click",".remove_field", function(e){ //user click on remove tex //resetTotal(j); jVal=$(this).closest('.textBlock').find('.jVal').text(); jVal=jVal.replace('.',''); resetTotal(jVal); e.preventDefault(); $(this).closest('.textBlock').remove(); }); /**************Block1*********/ //var max_fields = ; //maximum input boxes allowed var wrapper1 = $("#block1"); //Fields wrapper var add_button1 = $(".addFieldsBtn1"); //Add button ID var x = '<?php echo $productionDetailsCount; ?>'; //initlal text box count $(add_button1).click(function(e) { /*product = document.getElementById('product'+x); y3Product = document.getElementById('y3Product'+x); y2Product = document.getElementById('y2Product'+x); y1Product = document.getElementById('y1Product'+x);*/ productLength = document.getElementsByName('product[]').length; for(i=0;i<productLength;i++) { product = document.getElementsByName('product[]'); y3Product = document.getElementsByName('y3Product[]'); y2Product = document.getElementsByName('y2Product[]'); y1Product = document.getElementsByName('y1Product[]'); registrationNumber = document.getElementsByName('registrationNumber[]'); if(product[i].value.trim() != "" && y3Product[i].value.trim() != "" && y2Product[i].value.trim() != "" && y1Product[i].value.trim() != "") { flag = 1; } else { flag = 0; break; } } if(flag == 1) { //on add input button click e.preventDefault(); // if(x < max_fields){ //max input box allowed x++; //text box increment $(wrapper1).append('<div class="col-md-12 textBlock1"><span class="col-md-1 xVal">'+x+'.</span><input type="hidden" class="col-md-2" name="productID[]" id="productID1" value=""><input type="text" class="col-md-2" name="product[]"><input type="text" class="col-md-2 y3" name="y3Product[]" id="y3Product'+x+'" onkeypress="return number2(event)" onblur="calculateTotal2(this)"><input type="text" class="col-md-2 y2" name="y2Product[]" id="y2Product'+x+'" onkeypress="return number2(event)" onblur="calculateTotal2(this)"><input type="text" class="col-md-2 y1" name="y1Product[]" id="y1Product'+x+'" onkeypress="return number2(event)" onblur="calculateTotal2(this)"><a class="action2" class="col-md-1"><i class="fa fa-trash remove_field1" aria-hidden="true" ></i></a></div>'); //add input box //} } else { alert("Please fill all fields first."); } }); $(wrapper1).on("click",".remove_field1", function(e){ //user click on remove text xVal=$(this).closest('.textBlock1').find('.xVal').text(); xVal=xVal.replace('.',''); resetTotal2(xVal); e.preventDefault(); $(this).closest('.textBlock1').remove(); }); /**************Block2*********/ //var max_fields = ; //maximum input boxes allowed var wrapper2 = $("#block2"); //Fields wrapper var add_button2 = $(".addFieldsBtn2"); //Add button ID var i = '<?php echo $salesDetailsCount; ?>'; //initlal text box count $(add_button2).click(function(e) { /*saleProduct = document.getElementById('saleProduct'+i); y3Sale = document.getElementById('y3Sale'+i); y2Sale = document.getElementById('y2Sale'+i); y1Sale = document.getElementById('y1Sale'+i);*/ saleProductLength = document.getElementsByName('saleProduct[]').length; for(i=0;i<saleProductLength;i++) { saleProduct = document.getElementsByName('saleProduct[]'); y3Sale = document.getElementsByName('y3Sale[]'); y2Sale = document.getElementsByName('y2Sale[]'); y1Sale = document.getElementsByName('y1Sale[]'); if(saleProduct[i].value.trim() != "" && y3Sale[i].value.trim() != "" && y2Sale[i].value.trim() != "" && y1Sale[i].value.trim() != "") { flag = 1; } else { flag = 0; break; } } if(flag == 1) { //on add input button click e.preventDefault(); // if(x < max_fields){ //max input box allowed i++; //text box increment $(wrapper2).append('<div class="col-md-12 textBlock2"><span class="col-md-1 iVal">'+i+'.</span><input type="hidden" class="col-md-2" name="saleProductID[]" id="saleProductID1" value=""><input type="text" class="col-md-2" name="saleProduct[]" id="saleProduct'+i+'"><input type="text" class="col-md-2 y3" name="y3Sale[]" id="y3Sale'+i+'" onkeypress="return number2(event)" onblur="calculateTotal3(this)"><input type="text" class="col-md-2 y2" name="y2Sale[]" id="y2Sale'+i+'" onkeypress="return number2(event)" onblur="calculateTotal3(this)"><input type="text" class="col-md-2 y1" name="y1Sale[]" id="y1Sale'+i+'" onkeypress="return number2(event)" onblur="calculateTotal3(this)"><a class="action2" class="col-md-1"><i class="fa fa-trash remove_field2" aria-hidden="true" ></i></a></div>'); //add input box //} } else { alert("Please fill all fields first."); } }); $(wrapper2).on("click",".remove_field2", function(e){ //user click on remove text iVal=$(this).closest('.textBlock2').find('.iVal').text(); iVal=iVal.replace('.',''); resetTotal3(iVal) e.preventDefault(); $(this).closest('.textBlock2').remove(); }); }); function number2(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; } } function validatePage4() { /*material = document.getElementById('material1'); y3 = document.getElementById('y31'); y2 = document.getElementById('y21'); y1 = document.getElementById('y11'); product = document.getElementById('product1'); y3Product = document.getElementById('y3Product1'); y2Product = document.getElementById('y2Product1'); y1Product = document.getElementById('y1Product1'); saleProduct = document.getElementById('saleProduct1'); y3Sale = document.getElementById('y3Sale1'); y2Sale = document.getElementById('y2Sale1'); y1Sale = document.getElementById('y1Sale1'); if(material.value.trim() == '') { alert("Please enter raw material."); material.value = ""; material.focus(); return false; } if(y3.value.trim() == '') { alert("Please enter raw material year-3."); y3.value = ""; y3.focus(); return false; } if(y2.value.trim() == '') { alert("Please enter raw material year-2."); y2.value = ""; y2.focus(); return false; } if(y1.value.trim() == '') { alert("Please enter raw material year-1."); y1.value = ""; y1.focus(); return false; } if(product.value.trim() == '') { alert("Please enter product."); product.value = ""; product.focus(); return false; } if(y3Product.value.trim() == '') { alert("Please enter product year-3."); y3Product.value = ""; y3Product.focus(); return false; } if(y2Product.value.trim() == '') { alert("Please enter product year-2."); y2Product.value = ""; y2Product.focus(); return false; } if(y1Product.value.trim() == '') { alert("Please enter product year-1."); y1Product.value = ""; y1Product.focus(); return false; } if(saleProduct.value.trim() == '') { alert("Please enter sales product."); saleProduct.value = ""; saleProduct.focus(); return false; } if(y3Sale.value.trim() == '') { alert("Please enter sales year-3."); y3Sale.value = ""; y3Sale.focus(); return false; } if(y2Sale.value.trim() == '') { alert("Please enter sales year-2."); y2Sale.value = ""; y2Sale.focus(); return false; } if(y1Sale.value.trim() == '') { alert("Please enter sales year-1."); y1Sale.value = ""; y1Sale.focus(); return false; }*/ return true; } function calculateTotal(obj) { if($(obj).hasClass('y3')) { var sum=0; $(obj).parents('.materialClass').find('.y3').each(function(){ var y3val=$(this).val(); if(y3val) { sum+=parseFloat(y3val); } //alert(y3val); }); $('#totalyear3RawMateril').val(sum); } if($(obj).hasClass('y2')) { var sum=0; $(obj).parents('.materialClass').find('.y2').each(function(){ var y2val=$(this).val(); if(y2val) { sum+=parseFloat(y2val); } //alert(y3val); }); $('#totalyear2RawMateril').val(sum); } if($(obj).hasClass('y1')) { var sum=0; $(obj).parents('.materialClass').find('.y1').each(function(){ var y1val=$(this).val(); if(y1val) { sum+=parseFloat(y1val); } //alert(y3val); }); $('#totalyear1RawMateril').val(sum); } } function calculateTotal2(obj) { if($(obj).hasClass('y3')) { var sum=0; $(obj).parents('.productionClass').find('.y3').each(function(){ var y3val=$(this).val(); if(y3val) { sum+=parseFloat(y3val); } //alert(y3val); }); $('#totalyear3Production').val(sum); } if($(obj).hasClass('y2')) { var sum=0; $(obj).parents('.productionClass').find('.y2').each(function(){ var y2val=$(this).val(); if(y2val) { sum+=parseFloat(y2val); } //alert(y3val); }); $('#totalyear2Production').val(sum); } if($(obj).hasClass('y1')) { var sum=0; $(obj).parents('.productionClass').find('.y1').each(function(){ var y1val=$(this).val(); if(y1val) { sum+=parseFloat(y1val); } //alert(y3val); }); $('#totalyear1Production').val(sum); } } function calculateTotal3(obj) { if($(obj).hasClass('y3')) { var sum=0; $(obj).parents('.salesClass').find('.y3').each(function(){ var y3val=$(this).val(); if(y3val) { sum+=parseFloat(y3val); } //alert(y3val); }); $('#totalyear3Sales').val(sum); } if($(obj).hasClass('y2')) { var sum=0; $(obj).parents('.salesClass').find('.y2').each(function(){ var y2val=$(this).val(); if(y2val) { sum+=parseFloat(y2val); } //alert(y3val); }); $('#totalyear2Sales').val(sum); } if($(obj).hasClass('y1')) { var sum=0; $(obj).parents('.salesClass').find('.y1').each(function(){ var y1val=$(this).val(); if(y1val) { sum+=parseFloat(y1val); } //alert(y3val); }); $('#totalyear1Sales').val(sum); } } function resetTotal(i) { y3 = document.getElementById('y3'+i); y2 = document.getElementById('y2'+i); y1 = document.getElementById('y1'+i); totalyear3RawMateril = document.getElementById('totalyear3RawMateril'); totalyear2RawMateril = document.getElementById('totalyear2RawMateril'); totalyear1RawMateril = document.getElementById('totalyear1RawMateril'); totalyear3RawMateril.value = totalyear3RawMateril.value - y3.value; totalyear2RawMateril.value = totalyear2RawMateril.value - y2.value; totalyear1RawMateril.value = totalyear1RawMateril.value - y1.value; } /* function resetTotal() { totalyear3RawMateril = document.getElementById('totalyear3RawMateril'); totalyear2RawMateril = document.getElementById('totalyear2RawMateril'); totalyear1RawMateril = document.getElementById('totalyear1RawMateril'); y3Length = document.getElementsByName('y3[]').length; for(i=0;i<y3Length;i++) { y3 = document.getElementsByName('y3[]'); y2 = document.getElementsByName('y2[]'); y1 = document.getElementsByName('y1[]'); totalyear3RawMateril.value = totalyear3RawMateril.value - y3[i].value; totalyear2RawMateril.value = totalyear2RawMateril.value - y2[i].value; totalyear1RawMateril.value = totalyear1RawMateril.value - y1[i].value; //alert(totalyear3RawMateril.value); } }*/ function resetTotal2(i) { y3Product = document.getElementById('y3Product'+i); y2Product = document.getElementById('y2Product'+i); y1Product = document.getElementById('y1Product'+i); totalyear3Production = document.getElementById('totalyear3Production'); totalyear2Production = document.getElementById('totalyear2Production'); totalyear1Production = document.getElementById('totalyear1Production'); totalyear3Production.value = totalyear3Production.value - y3Product.value; totalyear2Production.value = totalyear2Production.value - y2Product.value; totalyear1Production.value = totalyear1Production.value - y1Product.value; } function resetTotal3(i) { y3Sale = document.getElementById('y3Sale'+i); y2Sale = document.getElementById('y2Sale'+i); y1Sale = document.getElementById('y1Sale'+i); totalyear3Sale = document.getElementById('totalyear3Sales'); totalyear2Sale = document.getElementById('totalyear2Sales'); totalyear1Sale = document.getElementById('totalyear1Sales'); totalyear3Sale.value = totalyear3Sale.value - y3Sale.value; totalyear2Sale.value = totalyear2Sale.value - y2Sale.value; totalyear1Sale.value = totalyear1Sale.value - y1Sale.value; } </script>