Permalink
Browse files

Fixed multi-account problems in timesheet and reporting

  • Loading branch information...
Timo Haberkern Timo Haberkern
Timo Haberkern authored and Timo Haberkern committed Aug 2, 2012
1 parent 6c44e09 commit 95531aabe53886ef27a067ca3a12f43000ff8e46
@@ -1,5 +1,5 @@
all:
- version: 1.3.5
+ version: 1.3.6
user:
cultures: [de,en]
@@ -94,7 +94,6 @@ public function executeProjectTotal(sfWebRequest $request)
$this->projects,
$this->user,
$account_id);
-
}
public function executeClearFilter(sfWebRequest $request)
@@ -10,86 +10,91 @@
<div class="content">
<table cellspacing="0">
<thead>
- <tr>
- <td colspan="5">
- <?php include_partial('filterbar', array('destination_action' => 'projectTotal',
- 'users' => $users,
- 'user' => $user,
- 'show_project_select' => true,
- 'show_pagesize_select' => false,
- 'projects'=>$projects)); ?>
- </td>
- </tr>
- <tr>
- <td class="tl"><?php echo __('Project');?></td>
- <td class="tl"><?php echo __('User');?></td>
- <td class="tl" style="width: 600px"><?php echo __('Effort');?></td>
- </tr>
+ <tr>
+ <td colspan="5">
+ <?php include_partial('filterbar', array('destination_action' => 'projectTotal',
+ 'users' => $users,
+ 'user' => $user,
+ 'show_project_select' => true,
+ 'show_pagesize_select' => false,
+ 'projects'=>$projects)); ?>
+ </td>
+ </tr>
+ <tr>
+ <td class="tl"><?php echo __('Project');?></td>
+ <td class="tl"><?php echo __('User');?></td>
+ <td class="tl" style="width: 600px"><?php echo __('Effort');?></td>
+ </tr>
</thead>
<tbody>
- <?php $project_totals = $sf_data->getRaw('project_totals');?>
- <?php $index = 0;?>
- <?php foreach ($project_totals as $project_infos): ?>
- <tr class="<?php echo $index++ % 2 == 1 ? "odd" : "even"; ?>">
- <td style="font-weight: bold;" rowspan="<?php echo sizeof($project_infos['items']) + 2; ?>">
- <?php echo $project_infos['project']->name ?>
- <?php if ($project_infos['project']->number != ""): ?>
- <p style="font-size: 0.8em;"><?php echo $project_infos['project']->number ?></p>
- <?php endif; ?>
- </td>
- <td class="slim">&nbsp;</td>
- <td class="slim">
- <table class="report" style="width: 100%">
- <thead>
- <tr>
- <?php foreach ($types as $type): ?>
- <td class="tc itemtype"><?php echo $type->name; ?></td>
- <?php endforeach; ?>
- <td class="tr slim"><?php echo __('Total hours (days)'); ?></td>
- </tr>
- </thead>
- </table>
- </td>
- </tr>
- <?php $project_total = 0; ?>
- <?php foreach ($project_infos['items'] as $user_infos): ?>
+ <?php $project_totals = $sf_data->getRaw('project_totals');?>
+ <?php $index = 0;?>
+ <?php $overall_total = 0; ?>
+ <?php foreach ($project_totals as $project_infos): ?>
+ <tr class="<?php echo $index++ % 2 == 1 ? "odd" : "even"; ?>">
+ <td style="font-weight: bold;" rowspan="<?php echo sizeof($project_infos['items']) + 2; ?>">
+ <?php echo $project_infos['project']->name ?>
+ <?php if ($project_infos['project']->number != ""): ?>
+ <p style="font-size: 0.8em;"><?php echo $project_infos['project']->number ?></p>
+ <?php endif; ?>
+ </td>
+ <td class="slim">&nbsp;</td>
+ <td class="slim">
+ <table class="report" style="width: 100%">
+ <thead>
<tr>
- <td class="slim"><?php echo $user_infos['user']; ?></td>
- <td class="slim">
- <?php if ($sf_user->hasProjectCredential('credential.report.other', $project_infos['project']) ||
- ($sf_user->getAttribute('overlord', 0) == 1) ||
- ($user_infos['user']->id == $sf_user->getId() && $sf_user->hasProjectCredential('credential.report.project_total.self', $project_infos['project']))):?>
- <table class="report" style="width: 100%">
- <tr>
- <?php $total = 0; ?>
- <?php foreach ($types as $type): ?>
- <?php
- $value = array_key_exists($type->id, $user_infos['time']) ? $user_infos['time'][$type->id]->get('sum') : 0;
- $total += $value;
- $project_total += $value;
- ?>
- <td class="tr itemtype" style="border-right: 1px solid #dedbb3;">
- <?php echo number_format($value, 2); ?>
- </td>
- <?php endforeach; ?>
- <td class="tr slim" style="background-color: #e5f7d3;">
- <?php echo number_format($total, 2); ?> (<?php echo number_format($total / 8, 2); ?>)
- </td>
- </tr>
- </table>
- <?php else: ?>
- <div class="msg msg-warn">
- <p><?php echo __('You are not allowed to show this users data in this project');?></p>
- </div>
-
- <?php endif;?>
- </td>
+ <?php foreach ($types as $type): ?>
+ <td class="tc itemtype"><?php echo $type->name; ?></td>
+ <?php endforeach; ?>
+ <td class="tr slim"><?php echo __('Total hours (days)'); ?></td>
</tr>
+ </thead>
+ </table>
+ </td>
+ </tr>
+ <?php $project_total = 0; ?>
+ <?php foreach ($project_infos['items'] as $user_infos): ?>
+ <tr>
+ <td class="slim"><?php echo $user_infos['user']; ?></td>
+ <td class="slim">
+ <?php if ($sf_user->hasProjectCredential('credential.report.other', $project_infos['project']) ||
+ ($sf_user->getAttribute('overlord', 0) == 1) ||
+ ($user_infos['user']->id == $sf_user->getId() && $sf_user->hasProjectCredential('credential.report.project_total.self', $project_infos['project']))):?>
+ <table class="report" style="width: 100%">
+ <tr>
+ <?php $total = 0; ?>
+ <?php foreach ($types as $type): ?>
+ <?php
+ $value = array_key_exists($type->id, $user_infos['time']) ? $user_infos['time'][$type->id]->get('sum') : 0;
+ $total += $value;
+ $project_total += $value;
+ ?>
+ <td class="tr itemtype" style="border-right: 1px solid #dedbb3;">
+ <?php echo number_format($value, 2); ?>
+ </td>
+ <?php endforeach; ?>
+ <td class="tr slim" style="background-color: #e5f7d3;">
+ <?php echo number_format($total, 2); ?> (<?php echo number_format($total / 8, 2); ?>)
+ </td>
+ </tr>
+ </table>
+ <?php else: ?>
+ <div class="msg msg-warn">
+ <p><?php echo __('You are not allowed to show this users data in this project');?></p>
+ </div>
+
+ <?php endif;?>
+ </td>
+ </tr>
<?php endforeach; ?>
- <tr>
- <td colspan="2" class="slim" style="background-color: #bee994; text-align: right; padding-right: 4px;"><?php echo __('Total Project'); ?>: <?php echo number_format($project_total, 2) . ' (' . number_format($project_total / 8, 2) . ')'; ?></td>
- </tr>
+ <?php $overall_total += $project_total; ?>
+ <tr>
+ <td colspan="2" class="slim" style="background-color: #bee994; text-align: right; padding-right: 4px;"><?php echo __('Total Project'); ?>: <?php echo number_format($project_total, 2) . ' (' . number_format($project_total / 8, 2) . ')'; ?></td>
+ </tr>
<?php endforeach; ?>
+ <tr>
+ <td colspan="3" class="slim" style="font-weight: bold; background-color: #71b82b; text-align: right; padding-right: 4px;"><?php echo __('Overall Total'); ?>: <?php echo number_format($overall_total, 2) . ' (' . number_format($overall_total / 8, 2) . ')'; ?></td>
+ </tr>
</tbody>
</table>
</div>
@@ -25,12 +25,12 @@ public function executeIndex(sfWebRequest $request)
$account_id = $this->getUser()->getAttribute('account_id');
$this->projects = ProjectTable::getInstance()
- ->findByAccountId($account_id);
+ ->findByAccountId($account_id);
$this->user = UserTable::getInstance()->find($this->getUser()->getAttribute('uid'));
$this->item_types = TimeItemTypeTable::getInstance()
- ->findByAccountId($account_id);
+ ->findByAccountId($account_id);
$this->default_item_type = TimeItemTypeTable::getInstance()->findDefaultForAccount($account_id);
if ($this->default_item_type) {
@@ -41,14 +41,14 @@ public function executeIndex(sfWebRequest $request)
}
$items = Doctrine_Query::create()
- ->from('TimeLogItem ti')
- ->where('ti.itemdate >= ? and itemdate <= ? and ti.user_id = ?',
- array(date('Y-m-d', $days[1]),
- date('Y-m-d', $days[1] + (5 * 24 * 60 * 60)),
- $this->getUser()->getAttribute('uid')
- )
- )
- ->execute();
+ ->from('TimeLogItem ti')
+ ->where('ti.itemdate >= ? and itemdate <= ? and ti.user_id = ?',
+ array(date('Y-m-d', $days[1]),
+ date('Y-m-d', $days[1] + (5 * 24 * 60 * 60)),
+ $this->getUser()->getAttribute('uid')
+ )
+ )
+ ->execute();
$this->time_items = new TimeItemSelector($items);
$this->account = AccountTable::getInstance()->find($account_id);
@@ -57,15 +57,15 @@ public function executeIndex(sfWebRequest $request)
public function executeField(sfWebRequest $request)
{
$this->weekstart = $request->getParameter('weekstart');
-
+
$account_id = $this->getUser()->getAttribute('account_id');
$query = new Doctrine_Query();
$project = ProjectTable::getInstance()
- ->find($request->getParameter('project_id'));
+ ->find($request->getParameter('project_id'));
$item_types = TimeItemTypeTable::getInstance()
- ->findByAccountId($account_id);
+ ->findByAccountId($account_id);
$this->default_item_type = TimeItemTypeTable::getInstance()->findDefaultForAccount($account_id);
if ($this->default_item_type) {
@@ -74,7 +74,7 @@ public function executeField(sfWebRequest $request)
else {
$this->default_item_type_name = null;
}
-
+
$this->setLayout(false);
return $this->renderPartial('timeitem', array(
'item_types' => $item_types,
@@ -88,7 +88,7 @@ public function executeField(sfWebRequest $request)
public function executeUpdate($request)
{
$time_values = $request->getParameter('time', array());
-
+
$user = UserTable::getInstance()->find($this->getUser()->getAttribute('uid'));
$this->time_values = $time_values;
@@ -97,7 +97,7 @@ public function executeUpdate($request)
if (!array_key_exists($i, $time_values)) {
continue;
}
-
+
$projects = $time_values[$i];
$booking_timestamp = $request->getParameter('weekstart') + ($i - 1) * 24 * 60 * 60;
@@ -107,10 +107,10 @@ public function executeUpdate($request)
foreach ($projects as $pid => $project) {
$query = new Doctrine_Query();
$query->delete('TimeLogItem ti')->where('ti.user_id=? AND ti.project_id=? AND ti.itemdate=?',
- array($this->getUser()->getAttribute('uid'),
- $pid,
- $booking_date))
- ->execute();
+ array($this->getUser()->getAttribute('uid'),
+ $pid,
+ $booking_date))
+ ->execute();
for ($time_index = 0; $time_index < count($project['time']); $time_index++) {
$time_value = $project['time'][$time_index];
@@ -120,8 +120,8 @@ public function executeUpdate($request)
if (($time_value != "") && ($time_value != 0)) {
$type_query = new Doctrine_Query();
$type = $type_query->from('TimeItemType tit')
- ->where('tit.name=?', array($time_type))
- ->fetchOne();
+ ->where('tit.name=? and tit.account_id=?', array($time_type, $this->getUser()->getAttribute('account_id')))
+ ->fetchOne();
$current_value = new TimeLogItem();
@@ -136,8 +136,8 @@ public function executeUpdate($request)
}
}
- TimeLogItemTable::getInstance()->updateMissedBookings($booking_timestamp,
- $user);
+ TimeLogItemTable::getInstance()->updateMissedBookings($booking_timestamp,
+ $user);
}
}

0 comments on commit 95531aa

Please sign in to comment.