print queue

main-gitea
Zelda Ababil 2024-03-05 13:59:35 +07:00
parent 0ed5a7a7f5
commit 41022131d0
10 changed files with 109 additions and 24 deletions

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Kasir;
use App\Http\Controllers\Controller;
use App\Jobs\ProcessPrint;
use App\Models\BukuBesar;
use App\Models\DetailPesanan;
use App\Models\KelompokKategori;
@ -268,22 +269,26 @@ class Transaksi extends Controller
}
DB::commit();
try {
$print = new PrintOutController();
$print->print($pesananModels->id);
return redirect()->back()->with('success', 'Pesanan berhasil ditambahkan');
// return ['url' => route('transaksi.print', $pesananModels->id) . '?print=true', 'message' => 'Pesanan berhasil ditambahkan'];
} catch (\Throwable $th) {
dd('Print Catch ', $th->getMessage(), $th->getLine(), $th->getFile());
return redirect()->back()->with('error', 'Pesanan berhasil ditambahkan, tetapi terjadi kesalahan saat mencetak struk');
}
// print struk
// try {
// $print = new PrintOutController();
// $print->print($pesananModels->id);
// return redirect()->back()->with('success', 'Pesanan berhasil ditambahkan');
// // return ['url' => route('transaksi.print', $pesananModels->id) . '?print=true', 'message' => 'Pesanan berhasil ditambahkan'];
// } catch (\Throwable $th) {
// dd('Print Catch ', $th->getMessage(), $th->getLine(), $th->getFile());
// return redirect()->back()->with('error', 'Pesanan berhasil ditambahkan, tetapi terjadi kesalahan saat mencetak struk');
// }
ProcessPrint::dispatch($pesananModels);
// return url link page print
return redirect()->back()->with('success', 'Pesanan berhasil ditambahkan');
// return ['url' => route('transaksi.print', $pesananModels->id) . '?print=true', 'message' => 'Pesanan berhasil ditambahkan'];
// return redirect()->back()->with('success', 'Pesanan berhasil ditambahkan');
return ['url' => route('transaksi.print', $pesananModels->id) . '?print=true', 'message' => 'Pesanan berhasil ditambahkan'];
} catch (\Throwable $th) {
DB::rollBack();
dd('Store Catch ', $th->getMessage(), $th->getLine());
// dd('Store Catch ', $th->getMessage(), $th->getLine());
return redirect()->back()->with('error', 'Terjadi kesalahan');
}

View File

@ -138,7 +138,7 @@ class kolomPrinter58mmController extends Controller
$items = [];
/* Information for the receipt */
foreach ($pesanan->detailPesanan as $key => $value) {
$status_pesanan = $value->status_pesanan == 0 ? '(TAKEAWAY)' : ($value->status_pesanan == 3 ? '(CANCEL)' : '(DINEIN)');
$status_pesanan = $value->status_pesanan == 0 ? '(TAKEAWAY)' : ($value->status_pesanan == 3 ? '(CANCEL)' : '');
$items[] = $this->buatBaris1Kolom('(' . $value->jumlah_produk . ') ' . $value->nama_produk . ' ' . $status_pesanan);
if ($value->keterangan_produk != '') {
$items[] = $this->buatBaris1Kolom('Ket: ' . $value->keterangan_produk);

View File

@ -139,7 +139,7 @@ class kolomPrinter88mmController extends Controller
$items = [];
/* Information for the receipt */
foreach ($pesanan->detailPesanan as $key => $value) {
$status_pesanan = $value->status_pesanan == 0 ? '(TAKEAWAY)' : ($value->status_pesanan == 3 ? '(CANCEL)' : '(DINEIN)');
$status_pesanan = $value->status_pesanan == 0 ? '(TAKEAWAY)' : ($value->status_pesanan == 3 ? '(CANCEL)' : '');
$items[] = $this->buatBaris1Kolom('(' . $value->jumlah_produk . ') ' . $value->nama_produk . ' ' . $status_pesanan);
if ($value->keterangan_produk != '') {
$items[] = $this->buatBaris1Kolom('Ket: ' . $value->keterangan_produk);

44
app/Jobs/ProcessPrint.php Normal file
View File

@ -0,0 +1,44 @@
<?php
namespace App\Jobs;
use App\Http\Controllers\Kasir\PrintOutController;
use App\Models\Pesanan;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class ProcessPrint implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $pesanan;
/**
* Create a new job instance.
*/
public function __construct(Pesanan $pesanan)
{
$this->pesanan = $pesanan;
}
/**
* Execute the job.
*/
public function handle(): void
{
try {
$pesanan = Pesanan::find($this->pesanan->id);
Log::info('Printing: ' . $pesanan->id);
$print = new PrintOutController();
$print->print($pesanan->id);
Log::info('Printed: ' . $pesanan->id);
} catch (\Throwable $th) {
//throw $th;
Log::error($th->getMessage());
}
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('jobs', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('jobs');
}
};

View File

@ -758,9 +758,11 @@
toastr.success(result.message, 'Success', {
timeOut: 2000
});
location.reload();
// location.reload();
// window.open(result.url, '_blank');
// window.open(result.url, '_blank', "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=900,height=600");
window.open(result.url, '_blank',
"toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=900,height=600"
);
// set localStorage.OrderStorage to null
theInterval = false;
@ -882,9 +884,11 @@
toastr.success(result.message, 'Success', {
timeOut: 2000
});
location.reload();
// location.reload();
// window.open(result.url, '_blank');
// window.open(result.url, '_blank', "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=900,height=600");
window.open(result.url, '_blank',
"toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=900,height=600"
);
// set localStorage.OrderStorage to null
theInterval = false;

View File

@ -122,7 +122,7 @@
@foreach ($pesanan->detailPesanan as $item)
<tr>
<td style="width: 100px;" colspan="5">{{ $item->nama_produk }}
{{ $item->status_pesanan == 0 ? '(TAKEAWAY)' : ($item->status_pesanan == 3 ? '(CANCEL)' : '(DINEIN)') }}
{{ $item->status_pesanan == 0 ? '(TAKEAWAY)' : ($item->status_pesanan == 3 ? '(CANCEL)' : '') }}
</td>
</tr>
<tr>
@ -213,7 +213,7 @@
<h4>
({{ $item->jumlah_produk }} X)
{{ $item->nama_produk }}
{{ $item->status_pesanan == 0 ? '(TAKEAWAY)' : ($item->status_pesanan == 3 ? '(CANCEL)' : '(DINEIN)') }}
{{ $item->status_pesanan == 0 ? '(TAKEAWAY)' : ($item->status_pesanan == 3 ? '(CANCEL)' : '') }}
</h4>
@if ($item->keterangan_produk != '')
<p>

View File

@ -133,7 +133,7 @@
@foreach ($pesanan->detailPesanan as $item)
<tr>
<td style="width: 100px;" colspan="5">
{{ $item->nama_produk }}{{ $item->status_pesanan == 0 ? '(TAKEAWAY)' : ($item->status_pesanan == 3 ? '(CANCEL)' : '(DINEIN)') }}
{{ $item->nama_produk }}{{ $item->status_pesanan == 0 ? '(TAKEAWAY)' : ($item->status_pesanan == 3 ? '(CANCEL)' : '') }}
</td>
</tr>
<tr>
@ -224,7 +224,7 @@
<td style="width: 80px;" colspan="3">
<h4>
({{ $item->jumlah_produk }} X)
{{ $item->nama_produk }}{{ $item->status_pesanan == 0 ? '(TAKEAWAY)' : ($item->status_pesanan == 3 ? '(CANCEL)' : '(DINEIN)') }}
{{ $item->nama_produk }}{{ $item->status_pesanan == 0 ? '(TAKEAWAY)' : ($item->status_pesanan == 3 ? '(CANCEL)' : '') }}
</h4>
@if ($item->keterangan_produk != '')
<p>

View File

@ -126,7 +126,7 @@
<tr>
<td style="width: 80px;" colspan="3">
({{ $item->jumlah_produk }} X)
{{ $item->nama_produk }}{{ $item->status_pesanan == 0 ? '(TAKEAWAY)' : ($item->status_pesanan == 3 ? '(CANCEL)' : '(DINEIN)') }}
{{ $item->nama_produk }}{{ $item->status_pesanan == 0 ? '(TAKEAWAY)' : ($item->status_pesanan == 3 ? '(CANCEL)' : '') }}
@if ($item->keterangan_produk != '')
<p>
&nbsp;&nbsp;&nbsp;&nbsp; ket: {{ $item->keterangan_produk }}

View File

@ -127,7 +127,7 @@
<td style="width: 80px;" colspan="3">
<h4>
({{ $item->jumlah_produk }} X)
{{ $item->nama_produk }}{{ $item->status_pesanan == 0 ? '(TAKEAWAY)' : ($item->status_pesanan == 3 ? '(CANCEL)' : '(DINEIN)') }}
{{ $item->nama_produk }}{{ $item->status_pesanan == 0 ? '(TAKEAWAY)' : ($item->status_pesanan == 3 ? '(CANCEL)' : '') }}
</h4>
@if ($item->keterangan_produk != '')
<p>