Improved handling for new invoices
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
namespace App\Domains\Invoice\Actions\CreateInvoice;
|
||||
|
||||
use App\Enumerations\InvoiceStatus;
|
||||
use App\Mail\InvoiceMails\InvoiceMailsNewInvoiceMail;
|
||||
use App\Mail\ParticipantParticipationMails\EventSignUpSuccessfullMail;
|
||||
use App\Models\Invoice;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class CreateInvoiceCommand {
|
||||
private CreateInvoiceRequest $request;
|
||||
@@ -36,6 +39,7 @@ class CreateInvoiceCommand {
|
||||
'amount' => $this->request->totalAmount,
|
||||
'distance' => $this->request->distance,
|
||||
'travel_direction' => $this->request->travelRoute,
|
||||
'travel_reason' => $this->request->travelReason,
|
||||
'passengers' => $this->request->passengers,
|
||||
'transportation' => $this->request->transportations,
|
||||
'document_filename' => $this->request->receiptFile !== null ? $this->request->receiptFile->fullPath : null,
|
||||
@@ -46,6 +50,23 @@ class CreateInvoiceCommand {
|
||||
$response->invoice = $invoice;
|
||||
}
|
||||
|
||||
if ($this->request->costUnit->mail_on_new) {
|
||||
$recipients = [app('tenant')->email_finance];
|
||||
|
||||
foreach ($this->request->costUnit->treasurers()->get() as $treasurer) {
|
||||
if (!in_array($treasurer->email, $recipients)) {
|
||||
$recipients[] = $treasurer->email;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($recipients as $recipient) {
|
||||
Mail::to($recipient)->send(new InvoiceMailsNewInvoiceMail(
|
||||
invoice: $invoice,
|
||||
costUnit: $this->request->costUnit,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ class CreateInvoiceRequest {
|
||||
public float $totalAmount;
|
||||
public bool $isDonation;
|
||||
public ?int $userId;
|
||||
public ?string $travelReason;
|
||||
|
||||
|
||||
public function __construct(
|
||||
@@ -41,6 +42,7 @@ class CreateInvoiceRequest {
|
||||
?int $distance = null,
|
||||
?int $passengers = null,
|
||||
?int $transportations,
|
||||
?string $travelReason = null,
|
||||
|
||||
) {
|
||||
$this->costUnit = $costUnit;
|
||||
@@ -59,6 +61,7 @@ class CreateInvoiceRequest {
|
||||
$this->totalAmount = $totalAmount;
|
||||
$this->isDonation = $isDonation;
|
||||
$this->userId = $userId;
|
||||
$this->travelReason = $travelReason;
|
||||
|
||||
if ($accountIban === 'undefined') {
|
||||
$this->accountIban = null;
|
||||
|
||||
@@ -84,6 +84,7 @@ class CreateInvoiceReceiptCommand {
|
||||
|
||||
$travelPartTemplate = <<<HTML
|
||||
<tr><td>Reiseweg:</td><td>%1\$s</td></tr>
|
||||
<tr><td>Grund der Reise:</td><td>%6\$s</td></tr>
|
||||
<tr><td>Gesamtlänge der Strecke:</td><td>%2\$s km x %3\$s / km</td></tr>
|
||||
<tr><td>Materialtransport:</td><td>%4\$s</td></tr>
|
||||
<tr><td>Mitfahrende im PKW:</td><td>%5\$s</td></tr>
|
||||
@@ -95,7 +96,8 @@ HTML;
|
||||
$invoiceReadable['distance'],
|
||||
$invoiceReadable['distanceAllowance'],
|
||||
$invoiceReadable['transportation'],
|
||||
$invoiceReadable['passengers']
|
||||
$invoiceReadable['passengers'],
|
||||
$invoiceReadable['travelReason'] ,
|
||||
);
|
||||
|
||||
$invoiceTravelPart = '<tr><td>Kosten für ÖPNV:</td><td>' . $invoiceReadable['amount'] . '</td></tr>';;
|
||||
|
||||
@@ -64,31 +64,32 @@ class NewInvoiceController extends CommonController {
|
||||
case InvoiceType::INVOICE_TYPE_TRAVELLING:
|
||||
|
||||
if ($uploadedFile !== null) {
|
||||
$amount = Amount::fromString($request->get('amount'))->getAmount();
|
||||
$amount = Amount::fromString($request->input('amount'))->getAmount();
|
||||
$distance = null;
|
||||
} else {
|
||||
$distance = Amount::fromString($request->get('amount'))->getRoundedAmount();
|
||||
$distance = Amount::fromString($request->input('amount'))->getRoundedAmount();
|
||||
$amount = $distance * $costUnit->distance_allowance;
|
||||
|
||||
}
|
||||
|
||||
$createInvoiceRequest = new CreateInvoiceRequest(
|
||||
$costUnit,
|
||||
$request->get('name'),
|
||||
$request->input('name'),
|
||||
InvoiceType::INVOICE_TYPE_TRAVELLING,
|
||||
$amount,
|
||||
$uploadedFile,
|
||||
'donation' === $request->get('decision') ? true : false,
|
||||
'donation' === $request->input('decision') ? true : false,
|
||||
$this->users->getCurrentUserDetails()['userId'],
|
||||
$request->get('contactEmail'),
|
||||
$request->get('telephone'),
|
||||
$request->get('accountOwner'),
|
||||
$request->get('accountIban'),
|
||||
$request->input('email'),
|
||||
$request->input('telephone'),
|
||||
$request->input('accountOwner'),
|
||||
$request->input('accountIban'),
|
||||
null,
|
||||
$request->get('otherText'),
|
||||
$request->input('otherText'),
|
||||
$distance,
|
||||
$request->get('havePassengers'),
|
||||
$request->get('materialTransportation'),
|
||||
$request->input('havePassengers'),
|
||||
$request->input('materialTransportation'),
|
||||
$request->input('travelReason'),
|
||||
);
|
||||
|
||||
break;
|
||||
@@ -96,21 +97,22 @@ class NewInvoiceController extends CommonController {
|
||||
default:
|
||||
$createInvoiceRequest = new CreateInvoiceRequest(
|
||||
$costUnit,
|
||||
$request->get('name'),
|
||||
$request->input('name'),
|
||||
$invoiceType,
|
||||
Amount::fromString($request->get('amount'))->getAmount(),
|
||||
Amount::fromString($request->input('amount'))->getAmount(),
|
||||
$uploadedFile,
|
||||
'donation' === $request->get('decision') ? true : false,
|
||||
'donation' === $request->input('decision') ? true : false,
|
||||
$this->users->getCurrentUserDetails()['userId'],
|
||||
$request->get('contactEmail'),
|
||||
$request->get('telephone'),
|
||||
$request->get('accountOwner'),
|
||||
$request->get('accountIban'),
|
||||
$request->get('otherText'),
|
||||
$request->input('email'),
|
||||
$request->input('telephone'),
|
||||
$request->input('accountOwner'),
|
||||
$request->input('accountIban'),
|
||||
$request->input('otherText'),
|
||||
null,
|
||||
null,
|
||||
$request->get('havePassengers'),
|
||||
$request->get('materialTransportation'),
|
||||
$request->input('havePassengers'),
|
||||
$request->input('materialTransportation'),
|
||||
null
|
||||
);
|
||||
|
||||
break;
|
||||
@@ -124,15 +126,10 @@ class NewInvoiceController extends CommonController {
|
||||
'success'
|
||||
);
|
||||
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Alright'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
dd($request->all());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,11 @@ const props = defineProps({
|
||||
<td>{{props.invoice.travelRoute}}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Grund der Reise</th>
|
||||
<td>{{props.invoice.travelReason}}</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Gesamte Wegstrecke</th>
|
||||
<td>{{props.invoice.distance}} km</td>
|
||||
|
||||
@@ -109,6 +109,7 @@ function handleFileChange(event) {
|
||||
:userIban="data.userIban"
|
||||
:userAccountOwner="data.userAccountOwner"
|
||||
:receipt="receipt"
|
||||
travelReason=""
|
||||
@close="finalStep = false"
|
||||
/>
|
||||
|
||||
|
||||
@@ -25,9 +25,10 @@ const props = defineProps({
|
||||
userIban: String,
|
||||
havePassengers: Number,
|
||||
materialTransportation: Boolean,
|
||||
travelReason: String,
|
||||
})
|
||||
|
||||
console.log(props.receipt)
|
||||
console.log(props)
|
||||
|
||||
const finalStep = ref(true)
|
||||
const userName = ref(props.userName)
|
||||
@@ -49,6 +50,8 @@ async function sendData() {
|
||||
errorMsg.value = ''
|
||||
success.value = false
|
||||
|
||||
console.log(props)
|
||||
|
||||
const formData = new FormData()
|
||||
|
||||
formData.append('name', userName.value)
|
||||
@@ -61,6 +64,7 @@ async function sendData() {
|
||||
formData.append('accountIban', userIban.value)
|
||||
formData.append('havePassengers', props.havePassengers ? 1 : 0)
|
||||
formData.append('materialTransportation', props.materialTransportation ? 1 : 0)
|
||||
formData.append('travelReason', props.travelReason)
|
||||
|
||||
if (props.receipt) {
|
||||
formData.append('receipt', props.receipt)
|
||||
|
||||
@@ -18,6 +18,7 @@ const data = defineProps({
|
||||
const { request } = useAjax();
|
||||
const distanceAllowance = ref(null);
|
||||
const travelDirection = ref(null);
|
||||
const travelReason = ref(null);
|
||||
const have_receipt = ref('')
|
||||
const havePassengers = ref(false);
|
||||
const materialTransportation = ref(false);
|
||||
@@ -57,7 +58,16 @@ function handleFileChange(event) {
|
||||
/>
|
||||
</fieldset><br /><br />
|
||||
|
||||
<fieldset v-if="travelDirection !== null">
|
||||
<fieldset v-if="travelDirection !== null">
|
||||
<legend><span style="font-weight: bolder;">Was war der Grund für deine Reise?</span></legend>
|
||||
<input
|
||||
type="text"
|
||||
name="travel-reason"
|
||||
v-model="travelReason"
|
||||
/>
|
||||
</fieldset><br /><br />
|
||||
|
||||
<fieldset v-if="travelReason !== null">
|
||||
<legend><span style="font-weight: bolder;">Bist du mit dem ÖPNV gefahren oder besitzt du einen Beleg</span></legend>
|
||||
<input type="button" style="border-radius: 0; width: 100px;" @click="have_receipt='yes'" value="Ja" />
|
||||
<input type="button" style="border-radius: 0; width: 100px;" @click="getDistanceAllowance" value="Nein" />
|
||||
@@ -92,6 +102,7 @@ function handleFileChange(event) {
|
||||
:userIban="data.userIban"
|
||||
:userAccountOwner="data.userAccountOwner"
|
||||
:receipt="receipt"
|
||||
:travelReason="travelReason"
|
||||
@close="finalStep = false"
|
||||
/>
|
||||
</fieldset>
|
||||
@@ -142,6 +153,7 @@ function handleFileChange(event) {
|
||||
:userTelephone="data.userTelephone"
|
||||
:userIban="data.userIban"
|
||||
:userAccountOwner="data.userAccountOwner"
|
||||
:travelReason="travelReason"
|
||||
@close="finalStep = false"
|
||||
/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user