Skip to content
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fleetbase/fleetops-api",
"version": "0.6.32",
"version": "0.6.33",
"description": "Fleet & Transport Management Extension for Fleetbase",
"keywords": [
"fleetbase-extension",
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Fleet-Ops",
"version": "0.6.32",
"version": "0.6.33",
"description": "Fleet & Transport Management Extension for Fleetbase",
"repository": "https://github.com/fleetbase/fleetops",
"license": "AGPL-3.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/fleetops-engine",
"version": "0.6.32",
"version": "0.6.33",
"description": "Fleet & Transport Management Extension for Fleetbase",
"fleetbase": {
"route": "fleet-ops"
Expand Down
98 changes: 98 additions & 0 deletions server/src/Console/Commands/TestEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

namespace Fleetbase\FleetOps\Console\Commands;

use Fleetbase\FleetOps\Mail\CustomerCredentialsMail;
use Fleetbase\FleetOps\Models\Contact;
use Fleetbase\Models\Company;
use Fleetbase\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;

class TestEmail extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fleetops:test-email {email} {--type=customer_credentials : The type of email to test}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Test FleetOps email templates';

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$email = $this->argument('email');
$type = $this->option('type');

$this->info('Sending test email...');
$this->info("Type: {$type}");
$this->info("To: {$email}");

try {
switch ($type) {
case 'customer_credentials':
$this->sendCustomerCredentialsEmail($email);
break;

default:
$this->error("Unknown email type: {$type}");
return Command::FAILURE;
}

$this->info('✓ Test email sent successfully!');
return Command::SUCCESS;
} catch (\Exception $e) {
$this->error('Failed to send test email: ' . $e->getMessage());
return Command::FAILURE;
}
}

/**
* Send a test customer credentials email.
*
* @param string $email
* @return void
*/
private function sendCustomerCredentialsEmail(string $email): void
{
// Create a mock user
$user = new User([
'name' => 'Test Customer',
'email' => $email,
]);

// Create a mock company
$company = new Company([
'name' => 'Test Company',
'public_id' => 'test_company_123',
]);

// Create a mock customer
$customer = new Contact([
'name' => 'Test Customer',
'email' => $email,
'phone' => '+1234567890',
]);

// Set relations
$customer->setRelation('company', $company);
$customer->setRelation('user', $user);

// Mock password
$plaintextPassword = 'TestPassword123!';

// Send the email
Mail::to($email)->send(new CustomerCredentialsMail($plaintextPassword, $customer));
}
}
3 changes: 3 additions & 0 deletions server/src/Http/Controllers/Api/v1/DriverController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public function create(CreateDriverRequest $request)
// Apply user infos
$userDetails = User::applyUserInfoFromRequest($request, $userDetails);

// Set company_uuid before creating user
$userDetails['company_uuid'] = $company->uuid;

// create user account for driver
$user = User::create($userDetails);

Expand Down
11 changes: 3 additions & 8 deletions server/src/Http/Controllers/Api/v1/VehicleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ public function create(CreateVehicleRequest $request)
{
// get request input
$input = $request->only(['status', 'make', 'model', 'year', 'trim', 'type', 'plate_number', 'vin', 'meta', 'online', 'location', 'altitude', 'heading', 'speed']);

// make sure company is set
$input['company_uuid'] = session('company');

// create instance of vehicle model
$vehicle = new Vehicle();

// set default online
if (!isset($input['online'])) {
$input['online'] = 0;
Expand All @@ -51,11 +49,8 @@ public function create(CreateVehicleRequest $request)
$input['location'] = Utils::getPointFromCoordinates($request->only(['latitude', 'longitude']));
}

// apply user input to vehicle
$vehicle = $vehicle->fill($input);

// save the vehicle
$vehicle->save();
// create the vehicle (fires 'created' event for billing resource tracking)
$vehicle = Vehicle::create($input);

// driver assignment
if ($request->has('driver')) {
Expand Down
32 changes: 31 additions & 1 deletion server/src/Http/Controllers/Internal/v1/DriverController.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,37 @@ function (&$request, &$input) {

if ($input->has('user_uuid')) {
$user = User::where('uuid', $input->get('user_uuid'))->first();
if ($user && $input->has('photo_uuid')) {

// If user doesn't exist with provided UUID, create new user
if (!$user) {
$userInput = $input
->only(['name', 'password', 'email', 'phone', 'status', 'avatar_uuid'])
->filter()
->toArray();

// handle `photo_uuid`
if (isset($input['photo_uuid']) && Str::isUuid($input['photo_uuid'])) {
$userInput['avatar_uuid'] = $input['photo_uuid'];
}

// Make sure password is set
if (empty($userInput['password'])) {
$userInput['password'] = Str::random(14);
}

// Set user company
$userInput['company_uuid'] = session('company', $company->uuid);

// Apply user infos
$userInput = User::applyUserInfoFromRequest($request, $userInput);

// Create user account
$user = User::create($userInput);

// Set the user type to driver
$user->setType('driver');
} elseif ($input->has('photo_uuid')) {
// Update existing user's avatar if photo provided
$user->update(['avatar_uuid' => $input->get('photo_uuid')]);
}
} else {
Expand Down
32 changes: 0 additions & 32 deletions server/src/Http/Controllers/Internal/v1/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@
use Fleetbase\FleetOps\Support\Utils;
use Fleetbase\Http\Requests\ExportRequest;
use Fleetbase\Http\Requests\Internal\BulkActionRequest;
use Fleetbase\Http\Requests\Internal\BulkDeleteRequest;
use Fleetbase\Models\File;
use Fleetbase\Models\Type;
use Fleetbase\Support\TemplateString;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
Expand Down Expand Up @@ -330,36 +328,6 @@ public function importFromFiles(Request $request)
);
}

/**
* Updates a order to canceled and updates order activity.
*
* @return \Illuminate\Http\Response
*/
public function bulkDelete(BulkDeleteRequest $request)
{
$ids = $request->input('ids', []);

if (!$ids) {
return response()->error('Nothing to delete.');
}

/** @var Order */
$count = Order::whereIn('uuid', $ids)->count();
$deleted = Order::whereIn('uuid', $ids)->delete();

if (!$deleted) {
return response()->error('Failed to bulk delete orders.');
}

return response()->json(
[
'status' => 'OK',
'message' => 'Deleted ' . $count . ' orders',
'count' => $count,
]
);
}

/**
* Updates a order to canceled and updates order activity.
*
Expand Down
33 changes: 0 additions & 33 deletions server/src/Http/Controllers/Internal/v1/PlaceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Fleetbase\FleetOps\Support\Geocoding;
use Fleetbase\Http\Requests\ExportRequest;
use Fleetbase\Http\Requests\ImportRequest;
use Fleetbase\Http\Requests\Internal\BulkDeleteRequest;
use Fleetbase\LaravelMysqlSpatial\Types\Point;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -150,38 +149,6 @@ public function export(ExportRequest $request)
return Excel::download(new PlaceExport($selections), $fileName);
}

/**
* Bulk deletes resources.
*
* @return \Illuminate\Http\Response
*/
public function bulkDelete(BulkDeleteRequest $request)
{
$ids = $request->input('ids', []);

if (!$ids) {
return response()->error('Nothing to delete.');
}

/**
* @var \Fleetbase\Models\Place
*/
$count = Place::whereIn('uuid', $ids)->applyDirectivesForPermissions('fleet-ops list place')->count();
$deleted = Place::whereIn('uuid', $ids)->applyDirectivesForPermissions('fleet-ops list place')->delete();

if (!$deleted) {
return response()->error('Failed to bulk delete places.');
}

return response()->json(
[
'status' => 'OK',
'message' => 'Deleted ' . $count . ' places',
],
200
);
}

/**
* Get all avatar options for an vehicle.
*
Expand Down
31 changes: 0 additions & 31 deletions server/src/Http/Controllers/Internal/v1/VendorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Fleetbase\FleetOps\Models\Vendor;
use Fleetbase\Http\Requests\ExportRequest;
use Fleetbase\Http\Requests\ImportRequest;
use Fleetbase\Http\Requests\Internal\BulkDeleteRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -85,36 +84,6 @@ public static function export(ExportRequest $request)
return Excel::download(new VendorExport($selections), $fileName);
}

/**
* Bulk delete resources.
*
* @return \Illuminate\Http\Response
*/
public function bulkDelete(BulkDeleteRequest $request)
{
$ids = $request->input('ids', []);

if (!$ids) {
return response()->error('Nothing to delete.');
}

/** @var \Fleetbase\Models\Vendor */
$count = Vendor::whereIn('uuid', $ids)->count();
$deleted = Vendor::whereIn('uuid', $ids)->delete();

if (!$deleted) {
return response()->error('Failed to bulk delete vendors.');
}

return response()->json(
[
'status' => 'OK',
'message' => 'Deleted ' . $count . ' vendors',
],
200
);
}

/**
* Get all status options for an vehicle.
*
Expand Down
4 changes: 2 additions & 2 deletions server/src/Http/Requests/CreateServiceRateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function rules()
'base_fee' => ['numeric'],
'per_meter_unit' => ['required_if:rate_calculation_method,per_meter', 'string', 'in:km,m'],
'per_meter_flat_rate_fee' => ['required_if:rate_calculation_method,per_meter', 'numeric'],
'meter_fees' => [Rule::requiredIf(function ($input) {
return in_array($input->rate_calculation_method, ['fixed_meter', 'fixed_rate']);
'meter_fees' => [Rule::requiredIf(function () {
return in_array($this->input('rate_calculation_method'), ['fixed_meter', 'fixed_rate']);
}), 'array'],
'meter_fees.*.distance' => ['numeric'],
'meter_fees.*.fee' => ['numeric'],
Expand Down
Loading
Loading