diff --git a/app/Http/Controllers/Pay/PayController.php b/app/Http/Controllers/Pay/PayController.php index f9a7fa4..85d4a21 100644 --- a/app/Http/Controllers/Pay/PayController.php +++ b/app/Http/Controllers/Pay/PayController.php @@ -76,7 +76,7 @@ class PayController extends Controller //make Payone payment public function setPrePayment($payment_method, $amount, $currency, $ret = []){ - $this->reference = substr(uniqid('m', false), 0, 16); + $this->reference = $this->shopping_order->created_at->format('Ym').$this->shopping_order->id;//substr(uniqid('m', false), 0, 16); $this->setMethod($payment_method, $ret); $this->prepayment = [ diff --git a/app/Http/Controllers/User/CheckoutController.php b/app/Http/Controllers/User/CheckoutController.php index c69bb69..8eccc21 100755 --- a/app/Http/Controllers/User/CheckoutController.php +++ b/app/Http/Controllers/User/CheckoutController.php @@ -340,7 +340,7 @@ class CheckoutController extends Controller $ShoppingPayment = ShoppingPayment::where('shopping_order_id', $shopping_order_id)->where('reference', $reference)->first(); if(!$ShoppingPayment){ //TODO log this - Util::setUserHistoryValue(['status'=>21]); + Util::setUserHistoryValue(['status'=>21], $reference); \Session::flash('checkout-error', 'Der Zahlungsvorgang konnte nicht abgeschlossen werden, die Zahlung wurde nicht gefunden: '.$reference); return redirect(route('checkout.checkout_card')); @@ -363,13 +363,13 @@ class CheckoutController extends Controller return view('web.templates.checkout-final', $data); } if($status === "cancel"){ - Util::setUserHistoryValue(['status'=>22]); + Util::setUserHistoryValue(['status'=>22], $reference); \Session::flash('checkout-error', 'Der Zahlungsvorgang wurde abgebrochen, die Bestellung konnte nicht ausgeführt werden.'); return redirect(route('checkout.checkout_card')); } if($status === "error"){ - Util::setUserHistoryValue(['status'=>23]); + Util::setUserHistoryValue(['status'=>23], $reference); \Session::flash('checkout-error', 'Der Zahlungsvorgang wurde abgebrochen, die Bestellung konnte nicht ausgeführt werden.'); return redirect(route('checkout.checkout_card')); diff --git a/app/Mail/MailInvoice.php b/app/Mail/MailInvoice.php new file mode 100644 index 0000000..06eec09 --- /dev/null +++ b/app/Mail/MailInvoice.php @@ -0,0 +1,50 @@ +shopping_order = $shopping_order; + $this->subject = 'Rechnung zu Deiner Bestellung: '.$shopping_order->getLastShoppingPayment('reference') ; + + } + + public function build() + { + $title = __('email.invoice_title'); + $copy1line = __('email.invoice_copy1line').$this->shopping_order->getLastShoppingPayment('reference'); + + $filename = Invoice::getFilename($this->shopping_order); + $path = Invoice::getDownloadPath($this->shopping_order); + if (!Storage::disk('public')->exists($path)) { + return; + } + $file = Storage::disk('public')->path($path); + $mime = Storage::disk('public')->mimeType($path); + + return $this->view('emails.blank')->with([ + 'title' => $title, + 'copy1line' => $copy1line, + ])->attach($file,[ + 'as' => $filename, + 'mime' => $mime, + ]); // attach file; + } +} \ No newline at end of file diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index 7605151..c68ccd2 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -21,6 +21,7 @@ class InvoiceRepository extends BaseRepository { $invoice_number = isset($request['invoice_number']) ? $request['invoice_number'] : Invoice::getInvoiceNumber(); $invoice_date = isset($request['invoice_date']) ? $request['invoice_date'] : $this->model->created_at->format("d.m.Y"); + $invoice_send_mail = isset($request['invoice_send_mail']) ? true: false; $invoice_number = Invoice::createInvoiceNumber($invoice_number, $invoice_date); $data = [ @@ -55,6 +56,11 @@ class InvoiceRepository extends BaseRepository { ]; $this->model->invoice = $data_file; $this->model->save(); + + if($invoice_send_mail){ + Invoice::sendInvoiceMail($this->model); + } + Invoice::makeNextInvoiceNumber(); return true; //return $pdf->stream('invoice.pdf'); diff --git a/app/Services/Invoice.php b/app/Services/Invoice.php index 0aec639..88c83ce 100644 --- a/app/Services/Invoice.php +++ b/app/Services/Invoice.php @@ -1,9 +1,11 @@ path($dir.$filename); } + + public static function sendInvoiceMail($shopping_order){ + $bcc = []; + $billing_email = $shopping_order->shopping_user->billing_email; + if(!$billing_email){ + if($shopping_order->mode === 'test'){ + $billing_email = config('app.checkout_test_mail'); + }else{ + $billing_email = config('app.checkout_mail'); + } + } + if($shopping_order->mode === 'test'){ + $bcc[] = config('app.checkout_test_mail'); + }else{ + $bcc[] = config('app.checkout_mail'); + } + Mail::to($billing_email)->bcc($bcc)->send(new MailInvoice($shopping_order)); + } } diff --git a/resources/lang/de/email.php b/resources/lang/de/email.php index e107978..7dadbbc 100644 --- a/resources/lang/de/email.php +++ b/resources/lang/de/email.php @@ -45,6 +45,8 @@ 'checkout_copy3line' => 'Bei Fragen sind wir jederzeit für Dich da.', 'checkout_copy3line_extern' => 'Bestellung über Berater:', 'status_copy1line' => 'Status zu Deiner Bestellung auf Grüne Seele', + 'invoice_title' => 'Rechnung zu Deiner Bestellung auf Grüne Seele', + 'invoice_copy1line' => 'vielen Dank für Deine Bestellung bei Grüne Seele. Nachfolgend senden wir Dir die Rechnung zu deiner Bestellung: ', 'footer_copy1' => 'GRÜNE SEELE GbR | Hauptstrasse 174 | 51143 Köln | Telefon: (+49) 2203 183 86 14 | E-Mail: service@gruene-seele.bio', 'footer_copy2' => '', 'footer_copy3' => '© 2021 All Rights Reserved', diff --git a/resources/views/admin/sales/_detail.blade.php b/resources/views/admin/sales/_detail.blade.php index 6132995..87e8dc0 100644 --- a/resources/views/admin/sales/_detail.blade.php +++ b/resources/views/admin/sales/_detail.blade.php @@ -641,6 +641,12 @@ {!! Form::text('invoice_number', App\Services\Invoice::getInvoiceNumber(), ['class'=>'form-control']) !!} nächste Rechnungsnummer +
+ +