several fixes

This commit is contained in:
Denis Duliçi
2021-05-14 18:29:24 +03:00
parent 7ac53681ff
commit b8057a7a12
19 changed files with 165 additions and 75 deletions

View File

@ -113,6 +113,10 @@ class Settings extends Controller
}
if ($real_key == 'default.locale') {
if (!in_array($value, config('language.allowed'))) {
continue;
}
user()->setAttribute('locale', $value)->save();
}
@ -156,10 +160,10 @@ class Settings extends Controller
Installer::updateEnv(['MAIL_FROM_NAME' => '"' . $value . '"']);
break;
case 'company.email':
Installer::updateEnv(['MAIL_FROM_ADDRESS' => $value]);
Installer::updateEnv(['MAIL_FROM_ADDRESS' => '"' . $value . '"']);
break;
case 'default.locale':
Installer::updateEnv(['APP_LOCALE' => $value]);
Installer::updateEnv(['APP_LOCALE' => '"' . $value . '"']);
break;
case 'schedule.time':
Installer::updateEnv(['APP_SCHEDULE_TIME' => '"' . $value . '"']);

View File

@ -14,7 +14,7 @@ class Kernel extends HttpKernel
* @var array
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,

View File

@ -43,6 +43,10 @@ class Money
$money_format = $request->get($parameter);
if (!preg_match("/^(?=.*?[0-9])[0-9.,]+$/", $money_format)) {
continue;
}
if ($parameter == 'sale_price' || $parameter == 'purchase_price') {
$money_format = Str::replaceFirst(',', '.', $money_format);
}
@ -62,6 +66,10 @@ class Money
continue;
}
if (!preg_match("/^(?=.*?[0-9])[0-9.,]+$/", $item['price'])) {
continue;
}
$amount = $item['price'];
if (strpos($item['price'], config('money.' . $currency_code . '.symbol')) !== false) {

View File

@ -26,8 +26,8 @@ class User extends FormRequest
{
$picture = 'nullable';
if ($this->request->get('picture', null)) {
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
if ($this->files->get('picture')) {
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
}
$email = 'required|email';

View File

@ -26,7 +26,7 @@ class Transaction extends FormRequest
{
$attachment = 'nullable';
if ($this->request->get('attachment', null)) {
if ($this->files->get('attachment')) {
$attachment = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
}

View File

@ -25,8 +25,8 @@ class Company extends FormRequest
{
$logo = 'nullable';
if ($this->request->get('logo', null)) {
$logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
if ($this->files->get('logo')) {
$logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
}
return [

View File

@ -25,6 +25,7 @@ class Contact extends FormRequest
{
$email = '';
$required = '';
$logo = 'nullable';
$type = $this->request->get('type', 'customer');
$company_id = $this->request->get('company_id');
@ -54,6 +55,10 @@ class Contact extends FormRequest
}
}
if ($this->files->get('logo')) {
$logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
}
return [
'type' => 'required|string',
'name' => 'required|string',
@ -62,6 +67,7 @@ class Contact extends FormRequest
'currency_code' => 'required|string|currency',
'password' => $required . 'confirmed',
'enabled' => 'integer|boolean',
'logo' => $logo,
];
}
}

View File

@ -25,14 +25,14 @@ class Item extends FormRequest
{
$picture = 'nullable';
if ($this->request->get('picture', null)) {
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
if ($this->files->get('picture')) {
$picture = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
}
return [
'name' => 'required|string',
'sale_price' => 'required',
'purchase_price' => 'required',
'sale_price' => 'required|regex:/^(?=.*?[0-9])[0-9.,]+$/',
'purchase_price' => 'required|regex:/^(?=.*?[0-9])[0-9.,]+$/',
'tax_ids' => 'nullable|array',
'category_id' => 'nullable|integer',
'enabled' => 'integer|boolean',

View File

@ -26,6 +26,9 @@ class Document extends FormRequest
*/
public function rules()
{
$company_logo = 'nullable';
$attachment = 'nullable';
$type = $this->request->get('type', Model::INVOICE_TYPE);
$type = config('type.' . $type . '.route.parameter');
@ -39,15 +42,11 @@ class Document extends FormRequest
$id = null;
}
$company_logo = 'nullable';
if ($this->request->get('company_logo', null)) {
$company_logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
if ($this->files->get('company_logo')) {
$company_logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
}
$attachment = 'nullable';
if ($this->request->get('attachment', null)) {
if ($this->files->get('attachment')) {
$attachment = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024;
}

View File

@ -30,7 +30,7 @@ class Setting extends FormRequest
if ($this->request->get('_prefix', null) == 'company') {
$name = 'required|string';
$email = 'required|email';
$logo = 'mimes:' . config('filesystems.mimes', 'pdf,jpeg,jpg,png');
$logo = 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000';
}
return [

View File

@ -39,7 +39,7 @@ class Company extends FormRequest
public function rules()
{
$rules = [
'company_logo' => 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024,
'company_logo' => 'mimes:' . config('filesystems.mimes') . '|between:0,' . config('filesystems.max_size') * 1024 . '|dimensions:max_width=1000,max_height=1000',
];
if (!setting('apps.api_key', false) && !empty($this->request->get('api_key'))) {

View File

@ -52,7 +52,15 @@ class CreateUser extends Job
}
if ($this->request->has('companies')) {
$this->user->companies()->attach($this->request->get('companies'));
$user = user();
$companies = $user->withoutEvents(function () use ($user) {
return $user->companies()->whereIn('id', $this->request->get('companies'))->pluck('id');
});
if ($companies->isNotEmpty()) {
$this->user->companies()->attach($companies->toArray());
}
}
if (empty($this->user->companies)) {

View File

@ -53,7 +53,15 @@ class UpdateUser extends Job
}
if ($this->request->has('companies')) {
$this->user->companies()->sync($this->request->get('companies'));
$user = user();
$companies = $user->withoutEvents(function () use ($user) {
return $user->companies()->whereIn('id', $this->request->get('companies'))->pluck('id');
});
if ($companies->isNotEmpty()) {
$this->user->companies()->sync($companies->toArray());
}
}
if ($this->user->contact) {

View File

@ -8,6 +8,7 @@ use App\Models\Common\Company;
use App\Models\Common\Media;
use App\Utilities\Date;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
@ -29,11 +30,22 @@ class Version2112 extends Listener
return;
}
Artisan::call('migrate', ['--force' => true]);
$this->updateDatabase();
$this->updateCompanies();
}
public function updateDatabase()
{
DB::table('migrations')->insert([
'id' => DB::table('migrations')->max('id') + 1,
'migration' => '2016_06_27_000001_create_mediable_test_tables',
'batch' => DB::table('migrations')->max('batch') + 1,
]);
Artisan::call('migrate', ['--force' => true]);
}
public function updateCompanies()
{
$companies = Company::withTrashed()->cursor();

View File

@ -46,6 +46,10 @@ class Validation extends Provider
$status = true;
}
if (!preg_match("/^(?=.*?[0-9])[0-9.,]+$/", $value)) {
$status = false;
}
$amount = $value;
return $status;

View File

@ -112,44 +112,20 @@ trait Uploads
return Storage::path($path);
}
public function streamMedia($media, $path = '', $action = '')
{
if ($this->isLocalStorage()) {
if (empty($path)) {
$path = $this->getMediaPathOnStorage($media);
}
if (empty($action)) {
$action = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
}
return $this->streamLocalMedia($path, $action);
}
return $this->streamRemoteMedia($media);
}
public function streamLocalMedia($path, $action)
{
$function = ($action == 'get') ? 'file' : $action;
return response()->$function($path);
}
public function streamRemoteMedia($media)
public function streamMedia($media, $path = '')
{
return response()->streamDownload(
function() use ($media) {
$stream = $media->stream();
while($bytes = $stream->read(1024)) {
while ($bytes = $stream->read(1024)) {
echo $bytes;
}
},
$media->basename,
[
'Content-Type' => $media->mime_type,
'Content-Length' => $media->size,
'Content-Type' => $media->mime_type,
'Content-Length' => $media->size,
],
);
}