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 == '') { ...@@ -52,10 +52,13 @@ if($task_id == '') {
$q = new w2p_Database_Query(); $q = new w2p_Database_Query();
$q->addQuery('task_log_id'); $q->addQuery('task_log_id');
$q->addTable('invoice_task_queue'); $q->addTable('invoice_task_queue');
$temp_billed = db_loadColumn($q->prepare()); //$temp_billed = db_loadColumn($q->prepare());
$temp_billed = $q->prepare();
$billed = ''; $billed = '';
foreach ($temp_billed as $task_log) foreach ($temp_billed as $task_log) {
echo "invoice: " . $task_log . "<br>";
$billed .= $task_log . ', '; $billed .= $task_log . ', ';
}
if (!empty($billed)) if (!empty($billed))
$billed = '(' . substr($billed, 0, -2) . ')'; $billed = '(' . substr($billed, 0, -2) . ')';
$q->clear(); $q->clear();
...@@ -63,8 +66,11 @@ $q->addQuery('invoice_tag, invoice_status'); ...@@ -63,8 +66,11 @@ $q->addQuery('invoice_tag, invoice_status');
$q->addTable('invoice'); $q->addTable('invoice');
$q->addWhere('invoice_id = ' . $invoice_id); $q->addWhere('invoice_id = ' . $invoice_id);
$ptrc = $q->exec(); $ptrc = $q->exec();
if (!$ptrc) {
echo db_error();
}
$nums=db_num_rows($ptrc); $nums=db_num_rows($ptrc);
echo db_error();
for ($x=0; $x < $nums; $x++) { for ($x=0; $x < $nums; $x++) {
$row = db_fetch_assoc( $ptrc ); $row = db_fetch_assoc( $ptrc );
$invoice_tag = $row["invoice_tag"]; $invoice_tag = $row["invoice_tag"];
...@@ -160,70 +166,85 @@ $q->addOrder('billingcode_name ASC'); ...@@ -160,70 +166,85 @@ $q->addOrder('billingcode_name ASC');
$billingcodes = $q->loadList(); $billingcodes = $q->loadList();
function showtask(&$a) { // FIXME: Refactor invoice_showtask() and invoice_getHours()
global $AppUI, $project_id, $billingcodes; // since they query the same database with the same row.
$df = $AppUI->getPref( 'SHDATEFORMAT' ); // This would make all more efficient.
function invoice_getHours(&$a) {
global $project_id;
$q = new w2p_Database_Query(); $q = new w2p_Database_Query();
$q->addQuery(' $q->addQuery('task_log_id, task_log_hours');
task_log_id, $q->addTable('task_log');
task_log_task, $q->addWhere('task_log_id = ' . $a['task_log_id']);
task_log_name, $q->addOrder('task_log_name ASC');
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(); $tmptasks=$q->exec();
$tasks=db_fetch_assoc($tmptasks); $tasks=db_fetch_assoc($tmptasks);
$q->clear(); $hours = $tasks['task_log_hours'];
$q->addQuery(' return $hours;
contact_first_name, }
contact_last_name');
$q->addTable('contacts'); function invoice_showtask(&$a) {
$q->leftJoin('users', 'u', 'user_contact = contact_id'); global $AppUI, $project_id, $billingcodes;
$q->addWhere('user_id = ' . $tasks['task_log_creator']); $df = $AppUI->getPref( 'SHDATEFORMAT' );
$tmpuser=$q->exec(); $q = new w2p_Database_Query();
$username=db_fetch_assoc($tmpuser); $q->addQuery('
task_log_id,
if ($a["task_amount"] == "0") { task_log_task,
$costdesc="None"; task_log_name,
for ($x=0; $x < count($billingcodes); $x++) { task_log_description,
if ($billingcodes[$x]["billingcode_id"] == $tasks["task_log_costcode"]) { task_log_costcode,
$costdesc=$billingcodes[$x]["billingcode_name"]; task_log_creator,
$rate=$billingcodes[$x]["billingcode_value"]; 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 = "\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="./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=\"".$AppUI->_('delete')."\"><img src=\"./images/icons/stock_delete-16.png\" border=\"0\" alt=\"Delete\"></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']); $tdate = new w2p_Utilities_Date($tasks['task_log_date']);
$s .= '<td nowrap align="center">' . $tdate->format($df) . '</td>'; $s .= '<td nowrap align="center">' . $tdate->format($df) . '</td>';
$alt = htmlspecialchars( $tasks["task_log_name"] ); $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 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>'.$username["contact_first_name"].' '.$username["contact_last_name"].'</td>';
$s .= '<td nowrap="nowrap" align=center>'.$tasks["task_log_hours"].'</td>'; $s .= '<td nowrap="nowrap" align=center>'.$tasks["task_log_hours"].'</td>';
$s .= '<td nowrap="nowrap">'.$costdesc.'</td>'; $s .= '<td nowrap="nowrap">'.$costdesc.'</td>';
$s .= '<td nowrap="nowarap">' . w2PgetConfig('currency_symbol') . '&nbsp;' . $amount.'</td>'; $s .= '<td nowrap="nowrap">' . 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 .= "</tr>\n"; $s .= "</tr>\n";
echo $s; echo $s;
...@@ -234,26 +255,29 @@ function showtasklog(&$a) { ...@@ -234,26 +255,29 @@ function showtasklog(&$a) {
global $AppUI, $project_id; global $AppUI, $project_id;
$df = $AppUI->getPref( 'SHDATEFORMAT' ); $df = $AppUI->getPref( 'SHDATEFORMAT' );
$q = new w2p_Database_Query(); $q = new w2p_Database_Query();
$q->addQuery(' $q->addQuery('
contact_first_name, contact_first_name,
contact_last_name'); contact_last_name');
$q->addTable('contacts'); $q->addTable('contacts');
$q->leftJoin('users', 'u', 'user_contact = contact_id'); $q->leftJoin('users', 'u', 'user_contact = contact_id');
$q->addWhere('user_id = ' . $a['task_log_creator']); $q->addWhere('user_id = ' . $a['task_log_creator']);
$tmpuser=$q->exec(); $tmpuser=$q->exec();
$username=db_fetch_assoc($tmpuser); if (!$tmpuser) {
echo db_error();
}
$username=db_fetch_assoc($tmpuser);
$q->clear(); $q->clear();
$q->addQuery('task_invoice'); $q->addQuery('task_invoice');
$q->addTable('invoice_task_queue'); $q->addTable('invoice_task_queue');
$q->addWhere('task_log_id = ' . $a['task_log_id']); $q->addWhere('task_log_id = ' . $a['task_log_id']);
$tmpcheck=$q->exec(); $tmpcheck=$q->exec();
$check=db_fetch_assoc($tmpcheck); $check=db_fetch_assoc($tmpcheck);
$date = new w2p_Utilities_Date($a['task_log_date']); $date = new w2p_Utilities_Date($a['task_log_date']);
$s=' $s='
<tr valign="top"> <tr valign="top">
<td><input type="checkbox" name="num_'.$a["task_log_id"].'"></td> <td><input type="checkbox" name="num_'.$a["task_log_id"].'"></td>
...@@ -263,7 +287,7 @@ $date = new w2p_Utilities_Date($a['task_log_date']); ...@@ -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>'.$username["contact_first_name"].' '.$username["contact_last_name"].'</td>
<td nowrap>'.$a['task_log_hours'].'</td> <td nowrap>'.$a['task_log_hours'].'</td>
<td nowrap>'.$a['billingcode_name'].'</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> </tr>
'; ';
if (trim($check['task_invoice']) == '') if (trim($check['task_invoice']) == '')
...@@ -410,29 +434,37 @@ Invoices will not be editable once the status changes from Open for Editing. ...@@ -410,29 +434,37 @@ Invoices will not be editable once the status changes from Open for Editing.
<tr> <tr>
<th width="10">&nbsp;</th> <th width="10">&nbsp;</th>
<th width="15">&nbsp;</td> <th width="15">&nbsp;</td>
<th><?php echo $AppUI->_('Date');?></th> <th><?php echo w2PformSafe('Date');?></th>
<th><?php echo $AppUI->_('Task Name');?></th> <th><?php echo w2PformSafe('Task Name');?></th>
<th width="250" nowrap="nowrap"><?php echo $AppUI->_('Task Creator');?></th> <th><?php echo w2PformSafe('Task Log');?></th>
<th width="100" nowrap="nowrap"><?php echo $AppUI->_('Task Hours');?></th> <th width="250" nowrap="nowrap"><?php echo w2PformSafe('Task Creator');?></th>
<th width="100" nowrap="nowrap"><?php echo $AppUI->_('Billing Code');?></th> <th width="100" nowrap="nowrap"><?php echo w2PformSafe('Task Hours');?></th>
<th width="100" nowrap="nowrap"><?php echo $AppUI->_('Amount');?></th> <th width="100" nowrap="nowrap"><?php echo w2PformSafe('Billing Code');?></th>
<th width="100" nowrap="nowrap"><?php echo w2PformSafe('Amount');?></th>
</tr> </tr>
<?php <?php
$myamount=0; $myamount=0;
$myhours=0;
for ($s=0; $s < count($tasks); $s++) { for ($s=0; $s < count($tasks); $s++) {
$tnums=count($tasks); $tnums=count($tasks);
if ($tnums) { if ($tnums) {
$tmpamount=0; $tmpamount=0;
$tmpamount = showtask( $tasks[$s], 1 ); $tmpamount = invoice_showtask( $tasks[$s], 1 );
$myamount=$myamount + $tmpamount; $myamount=$myamount + $tmpamount;
$t = &$tasks[$s];
$myhours = $myhours + invoice_getHours( $tasks[$s]);
} }
} }
?> ?>
<tr> <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> <td>
<?php echo w2PgetConfig('currency_symbol'); ?>&nbsp; <b>
<?php echo w2PgetConfig('currency_symbol'); ?>
<?php echo $myamount ?> <?php echo $myamount ?>
</b>
</td> </td>
</tr> </tr>
</table> </table>
...@@ -451,7 +483,7 @@ for ($s=0; $s < count($tasks); $s++) { ...@@ -451,7 +483,7 @@ for ($s=0; $s < count($tasks); $s++) {
<input type="hidden" name="inv_start_date" value="" class="text" /> <input type="hidden" name="inv_start_date" value="" class="text" />
<input type="text" name="start_date" value="" class="text" /> <input type="text" name="start_date" value="" class="text" />
<a href="#" onClick="popCalendar('start_date')"> <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> </a>
</td> </td>
...@@ -459,11 +491,11 @@ for ($s=0; $s < count($tasks); $s++) { ...@@ -459,11 +491,11 @@ for ($s=0; $s < count($tasks); $s++) {
<input type="hidden" name="inv_end_date" value="" class="text" /> <input type="hidden" name="inv_end_date" value="" class="text" />
<input type="text" name="end_date" value="" class="text" /> <input type="text" name="end_date" value="" class="text" />
<a href="#" onClick="popCalendar('end_date')"> <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> </a>
</td> </td>
<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> </td>
</tr> </tr>
</form> </form>
...@@ -476,14 +508,14 @@ for ($s=0; $s < count($tasks); $s++) { ...@@ -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="task_invoice" value="<?php echo $invoice_id;?>" />
<input type="hidden" name="project_creator" value="<?php echo $AppUI->user_id;?>" /> <input type="hidden" name="project_creator" value="<?php echo $AppUI->user_id;?>" />
<tr> <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> <?php echo arraySelect( $task_list, 'task_id', 'size="1" class="text" onchange="changeIt();"', $obj->task_status, true );?></td>
</form> </form>
</tr> </tr>
<tr> <tr>
<td colspan="2" align="right"> <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> </td>
</tr> </tr>
<?php <?php
...@@ -497,13 +529,13 @@ if (isset($_POST['start_date'])) ...@@ -497,13 +529,13 @@ if (isset($_POST['start_date']))
</table> </table>
<table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl"> <table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl">
<tr> <tr>
<th><?php $AppUI->_('Select') ?></th> <th><?php w2PformSafe('Select') ?></th>
<th><?php echo $AppUI->_('Date');?></th> <th><?php echo w2PformSafe('Date');?></th>
<th><?php echo $AppUI->_('Log Summary');?></th> <th><?php echo w2PformSafe('Log Summary');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Creator');?></th> <th nowrap="nowrap"><?php echo w2PformSafe('Creator');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Hours');?></th> <th nowrap="nowrap"><?php echo w2PformSafe('Hours');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Billing Code');?></th> <th nowrap="nowrap"><?php echo w2PformSafe('Billing Code');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Fixed Amount');?></th> <th nowrap="nowrap"><?php echo w2PformSafe('Fixed Amount');?></th>
</tr> </tr>
<form name="editFrm" action="./index.php?m=invoice" method="post"> <form name="editFrm" action="./index.php?m=invoice" method="post">
<input type="hidden" name="dosql" value="do_invoice_aed" /> <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