Browse Source

small fixes, logo update, prefix update

1day2die 3 years ago
parent
commit
a6de39bc32

+ 1 - 0
.gitignore

@@ -19,3 +19,4 @@ yarn-error.log
 .env.dev
 .env.testing
 storage/invoices.zip
+storage/app/public/logo.png

+ 6 - 3
app/Http/Controllers/Admin/PaymentController.php

@@ -198,6 +198,7 @@ class PaymentController extends Controller
                 $lastInvoiceID = \App\Models\Invoice::where("invoice_name", "like", "%" . now()->format('mY') . "%")->count("id");
                 $newInvoiceID = $lastInvoiceID + 1;
                 $InvoiceSettings = InvoiceSettings::all()->first();
+                $logoPath = storage_path('app/public/logo.png');
 
                 $seller = new Party([
                     'name' => $InvoiceSettings->company_name,
@@ -231,16 +232,18 @@ class PaymentController extends Controller
                     ->series(now()->format('mY'))
                     ->delimiter("-")
                     ->sequence($newInvoiceID)
-                    ->serialNumberFormat(env("INVOICE_PREFIX", "INV") . '{DELIMITER}{SERIES}{SEQUENCE}')
-                    ->logo(storage_path('app/public/logo.png'));
+                    ->serialNumberFormat($InvoiceSettings->invoice_prefix . '{DELIMITER}{SERIES}{SEQUENCE}');
 
+                if (file_exists($logoPath)) {
+                    $invoice->logo($logoPath);
+                }
                 //Save the invoice in "storage\app\invoice\USER_ID\YEAR"
                 $invoice->filename = $invoice->getSerialNumber() . '.pdf';
                 $invoice->render();
                 Storage::disk("local")->put("invoice/" . $user->id . "/" . now()->format('Y') . "/" . $invoice->filename, $invoice->output);
 
 
-                \App\Models\invoice::create([
+                \App\Models\Invoice::create([
                     'invoice_user' => $user->id,
                     'invoice_name' => $invoice->getSerialNumber(),
                     'payment_id' => $payment->payment_id,

+ 3 - 1
app/Http/Controllers/Admin/SettingsController.php

@@ -27,7 +27,8 @@ class SettingsController extends Controller
                 'company_phone' => invoiceSettings::get()->first()->company_phone,
                 'company_vat' => invoiceSettings::get()->first()->company_vat,
                 'company_mail' => invoiceSettings::get()->first()->company_mail,
-                'company_web' => invoiceSettings::get()->first()->company_web
+                'company_web' => invoiceSettings::get()->first()->company_web,
+                'invoice_prefix' => invoiceSettings::get()->first()->invoice_prefix
             ]);
     }
 
@@ -61,6 +62,7 @@ class SettingsController extends Controller
         invoiceSettings::updateOrCreate(['id' => "1",], ['company_mail' => $request->get('company-mail')]);
         invoiceSettings::updateOrCreate(['id' => "1",], ['company_vat' => $request->get('company-vat')]);
         invoiceSettings::updateOrCreate(['id' => "1",], ['company_web' => $request->get('company-web')]);
+        invoiceSettings::updateOrCreate(['id' => "1",], ['invoice_prefix' => $request->get('invoice-prefix')]);
 
         if ($request->hasFile('logo')) {
             $request->file('logo')->storeAs('public', 'logo.png');

+ 2 - 1
app/Models/InvoiceSettings.php

@@ -17,6 +17,7 @@ class InvoiceSettings extends Model
         'company_phone',
         'company_mail',
         'company_vat',
-        'company_web'
+        'company_web',
+        'invoice_prefix'
     ];
 }

+ 11 - 0
resources/views/admin/settings/index.blade.php

@@ -165,6 +165,17 @@
                                             </div>
                                         </div>
 
+                                        <!-- website -->
+                                        <div class="form-group">
+                                            <div class="custom-control mb-3">
+                                                <label
+                                                    for="invoice-prefix">{{__('Enter your custom invoice prefix' )}}</label>
+                                                <input x-model="invoice-prefix" id="invoice-prefix" name="invoice-prefix"
+                                                       type="text" value="{{$invoice_prefix}}"
+                                                       class="form-control @error('invoice-prefix') is-invalid @enderror">
+                                            </div>
+                                        </div>
+
                                         <!-- logo -->
                                         <div class="form-group">
                                             <div class="custom-file mb-3">

BIN
storage/app/public/logo.png