Merge pull request #10303 from turbo124/v5-develop

v5.10.55
This commit is contained in:
David Bomba 2024-11-23 15:37:15 +11:00 committed by GitHub
commit b5a3abdb36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 151 additions and 43 deletions

View File

@ -1 +1 @@
5.10.54
5.10.55

View File

@ -0,0 +1,52 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Events\Socket;
use App\Models\User;
use League\Fractal\Manager;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use App\Utils\Traits\Invoice\Broadcasting\DefaultResourceBroadcast;
/**
* Class DownloadAvailable.
*/
class DownloadAvailable implements ShouldBroadcast
{
use SerializesModels;
use InteractsWithSockets;
public function __construct(public string $url, public string $message, public User $user)
{
}
public function broadcastOn()
{
return [
new PrivateChannel("user-{$this->user->account->key}-{$this->user->id}"),
];
}
public function broadcastWith(): array
{
ctrans('texts.document_download_subject');
return [
'message' => $this->message,
'url' => $this->url,
];
}
}

View File

@ -66,8 +66,6 @@ class EInvoiceController extends BaseController
$payment_means_array = $request->input('payment_means', []);
nlog($payment_means_array);
$einvoice->PaymentMeans = [];
foreach ($payment_means_array as $payment_means) {

View File

@ -53,14 +53,14 @@ class UpdateEntityRequest extends FormRequest
$this->replace($input);
}
public function after(): array
{
return [
function (Validator $validator) {
if ($this->input('acts_as_sender') === false && $this->input('acts_as_receiver') === false) {
$validator->errors()->add('acts_as_receiver', ctrans('texts.acts_as_must_be_true'));
}
}
];
}
// public function after(): array
// {
// return [
// function (Validator $validator) {
// if ($this->input('acts_as_sender') === false && $this->input('acts_as_receiver') === false) {
// $validator->errors()->add('acts_as_receiver', ctrans('texts.acts_as_must_be_true'));
// }
// }
// ];
// }
}

View File

@ -14,12 +14,14 @@ namespace App\Import\Transformer\Csv;
use App\Import\ImportException;
use App\Import\Transformer\BaseTransformer;
use App\Models\Invoice;
use App\Utils\Traits\CleanLineItems;
/**
* Class InvoiceTransformer.
*/
class InvoiceTransformer extends BaseTransformer
{
use CleanLineItems;
/**
* @param $data
*
@ -224,7 +226,7 @@ class InvoiceTransformer extends BaseTransformer
];
}
$transformed['line_items'] = $line_items;
$transformed['line_items'] = $this->cleanItems($line_items);
return $transformed;
}

View File

@ -14,12 +14,15 @@ namespace App\Import\Transformer\Csv;
use App\Import\ImportException;
use App\Import\Transformer\BaseTransformer;
use App\Models\Quote;
use App\Utils\Traits\CleanLineItems;
/**
* Class QuoteTransformer.
*/
class QuoteTransformer extends BaseTransformer
{
use CleanLineItems;
/**
* @param $data
*
@ -120,7 +123,7 @@ class QuoteTransformer extends BaseTransformer
$this->getString($quote_data, 'quote.status')
))
] ?? Quote::STATUS_SENT,
'archived' => $status === 'archived',
// 'archived' => $status === 'archived',
];
/* If we can't find the client, then lets try and create a client */
@ -221,7 +224,7 @@ class QuoteTransformer extends BaseTransformer
'type_id' => '1', //$this->getQuoteTypeId( $record, 'item.type_id' ),
];
}
$transformed['line_items'] = $line_items;
$transformed['line_items'] = $this->cleanItems($line_items);
return $transformed;
}

View File

@ -15,12 +15,15 @@ use App\Import\ImportException;
use App\Import\Transformer\BaseTransformer;
use App\Models\Invoice;
use App\Models\RecurringInvoice;
use App\Utils\Traits\CleanLineItems;
/**
* Class RecurringInvoiceTransformer.
*/
class RecurringInvoiceTransformer extends BaseTransformer
{
use CleanLineItems;
/**
* @param $data
*
@ -187,7 +190,7 @@ class RecurringInvoiceTransformer extends BaseTransformer
];
}
$transformed['line_items'] = $line_items;
$transformed['line_items'] = $this->cleanItems($line_items);
return $transformed;
}

View File

@ -11,20 +11,22 @@
namespace App\Jobs\Invoice;
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Jobs\Util\UnlinkFile;
use App\Libraries\MultiDB;
use App\Mail\DownloadInvoices;
use App\Models\User;
use App\Models\Company;
use App\Models\Invoice;
use App\Models\User;
use App\Libraries\MultiDB;
use App\Jobs\Util\UnlinkFile;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use App\Mail\DownloadInvoices;
use App\Jobs\Mail\NinjaMailerJob;
use Illuminate\Support\Facades\App;
use App\Jobs\Mail\NinjaMailerObject;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;
use App\Events\Socket\DownloadAvailable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class ZipInvoices implements ShouldQueue
{
@ -55,11 +57,10 @@ class ZipInvoices implements ShouldQueue
public function handle(): void
{
MultiDB::setDb($this->company->db);
App::setLocale($this->company->locale());
$settings = $this->company->settings;
nlog(count($this->invoices));
$this->invoices = Invoice::withTrashed()
->where('company_id', $this->company->id)
->whereIn('id', $this->invoices)
@ -99,9 +100,10 @@ class ZipInvoices implements ShouldQueue
}
Storage::put($path.$file_name, $zipFile->outputAsString());
$storage_url = Storage::url($path.$file_name);
$nmo = new NinjaMailerObject();
$nmo->mailable = new DownloadInvoices(Storage::url($path.$file_name), $this->company);
$nmo->mailable = new DownloadInvoices($storage_url, $this->company);
$nmo->to_user = $this->user;
$nmo->settings = $settings;
$nmo->company = $this->company;
@ -110,6 +112,11 @@ class ZipInvoices implements ShouldQueue
UnlinkFile::dispatch(config('filesystems.default'), $path.$file_name)->delay(now()->addHours(1));
$message = count($this->invoices). " ". ctrans('texts.invoices');
$message = ctrans('texts.download_ready', ['message' => $message]);
broadcast(new DownloadAvailable($storage_url, $message, $this->user));
} catch (\PhpZip\Exception\ZipException $e) {
nlog('could not make zip => '.$e->getMessage());
} finally {

View File

@ -12,6 +12,7 @@
namespace App\Services\EDocument\Standards;
use App\DataMapper\InvoiceItem;
use App\Models\Company;
use App\Models\Credit;
use App\Models\Invoice;
use App\Models\Product;
@ -44,7 +45,6 @@ class ZugferdEDokument extends AbstractService
/** @var \App\Models\Company $company */
$company = $this->document->company;
/** @var \App\Models\Client $client */
$client = $this->document->client;
@ -122,14 +122,8 @@ class ZugferdEDokument extends AbstractService
if (isset($client->shipping_address1) && $client->shipping_country) {
$this->xdocument->setDocumentShipToAddress($client->shipping_address1, $client->shipping_address2, "", $client->shipping_postal_code, $client->shipping_city, $client->shipping_country->iso_3166_2, $client->shipping_state);
}
$custom_value1 = $company->settings->custom_value1;
//BR-DE-23 - If „Payment means type code“ (BT-81) contains a code for credit transfer (30, 58), „CREDIT TRANSFER“ (BG-17) shall be provided.
//Payment Means - Switcher
if (isset($custom_value1) && !empty($custom_value1) && ($custom_value1 == '30' || $custom_value1 == '58')) {
$this->xdocument->addDocumentPaymentMean(typecode: $company->settings->custom_value1, payeeIban: $company->settings->custom_value2, payeeAccountName: $company->settings->custom_value4, payeeBic: $company->settings->custom_value3);
} else {
$this->xdocument->addDocumentPaymentMean('68', ctrans("texts.xinvoice_online_payment"));
}
$this->injectPaymentMeans($company);
if (str_contains($company->getSetting('vat_number'), "/")) {
$this->xdocument->addDocumentSellerTaxRegistration("FC", $company->getSetting('vat_number'));
@ -265,7 +259,50 @@ class ZugferdEDokument extends AbstractService
return $this;
}
/**
*
* Expanded functionality to allow injecting UBL Payment Means
* into the document
*
* @return self
*/
private function injectPaymentMeans(Company $company): self
{
/**Check if the e_invoice object is populated */
if(isset($company->e_invoice->Invoice->PaymentMeans) && ($pm = $company->e_invoice->Invoice->PaymentMeans[0] ?? false)){
switch ($pm->PaymentMeansCode->value ?? false) {
case '30':
case '58':
$iban = $pm->PayeeFinancialAccount->ID->value;
$name = $pm->PayeeFinancialAccount->Name ?? '';
$bic = $pm->PayeeFinancialAccount->FinancialInstitutionBranch->FinancialInstitution->ID->value ?? '';
$typecode = $pm->PaymentMeansCode->value;
$this->xdocument->addDocumentPaymentMean(typecode: $typecode, payeeIban: $iban, payeeAccountName: $name, payeeBic: $bic);
return $this;
default:
# code...
break;
}
}
$custom_value1 = $company->settings->custom_value1;
//BR-DE-23 - If „Payment means type code“ (BT-81) contains a code for credit transfer (30, 58), „CREDIT TRANSFER“ (BG-17) shall be provided.
//Payment Means - Switcher
if (isset($custom_value1) && !empty($custom_value1) && ($custom_value1 == '30' || $custom_value1 == '58')) {
$this->xdocument->addDocumentPaymentMean(typecode: $company->settings->custom_value1, payeeIban: $company->settings->custom_value2, payeeAccountName: $company->settings->custom_value4, payeeBic: $company->settings->custom_value3);
} else {
$this->xdocument->addDocumentPaymentMean('68', ctrans("texts.xinvoice_online_payment"));
}
return $this;
}
/**
* Returns the XML document
* in string format

View File

@ -17,8 +17,8 @@ return [
'require_https' => env('REQUIRE_HTTPS', true),
'app_url' => rtrim(env('APP_URL', ''), '/'),
'app_domain' => env('APP_DOMAIN', 'invoicing.co'),
'app_version' => env('APP_VERSION', '5.10.54'),
'app_tag' => env('APP_TAG', '5.10.54'),
'app_version' => env('APP_VERSION', '5.10.55'),
'app_tag' => env('APP_TAG', '5.10.55'),
'minimum_client_version' => '5.0.16',
'terms_version' => '1.0.1',
'api_secret' => env('API_SECRET', false),

View File

@ -5474,6 +5474,7 @@ $lang = array(
'delete_identifier' => 'Delete identifier',
'delete_identifier_description' => 'Deleting this identifier will remove it from the system. Make sure this is the desired action before proceeding.',
'einvoice_something_went_wrong' => 'Oops! Something went wrong. Contact us at contact@invoiceninja.com for more information.',
'download_ready' => 'Your Download is now ready! [ :message ]',
);
return $lang;

View File

@ -14,3 +14,8 @@
Broadcast::channel('company-{company_key}', function (\App\Models\User $user, string $company_key) {
return $user->company()->company_key === $company_key;
});
Broadcast::channel('user-{account_key}-{user_id}', function (\App\Models\User $user, string $account_key, string $user_id) {
return $user->account->key === $account_key && $user->id === (int)$user_id;
});

View File

@ -63,12 +63,12 @@ class LicenseTest extends TestCase
{
$tes = [
[
'legal_entity_id' => rand(1,100),
'legal_entity_id' => 22,
'company_key' => \Illuminate\Support\Str::random(32),
'received_documents' => []
],
[
'legal_entity_id' => rand(1,100),
'legal_entity_id' => 33,
'company_key' => \Illuminate\Support\Str::random(32),
'received_documents' => []
],