mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-12 14:12:44 +01:00
Code Cleanup
This commit is contained in:
parent
ccf47f2829
commit
1d24d211ee
@ -91,7 +91,7 @@ class InvitationController extends Controller
|
||||
|
||||
$file_name = $invitation->purchase_order->numberFormatter().'.pdf';
|
||||
|
||||
$file = (new CreatePurchaseOrderPdf($invitation))->handle();
|
||||
$file = (new CreatePurchaseOrderPdf($invitation))->rawPdf();
|
||||
|
||||
$headers = ['Content-Type' => 'application/pdf'];
|
||||
|
||||
|
@ -64,7 +64,12 @@ class Email implements ShouldQueue
|
||||
public function __construct(public EmailObject $email_object, public Company $company)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The backoff time between retries.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function backoff()
|
||||
{
|
||||
return [10, 30, 60, 240];
|
||||
@ -88,14 +93,24 @@ class Email implements ShouldQueue
|
||||
$this->tearDown();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the override flag
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setOverride(): self
|
||||
{
|
||||
$this->override = $this->email_object->override;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initilializes the models
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function initModels(): self
|
||||
{
|
||||
|
||||
@ -136,9 +151,16 @@ class Email implements ShouldQueue
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates the correct set of variables
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
private function resolveVariables(): self
|
||||
{
|
||||
$_variables = $this->email_object->variables;
|
||||
|
||||
match(class_basename($this->email_object->entity)){
|
||||
"Invoice" => $this->email_object->variables = (new HtmlEngine($this->email_object->invitation))->makeValues(),
|
||||
"Quote" => $this->email_object->variables = (new HtmlEngine($this->email_object->invitation))->makeValues(),
|
||||
@ -147,9 +169,20 @@ class Email implements ShouldQueue
|
||||
default => $this->email_object->variables = []
|
||||
};
|
||||
|
||||
/** If we have passed some variable overrides we insert them here */
|
||||
foreach($_variables as $key => $value)
|
||||
{
|
||||
$this->email_object->variables[$key] = $value;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* tearDown
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
private function tearDown(): self
|
||||
{
|
||||
|
||||
@ -164,7 +197,12 @@ class Email implements ShouldQueue
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Builds the email defaults
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setDefaults(): self
|
||||
{
|
||||
|
||||
@ -173,7 +211,12 @@ class Email implements ShouldQueue
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Populates the mailable
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function buildMailable(): self
|
||||
{
|
||||
|
||||
@ -182,7 +225,12 @@ class Email implements ShouldQueue
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to send the email
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function email()
|
||||
{
|
||||
|
||||
@ -600,7 +648,7 @@ class Email implements ShouldQueue
|
||||
* Logs any errors to the SystemLog
|
||||
*
|
||||
* @param string $errors
|
||||
* @param null | App\Models\Client $recipient_object
|
||||
* @param null | \App\Models\Client $recipient_object
|
||||
* @return void
|
||||
*/
|
||||
private function logMailError($errors, $recipient_object) :void
|
||||
@ -627,7 +675,7 @@ class Email implements ShouldQueue
|
||||
/**
|
||||
* Attempts to refresh the Microsoft refreshToken
|
||||
*
|
||||
* @param App\Models\User
|
||||
* @param \App\Models\User $user
|
||||
* @return mixed
|
||||
*/
|
||||
private function refreshOfficeToken(User $user): mixed
|
||||
|
@ -21,19 +21,19 @@ use App\Models\Invoice;
|
||||
use App\Models\PurchaseOrder;
|
||||
use App\Jobs\Invoice\CreateUbl;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Mail\Attachment;
|
||||
use App\Jobs\Entity\CreateRawPdf;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use App\DataMapper\EmailTemplateDefaults;
|
||||
use League\CommonMark\CommonMarkConverter;
|
||||
use App\Jobs\Vendor\CreatePurchaseOrderPdf;
|
||||
|
||||
class EmailDefaults
|
||||
{
|
||||
use MakesHash;
|
||||
/**
|
||||
* The settings object for this email
|
||||
* @var CompanySettings $settings
|
||||
* @var \App\DataMapper\CompanySettings $settings
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
@ -51,7 +51,6 @@ class EmailDefaults
|
||||
|
||||
/**
|
||||
* @param Email $email job class
|
||||
* @param EmailObject $email_object the email object class
|
||||
*/
|
||||
public function __construct(protected Email $email)
|
||||
{
|
||||
@ -67,7 +66,7 @@ class EmailDefaults
|
||||
{
|
||||
$this->settings = $this->email->email_object->settings;
|
||||
|
||||
$this->setLocale() //
|
||||
$this->setLocale()
|
||||
->setFrom()
|
||||
->setTo()
|
||||
->setTemplate()
|
||||
@ -159,7 +158,6 @@ class EmailDefaults
|
||||
*/
|
||||
private function setBody(): self
|
||||
{
|
||||
|
||||
if ($this->email->email_object->body) {
|
||||
// A Custom Message has been set in the email screen.
|
||||
return $this;
|
||||
@ -274,41 +272,43 @@ class EmailDefaults
|
||||
$documents = [];
|
||||
|
||||
/* Return early if the user cannot attach documents */
|
||||
if (!$this->email->email_object->settings->document_email_attachment || !$this->email->company->account->hasFeature(Account::FEATURE_DOCUMENTS))
|
||||
if (!$this->email->email_object->settings->document_email_attachment || !$this->email->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) {
|
||||
return $this;
|
||||
|
||||
if($this->email->email_object->entity instanceof PurchaseOrder) {
|
||||
|
||||
}
|
||||
else if($this->email->email_object->settings->pdf_email_attachment &&
|
||||
|
||||
/** Purchase Order / Invoice / Credit / Quote PDF */
|
||||
if ($this->email->email_object->entity instanceof PurchaseOrder) {
|
||||
$pdf = (new CreatePurchaseOrderPdf($this->email->email_object->invitation))->rawPdf();
|
||||
|
||||
$this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode($pdf), 'name' => $this->email->email_object->entity->numberFormatter().'.pdf']]);
|
||||
} elseif ($this->email->email_object->settings->pdf_email_attachment &&
|
||||
($this->email->email_object->entity instanceof Invoice ||
|
||||
$this->email->email_object->entity instanceof Quote ||
|
||||
$this->email->email_object->entity instanceof Credit)) {
|
||||
|
||||
$pdf = ((new CreateRawPdf($this->email->email_object->invitation, $this->email->company->db))->handle());
|
||||
|
||||
$this->email->email_object->attachments = array_merge($this->email->email_object->attachments, [['file' => base64_encode($pdf), 'name' => $this->email->email_object->entity->numberFormatter().'.pdf']]);
|
||||
}
|
||||
|
||||
}
|
||||
/* Company Documents */
|
||||
$this->email->email_object->documents = array_merge($this->email->email_object->documents, $this->email->company->documents->pluck('id')->toArray());
|
||||
|
||||
/** Entity Documents */
|
||||
if ($this->email->email_object->entity?->documents) {
|
||||
$this->email->email_object->documents = array_merge($this->email->email_object->documents, $this->email->email_object->entity->documents->pluck('id')->toArray());
|
||||
}
|
||||
|
||||
if ($this->email->email_object->entity instanceof Invoice && $this->email->email_object->entity->recurring_id != null){
|
||||
/** Recurring Invoice Documents */
|
||||
if ($this->email->email_object->entity instanceof Invoice && $this->email->email_object->entity->recurring_id != null) {
|
||||
$this->email->email_object->documents = array_merge($this->email->email_object->documents, $this->email->email_object->entity->recurring_invoice->documents->pluck('id')->toArray());
|
||||
}
|
||||
|
||||
/** Task / Expense Documents */
|
||||
if ($this->email->email_object->entity instanceof Invoice) {
|
||||
|
||||
$expense_ids = [];
|
||||
$task_ids = [];
|
||||
|
||||
foreach ($this->email->email_object->entity->line_items as $item)
|
||||
{
|
||||
|
||||
foreach ($this->email->email_object->entity->line_items as $item) {
|
||||
if (property_exists($item, 'expense_id')) {
|
||||
$expense_ids[] = $item->expense_id;
|
||||
}
|
||||
@ -316,11 +316,9 @@ class EmailDefaults
|
||||
if (property_exists($item, 'task_id')) {
|
||||
$task_ids[] = $item->task_id;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (count($expense_ids) > 0) {
|
||||
|
||||
Expense::whereIn('id', $this->transformKeys($expense_ids))
|
||||
->where('invoice_documents', 1)
|
||||
->cursor()
|
||||
@ -333,13 +331,12 @@ class EmailDefaults
|
||||
Task::whereIn('id', $this->transformKeys($task_ids))
|
||||
->cursor()
|
||||
->each(function ($task) {
|
||||
$this->email->email_object->documents = array_merge($this->email->email_object->documents, $task->documents->pluck('id')->toArray());
|
||||
$this->email->email_object->documents = array_merge($this->email->email_object->documents, $task->documents->pluck('id')->toArray());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** UBL xml file */
|
||||
if ($this->email->email_object->entity instanceof Invoice && $this->email->email_object->settings->ubl_email_attachment) {
|
||||
$ubl_string = (new CreateUbl($this->email->email_object->entity))->handle();
|
||||
|
||||
@ -349,7 +346,6 @@ class EmailDefaults
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,7 +129,7 @@ class HtmlEngine
|
||||
$data['$line_tax_labels'] = ['value' => $this->lineTaxLabels(), 'label' => ctrans('texts.taxes')];
|
||||
$data['$line_tax_values'] = ['value' => $this->lineTaxValues(), 'label' => ctrans('texts.taxes')];
|
||||
$data['$date'] = ['value' => $this->translateDate($this->entity->date, $this->client->date_format(), $this->client->locale()) ?: ' ', 'label' => ctrans('texts.date')];
|
||||
$data['$status_logo'] = ['value' => '', 'label' => ''];
|
||||
$data['$status_logo'] = ['value' => ' ', 'label' => ' '];
|
||||
|
||||
$data['$invoice.date'] = &$data['$date'];
|
||||
$data['$invoiceDate'] = &$data['$date'];
|
||||
|
@ -146,6 +146,7 @@ class VendorHtmlEngine
|
||||
$data['$entity.datetime'] = ['value' => $this->formatDatetime($this->entity->created_at, $this->company->date_format()), 'label' => ctrans('texts.date')];
|
||||
|
||||
$data['$po_number'] = &$data['$poNumber'];
|
||||
$data['$status_logo'] = ['value' => ' ', 'label' => ' '];
|
||||
$data['$entity'] = ['value' => '', 'label' => ctrans('texts.purchase_order')];
|
||||
$data['$number'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.purchase_order_number')];
|
||||
$data['$number_short'] = ['value' => $this->entity->number ?: ' ', 'label' => ctrans('texts.purchase_order_number_short')];
|
||||
|
Loading…
Reference in New Issue
Block a user