diff --git a/app/Events/Design/DesignWasArchived.php b/app/Events/Design/DesignWasArchived.php new file mode 100644 index 000000000000..c41303db150d --- /dev/null +++ b/app/Events/Design/DesignWasArchived.php @@ -0,0 +1,54 @@ +design = $design; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } +} diff --git a/app/Events/Design/DesignWasCreated.php b/app/Events/Design/DesignWasCreated.php new file mode 100644 index 000000000000..b44e8fcd90a2 --- /dev/null +++ b/app/Events/Design/DesignWasCreated.php @@ -0,0 +1,48 @@ +design = $design; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } +} diff --git a/app/Events/Design/DesignWasDeleted.php b/app/Events/Design/DesignWasDeleted.php new file mode 100644 index 000000000000..653a40f47836 --- /dev/null +++ b/app/Events/Design/DesignWasDeleted.php @@ -0,0 +1,49 @@ +design = $design; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } +} +} diff --git a/app/Events/Design/DesignWasRestored.php b/app/Events/Design/DesignWasRestored.php new file mode 100644 index 000000000000..1b71ecf93233 --- /dev/null +++ b/app/Events/Design/DesignWasRestored.php @@ -0,0 +1,48 @@ +design = $design; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } +} diff --git a/app/Events/Design/DesignWasUpdated.php b/app/Events/Design/DesignWasUpdated.php new file mode 100644 index 000000000000..f90d8c76b4e3 --- /dev/null +++ b/app/Events/Design/DesignWasUpdated.php @@ -0,0 +1,49 @@ +design = $design; + } + + /** + * Get the channels the event should broadcast on. + * + * @return \Illuminate\Broadcasting\Channel|array + */ + public function broadcastOn() + { + return new PrivateChannel('channel-name'); + } +} +} diff --git a/app/Http/Controllers/DesignController.php b/app/Http/Controllers/DesignController.php index f39047e2f1f1..77c465b19eb5 100644 --- a/app/Http/Controllers/DesignController.php +++ b/app/Http/Controllers/DesignController.php @@ -21,6 +21,7 @@ use App\Http\Requests\Design\StoreDesignRequest; use App\Http\Requests\Design\UpdateDesignRequest; use App\Jobs\Entity\ActionEntity; use App\Models\Design; +use App\Repositories\DesignRepository; use App\Transformers\DesignTransformer; use App\Utils\Traits\BulkOptions; use App\Utils\Traits\MakesHash; @@ -40,14 +41,17 @@ class DesignController extends BaseController protected $entity_transformer = DesignTransformer::class; + protected $design_repo; /** * DesignController constructor. * @param DesignRepository $designRepo */ - public function __construct() + public function __construct(DesignRepository $design_repo) { parent::__construct(); + + $this->design_repo = $design_repo; } /** @@ -480,7 +484,7 @@ class DesignController extends BaseController $designs->each(function ($design, $key) use ($action) { if (auth()->user()->can('edit', $design)) { - //$this->design_repo->{$action}($design);@todo + $this->design_repo->{$action}($design);@todo } }); diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 85bc5e3ec942..f2b657e4ea42 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -11,10 +11,18 @@ namespace App\Providers; +use App\Events\Client\ClientWasArchived; use App\Events\Client\ClientWasCreated; +use App\Events\Client\ClientWasDeleted; +use App\Events\Client\ClientWasRestored; +use App\Events\Client\ClientWasUpdated; +use App\Events\Client\DesignWasDeleted; +use App\Events\Client\DesignWasRestored; +use App\Events\Client\DesignWasUpdated; use App\Events\Company\CompanyWasDeleted; use App\Events\Contact\ContactLoggedIn; use App\Events\Credit\CreditWasMarkedSent; +use App\Events\Design\DesignWasArchived; use App\Events\Invoice\InvoiceWasCancelled; use App\Events\Invoice\InvoiceWasCreated; use App\Events\Invoice\InvoiceWasDeleted; @@ -78,11 +86,6 @@ class EventServiceProvider extends ServiceProvider ContactLoggedIn::class => [ UpdateContactLastLogin::class, ], - // Clients - ClientWasCreated::class => [ - CreatedClientActivity::class, - // 'App\Listeners\SubscriptionListener@createdClient', - ], PaymentWasCreated::class => [ PaymentCreatedActivity::class, PaymentNotification::class, @@ -96,24 +99,29 @@ class EventServiceProvider extends ServiceProvider PaymentWasVoided::class => [ PaymentVoidedActivity::class, ], - 'App\Events\ClientWasArchived' => [ - 'App\Listeners\ActivityListener@archivedClient', + // Clients + ClientWasCreated::class =>[ + CreatedClientActivity::class, ], - 'App\Events\ClientWasUpdated' => [ - 'App\Listeners\SubscriptionListener@updatedClient', + ClientWasArchived::class =>[ ], - 'App\Events\ClientWasDeleted' => [ - 'App\Listeners\ActivityListener@deletedClient', - 'App\Listeners\SubscriptionListener@deletedClient', - 'App\Listeners\HistoryListener@deletedClient', + ClientWasUpdated::class =>[ ], - 'App\Events\ClientWasRestored' => [ - 'App\Listeners\ActivityListener@restoredClient', + ClientWasDeleted::class =>[ + ], + ClientWasRestored::class =>[ ], - CreditWasMarkedSent::class => [ ], - + //Designs + DesignWasArchived::class => [ + ], + DesignWasUpdated::class => [ + ], + DesignWasDeleted::class => [ + ], + DesignWasRestored::class => [ + ], //Invoices InvoiceWasMarkedSent::class => [ CreateInvoiceHtmlBackup::class, diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 277b15a6b984..72286610f6bc 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -203,13 +203,14 @@ class BaseRepository $lcfirst_resource_id = lcfirst($resource) . '_id'; if ($class->name == Invoice::class || $class->name == Quote::class) { + info("class name = invoice"); $state['starting_amount'] = $model->amount; + info("starting amount = {$model->amount}"); } if (!$model->id) { $company_defaults = $client->setCompanyDefaults($data, lcfirst($resource)); $model->uses_inclusive_taxes = $client->getSetting('inclusive_taxes'); - $data = array_merge($company_defaults, $data); } @@ -281,7 +282,10 @@ class BaseRepository $model->service()->createInvitations(); } + $model = $model->calc()->getInvoice(); $state['finished_amount'] = $model->amount; + + info("finished amount = {$model->amount}"); $model = $model->service()->applyNumber()->save(); @@ -291,11 +295,11 @@ class BaseRepository if ($class->name == Invoice::class) { if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) { + info("inside ledger updating"); $model->ledger()->updateInvoiceBalance(($state['finished_amount'] - $state['starting_amount'])); + $model->client->service()->updateBalance(($state['finished_amount'] - $state['starting_amount']))->save(); } - $model = $model->calc()->getInvoice(); - event(new InvoiceWasUpdated($model, $model->company)); } diff --git a/app/Repositories/DesignRepository.php b/app/Repositories/DesignRepository.php new file mode 100644 index 000000000000..9e9070aa866f --- /dev/null +++ b/app/Repositories/DesignRepository.php @@ -0,0 +1,40 @@ + ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::post('migrate', 'MigrationController@index')->name('migrate.start'); Route::resource('designs', 'DesignController');// name = (payments. index / create / show / update / destroy / edit + Route::post('designs/bulk', 'DesignController@bulk')->name('designs.bulk'); Route::get('users', 'UserController@index'); Route::put('users/{user}', 'UserController@update')->middleware('password_protected');