Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timesheet fixes #2361

Merged
merged 9 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/Domain/Tickets/Controllers/ShowTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 2,7 @@

namespace Leantime\Domain\Tickets\Controllers {

use Carbon\Carbon;
use Illuminate\Contracts\Container\BindingResolutionException;
use Leantime\Core\Controller;
use Leantime\Domain\Projects\Services\Projects as ProjectService;
Expand Down Expand Up @@ -154,7 155,12 @@ public function get($params): Response

$this->tpl->assign('onTheClock', $this->timesheetService->isClocked($_SESSION["userdata"]["id"]));

$this->tpl->assign("timesheetValues", array("kind" => "", "date" => date($this->language->__("language.dateformat")), "hours" => "", "description" => ""));
$this->tpl->assign("timesheetValues", array(
"kind" => "",
"date" => Carbon::now('UTC')->startOfDay(),
"hours" => "",
"description" => "",
));

//TODO: Refactor thumbnail generation in file manager
$this->tpl->assign('imgExtensions', array('jpg', 'jpeg', 'png', 'gif', 'psd', 'bmp', 'tif', 'thm', 'yuv'));
Expand All @@ -164,6 170,7 @@ public function get($params): Response

$response = $this->tpl->displayPartial('tickets.showTicketModal');
$response->headers->set('HX-Trigger', 'ticketUpdate');

return $response;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 35,7 @@
</span>

<label for="timesheetdate"><?php echo $tpl->__('label.date') ?>:</label>
<input type="text" id="timesheetdate" name="date" class="dates" value="<?php echo format($values['date'])->date() ?>" /><br/>
<input type="text" id="timesheetdate" name="date" class="dates" value="<?php echo format($values['date'], 'short') ?>" /><br/>

<label for="hours"><?php echo $tpl->__('label.hours') ?></label>
<span class="field">
Expand Down
52 changes: 32 additions & 20 deletions app/Domain/Timesheets/Controllers/EditTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 2,7 @@

namespace Leantime\Domain\Timesheets\Controllers;

use Carbon\Carbon;
use Leantime\Core\Controller;
use Leantime\Domain\Auth\Models\Roles;
use Leantime\Domain\Timesheets\Repositories\Timesheets as TimesheetRepository;
Expand All @@ -19,6 20,10 @@ class EditTime extends Controller
private ProjectRepository $projects;
private TicketRepository $tickets;

// This is the date we get back from the database, when no date has been sat. This is somewhat a hack and should
// be looked into.
const EMPTY_DATE = '0000-00-00 00:00:00';

/**
* init - initialize private variables
*
Expand Down Expand Up @@ -50,28 55,33 @@ public function run(): Response
Auth::authOrRedirect([Roles::$owner, Roles::$admin, Roles::$manager, Roles::$editor], true);

$info = '';
//Only admins and employees
// Only admins and employees
if (Auth::userIsAtLeast(Roles::$editor)) {
if (isset($_GET['id']) === true) {
$id = ($_GET['id']);

$timesheet = $this->timesheetsRepo->getTimesheet($id);

// Date validation.
$timesheet['invoicedEmplDate'] = $timesheet['invoicedEmplDate'] == self::EMPTY_DATE ? 'now' : $timesheet['invoicedEmplDate'];
$timesheet['invoicedCompDate'] = $timesheet['invoicedCompDate'] == self::EMPTY_DATE ? 'now' : $timesheet['invoicedCompDate'];
$timesheet['paidDate'] = $timesheet['paidDate'] == self::EMPTY_DATE ? 'now' : $timesheet['paidDate'];

$values = array(
'id' => $id,
'userId' => $timesheet['userId'],
'ticket' => $timesheet['ticketId'],
'project' => $timesheet['projectId'],
'date' => $timesheet['workDate'],
'date' => new Carbon($timesheet['workDate'], 'UTC'),
'kind' => $timesheet['kind'],
'hours' => $timesheet['hours'],
'description' => $timesheet['description'],
'invoicedEmpl' => $timesheet['invoicedEmpl'],
'invoicedComp' => $timesheet['invoicedComp'],
'invoicedEmplDate' => $timesheet['invoicedEmplDate'],
'invoicedCompDate' => $timesheet['invoicedCompDate'],
'invoicedEmplDate' => new Carbon($timesheet['invoicedEmplDate'], 'UTC'),
'invoicedCompDate' => new Carbon($timesheet['invoicedCompDate'], 'UTC'),
'paid' => $timesheet['paid'],
'paidDate' => $timesheet['paidDate'],
'paidDate' => new Carbon($timesheet['paidDate'], 'UTC'),
);

if (Auth::userIsAtLeast(Roles::$manager) || $_SESSION['userdata']['id'] == $values['userId']) {
Expand All @@ -86,9 96,7 @@ public function run(): Response
}

if (isset($_POST['date']) && $_POST['date'] != '') {
$timestamp = date_create_from_format($this->language->__("language.dateformat"), $_POST['date']);

$values['date'] = format($_POST['date'])->isoDateMid();
$values['date'] = Carbon::createFromFormat($this->language->__("language.dateformat"), $_POST['date'], 'UTC');
}

if (isset($_POST['hours']) && $_POST['hours'] != '') {
Expand All @@ -106,9 114,9 @@ public function run(): Response
}

if (isset($_POST['invoicedEmplDate']) && $_POST['invoicedEmplDate'] != '') {
$values['invoicedEmplDate'] = format($_POST['invoicedEmplDate'])->isoDateMid();
$values['invoicedEmplDate'] = Carbon::createFromFormat($this->language->__("language.dateformat"), $_POST['invoicedEmplDate'], 'UTC')->midDay();
} else {
$values['invoicedEmplDate'] = date("Y-m-d");
$values['invoicedEmplDate'] = Carbon::now('UTC')->midDay();
}
} else {
$values['invoicedEmpl'] = 0;
Expand All @@ -121,9 129,9 @@ public function run(): Response
}

if (isset($_POST['invoicedCompDate']) && $_POST['invoicedCompDate'] != '') {
$values['invoicedCompDate'] = format($_POST['invoicedCompDate'])->isoDateMid();
$values['invoicedCompDate'] = Carbon::createFromFormat($this->language->__("language.dateformat"), $_POST['invoicedCompDate'], 'UTC')->midDay();
} else {
$values['invoicedCompDate'] = date("Y-m-d");
$values['invoicedCompDate'] = Carbon::now('UTC')->midDay();
}
} else {
$values['invoicedComp'] = 0;
Expand All @@ -136,17 144,16 @@ public function run(): Response
}

if (isset($_POST['paidDate']) && $_POST['paidDate'] != '') {
$values['paidDate'] = format($_POST['paidDate'])->isoDateMid();
$values['paidDate'] = Carbon::createFromFormat($this->language->__("language.dateformat"), $_POST['paidDate'], 'UTC')->midDay();
} else {
$values['paidDate'] = date("Y-m-d");
$values['paidDate'] = Carbon::now('UTC')->midDay();
}
} else {
$values['paid'] = 0;
$values['paidDate'] = '';
}
}


if ($values['ticket'] != '' && $values['project'] != '') {
if ($values['kind'] != '') {
if ($values['date'] != '') {
Expand All @@ -156,21 163,26 @@ public function run(): Response

$timesheetUpdated = $this->timesheetsRepo->getTimesheet($id);

// Date validation.
$timesheetUpdated['invoicedEmplDate'] = $timesheetUpdated['invoicedEmplDate'] == self::EMPTY_DATE ? 'now' : $timesheetUpdated['invoicedEmplDate'];
$timesheetUpdated['invoicedCompDate'] = $timesheetUpdated['invoicedCompDate'] == self::EMPTY_DATE ? 'now' : $timesheetUpdated['invoicedCompDate'];
$timesheetUpdated['paidDate'] = $timesheetUpdated['paidDate'] == self::EMPTY_DATE ? 'now' : $timesheetUpdated['paidDate'];

$values = array(
'id' => $id,
'userId' => $timesheetUpdated['userId'],
'ticket' => $timesheetUpdated['ticketId'],
'project' => $timesheetUpdated['projectId'],
'date' => $timesheetUpdated['workDate'],
'date' => new Carbon($timesheetUpdated['workDate'], 'UTC'),
'kind' => $timesheetUpdated['kind'],
'hours' => $timesheetUpdated['hours'],
'description' => $timesheetUpdated['description'],
'invoicedEmpl' => $timesheetUpdated['invoicedEmpl'],
'invoicedComp' => $timesheetUpdated['invoicedComp'],
'invoicedEmplDate' => $timesheetUpdated['invoicedEmplDate'],
'invoicedCompDate' => $timesheetUpdated['invoicedCompDate'],
'invoicedEmplDate' => new Carbon($timesheetUpdated['invoicedEmplDate'], 'UTC'),
'invoicedCompDate' => new Carbon($timesheetUpdated['invoicedCompDate'], 'UTC'),
'paid' => $timesheetUpdated['paid'],
'paidDate' => $timesheetUpdated['paidDate'],
'paidDate' => new Carbon($timesheetUpdated['paidDate'], 'UTC'),
);
} else {
$this->tpl->setNotification('notifications.time_logged_error_no_hours', 'error');
Expand All @@ -186,13 198,13 @@ public function run(): Response
}
}


$this->tpl->assign('values', $values);

$this->tpl->assign('info', $info);
$this->tpl->assign('allProjects', $this->projects->getAll());
$this->tpl->assign('allTickets', $this->tickets->getAll());
$this->tpl->assign('kind', $this->timesheetsRepo->kind);

return $this->tpl->displayPartial('timesheets.editTime');
} else {
return $this->tpl->displayPartial('errors.error403');
Expand Down
60 changes: 26 additions & 34 deletions app/Domain/Timesheets/Controllers/ShowAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 2,7 @@

namespace Leantime\Domain\Timesheets\Controllers;

use Carbon\Carbon;
use Leantime\Core\Controller;
use Leantime\Domain\Auth\Models\Roles;
use Leantime\Domain\Users\Repositories\Users as UserRepository;
Expand Down Expand Up @@ -73,35 74,29 @@ public function run(): Response
$this->timesheetsService->updateInvoices($invEmpl, $invComp, $paid);
}

$invEmplCheck = '0';
$invCompCheck = '0';

$projectFilter = "";
$dateFromMk = mktime(0, 0, 0, date("m"), '1', date("Y"));
$dateToMk = mktime(0, 0, 0, date("m"), date("t"), date("Y"));

$dateFrom = date("Y-m-d", $dateFromMk);
$dateTo = date("Y-m-d", $dateToMk);
$kind = 'all';
$userId = null;

if (isset($_POST['kind']) && $_POST['kind'] != '') {
if (!empty($_POST['kind'])) {
$kind = strip_tags($_POST['kind']);
}

if (isset($_POST['userId']) && $_POST['userId'] != '') {
if (!empty($_POST['userId'])) {
$userId = intval(strip_tags($_POST['userId']));
}

if (isset($_POST['dateFrom']) && $_POST['dateFrom'] != '') {
$dateFrom = format($_POST['dateFrom'])->isoDate();
$dateFrom = Carbon::now('UTC')->startOfMonth();
if (!empty($_POST['dateFrom'])) {
$dateFrom = Carbon::createFromFormat($_SESSION['usersettings.language.date_format'], $_POST['dateFrom'], 'UTC')->startOfDay();
}

if (isset($_POST['dateTo']) && $_POST['dateTo'] != '') {
$dateTo = format($_POST['dateTo'])->isoDateEnd();
$dateTo = Carbon::now('UTC')->endOfMonth();
if (!empty($_POST['dateTo'])) {
$dateTo = Carbon::createFromFormat($_SESSION['usersettings.language.date_format'], $_POST['dateTo'], 'UTC')->startOfDay();
}

if (isset($_POST['invEmpl']) === true) {
if (isset($_POST['invEmpl'])) {
$invEmplCheck = $_POST['invEmpl'];

if ($invEmplCheck == 'on') {
Expand All @@ -113,7 108,7 @@ public function run(): Response
$invEmplCheck = '0';
}

if (isset($_POST['invComp']) === true) {
if (isset($_POST['invComp'])) {
$invCompCheck = ($_POST['invComp']);

if ($invCompCheck == 'on') {
Expand All @@ -123,7 118,7 @@ public function run(): Response
}
}

if (isset($_POST['paid']) === true) {
if (isset($_POST['paid'])) {
$paidCheck = ($_POST['paid']);

if ($paidCheck == 'on') {
Expand All @@ -136,29 131,15 @@ public function run(): Response
}

$projectFilter = "";
if (isset($_POST['project']) && $_POST['project'] != '') {
if (!empty($_POST['project'])) {
$projectFilter = strip_tags($_POST['project']);
}

$clientId = -1;
if (isset($_POST['clientId']) && $_POST['clientId'] != '') {
if (!empty($_POST['clientId'])) {
$clientId = strip_tags($_POST['clientId']);
}

if (isset($_POST['export'])) {
$values = array(
'project' => $projectFilter,
'clientId' => $clientId,
'kind' => $kind,
'userId' => $userId,
'dateFrom' => $dateFrom,
'dateTo' => $dateTo,
'invEmplCheck' => $invEmplCheck,
'invCompCheck' => $invCompCheck,
);
$this->timesheetsService->export($values);
}

$user = app()->make(UserRepository::class);
$employees = $user->getAll();

Expand All @@ -176,7 157,18 @@ public function run(): Response
$this->tpl->assign('projectFilter', $projectFilter);
$this->tpl->assign('clientFilter', $clientId);
$this->tpl->assign('allClients', $this->clientService->getAll());
$this->tpl->assign('allTimesheets', $this->timesheetsService->getAll((int)$projectFilter, $kind, $dateFrom, $dateTo, $userId, $invEmplCheck, $invCompCheck, '-1', $paidCheck, $clientId));
$this->tpl->assign('allTimesheets', $this->timesheetsService->getAll(
$dateFrom,
$dateTo,
(int)$projectFilter,
$kind,
$userId,
$invEmplCheck,
$invCompCheck,
'-1',
$paidCheck,
$clientId
));

return $this->tpl->display('timesheets.showAll');
}
Expand Down
Loading
Loading