Refactor for public/private documents

This commit is contained in:
David Bomba 2023-09-11 10:13:13 +10:00
parent f9925e0486
commit e2542e33bd
7 changed files with 28 additions and 31 deletions

View File

@ -123,21 +123,21 @@ class CreditEmailEngine extends BaseEmailEngine
//attach third party documents
if ($this->client->getSetting('document_email_attachment') !== false && $this->credit->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) {
// Storage::url
foreach ($this->credit->documents as $document) {
$this->credit->documents()->where('is_public',true)->cursor()->each(function($document) {
if ($document->size > $this->max_attachment_size) {
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
} else {
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null, 'file' => base64_encode($document->getFile())]]);
}
}
});
foreach ($this->credit->company->documents as $document) {
$this->credit->company->documents()->where('is_public',true)->cursor()->each(function($document) {
if ($document->size > $this->max_attachment_size) {
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
} else {
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null, 'file' => base64_encode($document->getFile())]]);
}
}
});
}
return $this;

View File

@ -135,31 +135,31 @@ class InvoiceEmailEngine extends BaseEmailEngine
//attach third party documents
if ($this->client->getSetting('document_email_attachment') !== false && $this->invoice->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) {
if ($this->invoice->recurring_invoice()->exists()) {
foreach ($this->invoice->recurring_invoice->documents as $document) {
$this->invoice->recurring_invoice->documents()->where('is_public',true)->cursor()->each(function ($document) {
if ($document->size > $this->max_attachment_size) {
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
} else {
$this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => null, ]]);
}
}
});
}
// Storage::url
foreach ($this->invoice->documents as $document) {
$this->invoice->documents()->where('is_public',true)->cursor()->each(function ($document) {
if ($document->size > $this->max_attachment_size) {
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
} else {
$this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => null, ]]);
}
}
});
foreach ($this->invoice->company->documents as $document) {
$this->invoice->company->documents()->where('is_public',true)->cursor()->each(function ($document) {
if ($document->size > $this->max_attachment_size) {
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
} else {
$this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => null, ]]);
}
}
});
$line_items = $this->invoice->line_items;
@ -175,13 +175,13 @@ class InvoiceEmailEngine extends BaseEmailEngine
->where('invoice_documents', 1)
->cursor()
->each(function ($expense) {
foreach ($expense->documents as $document) {
$expense->documents()->where('is_public',true)->cursor()->each(function ($document) {
if ($document->size > $this->max_attachment_size) {
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
} else {
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null, ]]);
}
}
});
});
}
@ -195,13 +195,13 @@ class InvoiceEmailEngine extends BaseEmailEngine
$tasks = Task::query()->whereIn('id', $this->transformKeys($task_ids))
->cursor()
->each(function ($task) {
foreach ($task->documents as $document) {
$task->documents()->where('is_public', true)->cursor()->each(function ($document) {
if ($document->size > $this->max_attachment_size) {
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
} else {
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null, ]]);
}
}
});
});
}
}

View File

@ -98,13 +98,13 @@ class PaymentEmailEngine extends BaseEmailEngine
//attach invoice documents also to payments
if ($this->client->getSetting('document_email_attachment') !== false) {
foreach ($invoice->documents as $document) {
$invoice->documents()->where('is_public', true)->cursor()->each(function ($document){
if ($document->size > $this->max_attachment_size) {
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
} else {
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null, ]]);
}
}
});
}
if($this->client->getSetting('enable_e_invoice'))

View File

@ -127,21 +127,21 @@ class PurchaseOrderEmailEngine extends BaseEmailEngine
//attach third party documents
if ($this->vendor->getSetting('document_email_attachment') !== false && $this->purchase_order->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) {
// Storage::url
foreach ($this->purchase_order->documents as $document) {
$this->purchase_order->documents()->where('is_public', true)->cursor()->each(function ($document) {
if ($document->size > $this->max_attachment_size) {
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
} else {
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]);
}
}
});
foreach ($this->purchase_order->company->documents as $document) {
$this->purchase_order->company->documents()->where('is_public', true)->cursor()->each(function ($document) {
if ($document->size > $this->max_attachment_size) {
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
} else {
$this->setAttachments([['path' => $document->filePath(), 'name' => $document->name, 'mime' => null]]);
}
}
});
}
return $this;

View File

@ -121,21 +121,21 @@ class QuoteEmailEngine extends BaseEmailEngine
//attach third party documents
if ($this->client->getSetting('document_email_attachment') !== false && $this->quote->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) {
// Storage::url
foreach ($this->quote->documents as $document) {
$this->quote->documents()->where('is_public', true)->cursor()->each(function ($document) {
if ($document->size > $this->max_attachment_size) {
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
} else {
$this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => null, ]]);
}
}
});
foreach ($this->quote->company->documents as $document) {
$this->quote->company->documents()->where('is_public', true)->cursor()->each(function ($document) {
if ($document->size > $this->max_attachment_size) {
$this->setAttachmentLinks(["<a class='doc_links' href='" . URL::signedRoute('documents.public_download', ['document_hash' => $document->hash]) ."'>". $document->name ."</a>"]);
} else {
$this->setAttachments([['file' => base64_encode($document->getFile()), 'path' => $document->filePath(), 'name' => $document->name, 'mime' => null, ]]);
}
}
});
}
return $this;

View File

@ -365,7 +365,7 @@ class EmailDefaults
->where('invoice_documents', 1)
->cursor()
->each(function ($expense) {
$this->email->email_object->documents = array_merge($this->email->email_object->documents, $expense->documents->pluck('id')->toArray());
$this->email->email_object->documents = array_merge($this->email->email_object->documents, $expense->documents()->where('is_public',true)->pluck('id')->toArray());
});
}
@ -373,7 +373,7 @@ class EmailDefaults
Task::query()->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()->where('is_public',true)->pluck('id')->toArray());
});
}
}

View File

@ -657,8 +657,6 @@ $LANG = array(
'created_by_invoice' => 'Created by :invoice',
'primary_user' => 'Primary User',
'help' => 'Help',
'customize_help' => '<p>We use :pdfmake_link to define the invoice designs declaratively. The pdfmake :playground_link provides a great way to see the library in action.</p>
<p>If you need help figuring something out post a question to our :forum_link with the design you\'re using.</p>',
'playground' => 'playground',
'support_forum' => 'Support Forums',
'invoice_due_date' => 'Due Date',
@ -1822,7 +1820,6 @@ $LANG = array(
'bot_emailed_notify_paid' => 'I\'ll email you when it\'s paid.',
'add_product_to_invoice' => 'Add 1 :product',
'not_authorized' => 'You are not authorized',
'bot_get_email' => 'Hi! (wave)<br/>Thanks for trying the Invoice Ninja Bot.<br/>You need to create a free account to use this bot.<br/>Send me your account email address to get started.',
'bot_get_code' => 'Thanks! I\'ve sent a you an email with your security code.',
'bot_welcome' => 'That\'s it, your account is verified.<br/>',
'email_not_found' => 'I wasn\'t able to find an available account for :email',
@ -1830,7 +1827,6 @@ $LANG = array(
'security_code_email_subject' => 'Security code for Invoice Ninja Bot',
'security_code_email_line1' => 'This is your Invoice Ninja Bot security code.',
'security_code_email_line2' => 'Note: it will expire in 10 minutes.',
'bot_help_message' => 'I currently support:<br/>• Create\update\email an invoice<br/>• List products<br/>For example:<br/><i>invoice bob for 2 tickets, set the due date to next thursday and the discount to 10 percent</i>',
'list_products' => 'List Products',
'include_item_taxes_inline' => 'Include <b>line item taxes in line total</b>',
@ -1843,7 +1839,6 @@ $LANG = array(
'update_invoiceninja_warning' => 'Before start upgrading Invoice Ninja create a backup of your database and files!',
'update_invoiceninja_available' => 'A new version of Invoice Ninja is available.',
'update_invoiceninja_unavailable' => 'No new version of Invoice Ninja available.',
'update_invoiceninja_instructions' => 'Please install the new version <strong>:version</strong> by clicking the <em>Update now</em> button below. Afterwards you\'ll be redirected to the dashboard.',
'update_invoiceninja_update_start' => 'Update now',
'update_invoiceninja_download_start' => 'Download :version',
'create_new' => 'Create New',
@ -5161,6 +5156,8 @@ $LANG = array(
'show_document_preview' => 'Show Document Preview',
'cash_accounting' => 'Cash accounting',
'click_or_drop_files_here' => 'Click or drop files here',
'set_as_public' => 'Set as public',
'set_as_private' => 'Set as private',
);
return $LANG;