mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Accept listener
This commit is contained in:
parent
1e30bf4bdc
commit
0f32e43fb6
51
app/Events/PurchaseOrder/PurchaseOrderWasAccepted.php
Normal file
51
app/Events/PurchaseOrder/PurchaseOrderWasAccepted.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?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 App\Models\PurchaseOrderInvitation;
|
||||
use App\Models\VendorContact;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class PurchaseOrderWasAccepted.
|
||||
*/
|
||||
class PurchaseOrderWasAccepted
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var PurchaseOrder
|
||||
*/
|
||||
public $purchase_order;
|
||||
|
||||
public $company;
|
||||
|
||||
public $event_vars;
|
||||
|
||||
public $contact;
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param PurchaseOrder $purchase_order
|
||||
* @param Company $company
|
||||
* @param array $event_vars
|
||||
*/
|
||||
public function __construct(PurchaseOrder $purchase_order, VendorContact $contact, Company $company, array $event_vars)
|
||||
{
|
||||
$this->purchase_order = $purchase_order;
|
||||
$this->contact = $contact;
|
||||
$this->company = $company;
|
||||
$this->event_vars = $event_vars;
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
namespace App\Http\Controllers\VendorPortal;
|
||||
|
||||
use App\Events\Misc\InvitationWasViewed;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasAccepted;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasViewed;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\VendorPortal\PurchaseOrders\ProcessPurchaseOrdersInBulkRequest;
|
||||
@ -138,12 +139,26 @@ class PurchaseOrderController extends Controller
|
||||
$purchase_orders = PurchaseOrder::query()
|
||||
->whereIn('id', $this->transformKeys($data['purchase_orders']))
|
||||
->where('company_id', auth()->guard('vendor')->user()->vendor->company_id)
|
||||
->whereIn('status_id', [PurchaseOrder::STATUS_DRAFT, PurchaseOrder::STATUS_SENT]);
|
||||
->whereIn('status_id', [PurchaseOrder::STATUS_DRAFT, PurchaseOrder::STATUS_SENT])
|
||||
->cursor()->each(function ($purchase_order){
|
||||
|
||||
$purchase_orders->update(['status_id' => PurchaseOrder::STATUS_ACCEPTED]);
|
||||
$purchase_order->service()
|
||||
->markSent()
|
||||
->applyNumber()
|
||||
->setStatus(PurchaseOrder::STATUS_ACCEPTED)
|
||||
->save();
|
||||
|
||||
if($purchase_orders->count() == 1)
|
||||
return redirect()->route('vendor.purchase_order.show', ['purchase_order' => $purchase_orders->first()->hashed_id]);
|
||||
event(new PurchaseOrderWasAccepted($purchase_order, auth()->guard('vendor')->user(), $purchase_order->company, Ninja::eventVars()));
|
||||
|
||||
});
|
||||
|
||||
if(count($data['purchase_orders']) == 1){
|
||||
|
||||
$purchase_order = PurchaseOrder::whereIn('id', $this->transformKeys($data['purchase_orders']))->first();
|
||||
|
||||
return redirect()->route('vendor.purchase_order.show', ['purchase_order' => $purchase_order->hashed_id]);
|
||||
|
||||
}
|
||||
else
|
||||
return redirect()->route('vendor.purchase_orders.index');
|
||||
|
||||
|
@ -46,22 +46,17 @@ class PurchaseOrdersTable extends Component
|
||||
$query = PurchaseOrder::query()
|
||||
->with('vendor.contacts')
|
||||
->orderBy($this->sort_field, $this->sort_asc ? 'asc' : 'desc')
|
||||
->whereIn('status_id', [PurchaseOrder::STATUS_SENT, PurchaseOrder::STATUS_ACCEPTED])
|
||||
->where('company_id', $this->company->id)
|
||||
->where('is_deleted', false);
|
||||
|
||||
// if (in_array('paid', $this->status)) {
|
||||
// $local_status[] = Invoice::STATUS_PAID;
|
||||
// }
|
||||
if (in_array('sent', $this->status)) {
|
||||
$local_status[] = PurchaseOrder::STATUS_SENT;
|
||||
}
|
||||
|
||||
// if (in_array('unpaid', $this->status)) {
|
||||
// $local_status[] = Invoice::STATUS_SENT;
|
||||
// $local_status[] = Invoice::STATUS_PARTIAL;
|
||||
// }
|
||||
|
||||
// if (in_array('overdue', $this->status)) {
|
||||
// $local_status[] = Invoice::STATUS_SENT;
|
||||
// $local_status[] = Invoice::STATUS_PARTIAL;
|
||||
// }
|
||||
if (in_array('accepted', $this->status)) {
|
||||
$local_status[] = PurchaseOrder::STATUS_ACCEPTED;
|
||||
}
|
||||
|
||||
if (count($local_status) > 0) {
|
||||
$query = $query->whereIn('status_id', array_unique($local_status));
|
||||
|
@ -49,7 +49,9 @@ class InvitationViewedListener implements ShouldQueue
|
||||
|
||||
if($entity_name == 'recurringInvoice')
|
||||
return;
|
||||
|
||||
elseif($entity_name == 'purchaseOrder')
|
||||
$entity_name = 'purchase_order';
|
||||
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = new NinjaMailer( (new EntityViewedObject($invitation, $entity_name))->build() );
|
||||
$nmo->company = $invitation->company;
|
||||
@ -60,6 +62,8 @@ class InvitationViewedListener implements ShouldQueue
|
||||
$entity_viewed = "{$entity_name}_viewed";
|
||||
$entity_viewed_all = "{$entity_name}_viewed_all";
|
||||
|
||||
|
||||
|
||||
$methods = $this->findUserNotificationTypes($invitation, $company_user, $entity_name, ['all_notifications', $entity_viewed, $entity_viewed_all]);
|
||||
|
||||
if (($key = array_search('mail', $methods)) !== false) {
|
||||
|
@ -0,0 +1,61 @@
|
||||
<?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\Listeners\PurchaseOrder;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Activity;
|
||||
use App\Repositories\ActivityRepository;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use stdClass;
|
||||
|
||||
class PurchaseOrderAcceptedActivity implements ShouldQueue
|
||||
{
|
||||
protected $activity_repo;
|
||||
|
||||
public $delay = 5;
|
||||
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @param ActivityRepository $activity_repo
|
||||
*/
|
||||
public function __construct(ActivityRepository $activity_repo)
|
||||
{
|
||||
$this->activity_repo = $activity_repo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
MultiDB::setDb($event->company->db);
|
||||
|
||||
$fields = new stdClass;
|
||||
|
||||
$user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->purchase_order->user_id;
|
||||
|
||||
$event->purchase_order->service()->markSent()->save();
|
||||
|
||||
$fields->user_id = $user_id;
|
||||
$fields->company_id = $event->purchase_order->company_id;
|
||||
$fields->activity_type_id = Activity::ACCEPT_PURCHASE_ORDER;
|
||||
$fields->vendor_id = $event->purchase_order->vendor_id;
|
||||
$fields->vendor_contact_id = $event->contact->id;
|
||||
$fields->purchase_order_id = $event->purchase_order->id;
|
||||
|
||||
$this->activity_repo->save($fields, $event->purchase_order, $event->event_vars);
|
||||
}
|
||||
}
|
@ -65,7 +65,12 @@ class EntityViewedObject
|
||||
|
||||
private function getAmount()
|
||||
{
|
||||
return Number::formatMoney($this->entity->amount, $this->entity->client);
|
||||
if($this->entity->client)
|
||||
$currency_entity = $this->entity->client;
|
||||
else
|
||||
$currency_entity = $this->company;
|
||||
|
||||
return Number::formatMoney($this->entity->amount, $currency_entity);
|
||||
}
|
||||
|
||||
private function getSubject()
|
||||
@ -82,7 +87,10 @@ class EntityViewedObject
|
||||
|
||||
private function getData()
|
||||
{
|
||||
$settings = $this->entity->client->getMergedSettings();
|
||||
if($this->entity->client)
|
||||
$settings = $this->entity->client->getMergedSettings();
|
||||
else
|
||||
$settings = $this->company->settings;
|
||||
|
||||
$data = [
|
||||
'title' => $this->getSubject(),
|
||||
|
@ -116,7 +116,8 @@ class Activity extends StaticModel
|
||||
const RESTORE_PURCHASE_ORDER = 134;
|
||||
const EMAIL_PURCHASE_ORDER = 135;
|
||||
const VIEW_PURCHASE_ORDER = 136;
|
||||
|
||||
const ACCEPT_PURCHASE_ORDER = 137;
|
||||
|
||||
protected $casts = [
|
||||
'is_system' => 'boolean',
|
||||
'updated_at' => 'timestamp',
|
||||
|
@ -60,11 +60,12 @@ use App\Events\Payment\PaymentWasRefunded;
|
||||
use App\Events\Payment\PaymentWasRestored;
|
||||
use App\Events\Payment\PaymentWasUpdated;
|
||||
use App\Events\Payment\PaymentWasVoided;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasMarkedSent;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasAccepted;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasArchived;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasCreated;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasDeleted;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasEmailed;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasMarkedSent;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasRestored;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasUpdated;
|
||||
use App\Events\PurchaseOrder\PurchaseOrderWasViewed;
|
||||
@ -179,6 +180,7 @@ use App\Listeners\Payment\PaymentEmailedActivity;
|
||||
use App\Listeners\Payment\PaymentNotification;
|
||||
use App\Listeners\Payment\PaymentRestoredActivity;
|
||||
use App\Listeners\PurchaseOrder\CreatePurchaseOrderActivity;
|
||||
use App\Listeners\PurchaseOrder\PurchaseOrderAcceptedActivity;
|
||||
use App\Listeners\PurchaseOrder\PurchaseOrderArchivedActivity;
|
||||
use App\Listeners\PurchaseOrder\PurchaseOrderDeletedActivity;
|
||||
use App\Listeners\PurchaseOrder\PurchaseOrderEmailActivity;
|
||||
@ -471,6 +473,9 @@ class EventServiceProvider extends ServiceProvider
|
||||
PurchaseOrderWasViewed::class => [
|
||||
PurchaseOrderViewedActivity::class,
|
||||
],
|
||||
PurchaseOrderWasAccepted::class => [
|
||||
PurchaseOrderAcceptedActivity::class,
|
||||
],
|
||||
CompanyDocumentsDeleted::class => [
|
||||
DeleteCompanyDocuments::class,
|
||||
],
|
||||
|
@ -15,6 +15,7 @@ use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Models\Quote;
|
||||
|
||||
/**
|
||||
@ -99,7 +100,10 @@ trait UserNotifies
|
||||
break;
|
||||
case ($entity instanceof Credit):
|
||||
return array_merge($required_permissions, ["all_notifications","all_user_notifications","credit_created_user","credit_sent_user","credit_viewed_user"]);
|
||||
break;
|
||||
break;
|
||||
case ($entity instanceof PurchaseOrder):
|
||||
return array_merge($required_permissions, ["all_notifications","all_user_notifications","purchase_order_created_user","purchase_order_sent_user","purchase_order_viewed_user"]);
|
||||
break;
|
||||
default:
|
||||
return [];
|
||||
break;
|
||||
@ -122,7 +126,10 @@ trait UserNotifies
|
||||
break;
|
||||
case ($entity instanceof Credit):
|
||||
return array_diff($required_permissions, ["all_user_notifications","credit_created_user","credit_sent_user","credit_viewed_user"]);
|
||||
break;
|
||||
break;
|
||||
case ($entity instanceof PurchaseOrder):
|
||||
return array_diff($required_permissions, ["all_user_notifications","purchase_order_created_user","purchase_order_sent_user","purchase_order_viewed_user"]);
|
||||
break;
|
||||
default:
|
||||
// code...
|
||||
break;
|
||||
|
@ -11,7 +11,12 @@
|
||||
"Credit card billing",
|
||||
"projects",
|
||||
"tasks",
|
||||
"freelancer"
|
||||
"freelancer",
|
||||
"quotes",
|
||||
"purchase orders",
|
||||
"stripe billing",
|
||||
"invoices",
|
||||
"subscriptions"
|
||||
],
|
||||
"license": "Elastic License",
|
||||
"authors": [
|
||||
|
@ -4629,6 +4629,7 @@ $LANG = array(
|
||||
'purchase_orders' => 'Purchase Orders',
|
||||
'purchase_order_number_placeholder' => 'Purchase Order # :purchase_order',
|
||||
'accepted' => 'Accepted',
|
||||
'activity_137' => ':contact accepted purchase order :purchase_order',
|
||||
);
|
||||
|
||||
return $LANG;
|
||||
|
@ -11,16 +11,12 @@
|
||||
</div>
|
||||
<div class="flex items-center">
|
||||
<div class="mr-3">
|
||||
<input wire:model="status" value="paid" type="checkbox" class="cursor-pointer form-checkbox" id="paid-checkbox">
|
||||
<label for="paid-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.status_paid') }}</label>
|
||||
<input wire:model="status" value="sent" type="checkbox" class="cursor-pointer form-checkbox" id="paid-checkbox">
|
||||
<label for="paid-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.status_sent') }}</label>
|
||||
</div>
|
||||
<div class="mr-3">
|
||||
<input wire:model="status" value="unpaid" type="checkbox" class="cursor-pointer form-checkbox" id="unpaid-checkbox">
|
||||
<label for="unpaid-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.status_unpaid') }}</label>
|
||||
</div>
|
||||
<div class="mr-3">
|
||||
<input wire:model="status" value="overdue" type="checkbox" class="cursor-pointer form-checkbox" id="overdue-checkbox">
|
||||
<label for="overdue-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.past_due') }}</label>
|
||||
<input wire:model="status" value="accepted" type="checkbox" class="cursor-pointer form-checkbox" id="unpaid-checkbox">
|
||||
<label for="unpaid-checkbox" class="text-sm cursor-pointer">{{ ctrans('texts.accepted') }}</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -33,7 +33,7 @@ Route::group(['middleware' => ['auth:vendor', 'vendor_locale', 'domain_db'], 'pr
|
||||
|
||||
Route::get('profile/{vendor_contact}/edit', [PurchaseOrderController::class, 'index'])->name('profile.edit');
|
||||
Route::post('purchase_orders/bulk', [PurchaseOrderController::class, 'bulk'])->name('purchase_orders.bulk');
|
||||
Route::post('logout', [VendorContactLoginController::class, 'logout'])->name('logout');
|
||||
Route::get('logout', [VendorContactLoginController::class, 'logout'])->name('logout');
|
||||
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user