Finish send mail dialog, fixes #12
This commit is contained in:
@@ -20,12 +20,17 @@
|
||||
use App\Support\ApiDataTransformer;
|
||||
use DateTime;
|
||||
use tbQuar\Facades\Quar;
|
||||
use App\Mail\Reminder;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
|
||||
class InvoiceController extends Controller
|
||||
{
|
||||
public function show()
|
||||
{
|
||||
return Inertia::render('Invoices', ['invoicesData' => $this->summaryThisYear()]
|
||||
return Inertia::render(
|
||||
'Invoices',
|
||||
['invoicesData' => $this->summaryThisYear()]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -569,7 +574,7 @@ public function update(Request $request, $id)
|
||||
}
|
||||
}
|
||||
|
||||
public function delete(Request $request, $id)
|
||||
public function delete(Request $request, int $id)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
|
||||
@@ -591,6 +596,34 @@ public function delete(Request $request, $id)
|
||||
}
|
||||
}
|
||||
|
||||
public function remind(Request $request, int $id)
|
||||
{
|
||||
$invoice = InvoiceController::single($id);
|
||||
$to = $request->query('to');
|
||||
$cc = $request->query('cc');
|
||||
|
||||
// TODO: get from settings
|
||||
$bcc = 'buchhaltung@tooloop.de';
|
||||
|
||||
if (empty($to) || !filter_var($to, FILTER_VALIDATE_EMAIL)) {
|
||||
return response()->json([
|
||||
'error' => 'Keine gültige E_Mail-Adresse ' . $to
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (!empty($cc) && !filter_var($cc, FILTER_VALIDATE_EMAIL)) {
|
||||
return response()->json([
|
||||
'error' => 'Keine gültige E_Mail-Adresse ' . $cc
|
||||
], 400);
|
||||
}
|
||||
|
||||
Mail::to($to)
|
||||
->cc($cc)
|
||||
->bcc($cc)
|
||||
->send(new Reminder($invoice));
|
||||
// return new Reminder($invoice);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the next available invoice number
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,6 @@ public function envelope(): Envelope
|
||||
return new Envelope(
|
||||
// TODO: get from settings
|
||||
from: new Address('buchhaltung@tooloop.de', 'Tooloop Multimedia'),
|
||||
bcc: [new Address('daniel.stock@tooloop.de', 'Daniel Stock')],
|
||||
subject: 'Zahlungserinnerung',
|
||||
);
|
||||
}
|
||||
|
||||
@@ -163,7 +163,6 @@ watch(invoice,
|
||||
if (newValue.customerId && newValue.customerId !== 0) {
|
||||
// if (importCustomer.value != newValue.customer)
|
||||
// console.warn('trigger importCustomer watcher')
|
||||
console.log(newValue, newValue.customerId)
|
||||
customers.value.find(customer => {
|
||||
if (customer.id === newValue.customerId) {
|
||||
if (invoice.value) invoice.value.customer = customer as Customer
|
||||
@@ -413,8 +412,8 @@ const openReminderDialog = function () {
|
||||
reminderDialogOpen.value = true
|
||||
}
|
||||
|
||||
const sendReminder = async function (recipient: string | undefined) {
|
||||
if (!recipient) return
|
||||
const sendReminder = async function (to: string | undefined, cc: string | undefined) {
|
||||
if (!to) return
|
||||
if (!invoice.value || !invoice.value.id) return
|
||||
|
||||
// Close dialog
|
||||
@@ -425,8 +424,12 @@ const sendReminder = async function (recipient: string | undefined) {
|
||||
|
||||
try {
|
||||
// await axios call
|
||||
await axios.get('/api/invoices/' + invoice.value.id + '/remind/' + recipient)
|
||||
toast.success("Zahlungserinnerung gesendet", { description: recipient })
|
||||
let request = '/api/invoices/' + invoice.value.id + '/remind?to=' + to
|
||||
if (cc) request += '&cc=' + cc
|
||||
await axios.get(request)
|
||||
invoice.value.paymentStatus = 'reminded'
|
||||
save()
|
||||
toast.success("Zahlungserinnerung gesendet", { description: to })
|
||||
} catch (error: any) {
|
||||
toast.error(error?.title || 'Fehler', { description: error?.message || String(error) })
|
||||
} finally {
|
||||
@@ -819,7 +822,7 @@ const updateLineItems = (newItems: LineItem[]) => {
|
||||
</Dialog>
|
||||
|
||||
<SendMailDialog v-model:open="reminderDialogOpen" title="Zahlungserinnerung senden?" description=""
|
||||
:recipient="billingContactEmail" @send="(recipient: string | undefined) => sendReminder(recipient)" />
|
||||
:to="billingContactEmail" @send="(to, cc) => sendReminder(to, cc)" />
|
||||
|
||||
</template>
|
||||
|
||||
|
||||
@@ -9,17 +9,19 @@ import { Label } from "@/components/ui/label"
|
||||
const props = defineProps<DialogRootProps & {
|
||||
title: string,
|
||||
description?: string,
|
||||
recipient?: string
|
||||
to?: string,
|
||||
cc?: string
|
||||
}>()
|
||||
const recipient = ref<string | undefined>(props.recipient)
|
||||
const to = ref<string | undefined>(props.to)
|
||||
const cc = ref<string | undefined>(props.cc)
|
||||
const emits = defineEmits<DialogRootEmits & {
|
||||
send: [recipient: string | undefined]
|
||||
send: [to: string | undefined, cc: string | undefined]
|
||||
}>()
|
||||
const forwarded = useForwardPropsEmits(props, emits)
|
||||
|
||||
watch(() => props.open,
|
||||
(newValue, oldValue) => {
|
||||
recipient.value = props.recipient
|
||||
to.value = props.to
|
||||
}
|
||||
)
|
||||
</script>
|
||||
@@ -32,15 +34,15 @@ watch(() => props.open,
|
||||
<DialogDescription v-if="props.description" v-html="props.description" />
|
||||
</DialogHeader>
|
||||
<div class="grid grid-cols-[min-content_1fr] gap-4 py-4">
|
||||
<Label for="email" class="text-right text-muted-foreground">
|
||||
<Label for="to" class="text-right text-muted-foreground">
|
||||
An
|
||||
</Label>
|
||||
<Input id="email" required v-model="recipient" type="email" placeholder="E-Mail" />
|
||||
<Input id="to" required v-model="to" type="email" placeholder="E-Mail" />
|
||||
|
||||
<Label for="email" class="text-right text-muted-foreground">
|
||||
<Label for="cc" class="text-right text-muted-foreground">
|
||||
Kopie
|
||||
</Label>
|
||||
<Input id="email" required :value="'buchhaltung@tooloop.de'" type="email" placeholder="E-Mail" />
|
||||
<Input id="cc" v-model="cc" type="email" placeholder="E-Mail" />
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<DialogClose as-child>
|
||||
@@ -48,7 +50,7 @@ watch(() => props.open,
|
||||
Abbrechen
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<Button variant="destructive" @click="$emit('send', recipient)">
|
||||
<Button variant="destructive" @click="$emit('send', to, cc)">
|
||||
E-Mail senden
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
|
||||
+2
-13
@@ -4,11 +4,9 @@
|
||||
use App\Http\Controllers\CustomerController;
|
||||
use App\Http\Controllers\InvoiceController;
|
||||
use App\Http\Controllers\LineItemController;
|
||||
use App\Mail\Reminder;
|
||||
use App\Http\Controllers\PaymentTermsController;
|
||||
use App\Http\Controllers\SettingController;
|
||||
use App\Mail\OrderConfirmation;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
|
||||
Route::get('/customers/{id}', [CustomerController::class, 'single']);
|
||||
@@ -26,21 +24,12 @@
|
||||
Route::get('/invoices/{id}', [InvoiceController::class, 'single']);
|
||||
Route::put('/invoices/{id}', [InvoiceController::class, 'update']);
|
||||
Route::delete('/invoices/{id}', [InvoiceController::class, 'delete']);
|
||||
Route::get('/invoices/{id}/remind', [InvoiceController::class, 'remind']);
|
||||
|
||||
Route::get('/invoices/{id}/remind/{recipient}', function ($id, $recipient) {
|
||||
if (empty($recipient) || !filter_var($recipient, FILTER_VALIDATE_EMAIL)) {
|
||||
return response()->json([
|
||||
'error' => 'Keine gültige E_Mail-Adresse'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$invoice = InvoiceController::single($id);
|
||||
Mail::to($recipient)->send(new Reminder($invoice));
|
||||
// return new Reminder($invoice);
|
||||
});
|
||||
|
||||
Route::get('/lineitems/{invoiceId}', [LineItemController::class, 'index']);
|
||||
|
||||
|
||||
Route::get('/offers/{id}/confirm', function ($id) {
|
||||
// $offer = offerController::single($id);
|
||||
$offer = [
|
||||
|
||||
Reference in New Issue
Block a user