mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Support bulk downloading PDFs
This commit is contained in:
parent
2bef0bdb66
commit
047a0fb2be
75
app/Jobs/DownloadInvoices.php
Normal file
75
app/Jobs/DownloadInvoices.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\User;
|
||||
use App\Ninja\Mailers\UserMailer;
|
||||
use Barracuda\ArchiveStream\Archive;
|
||||
|
||||
/**
|
||||
* Class SendInvoiceEmail.
|
||||
*/
|
||||
class DownloadInvoices extends Job implements ShouldQueue
|
||||
{
|
||||
use InteractsWithQueue, SerializesModels;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $invoices;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param mixed $files
|
||||
* @param mixed $settings
|
||||
*/
|
||||
public function __construct(User $user, $invoices)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->invoices = $invoices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @param ContactMailer $mailer
|
||||
*/
|
||||
public function handle(UserMailer $userMailer)
|
||||
{
|
||||
// if queues are disabled download a zip file
|
||||
if (config('queue.default') === 'sync') {
|
||||
$zip = Archive::instance_by_useragent(date('Y-m-d') . '-Invoice_PDFs');
|
||||
foreach ($this->invoices as $invoice) {
|
||||
$zip->add_file($invoice->getFileName(), $invoice->getPDFString());
|
||||
}
|
||||
$zip->finish();
|
||||
exit;
|
||||
|
||||
// otherwise sends the PDFs in an email
|
||||
} else {
|
||||
$data = [];
|
||||
foreach ($this->invoices as $invoice) {
|
||||
$data[] = [
|
||||
'name' => $invoice->getFileName(),
|
||||
'data' => $invoice->getPDFString(),
|
||||
];
|
||||
}
|
||||
|
||||
$subject = trans('texts.invoices_are_attached');
|
||||
$data = [
|
||||
'documents' => $data
|
||||
];
|
||||
|
||||
$userMailer->sendMessage($this->user, $subject, false, $data);
|
||||
}
|
||||
}
|
||||
}
|
@ -185,10 +185,15 @@ class InvoiceDatatable extends EntityDatatable
|
||||
|
||||
if ($this->entityType == ENTITY_INVOICE || $this->entityType == ENTITY_QUOTE) {
|
||||
$actions[] = \DropdownButton::DIVIDER;
|
||||
$actions[] = [
|
||||
'label' => mtrans($this->entityType, 'download_' . $this->entityType),
|
||||
'url' => 'javascript:submitForm_'.$this->entityType.'("download")',
|
||||
];
|
||||
$actions[] = [
|
||||
'label' => mtrans($this->entityType, 'email_' . $this->entityType),
|
||||
'url' => 'javascript:submitForm_'.$this->entityType.'("emailInvoice")',
|
||||
];
|
||||
$actions[] = \DropdownButton::DIVIDER;
|
||||
$actions[] = [
|
||||
'label' => mtrans($this->entityType, 'mark_sent'),
|
||||
'url' => 'javascript:submitForm_'.$this->entityType.'("markSent")',
|
||||
|
@ -119,14 +119,17 @@ class UserMailer extends Mailer
|
||||
/**
|
||||
* @param Invitation $invitation
|
||||
*/
|
||||
public function sendMessage($user, $subject, $message, $invoice = false)
|
||||
public function sendMessage($user, $subject, $message, $data = false)
|
||||
{
|
||||
if (! $user->email) {
|
||||
return;
|
||||
}
|
||||
|
||||
$invoice = $data && isset($data['invoice']) ? $data['invoice'] : false;
|
||||
$view = 'user_message';
|
||||
$data = [
|
||||
|
||||
$data = $data ?: [];
|
||||
$data += [
|
||||
'userName' => $user->getDisplayName(),
|
||||
'primaryMessage' => $subject,
|
||||
'secondaryMessage' => $message,
|
||||
|
@ -9,6 +9,7 @@ use App\Models\Invoice;
|
||||
use App\Ninja\Datatables\InvoiceDatatable;
|
||||
use App\Ninja\Repositories\ClientRepository;
|
||||
use App\Ninja\Repositories\InvoiceRepository;
|
||||
use App\Jobs\DownloadInvoices;
|
||||
use Auth;
|
||||
use Utils;
|
||||
|
||||
@ -54,6 +55,22 @@ class InvoiceService extends BaseService
|
||||
return $this->invoiceRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ids
|
||||
* @param $action
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function bulk($ids, $action)
|
||||
{
|
||||
if ($action == 'download') {
|
||||
$invoices = $this->getRepo()->findByPublicIdsWithTrashed($ids);
|
||||
dispatch(new DownloadInvoices(Auth::user(), $invoices));
|
||||
} else {
|
||||
return parent::bulk($ids, $action);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @param Invoice|null $invoice
|
||||
|
@ -140,7 +140,9 @@ class PaymentService extends BaseService
|
||||
$subject = trans('texts.auto_bill_failed', ['invoice_number' => $invoice->invoice_number]);
|
||||
$message = sprintf('%s: %s', ucwords($paymentDriver->providerName()), $exception->getMessage());
|
||||
$mailer = app('App\Ninja\Mailers\UserMailer');
|
||||
$mailer->sendMessage($invoice->user, $subject, $message, $invoice);
|
||||
$mailer->sendMessage($invoice->user, $subject, $message, [
|
||||
'invoice' => $invoice
|
||||
]);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
41
database/migrations/2017_07_18_124150_add_late_fees.php
Normal file
41
database/migrations/2017_07_18_124150_add_late_fees.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddLateFees extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('account_email_settings', function ($table) {
|
||||
$table->decimal('late_fee1_amount', 13, 2)->nullable();
|
||||
$table->decimal('late_fee1_percent', 13, 3)->nullable();
|
||||
$table->decimal('late_fee2_amount', 13, 2)->nullable();
|
||||
$table->decimal('late_fee2_percent', 13, 3)->nullable();
|
||||
$table->decimal('late_fee3_amount', 13, 2)->nullable();
|
||||
$table->decimal('late_fee3_percent', 13, 3)->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('account_email_settings', function ($table) {
|
||||
$table->dropColumn('late_fee1_amount');
|
||||
$table->dropColumn('late_fee1_percent');
|
||||
$table->dropColumn('late_fee2_amount');
|
||||
$table->dropColumn('late_fee2_percent');
|
||||
$table->dropColumn('late_fee3_amount');
|
||||
$table->dropColumn('late_fee3_percent');
|
||||
});
|
||||
}
|
||||
}
|
@ -2308,6 +2308,9 @@ $LANG = array(
|
||||
'late_fee_amount' => 'Late Fee Amount',
|
||||
'late_fee_percent' => 'Late Fee Percent',
|
||||
'late_fee_added' => 'Late fee added on :date',
|
||||
'download_invoice' => 'Download Invoice',
|
||||
'download_quote' => 'Download Quote',
|
||||
'invoices_are_attached' => 'Your invoice PDFs are attached.',
|
||||
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user