/home/optimumoperation/quarksperforma.optimumoperations.top/renewal_invoice_change.php
<?php include 'include/top-part.php'; ?>
<?php echo $phone;
$id=$_REQUEST['id'];   // Get Id from table
?>
<script src="ckeditor/ckeditor.js"></script>
        <div class="dashboard-wrapper">
            <div class="container-fluid  dashboard-content">
                <!-- ============================================================== -->
                <!-- pageheader -->
                <!-- ============================================================== -->
                <div class="row">
                    <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                        <div class="page-header">
                            <h2 class="pageheader-title">Change Data </h2>
                           
                            <div class="page-breadcrumb">
                                <nav aria-label="breadcrumb">
                                    <ol class="breadcrumb">
                                        <li class="breadcrumb-item"><a href="#" class="breadcrumb-link">Dashboard</a></li>
                                        
                                        <li class="breadcrumb-item active" aria-current="page">Change Data</li>
                                    </ol>
                                </nav>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- ============================================================== -->
                <!-- end pageheader -->
                <!-- ============================================================== -->
              
                <div class="row"  >
                    <!-- ============================================================== -->
                    <!-- data table  -->
                    <!-- ============================================================== -->
                   
                            <?php
						$sql = "SELECT * FROM invoice_details where id='$id'";
						$result = $conn->query($sql);
          				if ($result->num_rows > 0) {
							// output data of each row
							while($row = $result->fetch_assoc()) {
								?>
                                <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12" >
                            <div class="card">
                                
                                <div class="card-body" >
                                   <?php  $invoice_pay = $row["invoice_pay"]; ?>
                                   <?php
                                        if($invoice_pay ==2){
                                            ?>
                                            <style>
                                                .change_form{
                                                    display:none;
                                                }
                                            </style>
                                            <h2 style="color:red; text-align:center; text-transform:uppercase;"> Cancelled Invoice not available for Edit.</h2>
                                        <?php
                                        }
                                        else{
                                           ?> 
                                           <style>
                                                .change_form{
                                                    display:block;
                                                }
                                            </style>
                                          <?php }
                                   ?>
                                   
                                <form action="" method="post" class="change_form" enctype="multipart/form-data">
                                     <table class="table">
                                        <thead>
                                           <tr>
                                                <th> Invoice/Quotation: 
													 <select class="form-control" name="invoice_quatation">
												<?php $invoice_quatation = $row["invoice_quatation"]; ?> 
													  <option value="<?php echo $invoice_quatation;?>"> 
													  <?php echo $invoice_quatation;?> (Selected) </option>
													  <option value="RenQuot"> RenQuot</option>
													  <option value="Renewal"> Renewal </option> 
												</select>
												</th>
												 <th> Name: <input type="text"  class="form-control" name="customer_name" value="<?php echo $customer = $row["customer_name"]; ?>">  </th>
                                                
                                            </tr>
                                            <tr>
                                               <th> Mobile: <input class="form-control" type="text" name="customer_mobile" value="<?php echo $row["customer_mobile"]; ?>" /> </th>
											    <th> Mail: <input type="text"  class="form-control" name="customer_mail" value="<?php echo $customer = $row["customer_mail"]; ?>">  </th>
                                                
                                            </tr>
                                             <tr>
                                               <th> Address: <input class="form-control" type="text" name="customer_address" value="<?php echo $row["customer_address"]; ?>" /> </th>
                                                <th >
													Advance Payment 
                                                <input   type="text" class="form-control" placeholder="Advance Payment to start work. Eg- 50 (for 50% of invoice)." name="advance_payment_invoice" value="<?php echo $row["advance_payment_invoice"]; ?>" >
												</th>
                                            </tr> 
											

                                        </thead>    
                                    </table>
                                    <br>
                                    <table class="table">
                                        <thead style="background: #f3f3f3;">
                                            <tr>
                                                <th scope="col"> Description </th>
                                                <th scope="col"> Quantity  </th>
                                                <th scope="col"> Amount </th>
                                            </tr>
                                        </thead>
                                        <?php 
$product_description=explode(',', $row['product_description']);
foreach($product_description as $allproduct) {
   //echo "<th scope='col'>".$allproduct."</td>";
  //echo "<th scope='col'>". $allproduct = $product_description[0]."</td>";
}
?>



<?php 
$product_qty_type=explode(',', $row['product_qty_type']);
foreach($product_qty_type as $allquantity) {
   //echo "<th scope='col'>" .$allquantity."</td>";
}
?>


<?php 
$product_amount=explode(',', $row['product_amount']);
foreach($product_amount as $fullamount) {
   // echo "<th scope='col'>" .$fullamount."</td>";
}
?>

<?php
 $all_value = count($product_qty_type) - 1;
?>
<hr>
<?php  
$totalqty = 0;
$totalamount = 0;
$x = 0;
while($x <= $all_value -1 ) {
   $totalqty += $product_qty_type[$x]; 
   $totalamount += $product_amount[$x];
   
  $x++;
} 
$totalqty;  // Total Quantity
$totalamount; // Total Amount
?> 
<?php  
$x = 0;
 
while($x <= $all_value -1 ) {?>
  <tr><td>  <input type="text" class="form-control" name="product_description[]" value="<?php echo $product_description[$x];?>" /></td>
  <td><input type="number" class="form-control" name="product_qty_type[]" value="<?php echo $product_qty_type[$x]; ?>"/></td>
  <td> <input type="number" class="form-control" name="product_amount[]" value="<?php echo $product_amount[$x];?>" /> </td>
<?php
 $x++;
} 
?>  
<?php echo "<tr><th scope='col'> Total Amount</td>"; ?>
  <?php echo "<th scope='col'> $totalqty</td>"; ?>
  <?php echo "<th scope='col'> Rs. $totalamount</td></tr>"; ?>
</table>
<br>
 
                                    <table class="table">
                                        <thead>
                                            <tr>
                                            <th style="width: 50%;border-top:2px solid #ffffff; border-bottom:2px solid #ffffff;  border-left:2px solid #ffffff; border-right:2px solid #ffffff;"></th>
                                            <th style="border-top:2px solid #ffffff; border-left:2px solid #ffffff; border-right:2px solid #ffffff;border-bottom:1px solid #000;"> Total Paid:  Rs. <?php echo $previous_paid = $row["price_paid"]; ?> </th>
                                            </tr>
                                           
                                        </thead>   
                                        <thead>
                                            <tr>
                                            <th style="width: 50%;border-top:2px solid #ffffff; border-bottom:2px solid #ffffff;  border-left:2px solid #ffffff; border-right:2px solid #ffffff;"></th>
                                            <th style="border-top:2px solid #ffffff; border-left:2px solid #ffffff; border-right:2px solid #ffffff;border-bottom:1px solid #000;">
                                             Total Remaining:- Rs:<input  class="form-control" type="number" name="price_paid"  placeholder="<?php echo $totalamount - $row["price_paid"]; ?>" /> </th>
                                            </tr>
                                        </thead>    
                                    </table>

                                    <h3 class="mb-0" style="color: #1c0baf;">Features:</h3> 
                                    <textarea id="editor" name="complete_feature"> <?php echo $row['complete_feature'];?> </textarea>
                                    <br><h3 class="mb-0" style="color: #1c0baf;">Client's Support History:</h3> <br>
                                    <textarea id="seceditor" name="updation_work"> <?php echo $row['updation_work'];?> </textarea>
                                    
                                    <br>
<h3 class="mb-0" style="color: #1c0baf;">Payment Proof:</h3> <br>
<input class="form-control" type="file" name="file" id="file" /><br>

<?php
  if($row['invoice_pay'] == 0){?>
                                      <label for="sel1">Invoice Status:</label>
                                      <select class="form-control" name="invoice_pay">
                                        <option value="0"> Revision </option>
                                        <option value="1">Pay</option>
                                        <option value="2">Canceled</option>
                                      </select>
<br>
  <?php
  }
  else{
      ?>
                                    <select class="form-control" name="invoice_pay" style="display:none;">
                                        <option value="1">Pay</option>
                                    </select> 
<?php      
  }
?>

                                    <input class='btn btn-primary' type="submit" name="submit"  value="Change Data" />
                           </form>
                                    


                                </div>
                            </div>
                        </div>
						   <?php
							}
							
						} 
					
						else {
							echo "No Data Available";
						}
						?>

















<?php
$random = rand();
                if(isset($_POST['submit'])) {
                    $invoice_quatation  = $_POST['invoice_quatation'];
                    $advance_payment_invoice  = $_POST['advance_payment_invoice'];
                    $customer_name  = $_POST['customer_name'];
                    $price_paid  = $_POST['price_paid'] + $previous_paid;
                    $customer_address  = $_POST['customer_address'];
                    $customer_mail  = $_POST['customer_mail'];
                    $customer_mobile  = $_POST['customer_mobile'];
                    $complete_feature  = $_POST['complete_feature'];
                    $updation_work  = $_POST['updation_work'];
                    $invoice_pay  = $_POST['invoice_pay'];


    $network_image = $_FILES['file']['name'];
    $image_path = "img/paymentproof/";
    $image_name ="$random-$network_image";

    
 $product_descriptionall = $_POST['product_description'];
        $product_description="";  
        foreach($product_descriptionall as $allproductdescription)  
           {  
              $product_description.= $allproductdescription.",";  
           }

        $product_qty_typeall = $_POST['product_qty_type'];
           $product_qty_type="";  
           foreach($product_qty_typeall as $allproduct_qty_type)  
              {  
                 $product_qty_type.= $allproduct_qty_type.",";  
              }

        $product_amountall = $_POST['product_amount'];
              $product_amount="";  
              foreach($product_amountall as $allproduct_amount)  
                 {  
                    $product_amount.= $allproduct_amount.",";  
                 }
					


                 if(!is_null($network_image)) {
                    if(move_uploaded_file($_FILES["file"]["tmp_name"],$image_path.$image_name)){


					$sql = "UPDATE invoice_details SET 
payment_proof='$random-$network_image',
invoice_quatation='$invoice_quatation', advance_payment_invoice='$advance_payment_invoice',
customer_name='$customer_name', customer_address='$customer_address',
customer_mail='$customer_mail', customer_mobile='$customer_mobile',
product_description='$product_description',
product_qty_type='$product_qty_type',
product_amount='$product_amount',
complete_feature='$complete_feature',
updation_work='$updation_work', 
price_paid='$price_paid',
invoice_pay='$invoice_pay'
WHERE id=$id";

					if ($conn->query($sql) === TRUE) {
						
						echo "<h2 class='center_text'>"."Changes Accepted."."</h2>" ;
						echo "<meta http-equiv='refresh' content='5; url=renewal_all_invoice'>";
						
					} else {
							
							echo "<div style='color:red; font-size:20px;'>"."Error Occur Try Again". "</div>" . $conn->error;
							 echo "<h2 class='center_text'>"."Something Went Wrong. Please Try Again Later."."</h2>" ;
							 echo "<meta http-equiv='refresh' content='5; url=renewal_all_invoice'>";
					}
					
                }
				}
				 elseif(!is_null($customer_name)) {
					 	$sql = "UPDATE invoice_details SET  
                        invoice_quatation='$invoice_quatation', advance_payment_invoice='$advance_payment_invoice',
customer_name='$customer_name', customer_address='$customer_address',
customer_mail='$customer_mail', customer_mobile='$customer_mobile',
product_description='$product_description',
product_qty_type='$product_qty_type',
product_amount='$product_amount',
complete_feature='$complete_feature',
updation_work='$updation_work', 
price_paid='$price_paid',
invoice_pay='$invoice_pay'
WHERE id=$id";

					if ($conn->query($sql) === TRUE) {
						
						echo "<h2 class='center_text'>"."Changes Accepted."."</h2>" ;
						echo "<meta http-equiv='refresh' content='5; url=renewal_all_invoice'>";
						
					} else {
							
							echo "<div style='color:red; font-size:20px;'>"."Error Occur Try Again". "</div>" . $conn->error;
							 echo "<h2 class='center_text'>"."Something Went Wrong. Please Try Again Later."."</h2>" ;
							 echo "<meta http-equiv='refresh' content='5; url=renewal_all_invoice'>";
					}
					 
				 }
				 else{
					  echo "<h2 class='center_text'>"."Something Went Wrong. Please Try Again Later."."</h2>" ;
				 }
				}
?> 
       















                   
                </div>
              
                
            
            
            </div>

<script>
 CKEDITOR.replace('editor');
</script>	
<script>
 CKEDITOR.replace('seceditor');
</script>	
<?php include 'include/bottom-part.php'; ?>