Skip to content

Commit 58b70c8

Browse files
committed
Send invoice mailer
1 parent 6aa5c7e commit 58b70c8

File tree

6 files changed

+350
-4
lines changed

6 files changed

+350
-4
lines changed

resources/views/mail/templates/send-invoice/message.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
The amount outstanding of {{ money($invoice->total, $invoice->currency) }} is due on {{ $invoice->due_date->format('d M Y') }}.
66

7-
View and pay your bill online: [Online Invoice Link]
7+
View and pay your invoice online: [Online Invoice Link]
88

9-
From your online bill you can print a PDF, export a CSV, or create a free login and view your outstanding bills.
9+
From your online invoice you can print a PDF version.
1010

1111
If you have any questions, please let us know.
1212

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
@extends('laravel-crm::layouts.portal')
2+
3+
@section('content')
4+
5+
<header>
6+
<nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm fixed-top">
7+
<div class="container-fluid">
8+
<h1 class="navbar-brand mb-0" href="#">
9+
{{ money($invoice->total, $invoice->currency) }} {{ $invoice->currency }}
10+
{{--@if($invoice->accepted_at)
11+
<small><span class="badge badge-success">{{ ucfirst(__('laravel-crm::lang.accepted')) }}</span></small>
12+
@elseif($invoice->rejected_at)
13+
<small><span class="badge badge-danger">{{ ucfirst(__('laravel-crm::lang.rejected')) }}</span></small>
14+
@elseif(\Carbon\Carbon::now() <= $invoice->expire_at)
15+
<small><span class="badge badge-secondary">{{ ucfirst(__('laravel-crm::lang.expires_in')) }} {{ $invoice->expire_at->diffForHumans() }}</span></small>
16+
@else
17+
<small><span class="badge badge-danger">{{ ucfirst(__('laravel-crm::lang.invoice_expired')) }}</span></small>
18+
@endif--}}
19+
</h1>
20+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
21+
<ul class="navbar-nav ml-auto">
22+
{{-- @if($invoice->accepted_at)
23+
<div class="alert alert-success m-0" role="alert">
24+
{{ ucfirst(__('laravel-crm::lang.you_have_accepted_this_invoice')) }}.
25+
</div>
26+
@elseif($invoice->rejected_at)
27+
<div class="alert alert-danger m-0" role="alert">
28+
{{ ucfirst(__('laravel-crm::lang.you_have_rejected_this_invoice')) }}.
29+
</div>
30+
@elseif(\Carbon\Carbon::now() <= $invoice->expire_at)
31+
<li class="nav-item mr-2">
32+
<form action="{{ url()->current() }}?signature={{ request()->input('signature') }}" method="POST" class="form-check-inline mr-0">
33+
{{ csrf_field() }}
34+
<x-form-input name="action" value="accept" type="hidden" />
35+
<button class="btn btn-outline-success" type="submit">{{ ucfirst(__('laravel-crm::lang.accept')) }}</button>
36+
</form>
37+
</li>
38+
<li class="nav-item mr-2">
39+
<form action="{{ url()->current() }}?signature={{ request()->input('signature') }}" method="POST" class="form-check-inline mr-0">
40+
{{ csrf_field() }}
41+
<x-form-input name="action" value="reject" type="hidden" />
42+
<button class="btn btn-outline-danger" type="submit">{{ ucfirst(__('laravel-crm::lang.reject')) }}</button>
43+
</form>
44+
</li>
45+
@endif--}}
46+
{{--<li class="nav-item">
47+
<a class="btn btn-outline-secondary" href="#">Download</a>
48+
</li>--}}
49+
</ul>
50+
</div>
51+
</div>
52+
</nav>
53+
</header>
54+
55+
<main role="main" class="flex-shrink-0">
56+
<div class="container">
57+
<div class="row card shadow-sm mb-4">
58+
<div class="card-body p-0">
59+
<div class="row">
60+
<div class="col px-5 py-4">
61+
<h1 class="card-title pricing-card-title py-4 m-0">{{ ucfirst(__('laravel-crm::lang.invoice')) }}</h1>
62+
</div>
63+
<div class="col px-5 py-4 text-right">
64+
@if($logo)
65+
<img src="{{ asset('storage/'.$logo) }}" height="80" />
66+
@endif
67+
</div>
68+
</div>
69+
<hr class="m-0" />
70+
<div class="row">
71+
<div class="col px-5 py-4">
72+
<div class="row py-1">
73+
<div class="col-3">
74+
<strong>{{ ucfirst(__('laravel-crm::lang.to')) }}</strong>
75+
</div>
76+
<div class="col">
77+
{{ $invoice->organisation->name ?? $invoice->organisation->person->name }}<br />
78+
@if(isset($organisation_address))
79+
@if($organisation_address->line2)
80+
{{ $organisation_address->line1 }}<br />
81+
@endif
82+
@if($organisation_address->line2)
83+
{{ $organisation_address->line2 }}<br />
84+
@endif
85+
@if($organisation_address->line3)
86+
{{ $organisation_address->line3 }}<br />
87+
@endif
88+
@if($organisation_address->city || $organisation_address->state || $organisation_address->postcode)
89+
{{ $organisation_address->city }} {{ $organisation_address->state }} {{ $organisation_address->postcode }}<br />
90+
@endif
91+
{{ $organisation_address->country }}
92+
@elseif($address)
93+
{{ $address->line1 }}<br />
94+
@if($address->line2)
95+
{{ $address->line2 }}<br />
96+
@endif
97+
@if($address->line3)
98+
{{ $address->line3 }}<br />
99+
@endif
100+
{{ $address->city }}<br />
101+
{{ $address->country }}
102+
@endif
103+
</div>
104+
</div>
105+
@if($invoice->reference)
106+
<div class="row py-1">
107+
<div class="col-3">
108+
<strong>{{ ucfirst(__('laravel-crm::lang.reference')) }}</strong>
109+
</div>
110+
<div class="col">
111+
{{ $invoice->reference }}
112+
</div>
113+
</div>
114+
@endif
115+
@if($invoice->issue_date)
116+
<div class="row py-1">
117+
<div class="col-3">
118+
<strong>{{ ucfirst(__('laravel-crm::lang.issue_date')) }}</strong>
119+
</div>
120+
<div class="col">
121+
{{ $invoice->issue_date->toFormattedDateString() }}
122+
</div>
123+
</div>
124+
@endif
125+
@if($invoice->due_date)
126+
<div class="row py-1">
127+
<div class="col-3">
128+
<strong>{{ ucfirst(__('laravel-crm::lang.due_date')) }}</strong>
129+
</div>
130+
<div class="col">
131+
{{ $invoice->due_date->toFormattedDateString() }}
132+
</div>
133+
</div>
134+
@endif
135+
</div>
136+
<div class="col px-5 py-4">
137+
<div class="row py-1">
138+
<div class="col-3">
139+
<strong>{{ ucfirst(__('laravel-crm::lang.from')) }}</strong>
140+
</div>
141+
<div class="col">
142+
{{ $fromName }}<br />
143+
{{-- 19-21 South Steyne<br />
144+
MANLY NSW 2095<br />
145+
Australia--}}
146+
</div>
147+
</div>
148+
</div>
149+
</div>
150+
<hr />
151+
<div class="row py-1">
152+
<div class="col px-5 py-1">
153+
<table class="table table-hover mb-0">
154+
<thead>
155+
<tr>
156+
<th scope="col">{{ ucfirst(__('laravel-crm::lang.item')) }}</th>
157+
<th scope="col">{{ ucfirst(__('laravel-crm::lang.price')) }}</th>
158+
<th scope="col">{{ ucfirst(__('laravel-crm::lang.quantity')) }}</th>
159+
<th scope="col">{{ ucfirst(__('laravel-crm::lang.amount')) }}</th>
160+
</tr>
161+
</thead>
162+
<tbody>
163+
@foreach($invoice->invoiceLines()->whereNotNull('product_id')->get() as $invoiceLine)
164+
<tr>
165+
<td>{{ $invoiceLine->product->name }}</td>
166+
<td>{{ money($invoiceLine->price ?? null, $invoiceLine->currency) }}</td>
167+
<td>{{ $invoiceLine->quantity }}</td>
168+
<td>{{ money($invoiceLine->amount ?? null, $invoiceLine->currency) }}</td>
169+
</tr>
170+
@endforeach
171+
</tbody>
172+
<tfoot>
173+
<tr>
174+
<td></td>
175+
<td></td>
176+
<td><strong>{{ ucfirst(__('laravel-crm::lang.sub_total')) }}</strong></td>
177+
<td>{{ money($invoice->subtotal, $invoice->currency) }}</td>
178+
</tr>
179+
@if($invoice->discount > 0)
180+
<tr>
181+
<td></td>
182+
<td></td>
183+
<td><strong>{{ ucfirst(__('laravel-crm::lang.discount')) }}</strong></td>
184+
<td>{{ money($invoice->discount, $invoice->currency) }}</td>
185+
</tr>
186+
@endif
187+
<tr>
188+
<td></td>
189+
<td></td>
190+
<td><strong>{{ ucfirst(__('laravel-crm::lang.tax')) }}</strong></td>
191+
<td>{{ money($invoice->tax, $invoice->currency) }}</td>
192+
</tr>
193+
{{--<tr>
194+
<td></td>
195+
<td></td>
196+
<td><strong>{{ ucfirst(__('laravel-crm::lang.adjustment')) }}</strong></td>
197+
<td>{{ money($invoice->adjustments, $invoice->currency) }}</td>
198+
</tr>--}}
199+
<tr>
200+
<td></td>
201+
<td></td>
202+
<td><strong>{{ ucfirst(__('laravel-crm::lang.total')) }}</strong></td>
203+
<td>{{ money($invoice->total, $invoice->currency) }}</td>
204+
</tr>
205+
</tfoot>
206+
</table>
207+
</div>
208+
</div>
209+
<hr class="m-0" />
210+
<div class="row py-1">
211+
<div class="col px-5 py-4">
212+
<h5>{{ ucfirst(__('laravel-crm::lang.terms')) }}</h5>
213+
{!! nl2br($invoice->terms) !!}
214+
</div>
215+
</div>
216+
</div>
217+
</div>
218+
</div>
219+
</main>
220+
221+
@endsection
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace VentureDrake\LaravelCrm\Http\Controllers\Portal;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Routing\Controller;
7+
use VentureDrake\LaravelCrm\Models\Invoice;
8+
use VentureDrake\LaravelCrm\Services\SettingService;
9+
10+
class InvoiceController extends Controller
11+
{
12+
/**
13+
* @var SettingService
14+
*/
15+
private $settingService;
16+
17+
public function __construct(SettingService $settingService)
18+
{
19+
$this->settingService = $settingService;
20+
}
21+
22+
/**
23+
* Display a listing of the resource.
24+
*
25+
* @return \Illuminate\Http\Response
26+
*/
27+
public function index(Request $request)
28+
{
29+
//
30+
}
31+
32+
/**
33+
* Display the specified resource.
34+
*
35+
* @param int $id
36+
* @return \Illuminate\Http\Response
37+
*/
38+
public function show(Invoice $invoice)
39+
{
40+
if ($invoice->person) {
41+
$email = $invoice->person->getPrimaryEmail();
42+
$phone = $invoice->person->getPrimaryPhone();
43+
$address = $invoice->person->getPrimaryAddress();
44+
}
45+
46+
if ($invoice->organisation) {
47+
$organisation_address = $invoice->organisation->getPrimaryAddress();
48+
}
49+
50+
return view('laravel-crm::portal.invoices.show', [
51+
'invoice' => $invoice,
52+
'email' => $email ?? null,
53+
'phone' => $phone ?? null,
54+
'address' => $address ?? null,
55+
'organisation_address' => $organisation_address ?? null,
56+
'fromName' => $this->settingService->get('organisation_name')->value ?? null,
57+
'logo' => $this->settingService->get('logo_file')->value ?? null,
58+
]);
59+
}
60+
}

src/Http/Livewire/SendInvoice.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public function send()
5252

5353
$this->generateUrl();
5454

55-
/*Mail::send(new \VentureDrake\LaravelCrm\Mail\SendQuote([
55+
Mail::send(new \VentureDrake\LaravelCrm\Mail\SendInvoice([
5656
'to' => $this->to,
5757
'subject' => $this->subject,
5858
'message' => $this->message,
5959
'cc' => $this->cc,
6060
'onlineInvoiceLink' => $this->signedUrl,
61-
]));*/
61+
]));
6262

6363
/*Notification::route('mail', $this->email)
6464
->notify(new OrderSharedNotification(auth()->user(), auth()->user()->currentTeam, $this->order, $this->signedUrl));*/

src/Http/routes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
Route::post('{quote:external_id}', 'VentureDrake\LaravelCrm\Http\Controllers\Portal\QuoteController@process')
6060
->name('laravel-crm.portal.quotes.process');
6161
});
62+
63+
Route::prefix('invoices')->group(function () {
64+
Route::get('{invoice:external_id}', 'VentureDrake\LaravelCrm\Http\Controllers\Portal\InvoiceController@show')
65+
->name('laravel-crm.portal.invoices.show');
66+
});
6267
});
6368

6469
/* Private Routes */

src/Mail/SendInvoice.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace VentureDrake\LaravelCrm\Mail;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Mail\Mailable;
7+
use Illuminate\Queue\SerializesModels;
8+
9+
class SendInvoice extends Mailable
10+
{
11+
use Queueable;
12+
use SerializesModels;
13+
14+
public $emailTo;
15+
16+
public $subject;
17+
18+
public $content;
19+
20+
public $onlineInvoiceLink;
21+
22+
public $copyMe = false;
23+
24+
/**
25+
* Create a new message instance.
26+
*
27+
* @return void
28+
*/
29+
public function __construct($data)
30+
{
31+
$this->emailTo = $data['to'];
32+
$this->subject = $data['subject'];
33+
$this->content = $data['message'];
34+
$this->copyMe = $data['cc'];
35+
$this->onlineInvoiceLink = $data['onlineInvoiceLink'];
36+
}
37+
38+
/**
39+
* Build the message.
40+
*
41+
* @return $this
42+
*/
43+
public function build()
44+
{
45+
$this->content = str_replace('[Online Invoice Link]', $this->onlineInvoiceLink, $this->content);
46+
47+
$this->content = nl2br($this->content);
48+
49+
$mailable = $this->subject($this->subject)
50+
->from(auth()->user()->email, auth()->user()->name)
51+
->to($this->emailTo)
52+
->view('laravel-crm::mail.email');
53+
54+
if ($this->copyMe == 1) {
55+
$mailable->cc(auth()->user()->email);
56+
}
57+
58+
return $mailable;
59+
}
60+
}

0 commit comments

Comments
 (0)