1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/app/Jobs/Invoice/ZipInvoices.php
David Bomba a79c7bf60d
Code Cleanup
* Working on emailing invoices

* Working on emailing and displaying email

* Working on emailing and displaying email

* Email invoices

* Fixes for html emails

* Ensure valid client prior to store

* Ensure client exists when storing an entity

* refactor for emails

* Design Transformer

* Include designs in first_load response

* Code cleanup
2020-02-15 20:06:30 +11:00

85 lines
2.0 KiB
PHP

<?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\Jobs\Invoice;
use App\Libraries\MultiDB;
use App\Models\Company;
use App\Models\Invoice;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use ZipStream\Option\Archive;
use ZipStream\ZipStream;
use Illuminate\Support\Facades\Storage;
class ZipInvoices implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $invoice;
private $company;
/**
* @deprecated confirm to be deleted
* Create a new job instance.
*
* @return void
*/
public function __construct($invoices, Company $company)
{
$this->invoices = $invoices;
$this->company = $company;
}
/**
* Execute the job.
*
*
* @return void
*/
public function handle()
{
MultiDB::setDB($this->company->db);
$tempStream = fopen('php://memory', 'w+');
$options = new Archive();
$options->setOutputStream($tempStream);
# create a new zipstream object
$file_name = date('Y-m-d') . '_' . str_replace(' ', '_', trans('texts.invoices')).".zip";
$path = $this->invoices->first()->client->invoice_filepath();
$zip = new ZipStream($file_name, $options);
foreach ($invoices as $invoice) {
$zip->addFileFromPath(basename($invoice->pdf_file_path()), public_path($invoice->pdf_file_path()));
}
$zip->finish();
Storage::disk(config('filesystems.default'))->put($path . $file_name, $tempStream);
fclose($tempStream);
//fire email here
return Storage::disk(config('filesystems.default'))->url($path . $file_name);
}
}