Skip to content

Commit

Permalink
Update cost objects from basic view too.
Browse files Browse the repository at this point in the history
While I'm there, simplify updateTime() and enterTime() to always return a Hermes_Slice already, and only one. Code and coding style cleanups too.
  • Loading branch information
yunosh committed May 26, 2017
1 parent 6c52e9e commit e2039d8
Show file tree
Hide file tree
Showing 6 changed files with 209 additions and 153 deletions.
2 changes: 1 addition & 1 deletion hermes/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
try {
if ($vars->exists('id')) {
$notification->push(_("Your time was successfully updated."), 'horde.success', array('sticky'));
$injector->getInstance('Hermes_Driver')->updateTime(array($info));
$injector->getInstance('Hermes_Driver')->updateTime($info);
} else {
$notification->push(_("Your time was successfully entered."), 'horde.success', array('sticky'));
$injector->getInstance('Hermes_Driver')->enterTime($registry->getAuth(), $info);
Expand Down
92 changes: 55 additions & 37 deletions hermes/lib/Ajax/Application/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,30 @@ public function deleteJobType()
*/
public function deleteSlice()
{
global $injector, $notification;

$driver = $injector->getInstance('Hermes_Driver');
$ids = is_array($this->vars->id)
? $this->vars->id
: array($this->vars->id);

$slices = array();
$ids = !is_array($this->vars->id) ? array($this->vars->id) : $this->vars->id;
foreach ($ids as $id) {
$slices[] = array('id' => $id, 'delete' => true);
try {
$slice = $driver->updateTime(
array('id' => $id, 'delete' => true)
);
$slices[] = $slice['id'];
} catch (Hermes_Exception $e) {
$notification->push($e, 'horde.error');
}
}
try {
$result = $GLOBALS['injector']
->getInstance('Hermes_Driver')
->updateTime($slices);
$GLOBALS['notification']->push(
_("Your time entry was successfully deleted."), 'horde.success');

return $result;
} catch (Hermes_Exception $e) {
$GLOBALS['notification']->push($e, 'horde.error');
}
$notification->push(
_("Your time entry was successfully deleted."), 'horde.success'
);

return $slices;
}

/**
Expand All @@ -160,30 +168,31 @@ public function deleteSlice()
*/
public function enterTime()
{
global $injector, $notification, $registry;

$slice = new Hermes_Slice();
$slice->readForm();

try {
$id = $GLOBALS['injector']
->getInstance('Hermes_Driver')
$new = $injector->getInstance('Hermes_Driver')
->enterTime($slice['employee'], $slice);
$new = current($GLOBALS['injector']
->getInstance('Hermes_Driver')
->getHours(array('id' => $id)));

Hermes::updateCostObject($new);
if ($slice['employee'] == $GLOBALS['registry']->getAuth()) {
$GLOBALS['notification']
->push(_("Your time was successfully entered."), 'horde.success');

if ($slice['employee'] == $registry->getAuth()) {
$notification->push(
_("Your time was successfully entered."),
'horde.success'
);
return $new->toJson();
} else {
$GLOBALS['notification']
->push(sprintf(_("The time was successfully entered for %s."), $slice['employee']), 'horde.success');
return true;
}
$notification->push(
sprintf(
_("The time was successfully entered for %s."),
$slice['employee']
),
'horde.success'
);
return true;
} catch (Hermes_Exception $e) {
$GLOBALS['notification']->push($e, 'horde.error');
$notification->push($e, 'horde.error');
}
}

Expand Down Expand Up @@ -525,21 +534,30 @@ public function updateJobType()
*/
public function updateSlice()
{
global $injector, $notification, $registry;

$slice = new Hermes_Slice();
$slice->readForm();
try {
$GLOBALS['injector']->getInstance('Hermes_Driver')->updateTime(array($slice));
if ($slice['employee'] == $GLOBALS['registry']->getAuth()) {
$GLOBALS['notification']->push(_("Your time was successfully updated."), 'horde.success');
$new = $injector->getInstance('Hermes_Driver')
->updateTime($slice);
if ($slice['employee'] == $registry->getAuth()) {
$notification->push(
_("Your time was successfully updated."),
'horde.success'
);
} else {
$GLOBALS['notification']->push(sprintf(_("The time was successfully updated and saved to the time sheet of %s."), $slice['employee']), 'horde.success');
$notification->push(
sprintf(
_("The time was successfully updated and saved to the time sheet of %s."),
$slice['employee']
),
'horde.success'
);
}

$new = current($GLOBALS['injector']->getInstance('Hermes_Driver')->getHours(array('id' => $slice['id'])));
Hermes::updateCostObject($new);
return $new->toJson();
} catch (Hermes_Exception $e) {
$GLOBALS['notification']->push($e, 'horde.error');
$notification->push($e, 'horde.error');
}
}

Expand Down Expand Up @@ -599,4 +617,4 @@ protected function _readSearchForm()
return $criteria;
}

}
}
62 changes: 34 additions & 28 deletions hermes/lib/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,47 +165,53 @@ abstract public function updateClientSettings($clientID, $enterDescription = 1,
abstract public function purge();

/**
* Save a row of billing information.
* Saves a row of time information.
*
* @param string $employee The Horde ID of the person who worked the
* hours.
* @param array $entries The billing information to enter. Each array
* row must contain the following entries:
* 'date' The day the hours were worked (ISO format)
* 'client' The id of the client the work was done for.
* 'type' The type of work done.
* 'hours' The number of hours worked
* 'rate' The hourly rate the work was done at.
* 'billable' (optional) Whether or not the work is
* billable hours.
* 'description' A short description of the work.
*
* @return integer The new timeslice_id of the newly entered slice
* @param array $info The billing information to enter. Must contain
* the following entries:
* - date: The day the hours were worked
* (ISO format)
* - client: The id of the client the work
* was done for.
* - type: The type of work done.
* - hours: The number of hours worked
* - billable: (optional) Whether or not the
* work is billable hours.
* - description: A short description of the work.
* - note: Any notes.
* - costobject: The costobject id
*
* @return Hermes_Slice The new time slice.
* @throws Hermes_Exception
*/
abstract public function enterTime($employee, $info);

/**
* Update a set of billing information.
* Updates time slice information.
*
* @param array $entries The billing information to enter. Each array row
* must contain the following entries:
* 'id' The id of this time entry.
* 'date' The day the hours were worked (ISO format)
* 'client' The id of the client the work was done for.
* 'type' The type of work done.
* 'hours' The number of hours worked
* 'rate' The hourly rate the work was done at.
* 'billable' Whether or not the work is billable hours.
* 'description' A short description of the work.
* @param array $info The time information to enter. Must contain the
* following entries:
* - id: The id of this time entry.
* - date: The day the hours were worked (ISO
* format)
* - client: The id of the client the work was
* done for.
* - type: The type of work done.
* - hours: The number of hours worked
* - rate: The hourly rate the work was done at.
* - billable: Whether or not the work is billable
* hours.
* - description: A short description of the work.
* - employee: The employee
*
* If any rows contain a 'delete' entry, those rows
* will be deleted instead of updated.
* If any rows contain a 'delete' entry, those rows will
* be deleted instead of updated.
*
* @return mixed boolean
* @return Hermes_Slice The updated time slice.
* @throws Horde_Exception_PermissionDenied
* @throws Hermes_Exception
*/
abstract public function updateTime($entries);

}

0 comments on commit e2039d8

Please sign in to comment.