Skip to content
Draft
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
17 changes: 17 additions & 0 deletions app/Enums/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,23 @@ public static function values(): array

]
]),
"ID" => new Country("ID", [
"displayValue" => "Indonesia",
"currencyCode" => "IDR",
"language" => "Bahasa Indonesia",
"phoneCode" => "+62",
"format" => [
"frontendDate" => "dd/mm/yyyy",
"frontendTime" => "h:i a",
"momentjsDayAndDateWithText" => "ddd D MMMM",
"momentJsTime" => "HH:mm",
"carbonDate" => "d/m/Y",
"carbonTime" => "H:i",
"carbonFullDateWithText" => "d, F Y H:i",
"carbonDateWithText" => "d, F Y"

]
]),
"OT" => new Country("OT", [
"displayValue" => "Other",
"currencyCode" => "EUR",
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/AbsenceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function store(Request $request)
if ($request->user_external_id && auth()->user()->can('absence-manage')) {
$user = User::whereExternalId($request->user_external_id)->first();
if (!$user) {
Session::flash('flash_message_warning', __('Could not find user'));
session()->flash('flash_message_warning', __('Could not find user'));
return redirect()->back();
}
}
Expand All @@ -91,14 +91,14 @@ public function store(Request $request)
'comment' => clean($request->comment),
]);

Session::flash('flash_message', __('Absence registered'));
session()->flash('flash_message', __('Absence registered'));
return redirect()->back();
}

public function destroy(Absence $absence)
{
if (!auth()->user()->can('absence-manage')) {
Session::flash('flash_message_warning', __('You do not have sufficient privileges for this action'));
session()->flash('flash_message_warning', __('You do not have sufficient privileges for this action'));
return redirect()->back();
}
$absence->delete();
Expand Down
12 changes: 6 additions & 6 deletions app/Http/Controllers/ClientsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function store(StoreClientRequest $request)
'is_primary' => true
]);

Session()->flash('flash_message', __('Client successfully added'));
session()->flash('flash_message', __('Client successfully added'));
event(new \App\Events\ClientAction($client, self::CREATED));
return redirect()->route('clients.index');
}
Expand Down Expand Up @@ -351,7 +351,7 @@ public function update($external_id, UpdateClientRequest $request)
'is_primary' => true
])->save();

Session()->flash('flash_message', __('Client successfully updated'));
session()->flash('flash_message', __('Client successfully updated'));
return redirect()->route('clients.index');
}

Expand All @@ -364,9 +364,9 @@ public function destroy($external_id)
try {
$client = $this->findByExternalId($external_id);
$client->delete();
Session()->flash('flash_message', __('Client successfully deleted'));
session()->flash('flash_message', __('Client successfully deleted'));
} catch (\Exception $e) {
Session()->flash('flash_message_warning', __('Client could not be deleted, contact Daybyday support'));
session()->flash('flash_message_warning', __('Client could not be deleted, contact Daybyday support'));
}

return redirect()->route('clients.index');
Expand All @@ -380,15 +380,15 @@ public function destroy($external_id)
public function updateAssign($external_id, Request $request)
{
if (!auth()->user()->can('client-update')) {
Session()->flash('flash_message_warning', __("Not authorized"));
session()->flash('flash_message_warning', __("Not authorized"));
return back();
}

$user = User::where('external_id', $request->user_external_id)->first();
$client = Client::with('user')->where('external_id', $external_id)->first();
$client->updateAssignee($user);

Session()->flash('flash_message', __('New user is assigned'));
session()->flash('flash_message', __('New user is assigned'));
return redirect()->back();
}

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function store(Request $request)
];

if (!array_key_exists($request->type, $modelsMapping)) {
Session::flash('flash_message_warning', __('Could not create comment, type not found! Please contact Daybyday support'));
session()->flash('flash_message_warning', __('Could not create comment, type not found! Please contact Daybyday support'));
throw new \Exception("Could not create comment with type " . $request->type);
return redirect()->back();
}
Comment on lines +28 to 31
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Unreachable code after throw statement.

Line 30 (return redirect()->back();) will never execute because the throw statement on line 29 terminates execution. Additionally, flashing a session message before throwing an exception is ineffective since the flash data won't be available after the exception is handled.

🐛 Proposed fix - either redirect or throw, not both

Option 1: Flash and redirect (user-friendly):

 if (!array_key_exists($request->type, $modelsMapping)) {
     session()->flash('flash_message_warning', __('Could not create comment, type not found! Please contact Daybyday support'));
-    throw new \Exception("Could not create comment with type " . $request->type);
     return redirect()->back();
 }

Option 2: Just throw (for logging/debugging):

 if (!array_key_exists($request->type, $modelsMapping)) {
-    session()->flash('flash_message_warning', __('Could not create comment, type not found! Please contact Daybyday support'));
     throw new \Exception("Could not create comment with type " . $request->type);
-    return redirect()->back();
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
session()->flash('flash_message_warning', __('Could not create comment, type not found! Please contact Daybyday support'));
throw new \Exception("Could not create comment with type " . $request->type);
return redirect()->back();
}
session()->flash('flash_message_warning', __('Could not create comment, type not found! Please contact Daybyday support'));
return redirect()->back();
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Http/Controllers/CommentController.php` around lines 28 - 31, In
CommentController (the method containing session()->flash, throw new \Exception
and return redirect()->back()), remove the unreachable pattern by choosing one
behavior: either remove the throw and keep the user-friendly flow (keep
session()->flash and return redirect()->back()) or remove the session flash and
return redirect and instead just throw the exception for upstream
handling/logging (keep throw new \Exception and delete the return/flash). Ensure
you delete the dead statement (return redirect()->back() when throw remains) or
delete the throw when returning, keeping only the appropriate session/message or
exception handling.

Expand All @@ -40,7 +40,7 @@ public function store(Request $request)
);


Session::flash('flash_message', __('Comment successfully added')); //Snippet in Master.blade.php
session()->flash('flash_message', __('Comment successfully added')); //Snippet in Master.blade.php
return redirect()->back();
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/DepartmentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function store(StoreDepartmentRequest $request)
'name' => $request->name,
'description' => $request->description
]);
Session::flash('flash_message', __('Successfully created new department'));
session()->flash('flash_message', __('Successfully created new department'));
return redirect()->route('departments.index');
}

Expand All @@ -81,7 +81,7 @@ public function destroy($external_id)
$department = Department::whereExternalId($external_id)->first();

if (!$department->users->isEmpty()) {
Session::flash('flash_message_warning', __("Can't delete department with users, please remove users"));
session()->flash('flash_message_warning', __("Can't delete department with users, please remove users"));
return redirect()->route('departments.index');
}
$department->delete();
Expand Down
16 changes: 8 additions & 8 deletions app/Http/Controllers/DocumentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function upload(Request $request, $external_id)
$totaltsize = substr($mbsize, 0, 4);

if ($totaltsize > 15) {
Session::flash('flash_message', __('File Size cannot be bigger than 15MB'));
session()->flash('flash_message', __('File Size cannot be bigger than 15MB'));
return redirect()->back();
Comment on lines +83 to 84
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Incorrect flash key for error condition.

File size limit exceeded is an error scenario, but flash_message (typically styled as success/green) is used instead of flash_message_warning. This may confuse users seeing an error styled as a success message.

🔧 Suggested fix
-                    session()->flash('flash_message', __('File Size cannot be bigger than 15MB'));
+                    session()->flash('flash_message_warning', __('File Size cannot be bigger than 15MB'));

Apply this change at lines 83, 133, and 183.

Also applies to: 133-134, 183-184

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Http/Controllers/DocumentsController.php` around lines 83 - 84, Change
the flash key used for file-size error messages from 'flash_message' to the
error/styled key 'flash_message_warning' in DocumentsController where
session()->flash is called for the size limit check (the three occurrences
shown); update each session()->flash('flash_message', ...) to
session()->flash('flash_message_warning', ...) so the error is styled as a
warning instead of a success.

}

Expand All @@ -102,7 +102,7 @@ public function upload(Request $request, $external_id)
]
);
Document::create($input);
Session::flash('flash_message', __('File successfully uploaded'));
session()->flash('flash_message', __('File successfully uploaded'));
}

/**
Expand Down Expand Up @@ -130,7 +130,7 @@ public function uploadToTask(Request $request, $external_id)
$totaltsize = substr($mbsize, 0, 4);

if ($totaltsize > 15) {
Session::flash('flash_message', __('File Size cannot be bigger than 15MB'));
session()->flash('flash_message', __('File Size cannot be bigger than 15MB'));
return redirect()->back();
}

Expand All @@ -151,7 +151,7 @@ public function uploadToTask(Request $request, $external_id)
]);
}
}
Session::flash('flash_message', __('File successfully uploaded'));
session()->flash('flash_message', __('File successfully uploaded'));
return $task->external_id;
}

Expand Down Expand Up @@ -180,7 +180,7 @@ public function uploadToProject(Request $request, $external_id)
$totaltsize = substr($mbsize, 0, 4);

if ($totaltsize > 15) {
Session::flash('flash_message', __('File Size cannot be bigger than 15MB'));
session()->flash('flash_message', __('File Size cannot be bigger than 15MB'));
return redirect()->back();
}

Expand All @@ -203,7 +203,7 @@ public function uploadToProject(Request $request, $external_id)
]);
}
}
Session::flash('flash_message', __('File successfully uploaded'));
session()->flash('flash_message', __('File successfully uploaded'));
return $project->external_id;
}

Expand All @@ -219,9 +219,9 @@ public function destroy($external_id)
$document = Document::whereExternalId($external_id)->first();
$deleted = $fileSystem->delete($document);
if (!$deleted) {
Session()->flash('flash_message_warning', __("Something wen't wrong, we can't find the file on the cloud. But worry not, we delete what we know about the image"));
session()->flash('flash_message_warning', __("Something wen't wrong, we can't find the file on the cloud. But worry not, we delete what we know about the image"));
} else {
Session()->flash('flash_message', __('File has been deleted'));
session()->flash('flash_message', __('File has been deleted'));
}
$document->delete();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/InvoiceLinesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function destroy(InvoiceLine $invoiceLine)

$invoiceLine->delete();

Session()->flash('flash_message', __('Invoice line successfully deleted'));
session()->flash('flash_message', __('Invoice line successfully deleted'));
return redirect()->route('invoices.show', $invoiceLine->invoice->external_id);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/InvoicesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function newItem($external_id, AddInvoiceLine $request)
$invoice = $this->findByExternalId($external_id);

if (!$invoice->canUpdateInvoice()) {
Session::flash('flash_message_warning', __("Can't insert new invoice line, to already sent invoice"));
session()->flash('flash_message_warning', __("Can't insert new invoice line, to already sent invoice"));
return redirect()->back();
}

Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/LeadsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function updateAssign($external_id, Request $request)
$lead->fill($input)->save();

event(new \App\Events\LeadAction($lead, self::UPDATED_ASSIGN));
Session()->flash('flash_message', __('New user is assigned'));
session()->flash('flash_message', __('New user is assigned'));
return redirect()->back();
}

Expand All @@ -166,7 +166,7 @@ public function updateFollowup(UpdateLeadFollowUpRequest $request, $external_id)
$lead = $this->findByExternalId($external_id);
$lead->fill(['deadline' => Carbon::parse($request->deadline . " " . $request->contact_time . ":00")])->save();
event(new \App\Events\LeadAction($lead, self::UPDATED_DEADLINE));
Session()->flash('flash_message', __('New follow up date is set'));
session()->flash('flash_message', __('New follow up date is set'));
return redirect()->back();
}

Expand Down Expand Up @@ -215,7 +215,7 @@ public function updateStatus($external_id, Request $request)
$lead->fill($request->all())->save();
}
event(new \App\Events\LeadAction($lead, self::UPDATED_STATUS));
Session()->flash('flash_message', __('Lead status updated'));
session()->flash('flash_message', __('Lead status updated'));
return redirect()->back();
}

Expand Down
14 changes: 7 additions & 7 deletions app/Http/Controllers/ProjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function destroy(Project $project, Request $request)

$project->delete();

Session()->flash('flash_message', __('Project deleted'));
session()->flash('flash_message', __('Project deleted'));
return redirect()->back();
}

Expand All @@ -91,7 +91,7 @@ public function store(StoreProjectRequest $request)
}

if(!$client) {
Session()->flash('flash_message', __('Could not find client'));
session()->flash('flash_message', __('Could not find client'));
return redirect()->back();
}

Expand All @@ -110,7 +110,7 @@ public function store(StoreProjectRequest $request)

$insertedExternalId = $project->external_id;

Session()->flash('flash_message', __('Project successfully added'));
session()->flash('flash_message', __('Project successfully added'));
event(new \App\Events\ProjectAction($project, self::CREATED));

if (!is_null($request->images)) {
Expand Down Expand Up @@ -138,7 +138,7 @@ private function upload($image, $project)
$totaltsize = substr($mbsize, 0, 4);

if ($totaltsize > 15) {
Session::flash('flash_message', __('File Size cannot be bigger than 15MB'));
session()->flash('flash_message', __('File Size cannot be bigger than 15MB'));
return redirect()->back();
}

Expand Down Expand Up @@ -224,7 +224,7 @@ public function updateStatus($external_id, Request $request)
$project->fill($input)->save();

event(new \App\Events\ProjectAction($project, self::UPDATED_STATUS));
Session()->flash('flash_message', __('Task status is updated'));
session()->flash('flash_message', __('Task status is updated'));

return redirect()->back();
}
Expand All @@ -240,7 +240,7 @@ public function updateAssign($external_id, Request $request)

event(new \App\Events\ProjectAction($project, self::UPDATED_ASSIGN));

Session()->flash('flash_message', __('New user is assigned'));
session()->flash('flash_message', __('New user is assigned'));
return redirect()->back();
}

Expand All @@ -262,7 +262,7 @@ public function updateDeadline(Request $request, $external_id)
['deadline' => $request->deadline_date . " " . $request->deadline_time . ":00"];
$project->fill($input)->save();
event(new \App\Events\ProjectAction($project, self::UPDATED_DEADLINE));
Session()->flash('flash_message', __('New deadline is set'));
session()->flash('flash_message', __('New deadline is set'));
return redirect()->back();
}

Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/RolesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function store(StoreRoleRequest $request)
'display_name' => ucfirst($roleName),
'description' => $roleDescription
]);
Session()->flash('flash_message', __('Role created'));
session()->flash('flash_message', __('Role created'));
return view('roles.index');
}

Expand All @@ -118,16 +118,16 @@ public function destroy($external_id)
{
$role = Role::where('external_id', $external_id)->first();
if (!$role->users->isEmpty()) {
Session::flash('flash_message_warning', __("Can't delete role with users, please remove users"));
session()->flash('flash_message_warning', __("Can't delete role with users, please remove users"));
return redirect()->route('roles.index');
}
if ($role->name !== Role::ADMIN_ROLE && $role->name !== Role::OWNER_ROLE) {
$role->delete();
} else {
Session()->flash('flash_message_warning', __('Can not delete role'));
session()->flash('flash_message_warning', __('Can not delete role'));
return redirect()->route('roles.index');
}
Session()->flash('flash_message', __('Role deleted'));
session()->flash('flash_message', __('Role deleted'));
return redirect()->route('roles.index');
}

Expand All @@ -154,7 +154,7 @@ public function update(Request $request, $external_id)

$role->permissions()->sync($allowed_permissions);
$role->save();
Session::flash('flash_message', __('Role is updated'));
session()->flash('flash_message', __('Role is updated'));
return redirect()->back();
}
}
9 changes: 4 additions & 5 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,12 @@ public function updateOverall(UpdateSettingOverallRequest $request)
$setting = Setting::first();

if (!app(ClientNumberValidator::class)->validateClientNumber((int)$request->client_number)) {
Session::flash('flash_message_warning', __('Client number invalid'));
session()->flash('flash_message_warning', __('Client number invalid'));
return redirect()->back();
}


if (!app(InvoiceNumberValidator::class)->validateInvoiceNumber((int)$request->invoice_number)) {
Session::flash('flash_message_warning', __('Invoice number invalid'));
session()->flash('flash_message_warning', __('Invoice number invalid'));
return redirect()->back();
}
if ($request->currency == $setting->currency && !empty($request->vat)) {
Expand Down Expand Up @@ -157,14 +156,14 @@ public function updateOverall(UpdateSettingOverallRequest $request)

$setting->client_number = $request->client_number;
$setting->invoice_number = $request->invoice_number;
isset($request->company) ? $setting->company = $request->company: null;
isset($request->company) ? $setting->company = $request->company : null;
$setting->country = $request->country;
$setting->language = $request->language;
$setting->save();

cache()->delete(GetDateFormat::CACHE_KEY);

Session::flash('flash_message', __('Overall settings successfully updated'));
session()->flash('flash_message', __('Overall settings successfully updated'));
return redirect()->back();
}

Expand Down
Loading