diff --git a/database/migrations/2023_12_11_155249_update_invoices_table.php b/database/migrations/2023_12_11_155249_update_invoices_table.php new file mode 100644 index 0000000..acc9de8 --- /dev/null +++ b/database/migrations/2023_12_11_155249_update_invoices_table.php @@ -0,0 +1,41 @@ +foreignId('currency_id')->nullable()->constrained('currencies'); + $table->boolean('is_bank_transfer')->default(false)->nullable(); + $table->string('bank_account')->nullable(); + $table->string('bank_account_owner')->nullable(); + $table->string('bank_iban')->nullable(); + $table->string('bank_swift')->nullable(); + $table->string('bank_address')->nullable(); + $table->string('bank_branch')->nullable(); + $table->string('bank_name')->nullable(); + $table->string('bank_city')->nullable(); + $table->string('bank_country')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}; diff --git a/resources/views/invoices/create.blade.php b/resources/views/invoices/create.blade.php index 44ef969..0aa006a 100644 --- a/resources/views/invoices/create.blade.php +++ b/resources/views/invoices/create.blade.php @@ -1,6 +1,6 @@ +
+
+ {{__('Currency')}} +
+
+ +
+
{{__('Type')}} @@ -162,7 +179,88 @@
- +
+
+ {{__('Has Bank Transfer?')}} +
+
+ +
+
+
+
+
+ {{__('Bank Account')}} +
+
+ +
+
+
+
+ {{__('Bank Account IBAN')}} +
+
+ +
+
+
+
+ {{__('Bank Account Owner')}} +
+
+ +
+
+
+
+ {{__('Bank SWIFT')}} +
+
+ +
+
+
+
+ {{__('Bank Address')}} +
+
+ +
+
+
+
+ {{__('Bank Branch Code')}} +
+
+ +
+
+
+
+ {{__('Bank Name')}} +
+
+ +
+
+
+
+ {{__('Bank City')}} +
+
+ +
+
+
+
+ {{__('Bank Country')}} +
+
+ +
+
+
diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 9f94290..d9e0790 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -118,6 +118,23 @@
+
+
+ {{__('Currency')}} +
+
+ +
+
{{__('Type')}} @@ -146,7 +163,88 @@
- +
+
+ {{__('Has Bank Transfer?')}} +
+
+ +
+
+
+
+
+ {{__('Bank Account')}} +
+
+ +
+
+
+
+ {{__('Bank Account IBAN')}} +
+
+ +
+
+
+
+ {{__('Bank Account Owner')}} +
+
+ +
+
+
+
+ {{__('Bank SWIFT')}} +
+
+ +
+
+
+
+ {{__('Bank Address')}} +
+
+ +
+
+
+
+ {{__('Bank Branch Code')}} +
+
+ +
+
+
+
+ {{__('Bank Name')}} +
+
+ +
+
+
+
+ {{__('Bank City')}} +
+
+ +
+
+
+
+ {{__('Bank Country')}} +
+
+ +
+
+
diff --git a/resources/views/invoices/print.blade.php b/resources/views/invoices/print.blade.php new file mode 100644 index 0000000..41b89f8 --- /dev/null +++ b/resources/views/invoices/print.blade.php @@ -0,0 +1,263 @@ +
+
+
+ {{setting('site_name')}} +
+
+
+ {{$model->from_id->name}} +
+
+ {{$model->from_id->ceo}} +
+
+ {{$model->from_id->address}} +
+
+ {{$model->from_id->zip}} {{$model->from_id->city}} +
+
+ {{$model->from_id->country?->name}} +
+
+
+
+
+ {{__('Bill To')}}: +
+
+ {{$model->for_id?->name}} +
+
+ {{$model->for_id?->email}} +
+
+ {{$model->for_id?->phone}} +
+ @php + $address = $model->for_id?->locations()->first(); + @endphp + @if($address) +
+ {{$address->street}} +
+
+ {{$address->zip}}, {{$address->city->name}} +
+
+ {{$model->for_id?->locations()->first()?->country->name}} +
+ @endif + +
+
+
+
+
+
+
+

{{__('INVOICE')}}

+
+
+ {{__('Invoice')}}# {{$model->uuid}} +
+
+
+
+
+
+
+
{{__('Issue Date')}} :
+
{{$model->created_at->toDateString()}}
+
+
+
{{__('Due Date')}} :
+
{{$model->due_date->toDateString()}}
+
+
+
{{__('Status')}} :
+
{{$model->status}}
+
+
+
{{__('Type')}} :
+
{{$model->type}}
+
+
+
+
+
+
+ +
+
+
+ # +
+
+ {{__('Item')}} +
+
+ {{__('Price')}} +
+
+ {{__('Discount')}} +
+
+ {{__('Tax')}} +
+
+ {{__('QTY')}} +
+
+ {{__('Total')}} +
+
+
+ @foreach($model->invoicesitems as $key=>$item) +
+
+ {{ $key+1 }} +
+
+
+ {{ $item->item }} +
+ @if($item->options) +
+ @foreach($item->options ?? [] as $label=>$options) + {{ str($label)->ucfirst() }} : {{$options}}
+ @endforeach +
+ @endif +
+
+ {{ number_format($item->price, 2) }}{{ $model->currency?->symbol }} +
+
+ {{ number_format($item->discount, 2) }}{{ $model->currency?->symbol }} +
+
+ {{ number_format($item->tax, 2) }}{{ $model->currency?->symbol }} +
+
+ {{ $item->qty }} +
+
+ {{ number_format($item->total, 2) }}{{ $model->currency?->symbol }} +
+
+ @endforeach + +
+
+
+
+
+ {{__('Signature')}} +
+
+
+ {{ $model->from_id?->ceo }} +
+
+ {{ $model->from_id?->email }} +
+
+ {{ $model->from_id?->website }} +
+
+ {{ $model->from_id?->phone }} +
+
+
+ + + @if($model->is_bank_transfer) +
+
+ {{__('Bank Account')}} +
+
+
+ {{__('Name')}} : {{ $model->bank_name }} +
+
+ {{__('Address')}} : {{ $model->bank_address }}, {{ $model->bank_city }}, {{ $model->bank_country}} +
+
+ {{__('Branch')}} : {{ $model->bank_branch }} +
+
+ {{__('SWIFT')}} : {{ $model->bank_swift }} +
+
+ {{__('Account')}} : {{ $model->bank_account }} +
+
+ {{__('Owner')}} : {{ $model->bank_account_owner }} +
+
+ {{__('IBAN')}} : {{ $model->bank_iban }} +
+
+
+ @endif +
+
+
+
+ {{__('Sub Total')}} +
+
+ {{ number_format(($model->total + $model->discount) - ($model->vat + $model->shipping), 2) }}{{ $model->currency?->symbol }} +
+
+
+
+ {{__('Tax')}} +
+
+ {{ number_format($model->vat, 2) }}{{ $model->currency?->symbol }} +
+
+
+
+ {{__('Discount')}} +
+
+ {{ number_format($model->discount, 2) }}{{ $model->currency?->symbol }} +
+
+
+
+ {{__('Paid')}} +
+
+ {{ number_format($model->paid, 2) }}{{ $model->currency?->symbol }} +
+
+
+
+ {{__('Balance Due')}} +
+
+ {{ number_format($model->total-$model->paid, 2) }}{{ $model->currency?->symbol }} +
+
+
+
+ + + @if($model->notes) +
+ +
+
+ {{__('Notes')}} +
+
+ {!! $model->notes !!} +
+
+ @endif +
diff --git a/resources/views/invoices/show.blade.php b/resources/views/invoices/show.blade.php index 573fdc4..a847319 100644 --- a/resources/views/invoices/show.blade.php +++ b/resources/views/invoices/show.blade.php @@ -2,13 +2,10 @@
-
- {{setting('site_name')}} +
+ {{setting('site_name')}}
-
- {{__('From:')}} -
{{$model->from_id->name}}
@@ -25,12 +22,12 @@ {{$model->from_id->country?->name}}
-
-
- {{__('To:')}} -
+
-
+
+ {{__('Bill To')}}: +
+
{{$model->for_id?->name}}
@@ -39,156 +36,234 @@
{{$model->for_id?->phone}}
-
- {{$model->for_id?->address}} -
-
- {{$model->for_id?->country?->name}} , {{$model->for_id?->city}}, {{$model->for_id?->area?->name}} -
+ @php + $address = $model->for_id?->locations()->first(); + @endphp + @if($address) +
+ {{$address->street}} +
+
+ {{$address->zip}}, {{$address->city->name}} +
+
+ {{$model->for_id?->locations()->first()?->country->name}} +
+ @endif +
-
-
-
- {{__('Invoice')}} -
-
- {{$model->uuid}} -
-
-
-
- {{__('Issue date')}} -
-
- {{$model->created_at->toDateString()}} -
+
+
+
+
+

{{__('INVOICE')}}

+
+
+ {{__('Invoice')}}# {{$model->uuid}} +
+
-
-
- {{__('Due date')}} -
-
- {{$model->due_date->toDateString()}} -
-
-
-
- {{__('Status')}} -
-
- {{str($model->status)->upper()}} -
-
-
-
- {{__('Type')}} -
-
- {{str($model->type)->upper()}} +
+
+
+
+
{{__('Issue Date')}} :
+
{{$model->created_at->toDateString()}}
+
+
+
{{__('Due Date')}} :
+
{{$model->due_date->toDateString()}}
+
+
+
{{__('Status')}} :
+
{{$model->status}}
+
+
+
{{__('Type')}} :
+
{{$model->type}}
+
+
+
-
-
+
+
+ # +
+
{{__('Item')}}
-
+
{{__('Price')}}
-
+
{{__('Discount')}}
-
+
{{__('Tax')}}
-
+
{{__('QTY')}}
-
+
{{__('Total')}}
- @foreach($model->invoicesitems as $item) -
-
+ @foreach($model->invoicesitems as $key=>$item) +
+
+ {{ $key+1 }} +
+
{{ $item->item }}
+ @if($item->options)
@foreach($item->options ?? [] as $label=>$options) {{ str($label)->ucfirst() }} : {{$options}}
@endforeach
+ @endif
-
- {!! dollar($item->price) !!} +
+ {{ number_format($item->price, 2) }}{{ $model->currency?->symbol }}
-
- {!! dollar($item->discount) !!} +
+ {{ number_format($item->discount, 2) }}{{ $model->currency?->symbol }}
-
- {!! dollar($item->tax) !!} +
+ {{ number_format($item->tax, 2) }}{{ $model->currency?->symbol }}
-
- {{$item->qty}} +
+ {{ $item->qty }}
-
- {!! dollar($item->total) !!} +
+ {{ number_format($item->total, 2) }}{{ $model->currency?->symbol }}
@endforeach
-
-
-
- {{__('Sub Total')}} -
+
+
+ @if($model->is_bank_transfer) +
+
+ {{__('Bank Account')}} +
+
+
+ {{__('Name')}} : {{ $model->bank_name }} +
+
+ {{__('Address')}} : {{ $model->bank_address }}, {{ $model->bank_city }}, {{ $model->bank_country}} +
+
+ {{__('Branch')}} : {{ $model->bank_branch }} +
+
+ {{__('SWIFT')}} : {{ $model->bank_swift }} +
+
+ {{__('Account')}} : {{ $model->bank_account }} +
+
+ {{__('Owner')}} : {{ $model->bank_account_owner }} +
+
+ {{__('IBAN')}} : {{ $model->bank_iban }} +
+
+
+ @endif +
- {!! dollar(($model->total + $model->discount) - ($model->vat + $model->shipping)) !!} +
+ {{__('Signature')}} +
+
+
+ {{ $model->from_id?->ceo }} +
+
+ {{ $model->from_id?->email }} +
+
+ {{ $model->from_id?->website }} +
+
+ {{ $model->from_id?->phone }} +
+
-
-
- {{__('Tax')}} -
-
- {!! dollar($model->vat ) !!} +
+
+
+ {{__('Sub Total')}} +
+
+ {{ number_format(($model->total + $model->discount) - ($model->vat + $model->shipping), 2) }}{{ $model->currency?->symbol }} +
-
-
-
- {{__('Discount')}} +
+
+ {{__('Tax')}} +
+
+ {{ number_format($model->vat, 2) }}{{ $model->currency?->symbol }} +
-
- {!! dollar($model->discount ) !!} +
+
+ {{__('Discount')}} +
+
+ {{ number_format($model->discount, 2) }}{{ $model->currency?->symbol }} +
-
-
-
- {{__('Paid')}} +
+
+ {{__('Paid')}} +
+
+ {{ number_format($model->paid, 2) }}{{ $model->currency?->symbol }} +
-
- {!! dollar($model->paid ) !!} +
+
+ {{__('Balance Due')}} +
+
+ {{ number_format($model->total-$model->paid, 2) }}{{ $model->currency?->symbol }} +
-
-
- {{__('Total')}} +
+ + @if($model->notes) +
+
+
+ {{__('Notes')}}
-
- {!! dollar($model->total-$model->paid) !!} +
+ {!! $model->notes !!}
-
+ @endif
- {{-- --}} + + {{__('Print')}} + name('invoices.create'); Route::post('admin/invoices', [InvoiceController::class, 'store'])->name('invoices.store'); Route::get('admin/invoices/{model}', [InvoiceController::class, 'show'])->name('invoices.show'); + Route::get('admin/invoices/{model}/print', [InvoiceController::class, 'printIt'])->name('invoices.print'); Route::get('admin/invoices/{model}/edit', [InvoiceController::class, 'edit'])->name('invoices.edit'); Route::post('admin/invoices/{model}', [InvoiceController::class, 'update'])->name('invoices.update'); Route::delete('admin/invoices/{model}', [InvoiceController::class, 'destroy'])->name('invoices.destroy'); diff --git a/src/Http/Controllers/InvoiceController.php b/src/Http/Controllers/InvoiceController.php index c7b1065..489ba8c 100644 --- a/src/Http/Controllers/InvoiceController.php +++ b/src/Http/Controllers/InvoiceController.php @@ -183,6 +183,20 @@ public function show(\TomatoPHP\TomatoInvoices\Models\Invoice $model): View|Json ); } + /** + * @param \TomatoPHP\TomatoInvoices\Models\Invoice $model + * @return View|JsonResponse + */ + public function printIt(\TomatoPHP\TomatoInvoices\Models\Invoice $model): View|JsonResponse + { + $model->from_id = $model->from_type::find($model->from_id); + $model->for_id = $model->for_type::find($model->for_id); + return Tomato::get( + model: $model, + view: 'tomato-invoices::invoices.print', + ); + } + /** * @param \TomatoPHP\TomatoInvoices\Models\Invoice $model * @return View diff --git a/src/Models/Invoice.php b/src/Models/Invoice.php index c4d89b6..a4c34ca 100644 --- a/src/Models/Invoice.php +++ b/src/Models/Invoice.php @@ -5,6 +5,7 @@ use App\Models\User; use Illuminate\Database\Eloquent\Model; use TomatoPHP\TomatoCrm\Models\Account; +use TomatoPHP\TomatoLocations\Models\Currency; use TomatoPHP\TomatoOrders\Models\Order; use TomatoPHP\TomatoCategory\Models\Category; use TomatoPHP\TomatoBranches\Models\Branch; @@ -12,7 +13,18 @@ /** * @property integer $id * @property integer $from_id + * @property string $bank_account + * @property string $bank_account_owner + * @property string $bank_iban + * @property string $bank_swift + * @property string $bank_address + * @property string $bank_branch + * @property string $bank_name + * @property string $bank_city + * @property string $bank_country + * @property boolean $is_bank_transfer * @property string $from_type + * @property integer $currency_id * @property integer $for_id * @property string $for_type * @property integer $order_id @@ -43,6 +55,7 @@ * @property Category $category * @property Order $order * @property User $user + * @property Currency $currency * @property InvoicesItem[] $invoicesItems */ class Invoice extends Model @@ -50,15 +63,33 @@ class Invoice extends Model /** * @var array */ - protected $fillable = ['from_id','from_type','for_id', 'for_type', 'order_id', 'user_id', 'branch_id', 'category_id', 'uuid', 'name', 'phone', 'address', 'type', 'status', 'total', 'discount', 'vat', 'paid', 'date', 'due_date', 'is_activated', 'is_offer', 'send_email', 'notes', 'created_at', 'updated_at']; + protected $fillable = [ + 'bank_account', + 'bank_account_owner', + 'bank_iban', + 'bank_swift', + 'bank_address', + 'bank_branch', + 'bank_name', + 'bank_city', + 'bank_country', + 'is_bank_transfer', + 'currency_id', + 'from_id','from_type','for_id', 'for_type', 'order_id', 'user_id', 'branch_id', 'category_id', 'uuid', 'name', 'phone', 'address', 'type', 'status', 'total', 'discount', 'vat', 'paid', 'date', 'due_date', 'is_activated', 'is_offer', 'send_email', 'notes', 'created_at', 'updated_at']; protected $casts = [ 'due_date' => 'datetime', 'date' => 'datetime', 'is_offer' => 'bool', 'is_activated' => 'bool', - 'send_email' => 'bool' + 'send_email' => 'bool', + 'is_bank_transfer' => 'bool', ]; + + public function currency() + { + return $this->belongsTo(Currency::class, 'currency_id', 'id'); + } /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ diff --git a/src/Tables/InvoiceTable.php b/src/Tables/InvoiceTable.php index 2302b3e..012ea80 100644 --- a/src/Tables/InvoiceTable.php +++ b/src/Tables/InvoiceTable.php @@ -56,7 +56,6 @@ public function configure(SpladeTable $table) columns: ['id','uuid','name','phone',] ) ->defaultSort('id', 'desc') - ->column(key: 'actions',label: trans('tomato-admin::global.crud.actions')) ->column( key: 'id', label: __('Id'), @@ -113,6 +112,7 @@ public function configure(SpladeTable $table) label: __('Is activated'), sortable: true ) + ->column(key: 'actions',label: trans('tomato-admin::global.crud.actions')) ->paginate(10);