Skip to content

Commit

Permalink
Document edit company logo issue solved..
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Feb 15, 2021
1 parent fc6ed02 commit 6251d09
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/Jobs/Document/UpdateDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function handle()
$this->dispatch(new CreateDocumentItemsAndTotals($this->document, $this->request));

$this->document->paid_amount = $this->document->paid;

event(new PaidAmountCalculated($this->document));

if ($this->document->paid_amount > 0) {
Expand Down
36 changes: 35 additions & 1 deletion app/Listeners/Document/SettingFieldCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
namespace App\Listeners\Document;

use App\Events\Document\DocumentCreated as Event;
use App\Models\Common\Company;
use App\Traits\Documents;
use App\Traits\Uploads;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

class SettingFieldCreated
{
use Documents;
use Documents, Uploads;

/**
* Handle the event.
Expand All @@ -18,6 +22,7 @@ class SettingFieldCreated
public function handle(Event $event)
{
$request = $event->request;
$document = $event->document;

if (!$request->has('setting')) {
return;
Expand All @@ -28,6 +33,10 @@ public function handle(Event $event)

foreach ($fields as $key => $value) {
if ($key == 'company_logo') {
if (Arr::has($value, 'dropzone')) {
continue;
}

setting()->set('company.logo', $value);

continue;
Expand All @@ -38,6 +47,31 @@ public function handle(Event $event)
setting()->set($real_key, $value);
}

$files = $request->file('setting', []);

if ($files) {
$company = Company::find($document->company_id);

foreach ($files as $key => $value) {
// Upload attachment
$media = $this->getMedia($value, 'settings');

$company->attachMedia($media, Str::snake($real_key));

$value = $media->id;

if ($key == 'company_logo') {
setting()->set('company.logo', $value);

continue;
}

$real_key = $type . '.' . $key;

setting()->set($real_key, $value);
}
}

// Save all settings
setting()->save();
}
Expand Down
36 changes: 35 additions & 1 deletion app/Listeners/Document/SettingFieldUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
namespace App\Listeners\Document;

use App\Events\Document\DocumentUpdated as Event;
use App\Models\Common\Company;
use App\Traits\Uploads;
use App\Traits\Documents;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

class SettingFieldUpdated
{
use Documents;
use Documents, Uploads;

/**
* Handle the event.
Expand All @@ -18,6 +22,7 @@ class SettingFieldUpdated
public function handle(Event $event)
{
$request = $event->request;
$document = $event->document;

if (!$request->has('setting')) {
return;
Expand All @@ -28,6 +33,10 @@ public function handle(Event $event)

foreach ($fields as $key => $value) {
if ($key == 'company_logo') {
if (Arr::has($value, 'dropzone')) {
continue;
}

setting()->set('company.logo', $value);

continue;
Expand All @@ -38,6 +47,31 @@ public function handle(Event $event)
setting()->set($real_key, $value);
}

$files = $request->file('setting', []);

if ($files) {
$company = Company::find($document->company_id);

foreach ($files as $key => $value) {
// Upload attachment
$media = $this->getMedia($value, 'settings');

$company->attachMedia($media, Str::snake($real_key));

$value = $media->id;

if ($key == 'company_logo') {
setting()->set('company.logo', $value);

continue;
}

$real_key = $type . '.' . $key;

setting()->set($real_key, $value);
}
}

// Save all settings
setting()->save();
}
Expand Down

0 comments on commit 6251d09

Please sign in to comment.