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

$disp = '';
$pagetitle = 'Correct Expenses';
date_default_timezone_set('Asia/Kolkata');

if(isset($_REQUEST['start']))
$start = $_REQUEST['start'];
else
$start = 0;

$q = "select * from expenses where work_type='To be corrected' limit $start,20";
$res = mysqli_query($dbcon,$q);
while($row = mysqli_fetch_array($res))
{
$correct[] = array('id'=>$row['id'], 'date'=>$row['date'], 'particulars'=>$row['particulars'],'amount'=>$row['amount'],'work_type'=>$row['work_type']);
}


$q2 = "select * from work_type";
$res2 = mysqli_query($dbcon,$q2);
while($row2 = mysqli_fetch_array($res2))
{
$wtarray[$row2['id']] = $row2['work_type'];
}

$disp .= '<br> Pls correct Work Type for these following ('.count($correct).') Entries:<br>
<form method="post" action="correctexpenses2.php"><table class="table table-striped table-bordered table-hover" style="width:80%" border="1">
<input type="hidden" name="start" value="'.$start.'">
<tr><th>ID</th><th>Date</th><th>Particulars</th><th>Amount</th><th>Work Type</th></tr>';
foreach($correct as $k=>$v)
{
$ni = 'correct2['.$k.'][id]';
$nd = 'correct2['.$k.'][date]';
$nw = 'correct2['.$k.'][work_type]';
$np = 'correct2['.$k.'][particulars]';
$na = 'correct2['.$k.'][amount]';

$datedisp = date("d-m-Y", strtotime($correct[$k]['date']));

$disp .= '<tr><td>'.$correct[$k]['id'].' <input type="hidden" name="'.$ni.'" value="'.$correct[$k]['id'].'"></td><td><input type="text" name="'.$nd.'" value="'.$datedisp.'"></td>
<td>'.$correct[$k]['particulars'].'</td>
<td>'.$correct[$k]['amount'].'</td>
<Td><select name="'.$nw.'"><option value=""></option>';

foreach($wtarray as $i=>$w)
{
$disp .= '<option value="'.$i.'">'.$w.'</option>';
}
$disp .= '</select></td></tr>';
reset($wtarray);
}//end of foreach for $correct
$disp .= '<tr><td colspan="4"><input type="submit" name="correctexpensessubmit" value="Submit corrections"></td></tr>';
$disp .= '</table></form>';

include('../header.php');
include('../template.php');
