mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactor webhook handler
This commit is contained in:
parent
ffc87c4dc1
commit
2f4b46e435
@ -160,6 +160,18 @@ class InvoiceSum
|
||||
{
|
||||
$this->total += $this->total_taxes;
|
||||
|
||||
if($this->invoice->custom_value1 > 0)
|
||||
$this->total += $this->invoice->custom_value1;
|
||||
|
||||
if($this->invoice->custom_value2 > 0)
|
||||
$this->total += $this->invoice->custom_value2;
|
||||
|
||||
if($this->invoice->custom_value3 > 0)
|
||||
$this->total += $this->invoice->custom_value3;
|
||||
|
||||
if($this->invoice->custom_value4 > 0)
|
||||
$this->total += $this->invoice->custom_value4;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ class InvoiceSumInclusive
|
||||
->calculateCustomValues()
|
||||
->calculateInvoiceTaxes()
|
||||
->setTaxMap()
|
||||
// ->calculateTotals()
|
||||
->calculateTotals() //just don't add the taxes!!
|
||||
->calculateBalance()
|
||||
->calculatePartial();
|
||||
|
||||
@ -170,7 +170,19 @@ class InvoiceSumInclusive
|
||||
|
||||
private function calculateTotals()
|
||||
{
|
||||
$this->total += $this->total_taxes;
|
||||
//$this->total += $this->total_taxes;
|
||||
|
||||
if($this->invoice->custom_value1 > 0)
|
||||
$this->total += $this->invoice->custom_value1;
|
||||
|
||||
if($this->invoice->custom_value2 > 0)
|
||||
$this->total += $this->invoice->custom_value2;
|
||||
|
||||
if($this->invoice->custom_value3 > 0)
|
||||
$this->total += $this->invoice->custom_value3;
|
||||
|
||||
if($this->invoice->custom_value4 > 0)
|
||||
$this->total += $this->invoice->custom_value4;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ class UpdateOrCreateProduct implements ShouldQueue
|
||||
continue;
|
||||
}
|
||||
|
||||
$product = Product::firstOrNew(['product_key' => $item->product_key, 'company_id' => $this->invoice->company->id]);
|
||||
$product = Product::withTrashed()->firstOrNew(['product_key' => $item->product_key, 'company_id' => $this->invoice->company->id]);
|
||||
|
||||
$product->product_key = $item->product_key;
|
||||
$product->notes = isset($item->notes) ? $item->notes : '';
|
||||
@ -94,4 +94,10 @@ class UpdateOrCreateProduct implements ShouldQueue
|
||||
$product->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function failed($exception = null)
|
||||
{
|
||||
info("update create failed with = ");
|
||||
info(print_r($exception->getMessage(),1));
|
||||
}
|
||||
}
|
||||
|
@ -188,8 +188,6 @@ class Import implements ShouldQueue
|
||||
|
||||
foreach ($this->available_imports as $import) {
|
||||
|
||||
info("the key = {$import}");
|
||||
|
||||
if (! array_key_exists($import, $data)) {
|
||||
//throw new ResourceNotAvailableForMigration("Resource {$key} is not available for migration.");
|
||||
info("Resource {$import} is not available for migration.");
|
||||
@ -846,10 +844,10 @@ class Import implements ShouldQueue
|
||||
];
|
||||
|
||||
//depending on the status, we do a final action.
|
||||
$payment = $this->updatePaymentForStatus($payment, $modified['status_id']);
|
||||
//s$payment = $this->updatePaymentForStatus($payment, $modified['status_id']);
|
||||
|
||||
if($modified['is_deleted'])
|
||||
$payment->service()->deletePayment();
|
||||
// if($modified['is_deleted'])
|
||||
// $payment->service()->deletePayment();
|
||||
|
||||
// if(isset($modified['deleted_at']))
|
||||
// $payment->delete();
|
||||
|
@ -131,12 +131,12 @@ class Payment extends BaseModel
|
||||
|
||||
public function invoices()
|
||||
{
|
||||
return $this->morphedByMany(Invoice::class, 'paymentable')->withPivot('amount', 'refunded')->withTimestamps();
|
||||
return $this->morphedByMany(Invoice::class, 'paymentable')->withTrashed()->withPivot('amount', 'refunded')->withTimestamps();
|
||||
}
|
||||
|
||||
public function credits()
|
||||
{
|
||||
return $this->morphedByMany(Credit::class, 'paymentable')->withPivot('amount', 'refunded')->withTimestamps();
|
||||
return $this->morphedByMany(Credit::class, 'paymentable')->withTrashed()->withPivot('amount', 'refunded')->withTimestamps();
|
||||
}
|
||||
|
||||
public function company_ledger()
|
||||
|
@ -25,7 +25,12 @@ class ClientObserver
|
||||
*/
|
||||
public function created(Client $client)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_CLIENT, $client, $client->company);
|
||||
$subscriptions = Webhook::where('company_id', $client->company->id)
|
||||
->where('event_id', Webhook::EVENT_CREATE_CLIENT)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_CLIENT, $client, $client->company);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,7 +41,12 @@ class ClientObserver
|
||||
*/
|
||||
public function updated(Client $client)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_CLIENT, $client, $client->company);
|
||||
$subscriptions = Webhook::where('company_id', $client->company->id)
|
||||
->where('event_id', Webhook::EVENT_UPDATE_CLIENT)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_CLIENT, $client, $client->company);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +57,12 @@ class ClientObserver
|
||||
*/
|
||||
public function deleted(Client $client)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_CLIENT, $client, $client->company);
|
||||
$subscriptions = Webhook::where('company_id', $client->company->id)
|
||||
->where('event_id', Webhook::EVENT_DELETE_CLIENT)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_CLIENT, $client, $client->company);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,12 @@ class ExpenseObserver
|
||||
*/
|
||||
public function created(Expense $expense)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_EXPENSE, $expense, $expense->company);
|
||||
$subscriptions = Webhook::where('company_id', $expense->company->id)
|
||||
->where('event_id', Webhook::EVENT_CREATE_EXPENSE)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_EXPENSE, $expense, $expense->company);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,7 +41,12 @@ class ExpenseObserver
|
||||
*/
|
||||
public function updated(Expense $expense)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_EXPENSE, $expense, $expense->company);
|
||||
$subscriptions = Webhook::where('company_id', $expense->company->id)
|
||||
->where('event_id', Webhook::EVENT_UPDATE_EXPENSE)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_EXPENSE, $expense, $expense->company);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +57,12 @@ class ExpenseObserver
|
||||
*/
|
||||
public function deleted(Expense $expense)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_EXPENSE, $expense, $expense->company);
|
||||
$subscriptions = Webhook::where('company_id', $expense->company->id)
|
||||
->where('event_id', Webhook::EVENT_DELETE_EXPENSE)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_EXPENSE, $expense, $expense->company);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,7 +26,13 @@ class InvoiceObserver
|
||||
*/
|
||||
public function created(Invoice $invoice)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company);
|
||||
|
||||
$subscriptions = Webhook::where('company_id', $invoice->company->id)
|
||||
->where('event_id', Webhook::EVENT_CREATE_INVOICE)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_INVOICE, $invoice, $invoice->company);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -37,7 +43,12 @@ class InvoiceObserver
|
||||
*/
|
||||
public function updated(Invoice $invoice)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company);
|
||||
$subscriptions = Webhook::where('company_id', $invoice->company->id)
|
||||
->where('event_id', Webhook::EVENT_UPDATE_INVOICE)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_INVOICE, $invoice, $invoice->company);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,7 +59,12 @@ class InvoiceObserver
|
||||
*/
|
||||
public function deleted(Invoice $invoice)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company);
|
||||
$subscriptions = Webhook::where('company_id', $invoice->company->id)
|
||||
->where('event_id', Webhook::EVENT_DELETE_INVOICE)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_INVOICE, $invoice, $invoice->company);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,7 +26,13 @@ class PaymentObserver
|
||||
*/
|
||||
public function created(Payment $payment)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company);
|
||||
|
||||
$subscriptions = Webhook::where('company_id', $payment->company->id)
|
||||
->where('event_id', Webhook::EVENT_CREATE_PAYMENT)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_PAYMENT, $payment, $payment->company);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +53,12 @@ class PaymentObserver
|
||||
*/
|
||||
public function deleted(Payment $payment)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment, $payment->company);
|
||||
$subscriptions = Webhook::where('company_id', $payment->company->id)
|
||||
->where('event_id', Webhook::EVENT_DELETE_PAYMENT)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_PAYMENT, $payment, $payment->company);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,6 +25,11 @@ class QuoteObserver
|
||||
*/
|
||||
public function created(Quote $quote)
|
||||
{
|
||||
$subscriptions = Webhook::where('company_id', $quote->company->id)
|
||||
->where('event_id', Webhook::EVENT_CREATE_QUOTE)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_QUOTE, $quote, $quote->company);
|
||||
}
|
||||
|
||||
@ -36,7 +41,12 @@ class QuoteObserver
|
||||
*/
|
||||
public function updated(Quote $quote)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote, $quote->company);
|
||||
$subscriptions = Webhook::where('company_id', $quote->company->id)
|
||||
->where('event_id', Webhook::EVENT_UPDATE_QUOTE)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_QUOTE, $quote, $quote->company);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +57,12 @@ class QuoteObserver
|
||||
*/
|
||||
public function deleted(Quote $quote)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_QUOTE, $quote, $quote->company);
|
||||
$subscriptions = Webhook::where('company_id', $quote->company->id)
|
||||
->where('event_id', Webhook::EVENT_DELETE_QUOTE)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_QUOTE, $quote, $quote->company);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,13 @@ class TaskObserver
|
||||
*/
|
||||
public function created(Task $task)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_TASK, $task, $task->company);
|
||||
|
||||
$subscriptions = Webhook::where('company_id', $task->company->id)
|
||||
->where('event_id', Webhook::EVENT_CREATE_TASK)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_CREATE_TASK, $task, $task->company);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,7 +42,13 @@ class TaskObserver
|
||||
*/
|
||||
public function updated(Task $task)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_TASK, $task, $task->company);
|
||||
|
||||
$subscriptions = Webhook::where('company_id', $task->company->id)
|
||||
->where('event_id', Webhook::EVENT_UPDATE_TASK)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_UPDATE_TASK, $task, $task->company);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +59,14 @@ class TaskObserver
|
||||
*/
|
||||
public function deleted(Task $task)
|
||||
{
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_TASK, $task, $task->company);
|
||||
|
||||
|
||||
$subscriptions = Webhook::where('company_id', $task->company->id)
|
||||
->where('event_id', Webhook::EVENT_DELETE_TASK)
|
||||
->exists();
|
||||
|
||||
if($subscriptions)
|
||||
WebhookHandler::dispatch(Webhook::EVENT_DELETE_TASK, $task, $task->company);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +87,15 @@ class PaymentMigrationRepository extends BaseRepository
|
||||
|
||||
/*Fill the payment*/
|
||||
$payment->fill($data);
|
||||
$payment->status_id = Payment::STATUS_COMPLETED;
|
||||
//$payment->status_id = Payment::STATUS_COMPLETED;
|
||||
|
||||
if(!array_key_exists('status_id', $data)){
|
||||
info("payment with no status id?");
|
||||
info(print_r($data,1));
|
||||
}
|
||||
|
||||
$payment->status_id = $data['status_id'];
|
||||
$payment->deleted_at = $data['deleted_at'] ?: NULL;
|
||||
$payment->save();
|
||||
|
||||
/*Ensure payment number generated*/
|
||||
@ -104,7 +112,7 @@ class PaymentMigrationRepository extends BaseRepository
|
||||
$invoice_totals = array_sum(array_column($data['invoices'], 'amount'));
|
||||
$refund_totals = array_sum(array_column($data['invoices'], 'refunded'));
|
||||
|
||||
$invoices = Invoice::whereIn('id', array_column($data['invoices'], 'invoice_id'))->get();
|
||||
$invoices = Invoice::whereIn('id', array_column($data['invoices'], 'invoice_id'))->withTrashed()->get();
|
||||
|
||||
$payment->invoices()->saveMany($invoices);
|
||||
|
||||
@ -118,7 +126,7 @@ class PaymentMigrationRepository extends BaseRepository
|
||||
if (array_key_exists('credits', $data) && is_array($data['credits']) && count($data['credits']) > 0) {
|
||||
$credit_totals = array_sum(array_column($data['credits'], 'amount'));
|
||||
|
||||
$credits = Credit::whereIn('id', array_column($data['credits'], 'credit_id'))->get();
|
||||
$credits = Credit::whereIn('id', array_column($data['credits'], 'credit_id'))->withTrashed()->get();
|
||||
|
||||
$payment->credits()->saveMany($credits);
|
||||
|
||||
|
@ -72,7 +72,7 @@ class PaymentRepository extends BaseRepository
|
||||
$this->processExchangeRates($data, $payment);
|
||||
|
||||
$is_existing_payment = false;
|
||||
$client = Client::where('id', $data['client_id'])->withTrashed()->first();
|
||||
$client = Client::where('id', $data['client_id'])->withTrashed()->first;
|
||||
|
||||
/*We only update the paid to date ONCE per payment*/
|
||||
if (array_key_exists('invoices', $data) && is_array($data['invoices']) && count($data['invoices']) > 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user