mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
EPC QR Codes WIP
This commit is contained in:
parent
f49ecbdcba
commit
a87b8d1e99
@ -15,6 +15,7 @@ use App\Libraries\MultiDB;
|
|||||||
use App\Models\Backup;
|
use App\Models\Backup;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Design;
|
use App\Models\Design;
|
||||||
|
use App\Models\Document;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
@ -76,29 +77,51 @@ class BackupUpdate extends Command
|
|||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
|
|
||||||
//logos
|
//logos
|
||||||
|
Company::cursor()
|
||||||
Company::query()
|
|
||||||
->cursor()
|
|
||||||
->each(function ($company){
|
->each(function ($company){
|
||||||
|
|
||||||
$logo = @file_get_contents($company->present()->logo());
|
$company_logo = $company->present()->logo();
|
||||||
|
|
||||||
|
if($company_logo == 'https://invoicing.co/images/new_logo.png')
|
||||||
|
return;
|
||||||
|
|
||||||
|
$logo = @file_get_contents($company_logo);
|
||||||
|
|
||||||
if($logo){
|
if($logo){
|
||||||
|
|
||||||
$path = str_replace("https://object.invoicing.co/", "", $company->present()->logo());
|
$path = str_replace("https://objects.invoicing.co/", "", $company->present()->logo());
|
||||||
$path = str_replace("https://v5-at-backup.us-southeast-1.linodeobjects.com/", "", $path);
|
$path = str_replace("https://v5-at-backup.us-southeast-1.linodeobjects.com/", "", $path);
|
||||||
|
|
||||||
Storage::disk($this->option('disk'))->put($path, $logo);
|
Storage::disk($this->option('disk'))->put($path, $logo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//documents
|
//documents
|
||||||
|
Document::cursor()
|
||||||
|
->each(function ($document){
|
||||||
|
|
||||||
|
$doc_bin = $document->getFile();
|
||||||
|
|
||||||
|
if($doc_bin)
|
||||||
|
Storage::disk($this->option('disk'))->put($document->url, $doc_bin);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
//backups
|
//backups
|
||||||
|
Backup::cursor()
|
||||||
|
->each(function ($backup){
|
||||||
|
|
||||||
|
$backup_bin = Storage::disk('s3')->get($backup->filename);
|
||||||
|
|
||||||
|
if($backup_bin)
|
||||||
|
Storage::disk($this->option('disk'))->put($backup->filename, $backup_bin);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,6 +102,9 @@ class ProductFilters extends QueryFilters
|
|||||||
{
|
{
|
||||||
$sort_col = explode('|', $sort);
|
$sort_col = explode('|', $sort);
|
||||||
|
|
||||||
|
if(!is_array($sort_col))
|
||||||
|
return $this->builder;
|
||||||
|
|
||||||
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
return $this->builder->orderBy($sort_col[0], $sort_col[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
78
app/Helpers/Epc/EpcQrGenerator.php
Normal file
78
app/Helpers/Epc/EpcQrGenerator.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Helpers\Epc;
|
||||||
|
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use BaconQrCode\Renderer\ImageRenderer;
|
||||||
|
use BaconQrCode\Renderer\Image\SvgImageBackEnd;
|
||||||
|
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
|
||||||
|
use BaconQrCode\Writer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EpcQrGenerator.
|
||||||
|
*/
|
||||||
|
class EpcQrGenerator
|
||||||
|
{
|
||||||
|
|
||||||
|
private array $sepa = [
|
||||||
|
'serviceTag' => 'BCD',
|
||||||
|
'version' => 2,
|
||||||
|
'characterSet' => 1,
|
||||||
|
'identification' => 'SCT',
|
||||||
|
'bic' => '',
|
||||||
|
'purpose' => '',
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct(protected Company $company, protected Invoice $invoice, protected float $amount){}
|
||||||
|
|
||||||
|
public function getQrCode()
|
||||||
|
{
|
||||||
|
|
||||||
|
$renderer = new ImageRenderer(
|
||||||
|
new RendererStyle(200),
|
||||||
|
new SvgImageBackEnd()
|
||||||
|
);
|
||||||
|
$writer = new Writer($renderer);
|
||||||
|
|
||||||
|
$qr = $writer->writeString($this->encodeMessage());
|
||||||
|
|
||||||
|
return "<svg viewBox='0 0 200 200' width='200' height='200' x='0' y='0' xmlns='http://www.w3.org/2000/svg'>
|
||||||
|
<rect x='0' y='0' width='100%'' height='100%' />{$qr}</svg>";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function encodeMessage()
|
||||||
|
{
|
||||||
|
|
||||||
|
return rtrim(implode("\n", array(
|
||||||
|
$this->sepa['serviceTag'],
|
||||||
|
sprintf('%03d', $this->sepa['version']),
|
||||||
|
$this->sepa['characterSet'],
|
||||||
|
$this->sepa['identification'],
|
||||||
|
$this->sepa['bic'],
|
||||||
|
$this->company->present()->name(),
|
||||||
|
$this->company?->custom_fields?->company1 ?: '',
|
||||||
|
$this->formatMoney($this->amount),
|
||||||
|
$this->sepa['purpose'],
|
||||||
|
substr($this->invoice->number,0,34),
|
||||||
|
substr($this->invoice->public_notes,0,139),
|
||||||
|
''
|
||||||
|
)), "\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function formatMoney($value) {
|
||||||
|
return sprintf('EUR%s', number_format($value, 2, '.', ''));
|
||||||
|
}
|
||||||
|
}
|
@ -1107,7 +1107,7 @@ class CompanyImport implements ShouldQueue
|
|||||||
|
|
||||||
$storage_url = (object)$this->getObject('storage_url', true);
|
$storage_url = (object)$this->getObject('storage_url', true);
|
||||||
|
|
||||||
if(!Storage::exists($new_document->url)){
|
if(!Storage::exists($new_document->url) && is_string($storage_url)){
|
||||||
|
|
||||||
$url = $storage_url . $new_document->url;
|
$url = $storage_url . $new_document->url;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user