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

Currency Separator #103

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Controllers\V1\Admin\Settings;

use App\Http\Controllers\Controller;
use App\Models\CompanySetting;
use App\Models\Currency;
use Illuminate\Http\Request;

class GetCompanyCurrencyController extends Controller
{
/**
* Handle the incoming request.
*
* @return \Illuminate\Http\Response
*/
public function __invoke(Request $request)
{
$currency_id = CompanySetting::getSetting('currency', $request->header('company'));

$currency = Currency::find($currency_id);

return response()->json($currency);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Requests\UpdateSettingsRequest;
use App\Models\Company;
use App\Models\CompanySetting;
use App\Models\Currency;
use Illuminate\Support\Arr;

class UpdateCompanySettingsController extends Controller
Expand Down Expand Up @@ -36,6 +37,14 @@ public function __invoke(UpdateSettingsRequest $request)

CompanySetting::setSettings($data, $request->header('company'));

if (isset($data['currency_thousand_separator']) && isset($data['currency_decimal_separator'])) {
$currency = Currency::findOrFail($data['currency']);
$currency->update([
'thousand_separator' => $data['currency_thousand_separator'],
'decimal_separator' => $data['currency_decimal_separator'],
]);
}

return response()->json([
'success' => true,
]);
Expand Down
16 changes: 15 additions & 1 deletion resources/scripts/admin/stores/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ export const useCompanyStore = (useWindow = false) => {
})
},

fetchCompanyCurrency() {
return new Promise((resolve, reject) => {
axios
.get('/api/v1/company/currency')
.then((response) => {
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},

updateCompany(data) {
return new Promise((resolve, reject) => {
axios
Expand Down Expand Up @@ -157,7 +171,7 @@ export const useCompanyStore = (useWindow = false) => {
message: global.t(message),
})
}

resolve(response)
})
.catch((err) => {
Expand Down
50 changes: 48 additions & 2 deletions resources/scripts/admin/views/settings/PreferencesSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@
/>
</BaseInputGroup>

<BaseInputGroup
:content-loading="isFetchingInitialData"
:label="$t('settings.currencies.thousand_separator')"
:error="v$.language.$error && v$.language.$errors[0].$message"
required
>
<BaseInput
:content-loading="isFetchingInitialData"
v-model="settingsForm.currency_thousand_separator"
class="w-full"
:invalid="v$.currency_thousand_separator.$error"
/>
</BaseInputGroup>

<BaseInputGroup
:content-loading="isFetchingInitialData"
:label="$t('settings.currencies.decimal_separator')"
:error="v$.language.$error && v$.language.$errors[0].$message"
required
>
<BaseInput
:content-loading="isFetchingInitialData"
v-model="settingsForm.currency_decimal_separator"
class="w-full"
:invalid="v$.currency_decimal_separator.$error"
/>
</BaseInputGroup>

<BaseInputGroup
:label="$t('settings.preferences.time_zone')"
:content-loading="isFetchingInitialData"
Expand Down Expand Up @@ -262,6 +290,12 @@ const rules = computed(() => {
currency: {
required: helpers.withMessage(t('validation.required'), required),
},
currency_thousand_separator: {
//required: helpers.withMessage(t('validation.required'), required),
},
currency_decimal_separator: {
required: helpers.withMessage(t('validation.required'), required),
},
language: {
required: helpers.withMessage(t('validation.required'), required),
},
Expand Down Expand Up @@ -293,11 +327,22 @@ async function setInitialData() {
globalStore.fetchCurrencies(),
globalStore.fetchDateFormats(),
globalStore.fetchTimeZones(),
fetchCurrencyData()
]).then(([res1]) => {
isFetchingInitialData.value = false
})
}

async function fetchCurrencyData() {
try {
const response = await companyStore.fetchCompanyCurrency()
settingsForm.currency_thousand_separator = response.data.thousand_separator
settingsForm.currency_decimal_separator = response.data.decimal_separator
} catch (error) {
console.error('Error fetching currency data:', error)
}
}

async function updatePreferencesData() {
v$.value.$touch()
if (v$.value.$invalid) {
Expand Down Expand Up @@ -327,8 +372,9 @@ async function submitData() {
data: {
settings: {
link_expiry_days: settingsForm.link_expiry_days,
automatically_expire_public_links:
settingsForm.automatically_expire_public_links,
automatically_expire_public_links: settingsForm.automatically_expire_public_links,
currency_thousand_separator: settingsForm.currency.thousand_separator,
currency_decimal_separator: settingsForm.currency.decimal_separator,
},
},
message: 'settings.preferences.updated_message',
Expand Down
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
use App\Http\Controllers\V1\Admin\Settings\CompanyController;
use App\Http\Controllers\V1\Admin\Settings\CompanyCurrencyCheckTransactionsController;
use App\Http\Controllers\V1\Admin\Settings\DiskController;
use App\Http\Controllers\V1\Admin\Settings\GetCompanyCurrencyController;
use App\Http\Controllers\V1\Admin\Settings\GetCompanyMailConfigurationController;
use App\Http\Controllers\V1\Admin\Settings\GetCompanySettingsController;
use App\Http\Controllers\V1\Admin\Settings\GetSettingsController;
Expand Down Expand Up @@ -372,6 +373,8 @@

Route::get('/company/settings', GetCompanySettingsController::class);

Route::get('/company/currency', GetCompanyCurrencyController::class);

Route::post('/company/settings', UpdateCompanySettingsController::class);

Route::get('/settings', GetSettingsController::class);
Expand Down
Loading