mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-05 01:54:36 -04:00
Working on recurring & analytics
This commit is contained in:
parent
ff00ed3815
commit
b8b3149582
57
app/DataMapper/Analytics/EmailInvoiceFailure.php
Normal file
57
app/DataMapper/Analytics/EmailInvoiceFailure.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?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\DataMapper\Analytics;
|
||||||
|
|
||||||
|
class EmailInvoiceFailure
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The type of Sample.
|
||||||
|
*
|
||||||
|
* Monotonically incrementing counter
|
||||||
|
*
|
||||||
|
* - counter
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $type = 'mixed_metric';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the counter.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $name = 'job.failure.email_invoice';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The datetime of the counter measurement.
|
||||||
|
*
|
||||||
|
* date("Y-m-d H:i:s")
|
||||||
|
*
|
||||||
|
* @var DateTime
|
||||||
|
*/
|
||||||
|
public $datetime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class failure name
|
||||||
|
* set to 0.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $string_metric5 = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The exception string
|
||||||
|
* set to 0.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $string_metric6 = '';
|
||||||
|
}
|
57
app/DataMapper/Analytics/MigrationFailure.php
Normal file
57
app/DataMapper/Analytics/MigrationFailure.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?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\DataMapper\Analytics;
|
||||||
|
|
||||||
|
class MigrationFailure
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The type of Sample.
|
||||||
|
*
|
||||||
|
* Monotonically incrementing counter
|
||||||
|
*
|
||||||
|
* - counter
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $type = 'mixed_metric';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the counter.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $name = 'job.failure.migration';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The datetime of the counter measurement.
|
||||||
|
*
|
||||||
|
* date("Y-m-d H:i:s")
|
||||||
|
*
|
||||||
|
* @var DateTime
|
||||||
|
*/
|
||||||
|
public $datetime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class failure name
|
||||||
|
* set to 0.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $string_metric5 = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The exception string
|
||||||
|
* set to 0.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $string_metric6 = '';
|
||||||
|
}
|
57
app/DataMapper/Analytics/SendRecurringFailure.php
Normal file
57
app/DataMapper/Analytics/SendRecurringFailure.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?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\DataMapper\Analytics;
|
||||||
|
|
||||||
|
class SendRecurringFailure
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The type of Sample.
|
||||||
|
*
|
||||||
|
* Monotonically incrementing counter
|
||||||
|
*
|
||||||
|
* - counter
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $type = 'mixed_metric';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the counter.
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $name = 'job.failure.send_recurring';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The datetime of the counter measurement.
|
||||||
|
*
|
||||||
|
* date("Y-m-d H:i:s")
|
||||||
|
*
|
||||||
|
* @var DateTime
|
||||||
|
*/
|
||||||
|
public $datetime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class failure name
|
||||||
|
* set to 0.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $string_metric5 = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The exception string
|
||||||
|
* set to 0.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
public $string_metric6 = '';
|
||||||
|
}
|
@ -30,7 +30,7 @@ class RecurringInvoiceToInvoiceFactory
|
|||||||
$invoice->terms = $recurring_invoice->terms;
|
$invoice->terms = $recurring_invoice->terms;
|
||||||
$invoice->public_notes = $recurring_invoice->public_notes;
|
$invoice->public_notes = $recurring_invoice->public_notes;
|
||||||
$invoice->private_notes = $recurring_invoice->private_notes;
|
$invoice->private_notes = $recurring_invoice->private_notes;
|
||||||
$invoice->date = date_create()->format($client->date_format());
|
//$invoice->date = now()->format($client->date_format());
|
||||||
$invoice->due_date = $recurring_invoice->calculateDueDate($recurring_invoice->next_send_date);
|
$invoice->due_date = $recurring_invoice->calculateDueDate($recurring_invoice->next_send_date);
|
||||||
$invoice->is_deleted = $recurring_invoice->is_deleted;
|
$invoice->is_deleted = $recurring_invoice->is_deleted;
|
||||||
$invoice->line_items = $recurring_invoice->line_items;
|
$invoice->line_items = $recurring_invoice->line_items;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Invoice;
|
namespace App\Jobs\Invoice;
|
||||||
|
|
||||||
|
use App\DataMapper\Analytics\EmailInvoiceFailure;
|
||||||
use App\Events\Invoice\InvoiceWasEmailed;
|
use App\Events\Invoice\InvoiceWasEmailed;
|
||||||
use App\Events\Invoice\InvoiceWasEmailedAndFailed;
|
use App\Events\Invoice\InvoiceWasEmailedAndFailed;
|
||||||
use App\Helpers\Email\InvoiceEmail;
|
use App\Helpers\Email\InvoiceEmail;
|
||||||
@ -30,6 +31,7 @@ use Illuminate\Queue\InteractsWithQueue;
|
|||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Symfony\Component\Mime\Test\Constraint\EmailTextBodyContains;
|
use Symfony\Component\Mime\Test\Constraint\EmailTextBodyContains;
|
||||||
|
use Turbo124\Beacon\Facades\LightLogs;
|
||||||
|
|
||||||
/*Multi Mailer implemented*/
|
/*Multi Mailer implemented*/
|
||||||
|
|
||||||
@ -95,4 +97,17 @@ class EmailInvoice extends BaseMailerJob implements ShouldQueue
|
|||||||
/* Mark invoice sent */
|
/* Mark invoice sent */
|
||||||
$this->invoice_invitation->invoice->service()->markSent()->save();
|
$this->invoice_invitation->invoice->service()->markSent()->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function failed($exception = null)
|
||||||
|
{
|
||||||
|
info('the job failed');
|
||||||
|
|
||||||
|
$job_failure = new EmailInvoiceFailure();
|
||||||
|
$job_failure->string_metric5 = get_class($this);
|
||||||
|
$job_failure->string_metric6 = $exception->getMessage();
|
||||||
|
|
||||||
|
LightLogs::create($job_failure)
|
||||||
|
->batch();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs\RecurringInvoice;
|
namespace App\Jobs\RecurringInvoice;
|
||||||
|
|
||||||
|
use App\DataMapper\Analytics\SendRecurringFailure;
|
||||||
use App\Events\Invoice\InvoiceWasEmailed;
|
use App\Events\Invoice\InvoiceWasEmailed;
|
||||||
use App\Factory\RecurringInvoiceToInvoiceFactory;
|
use App\Factory\RecurringInvoiceToInvoiceFactory;
|
||||||
use App\Helpers\Email\InvoiceEmail;
|
use App\Helpers\Email\InvoiceEmail;
|
||||||
@ -26,6 +27,7 @@ use Illuminate\Http\Request;
|
|||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
use Turbo124\Beacon\Facades\LightLogs;
|
||||||
|
|
||||||
class SendRecurring implements ShouldQueue
|
class SendRecurring implements ShouldQueue
|
||||||
{
|
{
|
||||||
@ -59,6 +61,8 @@ class SendRecurring implements ShouldQueue
|
|||||||
// Generate Standard Invoice
|
// Generate Standard Invoice
|
||||||
$invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice, $this->recurring_invoice->client);
|
$invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice, $this->recurring_invoice->client);
|
||||||
|
|
||||||
|
$invoice->date = now()->format('Y-m-d');
|
||||||
|
|
||||||
$invoice = $invoice->service()
|
$invoice = $invoice->service()
|
||||||
->markSent()
|
->markSent()
|
||||||
->applyNumber()
|
->applyNumber()
|
||||||
@ -71,9 +75,10 @@ class SendRecurring implements ShouldQueue
|
|||||||
|
|
||||||
$email_builder = (new InvoiceEmail())->build($invitation);
|
$email_builder = (new InvoiceEmail())->build($invitation);
|
||||||
|
|
||||||
|
if($invitation->contact && strlen($invitation->contact->email) >=1){
|
||||||
EmailInvoice::dispatch($email_builder, $invitation, $invoice->company);
|
EmailInvoice::dispatch($email_builder, $invitation, $invoice->company);
|
||||||
|
|
||||||
info("Firing email for invoice {$invoice->number}");
|
info("Firing email for invoice {$invoice->number}");
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -101,4 +106,18 @@ class SendRecurring implements ShouldQueue
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function failed($exception = null)
|
||||||
|
{
|
||||||
|
info('the job failed');
|
||||||
|
|
||||||
|
$job_failure = new SendRecurringFailure();
|
||||||
|
$job_failure->string_metric5 = get_class($this);
|
||||||
|
$job_failure->string_metric6 = $exception->getMessage();
|
||||||
|
|
||||||
|
LightLogs::create($job_failure)
|
||||||
|
->batch();
|
||||||
|
|
||||||
|
info(print_r($exception->getMessage(), 1));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Jobs\Util;
|
namespace App\Jobs\Util;
|
||||||
|
|
||||||
|
use App\DataMapper\Analytics\MigrationFailure;
|
||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
use App\Exceptions\MigrationValidatorFailed;
|
use App\Exceptions\MigrationValidatorFailed;
|
||||||
use App\Exceptions\ResourceDependencyMissing;
|
use App\Exceptions\ResourceDependencyMissing;
|
||||||
@ -72,6 +73,7 @@ use Illuminate\Queue\SerializesModels;
|
|||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Turbo124\Beacon\Facades\LightLogs;
|
||||||
|
|
||||||
class Import implements ShouldQueue
|
class Import implements ShouldQueue
|
||||||
{
|
{
|
||||||
@ -966,6 +968,15 @@ class Import implements ShouldQueue
|
|||||||
public function failed($exception = null)
|
public function failed($exception = null)
|
||||||
{
|
{
|
||||||
info('the job failed');
|
info('the job failed');
|
||||||
|
|
||||||
|
$job_failure = new MigrationFailure();
|
||||||
|
$job_failure->string_metric5 = get_class($this);
|
||||||
|
$job_failure->string_metric6 = $exception->getMessage();
|
||||||
|
|
||||||
|
LightLogs::create($job_failure)
|
||||||
|
->batch();
|
||||||
|
|
||||||
info(print_r($exception->getMessage(), 1));
|
info(print_r($exception->getMessage(), 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -64,11 +64,12 @@ trait GeneratesCounter
|
|||||||
//Return a valid counter
|
//Return a valid counter
|
||||||
$pattern = $client->getSetting('invoice_number_pattern');
|
$pattern = $client->getSetting('invoice_number_pattern');
|
||||||
$padding = $client->getSetting('counter_padding');
|
$padding = $client->getSetting('counter_padding');
|
||||||
|
$prefix = '';
|
||||||
$invoice_number = $this->checkEntityNumber(Invoice::class, $client, $counter, $padding, $pattern);
|
|
||||||
|
|
||||||
if($invoice && $invoice->recurring_id)
|
if($invoice && $invoice->recurring_id)
|
||||||
$invoice_number = $this->prefixCounter($invoice_number, $client->getSetting('recurring_number_prefix'));
|
$prefix = $client->getSetting('recurring_number_prefix');
|
||||||
|
|
||||||
|
$invoice_number = $this->checkEntityNumber(Invoice::class, $client, $counter, $padding, $pattern, $prefix);
|
||||||
|
|
||||||
$this->incrementCounter($counter_entity, 'invoice_number_counter');
|
$this->incrementCounter($counter_entity, 'invoice_number_counter');
|
||||||
|
|
||||||
@ -289,7 +290,7 @@ trait GeneratesCounter
|
|||||||
*
|
*
|
||||||
* @return string The padded and prefixed entity number
|
* @return string The padded and prefixed entity number
|
||||||
*/
|
*/
|
||||||
private function checkEntityNumber($class, $entity, $counter, $padding, $pattern)
|
private function checkEntityNumber($class, $entity, $counter, $padding, $pattern, $prefix = '')
|
||||||
{
|
{
|
||||||
$check = false;
|
$check = false;
|
||||||
|
|
||||||
@ -298,6 +299,8 @@ trait GeneratesCounter
|
|||||||
|
|
||||||
$number = $this->applyNumberPattern($entity, $number, $pattern);
|
$number = $this->applyNumberPattern($entity, $number, $pattern);
|
||||||
|
|
||||||
|
$number = $this->prefixCounter($number, $prefix);
|
||||||
|
|
||||||
if ($class == Invoice::class || $class == RecurringInvoice::class)
|
if ($class == Invoice::class || $class == RecurringInvoice::class)
|
||||||
$check = $class::whereCompanyId($entity->company_id)->whereNumber($number)->withTrashed()->first();
|
$check = $class::whereCompanyId($entity->company_id)->whereNumber($number)->withTrashed()->first();
|
||||||
elseif ($class == Client::class || $class == Vendor::class)
|
elseif ($class == Client::class || $class == Vendor::class)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user