Upload company logo to client settings

This commit is contained in:
David Bomba 2019-10-07 22:05:06 +11:00
parent 2a7f62b579
commit b8515e26b0
9 changed files with 29 additions and 7 deletions

View File

@ -23,6 +23,7 @@ use App\Http\Requests\Client\UpdateClientRequest;
use App\Jobs\Client\StoreClient; use App\Jobs\Client\StoreClient;
use App\Jobs\Client\UpdateClient; use App\Jobs\Client\UpdateClient;
use App\Jobs\Entity\ActionEntity; use App\Jobs\Entity\ActionEntity;
use App\Jobs\Util\UploadAvatar;
use App\Models\Client; use App\Models\Client;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\Models\Country; use App\Models\Country;
@ -282,6 +283,22 @@ class ClientController extends BaseController
$client = $this->client_repo->save($request->all(), $client); $client = $this->client_repo->save($request->all(), $client);
if($request->file('company_logo'))
{
\Log::error('settings logo present');
$path = UploadAvatar::dispatchNow($request->file('company_logo'), $client->company->company_key);
if($path){
$settings = $client->settings;
$settings->company_logo_url = $client->company->domain . $path;
$client->settings = $settings;
$client->save();
}
}
return $this->itemResponse($client); return $this->itemResponse($client);
} }

View File

@ -213,7 +213,7 @@ class CompanyController extends BaseController
if($path){ if($path){
$settings = $company->settings; $settings = $company->settings;
$settings->logo_url = config('ninja.site_url').$path; $settings->company_logo_url = $company->domain . $path;
$company->settings = $settings; $company->settings = $settings;
$company->save(); $company->save();
} }
@ -428,7 +428,7 @@ class CompanyController extends BaseController
if($path){ if($path){
$settings = $company->settings; $settings = $company->settings;
$settings->logo_url = config('ninja.site_url').$path; $settings->company_logo_url = $company->domain . $path;
$company->settings = $settings; $company->settings = $settings;
$company->save(); $company->save();
} }

View File

@ -354,7 +354,7 @@ class GroupSettingController extends BaseController
$group_setting = $this->group_setting_repo->save($request->all(), $group_setting); $group_setting = $this->group_setting_repo->save($request->all(), $group_setting);
return $this->itemResponse($group_setting); return $this->itemResponse($group_setting);
} }

View File

@ -8,6 +8,7 @@
* @OA\Property(property="datetime_format_id", type="string", example="15", description="____________"), * @OA\Property(property="datetime_format_id", type="string", example="15", description="____________"),
* @OA\Property(property="financial_year_start", type="string", example="2000-01-01", description="____________"), * @OA\Property(property="financial_year_start", type="string", example="2000-01-01", description="____________"),
* @OA\Property(property="language_id", type="string", example="1", description="____________"), * @OA\Property(property="language_id", type="string", example="1", description="____________"),
* @OA\Property(property="company_logo_url", type="string", example="https://example.com/logo.png", description="The URL to the company Logo"),
* @OA\Property(property="custom_label1", type="string", example="Custom Label", description="____________"), * @OA\Property(property="custom_label1", type="string", example="Custom Label", description="____________"),
* @OA\Property(property="custom_label2", type="string", example="Custom Label", description="____________"), * @OA\Property(property="custom_label2", type="string", example="Custom Label", description="____________"),
* @OA\Property(property="custom_label3", type="string", example="Custom Label", description="____________"), * @OA\Property(property="custom_label3", type="string", example="Custom Label", description="____________"),
@ -52,4 +53,5 @@
* @OA\Property(property="default_gateway", type="integer", example="1", description="The default payment gateway"), * @OA\Property(property="default_gateway", type="integer", example="1", description="The default payment gateway"),
* @OA\Property(property="reset_counter_date", type="string", example="2019-01-01", description="The explicit date which is used to reset counters"), * @OA\Property(property="reset_counter_date", type="string", example="2019-01-01", description="The explicit date which is used to reset counters"),
* ) * )
*/ */
*

View File

@ -33,6 +33,8 @@ class UpdateClientRequest extends Request
/* Ensure we have a client name, and that all emails are unique*/ /* Ensure we have a client name, and that all emails are unique*/
$rules['name'] = 'required'; $rules['name'] = 'required';
$rules['company_logo'] = 'mimes:jpeg,jpg,png,gif|max:10000';
$rules['industry_id'] = 'integer|nullable'; $rules['industry_id'] = 'integer|nullable';
$rules['size_id'] = 'integer|nullable'; $rules['size_id'] = 'integer|nullable';
$rules['currency_id'] = 'integer|nullable'; $rules['currency_id'] = 'integer|nullable';

View File

@ -59,6 +59,7 @@ class CreateCompany
$company->ip = request()->ip(); $company->ip = request()->ip();
$company->settings = $settings; $company->settings = $settings;
$company->db = config('database.default'); $company->db = config('database.default');
$company->domain = isset($this->request['domain']) ? $this->request['domain'] : config('ninja.site_url');
$company->save(); $company->save();

View File

@ -189,7 +189,7 @@ class Company extends BaseModel
public function getLogo() public function getLogo()
{ {
return $this->settings->logo_url ?: null; return $this->settings->company_logo_url ?: null;
} }
/** /**

View File

@ -24,7 +24,7 @@ class ClientModelTest extends TestCase
$this->makeTestData(); $this->makeTestData();
if(config('ninja.testvars.travis') === false) if(config('ninja.testvars.travis') !== false)
$this->markTestSkipped('Skip test for Travis'); $this->markTestSkipped('Skip test for Travis');
} }

View File

@ -61,7 +61,7 @@ class UploadLogoTest extends TestCase
$response->assertStatus(200); $response->assertStatus(200);
$acc = $response->json(); $acc = $response->json();
$logo = $acc['data']['settings']['logo_url']; $logo = $acc['data']['settings']['company_logo_url'];
$logo_file = Storage::url($logo); $logo_file = Storage::url($logo);