Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#11] Direct Printing #12

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

PRINT_NODE_API_KEY=
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This project will be used for taking customer's order. It was built with Laravel
- Automated generation of receipt
- Generating reports
- Activity logs per user
- Direct printing of receipt
- Configurations:
- Category
- Products
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/TransactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Actions\Transactions\GenerateReceipt;
use App\Http\Requests\Store\TransactionRequest;
use App\Http\Requests\Update\TransactionRequest as UpdateTransactionRequest;
use App\Jobs\PrintReceiptJob;
use App\Models\Transaction;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
Expand Down Expand Up @@ -39,6 +40,8 @@ public function store(TransactionRequest $request): RedirectResponse

GenerateReceipt::run($transaction);

PrintReceiptJob::dispatch($transaction);

return back();
}

Expand Down
40 changes: 40 additions & 0 deletions app/Jobs/PrintReceiptJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Jobs;

use App\Models\Transaction;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Rawilk\Printing\Facades\Printing;

class PrintReceiptJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Create a new job instance.
*/
public function __construct(protected Transaction $transaction)
{
//
}

/**
* Execute the job.
*/
public function handle(): void
{
$printers = Printing::printers();

if (isset($printers[0]))
{
Printing::newPrintTask()
->printer($printers[0]->id())
->url($this->transaction->receipt->file)
->send();
}
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"laravel/framework": "^11.1",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.7",
"rawilk/laravel-printing": "^3.0",
"spatie/laravel-permission": "^6.4",
"tightenco/ziggy": "^1.0"
},
Expand Down
257 changes: 256 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading