Skip to content

Commit 8ea7517

Browse files
authored
Merge pull request #13 from web-vision/add-support-with-ninja5
Add support for Invoice Ninja version 5.8v.
2 parents abee394 + b765639 commit 8ea7517

File tree

5 files changed

+69
-51
lines changed

5 files changed

+69
-51
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [1.0.3]
5+
### Added
6+
- Add support for Invoice Ninja version 5.8v.
7+
48
## [1.0.2]
59
### Added
610
- Update installation steps in the documentation

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webvision/invoice-ninja-xrechnung",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "Add-on module for Invoice Ninja 5.x to create electronic invoices for Germany's xRechnung format",
55
"type": "library",
66
"license": "GPL-3.0-only",

src/Jobs/Entity/EmailEntity.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ public function __construct($invitation, Company $company, ?string $reminder_tem
103103
public function handle()
104104
{
105105
/* Don't fire emails if the company is disabled */
106-
if ($this->company->is_disabled)
106+
if ($this->company->is_disabled){
107107
return true;
108+
}
109+
110+
$this->email_entity_builder = $this->resolveEmailBuilder();
108111

109112
/* Set DB */
110113
MultiDB::setDB($this->company->db);
@@ -114,26 +117,24 @@ public function handle()
114117
App::setLocale($this->invitation->contact->preferredLocale());
115118
$t->replace(Ninja::transformTranslations($this->settings));
116119

120+
/* Mark entity sent */
121+
$this->entity->service()->markSent()->save();
122+
117123
$nmo = new NinjaMailerObject;
118-
$nmo->mailable = new TemplateEmail($this->email_entity_builder, $this->invitation->contact, $this->invitation);
119-
$nmo->company = $this->company;
124+
$nmo->mailable = new TemplateEmail($this->email_entity_builder, $this->invitation->contact->withoutRelations(), $this->invitation->withoutRelations());
125+
$nmo->company = $this->company->withoutRelations();
120126
$nmo->settings = $this->settings;
121-
$nmo->to_user = $this->invitation->contact;
127+
$nmo->to_user = $this->invitation->contact->withoutRelations();
122128
$nmo->entity_string = $this->entity_string;
123-
$nmo->invitation = $this->invitation;
129+
$nmo->invitation = $this->invitation->withoutRelations();
124130
$nmo->reminder_template = $this->reminder_template;
125-
$nmo->entity = $this->entity;
126-
131+
$nmo->entity = $this->entity->withoutRelations();
132+
127133
/**
128134
* Append file
129135
*/
130136
//$nmo->mailable->attachData('Test', $this->invitation->invoice->getFileName('xml'));
131-
132-
133-
NinjaMailerJob::dispatchNow($nmo);
134-
135-
/* Mark entity sent */
136-
$this->entity->service()->markSent()->save();
137+
NinjaMailerJob::dispatch($nmo);
137138
}
138139

139140
private function resolveEntityString() :string

src/Mail/TemplateEmail.php

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Illuminate\Bus\Queueable;
2424
use Illuminate\Mail\Mailable;
2525
use Illuminate\Queue\SerializesModels;
26+
use App\Utils\Ninja;
2627

2728
class TemplateEmail extends Mailable
2829
{
@@ -87,52 +88,64 @@ public function build()
8788

8889
$this->from(config('mail.from.address'), $email_from_name);
8990

90-
if (strlen($settings->bcc_email) > 1)
91-
$this->bcc(explode(",",str_replace(" ", "", $settings->bcc_email)));//remove whitespace if any has been inserted.
92-
93-
$this->subject($this->build_email->getSubject())
94-
->text('email.template.plain', [
95-
'body' => $this->build_email->getBody(),
96-
'footer' => $this->build_email->getFooter(),
97-
'whitelabel' => $this->client->user->account->isPaid() ? true : false,
98-
'settings' => $settings,
99-
])
100-
->view($template_name, [
101-
'greeting' => ctrans('texts.email_salutation', ['name' => $this->contact->present()->name()]),
102-
'body' => $this->build_email->getBody(),
103-
'footer' => $this->build_email->getFooter(),
104-
'view_link' => $this->build_email->getViewLink(),
105-
'view_text' => $this->build_email->getViewText(),
106-
'title' => '',
107-
'signature' => $signature,
108-
'settings' => $settings,
109-
'company' => $company,
110-
'whitelabel' => $this->client->user->account->isPaid() ? true : false,
111-
'logo' => $this->company->present()->logo(),
112-
])
113-
->withSwiftMessage(function ($message) use($company){
114-
$message->getHeaders()->addTextHeader('Tag', $company->company_key);
115-
$message->invitation = $this->invitation;
116-
});
91+
if (strlen($settings->bcc_email) > 1) {
92+
if (Ninja::isHosted()) {
11793

118-
foreach ($this->build_email->getAttachments() as $file) {
119-
120-
if(is_string($file))
121-
$this->attach($file);
122-
elseif(is_array($file))
123-
$this->attach($file['path'], ['as' => $file['name'], 'mime' => $file['mime']]);
94+
if($company->account->isPaid()) {
95+
$bccs = explode(',', str_replace(' ', '', $settings->bcc_email));
96+
$this->bcc(array_slice($bccs, 0, 5));
97+
}
12498

99+
} else {
100+
$this->bcc(explode(',', str_replace(' ', '', $settings->bcc_email)));
101+
}
125102
}
126103

127-
if($this->invitation && $this->invitation->invoice && $settings->ubl_email_attachment && $this->company->account->hasFeature(Account::FEATURE_DOCUMENTS)){
104+
$this->subject(str_replace("<br>", "", $this->build_email->getSubject()))
105+
->text('email.template.text', [
106+
'text_body' => $this->build_email->getTextBody(),
107+
'whitelabel' => $this->client->user->account->isPaid() ? true : false,
108+
'settings' => $settings,
109+
])
110+
->view($template_name, [
111+
'greeting' => ctrans('texts.email_salutation', ['name' => $this->contact->present()->name()]),
112+
'body' => $this->build_email->getBody(),
113+
'footer' => $this->build_email->getFooter(),
114+
'view_link' => $this->build_email->getViewLink(),
115+
'view_text' => $this->build_email->getViewText(),
116+
'title' => '',
117+
'signature' => $signature,
118+
'settings' => $settings,
119+
'company' => $company,
120+
'whitelabel' => $this->client->user->account->isPaid() ? true : false,
121+
'logo' => $this->company->present()->logo($settings),
122+
'links' => $this->build_email->getAttachmentLinks(),
123+
]);
128124

129-
$ubl_string = CreateZugferd::dispatchNow($this->invitation->invoice);
125+
foreach ($this->build_email->getAttachments() as $file) {
126+
if (array_key_exists('file', $file)) {
127+
$this->attachData(base64_decode($file['file']), $file['name']);
128+
} else {
129+
$this->attach($file['path'], ['as' => $file['name'], 'mime' => null]);
130+
}
131+
}
132+
133+
if($this->invitation && $this->invitation->invoice && $settings->ubl_email_attachment && $this->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)){
134+
$ubl_string = (new CreateZugferd($this->invitation->invoice))->handle();
130135

131136
nlog($ubl_string);
132137

133138
if($ubl_string)
134139
$this->attachData($ubl_string, $this->invitation->invoice->getFileName('xml'));
135140

141+
}
142+
if ($this->invitation && $this->invitation->invoice && $this->invitation->invoice->client->getSetting('enable_e_invoice') && $this->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) {
143+
$xml_string = $this->invitation->invoice->service()->getEInvoice($this->invitation->contact);
144+
145+
if($xml_string) {
146+
$this->attachData($xml_string, $this->invitation->invoice->getEFileName("xml"));
147+
}
148+
136149
}
137150

138151
return $this;

wiki.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ Ensure that you added all the highlighted fields in the Invoice. Navigate to **I
5454
## Installation
5555
In the root directory run the following commands using the command line
5656

57-
`composer update webvision/ninja-xrechnung --no-cache`
57+
`composer require webvision/invoice-ninja-xrechnung --no-cache`
5858

5959
`php artisan cache:clear && php artisan config:clear && php artisan route:clear`
6060

61-
Make sure to register `Webvision\NinjaZugferd\Providers\RouteServiceProvider::class` in the providers section of the root config/app.php file.
61+
Make sure to register `Webvision\NinjaZugferd\Providers\RouteServiceProvider::class` in the providers section of the root config/app.php file.

0 commit comments

Comments
 (0)