mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Purchase Order Events
This commit is contained in:
parent
1f7f58c693
commit
76bd11facb
47
app/Events/PurchaseOrder/PurchaseOrderWasArchived.php
Normal file
47
app/Events/PurchaseOrder/PurchaseOrderWasArchived.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Events\PurchaseOrder;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\PurchaseOrder;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class PurchaseOrderWasArchived.
|
||||
*/
|
||||
class PurchaseOrderWasArchived
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var PurchaseOrder
|
||||
*/
|
||||
public $purchase_order;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(PurchaseOrder $purchase_order, Company $company, array $event_vars)
|
||||
{
|
||||
$this->purchase_order = $purchase_order;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
}
|
47
app/Events/PurchaseOrder/PurchaseOrderWasCreated.php
Normal file
47
app/Events/PurchaseOrder/PurchaseOrderWasCreated.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Events\PurchaseOrder;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\PurchaseOrder;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class PurchaseOrderWasCreated.
|
||||
*/
|
||||
class PurchaseOrderWasCreated
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var PurchaseOrder
|
||||
*/
|
||||
public $purchase_order;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(PurchaseOrder $purchase_order, Company $company, array $event_vars)
|
||||
{
|
||||
$this->purchase_order = $purchase_order;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
}
|
47
app/Events/PurchaseOrder/PurchaseOrderWasDeleted.php
Normal file
47
app/Events/PurchaseOrder/PurchaseOrderWasDeleted.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Events\PurchaseOrder;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\PurchaseOrder;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class PurchaseOrderWasDeleted.
|
||||
*/
|
||||
class PurchaseOrderWasDeleted
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var PurchaseOrder
|
||||
*/
|
||||
public $purchase_order;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(PurchaseOrder $purchase_order, Company $company, array $event_vars)
|
||||
{
|
||||
$this->purchase_order = $purchase_order;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
}
|
47
app/Events/PurchaseOrder/PurchaseOrderWasEmailed.php
Normal file
47
app/Events/PurchaseOrder/PurchaseOrderWasEmailed.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Events\PurchaseOrder;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\PurchaseOrder;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class PurchaseOrderWasEmailed.
|
||||
*/
|
||||
class PurchaseOrderWasEmailed
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var PurchaseOrder
|
||||
*/
|
||||
public $purchase_order;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(PurchaseOrder $purchase_order, Company $company, array $event_vars)
|
||||
{
|
||||
$this->purchase_order = $purchase_order;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
}
|
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Events\PurchaseOrder;
|
||||
|
||||
|
47
app/Events/PurchaseOrder/PurchaseOrderWasRestored.php
Normal file
47
app/Events/PurchaseOrder/PurchaseOrderWasRestored.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Events\PurchaseOrder;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\PurchaseOrder;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class PurchaseOrderWasRestored.
|
||||
*/
|
||||
class PurchaseOrderWasRestored
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var PurchaseOrder
|
||||
*/
|
||||
public $purchase_order;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(PurchaseOrder $purchase_order, Company $company, array $event_vars)
|
||||
{
|
||||
$this->purchase_order = $purchase_order;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
}
|
47
app/Events/PurchaseOrder/PurchaseOrderWasUpdated.php
Normal file
47
app/Events/PurchaseOrder/PurchaseOrderWasUpdated.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Events\PurchaseOrder;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\PurchaseOrder;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class PurchaseOrderWasUpdated.
|
||||
*/
|
||||
class PurchaseOrderWasUpdated
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var PurchaseOrder
|
||||
*/
|
||||
public $purchase_order;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(PurchaseOrder $purchase_order, Company $company, array $event_vars)
|
||||
{
|
||||
$this->purchase_order = $purchase_order;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
}
|
47
app/Events/PurchaseOrder/PurchaseOrderWasViewed.php
Normal file
47
app/Events/PurchaseOrder/PurchaseOrderWasViewed.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Events\PurchaseOrder;
|
||||
|
||||
use App\Models\Company;
|
||||
use App\Models\PurchaseOrder;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class PurchaseOrderWasViewed.
|
||||
*/
|
||||
class PurchaseOrderWasViewed
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var PurchaseOrder
|
||||
*/
|
||||
public $purchase_order;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(PurchaseOrder $purchase_order, Company $company, array $event_vars)
|
||||
{
|
||||
$this->purchase_order = $purchase_order;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
}
|
@ -12,6 +12,8 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasCreated;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasUpdated;
|
||||
use App\Factory\PurchaseOrderFactory;
|
||||
use App\Filters\PurchaseOrderFilters;
|
||||
use App\Http\Requests\PurchaseOrder\ActionPurchaseOrderRequest;
|
||||
@ -26,6 +28,7 @@ use App\Models\Client;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Repositories\PurchaseOrderRepository;
|
||||
use App\Transformers\PurchaseOrderTransformer;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
@ -182,6 +185,8 @@ class PurchaseOrderController extends BaseController
|
||||
->fillDefaults()
|
||||
->save();
|
||||
|
||||
event(new PurchaseOrderWasCreated($purchase_order, $purchase_order->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
return $this->itemResponse($purchase_order);
|
||||
}
|
||||
/**
|
||||
@ -352,6 +357,8 @@ class PurchaseOrderController extends BaseController
|
||||
|
||||
$purchase_order = $this->purchase_order_repository->save($request->all(), $purchase_order);
|
||||
|
||||
event(new PurchaseOrderWasUpdated($purchase_order, $purchase_order->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||
|
||||
return $this->itemResponse($purchase_order);
|
||||
}
|
||||
/**
|
||||
|
@ -61,6 +61,13 @@ use App\Events\Payment\PaymentWasRestored;
|
||||
use App\Events\Payment\PaymentWasUpdated;
|
||||
use App\Events\Payment\PaymentWasVoided;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasMarkedSent;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasArchived;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasCreated;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasDeleted;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasEmailed;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasRestored;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasUpdated;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasViewed;
|
||||
use App\Events\Quote\QuoteWasApproved;
|
||||
use App\Events\Quote\QuoteWasArchived;
|
||||
use App\Events\Quote\QuoteWasCreated;
|
||||
@ -436,6 +443,22 @@ class EventServiceProvider extends ServiceProvider
|
||||
PaymentWasEmailedAndFailed::class => [
|
||||
PaymentEmailFailureActivity::class,
|
||||
],
|
||||
PurchaseOrderWasArchived::class => [
|
||||
],
|
||||
PurchaseOrderWasCreated::class => [
|
||||
],
|
||||
PurchaseOrderWasDeleted::class => [
|
||||
],
|
||||
PurchaseOrderWasEmailed::class => [
|
||||
],
|
||||
PurchaseOrderWasMarkedSent::class => [
|
||||
],
|
||||
PurchaseOrderWasRestored::class => [
|
||||
],
|
||||
PurchaseOrderWasUpdated::class => [
|
||||
],
|
||||
PurchaseOrderWasViewed::class => [
|
||||
],
|
||||
CompanyDocumentsDeleted::class => [
|
||||
DeleteCompanyDocuments::class,
|
||||
],
|
||||
@ -558,9 +581,7 @@ class EventServiceProvider extends ServiceProvider
|
||||
],
|
||||
VendorWasUpdated::class => [
|
||||
VendorUpdatedActivity::class,
|
||||
],
|
||||
PurchaseOrderWasMarkedSent::class => [
|
||||
],
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
|
@ -31,6 +31,11 @@ use App\Events\Invoice\InvoiceWasDeleted;
|
||||
use App\Events\Invoice\InvoiceWasRestored;
|
||||
use App\Events\Invoice\InvoiceWasUpdated;
|
||||
use App\Events\Payment\PaymentWasArchived;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasCreated;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasUpdated;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasArchived;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasRestored;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasDeleted;
|
||||
use App\Events\Payment\PaymentWasCreated;
|
||||
use App\Events\Payment\PaymentWasDeleted;
|
||||
use App\Events\Payment\PaymentWasRestored;
|
||||
@ -807,4 +812,77 @@ class EventTest extends TestCase
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
|
||||
public function PurchaseOrderEvents()
|
||||
{
|
||||
|
||||
/* Test fire new invoice */
|
||||
$data = [
|
||||
'client_id' => $this->vendor->hashed_id,
|
||||
'number' => 'dude',
|
||||
];
|
||||
|
||||
$this->expectsEvents([
|
||||
PurchaseOrderWasCreated::class,
|
||||
PurchaseOrderWasUpdated::class,
|
||||
PurchaseOrderWasArchived::class,
|
||||
PurchaseOrderWasRestored::class,
|
||||
PurchaseOrderWasDeleted::class,
|
||||
]);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/purchase_orders/', $data)
|
||||
->assertStatus(200);
|
||||
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$data = [
|
||||
'client_id' => $this->vendor->hashed_id,
|
||||
'number' => 'dude2',
|
||||
];
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->put('/api/v1/purchase_orders/' . $arr['data']['id'], $data)
|
||||
->assertStatus(200);
|
||||
|
||||
|
||||
$data = [
|
||||
'ids' => [$arr['data']['id']],
|
||||
];
|
||||
|
||||
$quote = PurchaseOrder::find($this->decodePrimaryKey($arr['data']['id']));
|
||||
$quote->status_id = PurchaseOrder::STATUS_SENT;
|
||||
$quote->save();
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/purchase_orders/bulk?action=archive', $data)
|
||||
->assertStatus(200);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/purchase_orders/bulk?action=restore', $data)
|
||||
->assertStatus(200);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/purchase_orders/bulk?action=approve', $data)
|
||||
->assertStatus(200);
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $this->token,
|
||||
])->post('/api/v1/purchase_orders/bulk?action=delete', $data)
|
||||
->assertStatus(200);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user