<?php
include('../headertop.php');
include('../datepicker.php');
include('../db.php');

$disp = '';
$pagetitle = 'Edit Expense';

if(!isset($_REQUEST['id']))
{
$disp .= 'Please select an expense first';
include('../template.php');
exit;
}

$id = $_REQUEST['id'];

$q = "select * from expenses where id='$id'";
$res = mysqli_query($dbcon,$q) or die(mysqli_error($dbcon));

if(mysqli_num_rows($res)<1)
{
$disp .= 'No expense found with this id';
include('../template.php');
exit;
}

$row = mysqli_fetch_array($res);

$qproj = "select * from project where type='ct'";
$qwork = "select * from work_type";

$rproj = mysqli_query($dbcon,$qproj) or die(mysqli_error($dbcon));
$rwork = mysqli_query($dbcon,$qwork) or die(mysqli_error($dbcon));

if(isset($_REQUEST['sm']))
$disp .= '<div class="smdiv">'.$_REQUEST['sm'].'</div>';
else
$disp .= '<div class="smdiv">Edit Expense Details</div>';


 
$disp .= '<form method="post" action="editexpense2.php" id="editexpenseform" enctype="multipart/form-data">
<input type="hidden" name="id" value="'.$id.'">
<div class="row">
                <div class="col-md-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                             Make changes and click submit
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <tbody>
									 
                                        
										<tr><th>Work Type *</th><td><select name="work_type" data-validation="required"><option value=""></option>';
										
while($rwwork = mysqli_fetch_array($rwork))
{
if($rwwork['id'] == $row['work_type'])
$disp .= '<option value="'.$rwwork['id'].'" selected>'.$rwwork['work_type'].'</option>';
else
$disp .= '<option value="'.$rwwork['id'].'">'.$rwwork['work_type'].'</option>';
}										


$disp .= '</select></td></tr>
<tr><th>Amount *:</th><td><input type="text" name="amount" value="'.$row['amount'].'" data-validation="required"></td></tr>
										<tr><th>Date *: </th><td><input type="text" name="date" id="datep1" readonly value="'.$row['date'].'"  data-validation="required"></td></tr>
<tr><th>Name *: </th><td><input type="text" name="name" value="'.$row['name'].'"  data-validation="required"></td></tr>
										<tr><th>Particulars *: </th><td><textarea name="particulars" row="5" data-validation="required">'.$row['particulars'].'</textarea></td></tr>
										
<tr><th>Payment Method: </th><td><select name="payment_method" data-validation="required"><option value=""></option>';
if($row['payment_method']=='cash')
$disp .= '<option value="cash" selected>Cash</option><option value="cheque">Cheque</option><option value="bank transfer">Bank Transfer</option>';
elseif($row['payment_method']=='cheque')
$disp .= '<option value="cash">Cash</option><option value="cheque" selected>Cheque</option><option value="bank transfer">Bank Transfer</option>';
elseif($row['payment_method']=='bank transfer')
$disp .= '<option value="cash">Cash</option><option value="cheque">Cheque</option><option value="bank transfer" selected>Bank Transfer</option>';

$disp .= '</select></td></tr>											

<tr><th>Payment Details: </th><td><input type="text" name="payment_details" value="'.$row['payment_details'].'"></td></tr>		
<Tr><th><a href="../'.$row['rcptphoto'].'" target=_blank><img src="../'.$row['rcptphoto'].'" style="width:100px;height:100px;"></a></th><td> Change Receipt Picture: <br><input type="file" name="rcptphoto"></td></tr>									
<tr><th>Click to Confirm Changes</th><td><button type="submit" name="editexpensesubmit" class="btn-success">Submit Changes</button></td></tr>
																						
                                       
                                    
                                    </tbody>
                                </table>
                            </div>
                            
                        </div>
                    </div>
                    <!--End Advanced Tables -->
                </div>
            </div>
			</form>';
			

		include('../header.php');
		include('../template.php');
			?>
		
    <!-- <script>
            $(document).ready(function () {
                $('#dataTables-example').dataTable();
            });
    </script>  -->
    <script>
                                    $.validate({
  form : '#editexpenseform'
});
</script>

			
               