Merge pull request #5519 from turbo124/v5-develop

Analytics
This commit is contained in:
David Bomba 2021-04-24 23:26:55 +10:00 committed by GitHub
commit 2c86fcb8b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 131 additions and 6 deletions

View File

@ -54,4 +54,22 @@ class EmailFailure
* @var string * @var string
*/ */
public $string_metric6 = ''; public $string_metric6 = '';
/**
* The counter
* set to 1.
*
* @var string
*/
public $int_metric1 = 1;
/**
* Company Key
* @var string
*/
public $string_metric7 = '';
public function __construct($string_metric7) {
$this->string_metric7 = $string_metric7;
}
} }

View File

@ -0,0 +1,76 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\DataMapper\Analytics;
class EmailSuccess
{
/**
* The type of Sample.
*
* Monotonically incrementing counter
*
* - counter
*
* @var string
*/
public $type = 'mixed_metric';
/**
* The name of the counter.
* @var string
*/
public $name = 'job.success.email';
/**
* 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 = '';
/**
* The counter
* set to 1.
*
* @var string
*/
public $int_metric1 = 1;
/**
* Company Key
* @var string
*/
public $string_metric7 = '';
public function __construct($string_metric7) {
$this->string_metric7 = $string_metric7;
}
}

View File

@ -12,6 +12,7 @@
namespace App\Jobs\Mail; namespace App\Jobs\Mail;
use App\DataMapper\Analytics\EmailFailure; use App\DataMapper\Analytics\EmailFailure;
use App\DataMapper\Analytics\EmailSuccess;
use App\Events\Invoice\InvoiceWasEmailedAndFailed; use App\Events\Invoice\InvoiceWasEmailedAndFailed;
use App\Events\Payment\PaymentWasEmailedAndFailed; use App\Events\Payment\PaymentWasEmailedAndFailed;
use App\Jobs\Mail\NinjaMailerObject; use App\Jobs\Mail\NinjaMailerObject;
@ -180,6 +181,8 @@ class NinjaMailerJob implements ShouldQueue
$message->getHeaders()->addTextHeader('GmailToken', $token); $message->getHeaders()->addTextHeader('GmailToken', $token);
}); });
LightLogs::create(new EmailSuccess($this->nmo->company_key->company_key))
->batch();
} }
private function logMailError($errors, $recipient_object) private function logMailError($errors, $recipient_object)
@ -198,7 +201,7 @@ class NinjaMailerJob implements ShouldQueue
nlog('mailer job failed'); nlog('mailer job failed');
nlog($exception->getMessage()); nlog($exception->getMessage());
$job_failure = new EmailFailure(); $job_failure = new EmailFailure($this->nmo->company->company_key);
$job_failure->string_metric5 = get_parent_class($this); $job_failure->string_metric5 = get_parent_class($this);
$job_failure->string_metric6 = $exception->getMessage(); $job_failure->string_metric6 = $exception->getMessage();

View File

@ -269,14 +269,36 @@ class CompanyGateway extends BaseModel
*/ */
public function calcGatewayFeeLabel($amount, Client $client, $gateway_type_id = GatewayType::CREDIT_CARD) :string public function calcGatewayFeeLabel($amount, Client $client, $gateway_type_id = GatewayType::CREDIT_CARD) :string
{ {
$label = ''; $label = ' ';
$fee = $this->calcGatewayFee($amount, $gateway_type_id); $fee = $this->calcGatewayFee($amount, $gateway_type_id);
if ($fee > 0) { // if ($fee > 0) {
$fee = Number::formatMoney(round($fee, 2), $client); // $fee = Number::formatMoney(round($fee, 2), $client);
$label = ' - '.$fee.' '.ctrans('texts.fee'); // $label = ' - '.$fee.' '.ctrans('texts.fee');
// }
if($fee > 0) {
$fees_and_limits = $this->fees_and_limits->{$gateway_type_id};
if(strlen($fees_and_limits->fee_percent) >=1)
$label .= $fees_and_limits->fee_percent . '%';
if(strlen($fees_and_limits->fee_amount) >=1){
if(strlen($label) > 1) {
$label .= ' + ' . Number::formatMoney($fees_and_limits->fee_amount, $client);
}else {
$label .= Number::formatMoney($fees_and_limits->fee_amount, $client);
} }
}
}
return $label; return $label;
} }

View File

@ -271,7 +271,7 @@ class BaseDriver extends AbstractPaymentDriver
$invoices->each(function ($invoice) use ($fee_total) { $invoices->each(function ($invoice) use ($fee_total) {
if (collect($invoice->line_items)->contains('type_id', '3')) { if (collect($invoice->line_items)->contains('type_id', '3')) {
$invoice->service()->toggleFeesPaid()->save(); $invoice->service()->toggleFeesPaid()->deletePdf()->save();
$invoice->client->service()->updateBalance($fee_total)->save(); $invoice->client->service()->updateBalance($fee_total)->save();
$invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for invoice {$invoice->number}"); $invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for invoice {$invoice->number}");
} }
@ -370,6 +370,12 @@ class BaseDriver extends AbstractPaymentDriver
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get(); $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get();
$invoices->each(function ($invoice){
$invoice->service()->deletePdf();
});
$invoices->first()->invitations->each(function ($invitation) use ($nmo){ $invoices->first()->invitations->each(function ($invitation) use ($nmo){
if ($invitation->contact->send_email && $invitation->contact->email) { if ($invitation->contact->send_email && $invitation->contact->email) {