1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Design repository

This commit is contained in:
David Bomba 2020-06-22 08:34:02 +10:00
parent dbff1ab6ab
commit 6b7db63e66
10 changed files with 327 additions and 22 deletions

View File

@ -0,0 +1,54 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Design;
use App\Models\Design;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
/**
* Class DesignWasArchived.
*/
class DesignWasArchived
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* @var Design
*/
public $design;
/**
* Create a new event instance.
*
* @param Design $design
*/
public function __construct(Design $design)
{
$this->design = $design;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Client;
use App\Models\Client;
use Illuminate\Queue\SerializesModels;
/**
* Class DesignWasCreated.
*/
class DesignWasCreated
{
use SerializesModels;
/**
* @var Design
*/
public $design;
/**
* Create a new event instance.
*
* @param Design $design
*/
public function __construct(Design $design)
{
$this->design = $design;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Client;
use App\Models\Client;
use Illuminate\Queue\SerializesModels;
/**
* Class DesignWasDeleted.
*/
class DesignWasDeleted
{
use SerializesModels;
/**
* @var Design
*/
public $design;
/**
* Create a new event instance.
*
* @param Design $design
*/
public function __construct(Design $design)
{
$this->design = $design;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Client;
use App\Models\Client;
use Illuminate\Queue\SerializesModels;
/**
* Class DesignWasRestored.
*/
class DesignWasRestored
{
use SerializesModels;
/**
* @var Design
*/
public $design;
/**
* Create a new event instance.
*
* @param Design $design
*/
public function __construct(Design $design)
{
$this->design = $design;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Events\Client;
use App\Models\Client;
use Illuminate\Queue\SerializesModels;
/**
* Class DesignWasUpdated.
*/
class DesignWasUpdated
{
use SerializesModels;
/**
* @var Design
*/
public $design;
/**
* Create a new event instance.
*
* @param Design $design
*/
public function __construct(Design $design)
{
$this->design = $design;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}
}

View File

@ -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
}
});

View File

@ -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,

View File

@ -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));
}

View File

@ -0,0 +1,40 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Repositories;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Backup;
use App\Models\Client;
use App\Models\Design;
use App\Models\Invoice;
use App\Models\User;
use App\Utils\Traits\MakesInvoiceHtml;
use Illuminate\Support\Facades\Log;
/**
* Class for activity repository.
*/
class DesignRepository extends BaseRepository
{
use MakesInvoiceHtml;
/**
* Gets the class name.
*
* @return string The class name.
*/
public function getClassName()
{
return Design::class;
}
}

View File

@ -84,6 +84,7 @@ Route::group(['middleware' => ['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');