Commit 06d0421a authored by Jean-Paul Saman's avatar Jean-Paul Saman

addedit.php: fix edit view of invoice

Added total amount of hours worked and outlined the column
with task_log summary in the table as an extra column iso
extra row.
parent 07faa856
......@@ -52,10 +52,13 @@ if($task_id == '') {
$q = new w2p_Database_Query();
$q->addQuery('task_log_id');
$q->addTable('invoice_task_queue');
$temp_billed = db_loadColumn($q->prepare());
//$temp_billed = db_loadColumn($q->prepare());
$temp_billed = $q->prepare();
$billed = '';
foreach ($temp_billed as $task_log)
foreach ($temp_billed as $task_log) {
echo "invoice: " . $task_log . "<br>";
$billed .= $task_log . ', ';
}
if (!empty($billed))
$billed = '(' . substr($billed, 0, -2) . ')';
$q->clear();
......@@ -63,8 +66,11 @@ $q->addQuery('invoice_tag, invoice_status');
$q->addTable('invoice');
$q->addWhere('invoice_id = ' . $invoice_id);
$ptrc = $q->exec();
if (!$ptrc) {
echo db_error();
}
$nums=db_num_rows($ptrc);
echo db_error();
for ($x=0; $x < $nums; $x++) {
$row = db_fetch_assoc( $ptrc );
$invoice_tag = $row["invoice_tag"];
......@@ -160,70 +166,85 @@ $q->addOrder('billingcode_name ASC');
$billingcodes = $q->loadList();
function showtask(&$a) {
global $AppUI, $project_id, $billingcodes;
$df = $AppUI->getPref( 'SHDATEFORMAT' );
// FIXME: Refactor invoice_showtask() and invoice_getHours()
// since they query the same database with the same row.
// This would make all more efficient.
function invoice_getHours(&$a) {
global $project_id;
$q = new w2p_Database_Query();
$q->addQuery('
task_log_id,
task_log_task,
task_log_name,
task_log_description,
task_log_costcode,
task_log_creator,
task_log_hours,
task_log_date,
task_log_task');
$q->addTable('task_log');
$q->addWhere('task_log_id = ' . $a['task_log_id']);
$q->addOrder('task_log_name ASC');
$q = new w2p_Database_Query();
$q->addQuery('task_log_id, task_log_hours');
$q->addTable('task_log');
$q->addWhere('task_log_id = ' . $a['task_log_id']);
$q->addOrder('task_log_name ASC');
$tmptasks=$q->exec();
$tasks=db_fetch_assoc($tmptasks);
$tmptasks=$q->exec();
$tasks=db_fetch_assoc($tmptasks);
$q->clear();
$q->addQuery('
contact_first_name,
contact_last_name');
$q->addTable('contacts');
$q->leftJoin('users', 'u', 'user_contact = contact_id');
$q->addWhere('user_id = ' . $tasks['task_log_creator']);
$tmpuser=$q->exec();
$username=db_fetch_assoc($tmpuser);
if ($a["task_amount"] == "0") {
$costdesc="None";
for ($x=0; $x < count($billingcodes); $x++) {
if ($billingcodes[$x]["billingcode_id"] == $tasks["task_log_costcode"]) {
$costdesc=$billingcodes[$x]["billingcode_name"];
$rate=$billingcodes[$x]["billingcode_value"];
$hours = $tasks['task_log_hours'];
return $hours;
}
function invoice_showtask(&$a) {
global $AppUI, $project_id, $billingcodes;
$df = $AppUI->getPref( 'SHDATEFORMAT' );
$q = new w2p_Database_Query();
$q->addQuery('
task_log_id,
task_log_task,
task_log_name,
task_log_description,
task_log_costcode,
task_log_creator,
task_log_hours,
task_log_date,
task_log_task');
$q->addTable('task_log');
$q->addWhere('task_log_id = ' . $a['task_log_id']);
$q->addOrder('task_log_name ASC');
$tmptasks=$q->exec();
$tasks=db_fetch_assoc($tmptasks);
$q->clear();
$q->addQuery('
contact_first_name,
contact_last_name');
$q->addTable('contacts');
$q->leftJoin('users', 'u', 'user_contact = contact_id');
$q->addWhere('user_id = ' . $tasks['task_log_creator']);
$tmpuser=$q->exec();
$username=db_fetch_assoc($tmpuser);
if ($a["task_amount"] == "0") {
$costdesc="None";
for ($x=0; $x < count($billingcodes); $x++) {
if ($billingcodes[$x]["billingcode_id"] == $tasks["task_log_costcode"]) {
$costdesc=$billingcodes[$x]["billingcode_name"];
$rate=$billingcodes[$x]["billingcode_value"];
}
}
$amount=round($rate * $tasks["task_log_hours"],2);
} else {
$costdesc="Fixed Price";
$amount=round($a["task_amount"],2);
}
$amount=round($rate * $tasks["task_log_hours"],2);
} else {
$costdesc="Fixed Price";
$amount=round($a["task_amount"],2);
}
$s = "\n<tr>";
$s .= '<td><a href="./index.php?m=tasks&a=view&task_id=' . $tasks["task_log_task"] . '"><img src="./images/icons/pencil.gif" border="0" alt="Edit"></a></td>';
$s .= "<td><a href=\"javascript:delIt2({$a['task_queue_id']});\" title=\"".$AppUI->_('delete')."\"><img src=\"./images/icons/stock_delete-16.png\" border=\"0\" alt=\"Delete\"></a></td>";
$s .= '<td><a href="./index.php?m=tasks&a=view&task_id=' . $tasks["task_log_task"] . '">'.w2PshowImage('icons/pencil.gif', '16', '16').'</a></td>';
$s .= "<td><a href=\"javascript:delIt2({$a['task_queue_id']});\" title=\"".w2PformSafe('delete')."\">". w2PshowImage('icons/stock_delete-16.png', '16', '16'). "</a></td>";
$tdate = new w2p_Utilities_Date($tasks['task_log_date']);
$s .= '<td nowrap align="center">' . $tdate->format($df) . '</td>';
$alt = htmlspecialchars( $tasks["task_log_name"] );
$s .= '<td align=left>&nbsp;<a href="./index.php?m=tasks&a=view&task_id=' . $tasks["task_log_task"] . '" title="' . $alt . '">' . $tasks["task_log_name"] . '</a></td>';
$s .= '<td>'. $tasks["task_log_description"] . '</td>';
$s .= '<td nowrap="nowrap" align=center>'.$username["contact_first_name"].' '.$username["contact_last_name"].'</td>';
$s .= '<td nowrap="nowrap" align=center>'.$tasks["task_log_hours"].'</td>';
$s .= '<td nowrap="nowrap">'.$costdesc.'</td>';
$s .= '<td nowrap="nowarap">' . w2PgetConfig('currency_symbol') . '&nbsp;' . $amount.'</td>';
$s .= '</tr>';
$s .= '<tr>';
$s .= '<td colspan="2">&nbsp;</td>';
$s .= '<td colspan="6">';
$s .= $tasks["task_log_description"];
$s .= '</td>';
$s .= '<td nowrap="nowrap">' . w2PgetConfig('currency_symbol') . '&nbsp;' . $amount.'</td>';
$s .= "</tr>\n";
echo $s;
......@@ -234,26 +255,29 @@ function showtasklog(&$a) {
global $AppUI, $project_id;
$df = $AppUI->getPref( 'SHDATEFORMAT' );
$q = new w2p_Database_Query();
$q->addQuery('
contact_first_name,
contact_last_name');
$q->addTable('contacts');
$q->leftJoin('users', 'u', 'user_contact = contact_id');
$q->addWhere('user_id = ' . $a['task_log_creator']);
$tmpuser=$q->exec();
$username=db_fetch_assoc($tmpuser);
$q = new w2p_Database_Query();
$q->addQuery('
contact_first_name,
contact_last_name');
$q->addTable('contacts');
$q->leftJoin('users', 'u', 'user_contact = contact_id');
$q->addWhere('user_id = ' . $a['task_log_creator']);
$tmpuser=$q->exec();
if (!$tmpuser) {
echo db_error();
}
$username=db_fetch_assoc($tmpuser);
$q->clear();
$q->addQuery('task_invoice');
$q->addTable('invoice_task_queue');
$q->addWhere('task_log_id = ' . $a['task_log_id']);
$q->clear();
$q->addQuery('task_invoice');
$q->addTable('invoice_task_queue');
$q->addWhere('task_log_id = ' . $a['task_log_id']);
$tmpcheck=$q->exec();
$check=db_fetch_assoc($tmpcheck);
$tmpcheck=$q->exec();
$check=db_fetch_assoc($tmpcheck);
$date = new w2p_Utilities_Date($a['task_log_date']);
$date = new w2p_Utilities_Date($a['task_log_date']);
$s='
<tr valign="top">
<td><input type="checkbox" name="num_'.$a["task_log_id"].'"></td>
......@@ -263,7 +287,7 @@ $date = new w2p_Utilities_Date($a['task_log_date']);
<td nowrap>'.$username["contact_first_name"].' '.$username["contact_last_name"].'</td>
<td nowrap>'.$a['task_log_hours'].'</td>
<td nowrap>'.$a['billingcode_name'].'</td>
<td align="right" nowrap="nowrap">'.w2PgetConfig('currency_symbol').'&nbsp; <input type="text" name="fixed_'.$a['task_log_id'].'" size="6">
<td align="right" nowrap="nowrap">'.w2PgetConfig('currency_symbol').'&nbsp; <input type="text" name="fixed_'.$a['task_log_id'].'" size="6">
</tr>
';
if (trim($check['task_invoice']) == '')
......@@ -410,29 +434,37 @@ Invoices will not be editable once the status changes from Open for Editing.
<tr>
<th width="10">&nbsp;</th>
<th width="15">&nbsp;</td>
<th><?php echo $AppUI->_('Date');?></th>
<th><?php echo $AppUI->_('Task Name');?></th>
<th width="250" nowrap="nowrap"><?php echo $AppUI->_('Task Creator');?></th>
<th width="100" nowrap="nowrap"><?php echo $AppUI->_('Task Hours');?></th>
<th width="100" nowrap="nowrap"><?php echo $AppUI->_('Billing Code');?></th>
<th width="100" nowrap="nowrap"><?php echo $AppUI->_('Amount');?></th>
<th><?php echo w2PformSafe('Date');?></th>
<th><?php echo w2PformSafe('Task Name');?></th>
<th><?php echo w2PformSafe('Task Log');?></th>
<th width="250" nowrap="nowrap"><?php echo w2PformSafe('Task Creator');?></th>
<th width="100" nowrap="nowrap"><?php echo w2PformSafe('Task Hours');?></th>
<th width="100" nowrap="nowrap"><?php echo w2PformSafe('Billing Code');?></th>
<th width="100" nowrap="nowrap"><?php echo w2PformSafe('Amount');?></th>
</tr>
<?php
$myamount=0;
$myhours=0;
for ($s=0; $s < count($tasks); $s++) {
$tnums=count($tasks);
if ($tnums) {
$tmpamount=0;
$tmpamount = showtask( $tasks[$s], 1 );
$tmpamount = invoice_showtask( $tasks[$s], 1 );
$myamount=$myamount + $tmpamount;
$t = &$tasks[$s];
$myhours = $myhours + invoice_getHours( $tasks[$s]);
}
}
?>
<tr>
<td colspan=7 align=right><b>Total</b></td>
<td colspan=6 align=right><b>Total</b></td>
<td align="center"><b><?php echo $myhours; ?></b></td>
<td>&nbsp;</td>
<td>
<?php echo w2PgetConfig('currency_symbol'); ?>&nbsp;
<b>
<?php echo w2PgetConfig('currency_symbol'); ?>
<?php echo $myamount ?>
</b>
</td>
</tr>
</table>
......@@ -451,7 +483,7 @@ for ($s=0; $s < count($tasks); $s++) {
<input type="hidden" name="inv_start_date" value="" class="text" />
<input type="text" name="start_date" value="" class="text" />
<a href="#" onClick="popCalendar('start_date')">
<img src="./images/calendar.gif" width="24" height="12" alt="<?php echo $AppUI->_('Calendar');?>" border="0" />
<img src="./images/calendar.gif" width="24" height="12" alt="<?php echo w2PformSafe('Calendar');?>" border="0" />
</a>
</td>
......@@ -459,11 +491,11 @@ for ($s=0; $s < count($tasks); $s++) {
<input type="hidden" name="inv_end_date" value="" class="text" />
<input type="text" name="end_date" value="" class="text" />
<a href="#" onClick="popCalendar('end_date')">
<img src="./images/calendar.gif" width="24" height="12" alt="<?php echo $AppUI->_('Calendar');?>" border="0" />
<img src="./images/calendar.gif" width="24" height="12" alt="<?php echo w2PformSafe('Calendar');?>" border="0" />
</a>
</td>
<td>
<input class="button" type="button" name="btnFuseSearch" value="<?php echo $AppUI->_('search');?>" onClick="searchIt();" />
<input class="button" type="button" name="btnFuseSearch" value="<?php echo w2PformSafe('search');?>" onClick="searchIt();" />
</td>
</tr>
</form>
......@@ -476,14 +508,14 @@ for ($s=0; $s < count($tasks); $s++) {
<input type="hidden" name="task_invoice" value="<?php echo $invoice_id;?>" />
<input type="hidden" name="project_creator" value="<?php echo $AppUI->user_id;?>" />
<tr>
<td align="right" nowrap="nowrap"><?php echo $AppUI->_('Task Name');?>
<td align="right" nowrap="nowrap"><?php echo w2PformSafe('Task Name');?>
<?php echo arraySelect( $task_list, 'task_id', 'size="1" class="text" onchange="changeIt();"', $obj->task_status, true );?></td>
</form>
</tr>
<tr>
<td colspan="2" align="right">
<input class="button" type="button" name="btnFuseAction" value="<?php echo $AppUI->_('Add selected tasks log to invoice');?>" onClick="submitIt();" />
<input class="button" type="button" name="btnFuseAction" value="<?php echo w2PformSafe('Add selected tasks log to invoice');?>" onClick="submitIt();" />
</td>
</tr>
<?php
......@@ -497,13 +529,13 @@ if (isset($_POST['start_date']))
</table>
<table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">
<tr>
<th><?php $AppUI->_('Select') ?></th>
<th><?php echo $AppUI->_('Date');?></th>
<th><?php echo $AppUI->_('Log Summary');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Creator');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Hours');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Billing Code');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Fixed Amount');?></th>
<th><?php w2PformSafe('Select') ?></th>
<th><?php echo w2PformSafe('Date');?></th>
<th><?php echo w2PformSafe('Log Summary');?></th>
<th nowrap="nowrap"><?php echo w2PformSafe('Creator');?></th>
<th nowrap="nowrap"><?php echo w2PformSafe('Hours');?></th>
<th nowrap="nowrap"><?php echo w2PformSafe('Billing Code');?></th>
<th nowrap="nowrap"><?php echo w2PformSafe('Fixed Amount');?></th>
</tr>
<form name="editFrm" action="./index.php?m=invoice" method="post">
<input type="hidden" name="dosql" value="do_invoice_aed" />
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment